1
0
فهرست منبع

销售明细接口和库存接口

qng 3 سال پیش
والد
کامیت
fdc207e1b5

+ 1 - 1
eccs-admin/src/main/resources/application-test.yml

@@ -10,7 +10,7 @@ spring:
     # 地址
     host: 120.78.152.8
     # 端口,默认为6379
-    port: 7379
+    port: 6379
     # 数据库索引
     database: 0
     # 密码

+ 50 - 0
eccs-biz/src/main/java/com/emato/biz/controller/mall/InventoryDataController.java

@@ -0,0 +1,50 @@
+package com.emato.biz.controller.mall;
+
+
+import com.alibaba.fastjson.JSONObject;
+import com.emato.biz.domain.mall.InventoryDataVo;
+import com.emato.biz.service.mall.ISalesDetaiServicel;
+import com.emato.common.annotation.AnonymousAccess;
+import com.emato.common.core.Result;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+
+@RestController
+@RequestMapping("/inventory")
+public class InventoryDataController {
+
+    @Autowired
+    private ISalesDetaiServicel salesDetaiServicel;
+
+    /**
+     * 接收来自oms的库存数据
+     * @param inventoryDataVo
+     * @return
+     */
+    @AnonymousAccess
+    @PostMapping("/pushinvent")
+    public Result pushInventory(@RequestBody InventoryDataVo inventoryDataVo)
+    {
+        return salesDetaiServicel.inserInventory(inventoryDataVo);
+    }
+
+    /**
+     * 查询库存数据提供给外部系统
+     * @param msg
+     * @param httpRequest
+     * @return
+     */
+    @AnonymousAccess
+    @PostMapping("/getinvdata")
+    public Result getpushinventMsg(@RequestBody JSONObject msg, HttpServletRequest httpRequest)
+    {
+        return salesDetaiServicel.queryInventory(msg,httpRequest);
+    }
+
+
+}

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

@@ -0,0 +1,61 @@
+package com.emato.biz.domain.mall;
+
+import java.io.Serializable;
+
+public class InventoryDataPushVo implements Serializable {
+
+    //条形码
+    private String barcode;
+
+    //产品名称
+    private String productName;
+
+    //门店名称
+    private String shopName;
+
+    //门店库存
+    private Integer shopInvent;
+
+    //e码头库存
+    private Integer eMatou;
+
+    public String getBarcode() {
+        return barcode;
+    }
+
+    public void setBarcode(String barcode) {
+        this.barcode = barcode;
+    }
+
+    public String getProductName() {
+        return productName;
+    }
+
+    public void setProductName(String productName) {
+        this.productName = productName;
+    }
+
+    public String getShopName() {
+        return shopName;
+    }
+
+    public void setShopName(String shopName) {
+        this.shopName = shopName;
+    }
+
+    public Integer getShopInvent() {
+        return shopInvent;
+    }
+
+    public void setShopInvent(Integer shopInvent) {
+        this.shopInvent = shopInvent;
+    }
+
+    public Integer geteMatou() {
+        return eMatou;
+    }
+
+    public void seteMatou(Integer eMatou) {
+        this.eMatou = eMatou;
+    }
+}

+ 77 - 0
eccs-biz/src/main/java/com/emato/biz/domain/mall/InventoryDataVo.java

@@ -0,0 +1,77 @@
+package com.emato.biz.domain.mall;
+
+import java.io.Serializable;
+
+/**
+ * 库存接口实体类
+ */
+public class InventoryDataVo implements Serializable {
+
+    //条形码
+    private String barcode;
+
+    //产品名称
+    private String productName;
+
+    //门店编码
+    private String shopCode;
+
+    //门店名称
+    private String shopName;
+
+    //门店库存
+    private Integer shopInvent;
+
+    //e码头库存
+    private Integer eMatou;
+
+
+    public String getBarcode() {
+        return barcode;
+    }
+
+    public void setBarcode(String barcode) {
+        this.barcode = barcode;
+    }
+
+    public String getProductName() {
+        return productName;
+    }
+
+    public void setProductName(String productName) {
+        this.productName = productName;
+    }
+
+    public String getShopName() {
+        return shopName;
+    }
+
+    public void setShopName(String shopName) {
+        this.shopName = shopName;
+    }
+
+    public Integer getShopInvent() {
+        return shopInvent;
+    }
+
+    public void setShopInvent(Integer shopInvent) {
+        this.shopInvent = shopInvent;
+    }
+
+    public Integer geteMatou() {
+        return eMatou;
+    }
+
+    public void seteMatou(Integer eMatou) {
+        this.eMatou = eMatou;
+    }
+
+    public String getShopCode() {
+        return shopCode;
+    }
+
+    public void setShopCode(String shopCode) {
+        this.shopCode = shopCode;
+    }
+
+}

+ 18 - 0
eccs-biz/src/main/java/com/emato/biz/mapper/mall/InventoryDataMapper.java

@@ -0,0 +1,18 @@
+package com.emato.biz.mapper.mall;
+
+import com.emato.biz.domain.mall.InventoryDataPushVo;
+import com.emato.biz.domain.mall.InventoryDataVo;
+
+import java.util.List;
+import java.util.Map;
+
+public interface InventoryDataMapper {
+    void inserInventory(InventoryDataVo inventoryDataVo);
+
+
+    List<InventoryDataPushVo> getInventoryData(Map<String,Object> map);
+
+    Integer queryOneInventory(InventoryDataVo inventoryDataVo);
+
+    void updateInventory(InventoryDataVo inventoryDataVo);
+}

+ 1 - 1
eccs-biz/src/main/java/com/emato/biz/mapper/mall/MallMngChangeMapper.java

@@ -70,5 +70,5 @@ public interface MallMngChangeMapper
 
     int pushSalesDetaiDate(NewSystemFormatEntiy newSystemFormatEntiy);
 
-    Date getPullDataTime(String tranDirection);
+    String getTotalRecord(Map<String, Object> weChatMapMsg);
 }

+ 109 - 13
eccs-biz/src/main/java/com/emato/biz/service/impl/SalesDetaiServicelImpl.java

@@ -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 + "&timestamp=" + timestamp + "&interType=" + interType;
+        return Md5Utils.encryption(sign);
+    }
+
+
+
 }

+ 6 - 1
eccs-biz/src/main/java/com/emato/biz/service/mall/ISalesDetaiServicel.java

@@ -1,14 +1,19 @@
 package com.emato.biz.service.mall;
 
 import com.alibaba.fastjson.JSONObject;
+import com.emato.biz.domain.mall.InventoryDataVo;
 import com.emato.biz.domain.mall.NewSystemFormatEntiy;
 import com.emato.common.core.Result;
 
 import javax.servlet.http.HttpServletRequest;
-import java.util.List;
 
 public interface ISalesDetaiServicel {
     int pushSalesDetaiServicel(NewSystemFormatEntiy newSystemFormatEntiy);
 
     Result getSalesDetaiData(JSONObject msg,HttpServletRequest httpServletRequest);
+
+    public Result inserInventory(InventoryDataVo inventoryDataVo);
+
+    public Result  queryInventory(JSONObject msg, HttpServletRequest httpServletRequest);
+
 }

+ 81 - 0
eccs-biz/src/main/resources/mapper/biz/mall/InventoryDataMapper.xml

@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.emato.biz.mapper.mall.InventoryDataMapper">
+
+
+    <!--    外部接口查询-->
+    <select id="getInventoryData"  parameterType="java.util.Map" resultType="com.emato.biz.domain.mall.InventoryDataPushVo">
+        SELECT
+            bar_code as barcode,
+            product_name as productName,
+            shop_name as shopName,
+            shop_invent as shopInvent,
+            e_matou as eMatou
+        FROM
+        o_inventory_data
+        <if test="offset != null and limit != null">
+            limit #{offset}, #{limit}
+        </if>
+    </select>
+
+
+    <insert id="inserInventory" parameterType="com.emato.biz.domain.mall.InventoryDataVo" >
+        insert into o_inventory_data
+        <trim prefix="(" suffix=")" suffixOverrides="," >
+            <if test="barcode != null" >
+                bar_code,
+            </if>
+            <if test="productName != null" >
+                product_name,
+            </if>
+            <if test="shopCode != null" >
+                shop_code,
+            </if>
+            <if test="shopName != null" >
+                shop_name,
+            </if>
+            <if test="shopInvent != null" >
+                shop_invent,
+            </if>
+            <if test="eMatou != null" >
+                e_matou,
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides="," >
+            <if test="barcode != null" >
+                #{barcode},
+            </if>
+            <if test="productName != null" >
+                #{productName},
+            </if>
+            <if test="shopCode != null" >
+                #{shopCode},
+            </if>
+            <if test="shopName != null" >
+                #{shopName},
+            </if>
+            <if test="shopInvent != null" >
+                #{shopInvent},
+            </if>
+            <if test="eMatou != null" >
+                #{eMatou},
+            </if>
+        </trim>
+    </insert>
+
+    <update id="updateInventory" parameterType="com.emato.biz.domain.mall.InventoryDataVo">
+        update o_inventory_data
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="shopInvent != null">shop_invent = #{shopInvent},</if>
+            <if test="eMatou != null">e_matou = #{eMatou},</if>
+        </trim>
+        where bar_code = #{barcode}  and shop_code = #{shopCode}
+    </update>
+
+    <select id="queryOneInventory" parameterType="com.emato.biz.domain.mall.InventoryDataVo" resultType="java.lang.Integer">
+        select count(*) from o_inventory_data oid  where bar_code = #{barcode}  and shop_code = #{shopCode}
+    </select>
+
+</mapper>

+ 23 - 5
eccs-biz/src/main/resources/mapper/biz/mall/MallMngChangeMapper.xml

@@ -259,6 +259,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </if>
     </select>
 
+    <select id="getTotalRecord"  parameterType="java.util.Map" resultType="java.lang.String">
+        SELECT
+        count(*) as totalRecord
+        FROM
+        mall_sales_detail_data
+        WHERE
+        <if test="starTime != null and starTime != ''">
+            time_stamp &gt; STR_TO_DATE(#{starTime}, '%Y-%m-%d %H:%i:%s')
+        </if>
+        <if test="endTime != null and endTime != ''">
+            AND time_stamp &lt;= STR_TO_DATE(#{endTime}, '%Y-%m-%d %H:%i:%s')
+        </if>
+        <if test="orderStatus !=null and orderStatus !=''">
+            AND order_status = #{orderStatus}
+        </if>
+        <if test="orderNo !=null and orderNo !=''">
+            AND receipt_no = #{orderNo}
+        </if>
+        <if test="offset != null and limit != null">
+            limit #{offset}, #{limit}
+        </if>
+    </select>
+
     <!--    记录外部调用接口入参-->
     <insert id="pullQueryData" parameterType="java.lang.String">
         insert into mall_sales_detail_log(
@@ -272,9 +295,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         )
     </insert>
 
-    <select  id="getPullDataTime" parameterType="java.lang.String" resultType="java.util.Date">
-        select msg_date from mall_sales_detail_log where tran_direction = #{tranDirection} order by msg_date desc limit 1
-    </select>
-
-
 </mapper>

+ 20 - 0
eccs-common/src/main/java/com/emato/common/core/Result.java

@@ -12,6 +12,8 @@ public class Result implements Serializable {
 
     private Object data;
 
+    //private String totalRecord;
+
 
 
     public static Result success() {
@@ -23,6 +25,16 @@ public class Result implements Serializable {
         return result;
     }
 
+//    public static Result success(Object data,String totalRecord) {
+//        Result result = new Result();
+//        result.code = "200";
+//        result.msg = "请求成功";
+//        result.status = "true";
+//        result.totalRecord = totalRecord;
+//        result.data = data;
+//        return result;
+//    }
+
     public static Result success(Object data) {
         Result result = new Result();
         result.code = "200";
@@ -45,6 +57,14 @@ public class Result implements Serializable {
         return status;
     }
 
+//    public String getTotalRecord() {
+//        return totalRecord;
+//    }
+//
+//    public void setTotalRecord(String totalRecord) {
+//        this.totalRecord = totalRecord;
+//    }
+
     public void setStatus(String status) {
         this.status = status;
     }

+ 96 - 0
eccs-common/src/main/java/com/emato/common/core/ResultNew.java

@@ -0,0 +1,96 @@
+package com.emato.common.core;
+
+import java.io.Serializable;
+
+public class ResultNew implements Serializable {
+
+    private String code;
+
+    private String msg;
+
+    private String status;
+
+    private Object data;
+
+    //private String totalRecord;
+
+
+
+    public static ResultNew success() {
+        ResultNew result = new ResultNew();
+        result.code = "200";
+        result.msg = "请求成功";
+        result.status = "true";
+        result.data = null;
+        return result;
+    }
+
+//    public static Result success(Object data,String totalRecord) {
+//        Result result = new Result();
+//        result.code = "200";
+//        result.msg = "请求成功";
+//        result.status = "true";
+//        result.totalRecord = totalRecord;
+//        result.data = data;
+//        return result;
+//    }
+
+    public static ResultNew success(Object data) {
+        ResultNew result = new ResultNew();
+        result.code = "200";
+        result.msg = "请求成功";
+        result.status = "true";
+        result.data = data;
+        return result;
+    }
+
+    public static ResultNew error(String code, String msg) {
+        ResultNew result = new ResultNew();
+        result.code = code;
+        result.status = "false";
+        result.msg = msg;
+        result.data = "";
+        return result;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+//    public String getTotalRecord() {
+//        return totalRecord;
+//    }
+//
+//    public void setTotalRecord(String totalRecord) {
+//        this.totalRecord = totalRecord;
+//    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    public Object getData() {
+        return data;
+    }
+
+    public void setData(Object data) {
+        this.data = data;
+    }
+}
+