|
|
|
@ -1,15 +1,20 @@
|
|
|
|
|
package com.logpm.distribution.receiver.report; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
import cn.hutool.core.util.NumberUtil; |
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.logpm.distribution.dto.ReportQualityDeliverDTO; |
|
|
|
|
import com.logpm.distribution.entity.QualityDeliverEntity; |
|
|
|
|
import com.logpm.distribution.mapper.QualityDeliverMapper; |
|
|
|
|
import com.logpm.factorydata.feign.IFactoryDataClient; |
|
|
|
|
import com.logpm.factorydata.vo.SendMsg; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.common.constant.WorkNodeEnums; |
|
|
|
|
import org.springblade.common.constant.report.ReportConstants; |
|
|
|
|
import org.springblade.common.enums.BizOperationEnums; |
|
|
|
|
import org.springblade.common.enums.PackageTypeEnums; |
|
|
|
@ -21,7 +26,11 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 自提任务生成明细报表 |
|
|
|
@ -36,6 +45,7 @@ public class BillPlanReportListener implements ReportService {
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private IFactoryDataClient factoryDataClient; |
|
|
|
|
private final QualityDeliverMapper qualityDeliverMapper; |
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public void buildReport(String msg) { |
|
|
|
@ -46,31 +56,75 @@ public class BillPlanReportListener implements ReportService {
|
|
|
|
|
Long warehouseId = bean.getWarehouseId(); |
|
|
|
|
BizOperationEnums bizOperation = bean.getBizOperation(); |
|
|
|
|
List<PackageData> details = vo.getPackageDataList(); |
|
|
|
|
String reservationCode = vo.getPickupBatch(); |
|
|
|
|
Map<String, List<QualityDeliverEntity>> cmpMap = new HashMap<>(); |
|
|
|
|
Map<String, List<QualityDeliverEntity>> ltlMap = new HashMap<>(); |
|
|
|
|
Map<String, List<QualityDeliverEntity>> invMap = new HashMap<>(); |
|
|
|
|
if (StrUtil.isNotEmpty(reservationCode)) { |
|
|
|
|
List<QualityDeliverEntity> qualityDeliverEntities = qualityDeliverMapper.selectList(Wrappers.<QualityDeliverEntity>lambdaQuery().eq(QualityDeliverEntity::getPlanReservationCode, reservationCode)); |
|
|
|
|
if (CollUtil.isNotEmpty(qualityDeliverEntities)) { |
|
|
|
|
// 取消预约 将表中数据全删
|
|
|
|
|
if (BizOperationEnums.DELETE.equals(bizOperation)) { |
|
|
|
|
for (QualityDeliverEntity qualityDeliverEntity : qualityDeliverEntities) { |
|
|
|
|
sendReport(qualityDeliverEntity, bizOperation); |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
cmpMap = qualityDeliverEntities.stream() |
|
|
|
|
.filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.CMP.getCode())) |
|
|
|
|
.collect(Collectors.groupingBy(item -> item.getOrderPackageCode())); |
|
|
|
|
ltlMap = qualityDeliverEntities.stream() |
|
|
|
|
.filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.LTL.getCode())) |
|
|
|
|
.collect(Collectors.groupingBy(item -> item.getCategory() + item.getOrderCode())); |
|
|
|
|
invMap = qualityDeliverEntities.stream() |
|
|
|
|
.filter(item -> NumberUtil.equals(item.getConditions(), PackageTypeEnums.INV.getCode())) |
|
|
|
|
.collect(Collectors.groupingBy(item -> item.getMallName() + item.getMaterielCode() + item.getIncomingBatch())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (CollUtil.isNotEmpty(details)) { |
|
|
|
|
for (PackageData detail : details) { |
|
|
|
|
QualityDeliverEntity qualityDeliverEntity = QualityDeliverEntity.builder() |
|
|
|
|
.warehouseName(bean.getWarehouse()) |
|
|
|
|
.warehouseId(warehouseId) |
|
|
|
|
.orderPackageCode(detail.getPackageCode()) |
|
|
|
|
.planReservationCode(vo.getPickupBatch()) |
|
|
|
|
.reservationConsignee(vo.getConsignee()) |
|
|
|
|
.reservationConsigneePhone(vo.getConsigneePhone()) |
|
|
|
|
.planReservationUser(bean.getOperator()) |
|
|
|
|
.planReservationTime(bean.getOperatorTime()) |
|
|
|
|
.planNum(detail.getNumber()) |
|
|
|
|
.planTrainNumber(vo.getPickupBatch()) |
|
|
|
|
.deliveryTime(vo.getPickUpTime()) |
|
|
|
|
.deliveryType("自提") |
|
|
|
|
.deliveryKind("自主配送") |
|
|
|
|
.vehicleName(vo.getPickUpPlate()) |
|
|
|
|
.bizCode(vo.getPickupBatch()) |
|
|
|
|
.driverName(vo.getConsignee()) |
|
|
|
|
.bizCode(vo.getPickupBatch()) |
|
|
|
|
.deliveryPlanTime(bean.getOperatorTime()) |
|
|
|
|
.deliveryCreateUserName(bean.getOperator()) |
|
|
|
|
.build(); |
|
|
|
|
if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.CMP)) { |
|
|
|
|
qualityDeliverEntity.setConditions(1); |
|
|
|
|
qualityDeliverEntity.setPlanNum(1); |
|
|
|
|
sendReport(bizOperation, qualityDeliverEntity, BizOperationEnums.MODIFY); |
|
|
|
|
// 存在订制品则修改 不存在则新增
|
|
|
|
|
if (cmpMap.containsKey(detail.getPackageCode())) { |
|
|
|
|
qualityDeliverEntity.setId(cmpMap.get(detail.getPackageCode()).get(0).getId()); |
|
|
|
|
sendReport(qualityDeliverEntity, BizOperationEnums.MODIFY); |
|
|
|
|
} else { |
|
|
|
|
sendReport(qualityDeliverEntity, BizOperationEnums.ADD); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.LTL)) { |
|
|
|
|
qualityDeliverEntity.setOrderCode(detail.getOrderCode()); |
|
|
|
|
qualityDeliverEntity.setCategory(detail.getProductName()); |
|
|
|
|
qualityDeliverEntity.setConditions(2); |
|
|
|
|
sendReport(bizOperation, qualityDeliverEntity, BizOperationEnums.MODIFY); |
|
|
|
|
// 存在零担则修改 不存在则新增
|
|
|
|
|
if (ltlMap.containsKey(detail.getProductName() + detail.getOrderCode())) { |
|
|
|
|
qualityDeliverEntity.setId(ltlMap.get(detail.getProductName() + detail.getOrderCode()).get(0).getId()); |
|
|
|
|
sendReport(qualityDeliverEntity, BizOperationEnums.MODIFY); |
|
|
|
|
} else { |
|
|
|
|
sendReport(qualityDeliverEntity, BizOperationEnums.ADD); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.INV)) { |
|
|
|
|
qualityDeliverEntity.setIncomingBatch(detail.getPickupBatch()); |
|
|
|
@ -79,28 +133,98 @@ public class BillPlanReportListener implements ReportService {
|
|
|
|
|
qualityDeliverEntity.setMaterielName(detail.getMaterialName()); |
|
|
|
|
qualityDeliverEntity.setConditions(3); |
|
|
|
|
Integer number = detail.getNumber(); |
|
|
|
|
for (int i = 0; i < number; i++) { |
|
|
|
|
QualityDeliverEntity entity = new QualityDeliverEntity(); |
|
|
|
|
BeanUtil.copyProperties(qualityDeliverEntity, entity); |
|
|
|
|
entity.setPlanNum(1); |
|
|
|
|
sendReport(bizOperation, entity, BizOperationEnums.ADD); |
|
|
|
|
// 存在库存品则修改 不存在则新增
|
|
|
|
|
// 当前库存品数据大于已有数量 则新增增量部分,如果当前库存品数量小于已有数量 需要删除数据 1 删除操作只针对未备货的数据 2 全删或者只删除部分
|
|
|
|
|
if (invMap.containsKey(detail.getMallName() + detail.getMaterialCode() + detail.getPickupBatch())) { |
|
|
|
|
List<QualityDeliverEntity> qualityDeliverEntities = invMap.get(detail.getMallName() + detail.getMaterialCode() + detail.getPickupBatch()); |
|
|
|
|
int size = qualityDeliverEntities.size(); |
|
|
|
|
if (number > size) { |
|
|
|
|
for (int i = 0; i < number - size; i++) { |
|
|
|
|
QualityDeliverEntity entity = new QualityDeliverEntity(); |
|
|
|
|
BeanUtil.copyProperties(qualityDeliverEntity, entity); |
|
|
|
|
entity.setPlanNum(1); |
|
|
|
|
sendReport(entity, BizOperationEnums.ADD); |
|
|
|
|
} |
|
|
|
|
for (QualityDeliverEntity deliverEntity : qualityDeliverEntities) { |
|
|
|
|
qualityDeliverEntity.setId(deliverEntity.getId()); |
|
|
|
|
qualityDeliverEntity.setPlanNum(1); |
|
|
|
|
sendReport(qualityDeliverEntity, BizOperationEnums.DELETE); |
|
|
|
|
} |
|
|
|
|
} else if (number == size) { |
|
|
|
|
for (QualityDeliverEntity deliverEntity : qualityDeliverEntities) { |
|
|
|
|
qualityDeliverEntity.setId(deliverEntity.getId()); |
|
|
|
|
qualityDeliverEntity.setPlanNum(1); |
|
|
|
|
sendReport(qualityDeliverEntity, BizOperationEnums.MODIFY); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
List<QualityDeliverEntity> collect = qualityDeliverEntities.stream() |
|
|
|
|
.filter(item -> StrUtil.isEmpty(item.getOrderPackageCode())) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
if (CollUtil.isNotEmpty(collect)) { |
|
|
|
|
int i = size - number; |
|
|
|
|
if (i >= collect.size()) { |
|
|
|
|
for (QualityDeliverEntity entity : collect) { |
|
|
|
|
sendReport(entity, BizOperationEnums.DELETE); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
for (int j = 0; j < i; j++) { |
|
|
|
|
sendReport(collect.get(j), BizOperationEnums.DELETE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
for (int i = 0; i < number; i++) { |
|
|
|
|
QualityDeliverEntity entity = new QualityDeliverEntity(); |
|
|
|
|
BeanUtil.copyProperties(qualityDeliverEntity, entity); |
|
|
|
|
entity.setPlanNum(1); |
|
|
|
|
sendReport(entity, BizOperationEnums.ADD); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 系统中有的包件在当前不存在,则删除
|
|
|
|
|
Set<String> cmpSet = details.stream().filter(item -> ObjectUtil.equals(item.getPackageType(), PackageTypeEnums.CMP)).map(PackageData::getPackageCode).collect(Collectors.toSet()); |
|
|
|
|
for (Map.Entry<String, List<QualityDeliverEntity>> entry : cmpMap.entrySet()) { |
|
|
|
|
String key = entry.getKey(); |
|
|
|
|
if (!cmpSet.contains(key)) { |
|
|
|
|
sendReport(entry.getValue().get(0), BizOperationEnums.DELETE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Set<String> ltlSet = details.stream().filter(item -> ObjectUtil.equals(item.getPackageType(), PackageTypeEnums.LTL)) |
|
|
|
|
.map(i -> i.getProductName() + i.getOrderCode()).collect(Collectors.toSet()); |
|
|
|
|
for (Map.Entry<String, List<QualityDeliverEntity>> entry : ltlMap.entrySet()) { |
|
|
|
|
String key = entry.getKey(); |
|
|
|
|
if (!ltlSet.contains(key)) { |
|
|
|
|
sendReport(entry.getValue().get(0), BizOperationEnums.DELETE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Set<String> invSet = details.stream().filter(item -> ObjectUtil.equals(item.getPackageType(), PackageTypeEnums.INV)) |
|
|
|
|
.map(i -> i.getMallName() + i.getMaterialCode() + i.getPickupBatch()).collect(Collectors.toSet()); |
|
|
|
|
for (Map.Entry<String, List<QualityDeliverEntity>> entry : invMap.entrySet()) { |
|
|
|
|
String key = entry.getKey(); |
|
|
|
|
if (!invSet.contains(key)) { |
|
|
|
|
List<QualityDeliverEntity> value = entry.getValue(); |
|
|
|
|
for (QualityDeliverEntity entity : value) { |
|
|
|
|
sendReport(entity, BizOperationEnums.DELETE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void sendReport(BizOperationEnums bizOperation, QualityDeliverEntity qualityDeliverEntity, BizOperationEnums bizOperationEnums) { |
|
|
|
|
if (BizOperationEnums.ADD.equals(bizOperation) || BizOperationEnums.MODIFY.equals(bizOperation)) { |
|
|
|
|
ReportQualityDeliverDTO dto = ReportQualityDeliverDTO.builder().data(JSONUtil.toJsonStr(qualityDeliverEntity)).operation(bizOperationEnums).build(); |
|
|
|
|
factoryDataClient.sendMessage(SendMsg.builder() |
|
|
|
|
.exchange(ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE) |
|
|
|
|
.routingKey(ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY) |
|
|
|
|
.message(JSONUtil.toJsonStr(dto)) |
|
|
|
|
.delay(3000) |
|
|
|
|
.build()); |
|
|
|
|
} |
|
|
|
|
private void sendReport(QualityDeliverEntity qualityDeliverEntity, BizOperationEnums operationEnums) { |
|
|
|
|
ReportQualityDeliverDTO dto = ReportQualityDeliverDTO.builder() |
|
|
|
|
.data(JSONUtil.toJsonStr(qualityDeliverEntity)) |
|
|
|
|
.operation(operationEnums) |
|
|
|
|
.node(WorkNodeEnums.PLAN_BILLOFLADING.getValue()) |
|
|
|
|
.build(); |
|
|
|
|
factoryDataClient.sendMessage(SendMsg.builder() |
|
|
|
|
.exchange(ReportConstants.REPORT_QUALITY_DELIVER_EXCHANGE) |
|
|
|
|
.routingKey(ReportConstants.REPORT_QUALITY_DELIVER_ROUTINGKEY) |
|
|
|
|
.message(JSONUtil.toJsonStr(dto)) |
|
|
|
|
.delay(3000) |
|
|
|
|
.build()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|