l3能源成本分摊(部分完成留存)

This commit is contained in:
2025-12-07 17:23:47 +08:00
parent b6328a94da
commit 59951b77c3
100 changed files with 14350 additions and 847 deletions

View File

@@ -101,4 +101,66 @@
</if>
</select>
<select id="selectLatestBefore" resultMap="EmsEnergyConsumptionResult">
SELECT *
FROM ems_energy_consumption
WHERE meter_id = #{meterId}
AND end_time &lt;= #{endTime}
ORDER BY end_time DESC
LIMIT 1
</select>
<select id="selectOverlapRange" resultMap="EmsEnergyConsumptionResult">
SELECT *
FROM ems_energy_consumption
WHERE meter_id = #{meterId}
AND end_time &gt;= #{startTime}
AND start_time &lt;= #{endTime}
ORDER BY start_time ASC
</select>
<select id="selectCoveringRange" resultMap="EmsEnergyConsumptionResult">
SELECT *
FROM ems_energy_consumption
WHERE meter_id = #{meterId}
AND start_time &lt;= #{startTime}
AND end_time &gt;= #{endTime}
ORDER BY start_time ASC
LIMIT 1
</select>
<select id="selectLatestTwoReadings" resultMap="EmsEnergyConsumptionResult">
SELECT *
FROM ems_energy_consumption
WHERE meter_id = #{meterId}
ORDER BY end_time DESC
LIMIT 2
</select>
<!-- 统计查询 -->
<select id="getStatistics" parameterType="com.klp.ems.domain.bo.EmsEnergyConsumptionBo" resultType="java.util.Map">
SELECT
COUNT(*) AS totalCount,
IFNULL(SUM(consumption), 0) AS totalConsumption,
IFNULL(AVG(consumption), 0) AS avgConsumption,
IFNULL(MAX(consumption), 0) AS maxConsumption,
IFNULL(MIN(consumption), 0) AS minConsumption
FROM ems_energy_consumption
WHERE 1=1
<if test="meterId != null">
AND meter_id = #{meterId}
</if>
<if test="energyTypeId != null">
AND meter_id IN (
SELECT meter_id FROM ems_meter WHERE energy_type_id = #{energyTypeId}
)
</if>
<if test="startTime != null">
AND start_time &gt;= #{startTime}
</if>
<if test="endTime != null">
AND end_time &lt;= #{endTime}
</if>
</select>
</mapper>