From 3cd993fba2f874b8f6b70fa2161d2c6fdd08af05 Mon Sep 17 00:00:00 2001 From: zhaoqiaobo <583671871@qq.com> Date: Wed, 6 Nov 2024 14:15:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(all):=20=E5=BF=97=E9=82=A6=E5=B7=A5?= =?UTF-8?q?=E5=8E=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1 增加志邦工厂自定义回传逻辑 2 修改志邦工厂接收工厂订单处理逻辑 3 修改回传处理逻辑 --- .../factorydata/zbom/config/XxlJobConfig.java | 74 ++ .../zbom/entity/CustomPushEntity.java | 58 ++ .../zbom/entity/ZbFactoryNodePushEntity.java | 5 + .../zbom/entity/ZbOrderPackageEntity.java | 11 + .../factorydata/zbom/job/CustomPushJob.java | 647 ++++++++++++++++++ .../zbom/mapper/CustomPushMapper.java | 36 + .../zbom/mapper/CustomPushMapper.xml | 17 + .../zbom/mapper/FactoryNodeOrderMapper.xml | 5 +- .../zbom/mapper/OrderPackageMapper.xml | 40 +- .../zbom/mq/ZbomFactoryOrderListener.java | 165 +---- .../zbom/mq/ZbomNodeDataPushListener.java | 235 ++++--- .../zbom/service/CustomPushService.java | 17 + .../zbom/service/IOrderPackageService.java | 2 + .../service/impl/CustomPusherviceImpl.java | 28 + .../service/impl/OrderPackageServiceImpl.java | 139 ++++ .../zbom/service/impl/ReceiptServiceImpl.java | 1 + .../src/main/resources/application-dev.yml | 1 + 17 files changed, 1180 insertions(+), 301 deletions(-) create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/config/XxlJobConfig.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/entity/CustomPushEntity.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/job/CustomPushJob.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/CustomPushMapper.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/CustomPushMapper.xml create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/CustomPushService.java create mode 100644 blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/CustomPusherviceImpl.java diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/config/XxlJobConfig.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/config/XxlJobConfig.java new file mode 100644 index 000000000..6a820d469 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/config/XxlJobConfig.java @@ -0,0 +1,74 @@ +package com.logpm.factorydata.zbom.config; + +import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * xxl-job config + * + * @author xuxueli 2017-04-28 + */ +@Configuration(proxyBeanMethods = false) +public class XxlJobConfig { + private final Logger logger = LoggerFactory.getLogger(XxlJobConfig.class); + + @Value("${xxl.job.admin.addresses}") + private String adminAddresses; + + @Value("${xxl.job.executor.appname}") + private String appName; + + @Value("${xxl.job.executor.ip}") + private String ip; + + @Value("${xxl.job.executor.port}") + private int port; + + @Value("${xxl.job.accessToken}") + private String accessToken; + + @Value("${xxl.job.executor.logpath}") + private String logPath; + + @Value("${xxl.job.executor.logretentiondays}") + private int logRetentionDays; + + + @Bean + public XxlJobSpringExecutor xxlJobExecutor() { + logger.info(">>>>>>>>>>> xxl-job config init."); + XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor(); + xxlJobSpringExecutor.setAdminAddresses(adminAddresses); + xxlJobSpringExecutor.setAppName(appName); + xxlJobSpringExecutor.setIp(ip); + xxlJobSpringExecutor.setPort(port); + xxlJobSpringExecutor.setAccessToken(accessToken); + xxlJobSpringExecutor.setLogPath(logPath); + xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays); + + return xxlJobSpringExecutor; + } + + /** + * 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP; + * + * 1、引入依赖: + * + * org.springframework.cloud + * spring-cloud-commons + * ${version} + * + * + * 2、配置文件,或者容器启动变量 + * spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.' + * + * 3、获取IP + * String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); + */ + + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/entity/CustomPushEntity.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/entity/CustomPushEntity.java new file mode 100644 index 000000000..8e40ba191 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/entity/CustomPushEntity.java @@ -0,0 +1,58 @@ +package com.logpm.factorydata.zbom.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.base.BaseEntity; + +/** + * 志邦自定义回传 实体类 + * + * @author zhaoqiaobo + * @create 2024-04-26 + */ +@Data +@TableName("zb_custom_push") +@ApiModel(value = "志邦自定义回传", description = "志邦自定义回传") +@EqualsAndHashCode(callSuper = true) +public class CustomPushEntity extends BaseEntity { + + @ApiModelProperty(name = "预约id", notes = "") + private String reservationId; + + @ApiModelProperty(name = "订单号", notes = "") + private String orderCode; + + @ApiModelProperty(name = "仓库", notes = "") + private String warehouse; + + @ApiModelProperty(name = "包件码", notes = "") + private String packageCode; + + @ApiModelProperty(name = "复核时间", notes = "") + private String signingTime; + + @ApiModelProperty(name = "复核人", notes = "") + private String examineUserName; + + @ApiModelProperty(name = "返回内容", notes = "") + private String result; + + @ApiModelProperty(name = "返回码", notes = "") + private String resultCode; + + @ApiModelProperty(name = "状态 1已发送 0未发送", notes = "") + private Integer sendStatus; + + @ApiModelProperty(name = "预留1", notes = "") + private String reserve1; + @ApiModelProperty(name = "预留3", notes = "") + private String reserve3; + @ApiModelProperty(name = "预留4", notes = "") + private String reserve4; + @ApiModelProperty(name = "预留5", notes = "") + private String reserve5; + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/entity/ZbFactoryNodePushEntity.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/entity/ZbFactoryNodePushEntity.java index 2c07f146b..b47fead01 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/entity/ZbFactoryNodePushEntity.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/entity/ZbFactoryNodePushEntity.java @@ -90,5 +90,10 @@ public class ZbFactoryNodePushEntity extends BaseEntity { */ @ApiModelProperty(name = "返回值", notes = "") private String resultContent; + /** + * 签收数量 + */ + @ApiModelProperty(name = "签收数量", notes = "") + private Integer signNum; } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/entity/ZbOrderPackageEntity.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/entity/ZbOrderPackageEntity.java index afa4d8ba5..0cb1ef44f 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/entity/ZbOrderPackageEntity.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/entity/ZbOrderPackageEntity.java @@ -34,6 +34,12 @@ public class ZbOrderPackageEntity extends BaseEntity { */ @ApiModelProperty(name = "行号", notes = "") private String lineNo; + + /** + * 发货单号 + */ + @ApiModelProperty(name = "发货单号", notes = "") + private String departCode; /** * OMS订单号(生产编号) */ @@ -159,6 +165,11 @@ public class ZbOrderPackageEntity extends BaseEntity { @ApiModelProperty(name = "处理状态 0 未处理 1 已处理 2 处理失败", notes = "") private Integer processingStatus; + /** + * 签收状态 + */ + @ApiModelProperty(name = "签收状态", notes = "") + private Integer signStatus; /** * 状态 */ diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/job/CustomPushJob.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/job/CustomPushJob.java new file mode 100644 index 000000000..f0a467617 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/job/CustomPushJob.java @@ -0,0 +1,647 @@ +package com.logpm.factorydata.zbom.job; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.logpm.factorydata.zbom.constants.ZbomConstants; +import com.logpm.factorydata.zbom.entity.CustomPushEntity; +import com.logpm.factorydata.zbom.entity.ZbFactoryNodeOrderEntity; +import com.logpm.factorydata.zbom.entity.ZbFactoryNodePushEntity; +import com.logpm.factorydata.zbom.entity.ZbOrderPackageEntity; +import com.logpm.factorydata.zbom.enums.ZbomNodeEnums; +import com.logpm.factorydata.zbom.pros.ZbFactoryProperties; +import com.logpm.factorydata.zbom.service.CustomPushService; +import com.logpm.factorydata.zbom.service.IFactoryNodeOrderService; +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.NodeConfirmParamDTO; +import com.xxl.job.core.biz.model.ReturnT; +import com.xxl.job.core.handler.annotation.XxlJob; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.common.constant.WorkNodeEnums; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * 自动回传工厂 + * + * @author zhaoqiaobo + * @create 2024-04-02 + */ +@AllArgsConstructor +@Component +@Slf4j +public class CustomPushJob { + + private final CustomPushService customPushService; + private final IFactoryNodePushService nodePushService; + private final IOrderPackageService orderPackageService; + private final ZbFactoryProperties zbProperties; + private final IFactoryNodeOrderService nodeOrderService; + + /** + * 自定义回传工厂节点作业数据 + * + * @param param + * @return + * @throws Exception + */ + @XxlJob("customPushFactoryData") + public ReturnT customPushFactoryData(String param) throws Exception { + // 获取参数 5 场站发车 10 回传在途 20 回传送货抵达 30 回传签收 + if (StrUtil.isEmpty(param)) { + return ReturnT.SUCCESS; + } + Integer type = Integer.valueOf(param); + // 查询出需要回传的数据 + List customPushEntities = customPushService.findData(type); + if (CollUtil.isNotEmpty(customPushEntities)) { + // Set collect = customPushEntities.stream().map(CustomPushEntity::getPackageCode).collect(Collectors.toSet()); + CustomPushEntity customPushEntity = customPushEntities.get(0); + ZbomNodeEnums node = null; + if (type == 5) { + node = ZbomNodeEnums.STATION_DEPART; + WorkNodeEnums initialWarehouseDepart = WorkNodeEnums.INITIAL_WAREHOUSE_DEPART; + String address = "从【基地仓发出】"; + sendFactory(customPushEntity, node, type, initialWarehouseDepart,address); + } + else if (type == 10) { + node = ZbomNodeEnums.INTRANSIT; + WorkNodeEnums initialWarehouseDepart = WorkNodeEnums.UNLOAD_INCOMING_WAREHOUSE; + String address = "到达【"+ customPushEntity.getWarehouse() +"】"; + sendFactory(customPushEntity, node, type, initialWarehouseDepart, address); + // List list = orderPackageService.list(Wrappers.lambdaQuery() + // .select(ZbOrderPackageEntity::getDepartCode) + // .eq(ZbOrderPackageEntity::getPackageCode, customPushEntity.getPackageCode()) + // .eq(ZbOrderPackageEntity::getPlatformOrderCode, customPushEntity.getOrderCode()) + // ); + // if (CollUtil.isNotEmpty(list)) { + // ZbOrderPackageEntity zbOrderPackageEntity = list.get(0); + // List list1 = nodePushService.list(Wrappers.lambdaQuery() + // .select(ZbFactoryNodePushEntity::getId) + // .eq(ZbFactoryNodePushEntity::getDepartCode, zbOrderPackageEntity.getDepartCode()) + // .eq(ZbFactoryNodePushEntity::getPlatformOrderCode, customPushEntity.getOrderCode()) + // // .eq(ZbFactoryNodePushEntity::getWarehouseName, customPushEntity.getWarehouse()) + // .eq(ZbFactoryNodePushEntity::getNode, node.getCode()) + // ); + // if (CollUtil.isEmpty(list1)) { + // NodeConfirmParamDTO nodeConfirmParam = NodeConfirmParamDTO.builder().address("到达【" + customPushEntity.getWarehouse() + "】") + // .departCode(zbOrderPackageEntity.getDepartCode()) + // .operator(customPushEntity.getExamineUserName()) + // .operatorTime(customPushEntity.getSigningTime()) + // .platformOrderCode(customPushEntity.getOrderCode()) + // .node(node.getCode()).build(); + // try { + // // 推送给志邦 + // String body = JSONUtil.toJsonStr(nodeConfirmParam); + // String result = null; + // if (zbProperties.getEnable()) { + // result = ZbomUtil.pushZbomSystem(zbProperties, body, ZbomConstants.Method.ROUTE_NODE_CONFIRM); + // } else { + // JSONObject jsonObject = new JSONObject(); + // jsonObject.set("code", "0"); + // result = JSONUtil.toJsonStr(jsonObject); + // } + // log.info("zb节点推送数据:参数{},返回值{}。", body, result); + // if (StrUtil.isNotBlank(result)) { + // if (!StrUtil.contains(result, "code")) { + // customPushService.update(Wrappers.lambdaUpdate() + // .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + // .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + // .set(CustomPushEntity::getSendStatus, type) + // .set(CustomPushEntity::getResultCode, "-1") + // .set(CustomPushEntity::getResult, "工厂返回结果异常") + // ); + // } else { + // JSONObject resultJson = JSONUtil.parseObj(result); + // String code = resultJson.getStr("code"); + // if (ObjectUtil.equal(code, "0")) { + // ZbFactoryNodePushEntity pushEntity = ZbFactoryNodePushEntity.builder() + // .departCode(nodeConfirmParam.getDepartCode()) + // .platformOrderCode(nodeConfirmParam.getPlatformOrderCode()) + // .node(nodeConfirmParam.getNode()) + // .workNode(initialWarehouseDepart.name()) + // .warehouseName(customPushEntity.getWarehouse()) + // .packageCode(customPushEntity.getPackageCode()) + // .content(body) + // .resultContent(result) + // .build(); + // // 推送成功 + // nodePushService.save(pushEntity); + // // 修改加盟商单号+发货单号节点数据 + // List list2 = nodeOrderService.list(Wrappers.lambdaQuery() + // .eq(ZbFactoryNodeOrderEntity::getPlatformOrderCode, customPushEntity.getOrderCode()) + // .eq(ZbFactoryNodeOrderEntity::getDepartCode, zbOrderPackageEntity.getDepartCode()) + // ); + // if (CollUtil.isNotEmpty(list2)) { + // ZbFactoryNodeOrderEntity zbFactoryNodeOrderEntity = list2.get(0); + // String pushNode = zbFactoryNodeOrderEntity.getPushNode(); + // Integer currentNode = zbFactoryNodeOrderEntity.getCurrentNode(); + // Integer index = node.getIndex(); + // if (currentNode < index) { + // pushNode = pushNode + "," + index; + // } + // zbFactoryNodeOrderEntity.setPushNode(pushNode); + // zbFactoryNodeOrderEntity.setCurrentNode(index); + // nodeOrderService.updateNodeOrder(zbFactoryNodeOrderEntity); + // } + // // 处理custom + // customPushService.update(Wrappers.lambdaUpdate() + // .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + // .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + // .set(CustomPushEntity::getSendStatus, type) + // .set(CustomPushEntity::getResultCode, code) + // .set(CustomPushEntity::getResult, result) + // ); + // } else { + // // 处理custom + // customPushService.update(Wrappers.lambdaUpdate() + // .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + // .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + // .set(CustomPushEntity::getSendStatus, type) + // .set(CustomPushEntity::getResultCode, code) + // .set(CustomPushEntity::getResult, result)); + // log.info("自定义回传失败"); + // } + // } + // } + // } catch (Exception e) { + // // 处理推送不成功的异常情况 + // log.error("zb节点推送数据异常:{}", e); + // // 保存日志 + // e.printStackTrace(); + // } + // }else { + // customPushService.update(Wrappers.lambdaUpdate() + // .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + // .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + // .set(CustomPushEntity::getSendStatus, type) + // .set(CustomPushEntity::getResultCode, "-1") + // .set(CustomPushEntity::getResult, "push里有记录") + // ); + // } + // }else{ + // customPushService.update(Wrappers.lambdaUpdate() + // .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + // .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + // .set(CustomPushEntity::getSendStatus, type) + // .set(CustomPushEntity::getResultCode, "-1") + // .set(CustomPushEntity::getResult, "未找到包件订单") + // ); + // } + + } + else if (type == 20) { + node = ZbomNodeEnums.DELIVERY_ARRIVAL; + WorkNodeEnums clerkReview = WorkNodeEnums.CLERK_REVIEW; + String address = ""; + sendFactory(customPushEntity, node, type, clerkReview, address); + // List list = orderPackageService.list(Wrappers.lambdaQuery() + // .select(ZbOrderPackageEntity::getDepartCode) + // .eq(ZbOrderPackageEntity::getPackageCode, customPushEntity.getPackageCode()) + // .eq(ZbOrderPackageEntity::getPlatformOrderCode, customPushEntity.getOrderCode()) + // ); + // if (CollUtil.isNotEmpty(list)) { + // ZbOrderPackageEntity zbOrderPackageEntity = list.get(0); + // List list1 = nodePushService.list(Wrappers.lambdaQuery() + // .select(ZbFactoryNodePushEntity::getId) + // .eq(ZbFactoryNodePushEntity::getDepartCode, zbOrderPackageEntity.getDepartCode()) + // .eq(ZbFactoryNodePushEntity::getPlatformOrderCode, customPushEntity.getOrderCode()) + // // .eq(ZbFactoryNodePushEntity::getWarehouseName, customPushEntity.getWarehouse()) + // .eq(ZbFactoryNodePushEntity::getNode, node.getCode()) + // ); + // if (CollUtil.isEmpty(list1)) { + // NodeConfirmParamDTO nodeConfirmParam = NodeConfirmParamDTO.builder() + // .address("到达【" + customPushEntity.getWarehouse() + "】") + // .departCode(zbOrderPackageEntity.getDepartCode()) + // .operator(customPushEntity.getExamineUserName()) + // .operatorTime(customPushEntity.getSigningTime()) + // .platformOrderCode(customPushEntity.getOrderCode()) + // .node(node.getCode()).build(); + // try { + // // 推送给志邦 + // String body = JSONUtil.toJsonStr(nodeConfirmParam); + // String result = null; + // if (zbProperties.getEnable()) { + // result = ZbomUtil.pushZbomSystem(zbProperties, body, ZbomConstants.Method.ROUTE_NODE_CONFIRM); + // } else { + // JSONObject jsonObject = new JSONObject(); + // jsonObject.set("code", "0"); + // result = JSONUtil.toJsonStr(jsonObject); + // } + // log.info("zb节点推送数据:参数{},返回值{}。", body, result); + // if (StrUtil.isNotBlank(result)) { + // if (!StrUtil.contains(result, "code")) { + // customPushService.update(Wrappers.lambdaUpdate() + // .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + // .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + // .set(CustomPushEntity::getSendStatus, type) + // .set(CustomPushEntity::getResultCode, "-1") + // .set(CustomPushEntity::getResult, "工厂返回异常") + // ); + // } else { + // JSONObject resultJson = JSONUtil.parseObj(result); + // String code = resultJson.getStr("code"); + // if (ObjectUtil.equal(code, "0")) { + // ZbFactoryNodePushEntity pushEntity = ZbFactoryNodePushEntity.builder() + // .departCode(nodeConfirmParam.getDepartCode()) + // .platformOrderCode(nodeConfirmParam.getPlatformOrderCode()) + // .node(nodeConfirmParam.getNode()) + // .workNode(WorkNodeEnums.CLERK_REVIEW.name()) + // .warehouseName(customPushEntity.getWarehouse()) + // .packageCode(customPushEntity.getPackageCode()) + // .content(body) + // .resultContent(result) + // .build(); + // // 推送成功 + // nodePushService.save(pushEntity); + // // 修改加盟商单号+发货单号节点数据 + // List list2 = nodeOrderService.list(Wrappers.lambdaQuery() + // .eq(ZbFactoryNodeOrderEntity::getPlatformOrderCode, customPushEntity.getOrderCode()) + // .eq(ZbFactoryNodeOrderEntity::getDepartCode, zbOrderPackageEntity.getDepartCode()) + // ); + // if (CollUtil.isNotEmpty(list2)) { + // ZbFactoryNodeOrderEntity zbFactoryNodeOrderEntity = list2.get(0); + // String pushNode = zbFactoryNodeOrderEntity.getPushNode(); + // Integer currentNode = zbFactoryNodeOrderEntity.getCurrentNode(); + // Integer index = node.getIndex(); + // if (currentNode < index) { + // pushNode = pushNode + "," + index; + // } + // zbFactoryNodeOrderEntity.setPushNode(pushNode); + // zbFactoryNodeOrderEntity.setCurrentNode(index); + // nodeOrderService.updateNodeOrder(zbFactoryNodeOrderEntity); + // } + // // 处理custom + // customPushService.update(Wrappers.lambdaUpdate() + // .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + // .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + // .set(CustomPushEntity::getSendStatus, type) + // .set(CustomPushEntity::getResultCode, code) + // .set(CustomPushEntity::getResult, result) + // ); + // } else { + // // 处理custom + // customPushService.update(Wrappers.lambdaUpdate() + // .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + // .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + // .set(CustomPushEntity::getSendStatus, type) + // .set(CustomPushEntity::getResultCode, code) + // .set(CustomPushEntity::getResult, result)); + // log.info("自定义回传失败"); + // } + // } + // } + // } catch (Exception e) { + // // 处理推送不成功的异常情况 + // log.error("zb节点推送数据异常:{}", e); + // // 保存日志 + // e.printStackTrace(); + // } + // }else { + // customPushService.update(Wrappers.lambdaUpdate() + // .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + // .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + // .set(CustomPushEntity::getSendStatus, type) + // .set(CustomPushEntity::getResultCode, "-1") + // .set(CustomPushEntity::getResult, "push中有记录") + // ); + // } + // }else { + // customPushService.update(Wrappers.lambdaUpdate() + // .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + // .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + // .set(CustomPushEntity::getSendStatus, type) + // .set(CustomPushEntity::getResultCode, "-1") + // .set(CustomPushEntity::getResult, "未找到包件订单") + // ); + // } + } + else if (type == 30) { + + int size1 = customPushEntities.size(); + List list = orderPackageService.list(Wrappers.lambdaQuery() + .select(ZbOrderPackageEntity::getDepartCode) + .eq(ZbOrderPackageEntity::getPackageCode, customPushEntity.getPackageCode()) + ); + if (CollUtil.isNotEmpty(list)) { + ZbOrderPackageEntity zbOrderPackageEntity = list.get(0); + List orderPackageEntities = orderPackageService.list(Wrappers.lambdaQuery() + .select(ZbOrderPackageEntity::getDepartCode, ZbOrderPackageEntity::getSignStatus, ZbOrderPackageEntity::getPlatformOrderCode, ZbOrderPackageEntity::getPackageCode) + .eq(ZbOrderPackageEntity::getPlatformOrderCode, customPushEntity.getOrderCode()) + .eq(ZbOrderPackageEntity::getDepartCode, zbOrderPackageEntity.getDepartCode()) + ); + if (CollUtil.isNotEmpty(orderPackageEntities)) { + // 总包件数 + int size = orderPackageEntities.size(); + List collect1 = orderPackageEntities.stream().filter(o -> ObjectUtil.equal(o.getSignStatus(), 1)).collect(Collectors.toList()); + int signNum = 0; + if (CollUtil.isNotEmpty(collect1)) { + signNum = collect1.size(); + } + if (signNum == (size - size1)) { + node = ZbomNodeEnums.SIGN_FOR; + }else{ + node = ZbomNodeEnums.PARTIAL_RECEIPT; + } + // List list1 = nodePushService.list(Wrappers.lambdaQuery() + // .select(ZbFactoryNodePushEntity::getId) + // .eq(ZbFactoryNodePushEntity::getDepartCode, zbOrderPackageEntity.getDepartCode()) + // .eq(ZbFactoryNodePushEntity::getPlatformOrderCode, customPushEntity.getOrderCode()) + // .eq(ZbFactoryNodePushEntity::getNode, node.getCode()) + // ); + // if (CollUtil.isEmpty(list1)) { + NodeConfirmParamDTO nodeConfirmParam = NodeConfirmParamDTO.builder() + // .address("到达【" + customPushEntity.getWarehouse() + "】") + .departCode(zbOrderPackageEntity.getDepartCode()) + .operator(customPushEntity.getExamineUserName()) + .operatorTime(customPushEntity.getSigningTime()) + .platformOrderCode(customPushEntity.getOrderCode()) + .signQty(Convert.toStr(size1)) + .node(node.getCode()).build(); + try { + // 推送给志邦 + String body = JSONUtil.toJsonStr(nodeConfirmParam); + String result = null; + if (zbProperties.getEnable()) { + result = ZbomUtil.pushZbomSystem(zbProperties, body, ZbomConstants.Method.ROUTE_NODE_CONFIRM); + } else { + JSONObject jsonObject = new JSONObject(); + jsonObject.set("code", "0"); + result = JSONUtil.toJsonStr(jsonObject); + } + log.info("zb节点推送数据:参数{},返回值{}。", body, result); + if (StrUtil.isNotBlank(result)) { + if (!StrUtil.contains(result, "code")) { + customPushService.update(Wrappers.lambdaUpdate() + .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + .set(CustomPushEntity::getSendStatus, type) + .set(CustomPushEntity::getResultCode, "-1") + .set(CustomPushEntity::getResult, "工厂返回异常") + ); + } else { + String packageCodes = customPushEntities.stream() + .map(CustomPushEntity::getPackageCode) + .filter(StrUtil::isNotEmpty) // 过滤掉空的包件码 + .collect(Collectors.joining(",")); + JSONObject resultJson = JSONUtil.parseObj(result); + String code = resultJson.getStr("code"); + if (ObjectUtil.equal(code, "0")) { + ZbFactoryNodePushEntity pushEntity = ZbFactoryNodePushEntity.builder() + .departCode(nodeConfirmParam.getDepartCode()) + .platformOrderCode(nodeConfirmParam.getPlatformOrderCode()) + .node(nodeConfirmParam.getNode()) + .workNode(WorkNodeEnums.CLERK_REVIEW.name()) + .warehouseName(customPushEntity.getWarehouse()) + .packageCode(packageCodes) + .content(body) + .resultContent(result) + .build(); + // 推送成功 + nodePushService.save(pushEntity); + // 修改加盟商单号+发货单号节点数据 + List list2 = nodeOrderService.list(Wrappers.lambdaQuery() + .eq(ZbFactoryNodeOrderEntity::getPlatformOrderCode, customPushEntity.getOrderCode()) + .eq(ZbFactoryNodeOrderEntity::getDepartCode, zbOrderPackageEntity.getDepartCode()) + ); + if (CollUtil.isNotEmpty(list2)) { + ZbFactoryNodeOrderEntity zbFactoryNodeOrderEntity = list2.get(0); + String pushNode = zbFactoryNodeOrderEntity.getPushNode(); + Integer currentNode = zbFactoryNodeOrderEntity.getCurrentNode(); + Integer index = node.getIndex(); + if (currentNode < index) { + pushNode = pushNode + "," + index; + } + zbFactoryNodeOrderEntity.setPushNode(pushNode); + zbFactoryNodeOrderEntity.setCurrentNode(index); + nodeOrderService.updateNodeOrder(zbFactoryNodeOrderEntity); + } + // 处理custom + customPushService.update(Wrappers.lambdaUpdate() + .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + .set(CustomPushEntity::getSendStatus, type) + .set(CustomPushEntity::getResultCode, code) + .set(CustomPushEntity::getResult, result) + ); + } else { + // 处理custom + customPushService.update(Wrappers.lambdaUpdate() + .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + .set(CustomPushEntity::getSendStatus, type) + .set(CustomPushEntity::getResultCode, code) + .set(CustomPushEntity::getResult, result)); + log.info("自定义回传失败"); + } + } + } + } catch (Exception e) { + // 处理推送不成功的异常情况 + log.error("zb节点推送数据异常:{}", e); + // 保存日志 + e.printStackTrace(); + } + // } + }else{ + customPushService.update(Wrappers.lambdaUpdate() + .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + .set(CustomPushEntity::getSendStatus, type) + .set(CustomPushEntity::getResultCode, "-1") + .set(CustomPushEntity::getResult, "未找到包件订单-发货单订单") + ); + } + }else{ + customPushService.update(Wrappers.lambdaUpdate() + .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + .set(CustomPushEntity::getSendStatus, type) + .set(CustomPushEntity::getResultCode, "-1") + .set(CustomPushEntity::getResult, "未找到包件订单-包件") + ); + } + } + } + + return ReturnT.SUCCESS; + } + + private void sendFactory(CustomPushEntity customPushEntity, ZbomNodeEnums node, Integer type, WorkNodeEnums initialWarehouseDepart, String address) { + List list = orderPackageService.list(Wrappers.lambdaQuery() + .select(ZbOrderPackageEntity::getDepartCode) + .eq(ZbOrderPackageEntity::getPackageCode, customPushEntity.getPackageCode()) + .eq(ZbOrderPackageEntity::getPlatformOrderCode, customPushEntity.getOrderCode()) + ); + if (CollUtil.isNotEmpty(list)) { + ZbOrderPackageEntity zbOrderPackageEntity = list.get(0); + List list1 = nodePushService.list(Wrappers.lambdaQuery() + .select(ZbFactoryNodePushEntity::getId) + .eq(ZbFactoryNodePushEntity::getDepartCode, zbOrderPackageEntity.getDepartCode()) + .eq(ZbFactoryNodePushEntity::getPlatformOrderCode, customPushEntity.getOrderCode()) + // .eq(ZbFactoryNodePushEntity::getWarehouseName, customPushEntity.getWarehouse()) + .eq(ZbFactoryNodePushEntity::getNode, node.getCode()) + ); + if (CollUtil.isEmpty(list1)) { + NodeConfirmParamDTO nodeConfirmParam = NodeConfirmParamDTO.builder().address(address) + .departCode(zbOrderPackageEntity.getDepartCode()) + .operator(customPushEntity.getExamineUserName()) + .operatorTime(customPushEntity.getSigningTime()) + .platformOrderCode(customPushEntity.getOrderCode()) + .node(node.getCode()).build(); + try { + // 推送给志邦 + String body = JSONUtil.toJsonStr(nodeConfirmParam); + String result = null; + if (zbProperties.getEnable()) { + result = ZbomUtil.pushZbomSystem(zbProperties, body, ZbomConstants.Method.ROUTE_NODE_CONFIRM); + } else { + JSONObject jsonObject = new JSONObject(); + jsonObject.set("code", "0"); + result = JSONUtil.toJsonStr(jsonObject); + } + log.info("zb节点推送数据:参数{},返回值{}。", body, result); + if (StrUtil.isNotBlank(result)) { + if (!StrUtil.contains(result, "code")) { + customPushService.update(Wrappers.lambdaUpdate() + .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + .set(CustomPushEntity::getSendStatus, type) + .set(CustomPushEntity::getResultCode, "-1") + .set(CustomPushEntity::getResult, "工厂返回结果异常") + ); + } else { + JSONObject resultJson = JSONUtil.parseObj(result); + String code = resultJson.getStr("code"); + if (ObjectUtil.equal(code, "0")) { + ZbFactoryNodePushEntity pushEntity = ZbFactoryNodePushEntity.builder() + .departCode(nodeConfirmParam.getDepartCode()) + .platformOrderCode(nodeConfirmParam.getPlatformOrderCode()) + .node(nodeConfirmParam.getNode()) + .workNode(initialWarehouseDepart.name()) + .warehouseName(customPushEntity.getWarehouse()) + .packageCode(customPushEntity.getPackageCode()) + .content(body) + .resultContent(result) + .build(); + // 推送成功 + nodePushService.save(pushEntity); + // 修改加盟商单号+发货单号节点数据 + List list2 = nodeOrderService.list(Wrappers.lambdaQuery() + .eq(ZbFactoryNodeOrderEntity::getPlatformOrderCode, customPushEntity.getOrderCode()) + .eq(ZbFactoryNodeOrderEntity::getDepartCode, zbOrderPackageEntity.getDepartCode()) + ); + if (CollUtil.isNotEmpty(list2)) { + ZbFactoryNodeOrderEntity zbFactoryNodeOrderEntity = list2.get(0); + String pushNode = zbFactoryNodeOrderEntity.getPushNode(); + Integer currentNode = zbFactoryNodeOrderEntity.getCurrentNode(); + Integer index = node.getIndex(); + if (currentNode < index) { + pushNode = pushNode + "," + index; + } + zbFactoryNodeOrderEntity.setPushNode(pushNode); + zbFactoryNodeOrderEntity.setCurrentNode(index); + nodeOrderService.updateNodeOrder(zbFactoryNodeOrderEntity); + } + // 处理custom + customPushService.update(Wrappers.lambdaUpdate() + .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + .set(CustomPushEntity::getSendStatus, type) + .set(CustomPushEntity::getResultCode, code) + .set(CustomPushEntity::getResult, result) + ); + } else { + // 处理custom + customPushService.update(Wrappers.lambdaUpdate() + .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + .set(CustomPushEntity::getSendStatus, type) + .set(CustomPushEntity::getResultCode, code) + .set(CustomPushEntity::getResult, result)); + log.info("自定义回传失败"); + } + } + } + } catch (Exception e) { + // 处理推送不成功的异常情况 + log.error("zb节点推送数据异常:{}", e); + // 保存日志 + e.printStackTrace(); + } + }else { + customPushService.update(Wrappers.lambdaUpdate() + .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + .set(CustomPushEntity::getSendStatus, type) + .set(CustomPushEntity::getResultCode, "-1") + .set(CustomPushEntity::getResult, "push里有记录") + ); + } + }else{ + customPushService.update(Wrappers.lambdaUpdate() + .eq(CustomPushEntity::getReservationId, customPushEntity.getReservationId()) + .eq(CustomPushEntity::getOrderCode, customPushEntity.getOrderCode()) + .set(CustomPushEntity::getSendStatus, type) + .set(CustomPushEntity::getResultCode, "-1") + .set(CustomPushEntity::getResult, "未找到包件订单") + ); + } + } + + + /** + * 添加回传数量字段,修正包件回传状态 + * + * @param param + * @Return com.xxl.job.core.biz.model.ReturnT + * @Author zqb 2024/11/4 + **/ + @XxlJob("checkPackageSignStatus") + public ReturnT checkPackageSignStatus(String param) throws Exception { + // 查询出需要回传的数据 + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery() + .select(ZbFactoryNodePushEntity::getPackageCode, ZbFactoryNodePushEntity::getId) + .in(ZbFactoryNodePushEntity::getNode, ZbomNodeEnums.SIGN_FOR.getCode(), ZbomNodeEnums.PARTIAL_RECEIPT.getCode()) + .isNull(ZbFactoryNodePushEntity::getSignNum) + .orderByAsc(ZbFactoryNodePushEntity::getId) + .last(" limit 500"); + if (StrUtil.isNotEmpty(param)) { + DateTime dateTime = DateUtil.parseDate(param); + wrapper.ge(ZbFactoryNodePushEntity::getCreateTime, dateTime); + } + List list = nodePushService.list(wrapper); + if (CollUtil.isNotEmpty(list)) { + for (ZbFactoryNodePushEntity entity : list) { + // ZbFactoryNodePushEntity entity = list.get(0); + String packageCode = entity.getPackageCode(); + if (StrUtil.isNotEmpty(packageCode)) { + String[] split = packageCode.split(","); + orderPackageService.update(Wrappers.lambdaUpdate() + .set(ZbOrderPackageEntity::getSignStatus, 1) + .in(ZbOrderPackageEntity::getPackageCode, split) + ); + nodePushService.update(Wrappers.lambdaUpdate() + .set(ZbFactoryNodePushEntity::getSignNum, split.length) + .eq(ZbFactoryNodePushEntity::getId, entity.getId()) + ); + } + } + + } + return ReturnT.SUCCESS; + } + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/CustomPushMapper.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/CustomPushMapper.java new file mode 100644 index 000000000..2c6211129 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/CustomPushMapper.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package com.logpm.factorydata.zbom.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.logpm.factorydata.zbom.entity.CustomPushEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 自定义回传 Mapper + * + * @author zqb + * @since 2024-03-26 + */ +@Mapper +public interface CustomPushMapper extends BaseMapper { + + List findData(@Param("type") Integer type); +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/CustomPushMapper.xml b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/CustomPushMapper.xml new file mode 100644 index 000000000..9997e1f91 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/CustomPushMapper.xml @@ -0,0 +1,17 @@ + + + + + + diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/FactoryNodeOrderMapper.xml b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/FactoryNodeOrderMapper.xml index 6290b2cba..871ad0007 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/FactoryNodeOrderMapper.xml +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/FactoryNodeOrderMapper.xml @@ -4,8 +4,7 @@ diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/OrderPackageMapper.xml b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/OrderPackageMapper.xml index cc27af552..d68a0f0b6 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/OrderPackageMapper.xml +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/OrderPackageMapper.xml @@ -2,8 +2,8 @@ - update zb_order_package t set t.sign_status = 1 where exists( - select 1 from ( + update zb_order_package t + join( select #{item} pid @@ -13,18 +13,18 @@ select #{item} pid - ) packageCodeIds where packageCodeIds.pid = t.package_code) + ) tt on tt.pid = t.package_code + set t.sign_status = 1 diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomFactoryOrderListener.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomFactoryOrderListener.java index a51563664..41a62af42 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomFactoryOrderListener.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomFactoryOrderListener.java @@ -1,69 +1,15 @@ package com.logpm.factorydata.zbom.mq; -import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.convert.Convert; -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.util.CharsetUtil; -import cn.hutool.core.util.NumberUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.core.util.URLUtil; -import cn.hutool.json.JSONObject; -import cn.hutool.json.JSONUtil; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.logpm.factorydata.base.feign.IFactoryDataBaseClient; -import com.logpm.factorydata.base.vo.FactoryWarehouseBindVO; -import com.logpm.factorydata.feign.IFactoryDataClient; -import com.logpm.factorydata.vo.SendMsg; -import com.logpm.factorydata.zbom.entity.FactoryLogEntity; -import com.logpm.factorydata.zbom.entity.ZbCategoryContrastEntity; -import com.logpm.factorydata.zbom.entity.ZbOrderPackageEntity; -import com.logpm.factorydata.zbom.entity.ZbPackageInfoEntity; -import com.logpm.factorydata.zbom.entity.ZbReceiptEntity; -import com.logpm.factorydata.zbom.mapper.ZbCategoryContrastMapper; -import com.logpm.factorydata.zbom.pros.ZbFactoryProperties; import com.logpm.factorydata.zbom.service.IOrderPackageService; -import com.logpm.factorydata.zbom.service.IPackageInfoService; -import com.logpm.factorydata.zbom.service.IReceiptService; -import com.logpm.factorydata.zbom.vo.OrderPackageDTO; -import com.logpm.factorydata.zbom.vo.PackageInfoDTO; -import com.logpm.factorydata.zbom.vo.ZBReceiptDTO; -import com.logpm.trunkline.entity.TrunklineAdvanceDetailEntity; -import com.logpm.trunkline.entity.TrunklineAdvanceEntity; -import com.logpm.trunkline.entity.TrunklineDetailProductEntity; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.common.annotations.LogpmAsync; -import org.springblade.common.constant.HttpConstants; -import org.springblade.common.constant.PatternConstant; -import org.springblade.common.constant.TenantNum; import org.springblade.common.constant.factorydata.FactoryDataConstants; -import org.springblade.core.redis.cache.BladeRedis; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.StringUtil; import org.springframework.amqp.core.ExchangeTypes; import org.springframework.amqp.rabbit.annotation.Exchange; import org.springframework.amqp.rabbit.annotation.Queue; import org.springframework.amqp.rabbit.annotation.QueueBinding; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -import java.math.BigDecimal; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; /** * 监听志邦订单数据 @@ -76,120 +22,19 @@ import java.util.stream.Collectors; @AllArgsConstructor public class ZbomFactoryOrderListener { - private final IReceiptService receiptService; - private final IPackageInfoService packageInfoService; private final IOrderPackageService orderPackageService; - private final ZbFactoryProperties zbFactoryProperties; @RabbitListener(bindings = @QueueBinding( value = @Queue(name = FactoryDataConstants.Mq.Queues.ZBOM_FACTORY_ORDER), exchange = @Exchange(name = FactoryDataConstants.Mq.Exchanges.FACTORY_ORDER, type = ExchangeTypes.TOPIC), key = FactoryDataConstants.Mq.RoutingKeys.ZBOM_FACTORY_ORDER )) - @Transactional(rollbackFor = Exception.class) public void factoryOrder(String msg) { - log.info("处理志邦订单:{}", msg); - if (StrUtil.isEmpty(msg)) { - log.error("消息内容为空"); - return; - } - FactoryLogEntity logEntity = JSONUtil.toBean(msg, FactoryLogEntity.class); - if (ObjectUtil.isEmpty(logEntity)) { - log.error("消息内容为空"); - return; - } - // 去 minio 下载文件到本地,然后解析文件内容为实体对象 - ZBReceiptDTO zbReceiptDTO = null; - Long logId = logEntity.getId(); - String logUrl = logEntity.getLogUrl(); - if (StrUtil.isNotEmpty(logUrl)) { - List res = new ArrayList<>(); - FileUtil.readLines(URLUtil.url(logUrl), CharsetUtil.CHARSET_UTF_8, res); - if (CollUtil.isNotEmpty(res)) { - String content = res.get(0); - if (StrUtil.isNotEmpty(content)) { - zbReceiptDTO = JSONUtil.toBean(content, ZBReceiptDTO.class); - } - } - } - if (ObjectUtil.isEmpty(zbReceiptDTO)) { - log.error("消息内容为空"); - return; - } - // 幂等控制,同一个入库单号只能入一次 - String taskCode = zbReceiptDTO.getTaskCode(); - if (StrUtil.isEmpty(taskCode)) { - log.error("入库单号为空"); - return; - } - if (CollUtil.isNotEmpty(receiptService.list(Wrappers.lambdaQuery().eq(ZbReceiptEntity::getTaskCode, taskCode)))) { - log.error("入库单号 {} 已推送过了", taskCode); - return; - } - // 查询当前这次推送的数据中的所有包件,校验其是否在数据库中已存在,存在则不保存 - Set packageCode = new HashSet<>(); - List details = zbReceiptDTO.getDetails(); - if (CollUtil.isNotEmpty(details)) { - // 收集包件编码 - List collect = details.stream().map(OrderPackageDTO::getPackageCode).collect(Collectors.toList()); - if (CollUtil.isNotEmpty(collect)) { - List packageCodes = orderPackageService.findByPackageCodes(collect); - if (CollUtil.isNotEmpty(packageCodes)) { - // 将packageCodes中的数据存到packageCode中 - packageCodes.forEach(item -> { - packageCode.add(item.getPackageCode()); - }); - } - } - } - ZbReceiptEntity zbReceiptEntity = new ZbReceiptEntity(); - BeanUtil.copyProperties(zbReceiptDTO, zbReceiptEntity); - zbReceiptEntity.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null); - // 保存订单数据 - receiptService.save(zbReceiptEntity); - if (CollUtil.isNotEmpty(details)) { - List packageEntities = new ArrayList<>(); - List packageInfoEntities = new ArrayList<>(); - for (OrderPackageDTO detail : details) { - if (packageCode.contains(detail.getPackageCode())) { - log.info(" 接收志邦数据:包条码 {} 已存在数据库中,不保存。", detail.getPackageCode()); - continue; - } - ZbOrderPackageEntity packageEntity = new ZbOrderPackageEntity(); - BeanUtil.copyProperties(detail, packageEntity); - packageEntity.setReceiptId(zbReceiptEntity.getId()); - packageEntity.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null); - packageEntities.add(packageEntity); - } - // 保存包件数据 - orderPackageService.saveBatch(packageEntities); - for (OrderPackageDTO detail : details) { - if (packageCode.contains(detail.getPackageCode())) { - continue; - } - Long detailId = null; - for (ZbOrderPackageEntity packageEntity : packageEntities) { - if (ObjectUtil.equal(packageEntity.getPackageCode(), detail.getPackageCode())) { - detailId = packageEntity.getId(); - } - } - List items = detail.getItems(); - if (CollUtil.isNotEmpty(items)) { - for (PackageInfoDTO item : items) { - ZbPackageInfoEntity packageInfoEntity = new ZbPackageInfoEntity(); - BeanUtil.copyProperties(item, packageInfoEntity); - packageInfoEntity.setPackageId(detailId); - packageInfoEntity.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null); - packageInfoEntities.add(packageInfoEntity); - } - } - } - // 保存物料数据 - packageInfoService.saveBatch(packageInfoEntities); - } - // 处理暂存单 - if(zbFactoryProperties.getIsAdvance()){ - receiptService.buildAdvance(zbReceiptDTO, packageCode); + try { + orderPackageService.saveOrder(msg); + }catch (Exception e){ + e.printStackTrace(); + log.error("处理志邦订单数据异常:{}", msg); } } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomNodeDataPushListener.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomNodeDataPushListener.java index 27c61e2cb..c84a9f6d0 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomNodeDataPushListener.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomNodeDataPushListener.java @@ -105,135 +105,142 @@ public class ZbomNodeDataPushListener { // 2 获取业务数据 // List packageCodeList = getBizData(entries); List content = entries.getBeanList("content", JSONObject.class); - if (CollUtil.isNotEmpty(content)) { - String warehouseName = content.get(0).getStr("warehouseName"); - String orderCode = content.get(0).getStr("orderCode"); - // 根据运单号和自编码分组查询出对应的数量 - List orders = orderPackageService.findOrderCodebypackageCodes(content); - Map nodeDataMap = new HashMap<>(); - if (CollUtil.isNotEmpty(orders)) { - for (NodeDataDTO order : orders) { - nodeDataMap.put(order.getDepartCode() + order.getPlatformOrderCode(), order); + try { + + + if (CollUtil.isNotEmpty(content)) { + String warehouseName = content.get(0).getStr("warehouseName"); + String orderCode = content.get(0).getStr("orderCode"); + // 根据运单号和自编码分组查询出对应的数量 + List orders = orderPackageService.findOrderCodebypackageCodes(content); + Map nodeDataMap = new HashMap<>(); + if (CollUtil.isNotEmpty(orders)) { + for (NodeDataDTO order : orders) { + nodeDataMap.put(order.getDepartCode() + order.getPlatformOrderCode(), order); + } + } else { + log.error("【{}】节点【{}】未查到数据", StrUtil.toString(content), node); + return; } - } else { - log.error("【{}】节点【{}】未查到数据", StrUtil.toString(content), node); - return; - } - if (CollUtil.isNotEmpty(nodeDataMap)) { - if (ObjectUtil.equals(workNodeEnums.getCode(), NodeNeedEnums.UNLOAD_INCOMING_WAREHOUSE.getCode())) { - for (Map.Entry stringNodeDataDTOEntry : nodeDataMap.entrySet()) { - NodeDataDTO value = stringNodeDataDTOEntry.getValue(); - // 卸车入库只发推一次 - List list = nodePushService.list(Wrappers.lambdaQuery() - .eq(ZbFactoryNodePushEntity::getPlatformOrderCode, orderCode) - .eq(ZbFactoryNodePushEntity::getWorkNode, node) - .eq(ZbFactoryNodePushEntity::getWarehouseName, warehouseName) - .eq(ZbFactoryNodePushEntity::getDepartCode, value.getDepartCode()) - ); - // 已经推送过了就不再推了 - if (CollUtil.isNotEmpty(list)) { - return; + if (CollUtil.isNotEmpty(nodeDataMap)) { + if (ObjectUtil.equals(workNodeEnums.getCode(), NodeNeedEnums.UNLOAD_INCOMING_WAREHOUSE.getCode())) { + for (Map.Entry stringNodeDataDTOEntry : nodeDataMap.entrySet()) { + NodeDataDTO value = stringNodeDataDTOEntry.getValue(); + // 卸车入库只发推一次 + List list = nodePushService.list(Wrappers.lambdaQuery() + .eq(ZbFactoryNodePushEntity::getPlatformOrderCode, orderCode) + .eq(ZbFactoryNodePushEntity::getWorkNode, node) + .eq(ZbFactoryNodePushEntity::getWarehouseName, warehouseName) + .eq(ZbFactoryNodePushEntity::getDepartCode, value.getDepartCode()) + ); + // 已经推送过了就不再推了 + if (CollUtil.isNotEmpty(list)) { + return; + } } } } - } - // 签收节点获取组装未签收数据 - Map noSignNumberMap = null; - if (EnumUtil.equals(WorkNodeEnums.CLERK_REVIEW, node)) { - noSignNumberMap = getNoSignNumber(content); - } - // 获取历史发送的节点数据 - List nodeOrderEntities = nodeOrderService.findHistoryNodeOrder(orders); - Map nodeOrderMap = new HashMap<>(); - if (CollUtil.isNotEmpty(nodeOrderEntities)) { - // 将nodeOrderEntities的数据封装到nodeOrderMap,以departCode+platformOrderCode为key - nodeOrderEntities.forEach(nodeOrderEntity -> { - String key = nodeOrderEntity.getDepartCode() + nodeOrderEntity.getPlatformOrderCode(); - nodeOrderMap.put(key, nodeOrderEntity); - }); - } - List nodeConfirmLsit = new ArrayList<>(); - Map sendMsgMap = new HashMap<>(); - // 构建提交参数 - buildParam(entries, node, workNodeEnums, orders, noSignNumberMap, nodeOrderMap, nodeConfirmLsit, sendMsgMap); - if (CollUtil.isNotEmpty(nodeConfirmLsit)) { - for (NodeConfirmParamDTO nodeConfirmParam : nodeConfirmLsit) { - log.info("zb节点数据推送NodeConfirmParamDTO:{}", JSONUtil.toJsonStr(nodeConfirmParam)); - try { - // 推送给志邦 - String key = nodeConfirmParam.getDepartCode() + nodeConfirmParam.getPlatformOrderCode(); - String body = JSONUtil.toJsonStr(nodeConfirmParam); - String result = null; - if (zbProperties.getEnable()) { - result = ZbomUtil.pushZbomSystem(zbProperties, body, ZbomConstants.Method.ROUTE_NODE_CONFIRM); - } else { - JSONObject jsonObject = new JSONObject(); - jsonObject.set("code", "0"); - result = JSONUtil.toJsonStr(jsonObject); - } - log.info("zb节点推送数据:参数{},返回值{}。", body, result); - if (StrUtil.isNotBlank(result)) { - NodeDataDTO nodeDataDTO = nodeDataMap.get(key); - String packageCode = nodeDataDTO.getPackageCode(); - ZbFactoryNodePushFailEntity build = ZbFactoryNodePushFailEntity.builder() - .content(body) - .resultContent(result) - .departCode(nodeConfirmParam.getDepartCode()) - .platformOrderCode(nodeConfirmParam.getPlatformOrderCode()) - .node(nodeConfirmParam.getNode()) - .packageCode(packageCode) - .build(); - if (!StrUtil.contains(result, "code")) { - // 推送失败 - nodePushFailService.save(build); + // 签收节点获取组装未签收数据 + Map noSignNumberMap = null; + if (EnumUtil.equals(WorkNodeEnums.CLERK_REVIEW, node)) { + noSignNumberMap = getNoSignNumber(content); + } + // 获取历史发送的节点数据 + List nodeOrderEntities = nodeOrderService.findHistoryNodeOrder(orders); + Map nodeOrderMap = new HashMap<>(); + if (CollUtil.isNotEmpty(nodeOrderEntities)) { + // 将nodeOrderEntities的数据封装到nodeOrderMap,以departCode+platformOrderCode为key + nodeOrderEntities.forEach(nodeOrderEntity -> { + String key = nodeOrderEntity.getDepartCode() + nodeOrderEntity.getPlatformOrderCode(); + nodeOrderMap.put(key, nodeOrderEntity); + }); + } + List nodeConfirmLsit = new ArrayList<>(); + Map sendMsgMap = new HashMap<>(); + // 构建提交参数 + buildParam(entries, node, workNodeEnums, orders, noSignNumberMap, nodeOrderMap, nodeConfirmLsit, sendMsgMap); + if (CollUtil.isNotEmpty(nodeConfirmLsit)) { + for (NodeConfirmParamDTO nodeConfirmParam : nodeConfirmLsit) { + log.info("zb节点数据推送NodeConfirmParamDTO:{}", JSONUtil.toJsonStr(nodeConfirmParam)); + try { + // 推送给志邦 + String key = nodeConfirmParam.getDepartCode() + nodeConfirmParam.getPlatformOrderCode(); + String body = JSONUtil.toJsonStr(nodeConfirmParam); + String result = null; + if (zbProperties.getEnable()) { + result = ZbomUtil.pushZbomSystem(zbProperties, body, ZbomConstants.Method.ROUTE_NODE_CONFIRM); } else { - JSONObject resultJson = JSONUtil.parseObj(result); - String code = resultJson.getStr("code"); - if (ObjectUtil.equal(code, "1")) { + JSONObject jsonObject = new JSONObject(); + jsonObject.set("code", "0"); + result = JSONUtil.toJsonStr(jsonObject); + } + log.info("zb节点推送数据:参数{},返回值{}。", body, result); + if (StrUtil.isNotBlank(result)) { + NodeDataDTO nodeDataDTO = nodeDataMap.get(key); + String packageCode = nodeDataDTO.getPackageCode(); + ZbFactoryNodePushFailEntity build = ZbFactoryNodePushFailEntity.builder() + .content(body) + .resultContent(result) + .departCode(nodeConfirmParam.getDepartCode()) + .platformOrderCode(nodeConfirmParam.getPlatformOrderCode()) + .node(nodeConfirmParam.getNode()) + .packageCode(packageCode) + .build(); + if (!StrUtil.contains(result, "code")) { // 推送失败 nodePushFailService.save(build); - } - if (ObjectUtil.isEmpty(packageCode)) { - continue; - } - if (ObjectUtil.equal(code, "0")) { - ZbFactoryNodePushEntity pushEntity = ZbFactoryNodePushEntity.builder() - .departCode(nodeConfirmParam.getDepartCode()) - .platformOrderCode(nodeConfirmParam.getPlatformOrderCode()) - .node(nodeConfirmParam.getNode()) - .workNode(node) - .warehouseName(warehouseName) - .packageCode(packageCode) - .content(body) - .resultContent(result) - .build(); - // 推送成功 - nodePushService.save(pushEntity); - // - if (ObjectUtil.equal(nodeConfirmParam.getNode(), ZbomNodeEnums.PARTIAL_RECEIPT.getCode()) - || ObjectUtil.equal(nodeConfirmParam.getNode(), ZbomNodeEnums.SIGN_FOR.getCode())) { - // 修改订单包件表的签收状态 - List packages = CollUtil.newArrayList(packageCode.split(",")); - orderPackageService.updateSignForStatus(packages); + } else { + JSONObject resultJson = JSONUtil.parseObj(result); + String code = resultJson.getStr("code"); + if (ObjectUtil.equal(code, "1")) { + // 推送失败 + nodePushFailService.save(build); } - if (sendMsgMap.containsKey(key)) { - factoryDataClient.sendMessage(sendMsgMap.get(key)); - log.info("补节点数据:{}", JSONUtil.toJsonStr(sendMsgMap.get(key))); + if (ObjectUtil.isEmpty(packageCode)) { + continue; + } + if (ObjectUtil.equal(code, "0")) { + if (sendMsgMap.containsKey(key)) { + factoryDataClient.sendMessage(sendMsgMap.get(key)); + log.info("补节点数据:{}", JSONUtil.toJsonStr(sendMsgMap.get(key))); + } + String[] split = packageCode.split(","); + ZbFactoryNodePushEntity pushEntity = ZbFactoryNodePushEntity.builder() + .departCode(nodeConfirmParam.getDepartCode()) + .platformOrderCode(nodeConfirmParam.getPlatformOrderCode()) + .node(nodeConfirmParam.getNode()) + .workNode(node) + .warehouseName(warehouseName) + .signNum(split.length) + .packageCode(packageCode) + .content(body) + .resultContent(result) + .build(); + // 推送成功 + nodePushService.save(pushEntity); + // + if (ObjectUtil.equal(nodeConfirmParam.getNode(), ZbomNodeEnums.PARTIAL_RECEIPT.getCode()) + || ObjectUtil.equal(nodeConfirmParam.getNode(), ZbomNodeEnums.SIGN_FOR.getCode())) { + // 修改订单包件表的签收状态 + List packages = CollUtil.newArrayList(packageCode.split(",")); + orderPackageService.updateSignForStatus(packages); + } + // 修改加盟商单号+发货单号节点数据 + nodeOrderService.updateNodeOrder(nodeOrderMap.get(key)); } - // 修改加盟商单号+发货单号节点数据 - nodeOrderService.updateNodeOrder(nodeOrderMap.get(key)); } } + } catch (Exception e) { + // 处理推送不成功的异常情况 + log.error("zb节点推送数据异常:{}", e); + // 保存日志 + e.printStackTrace(); } - } catch (Exception e) { - // 处理推送不成功的异常情况 - log.error("zb节点推送数据异常:{}", e); - // 保存日志 - - e.printStackTrace(); } } } + } catch (Exception e) { + log.error("zb接收到节点数据推送处理异常:{}", msg); } } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/CustomPushService.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/CustomPushService.java new file mode 100644 index 000000000..e71e47496 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/CustomPushService.java @@ -0,0 +1,17 @@ +package com.logpm.factorydata.zbom.service; + +import com.logpm.factorydata.zbom.entity.CustomPushEntity; +import org.springblade.core.mp.base.BaseService; + +import java.util.List; + +/** + * 自定义回传 服务类 + * + * @Author zqb + * @Date 2024/4/26 + **/ +public interface CustomPushService extends BaseService { + + List findData(Integer type); +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/IOrderPackageService.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/IOrderPackageService.java index e73b65609..4b398faf2 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/IOrderPackageService.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/IOrderPackageService.java @@ -40,4 +40,6 @@ public interface IOrderPackageService extends BaseService List findNoSignNumber(List content); List findByPackageCodes(List packageCodeList); + + void saveOrder(String msg); } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/CustomPusherviceImpl.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/CustomPusherviceImpl.java new file mode 100644 index 000000000..773ae875c --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/CustomPusherviceImpl.java @@ -0,0 +1,28 @@ +package com.logpm.factorydata.zbom.service.impl; + +import com.logpm.factorydata.zbom.entity.CustomPushEntity; +import com.logpm.factorydata.zbom.mapper.CustomPushMapper; +import com.logpm.factorydata.zbom.service.CustomPushService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 自定义回传 业务实现类 + * + * @Author zqb + * @Date 2024/4/26 + **/ +@Slf4j +@Service +@AllArgsConstructor +public class CustomPusherviceImpl extends BaseServiceImpl implements CustomPushService { + + @Override + public List findData(Integer type) { + return baseMapper.findData(type); + } +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/OrderPackageServiceImpl.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/OrderPackageServiceImpl.java index 2627ca6af..1cc5d6dd9 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/OrderPackageServiceImpl.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/OrderPackageServiceImpl.java @@ -16,17 +16,41 @@ */ package com.logpm.factorydata.zbom.service.impl; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.CharsetUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.core.util.URLUtil; import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.logpm.factorydata.zbom.entity.FactoryLogEntity; import com.logpm.factorydata.zbom.entity.ZbOrderPackageEntity; +import com.logpm.factorydata.zbom.entity.ZbPackageInfoEntity; +import com.logpm.factorydata.zbom.entity.ZbReceiptEntity; import com.logpm.factorydata.zbom.mapper.OrderPackageMapper; +import com.logpm.factorydata.zbom.pros.ZbFactoryProperties; import com.logpm.factorydata.zbom.service.IOrderPackageService; +import com.logpm.factorydata.zbom.service.IPackageInfoService; +import com.logpm.factorydata.zbom.service.IReceiptService; import com.logpm.factorydata.zbom.vo.NoSignNumberDTO; import com.logpm.factorydata.zbom.vo.OrderPackageDTO; import com.logpm.factorydata.zbom.vo.NodeDataDTO; +import com.logpm.factorydata.zbom.vo.PackageInfoDTO; +import com.logpm.factorydata.zbom.vo.ZBReceiptDTO; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springblade.core.mp.base.BaseServiceImpl; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; /** * 志邦入库订单和包件 服务实现类 @@ -35,8 +59,14 @@ import java.util.List; * @since 2023-08-21 */ @Service +@Slf4j +@AllArgsConstructor public class OrderPackageServiceImpl extends BaseServiceImpl implements IOrderPackageService { + private final IReceiptService receiptService; + private final IPackageInfoService packageInfoService; + private final ZbFactoryProperties zbFactoryProperties; + @Override public List findOrderCodebypackageCodes(List content) { List orders = this.baseMapper.findOrderCodebypackageCodes(content); @@ -57,4 +87,113 @@ public class OrderPackageServiceImpl extends BaseServiceImpl findByPackageCodes(List packageCodeList) { return this.baseMapper.findByPackageCodes(packageCodeList); } + + @Override + @Transactional(rollbackFor = Exception.class) + public void saveOrder(String msg) { + log.info("处理志邦订单:{}", msg); + if (StrUtil.isEmpty(msg)) { + log.error("消息内容为空"); + return; + } + FactoryLogEntity logEntity = JSONUtil.toBean(msg, FactoryLogEntity.class); + if (ObjectUtil.isEmpty(logEntity)) { + log.error("消息内容为空"); + return; + } + // 去 minio 下载文件到本地,然后解析文件内容为实体对象 + ZBReceiptDTO zbReceiptDTO = null; + Long logId = logEntity.getId(); + String logUrl = logEntity.getLogUrl(); + if (StrUtil.isNotEmpty(logUrl)) { + List res = new ArrayList<>(); + FileUtil.readLines(URLUtil.url(logUrl), CharsetUtil.CHARSET_UTF_8, res); + if (CollUtil.isNotEmpty(res)) { + String content = res.get(0); + if (StrUtil.isNotEmpty(content)) { + zbReceiptDTO = JSONUtil.toBean(content, ZBReceiptDTO.class); + } + } + } + if (ObjectUtil.isEmpty(zbReceiptDTO)) { + log.error("消息内容为空"); + return; + } + // 幂等控制,同一个入库单号只能入一次 + String taskCode = zbReceiptDTO.getTaskCode(); + if (StrUtil.isEmpty(taskCode)) { + log.error("入库单号为空"); + return; + } + if (CollUtil.isNotEmpty(receiptService.list(Wrappers.lambdaQuery().eq(ZbReceiptEntity::getTaskCode, taskCode)))) { + log.error("入库单号 {} 已推送过了", taskCode); + return; + } + // 查询当前这次推送的数据中的所有包件,校验其是否在数据库中已存在,存在则不保存 + Set packageCode = new HashSet<>(); + List details = zbReceiptDTO.getDetails(); + if (CollUtil.isNotEmpty(details)) { + // 收集包件编码 + List collect = details.stream().map(OrderPackageDTO::getPackageCode).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(collect)) { + List packageCodes = this.findByPackageCodes(collect); + if (CollUtil.isNotEmpty(packageCodes)) { + // 将packageCodes中的数据存到packageCode中 + packageCodes.forEach(item -> { + packageCode.add(item.getPackageCode()); + }); + } + } + } + ZbReceiptEntity zbReceiptEntity = new ZbReceiptEntity(); + BeanUtil.copyProperties(zbReceiptDTO, zbReceiptEntity); + zbReceiptEntity.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null); + // 保存订单数据 + receiptService.save(zbReceiptEntity); + if (CollUtil.isNotEmpty(details)) { + List packageEntities = new ArrayList<>(); + List packageInfoEntities = new ArrayList<>(); + for (OrderPackageDTO detail : details) { + if (packageCode.contains(detail.getPackageCode())) { + log.info(" 接收志邦数据:包条码 {} 已存在数据库中,不保存。", detail.getPackageCode()); + continue; + } + ZbOrderPackageEntity packageEntity = new ZbOrderPackageEntity(); + BeanUtil.copyProperties(detail, packageEntity); + packageEntity.setReceiptId(zbReceiptEntity.getId()); + packageEntity.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null); + packageEntity.setDepartCode(zbReceiptDTO.getDepartCode()); + packageEntities.add(packageEntity); + } + // 保存包件数据 + this.saveBatch(packageEntities); + for (OrderPackageDTO detail : details) { + if (packageCode.contains(detail.getPackageCode())) { + continue; + } + Long detailId = null; + for (ZbOrderPackageEntity packageEntity : packageEntities) { + if (ObjectUtil.equal(packageEntity.getPackageCode(), detail.getPackageCode())) { + detailId = packageEntity.getId(); + } + } + List items = detail.getItems(); + if (CollUtil.isNotEmpty(items)) { + for (PackageInfoDTO item : items) { + ZbPackageInfoEntity packageInfoEntity = new ZbPackageInfoEntity(); + BeanUtil.copyProperties(item, packageInfoEntity); + packageInfoEntity.setPackageId(detailId); + packageInfoEntity.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null); + packageInfoEntities.add(packageInfoEntity); + } + } + } + // 保存物料数据 + packageInfoService.saveBatch(packageInfoEntities); + } + // 处理暂存单 + if (zbFactoryProperties.getIsAdvance()) { + receiptService.buildAdvance(zbReceiptDTO, packageCode); + } + } } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/ReceiptServiceImpl.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/ReceiptServiceImpl.java index 1c7d5f135..6b8f3db46 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/ReceiptServiceImpl.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/ReceiptServiceImpl.java @@ -288,4 +288,5 @@ public class ReceiptServiceImpl extends BaseServiceImpl