From: Xia Kaixiang Date: Fri, 17 May 2019 10:41:51 +0000 (+0800) Subject: 商户树形管理 X-Git-Tag: 1.0.0^2~214 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=c171fdb1fd3c536575675042df0dcbd6e82ce3b8;p=epayment%2Ffood_payapi.git 商户树形管理 --- diff --git a/src/main/java/com/supwisdom/dlpay/framework/dao/ShopDao.java b/src/main/java/com/supwisdom/dlpay/framework/dao/ShopDao.java index fccf8009..968804e0 100644 --- a/src/main/java/com/supwisdom/dlpay/framework/dao/ShopDao.java +++ b/src/main/java/com/supwisdom/dlpay/framework/dao/ShopDao.java @@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.Lock; import org.springframework.data.jpa.repository.Query; import javax.persistence.LockModeType; +import java.util.List; /** * Created by shuwei on 2019/4/15. @@ -20,4 +21,7 @@ public interface ShopDao extends JpaRepository { TShop getTShopByShopid(Integer shopid); TShop getTShopByShopaccno(String shopaccno); + + @Query("from TShop where status='normal' and fshopid=?1 ") + List getChildShopsByShopid(Integer shopid); } diff --git a/src/main/java/com/supwisdom/dlpay/framework/dao/ShopaccDao.java b/src/main/java/com/supwisdom/dlpay/framework/dao/ShopaccDao.java index 45977f74..4e1f9ef7 100644 --- a/src/main/java/com/supwisdom/dlpay/framework/dao/ShopaccDao.java +++ b/src/main/java/com/supwisdom/dlpay/framework/dao/ShopaccDao.java @@ -40,4 +40,6 @@ public interface ShopaccDao extends JpaRepository { @Query("select a from TShopacc a where a.shopid=?1") TShopacc getShopaccWithLock(Integer shopid); + TShopacc getByShopaccno(String shopaccno); + } diff --git a/src/main/java/com/supwisdom/dlpay/system/bean/ZTreeNode.java b/src/main/java/com/supwisdom/dlpay/system/bean/ZTreeNode.java index 9d502731..5ad5fd31 100644 --- a/src/main/java/com/supwisdom/dlpay/system/bean/ZTreeNode.java +++ b/src/main/java/com/supwisdom/dlpay/system/bean/ZTreeNode.java @@ -8,6 +8,8 @@ public class ZTreeNode { private boolean checked; private boolean open; + private Integer shoptype; //商户类别,商户树用到 + public boolean isOpen() { return open; } @@ -47,4 +49,12 @@ public class ZTreeNode { public void setChecked(boolean checked) { this.checked = checked; } + + public Integer getShoptype() { + return shoptype; + } + + public void setShoptype(Integer shoptype) { + this.shoptype = shoptype; + } } diff --git a/src/main/java/com/supwisdom/dlpay/system/controller/ShopController.java b/src/main/java/com/supwisdom/dlpay/system/controller/ShopController.java new file mode 100644 index 00000000..2c8e0882 --- /dev/null +++ b/src/main/java/com/supwisdom/dlpay/system/controller/ShopController.java @@ -0,0 +1,53 @@ +package com.supwisdom.dlpay.system.controller; + +import com.supwisdom.dlpay.api.bean.JsonResult; +import com.supwisdom.dlpay.framework.domain.TShop; +import com.supwisdom.dlpay.system.service.ShopDataService; +import com.supwisdom.dlpay.util.WebCheckException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +public class ShopController { + @Autowired + private ShopDataService shopDataService; + + @GetMapping("/shop/index") + public String shopView() { + return "system/shop/index"; + } + + @GetMapping("/shop/shoptree") + @PreAuthorize("hasPermission('/shop/index','')") + @ResponseBody + public JsonResult shopTreeData(){ + return JsonResult.ok("OK").put("data", shopDataService.getAllShopNodes()); + } + + @PostMapping("/shop/deleteshop") + @PreAuthorize("hasPermission('/shop/deleteshop','')") + @ResponseBody + public JsonResult deleteShop(@RequestParam("shopid") Integer shopid) { + TShop shop = shopDataService.getShopByShopid(shopid); + if(null==shop){ + return JsonResult.error("商户不存在,请重新查询"); //商户不存在,请重新查询 + } + + try{ + if(shopDataService.deleteShop(shop)){ + return JsonResult.ok("删除成功"); + }else{ + return JsonResult.error("删除失败"); + } + }catch (WebCheckException ex){ + return JsonResult.error(ex.getMessage()); + }catch (Exception e){ + return JsonResult.error("系统处理异常").put("exception", e); + } + } +} diff --git a/src/main/java/com/supwisdom/dlpay/system/service/ShopDataService.java b/src/main/java/com/supwisdom/dlpay/system/service/ShopDataService.java new file mode 100644 index 00000000..087bec28 --- /dev/null +++ b/src/main/java/com/supwisdom/dlpay/system/service/ShopDataService.java @@ -0,0 +1,20 @@ +package com.supwisdom.dlpay.system.service; + +import com.supwisdom.dlpay.framework.domain.TShop; +import com.supwisdom.dlpay.system.bean.ZTreeNode; +import com.supwisdom.dlpay.util.WebCheckException; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +public interface ShopDataService { + @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,readOnly = true) + List getAllShopNodes(); + + @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,readOnly = true) + TShop getShopByShopid(Integer shopid); + + @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) + boolean deleteShop(TShop shop) throws WebCheckException; +} diff --git a/src/main/java/com/supwisdom/dlpay/system/service/impl/ShopDataServiceImpl.java b/src/main/java/com/supwisdom/dlpay/system/service/impl/ShopDataServiceImpl.java new file mode 100644 index 00000000..33d227d7 --- /dev/null +++ b/src/main/java/com/supwisdom/dlpay/system/service/impl/ShopDataServiceImpl.java @@ -0,0 +1,73 @@ +package com.supwisdom.dlpay.system.service.impl; + +import com.supwisdom.dlpay.framework.dao.ShopDao; +import com.supwisdom.dlpay.framework.dao.ShopaccDao; +import com.supwisdom.dlpay.framework.domain.TShop; +import com.supwisdom.dlpay.framework.domain.TShopacc; +import com.supwisdom.dlpay.framework.util.StringUtil; +import com.supwisdom.dlpay.framework.util.TradeDict; +import com.supwisdom.dlpay.system.bean.ZTreeNode; +import com.supwisdom.dlpay.system.service.ShopDataService; +import com.supwisdom.dlpay.util.WebCheckException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class ShopDataServiceImpl implements ShopDataService { + @Autowired + private ShopDao shopDao; + @Autowired + private ShopaccDao shopaccDao; + + @Override + public List getAllShopNodes() { + List result = new ArrayList<>(0); + List shoplist = shopDao.findAll(); + if (!StringUtil.isEmpty(shoplist)) { + for (TShop shop : shoplist) { + if (null == shop || !TradeDict.STATUS_NORMAL.equals(shop.getStatus())) continue; //跳过注销商户 + ZTreeNode node = new ZTreeNode(); + node.setId(shop.getShopid().toString()); + node.setName(shop.getShopname()); + node.setpId(shop.getFshopid() == null ? "" : shop.getFshopid().toString()); + node.setChecked(false); + node.setOpen(true); + node.setShoptype(shop.getShoptype()); + result.add(node); + } + } + return result; + } + + @Override + public TShop getShopByShopid(Integer shopid) { + if (null != shopid) { + return shopDao.getTShopByShopid(shopid); + } + return null; + } + + @Override + public boolean deleteShop(TShop shop) throws WebCheckException{ + if(null!=shop){ + List childShops = shopDao.getChildShopsByShopid(shop.getShopid()); + if(!StringUtil.isEmpty(childShops)) + throw new WebCheckException("请先删除下级商户"); + shop.setStatus(TradeDict.STATUS_CLOSED); + shopDao.save(shop); + if(!StringUtil.isEmpty(shop.getShopaccno())){ + TShopacc shopacc=shopaccDao.getByShopaccno(shop.getShopaccno()); + if(null==shopacc) throw new WebCheckException("数据异常!对应的商户账户不存在!"); + shopacc.setStatus(TradeDict.STATUS_CLOSED); + shopaccDao.save(shopacc); + } + return true; + } + return false; + } + + +} diff --git a/src/main/resources/static/libs/zTree/css/zTreeStyle/zTreeStyle.css b/src/main/resources/static/libs/zTree/css/zTreeStyle/zTreeStyle.css index a6845a44..a9e1b52f 100755 --- a/src/main/resources/static/libs/zTree/css/zTreeStyle/zTreeStyle.css +++ b/src/main/resources/static/libs/zTree/css/zTreeStyle/zTreeStyle.css @@ -75,6 +75,8 @@ website: http://code.google.com/p/jquerytree/ .ztree li span.button.ico_docu{margin-right:2px; background-position:-110px -32px; vertical-align:top; *vertical-align:middle} .ztree li span.button.edit {margin-right:2px; background-position:-110px -48px; vertical-align:top; *vertical-align:middle} .ztree li span.button.remove {margin-right:2px; background-position:-110px -64px; vertical-align:top; *vertical-align:middle} +.ztree li span.button.add {margin-right:2px; background-position:-144px 0; vertical-align:top; *vertical-align:middle} + .ztree li span.button.ico_loading{margin-right:2px; background:url(./img/loading.gif) no-repeat scroll 0 0 transparent; vertical-align:top; *vertical-align:middle} diff --git a/src/main/resources/templates/system/shop/index.html b/src/main/resources/templates/system/shop/index.html new file mode 100644 index 00000000..1211547e --- /dev/null +++ b/src/main/resources/templates/system/shop/index.html @@ -0,0 +1,167 @@ +
+
+

商户管理

+ + 商户中心 + 商户管理 + +
+
+
+
+
+
+
    +
    +
    +
    +
    +
    +
    +
    + 搜索: +   + + +
    +
    +
    +
    +
    +
    +
    +
    + + \ No newline at end of file