From 2108f127fb7665e4cf7e7d6f92cfe274c31075a1 Mon Sep 17 00:00:00 2001
From: liuy <37787198+LiuyCodes@users.noreply.github.com>
Date: Mon, 17 Mar 2025 12:13:58 +0800
Subject: [PATCH] =?UTF-8?q?perf(buildpackage):=20=E4=BC=98=E5=8C=96=20OFS?=
 =?UTF-8?q?=20=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8=E6=80=A7=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- 在 queryOfsReturnGoods 和 queryOfsPoOrder 方法中添加同步锁,减少接口堵塞
-优化了接口调用逻辑,提高查询效率
- 调整了测试用例中的输入参数
---
 .../plugin/lets/util/OfsStandardUtil.java     | 104 ++++++++++--------
 .../ConsignmachiningCinfurmInTest.java        |   3 +-
 2 files changed, 59 insertions(+), 48 deletions(-)

diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/OfsStandardUtil.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/OfsStandardUtil.java
index b239ed8b..771a5968 100644
--- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/OfsStandardUtil.java
+++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/OfsStandardUtil.java
@@ -83,6 +83,8 @@ public class OfsStandardUtil {
         }
     }
 
+    private static final Object queryOfsReturnGoodsLock = new Object();
+
     /**
      * OFS入库单查询
      *
@@ -93,31 +95,34 @@ public class OfsStandardUtil {
      * @author liuyang
      */
     public void queryOfsReturnGoods(QueryOfsSoSaleOutVo queryOfsSoSaleOutVo, List<StockinOrderSearchResponse.StockinOrder> headerDetailsDtoList, Long pageNo, String api) throws Exception {
-        Assert.notNull(queryOfsSoSaleOutVo, "queryOfsSoSaleOutVo不能为空!");
-        Assert.notNull(headerDetailsDtoList, "headerDetailsDtoList不能为空");
-        Assert.notNull(pageNo, "pageNo不能为空");
-        Assert.notNull(api, "api不能为空");
+        //减少 O 接口堵塞,临时解决办法
+        synchronized (queryOfsReturnGoodsLock) {
+            Assert.notNull(queryOfsSoSaleOutVo, "queryOfsSoSaleOutVo不能为空!");
+            Assert.notNull(headerDetailsDtoList, "headerDetailsDtoList不能为空");
+            Assert.notNull(pageNo, "pageNo不能为空");
+            Assert.notNull(api, "api不能为空");
 
-        Long pageSize = 200L;
-        queryOfsSoSaleOutVo.setPageNo(pageNo);
-        queryOfsSoSaleOutVo.setPageSize(pageSize);
+            Long pageSize = 200L;
+            queryOfsSoSaleOutVo.setPageNo(pageNo);
+            queryOfsSoSaleOutVo.setPageSize(pageSize);
 
-        InterfaceParamDto interfaceParamDto = new InterfaceParamDto();
-        interfaceParamDto.setApi(api);
-        interfaceParamDto.setData(JSON.toJSONString(queryOfsSoSaleOutVo));
-        StockinOrderSearchResponse rertunGoodsRootBean = (StockinOrderSearchResponse) ofsUnifiedService.unified(interfaceParamDto);
-        if (rertunGoodsRootBean != null) {
-            if ("false".equals(rertunGoodsRootBean.getError()) && "0".equals(rertunGoodsRootBean.getCode()) && "Success".equals(rertunGoodsRootBean.getMsg())) {
-                List<StockinOrderSearchResponse.StockinOrder> stockinOrderList = rertunGoodsRootBean.getData();
-                if (stockinOrderList != null && stockinOrderList.size() > 0) {
-                    headerDetailsDtoList.addAll(stockinOrderList);
-                    queryOfsReturnGoods(queryOfsSoSaleOutVo, headerDetailsDtoList, ++pageNo, api);
+            InterfaceParamDto interfaceParamDto = new InterfaceParamDto();
+            interfaceParamDto.setApi(api);
+            interfaceParamDto.setData(JSON.toJSONString(queryOfsSoSaleOutVo));
+            StockinOrderSearchResponse rertunGoodsRootBean = (StockinOrderSearchResponse) ofsUnifiedService.unified(interfaceParamDto);
+            if (rertunGoodsRootBean != null) {
+                if ("false".equals(rertunGoodsRootBean.getError()) && "0".equals(rertunGoodsRootBean.getCode()) && "Success".equals(rertunGoodsRootBean.getMsg())) {
+                    List<StockinOrderSearchResponse.StockinOrder> stockinOrderList = rertunGoodsRootBean.getData();
+                    if (stockinOrderList != null && stockinOrderList.size() > 0) {
+                        headerDetailsDtoList.addAll(stockinOrderList);
+                        queryOfsReturnGoods(queryOfsSoSaleOutVo, headerDetailsDtoList, ++pageNo, api);
+                    }
+                } else {
+                    logger.error("查询失败,失败原因:{}", JSON.toJSON(interfaceParamDto));
                 }
             } else {
-                logger.error("查询失败,失败原因:{}", JSON.toJSON(interfaceParamDto));
+                logger.error("rertunGoodsRootBean为空!interfaceParamDto对象的结果集json:{}", JSON.toJSON(interfaceParamDto));
             }
-        } else {
-            logger.error("rertunGoodsRootBean为空!interfaceParamDto对象的结果集json:{}", JSON.toJSON(interfaceParamDto));
         }
     }
 
@@ -155,49 +160,54 @@ public class OfsStandardUtil {
         }
     }
 
+    private static final Object queryOfsPoOrderlock = new Object();
+
     /**
      * 2024年8月20日 16:11:46 查询OFS采购订单
      *
      * @author liuyang
      */
     public OfsPoOrderData queryOfsPoOrder(String code) throws Exception {
-        if (code != null && !"".equals(code)) {
-            Long pageSize = 200L;
-            Long pageNo = 1L;
+        //减少 O 接口堵塞,临时解决办法
+        synchronized (queryOfsPoOrderlock) {
+            if (code != null && !"".equals(code)) {
+                Long pageSize = 200L;
+                Long pageNo = 1L;
 
-            QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo();
-            queryOfsSoSaleOutVo.setPageNo(pageNo);
-            queryOfsSoSaleOutVo.setPageSize(pageSize);
-            queryOfsSoSaleOutVo.setCode(code);
+                QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo();
+                queryOfsSoSaleOutVo.setPageNo(pageNo);
+                queryOfsSoSaleOutVo.setPageSize(pageSize);
+                queryOfsSoSaleOutVo.setCode(code);
 
-            InterfaceParamDto interfaceParamDto = new InterfaceParamDto();
-            interfaceParamDto.setApi("ofs.purchaseOrder.search");
-            interfaceParamDto.setData(JSON.toJSONString(queryOfsSoSaleOutVo));
-            OfsPoOrderBean ofsPoOrderBean = (OfsPoOrderBean) ofsUnifiedService.unified(interfaceParamDto);
-            if (ofsPoOrderBean != null) {
-                if ("false".equals(ofsPoOrderBean.getError()) && "0".equals(ofsPoOrderBean.getCode()) && "Success".equals(ofsPoOrderBean.getMsg())) {
-                    List<OfsPoOrderData> data = ofsPoOrderBean.getData();
-                    if (data != null && data.size() > 0) {
-                        OfsPoOrderData ofsPoOrderData = data.get(0);
-                        Assert.notNull(ofsPoOrderData, "OFS采购订单无法解析json!");
+                InterfaceParamDto interfaceParamDto = new InterfaceParamDto();
+                interfaceParamDto.setApi("ofs.purchaseOrder.search");
+                interfaceParamDto.setData(JSON.toJSONString(queryOfsSoSaleOutVo));
+                OfsPoOrderBean ofsPoOrderBean = (OfsPoOrderBean) ofsUnifiedService.unified(interfaceParamDto);
+                if (ofsPoOrderBean != null) {
+                    if ("false".equals(ofsPoOrderBean.getError()) && "0".equals(ofsPoOrderBean.getCode()) && "Success".equals(ofsPoOrderBean.getMsg())) {
+                        List<OfsPoOrderData> data = ofsPoOrderBean.getData();
+                        if (data != null && data.size() > 0) {
+                            OfsPoOrderData ofsPoOrderData = data.get(0);
+                            Assert.notNull(ofsPoOrderData, "OFS采购订单无法解析json!");
 
-                        OfsPoOrderHeader header = ofsPoOrderData.getHeader();
-                        Assert.notNull(header, "表头对象不能为空!");
+                            OfsPoOrderHeader header = ofsPoOrderData.getHeader();
+                            Assert.notNull(header, "表头对象不能为空!");
 
-                        List<OfsPoOrderDetails> details = ofsPoOrderData.getDetails();
-                        Assert.notNull(details, "明细对象不能为空");
-                        return data.get(0);
+                            List<OfsPoOrderDetails> details = ofsPoOrderData.getDetails();
+                            Assert.notNull(details, "明细对象不能为空");
+                            return data.get(0);
+                        }
+                    } else {
+                        logger.error("查询采购订单失败,失败原因:{}", JSON.toJSON(interfaceParamDto));
                     }
                 } else {
-                    logger.error("查询采购订单失败,失败原因:{}", JSON.toJSON(interfaceParamDto));
+                    logger.error("ofsPoOrderBean为空!interfaceParamDto接口入参:{}", JSON.toJSON(interfaceParamDto));
                 }
             } else {
-                logger.error("ofsPoOrderBean为空!interfaceParamDto接口入参:{}", JSON.toJSON(interfaceParamDto));
+                Assert.state(false, "采购订单编码不能为空!");
             }
-        } else {
-            Assert.state(false, "采购订单编码不能为空!");
+            return null;
         }
-        return null;
     }
 
     /**
diff --git a/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/outsourc/ConsignmachiningCinfurmInTest.java b/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/outsourc/ConsignmachiningCinfurmInTest.java
index 50a3cf81..93ef10cf 100644
--- a/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/outsourc/ConsignmachiningCinfurmInTest.java
+++ b/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/outsourc/ConsignmachiningCinfurmInTest.java
@@ -29,7 +29,8 @@ public class ConsignmachiningCinfurmInTest {
         try {
 //            consignmachiningCinfurmIn.startImplementByTime("2024-01-02 00:00:00", "2024-01-02 23:59:59");
 
-            String code = "LETS-RE2024111400002771-confirm";
+//            String code = "LETS-RE2024111400002771-confirm";
+            String code = "LETS-RE2025022800002706-confirm";
             consignmachiningCinfurmIn.startImplementByCode(code);
         } catch (Exception e) {
             e.printStackTrace();