Browse Source

feat(all): 金牌工厂

1 增加金牌工厂圣都运输单数据同步
dev
zhaoqiaobo 2 months ago
parent
commit
07ebfc6bf7
  1. 7
      blade-biz-common/src/main/java/org/springblade/common/constant/factorydata/FactoryDataConstants.java
  2. 37
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/config/InterceptorAdapterConfig.java
  3. 41
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/controller/OrderController.java
  4. 88
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/JpFactoryOrderEntity.java
  5. 72
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/JpFactoryPackageEntity.java
  6. 64
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/JpFactoryShipmentEntity.java
  7. 136
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/interceptor/FactoryAccountsInterceptor.java
  8. 39
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/interceptor/LocalServerLoginAccountsInterceptor.java
  9. 16
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/JpFactoryOrderMapper.java
  10. 5
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/JpFactoryOrderMapper.xml
  11. 16
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/JpFactoryPackageMapper.java
  12. 5
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/JpFactoryPackageMapper.xml
  13. 21
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/JpFactoryShipmentMapper.java
  14. 16
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/JpFactoryShipmentMapper.xml
  15. 275
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mq/FactoryOrderListener.java
  16. 6
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/pros/JinPaiProperties.java
  17. 3
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/DeliveryNoteService.java
  18. 14
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/JpFactoryOrderService.java
  19. 14
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/JpFactoryPackageService.java
  20. 19
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/JpFactoryShipmentService.java
  21. 14
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/MqWorkerService.java
  22. 157
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/DeliveryNoteServiceImpl.java
  23. 22
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/JpFactoryOrderServiceImpl.java
  24. 22
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/JpFactoryPackageServiceImpl.java
  25. 137
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/JpFactoryShipmentServiceImpl.java
  26. 356
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/MqWorkerServiceImpl.java
  27. 28
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/FactoryAuthVO.java
  28. 27
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/FactoryOrderDataVO.java
  29. 25
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/JpFactoryOrderVO.java
  30. 21
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/JpFactoryPackageVO.java
  31. 25
      blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/JpFactoryShipmentVO.java
  32. 20
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mq/AdvanceOrderListener.java
  33. 1
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/IAdvanceOrderMqService.java
  34. 138
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/AdvanceOrderMqServiceImpl.java

7
blade-biz-common/src/main/java/org/springblade/common/constant/factorydata/FactoryDataConstants.java

@ -59,6 +59,10 @@ public abstract class FactoryDataConstants {
* 工厂数据转暂存单
*/
String ADVANCE_ORDER_OUPAI = "factory.data.queue.advanceOrder.oupai" + DEVAUTH;
/**
* 工厂数据转暂存单
*/
String ADVANCE_ORDER_JP = "factory.data.queue.advanceOrder.jp" + DEVAUTH;
/**
* 志邦作业节点数据推送
@ -90,6 +94,7 @@ public abstract class FactoryDataConstants {
*/
String JP_NODE_DATA_PUSH = "factory.data.queue.jp.nodeDataPush" + DEVAUTH;
String JP_FACTORY_ORDER = "factory.data.queue.jp.factoryOrder" + DEVAUTH;
String JP_FACTORY_SHIPMENT = "factory.data.queue.jp.factoryShipment" + DEVAUTH;
/**
* 皮阿诺作业节点数据推送
*/
@ -112,6 +117,7 @@ public abstract class FactoryDataConstants {
* 工厂数据转暂存单
*/
String ADVANCE_ORDER = "advanceOrder" + DEVAUTH;
String ADVANCE_ORDER_JP = "advanceOrder.jp" + DEVAUTH;
/**
* 志邦作业节点数据推送
*/
@ -142,6 +148,7 @@ public abstract class FactoryDataConstants {
*/
String JP_NODE_DATA_PUSH = "jp.nodeDataPush" + DEVAUTH;
String JP_FACTORY_ORDER = "jp.factoryOrder" + DEVAUTH;
String JP_FACTORY_SHIPMENT = "jp.factoryShipment" + DEVAUTH;
/**
* 皮阿诺作业节点数据推送
*/

37
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/config/InterceptorAdapterConfig.java

@ -2,34 +2,49 @@ package com.logpm.factorydata.jinpai.config;
import com.logpm.factorydata.jinpai.interceptor.FactoryAccountsInterceptor;
import com.logpm.factorydata.jinpai.interceptor.LocalServerLoginAccountsInterceptor;
import com.logpm.factorydata.jinpai.pros.JinPaiProperties;
import com.logpm.factorydata.jinpai.service.IFactoryTokenService;
import lombok.AllArgsConstructor;
import com.logpm.factorydata.jinpai.service.JpFactoryShipmentService;
import org.springblade.common.component.MockLoginService;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.redis.lock.RedisLockClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.Resource;
@Configuration
@AllArgsConstructor
public class InterceptorAdapterConfig implements WebMvcConfigurer {
private final IFactoryTokenService factoryTokenService;
@Resource
private IFactoryTokenService factoryTokenService;
private final BladeRedis redis;
@Resource
private BladeRedis redis;
private final Environment environment;
private final RedisLockClient redisLockClient;
private final MockLoginService mockLoginService;
@Resource
private Environment environment;
@Resource
private RedisLockClient redisLockClient;
@Resource
private MockLoginService mockLoginService;
@Lazy
@Resource
private JpFactoryShipmentService jpFactoryShipmentService;
@Resource
private JinPaiProperties jinPaiProperties;
@Override
public void addInterceptors(InterceptorRegistry interceptorRegistry) {
// interceptorRegistry.addInterceptor(new FactoryAccountsInterceptor(factoryTokenService))
// .addPathPatterns("/**").order(1);
interceptorRegistry.addInterceptor(new LocalServerLoginAccountsInterceptor(redis, environment,redisLockClient,mockLoginService))
.addPathPatterns("/**").order(2);
interceptorRegistry.addInterceptor(new FactoryAccountsInterceptor(redis, environment, redisLockClient, mockLoginService, jinPaiProperties, jpFactoryShipmentService))
.addPathPatterns("/order/v1").order(3);
interceptorRegistry.addInterceptor(new LocalServerLoginAccountsInterceptor(redis, environment, redisLockClient, mockLoginService, jinPaiProperties, jpFactoryShipmentService))
.addPathPatterns("/**")
.excludePathPatterns("/order/v1")
.order(2);
}
}

41
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/controller/OrderController.java

@ -1,11 +1,16 @@
package com.logpm.factorydata.jinpai.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.logpm.factorydata.jinpai.pros.JinPaiProperties;
import com.logpm.factorydata.jinpai.service.DeliveryNoteService;
import com.logpm.factorydata.jinpai.service.JpFactoryShipmentService;
import com.logpm.factorydata.jinpai.vo.DeliveryNoteVO;
import com.logpm.factorydata.jinpai.vo.FactoryOrderDataVO;
import com.logpm.factorydata.jinpai.vo.JpFactoryShipmentVO;
import com.logpm.factorydata.jinpai.vo.OrderInfoVO;
import com.logpm.factorydata.jinpai.vo.PackageInfoVO;
import com.logpm.factorydata.jinpai.vo.PushOrderVO;
@ -14,12 +19,14 @@ import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@ -36,9 +43,16 @@ import java.util.Map;
@Api(value = "工厂订单", tags = "工厂订单")
public class OrderController {
private final DeliveryNoteService service;
@Resource
@Lazy
private DeliveryNoteService service;
private final JinPaiProperties jinPaiProperties;
@Lazy
@Resource
private JpFactoryShipmentService shipmentService;
@Resource
private JinPaiProperties jinPaiProperties;
@ResponseBody
@PostMapping
@ -109,4 +123,27 @@ public class OrderController {
return R.success(res);
}
@ResponseBody
@PostMapping("/v1")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "金牌-工厂订单", notes = "金牌-工厂订单")
public R orderV1(@RequestBody FactoryOrderDataVO vo) {
String jsonStr = JSONUtil.toJsonStr(vo);
log.info("接收金牌工厂订单:{} ", jsonStr);
String res = "";
try {
String params = vo.getParams();
if(StrUtil.isNotEmpty(params)){
JpFactoryShipmentVO bean = JSONUtil.toBean(params, JpFactoryShipmentVO.class);
if (ObjectUtil.isNotEmpty(bean)) {
res = shipmentService.shipment(bean);
}
}
} catch (Exception e) {
log.error("金牌工厂订单异常:{} ", e);
return R.fail("服务器异常");
}
return R.success(res);
}
}

88
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/JpFactoryOrderEntity.java

@ -0,0 +1,88 @@
package com.logpm.factorydata.jinpai.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("jp_factory_order")
@ApiModel(value = "金牌工厂订单", description = "金牌工厂订单")
@EqualsAndHashCode(callSuper = true)
public class JpFactoryOrderEntity extends BaseEntity {
@ApiModelProperty(name = "日志id")
private String logId;
@ApiModelProperty(name = "发货单id")
private Long shipmentId;
@ApiModelProperty(name = "订单号")
private String orderCode;
@ApiModelProperty(name = "交割单号/服务号")
private String serviceNum;
@ApiModelProperty(name = "服务类型")
private String serverType;
@ApiModelProperty(name = "结算方式")
private String settlementType;
@ApiModelProperty(name = "是否补件")
private String supplement;
@ApiModelProperty(name = "发运方式")
private String shipVia;
@ApiModelProperty(name = "订单总件数")
private Integer totalQuantity;
@ApiModelProperty(name = "商场名称")
private String mallName;
@ApiModelProperty(name = "商场编码")
private String mallCode;
@ApiModelProperty(name = "商场电话")
private String mallMobile;
@ApiModelProperty(name = "商场地址")
private String mallAddress;
@ApiModelProperty(name = "商场收货人")
private String mallConsignee;
@ApiModelProperty(name = "商场收货人电话")
private String mallConsigneeMobile;
@ApiModelProperty(name = "门店名称")
private String storeName;
@ApiModelProperty(name = "门店编码")
private String storeCode;
@ApiModelProperty(name = "门店电话")
private String storeMobile;
@ApiModelProperty(name = "门店地址")
private String storeAddress;
@ApiModelProperty(name = "门店收货人")
private String storeConsignee;
@ApiModelProperty(name = "门店收货人电话")
private String storeConsigneeMobile;
@ApiModelProperty(name = "终端收货人")
private String receiverName;
@ApiModelProperty(name = "终端收货人电话")
private String receiverMobile;
@ApiModelProperty(name = "终端收货人地址")
private String receiverAddress;
@ApiModelProperty(name = "备注")
private String remark;
@ApiModelProperty(name = "是否确认")
private Boolean checked;
@ApiModelProperty(name = "租户")
private String tenantCode;
@ApiModelProperty(name = "预留1", notes = "")
private String reserve1;
@ApiModelProperty(name = "预留2", notes = "")
private String reserve2;
@ApiModelProperty(name = "预留3", notes = "")
private String reserve3;
@ApiModelProperty(name = "预留4", notes = "")
private String reserve4;
@ApiModelProperty(name = "预留5", notes = "")
private String reserve5;
}

72
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/JpFactoryPackageEntity.java

@ -0,0 +1,72 @@
package com.logpm.factorydata.jinpai.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonProperty;
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("jp_factory_package")
@ApiModel(value = "金牌工厂包件", description = "金牌工厂包件")
@EqualsAndHashCode(callSuper = true)
public class JpFactoryPackageEntity extends BaseEntity {
@ApiModelProperty(name = "日志id")
private String logId;
@ApiModelProperty(name = "订单id")
private Long orderId;
@ApiModelProperty(name = "是否合包")
@JsonProperty("isConsolidation")
private String consolidation;
@ApiModelProperty(name = "合包码")
private String consolidationCode;
@ApiModelProperty(name = "包件码")
private String unitNo;
@ApiModelProperty(name = "产品编号")
private String productCode;
@ApiModelProperty(name = "产品名称")
private String productName;
@ApiModelProperty(name = "件数")
private Integer quantity;
@ApiModelProperty(name = "体积")
private Double volume;
@ApiModelProperty(name = "重量")
private Double weight;
@ApiModelProperty(name = "一级品类名称")
private String firstPackName;
@ApiModelProperty(name = "一级品类编码")
private String firstPackCode;
@ApiModelProperty(name = "二级品类名称")
private String secondPackName;
@ApiModelProperty(name = "二级品类编码")
private String secondPackCode;
@ApiModelProperty(name = "三级品类名称")
private String thirdPackName;
@ApiModelProperty(name = "三级品类编码")
private String thirdPackCode;
@ApiModelProperty(name = "是否确认")
private Boolean checked;
@ApiModelProperty(name = "租户")
private String tenantCode;
@ApiModelProperty(name = "预留1", notes = "")
private String reserve1;
@ApiModelProperty(name = "预留2", notes = "")
private String reserve2;
@ApiModelProperty(name = "预留3", notes = "")
private String reserve3;
@ApiModelProperty(name = "预留4", notes = "")
private String reserve4;
@ApiModelProperty(name = "预留5", notes = "")
private String reserve5;
}

64
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/entity/JpFactoryShipmentEntity.java

@ -0,0 +1,64 @@
package com.logpm.factorydata.jinpai.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("jp_factory_shipment")
@ApiModel(value = "金牌工厂发货单", description = "金牌工厂发货单")
@EqualsAndHashCode(callSuper = true)
public class JpFactoryShipmentEntity extends BaseEntity {
@ApiModelProperty(name = "日志id")
private String logId;
@ApiModelProperty(name = "发货单号")
private String shipmentId;
@ApiModelProperty(name = "物流公司编码")
private String carrierCode;
@ApiModelProperty(name = "物流公司名称")
private String carrierName;
@ApiModelProperty(name = "发货基地")
private String shipmentHub;
@ApiModelProperty(name = "计划发车时间")
private String planStartTime;
@ApiModelProperty(name = "计划到达时间")
private String planEndTime;
@ApiModelProperty(name = "司机")
private String driverName;
@ApiModelProperty(name = "司机电话")
private String driverMobile;
@ApiModelProperty(name = "车牌")
private String carNumber;
@ApiModelProperty(name = "发货人名称")
private String senderName;
@ApiModelProperty(name = "发货人电话")
private String senderMobile;
@ApiModelProperty(name = "发货人地址")
private String senderAddress;
@ApiModelProperty(name = "是否确认")
private Boolean checked;
@ApiModelProperty(name = "租户")
private String tenantCode;
@ApiModelProperty(name = "预留1", notes = "")
private String reserve1;
@ApiModelProperty(name = "预留2", notes = "")
private String reserve2;
@ApiModelProperty(name = "预留3", notes = "")
private String reserve3;
@ApiModelProperty(name = "预留4", notes = "")
private String reserve4;
@ApiModelProperty(name = "预留5", notes = "")
private String reserve5;
}

136
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/interceptor/FactoryAccountsInterceptor.java

@ -1,59 +1,149 @@
package com.logpm.factorydata.jinpai.interceptor;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.MD5;
import com.alibaba.fastjson.JSONObject;
import com.logpm.factorydata.jinpai.pros.JinPaiProperties;
import com.logpm.factorydata.jinpai.service.JpFactoryShipmentService;
import com.logpm.factorydata.jinpai.vo.FactoryAuthVO;
import com.logpm.factorydata.jinpai.wrapper.RequestWrapper;
import com.logpm.factorydata.jinpai.service.IFactoryTokenService;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springblade.common.cache.CacheNames;
import org.springblade.common.component.MockLoginService;
import org.springblade.common.exception.CustomerException;
import org.springblade.common.wrapper.CustomHttpServletRequestWrapper;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.redis.lock.LockType;
import org.springblade.core.redis.lock.RedisLockClient;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.core.tool.utils.ThreadLocalUtil;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpHeaders;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.time.Instant;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Log4j2
@AllArgsConstructor
@NoArgsConstructor
public class FactoryAccountsInterceptor implements HandlerInterceptor {
private final IFactoryTokenService factoryTokenService;
@Resource
private BladeRedis bladeRedis;
@Resource
private Environment environment;
@Resource
private RedisLockClient redisLockClient;
@Resource
private MockLoginService mockLoginService;
@Resource
private JinPaiProperties jinPaiProperties;
@Resource
@Lazy
private JpFactoryShipmentService jpFactoryShipmentService;
public FactoryAccountsInterceptor(BladeRedis redis, Environment environment, RedisLockClient redisLockClient, MockLoginService mockLoginService, JinPaiProperties suoFeiYaProperties, JpFactoryShipmentService deliveryNoteService) {
this.bladeRedis = redis;
this.environment = environment;
this.redisLockClient = redisLockClient;
this.mockLoginService = mockLoginService;
this.jinPaiProperties = suoFeiYaProperties;
this.jpFactoryShipmentService = deliveryNoteService;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException {
try {
log.info("##########preHandle: 认证开始--------------");
RequestWrapper myRequestWrapper = new RequestWrapper(request);
String body = myRequestWrapper.getBody();
log.info("##########preHandle: body={}", body);
JSONObject jsonObject = JSONObject.parseObject(body);
//获取头中参数
String token = request.getHeader("Authorization");
String corpId = request.getHeader("corpid");
if(StringUtil.isBlank(corpId)){
corpId = jsonObject.getString("corpid");
// 获取头中参数
String companyCode = jsonObject.getString("companyCode");
String params = jsonObject.getString("params");
String sign = jsonObject.getString("digest");
Long authTime = jsonObject.getLong("timestamp");
if (ObjectUtil.isEmpty(authTime)) {
log.info("##########preHandle: 时间戳不能为空");
returnJson(response, JSONObject.toJSONString(R.fail("时间戳不能为空")));
return false;
}
if(!StringUtil.hasLength(token)){
returnJson(response,JSONObject.toJSONString(R.fail(203,"认证不通过,token有误")));
log.info("##########preHandle: authTime={},sign={},companyCodeH={}", authTime, sign, companyCode);
long secondTimestamp = Instant.now().getEpochSecond();
// 验证时间 不能大于5秒
if (secondTimestamp - authTime > jinPaiProperties.getAuthTime()) {
log.info("##########preHandle: 时间戳过期");
returnJson(response, JSONObject.toJSONString(R.fail("认证不通过,时间戳过期")));
return false;
}
if(!StringUtil.hasLength(corpId)){
returnJson(response,JSONObject.toJSONString(R.fail(203,"认证不通过,corpId有误")));
// 验证签名
String auth = jinPaiProperties.getAuth();
String md5Hex = Base64.encode(MD5.create().digestHex(params + auth + authTime)).toUpperCase();
log.info("##########preHandle: md5Hex={}", md5Hex);
if (!StrUtil.equals(md5Hex, sign)) {
log.info("##########preHandle: 签名不正确");
returnJson(response, JSONObject.toJSONString(R.fail("认证不通过,签名不正确")));
return false;
}
log.info("##########preHandle: token={}",token);
//验证token
boolean b = factoryTokenService.verifyToken(token,corpId);
if(!b){
returnJson(response,JSONObject.toJSONString(R.fail(203,"认证不通过,token不存在或已过期")));
String account = "shujutongbu";
String tenantId = "627683";
String authorizationHeader = "bG9jYWw6bG9jYWxfc2VjcmV0";
if (StringUtil.isNotBlank(companyCode)) {
FactoryAuthVO authVO = jpFactoryShipmentService.findFactoryAuth(companyCode);
if (ObjectUtil.isNotEmpty(authVO)) {
account = authVO.getLoginAccount();
tenantId = authVO.getTenantCode();
authorizationHeader = authVO.getAuthorizationHeader();
org.springblade.common.wrapper.CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request);
String key = CacheNames.LOCAL_SERVER_USER + tenantId + ":" + account;
String lockKey = key + ":lock";
JSONObject data = bladeRedis.get(key);
if (Objects.isNull(data)) {
boolean flag = redisLockClient.tryLock(lockKey, LockType.FAIR, 5000, 10000, TimeUnit.MILLISECONDS);
if (flag) {
data = bladeRedis.get(key);
if (Objects.isNull(data)) {
data = mockLoginService.mockToken(tenantId, account);
bladeRedis.setEx(key, data, 2591990L);
redisLockClient.unLock(lockKey, LockType.FAIR);
}
}
}
// 发送登录请求
log.info("##########preHandle: request={}", request);
wrappedRequest.addHeader("Blade-Auth", "bearer " + data.getString("access_token"));
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Blade-Auth", "bearer " + data.get("access_token"));
httpHeaders.add("Authorization", "Basic " + authorizationHeader);
ThreadLocalUtil.put("bladeContext", httpHeaders);
// 用包装后的request替换原始request
request = wrappedRequest;
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
return true;
}
} else {
returnJson(response, JSONObject.toJSONString(R.fail("缺少参数 companyCode")));
return false;
}
return true;
return false;
} catch (Exception e) {
returnJson(response,JSONObject.toJSONString(R.fail(500,"服务异常,请联系管理员")));
e.printStackTrace();
returnJson(response, JSONObject.toJSONString(R.fail("服务异常,请联系管理员")));
return false;
}
}
@ -69,7 +159,7 @@ public class FactoryAccountsInterceptor implements HandlerInterceptor {
} catch (IOException e) {
System.out.println(e.getMessage());
} finally {
if (writer != null){
if (writer != null) {
writer.close();
}
}

39
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/interceptor/LocalServerLoginAccountsInterceptor.java

@ -1,13 +1,12 @@
package com.logpm.factorydata.jinpai.interceptor;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import com.logpm.factorydata.jinpai.pros.JinPaiProperties;
import com.logpm.factorydata.jinpai.service.JpFactoryShipmentService;
import lombok.NoArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springblade.common.cache.CacheNames;
import org.springblade.common.component.MockLoginService;
import org.springblade.common.constant.LauncherConstant;
import org.springblade.common.exception.CustomerException;
import org.springblade.common.wrapper.CustomHttpServletRequestWrapper;
import org.springblade.core.redis.cache.BladeRedis;
@ -15,29 +14,47 @@ import org.springblade.core.redis.lock.LockType;
import org.springblade.core.redis.lock.RedisLockClient;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.ThreadLocalUtil;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpHeaders;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Log4j2
@AllArgsConstructor
@NoArgsConstructor
public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapter {
private final BladeRedis bladeRedis;
private final Environment environment;
private final RedisLockClient redisLockClient;
private final MockLoginService mockLoginService;
@Resource
private BladeRedis bladeRedis;
@Resource
private Environment environment;
@Resource
private RedisLockClient redisLockClient;
@Resource
private MockLoginService mockLoginService;
@Resource
private JinPaiProperties jinPaiProperties;
@Lazy
@Resource
private JpFactoryShipmentService jpFactoryShipmentService;
public LocalServerLoginAccountsInterceptor(BladeRedis redis, Environment environment, RedisLockClient redisLockClient, MockLoginService mockLoginService, JinPaiProperties suoFeiYaProperties, JpFactoryShipmentService deliveryNoteService) {
this.bladeRedis = redis;
this.environment = environment;
this.redisLockClient = redisLockClient;
this.mockLoginService = mockLoginService;
this.jinPaiProperties = suoFeiYaProperties;
this.jpFactoryShipmentService = deliveryNoteService;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException {

16
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/JpFactoryOrderMapper.java

@ -0,0 +1,16 @@
package com.logpm.factorydata.jinpai.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.logpm.factorydata.jinpai.entity.JpFactoryOrderEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* 金牌工厂订单 mapper
*
* @author zqb
* @since 2024-03-26
*/
@Mapper
public interface JpFactoryOrderMapper extends BaseMapper<JpFactoryOrderEntity> {
}

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

@ -0,0 +1,5 @@
<?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.jinpai.mapper.JpFactoryOrderMapper">
</mapper>

16
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/JpFactoryPackageMapper.java

@ -0,0 +1,16 @@
package com.logpm.factorydata.jinpai.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.logpm.factorydata.jinpai.entity.JpFactoryPackageEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* 金牌工厂包件 mapper
*
* @author zqb
* @since 2024-03-26
*/
@Mapper
public interface JpFactoryPackageMapper extends BaseMapper<JpFactoryPackageEntity> {
}

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

@ -0,0 +1,5 @@
<?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.jinpai.mapper.JpFactoryPackageMapper">
</mapper>

21
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/JpFactoryShipmentMapper.java

@ -0,0 +1,21 @@
package com.logpm.factorydata.jinpai.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.logpm.factorydata.jinpai.entity.JpFactoryShipmentEntity;
import com.logpm.factorydata.jinpai.vo.FactoryAuthVO;
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 JpFactoryShipmentMapper extends BaseMapper<JpFactoryShipmentEntity> {
List<FactoryAuthVO> findFactoryAuth(@Param("companyCode") String companyCode);
}

16
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mapper/JpFactoryShipmentMapper.xml

@ -0,0 +1,16 @@
<?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.jinpai.mapper.JpFactoryShipmentMapper">
<select id="findFactoryAuth" resultType="com.logpm.factorydata.jinpai.vo.FactoryAuthVO">
select
logistics_code,
app_key,
tenant_code,
login_account,
authorization_header
from jp_factory_auth
where
company_code = #{companyCode}
</select>
</mapper>

275
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mq/FactoryOrderListener.java

@ -1,53 +1,20 @@
package com.logpm.factorydata.jinpai.mq;
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.JSONArray;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.logpm.factorydata.base.feign.IFactoryDataBaseClient;
import com.logpm.factorydata.enums.SaxStatusEnums;
import com.logpm.factorydata.feign.IFactoryDataClient;
import com.logpm.factorydata.jinpai.entity.DeliveryNoteEntity;
import com.logpm.factorydata.jinpai.entity.FactoryOrderLogEntity;
import com.logpm.factorydata.jinpai.entity.OrderInfoEntity;
import com.logpm.factorydata.jinpai.entity.PackageInfoEntity;
import com.logpm.factorydata.jinpai.entity.PushOrderDetailEntity;
import com.logpm.factorydata.jinpai.entity.PushOrderEntity;
import com.logpm.factorydata.jinpai.enums.DimensionEnums;
import com.logpm.factorydata.jinpai.service.DeliveryNoteService;
import com.logpm.factorydata.jinpai.service.FactoryOrderLogService;
import com.logpm.factorydata.jinpai.service.OrderInfoService;
import com.logpm.factorydata.jinpai.service.PackageInfoService;
import com.logpm.factorydata.jinpai.service.PushOrderDetailService;
import com.logpm.factorydata.jinpai.service.PushOrderService;
import com.logpm.factorydata.jinpai.vo.DeliveryNoteVO;
import com.logpm.factorydata.jinpai.vo.OrderInfoVO;
import com.logpm.factorydata.jinpai.vo.PackageCategoryVO;
import com.logpm.factorydata.jinpai.vo.PackageInfoVO;
import com.logpm.factorydata.jinpai.vo.PushOrderDetailVO;
import com.logpm.factorydata.jinpai.vo.PushOrderVO;
import com.logpm.factorydata.jinpai.service.MqWorkerService;
import com.rabbitmq.client.Channel;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.common.constant.factorydata.FactoryDataConstants;
import org.springblade.core.redis.cache.BladeRedis;
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.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.IOException;
/**
* 监听索菲亚订单数据
@ -60,216 +27,46 @@ import java.util.Map;
@AllArgsConstructor
public class FactoryOrderListener {
private final PushOrderService pushOrderService;
private final PushOrderDetailService pushOrderDetailService;
private final DeliveryNoteService deliveryNoteService;
private final OrderInfoService orderInfoService;
private final PackageInfoService packageInfoService;
private final FactoryOrderLogService logService;
private final BladeRedis bladeRedis;
private final IFactoryDataBaseClient baseClient;
private final IFactoryDataClient factoryDataClient;
private final MqWorkerService mqWorkerService;
@RabbitListener(bindings = @QueueBinding(
value = @Queue(name = FactoryDataConstants.Mq.Queues.JP_FACTORY_ORDER),
value = @Queue(name = FactoryDataConstants.Mq.Queues.JP_FACTORY_SHIPMENT),
exchange = @Exchange(name = FactoryDataConstants.Mq.Exchanges.FACTORY_ORDER, type = ExchangeTypes.TOPIC),
key = FactoryDataConstants.Mq.RoutingKeys.JP_FACTORY_ORDER
))
@Transactional(rollbackFor = Exception.class)
public void factoryOrder(String msg) {
log.info("处理金牌订单:{}", msg);
if (StrUtil.isEmpty(msg)) {
log.error("消息内容为空");
return;
}
FactoryOrderLogEntity logEntity = JSONUtil.toBean(msg, FactoryOrderLogEntity.class);
if (ObjectUtil.isEmpty(logEntity)) {
log.error("消息内容为空");
return;
key = FactoryDataConstants.Mq.RoutingKeys.JP_FACTORY_SHIPMENT
), ackMode = "MANUAL")
public void factoryShipment(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) {
log.info("处理金牌工厂订单:{}", msg);
try {
mqWorkerService.factoryShipment(msg);
} catch (Exception e) {
e.printStackTrace();
log.error("处理金牌工厂订单失败: {}", e.getMessage());
}
// 去 minio 下载文件到本地,然后解析文件内容为实体对象
List<DeliveryNoteVO> deliveryNoteVOS = null;
List<OrderInfoVO> orderInfoVOS = null;
List<PackageInfoVO> packageInfoVOS = null;
PushOrderVO pushOrderVO = null;
Long logId = logEntity.getId();
String logUrl = logEntity.getLogUrl();
// 1 订单 2 订单明细 3 包件
Integer dimension = logEntity.getDimension();
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)) {
// 拉取的数据
if (ObjectUtil.equal(logEntity.getType(), 1)) {
if (ObjectUtil.equal(dimension, DimensionEnums.ORDER.getCode())) {
deliveryNoteVOS = new JSONArray(content).toList(DeliveryNoteVO.class);
}
if (ObjectUtil.equal(dimension, DimensionEnums.ORDER_DETAIL.getCode())) {
orderInfoVOS = new JSONArray(content).toList(OrderInfoVO.class);
}
if (ObjectUtil.equal(dimension, DimensionEnums.PACKAGE.getCode())) {
packageInfoVOS = new JSONArray(content).toList(PackageInfoVO.class);
}
} else if (ObjectUtil.equal(logEntity.getType(), 2)) {
// 推送的数据
pushOrderVO = JSONUtil.toBean(content, PushOrderVO.class);
}
}
}
try {
channel.basicAck(tag, false);
} catch (IOException e) {
throw new RuntimeException(e);
}
if (ObjectUtil.equal(logEntity.getType(), 1)) {
pullData(deliveryNoteVOS, orderInfoVOS, packageInfoVOS, logEntity);
} else if (ObjectUtil.equal(logEntity.getType(), 2)) {
pushData(pushOrderVO, logEntity);
}
}
private void pushData(PushOrderVO vo, FactoryOrderLogEntity logEntity) {
if (ObjectUtil.isNotEmpty(vo)) {
// 1 解析数据保存入库
// 装车单号唯一
Long logId = logEntity.getId();
String truckNo = vo.getTransportNo();
List<PushOrderEntity> list = pushOrderService.list(Wrappers.<PushOrderEntity>lambdaQuery().eq(PushOrderEntity::getTransportNo, truckNo));
if (CollUtil.isNotEmpty(list)) {
log.error("装车单号{} 数据已经处理过了, logId: {}", truckNo, logId);
return;
}
vo.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null);
pushOrderService.save(vo);
List<PushOrderDetailVO> orderInfos = vo.getItems();
if (CollUtil.isNotEmpty(orderInfos)) {
List<PushOrderDetailEntity> infoEntities = new ArrayList<>();
for (PushOrderDetailVO orderInfo : orderInfos) {
PushOrderDetailEntity orderInfoEntity = new PushOrderDetailEntity();
BeanUtil.copyProperties(orderInfo, orderInfoEntity);
orderInfoEntity.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null);
orderInfoEntity.setOrderId(vo.getId().toString());
List<String> boxCodes = orderInfo.getBoxCodes();
if (CollUtil.isNotEmpty(boxCodes)) {
orderInfoEntity.setBoxCodeList(JSONUtil.toJsonStr(boxCodes));
}
List<PackageCategoryVO> boxDetails = orderInfo.getBoxDetails();
if (CollUtil.isNotEmpty(boxDetails)) {
orderInfoEntity.setBoxDetailList(JSONUtil.toJsonStr(boxDetails));
}
infoEntities.add(orderInfoEntity);
}
pushOrderDetailService.saveBatch(infoEntities);
}
// 2 构建暂存单,发送 mq 消息
FactoryOrderLogEntity logEntity1 = new FactoryOrderLogEntity();
logEntity1.setSaxStatus(SaxStatusEnums.SUCCESS.getCode());
logEntity1.setId(logId);
logService.saveOrUpdate(logEntity1);
// 处理暂存单
deliveryNoteService.buildAdvance(vo);
}
}
private void pullData(List<DeliveryNoteVO> deliveryNoteVOS, List<OrderInfoVO> orderInfoVOS, List<PackageInfoVO> packageInfoVOS, FactoryOrderLogEntity logEntity) {
if (CollUtil.isNotEmpty(deliveryNoteVOS)) {
List<DeliveryNoteEntity> entities = new ArrayList<>();
List<String> orderCodes = new ArrayList<>();
for (DeliveryNoteVO deliveryNoteVO : deliveryNoteVOS) {
orderCodes.add(deliveryNoteVO.getOrderId());
}
List<DeliveryNoteEntity> list = deliveryNoteService.list(Wrappers.<DeliveryNoteEntity>lambdaQuery()
.in(DeliveryNoteEntity::getOrderId, orderCodes));
Map<String, String> map = new HashMap<>();
if (CollUtil.isNotEmpty(list)) {
// 将list中的数据封装到map中
list.forEach(item -> {
map.put(item.getOrderId(), item.getOrderId());
});
}
for (DeliveryNoteVO deliveryNoteVO : deliveryNoteVOS) {
if (map.containsKey(deliveryNoteVO.getOrderId())) {
log.error("订单号:{},已推送过了", deliveryNoteVO.getOrderId());
continue;
}
DeliveryNoteEntity deliveryNoteEntity = new DeliveryNoteEntity();
BeanUtil.copyProperties(deliveryNoteVO, deliveryNoteEntity);
deliveryNoteEntity.setLogId(ObjectUtil.isNotEmpty(logEntity.getId()) ? logEntity.getId().toString() : null);
entities.add(deliveryNoteEntity);
}
if (CollUtil.isNotEmpty(entities)) {
deliveryNoteService.saveBatch(entities);
}
}
if (CollUtil.isNotEmpty(orderInfoVOS)) {
List<OrderInfoEntity> entities = new ArrayList<>();
List<String> orderCodes = new ArrayList<>();
for (OrderInfoVO orderInfoVO : orderInfoVOS) {
orderCodes.add(orderInfoVO.getOrderId());
}
List<OrderInfoEntity> list = orderInfoService.list(Wrappers.<OrderInfoEntity>lambdaQuery()
.in(OrderInfoEntity::getOmsExtOrderNo, orderCodes));
Map<String, String> map = new HashMap<>();
if (CollUtil.isNotEmpty(list)) {
// 将list中的数据封装到map中
list.forEach(item -> {
map.put(item.getOmsExtOrderNo(), item.getOmsExtOrderNo());
});
}
for (OrderInfoVO vo : orderInfoVOS) {
if (map.containsKey(vo.getOmsExtOrderNo())) {
log.error("DD单号:{},已推送过了", vo.getOmsExtOrderNo());
continue;
}
OrderInfoEntity deliveryNoteEntity = new OrderInfoEntity();
BeanUtil.copyProperties(vo, deliveryNoteEntity);
deliveryNoteEntity.setLogId(ObjectUtil.isNotEmpty(logEntity.getId()) ? logEntity.getId().toString() : null);
entities.add(deliveryNoteEntity);
}
if (CollUtil.isNotEmpty(entities)) {
orderInfoService.saveBatch(entities);
}
@RabbitListener(bindings = @QueueBinding(
value = @Queue(name = FactoryDataConstants.Mq.Queues.JP_FACTORY_ORDER),
exchange = @Exchange(name = FactoryDataConstants.Mq.Exchanges.FACTORY_ORDER, type = ExchangeTypes.TOPIC),
key = FactoryDataConstants.Mq.RoutingKeys.JP_FACTORY_ORDER
), ackMode = "MANUAL")
public void factoryOrder(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) {
log.info("处理金牌订单:{}", msg);
try {
mqWorkerService.factoryOrder(msg);
} catch (Exception e) {
e.printStackTrace();
log.error("处理金牌订单失败: {}", e.getMessage());
}
if (CollUtil.isNotEmpty(packageInfoVOS)) {
List<PackageInfoEntity> entities = new ArrayList<>();
List<String> orderCodes = new ArrayList<>();
List<String> packageCodes = new ArrayList<>();
for (PackageInfoVO orderInfoVO : packageInfoVOS) {
orderCodes.add(orderInfoVO.getOmsExtOrderNo());
packageCodes.add(orderInfoVO.getExtBoxCode());
}
List<PackageInfoEntity> list = packageInfoService.list(Wrappers.<PackageInfoEntity>lambdaQuery()
.in(PackageInfoEntity::getOmsExtOrderNo, orderCodes)
.in(PackageInfoEntity::getExtBoxCode, packageCodes)
);
Map<String, String> map = new HashMap<>();
if (CollUtil.isNotEmpty(list)) {
// 将list中的数据封装到map中
list.forEach(item -> {
map.put(item.getOmsExtOrderNo() + item.getExtBoxCode(), item.getOmsExtOrderNo());
});
}
for (PackageInfoVO vo : packageInfoVOS) {
if (map.containsKey(vo.getOmsExtOrderNo() + vo.getExtBoxCode())) {
log.error("DD单号:{} + 箱码:{},已推送过了", vo.getOmsExtOrderNo(), vo.getExtBoxCode());
continue;
}
PackageInfoEntity entity = new PackageInfoEntity();
BeanUtil.copyProperties(vo, entity);
entity.setLogId(ObjectUtil.isNotEmpty(logEntity.getId()) ? logEntity.getId().toString() : null);
entities.add(entity);
}
if (CollUtil.isNotEmpty(entities)) {
packageInfoService.saveBatch(entities);
}
try {
channel.basicAck(tag, false);
} catch (IOException e) {
throw new RuntimeException(e);
}
// 处理暂存单 通过定时任务扫描的方式判定是否齐套 然后创建暂存单
FactoryOrderLogEntity logEntity1 = new FactoryOrderLogEntity();
logEntity1.setSaxStatus(SaxStatusEnums.SUCCESS.getCode());
logEntity1.setId(logEntity.getId());
logService.saveOrUpdate(logEntity1);
}
}

6
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/pros/JinPaiProperties.java

@ -69,4 +69,10 @@ public class JinPaiProperties {
private Map<String,String> warehouse;
/** auth过期时间 */
private Long authTime;
/** key */
private String auth;
}

3
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/DeliveryNoteService.java

@ -4,6 +4,7 @@ import com.logpm.factorydata.jinpai.entity.DeliveryNoteEntity;
import com.logpm.factorydata.jinpai.entity.OrderInfoEntity;
import com.logpm.factorydata.jinpai.entity.PackageInfoEntity;
import com.logpm.factorydata.jinpai.vo.DeliveryNoteVO;
import com.logpm.factorydata.jinpai.vo.JpFactoryShipmentVO;
import com.logpm.factorydata.jinpai.vo.OrderInfoVO;
import com.logpm.factorydata.jinpai.vo.PackageInfoVO;
import com.logpm.factorydata.jinpai.vo.PushOrderVO;
@ -34,4 +35,6 @@ public interface DeliveryNoteService extends BaseService<DeliveryNoteEntity> {
void buildAdvance(PushOrderVO vo);
void buildAdvancePull(Map<String, List<PackageInfoEntity>> packageInfoEntityMap, Map<String, DeliveryNoteEntity> deliveryNoteEntityMap, Map<String, OrderInfoEntity> orderInfoEntityMap);
void buildFactoryAdvance(JpFactoryShipmentVO vo);
}

14
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/JpFactoryOrderService.java

@ -0,0 +1,14 @@
package com.logpm.factorydata.jinpai.service;
import com.logpm.factorydata.jinpai.entity.JpFactoryOrderEntity;
import org.springblade.core.mp.base.BaseService;
/**
* 金牌工厂订单 服务类
*
* @Author zqb
* @Date 2024/4/26
**/
public interface JpFactoryOrderService extends BaseService<JpFactoryOrderEntity> {
}

14
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/JpFactoryPackageService.java

@ -0,0 +1,14 @@
package com.logpm.factorydata.jinpai.service;
import com.logpm.factorydata.jinpai.entity.JpFactoryPackageEntity;
import org.springblade.core.mp.base.BaseService;
/**
* 金牌工厂包件 服务类
*
* @Author zqb
* @Date 2024/4/26
**/
public interface JpFactoryPackageService extends BaseService<JpFactoryPackageEntity> {
}

19
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/JpFactoryShipmentService.java

@ -0,0 +1,19 @@
package com.logpm.factorydata.jinpai.service;
import com.logpm.factorydata.jinpai.entity.JpFactoryShipmentEntity;
import com.logpm.factorydata.jinpai.vo.FactoryAuthVO;
import com.logpm.factorydata.jinpai.vo.JpFactoryShipmentVO;
import org.springblade.core.mp.base.BaseService;
/**
* 金牌工厂发货单 服务类
*
* @Author zqb
* @Date 2024/4/26
**/
public interface JpFactoryShipmentService extends BaseService<JpFactoryShipmentEntity> {
FactoryAuthVO findFactoryAuth(String companyCode);
String shipment(JpFactoryShipmentVO bean);
}

14
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/MqWorkerService.java

@ -0,0 +1,14 @@
package com.logpm.factorydata.jinpai.service;
/**
* 消息队列工作类 服务类
*
* @Author zqb
* @Date 2024/4/26
**/
public interface MqWorkerService {
void factoryShipment(String msg);
void factoryOrder(String msg);
}

157
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/DeliveryNoteServiceImpl.java

@ -24,6 +24,9 @@ import com.logpm.factorydata.jinpai.mapper.DeliveryNoteMapper;
import com.logpm.factorydata.jinpai.service.DeliveryNoteService;
import com.logpm.factorydata.jinpai.service.FactoryOrderLogService;
import com.logpm.factorydata.jinpai.vo.DeliveryNoteVO;
import com.logpm.factorydata.jinpai.vo.JpFactoryOrderVO;
import com.logpm.factorydata.jinpai.vo.JpFactoryPackageVO;
import com.logpm.factorydata.jinpai.vo.JpFactoryShipmentVO;
import com.logpm.factorydata.jinpai.vo.OrderInfoVO;
import com.logpm.factorydata.jinpai.vo.PackageCategoryVO;
import com.logpm.factorydata.jinpai.vo.PackageInfoVO;
@ -33,7 +36,6 @@ import com.logpm.factorydata.jinpai.vo.ThirdPlWarehouseMappingVO;
import com.logpm.factorydata.vo.SendMsg;
import com.logpm.trunkline.entity.TrunklineAdvanceDetailEntity;
import com.logpm.trunkline.entity.TrunklineAdvanceEntity;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
@ -54,6 +56,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
@ -74,14 +77,16 @@ import java.util.Map;
**/
@Slf4j
@Service
@AllArgsConstructor
public class DeliveryNoteServiceImpl extends BaseServiceImpl<DeliveryNoteMapper, DeliveryNoteEntity> implements DeliveryNoteService {
private final IFactoryDataClient factoryDataClient;
private final FactoryOrderLogService factoryOrderLogService;
private final IOssClient ossClient;
private final IFactoryDataBaseClient baseClient;
@Resource
private IFactoryDataClient factoryDataClient;
@Resource
private FactoryOrderLogService factoryOrderLogService;
@Resource
private IOssClient ossClient;
@Resource
private IFactoryDataBaseClient baseClient;
@Override
public String order(List<DeliveryNoteVO> vo) {
@ -165,7 +170,7 @@ public class DeliveryNoteServiceImpl extends BaseServiceImpl<DeliveryNoteMapper,
@LogpmAsync("asyncExecutor")
@Override
public void buildAdvance(PushOrderVO vo) {
// 新起线程构建暂存单发送mq
// 新起线程构建暂存单发送mq
Long startWarehouseId = null;
String startWarehouseName = null;
String tenantId = null;
@ -253,9 +258,9 @@ public class DeliveryNoteServiceImpl extends BaseServiceImpl<DeliveryNoteMapper,
volume = new BigDecimal(goodsVolume);
}
// 如果有数量没有包条码,则生成系统包条
if(CollUtil.isEmpty(boxCodes)){
if (CollUtil.isEmpty(boxCodes)) {
for (int i = 0; i < Convert.toInt(orderInfoVO.getGoodsNumber()); i++) {
boxCodes.add(orderInfoVO.getCustomItemNo() + "-" + (i+1));
boxCodes.add(orderInfoVO.getCustomItemNo() + "-" + (i + 1));
}
}
int size = boxCodes.size();
@ -524,6 +529,138 @@ public class DeliveryNoteServiceImpl extends BaseServiceImpl<DeliveryNoteMapper,
}
}
@Override
@LogpmAsync("asyncExecutor")
public void buildFactoryAdvance(JpFactoryShipmentVO vo) {
// 新起线程构建暂存单发送mq
Long startWarehouseId = null;
String startWarehouseName = null;
String tenantId = null;
// 获取工厂基地绑定的始发仓信息
List<JpFactoryOrderVO> details = vo.getOrderList();
if (CollUtil.isEmpty(details)) {
return;
}
R<FactoryWarehouseBindVO> warehouseByBrandAndSiteName = baseClient.getWarehouseByBrandAndSiteName(BrandEnums.JP.getValue(), vo.getShipmentHub());
if (ObjectUtil.equal(HttpConstants.HTTP.HTTP_RESOURCE_CODE.SUCCESS_CODE, warehouseByBrandAndSiteName.getCode())) {
FactoryWarehouseBindVO data = warehouseByBrandAndSiteName.getData();
if (ObjectUtil.isNotNull(data)) {
startWarehouseId = data.getWarehouseId();
startWarehouseName = data.getWarehouseName();
tenantId = data.getTenantId();
}
}
Map<String, List<PackageInfoVO>> advanceMap = new HashMap<>();
// 一个dd单号 一个暂存单
// 组装暂存单数据
List<JSONObject> advances = new ArrayList<>();
for (JpFactoryOrderVO orderInfoVO : details) {
List<JSONObject> packageList = new ArrayList<>();
TrunklineAdvanceEntity advanceEntity = new TrunklineAdvanceEntity();
Boolean checked = vo.getChecked();
if (checked) {
advanceEntity.setReserve2("1");
} else {
advanceEntity.setReserve2("0");
}
advanceEntity.setTenantId(tenantId);
advanceEntity.setStatus(0);
advanceEntity.setIsDeleted(0);
advanceEntity.setHasPackage(1);
advanceEntity.setOrderType("");
advanceEntity.setBrand(BrandEnums.JP.getValue());
advanceEntity.setSiteName(vo.getShipmentHub());
advanceEntity.setArea("");
advanceEntity.setTotalNum(CollUtil.isNotEmpty(orderInfoVO.getPackageList()) ? orderInfoVO.getPackageList().size() : 0);
advanceEntity.setPackName("");
advanceEntity.setPackCode("");
advanceEntity.setWarehouseId(startWarehouseId);
advanceEntity.setWarehouseName(startWarehouseName);
advanceEntity.setIsGcp(0);
advanceEntity.setCarrierName("");
advanceEntity.setSystemType("线上");
advanceEntity.setMatingType("1");
advanceEntity.setSenderName("");
advanceEntity.setSenderPhone("");
advanceEntity.setSenderAddress("");
advanceEntity.setWaybillStatus("0");
advanceEntity.setWaybillNo("");
advanceEntity.setTrainNumber(vo.getShipmentId());
advanceEntity.setFreezeStatus("0");
advanceEntity.setOrderCode(orderInfoVO.getOrderCode());
advanceEntity.setServiceNum(orderInfoVO.getServiceNum());
advanceEntity.setSenderFactory("金牌");
// 门店是商场
// advanceEntity.setDealerCode(orderInfoVO.getShopCode());
advanceEntity.setDealerName(orderInfoVO.getMallName());
// advanceEntity.setStoreCode(orderInfoVO.getShopCode());
advanceEntity.setStoreName(orderInfoVO.getStoreName());
// 安装是客户
advanceEntity.setCustomerName(orderInfoVO.getReceiverName());
advanceEntity.setCustomerPhone(orderInfoVO.getReceiverMobile());
advanceEntity.setCustomerAddress(orderInfoVO.getReceiverAddress());
// 收货人就是商场收货人
advanceEntity.setConsigneePerson(orderInfoVO.getMallConsignee());
advanceEntity.setConsigneeMobile(orderInfoVO.getMallConsigneeMobile());
advanceEntity.setConsigneeAddress(orderInfoVO.getMallAddress());
// 封装包件品类信息
for (JpFactoryPackageVO packageInfoVO : orderInfoVO.getPackageList()) {
// 封装包件
TrunklineAdvanceDetailEntity advanceDetailEntity = new TrunklineAdvanceDetailEntity();
advanceDetailEntity.setWarehouseId(startWarehouseId);
advanceDetailEntity.setWarehouseName(startWarehouseName);
advanceDetailEntity.setOrderCode(orderInfoVO.getOrderCode());
advanceDetailEntity.setBrand(BrandEnums.JP.getValue());
advanceDetailEntity.setSystemType("线上");
// 获取映射品类信息
advanceDetailEntity.setFirstPackName(packageInfoVO.getFirstPackName());
advanceDetailEntity.setFirstPackCode(packageInfoVO.getFirstPackCode());
advanceDetailEntity.setSecondPackName(packageInfoVO.getSecondPackName());
advanceDetailEntity.setSecondPackCode(packageInfoVO.getSecondPackCode());
advanceDetailEntity.setThirdPackName(packageInfoVO.getThirdPackName());
advanceDetailEntity.setThirdPackCode(packageInfoVO.getThirdPackCode());
advanceDetailEntity.setSiteName(vo.getShipmentHub());
advanceDetailEntity.setSiteCode("");
advanceDetailEntity.setQuantity(1);
advanceDetailEntity.setOrderPackageCode(packageInfoVO.getUnitNo());
advanceDetailEntity.setTrainNumber(vo.getShipmentId());
advanceDetailEntity.setServiceNum(orderInfoVO.getServiceNum());
advanceDetailEntity.setWaybillNo("");
advanceDetailEntity.setPackageStatus("0");
advanceDetailEntity.setWeight(NumberUtil.toBigDecimal(packageInfoVO.getWeight()));
advanceDetailEntity.setVolume(NumberUtil.toBigDecimal(packageInfoVO.getVolume()));
// advanceDetailEntity.setChargeType(0);
advanceDetailEntity.setSupple("");
advanceDetailEntity.setManifest("");
advanceDetailEntity.setReturnNum("");
advanceDetailEntity.setSendDateStr(DateUtil.formatLocalDateTime(LocalDateTime.now()));
advanceDetailEntity.setCarNumber("");
advanceDetailEntity.setGoodsMan("");
advanceDetailEntity.setTenantId(tenantId);
advanceDetailEntity.setStatus(0);
advanceDetailEntity.setIsDeleted(0);
JSONObject entries = JSONUtil.parseObj(advanceDetailEntity);
packageList.add(entries);
}
// 转成json对象,然后将包件明细放到detail中
JSONObject entries = JSONUtil.parseObj(advanceEntity);
entries.set("details", JSONUtil.toJsonStr(packageList));
advances.add(entries);
}
// 将组装好的暂存单发送到 MQ ,由暂存单服务统一消费SendMsg.
if (CollUtil.isNotEmpty(advances)) {
for (JSONObject advance : advances) {
SendMsg sendMsg = SendMsg.builder().exchange(FactoryDataConstants.Mq.Exchanges.ADVANCE_ORDER)
.routingKey(FactoryDataConstants.Mq.RoutingKeys.ADVANCE_ORDER_JP).message(JSONUtil.toJsonStr(advance)).build();
factoryDataClient.sendMessage(sendMsg);
}
}
}
private String uploadFile(String body) {
// 文本内容和保存为本地文件 并上传
String logPath = FileLogsUtil.saveFileLogs(body);

22
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/JpFactoryOrderServiceImpl.java

@ -0,0 +1,22 @@
package com.logpm.factorydata.jinpai.service.impl;
import com.logpm.factorydata.jinpai.entity.JpFactoryOrderEntity;
import com.logpm.factorydata.jinpai.mapper.JpFactoryOrderMapper;
import com.logpm.factorydata.jinpai.service.JpFactoryOrderService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
/**
* 金牌工厂订单 业务实现类
*
* @Author zqb
* @Date 2024/4/26
**/
@Slf4j
@Service
@AllArgsConstructor
public class JpFactoryOrderServiceImpl extends BaseServiceImpl<JpFactoryOrderMapper, JpFactoryOrderEntity> implements JpFactoryOrderService {
}

22
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/JpFactoryPackageServiceImpl.java

@ -0,0 +1,22 @@
package com.logpm.factorydata.jinpai.service.impl;
import com.logpm.factorydata.jinpai.entity.JpFactoryPackageEntity;
import com.logpm.factorydata.jinpai.mapper.JpFactoryPackageMapper;
import com.logpm.factorydata.jinpai.service.JpFactoryPackageService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
/**
* 金牌工厂包件 业务实现类
*
* @Author zqb
* @Date 2024/4/26
**/
@Slf4j
@Service
@AllArgsConstructor
public class JpFactoryPackageServiceImpl extends BaseServiceImpl<JpFactoryPackageMapper, JpFactoryPackageEntity> implements JpFactoryPackageService {
}

137
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/JpFactoryShipmentServiceImpl.java

@ -0,0 +1,137 @@
package com.logpm.factorydata.jinpai.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.logpm.factorydata.enums.SaxStatusEnums;
import com.logpm.factorydata.feign.IFactoryDataClient;
import com.logpm.factorydata.jinpai.entity.FactoryOrderLogEntity;
import com.logpm.factorydata.jinpai.entity.JpFactoryShipmentEntity;
import com.logpm.factorydata.jinpai.mapper.JpFactoryShipmentMapper;
import com.logpm.factorydata.jinpai.service.FactoryOrderLogService;
import com.logpm.factorydata.jinpai.service.JpFactoryShipmentService;
import com.logpm.factorydata.jinpai.vo.FactoryAuthVO;
import com.logpm.factorydata.jinpai.vo.JpFactoryShipmentVO;
import com.logpm.factorydata.vo.SendMsg;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
import org.springblade.common.constant.factorydata.FactoryDataConstants;
import org.springblade.common.utils.FileLogsUtil;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.tool.api.R;
import org.springblade.resource.feign.IOssClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.time.Duration;
import java.util.List;
/**
* 金牌工厂发货单 业务实现类
*
* @Author zqb
* @Date 2024/4/26
**/
@Slf4j
@Service
public class JpFactoryShipmentServiceImpl extends BaseServiceImpl<JpFactoryShipmentMapper, JpFactoryShipmentEntity> implements JpFactoryShipmentService {
@Resource
private BladeRedis bladeRedis;
@Resource
private IOssClient ossClient;
@Resource
private IFactoryDataClient factoryDataClient;
@Resource
private FactoryOrderLogService factoryOrderLogService;
@Override
public FactoryAuthVO findFactoryAuth(String companyCode) {
// redis 缓存数据 缓存时间 1天
if (StrUtil.isNotBlank(companyCode)) {
String key = "factory-data:jinpai:" + companyCode;
String json = bladeRedis.get(key);
if (StrUtil.isNotBlank(json)) {
return JSONUtil.toBean(json, FactoryAuthVO.class);
} else {
List<FactoryAuthVO> factoryAuth = baseMapper.findFactoryAuth(companyCode);
if(CollUtil.isNotEmpty(factoryAuth)){
FactoryAuthVO authVO = factoryAuth.get(0);
bladeRedis.setEx(key, JSONUtil.toJsonStr(authVO), Duration.ofDays(1));
return authVO;
}
}
}
return null;
}
@Override
public String shipment(JpFactoryShipmentVO vo) {
// 1 上传数据到 minio 获取到地址
String url = uploadFile(JSONUtil.toJsonStr(vo));
// 2 保存地址到数据库
FactoryOrderLogEntity logEntity = new FactoryOrderLogEntity();
logEntity.setType(2);
logEntity.setSaxStatus(SaxStatusEnums.NOMAL.getCode());
logEntity.setLogUrl(url);
factoryOrderLogService.save(logEntity);
// 3 将消息发送给 mq,解析保存
SendMsg build = SendMsg.builder().exchange(FactoryDataConstants.Mq.Exchanges.FACTORY_ORDER)
.routingKey(FactoryDataConstants.Mq.RoutingKeys.JP_FACTORY_SHIPMENT).message(JSONUtil.toJsonStr(logEntity)).build();
factoryDataClient.sendMessage(build);
return "成功";
}
private String uploadFile(String body) {
// 文本内容和保存为本地文件 并上传
String logPath = FileLogsUtil.saveFileLogs(body);
log.info(">>> 文件路径 {}", logPath);
MultipartFile multi = getMultipartFile(logPath);
// 上传到服务器
R r = ossClient.fileUpload(multi, "jp-order-logs");
if (r.isSuccess()) {
BladeFile data = (BladeFile) r.getData();
// 删除本地文件
FileUtil.del(logPath);
return data.getLink();
}
return null;
}
@NotNull
private MultipartFile getMultipartFile(String logPath) {
File file = new File(logPath);
// File 转 MultipartFile
FileItem item = new DiskFileItemFactory().createItem("file"
, MediaType.MULTIPART_FORM_DATA_VALUE
, true
, file.getName());
try (
InputStream input = Files.newInputStream(file.toPath());
OutputStream os = item.getOutputStream()) {
// 流转移
IOUtils.copy(input, os);
} catch (Exception e) {
throw new IllegalArgumentException("Invalid file: " + e, e);
}
return new CommonsMultipartFile(item);
}
}

356
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/service/impl/MqWorkerServiceImpl.java

@ -0,0 +1,356 @@
package com.logpm.factorydata.jinpai.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.JSONArray;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.logpm.factorydata.enums.SaxStatusEnums;
import com.logpm.factorydata.jinpai.entity.DeliveryNoteEntity;
import com.logpm.factorydata.jinpai.entity.FactoryOrderLogEntity;
import com.logpm.factorydata.jinpai.entity.JpFactoryOrderEntity;
import com.logpm.factorydata.jinpai.entity.JpFactoryPackageEntity;
import com.logpm.factorydata.jinpai.entity.JpFactoryShipmentEntity;
import com.logpm.factorydata.jinpai.entity.OrderInfoEntity;
import com.logpm.factorydata.jinpai.entity.PackageInfoEntity;
import com.logpm.factorydata.jinpai.entity.PushOrderDetailEntity;
import com.logpm.factorydata.jinpai.entity.PushOrderEntity;
import com.logpm.factorydata.jinpai.enums.DimensionEnums;
import com.logpm.factorydata.jinpai.service.DeliveryNoteService;
import com.logpm.factorydata.jinpai.service.FactoryOrderLogService;
import com.logpm.factorydata.jinpai.service.JpFactoryOrderService;
import com.logpm.factorydata.jinpai.service.JpFactoryPackageService;
import com.logpm.factorydata.jinpai.service.JpFactoryShipmentService;
import com.logpm.factorydata.jinpai.service.MqWorkerService;
import com.logpm.factorydata.jinpai.service.OrderInfoService;
import com.logpm.factorydata.jinpai.service.PackageInfoService;
import com.logpm.factorydata.jinpai.service.PushOrderDetailService;
import com.logpm.factorydata.jinpai.service.PushOrderService;
import com.logpm.factorydata.jinpai.vo.DeliveryNoteVO;
import com.logpm.factorydata.jinpai.vo.JpFactoryOrderVO;
import com.logpm.factorydata.jinpai.vo.JpFactoryPackageVO;
import com.logpm.factorydata.jinpai.vo.JpFactoryShipmentVO;
import com.logpm.factorydata.jinpai.vo.OrderInfoVO;
import com.logpm.factorydata.jinpai.vo.PackageCategoryVO;
import com.logpm.factorydata.jinpai.vo.PackageInfoVO;
import com.logpm.factorydata.jinpai.vo.PushOrderDetailVO;
import com.logpm.factorydata.jinpai.vo.PushOrderVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 消息队列工作类 业务实现类
*
* @Author zqb
* @Date 2024/4/26
**/
@Slf4j
@Service
@AllArgsConstructor
public class MqWorkerServiceImpl implements MqWorkerService {
private final PushOrderService pushOrderService;
private final PushOrderDetailService pushOrderDetailService;
private final DeliveryNoteService deliveryNoteService;
private final OrderInfoService orderInfoService;
private final PackageInfoService packageInfoService;
private final FactoryOrderLogService logService;
private final JpFactoryShipmentService jpFactoryShipmentService;
private final JpFactoryOrderService jpFactoryOrderService;
private final JpFactoryPackageService jpFactoryPackageService;
@Override
@Transactional(rollbackFor = Exception.class)
public void factoryShipment(String msg) {
if (StrUtil.isEmpty(msg)) {
log.error("消息内容为空");
return;
}
FactoryOrderLogEntity logEntity = JSONUtil.toBean(msg, FactoryOrderLogEntity.class);
if (ObjectUtil.isEmpty(logEntity)) {
log.error("消息内容为空");
return;
}
// 去 minio 下载文件到本地,然后解析文件内容为实体对象
JpFactoryShipmentVO pushOrderVO = null;
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)) {
pushOrderVO = JSONUtil.toBean(content, JpFactoryShipmentVO.class);
}
}
}
shipmentData(pushOrderVO, logEntity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void factoryOrder(String msg) {
if (StrUtil.isEmpty(msg)) {
log.error("消息内容为空");
return;
}
FactoryOrderLogEntity logEntity = JSONUtil.toBean(msg, FactoryOrderLogEntity.class);
if (ObjectUtil.isEmpty(logEntity)) {
log.error("消息内容为空");
return;
}
// 去 minio 下载文件到本地,然后解析文件内容为实体对象
List<DeliveryNoteVO> deliveryNoteVOS = null;
List<OrderInfoVO> orderInfoVOS = null;
List<PackageInfoVO> packageInfoVOS = null;
PushOrderVO pushOrderVO = null;
Long logId = logEntity.getId();
String logUrl = logEntity.getLogUrl();
// 1 订单 2 订单明细 3 包件
Integer dimension = logEntity.getDimension();
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)) {
// 拉取的数据
if (ObjectUtil.equal(logEntity.getType(), 1)) {
if (ObjectUtil.equal(dimension, DimensionEnums.ORDER.getCode())) {
deliveryNoteVOS = new JSONArray(content).toList(DeliveryNoteVO.class);
}
if (ObjectUtil.equal(dimension, DimensionEnums.ORDER_DETAIL.getCode())) {
orderInfoVOS = new JSONArray(content).toList(OrderInfoVO.class);
}
if (ObjectUtil.equal(dimension, DimensionEnums.PACKAGE.getCode())) {
packageInfoVOS = new JSONArray(content).toList(PackageInfoVO.class);
}
} else if (ObjectUtil.equal(logEntity.getType(), 2)) {
// 推送的数据
pushOrderVO = JSONUtil.toBean(content, PushOrderVO.class);
}
}
}
}
if (ObjectUtil.equal(logEntity.getType(), 1)) {
pullData(deliveryNoteVOS, orderInfoVOS, packageInfoVOS, logEntity);
} else if (ObjectUtil.equal(logEntity.getType(), 2)) {
pushData(pushOrderVO, logEntity);
}
}
private void shipmentData(JpFactoryShipmentVO vo, FactoryOrderLogEntity logEntity) {
if (ObjectUtil.isNotEmpty(vo)) {
// 1 解析数据保存入库
// 装车单号唯一
Long logId = logEntity.getId();
String truckNo = vo.getShipmentId();
if (StrUtil.isEmpty(truckNo)) {
return;
}
List<JpFactoryShipmentEntity> list = jpFactoryShipmentService.list(Wrappers.<JpFactoryShipmentEntity>lambdaQuery().eq(JpFactoryShipmentEntity::getShipmentId, truckNo));
Boolean checked = Boolean.FALSE;
if (CollUtil.isNotEmpty(list)) {
if (list.size() > 1) {
return;
}
checked = Boolean.TRUE;
}
vo.setChecked(checked);
vo.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null);
vo.setTenantCode(AuthUtil.getTenantId());
jpFactoryShipmentService.save(vo);
List<JpFactoryOrderVO> orderVOS = vo.getOrderList();
if (CollUtil.isNotEmpty(orderVOS)) {
List<JpFactoryPackageEntity> packageEntities = new ArrayList<>();
for (JpFactoryOrderVO orderVO : orderVOS) {
JpFactoryOrderEntity orderEntity = new JpFactoryOrderEntity();
BeanUtil.copyProperties(orderVO, orderEntity);
orderEntity.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null);
orderEntity.setShipmentId(vo.getId());
orderEntity.setChecked(checked);
orderEntity.setTenantCode(AuthUtil.getTenantId());
jpFactoryOrderService.save(orderEntity);
List<JpFactoryPackageVO> packageList = orderVO.getPackageList();
if (CollUtil.isNotEmpty(packageList)) {
for (JpFactoryPackageVO jpFactoryPackageVO : packageList) {
JpFactoryPackageEntity packageEntity = new JpFactoryPackageEntity();
BeanUtil.copyProperties(jpFactoryPackageVO, packageEntity);
packageEntity.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null);
packageEntity.setOrderId(orderEntity.getId());
packageEntity.setChecked(checked);
packageEntity.setTenantCode(AuthUtil.getTenantId());
packageEntities.add(packageEntity);
}
}
}
if (CollUtil.isNotEmpty(packageEntities)) {
jpFactoryPackageService.saveBatch(packageEntities);
}
}
// 2 构建暂存单,发送 mq 消息
FactoryOrderLogEntity logEntity1 = new FactoryOrderLogEntity();
logEntity1.setSaxStatus(SaxStatusEnums.SUCCESS.getCode());
logEntity1.setId(logId);
logService.saveOrUpdate(logEntity1);
// 处理暂存单
deliveryNoteService.buildFactoryAdvance(vo);
}
}
private void pushData(PushOrderVO vo, FactoryOrderLogEntity logEntity) {
if (ObjectUtil.isNotEmpty(vo)) {
// 1 解析数据保存入库
// 装车单号唯一
Long logId = logEntity.getId();
String truckNo = vo.getTransportNo();
List<PushOrderEntity> list = pushOrderService.list(Wrappers.<PushOrderEntity>lambdaQuery().eq(PushOrderEntity::getTransportNo, truckNo));
if (CollUtil.isNotEmpty(list)) {
log.error("装车单号{} 数据已经处理过了, logId: {}", truckNo, logId);
return;
}
vo.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null);
pushOrderService.save(vo);
List<PushOrderDetailVO> orderInfos = vo.getItems();
if (CollUtil.isNotEmpty(orderInfos)) {
List<PushOrderDetailEntity> infoEntities = new ArrayList<>();
for (PushOrderDetailVO orderInfo : orderInfos) {
PushOrderDetailEntity orderInfoEntity = new PushOrderDetailEntity();
BeanUtil.copyProperties(orderInfo, orderInfoEntity);
orderInfoEntity.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null);
orderInfoEntity.setOrderId(vo.getId().toString());
List<String> boxCodes = orderInfo.getBoxCodes();
if (CollUtil.isNotEmpty(boxCodes)) {
orderInfoEntity.setBoxCodeList(JSONUtil.toJsonStr(boxCodes));
}
List<PackageCategoryVO> boxDetails = orderInfo.getBoxDetails();
if (CollUtil.isNotEmpty(boxDetails)) {
orderInfoEntity.setBoxDetailList(JSONUtil.toJsonStr(boxDetails));
}
infoEntities.add(orderInfoEntity);
}
pushOrderDetailService.saveBatch(infoEntities);
}
// 2 构建暂存单,发送 mq 消息
FactoryOrderLogEntity logEntity1 = new FactoryOrderLogEntity();
logEntity1.setSaxStatus(SaxStatusEnums.SUCCESS.getCode());
logEntity1.setId(logId);
logService.saveOrUpdate(logEntity1);
// 处理暂存单
deliveryNoteService.buildAdvance(vo);
}
}
private void pullData(List<DeliveryNoteVO> deliveryNoteVOS, List<OrderInfoVO> orderInfoVOS, List<PackageInfoVO> packageInfoVOS, FactoryOrderLogEntity logEntity) {
if (CollUtil.isNotEmpty(deliveryNoteVOS)) {
List<DeliveryNoteEntity> entities = new ArrayList<>();
List<String> orderCodes = new ArrayList<>();
for (DeliveryNoteVO deliveryNoteVO : deliveryNoteVOS) {
orderCodes.add(deliveryNoteVO.getOrderId());
}
List<DeliveryNoteEntity> list = deliveryNoteService.list(Wrappers.<DeliveryNoteEntity>lambdaQuery()
.in(DeliveryNoteEntity::getOrderId, orderCodes));
Map<String, String> map = new HashMap<>();
if (CollUtil.isNotEmpty(list)) {
// 将list中的数据封装到map中
list.forEach(item -> {
map.put(item.getOrderId(), item.getOrderId());
});
}
for (DeliveryNoteVO deliveryNoteVO : deliveryNoteVOS) {
if (map.containsKey(deliveryNoteVO.getOrderId())) {
log.error("订单号:{},已推送过了", deliveryNoteVO.getOrderId());
continue;
}
DeliveryNoteEntity deliveryNoteEntity = new DeliveryNoteEntity();
BeanUtil.copyProperties(deliveryNoteVO, deliveryNoteEntity);
deliveryNoteEntity.setLogId(ObjectUtil.isNotEmpty(logEntity.getId()) ? logEntity.getId().toString() : null);
entities.add(deliveryNoteEntity);
}
if (CollUtil.isNotEmpty(entities)) {
deliveryNoteService.saveBatch(entities);
}
}
if (CollUtil.isNotEmpty(orderInfoVOS)) {
List<OrderInfoEntity> entities = new ArrayList<>();
List<String> orderCodes = new ArrayList<>();
for (OrderInfoVO orderInfoVO : orderInfoVOS) {
orderCodes.add(orderInfoVO.getOrderId());
}
List<OrderInfoEntity> list = orderInfoService.list(Wrappers.<OrderInfoEntity>lambdaQuery()
.in(OrderInfoEntity::getOmsExtOrderNo, orderCodes));
Map<String, String> map = new HashMap<>();
if (CollUtil.isNotEmpty(list)) {
// 将list中的数据封装到map中
list.forEach(item -> {
map.put(item.getOmsExtOrderNo(), item.getOmsExtOrderNo());
});
}
for (OrderInfoVO vo : orderInfoVOS) {
if (map.containsKey(vo.getOmsExtOrderNo())) {
log.error("DD单号:{},已推送过了", vo.getOmsExtOrderNo());
continue;
}
OrderInfoEntity deliveryNoteEntity = new OrderInfoEntity();
BeanUtil.copyProperties(vo, deliveryNoteEntity);
deliveryNoteEntity.setLogId(ObjectUtil.isNotEmpty(logEntity.getId()) ? logEntity.getId().toString() : null);
entities.add(deliveryNoteEntity);
}
if (CollUtil.isNotEmpty(entities)) {
orderInfoService.saveBatch(entities);
}
}
if (CollUtil.isNotEmpty(packageInfoVOS)) {
List<PackageInfoEntity> entities = new ArrayList<>();
List<String> orderCodes = new ArrayList<>();
List<String> packageCodes = new ArrayList<>();
for (PackageInfoVO orderInfoVO : packageInfoVOS) {
orderCodes.add(orderInfoVO.getOmsExtOrderNo());
packageCodes.add(orderInfoVO.getExtBoxCode());
}
List<PackageInfoEntity> list = packageInfoService.list(Wrappers.<PackageInfoEntity>lambdaQuery()
.in(PackageInfoEntity::getOmsExtOrderNo, orderCodes)
.in(PackageInfoEntity::getExtBoxCode, packageCodes)
);
Map<String, String> map = new HashMap<>();
if (CollUtil.isNotEmpty(list)) {
// 将list中的数据封装到map中
list.forEach(item -> {
map.put(item.getOmsExtOrderNo() + item.getExtBoxCode(), item.getOmsExtOrderNo());
});
}
for (PackageInfoVO vo : packageInfoVOS) {
if (map.containsKey(vo.getOmsExtOrderNo() + vo.getExtBoxCode())) {
log.error("DD单号:{} + 箱码:{},已推送过了", vo.getOmsExtOrderNo(), vo.getExtBoxCode());
continue;
}
PackageInfoEntity entity = new PackageInfoEntity();
BeanUtil.copyProperties(vo, entity);
entity.setLogId(ObjectUtil.isNotEmpty(logEntity.getId()) ? logEntity.getId().toString() : null);
entities.add(entity);
}
if (CollUtil.isNotEmpty(entities)) {
packageInfoService.saveBatch(entities);
}
}
// 处理暂存单 通过定时任务扫描的方式判定是否齐套 然后创建暂存单
FactoryOrderLogEntity logEntity1 = new FactoryOrderLogEntity();
logEntity1.setSaxStatus(SaxStatusEnums.SUCCESS.getCode());
logEntity1.setId(logEntity.getId());
logService.saveOrUpdate(logEntity1);
}
}

28
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/FactoryAuthVO.java

@ -0,0 +1,28 @@
package com.logpm.factorydata.jinpai.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 物流商认证
*
* @author zhaoqiaobo
* @create 2024-04-26
*/
@Data
public class FactoryAuthVO {
@ApiModelProperty(name = "物流编码")
private String logisticsCode;
@ApiModelProperty(name = "秘钥")
private String appKey;
@ApiModelProperty(name = "物流公司")
private String companyCode;
@ApiModelProperty(name = "租户")
private String tenantCode;
@ApiModelProperty(name = "登录账号")
private String loginAccount;
@ApiModelProperty(name = "Authorization头")
private String authorizationHeader;
}

27
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/FactoryOrderDataVO.java

@ -0,0 +1,27 @@
package com.logpm.factorydata.jinpai.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 送货单 实体类
*
* @author zhaoqiaobo
* @create 2024-04-26
*/
@Data
@ApiModel(value = "发货单", description = "发货单")
public class FactoryOrderDataVO {
@ApiModelProperty("加密后的密文")
private String digest;
@ApiModelProperty("时间戳 毫秒")
private Long timestamp;
@ApiModelProperty("公司编码")
private String companyCode;
@ApiModelProperty("订单信息")
private String params;
}

25
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/JpFactoryOrderVO.java

@ -0,0 +1,25 @@
package com.logpm.factorydata.jinpai.vo;
import com.logpm.factorydata.jinpai.entity.JpFactoryOrderEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
/**
* 送货单 实体类
*
* @author zhaoqiaobo
* @create 2024-04-26
*/
@Data
@ApiModel(value = "发货单", description = "发货单")
@EqualsAndHashCode(callSuper = true)
public class JpFactoryOrderVO extends JpFactoryOrderEntity {
@ApiModelProperty(name = "包件明细")
private List<JpFactoryPackageVO> packageList;
}

21
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/JpFactoryPackageVO.java

@ -0,0 +1,21 @@
package com.logpm.factorydata.jinpai.vo;
import com.logpm.factorydata.jinpai.entity.JpFactoryPackageEntity;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 送货单 实体类
*
* @author zhaoqiaobo
* @create 2024-04-26
*/
@Data
@ApiModel(value = "发货单", description = "发货单")
@EqualsAndHashCode(callSuper = true)
public class JpFactoryPackageVO extends JpFactoryPackageEntity {
}

25
blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/vo/JpFactoryShipmentVO.java

@ -0,0 +1,25 @@
package com.logpm.factorydata.jinpai.vo;
import com.logpm.factorydata.jinpai.entity.JpFactoryShipmentEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
/**
* 送货单 实体类
*
* @author zhaoqiaobo
* @create 2024-04-26
*/
@Data
@ApiModel(value = "发货单", description = "发货单")
@EqualsAndHashCode(callSuper = true)
public class JpFactoryShipmentVO extends JpFactoryShipmentEntity {
@ApiModelProperty(name = "订单明细")
private List<JpFactoryOrderVO> orderList;
}

20
blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mq/AdvanceOrderListener.java

@ -49,6 +49,26 @@ public class AdvanceOrderListener {
throw new RuntimeException(e);
}
}
@RabbitListener(bindings = @QueueBinding(
value = @Queue(name = FactoryDataConstants.Mq.Queues.ADVANCE_ORDER_JP),
exchange = @Exchange(name = FactoryDataConstants.Mq.Exchanges.ADVANCE_ORDER, type = ExchangeTypes.TOPIC),
key = FactoryDataConstants.Mq.RoutingKeys.ADVANCE_ORDER_JP
), ackMode = "MANUAL")
public void advanceOrderJp(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) {
// 新增暂存单
log.info("收到金牌工厂数据暂存单消息:{}", msg);
try {
advanceOrderMqService.advanceOrderJp(msg);
} catch (Exception e) {
e.printStackTrace();
log.error("收到金牌工厂数据暂存单消息失败: {}", e.getMessage());
}
try {
channel.basicAck(tag, false);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@RabbitListener(bindings = @QueueBinding(
value = @Queue(name = FactoryDataConstants.Mq.Queues.ADVANCE_ORDER_OUPAI),

1
blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/IAdvanceOrderMqService.java

@ -3,6 +3,7 @@ package com.logpm.trunkline.service;
public interface IAdvanceOrderMqService {
void advanceOrder(String msg);
void advanceOrderJp(String msg);
void advanceOrderOuPai(String msg);
}

138
blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/AdvanceOrderMqServiceImpl.java

@ -175,6 +175,144 @@ public class AdvanceOrderMqServiceImpl implements IAdvanceOrderMqService {
}
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void advanceOrderJp(String msg) {
if (StrUtil.isNotBlank(msg)) {
JSONObject entries = JSONUtil.parseObj(msg);
JSONArray details = entries.getJSONArray("details");
TrunklineAdvanceEntity advanceEntity = JSONUtil.toBean(entries, TrunklineAdvanceEntity.class);
LambdaQueryWrapper<TrunklineAdvanceEntity> eq = Wrappers.<TrunklineAdvanceEntity>lambdaQuery()
.eq(TrunklineAdvanceEntity::getOrderCode, advanceEntity.getOrderCode());
if (StrUtil.isNotEmpty(advanceEntity.getTrainNumber())) {
eq.eq(TrunklineAdvanceEntity::getTrainNumber, advanceEntity.getTrainNumber());
}
// 暂存单 订单自编号 + 车次号 唯一
List<TrunklineAdvanceEntity> advanceEntities = advanceService.list(eq);
// 暂存单存在 并且未开单 则将新数据添加到原来的暂存单上
// 如果已开单则新增暂存单
if (CollUtil.isNotEmpty(advanceEntities) && ObjectUtil.equal(advanceEntity.getWaybillStatus(), "0")) {
TrunklineAdvanceEntity entity = advanceEntities.get(0);
if (ObjectUtil.isNotEmpty(entity)) {
advanceEntity.setId(entity.getId());
// advanceEntity.setTotalNum(entity.getTotalNum() + advanceEntity.getTotalNum());
}
}
Set<String> packageCodeSet = new HashSet<>();
if (CollUtil.isNotEmpty(details)) {
// 使用HashSet代替ArrayList以优化内存使用和检查重复值
Set<String> orderPackageCodes = new HashSet<>();
details.forEach(detail -> {
try {
// 更具描述性的变量命名
JSONObject jsonObject = JSONUtil.parseObj(detail);
TrunklineAdvanceDetailEntity entity = JSONUtil.toBean(jsonObject, TrunklineAdvanceDetailEntity.class);
// 检查转换后的实体不为null,且其orderPackageCode非null
if (!ObjectUtil.isAllEmpty(entity, entity.getOrderPackageCode())) {
orderPackageCodes.add(entity.getOrderPackageCode());
}
} catch (Exception e) {
// 异常处理,可根据实际情况记录日志或进行其他处理
log.error("暂存单转换时发生异常: " + detail + ",异常:" + e.getMessage());
}
});
// 查询数据库,校验订单包件编码是否重复
if (CollUtil.isNotEmpty(orderPackageCodes)) {
Map<String, String> packageCodeByCodes = advanceDetailService.findPackageCodeByCodes(orderPackageCodes);
if (CollUtil.isNotEmpty(packageCodeByCodes)) {
packageCodeSet.addAll(packageCodeByCodes.keySet());
}
}
}
if (ObjectUtil.isNotNull(advanceEntity)) {
String orderCode = advanceEntity.getOrderCode();
if (StrUtil.isNotEmpty(orderCode) && orderCode.contains("遗")) {
advanceEntity.setLegacyStatus("1");
}
// 暂存单不存在则新增,暂存单存在则将暂存单明细往原暂存单中添加
if (ObjectUtil.isEmpty(advanceEntity.getId())) {
advanceEntity.setCreateUserName(AuthUtil.getNickName());
advanceService.save(advanceEntity);
} else {
advanceEntity.setWaybillStatus(null);
advanceEntity.setWaybillNo(null);
advanceService.updateById(advanceEntity);
// 查询出当前暂存单明细
List<TrunklineAdvanceDetailEntity> advanceDetailEntityList = advanceDetailService.list(Wrappers.<TrunklineAdvanceDetailEntity>lambdaQuery()
.eq(TrunklineAdvanceDetailEntity::getAdvanceId, advanceEntity.getId()));
// 如果 packageCodeSet 不存在 则删除
if (CollUtil.isNotEmpty(advanceDetailEntityList)) {
advanceDetailEntityList.forEach(advanceDetailEntity -> {
if (!packageCodeSet.contains(advanceDetailEntity.getOrderPackageCode())) {
advanceDetailService.removeById(advanceDetailEntity.getId());
}
});
}
}
}
if (ObjectUtil.isNotEmpty(advanceEntity) && CollUtil.isNotEmpty(details)) {
List<TrunklineAdvanceDetailEntity> advanceDetailEntityList = new ArrayList<>();
List<TrunklineDetailProductEntity> detailProductEntityList = new ArrayList<>();
for (Object detailObj : details) {
JSONObject detail = JSONUtil.parseObj(detailObj);
TrunklineAdvanceDetailEntity advanceDetailEntity = JSONUtil.toBean(detail, TrunklineAdvanceDetailEntity.class);
if (ObjectUtil.isNotNull(advanceDetailEntity)) {
if (CollUtil.isNotEmpty(packageCodeSet) && packageCodeSet.contains(advanceDetailEntity.getOrderPackageCode())) {
// 金牌如果是重复包条,则单独处理
if (ObjectUtil.equal(advanceEntity.getBrand(), BrandEnums.JP.getValue())) {
// 金牌按DD单号+包条确定唯一值
List<TrunklineAdvanceDetailEntity> list = advanceDetailService.list(Wrappers.<TrunklineAdvanceDetailEntity>lambdaQuery()
.eq(TrunklineAdvanceDetailEntity::getOrderPackageCode, advanceDetailEntity.getOrderPackageCode())
.eq(TrunklineAdvanceDetailEntity::getOrderCode, advanceEntity.getOrderCode())
);
if (CollUtil.isNotEmpty(list)) {
// 订单+包件重复则不处理这条数据
log.error("金牌,订单+包条码重复,订单:{},包条码:{}", advanceEntity.getOrderCode(), advanceDetailEntity.getOrderPackageCode());
continue;
} else {
// 包件码重复,订单+包件不重复,设置预留字段1 为 1
advanceDetailEntity.setReserve1("1");
}
} else {
log.error("非金牌,包条码重复,包条码:{}", advanceDetailEntity.getOrderPackageCode());
continue;
}
}
advanceDetailEntity.setAdvanceId(advanceEntity.getId());
// 设置发货时间为当前时间
if (StrUtil.isEmpty(advanceDetailEntity.getSendDateStr())) {
advanceDetailEntity.setSendDateStr(DateUtil.today());
}
advanceDetailEntityList.add(advanceDetailEntity);
JSONArray items = detail.getJSONArray("items");
if (CollUtil.isNotEmpty(items)) {
for (Object itemObj : items) {
JSONObject item = JSONUtil.parseObj(itemObj);
TrunklineDetailProductEntity detailProductEntity = JSONUtil.toBean(item, TrunklineDetailProductEntity.class);
if (ObjectUtil.isNotNull(detailProductEntity)) {
detailProductEntityList.add(detailProductEntity);
}
}
}
}
}
advanceDetailService.saveBatch(advanceDetailEntityList);
// 发送入库包件处理无数据装车数据
trunklineCarsLoadService.sendRabbitMessageLoadScanData(JSONUtil.toJsonStr(advanceEntity));
detailProductService.saveBatch(detailProductEntityList);
// 发送报表数据广播
Long warehouseId = advanceEntity.getWarehouseId();
String warehouseName = advanceEntity.getWarehouseName();
String dealerCode = advanceEntity.getDealerCode();
String dealerName = advanceEntity.getDealerName();
advanceDetailService.sendReportBasicdataFanout(AuthUtil.getNickName(), AuthUtil.getUserId(), warehouseId, warehouseName, new Date(), advanceDetailEntityList, dealerCode, dealerName);
}
}
}
@Override
@Transactional(rollbackFor = Exception.class)

Loading…
Cancel
Save