<?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.assess.program.configuration.projectList.mapper.ProgramAuditMapper">

    <resultMap id="BaseResultMap" type="com.jeeplus.assess.program.configuration.projectList.service.dto.ProgramAuditDto">
            <id property="id" column="id" jdbcType="VARCHAR"/>
            <result property="createBy.id" column="create_by_id" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="updateBy.id" column="update_by_id" jdbcType="VARCHAR"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
            <result property="delFlag" column="del_flag" jdbcType="INTEGER"/>
            <result property="remarks" column="remarks" jdbcType="VARCHAR"/>
            <result property="programId" column="program_id" jdbcType="VARCHAR"/>
            <result property="auditLevel" column="audit_level" jdbcType="VARCHAR"/>
            <result property="auditPeople" column="audit_people" jdbcType="VARCHAR"/>
            <result property="auditDate" column="audit_date" jdbcType="TIMESTAMP"/>
            <result property="retainOpinion" column="retain_opinion" jdbcType="VARCHAR"/>
            <result property="changeOpinion" column="change_opinion" jdbcType="VARCHAR"/>
            <result property="detailOpinion" column="detail_opinion" jdbcType="VARCHAR"/>
            <result property="reportOpinion" column="report_opinion" jdbcType="VARCHAR"/>
            <result property="remarksOpinion" column="remarks_opinion" jdbcType="VARCHAR"/>
            <result property="workOpinion" column="work_opinion" jdbcType="VARCHAR"/>
            <result property="procInsId" column="proc_ins_id" jdbcType="VARCHAR"/>
            <result property="processDefinitionId" column="process_definition_id" jdbcType="VARCHAR"/>
            <result property="status" column="status" jdbcType="VARCHAR"/>
            <association property="programProjectListInfo" select="getProgram" javaType="com.jeeplus.assess.program.configuration.projectList.domain.ProgramProjectListInfo" column="program_id"></association>
            <collection property="programAuditAssessPeopleDtoList" select="getAssess" ofType="com.jeeplus.assess.program.configuration.projectList.service.dto.ProgramAuditAssessPeopleDto" column="id"></collection>
    </resultMap>

    <sql id="Base_Column_List">
        pa.id,
        pa.create_by_id,
        pa.create_time,
        pa.update_by_id,
        pa.update_time,
        pa.del_flag,
        pa.remarks,
        pa.program_id,
        pa.audit_level,
        pa.audit_people,
        pa.audit_date,
        pa.retain_opinion,
        pa.change_opinion,
        pa.detail_opinion,
        pa.report_opinion,
        pa.remarks_opinion,
        pa.work_opinion,
        pa.proc_ins_id,
        pa.process_definition_id,
        pa.status
    </sql>
    <sql id="Program_Column_List">
        id,create_by_id,create_time,
        update_by_id,update_time,del_flag,
        contract_id,contract_name,client,
        client_name,amount,contract_type,
        name,no,project_type,
        approval_no,company,project_mould,
        property_holder,property_holder_name,location,
        is_first,year_num,check_year,
        project_manager,project_manager_name,report_type,
        industry,enterprise_type,risk_level,
        project_source,estimate,plan_end_time,
        use_num,appointment,work_hours,
        remarks,assessment_enterprise,assessment_enterprise_name,
        link_num,relationship,assessment_way,
        assessment_objective,assessment_date,num,
        project_development,delegate_project_type,assessment_object,
        work_begin_date,work_end_date,reporting_date,
        is_have,is_influence,mode,
        status,proc_ins_id,process_definition_id
    </sql>
    <sql id="Assess_Column_List">
        paap.id,
        paap.create_by_id,
        paap.create_time,
        paap.update_by_id,
        paap.update_time,
        paap.del_flag,
        paap.remarks,
        paap.audit_id,
        paap.assess_people
    </sql>
    <select id="getAssess" resultType="com.jeeplus.assess.program.configuration.projectList.service.dto.ProgramAuditAssessPeopleDto">
        select
        <include refid="Assess_Column_List"></include>
        from program_audit_assess_people paap
        where paap.del_flag = '0' and paap.audit_id = #{id}
    </select>
    <select id="getProgram" resultType="com.jeeplus.assess.program.configuration.projectList.domain.ProgramProjectListInfo">
        select
        <include refid="Program_Column_List"></include>
        from program_project_list_info ppli
        where ppli.del_flag = '0' and id = #{program_id}
    </select>
    <select id="findByIdAudit" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"></include>
        from program_audit pa
        where pa.del_flag = '0' and pa.id = #{id}
    </select>
    <select id="findIdByProIdAndLevel" resultType="string">
        select id from program_audit where del_flag = '0' and program_id = #{programId} and audit_level = #{auditLevel}
    </select>
    <select id="getIDsByProId" resultType="string">
        SELECT id
        FROM program_audit
        WHERE program_id = #{programId} and del_flag = '0'
        ORDER BY
        CASE WHEN audit_date IS NULL THEN 1 ELSE 0 END,
        audit_date ASC
    </select>
</mapper>
