修复成本问题
This commit is contained in:
@@ -133,7 +133,7 @@ public class EnergyCostReportServiceImpl implements IEnergyCostReportService {
|
||||
long offset = (pageNum - 1) * pageSize;
|
||||
// 手工 count 与数据分页,避免复杂 SQL 自动 count 解析
|
||||
Long total = coilDailyMapper.selectCoilTotalMergedCount(bo);
|
||||
java.util.List<CoilTotalCostVo> rows = coilDailyMapper.selectCoilTotalMerged(bo, offset, pageSize);
|
||||
List<CoilTotalCostVo> rows = coilDailyMapper.selectCoilTotalMerged(bo, offset, pageSize);
|
||||
Page<CoilTotalCostVo> page = new Page<>(pageNum, pageSize);
|
||||
page.setTotal(total == null ? 0L : total);
|
||||
page.setRecords(rows);
|
||||
|
||||
@@ -29,6 +29,73 @@
|
||||
SELECT * FROM wms_energy_coil_daily WHERE task_id = #{taskId}
|
||||
</select>
|
||||
|
||||
<!-- ========================= -->
|
||||
<!-- 公共筛选片段(卷号/时间范围) -->
|
||||
<!-- 说明:尽量避免使用 ${} 以免引入 SQL 注入风险,所以按常用别名拆分多个片段 -->
|
||||
<!-- ========================= -->
|
||||
<sql id="FilterCoilNo_Material_NoAlias">
|
||||
<if test="bo != null and bo.enterCoilNo != null and bo.enterCoilNo != ''">
|
||||
AND enter_coil_no LIKE CONCAT('%', #{bo.enterCoilNo}, '%')
|
||||
</if>
|
||||
<if test="bo != null and bo.currentCoilNo != null and bo.currentCoilNo != ''">
|
||||
AND current_coil_no LIKE CONCAT('%', #{bo.currentCoilNo}, '%')
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<sql id="FilterDate_CreateTime_NoAlias">
|
||||
<if test="bo != null and bo.startDate != null and bo.startDate != ''">
|
||||
AND create_time <![CDATA[>=]]> CONCAT(#{bo.startDate}, ' 00:00:00')
|
||||
</if>
|
||||
<if test="bo != null and bo.endDate != null and bo.endDate != ''">
|
||||
AND create_time <![CDATA[<=]]> CONCAT(#{bo.endDate}, ' 23:59:59')
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<sql id="FilterCoilNo_Pa">
|
||||
<if test="bo != null and bo.enterCoilNo != null and bo.enterCoilNo != ''">
|
||||
AND c.enter_coil_no LIKE CONCAT('%', #{bo.enterCoilNo}, '%')
|
||||
</if>
|
||||
<if test="bo != null and bo.currentCoilNo != null and bo.currentCoilNo != ''">
|
||||
AND pa.current_coil_no LIKE CONCAT('%', #{bo.currentCoilNo}, '%')
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<sql id="FilterDate_PaCreateTime">
|
||||
<if test="bo != null and bo.startDate != null and bo.startDate != ''">
|
||||
AND pa.create_time <![CDATA[>=]]> CONCAT(#{bo.startDate}, ' 00:00:00')
|
||||
</if>
|
||||
<if test="bo != null and bo.endDate != null and bo.endDate != ''">
|
||||
AND pa.create_time <![CDATA[<=]]> CONCAT(#{bo.endDate}, ' 23:59:59')
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<sql id="FilterDate_PaAllCreateTime">
|
||||
<if test="bo != null and bo.startDate != null and bo.startDate != ''">
|
||||
AND pa_all.create_time >= CONCAT(#{bo.startDate}, ' 00:00:00')
|
||||
</if>
|
||||
<if test="bo != null and bo.endDate != null and bo.endDate != ''">
|
||||
AND pa_all.create_time <= CONCAT(#{bo.endDate}, ' 23:59:59')
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<sql id="FilterDate_ChangeTime">
|
||||
<if test="bo != null and bo.startDate != null and bo.startDate != ''">
|
||||
AND change_time >= CONCAT(#{bo.startDate}, ' 00:00:00')
|
||||
</if>
|
||||
<if test="bo != null and bo.endDate != null and bo.endDate != ''">
|
||||
AND change_time <= CONCAT(#{bo.endDate}, ' 23:59:59')
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<!-- 统一的“有效分钟数”表达式:基于库区抄表结束时间/完工时间择优 -->
|
||||
<sql id="ExprPaEffectiveMinutes">
|
||||
CASE
|
||||
WHEN pa.create_time <![CDATA[<]]> COALESCE(pa.complete_time, wmt.warehouse_end_time, NOW())
|
||||
THEN TIMESTAMPDIFF(MINUTE, pa.create_time, COALESCE(pa.complete_time, wmt.warehouse_end_time, NOW()))
|
||||
ELSE 0
|
||||
END
|
||||
</sql>
|
||||
|
||||
<!-- 入场卷号维度能源+囤积成本汇总(分页) -->
|
||||
<select id="selectCoilTotalMerged" parameterType="map"
|
||||
resultType="com.klp.ems.domain.vo.CoilTotalCostVo">
|
||||
@@ -54,18 +121,8 @@
|
||||
WHERE data_type = 1
|
||||
AND del_flag = 0
|
||||
AND status = 0
|
||||
<if test="bo != null and bo.enterCoilNo != null and bo.enterCoilNo != ''">
|
||||
AND enter_coil_no LIKE CONCAT('%', #{bo.enterCoilNo}, '%')
|
||||
</if>
|
||||
<if test="bo != null and bo.currentCoilNo != null and bo.currentCoilNo != ''">
|
||||
AND current_coil_no LIKE CONCAT('%', #{bo.currentCoilNo}, '%')
|
||||
</if>
|
||||
<if test="bo != null and bo.startDate != null and bo.startDate != ''">
|
||||
AND create_time <![CDATA[>=]]> CONCAT(#{bo.startDate}, ' 00:00:00')
|
||||
</if>
|
||||
<if test="bo != null and bo.endDate != null and bo.endDate != ''">
|
||||
AND create_time <![CDATA[<=]]> CONCAT(#{bo.endDate}, ' 23:59:59')
|
||||
</if>
|
||||
<include refid="FilterCoilNo_Material_NoAlias"/>
|
||||
<include refid="FilterDate_CreateTime_NoAlias"/>
|
||||
GROUP BY current_coil_no
|
||||
) m
|
||||
LEFT JOIN (
|
||||
@@ -73,14 +130,10 @@
|
||||
pa.current_coil_no,
|
||||
COUNT(DISTINCT pa.coil_id) AS coil_count,
|
||||
SUM(
|
||||
CASE
|
||||
WHEN pa.create_time <![CDATA[<]]> COALESCE(pa.complete_time, wmt.warehouse_end_time, NOW())
|
||||
THEN CAST(TIMESTAMPDIFF(MINUTE,
|
||||
pa.create_time,
|
||||
COALESCE(pa.complete_time, wmt.warehouse_end_time, NOW())
|
||||
) AS DECIMAL(20,6)) / 60.0
|
||||
ELSE 0
|
||||
END
|
||||
CAST(
|
||||
<include refid="ExprPaEffectiveMinutes"/>
|
||||
AS DECIMAL(20,6)
|
||||
) / 60.0
|
||||
) AS total_duration,
|
||||
SUM(
|
||||
CASE
|
||||
@@ -89,14 +142,7 @@
|
||||
AND wd_prod.total_prod_minutes > 0
|
||||
THEN wd.total_warehouse_consumption *
|
||||
(CAST(
|
||||
CASE
|
||||
WHEN pa.create_time <![CDATA[<]]> COALESCE(pa.complete_time, wmt.warehouse_end_time, NOW())
|
||||
THEN TIMESTAMPDIFF(MINUTE,
|
||||
pa.create_time,
|
||||
COALESCE(pa.complete_time, wmt.warehouse_end_time, NOW())
|
||||
)
|
||||
ELSE 0
|
||||
END AS DECIMAL(20,6)
|
||||
<include refid="ExprPaEffectiveMinutes"/> AS DECIMAL(20,6)
|
||||
) / wd_prod.total_prod_minutes)
|
||||
ELSE 0
|
||||
END
|
||||
@@ -108,14 +154,7 @@
|
||||
AND wd_prod.total_prod_minutes > 0
|
||||
THEN wd.total_warehouse_cost *
|
||||
(CAST(
|
||||
CASE
|
||||
WHEN pa.create_time <![CDATA[<]]> COALESCE(pa.complete_time, wmt.warehouse_end_time, NOW())
|
||||
THEN TIMESTAMPDIFF(MINUTE,
|
||||
pa.create_time,
|
||||
COALESCE(pa.complete_time, wmt.warehouse_end_time, NOW())
|
||||
)
|
||||
ELSE 0
|
||||
END AS DECIMAL(20,6)
|
||||
<include refid="ExprPaEffectiveMinutes"/> AS DECIMAL(20,6)
|
||||
) / wd_prod.total_prod_minutes)
|
||||
ELSE 0
|
||||
END
|
||||
@@ -160,18 +199,8 @@
|
||||
WHERE pa.action_status IN (0, 1, 2)
|
||||
and pa.del_flag='0'
|
||||
AND pa.warehouse_id IS NOT NULL
|
||||
<if test="bo != null and bo.enterCoilNo != null and bo.enterCoilNo != ''">
|
||||
AND c.enter_coil_no LIKE CONCAT('%', #{bo.enterCoilNo}, '%')
|
||||
</if>
|
||||
<if test="bo != null and bo.currentCoilNo != null and bo.currentCoilNo != ''">
|
||||
AND pa.current_coil_no LIKE CONCAT('%', #{bo.currentCoilNo}, '%')
|
||||
</if>
|
||||
<if test="bo != null and bo.startDate != null and bo.startDate != ''">
|
||||
AND pa.create_time <![CDATA[>=]]> CONCAT(#{bo.startDate}, ' 00:00:00')
|
||||
</if>
|
||||
<if test="bo != null and bo.endDate != null and bo.endDate != ''">
|
||||
AND pa.create_time <![CDATA[<=]]> CONCAT(#{bo.endDate}, ' 23:59:59')
|
||||
</if>
|
||||
<include refid="FilterCoilNo_Pa"/>
|
||||
<include refid="FilterDate_PaCreateTime"/>
|
||||
GROUP BY pa.current_coil_no
|
||||
) e ON m.current_coil_no = e.current_coil_no
|
||||
LEFT JOIN (
|
||||
@@ -253,27 +282,12 @@
|
||||
) AS total_minutes
|
||||
FROM wms_coil_pending_action pa_all
|
||||
WHERE pa_all.action_status IN (0,1,2)
|
||||
<if test="bo != null and bo.startDate != null and bo.startDate != ''">
|
||||
AND pa_all.create_time >= CONCAT(#{bo.startDate}, ' 00:00:00')
|
||||
</if>
|
||||
<if test="bo != null and bo.endDate != null and bo.endDate != ''">
|
||||
AND pa_all.create_time <= CONCAT(#{bo.endDate}, ' 23:59:59')
|
||||
</if>
|
||||
<include refid="FilterDate_PaAllCreateTime"/>
|
||||
GROUP BY DATE(pa_all.create_time)
|
||||
) td ON td.day_key = DATE(pa.create_time)
|
||||
WHERE pa.action_status IN (0,1,2)
|
||||
<if test="bo != null and bo.enterCoilNo != null and bo.enterCoilNo != ''">
|
||||
AND c.enter_coil_no LIKE CONCAT('%', #{bo.enterCoilNo}, '%')
|
||||
</if>
|
||||
<if test="bo != null and bo.currentCoilNo != null and bo.currentCoilNo != ''">
|
||||
AND pa.current_coil_no LIKE CONCAT('%', #{bo.currentCoilNo}, '%')
|
||||
</if>
|
||||
<if test="bo != null and bo.startDate != null and bo.startDate != ''">
|
||||
AND pa.create_time >= CONCAT(#{bo.startDate}, ' 00:00:00')
|
||||
</if>
|
||||
<if test="bo != null and bo.endDate != null and bo.endDate != ''">
|
||||
AND pa.create_time <= CONCAT(#{bo.endDate}, ' 23:59:59')
|
||||
</if>
|
||||
<include refid="FilterCoilNo_Pa"/>
|
||||
<include refid="FilterDate_PaCreateTime"/>
|
||||
GROUP BY DATE(pa.create_time), pa.current_coil_no, td.total_minutes
|
||||
) dm
|
||||
LEFT JOIN (
|
||||
@@ -283,12 +297,7 @@
|
||||
FROM eqp_auxiliary_material_change
|
||||
WHERE del_flag = '0'
|
||||
AND change_type = '减少'
|
||||
<if test="bo != null and bo.startDate != null and bo.startDate != ''">
|
||||
AND change_time >= CONCAT(#{bo.startDate}, ' 00:00:00')
|
||||
</if>
|
||||
<if test="bo != null and bo.endDate != null and bo.endDate != ''">
|
||||
AND change_time <= CONCAT(#{bo.endDate}, ' 23:59:59')
|
||||
</if>
|
||||
<include refid="FilterDate_ChangeTime"/>
|
||||
GROUP BY DATE(change_time)
|
||||
) a ON dm.day_key = a.day_key
|
||||
LEFT JOIN (
|
||||
@@ -298,17 +307,11 @@
|
||||
FROM eqp_spare_parts_change
|
||||
WHERE del_flag = '0'
|
||||
AND change_type = '减少'
|
||||
<if test="bo != null and bo.startDate != null and bo.startDate != ''">
|
||||
AND change_time >= CONCAT(#{bo.startDate}, ' 00:00:00')
|
||||
</if>
|
||||
<if test="bo != null and bo.endDate != null and bo.endDate != ''">
|
||||
AND change_time <= CONCAT(#{bo.endDate}, ' 23:59:59')
|
||||
</if>
|
||||
<include refid="FilterDate_ChangeTime"/>
|
||||
GROUP BY DATE(change_time)
|
||||
) p ON dm.day_key = p.day_key
|
||||
GROUP BY dm.current_coil_no
|
||||
) x ON m.current_coil_no = x.current_coil_no
|
||||
WHERE s.current_coil_no IS NOT NULL
|
||||
ORDER BY totalCost DESC
|
||||
LIMIT #{offset}, #{pageSize}
|
||||
</select>
|
||||
@@ -367,18 +370,8 @@
|
||||
WHERE data_type IN (0,1)
|
||||
AND del_flag = 0
|
||||
AND status = 0
|
||||
<if test="bo != null and bo.enterCoilNo != null and bo.enterCoilNo != ''">
|
||||
AND enter_coil_no LIKE CONCAT('%', #{bo.enterCoilNo}, '%')
|
||||
</if>
|
||||
<if test="bo != null and bo.currentCoilNo != null and bo.currentCoilNo != ''">
|
||||
AND current_coil_no LIKE CONCAT('%', #{bo.currentCoilNo}, '%')
|
||||
</if>
|
||||
<if test="bo != null and bo.startDate != null and bo.startDate != ''">
|
||||
AND create_time <![CDATA[>=]]> CONCAT(#{bo.startDate}, ' 00:00:00')
|
||||
</if>
|
||||
<if test="bo != null and bo.endDate != null and bo.endDate != ''">
|
||||
AND create_time <![CDATA[<=]]> CONCAT(#{bo.endDate}, ' 23:59:59')
|
||||
</if>
|
||||
<include refid="FilterCoilNo_Material_NoAlias"/>
|
||||
<include refid="FilterDate_CreateTime_NoAlias"/>
|
||||
GROUP BY current_coil_no
|
||||
) m
|
||||
LEFT JOIN (
|
||||
@@ -386,14 +379,10 @@
|
||||
pa.current_coil_no,
|
||||
COUNT(DISTINCT pa.coil_id) AS coil_count,
|
||||
SUM(
|
||||
CASE
|
||||
WHEN pa.create_time <![CDATA[<]]> COALESCE(pa.complete_time, wmt.warehouse_end_time, NOW())
|
||||
THEN CAST(TIMESTAMPDIFF(MINUTE,
|
||||
pa.create_time,
|
||||
COALESCE(pa.complete_time, wmt.warehouse_end_time, NOW())
|
||||
) AS DECIMAL(20,6)) / 60.0
|
||||
ELSE 0
|
||||
END
|
||||
CAST(
|
||||
<include refid="ExprPaEffectiveMinutes"/>
|
||||
AS DECIMAL(20,6)
|
||||
) / 60.0
|
||||
) AS total_duration,
|
||||
SUM(
|
||||
CASE
|
||||
@@ -402,14 +391,7 @@
|
||||
AND wd_prod.total_prod_minutes > 0
|
||||
THEN wd.total_warehouse_consumption *
|
||||
(CAST(
|
||||
CASE
|
||||
WHEN pa.create_time <![CDATA[<]]> COALESCE(pa.complete_time, wmt.warehouse_end_time, NOW())
|
||||
THEN TIMESTAMPDIFF(MINUTE,
|
||||
pa.create_time,
|
||||
COALESCE(pa.complete_time, wmt.warehouse_end_time, NOW())
|
||||
)
|
||||
ELSE 0
|
||||
END AS DECIMAL(20,6)
|
||||
<include refid="ExprPaEffectiveMinutes"/> AS DECIMAL(20,6)
|
||||
) / wd_prod.total_prod_minutes)
|
||||
ELSE 0
|
||||
END
|
||||
@@ -421,14 +403,7 @@
|
||||
AND wd_prod.total_prod_minutes > 0
|
||||
THEN wd.total_warehouse_cost *
|
||||
(CAST(
|
||||
CASE
|
||||
WHEN pa.create_time <![CDATA[<]]> COALESCE(pa.complete_time, wmt.warehouse_end_time, NOW())
|
||||
THEN TIMESTAMPDIFF(MINUTE,
|
||||
pa.create_time,
|
||||
COALESCE(pa.complete_time, wmt.warehouse_end_time, NOW())
|
||||
)
|
||||
ELSE 0
|
||||
END AS DECIMAL(20,6)
|
||||
<include refid="ExprPaEffectiveMinutes"/> AS DECIMAL(20,6)
|
||||
) / wd_prod.total_prod_minutes)
|
||||
ELSE 0
|
||||
END
|
||||
@@ -472,6 +447,8 @@
|
||||
) wd_prod ON pa.warehouse_id = wd_prod.warehouse_id
|
||||
WHERE pa.action_status IN (0, 1, 2)
|
||||
AND pa.warehouse_id IS NOT NULL
|
||||
<include refid="FilterCoilNo_Pa"/>
|
||||
<include refid="FilterDate_PaCreateTime"/>
|
||||
GROUP BY c.enter_coil_no
|
||||
) e ON m.enter_coil_no = e.enter_coil_no
|
||||
LEFT JOIN (
|
||||
@@ -541,21 +518,11 @@
|
||||
) AS total_minutes
|
||||
FROM wms_coil_pending_action pa_all
|
||||
WHERE pa_all.action_status IN (0,1,2)
|
||||
<if test="bo != null and bo.startDate != null and bo.startDate != ''">
|
||||
AND pa_all.create_time >= CONCAT(#{bo.startDate}, ' 00:00:00')
|
||||
</if>
|
||||
<if test="bo != null and bo.endDate != null and bo.endDate != ''">
|
||||
AND pa_all.create_time <= CONCAT(#{bo.endDate}, ' 23:59:59')
|
||||
</if>
|
||||
<include refid="FilterDate_PaAllCreateTime"/>
|
||||
GROUP BY DATE(pa_all.create_time)
|
||||
) td ON td.day_key = DATE(pa.create_time)
|
||||
WHERE pa.action_status IN (0,1,2)
|
||||
<if test="bo != null and bo.startDate != null and bo.startDate != ''">
|
||||
AND pa.create_time >= CONCAT(#{bo.startDate}, ' 00:00:00')
|
||||
</if>
|
||||
<if test="bo != null and bo.endDate != null and bo.endDate != ''">
|
||||
AND pa.create_time <= CONCAT(#{bo.endDate}, ' 23:59:59')
|
||||
</if>
|
||||
<include refid="FilterDate_PaCreateTime"/>
|
||||
GROUP BY DATE(pa.create_time), c.enter_coil_no, td.total_minutes
|
||||
) dm
|
||||
LEFT JOIN (
|
||||
@@ -565,12 +532,7 @@
|
||||
FROM eqp_auxiliary_material_change
|
||||
WHERE del_flag = '0'
|
||||
AND change_type = '减少'
|
||||
<if test="bo != null and bo.startDate != null and bo.startDate != ''">
|
||||
AND change_time >= CONCAT(#{bo.startDate}, ' 00:00:00')
|
||||
</if>
|
||||
<if test="bo != null and bo.endDate != null and bo.endDate != ''">
|
||||
AND change_time <= CONCAT(#{bo.endDate}, ' 23:59:59')
|
||||
</if>
|
||||
<include refid="FilterDate_ChangeTime"/>
|
||||
GROUP BY DATE(change_time)
|
||||
) a ON dm.day_key = a.day_key
|
||||
LEFT JOIN (
|
||||
@@ -580,12 +542,7 @@
|
||||
FROM eqp_spare_parts_change
|
||||
WHERE del_flag = '0'
|
||||
AND change_type = '减少'
|
||||
<if test="bo != null and bo.startDate != null and bo.startDate != ''">
|
||||
AND change_time >= CONCAT(#{bo.startDate}, ' 00:00:00')
|
||||
</if>
|
||||
<if test="bo != null and bo.endDate != null and bo.endDate != ''">
|
||||
AND change_time <= CONCAT(#{bo.endDate}, ' 23:59:59')
|
||||
</if>
|
||||
<include refid="FilterDate_ChangeTime"/>
|
||||
GROUP BY DATE(change_time)
|
||||
) p ON dm.day_key = p.day_key
|
||||
GROUP BY dm.enter_coil_no
|
||||
|
||||
@@ -89,13 +89,13 @@ export function batchCalculateCost(calcDate) {
|
||||
})
|
||||
}
|
||||
|
||||
// 按入场钢卷号维度计算成本
|
||||
export function calculateCostByEnterCoilNo(enterCoilNo, calcDate) {
|
||||
// 按当前钢卷号维度计算成本(单卷详情)
|
||||
export function calculateCostByCurrentCoilNo(currentCoilNo, calcDate) {
|
||||
return request({
|
||||
url: '/wms/cost/coil/calculateByEnterCoilNo',
|
||||
url: '/wms/cost/coil/calculateByCurrentCoilNo',
|
||||
method: 'post',
|
||||
params: {
|
||||
enterCoilNo,
|
||||
currentCoilNo,
|
||||
calcDate
|
||||
}
|
||||
})
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
|
||||
<el-card class="block-card">
|
||||
<div slot="header" class="clearfix">
|
||||
<span class="card-title">成本汇总(按入场卷号)</span>
|
||||
<span class="card-title">成本汇总</span>
|
||||
</div>
|
||||
<el-table :data="mergedRows" border stripe>
|
||||
<el-table-column prop="enterCoilNo" label="入场卷号"></el-table-column>
|
||||
@@ -257,6 +257,7 @@ export default {
|
||||
}
|
||||
fetchCoilTotalMerged(params).then(res => {
|
||||
this.mergedRows = res.rows || []
|
||||
console.log(res)
|
||||
this.mergedTotal = res.total || 0
|
||||
|
||||
const rows = this.mergedRows || []
|
||||
|
||||
@@ -81,7 +81,7 @@
|
||||
style="width: 100%"
|
||||
@sort-change="handleSortChange"
|
||||
>
|
||||
<el-table-column prop="enterCoilNo" label="入场钢卷号" />
|
||||
<el-table-column prop="currentCoilNo" label="当前钢卷号" />
|
||||
<el-table-column prop="coilCount" label="子钢卷数" align="right" />
|
||||
<el-table-column prop="totalGrossWeight" label="总毛重(吨)" align="right">
|
||||
<template slot-scope="scope">
|
||||
@@ -112,7 +112,7 @@
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" fixed="right">
|
||||
<template slot-scope="scope">
|
||||
<el-button type="text" size="small" @click="viewCoilDetail(scope.row)">查看子钢卷成本</el-button>
|
||||
<el-button type="text" size="small" @click="viewCoilDetail(scope.row)">查看详情</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -126,56 +126,45 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 入场钢卷号下子钢卷详情对话框 -->
|
||||
<!-- 当前钢卷成本详情对话框 -->
|
||||
<el-dialog
|
||||
title="入场钢卷号下子钢卷成本详情"
|
||||
title="当前钢卷成本详情"
|
||||
:visible.sync="showDetailDialog"
|
||||
width="900px"
|
||||
>
|
||||
<div v-if="detailEnterCoilNo" style="margin-bottom: 10px;">
|
||||
入场钢卷号:<strong>{{ detailEnterCoilNo }}</strong>
|
||||
</div>
|
||||
<el-table :data="detailList" stripe style="width: 100%">
|
||||
<el-table-column prop="currentCoilNo" label="当前钢卷号" />
|
||||
<el-table-column prop="grossWeightTon" label="毛重(吨)" align="right">
|
||||
<template slot-scope="scope">
|
||||
{{ formatWeight(scope.row.grossWeightTon) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="netWeightTon" label="净重(吨)" align="right">
|
||||
<template slot-scope="scope">
|
||||
{{ formatWeight(scope.row.netWeightTon) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="storageDays" label="在库天数" align="right">
|
||||
<template slot-scope="scope">
|
||||
<span :class="getStorageDaysClass(scope.row.storageDays)">
|
||||
{{ scope.row.storageDays || '-' }}
|
||||
<div v-if="detailInfo">
|
||||
<el-form label-width="140px" size="small">
|
||||
<el-form-item label="当前钢卷号">
|
||||
<span>{{ detailCoilNo }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="毛重(吨)">
|
||||
<span>{{ formatWeight(detailInfo.grossWeightTon) }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="净重(吨)">
|
||||
<span>{{ formatWeight(detailInfo.netWeightTon) }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="在库天数">
|
||||
<span :class="getStorageDaysClass(detailInfo.storageDays)">
|
||||
{{ detailInfo.storageDays || '-' }}
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="unitCost" label="单位成本(元/吨/天)" align="right">
|
||||
<template slot-scope="scope">
|
||||
{{ formatMoney(scope.row.unitCost) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="dailyCost" label="日成本(元)" align="right">
|
||||
<template slot-scope="scope">
|
||||
{{ formatMoney(scope.row.dailyCost) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="totalCost" label="累计成本(元)" align="right">
|
||||
<template slot-scope="scope">
|
||||
<span class="cost-total">{{ formatMoney(scope.row.totalCost) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-form-item>
|
||||
<el-form-item label="单位成本(元/吨/天)">
|
||||
<span>{{ formatMoney(detailInfo.unitCost) }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="日成本(元)">
|
||||
<span>{{ formatMoney(detailInfo.dailyCost) }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="累计成本(元)">
|
||||
<span class="cost-total">{{ formatMoney(detailInfo.totalCost) }}</span>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { calculateCostByEnterCoilNo, getStockpileCostList } from '@/api/wms/cost'
|
||||
import { calculateCostByCurrentCoilNo, getStockpileCostList } from '@/api/wms/cost'
|
||||
|
||||
export default {
|
||||
name: 'CostStockpile',
|
||||
@@ -197,8 +186,8 @@ export default {
|
||||
currentCoilNo: null
|
||||
},
|
||||
showDetailDialog: false,
|
||||
detailEnterCoilNo: null,
|
||||
detailList: []
|
||||
detailCoilNo: null,
|
||||
detailInfo: null
|
||||
}
|
||||
},
|
||||
created() {
|
||||
@@ -272,10 +261,10 @@ export default {
|
||||
},
|
||||
async viewCoilDetail(row) {
|
||||
try {
|
||||
const res = await calculateCostByEnterCoilNo(row.enterCoilNo, null)
|
||||
const res = await calculateCostByCurrentCoilNo(row.currentCoilNo, null)
|
||||
if (res.code === 200 && res.data && !res.data.error) {
|
||||
this.detailEnterCoilNo = row.enterCoilNo
|
||||
this.detailList = res.data.coilDetails || []
|
||||
this.detailCoilNo = row.currentCoilNo
|
||||
this.detailInfo = res.data
|
||||
this.showDetailDialog = true
|
||||
} else {
|
||||
this.$message.error(res.data?.error || '加载详情失败')
|
||||
|
||||
@@ -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