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

    <resultMap id="BaseResultMap" type="com.jeeplus.finance.projectReport.service.dto.CwProjectReportSignatureDTO">
            <id property="id" column="id" jdbcType="VARCHAR"/>
            <result property="createBy.id" column="create_by" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_date" jdbcType="TIMESTAMP"/>
            <result property="updateBy.id" column="update_by" jdbcType="VARCHAR"/>
            <result property="updateTime" column="update_date" jdbcType="TIMESTAMP"/>
            <result property="delFlag" column="del_flag" jdbcType="INTEGER"/>
            <result property="remarks" column="remarks" jdbcType="VARCHAR"/>
            <result property="reportId" column="report_id" jdbcType="VARCHAR"/>
            <result property="type" column="type" jdbcType="VARCHAR"/>
            <result property="procInsId" column="proc_ins_id" jdbcType="VARCHAR"/>
            <result property="status" column="status" jdbcType="VARCHAR"/>
            <result property="processDefinitionId" column="process_definition_id" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        cw_prs.id,
        cw_prs.create_by,
        cw_prs.create_date,
        cw_prs.update_by,
        cw_prs.update_date,
        cw_prs.del_flag,
        cw_prs.remarks,
        cw_prs.report_id,
        cw_prs.type,
        cw_prs.proc_ins_id,
        cw_prs.status,
        cw_prs.process_definition_id
    </sql>

    <select id="getInfoById" resultType="com.jeeplus.finance.projectReport.domain.CwProjectReportSignature">
        SELECT
            id,
            remarks,
            report_id,
            type,
            proc_ins_id,
            STATUS,
            process_definition_id,
            signature_annotator1_status,
            signature_annotator2_status,
            seal_admin_status,
            create_time,
            create_by_id,
            update_time,
            update_by_id,
            del_flag,
            tenant_id
        FROM
            cw_project_report_signature
        WHERE
            id = #{id}
            AND del_flag = 0
    </select>

    <update id="updateInfoById">
        update cw_project_report_signature SET
        <if test="status != null and status != ''">
            status = #{status},
        </if>
        <if test="sealAdminStatus != null and sealAdminStatus != ''">
            seal_admin_status = #{sealAdminStatus},
        </if>
        <if test="signatureAnnotator1Status != null and signatureAnnotator1Status != ''">
            signature_annotator1_status = #{signatureAnnotator1Status},
        </if>
        <if test="signatureAnnotator2Status != null and signatureAnnotator2Status != ''">
            signature_annotator2_status = #{signatureAnnotator2Status},
        </if>
            update_by_id = #{updateById},
            update_time = #{updateTime}
        WHERE id = #{id}
            AND del_flag = 0
    </update>

    <select id="getSignatureAnnotatorList" resultType="com.jeeplus.finance.projectReport.domain.CwSignatureAnnotator">
        select
            sa.id,
            (SELECT DISTINCT su.login_name  from cw_project_report_signature_annotator sa
            LEFT JOIN sys_user su on sa.signature_annotator1=su.id
            where sa.signature_annotator1= sa.signature_annotator1 and sa.report_id=#{reportId}) as signatureAnnotator1,
            (SELECT DISTINCT su.login_name  from cw_project_report_signature_annotator sa
            LEFT JOIN sys_user su on sa.signature_annotator2=su.id
            where sa.signature_annotator2= sa.signature_annotator2 and sa.report_id=#{reportId}) as signatureAnnotator2,
            (SELECT DISTINCT su.login_name  from cw_project_report_signature_annotator sa
            LEFT JOIN sys_user su on sa.create_by_id=su.id
            where sa.create_by_id= sa.create_by_id and sa.report_id=#{reportId} and sa.create_by_id=(SELECT create_by_id from cw_project_report where id=#{reportId})) as userName,
            sa.create_time
        from
            cw_project_report_signature_annotator sa
        LEFT JOIN sys_user su on sa.create_by_id=su.id
        where sa.create_by_id=(SELECT create_by_id from cw_project_report where id=#{reportId}) and sa.report_id=#{reportId}
    </select>


</mapper>
