Browse Source

-- 中间表数据存储优化
-- 中间表数据写入提供对外接口

stars 1 năm trước cách đây
mục cha
commit
287a3a84ec

+ 30 - 0
src/main/java/com/warewms/controller/ErpWriteBackController.java

@@ -0,0 +1,30 @@
+package com.warewms.controller;
+
+import com.warewms.common.utils.R;
+import com.warewms.entity.erp.ErpBarCodeList;
+import com.warewms.service.impl.ErpSyncServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@Controller
+@RequestMapping("/sys/erpWriteData")
+@Slf4j
+public class ErpWriteBackController {
+
+    @Autowired
+    private ErpSyncServiceImpl erpSyncService;
+
+    /**
+     * 中间表写入数据
+     */
+    @ResponseBody
+    @PostMapping("writeData")
+    public R writeData(@RequestParam List<ErpBarCodeList> erpBarCodeListList){
+        erpSyncService.writeBack(erpBarCodeListList);
+        return R.ok();
+    }
+}

+ 22 - 5
src/main/java/com/warewms/service/impl/ErpSyncServiceImpl.java

@@ -1,14 +1,17 @@
 package com.warewms.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.jfinal.kit.Kv;
 import com.jfinal.plugin.activerecord.Db;
 import com.jfinal.plugin.activerecord.Record;
 import com.jfinal.plugin.activerecord.SqlPara;
 import com.warewms.common.annotation.JFinalTx;
+import com.warewms.common.exception.RRException;
 import com.warewms.common.utils.RecordUtils;
 import com.warewms.entity.erp.*;
 import com.warewms.service.ErpSyncService;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Service;
@@ -31,7 +34,10 @@ public class ErpSyncServiceImpl implements ErpSyncService {
         SqlPara sqlParaOb = Db.getSqlPara("erp.selectProOb");
         List<Record> recordObList = Db.find(sqlParaOb);
         List<ErpProOb> erpProObList = RecordUtils.converModel(recordObList, ErpProOb.class);
-        if (erpProObList != null && erpProObList.size() > 0) {
+        //根据KEY 获取对应的 redis存储的value,存储数据为空进行新的存储
+        String getErpProOb = redisTemplate.opsForValue().get("erpProOb");
+
+        if (erpProObList != null && erpProObList.size() > 0 && StringUtils.isEmpty(getErpProOb)) {
             for (ErpProOb erpProOb : erpProObList) {
                 Kv param = Kv.create();
                 param.put("ima01", erpProOb.getIma01());
@@ -44,7 +50,10 @@ public class ErpSyncServiceImpl implements ErpSyncService {
         // 产品类型基础表 ERP_PRO_TYPE
         SqlPara sqlPara = Db.getSqlPara("erp.selectProType");
         List<Record> recordList = Db.find(sqlPara);
-        if (recordList != null && recordList.size() > 0) {
+        //根据KEY 获取对应的 redis存储的value,存储数据为空进行新的存储
+        String getErpProType = redisTemplate.opsForValue().get("erpProType");
+
+        if (recordList != null && recordList.size() > 0 && StringUtils.isEmpty(getErpProType)) {
             List<ErpProType> list = new ArrayList<>();
             for (Record record : recordList) {
                 ErpProType proType = new ErpProType();
@@ -64,7 +73,10 @@ public class ErpSyncServiceImpl implements ErpSyncService {
         SqlPara sqlParaBarCode = Db.getSqlPara("erp.selectBarCode");
         List<Record> recordBarCodeList = Db.find(sqlParaBarCode);
         List<ErpProBarCode> erpBarCodeList = RecordUtils.converModel(recordBarCodeList, ErpProBarCode.class);
-        if (erpBarCodeList != null && erpBarCodeList.size() > 0) {
+        //根据KEY 获取对应的 redis存储的value,存储数据为空进行新的存储
+        String getErpBarCode = redisTemplate.opsForValue().get("erpBarCode");
+
+        if (erpBarCodeList != null && erpBarCodeList.size() > 0 && StringUtils.isEmpty(getErpBarCode)) {
             for (ErpProBarCode erpProBarCode : erpBarCodeList) {
                 Kv param = Kv.create();
                 param.put("barcode", erpProBarCode.getBarcode());
@@ -78,7 +90,10 @@ public class ErpSyncServiceImpl implements ErpSyncService {
         SqlPara sqlParaOrderList = Db.getSqlPara("erp.selectOrderList");
         List<Record> recordOrderList = Db.find(sqlParaOrderList);
         List<ErpOrderList> erpOrderLists = RecordUtils.converModel(recordOrderList, ErpOrderList.class);
-        if (erpOrderLists != null && erpOrderLists.size() > 0) {
+        //根据KEY 获取对应的 redis存储的value,存储数据为空进行新的存储
+        String getErpOrderList = redisTemplate.opsForValue().get("erpOrderList");
+
+        if (erpOrderLists != null && erpOrderLists.size() > 0 && StringUtils.isEmpty(getErpOrderList)) {
             for (ErpOrderList erpOrderList : erpOrderLists) {
                 Kv param = Kv.create();
                 param.put("orderNo", erpOrderList.getOrderNo());
@@ -107,7 +122,9 @@ public class ErpSyncServiceImpl implements ErpSyncService {
             param.set("createDate",erpBarCodeList.getCreateDate());
             param.set("wmsMark","N");
             SqlPara sqlPara = Db.getSqlPara("erp.insertBarcodeList",param);
-            Db.update(sqlPara);
+            if (Db.update(sqlPara) == 0) {
+                throw new RRException("writeBack失败!");
+            }
         }
     }
 }