<?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.ruoyi.zdsz.mapper.ZEngineeringIndustryMapper">

    <resultMap type="com.ruoyi.zdsz.domain.ZEngineeringIndustry" id="ZEngineeringIndustryResult">
        <result property="id" column="id"/>
        <result property="enginType" column="engin_type"/>
        <result property="constructUnit" column="construct_unit"/>
        <result property="projectHead" column="project_head"/>
        <result property="sceneHead" column="scene_head"/>
        <result property="designUnit" column="design_unit"/>
        <result property="designHead" column="design_head"/>
        <result property="designPhone" column="design_phone"/>
        <result property="supervisionUnit" column="supervision_unit"/>
        <result property="supervisionHead" column="supervision_head"/>
        <result property="supervisionPhone" column="supervision_phone"/>
        <result property="type" column="type"/>
        <result property="version" column="version"/>
        <result property="remark" column="remark"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <select id="getReviewStatusByNodeId" resultType="java.util.Map">
        SELECT
            en.type,
            COALESCE(
                    (SELECT er.review_status FROM z_engineering_review er WHERE er.eng_info_id = en.id AND er.del_flag = 0 ORDER BY er.update_info_time DESC LIMIT 1),
        '2'
    ) AS reviewStatus
        FROM
            z_engineering_node en
        WHERE
            en.civli_id = #{id};
    </select>
    <select id="getByUserList" resultType="java.util.Map">
        SELECT
            epj.id AS id,
            epj.engin_name AS enginName,
            epj.create_time AS createTime
        FROM z_engineering_info  ei
                 LEFT JOIN z_engineering_node en ON ei.eng_info_id = en.id
                 LEFT JOIN ${type} epj ON epj.id = en.civli_id
                <if test="szAndGy != null and szAndGy != ''">
                    <if test="szAndGy == 'sz'">
                        and epj.type = '1'
                    </if>
                    <if test="szAndGy == 'gy'">
                        and epj.type = '2'
                    </if>
                </if>
        WHERE ei.create_by = #{by} AND epj.id IS NOT NULL GROUP BY epj.id
        <foreach collection="names" item="name">
            union
            SELECT
            epj.id AS id,
            epj.engin_name AS enginName,
            epj.create_time AS createTime
            FROM z_engineering_info_${name}  ei
            LEFT JOIN z_engineering_node_${name} en ON ei.eng_info_id = en.id
            LEFT JOIN ${type} epj ON epj.id = en.civli_id
            <if test="szAndGy != null and szAndGy != ''">
                <if test="szAndGy == 'sz'">
                    and epj.type = '1'
                </if>
                <if test="szAndGy == 'gy'">
                    and epj.type = '2'
                </if>
            </if>
            WHERE ei.create_by = #{by} AND epj.id IS NOT NULL GROUP BY epj.id

        </foreach>
    </select>

</mapper>
