|
|
@@ -13,10 +13,12 @@ import com.sckw.freight.mapper.freight.KwpLedgerLogisticsMapper;
|
|
|
import com.sckw.freight.mapper.freight.KwpSettlementLogisticsMapper;
|
|
|
import com.sckw.freight.mapper.kll.KllOrderTaskMapper;
|
|
|
import com.sckw.freight.model.enums.*;
|
|
|
+import com.sckw.freight.model.po.LedgerLogisticsStatistics;
|
|
|
import com.sckw.freight.model.vo.request.RequestLedgerLogisticsPageInfo;
|
|
|
import com.sckw.freight.model.vo.request.RequestSaveLedgerLogisticsInfo;
|
|
|
import com.sckw.freight.model.vo.response.ResponseKllOrderTask;
|
|
|
import com.sckw.freight.model.vo.response.ResponseLedgerLogistics;
|
|
|
+import com.sckw.freight.model.vo.response.ResponseLedgerLogisticsStatistics;
|
|
|
import com.sckw.freight.model.vo.response.ResponsePageData;
|
|
|
import com.sckw.freight.service.freight.IKwpLedgerLogisticsOrderService;
|
|
|
import com.sckw.freight.service.freight.IKwpLedgerLogisticsService;
|
|
|
@@ -28,7 +30,6 @@ import com.sckw.freight.util.SnowflakeIdUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
@@ -60,6 +61,32 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
@Autowired
|
|
|
KllOrderTaskMapper kllOrderTaskMapper;
|
|
|
|
|
|
+ /**
|
|
|
+ * @description: 物流对账统计信息
|
|
|
+ * @author: xj
|
|
|
+ * @date: 2025/1/13 星期一 15:43
|
|
|
+ * @param: entId 企业id
|
|
|
+ * @return: null
|
|
|
+ **/
|
|
|
+ @Override
|
|
|
+ public R<ResponseLedgerLogisticsStatistics> queryLedgerLogisticsStatistics(Long entId) {
|
|
|
+
|
|
|
+ List<LedgerLogisticsStatistics> statistics = kwpLedgerLogisticsMapper.queryLedgerLogisticsStatistics(entId);
|
|
|
+ if (statistics == null) {
|
|
|
+ statistics = new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ ResponseLedgerLogisticsStatistics responseLedgerLogisticsStatistics = new ResponseLedgerLogisticsStatistics();
|
|
|
+ responseLedgerLogisticsStatistics.setAllTotal(statistics.stream().mapToLong(LedgerLogisticsStatistics::getCount).sum());
|
|
|
+ responseLedgerLogisticsStatistics.setUnpaidTotal(statistics.stream().filter(item -> item.getStatus() == KwpLedgerLogisticsStatusEnum.Unpaid.getCode())
|
|
|
+ .mapToLong(LedgerLogisticsStatistics::getCount).sum());
|
|
|
+ responseLedgerLogisticsStatistics.setPartialPaidTotal(statistics.stream().filter(item -> item.getStatus() == KwpLedgerLogisticsStatusEnum.PartialPaid.getCode())
|
|
|
+ .mapToLong(LedgerLogisticsStatistics::getCount).sum());
|
|
|
+ responseLedgerLogisticsStatistics.setPaidTotal(statistics.stream().filter(item -> item.getStatus() == KwpLedgerLogisticsStatusEnum.Paid.getCode())
|
|
|
+ .mapToLong(LedgerLogisticsStatistics::getCount).sum());
|
|
|
+ return R.ok(responseLedgerLogisticsStatistics);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* @description:更改物流对账单状态(每一次收款后调用)
|
|
|
@@ -81,7 +108,7 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
|
|
|
LambdaQueryWrapper<KwpSettlementLogistics> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(KwpSettlementLogistics::getLLedgerId, ledgerLogistics.getId());
|
|
|
- wrapper.eq(KwpSettlementLogistics::getStatus, SettlementLogisticsStatusEnum.FullSettlement.getCode());
|
|
|
+ wrapper.eq(KwpSettlementLogistics::getStatus, KwpSettlementLogisticsStatusEnum.FullSettlement.getCode());
|
|
|
List<KwpSettlementLogistics> kwpSettlementLogistics = kwpSettlementLogisticsMapper.selectList(wrapper);
|
|
|
if (kwpSettlementLogistics == null) kwpSettlementLogistics = new ArrayList<>();
|
|
|
BigDecimal totalPrice = kwpSettlementLogistics.stream().map(KwpSettlementLogistics::getActualPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
@@ -104,6 +131,7 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 根骨对账单id查询运单
|
|
|
*
|
|
|
@@ -124,11 +152,14 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
wrapper.eq(KwpLedgerLogistics::getEntId, entId);
|
|
|
List<KwpLedgerLogistics> records = kwpLedgerLogisticsMapper.selectList(wrapper);
|
|
|
if (records == null) records = new ArrayList<>();
|
|
|
+ if (records.size() == 0)
|
|
|
+ return R.failed("企业id【entId=" + entId + "】物流对账单[ledgerLogisticsId=" + ledgerLogisticsId + "]不存在");
|
|
|
//查对账单 下的订单
|
|
|
LambdaQueryWrapper<KwpLedgerLogisticsOrder> wrapper1 = new LambdaQueryWrapper<>();
|
|
|
wrapper1.in(KwpLedgerLogisticsOrder::getLLedgerId, records.stream().map(KwpLedgerLogistics::getId).collect(Collectors.toList()));
|
|
|
List<KwpLedgerLogisticsOrder> orders = iKwpLedgerLogisticsOrderService.list(wrapper1);
|
|
|
if (orders == null) orders = new ArrayList<>();
|
|
|
+ if (orders.size() == 0) return R.failed("物流对账单[ledgerLogisticsId=" + ledgerLogisticsId + "]下没有运单");
|
|
|
|
|
|
//查询运单
|
|
|
LambdaQueryWrapper<KllOrderTask> wrapperOrderTask = new LambdaQueryWrapper<>();
|
|
|
@@ -140,7 +171,7 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
//组装数据
|
|
|
List<ResponseKllOrderTask> responseKllOrderTasks = tasks.stream().map(task -> {
|
|
|
ResponseKllOrderTask orderTask = new ResponseKllOrderTask();
|
|
|
- orderTask.setId(task.getId().intValue());
|
|
|
+ orderTask.setId(task.getId().toString());
|
|
|
orderTask.setTaskNo(task.getTaskNo());
|
|
|
orderTask.setOrderId(task.getOrderId().intValue());
|
|
|
//orderTask.setLogisticId(task.getLogisticId().intValue());
|
|
|
@@ -206,7 +237,7 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
List<ResponseLedgerLogistics> responseLedgerLogisticsList = records.stream().map(item -> {
|
|
|
|
|
|
ResponseLedgerLogistics responseLedgerLogistics = new ResponseLedgerLogistics();
|
|
|
- responseLedgerLogistics.setId(item.getId());
|
|
|
+ responseLedgerLogistics.setId(item.getId().toString());
|
|
|
responseLedgerLogistics.setLLedgerNo(item.getLLedgerNo());
|
|
|
responseLedgerLogistics.setName(item.getName());
|
|
|
responseLedgerLogistics.setStatusName(KwpLedgerLogisticsStatusEnum.getMsg(item.getStatus()));
|
|
|
@@ -239,7 +270,7 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
* @since 2025-01-09
|
|
|
*/
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
+ //@Transactional
|
|
|
public R<String> saveLedgerLogistics(RequestSaveLedgerLogisticsInfo requestSaveLedgerSettlementInfo) {
|
|
|
/**
|
|
|
* 1:数据验证
|
|
|
@@ -272,13 +303,13 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
*/
|
|
|
private List<KllOrder> verifySaveLedgerLogisticsInfo(RequestSaveLedgerLogisticsInfo requestSaveLedgerSettlementInfo) {
|
|
|
if (requestSaveLedgerSettlementInfo == null) {
|
|
|
- throw new RuntimeException("保存对账单参数为空");
|
|
|
+ throw new RuntimeException("对账单参数为空");
|
|
|
}
|
|
|
- if (requestSaveLedgerSettlementInfo.getOrderIds() == null || requestSaveLedgerSettlementInfo.getOrderIds().size() == 0) {
|
|
|
- throw new RuntimeException("保存对账单的订单为空");
|
|
|
+ if (requestSaveLedgerSettlementInfo.getOrderIds() == null || requestSaveLedgerSettlementInfo.getOrderIds().isEmpty()) {
|
|
|
+ throw new RuntimeException("对账单的订单为空");
|
|
|
}
|
|
|
if (requestSaveLedgerSettlementInfo.getEntId() == null) {
|
|
|
- throw new RuntimeException("保存对账单的企业id为空");
|
|
|
+ throw new RuntimeException("对账单的企业id为空");
|
|
|
}
|
|
|
if (requestSaveLedgerSettlementInfo.getName() == null) {
|
|
|
throw new RuntimeException("保存对账单的名称为空");
|
|
|
@@ -293,17 +324,15 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
//验证对应的订单是否在该企业下 ,且状态是完结
|
|
|
LambdaQueryWrapper<KllOrder> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.in(KllOrder::getId, requestSaveLedgerSettlementInfo.getOrderIds());
|
|
|
- wrapper.eq(KllOrder::getCompanyId, requestSaveLedgerSettlementInfo.getEntId());
|
|
|
- //wrapper.eq(KllOrder::getStatus, OrderStatusEnum.SAVED);
|
|
|
- wrapper.eq(KllOrder::getStatus, OrderExecutionStatusEnum.ExecutionSuccess.getCode());
|
|
|
+ //wrapper.eq(KllOrder::getCompanyId, requestSaveLedgerSettlementInfo.getEntId());
|
|
|
+ wrapper.eq(KllOrder::getExecutionStatus, KllOrderExecutionStatusEnum.Finished.getCode());
|
|
|
+ wrapper.eq(KllOrder::getLedgerStatus, KllOrderLedgerStatusEnum.NoLedger.getCode());
|
|
|
List<KllOrder> list = iKllOrderService.list(wrapper);
|
|
|
- if (list == null || list.size() == 0 || list.size() != requestSaveLedgerSettlementInfo.getOrderIds().size()) {
|
|
|
- if (list.size() == 0) {
|
|
|
- throw new RuntimeException("保存对账单的物流订单不存在,请检查物流单所属企业和状态。");
|
|
|
- }
|
|
|
- if (list.size() != requestSaveLedgerSettlementInfo.getOrderIds().size()) {
|
|
|
- throw new RuntimeException("保存对账单的物流订单数量和参数数量不一致,请检查物流单所属企业和状态。");
|
|
|
- }
|
|
|
+ if (list == null || list.isEmpty()) {
|
|
|
+ throw new RuntimeException("保存对账单的物流订单不存在,请检查物流单状态。");
|
|
|
+ }
|
|
|
+ if (list.size() != requestSaveLedgerSettlementInfo.getOrderIds().size()) {
|
|
|
+ throw new RuntimeException("保存对账单的物流订单数量和参数数量不一致,请检查物流单所属企业和状态。");
|
|
|
}
|
|
|
//扣减金额不能大于 总金额
|
|
|
if (requestSaveLedgerSettlementInfo.getDeductPrice().compareTo(list.stream().map(KllOrder::getTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add)) > 0) {
|
|
|
@@ -344,6 +373,7 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
kwpLedgerLogistics.setUpdateTime(LocalDateTime.now());
|
|
|
kwpLedgerLogistics.setDelFlag(DelFlagEnum.NotDelete.getCode());
|
|
|
kwpLedgerLogistics.setId(SnowflakeIdUtil.getInstance().nextId());
|
|
|
+ kwpLedgerLogistics.setCompanyId(Long.valueOf(orderList.get(0).getCompanyId()));
|
|
|
boolean isSave = this.save(kwpLedgerLogistics);
|
|
|
if (isSave) return kwpLedgerLogistics;
|
|
|
throw new RuntimeException("保存对账单失败");
|
|
|
@@ -370,7 +400,7 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
kwpLedgerLogisticsOrder.setUpdateBy(kwpLedgerLogistics.getUpdateBy());
|
|
|
kwpLedgerLogisticsOrder.setCreateTime(kwpLedgerLogistics.getCreateTime());
|
|
|
kwpLedgerLogisticsOrder.setUpdateTime(kwpLedgerLogistics.getUpdateTime());
|
|
|
- kwpLedgerLogisticsOrder.setStatus(LedgerLogisticsOrderStatusEnum.Normal.getCode());
|
|
|
+ kwpLedgerLogisticsOrder.setStatus(KwpLedgerLogisticsOrderStatusEnum.Normal.getCode());
|
|
|
kwpLedgerLogisticsOrder.setDelFlag(DelFlagEnum.NotDelete.getCode());
|
|
|
kwpLedgerLogisticsOrder.setLOrderNo(order.getOrderNo());
|
|
|
return kwpLedgerLogisticsOrder;
|
|
|
@@ -413,7 +443,7 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
*/
|
|
|
private void updateKllOrderStatus(List<KllOrder> orderList) {
|
|
|
KllOrder newOrder = new KllOrder();
|
|
|
- newOrder.setExecutionStatus(OrderExecutionStatusEnum.Settlement.getCode());
|
|
|
+ newOrder.setLedgerStatus(KllOrderLedgerStatusEnum.Ledgered.getCode());
|
|
|
newOrder.setUpdateTime(LocalDateTime.now());
|
|
|
boolean isUpdate = iKllOrderService.update(newOrder, new LambdaQueryWrapper<KllOrder>().in(KllOrder::getId, orderList.stream().map(KllOrder::getId).collect(Collectors.toList())));
|
|
|
if (!isUpdate) throw new RuntimeException("更新物流订单状态失败");
|