Files
jsowell-charger-web/jsowell-pile/src/main/resources/mapper/pile/PileBillingTemplateMapper.xml
2023-06-25 17:16:14 +08:00

503 lines
20 KiB
XML

<?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.jsowell.pile.mapper.PileBillingTemplateMapper">
<resultMap type="com.jsowell.pile.domain.PileBillingTemplate" id="PileBillingTemplateResult">
<result property="id" column="id"/>
<result property="templateCode" column="template_code"/>
<result property="name" column="name"/>
<result property="status" column="status"/>
<result property="remark" column="remark"/>
<result property="type" column="type"/>
<result property="stationId" column="station_id"/>
<result property="publicFlag" column="public_flag"/>
<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="delFlag" column="del_flag"/>
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated PileBillingTemplate-->
id, template_code, name, status, remark, type, station_id, public_flag,
create_time, update_by, update_time, del_flag
</sql>
<resultMap type="com.jsowell.pile.domain.PileBillingDetail" id="PileBillingDetailResult">
<result property="id" column="id"/>
<result property="templateCode" column="template_code"/>
<result property="timeType" column="time_type"/>
<result property="electricityPrice" column="electricity_price"/>
<result property="servicePrice" column="service_price"/>
<result property="applyTime" column="apply_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="delFlag" column="del_flag"/>
</resultMap>
<sql id="Detail_Base_Column_List">
<!--@mbg.generated PileBillingDetail-->
id, template_code, time_type, electricity_price, service_price, apply_time, create_by,
create_time, update_by, update_time, del_flag
</sql>
<resultMap id="PileBillingTemplatePileBillingDetailResult" type="com.jsowell.pile.domain.PileBillingTemplate"
extends="PileBillingTemplateResult">
<collection property="pileBillingDetailList" ofType="com.jsowell.pile.domain.PileBillingDetail" javaType="java.util.List">
<id property="id" column="sub_id"/>
<result property="templateCode" column="sub_template_code"/>
<result property="timeType" column="sub_time_type"/>
<result property="electricityPrice" column="sub_electricity_price"/>
<result property="servicePrice" column="sub_service_price"/>
<result property="applyTime" column="sub_apply_time"/>
<result property="createBy" column="sub_create_by"/>
<result property="createTime" column="sub_create_time"/>
<result property="updateBy" column="sub_update_by"/>
<result property="updateTime" column="sub_update_time"/>
<result property="delFlag" column="sub_del_flag"/>
</collection>
</resultMap>
<sql id="selectPileBillingTemplateVo">
select
<include refid="Base_Column_List" />
from pile_billing_template
</sql>
<select id="selectPileBillingTemplateList" parameterType="com.jsowell.pile.domain.PileBillingTemplate"
resultMap="PileBillingTemplateResult">
<include refid="selectPileBillingTemplateVo"/>
<where>
<if test="publicFlag != null and publicFlag != ''">
and public_flag = #{publicFlag,jdbcType=VARCHAR}
</if>
</where>
</select>
<select id="selectPileBillingTemplateById" parameterType="Long"
resultMap="PileBillingTemplatePileBillingDetailResult">
select a.id as id,
a.template_code,
a.name,
a.remark,
a.type,
a.station_id,
a.create_by,
a.create_time,
a.update_by,
a.update_time,
a.del_flag,
b.id as sub_id,
b.template_code as sub_template_code,
b.time_type as sub_time_type,
b.electricity_price as sub_electricity_price,
b.service_price as sub_service_price,
b.apply_time as sub_apply_time,
b.create_by as sub_create_by,
b.create_time as sub_create_time,
b.update_by as sub_update_by,
b.update_time as sub_update_time,
b.del_flag as sub_del_flag
from pile_billing_template a
left join pile_billing_detail b on b.template_code = a.template_code
where a.id = #{id}
</select>
<insert id="insertPileBillingTemplate" parameterType="com.jsowell.pile.domain.PileBillingTemplate"
useGeneratedKeys="true" keyProperty="id">
insert into pile_billing_template
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="templateCode != null">
template_code,
</if>
<if test="publicFlag != null">
public_flag,
</if>
<if test="name != null">
name,
</if>
<if test="status != null">
status,
</if>
<if test="remark != null">
remark,
</if>
<if test="type != null">
type,
</if>
<if test="stationId != null">
station_id,
</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="delFlag != null">
del_flag,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="templateCode != null">
#{templateCode},
</if>
<if test="publicFlag != null">
#{publicFlag},
</if>
<if test="name != null">
#{name},
</if>
<if test="status!= null">
#{status},
</if>
<if test="remark != null">
#{remark},
</if>
<if test="type != null">
#{type},
</if>
<if test="stationId != null">
#{stationId},
</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="delFlag != null">
#{delFlag},
</if>
</trim>
</insert>
<update id="updatePileBillingTemplate" parameterType="com.jsowell.pile.domain.PileBillingTemplate">
update pile_billing_template
<trim prefix="SET" suffixOverrides=",">
<if test="templateCode != null">
template_code = #{templateCode},
</if>
<if test="publicFlag != null">
public_flag = #{publicFlag},
</if>
<if test="name != null">
name = #{name},
</if>
<if test="status != null">
status = #{status},
</if>
<if test="remark != null">
remark = #{remark},
</if>
<if test="type != null">
type = #{type},
</if>
<if test="stationId != null">
station_id = #{stationId},
</if>
<if test="publishTime != null">
publish_time = #{publishTime},
</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="delFlag != null">
del_flag = #{delFlag},
</if>
</trim>
where id = #{id}
</update>
<delete id="deletePileBillingTemplateById" parameterType="Long">
delete
from pile_billing_template
where id = #{id}
</delete>
<delete id="deletePileBillingTemplateByIds" parameterType="String">
delete
from pile_billing_template where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<delete id="deletePileBillingDetailByTemplateCodes" parameterType="String">
delete
from pile_billing_detail
where template_code in
<foreach item="templateCode" collection="templateCodes" open="(" separator="," close=")">
#{templateCode}
</foreach>
</delete>
<delete id="deletePileBillingDetailByTemplateCode" parameterType="String">
delete
from pile_billing_detail
where template_code = #{templateCode}
</delete>
<insert id="batchPileBillingDetail">
insert into pile_billing_detail
(id, template_code, time_type, electricity_price, service_price, apply_time,
create_by, update_by)
values
<foreach item="item" index="index" collection="list" separator=",">
(#{item.id}, #{item.templateCode}, #{item.timeType}, #{item.electricityPrice}, #{item.servicePrice},
#{item.applyTime}, #{item.createBy}, #{item.updateBy})
</foreach>
</insert>
<select id="queryPublicBillingTemplateList" resultType="com.jsowell.pile.vo.web.BillingTemplateVO">
select
t.id as templateId,
t.template_code as templateCode,
t.name as templateName
from
pile_billing_template t
where
t.del_flag = '0'
and t.public_flag = '1'
</select>
<select id="queryStationBillingTemplateList" resultType="com.jsowell.pile.vo.web.BillingTemplateVO">
select
t2.id as templateId,
t2.template_code as templateCode,
t2.name as templateName,
t2.status,
t2.remark as remark,
t2.type as deviceType,
t2.publish_time as publishTime,
t3.electricity_price AS sharpElectricityPrice,
t3.service_price AS sharpServicePrice,
t3.apply_time AS sharpApplyDate,
t4.electricity_price AS peakElectricityPrice,
t4.service_price AS peakServicePrice,
t4.apply_time AS peakApplyDate,
t5.electricity_price AS flatElectricityPrice,
t5.service_price AS flatServicePrice,
t5.apply_time AS flatApplyDate,
t6.electricity_price AS valleyElectricityPrice,
t6.service_price AS valleyServicePrice,
t6.apply_time AS valleyApplyDate
from
pile_billing_template t2
left join pile_station_info t1 on t1.id = t2.station_id
left JOIN pile_billing_detail t3 ON t3.template_code = t2.template_code AND t3.time_type = '1'
left JOIN pile_billing_detail t4 ON t4.template_code = t2.template_code AND t4.time_type = '2'
left JOIN pile_billing_detail t5 ON t5.template_code = t2.template_code AND t5.time_type = '3'
left JOIN pile_billing_detail t6 ON t6.template_code = t2.template_code AND t6.time_type = '4'
where
t2.del_flag = '0'
and t2.station_id = #{stationId,jdbcType=VARCHAR}
<!--数据范围过滤-->
<if test="stationDeptIds != null and stationDeptIds.size() != 0">
and t1.dept_id in
<foreach collection="stationDeptIds" item="stationDeptId" open="(" separator="," close=")">
#{stationDeptId,jdbcType=VARCHAR}
</foreach>
</if>
order by t2.publish_time desc
</select>
<select id="selectBillingTemplateByPileSn" resultType="com.jsowell.pile.vo.web.BillingTemplateVO">
SELECT
t2.id as templateId,
t2.template_code AS templateCode,
t2.`name` AS templateName,
t3.electricity_price AS sharpElectricityPrice,
t3.service_price AS sharpServicePrice,
t3.apply_time AS sharpApplyDate,
t4.electricity_price AS peakElectricityPrice,
t4.service_price AS peakServicePrice,
t4.apply_time AS peakApplyDate,
t5.electricity_price AS flatElectricityPrice,
t5.service_price AS flatServicePrice,
t5.apply_time AS flatApplyDate,
t6.electricity_price AS valleyElectricityPrice,
t6.service_price AS valleyServicePrice,
t6.apply_time AS valleyApplyDate
FROM
pile_billing_relation t1
JOIN pile_billing_template t2 ON t1.billing_template_code = t2.template_code
JOIN pile_billing_detail t3 ON t3.template_code = t2.template_code AND t3.time_type = '1'
JOIN pile_billing_detail t4 ON t4.template_code = t2.template_code AND t4.time_type = '2'
JOIN pile_billing_detail t5 ON t5.template_code = t2.template_code AND t5.time_type = '3'
JOIN pile_billing_detail t6 ON t6.template_code = t2.template_code AND t6.time_type = '4'
WHERE
t1.pile_sn = #{pileSn,jdbcType=VARCHAR};
</select>
<select id="selectBillingTemplateByTemplateId" resultType="com.jsowell.pile.vo.web.BillingTemplateVO">
SELECT
t2.id as templateId,
t2.template_code AS templateCode,
t2.`name` AS templateName,
t3.electricity_price AS sharpElectricityPrice,
t3.service_price AS sharpServicePrice,
t3.apply_time AS sharpApplyDate,
t4.electricity_price AS peakElectricityPrice,
t4.service_price AS peakServicePrice,
t4.apply_time AS peakApplyDate,
t5.electricity_price AS flatElectricityPrice,
t5.service_price AS flatServicePrice,
t5.apply_time AS flatApplyDate,
t6.electricity_price AS valleyElectricityPrice,
t6.service_price AS valleyServicePrice,
t6.apply_time AS valleyApplyDate
FROM
pile_billing_template t2
left JOIN pile_billing_detail t3 ON t3.template_code = t2.template_code AND t3.time_type = '1'
left JOIN pile_billing_detail t4 ON t4.template_code = t2.template_code AND t4.time_type = '2'
left JOIN pile_billing_detail t5 ON t5.template_code = t2.template_code AND t5.time_type = '3'
left JOIN pile_billing_detail t6 ON t6.template_code = t2.template_code AND t6.time_type = '4'
WHERE
t2.id = #{templateId,jdbcType=VARCHAR};
</select>
<select id="queryBillingDetailByTemplateIds" resultMap="PileBillingDetailResult">
SELECT
t1.id,
t1.template_code,
t1.time_type,
t1.electricity_price,
t1.service_price,
t1.apply_time,
t1.create_by,
t1.create_time,
t1.update_by,
t1.update_time,
t1.del_flag
FROM pile_billing_detail t1
JOIN pile_billing_template t2 ON t2.template_code = t1.template_code
WHERE t2.id in
<foreach collection="templateIds" item="templateId" open="(" separator="," close=")">
#{templateId,jdbcType=BIGINT}
</foreach>
</select>
<select id="queryBillingDetailByTemplateId" resultMap="PileBillingDetailResult">
SELECT
t1.id,
t1.template_code,
t1.time_type,
t1.electricity_price,
t1.service_price,
t1.apply_time,
t1.create_by,
t1.create_time,
t1.update_by,
t1.update_time,
t1.del_flag
FROM pile_billing_detail t1
JOIN pile_billing_template t2 ON t2.template_code = t1.template_code
WHERE t2.id = #{templateId,jdbcType=BIGINT}
</select>
<insert id="insertPileBillingRelation">
insert into pile_billing_relation
(pile_sn, billing_template_code, station_id)
values
<foreach item="item" index="index" collection="list" separator=",">
(#{item.pileSn}, #{item.billingTemplateCode}, #{item.stationId})
</foreach>
</insert>
<delete id="deleteRelationByPileSn">
delete
from pile_billing_relation
where pile_sn in
<foreach collection="pileSnList" item="pileSn" open="(" separator="," close=")">
#{pileSn,jdbcType=VARCHAR}
</foreach>
</delete>
<select id="selectBillingTemplateByStationId" resultType="com.jsowell.pile.vo.web.BillingTemplateVO">
SELECT
t2.id as templateId,
t2.template_code AS templateCode,
t2.`name` AS templateName,
t3.electricity_price AS sharpElectricityPrice,
t3.service_price AS sharpServicePrice,
t3.apply_time AS sharpApplyDate,
t4.electricity_price AS peakElectricityPrice,
t4.service_price AS peakServicePrice,
t4.apply_time AS peakApplyDate,
t5.electricity_price AS flatElectricityPrice,
t5.service_price AS flatServicePrice,
t5.apply_time AS flatApplyDate,
t6.electricity_price AS valleyElectricityPrice,
t6.service_price AS valleyServicePrice,
t6.apply_time AS valleyApplyDate
FROM
pile_billing_template t2
left JOIN pile_billing_detail t3 ON t3.template_code = t2.template_code AND t3.time_type = '1'
left JOIN pile_billing_detail t4 ON t4.template_code = t2.template_code AND t4.time_type = '2'
left JOIN pile_billing_detail t5 ON t5.template_code = t2.template_code AND t5.time_type = '3'
left JOIN pile_billing_detail t6 ON t6.template_code = t2.template_code AND t6.time_type = '4'
WHERE
t2.station_id = #{stationId,jdbcType=VARCHAR}
order by t2.publish_time DESC
limit 1
</select>
<select id="queryStationBillingTemplateListForUniApp" resultType="com.jsowell.pile.vo.web.BillingTemplateVO">
select
t2.id as templateId,
t2.template_code as templateCode,
t2.name as templateName,
t2.remark as remark,
t2.type as deviceType,
t2.publish_time as publishTime,
t3.electricity_price AS sharpElectricityPrice,
t3.service_price AS sharpServicePrice,
t3.apply_time AS sharpApplyDate,
t4.electricity_price AS peakElectricityPrice,
t4.service_price AS peakServicePrice,
t4.apply_time AS peakApplyDate,
t5.electricity_price AS flatElectricityPrice,
t5.service_price AS flatServicePrice,
t5.apply_time AS flatApplyDate,
t6.electricity_price AS valleyElectricityPrice,
t6.service_price AS valleyServicePrice,
t6.apply_time AS valleyApplyDate
from
pile_billing_template t2
left join pile_station_info t1 on t1.id = t2.station_id
left JOIN pile_billing_detail t3 ON t3.template_code = t2.template_code AND t3.time_type = '1'
left JOIN pile_billing_detail t4 ON t4.template_code = t2.template_code AND t4.time_type = '2'
left JOIN pile_billing_detail t5 ON t5.template_code = t2.template_code AND t5.time_type = '3'
left JOIN pile_billing_detail t6 ON t6.template_code = t2.template_code AND t6.time_type = '4'
where
t2.del_flag = '0'
and t2.station_id = #{stationId,jdbcType=VARCHAR}
order by t2.publish_time desc
</select>
</mapper>