This commit is contained in:
2026-08-28 18:05:08 +08:00
parent a029463f82
commit a2b604f3a3
5 changed files with 62 additions and 19 deletions
@@ -57,8 +57,8 @@ public class LoadingManageController extends BladeController {
@GetMapping("/carrier-contracts") @GetMapping("/carrier-contracts")
@ApiOperationSupport(order = 13) @ApiOperationSupport(order = 13)
@Operation(summary = "可选承运商合同", description = "查询已审核生效的承运商合同") @Operation(summary = "可选承运商合同", description = "查询已审核生效的承运商合同")
public R<List<LoadingCarrierContractVO>> carrierContracts() { public R<List<LoadingCarrierContractVO>> carrierContracts(@RequestParam List<Long> projectIds) {
return R.data(loadingManageService.carrierContracts()); return R.data(loadingManageService.carrierContracts(projectIds));
} }
@GetMapping("/list") @GetMapping("/list")
@@ -25,7 +25,7 @@ public interface ILoadingManageService extends BaseService<LoadingManage> {
LoadingManageVO detail(Long id); LoadingManageVO detail(Long id);
List<LoadingCarrierContractVO> carrierContracts(); List<LoadingCarrierContractVO> carrierContracts(List<Long> projectIds);
boolean saveDraft(LoadingManage loadingManage); boolean saveDraft(LoadingManage loadingManage);
@@ -85,8 +85,11 @@ public class LoadingManageServiceImpl extends BaseServiceImpl<LoadingManageMappe
} }
@Override @Override
public List<LoadingCarrierContractVO> carrierContracts() { public List<LoadingCarrierContractVO> carrierContracts(List<Long> projectIds) {
return availableCarrierContracts().stream().map(contract -> { if (Func.isEmpty(projectIds)) {
return List.of();
}
return availableCarrierContracts(projectIds).stream().map(contract -> {
LoadingCarrierContractVO option = new LoadingCarrierContractVO(); LoadingCarrierContractVO option = new LoadingCarrierContractVO();
option.setId(contract.getId()); option.setId(contract.getId());
option.setContractName(contract.getContractName()); option.setContractName(contract.getContractName());
@@ -289,7 +292,7 @@ public class LoadingManageServiceImpl extends BaseServiceImpl<LoadingManageMappe
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean complete(Long id) { public boolean complete(Long id) {
LoadingManage loadingManage = loadEditable(id, true); LoadingManage loadingManage = loadEditable(id, true);
validateCompletedCarrierContract(loadingManage); validateCarrierContract(loadingManage, true);
if (!Objects.equals(loadingManage.getBusinessStatus(), STATUS_RUNNING) if (!Objects.equals(loadingManage.getBusinessStatus(), STATUS_RUNNING)
&& !Objects.equals(loadingManage.getBusinessStatus(), STATUS_PENDING)) { && !Objects.equals(loadingManage.getBusinessStatus(), STATUS_PENDING)) {
throw new ServiceException("仅待执行或进行中状态允许完成"); throw new ServiceException("仅待执行或进行中状态允许完成");
@@ -321,7 +324,7 @@ public class LoadingManageServiceImpl extends BaseServiceImpl<LoadingManageMappe
|| Objects.equals(loadingManage.getBusinessStatus(), STATUS_DRAFT)) { || Objects.equals(loadingManage.getBusinessStatus(), STATUS_DRAFT)) {
return false; return false;
} }
validateCompletedCarrierContract(loadingManage); validateCarrierContract(loadingManage, true);
List<Long> waybillIdList = waybillIds(loadingManage.getWaybillIdsJson()); List<Long> waybillIdList = waybillIds(loadingManage.getWaybillIdsJson());
if (Func.isEmpty(waybillIdList)) { if (Func.isEmpty(waybillIdList)) {
return false; return false;
@@ -496,7 +499,7 @@ public class LoadingManageServiceImpl extends BaseServiceImpl<LoadingManageMappe
TransportBusinessSupport.validateRequired(loadingManage.getVehicleNo(), "车/船/航班/班列不能为空"); TransportBusinessSupport.validateRequired(loadingManage.getVehicleNo(), "车/船/航班/班列不能为空");
TransportBusinessSupport.validateRequired(loadingManage.getDepartureAddress(), "发货地不能为空"); TransportBusinessSupport.validateRequired(loadingManage.getDepartureAddress(), "发货地不能为空");
TransportBusinessSupport.validateRequired(loadingManage.getArrivalAddress(), "到货地不能为空"); TransportBusinessSupport.validateRequired(loadingManage.getArrivalAddress(), "到货地不能为空");
if (!Objects.equals(loadingManage.getCarrierType(), CARRIER_SELF) if (Objects.equals(loadingManage.getCarrierType(), "承运商")
&& Func.isEmpty(loadingManage.getCarrierContractId())) { && Func.isEmpty(loadingManage.getCarrierContractId())) {
throw new ServiceException("请选择承运商合同"); throw new ServiceException("请选择承运商合同");
} }
@@ -579,7 +582,7 @@ public class LoadingManageServiceImpl extends BaseServiceImpl<LoadingManageMappe
} }
private void validateCarrierContract(LoadingManage loadingManage, boolean required) { private void validateCarrierContract(LoadingManage loadingManage, boolean required) {
if (Objects.equals(loadingManage.getCarrierType(), CARRIER_SELF)) { if (!Objects.equals(loadingManage.getCarrierType(), "承运商")) {
loadingManage.setCarrierContractId(null); loadingManage.setCarrierContractId(null);
loadingManage.setCarrierName(null); loadingManage.setCarrierName(null);
return; return;
@@ -591,7 +594,7 @@ public class LoadingManageServiceImpl extends BaseServiceImpl<LoadingManageMappe
loadingManage.setCarrierName(null); loadingManage.setCarrierName(null);
return; return;
} }
ContractManage carrierContract = availableCarrierContracts().stream() ContractManage carrierContract = availableCarrierContracts(projectIdsByWaybills(loadingManage)).stream()
.filter(contract -> Objects.equals(contract.getId(), loadingManage.getCarrierContractId())) .filter(contract -> Objects.equals(contract.getId(), loadingManage.getCarrierContractId()))
.findFirst() .findFirst()
.orElseThrow(() -> new ServiceException("所选承运商合同不存在、未审核通过或已失效")); .orElseThrow(() -> new ServiceException("所选承运商合同不存在、未审核通过或已失效"));
@@ -599,7 +602,7 @@ public class LoadingManageServiceImpl extends BaseServiceImpl<LoadingManageMappe
} }
private void validateCompletedCarrierContract(LoadingManage loadingManage) { private void validateCompletedCarrierContract(LoadingManage loadingManage) {
if (Objects.equals(loadingManage.getCarrierType(), CARRIER_SELF)) { if (!Objects.equals(loadingManage.getCarrierType(), "承运商")) {
loadingManage.setCarrierContractId(null); loadingManage.setCarrierContractId(null);
loadingManage.setCarrierName(null); loadingManage.setCarrierName(null);
return; return;
@@ -609,11 +612,27 @@ public class LoadingManageServiceImpl extends BaseServiceImpl<LoadingManageMappe
} }
} }
private List<ContractManage> availableCarrierContracts() { private List<Long> projectIdsByWaybills(LoadingManage loadingManage) {
List<Long> waybillIds = waybillIds(loadingManage.getWaybillIdsJson());
if (Func.isEmpty(waybillIds)) {
return List.of();
}
return waybillMapper.selectList(Wrappers.<Waybill>lambdaQuery()
.select(Waybill::getProjectId)
.eq(Waybill::getIsDeleted, 0)
.in(Waybill::getId, waybillIds))
.stream().map(Waybill::getProjectId).filter(Objects::nonNull).distinct().toList();
}
private List<ContractManage> availableCarrierContracts(List<Long> projectIds) {
if (Func.isEmpty(projectIds)) {
return List.of();
}
return contractManageService.list(Wrappers.<ContractManage>lambdaQuery() return contractManageService.list(Wrappers.<ContractManage>lambdaQuery()
.eq(ContractManage::getIsDeleted, 0) .eq(ContractManage::getIsDeleted, 0)
.eq(ContractManage::getStatus, 1) .eq(ContractManage::getStatus, 1)
.eq(ContractManage::getContractCategory, "承运商合同") .eq(ContractManage::getContractCategory, "承运商合同")
.in(ContractManage::getProjectId, projectIds)
.in(ContractManage::getApprovalStatus, "approved", "change_approved") .in(ContractManage::getApprovalStatus, "approved", "change_approved")
.and(wrapper -> wrapper.isNull(ContractManage::getContractStage) .and(wrapper -> wrapper.isNull(ContractManage::getContractStage)
.or().ne(ContractManage::getContractStage, "terminated")) .or().ne(ContractManage::getContractStage, "terminated"))
@@ -400,8 +400,7 @@ public class MasterOrderServiceImpl extends BaseServiceImpl<MasterOrderMapper, M
if (!Objects.equals(masterOrder.getProjectId(), customerContract.getProjectId())) { if (!Objects.equals(masterOrder.getProjectId(), customerContract.getProjectId())) {
throw new ServiceException("总单项目与客户合同所属项目不一致"); throw new ServiceException("总单项目与客户合同所属项目不一致");
} }
Map<String, ContractManage> contractsByCarrier = new LinkedHashMap<>(); return contractManageService.list(new LambdaQueryWrapper<ContractManage>()
contractManageService.list(new LambdaQueryWrapper<ContractManage>()
.eq(ContractManage::getIsDeleted, 0) .eq(ContractManage::getIsDeleted, 0)
.eq(ContractManage::getProjectId, customerContract.getProjectId()) .eq(ContractManage::getProjectId, customerContract.getProjectId())
.eq(ContractManage::getContractCategory, "承运商合同") .eq(ContractManage::getContractCategory, "承运商合同")
@@ -409,21 +408,19 @@ public class MasterOrderServiceImpl extends BaseServiceImpl<MasterOrderMapper, M
.and(wrapper -> wrapper.isNull(ContractManage::getContractStage) .and(wrapper -> wrapper.isNull(ContractManage::getContractStage)
.or().ne(ContractManage::getContractStage, "terminated")) .or().ne(ContractManage::getContractStage, "terminated"))
.orderByDesc(ContractManage::getCreateTime)) .orderByDesc(ContractManage::getCreateTime))
.stream().filter(contract -> Func.isNotEmpty(contract.getPartyB())) .stream().filter(contract -> Func.isNotEmpty(contract.getPartyB())).toList();
.forEach(contract -> contractsByCarrier.putIfAbsent(contract.getPartyB(), contract));
return new ArrayList<>(contractsByCarrier.values());
} }
private void validateCarrier(Map<String, Object> dispatch, Map<Long, ContractManage> availableCarrierContracts) { private void validateCarrier(Map<String, Object> dispatch, Map<Long, ContractManage> availableCarrierContracts) {
String carrierType = string(dispatch, "carrierType", "承运商"); String carrierType = string(dispatch, "carrierType", "承运商");
if ("自运".equals(carrierType)) { if (!"承运商".equals(carrierType)) {
dispatch.remove("carrierContractId"); dispatch.remove("carrierContractId");
dispatch.remove("carrierName"); dispatch.remove("carrierName");
} }
String carrierName = string(dispatch, "carrierName"); String carrierName = string(dispatch, "carrierName");
Long carrierContractId = longValue(dispatch, "carrierContractId"); Long carrierContractId = longValue(dispatch, "carrierContractId");
ContractManage carrierContract = carrierContractId == null ? null : availableCarrierContracts.get(carrierContractId); ContractManage carrierContract = carrierContractId == null ? null : availableCarrierContracts.get(carrierContractId);
if (!"自运".equals(carrierType) && (carrierContract == null if ("承运商".equals(carrierType) && (carrierContract == null
|| !Objects.equals(carrierContract.getPartyB(), carrierName))) { || !Objects.equals(carrierContract.getPartyB(), carrierName))) {
throw new ServiceException("所选承运商不属于总单客户合同对应项目的有效承运商合同乙方"); throw new ServiceException("所选承运商不属于总单客户合同对应项目的有效承运商合同乙方");
} }
@@ -37,6 +37,7 @@ import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import org.springblade.transport.mapper.WaybillMapper; import org.springblade.transport.mapper.WaybillMapper;
import org.springblade.transport.pojo.entity.LoadingManage; import org.springblade.transport.pojo.entity.LoadingManage;
import org.springblade.transport.pojo.entity.ContractManage;
import org.springblade.transport.pojo.entity.ProcessConfig; import org.springblade.transport.pojo.entity.ProcessConfig;
import org.springblade.transport.pojo.entity.Waybill; import org.springblade.transport.pojo.entity.Waybill;
import org.springblade.transport.pojo.vo.BusinessRemoveResultVO; import org.springblade.transport.pojo.vo.BusinessRemoveResultVO;
@@ -45,6 +46,7 @@ import org.springblade.transport.pojo.vo.WaybillVO;
import org.springblade.transport.service.ILoadingManageService; import org.springblade.transport.service.ILoadingManageService;
import org.springblade.transport.service.IProcessConfigService; import org.springblade.transport.service.IProcessConfigService;
import org.springblade.transport.service.IReceivablePayableDetailService; import org.springblade.transport.service.IReceivablePayableDetailService;
import org.springblade.transport.service.IContractManageService;
import org.springblade.transport.service.IWaybillService; import org.springblade.transport.service.IWaybillService;
import org.springblade.transport.support.TransportBusinessSupport; import org.springblade.transport.support.TransportBusinessSupport;
import org.springblade.transport.wrapper.WaybillWrapper; import org.springblade.transport.wrapper.WaybillWrapper;
@@ -77,6 +79,9 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
@jakarta.annotation.Resource @jakarta.annotation.Resource
private IProcessConfigService processConfigService; private IProcessConfigService processConfigService;
@jakarta.annotation.Resource
private IContractManageService contractManageService;
@jakarta.annotation.Resource @jakarta.annotation.Resource
@org.springframework.context.annotation.Lazy @org.springframework.context.annotation.Lazy
private IReceivablePayableDetailService receivablePayableDetailService; private IReceivablePayableDetailService receivablePayableDetailService;
@@ -593,6 +598,7 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
} }
} }
TransportBusinessSupport.validateRequired(waybill.getCarrierJson(), "承运信息不能为空"); TransportBusinessSupport.validateRequired(waybill.getCarrierJson(), "承运信息不能为空");
validateCarrierContract(waybill);
if (Func.isEmpty(waybill.getQuantity())) { if (Func.isEmpty(waybill.getQuantity())) {
throw new ServiceException("数量不能为空"); throw new ServiceException("数量不能为空");
} }
@@ -664,6 +670,23 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
} }
} }
private void validateCarrierContract(Waybill waybill) {
if (!"承运商".equals(waybill.getCarrierType())) {
waybill.setCarrierContractId(null);
return;
}
if (Func.isEmpty(waybill.getCarrierContractId())) {
throw new ServiceException("请选择承运商合同");
}
ContractManage carrierContract = contractManageService.getById(waybill.getCarrierContractId());
if (carrierContract == null || Objects.equals(carrierContract.getIsDeleted(), 1)
|| !"承运商合同".equals(carrierContract.getContractCategory())
|| !Objects.equals(carrierContract.getProjectId(), waybill.getProjectId())
|| !Objects.equals(carrierContract.getPartyB(), waybill.getCarrierName())) {
throw new ServiceException("承运商合同必须属于所选项目,且合同乙方须与承运商一致");
}
}
private Waybill loadEditable(Long id, boolean checkDept) { private Waybill loadEditable(Long id, boolean checkDept) {
if (Func.isEmpty(id)) { if (Func.isEmpty(id)) {
throw new ServiceException("主键不能为空"); throw new ServiceException("主键不能为空");
@@ -746,6 +769,7 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
waybill.getCarrierType(), waybill.getCarrierType(),
waybill.getCarrierId(), waybill.getCarrierId(),
waybill.getCarrierName(), waybill.getCarrierName(),
waybill.getCarrierContractId(),
waybill.getDriverId(), waybill.getDriverId(),
waybill.getDriverName(), waybill.getDriverName(),
waybill.getDriverPhone(), waybill.getDriverPhone(),
@@ -762,6 +786,7 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
putIfNotEmpty(carrier, "carrierId", waybill.getCarrierId()); putIfNotEmpty(carrier, "carrierId", waybill.getCarrierId());
putIfNotEmpty(carrier, "carrier", waybill.getCarrierName()); putIfNotEmpty(carrier, "carrier", waybill.getCarrierName());
putIfNotEmpty(carrier, "carrierName", waybill.getCarrierName()); putIfNotEmpty(carrier, "carrierName", waybill.getCarrierName());
putIfNotEmpty(carrier, "carrierContractId", waybill.getCarrierContractId());
putIfNotEmpty(carrier, "driverId", waybill.getDriverId()); putIfNotEmpty(carrier, "driverId", waybill.getDriverId());
putIfNotEmpty(carrier, "driverName", waybill.getDriverName()); putIfNotEmpty(carrier, "driverName", waybill.getDriverName());
putIfNotEmpty(carrier, "driverPhone", waybill.getDriverPhone()); putIfNotEmpty(carrier, "driverPhone", waybill.getDriverPhone());
@@ -783,6 +808,7 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
waybill.getCarrierType(), waybill.getCarrierType(),
waybill.getCarrierId(), waybill.getCarrierId(),
waybill.getCarrierName(), waybill.getCarrierName(),
waybill.getCarrierContractId(),
waybill.getDriverId(), waybill.getDriverId(),
waybill.getDriverName(), waybill.getDriverName(),
waybill.getDriverPhone(), waybill.getDriverPhone(),
@@ -805,6 +831,7 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
putIfNotEmpty(taskInfo, "carrierType", waybill.getCarrierType()); putIfNotEmpty(taskInfo, "carrierType", waybill.getCarrierType());
putIfNotEmpty(taskInfo, "carrierId", waybill.getCarrierId()); putIfNotEmpty(taskInfo, "carrierId", waybill.getCarrierId());
putIfNotEmpty(taskInfo, "carrierName", waybill.getCarrierName()); putIfNotEmpty(taskInfo, "carrierName", waybill.getCarrierName());
putIfNotEmpty(taskInfo, "carrierContractId", waybill.getCarrierContractId());
putIfNotEmpty(taskInfo, "driverId", waybill.getDriverId()); putIfNotEmpty(taskInfo, "driverId", waybill.getDriverId());
putIfNotEmpty(taskInfo, "driverName", waybill.getDriverName()); putIfNotEmpty(taskInfo, "driverName", waybill.getDriverName());
putIfNotEmpty(taskInfo, "driverPhone", waybill.getDriverPhone()); putIfNotEmpty(taskInfo, "driverPhone", waybill.getDriverPhone());