<?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.TCheckLawsMapper">

    <resultMap type="TCheckLaws" id="TCheckLawsResult">
        <result property="id"    column="id"    />
        <result property="code"    column="code"    />
        <result property="name"    column="name"    />
        <result property="type"    column="type"    />
        <result property="status"    column="status"    />
        <result property="starttime"    column="starttime"    />
        <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="selectTCheckLawsVo">
        select id, code, name, type, status, starttime, remarks, dept_id, del_flag, creater_code, createdate, updater_code, updatedate from t_check_laws
    </sql>

    <select id="selectTCheckLawsList" parameterType="TCheckLaws" resultMap="TCheckLawsResult">
        select id, code, name, type, d.status, starttime, remarks, d.dept_id, d.del_flag, creater_code, createdate, updater_code , updatedate,su.user_name updater from t_check_laws d
        left join sys_user su on su.user_id=d.updater_code
        <where>
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="status != null  and status != ''"> and d.status = #{status}</if>
            <if test="starttime != null "> and starttime = #{starttime}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="deptId != null "> and d.dept_id = #{deptId}</if>
            <if test="createrCode != null "> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null "> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
        and d.del_flag = 0
        </where>
    </select>

    <select id="selectTCheckLawsById" parameterType="Long" resultMap="TCheckLawsResult">
        <include refid="selectTCheckLawsVo"/>
        where id = #{id}
    </select>

    <insert id="insertTCheckLaws" parameterType="TCheckLaws" useGeneratedKeys="true" keyProperty="id">
        insert into t_check_laws
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="code != null">code,</if>
            <if test="name != null">name,</if>
            <if test="type != null">type,</if>
            <if test="status != null">status,</if>
            <if test="starttime != null">starttime,</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="code != null">#{code},</if>
            <if test="name != null">#{name},</if>
            <if test="type != null">#{type},</if>
            <if test="status != null">#{status},</if>
            <if test="starttime != null">#{starttime},</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>

    <update id="updateTCheckLaws" parameterType="TCheckLaws">
        update t_check_laws
        <trim prefix="SET" suffixOverrides=",">
            <if test="code != null">code = #{code},</if>
            <if test="name != null">name = #{name},</if>
            <if test="type != null">type = #{type},</if>
            <if test="status != null">status = #{status},</if>
            <if test="starttime != null">starttime = #{starttime},</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>

    <update id="updateTCheckLawsStatus" parameterType="TCheckLaws">
        update t_check_laws
        <trim prefix="SET" suffixOverrides=",">
            <if test="status != null">status = #{status},</if>
            <if test="starttime != null">starttime = #{starttime},</if>
        </trim>
        where id = #{id};
        update t_check_laws set `starttime` = null ,`status`=0   where id!=#{id};
    </update>

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

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