<?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.production.mapper.TFivesChangeRecordMapper">

    <resultMap type="TFivesChangeRecord" id="TFivesChangeRecordResult">
        <result property="id"    column="id"    />
        <result property="regionOrder"    column="region_order"    />
        <result property="position"    column="position"    />
        <result property="owner"    column="owner"    />
        <result property="checkDate"    column="check_date"    />
        <result property="checkerId"    column="checker_id"    />
        <result property="checkerName"    column="checker_name"    />
        <result property="checkProblem"    column="check_problem"    />
        <result property="checkFile"    column="check_file"    />
        <result property="changeDate"    column="change_date"    />
        <result property="changeContent"    column="change_content"    />
        <result property="changeFile"    column="change_file"    />
        <result property="changeResult"    column="change_result"    />
        <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"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTFivesChangeRecordVo">
        select d.id, d.region_order, d.position, d.owner, d.check_date, d.checker_id, d.checker_name, d.check_problem, d.check_file, d.change_date, d.change_content, d.change_file, d.change_result, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks,  d.dept_id ,s.dept_name from t_fives_change_record d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTFivesChangeRecordList" parameterType="TFivesChangeRecord" resultMap="TFivesChangeRecordResult">
        <include refid="selectTFivesChangeRecordVo"/>
        <where>
            <if test="regionOrder != null  and regionOrder != ''"> and region_order = #{regionOrder}</if>
            <if test="position != null  and position != ''"> and position = #{position}</if>
            <if test="owner != null  and owner != ''"> and owner = #{owner}</if>
            <if test="checkDate != null "> and check_date = #{checkDate}</if>
            <if test="checkerId != null  and checkerId != ''"> and checker_id = #{checkerId}</if>
            <if test="checkerName != null  and checkerName != ''"> and checker_name like concat(concat('%', #{checkerName}), '%')</if>
            <if test="checkProblem != null  and checkProblem != ''"> and check_problem = #{checkProblem}</if>
            <if test="checkFile != null  and checkFile != ''"> and check_file = #{checkFile}</if>
            <if test="changeDate != null "> and change_date = #{changeDate}</if>
            <if test="changeContent != null  and changeContent != ''"> and change_content = #{changeContent}</if>
            <if test="changeFile != null  and changeFile != ''"> and change_file = #{changeFile}</if>
            <if test="changeResult != null  and changeResult != ''"> and change_result = #{changeResult}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTFivesChangeRecordById" parameterType="Long" resultMap="TFivesChangeRecordResult">
        <include refid="selectTFivesChangeRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertTFivesChangeRecord" parameterType="TFivesChangeRecord">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_fives_change_record.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_fives_change_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="regionOrder != null">region_order,</if>
            <if test="position != null">position,</if>
            <if test="owner != null">owner,</if>
            <if test="checkDate != null">check_date,</if>
            <if test="checkerId != null">checker_id,</if>
            <if test="checkerName != null">checker_name,</if>
            <if test="checkProblem != null">check_problem,</if>
            <if test="checkFile != null  and checkFile != ''">check_file,</if>
            <if test="changeDate != null">change_date,</if>
            <if test="changeContent != null">change_content,</if>
            <if test="changeFile != null and changeFile != ''">change_file,</if>
            <if test="changeResult != null">change_result,</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>
            <if test="remarks != null">remarks,</if>
            <if test="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="regionOrder != null">#{regionOrder},</if>
            <if test="position != null">#{position},</if>
            <if test="owner != null">#{owner},</if>
            <if test="checkDate != null">#{checkDate},</if>
            <if test="checkerId != null">#{checkerId},</if>
            <if test="checkerName != null">#{checkerName},</if>
            <if test="checkProblem != null">#{checkProblem},</if>
            <if test="checkFile != null and checkFile != ''">#{checkFile},</if>
            <if test="changeDate != null">#{changeDate},</if>
            <if test="changeContent != null">#{changeContent},</if>
            <if test="changeFile != null and changeFile != ''">#{changeFile},</if>
            <if test="changeResult != null">#{changeResult},</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>
            <if test="remarks != null">#{remarks},</if>
            <if test="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateTFivesChangeRecord" parameterType="TFivesChangeRecord">
        update t_fives_change_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="regionOrder != null">region_order = #{regionOrder},</if>
            <if test="position != null">position = #{position},</if>
            <if test="owner != null">owner = #{owner},</if>
            <if test="checkDate != null">check_date = #{checkDate},</if>
            <if test="checkerId != null">checker_id = #{checkerId},</if>
            <if test="checkerName != null">checker_name = #{checkerName},</if>
            <if test="checkProblem != null">check_problem = #{checkProblem},</if>
            <if test="checkFile != null and checkFile != ''">check_file = #{checkFile},</if>
            <if test="changeDate != null">change_date = #{changeDate},</if>
            <if test="changeContent != null">change_content = #{changeContent},</if>
            <if test="changeFile != null and changeFile != ''">change_file = #{changeFile},</if>
            <if test="changeResult != null">change_result = #{changeResult},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTFivesChangeRecordById" parameterType="Long">
        update t_fives_change_record set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTFivesChangeRecordByIds" parameterType="String">
        update t_fives_change_record set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

</mapper>
