Browse Source

feat(all): 志邦工厂

1 增加志邦工厂自定义回传逻辑
2 修改志邦工厂接收工厂订单处理逻辑
3 修改回传处理逻辑
fix-sign
zhaoqiaobo 5 months ago
parent
commit
3cd993fba2
  1. 74
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/config/XxlJobConfig.java
  2. 58
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/entity/CustomPushEntity.java
  3. 5
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/entity/ZbFactoryNodePushEntity.java
  4. 11
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/entity/ZbOrderPackageEntity.java
  5. 647
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/job/CustomPushJob.java
  6. 36
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/CustomPushMapper.java
  7. 17
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/CustomPushMapper.xml
  8. 5
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/FactoryNodeOrderMapper.xml
  9. 40
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/OrderPackageMapper.xml
  10. 165
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomFactoryOrderListener.java
  11. 235
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomNodeDataPushListener.java
  12. 17
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/CustomPushService.java
  13. 2
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/IOrderPackageService.java
  14. 28
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/CustomPusherviceImpl.java
  15. 139
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/OrderPackageServiceImpl.java
  16. 1
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/ReceiptServiceImpl.java
  17. 1
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/resources/application-dev.yml

74
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引入依赖
* <dependency>
* <groupId>org.springframework.cloud</groupId>
* <artifactId>spring-cloud-commons</artifactId>
* <version>${version}</version>
* </dependency>
*
* 2配置文件或者容器启动变量
* spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
*
* 3获取IP
* String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
*/
}

58
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;
}

5
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;
}

11
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;
/**
* 状态
*/

647
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<String> customPushFactoryData(String param) throws Exception {
// 获取参数 5 场站发车 10 回传在途 20 回传送货抵达 30 回传签收
if (StrUtil.isEmpty(param)) {
return ReturnT.SUCCESS;
}
Integer type = Integer.valueOf(param);
// 查询出需要回传的数据
List<CustomPushEntity> customPushEntities = customPushService.findData(type);
if (CollUtil.isNotEmpty(customPushEntities)) {
// Set<String> 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<ZbOrderPackageEntity> list = orderPackageService.list(Wrappers.<ZbOrderPackageEntity>lambdaQuery()
// .select(ZbOrderPackageEntity::getDepartCode)
// .eq(ZbOrderPackageEntity::getPackageCode, customPushEntity.getPackageCode())
// .eq(ZbOrderPackageEntity::getPlatformOrderCode, customPushEntity.getOrderCode())
// );
// if (CollUtil.isNotEmpty(list)) {
// ZbOrderPackageEntity zbOrderPackageEntity = list.get(0);
// List<ZbFactoryNodePushEntity> list1 = nodePushService.list(Wrappers.<ZbFactoryNodePushEntity>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.<CustomPushEntity>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<ZbFactoryNodeOrderEntity> list2 = nodeOrderService.list(Wrappers.<ZbFactoryNodeOrderEntity>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.<CustomPushEntity>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.<CustomPushEntity>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.<CustomPushEntity>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.<CustomPushEntity>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<ZbOrderPackageEntity> list = orderPackageService.list(Wrappers.<ZbOrderPackageEntity>lambdaQuery()
// .select(ZbOrderPackageEntity::getDepartCode)
// .eq(ZbOrderPackageEntity::getPackageCode, customPushEntity.getPackageCode())
// .eq(ZbOrderPackageEntity::getPlatformOrderCode, customPushEntity.getOrderCode())
// );
// if (CollUtil.isNotEmpty(list)) {
// ZbOrderPackageEntity zbOrderPackageEntity = list.get(0);
// List<ZbFactoryNodePushEntity> list1 = nodePushService.list(Wrappers.<ZbFactoryNodePushEntity>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.<CustomPushEntity>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<ZbFactoryNodeOrderEntity> list2 = nodeOrderService.list(Wrappers.<ZbFactoryNodeOrderEntity>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.<CustomPushEntity>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.<CustomPushEntity>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.<CustomPushEntity>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.<CustomPushEntity>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<ZbOrderPackageEntity> list = orderPackageService.list(Wrappers.<ZbOrderPackageEntity>lambdaQuery()
.select(ZbOrderPackageEntity::getDepartCode)
.eq(ZbOrderPackageEntity::getPackageCode, customPushEntity.getPackageCode())
);
if (CollUtil.isNotEmpty(list)) {
ZbOrderPackageEntity zbOrderPackageEntity = list.get(0);
List<ZbOrderPackageEntity> orderPackageEntities = orderPackageService.list(Wrappers.<ZbOrderPackageEntity>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<ZbOrderPackageEntity> 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<ZbFactoryNodePushEntity> list1 = nodePushService.list(Wrappers.<ZbFactoryNodePushEntity>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.<CustomPushEntity>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<ZbFactoryNodeOrderEntity> list2 = nodeOrderService.list(Wrappers.<ZbFactoryNodeOrderEntity>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.<CustomPushEntity>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.<CustomPushEntity>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.<CustomPushEntity>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.<CustomPushEntity>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<ZbOrderPackageEntity> list = orderPackageService.list(Wrappers.<ZbOrderPackageEntity>lambdaQuery()
.select(ZbOrderPackageEntity::getDepartCode)
.eq(ZbOrderPackageEntity::getPackageCode, customPushEntity.getPackageCode())
.eq(ZbOrderPackageEntity::getPlatformOrderCode, customPushEntity.getOrderCode())
);
if (CollUtil.isNotEmpty(list)) {
ZbOrderPackageEntity zbOrderPackageEntity = list.get(0);
List<ZbFactoryNodePushEntity> list1 = nodePushService.list(Wrappers.<ZbFactoryNodePushEntity>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.<CustomPushEntity>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<ZbFactoryNodeOrderEntity> list2 = nodeOrderService.list(Wrappers.<ZbFactoryNodeOrderEntity>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.<CustomPushEntity>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.<CustomPushEntity>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.<CustomPushEntity>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.<CustomPushEntity>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<java.lang.String>
* @Author zqb 2024/11/4
**/
@XxlJob("checkPackageSignStatus")
public ReturnT<String> checkPackageSignStatus(String param) throws Exception {
// 查询出需要回传的数据
LambdaQueryWrapper<ZbFactoryNodePushEntity> wrapper = Wrappers.<ZbFactoryNodePushEntity>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<ZbFactoryNodePushEntity> 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.<ZbOrderPackageEntity>lambdaUpdate()
.set(ZbOrderPackageEntity::getSignStatus, 1)
.in(ZbOrderPackageEntity::getPackageCode, split)
);
nodePushService.update(Wrappers.<ZbFactoryNodePushEntity>lambdaUpdate()
.set(ZbFactoryNodePushEntity::getSignNum, split.length)
.eq(ZbFactoryNodePushEntity::getId, entity.getId())
);
}
}
}
return ReturnT.SUCCESS;
}
}

36
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<CustomPushEntity> {
List<CustomPushEntity> findData(@Param("type") Integer type);
}

17
blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/CustomPushMapper.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.logpm.factorydata.zbom.mapper.CustomPushMapper">
<select id="findData" resultType="com.logpm.factorydata.zbom.entity.CustomPushEntity">
select tt.reservation_id,tt.order_code,tt.package_code,tt.examine_user_name,tt.signing_time
from zb_custom_push tt
join (
select t.reservation_id,t.order_code
from zb_custom_push t
where t.send_status &lt; #{type}
group by t.reservation_id,t.order_code
limit 1
) aa on aa.order_code = tt.order_code and aa.reservation_id = tt.reservation_id
order by tt.signing_time
</select>
</mapper>

5
blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/FactoryNodeOrderMapper.xml

@ -4,8 +4,7 @@
<select id="findHistoryNodeOrder" resultType="com.logpm.factorydata.zbom.entity.ZbFactoryNodeOrderEntity">
select t.id,t.depart_code,t.platform_order_code,t.push_node,t.current_node from zb_factory_node_order t
where exists(
select 1 from (
join(
<foreach collection="orders" index="ind" item="item">
<if test="ind == 0">
select #{item.departCode} departCode,#{item.platformOrderCode} platformOrderCode
@ -15,6 +14,6 @@
select #{item.departCode} departCode,#{item.platformOrderCode} platformOrderCode
</if>
</foreach>
) orders where orders.departCode = t.depart_code and orders.platformOrderCode = t.platform_order_code)
) tt on tt.departCode = t.depart_code and tt.platformOrderCode = t.platform_order_code
</select>
</mapper>

40
blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/OrderPackageMapper.xml

@ -2,8 +2,8 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.logpm.factorydata.zbom.mapper.OrderPackageMapper">
<update id="updateSignForStatus">
update zb_order_package t set t.sign_status = 1 where exists(
select 1 from (
update zb_order_package t
join(
<foreach collection="packageCodeList" index="ind" item="item">
<if test="ind == 0">
select #{item} pid
@ -13,18 +13,18 @@
select #{item} pid
</if>
</foreach>
) packageCodeIds where packageCodeIds.pid = t.package_code)
) tt on tt.pid = t.package_code
set t.sign_status = 1
</update>
<select id="findOrderCodebypackageCodes" resultType="com.logpm.factorydata.zbom.vo.NodeDataDTO">
select re.depart_code,
select t.depart_code,
t.platform_order_code,
t.package_code,
group_concat(t.package_code) packageCode,
count(*) signQty
from zb_order_package t
left join zb_receipt re on re.id = t.receipt_id
where exists(
select 1 from (
join(
<foreach collection="packageList" index="ind" item="item">
<if test="ind == 0">
select #{item.packageCode} pid
@ -34,21 +34,15 @@
select #{item.packageCode} pid
</if>
</foreach>
) packageCodeIds where packageCodeIds.pid = t.package_code)
and t.sign_status = 0
group by re.depart_code, t.platform_order_code
) tt on tt.pid = t.package_code
group by t.depart_code, t.platform_order_code
</select>
<select id="findNoSignNumber" resultType="com.logpm.factorydata.zbom.vo.NoSignNumberDTO">
select re.depart_code departCode,
select t.depart_code departCode,
t.platform_order_code platformOrderCode,
count(*) num
from zb_order_package t
left join zb_receipt re on re.id = t.receipt_id
where t.platform_order_code in (
select tt.platform_order_code
from zb_order_package tt
where exists(
select 1 from (
join(
<foreach collection="packageCodeList" index="ind" item="item">
<if test="ind == 0">
select #{item.packageCode} pid
@ -58,15 +52,13 @@
select #{item.packageCode} pid
</if>
</foreach>
) packageCodeIds where packageCodeIds.pid = tt.package_code)
)
and t.sign_status = 0
group by re.depart_code, t.platform_order_code
) tt on tt.pid = t.package_code
where t.sign_status = 0
group by t.depart_code, t.platform_order_code
</select>
<select id="findByPackageCodes" resultType="com.logpm.factorydata.zbom.vo.OrderPackageDTO">
select t.package_code from zb_order_package t
where exists(
select 1 from (
join(
<foreach collection="packageCodeList" index="ind" item="item">
<if test="ind == 0">
select #{item} pid
@ -76,7 +68,7 @@
select #{item} pid
</if>
</foreach>
) packageCodes where packageCodes.pid = t.package_code)
) tt on tt.pid = t.package_code
</select>
</mapper>

165
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<String> 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.<ZbReceiptEntity>lambdaQuery().eq(ZbReceiptEntity::getTaskCode, taskCode)))) {
log.error("入库单号 {} 已推送过了", taskCode);
return;
}
// 查询当前这次推送的数据中的所有包件,校验其是否在数据库中已存在,存在则不保存
Set<String> packageCode = new HashSet<>();
List<OrderPackageDTO> details = zbReceiptDTO.getDetails();
if (CollUtil.isNotEmpty(details)) {
// 收集包件编码
List<String> collect = details.stream().map(OrderPackageDTO::getPackageCode).collect(Collectors.toList());
if (CollUtil.isNotEmpty(collect)) {
List<OrderPackageDTO> 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<ZbOrderPackageEntity> packageEntities = new ArrayList<>();
List<ZbPackageInfoEntity> 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<PackageInfoDTO> 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);
}
}

235
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<String> packageCodeList = getBizData(entries);
List<JSONObject> 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<NodeDataDTO> orders = orderPackageService.findOrderCodebypackageCodes(content);
Map<String, NodeDataDTO> 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<NodeDataDTO> orders = orderPackageService.findOrderCodebypackageCodes(content);
Map<String, NodeDataDTO> 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<String, NodeDataDTO> stringNodeDataDTOEntry : nodeDataMap.entrySet()) {
NodeDataDTO value = stringNodeDataDTOEntry.getValue();
// 卸车入库只发推一次
List<ZbFactoryNodePushEntity> list = nodePushService.list(Wrappers.<ZbFactoryNodePushEntity>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<String, NodeDataDTO> stringNodeDataDTOEntry : nodeDataMap.entrySet()) {
NodeDataDTO value = stringNodeDataDTOEntry.getValue();
// 卸车入库只发推一次
List<ZbFactoryNodePushEntity> list = nodePushService.list(Wrappers.<ZbFactoryNodePushEntity>lambdaQuery()
.eq(ZbFactoryNodePushEntity::getPlatformOrderCode, orderCode)
.eq(ZbFactoryNodePushEntity::getWorkNode, node)
.eq(ZbFactoryNodePushEntity::getWarehouseName, warehouseName)
.eq(ZbFactoryNodePushEntity::getDepartCode, value.getDepartCode())
);
// 已经推送过了就不再推了
if (CollUtil.isNotEmpty(list)) {
return;
}
}
}
}
}
// 签收节点获取组装未签收数据
Map<String, Integer> noSignNumberMap = null;
if (EnumUtil.equals(WorkNodeEnums.CLERK_REVIEW, node)) {
noSignNumberMap = getNoSignNumber(content);
}
// 获取历史发送的节点数据
List<ZbFactoryNodeOrderEntity> nodeOrderEntities = nodeOrderService.findHistoryNodeOrder(orders);
Map<String, ZbFactoryNodeOrderEntity> 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<NodeConfirmParamDTO> nodeConfirmLsit = new ArrayList<>();
Map<String, SendMsg> 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<String, Integer> noSignNumberMap = null;
if (EnumUtil.equals(WorkNodeEnums.CLERK_REVIEW, node)) {
noSignNumberMap = getNoSignNumber(content);
}
// 获取历史发送的节点数据
List<ZbFactoryNodeOrderEntity> nodeOrderEntities = nodeOrderService.findHistoryNodeOrder(orders);
Map<String, ZbFactoryNodeOrderEntity> 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<NodeConfirmParamDTO> nodeConfirmLsit = new ArrayList<>();
Map<String, SendMsg> 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<String> 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<String> 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);
}
}

17
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<CustomPushEntity> {
List<CustomPushEntity> findData(Integer type);
}

2
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<ZbOrderPackageEntity>
List<NoSignNumberDTO> findNoSignNumber(List<JSONObject> content);
List<OrderPackageDTO> findByPackageCodes(List<String> packageCodeList);
void saveOrder(String msg);
}

28
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<CustomPushMapper, CustomPushEntity> implements CustomPushService {
@Override
public List<CustomPushEntity> findData(Integer type) {
return baseMapper.findData(type);
}
}

139
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<OrderPackageMapper, ZbOrderPackageEntity> implements IOrderPackageService {
private final IReceiptService receiptService;
private final IPackageInfoService packageInfoService;
private final ZbFactoryProperties zbFactoryProperties;
@Override
public List<NodeDataDTO> findOrderCodebypackageCodes(List<JSONObject> content) {
List<NodeDataDTO> orders = this.baseMapper.findOrderCodebypackageCodes(content);
@ -57,4 +87,113 @@ public class OrderPackageServiceImpl extends BaseServiceImpl<OrderPackageMapper,
public List<OrderPackageDTO> findByPackageCodes(List<String> 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<String> 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.<ZbReceiptEntity>lambdaQuery().eq(ZbReceiptEntity::getTaskCode, taskCode)))) {
log.error("入库单号 {} 已推送过了", taskCode);
return;
}
// 查询当前这次推送的数据中的所有包件,校验其是否在数据库中已存在,存在则不保存
Set<String> packageCode = new HashSet<>();
List<OrderPackageDTO> details = zbReceiptDTO.getDetails();
if (CollUtil.isNotEmpty(details)) {
// 收集包件编码
List<String> collect = details.stream().map(OrderPackageDTO::getPackageCode).collect(Collectors.toList());
if (CollUtil.isNotEmpty(collect)) {
List<OrderPackageDTO> 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<ZbOrderPackageEntity> packageEntities = new ArrayList<>();
List<ZbPackageInfoEntity> 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<PackageInfoDTO> 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);
}
}
}

1
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<ReceiptMapper, ZbReceipt
Matcher matcher = pattern.matcher(str);
return matcher.find();
}
}

1
blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/resources/application-dev.yml

@ -34,6 +34,7 @@ spring:
multiplier: 1 # 失败的等待时长倍数,下次等待时长 = multiplier * last-interval
max-attempts: 3 # 最大重试次数
stateless: true # true无状态;false有状态。如果业务中包含事务,这里改为false
prefetch: 1
direct:
acknowledge-mode: manual
template:

Loading…
Cancel
Save