<?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.jeeplus.finance.projectReport.mapper.CwProjectReportReviewMapper">
    <update id="updateReviewStatysByReportId">
        update cw_project_report_review set review_status = #{reviewStatus},
        need_update2 = #{needUpdate2},
        need_update3 = #{needUpdate3},
        remark2 = #{remark2},
        remark3 = #{remark3}
        where report_id = #{id}
    </update>
    <update id="updateReviewStatusByReportId">
        update cw_project_report_review set review_status = #{reviewStatus}
        where report_id = #{reportId}
    </update>
    <select id="selectByReportId" resultType="com.jeeplus.finance.projectReport.domain.CwProjectReview">
        select * from cw_project_report_review where report_id = #{id}
    </select>
    <select id="selectByPortId" resultType="com.jeeplus.finance.projectReport.domain.CwProjectReportData">
        select * from cw_project_report_review where report_id = #{id}
    </select>
    <select id="getProjectIdByReportId" resultType="java.lang.String">
        SELECT project_id FROM cw_project_report cw_p
        LEFT JOIN cw_project_report_review cw_re
        on cw_p.id = cw_re.report_id and cw_re.del_flag = '0'
        WHERE cw_p.id = #{id}
    </select>

    <select id="getProjectReportByNumber" resultType="com.jeeplus.finance.reimbursementApproval.approvalInfo.service.dto.ReportNoDto">
        SELECT
        *
        FROM cw_project_report_new_line a
        where a.report_no = #{number}
        limit 1
    </select>

    <select id="getNewProjectReportByNumber" resultType="string">
        SELECT
            a.report_no
        FROM cw_project_report_new_line a
        where a.report_no like concat ('%',#{number},'%')
        order By
            CAST(SUBSTRING(a.report_no, LOCATE(']', a.report_no) + 1, LOCATE('号', a.report_no) - LOCATE(']', a.report_no) - 1) AS UNSIGNED) DESC
        limit 1
    </select>

    <select id="selectById" resultType="com.jeeplus.finance.projectReport.domain.CwProjectReview">
        SELECT
            id,
            proc_ins_id,
            process_definition_id,
            review_status,
            all_print_num,
            issue_num,
            place_on_file_num,
            printed_by,
            check_autograph,
            report_id,
            report_review_no,
            report_title_type,
            need_update1,
            need_update2,
            need_update3,
            remark1,
            remark2,
            remark3,
            computer_no,
            review_by,
            create_time,
            create_by_id,
            update_time,
            update_by_id,
            del_flag,
            tenant_id,
            new_type
        FROM
            cw_project_report_review
        WHERE
            id = #{id}
    </select>

    <update id="updateReviewById">
        UPDATE cw_project_report_review
        SET
        <if test="reviewStatus != null and reviewStatus != ''">
            review_status = #{reviewStatus},
        </if>
        <if test="allPrintNum != null and allPrintNum != ''">
            all_print_num = #{allPrintNum},
        </if>
        <if test="issueNum != null and issueNum != ''">
            issue_num = #{issueNum},
        </if>
        <if test="placeOnFileNum != null and placeOnFileNum != ''">
            place_on_file_num = #{placeOnFileNum},
        </if>
        <if test="printedBy != null and printedBy != ''">
            printed_by = #{printedBy},
        </if>
        <if test="checkAutograph != null and checkAutograph != ''">
            check_autograph = #{checkAutograph},
        </if>
        <if test="reportReviewNo != null and reportReviewNo != ''">
            report_review_no = #{reportReviewNo},
        </if>
        <if test="reportTitleType != null and reportTitleType != ''">
            report_title_type = #{reportTitleType},
        </if>
        <if test="reportTitleType != null and reportTitleType != ''">
            report_title_type = #{reportTitleType},
        </if>
        <if test="needUpdate1 != null and needUpdate1 != ''">
            need_update1 = #{needUpdate1},
        </if>
        <if test="needUpdate2 != null and needUpdate2 != ''">
            need_update2 = #{needUpdate2},
        </if>
        <if test="needUpdate3 != null and needUpdate3 != ''">
            need_update3 = #{needUpdate3},
        </if>
        <if test="remark1 != null and remark1 != ''">
            remark1 = #{remark1},
        </if>
        <if test="remark2 != null and remark2 != ''">
            remark2 = #{remark2},
        </if>
        <if test="remark3 != null and remark3 != ''">
            remark3 = #{remark3},
        </if>
        <if test="computerNo != null and computerNo != ''">
            computer_no = #{computerNo},
        </if>
        <if test="reviewBy != null and reviewBy != ''">
            review_by = #{reviewBy},
        </if>
        <if test="auditTime != null">
            audit_time = #{auditTime},
        </if>
        update_by_id = #{updateById},
        update_time = #{updateTime}
        WHERE
            id = #{id}
            AND del_flag = 0
    </update>

    <update id="updateSignatureProcInsId">
       update cw_project_report_signature set proc_ins_id = #{procInsId},process_definition_id = #{processDefinitionId}  where id = #{id}
    </update>


    <select id="selectProjectReportById" resultType="com.jeeplus.finance.projectReport.domain.CwProjectReportData">
        select a.*,b.* from cw_project_report a
        left join cw_project_report_review b on a.id = b.report_id
        where a.id = #{id}
    </select>

    <update id="updateNumberById">
        update cw_project_report_new_line set report_no = #{replaceNumber} where id = #{id}
    </update>

</mapper>
