|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
package com.logpm.factorydata.olo.mq; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
|
import cn.hutool.core.util.EnumUtil; |
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
@ -9,11 +8,15 @@ import cn.hutool.http.HttpUtil;
|
|
|
|
|
import cn.hutool.json.JSONArray; |
|
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
|
import com.logpm.factorydata.feign.IFactoryDataClient; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.logpm.factorydata.olo.entity.DeliveryNoteEntity; |
|
|
|
|
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.FactoryNodePushService; |
|
|
|
|
import com.logpm.factorydata.vo.PushData; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
@ -27,8 +30,11 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -42,8 +48,9 @@ import java.util.stream.Collectors;
|
|
|
|
|
@AllArgsConstructor |
|
|
|
|
public class NodeDataPushListener { |
|
|
|
|
|
|
|
|
|
private final IFactoryDataClient factoryDataClient; |
|
|
|
|
private final OldProperties oldProperties; |
|
|
|
|
private final FactoryNodePushService factoryNodePushService; |
|
|
|
|
private final DeliveryNoteService deliveryNoteService; |
|
|
|
|
|
|
|
|
|
@RabbitListener(bindings = @QueueBinding( |
|
|
|
|
value = @Queue(name = FactoryDataConstants.Mq.Queues.OLO_NODE_DATA_PUSH, durable = "true"), |
|
|
|
@ -59,40 +66,120 @@ public class NodeDataPushListener {
|
|
|
|
|
JSONObject entries = JSONUtil.parseObj(msg); |
|
|
|
|
// 节点
|
|
|
|
|
String node = entries.getStr("node"); |
|
|
|
|
WorkNodeEnums workNodeEnums = EnumUtil.fromString(WorkNodeEnums.class, node); |
|
|
|
|
FactoryNodeEnums factoryNode = NodeMappingEnums.getFactoryByNodeAndStatus(workNodeEnums); |
|
|
|
|
// 2 获取业务数据
|
|
|
|
|
List<PushData> content = entries.getBeanList("content", PushData.class); |
|
|
|
|
WorkNodeEnums workNodeEnums = EnumUtil.fromString(WorkNodeEnums.class, node); |
|
|
|
|
// 按订单号和运单号进行分组
|
|
|
|
|
if (CollUtil.isNotEmpty(content)) { |
|
|
|
|
Map<String, List<PushData>> sendMap = content.stream() |
|
|
|
|
.collect(Collectors.groupingBy(data -> data.getOrderCode() + data.getWaybillNumber())); |
|
|
|
|
JSONArray jsons = new JSONArray(sendMap.size()); |
|
|
|
|
for (Map.Entry<String, List<PushData>> entry : sendMap.entrySet()) { |
|
|
|
|
List<PushData> pushDatas = entry.getValue(); |
|
|
|
|
PushData pushData = pushDatas.get(0); |
|
|
|
|
JSONObject js = new JSONObject(); |
|
|
|
|
js.set("status", factoryNode.getText()); |
|
|
|
|
js.set("opTime", DateUtil.now()); |
|
|
|
|
js.set("content", factoryNode.getText()); |
|
|
|
|
js.set("orderNo", pushData.getOrderCode()); |
|
|
|
|
js.set("deliveryNo", pushData.getWaybillNumber()); |
|
|
|
|
js.set("siteLevel", 3); |
|
|
|
|
js.set("nodeName", pushData.getWarehouseName()); |
|
|
|
|
js.set("receiveOrSend", 1); |
|
|
|
|
js.set("shipmentSplitNo", ""); |
|
|
|
|
js.set("receivable", 0); |
|
|
|
|
js.set("receipts", 0); |
|
|
|
|
js.set("shipmentNo", ""); |
|
|
|
|
JSONArray snArray = new JSONArray(pushDatas.size()); |
|
|
|
|
for (PushData data : pushDatas) { |
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
jsonObject.set("sn", data.getPackageCode()); |
|
|
|
|
jsonObject.set("qty", 1); |
|
|
|
|
snArray.add(jsonObject); |
|
|
|
|
FactoryNodeEnums factoryNode = NodeMappingEnums.getFactoryByNodeAndStatus(workNodeEnums, 1); |
|
|
|
|
// 1 先处理 批次件 OLO开头的包件 OLO2312064418-20231226010129-1-001 原始包件 2312064418 回传按原始包件回传
|
|
|
|
|
content.stream().map(i -> { |
|
|
|
|
String packageCode = i.getPackageCode(); |
|
|
|
|
if (StrUtil.startWith(packageCode, "OLO")) { |
|
|
|
|
if (StrUtil.isNotEmpty(packageCode)) { |
|
|
|
|
String[] split = packageCode.split("-"); |
|
|
|
|
i.setPackageCode(split[0].substring(3)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return i; |
|
|
|
|
}); |
|
|
|
|
// 2 先查出 包件+订单 的所有发运分单号和发运单号
|
|
|
|
|
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) |
|
|
|
|
.in(DeliveryNoteEntity::getSn, packageSet) |
|
|
|
|
.in(DeliveryNoteEntity::getCrmSo, orderSet) |
|
|
|
|
); |
|
|
|
|
// 查询出已推的到达
|
|
|
|
|
JSONArray jsons = new JSONArray(); |
|
|
|
|
List<FactoryNodePushEntity> pushEntities = new ArrayList<>(); |
|
|
|
|
if (CollUtil.isNotEmpty(factoryList)) { |
|
|
|
|
// 按 包件+订单 分组
|
|
|
|
|
Map<String, List<DeliveryNoteEntity>> collect = factoryList.stream().collect(Collectors.groupingBy(data -> data.getSn() + data.getCrmSo())); |
|
|
|
|
// 按 订单+运单+发货分单号 分组 作为发送的 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())); |
|
|
|
|
for (Map.Entry<String, List<PushData>> entry : collect1.entrySet()) { |
|
|
|
|
List<PushData> value = entry.getValue(); |
|
|
|
|
PushData sendData = value.get(0); |
|
|
|
|
String orderCode = sendData.getOrderCode(); |
|
|
|
|
String waybillNumber = sendData.getWaybillNumber(); |
|
|
|
|
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()) |
|
|
|
|
); |
|
|
|
|
FactoryNodeEnums needSendNode = factoryNode; |
|
|
|
|
// 是否是分拨中心
|
|
|
|
|
Boolean isArrival = Boolean.FALSE; |
|
|
|
|
switch (workNodeEnums) { |
|
|
|
|
// 卸车扫描的时候 如果没有推到达,则不处理 推了到达则推入库
|
|
|
|
|
case UNLOAD_INCOMING_WAREHOUSE: |
|
|
|
|
if (CollUtil.isEmpty(list)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
// 中转 卸车确认 时,如果推了达到,则不处理
|
|
|
|
|
case TRANSFER_WAREHOUSE_UNLOADING: |
|
|
|
|
if (CollUtil.isNotEmpty(list)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
isArrival = Boolean.TRUE; |
|
|
|
|
break; |
|
|
|
|
// 末端仓卸车确认 时,如果推了到达,则不处理
|
|
|
|
|
case END_WAREHOUSE_UNLOADING: |
|
|
|
|
if (CollUtil.isNotEmpty(list)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
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()); |
|
|
|
|
js.set("opTime", entries.getStr("operatorTime")); |
|
|
|
|
js.set("content", needSendNode.getValue()); |
|
|
|
|
js.set("orderNo", orderCode); |
|
|
|
|
js.set("deliveryNo", waybillNumber); |
|
|
|
|
js.set("siteLevel", needSendNode.getSiteLecel(isArrival)); |
|
|
|
|
js.set("nodeName", sendData.getWarehouseName()); |
|
|
|
|
js.set("receiveOrSend", needSendNode.getReceiveOrSend()); |
|
|
|
|
js.set("shipmentSplitNo", shipmentSplitNo); |
|
|
|
|
js.set("receivable", 0); |
|
|
|
|
js.set("receipts", 0); |
|
|
|
|
js.set("shipmentNo", collect.get(sendData.getPackageCode() + sendData.getOrderCode()).get(0).getShipmentNo()); |
|
|
|
|
JSONArray snArray = new JSONArray(); |
|
|
|
|
Map<String, Integer> snMap = new HashMap<>(); |
|
|
|
|
// 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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (Map.Entry<String, Integer> stringIntegerEntry : snMap.entrySet()) { |
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
jsonObject.set("sn", stringIntegerEntry.getKey()); |
|
|
|
|
jsonObject.set("qty", stringIntegerEntry.getValue()); |
|
|
|
|
snArray.add(jsonObject); |
|
|
|
|
} |
|
|
|
|
js.set("snList", snArray); |
|
|
|
|
jsons.add(js); |
|
|
|
|
} |
|
|
|
|
js.set("snList", snArray); |
|
|
|
|
jsons.add(js); |
|
|
|
|
} |
|
|
|
|
if (oldProperties.getEnable()) { |
|
|
|
|
try { |
|
|
|
@ -100,6 +187,9 @@ public class NodeDataPushListener {
|
|
|
|
|
log.info("推送节点数据:{}", JSONUtil.toJsonStr(jsons)); |
|
|
|
|
String post = HttpUtil.post(oldProperties.getPushNodeUrl(), JSONUtil.toJsonStr(jsons)); |
|
|
|
|
log.info("推送结果:{}", post); |
|
|
|
|
if (CollUtil.isNotEmpty(pushEntities)) { |
|
|
|
|
factoryNodePushService.saveBatch(pushEntities); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|