From 1289e6e0d6a781ed5b55e28bd158faa5b321c3b8 Mon Sep 17 00:00:00 2001 From: zhaoqiaobo <583671871@qq.com> Date: Fri, 25 Oct 2024 15:40:58 +0800 Subject: [PATCH] =?UTF-8?q?feat(all):=20=E4=BF=AE=E6=94=B9=E9=87=91?= =?UTF-8?q?=E7=89=8C=E6=89=8B=E5=8A=A8=E5=9B=9E=E6=8E=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1 增加金牌手动回推时老数据查不到的情况,增加去老系统查询的逻辑 --- .../jinpai/mq/NodeDataPushListener.java | 266 ++++++++++-------- .../jinpai/pros/JinPaiProperties.java | 4 + 2 files changed, 149 insertions(+), 121 deletions(-) diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mq/NodeDataPushListener.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mq/NodeDataPushListener.java index c7bb5034e..0f28c8fcb 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mq/NodeDataPushListener.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mq/NodeDataPushListener.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.UUID; import cn.hutool.core.util.EnumUtil; +import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpUtil; @@ -98,134 +99,157 @@ public class NodeDataPushListener { log.info("订单数据为空,不处理:{}", JSONUtil.toJsonStr(content)); return; } - List orderDetailEntities = pushOrderDetailService.list(Wrappers.lambdaQuery() - .in(PushOrderDetailEntity::getCustomItemNo, orderCodes) - ); - if (CollUtil.isEmpty(orderDetailEntities)) { - log.info("未查到包件数据,不处理:{}", JSONUtil.toJsonStr(content)); - return; - } - Map orderCodeMap = orderDetailEntities.stream().collect(Collectors.toMap(PushOrderDetailEntity::getOrderId, PushOrderDetailEntity::getCustomItemNo)); - Map detailEntityMap = orderDetailEntities.stream().collect(Collectors.toMap(PushOrderDetailEntity::getCustomItemNo, v -> v)); - List orderIds = orderDetailEntities.stream().map(PushOrderDetailEntity::getOrderId).collect(Collectors.toList()); - Map pushOrderEntityMap = new HashMap<>(); - if (CollUtil.isNotEmpty(orderIds)) { - List pushOrderEntities = pushOrderService.listByIds(orderIds); - if (CollUtil.isNotEmpty(pushOrderEntities)) { - pushOrderEntities.forEach(pushOrderEntity -> { - pushOrderEntityMap.put(orderCodeMap.get(pushOrderEntity.getId().toString()), pushOrderEntity); - }); - } - } - List pushEntities = factoryNodePushService.list(Wrappers.lambdaQuery() - .in(FactoryNodePushEntity::getOrderCode, orderCodes) - ); - // 到站还是入库 - if (workNodeEnums.equals(WorkNodeEnums.FINAL_NET_ARRIVE_CAR)) { - Map pushEntityMap = new HashMap<>(); - if (CollUtil.isNotEmpty(pushEntities)) { - pushEntityMap = pushEntities.stream().filter(pushEntity -> { - return StrUtil.equals(pushEntity.getNode(),FactoryNodeEnums.FINAL_NET_ARRIVE_CAR.getCode().toString()); - }).collect(Collectors.toMap(FactoryNodePushEntity::getOrderCode, v -> v)); - } - JSONObject mainJson = JSONUtil.parseObj(main); - // 到站 一个订单只发送一次 - for (String orderCode : orderCodes) { - if (pushEntityMap.containsKey(orderCode)) { - continue; - } - PushOrderDetailEntity pushOrderDetailEntity = detailEntityMap.get(orderCode); - String boxCodeList = pushOrderDetailEntity.getBoxCodeList(); - JSONArray boxCodeListJson = JSONUtil.parseArray(boxCodeList); - // JSONArray details = new JSONArray(); - JSONObject detail = new JSONObject(); - boxCodeListJson.forEach(item -> { - // JSONObject jsonObject = new JSONObject(); - detail.set(item.toString(), 1); - // details.add(jsonObject); - }); - if (!CollUtil.contains(pushEntityMap.keySet(), orderCode)) { - JSONObject js = new JSONObject(); - js.set("extOrderNo", orderCode); - js.set("extWaybillNO", mainJson.getStr("serviceNumber")); - js.set("detail", detail); - js.set("shipNo", mainJson.getStr("waybillNumber")); - js.set("targetNo", pushOrderEntityMap.get(orderCode).getTransportNo()); - js.set("targetType", "1"); - js.set("doType", "32"); - js.set("doLocation", ""); - js.set("doTime", DateUtil.now()); - js.set("sendSite", mainJson.getStr("sendWarehouseName")); - js.set("endSite", mainJson.getStr("warehouseName")); - js.set("passSite", mainJson.getStr("acceptWarehouseName")); - js.set("doRemark", ""); - js.set("reqSn", pushOrderEntityMap.get(orderCode).getId()); - js.set("syscode", "huitong"); - js.set("carNo", mainJson.getStr("carNumber")); - js.set("carHangNo", ""); - js.set("driverName", mainJson.getStr("driverName")); - js.set("driverPhone", mainJson.getStr("driverMobile")); - js.set("carType", "A"); - js.set("carSize", "1"); - // js.set("arriveFor", ""); - log.info("推送工厂:{}", js); - String url = jinPaiProperties.getOldSystemHost() + jinPaiProperties.getOldSystemArrivedUrl(); + for (String sendOrderCode : orderCodes) { + // 先从新系统查,如果查不到,去老系统查一次 + List orderDetailEntities = pushOrderDetailService.list(Wrappers.lambdaQuery() + .in(PushOrderDetailEntity::getCustomItemNo, sendOrderCode) + ); + if (CollUtil.isEmpty(orderDetailEntities)) { + // 去老系统查 + if(StrUtil.isNotEmpty(jinPaiProperties.getOldSystemHost()) && StrUtil.isNotEmpty(jinPaiProperties.getFindOldDataUrl())){ try { - if (jinPaiProperties.getEnable()) { - String result = HttpUtil.post(url, JSONUtil.toJsonStr(js)); - log.info("推送工厂结果:{}", result); - // 保存推送记录 - factoryNodePushService.save(FactoryNodePushEntity.builder() - .orderCode(orderCode) - .node(FactoryNodeEnums.FINAL_NET_ARRIVE_CAR.getCode().toString()) - .content(JSONUtil.toJsonStr(js)) - .resultContent(result) - .build()); + String result = HttpUtil.get(jinPaiProperties.getOldSystemHost() + jinPaiProperties.getFindOldDataUrl() + "?orderCode=" + sendOrderCode); + if(StrUtil.isNotEmpty(result)){ + JSONObject jsonObject = JSONUtil.parseObj(result); + Integer code = jsonObject.getInt("code"); + if(NumberUtil.equals(code, 200)){ + JSONArray data = jsonObject.getJSONArray("data"); + if (CollUtil.isNotEmpty(data)) { + orderDetailEntities = data.toList(PushOrderDetailEntity.class); + } + } } - } catch (Exception e) { - log.error("推送工厂失败:{}", e); + }catch (Exception e){ + log.error("老系统查询失败",e); } } } - } else { - // 入库一个包件一次 - Map pushEntityMap = new HashMap<>(); - if (CollUtil.isNotEmpty(pushEntities)) { - pushEntityMap = pushEntities.stream().filter(pushEntity -> { - return StrUtil.equals(pushEntity.getNode(),FactoryNodeEnums.END_WAREHOUSE_UNLOADING.getCode().toString()); - }).collect(Collectors.toMap(FactoryNodePushEntity::getPackageCode, v -> v)); + if (CollUtil.isEmpty(orderDetailEntities)) { + log.info("未查到包件数据,不处理:{}", JSONUtil.toJsonStr(content)); + return; } - for (PushData pushData : content) { - if (!CollUtil.contains(pushEntityMap.keySet(), pushData.getPackageCode())) { - JSONObject js = new JSONObject(); - js.set("extOrderNo", pushData.getOrderCode()); - js.set("extWaybillNO", detailEntityMap.get(pushData.getOrderCode()).getCustomOrderNo()); - js.set("transportNo", pushOrderEntityMap.get(pushData.getOrderCode()).getTransportNo()); - js.set("doTime", entries.getStr("operatorTime")); - js.set("syscode", "huitong"); - js.set("reqSn", UUID.randomUUID()); - // js.set("arriveFor", ""); - JSONObject detailJson = new JSONObject(); - detailJson.set(pushData.getPackageCode(), 1); - js.set("detail", detailJson.toString()); - js.set("shipNo", pushData.getWaybillNumber()); - log.info("推送工厂:{}", js); - String url = jinPaiProperties.getOldSystemHost() + jinPaiProperties.getOldSystemAlreadyStockedUrl(); - try { - if (jinPaiProperties.getEnable()) { - String result = HttpUtil.post(url, JSONUtil.toJsonStr(js)); - log.info("推送工厂结果:{}", result); - // 保存推送记录 - factoryNodePushService.save(FactoryNodePushEntity.builder() - .orderCode(pushData.getOrderCode()) - .node(FactoryNodeEnums.END_WAREHOUSE_UNLOADING.getCode().toString()) - .content(JSONUtil.toJsonStr(js)) - .packageCode(pushData.getPackageCode()) - .resultContent(result) - .build()); + Map orderCodeMap = orderDetailEntities.stream().collect(Collectors.toMap(PushOrderDetailEntity::getOrderId, PushOrderDetailEntity::getCustomItemNo)); + Map detailEntityMap = orderDetailEntities.stream().collect(Collectors.toMap(PushOrderDetailEntity::getCustomItemNo, v -> v)); + List orderIds = orderDetailEntities.stream().map(PushOrderDetailEntity::getOrderId).collect(Collectors.toList()); + Map pushOrderEntityMap = new HashMap<>(); + if (CollUtil.isNotEmpty(orderIds)) { + List pushOrderEntities = pushOrderService.listByIds(orderIds); + if (CollUtil.isNotEmpty(pushOrderEntities)) { + pushOrderEntities.forEach(pushOrderEntity -> { + pushOrderEntityMap.put(orderCodeMap.get(pushOrderEntity.getId().toString()), pushOrderEntity); + }); + } + } + List pushEntities = factoryNodePushService.list(Wrappers.lambdaQuery() + .in(FactoryNodePushEntity::getOrderCode, orderCodes) + ); + // 到站还是入库 + if (workNodeEnums.equals(WorkNodeEnums.FINAL_NET_ARRIVE_CAR)) { + Map pushEntityMap = new HashMap<>(); + if (CollUtil.isNotEmpty(pushEntities)) { + pushEntityMap = pushEntities.stream().filter(pushEntity -> { + return StrUtil.equals(pushEntity.getNode(), FactoryNodeEnums.FINAL_NET_ARRIVE_CAR.getCode().toString()); + }).collect(Collectors.toMap(FactoryNodePushEntity::getOrderCode, v -> v)); + } + JSONObject mainJson = JSONUtil.parseObj(main); + // 到站 一个订单只发送一次 + for (String orderCode : orderCodes) { + if (pushEntityMap.containsKey(orderCode)) { + continue; + } + PushOrderDetailEntity pushOrderDetailEntity = detailEntityMap.get(orderCode); + String boxCodeList = pushOrderDetailEntity.getBoxCodeList(); + JSONArray boxCodeListJson = JSONUtil.parseArray(boxCodeList); + // JSONArray details = new JSONArray(); + JSONObject detail = new JSONObject(); + boxCodeListJson.forEach(item -> { + // JSONObject jsonObject = new JSONObject(); + detail.set(item.toString(), 1); + // details.add(jsonObject); + }); + if (!CollUtil.contains(pushEntityMap.keySet(), orderCode)) { + JSONObject js = new JSONObject(); + js.set("extOrderNo", orderCode); + js.set("extWaybillNO", mainJson.getStr("serviceNumber")); + js.set("detail", detail); + js.set("shipNo", mainJson.getStr("waybillNumber")); + js.set("targetNo", pushOrderEntityMap.get(orderCode).getTransportNo()); + js.set("targetType", "1"); + js.set("doType", "32"); + js.set("doLocation", ""); + js.set("doTime", DateUtil.now()); + js.set("sendSite", mainJson.getStr("sendWarehouseName")); + js.set("endSite", mainJson.getStr("warehouseName")); + js.set("passSite", mainJson.getStr("acceptWarehouseName")); + js.set("doRemark", ""); + js.set("reqSn", pushOrderEntityMap.get(orderCode).getId()); + js.set("syscode", "huitong"); + js.set("carNo", mainJson.getStr("carNumber")); + js.set("carHangNo", ""); + js.set("driverName", mainJson.getStr("driverName")); + js.set("driverPhone", mainJson.getStr("driverMobile")); + js.set("carType", "A"); + js.set("carSize", "1"); + // js.set("arriveFor", ""); + log.info("推送工厂:{}", js); + String url = jinPaiProperties.getOldSystemHost() + jinPaiProperties.getOldSystemArrivedUrl(); + try { + if (jinPaiProperties.getEnable()) { + String result = HttpUtil.post(url, JSONUtil.toJsonStr(js)); + log.info("推送工厂结果:{}", result); + // 保存推送记录 + factoryNodePushService.save(FactoryNodePushEntity.builder() + .orderCode(orderCode) + .node(FactoryNodeEnums.FINAL_NET_ARRIVE_CAR.getCode().toString()) + .content(JSONUtil.toJsonStr(js)) + .resultContent(result) + .build()); + } + } catch (Exception e) { + log.error("推送工厂失败:{}", e); + } + } + } + } else { + // 入库一个包件一次 + Map pushEntityMap = new HashMap<>(); + if (CollUtil.isNotEmpty(pushEntities)) { + pushEntityMap = pushEntities.stream().filter(pushEntity -> { + return StrUtil.equals(pushEntity.getNode(), FactoryNodeEnums.END_WAREHOUSE_UNLOADING.getCode().toString()); + }).collect(Collectors.toMap(FactoryNodePushEntity::getPackageCode, v -> v)); + } + for (PushData pushData : content) { + if (!CollUtil.contains(pushEntityMap.keySet(), pushData.getPackageCode())) { + JSONObject js = new JSONObject(); + js.set("extOrderNo", pushData.getOrderCode()); + js.set("extWaybillNO", detailEntityMap.get(pushData.getOrderCode()).getCustomOrderNo()); + js.set("transportNo", pushOrderEntityMap.get(pushData.getOrderCode()).getTransportNo()); + js.set("doTime", entries.getStr("operatorTime")); + js.set("syscode", "huitong"); + js.set("reqSn", UUID.randomUUID()); + // js.set("arriveFor", ""); + JSONObject detailJson = new JSONObject(); + detailJson.set(pushData.getPackageCode(), 1); + js.set("detail", detailJson.toString()); + js.set("shipNo", pushData.getWaybillNumber()); + log.info("推送工厂:{}", js); + String url = jinPaiProperties.getOldSystemHost() + jinPaiProperties.getOldSystemAlreadyStockedUrl(); + try { + if (jinPaiProperties.getEnable()) { + String result = HttpUtil.post(url, JSONUtil.toJsonStr(js)); + log.info("推送工厂结果:{}", result); + // 保存推送记录 + factoryNodePushService.save(FactoryNodePushEntity.builder() + .orderCode(pushData.getOrderCode()) + .node(FactoryNodeEnums.END_WAREHOUSE_UNLOADING.getCode().toString()) + .content(JSONUtil.toJsonStr(js)) + .packageCode(pushData.getPackageCode()) + .resultContent(result) + .build()); + } + } catch (Exception e) { + log.error("推送工厂失败:{}", e); } - } catch (Exception e) { - log.error("推送工厂失败:{}", e); } } } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/pros/JinPaiProperties.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/pros/JinPaiProperties.java index 45317fbec..bf7f52b56 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/pros/JinPaiProperties.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/pros/JinPaiProperties.java @@ -18,6 +18,10 @@ public class JinPaiProperties { * 金牌工厂推送节点数据url */ private String pushNodeUrl; + /** + * 金牌查询老数据查询老系统数据URL + */ + private String findOldDataUrl = "/openApi/jinpai/code-query"; /** * 是否推送工厂 */