1
0
Quellcode durchsuchen

Merge branch 'feature/eccs-upgrade' of lvjian/eccs into feature/eccs-upgrade

吕健 vor 2 Jahren
Ursprung
Commit
ddcff9ba6a

+ 3 - 1
eccs-biz/src/main/java/com/emato/biz/controller/mall/InventoryDataController.java

@@ -52,11 +52,13 @@ public class InventoryDataController {
     }
 
     /**
-     * 商户外部系统查询其所要同步的库存数据
+     * 商户外部系统查询其所要同步的库存数据(已弃用)
+     *
      * @param msg
      * @param httpRequest
      * @return
      */
+    @Deprecated
     @AnonymousAccess
     @PostMapping("/getinvdata")
     public Result getpushinventMsg(@RequestBody JSONObject msg, HttpServletRequest httpRequest)

+ 22 - 0
eccs-biz/src/main/java/com/emato/biz/domain/mall/InventoryDataPushVo.java

@@ -7,6 +7,12 @@ public class InventoryDataPushVo implements Serializable {
     //条形码
     private String barcode;
 
+    // plu (CW 需要)
+    private String plu;
+
+    // mychemId (CW 需要)
+    private String mychemId;
+
     //产品名称
     private String productName;
 
@@ -27,6 +33,22 @@ public class InventoryDataPushVo implements Serializable {
         this.barcode = barcode;
     }
 
+    public String getPlu() {
+        return plu;
+    }
+
+    public void setPlu(String plu) {
+        this.plu = plu;
+    }
+
+    public String getMychemId() {
+        return mychemId;
+    }
+
+    public void setMychemId(String mychemId) {
+        this.mychemId = mychemId;
+    }
+
     public String getProductName() {
         return productName;
     }

+ 20 - 19
eccs-biz/src/main/java/com/emato/biz/exception/Assert.java

@@ -2,8 +2,9 @@ package com.emato.biz.exception;
 
 
 
-import com.emato.common.exception.CustomException;
+import com.emato.common.exception.ServiceException;
 import com.emato.common.utils.StringUtils;
+import com.emato.common.utils.oms.response.ResultCodeEnum;
 
 import java.util.Objects;
 
@@ -21,9 +22,9 @@ public abstract class Assert {
      * 如果对象obj为空,则抛出异常
      * @param obj 待判断对象
      */
-    public static void notNull(Object obj, String msg) {
+    public static void notNull(Object obj, ResultCodeEnum resultCode) {
         if (Objects.isNull(obj)) {
-            throw new CustomException(msg);
+            throw new ServiceException(resultCode.getMsg(), resultCode.getCode());
         }
     }
 
@@ -32,11 +33,11 @@ public abstract class Assert {
      * 断言对象为空
      * 如果对象obj不为空,则抛出异常
      * @param object
-     * @param msg
+     * @param resultCode
      */
-    public static void isNull(Object object, String msg) {
+    public static void isNull(Object object, ResultCodeEnum resultCode) {
         if (Objects.nonNull(object)) {
-            throw new CustomException(msg);
+            throw new ServiceException(resultCode.getMsg(), resultCode.getCode());
         }
     }
 
@@ -46,9 +47,9 @@ public abstract class Assert {
      *
      * @param expression 是否成功
      */
-    public static void isTrue(boolean expression, String msg) {
+    public static void isTrue(boolean expression, ResultCodeEnum resultCode) {
         if (!expression) {
-            throw new CustomException(msg);
+            throw new ServiceException(resultCode.getMsg(), resultCode.getCode());
         }
     }
 
@@ -58,9 +59,9 @@ public abstract class Assert {
      *
      * @param expression 是否成功
      */
-    public static void notTrue(boolean expression, String msg) {
+    public static void notTrue(boolean expression, ResultCodeEnum resultCode) {
         if (expression) {
-            throw new CustomException(msg);
+            throw new ServiceException(resultCode.getMsg(), resultCode.getCode());
         }
     }
 
@@ -69,11 +70,11 @@ public abstract class Assert {
      * 如果相等,则抛出异常
      * @param m1
      * @param m2
-     * @param msg
+     * @param resultCode
      */
-    public static void notEquals(Object m1, Object m2,  String msg) {
+    public static void notEquals(Object m1, Object m2,  ResultCodeEnum resultCode) {
         if (m1.equals(m2)) {
-            throw new CustomException(msg);
+            throw new ServiceException(resultCode.getMsg(), resultCode.getCode());
         }
     }
 
@@ -82,11 +83,11 @@ public abstract class Assert {
      * 如果不相等,则抛出异常
      * @param m1
      * @param m2
-     * @param msg
+     * @param resultCode
      */
-    public static void equals(Object m1, Object m2,  String msg) {
+    public static void equals(Object m1, Object m2,  ResultCodeEnum resultCode) {
         if (!m1.equals(m2)) {
-            throw new CustomException(msg);
+            throw new ServiceException(resultCode.getMsg(), resultCode.getCode());
         }
     }
 
@@ -94,11 +95,11 @@ public abstract class Assert {
      * 断言参数不为空
      * 如果为空,则抛出异常
      * @param s
-     * @param msg
+     * @param resultCode
      */
-    public static void notEmpty(String s, String msg) {
+    public static void notEmpty(String s, ResultCodeEnum resultCode) {
         if (StringUtils.isBlank(s)) {
-            throw new CustomException(msg);
+            throw new ServiceException(resultCode.getMsg(), resultCode.getCode());
         }
     }
 }

+ 15 - 4
eccs-biz/src/main/java/com/emato/biz/mapper/mall/InventoryDataMapper.java

@@ -2,16 +2,27 @@ package com.emato.biz.mapper.mall;
 
 import com.emato.biz.domain.mall.InventoryDataPushVo;
 import com.emato.biz.domain.mall.InventoryDataVo;
-import com.emato.biz.domain.mall.InventoryReqVO;
 
 import java.util.List;
-import java.util.Map;
 
 public interface InventoryDataMapper {
     void inserInventory(InventoryDataVo inventoryDataVo);
 
-
-    List<InventoryDataPushVo> getInventoryData(int pageIndex, int pageSize);
+    /**
+     * 查询库存数据
+     *
+     * @param pageIndex
+     * @param pageSize
+     * @return
+     */
+    List<InventoryDataPushVo> selectInventoryData(int pageIndex, int pageSize);
+
+    /**
+     * 查询库存数据总条数
+     *
+     * @return
+     */
+    int selectInventoryTotal();
 
     Integer queryOneInventory(InventoryDataVo inventoryDataVo);
 

+ 19 - 14
eccs-biz/src/main/java/com/emato/biz/service/impl/InventoryServiceImpl.java

@@ -13,6 +13,8 @@ import com.emato.biz.service.mall.InventoryService;
 import com.emato.biz.service.merchant.IThirdMerchantBizService;
 import com.emato.common.core.Result;
 import com.emato.common.exception.CustomException;
+import com.emato.common.exception.ServiceException;
+import com.emato.common.utils.oms.response.ResultCodeEnum;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -20,6 +22,7 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -40,9 +43,6 @@ public class InventoryServiceImpl implements InventoryService {
     @Autowired
     private SignService signService;
 
-    @Autowired
-    private IThirdMerchantBizService thirdMerService;
-
     @Resource
     private InventoryDataMapper inventoryDataMapper;
 
@@ -58,7 +58,7 @@ public class InventoryServiceImpl implements InventoryService {
             log.info("---------- 查询库存数据开始 ----------");
             log.info("========== 电商请求 eccs 报文 =========> {}", outRequest);
             // 验签
-            Assert.notTrue(!signService.verifySign(outRequest), "验签失败!");
+            Assert.notTrue(!signService.verifySign(outRequest), ResultCodeEnum.SIGN_ERROR);
             // 转为请求类
             InventoryReqVO reqVO = JSON.parseObject(outRequest.getData(), InventoryReqVO.class);
             log.debug("========== 解析后的请求数据 ==========> {}", reqVO);
@@ -68,10 +68,10 @@ public class InventoryServiceImpl implements InventoryService {
             String pageSizeStr = reqVO.getPageSize();
 
             // 参数校验
-            Assert.notNull(pageIndexStr, "分页页码不能为空!");
-            Assert.notNull(pageSizeStr, "分页大小不能为空!");
-            Assert.notTrue(!isPositiveInteger(pageIndexStr), "分页页码请填入正整数!");
-            Assert.notTrue(!isPositiveInteger(pageSizeStr), "分页大小请填入正整数!");
+            Assert.notNull(pageIndexStr, ResultCodeEnum.PARAM_ERROR_PAGE_INDEX_NOT_NULL);
+            Assert.notNull(pageSizeStr, ResultCodeEnum.PARAM_ERROR_PAGE_SIZE_NOT_NULL);
+            Assert.notTrue(!isPositiveInteger(pageIndexStr), ResultCodeEnum.PARAM_ERROR_PAGE_INDEX_NOT_POS_INT);
+            Assert.notTrue(!isPositiveInteger(pageSizeStr), ResultCodeEnum.PARAM_ERROR_PAGE_SIZE_NOT_POS_INT);
 
             // 分页大小
             int pageSize = Integer.parseInt(pageSizeStr);
@@ -83,19 +83,24 @@ public class InventoryServiceImpl implements InventoryService {
             pageIndex = Math.max(pageIndex, 1);
             pageIndex = (pageIndex - 1) * pageSize;
 
-            // 查询参数
-            List<InventoryDataPushVo> inventoryData = inventoryDataMapper.getInventoryData(pageIndex, pageSize);
+            // 查询库存数据
+            List<InventoryDataPushVo> inventoryData = inventoryDataMapper.selectInventoryData(pageIndex, pageSize);
+            // 查询库存记录总数
+            int inventoryTotal = inventoryDataMapper.selectInventoryTotal();
 
             // 组装返回数据
             Map<String, Object> resultMap = new HashMap<>();
-            resultMap.put("row", inventoryData);
-            resultMap.put("invTime", LocalDateTime.now().toString());
+            resultMap.put("rows", inventoryData);
+            resultMap.put("total", inventoryTotal);
+
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+            resultMap.put("invTime", LocalDateTime.now().format(formatter));
 
             log.info("---------- 查询库存数据结束 ----------");
             return Result.success(resultMap);
-        }catch (CustomException ce){
+        }catch (ServiceException se){
             // 交给统一异常处理
-            throw ce;
+            throw se;
         } catch (Exception e) {
             log.error("查询库存数据异常 => ", e);
             throw new CustomException("查询库存数据异常,请稍后再试!");

+ 7 - 6
eccs-biz/src/main/java/com/emato/biz/service/impl/SignServiceImpl.java

@@ -6,6 +6,7 @@ import com.emato.biz.exception.Assert;
 import com.emato.biz.service.SignService;
 import com.emato.biz.service.merchant.IMerchantSecretService;
 import com.emato.common.utils.oms.request.OmsSign;
+import com.emato.common.utils.oms.response.ResultCodeEnum;
 import com.google.common.collect.Maps;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -57,7 +58,7 @@ public class SignServiceImpl implements SignService {
         MerchantSecret merchantSecret = new MerchantSecret();
         merchantSecret.setMerchSn(merchId);
         List<MerchantSecret> merchantSecrets = merchantSecretService.selectMerchantSecretList(merchantSecret);
-        Assert.notTrue(merchantSecrets.isEmpty(), "商户密钥不存在!");
+        Assert.notTrue(merchantSecrets.isEmpty(), ResultCodeEnum.MERCHANT_KEY_NOT_EXIST);
         String md5Salt = merchantSecrets.get(0).getMd5Salt();
         // 封装校验信息
         Map params = Maps.newLinkedHashMap();
@@ -82,7 +83,7 @@ public class SignServiceImpl implements SignService {
         Instant now = Instant.now();
         Duration duration = Duration.between(target, now);
         boolean b = duration.toMinutes() > 5L;
-        Assert.notTrue(b, "时间戳超时!");
+        Assert.notTrue(b, ResultCodeEnum.TIME_STAMP_TIMEOUT);
     }
 
     /**
@@ -94,9 +95,9 @@ public class SignServiceImpl implements SignService {
      * @param data
      */
     private void emptyCheck(String merchId, String sign, String timestamp, Object data) {
-        Assert.notEmpty(merchId, "商户号不能为空!");
-        Assert.notEmpty(sign, "接口签名不能为空!");
-        Assert.notEmpty(timestamp, "时间戳不能为空!");
-        Assert.notNull(data, "业务请求数据不能为空!");
+        Assert.notEmpty(merchId, ResultCodeEnum.MERCHANT_ID_NOT_NULL);
+        Assert.notEmpty(sign, ResultCodeEnum.SIGN_NOT_NULL);
+        Assert.notEmpty(timestamp, ResultCodeEnum.TIME_STAMP_NOT_NULL);
+        Assert.notNull(data, ResultCodeEnum.DATA_NOT_NULL);
     }
 }

+ 19 - 4
eccs-biz/src/main/resources/mapper/biz/mall/InventoryDataMapper.xml

@@ -6,17 +6,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <resultMap id="inventoryDataVO" type="com.emato.biz.domain.mall.InventoryDataPushVo">
         <result column="prod_barcode" property="barcode" />
+        <result column="plu" property="plu" />
+        <result column="mychem_id" property="mychemId" />
         <result column="name" property="productName"/>
         <result column="shop_sn" property="shopSn" />
         <result column="shop_inve" property="shopInvent" />
         <result column="valid_num" property="eMatou" />
     </resultMap>
 
-
-    <!--    外部接口查询-->
-    <select id="getInventoryData"  parameterType="com.emato.biz.domain.mall.InventoryReqVO" resultMap="inventoryDataVO">
+    <!-- 查询库存数据 -->
+    <select id="selectInventoryData"  parameterType="com.emato.biz.domain.mall.InventoryReqVO" resultMap="inventoryDataVO">
         SELECT
-            t.sku,
             t.prod_barcode,
             t.plu,
             t.mychem_id,
@@ -38,6 +38,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </if>
     </select>
 
+    <!-- 查询库存数据总条数 -->
+    <select id="selectInventoryTotal" resultType="int">
+        SELECT
+            COUNT(1)
+        FROM
+            mall_goods t
+            LEFT JOIN wb_merch_shop_inve t1 ON t.sku = t1.sku
+            LEFT JOIN wb_inve_mng t2 ON t2.sku = t.sku
+        <where>
+            t1.is_valid = 0
+            AND t2.inve_status = 0
+            AND t2.is_valid = 0
+        </where>
+    </select>
+
     <select id="getInventoryTotal" resultType="java.lang.Integer">
         SELECT
         count(*)

+ 45 - 0
eccs-common/src/main/java/com/emato/common/exception/ServiceException.java

@@ -0,0 +1,45 @@
+package com.emato.common.exception;
+
+/**
+ * 自定义业务异常
+ *
+ * @author frankeleyn
+ * @email lvjian@qhdswl.com
+ * @date 2023/4/3 14:50
+ */
+public class ServiceException extends RuntimeException
+{
+    private static final long serialVersionUID = 1L;
+
+    private String code;
+
+    private String message;
+
+    public ServiceException(String message)
+    {
+        this.message = message;
+    }
+
+    public ServiceException(String message, String code)
+    {
+        this.message = message;
+        this.code = code;
+    }
+
+    public ServiceException(String message, Throwable e)
+    {
+        super(message, e);
+        this.message = message;
+    }
+
+    @Override
+    public String getMessage()
+    {
+        return message;
+    }
+
+    public String getCode()
+    {
+        return code;
+    }
+}

+ 17 - 1
eccs-common/src/main/java/com/emato/common/utils/oms/response/ResultCodeEnum.java

@@ -6,7 +6,23 @@ public enum ResultCodeEnum {
 	/** 失败 */
 	FAILURE("1", "system.ex.msg.prefix"),
 	/** 未登录/登录超时 */
-	SESSION_TIMEOUT("2", "system.session.timeout");
+	SESSION_TIMEOUT("2", "system.session.timeout"),
+
+	PARAM_ERROR_PAGE_INDEX_NOT_NULL("900001", "分页页码不能为空!"),
+	PARAM_ERROR_PAGE_SIZE_NOT_NULL("900001", "分页大小不能为空!"),
+	PARAM_ERROR_PAGE_INDEX_NOT_POS_INT("900001", "分页页码请填入正整数!"),
+	PARAM_ERROR_PAGE_SIZE_NOT_POS_INT("900001", "分页大小请填入正整数!"),
+
+	MERCHANT_ID_NOT_NULL("900002", "商户号不能为空!"),
+	SIGN_NOT_NULL("900002", "接口签名不能为空!"),
+	TIME_STAMP_NOT_NULL("900002", "时间戳不能为空!"),
+	DATA_NOT_NULL("900002", "业务数据不能为空!"),
+
+	TIME_STAMP_TIMEOUT("900002", "时间戳超时!"),
+	MERCHANT_KEY_NOT_EXIST("900002", "商户密钥不存在!"),
+
+	SIGN_ERROR("900002", "验签失败!"),
+	;
 
 	/** 状态码 */
 	private String code;

+ 15 - 0
eccs-framework/src/main/java/com/emato/framework/web/exception/GlobalExceptionHandler.java

@@ -1,5 +1,8 @@
 package com.emato.framework.web.exception;
 
+import com.emato.common.core.Result;
+import com.emato.common.exception.ServiceException;
+import com.emato.common.utils.oms.response.ResultCodeEnum;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.security.access.AccessDeniedException;
@@ -39,6 +42,18 @@ public class GlobalExceptionHandler
     /**
      * 业务异常
      */
+    @ExceptionHandler(ServiceException.class)
+    public Result serviceExp(ServiceException se)
+    {
+        if (StringUtils.isNull(se.getCode()))
+            return Result.error(ResultCodeEnum.PARAM_ERROR_PAGE_SIZE_NOT_NULL.getCode(), se.getMessage());
+        else
+            return Result.error(se.getCode(), se.getMessage());
+    }
+
+    /**
+     * 业务异常
+     */
     @ExceptionHandler(CustomException.class)
     public AjaxResult businessException(CustomException e)
     {