|
@@ -2,13 +2,16 @@ package com.emato.biz.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+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.mapper.mall.InventoryDataMapper;
|
|
|
import com.emato.biz.mapper.mall.MallMngChangeMapper;
|
|
|
-import com.emato.biz.mapper.mall.SalesDetailMapper;
|
|
|
import com.emato.biz.service.mall.ISalesDetaiServicel;
|
|
|
import com.emato.common.core.Result;
|
|
|
import com.emato.common.utils.DateUtils;
|
|
|
import com.emato.common.utils.oms.request.DesUtils;
|
|
|
+import com.emato.common.utils.sign.Md5Utils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -19,6 +22,9 @@ import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+/**
|
|
|
+ * CW推送数据接口
|
|
|
+ */
|
|
|
@Service
|
|
|
public class SalesDetaiServicelImpl implements ISalesDetaiServicel {
|
|
|
|
|
@@ -26,11 +32,12 @@ public class SalesDetaiServicelImpl implements ISalesDetaiServicel {
|
|
|
private final Logger logger = LoggerFactory.getLogger(SalesDetaiServicelImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
- private SalesDetailMapper salesDetailMapper;
|
|
|
-
|
|
|
+ private InventoryDataMapper inventoryDataMapper;
|
|
|
@Autowired
|
|
|
private MallMngChangeMapper mallMngChangeMapper;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* kmall向eccs系统推送数据
|
|
|
* @param newSystemFormatEntiy
|
|
@@ -58,23 +65,35 @@ public class SalesDetaiServicelImpl implements ISalesDetaiServicel {
|
|
|
return Result.error("1002","参数错误");
|
|
|
}
|
|
|
Map<String, Object> weChatMapMsg = JSONObject.toJavaObject(msg, Map.class);
|
|
|
- logger.error("外部系统查询订单销售数据查询条件:"+JSON.toJSONString(weChatMapMsg));
|
|
|
+ String starTime = (String) weChatMapMsg.get("starTime");
|
|
|
+ String endTime = (String) weChatMapMsg.get("endTime");
|
|
|
+ Integer pageIndex = Integer.parseInt(weChatMapMsg.get("pageIndex")+"");
|
|
|
+ Integer pageSize = Integer.parseInt(weChatMapMsg.get("pageSize")+"");
|
|
|
weChatMapMsg.put("starTime", DateUtils.getStrDate((String) weChatMapMsg.get("starTime")));
|
|
|
weChatMapMsg.put("endTime",DateUtils.getStrDate((String)weChatMapMsg.get("endTime")));
|
|
|
- weChatMapMsg.put("offset",Integer.parseInt(weChatMapMsg.get("pageIndex")+""));
|
|
|
- weChatMapMsg.put("limit",Integer.parseInt(weChatMapMsg.get("pageSize")+""));
|
|
|
+ weChatMapMsg.put("offset",pageIndex);
|
|
|
+ weChatMapMsg.put("limit",pageSize);
|
|
|
+ if((pageSize-pageIndex)>500){
|
|
|
+ return Result.error("1005","请求总数或时间区间过大");
|
|
|
+ }
|
|
|
//记录调用参数接口日志
|
|
|
- pullQueryData(weChatMapMsg,tranDtion);
|
|
|
+ long diff=(Long.parseLong(endTime) - Long.parseLong(starTime))/1000/60/60;
|
|
|
+ if(diff<=24){
|
|
|
+ weChatMapMsg.put("tranDtion",tranDtion);
|
|
|
+ pullQueryData(weChatMapMsg);
|
|
|
List<NewSystemFormatEntiy> list = mallMngChangeMapper.getSalesDetaiData(weChatMapMsg);
|
|
|
- String desList ="";
|
|
|
+ //desList = DesUtils.encode(JSON.toJSONString(list));
|
|
|
if(list.size()==0){
|
|
|
return Result.error("1004","该条件下无数据");
|
|
|
}else{
|
|
|
- desList = DesUtils.encode(JSON.toJSONString(list));
|
|
|
- return Result.success(desList);
|
|
|
+ return Result.success(list);
|
|
|
}
|
|
|
+ }else{
|
|
|
+ return Result.error("1005","请求总数或时间区间过大");
|
|
|
+ }
|
|
|
+
|
|
|
}catch (Exception e){
|
|
|
- logger.error("外部系统查询订单销售数据错误"+ JSON.toJSONString(msg),e);
|
|
|
+ logger.error("外部系统查询订单销售数据错误="+ JSON.toJSONString(msg),e);
|
|
|
return Result.error("1002","参数错误");
|
|
|
}
|
|
|
|
|
@@ -84,12 +103,89 @@ public class SalesDetaiServicelImpl implements ISalesDetaiServicel {
|
|
|
* 记录外部调用接口参数,时间和调用方
|
|
|
* @param msg
|
|
|
*/
|
|
|
- private void pullQueryData(Map msg,String tranDtion) {
|
|
|
+ private void pullQueryData(Map msg) {
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
- map.put("tranDirection",tranDtion);
|
|
|
+ map.put("tranDirection",msg.get("tranDtion"));
|
|
|
map.put("msg",msg.toString());
|
|
|
mallMngChangeMapper.pullQueryData(map);
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 插入来源于oms的库存数据
|
|
|
+ * @param inventoryDataVo
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result inserInventory(InventoryDataVo inventoryDataVo) {
|
|
|
+ try{
|
|
|
+ //查询是否存在该库存信息
|
|
|
+ Integer checkStuts = inventoryDataMapper.queryOneInventory(inventoryDataVo);
|
|
|
+ if(checkStuts>0){
|
|
|
+ inventoryDataMapper.updateInventory(inventoryDataVo);
|
|
|
+ }else{
|
|
|
+ inventoryDataMapper.inserInventory(inventoryDataVo);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.error("插入来源于oms的库存数据"+JSON.toJSONString(inventoryDataVo),e);
|
|
|
+ return Result.error("1001","数据插入出错");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询库存数据提供给外部系统
|
|
|
+ * @param msg
|
|
|
+ * @param httpServletRequest
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result queryInventory(JSONObject msg, HttpServletRequest httpServletRequest) {
|
|
|
+ try{
|
|
|
+ //签名验证
|
|
|
+ String strSign = httpServletRequest.getHeader("Sign");
|
|
|
+ String tranDtion = httpServletRequest.getHeader("tranDtion")==null?"":httpServletRequest.getHeader("tranDtion");
|
|
|
+ String timestamp = httpServletRequest.getHeader("timestamp")==null?"":httpServletRequest.getHeader("timestamp");
|
|
|
+ String interType = httpServletRequest.getHeader("interType")==null?"":httpServletRequest.getHeader("interType");
|
|
|
+ if(tranDtion.equals("")||timestamp.equals("")||interType.equals("")){
|
|
|
+ return Result.error("1005","参数错误");
|
|
|
+ }
|
|
|
+ if(!strSign.equals(checkType(tranDtion,timestamp,interType))){
|
|
|
+ return Result.error("1003","签名错误");
|
|
|
+ }
|
|
|
+ //校验签名
|
|
|
+ Map<String, Object> weChatMapMsg = JSONObject.toJavaObject(msg, Map.class);
|
|
|
+ Integer pageIndex = Integer.parseInt(weChatMapMsg.get("pageIndex")+"");
|
|
|
+ Integer pageSize = Integer.parseInt(weChatMapMsg.get("pageSize")+"");
|
|
|
+ weChatMapMsg.put("offset",pageIndex);
|
|
|
+ weChatMapMsg.put("limit",pageSize);
|
|
|
+ weChatMapMsg.put("tranDtion",tranDtion);
|
|
|
+ weChatMapMsg.put("interType",interType);
|
|
|
+ if(pageSize>3000){
|
|
|
+ return Result.error("1004","请求数量过大");
|
|
|
+ }
|
|
|
+ //数据查询
|
|
|
+ pullQueryData(weChatMapMsg);
|
|
|
+ List<InventoryDataPushVo> list = inventoryDataMapper.getInventoryData(weChatMapMsg);
|
|
|
+ if(list.size()==0){
|
|
|
+ return Result.error("1002","该条件下无数据");
|
|
|
+ }else{
|
|
|
+ return Result.success(list);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.error("外部系统查询库存系统条件="+JSON.toJSONString(msg),e);
|
|
|
+ return Result.error("1005","参数错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //签名加密校验
|
|
|
+ public String checkType(String tranDtion,String timestamp,String interType) {
|
|
|
+ String sign = "tranDtion=" + tranDtion + "×tamp=" + timestamp + "&interType=" + interType;
|
|
|
+ return Md5Utils.encryption(sign);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|