<?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.rc.mapper.TProgressMapper">
    
    <resultMap type="TProgress" id="TProgressResult">
        <result property="id"    column="id"    />
        <result property="questionnaireId"    column="questionnaire_id"    />
        <result property="chapName"    column="chap_name"    />
        <result property="subChapName"    column="sub_chap_name"    />
        <result property="secSubChapName"    column="sec_sub_chap_name"    />
        <result property="content"    column="content"    />
        <result property="personInCharge"    column="person_in_charge"    />
        <result property="supporter"    column="supporter"    />
        <result property="startDate"    column="start_date"    />
        <result property="targetDate"    column="target_date"    />
        <result property="finishDate"    column="finish_date"    />
        <result property="preparation"    column="preparation"    />
        <result property="progress"    column="progress"    />
        <result property="applyStatus"    column="apply_status"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptId"    column="dept_id"    />
        <result property="auditId"    column="audit_id"    />
        <result property="personInChargeName"    column="person_in_charge_name"    />
        <result property="supporterName"    column="supporter_name"    />
        <result property="code"    column="code"    />
        <result property="name"    column="name"    />
        <result property="apNo"    column="ap_no"    />
        <result property="processId"    column="process_id"    />
        <result property="taskId"    column="task_id"    />
        <result property="taskName"    column="task_name"    />
    </resultMap>

    <sql id="selectTProgressVo">
        select p.id, questionnaire_id, chap_name, sub_chap_name, sec_sub_chap_name, content, p.person_in_charge, supporter, start_date, target_date,
         finish_date, preparation, progress, apply_status, p.remarks, p.dept_id, p.audit_id, p.ap_no, p.process_id, p.task_id, p.task_name,
        u1.nick_name as person_in_charge_name, u2.nick_name as supporter_name,
        q.code as code, q.name as name
        from t_progress p
        left join sys_user u1 on p.person_in_charge = u1.user_id
        left join sys_user u2 on p.supporter = u2.user_id
        inner join t_questionnaire q on p.questionnaire_id = q.id
    </sql>

    <select id="selectTProgressList" parameterType="TProgress" resultMap="TProgressResult">
        <include refid="selectTProgressVo"/>
        <where>  
            <if test="questionnaireId != null "> and questionnaire_id = #{questionnaireId}</if>
            <if test="chapName != null  and chapName != ''"> and chap_name like concat('%', #{chapName}, '%')</if>
            <if test="subChapName != null  and subChapName != ''"> and sub_chap_name like concat('%', #{subChapName}, '%')</if>
            <if test="secSubChapName != null  and secSubChapName != ''"> and sec_sub_chap_name like concat('%', #{secSubChapName}, '%')</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="personInCharge != null "> and person_in_charge = #{personInCharge}</if>
            <if test="supporter != null "> and supporter = #{supporter}</if>
            <if test="startDate != null "> and start_date = #{startDate}</if>
            <if test="targetDate != null "> and target_date = #{targetDate}</if>
            <if test="finishDate != null "> and finish_date = #{finishDate}</if>
            <if test="preparation != null  and preparation != ''"> and preparation = #{preparation}</if>
            <if test="progress != null  and progress != ''"> and progress = #{progress}</if>
            <if test="applyStatus != null  and applyStatus != ''"> and apply_status = #{applyStatus}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="deptId != null  and deptId != ''"> and p.dept_id = #{deptId}</if>
            <if test="auditId != null "> and p.audit_id = #{auditId}</if>
            <if test="apNo != null "> and p.ap_no = #{apNo}</if>
            <if test="processId != null "> and p.process_id = #{processId}</if>
            <if test="taskId != null  and taskId != ''"> and task_id = #{taskId}</if>
            <if test="taskName != null  and taskName != ''"> and task_name = #{taskName}</if>
        </where>
    </select>
    
    <select id="selectTProgressById" parameterType="Long" resultMap="TProgressResult">
        <include refid="selectTProgressVo"/>
        where p.id = #{id}
    </select>

    <insert id="insertTProgress" parameterType="TProgress" useGeneratedKeys="true" keyProperty="id">
        insert into t_progress
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="questionnaireId != null">questionnaire_id,</if>
            <if test="chapName != null">chap_name,</if>
            <if test="subChapName != null">sub_chap_name,</if>
            <if test="secSubChapName != null">sec_sub_chap_name,</if>
            <if test="content != null">content,</if>
            <if test="personInCharge != null">person_in_charge,</if>
            <if test="supporter != null">supporter,</if>
            <if test="startDate != null">start_date,</if>
            <if test="targetDate != null">target_date,</if>
            <if test="finishDate != null">finish_date,</if>
            <if test="preparation != null">preparation,</if>
            <if test="progress != null">progress,</if>
            <if test="applyStatus != null">apply_status,</if>
            <if test="remarks != null">remarks,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="auditId != null">audit_id,</if>
            <if test="apNo != null">ap_no,</if>
            <if test="processId != null">process_id,</if>
            <if test="taskId != null">task_id,</if>
            <if test="taskName != null">task_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="questionnaireId != null">#{questionnaireId},</if>
            <if test="chapName != null">#{chapName},</if>
            <if test="subChapName != null">#{subChapName},</if>
            <if test="secSubChapName != null">#{secSubChapName},</if>
            <if test="content != null">#{content},</if>
            <if test="personInCharge != null">#{personInCharge},</if>
            <if test="supporter != null">#{supporter},</if>
            <if test="startDate != null">#{startDate},</if>
            <if test="targetDate != null">#{targetDate},</if>
            <if test="finishDate != null">#{finishDate},</if>
            <if test="preparation != null">#{preparation},</if>
            <if test="progress != null">#{progress},</if>
            <if test="applyStatus != null">#{applyStatus},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="auditId != null">#{auditId},</if>
            <if test="apNo != null">#{apNo},</if>
            <if test="processId != null">#{processId},</if>
            <if test="taskId != null">#{taskId},</if>
            <if test="taskName != null">#{taskName},</if>
         </trim>
    </insert>

    <update id="updateTProgress" parameterType="TProgress">
        update t_progress
        <trim prefix="SET" suffixOverrides=",">
            <if test="questionnaireId != null">questionnaire_id = #{questionnaireId},</if>
            <if test="chapName != null">chap_name = #{chapName},</if>
            <if test="subChapName != null">sub_chap_name = #{subChapName},</if>
            <if test="secSubChapName != null">sec_sub_chap_name = #{secSubChapName},</if>
            <if test="content != null">content = #{content},</if>
            <if test="personInCharge != null">person_in_charge = #{personInCharge},</if>
            <if test="supporter != null">supporter = #{supporter},</if>
            <if test="startDate != null">start_date = #{startDate},</if>
            <if test="targetDate != null">target_date = #{targetDate},</if>
            <if test="finishDate != null">finish_date = #{finishDate},</if>
            <if test="preparation != null">preparation = #{preparation},</if>
            <if test="progress != null">progress = #{progress},</if>
            <if test="applyStatus != null">apply_status = #{applyStatus},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="auditId != null">audit_id = #{auditId},</if>
            <if test="apNo != null">ap_no = #{apNo},</if>
            <if test="processId != null">process_id = #{processId},</if>
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="taskId == null">task_id = null,</if>
            <if test="taskName != null">task_name = #{taskName},</if>
            <if test="taskName == null">task_name = null,</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTProgressById" parameterType="Long">
        delete from t_progress where id = #{id}
    </delete>

    <delete id="deleteTProgressByIds" parameterType="String">
        delete from t_progress where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>