Files
klp-oa/klp-ems/src/main/resources/mapper/EmsRateTierPeriodLinkMapper.xml

106 lines
4.0 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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.EmsRateTierPeriodLinkMapper">
<resultMap type="com.klp.ems.domain.EmsRateTierPeriodLink" id="EmsRateTierPeriodLinkResult">
<result property="linkId" column="link_id"/>
<result property="tierId" column="tier_id"/>
<result property="periodId" column="period_id"/>
<result property="rate" column="rate"/>
<result property="createBy" column="create_by"/>
<result property="updateBy" column="update_by"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="delFlag" column="del_flag"/>
<result property="remark" column="remark"/>
</resultMap>
<resultMap type="com.klp.ems.domain.vo.EmsRateTierPeriodLinkVo" id="EmsRateTierPeriodLinkVoResult">
<result property="linkId" column="link_id"/>
<result property="tierId" column="tier_id"/>
<result property="tierLevel" column="tier_level"/>
<result property="minUsage" column="min_usage"/>
<result property="maxUsage" column="max_usage"/>
<result property="periodId" column="period_id"/>
<result property="periodName" column="period_name"/>
<result property="periodType" column="period_type"/>
<result property="startTime" column="start_time"/>
<result property="endTime" column="end_time"/>
<result property="rate" column="rate"/>
<result property="createTime" column="create_time"/>
<result property="remark" column="remark"/>
</resultMap>
<!-- 根据梯度ID查询所有关联的时段费率 -->
<select id="selectByTierId" parameterType="long" resultMap="EmsRateTierPeriodLinkResult">
SELECT *
FROM ems_tier_period_link
WHERE tier_id = #{tierId}
AND del_flag = '0'
ORDER BY period_id
</select>
<!-- 根据梯度ID删除所有关联的时段费率逻辑删除 -->
<delete id="deleteByTierId" parameterType="long">
UPDATE ems_tier_period_link
SET del_flag = '2'
WHERE tier_id = #{tierId}
</delete>
<!-- 根据梯度ID物理删除所有关联的时段费率 -->
<delete id="deleteByTierIdPhysical" parameterType="long">
DELETE FROM ems_tier_period_link
WHERE tier_id = #{tierId}
</delete>
<!-- 根据费率ID删除所有关联的梯度-时段费率(逻辑删除) -->
<delete id="deleteByEnergyRateId" parameterType="long">
UPDATE ems_tier_period_link tpl
SET tpl.del_flag = '2'
WHERE tpl.tier_id IN (
SELECT tier_id
FROM ems_rate_tier
WHERE energy_rate_id = #{energyRateId}
)
</delete>
<!-- 根据费率ID物理删除所有关联的梯度-时段费率 -->
<delete id="deleteByEnergyRateIdPhysical" parameterType="long">
DELETE FROM ems_tier_period_link
WHERE tier_id IN (
SELECT tier_id
FROM ems_rate_tier
WHERE energy_rate_id = #{energyRateId}
)
</delete>
<!-- 查询梯度-时段关联的完整信息 -->
<select id="selectVoByEnergyRateId" parameterType="long" resultMap="EmsRateTierPeriodLinkVoResult">
SELECT
tpl.link_id,
tpl.tier_id,
rt.tier_level,
rt.min_usage,
rt.max_usage,
tpl.period_id,
tp.period_name,
tp.period_type,
tp.start_time,
tp.end_time,
tpl.rate,
tpl.create_time,
tpl.remark
FROM ems_tier_period_link tpl
JOIN ems_rate_tier rt ON tpl.tier_id = rt.tier_id
JOIN ems_time_period tp ON tpl.period_id = tp.period_id
WHERE rt.energy_rate_id = #{energyRateId}
AND tpl.del_flag = '0'
AND rt.del_flag = '0'
AND tp.del_flag = '0'
ORDER BY rt.tier_level, tp.period_type
</select>
</mapper>