Procházet zdrojové kódy

xwh修改所有商品导入模板,增加plu和mychemId

xwh před 4 roky
rodič
revize
a2676c5566

+ 7 - 0
kmall-admin/pom.xml

@@ -129,6 +129,13 @@
             <version>1.9.7</version>
         </dependency>
 
+        <!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.5.1</version>
+        </dependency>
+
 
     </dependencies>
 

+ 27 - 10
kmall-admin/src/main/java/com/kmall/admin/Test.java

@@ -12,7 +12,14 @@
  */
 package com.kmall.admin;
 
-import org.springframework.web.util.HtmlUtils;
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpUtil;
+import com.alibaba.fastjson.JSON;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 名称:Test <br>
@@ -24,18 +31,28 @@ import org.springframework.web.util.HtmlUtils;
  */
 public class Test {
     public static void main(String[] args) {
-        //Integer使用equals判断
-//        Integer a = 127;
-//        Integer b = 127;
-//        System.out.println(a == b);
-//        Integer c = 129;
-//        Integer d = 129;
-//        System.out.println(c == d);
+        Map params = new HashMap();
+//        Map header = new HashMap();
+//        header.put("Content-Type", "application/json");
+        List<String> skuList = new ArrayList<String>();
+        skuList.add("ISGDKK175117");
+        skuList.add("ISTH01000185");
+        params.put("skuList",skuList);
+//
+//        String result = HttpUtil.URLPost("http://127.0.0.1:8080/oms-controller-mgt/pdProductRecord/hsCodeMapBySkuList",header, params, "UTF-8");
 //
-//        System.out.println(c.equals(d));
+//        System.out.println(result);
+
 
+//        System.out.println();
+//        String result = HttpUtil.post("http://127.0.0.1:8080/oms-controller-mgt/pdProductRecord/hsCodeMapBySkuList", JSON.toJSONString(params));
+//        HttpRequest post = HttpUtil.createPost();
+        String result = HttpUtil.get("http://127.0.0.1:8080/oms-controller-mgt/pdProductRecord/hsCodeMapBySkuList?skuList=" + skuList);
+        Map<String,Map> map = JSON.parseObject(result, Map.class);
+        Map<String,String> isgdkk175117 = map.get("ISGDKK175117");
+        System.out.println(isgdkk175117.get("cusGoodsName"));
+        System.out.println(result);
 
-        System.out.println(HtmlUtils.htmlUnescape("Baby&amp;Children"));
 
     }
 }

+ 5 - 0
kmall-admin/src/main/java/com/kmall/admin/dao/GoodsDao.java

@@ -62,4 +62,9 @@ public interface GoodsDao extends BaseDao<GoodsEntity> {
     List<GoodsEntity> queryListByBarcode(@Param("prodBarcode")String prodBarcode, @Param("storeId")Integer storeId);
 
     List<GoodsEntity> queryByName(@Param("goodsName")String goodsName);
+
+
+    List<String> queryNonSyncOmsHsCodeSkuList();
+
+    List<GoodsEntity> queryListBySku(String sku);
 }

+ 11 - 0
kmall-admin/src/main/java/com/kmall/admin/entity/GoodsEntity.java

@@ -231,6 +231,17 @@ public class GoodsEntity implements Serializable {
 
     private String hsCodeName;
 
+
+    private String isSyncHsCode;
+
+    public String getIsSyncHsCode() {
+        return isSyncHsCode;
+    }
+
+    public void setIsSyncHsCode(String isSyncHsCode) {
+        this.isSyncHsCode = isSyncHsCode;
+    }
+
     public String getHsCode() {
         return hsCode;
     }

+ 2 - 0
kmall-admin/src/main/java/com/kmall/admin/service/GoodsService.java

@@ -191,4 +191,6 @@ public interface GoodsService {
      * @return
      */
     List<GoodsEntity> queryByName(String goodsName);
+
+    void syncOmsHsCode();
 }

+ 35 - 0
kmall-admin/src/main/java/com/kmall/admin/service/impl/GoodsServiceImpl.java

@@ -1,6 +1,8 @@
 package com.kmall.admin.service.impl;
 
+import cn.hutool.http.HttpUtil;
 import com.alibaba.druid.support.json.JSONUtils;
+import com.alibaba.fastjson.JSON;
 import com.google.common.collect.ImmutableBiMap;
 import com.google.common.collect.Maps;
 import com.kmall.admin.dao.*;
@@ -621,6 +623,7 @@ public class GoodsServiceImpl implements GoodsService {
         return goodsDao.queryByName(goodsName);
     }
 
+
     /**
      * 更新门店商品是否有修改字段
      * @param storeId
@@ -1797,4 +1800,36 @@ public class GoodsServiceImpl implements GoodsService {
     public GoodsEntity queryObjectBySn(String goodsSn) {
         return goodsDao.queryObjectBySn(goodsSn);
     }
+
+
+    @Override
+    @Transactional
+    public void syncOmsHsCode() {
+        List<String> skuList = goodsDao.queryNonSyncOmsHsCodeSkuList();
+        if (Objects.nonNull(skuList) && skuList.size()>0){
+            String result = HttpUtil.get("https://oms.ds-bay.com/oms-controller-mgt/pdProductRecord/hsCodeMapBySkuList?skuList=" + skuList);
+            Map<String,Map> map = JSON.parseObject(result, Map.class);
+
+            for (String sku : skuList) {
+                Map<String,String> skuInfoMap = map.get(sku);
+                if (Objects.nonNull(skuInfoMap)){
+                    String hsCodeName = skuInfoMap.get("cusGoodsName");
+                    String hsCode = skuInfoMap.get("cusGoodsCode");
+                    if (StringUtils.isNotEmpty(hsCodeName) && StringUtils.isNotEmpty(hsCode)){
+                        List<GoodsEntity> goodsEntityList = goodsDao.queryListBySku(sku);
+                        if (Objects.nonNull(goodsEntityList) && goodsEntityList.size()>0){
+                            for (GoodsEntity goodsEntity : goodsEntityList) {
+                                goodsEntity.setHsCode(hsCode);
+                                goodsEntity.setHsCodeName(hsCodeName);
+                                goodsEntity.setIsSyncHsCode("1");
+                                goodsDao.update(goodsEntity);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+    }
+
 }

+ 47 - 0
kmall-admin/src/main/java/com/kmall/admin/task/SyncOmsTask.java

@@ -0,0 +1,47 @@
+package com.kmall.admin.task;
+
+import com.kmall.admin.service.GoodsService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+/**
+ * 同步oms数据定时器
+ *
+ * @author 小问号
+ * @email 1076650290@qq.com
+ * @date 2020年11月30日15:33:57
+ */
+@Component("syncOmsTask")
+@EnableScheduling
+@EnableAsync
+public class SyncOmsTask {
+
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private GoodsService goodsService;
+
+
+    /**
+     * 同步oms海关备案编码
+     * 每天凌晨四点执行一次
+     */
+    @Scheduled(cron = "0 0 4 * * ?")
+    public void syncOmsHsCode() {
+        logger.info("同步所有商品表海关备案编码数据开始-----------------");
+        try {
+            goodsService.syncOmsHsCode();
+        } catch (Exception e) {
+            e.printStackTrace();
+            logger.info("同步所有商品表海关备案编码数据异常-----------------原因:" + e.getMessage());
+        }
+        logger.info("同步所有商品表海关备案编码数据结束-----------");
+
+    }
+
+}

+ 16 - 1
kmall-admin/src/main/resources/mybatis/mapper/GoodsDao.xml

@@ -74,6 +74,7 @@
         <result column="mychem_id" property="mychemId"/>
         <result column="hs_code" property="hsCode"/>
         <result column="hs_code_name" property="hsCodeName"/>
+        <result column="is_sync_hs_code" property="isSyncHsCode"/>
     </resultMap>
 
     <select id="queryObject" resultType="com.kmall.admin.entity.GoodsEntity">
@@ -504,6 +505,7 @@
 			`mychem_id`,
 			`hs_code`,
 			`hs_code_name`,
+			`is_sync_hs_code`,
 			`tstm`)
 		values(
 			#{merchSn},
@@ -559,6 +561,7 @@
 			#{mychemId},
 			#{hsCode},
 			#{hsCodeName},
+			'0',
 			#{tstm})
     </insert>
 
@@ -619,7 +622,8 @@
             <if test="lastSaleTime != null">`last_sale_time` = #{lastSaleTime},</if>
             <if test="mychemId != null">`mychem_id` = #{mychemId},</if>
             <if test="hsCode != null">`hs_code` = #{hsCode},</if>
-            <if test="hsCodeName != null">`hs_code_name` = #{hsCodeName}</if>
+            <if test="hsCodeName != null">`hs_code_name` = #{hsCodeName},</if>
+            <if test="isSyncHsCode != null">`is_sync_hs_code` = #{isSyncHsCode}</if>
         </set>
         where id = #{id}
     </update>
@@ -762,5 +766,16 @@
             and name like concat('%',#{goodsName},'%');
         </if>
     </select>
+    <select id="queryNonSyncOmsHsCodeSkuList" resultType="java.lang.String">
+        select sku
+        from mall_goods
+        where is_sync_hs_code = '0'
+    </select>
+    <select id="queryListBySku" resultType="com.kmall.admin.entity.GoodsEntity">
+         select *
+        from mall_goods
+        where sku = #{sku}
+    </select>
+
 
 </mapper>