Procházet zdrojové kódy

修改获取销售数据接口,记录商户请求日志

lvjian před 2 roky
rodič
revize
63b5e3c51a

+ 1 - 1
eccs-admin/src/main/resources/mybatis/mybatis-config.xml

@@ -9,7 +9,7 @@ PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
 		<setting name="useGeneratedKeys"         value="true" />  <!-- 允许 JDBC 支持自动生成主键 -->
 		<setting name="defaultExecutorType"      value="REUSE" /> <!-- 配置默认的执行器 -->
 		<setting name="logImpl"                  value="SLF4J" /> <!-- 指定 MyBatis 所用日志的具体实现 -->
-		<!-- <setting name="mapUnderscoreToCamelCase" value="true"/>  驼峰式命名 -->
+		 <setting name="mapUnderscoreToCamelCase" value="true"/>  <!--驼峰式命名-->
 	</settings>
 	
 </configuration>

+ 13 - 0
eccs-biz/src/main/java/com/emato/biz/controller/mall/SalesDetailController.java

@@ -2,6 +2,7 @@ package com.emato.biz.controller.mall;
 
 
 import com.alibaba.fastjson.JSONObject;
+import com.emato.biz.domain.OutRequest;
 import com.emato.biz.domain.mall.NewSystemFormatEntiy;
 import com.emato.biz.service.mall.ISalesDetaiServicel;
 import com.emato.common.annotation.AnonymousAccess;
@@ -60,5 +61,17 @@ public class SalesDetailController {
         return salesDetaiServicel.getSalesDetaiData(msg,httpRequest);
     }
 
+    /**
+     * 商户外部系统查询其所要同步的订单销售数据
+     * @param outRequest
+     * @return
+     */
+    @AnonymousAccess
+    @PostMapping("/salesdetail/getSalesData")
+    public Result getSalesData(@RequestBody OutRequest outRequest)
+    {
+        return salesDetaiServicel.getSalesDetailData(outRequest);
+    }
+
 
 }

+ 31 - 0
eccs-biz/src/main/java/com/emato/biz/domain/OperateLogDTO.java

@@ -0,0 +1,31 @@
+package com.emato.biz.domain;
+
+/**
+ * 记录操作日志
+ *
+ * @author frankeleyn
+ * @email lvjian@qhdswl.com
+ * @date 2023/4/10 18:13
+ */
+public class OperateLogDTO {
+
+    private String reqData;
+
+    private String merchSn;
+
+    public String getReqData() {
+        return reqData;
+    }
+
+    public void setReqData(String reqData) {
+        this.reqData = reqData;
+    }
+
+    public String getMerchSn() {
+        return merchSn;
+    }
+
+    public void setMerchSn(String merchSn) {
+        this.merchSn = merchSn;
+    }
+}

+ 34 - 6
eccs-biz/src/main/java/com/emato/biz/domain/mall/SalesDataReqVO.java

@@ -14,7 +14,7 @@ public class SalesDataReqVO {
     /**
      * 订单编号
      */
-    private String orderSn;
+    private String orderNo;
 
     /**
      * 订单状态
@@ -41,24 +41,36 @@ public class SalesDataReqVO {
      */
     private String pageSize;
 
+    /**
+     * 查询偏移量
+     */
+    private int offset;
+
+    /**
+     * 查询条数
+     */
+    private int limit;
+
     @Override
     public String toString() {
         return "SalesDataReqVO{" +
-                "orderSn='" + orderSn + '\'' +
+                "orderNo='" + orderNo + '\'' +
                 ", orderStatus='" + orderStatus + '\'' +
                 ", starTime='" + starTime + '\'' +
                 ", endTime='" + endTime + '\'' +
                 ", pageIndex='" + pageIndex + '\'' +
                 ", pageSize='" + pageSize + '\'' +
+                ", offset=" + offset +
+                ", limit=" + limit +
                 '}';
     }
 
-    public String getOrderSn() {
-        return orderSn;
+    public String getOrderNo() {
+        return orderNo;
     }
 
-    public void setOrderSn(String orderSn) {
-        this.orderSn = orderSn;
+    public void setOrderNo(String orderNo) {
+        this.orderNo = orderNo;
     }
 
     public String getOrderStatus() {
@@ -100,4 +112,20 @@ public class SalesDataReqVO {
     public void setPageSize(String pageSize) {
         this.pageSize = pageSize;
     }
+
+    public int getOffset() {
+        return offset;
+    }
+
+    public void setOffset(int offset) {
+        this.offset = offset;
+    }
+
+    public int getLimit() {
+        return limit;
+    }
+
+    public void setLimit(int limit) {
+        this.limit = limit;
+    }
 }

+ 275 - 0
eccs-biz/src/main/java/com/emato/biz/domain/mall/SalesDataResVO.java

@@ -0,0 +1,275 @@
+package com.emato.biz.domain.mall;
+
+import java.util.Date;
+
+/**
+ * 响应销售数据
+ *
+ * @author frankeleyn
+ * @email lvjian@qhdswl.com
+ * @date 2023/4/10 17:24
+ */
+public class SalesDataResVO {
+
+    private String storeName;//门店名称
+    private String storeNameSn;//门店名称
+    private String receiptNo;// 销售单号
+    private String cashRegisterNo;// 收银台
+    private String timeStampDetails;// 销售时间
+    private String staffID;// 收银员
+    private String staffName;// 收银员姓名
+    private String hsCodeName;// 品类名称
+    private String ematouCode;// 商品编码
+    private String plu;// PLU
+    private String mychemID;// MychemID
+    private String productNameEN;// 商品名称(英文)
+    private String productNameCN;// 商品名称(中文)
+    private String barcode;// 商品主条码
+    private String packSize;// 规格
+    private String productSpecification;// 单位
+    private String brand;// 品牌
+    private String edlp;// 日常价
+    private String currentPrice;// 实际销售价
+    private String costPrice;// 进货价
+    private String supplierName;// 主供应商名称
+    private String transactionType;// 销售类型
+    private String saleReturnType;// 退货类型
+    private String remark;// 备注
+    private String orderStatus;//订单状态
+    private String taxPrice; // 税费
+    private String payFlag;//支付方式
+    private String orderSnWx;//微信流水号
+    private String orderSnAli;//支付宝流水号
+
+    public String getStoreName() {
+        return storeName;
+    }
+
+    public void setStoreName(String storeName) {
+        this.storeName = storeName;
+    }
+
+    public String getStoreNameSn() {
+        return storeNameSn;
+    }
+
+    public void setStoreNameSn(String storeNameSn) {
+        this.storeNameSn = storeNameSn;
+    }
+
+    public String getReceiptNo() {
+        return receiptNo;
+    }
+
+    public void setReceiptNo(String receiptNo) {
+        this.receiptNo = receiptNo;
+    }
+
+    public String getCashRegisterNo() {
+        return cashRegisterNo;
+    }
+
+    public void setCashRegisterNo(String cashRegisterNo) {
+        this.cashRegisterNo = cashRegisterNo;
+    }
+
+    public String getTimeStampDetails() {
+        return timeStampDetails;
+    }
+
+    public void setTimeStampDetails(String timeStampDetails) {
+        this.timeStampDetails = timeStampDetails;
+    }
+
+    public String getStaffID() {
+        return staffID;
+    }
+
+    public void setStaffID(String staffID) {
+        this.staffID = staffID;
+    }
+
+    public String getStaffName() {
+        return staffName;
+    }
+
+    public void setStaffName(String staffName) {
+        this.staffName = staffName;
+    }
+
+    public String getHsCodeName() {
+        return hsCodeName;
+    }
+
+    public void setHsCodeName(String hsCodeName) {
+        this.hsCodeName = hsCodeName;
+    }
+
+    public String getEmatouCode() {
+        return ematouCode;
+    }
+
+    public void setEmatouCode(String ematouCode) {
+        this.ematouCode = ematouCode;
+    }
+
+    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 getProductNameEN() {
+        return productNameEN;
+    }
+
+    public void setProductNameEN(String productNameEN) {
+        this.productNameEN = productNameEN;
+    }
+
+    public String getProductNameCN() {
+        return productNameCN;
+    }
+
+    public void setProductNameCN(String productNameCN) {
+        this.productNameCN = productNameCN;
+    }
+
+    public String getBarcode() {
+        return barcode;
+    }
+
+    public void setBarcode(String barcode) {
+        this.barcode = barcode;
+    }
+
+    public String getPackSize() {
+        return packSize;
+    }
+
+    public void setPackSize(String packSize) {
+        this.packSize = packSize;
+    }
+
+    public String getProductSpecification() {
+        return productSpecification;
+    }
+
+    public void setProductSpecification(String productSpecification) {
+        this.productSpecification = productSpecification;
+    }
+
+    public String getBrand() {
+        return brand;
+    }
+
+    public void setBrand(String brand) {
+        this.brand = brand;
+    }
+
+    public String getEdlp() {
+        return edlp;
+    }
+
+    public void setEdlp(String edlp) {
+        this.edlp = edlp;
+    }
+
+    public String getCurrentPrice() {
+        return currentPrice;
+    }
+
+    public void setCurrentPrice(String currentPrice) {
+        this.currentPrice = currentPrice;
+    }
+
+    public String getCostPrice() {
+        return costPrice;
+    }
+
+    public void setCostPrice(String costPrice) {
+        this.costPrice = costPrice;
+    }
+
+    public String getSupplierName() {
+        return supplierName;
+    }
+
+    public void setSupplierName(String supplierName) {
+        this.supplierName = supplierName;
+    }
+
+    public String getTransactionType() {
+        return transactionType;
+    }
+
+    public void setTransactionType(String transactionType) {
+        this.transactionType = transactionType;
+    }
+
+    public String getSaleReturnType() {
+        return saleReturnType;
+    }
+
+    public void setSaleReturnType(String saleReturnType) {
+        this.saleReturnType = saleReturnType;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+
+    public String getOrderStatus() {
+        return orderStatus;
+    }
+
+    public void setOrderStatus(String orderStatus) {
+        this.orderStatus = orderStatus;
+    }
+
+    public String getTaxPrice() {
+        return taxPrice;
+    }
+
+    public void setTaxPrice(String taxPrice) {
+        this.taxPrice = taxPrice;
+    }
+
+    public String getPayFlag() {
+        return payFlag;
+    }
+
+    public void setPayFlag(String payFlag) {
+        this.payFlag = payFlag;
+    }
+
+    public String getOrderSnWx() {
+        return orderSnWx;
+    }
+
+    public void setOrderSnWx(String orderSnWx) {
+        this.orderSnWx = orderSnWx;
+    }
+
+    public String getOrderSnAli() {
+        return orderSnAli;
+    }
+
+    public void setOrderSnAli(String orderSnAli) {
+        this.orderSnAli = orderSnAli;
+    }
+}

+ 17 - 0
eccs-biz/src/main/java/com/emato/biz/mapper/mall/SalesDetailMapper.java

@@ -1,5 +1,6 @@
 package com.emato.biz.mapper.mall;
 
+import com.emato.biz.domain.OperateLogDTO;
 import com.emato.biz.domain.mall.NewSystemFormatEntiy;
 import com.emato.biz.domain.mall.SalesDataReqVO;
 import org.springframework.stereotype.Component;
@@ -10,6 +11,14 @@ import java.util.Map;
 @Component
 public interface SalesDetailMapper {
 
+    /**
+     * 记录查询请求记录
+     *
+     * @param operateLog
+     * @return
+     */
+    int insertSalesDataReqLog(OperateLogDTO operateLog);
+
     public List<NewSystemFormatEntiy> getSalesDetaiData(Map<String, Object> weChatMapMsg);
 
     public void pullQueryData(Map map);
@@ -25,6 +34,14 @@ public interface SalesDetailMapper {
     List<NewSystemFormatEntiy> selectSalesDetailData(SalesDataReqVO reqVO);
 
     /**
+     * 查询销售数据条数
+     *
+     * @param reqVO
+     * @return
+     */
+    int selectSalesDetailDataTotal(SalesDataReqVO reqVO);
+
+    /**
      * 修改销售数据
      *
      * @param newSystemFormatEntiy

+ 12 - 20
eccs-biz/src/main/java/com/emato/biz/service/impl/InventoryServiceImpl.java

@@ -9,8 +9,10 @@ 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.ISalesDetaiServicel;
 import com.emato.biz.service.mall.InventoryService;
 import com.emato.biz.service.merchant.IThirdMerchantBizService;
+import com.emato.biz.util.MatchUtil;
 import com.emato.common.core.Result;
 import com.emato.common.exception.CustomException;
 import com.emato.common.exception.ServiceException;
@@ -46,6 +48,9 @@ public class InventoryServiceImpl implements InventoryService {
     @Resource
     private InventoryDataMapper inventoryDataMapper;
 
+    @Autowired
+    private ISalesDetaiServicel salesDataService;
+
     /**
      * 查询库存数据
      *
@@ -57,6 +62,7 @@ public class InventoryServiceImpl implements InventoryService {
         try {
             log.info("---------- 查询库存数据开始 ----------");
             log.info("========== 电商请求 eccs 报文 =========> {}", outRequest);
+
             // 验签
             Assert.notTrue(!signService.verifySign(outRequest), ResultCodeEnum.SIGN_ERROR);
             // 转为请求类
@@ -70,8 +76,8 @@ public class InventoryServiceImpl implements InventoryService {
             // 参数校验
             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);
+            Assert.notTrue(!MatchUtil.isPositiveInteger(pageIndexStr), ResultCodeEnum.PARAM_ERROR_PAGE_INDEX_NOT_POS_INT);
+            Assert.notTrue(!MatchUtil.isPositiveInteger(pageSizeStr), ResultCodeEnum.PARAM_ERROR_PAGE_SIZE_NOT_POS_INT);
 
             // 分页大小
             int pageSize = Integer.parseInt(pageSizeStr);
@@ -88,6 +94,9 @@ public class InventoryServiceImpl implements InventoryService {
             // 查询库存记录总数
             int inventoryTotal = inventoryDataMapper.selectInventoryTotal();
 
+            // 记录商户请求数据
+            salesDataService.insertReqLog(JSON.toJSONString(outRequest), outRequest.getMerchId());
+
             // 组装返回数据
             Map<String, Object> resultMap = new HashMap<>();
             resultMap.put("rows", inventoryData);
@@ -103,25 +112,8 @@ public class InventoryServiceImpl implements InventoryService {
             throw se;
         } catch (Exception e) {
             log.error("查询库存数据异常 => ", e);
-            throw new CustomException("查询库存数据异常,请稍后再试!");
+            throw new ServiceException("查询库存数据异常,请稍后再试!");
         }
     }
 
-
-    /**
-     * 判断是否是正整数
-     *
-     * @param str
-     * @return
-     */
-    private static boolean isPositiveInteger(String str) {
-        if (str == null || str.isEmpty()) {
-            return false;
-        }
-        // 正则表达式: ^ 表示开头,\\d+ 表示一位或多位数字,$ 表示结尾
-        // 如果要包含0,则将 + 改为 *
-        return str.matches("^\\d+$");
-    }
-
-
 }

+ 124 - 5
eccs-biz/src/main/java/com/emato/biz/service/impl/SalesDetaiServicelImpl.java

@@ -3,25 +3,30 @@ package com.emato.biz.service.impl;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.emato.biz.domain.OmsUtils;
-import com.emato.biz.domain.mall.InventoryDataPushVo;
-import com.emato.biz.domain.mall.InventoryDataVo;
-import com.emato.biz.domain.mall.NewSystemFormatEntiy;
-import com.emato.biz.domain.mall.SalesDataReqVO;
+import com.emato.biz.domain.OperateLogDTO;
+import com.emato.biz.domain.OutRequest;
+import com.emato.biz.domain.mall.*;
 import com.emato.biz.domain.merchant.MerchantSecret;
 import com.emato.biz.exception.Assert;
 import com.emato.biz.mapper.mall.InventoryDataMapper;
 import com.emato.biz.mapper.mall.MallMngChangeMapper;
 import com.emato.biz.mapper.mall.SalesDetailMapper;
 import com.emato.biz.mapper.merchant.MerchantSecretMapper;
+import com.emato.biz.service.SignService;
 import com.emato.biz.service.mall.ISalesDetaiServicel;
+import com.emato.biz.util.DateUtil;
+import com.emato.biz.util.MatchUtil;
 import com.emato.common.core.Result;
+import com.emato.common.exception.CustomException;
 import com.emato.common.exception.ServiceException;
 import com.emato.common.utils.DateUtils;
 import com.emato.common.utils.StringUtils;
+import com.emato.common.utils.oms.response.ResultCodeEnum;
 import com.emato.common.utils.sign.Md5Utils;
 import com.emato.system.mapper.SysConfigMapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -33,6 +38,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * CW推送数据接口
@@ -57,6 +63,119 @@ public class SalesDetaiServicelImpl implements ISalesDetaiServicel {
     @Resource
     private SalesDetailMapper salesDetailMapper;
 
+    @Autowired
+    private SignService signService;
+
+    /**
+     * 记录请求日志
+     *
+     * @param reqData
+     * @param merchantSn
+     */
+    @Override
+    public void insertReqLog(String reqData, String merchantSn) {
+        try {
+            OperateLogDTO operateLogDTO = new OperateLogDTO();
+            operateLogDTO.setReqData(reqData);
+            operateLogDTO.setMerchSn(merchantSn);
+            salesDetailMapper.insertSalesDataReqLog(operateLogDTO);
+        } catch (Exception e) {
+            logger.error("记录商户请求日志异常", e);
+            throw new ServiceException("系统异常,请稍后再试!");
+        }
+    }
+
+    /**
+     * 获取销售数据
+     *
+     * @param outRequest
+     * @return
+     */
+    @Override
+    public Result getSalesDetailData(OutRequest outRequest) {
+        try {
+            logger.info("---------- 查询销售数据开始 ----------");
+            logger.info("========== 电商请求 eccs 报文 =========> {}", outRequest);
+            // 验签
+            Assert.notTrue(!signService.verifySign(outRequest), ResultCodeEnum.SIGN_ERROR);
+            // 转为请求类
+            SalesDataReqVO reqVO = JSON.parseObject(outRequest.getData(), SalesDataReqVO.class);
+            logger.debug("========== 解析后的请求数据 ==========> 【{}】", reqVO);
+            // 分页页码
+            String pageIndexStr = reqVO.getPageIndex();
+            // 分页大小
+            String pageSizeStr = reqVO.getPageSize();
+            // 起始时间戳
+            String startTimeTimeStamp = reqVO.getStarTime();
+            // 起始时间戳
+            String endTimeTimeStamp = reqVO.getEndTime();
+
+            // 参数校验
+            Assert.notNull(pageIndexStr, ResultCodeEnum.PARAM_ERROR_PAGE_INDEX_NOT_NULL);
+            Assert.notNull(pageSizeStr, ResultCodeEnum.PARAM_ERROR_PAGE_SIZE_NOT_NULL);
+            Assert.notTrue(!MatchUtil.isPositiveInteger(pageIndexStr), ResultCodeEnum.PARAM_ERROR_PAGE_INDEX_NOT_POS_INT);
+            Assert.notTrue(!MatchUtil.isPositiveInteger(pageSizeStr), ResultCodeEnum.PARAM_ERROR_PAGE_SIZE_NOT_POS_INT);
+            Assert.notTrue(!MatchUtil.isTimestamp(reqVO.getStarTime()), ResultCodeEnum.PARAM_ERROR_START_TIME_NOT_TIMES_STAMP);
+            Assert.notTrue(!MatchUtil.isTimestamp(reqVO.getEndTime()), ResultCodeEnum.PARAM_ERROR_END_TIME_NOT_TIMES_STAMP);
+
+            // 计算起始时间和结束时间相差多少小时,
+            long hourBetweenTimesStamp = DateUtil.getHourBetweenTimesStamp(startTimeTimeStamp, endTimeTimeStamp);
+            Assert.notTrue(hourBetweenTimesStamp > 24, ResultCodeEnum.TIME_INTERVAL_TOO_LARGE);
+
+            // 分页大小
+            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;
+
+            // 格式化起始时间
+            String startTime = DateUtil.dateFormat(startTimeTimeStamp, "yyyy-MM-dd HH:mm:ss");
+            // 格式化结束时间
+            String endTime = DateUtil.dateFormat(endTimeTimeStamp, "yyyy-MM-dd HH:mm:ss");
+
+            // 设置查询条件
+            reqVO.setOffset(pageIndex);
+            reqVO.setLimit(pageSize);
+            reqVO.setStarTime(startTime);
+            reqVO.setEndTime(endTime);
+
+            // 查询销售数据
+            List<NewSystemFormatEntiy> salesDataList = salesDetailMapper.selectSalesDetailData(reqVO);
+            Assert.notTrue(salesDataList.isEmpty(), ResultCodeEnum.NO_DATA);
+
+            // 记录查询日志
+            insertReqLog(JSON.toJSONString(outRequest), outRequest.getMerchId());
+
+
+            // 将数据库数据转换为接口输出的数据格式
+            List<SalesDataResVO> salesDataVOList = salesDataList.stream().map(salesData -> {
+                SalesDataResVO resVO = new SalesDataResVO();
+                BeanUtils.copyProperties(salesData, resVO);
+                return resVO;
+            }).collect(Collectors.toList());
+
+            // 查询总记录数
+            int total = salesDetailMapper.selectSalesDetailDataTotal(reqVO);
+
+            // 组装返回数据
+            Map<String, Object> resultMap = new HashMap<>();
+            resultMap.put("rows", salesDataVOList);
+            resultMap.put("total", total);
+
+            logger.info("---------- 查询销售数据结束 ----------");
+            return Result.success(resultMap);
+        } catch (ServiceException se) {
+            throw se;
+        } catch (Exception e) {
+            logger.error("外部商户获取销售数据异常 => ", e);
+            throw new ServiceException("获取销售数据异常,请稍后再试!");
+        }
+    }
+
     /**
      * kmall向eccs系统推送数据
      * @param newSystemFormatEntiy
@@ -69,7 +188,7 @@ public class SalesDetaiServicelImpl implements ISalesDetaiServicel {
         try {
             // 查询订单查看是否存在
             SalesDataReqVO reqVO = new SalesDataReqVO();
-            reqVO.setOrderSn(newSystemFormatEntiy.getReceiptNo());
+            reqVO.setOrderNo(newSystemFormatEntiy.getReceiptNo());
             List<NewSystemFormatEntiy> salesDataList = salesDetailMapper.selectSalesDetailData(reqVO);
 
             if (salesDataList.isEmpty()) {

+ 16 - 0
eccs-biz/src/main/java/com/emato/biz/service/mall/ISalesDetaiServicel.java

@@ -1,6 +1,7 @@
 package com.emato.biz.service.mall;
 
 import com.alibaba.fastjson.JSONObject;
+import com.emato.biz.domain.OutRequest;
 import com.emato.biz.domain.mall.InventoryDataVo;
 import com.emato.biz.domain.mall.NewSystemFormatEntiy;
 import com.emato.common.core.Result;
@@ -16,4 +17,19 @@ public interface ISalesDetaiServicel {
 
     public Result  queryInventory(JSONObject msg, HttpServletRequest httpServletRequest);
 
+    /**
+     * 获取销售数据
+     *
+     * @param outRequest
+     * @return
+     */
+    Result getSalesDetailData(OutRequest outRequest);
+
+    /**
+     * 记录请求日志
+     *
+     * @param reqData
+     * @param merchantSn
+     */
+    void insertReqLog(String reqData, String merchantSn);
 }

+ 42 - 0
eccs-biz/src/main/java/com/emato/biz/util/DateUtil.java

@@ -0,0 +1,42 @@
+package com.emato.biz.util;
+
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+
+/**
+ * 时间工具类
+ *
+ * @author frankeleyn
+ * @email lvjian@qhdswl.com
+ * @date 2023/4/10 16:21
+ */
+public class DateUtil {
+
+    /**
+     * 格式化时间戳
+     *
+     * @param timestampStr
+     * @param format
+     * @return
+     */
+    public static String dateFormat(String timestampStr, String format) {
+        long timestamp = Long.parseLong(timestampStr);
+        Timestamp ts = new Timestamp(timestamp);
+        SimpleDateFormat sdf = new SimpleDateFormat(format);
+        return sdf.format(ts);
+    }
+
+    /**
+     * 计算时间戳相差多少小时
+     *
+     * @param timestamp1
+     * @param timestamp2
+     * @return
+     */
+    public static long getHourBetweenTimesStamp(String timestamp1, String timestamp2) {
+        long diff = (Long.parseLong(timestamp2) - Long.parseLong(timestamp1)) / (1000 * 60 *60);
+        return diff;
+    }
+
+
+}

+ 43 - 0
eccs-biz/src/main/java/com/emato/biz/util/MatchUtil.java

@@ -0,0 +1,43 @@
+package com.emato.biz.util;
+
+import com.emato.common.utils.oms.response.ResultCodeEnum;
+
+/**
+ * 匹配字符串
+ *
+ * @author frankeleyn
+ * @email lvjian@qhdswl.com
+ * @date 2023/4/10 15:51
+ */
+public class MatchUtil {
+
+    /**
+     * 判断是否是正整数
+     *
+     * @param str
+     * @return
+     */
+    public static boolean isPositiveInteger(String str) {
+        if (str == null || str.isEmpty()) {
+            return false;
+        }
+        // 正则表达式: ^ 表示开头,\\d+ 表示一位或多位数字,$ 表示结尾
+        // 如果要包含0,则将 + 改为 *
+        return str.matches("^\\d+$");
+    }
+
+    /**
+     * 判断字符串是不是时间戳
+     *
+     * @param str
+     * @return
+     */
+    public static boolean isTimestamp(String str) {
+        if (str == null || str.isEmpty()) {
+            return false;
+        }
+        return str.matches("^\\d{10,13}$");
+    }
+
+
+}

+ 52 - 4
eccs-biz/src/main/resources/mapper/biz/mall/SalesDetailMapper.xml

@@ -4,6 +4,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.emato.biz.mapper.mall.SalesDetailMapper">
 
+    <!-- 记录请求操作日志 -->
+    <insert id="insertSalesDataReqLog">
+        insert into mall_sales_detail_log(
+        msg,
+        tran_direction,
+        msg_date
+        ) VALUES (
+        <if test="reqData != null and reqData != ''">#{reqData},</if>
+        <if test="merchSn != null and merchSn != ''">#{merchSn},</if>
+        sysdate()
+        )
+    </insert>
 
     <!-- 查询销售数据 -->
     <select id="selectSalesDetailData" resultType="com.emato.biz.domain.mall.NewSystemFormatEntiy" parameterType="com.emato.biz.domain.mall.SalesDataReqVO">
@@ -46,15 +58,50 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         FROM
             mall_sales_detail_data
         <where>
-            <if test="orderSn != null and orderSn != '' ">
-                AND receipt_no = #{orderSn}
+            <if test="orderNo != null and orderNo != '' ">
+                AND receipt_no = #{orderNo}
+            </if>
+            <if test="starTime != null and starTime != '' ">
+                AND time_stamp &gt; #{starTime}
+            </if>
+            <if test="endTime != null and endTime != '' ">
+                AND time_stamp &lt;= #{endTime}
+            </if>
+            <if test="orderStatus != null and orderStatus != '' ">
+                AND order_status &lt;= #{orderStatus}
             </if>
         </where>
-        <if test="pageIndex != null and pageSize != null">
-            limit #{pageIndex}, #{pageSize}
+        <if test="offset != null and limit != null">
+            limit #{offset}, #{limit}
         </if>
     </select>
 
+    <!-- 查询销售数据条数 -->
+    <select id="selectSalesDetailDataTotal" resultType="int">
+        SELECT
+            COUNT(1)
+        FROM
+            mall_sales_detail_data
+        <where>
+            <if test="orderNo != null and orderNo != '' ">
+                AND receipt_no = #{orderNo}
+            </if>
+            <if test="starTime != null and starTime != '' ">
+                AND time_stamp &gt; #{starTime}
+            </if>
+            <if test="endTime != null and endTime != '' ">
+                AND time_stamp &lt;= #{endTime}
+            </if>
+            <if test="endTime != null and endTime != '' ">
+                AND time_stamp &lt;= #{endTime}
+            </if>
+            <if test="orderStatus != null and orderStatus != '' ">
+                AND order_status &lt;= #{orderStatus}
+            </if>
+        </where>
+    </select>
+
+
 <!--    接收kmall数据-->
     <insert id="insertSalesDetaiDate" parameterType="com.emato.biz.domain.mall.NewSystemFormatEntiy">
         insert into mall_sales_detail_data(
@@ -251,4 +298,5 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </set>
         where receipt_no = #{receiptNo}
     </update>
+
 </mapper>

+ 7 - 0
eccs-common/src/main/java/com/emato/common/utils/oms/response/ResultCodeEnum.java

@@ -12,6 +12,8 @@ public enum ResultCodeEnum {
 	PARAM_ERROR_PAGE_SIZE_NOT_NULL("900001", "分页大小不能为空!"),
 	PARAM_ERROR_PAGE_INDEX_NOT_POS_INT("900001", "分页页码请填入正整数!"),
 	PARAM_ERROR_PAGE_SIZE_NOT_POS_INT("900001", "分页大小请填入正整数!"),
+	PARAM_ERROR_START_TIME_NOT_TIMES_STAMP("900001", "起始时间不是时间戳!"),
+	PARAM_ERROR_END_TIME_NOT_TIMES_STAMP("900001", "结束时间不是时间戳!"),
 
 	MERCHANT_ID_NOT_NULL("900002", "商户号不能为空!"),
 	SIGN_NOT_NULL("900002", "接口签名不能为空!"),
@@ -22,6 +24,11 @@ public enum ResultCodeEnum {
 	MERCHANT_KEY_NOT_EXIST("900002", "商户密钥不存在!"),
 
 	SIGN_ERROR("900002", "验签失败!"),
+
+	TIME_INTERVAL_TOO_LARGE("900003", "时间区间过大, 请勿超过24小时!"),
+
+	NO_DATA("900004", "该条件下无数据!"),
+
 	;
 
 	/** 状态码 */