|
|
|
@ -1,21 +1,24 @@
|
|
|
|
|
package com.logpm.factorydata.zbom.mq; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
import cn.hutool.core.convert.Convert; |
|
|
|
|
import cn.hutool.core.util.EnumUtil; |
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
|
import com.logpm.factorydata.enums.NodeEnums; |
|
|
|
|
import com.logpm.factorydata.enums.SignForStatusEnums; |
|
|
|
|
import com.logpm.factorydata.zbom.constants.ZbomConstants; |
|
|
|
|
import com.logpm.factorydata.zbom.entity.ZbFactoryNodePushEntity; |
|
|
|
|
import com.logpm.factorydata.zbom.entity.ZbFactoryNodePushFailEntity; |
|
|
|
|
import com.logpm.factorydata.zbom.enums.NodeNeedEnums; |
|
|
|
|
import com.logpm.factorydata.zbom.enums.ZbomNodeMappingEnums; |
|
|
|
|
import com.logpm.factorydata.zbom.pros.ZbFactoryProperties; |
|
|
|
|
import com.logpm.factorydata.zbom.service.IFactoryNodePushFailService; |
|
|
|
|
import com.logpm.factorydata.zbom.service.IFactoryNodePushService; |
|
|
|
|
import com.logpm.factorydata.zbom.service.IOrderPackageService; |
|
|
|
|
import com.logpm.factorydata.zbom.util.ZbomUtil; |
|
|
|
|
import com.logpm.factorydata.zbom.vo.NoSignNumberDTO; |
|
|
|
|
import com.logpm.factorydata.zbom.vo.NodeConfirmParamDTO; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
@ -28,7 +31,9 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 监听业务系统推送给志邦的节点数据 |
|
|
|
@ -44,6 +49,7 @@ public class ZbomNodeDataPushListener {
|
|
|
|
|
private final ZbFactoryProperties zbProperties; |
|
|
|
|
private final IOrderPackageService orderPackageService; |
|
|
|
|
private final IFactoryNodePushFailService nodePushFailService; |
|
|
|
|
private final IFactoryNodePushService nodePushService; |
|
|
|
|
|
|
|
|
|
@RabbitListener(bindings = @QueueBinding( |
|
|
|
|
value = @Queue(name = FactoryDataConstants.Mq.Queues.ZBOM_NODE_DATA_PUSH), |
|
|
|
@ -57,8 +63,22 @@ public class ZbomNodeDataPushListener {
|
|
|
|
|
if (!checkMsg(msg)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
JSONObject msgEntries = JSONUtil.parseObj(msg); |
|
|
|
|
// 业务数据
|
|
|
|
|
List<JSONObject> content = msgEntries.getBeanList("content", JSONObject.class); |
|
|
|
|
List<String> packageCodeList = null; |
|
|
|
|
if (CollUtil.isNotEmpty(content)) { |
|
|
|
|
// 查询这次操作的所有包件和运单号
|
|
|
|
|
packageCodeList = new ArrayList<>(); |
|
|
|
|
for (JSONObject obj : content) { |
|
|
|
|
String packageCode = obj.getStr("packageCode"); |
|
|
|
|
if (StrUtil.isNotBlank(packageCode)) { |
|
|
|
|
packageCodeList.add(packageCode); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 构建参数对象
|
|
|
|
|
List<NodeConfirmParamDTO> nodeConfirmParams = initParam(msg); |
|
|
|
|
List<NodeConfirmParamDTO> nodeConfirmParams = initParam(msgEntries, packageCodeList); |
|
|
|
|
try { |
|
|
|
|
// 推送给志邦
|
|
|
|
|
if (CollUtil.isNotEmpty(nodeConfirmParams)) { |
|
|
|
@ -78,10 +98,23 @@ public class ZbomNodeDataPushListener {
|
|
|
|
|
// 推送失败
|
|
|
|
|
nodePushFailService.save(build); |
|
|
|
|
} |
|
|
|
|
if (ObjectUtil.equal(code, "0")) { |
|
|
|
|
ZbFactoryNodePushEntity pushEntity = ZbFactoryNodePushEntity.builder() |
|
|
|
|
.departCode(nodeConfirmParam.getDepartCode()) |
|
|
|
|
.platformOrderCode(nodeConfirmParam.getPlatformOrderCode()) |
|
|
|
|
.content(body) |
|
|
|
|
.resultContent(result) |
|
|
|
|
.build(); |
|
|
|
|
// 推送成功
|
|
|
|
|
nodePushService.save(pushEntity); |
|
|
|
|
// 修改订单包件表的签收状态
|
|
|
|
|
orderPackageService.updateSignForStatus(packageCodeList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
// 处理推送不成功的异常情况
|
|
|
|
|
log.error("zb节点推送数据异常:{}", e); |
|
|
|
@ -90,39 +123,36 @@ public class ZbomNodeDataPushListener {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<NodeConfirmParamDTO> initParam(String msg) { |
|
|
|
|
JSONObject entries = JSONUtil.parseObj(msg); |
|
|
|
|
private List<NodeConfirmParamDTO> initParam(JSONObject entries, List<String> packageCodeList) { |
|
|
|
|
// 处理节点信息
|
|
|
|
|
String node = entries.getStr("node"); |
|
|
|
|
NodeEnums nodeEnums = EnumUtil.fromString(NodeEnums.class, node); |
|
|
|
|
// 业务数据
|
|
|
|
|
List<JSONObject> content = entries.getBeanList("content", JSONObject.class); |
|
|
|
|
if (CollUtil.isNotEmpty(content)) { |
|
|
|
|
// 查询这次操作的所有包件和运单号
|
|
|
|
|
List<String> packageCodeList = new ArrayList<>(); |
|
|
|
|
for (JSONObject obj : content) { |
|
|
|
|
String packageCode = obj.getStr("packageCode"); |
|
|
|
|
if (StrUtil.isNotBlank(packageCode)) { |
|
|
|
|
packageCodeList.add(packageCode); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (CollUtil.isNotEmpty(packageCodeList)) { |
|
|
|
|
// 根据运单号和自编码分组查询出对应的数量
|
|
|
|
|
List<NodeConfirmParamDTO> orders = orderPackageService.findOrderCodebypackageCodes(packageCodeList); |
|
|
|
|
// 根据运单号和自编码分组查询出未签收的数量
|
|
|
|
|
List<NoSignNumberDTO> noSignNumberDTOS = orderPackageService.findNoSignNumber(packageCodeList); |
|
|
|
|
Map<String, Integer> noSignNumberMap = new HashMap<>(); |
|
|
|
|
if (CollUtil.isNotEmpty(noSignNumberDTOS)) { |
|
|
|
|
for (NoSignNumberDTO noSignNumberDTO : noSignNumberDTOS) { |
|
|
|
|
noSignNumberMap.put(noSignNumberDTO.getDepartCode() + noSignNumberDTO.getPlatformOrderCode(), noSignNumberDTO.getNum()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (CollUtil.isNotEmpty(orders)) { |
|
|
|
|
for (NodeConfirmParamDTO order : orders) { |
|
|
|
|
order.setOperator(entries.getStr("operator")); |
|
|
|
|
order.setOperatorTime(entries.getStr("operatorTime")); |
|
|
|
|
order.setAddress(entries.getStr("address")); |
|
|
|
|
String signForStatus = entries.getStr("signForStatus"); |
|
|
|
|
// 如果是签收节点,需要判断是否为全部签收和部分签收
|
|
|
|
|
if (EnumUtil.equals(NodeEnums.CLERK_REVIEW, node)) { |
|
|
|
|
Integer signNumber = Convert.toInt(order.getRejectQty()); |
|
|
|
|
// 查询当前未签收的数量与当前签收数量比较,如果未签收数较大,则是部分签收
|
|
|
|
|
String key = order.getDepartCode() + order.getPlatformOrderCode(); |
|
|
|
|
// 部分签收
|
|
|
|
|
order.setNode(ZbomNodeMappingEnums.getZbomByNodeAndStatus(nodeEnums, ZbomConstants.Status.SIGN_FOR_SECTION_STATUS).getCode()); |
|
|
|
|
// 判断是否全部签收完成
|
|
|
|
|
if (StrUtil.isNotBlank(signForStatus)) { |
|
|
|
|
SignForStatusEnums signFornEnum = EnumUtil.fromString(SignForStatusEnums.class, signForStatus); |
|
|
|
|
if (EnumUtil.equals(SignForStatusEnums.SIGN_FOR_ALL, EnumUtil.toString(signFornEnum))) { |
|
|
|
|
if (noSignNumberMap.containsKey(key)) { |
|
|
|
|
Integer noSignNum = noSignNumberMap.get(key); |
|
|
|
|
if (noSignNum <= signNumber) { |
|
|
|
|
// 全部签收
|
|
|
|
|
order.setNode(ZbomNodeMappingEnums.getZbomByNodeAndStatus(nodeEnums, ZbomConstants.Status.SIGN_FOR_ALL_STATUS).getCode()); |
|
|
|
|
} |
|
|
|
@ -135,7 +165,6 @@ public class ZbomNodeDataPushListener {
|
|
|
|
|
} |
|
|
|
|
return orders; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|