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

137 lines
7.1 KiB
XML
Raw Normal View History

2025-06-28 14:56:22 +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.EmsAmmeterDataMapper">
<resultMap type="EmsAmmeterData" id="EmsAmmeterDataResult">
<result property="id" column="id" />
<result property="dataUpdateTime" column="data_update_time" />
<result property="category" column="category" />
<result property="totalKwh" column="total_kwh" />
2025-06-29 10:55:05 +08:00
<result property="sharpKwh" column="sharp_kwh" />
2025-06-28 14:56:22 +08:00
<result property="peakKwh" column="peak_kwh" />
<result property="flatKwh" column="flat_kwh" />
<result property="valleyKwh" column="valley_kwh" />
<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" />
<result property="siteId" column="site_id" />
<result property="deviceId" column="device_id" />
</resultMap>
<sql id="selectEmsAmmeterDataVo">
2025-06-29 10:55:05 +08:00
select id, data_update_time, category, total_kwh, sharp_kwh, peak_kwh, flat_kwh, valley_kwh, create_by, create_time, update_by, update_time, remark, site_id, device_id from ems_ammeter_data
2025-06-28 14:56:22 +08:00
</sql>
<select id="selectEmsAmmeterDataList" parameterType="EmsAmmeterData" resultMap="EmsAmmeterDataResult">
<include refid="selectEmsAmmeterDataVo"/>
<where>
<if test="dataUpdateTime != null "> and data_update_time = #{dataUpdateTime}</if>
<if test="category != null and category != ''"> and category = #{category}</if>
<if test="totalKwh != null "> and total_kwh = #{totalKwh}</if>
2025-06-29 10:55:05 +08:00
<if test="sharpKwh != null "> and sharp_kwh = #{sharpKwh}</if>
2025-06-28 14:56:22 +08:00
<if test="peakKwh != null "> and peak_kwh = #{peakKwh}</if>
<if test="flatKwh != null "> and flat_kwh = #{flatKwh}</if>
<if test="valleyKwh != null "> and valley_kwh = #{valleyKwh}</if>
2025-06-29 10:55:05 +08:00
<if test="siteId != null and siteId != ''"> and site_id = #{siteId}</if>
<if test="deviceId != null and deviceId != ''"> and device_id = #{deviceId}</if>
2025-06-28 14:56:22 +08:00
</where>
</select>
<select id="selectEmsAmmeterDataById" parameterType="Long" resultMap="EmsAmmeterDataResult">
<include refid="selectEmsAmmeterDataVo"/>
where id = #{id}
</select>
<insert id="insertEmsAmmeterData" parameterType="EmsAmmeterData" useGeneratedKeys="true" keyProperty="id">
insert into ems_ammeter_data
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="dataUpdateTime != null">data_update_time,</if>
<if test="category != null">category,</if>
<if test="totalKwh != null">total_kwh,</if>
2025-06-29 10:55:05 +08:00
<if test="sharpKwh != null">sharp_kwh,</if>
2025-06-28 14:56:22 +08:00
<if test="peakKwh != null">peak_kwh,</if>
<if test="flatKwh != null">flat_kwh,</if>
<if test="valleyKwh != null">valley_kwh,</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>
<if test="siteId != null">site_id,</if>
2025-06-29 10:55:05 +08:00
<if test="deviceId != null and deviceId != ''">device_id,</if>
2025-06-28 14:56:22 +08:00
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="dataUpdateTime != null">#{dataUpdateTime},</if>
<if test="category != null">#{category},</if>
<if test="totalKwh != null">#{totalKwh},</if>
2025-06-29 10:55:05 +08:00
<if test="sharpKwh != null">#{sharpKwh},</if>
2025-06-28 14:56:22 +08:00
<if test="peakKwh != null">#{peakKwh},</if>
<if test="flatKwh != null">#{flatKwh},</if>
<if test="valleyKwh != null">#{valleyKwh},</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>
<if test="siteId != null">#{siteId},</if>
2025-06-29 10:55:05 +08:00
<if test="deviceId != null and deviceId != ''">#{deviceId},</if>
2025-06-28 14:56:22 +08:00
</trim>
</insert>
<update id="updateEmsAmmeterData" parameterType="EmsAmmeterData">
update ems_ammeter_data
<trim prefix="SET" suffixOverrides=",">
<if test="dataUpdateTime != null">data_update_time = #{dataUpdateTime},</if>
<if test="category != null">category = #{category},</if>
<if test="totalKwh != null">total_kwh = #{totalKwh},</if>
2025-06-29 10:55:05 +08:00
<if test="sharpKwh != null">sharp_kwh = #{sharpKwh},</if>
2025-06-28 14:56:22 +08:00
<if test="peakKwh != null">peak_kwh = #{peakKwh},</if>
<if test="flatKwh != null">flat_kwh = #{flatKwh},</if>
<if test="valleyKwh != null">valley_kwh = #{valleyKwh},</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>
<if test="siteId != null">site_id = #{siteId},</if>
2025-06-29 10:55:05 +08:00
<if test="deviceId != null and deviceId != ''">device_id = #{deviceId},</if>
2025-06-28 14:56:22 +08:00
</trim>
where id = #{id}
</update>
<delete id="deleteEmsAmmeterDataById" parameterType="Long">
delete from ems_ammeter_data where id = #{id}
</delete>
<delete id="deleteEmsAmmeterDataByIds" parameterType="String">
delete from ems_ammeter_data where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
2025-06-29 10:55:05 +08:00
<select id="getAmmeterDetailInfo" parameterType="String" resultType="com.xzzn.ems.domain.vo.AmmeterDataDetailInfo">
2025-06-30 13:11:05 +08:00
SELECT t.category as category,
2025-06-28 14:56:22 +08:00
t.total_kwh as totalKwh,
2025-06-29 10:55:05 +08:00
t.sharp_kwh as sharpKwh,
2025-06-28 14:56:22 +08:00
t.flat_kwh as flatKwh,
t.peak_kwh as peakKwh,
t.valley_kwh as valleyKwh,
t.device_id as deviceId,
Max(t.data_update_time) as updateTime
2025-06-30 13:11:05 +08:00
FROM ems_ammeter_data t
INNER JOIN (
SELECT p.site_id, p.device_id,p.category,MAX(p.data_update_time) AS max_update_time
FROM ems_ammeter_data p
WHERE p.site_id = #{siteId}
GROUP BY p.site_id,p.device_id,p.category
) latest on t.device_id = latest.device_id and t.data_update_time = latest.max_update_time
WHERE t.site_id = #{siteId}
group by t.category,t.total_kwh,t.sharp_kwh,t.flat_kwh,t.peak_kwh,t.valley_kwh,t.device_id
2025-06-28 14:56:22 +08:00
order by updateTime desc
</select>
</mapper>