3 changed files with 119 additions and 108 deletions
@ -0,0 +1,116 @@
|
||||
package com.logpm.statistics.listener.mq; |
||||
|
||||
import cn.hutool.core.collection.CollUtil; |
||||
import cn.hutool.core.date.DateUtil; |
||||
import cn.hutool.core.util.StrUtil; |
||||
import cn.hutool.json.JSONArray; |
||||
import cn.hutool.json.JSONObject; |
||||
import cn.hutool.json.JSONUtil; |
||||
import com.logpm.statistics.entity.ExpenseWarehouseTransitEntity; |
||||
import com.logpm.statistics.service.IExpenseWarehouseTransitService; |
||||
import com.logpm.trunkline.entity.TrunklineCarsLoadEntity; |
||||
import com.logpm.trunkline.entity.TrunklineCostShareRecordEntity; |
||||
import com.rabbitmq.client.Channel; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.jetbrains.annotations.NotNull; |
||||
import org.springblade.common.constant.broadcast.FanoutConstants; |
||||
import org.springblade.common.model.NodeFanoutMsg; |
||||
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 java.io.IOException; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 自提任务生成明细报表 |
||||
* |
||||
* @author zhaoqiaobo |
||||
* @create 2024-03-18 0:02 |
||||
*/ |
||||
@Slf4j |
||||
@Component |
||||
@AllArgsConstructor |
||||
public class ExpenseFanoutListener { |
||||
|
||||
private final IExpenseWarehouseTransitService transitService; |
||||
|
||||
@RabbitListener(bindings = @QueueBinding( |
||||
value = @Queue(name = FanoutConstants.trunkline.COSTSHARE.QUEUE.TRANSIT_COST_DETAILS, durable = "true"), |
||||
exchange = @Exchange(name = FanoutConstants.trunkline.COSTSHARE.EXCHANGE, type = ExchangeTypes.FANOUT) |
||||
), ackMode = "MANUAL") |
||||
public void transitCostDetails(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) { |
||||
log.info("中转成本出入库报表: {}", msg); |
||||
try { |
||||
NodeFanoutMsg bean = JSONUtil.toBean(msg, NodeFanoutMsg.class); |
||||
Object main = bean.getMain(); |
||||
JSONObject entries = JSONUtil.parseObj(main); |
||||
TrunklineCarsLoadEntity vo = JSONUtil.toBean(entries, TrunklineCarsLoadEntity.class); |
||||
JSONArray details = entries.getJSONArray("details"); |
||||
List<TrunklineCostShareRecordEntity> list = JSONUtil.toList(details, TrunklineCostShareRecordEntity.class); |
||||
List<ExpenseWarehouseTransitEntity> entities = new ArrayList<>(); |
||||
for (TrunklineCostShareRecordEntity trunklineCostShareRecordEntity : list) { |
||||
if (StrUtil.isEmpty(trunklineCostShareRecordEntity.getWaybillStartWarehouseName()) |
||||
|| StrUtil.isEmpty(trunklineCostShareRecordEntity.getWaybillEndWarehouseName())) { |
||||
continue; |
||||
} |
||||
String packageType = trunklineCostShareRecordEntity.getProductType() == 1 ? "订制品" : "零担"; |
||||
// 卸车仓库 != 运单始发仓 && 卸车仓库 != 运单目的仓
|
||||
if (StrUtil.isNotEmpty(trunklineCostShareRecordEntity.getRealUnloadWarehouseName())) { |
||||
if (!trunklineCostShareRecordEntity.getRealUnloadWarehouseName().equals(trunklineCostShareRecordEntity.getWaybillStartWarehouseName()) |
||||
&& !trunklineCostShareRecordEntity.getRealUnloadWarehouseName().equals(trunklineCostShareRecordEntity.getWaybillEndWarehouseName())) { |
||||
String workType = "入库"; |
||||
ExpenseWarehouseTransitEntity entity = buildEntiry(trunklineCostShareRecordEntity, bean, workType, packageType); |
||||
entities.add(entity); |
||||
} |
||||
} |
||||
// 卸车仓库 != 运单始发仓 && 卸车仓库 != 运单目的仓
|
||||
if (StrUtil.isNotEmpty(trunklineCostShareRecordEntity.getLoadingWarehouseName())) { |
||||
if (!trunklineCostShareRecordEntity.getLoadingWarehouseName().equals(trunklineCostShareRecordEntity.getWaybillStartWarehouseName()) |
||||
&& !trunklineCostShareRecordEntity.getLoadingWarehouseName().equals(trunklineCostShareRecordEntity.getWaybillEndWarehouseName())) { |
||||
String workType = "出库"; |
||||
ExpenseWarehouseTransitEntity entity = buildEntiry(trunklineCostShareRecordEntity, bean, workType, packageType); |
||||
entities.add(entity); |
||||
} |
||||
} |
||||
} |
||||
if (CollUtil.isNotEmpty(entities)) { |
||||
transitService.saveBatch(entities); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("中转成本出入库报表失败: {}", e.getMessage()); |
||||
} |
||||
try { |
||||
channel.basicAck(tag, false); |
||||
} catch (IOException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
|
||||
private static @NotNull ExpenseWarehouseTransitEntity buildEntiry(TrunklineCostShareRecordEntity trunklineCostShareRecordEntity, NodeFanoutMsg bean, String workType, String packageType) { |
||||
ExpenseWarehouseTransitEntity entity = new ExpenseWarehouseTransitEntity(); |
||||
// entity.setTaskTime(new Date());
|
||||
entity.setConfirmAllocationYear(DateUtil.year(bean.getOperatorTime())); |
||||
entity.setConfirmAllocationMonth(DateUtil.month(bean.getOperatorTime())); |
||||
entity.setConfirmAllocationDay(DateUtil.dayOfMonth(bean.getOperatorTime())); |
||||
entity.setConfirmAllocationTime(bean.getOperatorTime()); |
||||
entity.setTransitWarehouseName(trunklineCostShareRecordEntity.getRealUnloadWarehouseName()); |
||||
entity.setDestinationWarehouseName(trunklineCostShareRecordEntity.getWaybillEndWarehouseName()); |
||||
entity.setWorkType(workType); |
||||
entity.setPackageType(packageType); |
||||
entity.setPackageCode(trunklineCostShareRecordEntity.getProductCode()); |
||||
entity.setOrderCode(trunklineCostShareRecordEntity.getOrderCode()); |
||||
entity.setWaybillNumber(trunklineCostShareRecordEntity.getWaybillNo()); |
||||
entity.setTrainNumber(trunklineCostShareRecordEntity.getCarsNo()); |
||||
entity.setNum(trunklineCostShareRecordEntity.getNum()); |
||||
return entity; |
||||
} |
||||
|
||||
} |
@ -1,107 +0,0 @@
|
||||
package com.logpm.statistics.listener.mq; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
/** |
||||
* 自提任务生成明细报表 |
||||
* |
||||
* @author zhaoqiaobo |
||||
* @create 2024-03-18 0:02 |
||||
*/ |
||||
@Slf4j |
||||
@Component |
||||
@AllArgsConstructor |
||||
public class expenseFanoutListener { |
||||
|
||||
// @RabbitListener(bindings = @QueueBinding(
|
||||
// value = @Queue(name = FanoutConstants.DeliveryOfPickup.BillPlan.QUEUE.REPORT, durable = "true"),
|
||||
// exchange = @Exchange(name = FanoutConstants.DeliveryOfPickup.BillPlan.EXCHANGE, type = ExchangeTypes.FANOUT)
|
||||
// ))
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void buildReport(String msg) {
|
||||
// log.info("自提任务生成明细报表: {}", msg);
|
||||
// if (StrUtil.isEmpty(msg)) {
|
||||
// return;
|
||||
// }
|
||||
// NodeFanoutMsg bean = JSONUtil.toBean(msg, NodeFanoutMsg.class);
|
||||
// Object main = bean.getMain();
|
||||
// JSONObject entries = JSONUtil.parseObj(main);
|
||||
// DeliveryOfPickupPlanVO vo = JSONUtil.toBean(entries, DeliveryOfPickupPlanVO.class);
|
||||
// Long warehouseId = bean.getWarehouseId();
|
||||
// BizOperationEnums bizOperation = bean.getBizOperation();
|
||||
// List<PackageData> details = vo.getPackageDataList();
|
||||
// if (BizOperationEnums.MODIFY.equals(bizOperation) || BizOperationEnums.DELETE.equals(bizOperation)) {
|
||||
// // 根据预约单号查询出所有这个预约单下的数据 先置空
|
||||
// LambdaUpdateWrapper<QualityDeliverEntity> wrapper = Wrappers.<QualityDeliverEntity>lambdaUpdate()
|
||||
// .set(QualityDeliverEntity::getPlanTrainNumber, null)
|
||||
// .set(QualityDeliverEntity::getDeliveryTime, null)
|
||||
// .set(QualityDeliverEntity::getDeliveryType, null)
|
||||
// .set(QualityDeliverEntity::getVehicleName, null)
|
||||
// .set(QualityDeliverEntity::getBizCode, null)
|
||||
// .set(QualityDeliverEntity::getDriverName, null)
|
||||
// .set(QualityDeliverEntity::getDeliveryPlanTime, null)
|
||||
// .set(QualityDeliverEntity::getDeliveryCreateUserName, null)
|
||||
// .eq(QualityDeliverEntity::getBizCode, vo.getPickupBatch())
|
||||
// .ne(QualityDeliverEntity::getBizStatus, 110);
|
||||
// qualityDeliverService.update(wrapper);
|
||||
// }
|
||||
// if (CollUtil.isNotEmpty(details)) {
|
||||
// for (PackageData detail : details) {
|
||||
// QualityDeliverEntity qualityDeliverEntity = QualityDeliverEntity.builder()
|
||||
// .warehouseName(bean.getWarehouse())
|
||||
// .warehouseId(warehouseId)
|
||||
// .orderPackageCode(detail.getPackageCode())
|
||||
// .planTrainNumber(vo.getPickupBatch())
|
||||
// .deliveryTime(vo.getPickUpTime())
|
||||
// .deliveryType("自提")
|
||||
// .vehicleName(vo.getPickUpPlate())
|
||||
// .bizCode(vo.getPickupBatch())
|
||||
// .driverName(vo.getConsignee())
|
||||
// .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 (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.LTL)) {
|
||||
// qualityDeliverEntity.setOrderCode(detail.getOrderCode());
|
||||
// qualityDeliverEntity.setCategory(detail.getProductName());
|
||||
// qualityDeliverEntity.setConditions(2);
|
||||
// sendReport(bizOperation, qualityDeliverEntity,BizOperationEnums.MODIFY);
|
||||
// }
|
||||
// if (ObjectUtil.equals(detail.getPackageType(), PackageTypeEnums.INV)) {
|
||||
// qualityDeliverEntity.setIncomingBatch(detail.getPickupBatch());
|
||||
// qualityDeliverEntity.setMallName(detail.getMallName());
|
||||
// qualityDeliverEntity.setMaterielCode(detail.getMaterialCode());
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// 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());
|
||||
// }
|
||||
// }
|
||||
|
||||
} |
Loading…
Reference in new issue