|
|
|
@ -1,31 +1,10 @@
|
|
|
|
|
package com.logpm.trunkline.mq; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
import cn.hutool.core.convert.Convert; |
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import cn.hutool.json.JSONArray; |
|
|
|
|
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.distribution.entity.DistributionParcelListEntity; |
|
|
|
|
import com.logpm.distribution.feign.IDistributionParcelListClient; |
|
|
|
|
import com.logpm.distribution.feign.IDistributionStockArticleClient; |
|
|
|
|
import com.logpm.trunkline.entity.TrunklineAdvanceDetailEntity; |
|
|
|
|
import com.logpm.trunkline.entity.TrunklineAdvanceEntity; |
|
|
|
|
import com.logpm.trunkline.entity.TrunklineDetailProductEntity; |
|
|
|
|
import com.logpm.trunkline.service.IAdvanceOrderMqService; |
|
|
|
|
import com.logpm.trunkline.service.ITrunklineAdvanceDetailService; |
|
|
|
|
import com.logpm.trunkline.service.ITrunklineAdvanceService; |
|
|
|
|
import com.logpm.trunkline.service.ITrunklineCarsLoadService; |
|
|
|
|
import com.logpm.trunkline.service.ITrunklineDetailProductService; |
|
|
|
|
import com.rabbitmq.client.Channel; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.common.constant.factorydata.FactoryDataConstants; |
|
|
|
|
import org.springblade.core.secure.utils.AuthUtil; |
|
|
|
|
import org.springframework.amqp.core.ExchangeTypes; |
|
|
|
|
import org.springframework.amqp.rabbit.annotation.Exchange; |
|
|
|
|
import org.springframework.amqp.rabbit.annotation.Queue; |
|
|
|
@ -34,15 +13,8 @@ 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.io.IOException; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.HashSet; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 监听工厂数据转暂存单 |
|
|
|
@ -56,12 +28,6 @@ import java.util.Set;
|
|
|
|
|
public class AdvanceOrderListener { |
|
|
|
|
|
|
|
|
|
private final IAdvanceOrderMqService advanceOrderMqService; |
|
|
|
|
private final ITrunklineAdvanceService advanceService; |
|
|
|
|
private final ITrunklineAdvanceDetailService advanceDetailService; |
|
|
|
|
private final ITrunklineDetailProductService detailProductService; |
|
|
|
|
private final ITrunklineCarsLoadService trunklineCarsLoadService; |
|
|
|
|
private final IDistributionStockArticleClient stockArticleClient; |
|
|
|
|
private final IDistributionParcelListClient parcelListClient; |
|
|
|
|
|
|
|
|
|
@RabbitListener(bindings = @QueueBinding( |
|
|
|
|
value = @Queue(name = FactoryDataConstants.Mq.Queues.ADVANCE_ORDER), |
|
|
|
@ -88,188 +54,20 @@ public class AdvanceOrderListener {
|
|
|
|
|
value = @Queue(name = FactoryDataConstants.Mq.Queues.ADVANCE_ORDER_OUPAI), |
|
|
|
|
exchange = @Exchange(name = FactoryDataConstants.Mq.Exchanges.ADVANCE_ORDER_OUPAI, type = ExchangeTypes.TOPIC), |
|
|
|
|
key = FactoryDataConstants.Mq.RoutingKeys.ADVANCE_ORDER |
|
|
|
|
)) |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public void advanceOrderOuPai(String msg) { |
|
|
|
|
), ackMode = "MANUAL") |
|
|
|
|
public void advanceOrderOuPai(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) { |
|
|
|
|
// 新增暂存单
|
|
|
|
|
if (StrUtil.isNotBlank(msg)) { |
|
|
|
|
log.info("收到欧派工厂数据暂存单消息:{}", 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)) { |
|
|
|
|
TrunklineAdvanceEntity entity = advanceEntities.get(0); |
|
|
|
|
if (ObjectUtil.isNotEmpty(entity)) { |
|
|
|
|
// 如果存在则只修改客户信息
|
|
|
|
|
if (StrUtil.isNotEmpty(advanceEntity.getCustomerName())) { |
|
|
|
|
entity.setCustomerName(advanceEntity.getCustomerName()); |
|
|
|
|
} |
|
|
|
|
if (StrUtil.isNotEmpty(advanceEntity.getCustomerAddress())) { |
|
|
|
|
entity.setCustomerAddress(advanceEntity.getCustomerAddress()); |
|
|
|
|
} |
|
|
|
|
if (StrUtil.isNotEmpty(advanceEntity.getCustomerPhone())) { |
|
|
|
|
entity.setCustomerPhone(advanceEntity.getCustomerPhone()); |
|
|
|
|
} |
|
|
|
|
advanceService.updateById(entity); |
|
|
|
|
// 修改在库订单信息 未预约的数据 reservation_status = 10 才更新
|
|
|
|
|
if (ObjectUtil.isAllNotEmpty(entity.getOrderCode(), advanceEntity.getCustomerName(), advanceEntity.getCustomerAddress(), advanceEntity.getCustomerPhone())) { |
|
|
|
|
try { |
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
jsonObject.set("orderCode", entity.getOrderCode()); |
|
|
|
|
jsonObject.set("customerName", advanceEntity.getCustomerName()); |
|
|
|
|
jsonObject.set("customerAddress", advanceEntity.getCustomerAddress()); |
|
|
|
|
jsonObject.set("customerPhone", advanceEntity.getCustomerPhone()); |
|
|
|
|
stockArticleClient.updateCustomerAllByOrderCode(JSONUtil.toJsonStr(jsonObject)); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("更新在库订单失败"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Map<String, String> packageCodeMap = new HashMap<>(); |
|
|
|
|
Map<String, Set<String>> parcelListMap = new HashMap<>(); |
|
|
|
|
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()); |
|
|
|
|
} |
|
|
|
|
advanceOrderMqService.advanceOrderOuPai(msg); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
// 异常处理,可根据实际情况记录日志或进行其他处理
|
|
|
|
|
log.error("暂存单转换时发生异常: " + detail + ",异常:" + e.getMessage()); |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
log.error("收到欧派工厂数据暂存单消息失败: {}", e.getMessage()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
// 查询数据库,校验订单包件编码是否重复
|
|
|
|
|
if (CollUtil.isNotEmpty(orderPackageCodes)) { |
|
|
|
|
packageCodeMap = advanceDetailService.findPackageCodeByCodes(orderPackageCodes); |
|
|
|
|
try { |
|
|
|
|
if(CollUtil.isNotEmpty(packageCodeMap)){ |
|
|
|
|
parcelListMap = parcelListClient.findPackageCodeByCodes(packageCodeMap.keySet()); |
|
|
|
|
} |
|
|
|
|
}catch (Exception e){ |
|
|
|
|
log.error("查询包件表失败"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 包件 修改 品类信息 物料名称
|
|
|
|
|
if (ObjectUtil.isNotEmpty(advanceEntity) && CollUtil.isNotEmpty(details)) { |
|
|
|
|
List<TrunklineAdvanceDetailEntity> advanceDetailEntityList = new ArrayList<>(); |
|
|
|
|
List<DistributionParcelListEntity> parcelListEntityList = new ArrayList<>(); |
|
|
|
|
List<TrunklineDetailProductEntity> detailProductEntityList = new ArrayList<>(); |
|
|
|
|
Set<String> productCodes = new HashSet<>(); |
|
|
|
|
for (Object detailObj : details) { |
|
|
|
|
JSONObject detail = JSONUtil.parseObj(detailObj); |
|
|
|
|
TrunklineAdvanceDetailEntity advanceDetailEntity = JSONUtil.toBean(detail, TrunklineAdvanceDetailEntity.class); |
|
|
|
|
if (ObjectUtil.isNotNull(advanceDetailEntity)) { |
|
|
|
|
if (CollUtil.isNotEmpty(packageCodeMap) && StrUtil.isNotEmpty(advanceDetailEntity.getOrderPackageCode()) |
|
|
|
|
&& packageCodeMap.containsKey(advanceDetailEntity.getOrderPackageCode())) { |
|
|
|
|
if(!ObjectUtil.isAllEmpty(advanceDetailEntity.getFirstPackName(),advanceDetailEntity.getSecondPackName(), |
|
|
|
|
advanceDetailEntity.getThirdPackName(),advanceDetailEntity.getMaterialName())){ |
|
|
|
|
TrunklineAdvanceDetailEntity updatedetailEntity = new TrunklineAdvanceDetailEntity(); |
|
|
|
|
updatedetailEntity.setId(Convert.toLong(packageCodeMap.get(advanceDetailEntity.getOrderPackageCode()))); |
|
|
|
|
updatedetailEntity.setFirstPackName(advanceDetailEntity.getFirstPackName()); |
|
|
|
|
updatedetailEntity.setFirstPackCode(advanceDetailEntity.getFirstPackCode()); |
|
|
|
|
updatedetailEntity.setSecondPackName(advanceDetailEntity.getSecondPackName()); |
|
|
|
|
updatedetailEntity.setSecondPackCode(advanceDetailEntity.getSecondPackCode()); |
|
|
|
|
updatedetailEntity.setThirdPackName(advanceDetailEntity.getThirdPackName()); |
|
|
|
|
updatedetailEntity.setThirdPackCode(advanceDetailEntity.getThirdPackCode()); |
|
|
|
|
updatedetailEntity.setMaterialName(advanceDetailEntity.getMaterialName()); |
|
|
|
|
updatedetailEntity.setMaterialCode(advanceDetailEntity.getMaterialCode()); |
|
|
|
|
advanceDetailEntityList.add(updatedetailEntity); |
|
|
|
|
} |
|
|
|
|
if(CollUtil.isNotEmpty(parcelListMap) && parcelListMap.containsKey(advanceDetailEntity.getOrderPackageCode())){ |
|
|
|
|
Set<String> strings = parcelListMap.get(advanceDetailEntity.getOrderPackageCode()); |
|
|
|
|
for (String string : strings) { |
|
|
|
|
DistributionParcelListEntity parcelListEntity = new DistributionParcelListEntity(); |
|
|
|
|
parcelListEntity.setId(Convert.toLong(string)); |
|
|
|
|
parcelListEntity.setFirsts(advanceDetailEntity.getFirstPackName()); |
|
|
|
|
parcelListEntity.setSecond(advanceDetailEntity.getSecondPackName()); |
|
|
|
|
parcelListEntity.setThirdProduct(advanceDetailEntity.getThirdPackName()); |
|
|
|
|
parcelListEntity.setMaterialName(advanceDetailEntity.getMaterialName()); |
|
|
|
|
parcelListEntity.setMaterialCode(advanceDetailEntity.getMaterialCode()); |
|
|
|
|
parcelListEntityList.add(parcelListEntity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
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)) { |
|
|
|
|
productCodes.add(detailProductEntity.getProductCode()); |
|
|
|
|
detailProductEntityList.add(detailProductEntity); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
if(CollUtil.isNotEmpty(parcelListEntityList)){ |
|
|
|
|
parcelListClient.saveorUpdateBatchByOP(parcelListEntityList); |
|
|
|
|
} |
|
|
|
|
if(CollUtil.isNotEmpty(advanceDetailEntityList)){ |
|
|
|
|
advanceDetailService.saveOrUpdateBatch(advanceDetailEntityList); |
|
|
|
|
} |
|
|
|
|
//发送入库包件处理无数据装车数据
|
|
|
|
|
trunklineCarsLoadService.sendRabbitMessageLoadScanData(JSONUtil.toJsonStr(advanceEntity)); |
|
|
|
|
if(CollUtil.isNotEmpty(detailProductEntityList)){ |
|
|
|
|
if(ObjectUtil.isAllNotEmpty(packageCodeMap,productCodes)){ |
|
|
|
|
List<TrunklineDetailProductEntity> list = detailProductService.list(Wrappers.<TrunklineDetailProductEntity>lambdaQuery() |
|
|
|
|
.in(TrunklineDetailProductEntity::getUnitNo, packageCodeMap.keySet()) |
|
|
|
|
.in(TrunklineDetailProductEntity::getProductCode, productCodes) |
|
|
|
|
); |
|
|
|
|
if(CollUtil.isNotEmpty(list)){ |
|
|
|
|
for (TrunklineDetailProductEntity productEntity : detailProductEntityList) { |
|
|
|
|
for (TrunklineDetailProductEntity detailProductEntity : list) { |
|
|
|
|
if(ObjectUtil.equal(productEntity.getProductCode(),detailProductEntity.getProductCode())){ |
|
|
|
|
productEntity.setId(detailProductEntity.getId()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
detailProductService.saveOrUpdateBatch(detailProductEntityList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
channel.basicAck(tag, false); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|