pengcheng 1 місяць тому
батько
коміт
ef747bb674

+ 21 - 5
ruoyi-admin/src/main/java/com/ruoyi/web/controller/clock/ShopController.java

@@ -1,6 +1,8 @@
 package com.ruoyi.web.controller.clock;
 
 import cn.dev33.satoken.annotation.SaCheckPermission;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjectUtil;
 import com.ruoyi.clock.domain.bo.ShopBo;
 import com.ruoyi.clock.domain.vo.ShopVo;
 import com.ruoyi.clock.service.IShopService;
@@ -50,7 +52,13 @@ public class ShopController extends BaseController {
     @SaCheckPermission("clock:shop:list")
     @GetMapping("/page")
     public TableDataInfo<ShopVo> page(@Validated(QueryGroup.class) ShopBo bo, PageQuery pageQuery) {
-        return iShopService.queryPageList(bo, pageQuery);
+        TableDataInfo<ShopVo> shopVoTableDataInfo = iShopService.queryPageList(bo, pageQuery);
+        if (CollUtil.isNotEmpty(shopVoTableDataInfo.getRows())){
+            shopVoTableDataInfo.getRows().forEach(item -> {
+                item.loadAgentVo();
+            });
+        }
+        return shopVoTableDataInfo;
     }
 
     /**
@@ -59,10 +67,13 @@ public class ShopController extends BaseController {
     @ApiOperation("获取门店信息详细信息")
     @SaCheckPermission("clock:shop:query")
     @GetMapping("/info/{shopId}")
-    public R<ShopVo> getInfo(@ApiParam("主键")
-                                                  @NotNull(message = "主键不能为空")
-                                                  @PathVariable("shopId") Long shopId) {
-        return R.ok(iShopService.queryById(shopId));
+    public R<ShopVo> getInfo(@ApiParam("主键")  @NotNull(message = "主键不能为空")
+                              @PathVariable("shopId") Long shopId) {
+        ShopVo shopVo = iShopService.queryById(shopId);
+        if(ObjectUtil.isNotNull(shopVo)){
+            shopVo.loadAgentVo();
+        }
+        return R.ok(shopVo);
     }
 
     /**
@@ -111,6 +122,11 @@ public class ShopController extends BaseController {
     @PostMapping("/export")
     public void export(@Validated ShopBo bo, HttpServletResponse response) {
         List<ShopVo> list = iShopService.queryList(bo);
+        if (CollUtil.isNotEmpty(list)){
+            list.forEach(item -> {
+                item.loadAgentVo();
+            });
+        }
         ExcelUtil.exportExcel(list, "门店信息", ShopVo.class, response);
     }
 

+ 20 - 2
ruoyi-system/src/main/java/com/ruoyi/clock/domain/vo/ShopVo.java

@@ -1,9 +1,13 @@
 package com.ruoyi.clock.domain.vo;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
 import com.alibaba.excel.annotation.ExcelProperty;
+import com.ruoyi.clock.service.IAgentService;
 import com.ruoyi.common.annotation.ExcelDictFormat;
 import com.ruoyi.common.convert.ExcelDictConvert;
+import com.ruoyi.common.core.domain.entity.SysDept;
+import com.ruoyi.common.utils.spring.SpringUtils;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -26,14 +30,12 @@ public class ShopVo {
     /**
      * 店铺id
      */
-    @ExcelProperty(value = "店铺id")
     @ApiModelProperty("店铺id")
     private Long shopId;
 
     /**
      * 代理商id
      */
-    @ExcelProperty(value = "代理商id")
     @ApiModelProperty("代理商id")
     private Long agentId;
 
@@ -44,6 +46,10 @@ public class ShopVo {
     @ApiModelProperty("店铺名称")
     private String shopName;
 
+    @ApiModelProperty("所属代理商")
+    @ExcelProperty(value = "所属代理商")
+    private String agentName;
+
     /**
      * 地址
      */
@@ -65,5 +71,17 @@ public class ShopVo {
     @ApiModelProperty("联系电话")
     private String phonenumber;
 
+    @ApiModelProperty("代理商信息")
+    private AgentVo agent;
 
+    public AgentVo loadAgentVo(){
+        if (ObjectUtil.isNotNull(this.agentId)){
+            IAgentService agentService = SpringUtils.getBean("agentServiceImpl", IAgentService.class);
+            this.agent = agentService.queryById(this.agentId);
+            if (ObjectUtil.isNotNull(this.agent)){
+                this.agentName = agent.getAgentName();
+            }
+        }
+        return this.agent;
+    }
 }

+ 2 - 1
ruoyi-system/src/main/java/com/ruoyi/clock/exception/ShopExceptionEnum.java

@@ -10,7 +10,8 @@ import java.util.Objects;
 public enum ShopExceptionEnum implements IIntegerEnum {
 
     // TODO 注意检查错误码,保证系统内唯一
-    Shop_IS_NOT_EXISTS(200001, "门店信息不存在"),
+    SHOP_IS_NOT_EXISTS(200001, "门店信息不存在"),
+    SHOP_REPEAT(200002, "门店已经存在"),
 
     ;
 

+ 1 - 0
ruoyi-system/src/main/java/com/ruoyi/clock/service/impl/AgentServiceImpl.java

@@ -69,6 +69,7 @@ public class AgentServiceImpl implements IAgentService {
         lqw.eq(StringUtils.isNotBlank(bo.getAddress()), Agent::getAddress, bo.getAddress());
         lqw.like(StringUtils.isNotBlank(bo.getContact()), Agent::getContact, bo.getContact());
         lqw.like(StringUtils.isNotBlank(bo.getPhonenumber()), Agent::getPhonenumber, bo.getPhonenumber());
+        lqw.orderByDesc(Agent::getUpdateTime);
         return lqw;
     }
 

+ 18 - 6
ruoyi-system/src/main/java/com/ruoyi/clock/service/impl/ShopServiceImpl.java

@@ -2,6 +2,8 @@ package com.ruoyi.clock.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
+import com.ruoyi.clock.domain.Agent;
+import com.ruoyi.clock.exception.AgentExceptionEnum;
 import com.ruoyi.clock.exception.ShopExceptionEnum;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.BeanCopyUtils;
@@ -66,7 +68,7 @@ public class ShopServiceImpl implements IShopService {
         lqw.eq(bo.getAgentId() != null, Shop::getAgentId, bo.getAgentId());
         lqw.like(StringUtils.isNotBlank(bo.getShopName()), Shop::getShopName, bo.getShopName());
         lqw.eq(StringUtils.isNotBlank(bo.getAddress()), Shop::getAddress, bo.getAddress());
-        lqw.eq(StringUtils.isNotBlank(bo.getContact()), Shop::getContact, bo.getContact());
+        lqw.like(StringUtils.isNotBlank(bo.getContact()), Shop::getContact, bo.getContact());
         lqw.eq(StringUtils.isNotBlank(bo.getPhonenumber()), Shop::getPhonenumber, bo.getPhonenumber());
         return lqw;
     }
@@ -92,7 +94,7 @@ public class ShopServiceImpl implements IShopService {
     public Shop loadById(Long shopId, Boolean tw){
         Shop info = this.baseMapper.selectById(shopId);
         if(ObjectUtil.isEmpty(info) && tw){
-            throw new ServiceException(ShopExceptionEnum.Shop_IS_NOT_EXISTS);
+            throw new ServiceException(ShopExceptionEnum.SHOP_IS_NOT_EXISTS);
         }
         return info;
     }
@@ -105,8 +107,8 @@ public class ShopServiceImpl implements IShopService {
      */
     @Override
     public Boolean insertByBo(ShopBo bo) {
+        validEntityBeforeSave(bo);
         Shop add = BeanUtil.toBean(bo, Shop.class);
-        validEntityBeforeSave(add);
         boolean flag = baseMapper.insert(add) > 0;
         if (flag) {
             bo.setShopId(add.getShopId());
@@ -122,21 +124,31 @@ public class ShopServiceImpl implements IShopService {
      */
     @Override
     public Boolean updateByBo(ShopBo bo) {
+        validEntityBeforeSave(bo);
         Shop shop = baseMapper.selectById(bo.getShopId());
         Shop update = BeanCopyUtils.copy(bo, shop);
-        validEntityBeforeSave(update);
         return baseMapper.updateById(update) > 0;
     }
 
     /**
      * 保存前的数据校验
      *
-     * @param entity 实体类数据
+     * @param bo 实体类数据
      */
-    private void validEntityBeforeSave(Shop entity){
+    private void validEntityBeforeSave(ShopBo bo){
         //TODO 做一些数据校验,如唯一约束
+        Shop shop = getShopByName(bo.getShopName());
+        if(ObjectUtil.isNotNull(shop)&& !shop.getShopId().equals(bo.getShopId())){
+            throw new ServiceException(ShopExceptionEnum.SHOP_REPEAT);
+        }
+    }
+
+    public Shop getShopByName(String shopName) {
+        return baseMapper.selectOne(new LambdaQueryWrapper<Shop>().eq(Shop::getShopName,shopName)
+            .last("limit 1"));
     }
 
+
     /**
      * 批量删除门店信息
      *