修复成本问题

This commit is contained in:
2026-01-27 16:54:46 +08:00
parent bfe8750b86
commit a1f8b0c60b
9 changed files with 268 additions and 205 deletions

View File

@@ -573,6 +573,95 @@ public class WmsCostCoilDailyServiceImpl implements IWmsCostCoilDailyService {
return result;
}
/**
* 按当前钢卷号维度计算成本(单卷详情)
*/
@Override
public Map<String, Object> calculateCostByCurrentCoilNo(String currentCoilNo, LocalDate calcDate) {
Map<String, Object> result = new HashMap<>();
result.put("currentCoilNo", currentCoilNo);
if (calcDate == null) {
calcDate = LocalDate.now();
}
// 查询单个钢卷
QueryWrapper<WmsMaterialCoil> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("current_coil_no", currentCoilNo)
.eq("data_type", 1)
.eq("del_flag", 0);
WmsMaterialCoil coil = coilMapper.selectOne(queryWrapper);
if (coil == null) {
result.put("error", "未找到当前钢卷号 " + currentCoilNo + " 的相关钢卷");
return result;
}
// 计算在库天数
LocalDate startDate = coil.getCreateTime() != null
? coil.getCreateTime().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate()
: LocalDate.now();
LocalDate endDate;
if (coil.getExportTime() != null) {
endDate = coil.getExportTime().toInstant()
.atZone(java.time.ZoneId.systemDefault())
.toLocalDate()
.minusDays(1);
} else {
endDate = calcDate;
}
if (endDate.isBefore(startDate)) {
endDate = startDate;
}
long days = ChronoUnit.DAYS.between(startDate, endDate) + 1;
if (days < 1) {
days = 1;
}
// 成本标准
WmsCostStandardConfigVo costStandard = costStandardConfigService.queryEffectiveByDate(startDate);
if (costStandard == null) {
costStandard = costStandardConfigService.queryCurrentEffective();
}
if (costStandard == null || costStandard.getUnitCost() == null) {
result.put("error", "未找到有效的成本标准配置");
return result;
}
BigDecimal unitCost = costStandard.getUnitCost();
// 重量与成本基础
WeightContext weightContext = resolveWeightContext(coil);
if (!weightContext.isValid()) {
result.put("error", "钢卷缺少有效重量,无法计算");
return result;
}
BigDecimal dailyCost = weightContext.getCostTon().multiply(unitCost).setScale(2, RoundingMode.HALF_UP);
BigDecimal totalCost = dailyCost.multiply(BigDecimal.valueOf(days)).setScale(2, RoundingMode.HALF_UP);
result.put("coilId", coil.getCoilId());
result.put("currentCoilNo", coil.getCurrentCoilNo());
result.put("isShipped", coil.getExportTime() != null);
result.put("netWeightTon", weightContext.getNetTon());
result.put("grossWeightTon", weightContext.getGrossTon());
result.put("weightBasis", weightContext.useGross() ? "gross" : "net");
result.put("storageDays", days);
result.put("unitCost", unitCost);
result.put("dailyCost", dailyCost);
result.put("totalCost", totalCost);
result.put("startDate", startDate);
result.put("endDate", endDate);
result.put("exportTime", coil.getExportTime());
result.put("calcDate", calcDate);
return result;
}
/**
* 批量按入场钢卷号维度计算成本(定时任务使用)
*/