|
|
|
@ -2,8 +2,12 @@ package com.logpm.trunkline.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
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.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
@ -19,14 +23,18 @@ import com.logpm.distribution.entity.DistributionParcelListEntity;
|
|
|
|
|
import com.logpm.distribution.entity.DistributionStockArticleEntity; |
|
|
|
|
import com.logpm.distribution.feign.IDistributionParcelListClient; |
|
|
|
|
import com.logpm.distribution.feign.IDistributionStockArticleClient; |
|
|
|
|
import com.logpm.factorydata.enums.BrandEnums; |
|
|
|
|
import com.logpm.trunkline.dto.AdvanceDTO; |
|
|
|
|
import com.logpm.trunkline.dto.InComingDTO; |
|
|
|
|
import com.logpm.trunkline.dto.OrderStatusDTO; |
|
|
|
|
import com.logpm.trunkline.entity.TrunklineAdvanceDetailEntity; |
|
|
|
|
import com.logpm.trunkline.entity.TrunklineAdvanceEntity; |
|
|
|
|
import com.logpm.trunkline.entity.TrunklineDetailProductEntity; |
|
|
|
|
import com.logpm.trunkline.mapper.TrunklineAdvanceMapper; |
|
|
|
|
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.logpm.trunkline.vo.CustomerInfoVO; |
|
|
|
|
import com.logpm.trunkline.vo.OpenOrderVO; |
|
|
|
|
import com.logpm.trunkline.vo.TrunklineAdvanceVO; |
|
|
|
@ -60,12 +68,13 @@ public class TrunklineAdvanceServiceImpl extends BaseServiceImpl<TrunklineAdvanc
|
|
|
|
|
private final IBasicdataClientClient basicdataClientClient; |
|
|
|
|
private final IBasicdataStoreBusinessClient basicdataStoreBusinessClient; |
|
|
|
|
private final IBasicMaterialClient basicMaterialClient; |
|
|
|
|
private final IBasicdataTripartiteMallClient tripartiteMallClient; |
|
|
|
|
private final IWarehouseWaybillClient warehouseWaybillClient; |
|
|
|
|
private final IBasicdataTripartiteMallClient basicdataTripartiteMallClient; |
|
|
|
|
private final RabbitTemplate rabbitTemplate; |
|
|
|
|
private final ITrunklineAdvanceDetailService advanceDetailService; |
|
|
|
|
private final IBasicdataBrandClient basicdataBrandClient; |
|
|
|
|
private final ITrunklineDetailProductService detailProductService; |
|
|
|
|
private final ITrunklineCarsLoadService trunklineCarsLoadService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -1972,4 +1981,130 @@ public class TrunklineAdvanceServiceImpl extends BaseServiceImpl<TrunklineAdvanc
|
|
|
|
|
public Integer findTotalNumByWaybillNoAndOrderCode(String waybillNo, String orderCode) { |
|
|
|
|
return baseMapper.findTotalNumByWaybillNoAndOrderCode(waybillNo,orderCode); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public void advanceOrder(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 = this.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()); |
|
|
|
|
this.save(advanceEntity); |
|
|
|
|
} else { |
|
|
|
|
this.updateById(advanceEntity); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|