<?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.simuwang.base.mapper.EmailTemplateDataRuleMapper">
    <resultMap id="BaseResultMap" type="com.simuwang.base.pojo.dos.EmailTemplateDataRuleDO">
        <id column="id" property="id"/>
        <result column="template_id" property="templateId"/>
        <result column="field_name" property="fieldName"/>
        <result column="position" property="position"/>
        <result column="row" property="row"/>
        <result column="column" property="column"/>
        <result column="field_rule" property="fieldRule"/>
        <result column="unit_convert" property="unitConvert"/>
        <result column="isvalid" property="isvalid"/>
        <result column="creatorid" property="creatorId"/>
        <result column="createtime" property="createTime"/>
        <result column="updaterid" property="updaterId"/>
        <result column="updatetime" property="updateTime"/>
    </resultMap>
    <insert id="batchInsert">
        insert into PPW_EMAIL.email_template_data_rule(template_id,field_name,`POSITION`,`ROW`,`COLUMN`,field_rule,unit_convert,isvalid,creatorid,createtime,updaterid,updatetime)
        values
        <foreach collection="itemDoList" item="itemDo" index="index" separator=",">
            (#{itemDo.templateId},#{itemDo.fieldName},#{itemDo.position},#{itemDo.row},#{itemDo.column},#{itemDo.fieldRule},#{itemDo.unitConvert},
            #{itemDo.isvalid}, #{itemDo.creatorId}, #{itemDo.createTime}, #{itemDo.updaterId}, #{itemDo.updateTime})
        </foreach>
    </insert>
    <update id="batchUpdate">
        <foreach collection="itemDoList" item="itemDo" index="index" open="" close="" separator=";">
            update PPW_EMAIL.email_template_data_rule
            <set>
                template_id = #{itemDo.templateId},
                field_name = #{itemDo.fieldName},
                `POSITION` = #{itemDo.position},
                `ROW` = #{itemDo.row},
                `COLUMN` = #{itemDo.column},
                field_rule = #{itemDo.fieldRule},
                unit_convert = #{itemDo.unitConvert},
                updatetime = #{itemDo.updateTime},
                updaterid = #{itemDo.updaterId}
            </set>
            where isvalid = 1 and id=#{itemDo.id}
        </foreach>
    </update>
    <update id="deleteByTemplateId">
        update PPW_EMAIL.email_template_data_rule set isvalid=0,updatetime=sysdate(),updaterid=#{userId}
        where isvalid=1 and template_id in
        <foreach collection="templateIdList" index="index" item="templateId" open="(" separator="," close=")">
            #{templateId}
        </foreach>
    </update>

    <select id="queryByTemplateId" resultMap="BaseResultMap">
        select *
        from PPW_EMAIL.email_template_data_rule
        where isvalid = 1
        and template_id in
        <foreach collection="templateIdList" index="index" item="templateId" open="(" separator="," close=")">
            #{templateId}
        </foreach>
    </select>
</mapper>