Bladeren bron

Merge branch 'dev' into dev_spt

sptkw 2 jaren geleden
bovenliggende
commit
e34eeed280

+ 1 - 1
sckw-common/sckw-common-core/src/main/java/com/sckw/core/exception/BusinessException.java

@@ -16,7 +16,7 @@ public class BusinessException extends RuntimeException {
     /**
      * 异常信息
      **/
-    private String msg;
+    private final String msg;
     private Object[] param;
 
     public BusinessException(String msg) {

+ 7 - 4
sckw-common/sckw-common-core/src/main/java/com/sckw/core/exception/CustomPromptException.java

@@ -6,7 +6,7 @@ import java.io.Serial;
 
 /**
  * @Author yzc
- * @Description 自定义提示异常
+ * @Description 前端自定义提示异常
  * @createTime 2023年06月08日 10:05:00
  */
 @Getter
@@ -17,16 +17,19 @@ public class CustomPromptException extends RuntimeException {
     /**
      * 异常信息
      **/
-    private String msg;
+    private final String msg;
+    private final Integer code;
     private Object[] param;
 
-    public CustomPromptException(String msg) {
+    public CustomPromptException(Integer code,String msg) {
         super(msg);
+        this.code = code;
         this.msg = msg;
     }
 
-    public CustomPromptException(String msg, Object... param) {
+    public CustomPromptException(Integer code,String msg, Object... param) {
         super(msg);
+        this.code = code;
         this.msg = msg;
         this.param = param;
     }

+ 3 - 2
sckw-common/sckw-common-core/src/main/java/com/sckw/core/exception/GlobalSystemExceptionHandler.java

@@ -49,14 +49,15 @@ public class GlobalSystemExceptionHandler {
 
     /**
      * 前端自定义提示异常
+     *
      * @param ex
      * @return
      */
     @ResponseBody
     @ExceptionHandler(CustomPromptException.class)
     public HttpResult customPromptExceptionHandler(CustomPromptException ex) {
-        log.info("业务异常,message={},param={}", ex.getMsg(), ex.getParam());
-        return HttpResult.error(HttpStatus.CUSTOM_PROMPT_CODE, ex.getMessage());
+        log.info("前端自定义提示异常,code={},message={},param={}", ex.getCode(), ex.getMsg(), ex.getParam());
+        return HttpResult.error(ex.getCode(), ex.getMessage());
     }
 
 

+ 6 - 2
sckw-common/sckw-common-core/src/main/java/com/sckw/core/web/constant/HttpStatus.java

@@ -24,9 +24,13 @@ public class HttpStatus {
     /**全局异常状态码*/
     public static final int GLOBAL_EXCEPTION_CODE = 60500;
     /**
-     * 自定义提示异常
+     * 完结贸易订单失败异常码
      */
-    public static final int CUSTOM_PROMPT_CODE = 60666;
+    public static final int COMPLETE_TORDER_FAIL_CODE = 60666;
+    /**
+     * 商品上架失败异常码
+     */
+    public static final int GOODS_PUT_ON_SHELVES_FAIL_CODE = 60667;
     /**全局异常提示信息*/
     public static final String GLOBAL_EXCEPTION_MESSAGE = "攻城狮正在拼命优化,请您稍候再试!";
 

+ 1 - 1
sckw-modules/sckw-order/src/main/java/com/sckw/order/serivce/KwoTradeOrderService.java

@@ -787,7 +787,7 @@ public class KwoTradeOrderService {
             throw new BusinessException("无订单操作权限!");
         }
         if (transportDubboService.checkLogisticsOrderByTradeOrderId(param.getId())) {
-            throw new CustomPromptException("订单存在未完成的物流托运,不可完结!");
+            throw new CustomPromptException(HttpStatus.COMPLETE_TORDER_FAIL_CODE, "订单存在未完成的物流托运,不可完结!");
         }
         String lockKey = String.format(RedisConstant.TORDER_UPDATE_AMOUNT_KEY, param.getId());
         if (Boolean.FALSE.equals(RedissonUtils.tryLock(lockKey, 5L, 10L))) {

+ 45 - 36
sckw-modules/sckw-product/src/main/java/com/sckw/product/service/KwpGoodsService.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.sckw.core.common.enums.enums.DictEnum;
 import com.sckw.core.common.enums.enums.DictTypeEnum;
 import com.sckw.core.exception.BusinessException;
+import com.sckw.core.exception.CustomPromptException;
 import com.sckw.core.model.constant.Global;
 import com.sckw.core.model.page.PageResult;
 import com.sckw.core.model.vo.TableBottom;
@@ -16,6 +17,7 @@ import com.sckw.core.utils.BeanUtils;
 import com.sckw.core.utils.CollectionUtils;
 import com.sckw.core.utils.NumberUtils;
 import com.sckw.core.utils.StringUtils;
+import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.excel.utils.DateUtil;
 import com.sckw.payment.api.dubbo.PayCenterDubboService;
@@ -273,7 +275,10 @@ public class KwpGoodsService {
         }
         if (Objects.equals(goods.getStatus(), GoodsStatusEnum.PUT_ON_SHELVES.getCode()) ||
                 Objects.equals(goods.getStatus(), GoodsStatusEnum.TAKE_OFF_SHELVES.getCode())) {
-            judgeParameters(param);
+            String msg = judgeParameters(param);
+            if (StringUtils.isNotBlank(msg)) {
+                throw new BusinessException(msg);
+            }
             if (Objects.equals(goods.getStatus(), GoodsStatusEnum.PUT_ON_SHELVES.getCode()) &&
                     goods.getAmount().compareTo(param.getAmount()) != 0) {
                 throw new BusinessException("上架商品不可修改库存数量!");
@@ -349,103 +354,104 @@ public class KwpGoodsService {
      * @Param param:
      * @return: void
      */
-    private void judgeParameters(UpdateGoodsParam param) {
+    private String judgeParameters(UpdateGoodsParam param) {
         if (StringUtils.isBlank(param.getName())) {
-            throw new BusinessException("商品名称不能为空!");
+            return "商品名称不能为空!";
         }
         if (StringUtils.isBlank(param.getGoodsType())) {
-            throw new BusinessException("商品类型不能为空!");
+            return "商品类型不能为空!";
         }
         if (StringUtils.isBlank(param.getUnit())) {
-            throw new BusinessException("计量单位不能为空!");
+            return "计量单位不能为空!";
         }
         if (StringUtils.isBlank(param.getSpec())) {
-            throw new BusinessException("规格尺寸不能为空!");
+            return "规格尺寸不能为空!";
         }
         if (Objects.isNull(param.getAmount())) {
-            throw new BusinessException("库存数量不能为空!");
+            return "库存数量不能为空!";
         }
         if (StringUtils.isBlank(param.getTaxRate())) {
-            throw new BusinessException("发票税率不能为空!");
+            return "发票税率不能为空!";
         }
         if (Objects.isNull(param.getPrepaidLimit())) {
-            throw new BusinessException("是否设置预付限额不能为空!");
+            return "是否设置预付限额不能为空!";
         }
         if (Objects.equals(param.getPrepaidLimit(), 1) && Objects.isNull(param.getAdvancePrice())) {
-            throw new BusinessException("设置预付限额时,预付款最低限额不能为空!");
+            return "设置预付限额时,预付款最低限额不能为空!";
         }
 
         List<GoodsAttributes> attributes = param.getAttributes();
         if (CollectionUtils.isNotEmpty(attributes)) {
-            attributes.forEach(e -> {
+            for (GoodsAttributes e : attributes) {
                 if (StringUtils.isBlank(e.getName()) || StringUtils.isBlank(e.getVal())) {
-                    throw new BusinessException("参数名称或参数值不能为空且!");
+                    return "参数名称或参数值不能为空!";
                 }
-            });
+            }
         }
         List<GoodsImages> images = param.getImages();
         if (CollectionUtils.isNotEmpty(images)) {
-            images.forEach(e -> {
+            for (GoodsImages e : images) {
                 if (StringUtils.isBlank(e.getImage())) {
-                    throw new BusinessException("商品图片地址不能为空!");
+                    return "商品图片地址不能为空!";
                 }
                 if (Objects.isNull(e.getSort())) {
-                    throw new BusinessException("商品图片排序不能为空!");
+                    return "商品图片排序不能为空!";
                 }
-            });
+            }
         }
         List<GoodsPriceRanges> priceRanges = param.getPriceRanges();
         if (CollectionUtils.isEmpty(priceRanges)) {
-            throw new BusinessException("价格梯度不能为空!");
+            return "价格梯度不能为空!";
         }
-        priceRanges.forEach(e -> {
+        for (GoodsPriceRanges e : priceRanges) {
             if (Objects.isNull(e.getStartAmount()) || e.getStartAmount().compareTo(BigDecimal.ZERO) < 0) {
-                throw new BusinessException("起售量最小为零!");
+                return "起售量不能为空且最小为零!";
             }
             if (Objects.isNull(e.getEndAmount()) || e.getEndAmount().compareTo(new BigDecimal("-1.00")) < 0) {
-                throw new BusinessException("上限售量最小为零!");
+                return "上限售量不能为空且最小为零!";
             }
             if (Objects.isNull(e.getPrice()) || e.getStartAmount().compareTo(BigDecimal.ZERO) < 0) {
-                throw new BusinessException("含税价最低为零!");
+                return "含税价不能为空且最低为零!";
             }
             if (Objects.isNull(e.getSort())) {
-                throw new BusinessException("价格梯度顺序不能为空!");
+                return "价格梯度顺序不能为空!";
             }
-        });
+        }
         AddressInfo address = param.getAddressInfo();
         if (Objects.isNull(address)) {
-            throw new BusinessException("地址信息不能为空!");
+            return "地址信息不能为空!";
         }
         if (StringUtils.isBlank(address.getName()) || address.getName().length() > 50) {
-            throw new BusinessException("地址名称不能为空且最长50字符!");
+            return "地址名称不能为空且最长50字符!";
         }
         if (StringUtils.isBlank(address.getType())) {
-            throw new BusinessException("地址类型不能为空!");
+            return "地址类型不能为空!";
         }
         if (StringUtils.isBlank(address.getContacts())) {
-            throw new BusinessException("联系人不能为空!");
+            return "联系人不能为空!";
         }
         if (StringUtils.isBlank(address.getPhone())) {
-            throw new BusinessException("联系电话不能为空!");
+            return "联系电话不能为空!";
         }
         if (Objects.isNull(address.getCityCode())) {
-            throw new BusinessException("所在地区code不能为空!");
+            return "所在地区code不能为空!";
         }
         if (StringUtils.isBlank(address.getCityName()) || address.getCityName().length() > 40) {
-            throw new BusinessException("所属区域名称不能为空最长40字符!");
+            return "所属区域名称不能为空最长40字符!";
         }
         if (Objects.isNull(address.getLat())) {
-            throw new BusinessException("纬度不能为空!");
+            return "纬度不能为空!";
         }
         if (Objects.isNull(address.getLng())) {
-            throw new BusinessException("经度不能为空!");
+            return "经度不能为空!";
         }
         if (Objects.isNull(param.getSupplyEntId())) {
-            throw new BusinessException("供应企业不能为空!");
+            return "供应企业不能为空!";
         }
         if (Objects.isNull(param.getManager())) {
-            throw new BusinessException("客户经理不能为空!");
+            return "客户经理不能为空!";
         }
+        return null;
     }
 
     /**
@@ -656,7 +662,10 @@ public class KwpGoodsService {
             updateParam.setPriceRanges(BeanUtils.copyToList(kwpGoodsPriceRangeService.getByGoodsId(id), GoodsPriceRanges.class));
             updateParam.setImages(BeanUtils.copyToList(kwpGoodsImageService.getByGoodsId(id), GoodsImages.class));
             updateParam.setAddressInfo(BeanUtils.copyProperties(kwpGoodsAddressService.getByGoodsId(id), AddressInfo.class));
-            judgeParameters(updateParam);
+            String msg = judgeParameters(updateParam);
+            if (StringUtils.isNotBlank(msg)) {
+                throw new CustomPromptException(HttpStatus.GOODS_PUT_ON_SHELVES_FAIL_CODE, msg);
+            }
         }
         LambdaUpdateWrapper<KwpGoods> updateWrapper = new LambdaUpdateWrapper<>();
         updateWrapper.set(KwpGoods::getStatus, GoodsStatusEnum.PUT_ON_SHELVES.getCode()).set(KwpGoods::getAddedTime, new Date()).eq(KwpGoods::getId, id);