l3能源成本分摊(部分完成留存)
This commit is contained in:
244
klp-ems/src/main/resources/mapper/WmsEnergyCoilDailyMapper.xml
Normal file
244
klp-ems/src/main/resources/mapper/WmsEnergyCoilDailyMapper.xml
Normal file
@@ -0,0 +1,244 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.klp.ems.mapper.WmsEnergyCoilDailyMapper">
|
||||
|
||||
<resultMap id="WmsEnergyCoilDailyResult" type="com.klp.ems.domain.WmsEnergyCoilDaily">
|
||||
<result property="energyCostId" column="energy_cost_id"/>
|
||||
<result property="taskId" column="task_id"/>
|
||||
<result property="calcDate" column="calc_date"/>
|
||||
<result property="coilId" column="coil_id"/>
|
||||
<result property="enterCoilNo" column="enter_coil_no"/>
|
||||
<result property="currentCoilNo" column="current_coil_no"/>
|
||||
<result property="warehouseId" column="warehouse_id"/>
|
||||
<result property="actualWarehouseId" column="actual_warehouse_id"/>
|
||||
<result property="energyTypeId" column="energy_type_id"/>
|
||||
<result property="meterId" column="meter_id"/>
|
||||
<result property="consumptionQty" column="consumption_qty"/>
|
||||
<result property="costAmount" column="cost_amount"/>
|
||||
<result property="allocationBasisWeight" column="allocation_basis_weight"/>
|
||||
<result property="allocationBasisDays" column="allocation_basis_days"/>
|
||||
<result property="allocationFactor" column="allocation_factor"/>
|
||||
<result property="remark" column="remark"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
</resultMap>
|
||||
|
||||
<delete id="deleteByTaskId" parameterType="long">
|
||||
DELETE FROM wms_energy_coil_daily WHERE task_id = #{taskId}
|
||||
</delete>
|
||||
|
||||
<select id="selectListByTask" resultMap="WmsEnergyCoilDailyResult" parameterType="long">
|
||||
SELECT * FROM wms_energy_coil_daily WHERE task_id = #{taskId}
|
||||
</select>
|
||||
|
||||
<sql id="ReportWhere">
|
||||
<where>
|
||||
<if test="bo != null and bo.taskId != null">
|
||||
AND c.task_id = #{bo.taskId}
|
||||
</if>
|
||||
<if test="bo != null and bo.energyTypeId != null">
|
||||
AND c.energy_type_id = #{bo.energyTypeId}
|
||||
</if>
|
||||
<if test="bo != null and bo.meterId != null">
|
||||
AND c.meter_id = #{bo.meterId}
|
||||
</if>
|
||||
<if test="bo != null and bo.warehouseId != null">
|
||||
AND c.warehouse_id = #{bo.warehouseId}
|
||||
</if>
|
||||
<if test="bo != null and bo.actualWarehouseId != null">
|
||||
AND c.actual_warehouse_id = #{bo.actualWarehouseId}
|
||||
</if>
|
||||
<if test="bo != null and bo.startDate != null">
|
||||
AND c.calc_date <![CDATA[>=]]> #{bo.startDate}
|
||||
</if>
|
||||
<if test="bo != null and bo.endDate != null">
|
||||
AND c.calc_date <![CDATA[<=]]> #{bo.endDate}
|
||||
</if>
|
||||
<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 c.current_coil_no LIKE CONCAT('%', #{bo.currentCoilNo}, '%')
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<select id="summaryByEnergyType" parameterType="com.klp.ems.domain.bo.EnergyCostReportBo"
|
||||
resultType="com.klp.ems.domain.vo.EnergyCostSummaryVo">
|
||||
SELECT
|
||||
CAST(c.energy_type_id AS CHAR) AS groupKey,
|
||||
COALESCE(et.name, CONCAT('能源-', c.energy_type_id)) AS groupName,
|
||||
c.energy_type_id,
|
||||
SUM(c.consumption_qty) AS totalConsumption,
|
||||
SUM(c.cost_amount) AS totalCost,
|
||||
COUNT(DISTINCT c.coil_id) AS coilCount
|
||||
FROM wms_energy_coil_daily c
|
||||
LEFT JOIN ems_energy_type et ON c.energy_type_id = et.energy_type_id
|
||||
<include refid="ReportWhere"/>
|
||||
GROUP BY c.energy_type_id
|
||||
ORDER BY totalCost DESC
|
||||
</select>
|
||||
|
||||
<select id="summaryByWarehouse" parameterType="com.klp.ems.domain.bo.EnergyCostReportBo"
|
||||
resultType="com.klp.ems.domain.vo.EnergyCostSummaryVo">
|
||||
SELECT
|
||||
CAST(c.warehouse_id AS CHAR) AS groupKey,
|
||||
COALESCE(wh.warehouse_name, CONCAT('库区-', c.warehouse_id)) AS groupName,
|
||||
c.warehouse_id,
|
||||
c.actual_warehouse_id,
|
||||
SUM(c.consumption_qty) AS totalConsumption,
|
||||
SUM(c.cost_amount) AS totalCost,
|
||||
COUNT(DISTINCT c.coil_id) AS coilCount
|
||||
FROM wms_energy_coil_daily c
|
||||
LEFT JOIN wms_warehouse wh ON c.warehouse_id = wh.warehouse_id
|
||||
<include refid="ReportWhere"/>
|
||||
GROUP BY c.warehouse_id, c.actual_warehouse_id
|
||||
ORDER BY totalCost DESC
|
||||
</select>
|
||||
|
||||
<select id="summaryByMeter" parameterType="com.klp.ems.domain.bo.EnergyCostReportBo"
|
||||
resultType="com.klp.ems.domain.vo.EnergyCostSummaryVo">
|
||||
SELECT
|
||||
CAST(c.meter_id AS CHAR) AS groupKey,
|
||||
COALESCE(m.meter_code, CONCAT('计量表-', c.meter_id)) AS groupName,
|
||||
c.meter_id,
|
||||
c.energy_type_id,
|
||||
SUM(c.consumption_qty) AS totalConsumption,
|
||||
SUM(c.cost_amount) AS totalCost,
|
||||
COUNT(DISTINCT c.coil_id) AS coilCount
|
||||
FROM wms_energy_coil_daily c
|
||||
LEFT JOIN ems_meter m ON c.meter_id = m.meter_id
|
||||
<include refid="ReportWhere"/>
|
||||
GROUP BY c.meter_id, c.energy_type_id
|
||||
ORDER BY totalCost DESC
|
||||
</select>
|
||||
|
||||
<select id="summaryByTask" parameterType="com.klp.ems.domain.bo.EnergyCostReportBo"
|
||||
resultType="com.klp.ems.domain.vo.EnergyCostSummaryVo">
|
||||
SELECT
|
||||
CAST(c.task_id AS CHAR) AS groupKey,
|
||||
CONCAT('任务-', c.task_id) AS groupName,
|
||||
c.task_id,
|
||||
c.energy_type_id,
|
||||
SUM(c.consumption_qty) AS totalConsumption,
|
||||
SUM(c.cost_amount) AS totalCost,
|
||||
COUNT(DISTINCT c.coil_id) AS coilCount
|
||||
FROM wms_energy_coil_daily c
|
||||
<include refid="ReportWhere"/>
|
||||
GROUP BY c.task_id, c.energy_type_id
|
||||
ORDER BY c.task_id DESC
|
||||
</select>
|
||||
|
||||
<select id="selectEnergyOverview" parameterType="com.klp.ems.domain.bo.EnergyCostReportBo"
|
||||
resultType="java.util.Map">
|
||||
SELECT
|
||||
COUNT(DISTINCT c.coil_id) AS coilCount,
|
||||
SUM(c.consumption_qty) AS totalConsumption,
|
||||
SUM(c.cost_amount) AS totalCost
|
||||
FROM wms_energy_coil_daily c
|
||||
<include refid="ReportWhere"/>
|
||||
</select>
|
||||
|
||||
<!-- 查询待操作钢卷的能源成本(按钢卷维度聚合,综合所有能源类型) -->
|
||||
<select id="selectPendingActionCoilCost" resultType="com.klp.ems.domain.vo.WmsEnergyCoilDailyVo">
|
||||
SELECT
|
||||
pa.coil_id AS coilId,
|
||||
pa.current_coil_no AS currentCoilNo,
|
||||
c.enter_coil_no AS enterCoilNo,
|
||||
pa.warehouse_id AS warehouseId,
|
||||
wh.warehouse_name AS warehouseName,
|
||||
pa.create_time AS scanTime,
|
||||
COALESCE(pa.complete_time, NOW()) AS completeTime,
|
||||
TIMESTAMPDIFF(MINUTE, pa.create_time, COALESCE(pa.complete_time, NOW())) AS productionDuration,
|
||||
SUM(COALESCE(ec.consumption, 0)) AS consumptionQty,
|
||||
SUM(COALESCE(ec.consumption, 0) * COALESCE(er.rate, 0)) AS costAmount,
|
||||
CAST(1.0 AS DECIMAL(10, 6)) AS allocationFactor
|
||||
FROM wms_coil_pending_action pa
|
||||
LEFT JOIN wms_material_coil c ON pa.coil_id = c.coil_id
|
||||
LEFT JOIN wms_warehouse wh ON pa.warehouse_id = wh.warehouse_id
|
||||
LEFT JOIN ems_energy_consumption ec ON ec.end_time BETWEEN pa.create_time AND COALESCE(pa.complete_time, NOW())
|
||||
LEFT JOIN ems_meter m ON ec.meter_id = m.meter_id
|
||||
LEFT JOIN ems_energy_type et ON m.energy_type_id = et.energy_type_id
|
||||
LEFT JOIN ems_energy_rate er ON et.energy_type_id = er.energy_type_id
|
||||
AND er.effective_date <![CDATA[<=]]> CURDATE()
|
||||
AND (er.expiry_date IS NULL OR er.expiry_date <![CDATA[>=]]> CURDATE())
|
||||
WHERE pa.action_status IN (0, 1, 2)
|
||||
AND pa.warehouse_id IS NOT NULL
|
||||
GROUP BY pa.coil_id, pa.current_coil_no, c.enter_coil_no, pa.warehouse_id, wh.warehouse_name, pa.create_time, pa.complete_time
|
||||
ORDER BY pa.warehouse_id, pa.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 查询待操作钢卷的能源成本统计 -->
|
||||
<select id="selectPendingActionCoilCostStatistics" resultType="com.klp.ems.domain.vo.WmsEnergyCoilDailyStatisticsVo">
|
||||
SELECT
|
||||
COUNT(DISTINCT t.coil_id) AS totalCoils,
|
||||
SUM(t.total_consumption) AS totalConsumption,
|
||||
SUM(t.total_cost) AS totalCost,
|
||||
SUM(t.production_duration) AS totalProductionDuration,
|
||||
CASE
|
||||
WHEN SUM(t.production_duration) > 0
|
||||
THEN SUM(t.total_cost) / (SUM(t.production_duration) / 60.0)
|
||||
ELSE 0
|
||||
END AS avgUnitCost
|
||||
FROM (
|
||||
SELECT
|
||||
pa.coil_id,
|
||||
pa.current_coil_no,
|
||||
c.enter_coil_no,
|
||||
pa.warehouse_id,
|
||||
wh.warehouse_name,
|
||||
pa.create_time,
|
||||
COALESCE(pa.complete_time, NOW()) AS complete_time,
|
||||
TIMESTAMPDIFF(MINUTE, pa.create_time, COALESCE(pa.complete_time, NOW())) AS production_duration,
|
||||
SUM(COALESCE(ec.consumption, 0)) AS total_consumption,
|
||||
SUM(COALESCE(ec.consumption, 0) * COALESCE(er.rate, 0)) AS total_cost
|
||||
FROM wms_coil_pending_action pa
|
||||
LEFT JOIN wms_material_coil c ON pa.coil_id = c.coil_id
|
||||
LEFT JOIN wms_warehouse wh ON pa.warehouse_id = wh.warehouse_id
|
||||
LEFT JOIN ems_energy_consumption ec ON ec.end_time BETWEEN pa.create_time AND COALESCE(pa.complete_time, NOW())
|
||||
LEFT JOIN ems_meter m ON ec.meter_id = m.meter_id
|
||||
LEFT JOIN ems_energy_type et ON m.energy_type_id = et.energy_type_id
|
||||
LEFT JOIN ems_energy_rate er ON et.energy_type_id = er.energy_type_id
|
||||
AND er.effective_date <![CDATA[<=]]> CURDATE()
|
||||
AND (er.expiry_date IS NULL OR er.expiry_date <![CDATA[>=]]> CURDATE())
|
||||
WHERE pa.action_status IN (0, 1, 2)
|
||||
AND pa.warehouse_id IS NOT NULL
|
||||
<if test="enterCoilNo != null and enterCoilNo != ''">
|
||||
AND c.enter_coil_no LIKE CONCAT('%', #{enterCoilNo}, '%')
|
||||
</if>
|
||||
<if test="currentCoilNo != null and currentCoilNo != ''">
|
||||
AND pa.current_coil_no LIKE CONCAT('%', #{currentCoilNo}, '%')
|
||||
</if>
|
||||
<if test="warehouseId != null">
|
||||
AND pa.warehouse_id = #{warehouseId}
|
||||
</if>
|
||||
GROUP BY pa.coil_id, pa.current_coil_no, c.enter_coil_no, pa.warehouse_id, wh.warehouse_name, pa.create_time, pa.complete_time
|
||||
) t
|
||||
</select>
|
||||
|
||||
<select id="selectReportDetail" resultType="com.klp.ems.domain.vo.WmsEnergyCoilDailyVo">
|
||||
SELECT
|
||||
c.energy_cost_id AS energyCostId,
|
||||
c.task_id AS taskId,
|
||||
c.calc_date AS calcDate,
|
||||
c.coil_id AS coilId,
|
||||
c.enter_coil_no AS enterCoilNo,
|
||||
c.current_coil_no AS currentCoilNo,
|
||||
c.warehouse_id AS warehouseId,
|
||||
c.actual_warehouse_id AS actualWarehouseId,
|
||||
c.energy_type_id AS energyTypeId,
|
||||
c.meter_id AS meterId,
|
||||
c.consumption_qty AS consumptionQty,
|
||||
c.cost_amount AS costAmount,
|
||||
c.allocation_basis_weight AS allocationBasisWeight,
|
||||
c.allocation_basis_days AS allocationBasisDays,
|
||||
c.allocation_factor AS allocationFactor,
|
||||
c.remark AS remark
|
||||
FROM wms_energy_coil_daily c
|
||||
<include refid="ReportWhere"/>
|
||||
ORDER BY c.calc_date DESC, c.energy_cost_id DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user