소스 검색

修改全量写入库存信息数据

csk 4 년 전
부모
커밋
3871a60d23

+ 5 - 1
src/main/java/com/emato/cus/supervise/biz/acqInventoryInfo/AcqInventoryInfoBiz.java

@@ -83,6 +83,7 @@ public class AcqInventoryInfoBiz implements CusWmsTask {
         }
 
         // 扫描WMS 数据
+        // sql中固定的起始时间,oldThisTime 不会用到
         List<WmsAcqInventoryInfo> wmsList = acqInventoryInfoWmsData.getWmsData(oldThisTime);
         // 执行wms相关操作
         boolean wmsOp = true;
@@ -173,7 +174,10 @@ public class AcqInventoryInfoBiz implements CusWmsTask {
 
         // 有则更新,无则新增
         // 写CUS 数据
-        int res = acqInventoryInfoCusData.writeCus(cusAcqInventoryInfo03List);
+        // int res = acqInventoryInfoCusData.writeCus(cusAcqInventoryInfo03List);
+
+        // 全量一次性写入
+        int res = acqInventoryInfoCusData.writeCusWms(cusAcqInventoryInfo03List);
     }
 
 

+ 65 - 0
src/main/java/com/emato/cus/supervise/biz/acqInventoryInfo/AcqInventoryInfoCusData.java

@@ -13,7 +13,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.beans.Transient;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -37,14 +39,74 @@ public class AcqInventoryInfoCusData implements CusData {
 
     private static final String DATA_TYPE_INFO = "[" + EmtRecordTimeEnum.I_ACQ_INVENTORY_INFO.getCode() + "]" + EmtRecordTimeEnum.I_ACQ_INVENTORY_INFO.getName();
 
+    /**
+     * 海关抓取库存信息为全量抓取
+     * 先删除,再插入
+     *
+     * @param list
+     * @return
+     */
+    public int writeCusWms(List<?> list) {
+        logger.info("---------- 货物库存数据::写入本次监控数据开始 --------------------");
+
+        // bug 20200914 修改为库存全量更新
+
+        // 数据准备
+
+        List<CusAcqInventoryInfo03> cusList = ( List<CusAcqInventoryInfo03>)list;
+        // 全部删除,使用一个空集
+        List<CusAcqInventoryInfo03> deleteList = Lists.newArrayList();
+        // 新增库存list
+        List<CusAcqInventoryInfo03> insertList = new ArrayList<>();
+
+        // ------ 查询oms产品数据
+        List<String> gUnitNameList = Lists.newArrayList();
+        cusList.forEach(
+                i -> {
+                    gUnitNameList.add(i.getgUnit());
+                });
+
+        List<OmsCusUnitCode> codeList = omsCusUnitCodeMapper.getOmsCusUnitCodeList(gUnitNameList);
+        Map<String,OmsCusUnitCode> omsCusUnitCodeMap = codeList.stream().collect(Collectors.toMap(k->k.getgUnitName(), v->v));
+
+        for (CusAcqInventoryInfo03 info : cusList) {
+            /*if (info.getgQty() == null) {
+                logger.debug("{}为空,qty变为0.0", info.getSkuNo());
+                info.setgQty(0.0);
+            }else{
+                logger.debug("{}不为空,qty: {}", info.getSkuNo(), info.getgQty());
+            }*/
+
+            OmsCusUnitCode omsProductInfo = omsCusUnitCodeMap.get(info.getgUnit());
+            if(omsProductInfo != null) {
+                info.setgUnit(omsProductInfo.getgUnitCode());
+            }
+            insertList.add(info);
+
+        }
+
+        int deleteResult = 0;
+        int insertResult = 0;
+
+        //先删除,再新增
+        deleteResult = cusAcqInventoryInfoService03.deleteCusAcqInventoryInfo(deleteList);
+        insertResult = cusAcqInventoryInfoService03.addCusAcqInventoryInfo(insertList);
+
+        logger.info("---【" + DATA_TYPE_INFO + "】删除监控数据:{}条, 新增监控数据:{}条", deleteResult, insertResult);
+
+        logger.info("---------- 货物库存数据::写入本次监控数据结束 --------------------");
+        return deleteResult + insertResult;
+    }
 
     /**
+     * !!!作废!!!
      * 海关抓取库存信息为全量抓取
      * 无则新增,有则更新
      *
      * @param list
      * @return
      */
+    @Deprecated
     @Override
     public int writeCus(List<?> list) {
         logger.info("---------- 货物库存数据::写入本次监控数据开始 --------------------");
@@ -69,6 +131,9 @@ public class AcqInventoryInfoCusData implements CusData {
                     // 查询条件
                     listSku.add(i.getSkuNo());
                 });
+
+        // bug 20200914 修改为库存全量更新
+
         // 查询已有库存信息表对应sku数据
         List<CusAcqInventoryInfo03> listInveInfo = cusAcqInventoryInfoService03.listCusAcqInventoryInfo(listSku);
         Map<String, CusAcqInventoryInfo03> exitInveInfo = new HashMap<>();

+ 2 - 0
src/main/java/com/emato/cus/supervise/mapperCus/CusAcqInventoryInfoMapper03.java

@@ -21,6 +21,8 @@ public interface CusAcqInventoryInfoMapper03 {
      */
     int addAcqInventoryInfo03(List<CusAcqInventoryInfo03> list);
 
+    int deleteAcqInventoryInfo03(List<CusAcqInventoryInfo03> list);
+
     int updateAcqInventoryInfo03(List<CusAcqInventoryInfo03> list);
 
     List<CusAcqInventoryInfo03> listAcqInventoryInfo03(List<String> list);

+ 7 - 0
src/main/java/com/emato/cus/supervise/service/cus/CusAcqInventoryInfoService03.java

@@ -20,6 +20,13 @@ public interface CusAcqInventoryInfoService03 {
     int addCusAcqInventoryInfo(List<CusAcqInventoryInfo03> list);
 
     /**
+     * 删除库存数据
+     * @param list
+     * @return
+     */
+    int deleteCusAcqInventoryInfo(List<CusAcqInventoryInfo03> list);
+
+    /**
      * 更新库存数据
      * @param list
      * @return

+ 6 - 0
src/main/java/com/emato/cus/supervise/service/cus/impl/CusAcqInventoryInfoServiceImpl03.java

@@ -31,6 +31,12 @@ public class CusAcqInventoryInfoServiceImpl03 implements CusAcqInventoryInfoServ
 
     @Override
     @Transactional(value ="secondTransactionManager")
+    public int deleteCusAcqInventoryInfo(List<CusAcqInventoryInfo03> list) {
+        return cusAcqInventoryInfoMapper03.deleteAcqInventoryInfo03(list);
+    }
+
+    @Override
+    @Transactional(value ="secondTransactionManager")
     public int updateCusAcqInventoryInfo(List<CusAcqInventoryInfo03> list) {
         return cusAcqInventoryInfoMapper03.updateAcqInventoryInfo03(list);
     }

+ 46 - 41
src/main/resources/mybatis/mapper/wms-acq-inventory-info.xml

@@ -7,53 +7,58 @@
     <!-- WMS库存查询,作了库位转账册分类转换 -->
     <select id="getWmsAcqInventoryInfo" parameterType="java.util.Map"
             resultType="com.emato.cus.supervise.domain.WmsAcqInventoryInfo">
+
 		SELECT
-			emsClassCode, skuNo, goodsId, SUM(gQty) AS gQty,
+			emsClassCode,
+			skuNo,
+			goodsId,
+			SUM(gQty) AS gQty,
 			merchSn,
 			goodsName,
 			goodsModel,
 			storeCode
 		FROM (
-			SELECT
-				(CASE
-					WHEN (left(a.seatNo, 2) = 'ZS') THEN 'zszc'
-					WHEN (left(a.seatNo, 2) = 'F-') THEN 'fbwl'
-					ELSE 'kjds' END) as emsClassCode,
-				seatNo,
-				skuNo,
-				goodsId,
-				gQty,
-				merchSn,
-				goodsName,
-				goodsModel,
-				storeCode
-			FROM
-				(SELECT DISTINCT
-					th.zone,
-					th.companyCode AS merchSn,
-					th.locationCode AS seatNo,
-					th.itemName AS goodsName,
-					th.itemCode AS skuNo,
-					th.itemCode AS goodsId,
-					i.unitDesc AS gUnit,
-					( case when (li.qty is null and th.afterOnHandQty = 0) or (li.qty is not null and th.afterOnHandQty = li.qty) then th.afterOnHandQty
-						else li.qty end)  AS gQty,
-					th.warehouseCode AS storeCode,
-					CONCAT( i.itemSize, '-', i.itemColor, '-', i.itemStyle ) AS goodsModel
-				FROM
-					transaction_history th
-					LEFT OUTER JOIN ( SELECT itemCode, locationCode, SUM( onHandQty ) AS qty FROM location_inventory GROUP BY itemCode, locationCode ) AS li ON
-					th.itemCode = li.itemCode AND th.locationCode = li.locationCode
-					LEFT OUTER JOIN item i ON th.itemCode = i.CODE
-				WHERE
-					1 = 1
-					AND th.zone IN ( 'A区', 'B区', 'C区', 'GQ区', 'F区', 'P区', 'Y区', 'ZS')
-						<if test="thisTime != null">
-							and th.lastUpdated &gt;= #{thisTime}
-						</if>
-					ORDER BY th.lastUpdated DESC
-				) AS a GROUP BY seatNo, skuNo
-		) as b GROUP BY emsClassCode, skuNo;
+				 SELECT
+					 (CASE
+						  WHEN (left(a.seatNo, 2) = 'ZS') THEN 'zszc'
+						  WHEN (left(a.seatNo, 2) = 'F-') THEN 'fbwl'
+						  ELSE 'kjds' END) as emsClassCode,
+					 seatNo,
+					 skuNo,
+					 goodsId,
+					 gQty,
+					 merchSn,
+					 goodsName,
+					 goodsModel,
+					 storeCode
+				 FROM
+					 (SELECT distinct
+						  th.zone,
+						  th.companyCode AS merchSn,
+						  th.locationCode AS seatNo,
+						  th.itemName AS goodsName,
+						  th.itemCode AS skuNo,
+						  th.itemCode AS goodsId,
+						  i.unitDesc AS gUnit,
+						  ( case when (li.qty is null and th.afterOnHandQty = 0) or (li.qty is not null and th.afterOnHandQty = li.qty) then th.afterOnHandQty
+								 else li.qty end)  AS gQty,
+						  th.warehouseCode AS storeCode,
+						  CONCAT( i.itemSize, '-', i.itemColor, '-', i.itemStyle ) AS goodsModel
+					  FROM
+						  transaction_history th
+							  LEFT OUTER JOIN ( SELECT itemCode, locationCode, SUM( onHandQty ) AS qty
+												FROM location_inventory
+												GROUP BY itemCode, locationCode ) AS li
+											  ON th.itemCode = li.itemCode AND th.locationCode = li.locationCode
+							  LEFT OUTER JOIN item i ON th.itemCode = i.CODE
+					  WHERE
+						  1 = 1
+						AND th.zone IN ( 'A区', 'B区', 'C区', 'GQ区', 'F区', 'P区', 'Y区', 'ZS')
+						and th.created >= '2019-01-01 00:00:00'
+						  /*and th.itemCode = 'bj1510081058'*/
+					  ORDER BY th.lastUpdated DESC
+					 ) AS a where a.gQty is not null GROUP BY seatNo, skuNo
+			 ) as b GROUP BY emsClassCode, skuNo;
 	</select>
 
 

+ 11 - 0
src/main/resources/mybatis/mapperCus/cus-acq-inventory-info.xml

@@ -63,6 +63,17 @@
         </foreach>
     </insert>
 
+    <delete id="deleteAcqInventoryInfo03" parameterType="List">
+        delete from acq_inventory_info
+        <where>
+            <if test="list != null and list.size()>0">
+                <foreach collection="list" item="i" index="index" separator="or" >
+                    sku_no=#{i.skuNo} and local_ems_no=#{i.localEmsNo}
+                </foreach>
+            </if>
+        </where>
+    </delete>
+
     <update id="updateAcqInventoryInfo03" parameterType="List">
         UPDATE acq_inventory_info
         <trim prefix="set" suffixOverrides=",">