囤积成本重构
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.klp.mapper.CostCoilDailyMapper">
|
||||
<mapper namespace="com.klp.mapper.WmsCostCoilDailyMapper">
|
||||
|
||||
<resultMap type="com.klp.domain.CostCoilDaily" id="CostCoilDailyResult">
|
||||
<resultMap type="com.klp.domain.WmsCostCoilDaily" id="CostCoilDailyResult">
|
||||
<result property="costId" column="cost_id"/>
|
||||
<result property="coilId" column="coil_id"/>
|
||||
<result property="currentCoilNo" column="current_coil_no"/>
|
||||
@@ -20,7 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="createTime" column="create_time"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="com.klp.domain.vo.CostCoilDailyVo" id="CostCoilDailyVoResult">
|
||||
<resultMap type="com.klp.domain.vo.WmsCostCoilDailyVo" id="CostCoilDailyVoResult">
|
||||
<result property="costId" column="cost_id"/>
|
||||
<result property="coilId" column="coil_id"/>
|
||||
<result property="currentCoilNo" column="current_coil_no"/>
|
||||
@@ -37,7 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</resultMap>
|
||||
|
||||
<!-- 自定义查询,关联库区名称 -->
|
||||
<select id="selectVoPage" resultType="com.klp.domain.vo.CostCoilDailyVo">
|
||||
<select id="selectVoPage" resultType="com.klp.domain.vo.WmsCostCoilDailyVo">
|
||||
SELECT
|
||||
ccd.cost_id,
|
||||
ccd.coil_id,
|
||||
@@ -52,7 +52,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
w.warehouse_name,
|
||||
ccd.item_type,
|
||||
ccd.material_type
|
||||
FROM cost_coil_daily ccd
|
||||
FROM wms_cost_coil_daily ccd
|
||||
LEFT JOIN wms_warehouse w ON ccd.warehouse_id = w.warehouse_id AND w.del_flag = 0
|
||||
${ew.customSqlSegment}
|
||||
</select>
|
||||
@@ -72,7 +72,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
w.warehouse_name,
|
||||
ccd.item_type,
|
||||
ccd.material_type
|
||||
FROM cost_coil_daily ccd
|
||||
FROM wms_cost_coil_daily ccd
|
||||
LEFT JOIN wms_warehouse w ON ccd.warehouse_id = w.warehouse_id AND w.del_flag = 0
|
||||
${ew.customSqlSegment}
|
||||
</select>
|
||||
@@ -92,7 +92,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
w.warehouse_name,
|
||||
ccd.item_type,
|
||||
ccd.material_type
|
||||
FROM cost_coil_daily ccd
|
||||
FROM wms_cost_coil_daily ccd
|
||||
LEFT JOIN wms_warehouse w ON ccd.warehouse_id = w.warehouse_id AND w.del_flag = 0
|
||||
WHERE ccd.cost_id = #{costId}
|
||||
</select>
|
||||
@@ -102,13 +102,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
SELECT
|
||||
COUNT(*) AS totalCoils,
|
||||
SUM(t.net_weight_ton) AS totalNetWeight,
|
||||
SUM(t.gross_weight_ton) AS totalGrossWeight,
|
||||
SUM(t.total_cost_amount) AS totalCost,
|
||||
AVG(t.storage_days) AS avgStorageDays,
|
||||
SUM(t.daily_cost_amount) AS totalDailyCost
|
||||
FROM (
|
||||
SELECT
|
||||
m.coil_id,
|
||||
IFNULL(m.net_weight, 0) / 1000 AS net_weight_ton,
|
||||
IFNULL(m.net_weight, 0) AS net_weight_ton,
|
||||
IFNULL(m.gross_weight, 0) AS gross_weight_ton,
|
||||
(DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1) AS storage_days,
|
||||
CASE
|
||||
WHEN cs.unit_cost IS NULL THEN 0
|
||||
@@ -117,7 +119,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN m.gross_weight
|
||||
ELSE IFNULL(m.net_weight, 0)
|
||||
END
|
||||
) / 1000 * cs.unit_cost
|
||||
) * cs.unit_cost
|
||||
END AS daily_cost_amount,
|
||||
CASE
|
||||
WHEN cs.unit_cost IS NULL THEN 0
|
||||
@@ -126,10 +128,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN m.gross_weight
|
||||
ELSE IFNULL(m.net_weight, 0)
|
||||
END
|
||||
) / 1000 * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
) * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
END AS total_cost_amount
|
||||
FROM wms_material_coil m
|
||||
LEFT JOIN cost_standard_config cs
|
||||
LEFT JOIN wms_cost_standard_config cs
|
||||
ON cs.status = 1
|
||||
AND DATE(m.create_time) >= cs.effective_date
|
||||
AND (cs.expire_date IS NULL OR DATE(m.create_time) <= cs.expire_date)
|
||||
@@ -156,12 +158,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
COUNT(*) AS coilCount,
|
||||
SUM(t.total_cost_amount) AS totalCost,
|
||||
AVG(t.storage_days) AS avgStorageDays,
|
||||
SUM(t.net_weight_ton) AS totalNetWeight
|
||||
SUM(t.net_weight_ton) AS totalNetWeight,
|
||||
SUM(t.gross_weight_ton) AS totalGrossWeight
|
||||
FROM (
|
||||
SELECT
|
||||
m.coil_id,
|
||||
m.warehouse_id,
|
||||
IFNULL(m.net_weight, 0) / 1000 AS net_weight_ton,
|
||||
IFNULL(m.net_weight, 0) AS net_weight_ton,
|
||||
IFNULL(m.gross_weight, 0) AS gross_weight_ton,
|
||||
(DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1) AS storage_days,
|
||||
CASE
|
||||
WHEN cs.unit_cost IS NULL THEN 0
|
||||
@@ -170,10 +174,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN m.gross_weight
|
||||
ELSE IFNULL(m.net_weight, 0)
|
||||
END
|
||||
) / 1000 * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
) * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
END AS total_cost_amount
|
||||
FROM wms_material_coil m
|
||||
LEFT JOIN cost_standard_config cs
|
||||
LEFT JOIN wms_cost_standard_config cs
|
||||
ON cs.status = 1
|
||||
AND DATE(m.create_time) >= cs.effective_date
|
||||
AND (cs.expire_date IS NULL OR DATE(m.create_time) <= cs.expire_date)
|
||||
@@ -193,12 +197,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
COUNT(*) AS coilCount,
|
||||
SUM(t.total_cost_amount) AS totalCost,
|
||||
AVG(t.storage_days) AS avgStorageDays,
|
||||
SUM(t.net_weight_ton) AS totalNetWeight
|
||||
SUM(t.net_weight_ton) AS totalNetWeight,
|
||||
SUM(t.gross_weight_ton) AS totalGrossWeight
|
||||
FROM (
|
||||
SELECT
|
||||
m.coil_id,
|
||||
m.item_type,
|
||||
IFNULL(m.net_weight, 0) / 1000 AS net_weight_ton,
|
||||
IFNULL(m.net_weight, 0) AS net_weight_ton,
|
||||
IFNULL(m.gross_weight, 0) AS gross_weight_ton,
|
||||
(DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1) AS storage_days,
|
||||
CASE
|
||||
WHEN cs.unit_cost IS NULL THEN 0
|
||||
@@ -207,10 +213,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN m.gross_weight
|
||||
ELSE IFNULL(m.net_weight, 0)
|
||||
END
|
||||
) / 1000 * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
) * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
END AS total_cost_amount
|
||||
FROM wms_material_coil m
|
||||
LEFT JOIN cost_standard_config cs
|
||||
LEFT JOIN wms_cost_standard_config cs
|
||||
ON cs.status = 1
|
||||
AND DATE(m.create_time) >= cs.effective_date
|
||||
AND (cs.expire_date IS NULL OR DATE(m.create_time) <= cs.expire_date)
|
||||
@@ -225,7 +231,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<!-- 检查指定日期和钢卷的成本记录是否存在 -->
|
||||
<select id="countByCoilIdAndDate" resultType="int">
|
||||
SELECT COUNT(1)
|
||||
FROM cost_coil_daily
|
||||
FROM wms_cost_coil_daily
|
||||
WHERE coil_id = #{coilId}
|
||||
AND calc_date = #{calcDate}
|
||||
</select>
|
||||
@@ -241,7 +247,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
SUM(ccd.net_weight) AS totalNetWeight,
|
||||
AVG(ccd.storage_days) AS avgStorageDays,
|
||||
MAX(ccd.calc_date) AS lastCalcDate
|
||||
FROM cost_coil_daily ccd
|
||||
FROM wms_cost_coil_daily ccd
|
||||
INNER JOIN wms_material_coil mc ON ccd.coil_id = mc.coil_id
|
||||
WHERE ccd.calc_date BETWEEN #{startDate} AND #{endDate}
|
||||
AND mc.data_type = 1
|
||||
@@ -261,24 +267,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
SUM(t.gross_weight_ton) AS totalGrossWeight,
|
||||
SUM(t.cost_amount) AS totalCost,
|
||||
AVG(t.storage_days) AS avgStorageDays,
|
||||
MAX(t.storage_days) AS maxStorageDays
|
||||
MAX(t.storage_days) AS maxStorageDays,
|
||||
MAX(CASE WHEN IFNULL(t.net_weight_ton, 0) = 0 THEN 1 ELSE 0 END) AS hasNetWeightZero
|
||||
FROM (
|
||||
SELECT
|
||||
m.enter_coil_no,
|
||||
IFNULL(m.net_weight, 0) / 1000 AS net_weight_ton,
|
||||
IFNULL(m.gross_weight, 0) / 1000 AS gross_weight_ton,
|
||||
IFNULL(m.net_weight, 0) AS net_weight_ton,
|
||||
IFNULL(m.gross_weight, 0) AS gross_weight_ton,
|
||||
CASE
|
||||
WHEN cs.unit_cost IS NULL THEN 0
|
||||
ELSE (
|
||||
CASE
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN m.gross_weight
|
||||
WHEN IFNULL(m.net_weight, 0) = 0 AND IFNULL(m.gross_weight, 0) > 0 THEN m.gross_weight
|
||||
ELSE IFNULL(m.net_weight, 0)
|
||||
END
|
||||
) / 1000 * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
) * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
END AS cost_amount,
|
||||
(DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1) AS storage_days
|
||||
FROM wms_material_coil m
|
||||
LEFT JOIN cost_standard_config cs
|
||||
LEFT JOIN wms_cost_standard_config cs
|
||||
ON cs.status = 1
|
||||
AND DATE(m.create_time) >= cs.effective_date
|
||||
AND (cs.expire_date IS NULL OR DATE(m.create_time) <= cs.expire_date)
|
||||
@@ -320,8 +327,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
AVG(t.storage_days) AS avgStorageDays
|
||||
FROM (
|
||||
SELECT
|
||||
IFNULL(m.net_weight, 0) / 1000 AS net_weight_ton,
|
||||
IFNULL(m.gross_weight, 0) / 1000 AS gross_weight_ton,
|
||||
IFNULL(m.net_weight, 0) AS net_weight_ton,
|
||||
IFNULL(m.gross_weight, 0) AS gross_weight_ton,
|
||||
CASE
|
||||
WHEN cs.unit_cost IS NULL THEN 0
|
||||
ELSE (
|
||||
@@ -329,11 +336,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN m.gross_weight
|
||||
ELSE IFNULL(m.net_weight, 0)
|
||||
END
|
||||
) / 1000 * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
) * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
END AS cost_amount,
|
||||
(DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1) AS storage_days
|
||||
FROM wms_material_coil m
|
||||
LEFT JOIN cost_standard_config cs
|
||||
LEFT JOIN wms_cost_standard_config cs
|
||||
ON cs.status = 1
|
||||
AND DATE(m.create_time) >= cs.effective_date
|
||||
AND (cs.expire_date IS NULL OR DATE(m.create_time) <= cs.expire_date)
|
||||
@@ -355,8 +362,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
SUM(t.cost_amount) AS totalCost
|
||||
FROM (
|
||||
SELECT
|
||||
IFNULL(m.net_weight, 0) / 1000 AS net_weight_ton,
|
||||
IFNULL(m.gross_weight, 0) / 1000 AS gross_weight_ton,
|
||||
IFNULL(m.net_weight, 0) AS net_weight_ton,
|
||||
IFNULL(m.gross_weight, 0) AS gross_weight_ton,
|
||||
(DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1) AS storage_days,
|
||||
CASE
|
||||
WHEN cs.unit_cost IS NULL THEN 0
|
||||
@@ -365,10 +372,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN m.gross_weight
|
||||
ELSE IFNULL(m.net_weight, 0)
|
||||
END
|
||||
) / 1000 * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
) * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
END AS cost_amount
|
||||
FROM wms_material_coil m
|
||||
LEFT JOIN cost_standard_config cs
|
||||
LEFT JOIN wms_cost_standard_config cs
|
||||
ON cs.status = 1
|
||||
AND DATE(m.create_time) >= cs.effective_date
|
||||
AND (cs.expire_date IS NULL OR DATE(m.create_time) <= cs.expire_date)
|
||||
@@ -378,14 +385,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
) t
|
||||
</select>
|
||||
|
||||
<!-- 成本趋势(按日统计 cost_coil_daily) -->
|
||||
<!-- 成本趋势(按日统计 wms_cost_coil_daily) -->
|
||||
<select id="selectCostTrend" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
ccd.calc_date AS date,
|
||||
SUM(ccd.total_cost) AS totalCost,
|
||||
SUM(ccd.net_weight) AS totalNetWeight,
|
||||
SUM(ccd.daily_cost) AS totalDailyCost
|
||||
FROM cost_coil_daily ccd
|
||||
SUM(ccd.daily_cost) AS totalDailyCost,
|
||||
COUNT(*) AS coilCount
|
||||
FROM wms_cost_coil_daily ccd
|
||||
WHERE 1 = 1
|
||||
<if test="startDate != null">
|
||||
AND ccd.calc_date >= #{startDate}
|
||||
@@ -403,8 +411,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
m.enter_coil_no,
|
||||
m.coil_id,
|
||||
m.current_coil_no,
|
||||
IFNULL(m.net_weight, 0) / 1000 AS net_weight_ton,
|
||||
IFNULL(m.gross_weight, 0) / 1000 AS gross_weight_ton,
|
||||
IFNULL(m.net_weight, 0) AS net_weight_ton,
|
||||
IFNULL(m.gross_weight, 0) AS gross_weight_ton,
|
||||
CASE
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN 'gross'
|
||||
ELSE 'net'
|
||||
@@ -412,7 +420,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
CASE
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN IFNULL(m.gross_weight, 0)
|
||||
ELSE IFNULL(m.net_weight, 0)
|
||||
END / 1000 AS charge_weight_ton,
|
||||
END AS charge_weight_ton,
|
||||
DATE(m.create_time) AS start_date,
|
||||
CASE
|
||||
WHEN m.export_time IS NOT NULL THEN DATE_SUB(DATE(m.export_time), INTERVAL 1 DAY)
|
||||
@@ -427,7 +435,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
m.warehouse_id,
|
||||
COALESCE(w.warehouse_name, '-') AS warehouse_name
|
||||
FROM wms_material_coil m
|
||||
LEFT JOIN cost_standard_config cs
|
||||
LEFT JOIN wms_cost_standard_config cs
|
||||
ON cs.status = 1
|
||||
AND DATE(m.create_time) >= cs.effective_date
|
||||
AND (cs.expire_date IS NULL OR DATE(m.create_time) <= cs.expire_date)
|
||||
@@ -515,7 +523,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<!-- 删除指定日期的成本记录 -->
|
||||
<delete id="deleteByCalcDate">
|
||||
DELETE FROM cost_coil_daily
|
||||
DELETE FROM wms_cost_coil_daily
|
||||
WHERE calc_date = #{calcDate}
|
||||
</delete>
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.klp.mapper.CostStandardConfigMapper">
|
||||
<mapper namespace="com.klp.mapper.WmsCostStandardConfigMapper">
|
||||
|
||||
<resultMap type="com.klp.domain.CostStandardConfig" id="CostStandardConfigResult">
|
||||
<resultMap type="com.klp.domain.WmsCostStandardConfig" id="CostStandardConfigResult">
|
||||
<result property="configId" column="config_id"/>
|
||||
<result property="unitCost" column="unit_cost"/>
|
||||
<result property="effectiveDate" column="effective_date"/>
|
||||
@@ -18,7 +18,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="updateBy" column="update_by"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="com.klp.domain.vo.CostStandardConfigVo" id="CostStandardConfigVoResult">
|
||||
<resultMap type="com.klp.domain.vo.WmsCostStandardConfigVo" id="CostStandardConfigVoResult">
|
||||
<result property="configId" column="config_id"/>
|
||||
<result property="unitCost" column="unit_cost"/>
|
||||
<result property="effectiveDate" column="effective_date"/>
|
||||
@@ -34,7 +34,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<!-- 查询指定日期的有效成本标准 -->
|
||||
<select id="selectEffectiveByDate" resultMap="CostStandardConfigVoResult">
|
||||
SELECT *
|
||||
FROM cost_standard_config
|
||||
FROM wms_cost_standard_config
|
||||
WHERE del_flag = 0
|
||||
AND status = 1
|
||||
AND effective_date <= #{date}
|
||||
@@ -46,7 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<!-- 查询当前有效的成本标准 -->
|
||||
<select id="selectCurrentEffective" resultMap="CostStandardConfigVoResult">
|
||||
SELECT *
|
||||
FROM cost_standard_config
|
||||
FROM wms_cost_standard_config
|
||||
WHERE del_flag = 0
|
||||
AND status = 1
|
||||
AND effective_date <= CURDATE()
|
||||
Reference in New Issue
Block a user