<?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.testor.module.contractor.manage.dao.TContractorEvaluateDao">
    <!-- 开启二级缓存 -->
    <!-- <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> -->
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.testor.module.contractor.manage.model.domain.TContractorEvaluate">
                <id column="id" property="id"/>
                <id column="contractor_id" property="contractorId"/>
                <id column="proj_id" property="projId"/>
                <id column="biz_id" property="bizId"/>
                <id column="process_id" property="processId"/>
                <id column="process_status" property="processStatus"/>
                <id column="evaluation_sheet_type_id" property="evaluationSheetTypeId"/>
                <id column="evaluation_sheet_type" property="evaluationSheetType"/>
                <id column="evaluation_subject_id" property="evaluationSubjectId"/>
                <id column="evaluation_subject" property="evaluationSubject"/>
                <id column="evaluation_cycle_id" property="evaluationCycleId"/>
                <id column="evaluation_cycle" property="evaluationCycle"/>
                <id column="if_veto" property="ifVeto"/>
                <id column="score" property="score"/>
                <id column="reject_opinion" property="rejectOpinion"/>
                <id column="org_id" property="orgId"/>
                <id column="evaluate_level" property="evaluateLevel"/>
                <id column="if_next" property="ifNext"/>
                <id column="evaluate_time" property="evaluateTime"/>
                <id column="evaluate_person" property="evaluatePerson"/>
    </resultMap>
    <select id="pageList" resultType="com.testor.module.contractor.manage.model.dto.ContractorEvaluateDto">
        SELECT
        t.id,
        t.contractor_id,
        tci.NAME as contractorName,
        t.proj_id,
        tcp.name as projectName,
        t.biz_id,
        t.process_id,
        t.process_status,
        t.evaluation_sheet_type_id,
        t.evaluation_subject_id,
        t.evaluation_cycle_id,
        t.if_veto,
        t.score,
        t.evaluate_level,
        t.reject_opinion,
        t.if_next,
        t.evaluate_person,
        t.evaluate_time,
        t.org_id,
        t.status,
        t.create_by,
        t.create_date,
        t.update_by,
        t.update_date,
        t.remarks
        FROM
        t_contractor_evaluate t
        LEFT JOIN t_contractor_ledger tcl ON t.contractor_id = tcl.id
        LEFT JOIN t_contractor_info tci ON tcl.info_id = tci.id
        LEFT JOIN t_contractor_project tcp ON t.proj_id = tcp.id
        <!--WHERE
        t.org_id IN (select org.org_id from t_sys_org org where org.parent_ids like concat('%',#{param.orgId},'%') or org.org_id = #{param.orgId})-->
        WHERE EXISTS (
        SELECT 1
        FROM unnest(string_to_array(tcl.org_id, ',')) AS org(id)
        JOIN t_sys_org o ON org.id = o.org_id
        WHERE
        o.parent_ids LIKE concat('%',#{param.orgId},'%')
        OR o.org_id = #{param.orgId}
        )
        and t.status = '0'
        <if test="param.contractorName != null and param.contractorName != ''">
            AND tci.name like concat('%',#{param.contractorName},'%')
        </if>
        order by t.update_date desc
    </select>
</mapper>