From 954480166aad6d24c9e9889906a0edf762f0da2a Mon Sep 17 00:00:00 2001
From: czt <czt18638530771@163.com>
Date: 星期一, 10 二月 2025 16:32:56 +0800
Subject: [PATCH] 优化库存同步

---
 src/main/java/com/fzzy/otherview/whhpjl/pr/WhjlApi1106PR.java |  154 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 154 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/fzzy/otherview/whhpjl/pr/WhjlApi1106PR.java b/src/main/java/com/fzzy/otherview/whhpjl/pr/WhjlApi1106PR.java
new file mode 100644
index 0000000..af27ebf
--- /dev/null
+++ b/src/main/java/com/fzzy/otherview/whhpjl/pr/WhjlApi1106PR.java
@@ -0,0 +1,154 @@
+package com.fzzy.otherview.whhpjl.pr;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.bstek.dorado.annotation.DataProvider;
+import com.bstek.dorado.annotation.DataResolver;
+import com.bstek.dorado.annotation.Expose;
+import com.fzzy.api.Constant;
+import com.fzzy.api.data.ApiParam;
+import com.fzzy.api.dto.ResponseDto;
+import com.fzzy.api.entity.ApiConfs;
+import com.fzzy.api.entity.ApiInfoData;
+import com.fzzy.api.service.ApiCommonService;
+import com.fzzy.api.service.ApiPushManager;
+import com.fzzy.api.service.ApiRemoteService;
+import com.fzzy.api.view.repository.ApiInfoDataRep;
+import com.fzzy.otherview.whhpjl.WhjlConstant;
+import com.fzzy.otherview.whhpjl.dto.WhjlApi1106;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @Author: YYC
+ * @Description:娌圭綈淇℃伅
+ * @DateTime: 2023-10-25 14:13
+ **/
+@Component
+public class WhjlApi1106PR {
+
+    @Autowired
+    private ApiCommonService apiCommonService;
+    @Autowired
+    private ApiPushManager apiPushManager;
+    @Autowired
+    private ApiInfoDataRep apiInfoDataRep;
+
+    /**
+     * 鑾峰彇鍒楄〃淇℃伅
+     * WhjlApi1106PR#listData
+     *
+     * @return
+     */
+    @DataProvider
+    public List<WhjlApi1106> listData() {
+        List<ApiInfoData> result = apiInfoDataRep.getDataByInteId(WhjlConstant.API_CODE_1106);
+        if (null == result || result.isEmpty()) {
+            return null;
+        }
+        List<WhjlApi1106> list = new ArrayList<>();
+        WhjlApi1106 whjlApi1106;
+        for (ApiInfoData infoData : result) {
+            whjlApi1106 = JSONObject.parseObject(infoData.getData(), WhjlApi1106.class);
+            whjlApi1106.setKqdm(infoData.getKqdm());
+            whjlApi1106.setCzbz(infoData.getCzbz());
+            whjlApi1106.setUpdateTime(infoData.getUpdateTime());
+            whjlApi1106.setBizId(infoData.getDataId());
+            list.add(whjlApi1106);
+        }
+        return list;
+    }
+
+    /**
+     * 鏇存柊鎴栦慨鏀�
+     * WhjlApi1106PR#saveData
+     *
+     * @param data
+     * @return
+     */
+    @DataResolver
+    public void saveData(WhjlApi1106 data) {
+        ApiInfoData infoData = new ApiInfoData();
+        infoData.setId(data.getBizId());
+        infoData.setKqdm(data.getKqdm());
+        infoData.setInteType(WhjlConstant.API_CATEGORY_11);
+        infoData.setInteId(WhjlConstant.API_CODE_1106);
+        infoData.setUpdateTime(new Date());
+        infoData.setDataId(data.getBizId());
+        infoData.setData(JSON.toJSONString(data));
+        infoData.setCzbz(data.getCzbz());
+        infoData.setRemarks("澶囨敞淇℃伅");
+
+        apiInfoDataRep.save(infoData);
+    }
+
+    /**
+     * 鍒犻櫎
+     * WhjlApi1106PR#delData
+     *
+     * @param data
+     * @return
+     */
+    @Expose
+    public String delData(WhjlApi1106 data) {
+        apiInfoDataRep.deleteById(data.getBizId());
+        return null;
+    }
+
+    /**
+     * 涓婁紶
+     * WhjlApi1106PR#pushData
+     *
+     * @param items
+     * @return
+     */
+    @Expose
+    public String pushData(List<WhjlApi1106> items) {
+
+        String result = "";
+
+        String kqdm = items.get(0).getKqdm();
+        ApiConfs apiConf = apiCommonService.getConf(kqdm);
+
+        if (null == apiConf) {
+            return "绯荤粺娌℃湁鑾峰彇鍒板綋鍓嶅簱鍖洪厤缃俊鎭紝鎵ц澶辫触";
+        }
+
+        //灏佽鍙傛暟
+        ApiParam param = new ApiParam(apiConf, WhjlConstant.API_CATEGORY_11, WhjlConstant.API_CODE_1106);
+
+        //鑾峰彇瀹炵幇鎺ュ彛
+        ApiRemoteService apiService = apiPushManager.getApiRemoteService(param.getPushProtocol());
+        if (null == apiService) {
+            return "绯荤粺娌℃湁褰撳墠鎺ㄩ�佸崗璁厤缃紝鎵ц澶辫触";
+        }
+
+        ResponseDto responseDto;
+        ApiInfoData infoData;
+        for (WhjlApi1106 data : items) {
+            responseDto = apiService.pushData(param, apiConf, data);
+            if (responseDto.getSuccess() == 0) {
+                if (Constant.CZBZ_I.equals(data.getCzbz())) {
+                    infoData = new ApiInfoData();
+                    infoData.setId(data.getBizId());
+                    infoData.setKqdm(data.getKqdm());
+                    infoData.setInteType(WhjlConstant.API_CATEGORY_11);
+                    infoData.setInteId(WhjlConstant.API_CODE_1106);
+                    infoData.setUpdateTime(new Date());
+                    infoData.setDataId(data.getBizId());
+
+                    data.setCzbz(Constant.CZBZ_U);
+                    infoData.setCzbz(Constant.CZBZ_U);
+                    infoData.setData(JSON.toJSONString(data));
+                    apiInfoDataRep.save(infoData);
+                }
+            }
+            result += responseDto.toString();
+        }
+        return result;
+    }
+}

--
Gitblit v1.9.3