<?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.ruoyi.project.check.mapper.TCheckLawitemsMapper">

    <resultMap type="TCheckLawitems" id="TCheckLawitemsResult">
        <result property="id" column="id"/>
        <result property="lawId" column="law_id"/>
        <result property="plantType" column="plant_type"/>
        <result property="pointType" column="point_type"/>
        <result property="mediumType" column="medium_type"/>
        <result property="general" column="general"/>
        <result property="serious" column="serious"/>
        <result property="detectionFrequency" column="detection_frequency"/>
        <result property="stratFix" column="strat_fix"/>
        <result property="endFix" column="end_fix"/>
        <result property="remarks" column="remarks"/>
        <result property="deptId" column="dept_id"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createrCode" column="creater_code"/>
        <result property="createdate" column="createdate"/>
        <result property="updaterCode" column="updater_code"/>
        <result property="updatedate" column="updatedate"/>
    </resultMap>

    <sql id="selectTCheckLawitemsVo">
        select d.id,
               d.law_id,
               d.plant_type,
               d.point_type,
               d.medium_type,
               d.`general`,
               d.serious,
               d.detection_frequency,
               d.strat_fix,
               d.end_fix,
               d.remarks,
               d.dept_id,
               d.del_flag,
               d.creater_code,
               d.createdate,
               d.updater_code,
               d.updatedate,
               su.user_name updater
        from t_check_lawitems d
        left join sys_user su on su.user_id=d.updater_code
    </sql>

    <select id="selectTCheckLawitemsByLawStatus" resultMap="TCheckLawitemsResult">
        select d.* from  t_check_lawitems d
        left join t_check_laws cl on cl.id=d.law_id where cl.status=1;
    </select>

    <select id="selectTCheckLawitemsList" parameterType="TCheckLawitems" resultMap="TCheckLawitemsResult">
        <include refid="selectTCheckLawitemsVo"/>
        <where>
            <if test="lawId != null  and lawId != ''">and d.law_id = #{lawId}</if>
            <if test="plantType != null  and plantType != ''">and d.plant_type = #{plantType}</if>
            <if test="pointType != null  and pointType != ''">and d.point_type = #{pointType}</if>
            <if test="mediumType != null  and mediumType != ''">and d.medium_type = #{mediumType}</if>
            <if test="general != null  and general != ''">and d.`general` = #{general}</if>
            <if test="serious != null  and serious != ''">and d.serious = #{serious}</if>
            <if test="detectionFrequency != null  and detectionFrequency != ''">and d.detection_frequency =
                #{detectionFrequency}
            </if>
            <if test="stratFix != null  and stratFix != ''">and d.strat_fix = #{stratFix}</if>
            <if test="endFix != null  and endFix != ''">and d.end_fix = #{endFix}</if>
            <if test="remarks != null  and remarks != ''">and d.remarks = #{remarks}</if>
            <if test="deptId != null ">and d.dept_id = #{deptId}</if>
            <if test="createrCode != null ">and d.creater_code = #{createrCode}</if>
            <if test="createdate != null ">and d.createdate = #{createdate}</if>
            <if test="updaterCode != null ">and d.updater_code = #{updaterCode}</if>
            <if test="updatedate != null ">and d.updatedate = #{updatedate}</if>
            and d.del_flag = 0
        </where>
    </select>

    <select id="selectTCheckLawitemsById" parameterType="Long" resultMap="TCheckLawitemsResult">
        <include refid="selectTCheckLawitemsVo"/>
        where d.id = #{id}
    </select>

    <insert id="insertTCheckLawitems" parameterType="TCheckLawitems" useGeneratedKeys="true" keyProperty="id">
        insert into t_check_lawitems
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="lawId != null">law_id,</if>
            <if test="plantType != null">plant_type,</if>
            <if test="pointType != null">point_type,</if>
            <if test="mediumType != null">medium_type,</if>
            <if test="general != null">`general`,</if>
            <if test="serious != null">serious,</if>
            <if test="detectionFrequency != null">detection_frequency,</if>
            <if test="stratFix != null">strat_fix,</if>
            <if test="endFix != null">end_fix,</if>
            <if test="remarks != null">remarks,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="lawId != null">#{lawId},</if>
            <if test="plantType != null">#{plantType},</if>
            <if test="pointType != null">#{pointType},</if>
            <if test="mediumType != null">#{mediumType},</if>
            <if test="general != null">#{general},</if>
            <if test="serious != null">#{serious},</if>
            <if test="detectionFrequency != null">#{detectionFrequency},</if>
            <if test="stratFix != null">#{stratFix},</if>
            <if test="endFix != null">#{endFix},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
        </trim>
    </insert>

    <insert id="insertTCheckLawitemsByList" parameterType="java.util.List" useGeneratedKeys="true">
        insert into t_check_lawitems
        <trim prefix="(" suffix=")" suffixOverrides=",">
            law_id,
            plant_type,
            point_type,
            medium_type,
            `general`,
            serious,
            detection_frequency,
            strat_fix,
            end_fix,
            creater_code,
            createdate,
            updater_code,
            updatedate,
        </trim>
        values
        <foreach collection="list" index="index" separator="," item="item">
            <trim prefix="(" suffix=")" suffixOverrides=",">
                #{item.lawId},
                #{item.plantType},
                #{item.pointType},
                #{item.mediumType},
                #{item.general},
                #{item.serious},
                #{item.detectionFrequency},
                #{item.stratFix},
                #{item.endFix},
                #{item.createrCode},
                #{item.createdate},
                #{item.updaterCode},
                #{item.updatedate},
            </trim>
        </foreach>
    </insert>

    <update id="updateTCheckLawitems" parameterType="TCheckLawitems">
        update t_check_lawitems
        <trim prefix="SET" suffixOverrides=",">
            <if test="lawId != null">law_id = #{lawId},</if>
            <if test="plantType != null">plant_type = #{plantType},</if>
            <if test="pointType != null">point_type = #{pointType},</if>
            <if test="mediumType != null">medium_type = #{mediumType},</if>
            <if test="general != null">`general` = #{general},</if>
            <if test="serious != null">serious = #{serious},</if>
            <if test="detectionFrequency != null">detection_frequency = #{detectionFrequency},</if>
            <if test="stratFix != null">strat_fix = #{stratFix},</if>
            <if test="endFix != null">end_fix = #{endFix},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTCheckLawitemsById" parameterType="Long">
        update t_check_lawitems
        set del_flag=1
        where id = #{id}
    </delete>

    <delete id="deleteTCheckLawitemsByIds" parameterType="String">
        update t_check_lawitems set del_flag=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
