Files
emsback/ems-system/src/main/resources/mapper/ems/EmsEnergyPriceConfigMapper.xml

180 lines
7.6 KiB
XML
Raw Normal View History

2025-10-09 19:58:50 +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.EmsEnergyPriceConfigMapper">
<resultMap type="EmsEnergyPriceConfig" id="EmsEnergyPriceConfigResult">
<result property="id" column="id" />
2025-10-11 16:28:50 +08:00
<result property="siteId" column="site_id" />
2025-10-09 19:58:50 +08:00
<result property="year" column="year" />
<result property="month" column="month" />
<result property="peak" column="peak" />
<result property="high" column="high" />
<result property="flat" column="flat" />
<result property="valley" column="valley" />
<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="selectEmsEnergyPriceConfigVo">
2025-10-11 16:28:50 +08:00
select id, site_id, year, month, peak, high, flat, valley, create_by, create_time, update_by, update_time, remark from ems_energy_price_config
2025-10-09 19:58:50 +08:00
</sql>
<select id="selectEmsEnergyPriceConfigList" parameterType="EmsEnergyPriceConfig" resultMap="EmsEnergyPriceConfigResult">
<include refid="selectEmsEnergyPriceConfigVo"/>
<where>
2025-10-11 16:28:50 +08:00
<if test="siteId != null and siteId != ''"> and site_id = #{siteId}</if>
2025-10-09 19:58:50 +08:00
<if test="year != null and year != ''"> and year = #{year}</if>
<if test="month != null and month != ''"> and month = #{month}</if>
<if test="peak != null "> and peak = #{peak}</if>
<if test="high != null "> and high = #{high}</if>
<if test="flat != null "> and flat = #{flat}</if>
<if test="valley != null "> and valley = #{valley}</if>
</where>
</select>
<select id="selectEmsEnergyPriceConfigById" parameterType="Long" resultMap="EmsEnergyPriceConfigResult">
<include refid="selectEmsEnergyPriceConfigVo"/>
where id = #{id}
</select>
<insert id="insertEmsEnergyPriceConfig" parameterType="EmsEnergyPriceConfig" useGeneratedKeys="true" keyProperty="id">
insert into ems_energy_price_config
<trim prefix="(" suffix=")" suffixOverrides=",">
2025-10-11 16:28:50 +08:00
<if test="siteId != null">site_id,</if>
2025-10-09 19:58:50 +08:00
<if test="year != null and year != ''">year,</if>
<if test="month != null and month != ''">month,</if>
<if test="peak != null">peak,</if>
<if test="high != null">high,</if>
<if test="flat != null">flat,</if>
<if test="valley != null">valley,</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=",">
2025-10-11 16:28:50 +08:00
<if test="siteId != null">#{siteId},</if>
2025-10-09 19:58:50 +08:00
<if test="year != null and year != ''">#{year},</if>
<if test="month != null and month != ''">#{month},</if>
<if test="peak != null">#{peak},</if>
<if test="high != null">#{high},</if>
<if test="flat != null">#{flat},</if>
<if test="valley != null">#{valley},</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="updateEmsEnergyPriceConfig" parameterType="EmsEnergyPriceConfig">
update ems_energy_price_config
<trim prefix="SET" suffixOverrides=",">
2025-10-11 16:28:50 +08:00
<if test="siteId != null">site_id = #{siteId},</if>
2025-10-09 19:58:50 +08:00
<if test="year != null and year != ''">year = #{year},</if>
<if test="month != null and month != ''">month = #{month},</if>
<if test="peak != null">peak = #{peak},</if>
<if test="high != null">high = #{high},</if>
<if test="flat != null">flat = #{flat},</if>
<if test="valley != null">valley = #{valley},</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="deleteEmsEnergyPriceConfigById" parameterType="Long">
delete from ems_energy_price_config where id = #{id}
</delete>
<delete id="deleteEmsEnergyPriceConfigByIds" parameterType="String">
delete from ems_energy_price_config where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="getCurrentYearConfigList" resultMap="EmsEnergyPriceConfigResult">
<include refid="selectEmsEnergyPriceConfigVo"/>
<where>
year = #{currentYear}
2025-10-11 16:28:50 +08:00
<if test="siteId != null and siteId != ''">
and site_id = #{siteId}
</if>
2025-10-09 19:58:50 +08:00
</where>
</select>
<insert id="insertOrUpdateEmsEnergyPriceConfig" parameterType="com.xzzn.ems.domain.EmsEnergyPriceConfig"
useGeneratedKeys="true" keyProperty="id">
INSERT INTO ems_energy_price_config (
id,
2025-10-11 16:28:50 +08:00
site_id,
2025-10-09 19:58:50 +08:00
year,
month,
peak,
high,
flat,
valley,
create_by,
create_time,
update_by,
update_time,
remark
) VALUES (
#{id},
2025-10-11 16:28:50 +08:00
#{siteId},
2025-10-09 19:58:50 +08:00
#{year},
#{month},
#{peak},
#{high},
#{flat},
#{valley},
'system',
NOW(),
'system',
NOW(),
#{remark}
) ON DUPLICATE KEY UPDATE
peak = #{peak},
high = #{high},
flat = #{flat},
valley = #{valley},
update_time = NOW();
</insert>
<select id="getConfigListByYearAndMonth" resultMap="EmsEnergyPriceConfigResult">
<include refid="selectEmsEnergyPriceConfigVo"/>
2025-10-11 16:28:50 +08:00
where site_id = #{siteId}
and year = #{currentYear}
2025-10-09 19:58:50 +08:00
and month = #{month}
</select>
<select id="getTimeRangeByDate" resultType="com.xzzn.ems.domain.vo.EnergyPriceTimeRange">
select t2.cost_type as costType,
t2.start_time as startTime,
t2.end_time as endTime
from ems_energy_price_config t
left join ems_price_time_config t2 on t.id = t2.price_id
2025-10-11 16:28:50 +08:00
where t.site_id = #{siteId}
and t.`year` = #{currentYear}
and t.`month` = #{currentMonth}
</select>
<select id="getAllSitePriceConfig" resultMap="EmsEnergyPriceConfigResult">
select t.*
from ems_energy_price_config t
LEFT JOIN ems_site_setting t2 on t.site_id = t2.site_id
where t.`year` = #{currentYear}
and t.`month` = #{currentMonth}
</select>
2025-10-09 19:58:50 +08:00
</mapper>