|
|
|
@ -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<PushOrderDetailEntity> orderDetailEntities = pushOrderDetailService.list(Wrappers.<PushOrderDetailEntity>lambdaQuery() |
|
|
|
|
.in(PushOrderDetailEntity::getCustomItemNo, orderCodes) |
|
|
|
|
); |
|
|
|
|
if (CollUtil.isEmpty(orderDetailEntities)) { |
|
|
|
|
log.info("未查到包件数据,不处理:{}", JSONUtil.toJsonStr(content)); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
Map<String, String> orderCodeMap = orderDetailEntities.stream().collect(Collectors.toMap(PushOrderDetailEntity::getOrderId, PushOrderDetailEntity::getCustomItemNo)); |
|
|
|
|
Map<String, PushOrderDetailEntity> detailEntityMap = orderDetailEntities.stream().collect(Collectors.toMap(PushOrderDetailEntity::getCustomItemNo, v -> v)); |
|
|
|
|
List<String> orderIds = orderDetailEntities.stream().map(PushOrderDetailEntity::getOrderId).collect(Collectors.toList()); |
|
|
|
|
Map<String, PushOrderEntity> pushOrderEntityMap = new HashMap<>(); |
|
|
|
|
if (CollUtil.isNotEmpty(orderIds)) { |
|
|
|
|
List<PushOrderEntity> pushOrderEntities = pushOrderService.listByIds(orderIds); |
|
|
|
|
if (CollUtil.isNotEmpty(pushOrderEntities)) { |
|
|
|
|
pushOrderEntities.forEach(pushOrderEntity -> { |
|
|
|
|
pushOrderEntityMap.put(orderCodeMap.get(pushOrderEntity.getId().toString()), pushOrderEntity); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
List<FactoryNodePushEntity> pushEntities = factoryNodePushService.list(Wrappers.<FactoryNodePushEntity>lambdaQuery() |
|
|
|
|
.in(FactoryNodePushEntity::getOrderCode, orderCodes) |
|
|
|
|
); |
|
|
|
|
// 到站还是入库
|
|
|
|
|
if (workNodeEnums.equals(WorkNodeEnums.FINAL_NET_ARRIVE_CAR)) { |
|
|
|
|
Map<String, FactoryNodePushEntity> 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<PushOrderDetailEntity> orderDetailEntities = pushOrderDetailService.list(Wrappers.<PushOrderDetailEntity>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<String, FactoryNodePushEntity> 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<String, String> orderCodeMap = orderDetailEntities.stream().collect(Collectors.toMap(PushOrderDetailEntity::getOrderId, PushOrderDetailEntity::getCustomItemNo)); |
|
|
|
|
Map<String, PushOrderDetailEntity> detailEntityMap = orderDetailEntities.stream().collect(Collectors.toMap(PushOrderDetailEntity::getCustomItemNo, v -> v)); |
|
|
|
|
List<String> orderIds = orderDetailEntities.stream().map(PushOrderDetailEntity::getOrderId).collect(Collectors.toList()); |
|
|
|
|
Map<String, PushOrderEntity> pushOrderEntityMap = new HashMap<>(); |
|
|
|
|
if (CollUtil.isNotEmpty(orderIds)) { |
|
|
|
|
List<PushOrderEntity> pushOrderEntities = pushOrderService.listByIds(orderIds); |
|
|
|
|
if (CollUtil.isNotEmpty(pushOrderEntities)) { |
|
|
|
|
pushOrderEntities.forEach(pushOrderEntity -> { |
|
|
|
|
pushOrderEntityMap.put(orderCodeMap.get(pushOrderEntity.getId().toString()), pushOrderEntity); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
List<FactoryNodePushEntity> pushEntities = factoryNodePushService.list(Wrappers.<FactoryNodePushEntity>lambdaQuery() |
|
|
|
|
.in(FactoryNodePushEntity::getOrderCode, orderCodes) |
|
|
|
|
); |
|
|
|
|
// 到站还是入库
|
|
|
|
|
if (workNodeEnums.equals(WorkNodeEnums.FINAL_NET_ARRIVE_CAR)) { |
|
|
|
|
Map<String, FactoryNodePushEntity> 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<String, FactoryNodePushEntity> 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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|