修复成本问题
This commit is contained in:
@@ -204,6 +204,22 @@ public class WmsCostCoilDailyController extends BaseController {
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按当前钢卷号维度计算成本(单卷详情)
|
||||
*
|
||||
* @param currentCoilNo 当前钢卷号
|
||||
* @param calcDate 计算日期(可选,默认当前日期)
|
||||
*/
|
||||
@PostMapping("/calculateByCurrentCoilNo")
|
||||
public R<Map<String, Object>> calculateCostByCurrentCoilNo(@RequestParam String currentCoilNo,
|
||||
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate calcDate) {
|
||||
Map<String, Object> result = iWmsCostCoilDailyService.calculateCostByCurrentCoilNo(currentCoilNo, calcDate);
|
||||
if (result.containsKey("error")) {
|
||||
return R.fail(result.get("error").toString());
|
||||
}
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 现算成本检索(基于 wms_material_coil)
|
||||
*/
|
||||
|
||||
@@ -106,6 +106,15 @@ public interface IWmsCostCoilDailyService {
|
||||
*/
|
||||
Map<String, Object> calculateCostByEnterCoilNo(String enterCoilNo, LocalDate calcDate);
|
||||
|
||||
/**
|
||||
* 按当前钢卷号维度计算成本(单卷详情)
|
||||
*
|
||||
* @param currentCoilNo 当前钢卷号
|
||||
* @param calcDate 计算日期(可选,默认当前日期)
|
||||
* @return 单卷成本详情
|
||||
*/
|
||||
Map<String, Object> calculateCostByCurrentCoilNo(String currentCoilNo, LocalDate calcDate);
|
||||
|
||||
/**
|
||||
* 批量按入场钢卷号维度计算成本(定时任务使用)
|
||||
* 按入场钢卷号分组,计算每个入场钢卷号的总成本
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量按入场钢卷号维度计算成本(定时任务使用)
|
||||
*/
|
||||
|
||||
@@ -237,9 +237,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</select>
|
||||
|
||||
<!-- 按入场钢卷号统计成本 -->
|
||||
<!-- 虽然方法名仍然包含 EnterCoilNo,但统计口径已统一为“当前钢卷号(current_coil_no)” -->
|
||||
<select id="selectCostByEnterCoilNo" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
mc.enter_coil_no AS enterCoilNo,
|
||||
mc.current_coil_no AS currentCoilNo,
|
||||
COUNT(DISTINCT mc.coil_id) AS coilCount,
|
||||
COUNT(DISTINCT CASE WHEN mc.export_time IS NULL THEN mc.coil_id END) AS unshippedCount,
|
||||
COUNT(DISTINCT CASE WHEN mc.export_time IS NOT NULL THEN mc.coil_id END) AS shippedCount,
|
||||
@@ -253,15 +254,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
AND mc.data_type = 1
|
||||
AND mc.del_flag = 0
|
||||
<if test="enterCoilNo != null and enterCoilNo != ''">
|
||||
AND mc.enter_coil_no = #{enterCoilNo}
|
||||
AND mc.current_coil_no = #{enterCoilNo}
|
||||
</if>
|
||||
GROUP BY mc.enter_coil_no
|
||||
GROUP BY mc.current_coil_no
|
||||
ORDER BY totalCost DESC
|
||||
</select>
|
||||
|
||||
<!-- 囤积成本(按当前钢卷号聚合)列表 -->
|
||||
<select id="selectStockpileByEnterCoilNo" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
t.enter_coil_no AS enterCoilNo,
|
||||
t.current_coil_no AS currentCoilNo,
|
||||
COUNT(*) AS coilCount,
|
||||
SUM(t.net_weight_ton) AS totalNetWeight,
|
||||
SUM(t.gross_weight_ton) AS totalGrossWeight,
|
||||
@@ -271,7 +273,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
MAX(CASE WHEN IFNULL(t.net_weight_ton, 0) = 0 THEN 1 ELSE 0 END) AS hasNetWeightZero
|
||||
FROM (
|
||||
SELECT
|
||||
m.enter_coil_no,
|
||||
m.current_coil_no,
|
||||
IFNULL(m.net_weight, 0) AS net_weight_ton,
|
||||
IFNULL(m.gross_weight, 0) AS gross_weight_ton,
|
||||
CASE
|
||||
@@ -293,33 +295,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
AND m.del_flag = 0
|
||||
AND m.export_time IS NULL
|
||||
<if test="enterCoilNo != null and enterCoilNo != ''">
|
||||
AND m.enter_coil_no LIKE CONCAT(#{enterCoilNo}, '%')
|
||||
AND m.current_coil_no LIKE CONCAT(#{enterCoilNo}, '%')
|
||||
</if>
|
||||
) t
|
||||
GROUP BY t.enter_coil_no
|
||||
ORDER BY t.enter_coil_no DESC
|
||||
GROUP BY t.current_coil_no
|
||||
ORDER BY t.current_coil_no DESC
|
||||
LIMIT #{offset}, #{pageSize}
|
||||
</select>
|
||||
|
||||
<!-- 囤积成本(按入场钢卷号聚合)列表总数 -->
|
||||
<!-- 囤积成本(按当前钢卷号聚合)列表总数 -->
|
||||
<select id="countStockpileByEnterCoilNo" resultType="long">
|
||||
SELECT
|
||||
COUNT(*) AS cnt
|
||||
FROM (
|
||||
SELECT m.enter_coil_no
|
||||
SELECT m.current_coil_no
|
||||
FROM wms_material_coil m
|
||||
WHERE m.data_type = 1
|
||||
AND m.del_flag = 0
|
||||
and m.status = 0
|
||||
AND m.export_time IS NULL
|
||||
<if test="enterCoilNo != null and enterCoilNo != ''">
|
||||
AND m.enter_coil_no LIKE CONCAT(#{enterCoilNo}, '%')
|
||||
AND m.current_coil_no LIKE CONCAT(#{enterCoilNo}, '%')
|
||||
</if>
|
||||
GROUP BY m.enter_coil_no
|
||||
GROUP BY m.current_coil_no
|
||||
) t
|
||||
</select>
|
||||
|
||||
<!-- 囤积成本(按入场钢卷号聚合)汇总 -->
|
||||
<!-- 囤积成本(按当前钢卷号聚合)汇总 -->
|
||||
<select id="selectStockpileSummaryByEnterCoilNo" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
SUM(t.net_weight_ton) AS totalNetWeight,
|
||||
|
||||
Reference in New Issue
Block a user