|
@@ -0,0 +1,122 @@
|
|
|
|
+package com.emato.biz.service.impl;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.emato.biz.domain.OutRequest;
|
|
|
|
+import com.emato.biz.domain.mall.InventoryDataPushVo;
|
|
|
|
+import com.emato.biz.domain.mall.InventoryDataVo;
|
|
|
|
+import com.emato.biz.domain.mall.InventoryReqVO;
|
|
|
|
+import com.emato.biz.domain.merchant.ThirdMerchantBiz;
|
|
|
|
+import com.emato.biz.exception.Assert;
|
|
|
|
+import com.emato.biz.mapper.mall.InventoryDataMapper;
|
|
|
|
+import com.emato.biz.service.SignService;
|
|
|
|
+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 org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 库存业务接口实现类
|
|
|
|
+ *
|
|
|
|
+ * @author frankeleyn
|
|
|
|
+ * @email lvjian@qhdswl.com
|
|
|
|
+ * @date 2023/3/31 16:00
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class InventoryServiceImpl implements InventoryService {
|
|
|
|
+
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(InventoryServiceImpl.class);
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private SignService signService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IThirdMerchantBizService thirdMerService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private InventoryDataMapper inventoryDataMapper;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询库存数据
|
|
|
|
+ *
|
|
|
|
+ * @param outRequest
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result getInventory(OutRequest outRequest) {
|
|
|
|
+ try {
|
|
|
|
+ log.info("---------- 查询库存数据开始 ----------");
|
|
|
|
+ log.info("========== 电商请求 eccs 报文 =========> {}", outRequest);
|
|
|
|
+ // 验签
|
|
|
|
+ Assert.notTrue(!signService.verifySign(outRequest), "验签失败!");
|
|
|
|
+ // 转为请求类
|
|
|
|
+ InventoryReqVO reqVO = JSON.parseObject(outRequest.getData(), InventoryReqVO.class);
|
|
|
|
+ log.debug("========== 解析后的请求数据 ==========> {}", reqVO);
|
|
|
|
+ // 分页页码
|
|
|
|
+ String pageIndexStr = reqVO.getPageIndex();
|
|
|
|
+ // 分页大小
|
|
|
|
+ String pageSizeStr = reqVO.getPageSize();
|
|
|
|
+
|
|
|
|
+ // 参数校验
|
|
|
|
+ Assert.notNull(pageIndexStr, "分页页码不能为空!");
|
|
|
|
+ Assert.notNull(pageSizeStr, "分页大小不能为空!");
|
|
|
|
+ Assert.notTrue(!isPositiveInteger(pageIndexStr), "分页页码请填入正整数!");
|
|
|
|
+ Assert.notTrue(!isPositiveInteger(pageSizeStr), "分页大小请填入正整数!");
|
|
|
|
+
|
|
|
|
+ // 分页大小
|
|
|
|
+ int pageSize = Integer.parseInt(pageSizeStr);
|
|
|
|
+ // 大于500就取500,否则取 pageSize
|
|
|
|
+ pageSize = Math.min(pageSize, 500);
|
|
|
|
+
|
|
|
|
+ int pageIndex = Integer.parseInt(pageIndexStr);
|
|
|
|
+ // 小于1就取1,否则取 pageIndex
|
|
|
|
+ pageIndex = Math.max(pageIndex, 1);
|
|
|
|
+ pageIndex = (pageIndex - 1) * pageSize;
|
|
|
|
+
|
|
|
|
+ // 查询参数
|
|
|
|
+ List<InventoryDataPushVo> inventoryData = inventoryDataMapper.getInventoryData(pageIndex, pageSize);
|
|
|
|
+
|
|
|
|
+ // 组装返回数据
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
+ resultMap.put("row", inventoryData);
|
|
|
|
+ resultMap.put("invTime", LocalDateTime.now().toString());
|
|
|
|
+
|
|
|
|
+ log.info("---------- 查询库存数据结束 ----------");
|
|
|
|
+ return Result.success(resultMap);
|
|
|
|
+ }catch (CustomException ce){
|
|
|
|
+ // 交给统一异常处理
|
|
|
|
+ throw ce;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("查询库存数据异常 => ", e);
|
|
|
|
+ throw new CustomException("查询库存数据异常,请稍后再试!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 判断是否是正整数
|
|
|
|
+ *
|
|
|
|
+ * @param str
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private static boolean isPositiveInteger(String str) {
|
|
|
|
+ if (str == null || str.isEmpty()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // 正则表达式: ^ 表示开头,\\d+ 表示一位或多位数字,$ 表示结尾
|
|
|
|
+ // 如果要包含0,则将 + 改为 *
|
|
|
|
+ return str.matches("^\\d+$");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|