|
|
@@ -10,10 +10,13 @@ import com.sckw.freight.entity.freight.KwpSettlementLogistics;
|
|
|
import com.sckw.freight.entity.kll.KllOrder;
|
|
|
import com.sckw.freight.entity.kll.KllOrderTask;
|
|
|
import com.sckw.freight.entity.saas.SaasCompany;
|
|
|
+import com.sckw.freight.entity.saas.SaasLogisticCustomer;
|
|
|
import com.sckw.freight.mapper.freight.KwpLedgerLogisticsMapper;
|
|
|
import com.sckw.freight.mapper.freight.KwpSettlementLogisticsMapper;
|
|
|
+import com.sckw.freight.mapper.kll.KllOrderMapper;
|
|
|
import com.sckw.freight.mapper.kll.KllOrderTaskMapper;
|
|
|
import com.sckw.freight.mapper.saas.SaasCompanyMapper;
|
|
|
+import com.sckw.freight.mapper.saas.SaasLogisticCustomerMapper;
|
|
|
import com.sckw.freight.model.dto.PayIndex;
|
|
|
import com.sckw.freight.model.enums.*;
|
|
|
import com.sckw.freight.model.po.LedgerLogisticsStatistics;
|
|
|
@@ -76,6 +79,10 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
//@Lazy
|
|
|
@Autowired
|
|
|
IKwpSettlementLogisticsService iKwpSettlementLogisticsService;
|
|
|
+ @Autowired
|
|
|
+ KllOrderMapper kllOrderMapper;
|
|
|
+ @Autowired
|
|
|
+ SaasLogisticCustomerMapper saasLogisticCustomerMapper;
|
|
|
|
|
|
/**
|
|
|
* @description: 物流对账统计信息
|
|
|
@@ -85,7 +92,7 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
* @return: null
|
|
|
**/
|
|
|
@Override
|
|
|
- public R<ResponseLedgerLogisticsStatistics> queryLedgerLogisticsStatistics(Long entId) {
|
|
|
+ public R<ResponseLedgerLogisticsStatistics> queryLedgerLogisticsStatistics(String entId) {
|
|
|
|
|
|
List<LedgerLogisticsStatistics> statistics = kwpLedgerLogisticsMapper.queryLedgerLogisticsStatistics(entId);
|
|
|
if (statistics == null) {
|
|
|
@@ -181,7 +188,7 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
//查询运单
|
|
|
LambdaQueryWrapper<KllOrderTask> wrapperOrderTask = new LambdaQueryWrapper<>();
|
|
|
wrapperOrderTask.in(KllOrderTask::getOrderId, orders.stream().map(order -> {
|
|
|
- return order.getId().intValue();
|
|
|
+ return order.getLOrderId().intValue();
|
|
|
}).collect(Collectors.toList()));
|
|
|
|
|
|
List<KllOrderTask> tasks = kllOrderTaskMapper.selectList(wrapperOrderTask);
|
|
|
@@ -198,6 +205,10 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
orderTask.setDriverPhone(task.getDriverPhone());
|
|
|
orderTask.setFirstWeight(task.getFirstWeight());
|
|
|
orderTask.setSecondWeight(task.getSecondWeight());
|
|
|
+
|
|
|
+// orderTask.setFirstWeightTime(task.getFirstWeightTime());
|
|
|
+// orderTask.setSecondWeightTime(task.getSecondWeightTime());
|
|
|
+// orderTask.setOrderNo(task.getOrderNo());
|
|
|
return orderTask;
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
@@ -238,8 +249,10 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
wrapper.ge(KwpLedgerLogistics::getUpdateTime, requestPageInfo.getUpdateTime()[0]);
|
|
|
wrapper.le(KwpLedgerLogistics::getUpdateTime, requestPageInfo.getUpdateTime()[1]);
|
|
|
}
|
|
|
+ if (requestPageInfo.getEntId() != null) {
|
|
|
+ wrapper.eq(KwpLedgerLogistics::getEntId, requestPageInfo.getEntId());
|
|
|
+ }
|
|
|
wrapper.eq(KwpLedgerLogistics::getDelFlag, 0);
|
|
|
- wrapper.eq(KwpLedgerLogistics::getEntId, requestPageInfo.getEntId());
|
|
|
wrapper.orderByDesc(KwpLedgerLogistics::getCreateTime);
|
|
|
|
|
|
// 创建分页对象
|
|
|
@@ -261,7 +274,7 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
responseLedgerLogistics.setTotalPrice(item.getTotalPrice());
|
|
|
responseLedgerLogistics.setRemark(item.getRemark());
|
|
|
responseLedgerLogistics.setActualPrice(item.getActualPrice());
|
|
|
- responseLedgerLogistics.setPayRatio(item.getActualPrice().divide(item.getTotalPrice(), 2).toString() + "%");
|
|
|
+ responseLedgerLogistics.setPayRatio((item.getTotalPrice().compareTo(BigDecimal.ZERO) == 0 ? "100" : item.getActualPrice().divide(item.getTotalPrice(), 2).toString()) + "%");
|
|
|
responseLedgerLogistics.setCreateTime(DateTimeUtil.format(item.getCreateTime(), "YYYY-MM-dd HH:mm:ss"));
|
|
|
responseLedgerLogistics.setUpdateTime(DateTimeUtil.format(item.getUpdateTime(), "YYYY-MM-dd HH:mm:ss"));
|
|
|
responseLedgerLogistics.setStatus(item.getStatus());
|
|
|
@@ -341,30 +354,40 @@ 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::getExecutionStatus, KllOrderExecutionStatusEnum.Finished.getCode());
|
|
|
+ wrapper.eq(KllOrder::getCompanyId, requestSaveLedgerSettlementInfo.getEntId());
|
|
|
+// List<Integer> statuList=new ArrayList<>();
|
|
|
+// statuList.add(KllOrderStatusEnum.Finished.getCode());
|
|
|
+// statuList.add(KllOrderStatusEnum.Pending.getCode());
|
|
|
+ wrapper.in(KllOrder::getExecutionStatus, 1);
|
|
|
+ wrapper.in(KllOrder::getStatus, 1);
|
|
|
wrapper.eq(KllOrder::getLedgerStatus, KllOrderLedgerStatusEnum.NoLedger.getCode());
|
|
|
List<KllOrder> list = iKllOrderService.list(wrapper);
|
|
|
|
|
|
|
|
|
+ //运单总额 = sum(单价*二次称重)
|
|
|
+ BigDecimal totalPrice = kllOrderMapper.getOrderTotalPrice(requestSaveLedgerSettlementInfo.getOrderIds(), requestSaveLedgerSettlementInfo.getEntId());
|
|
|
+
|
|
|
+
|
|
|
if (list == null || list.isEmpty()) {
|
|
|
throw new RuntimeException("物流订单不存在或状态为已对账。");
|
|
|
}
|
|
|
if (list.size() != requestSaveLedgerSettlementInfo.getOrderIds().size()) {
|
|
|
throw new RuntimeException("保存对账单的物流订单数量和参数数量不一致,请检查物流单所属企业和状态。");
|
|
|
}
|
|
|
+ //不能同时对个客户企业对账
|
|
|
Map<Integer, List<KllOrder>> ageGroup = list.stream()
|
|
|
- .collect(Collectors.groupingBy(KllOrder::getCompanyId));
|
|
|
+ .collect(Collectors.groupingBy(KllOrder::getCustomerId));
|
|
|
if (ageGroup.size() != 1) {
|
|
|
- throw new RuntimeException("保存对账单的物流订单企业id不一致,请检查物流单所属企业。");
|
|
|
+ throw new RuntimeException("保存对账单的物流订单客户id不一致,请检查物流单所属客户企业。");
|
|
|
}
|
|
|
//扣减金额不能大于 总金额
|
|
|
- if (requestSaveLedgerSettlementInfo.getDeductPrice().compareTo(list.stream().map(KllOrder::getTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add)) > 0) {
|
|
|
+ if (requestSaveLedgerSettlementInfo.getDeductPrice().compareTo(totalPrice) > 0) {
|
|
|
throw new RuntimeException("保存对账单的物流订单扣减金额不能大于 总金额");
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 保存对账单
|
|
|
*
|
|
|
@@ -379,8 +402,9 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
|
|
|
kwpLedgerLogistics.setEntId(requestSaveLedgerSettlementInfo.getEntId());
|
|
|
kwpLedgerLogistics.setDeductPrice(requestSaveLedgerSettlementInfo.getDeductPrice());
|
|
|
kwpLedgerLogistics.setOrderCount(orderList.size());
|
|
|
- //运单总额 = 总应收
|
|
|
- kwpLedgerLogistics.setTotalPrice(orderList.stream().map(KllOrder::getTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ BigDecimal totalPrice = kllOrderMapper.getOrderTotalPrice(requestSaveLedgerSettlementInfo.getOrderIds(), requestSaveLedgerSettlementInfo.getEntId());
|
|
|
+
|
|
|
+ kwpLedgerLogistics.setTotalPrice(totalPrice);
|
|
|
//不含税金额 = 总应收
|
|
|
kwpLedgerLogistics.setExTaxPrice(kwpLedgerLogistics.getTotalPrice());
|
|
|
//账单结算金额 = 总应收 - 款金额
|
|
|
@@ -397,7 +421,10 @@ 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()));
|
|
|
+ //客户企业id 从saas 的关系里面找
|
|
|
+ SaasLogisticCustomer customer = saasLogisticCustomerMapper.selectById(orderList.get(0).getCustomerId());
|
|
|
+
|
|
|
+ kwpLedgerLogistics.setCompanyId(Long.valueOf(customer.getCompanyId()));
|
|
|
boolean isSave = this.save(kwpLedgerLogistics);
|
|
|
if (isSave) return kwpLedgerLogistics;
|
|
|
throw new RuntimeException("保存对账单失败");
|