|
@@ -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()) {
|