<?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.modules.sg.scheduleView.mapper.ScheduleViewMapper">

    <insert id="insert">
        INSERT INTO md_acquisition_process
        (id,
         proc_ins_id,
         project_id,
         the_number,
         version,
         select_number,
         create_by,
         create_date,
         update_by,
         update_date,
         remarks,
         del_flag)
        VALUES (#{id},
                #{procInsId},
                #{projectId},
                #{theNumber},
                #{version},
                #{selectNumber},
                #{createBy.id},
                #{createDate},
                #{updateBy.id},
                #{updateDate},
                #{remarks},
                #{delFlag})
    </insert>

    <update id="update">
        UPDATE md_acquisition_process
        SET proc_ins_id   = #{procInsId},
            project_id    = #{projectId},
            the_number    = #{theNumber},
            version       = #{version},
            select_number = #{selectNumber},
            update_by     = #{updateBy.id},
            update_date   = #{updateDate},
            remarks       = #{remarks}
        WHERE id = #{id}
    </update>


    <!--物理删除-->
    <update id="delete">
        DELETE
        FROM md_module_block
        WHERE id = #{id}
    </update>

    <!--逻辑删除-->
    <update id="deleteByLogic">
        UPDATE md_module_block
        SET del_flag = #{DEL_FLAG_DELETE}
        WHERE id = #{id}
    </update>


    <select id="scheduleProjectAll" resultType="com.jeeplus.modules.sg.scheduleView.entity.ScheduleView">
        select
        xmp.reserveProjectName,
        xmp.projectId,
        xmp.projectName,
        xmp.status,
        xmp.acquisitionStatus,
        xmp.advanceStatus,
        xmp.constructionStatus,
        xmp.whetherCloseStatus,
        xmp.settStatus
        from xm_material_project xmp
        left join xm_project_assignment xpa
        on xmp.reserveProjectName = xpa.reserveProjectName
        <where>
            1 = 1
            and
            xmp.secondPower = 0
            <if test="projectList!=null and projectList.size>0 and projectList!=''">
            and xmp.projectId in(
                <foreach collection="projectList" item="item" separator=",">
                    #{item}
                </foreach>
                )
            </if>
            <if test="reserveProjectName!=null and reserveProjectName!=''">
                and xmp.reserveProjectName like concat('%',#{reserveProjectName}, '%')
            </if>
            <if test="projectName!=null and projectName!=''">
                and xmp.projectName like concat('%', #{projectName}, '%')
            </if>
            <if test="dataScope != null and dataScope != ''">
                ${dataScope}
            </if>
        </where>
    </select>

    <select id="disAll" resultType="com.jeeplus.modules.sg.scheduleView.entity.ScheduleView">
        select a.projectName,
        a.reserveProjectName,
        a.projectId,
        a.projectType,
        a.status,
        a.acquisitionStatus,
        a.advanceStatus,
        a.constructionStatus,
        a.settStatus,
        b.proc_ins_id
        from xm_material_project a
        LEFT JOIN xm_construction_clarificaiton b
        on a.reserveProjectName = b.reserveProjectName
        left join xm_project_assignment xpa
        on a.reserveProjectName = xpa.reserveProjectName
        <where>
            1 = 1
            and
            a.secondPower = 0
            <if test="projectList!=null and projectList.size>0 and projectList!=''">
                and a.projectId in(
                <foreach collection="projectList" item="item" separator=",">
                    #{item}
                </foreach>
                )
            </if>
            <if test="reserveProjectName!=null and reserveProjectName!=''">
                and a.reserveProjectName like concat('%',#{reserveProjectName}, '%')
            </if>
            <if test="projectName!=null and projectName!=''">
                and a.projectName like concat('%', #{projectName}, '%')
            </if>
            <if test="dataScope != null and dataScope != ''">
                ${dataScope}
            </if>
        </where>
    </select>

    <select id="recAll" resultType="com.jeeplus.modules.sg.scheduleView.entity.ScheduleView">
        select a.projectName,
                a.reserveProjectName,
                a.projectId,
                a.projectType,
                a.status,
                a.acquisitionStatus,
                a.advanceStatus,
                a.constructionStatus,
                a.settStatus,
                b.proc_ins_id,
               b.the_number as 'receiveView.theNumber'
        from xm_material_project a
        left join md_acquisition_process b
        on a.reserveProjectName = b.reserveProjectName
        left join xm_project_assignment xpa
        on a.reserveProjectName = xpa.reserveProjectName
        <where>
            1 = 1
            and
            a.secondPower = 0
            <if test="projectList!=null and projectList.size>0 and projectList!=''">
                and a.projectId in(
                <foreach collection="projectList" item="item" separator=",">
                    #{item}
                </foreach>
                )
            </if>
            <if test="reserveProjectName!=null and reserveProjectName!=''">
                and a.reserveProjectName like concat('%',#{reserveProjectName}, '%')
            </if>
            <if test="projectName!=null and projectName!=''">
                and a.projectName like concat('%', #{projectName}, '%')
            </if>
            <if test="dataScope != null and dataScope != ''">
                ${dataScope}
            </if>
        </where>
    </select>
    
    <select id="settAll" resultType="com.jeeplus.modules.sg.scheduleView.entity.ScheduleView">
        select a.projectName,
                a.reserveProjectName,
                a.projectId,
                a.projectType,
                a.status,
                a.acquisitionStatus,
                a.advanceStatus,
                a.constructionStatus,
                a.settStatus,
                b.proc_ins_id
        from xm_material_project a
        left join xm_settlement_process b
        on a.reserveProjectName = b.reserveProjectName
        left join xm_project_assignment xpa
        on a.reserveProjectName = xpa.reserveProjectName
        <where>
            1 = 1
            and
            a.secondPower = 0
            <if test="projectList!=null and projectList.size>0 and projectList!=''">
                and a.projectId in(
                <foreach collection="projectList" item="item" separator=",">
                    #{item}
                </foreach>
                )
            </if>
            <if test="reserveProjectName!=null and reserveProjectName!=''">
                and a.reserveProjectName like concat('%',#{reserveProjectName}, '%')
            </if>
            <if test="projectName!=null and projectName!=''">
                and a.projectName like concat('%', #{projectName}, '%')
            </if>
            <if test="dataScope != null and dataScope != ''">
                ${dataScope}
            </if>
        </where>
    </select>

    <select id="civilAll" resultType="com.jeeplus.modules.sg.scheduleView.entity.ScheduleView">
        select a.projectName,
        a.reserveProjectName,
        a.projectId,
        a.projectType,
        a.status,
        a.acquisitionStatus,
        a.advanceStatus,
        a.constructionStatus,
        a.settStatus,
        b.proc_ins_id
        from xm_material_project a
        left join xm_nonpower_process b
        on a.reserveProjectName = b.reserveProjectName
        left join xm_project_assignment xpa
        on a.reserveProjectName = xpa.reserveProjectName
        <where>
            1 = 1
            and
            a.secondPower = 0
            <if test="projectList!=null and projectList.size>0 and projectList!=''">
                and a.projectId in(
                <foreach collection="projectList" item="item" separator=",">
                    #{item}
                </foreach>
                )
            </if>
            <if test="reserveProjectName!=null and reserveProjectName!=''">
                and a.reserveProjectName like concat('%',#{reserveProjectName}, '%')
            </if>
            <if test="projectName!=null and projectName!=''">
                and a.projectName like concat('%', #{projectName}, '%')
            </if>
            <if test="dataScope != null and dataScope != ''">
                ${dataScope}
            </if>
        </where>
    </select>

    <select id="electricAll" resultType="com.jeeplus.modules.sg.scheduleView.entity.ScheduleView">
        select a.projectName,
        a.reserveProjectName,
        a.projectId,
        a.projectType,
        a.status,
        a.acquisitionStatus,
        a.advanceStatus,
        a.constructionStatus,
        a.settStatus,
        b.proc_ins_id
        from xm_material_project a
        left join sg_construction_process b
        on a.reserveProjectName = b.reserveProjectName
        left join xm_project_assignment xpa
        on a.reserveProjectName = xpa.reserveProjectName
        <where>
            1 = 1
            and
            a.secondPower = 0
            <if test="projectList!=null and projectList.size>0 and projectList!=''">
                and a.projectId in(
                <foreach collection="projectList" item="item" separator=",">
                    #{item}
                </foreach>
                )
            </if>
            <if test="reserveProjectName!=null and reserveProjectName!=''">
                and a.reserveProjectName like concat('%',#{reserveProjectName}, '%')
            </if>
            <if test="projectName!=null and projectName!=''">
                and a.projectName like concat('%', #{projectName}, '%')
            </if>
            <if test="dataScope != null and dataScope != ''">
                ${dataScope}
            </if>
        </where>
    </select>
</mapper>