|
|
|
@ -1,8 +1,11 @@
|
|
|
|
|
package com.logpm.factorydata.olo.mq; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
import cn.hutool.core.convert.Convert; |
|
|
|
|
import cn.hutool.core.util.EnumUtil; |
|
|
|
|
import cn.hutool.core.util.NumberUtil; |
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
import cn.hutool.core.util.RandomUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import cn.hutool.http.HttpUtil; |
|
|
|
|
import cn.hutool.json.JSONArray; |
|
|
|
@ -10,12 +13,14 @@ import cn.hutool.json.JSONObject;
|
|
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.logpm.factorydata.olo.entity.DeliveryNoteEntity; |
|
|
|
|
import com.logpm.factorydata.olo.entity.FactoryNodeAllPushEntity; |
|
|
|
|
import com.logpm.factorydata.olo.entity.FactoryNodePushEntity; |
|
|
|
|
import com.logpm.factorydata.olo.enums.FactoryNodeEnums; |
|
|
|
|
import com.logpm.factorydata.olo.enums.NodeMappingEnums; |
|
|
|
|
import com.logpm.factorydata.olo.enums.NodeNeedEnums; |
|
|
|
|
import com.logpm.factorydata.olo.pros.OldProperties; |
|
|
|
|
import com.logpm.factorydata.olo.service.DeliveryNoteService; |
|
|
|
|
import com.logpm.factorydata.olo.service.FactoryNodeAllPushService; |
|
|
|
|
import com.logpm.factorydata.olo.service.FactoryNodePushService; |
|
|
|
|
import com.logpm.factorydata.vo.PushData; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
@ -51,6 +56,7 @@ public class NodeDataPushListener {
|
|
|
|
|
private final OldProperties oldProperties; |
|
|
|
|
private final FactoryNodePushService factoryNodePushService; |
|
|
|
|
private final DeliveryNoteService deliveryNoteService; |
|
|
|
|
private final FactoryNodeAllPushService nodeAllPushService; |
|
|
|
|
|
|
|
|
|
@RabbitListener(bindings = @QueueBinding( |
|
|
|
|
value = @Queue(name = FactoryDataConstants.Mq.Queues.OLO_NODE_DATA_PUSH, durable = "true"), |
|
|
|
@ -87,29 +93,30 @@ public class NodeDataPushListener {
|
|
|
|
|
Set<String> packageSet = content.stream().map(PushData::getPackageCode).collect(Collectors.toSet()); |
|
|
|
|
Set<String> orderSet = content.stream().map(PushData::getOrderCode).collect(Collectors.toSet()); |
|
|
|
|
List<DeliveryNoteEntity> factoryList = deliveryNoteService.list(Wrappers.<DeliveryNoteEntity>lambdaQuery() |
|
|
|
|
.select(DeliveryNoteEntity::getSn, DeliveryNoteEntity::getCrmSo, DeliveryNoteEntity::getShipmentSplitNo, DeliveryNoteEntity::getShipmentNo, DeliveryNoteEntity::getReserve1) |
|
|
|
|
.select(DeliveryNoteEntity::getSn, DeliveryNoteEntity::getCrmSo, DeliveryNoteEntity::getShipmentSplitNo, DeliveryNoteEntity::getShipmentNo, DeliveryNoteEntity::getQty) |
|
|
|
|
.in(DeliveryNoteEntity::getSn, packageSet) |
|
|
|
|
.in(DeliveryNoteEntity::getCrmSo, orderSet) |
|
|
|
|
); |
|
|
|
|
// 查询出已推的到达
|
|
|
|
|
JSONArray jsons = new JSONArray(); |
|
|
|
|
List<FactoryNodePushEntity> pushEntities = new ArrayList<>(); |
|
|
|
|
List<FactoryNodeAllPushEntity> pushAllEntities = new ArrayList<>(); |
|
|
|
|
if (CollUtil.isNotEmpty(factoryList)) { |
|
|
|
|
// 按 包件+订单 分组
|
|
|
|
|
Map<String, List<DeliveryNoteEntity>> collect = factoryList.stream().collect(Collectors.groupingBy(data -> data.getSn() + data.getCrmSo())); |
|
|
|
|
// 按 订单+运单+发货分单号 分组 作为发送的 key
|
|
|
|
|
// 按 订单+发货分单号 分组 作为发送的 key
|
|
|
|
|
Map<String, List<PushData>> collect1 = content.stream() |
|
|
|
|
.filter(data -> StrUtil.isNotEmpty(data.getWaybillNumber())) |
|
|
|
|
.collect(Collectors.groupingBy(data -> data.getOrderCode() + data.getWaybillNumber() + collect.get(data.getPackageCode() + data.getOrderCode()).get(0).getShipmentSplitNo())); |
|
|
|
|
.collect(Collectors.groupingBy(data -> data.getOrderCode() + collect.get(data.getPackageCode() + data.getOrderCode()).get(0).getShipmentSplitNo())); |
|
|
|
|
// 生成一个9位数的随机数
|
|
|
|
|
String workBatch = Convert.toStr(RandomUtil.randomLong(100000000000000000L, 999999999999999999L)); |
|
|
|
|
for (Map.Entry<String, List<PushData>> entry : collect1.entrySet()) { |
|
|
|
|
JSONArray jsons = new JSONArray(); |
|
|
|
|
List<PushData> value = entry.getValue(); |
|
|
|
|
PushData sendData = value.get(0); |
|
|
|
|
String orderCode = sendData.getOrderCode(); |
|
|
|
|
String waybillNumber = sendData.getWaybillNumber(); |
|
|
|
|
String waybillNumber = StrUtil.isNotEmpty(sendData.getWaybillNumber()) ? sendData.getWaybillNumber() : orderCode; |
|
|
|
|
String shipmentSplitNo = collect.get(sendData.getPackageCode() + sendData.getOrderCode()).get(0).getShipmentSplitNo(); |
|
|
|
|
List<FactoryNodePushEntity> list = factoryNodePushService.list(Wrappers.<FactoryNodePushEntity>lambdaQuery() |
|
|
|
|
.eq(FactoryNodePushEntity::getOrderCode, orderCode) |
|
|
|
|
.eq(FactoryNodePushEntity::getWaybillCode, waybillNumber) |
|
|
|
|
.eq(FactoryNodePushEntity::getShipmentSpitCode, shipmentSplitNo) |
|
|
|
|
.eq(FactoryNodePushEntity::getTypeCode, FactoryNodeEnums.ARRIVAL.getCode()) |
|
|
|
|
); |
|
|
|
@ -138,15 +145,6 @@ public class NodeDataPushListener {
|
|
|
|
|
isArrival = Boolean.TRUE; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if(isArrival){ |
|
|
|
|
FactoryNodePushEntity entity = new FactoryNodePushEntity(); |
|
|
|
|
entity.setOrderCode(orderCode); |
|
|
|
|
entity.setWaybillCode(waybillNumber); |
|
|
|
|
entity.setShipmentSpitCode(shipmentSplitNo); |
|
|
|
|
entity.setType(needSendNode.getValue()); |
|
|
|
|
entity.setTypeCode(needSendNode.getCode()); |
|
|
|
|
pushEntities.add(entity); |
|
|
|
|
} |
|
|
|
|
needSendNode = NodeMappingEnums.getFactoryByNodeAndStatus(workNodeEnums); |
|
|
|
|
JSONObject js = new JSONObject(); |
|
|
|
|
js.set("status", needSendNode.getStatus()); |
|
|
|
@ -163,14 +161,46 @@ public class NodeDataPushListener {
|
|
|
|
|
js.set("shipmentNo", collect.get(sendData.getPackageCode() + sendData.getOrderCode()).get(0).getShipmentNo()); |
|
|
|
|
JSONArray snArray = new JSONArray(); |
|
|
|
|
Map<String, Integer> snMap = new HashMap<>(); |
|
|
|
|
FactoryNodeAllPushEntity factoryNodeAllPushEntity = FactoryNodeAllPushEntity.builder() |
|
|
|
|
.warehouse(sendData.getWarehouseName()) |
|
|
|
|
.workBatch(workBatch) |
|
|
|
|
.orderCode(orderCode) |
|
|
|
|
.waybillCode(waybillNumber) |
|
|
|
|
.shipmentCode(collect.get(sendData.getPackageCode() + sendData.getOrderCode()).get(0).getShipmentNo()) |
|
|
|
|
.shipmentSpitCode(shipmentSplitNo) |
|
|
|
|
.type(needSendNode.getValue()) |
|
|
|
|
.typeCode(needSendNode.getCode()) |
|
|
|
|
.build(); |
|
|
|
|
// value 按包件分组 包含则数量+1
|
|
|
|
|
for (PushData data : value) { |
|
|
|
|
if (snMap.containsKey(data.getPackageCode())) { |
|
|
|
|
snMap.put(data.getPackageCode(), snMap.get(data.getPackageCode()) + 1); |
|
|
|
|
} else { |
|
|
|
|
snMap.put(data.getPackageCode(), 1); |
|
|
|
|
// 分拨中心回传所有包件,其他节点回传当前操作的包件
|
|
|
|
|
if (isArrival) { |
|
|
|
|
List<DeliveryNoteEntity> collect2 = factoryList.stream() |
|
|
|
|
.filter(data -> data.getCrmSo().equals(orderCode)) |
|
|
|
|
.filter(data -> data.getShipmentSplitNo().equals(shipmentSplitNo)) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
snMap = collect2.stream().collect(Collectors.toMap(DeliveryNoteEntity::getSn, s -> Convert.toInt(s.getQty()))); |
|
|
|
|
FactoryNodePushEntity entity1 = FactoryNodePushEntity.builder() |
|
|
|
|
.orderCode(orderCode).statusName(needSendNode.getStatus()).opTime(entries.getStr("operatorTime")).content(needSendNode.getValue()) |
|
|
|
|
.waybillCode(waybillNumber).siteLevel(needSendNode.getSiteLecel(isArrival)).warehouse(sendData.getWarehouseName()) |
|
|
|
|
.receiveOrSend(needSendNode.getReceiveOrSend()) |
|
|
|
|
.shipmentSpitCode(shipmentSplitNo).shipmentCode(collect.get(sendData.getPackageCode() + sendData.getOrderCode()).get(0).getShipmentNo()) |
|
|
|
|
.receivable(0).receipts(0) |
|
|
|
|
.type(needSendNode.getValue()) |
|
|
|
|
.typeCode(needSendNode.getCode()) |
|
|
|
|
.build(); |
|
|
|
|
pushEntities.add(entity1); |
|
|
|
|
factoryNodeAllPushEntity.setPackageCode(collect2.stream().map(DeliveryNoteEntity::getSn).collect(Collectors.joining(","))); |
|
|
|
|
} else { |
|
|
|
|
for (PushData data : value) { |
|
|
|
|
if (snMap.containsKey(data.getPackageCode())) { |
|
|
|
|
snMap.put(data.getPackageCode(), snMap.get(data.getPackageCode()) + 1); |
|
|
|
|
} else { |
|
|
|
|
snMap.put(data.getPackageCode(), 1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
factoryNodeAllPushEntity.setPackageCode(value.stream().map(PushData::getPackageCode).collect(Collectors.joining(","))); |
|
|
|
|
} |
|
|
|
|
pushAllEntities.add(factoryNodeAllPushEntity); |
|
|
|
|
for (Map.Entry<String, Integer> stringIntegerEntry : snMap.entrySet()) { |
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
jsonObject.set("sn", stringIntegerEntry.getKey()); |
|
|
|
@ -180,23 +210,57 @@ public class NodeDataPushListener {
|
|
|
|
|
} |
|
|
|
|
js.set("snList", snArray); |
|
|
|
|
jsons.add(js); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (oldProperties.getEnable()) { |
|
|
|
|
try { |
|
|
|
|
if (CollUtil.isNotEmpty(jsons)) { |
|
|
|
|
log.info("推送节点数据:{}", JSONUtil.toJsonStr(jsons)); |
|
|
|
|
String post = HttpUtil.post(oldProperties.getPushNodeUrl(), JSONUtil.toJsonStr(jsons)); |
|
|
|
|
log.info("推送结果:{}", post); |
|
|
|
|
if (CollUtil.isNotEmpty(pushEntities)) { |
|
|
|
|
factoryNodePushService.saveBatch(pushEntities); |
|
|
|
|
|
|
|
|
|
if (oldProperties.getEnable()) { |
|
|
|
|
try { |
|
|
|
|
if (CollUtil.isNotEmpty(jsons)) { |
|
|
|
|
log.info("推送节点数据:{}", JSONUtil.toJsonStr(jsons)); |
|
|
|
|
String post = HttpUtil.post(oldProperties.getPushNodeUrl(), JSONUtil.toJsonStr(jsons)); |
|
|
|
|
log.info("推送结果:{}", post); |
|
|
|
|
try { |
|
|
|
|
JSONObject entries1 = JSONUtil.parseObj(post); |
|
|
|
|
Integer code = entries1.getInt("code"); |
|
|
|
|
String data = entries1.getStr("data"); |
|
|
|
|
// 成功
|
|
|
|
|
Integer successCode = code; |
|
|
|
|
String message = data; |
|
|
|
|
if (NumberUtil.equals(code, 200)) { |
|
|
|
|
if (StrUtil.isNotEmpty(data)) { |
|
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(data); |
|
|
|
|
Integer code1 = jsonObject.getInt("code"); |
|
|
|
|
successCode = code1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (CollUtil.isNotEmpty(pushEntities)) { |
|
|
|
|
for (FactoryNodePushEntity pushEntity : pushEntities) { |
|
|
|
|
pushEntity.setSendStatus(successCode + ""); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (CollUtil.isNotEmpty(pushAllEntities)) { |
|
|
|
|
for (FactoryNodeAllPushEntity pushAllEntity : pushAllEntities) { |
|
|
|
|
pushAllEntity.setSendStatus(successCode + ""); |
|
|
|
|
pushAllEntity.setContent(JSONUtil.toJsonStr(js)); |
|
|
|
|
pushAllEntity.setResultContent(message); |
|
|
|
|
pushAllEntity.setSendUrl(oldProperties.getPushNodeUrl()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("解析返回值失败"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
log.error("推送节点数据错误:{}", e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
log.error("推送节点数据错误:{}", e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (CollUtil.isNotEmpty(pushEntities)) { |
|
|
|
|
factoryNodePushService.saveBatch(pushEntities); |
|
|
|
|
} |
|
|
|
|
if (CollUtil.isNotEmpty(pushAllEntities)) { |
|
|
|
|
nodeAllPushService.saveBatch(pushAllEntities); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|