优化
This commit is contained in:
@@ -84,7 +84,7 @@ public class ContainerFeeDetailService {
|
||||
SaveRequest common = request.fee();
|
||||
FeeItemEntity item = requireItem(common.feeItemId(), common.direction());
|
||||
BigDecimal total = common.amount().setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal allocated = request.allocations().stream().map(Allocation::amount)
|
||||
BigDecimal allocated = request.allocations().stream().map(value -> allocationAmount(value.amount()))
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
|
||||
if (allocated.compareTo(total) != 0) throw conflict("柜级费用分摊合计必须等于费用总额");
|
||||
Map<InboundAllocationKey, Long> ownership = new HashMap<>();
|
||||
@@ -158,7 +158,7 @@ public class ContainerFeeDetailService {
|
||||
throw conflict("只有完整的当前已审核分摊组可以调整");
|
||||
Map<Long, BigDecimal> amounts = new HashMap<>();
|
||||
for (AllocationAmount allocation : request.allocations()) {
|
||||
if (amounts.put(allocation.feeId(), allocation.amount().setScale(2, RoundingMode.HALF_UP)) != null)
|
||||
if (amounts.put(allocation.feeId(), allocationAmount(allocation.amount())) != null)
|
||||
throw conflict("分摊费用行不得重复");
|
||||
}
|
||||
if (!amounts.keySet().equals(rows.stream().map(ContainerFeeDetailEntity::getId).collect(java.util.stream.Collectors.toSet())))
|
||||
@@ -372,6 +372,12 @@ public class ContainerFeeDetailService {
|
||||
return new BizException(ResultCode.CONFLICT, message);
|
||||
}
|
||||
|
||||
private static BigDecimal allocationAmount(BigDecimal amount) {
|
||||
BigDecimal rounded = amount.setScale(2, RoundingMode.HALF_UP);
|
||||
if (rounded.signum() <= 0) throw conflict("分摊金额按两位小数取整后必须大于0");
|
||||
return rounded;
|
||||
}
|
||||
|
||||
private static long containerBookingId(ContainerFeeDetailEntity value) {
|
||||
if (value.getContainerBookingId() == null || value.getContainerBookingId() <= 0) {
|
||||
throw conflict("柜次费用缺少真实货柜关联");
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ public final class TerminalDrayageDtos {
|
||||
|
||||
public record ActualTimeRequest(@NotNull @Min(0) Integer expectedVersion,
|
||||
@NotNull LocalDateTime actualAt,
|
||||
@Size(max = 500) String reason) {}
|
||||
@Size(max = 500) String remark) {}
|
||||
|
||||
public record Warning(String status, LocalDateTime deadlineAt,
|
||||
long overdueHours, long overdueDays) {}
|
||||
|
||||
+4
-4
@@ -147,14 +147,14 @@ public class TerminalDrayageService {
|
||||
throw badRequest("实际提柜时间不能早于当前实际船节点时间");
|
||||
}
|
||||
advanceNode(context, CarrierScheduleNode.PICKED_UP, request.actualAt(), action, key,
|
||||
request.reason(), operatorId, operatorName);
|
||||
request.remark(), operatorId, operatorName);
|
||||
int fromVersion = version(value);
|
||||
String fromStatus = status(context, value);
|
||||
value.setActualPickupAt(request.actualAt());
|
||||
applyAuthoritativeDeadline(context, value);
|
||||
persist(value, fromVersion, operatorId, operatorName);
|
||||
return finish(requiredContext(containerBookingId), value, action, key, request, fromStatus,
|
||||
fromVersion, request.reason(), operatorId, operatorName);
|
||||
fromVersion, request.remark(), operatorId, operatorName);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -174,14 +174,14 @@ public class TerminalDrayageService {
|
||||
if (request.actualAt().isBefore(earliest)) throw badRequest("实际还柜时间不能早于提柜或卸柜完成时间");
|
||||
if (actualEmptyReturnAt(context, value) != null) throw conflict("实际还柜时间已确认");
|
||||
advanceNode(context, CarrierScheduleNode.EMPTY_RETURNED, request.actualAt(), action, key,
|
||||
request.reason(), operatorId, operatorName);
|
||||
request.remark(), operatorId, operatorName);
|
||||
int fromVersion = version(value);
|
||||
String fromStatus = status(context, value);
|
||||
applyAuthoritativeDeadline(context, value);
|
||||
value.setActualEmptyReturnAt(request.actualAt());
|
||||
persist(value, fromVersion, operatorId, operatorName);
|
||||
return finish(requiredContext(containerBookingId), value, action, key, request, fromStatus,
|
||||
fromVersion, request.reason(), operatorId, operatorName);
|
||||
fromVersion, request.remark(), operatorId, operatorName);
|
||||
}
|
||||
|
||||
private void advanceNode(WorkContext context, CarrierScheduleNode target, LocalDateTime actualAt,
|
||||
|
||||
Reference in New Issue
Block a user