<?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="org.springblade.system.mapper.RectFeedbackMapper">
    <insert id="saveRecord">
        INSERT INTO record_rectification(rectification_id, description,create_user_id,create_time)
        VALUES (#{id}, #{description},#{createUserId},NOW())
    </insert>
    <update id="rectify">
        UPDATE record_rectification_list
        SET rectify_status = #{rectifyStatus}
        WHERE id = #{id}
    </update>

    <select id="list" resultType="org.springblade.system.domain.RectificationDto">
        SELECT
            rrl.id,
            rrl.file_id AS fileId,
            dkp.id AS proId,
            dkp.pro_name AS proName,
            dkp.single_pro_name AS singleProName,
            bd.dept_name AS deptName,
            rrl.is_issue AS isIssue,
            rrl.issue_time AS issueTime,
            rrl.rectify_status AS rectifyStatus
        from record_rectification_list rrl
                 left join record_da_ky_project dkp on rrl.pro_id = dkp.id
                 left join da_ky_sys_file_source dksfs on rrl.file_id = dksfs.id
                 left join record_da_ky_pro_files_contents dkpfc on dksfs.business_id = dkpfc.id
                 left join blade_dept bd on bd.id = dkpfc.unit_name
        WHERE 1=1
        <if test="singleProName != null and singleProName != ''">
            and dkp.single_pro_name like concat('%',#{singleProName},'%')
        </if>
        <if test="rectifyStatus != null">
            and rrl.rectify_status = #{rectifyStatus}
        </if>
    </select>
    <select id="detail" resultType="org.springblade.system.domain.RectificationDto">
        SELECT
        rrl.id,
        rrl.file_id AS fileId,
        dkp.pro_name AS proName,
        dkp.single_pro_name AS singleProName,
        concat( dkpfc4.content_name, '/', dkpfc3.content_name, '/', dkpfc2.content_name, '/', dkpfc.content_name, '/', dksfs.file_name ) AS contentName,
        rrl.description,
        rrl.rectify_status AS rectifyStatus,
        bu.name AS issuerName,
        bu.phone AS issuerPhone,
        bd.dept_name AS deptName,
        rrl.is_issue AS isIssue
        from record_rectification_list rrl
        left join record_da_ky_project dkp on rrl.pro_id = dkp.id
        left join da_ky_sys_file_source dksfs on rrl.file_id = dksfs.id
        left join record_da_ky_pro_files_contents dkpfc on dkpfc.id = dksfs.business_id
        left join record_da_ky_pro_files_contents dkpfc2 on dkpfc.parent_id = dkpfc2.id
        left join record_da_ky_pro_files_contents dkpfc3 on dkpfc2.parent_id = dkpfc3.id
        left join record_da_ky_pro_files_contents dkpfc4 on dkpfc3.parent_id = dkpfc4.id
        left join blade_dept bd on bd.id = dkpfc.unit_name
        left join blade_user bu on bu.id = rrl.issue_user
        WHERE rrl.pro_id = #{proId} and dkpfc.pro_id = #{proId} and dkpfc2.pro_id = #{proId} and dkpfc3.pro_id = #{proId} and dkpfc4.pro_id = #{proId}
        and rrl.id = #{id}
    </select>
    <select id="getRecordDetails" resultType="org.springblade.system.domain.RectificationDto">
        select bu.name, rr.description
        from record_rectification rr
                 left join blade_user bu on bu.id = rr.create_user_id
        where rectification_id = #{id} order by rr.create_time desc
    </select>
</mapper>
