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

    <sql id="Base_Column_List">
        a.id,
        a.create_by_id,
        a.create_time,
        a.update_by_id,
        a.update_time,
        a.del_flag,
        a.report_id,
        a.user_id,
        a.user_role,
        a.content,
        a.opinion,
        a.detail_number
    </sql>
    <delete id="deleteByReportId">
        update cw_project_report_review_new_team set del_flag = '1' where report_id = #{reportId}
    </delete>
    <select id="selectByReportId" resultType="com.jeeplus.finance.projectReport.domain.CwProjectReviewNewTeam">
        select
        <include refid="Base_Column_List"></include>,
        su.name as memberName,
        cert.type AS professionType,
        cert.profession AS profession,
        cert.enroll_cert_no AS enrollCertNo
        from cw_project_report_review_new_team a
        left join sys_user su on a.user_id = su.id and su.del_flag = '0'
        LEFT JOIN sys_cert cert ON su.id = cert.user_id AND cert.del_flag = '0'
        where a.report_id = #{reportId} and a.del_flag = '0'
        AND cert.type IN ('3', '4')
        AND cert.type = (
        CASE
        WHEN EXISTS (
        SELECT 1
        FROM sys_cert sub_cert
        WHERE sub_cert.user_id = su.id
        AND sub_cert.type = '3'
        AND sub_cert.del_flag = '0'
        ) THEN '3'
        ELSE '4'
        END
        )
        ORDER BY
--         CASE
--         WHEN a.user_role = '负责人' THEN 1
--         WHEN a.user_role = '技术负责人' THEN 2
--         ELSE 3
--         END,
        a.detail_number ASC;
    </select>

</mapper>