2025-10-10 16:10:37 +08:00
|
|
|
<?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.xzzn.ems.mapper.EmsDailyEnergyDataMapper">
|
|
|
|
|
|
|
|
|
|
<resultMap type="EmsDailyEnergyData" id="EmsDailyEnergyDataResult">
|
|
|
|
|
<result property="id" column="id" />
|
|
|
|
|
<result property="siteId" column="site_id" />
|
|
|
|
|
<result property="dataDate" column="data_date" />
|
2025-10-12 19:47:55 +08:00
|
|
|
<result property="totalRevenue" column="total_revenue" />
|
|
|
|
|
<result property="dayRevenue" column="day_revenue" />
|
2025-10-10 16:10:37 +08:00
|
|
|
<result property="peakChargeDiff" column="peak_charge_diff" />
|
|
|
|
|
<result property="peakDischargeDiff" column="peak_discharge_diff" />
|
|
|
|
|
<result property="highChargeDiff" column="high_charge_diff" />
|
|
|
|
|
<result property="highDischargeDiff" column="high_discharge_diff" />
|
|
|
|
|
<result property="flatChargeDiff" column="flat_charge_diff" />
|
|
|
|
|
<result property="flatDischargeDiff" column="flat_discharge_diff" />
|
|
|
|
|
<result property="valleyChargeDiff" column="valley_charge_diff" />
|
|
|
|
|
<result property="valleyDischargeDiff" column="valley_discharge_diff" />
|
|
|
|
|
<result property="calcTime" column="calc_time" />
|
|
|
|
|
<result property="createBy" column="create_by" />
|
|
|
|
|
<result property="createTime" column="create_time" />
|
|
|
|
|
<result property="updateBy" column="update_by" />
|
|
|
|
|
<result property="updateTime" column="update_time" />
|
|
|
|
|
<result property="remark" column="remark" />
|
|
|
|
|
</resultMap>
|
|
|
|
|
|
|
|
|
|
<sql id="selectEmsDailyEnergyDataVo">
|
2025-10-12 19:47:55 +08:00
|
|
|
select id, site_id, data_date, total_revenue, day_revenue, peak_charge_diff, peak_discharge_diff, high_charge_diff, high_discharge_diff, flat_charge_diff, flat_discharge_diff, valley_charge_diff, valley_discharge_diff, calc_time, create_by, create_time, update_by, update_time, remark from ems_daily_energy_data
|
2025-10-10 16:10:37 +08:00
|
|
|
</sql>
|
|
|
|
|
|
|
|
|
|
<select id="selectEmsDailyEnergyDataList" parameterType="EmsDailyEnergyData" resultMap="EmsDailyEnergyDataResult">
|
|
|
|
|
<include refid="selectEmsDailyEnergyDataVo"/>
|
|
|
|
|
<where>
|
|
|
|
|
<if test="siteId != null and siteId != ''"> and site_id = #{siteId}</if>
|
|
|
|
|
<if test="dataDate != null "> and data_date = #{dataDate}</if>
|
2025-10-12 19:47:55 +08:00
|
|
|
<if test="totalRevenue != null "> and total_revenue = #{totalRevenue}</if>
|
|
|
|
|
<if test="dayRevenue != null "> and day_revenue = #{dayRevenue}</if>
|
2025-10-10 16:10:37 +08:00
|
|
|
<if test="peakChargeDiff != null "> and peak_charge_diff = #{peakChargeDiff}</if>
|
|
|
|
|
<if test="peakDischargeDiff != null "> and peak_discharge_diff = #{peakDischargeDiff}</if>
|
|
|
|
|
<if test="highChargeDiff != null "> and high_charge_diff = #{highChargeDiff}</if>
|
|
|
|
|
<if test="highDischargeDiff != null "> and high_discharge_diff = #{highDischargeDiff}</if>
|
|
|
|
|
<if test="flatChargeDiff != null "> and flat_charge_diff = #{flatChargeDiff}</if>
|
|
|
|
|
<if test="flatDischargeDiff != null "> and flat_discharge_diff = #{flatDischargeDiff}</if>
|
|
|
|
|
<if test="valleyChargeDiff != null "> and valley_charge_diff = #{valleyChargeDiff}</if>
|
|
|
|
|
<if test="valleyDischargeDiff != null "> and valley_discharge_diff = #{valleyDischargeDiff}</if>
|
|
|
|
|
<if test="calcTime != null "> and calc_time = #{calcTime}</if>
|
|
|
|
|
</where>
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<select id="selectEmsDailyEnergyDataById" parameterType="Long" resultMap="EmsDailyEnergyDataResult">
|
|
|
|
|
<include refid="selectEmsDailyEnergyDataVo"/>
|
|
|
|
|
where id = #{id}
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<insert id="insertEmsDailyEnergyData" parameterType="EmsDailyEnergyData" useGeneratedKeys="true" keyProperty="id">
|
|
|
|
|
insert into ems_daily_energy_data
|
|
|
|
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
|
|
|
<if test="siteId != null">site_id,</if>
|
|
|
|
|
<if test="dataDate != null">data_date,</if>
|
2025-10-12 19:47:55 +08:00
|
|
|
<if test="totalRevenue != null">total_revenue,</if>
|
|
|
|
|
<if test="dayRevenue != null">day_revenue,</if>
|
2025-10-10 16:10:37 +08:00
|
|
|
<if test="peakChargeDiff != null">peak_charge_diff,</if>
|
|
|
|
|
<if test="peakDischargeDiff != null">peak_discharge_diff,</if>
|
|
|
|
|
<if test="highChargeDiff != null">high_charge_diff,</if>
|
|
|
|
|
<if test="highDischargeDiff != null">high_discharge_diff,</if>
|
|
|
|
|
<if test="flatChargeDiff != null">flat_charge_diff,</if>
|
|
|
|
|
<if test="flatDischargeDiff != null">flat_discharge_diff,</if>
|
|
|
|
|
<if test="valleyChargeDiff != null">valley_charge_diff,</if>
|
|
|
|
|
<if test="valleyDischargeDiff != null">valley_discharge_diff,</if>
|
|
|
|
|
<if test="calcTime != null">calc_time,</if>
|
|
|
|
|
<if test="createBy != null">create_by,</if>
|
|
|
|
|
<if test="createTime != null">create_time,</if>
|
|
|
|
|
<if test="updateBy != null">update_by,</if>
|
|
|
|
|
<if test="updateTime != null">update_time,</if>
|
|
|
|
|
<if test="remark != null">remark,</if>
|
|
|
|
|
</trim>
|
|
|
|
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
|
|
|
<if test="siteId != null">#{siteId},</if>
|
|
|
|
|
<if test="dataDate != null">#{dataDate},</if>
|
2025-10-12 19:47:55 +08:00
|
|
|
<if test="totalRevenue != null">#{totalRevenue},</if>
|
|
|
|
|
<if test="dayRevenue != null">#{dayRevenue},</if>
|
2025-10-10 16:10:37 +08:00
|
|
|
<if test="peakChargeDiff != null">#{peakChargeDiff},</if>
|
|
|
|
|
<if test="peakDischargeDiff != null">#{peakDischargeDiff},</if>
|
|
|
|
|
<if test="highChargeDiff != null">#{highChargeDiff},</if>
|
|
|
|
|
<if test="highDischargeDiff != null">#{highDischargeDiff},</if>
|
|
|
|
|
<if test="flatChargeDiff != null">#{flatChargeDiff},</if>
|
|
|
|
|
<if test="flatDischargeDiff != null">#{flatDischargeDiff},</if>
|
|
|
|
|
<if test="valleyChargeDiff != null">#{valleyChargeDiff},</if>
|
|
|
|
|
<if test="valleyDischargeDiff != null">#{valleyDischargeDiff},</if>
|
|
|
|
|
<if test="calcTime != null">#{calcTime},</if>
|
|
|
|
|
<if test="createBy != null">#{createBy},</if>
|
|
|
|
|
<if test="createTime != null">#{createTime},</if>
|
|
|
|
|
<if test="updateBy != null">#{updateBy},</if>
|
|
|
|
|
<if test="updateTime != null">#{updateTime},</if>
|
|
|
|
|
<if test="remark != null">#{remark},</if>
|
|
|
|
|
</trim>
|
|
|
|
|
</insert>
|
|
|
|
|
|
|
|
|
|
<update id="updateEmsDailyEnergyData" parameterType="EmsDailyEnergyData">
|
|
|
|
|
update ems_daily_energy_data
|
|
|
|
|
<trim prefix="SET" suffixOverrides=",">
|
|
|
|
|
<if test="siteId != null">site_id = #{siteId},</if>
|
|
|
|
|
<if test="dataDate != null">data_date = #{dataDate},</if>
|
2025-10-12 19:47:55 +08:00
|
|
|
<if test="totalRevenue != null">total_revenue = #{totalRevenue},</if>
|
|
|
|
|
<if test="dayRevenue != null">day_revenue = #{dayRevenue},</if>
|
2025-10-10 16:10:37 +08:00
|
|
|
<if test="peakChargeDiff != null">peak_charge_diff = #{peakChargeDiff},</if>
|
|
|
|
|
<if test="peakDischargeDiff != null">peak_discharge_diff = #{peakDischargeDiff},</if>
|
|
|
|
|
<if test="highChargeDiff != null">high_charge_diff = #{highChargeDiff},</if>
|
|
|
|
|
<if test="highDischargeDiff != null">high_discharge_diff = #{highDischargeDiff},</if>
|
|
|
|
|
<if test="flatChargeDiff != null">flat_charge_diff = #{flatChargeDiff},</if>
|
|
|
|
|
<if test="flatDischargeDiff != null">flat_discharge_diff = #{flatDischargeDiff},</if>
|
|
|
|
|
<if test="valleyChargeDiff != null">valley_charge_diff = #{valleyChargeDiff},</if>
|
|
|
|
|
<if test="valleyDischargeDiff != null">valley_discharge_diff = #{valleyDischargeDiff},</if>
|
|
|
|
|
<if test="calcTime != null">calc_time = #{calcTime},</if>
|
|
|
|
|
<if test="createBy != null">create_by = #{createBy},</if>
|
|
|
|
|
<if test="createTime != null">create_time = #{createTime},</if>
|
|
|
|
|
<if test="updateBy != null">update_by = #{updateBy},</if>
|
|
|
|
|
<if test="updateTime != null">update_time = #{updateTime},</if>
|
|
|
|
|
<if test="remark != null">remark = #{remark},</if>
|
|
|
|
|
</trim>
|
|
|
|
|
where id = #{id}
|
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
<delete id="deleteEmsDailyEnergyDataById" parameterType="Long">
|
|
|
|
|
delete from ems_daily_energy_data where id = #{id}
|
|
|
|
|
</delete>
|
|
|
|
|
|
|
|
|
|
<delete id="deleteEmsDailyEnergyDataByIds" parameterType="String">
|
|
|
|
|
delete from ems_daily_energy_data where id in
|
|
|
|
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
|
|
|
|
#{id}
|
|
|
|
|
</foreach>
|
|
|
|
|
</delete>
|
|
|
|
|
|
|
|
|
|
<select id="getDataByDate" parameterType="String" resultMap="EmsDailyEnergyDataResult">
|
|
|
|
|
<include refid="selectEmsDailyEnergyDataVo"/>
|
|
|
|
|
where data_date = #{today}
|
|
|
|
|
AND site_id = #{siteId}
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<insert id="insertOrUpdateData" parameterType="com.xzzn.ems.domain.EmsDailyEnergyData"
|
|
|
|
|
useGeneratedKeys="true" keyProperty="id">
|
|
|
|
|
INSERT INTO ems_daily_energy_data (
|
|
|
|
|
id, site_id, data_date,
|
2025-10-12 19:47:55 +08:00
|
|
|
<if test="totalRevenue != null">total_revenue,</if>
|
|
|
|
|
<if test="dayRevenue != null">day_revenue,</if>
|
2025-10-10 16:10:37 +08:00
|
|
|
<if test="peakChargeDiff != null">peak_charge_diff,</if>
|
|
|
|
|
<if test="peakDischargeDiff != null">peak_discharge_diff,</if>
|
|
|
|
|
<if test="highChargeDiff != null">high_charge_diff,</if>
|
|
|
|
|
<if test="highDischargeDiff != null">high_discharge_diff,</if>
|
|
|
|
|
<if test="flatChargeDiff != null">flat_charge_diff,</if>
|
|
|
|
|
<if test="flatDischargeDiff != null">flat_discharge_diff,</if>
|
|
|
|
|
<if test="valleyChargeDiff != null">valley_charge_diff,</if>
|
|
|
|
|
<if test="valleyDischargeDiff != null">valley_discharge_diff,</if>
|
|
|
|
|
calc_time,
|
|
|
|
|
create_by,
|
|
|
|
|
create_time,
|
|
|
|
|
update_by,
|
|
|
|
|
update_time,
|
|
|
|
|
remark
|
|
|
|
|
) VALUES (
|
|
|
|
|
#{id},
|
|
|
|
|
#{siteId},
|
|
|
|
|
#{dataDate},
|
2025-10-12 19:47:55 +08:00
|
|
|
<if test="totalRevenue != null">#{totalRevenue},</if>
|
|
|
|
|
<if test="dayRevenue != null">#{dayRevenue},</if>
|
2025-10-10 16:10:37 +08:00
|
|
|
<if test="peakChargeDiff != null">#{peakChargeDiff},</if>
|
|
|
|
|
<if test="peakDischargeDiff != null">#{peakDischargeDiff},</if>
|
|
|
|
|
<if test="highChargeDiff != null">#{highChargeDiff},</if>
|
|
|
|
|
<if test="highDischargeDiff != null">#{highDischargeDiff},</if>
|
|
|
|
|
<if test="flatChargeDiff != null">#{flatChargeDiff},</if>
|
|
|
|
|
<if test="flatDischargeDiff != null">#{flatDischargeDiff},</if>
|
|
|
|
|
<if test="valleyChargeDiff != null">#{valleyChargeDiff},</if>
|
|
|
|
|
<if test="valleyDischargeDiff != null">#{valleyDischargeDiff},</if>
|
|
|
|
|
#{calcTime},
|
|
|
|
|
'system',
|
|
|
|
|
NOW(),
|
|
|
|
|
'system',
|
|
|
|
|
NOW(),
|
|
|
|
|
#{remark}
|
|
|
|
|
) ON DUPLICATE KEY UPDATE
|
2025-10-12 19:47:55 +08:00
|
|
|
<if test="totalRevenue != null">total_revenue = #{totalRevenue},</if>
|
|
|
|
|
<if test="dayRevenue != null">day_revenue = #{dayRevenue},</if>
|
2025-10-10 16:10:37 +08:00
|
|
|
<if test="peakChargeDiff != null">peak_charge_diff = #{peakChargeDiff},</if>
|
|
|
|
|
<if test="peakDischargeDiff != null">peak_discharge_diff = #{peakDischargeDiff},</if>
|
|
|
|
|
<if test="highChargeDiff != null">high_charge_diff = #{highChargeDiff},</if>
|
|
|
|
|
<if test="highDischargeDiff != null">high_discharge_diff = #{highDischargeDiff},</if>
|
|
|
|
|
<if test="flatChargeDiff != null">flat_charge_diff = #{flatChargeDiff},</if>
|
|
|
|
|
<if test="flatDischargeDiff != null">flat_discharge_diff = #{flatDischargeDiff},</if>
|
|
|
|
|
<if test="valleyChargeDiff != null">valley_charge_diff = #{valleyChargeDiff},</if>
|
|
|
|
|
<if test="valleyDischargeDiff != null">valley_discharge_diff = #{valleyDischargeDiff},</if>
|
|
|
|
|
calc_time = #{calcTime},
|
|
|
|
|
update_time = NOW();
|
|
|
|
|
</insert>
|
2025-10-10 17:32:15 +08:00
|
|
|
|
|
|
|
|
<select id="getDataBySiteId" resultType="com.xzzn.ems.domain.vo.AmmeterStatisListVo">
|
|
|
|
|
select t.data_date as dataTime,
|
|
|
|
|
t.peak_charge_diff as activePeakKwh,
|
|
|
|
|
t.peak_discharge_diff as reActivePeakKwh,
|
|
|
|
|
t.high_charge_diff as activeHighKwh,
|
|
|
|
|
t.high_discharge_diff as reActiveHighKwh,
|
|
|
|
|
t.flat_charge_diff as activeFlatKwh,
|
|
|
|
|
t.flat_discharge_diff as reActiveFlatKwh,
|
|
|
|
|
t.valley_charge_diff as activeValleyKwh,
|
|
|
|
|
t.valley_discharge_diff as reActiveValleyKwh
|
|
|
|
|
from ems_daily_energy_data t
|
|
|
|
|
where 1=1
|
|
|
|
|
<if test="siteId != null">
|
|
|
|
|
and t.site_id = #{siteId}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="startTime != null">
|
|
|
|
|
and t.data_date >= #{startTime}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="endTime != null">
|
2025-10-12 19:47:55 +08:00
|
|
|
and t.data_date <= #{endTime}
|
2025-10-10 17:32:15 +08:00
|
|
|
</if>
|
|
|
|
|
</select>
|
2025-10-12 19:47:55 +08:00
|
|
|
|
|
|
|
|
<select id="getLastTotalRevenue" resultType="java.math.BigDecimal">
|
|
|
|
|
select t.total_revenue
|
|
|
|
|
from ems_daily_energy_data t
|
|
|
|
|
where t.site_id = #{siteId}
|
|
|
|
|
and t.data_date < CURDATE()
|
|
|
|
|
order by t.data_date desc limit 1
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<select id="getRealTimeRevenue" resultType="java.util.Map">
|
|
|
|
|
select t.total_revenue as totalRevenue, t.day_revenue as dayRevenue
|
|
|
|
|
from ems_daily_energy_data t
|
|
|
|
|
where t.site_id = #{siteId}
|
|
|
|
|
order by t.data_date desc limit 1
|
|
|
|
|
</select>
|
2025-12-23 15:43:53 +08:00
|
|
|
|
|
|
|
|
<select id="getRevenueDataBySiteId" resultType="com.xzzn.ems.domain.vo.AmmeterRevenueStatisListVo">
|
|
|
|
|
select
|
|
|
|
|
t.data_date as dataTime,
|
2026-01-22 14:30:52 +08:00
|
|
|
ROUND(t.peak_charge_diff * pc.peak, 3) as activePeakPrice,
|
|
|
|
|
ROUND(t.peak_discharge_diff * pc.peak, 3) as reActivePeakPrice,
|
|
|
|
|
ROUND(t.high_charge_diff * pc.high, 3) as activeHighPrice,
|
|
|
|
|
ROUND(t.high_discharge_diff * pc.high, 3) as reActiveHighPrice,
|
|
|
|
|
ROUND(t.flat_charge_diff * pc.flat, 3) as activeFlatPrice,
|
|
|
|
|
ROUND(t.flat_discharge_diff * pc.flat, 3) as reActiveFlatPrice,
|
|
|
|
|
ROUND(t.valley_charge_diff * pc.valley, 3) as activeValleyPrice,
|
|
|
|
|
ROUND(t.valley_discharge_diff * pc.valley, 3) as reActiveValleyPrice
|
2025-12-23 15:43:53 +08:00
|
|
|
from ems_daily_energy_data t
|
|
|
|
|
left join (
|
|
|
|
|
select
|
|
|
|
|
id, site_id, peak, high, flat, valley,
|
|
|
|
|
CONCAT(year, '-', LPAD(month, 2, '0')) as yearMonth
|
|
|
|
|
from ems_energy_price_config
|
|
|
|
|
where 1=1
|
|
|
|
|
<if test="siteId != null">
|
|
|
|
|
and site_id = #{siteId}
|
|
|
|
|
</if>
|
|
|
|
|
order by year, month
|
|
|
|
|
) pc on pc.yearMonth = DATE_FORMAT(t.data_date, '%Y-%m')
|
|
|
|
|
where 1=1
|
|
|
|
|
<if test="siteId != null">
|
|
|
|
|
and t.site_id = #{siteId}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="startTime != null">
|
|
|
|
|
and t.data_date >= #{startTime}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="endTime != null">
|
|
|
|
|
and t.data_date <= #{endTime}
|
|
|
|
|
</if>
|
|
|
|
|
|
|
|
|
|
</select>
|
2025-10-10 16:10:37 +08:00
|
|
|
</mapper>
|