<?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.managementcenter.project.mapper.ProjectMapper">

    <sql id="projectColumns">
        a.id as `id`,
		a.reserveProjectName,
		a.projectId,
		a.projectName,
        a.status,
        a.acquisitionStatus,
        a.advanceStatus,
        a.constructionStatus,
        a.whetherCloseStatus,
        a.settStatus,
        a.earlyMaterial,
        a.preConstruction,
        a.advanceConstruction
    </sql>
    <sql id="basicColumns">
        b.id as `basicInformation.id`,
        b.reserveProjectName as `basicInformation.reserveProjectName`,
		b.municipalCompany AS `basicInformation.municipalCompany`,
		b.countyCompany AS `basicInformation.countyCompany`,
		b.projectNature AS `basicInformation.projectNature`,
		b.demandUnit AS `basicInformation.demandUnit`,
		b.operationUnit AS `basicInformation.operationUnit`,
		b.powerSupplyArea AS `basicInformation.powerSupplyArea`,
		b.gridNumber AS `basicInformation.gridNumber`,
		b.cellNumber AS `basicInformation.cellNumber`,
		b.projectReserveNo AS `basicInformation.projectReserveNo`,
		b.gridProjectNo AS `basicInformation.gridProjectNo`,
		b.erpNo AS `basicInformation.erpNo`,
		b.necessityContent AS `basicInformation.necessityContent`,
		b.subStationName AS `basicInformation.subStationName`,
		b.lineName AS `basicInformation.lineName`,
		b.projectType AS `basicInformation.projectType`,
		b.whetherSummer AS `basicInformation.whetherSummer`,
		b.basicDescription AS `basicInformation.basicDescription`,
		b.workAreaRemarks AS `basicInformation.workAreaRemarks`
    </sql>
    <sql id="assignmentColumns">
        c.reserveProjectName as `assignment.reserveProjectName`,
            c.disclosureType as `assignment.disclosureType`,
            c.projectReleaseBatch as `assignment.projectReleaseBatch`,
            c.deliveryDate as `assignment.deliveryDate`,
            c.packageNo as `assignment.packageNo`,
            c.rate as `assignment.rate`,
            c.assignedUnit as `assignment.assignedUnit`,
            c.constructionUnit as `assignment.constructionUnit`,
            c.constructionSubcontractor as `assignment.constructionSubcontractor`,
            c.behalf as `assignment.behalf`,
            c.constructionFullTime as `assignment.constructionFullTime`,
            c.constructionTechnical as `assignment.constructionTechnical`,
            c.constructionManage as `assignment.constructionManage`,
            c.constructionLeader as `assignment.constructionLeader`,
            c.subcontractingContact as `assignment.subcontractingContact`,
            c.designer as `assignment.designer`,
            c.designLeader as `assignment.designLeader`,
            c.ownerManager as `assignment.ownerManager`,
            c.distribution as `assignment.distribution`,
            c.distributionFullTime as `assignment.distributionFullTime`,
            c.distributionSystem as `assignment.distributionSystem`,
            c.distributionPolicy as `assignment.distributionPolicy`,
            c.centerLeader as `assignment.centerLeader`,
            c.centerTechnical as `assignment.centerTechnical`,
            c.instituteRole as `assignment.instituteRole`,
            c.repUnit as `assignment.repUnit`,
            c.inspectionUnit as `assignment.inspectionUnit`
    </sql>

    <sql id="planColumns">
        a.id as `id`,
        a.reserveProjectName,
		a.projectId,
		a.projectName,
		c.disclosureType as `disclosurePlan.disclosureType`,
		b.projectType as `disclosurePlan.projectType`,
		c.disclosureType as `disclosurePlan.disclosureMethod`,
		b.operationUnit as `disclosurePlan.operationUnit`,
		c.constructionUnit as `disclosurePlan.constructionUnit`,
		d.powerSupplyStation as `disclosurePlan.powerSupplyStation`,
		c.constructionManage as `disclosurePlan.constructionManage`,
		d.maintenance as `disclosurePlan.maintenance`,
		d.automationContacts as `disclosurePlan.automationContacts`,
		d.liveSurveyContact as `disclosurePlan.liveSurveyContact`,
		d.inspector as `disclosurePlan.inspector`,
		d.disclosurePlanDate as `disclosurePlan.disclosurePlanDate`
    </sql>

    <sql id="approvalColumns">
        e.projectPackage as `approval.projectPackage`,
        e.projectBudget as `approval.projectBudget`,
        e.enterSystemAmount as `approval.enterSystemAmount`,
        e.afterAmount as `approval.afterAmount`,
        e.adjustmentReasons as `approval.adjustmentReasons`,
        e.constructionCost as `approval.constructionCost`,
        e.materialCost as `approval.materialCost`,
        e.designFee as `approval.designFee`,
        e.supervisionFee as `approval.supervisionFee`,
        e.policyFee as `approval.policyFee`,
        e.otherExpenses as `approval.otherExpenses`
    </sql>

    <sql id="tearColumns">
        t.reservedName as `tearDown.reservedName`,
        t.reserveModel as `tearDown.reserveModel`,
        t.reserveUnit as `tearDown.reserveUnit`,
        t.reserveNumber as `tearDown.reserveNumber`,
        t.reserveBalance as `tearDown.reserveBalance`,
        t.reserveNotes as `tearDown.reserveNotes`,
        t.confessionName as `tearDown.confessionName`,
        t.confessionModel as `tearDown.confessionModel`,
        t.confessionUnit as `tearDown.confessionUnit`,
        t.confessionNumber as `tearDown.confessionNumber`,
        t.confessionDifference as `tearDown.confessionDifference`,
        t.confessionNotes as `tearDown.confessionNotes`,
        t.changeName as `tearDown.changeName`,
        t.changeModel as `tearDown.changeModel`,
        t.changeUnit as `tearDown.changeUnit`,
        t.changeNumber as `tearDown.changeNumber`,
        t.changeDifference as `tearDown.changeDifference`,
        t.changeNotes as `tearDown.changeNotes`,
        t.actualName as `tearDown.actualName`,
        t.actualModel as `tearDown.actualModel`,
        t.actualUnit as `tearDown.actualUnit`,
        t.actualNumber as `tearDown.actualNumber`,
        t.actualDifference as `tearDown.actualDifference`,
        t.actualNotes as `tearDown.actualNotes`
    </sql>

    <sql id="capitalPlanColumns">
        cp.projectBatch as `capitalPlan.projectBatch`,
        cp.actualCost as `capitalPlan.actualCost`,
        cp.projectDifference as `capitalPlan.projectDifference`,
        cp.actualConstructionCost as `capitalPlan.actualConstructionCost`,
        cp.constructionDifference as `capitalPlan.constructionDifference`,
        cp.actualMaterialCost as `capitalPlan.actualMaterialCost`,
        cp.costDifference as `capitalPlan.costDifference`,
        cp.DesignPayFee as `capitalPlan.DesignPayFee`,
        cp.actualDesignCost as `capitalPlan.actualDesignCost`,
        cp.designDifference as `capitalPlan.designDifference`,
        cp.supervisionPayFee as `capitalPlan.supervisionPayFee`,
        cp.actualSupervisionCost as `capitalPlan.actualSupervisionCost`,
        cp.supervisionDifference as `capitalPlan.supervisionDifference`,
        cp.ActualManagementFee as `capitalPlan.ActualManagementFee`,
        cp.policyDifference as `capitalPlan.policyDifference`,
        cp.actualOtherCost as `capitalPlan.actualOtherCost`,
        cp.otherDifference as `capitalPlan.otherDifference`,
        cp.designRate as `capitalPlan.designRate`,
        cp.supervisionRate as `capitalPlan.supervisionRate`
    </sql>

    <delete id="deleteTearAll">
        delete
        from xm_tear_down
        where id = #{id}
    </delete>

    <select id="get" resultType="Project">
        SELECT
        <include refid="projectColumns"/>,
        <include refid="basicColumns"/>
        from xm_material_project a
        left join xm_project_basicinformation b
        on a.reserveProjectName = b.reserveProjectName
        WHERE a.id = #{id}
    </select>

    <select id="getAss" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        SELECT
        <include refid="projectColumns"/>,
        <include refid="basicColumns"/>,
        <include refid="assignmentColumns"/>
        from xm_material_project a
        left join xm_project_basicinformation b
        on a.reserveProjectName = b.reserveProjectName
        left join xm_project_assignment c
        on a.reserveProjectName = c.reserveProjectName
        WHERE a.id = #{id}
    </select>

    <select id="getPlan" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select
        <include refid="planColumns"/>
        from xm_material_project a
        left join xm_project_basicinformation b
        on a.reserveProjectName = b.reserveProjectName
        left join xm_project_assignment c
        on a.reserveProjectName = c.reserveProjectName
        left join xm_project_disclosurePlan d
        on a.reserveProjectName = d.reserveProjectName
        where a.id = #{id}
    </select>

    <select id="getApproval" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select
        <include refid="projectColumns"/>,
        <include refid="approvalColumns"/>
        from xm_material_project a
        left join xm_project_approval e
        on a.projectId = e.projectId
        where a.id = #{id}
    </select>

    <select id="findAllMember" resultType="java.lang.String">
        SELECT NAME
        FROM sys_user
    </select>

    <select id="findDemandUnit" resultType="java.lang.String">
        select demandUnit
        from xm_project_basicinformation
        where reserveProjectName = #{name}
    </select>

    <select id="findList" resultType="Project">
        select
        <include refid="projectColumns"/>,
        <include refid="basicColumns"/>
        from xm_material_project a
        left join xm_project_basicinformation b
        on a.reserveProjectName = b.reserveProjectName
        <where>
            1 = 1
            and
            a.secondPower = 0
            and a.whetherCloseStatus = '0'
            <if test="reserveList != null and  reserveList !='' ">
                and a.reserveProjectName in
                <foreach collection="reserveList" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="reserveProjectName!=null and reserveProjectName !=''">
                and a.reserveProjectName = #{reserveProjectName}
            </if>
            <if test="projectId != null and projectId !=''">
                and a.projectId = #{projectId}
            </if>
            <if test="projectName !=null and projectName !=''">
                and a.projectName = #{projectName}
            </if>
            <if test="status!=null and status !=''">
                and a.status = #{status}
            </if>
            <if test="acquisitionStatus!=null and acquisitionStatus !=''">
                and a.acquisitionStatus = #{acquisitionStatus}
            </if>
            <if test="advanceStatus!=null and advanceStatus !=''">
                and a.advanceStatus = #{advanceStatus}
            </if>
            <if test="constructionStatus!=null and constructionStatus !=''">
                and a.constructionStatus = #{constructionStatus}
            </if>
            <if test="settStatus!=null and settStatus !=''">
                and a.settStatus = #{settStatus}
            </if>
            <if test="earlyMaterial!=null and earlyMaterial !=''">
                <if test="earlyMaterial == 0">
                    and a.eaArlyMaterial = #{earlyMaterial}
                </if>
                <if test="earlyMaterial == 1">
                    or a.earlyMaterial = #{earlyMaterial}
                </if>
            </if>
            <if test="preConstruction!=null and preConstruction !=''">
                and a.preConstruction = #{preConstruction}
            </if>
            <if test="advanceConstruction!=null and advanceConstruction!=''">
                and a.advanceConstruction = #{advanceConstruction}
            </if>
            <if test="policyStatus!=null and policyStatus !=''">
                and a.policyStatus = #{policyStatus}
            </if>
            <if test="canEnter != null and canEnter != '' ">
                and a.canEnter = #{canEnter}
            </if>
            <if test="basicInformation.projectNature!=null and basicInformation.projectNature!=''">
                and b.projectNature like concat('%', #{basicInformation.projectNature}, '%')
            </if>
            ${dataScope}
        </where>
    </select>

    <select id="findBasicList" resultType="Project">
        select
        <include refid="projectColumns"/>,
        <include refid="basicColumns"/>
        from xm_material_project a
        left join xm_project_basicinformation b
        on a.reserveProjectName = b.reserveProjectName
        <where>
            1 = 1
            and
            a.secondPower = 0
            and a.whetherCloseStatus = '0'
            <if test="reserveList != null and  reserveList !='' ">
                and a.reserveProjectName in
                <foreach collection="reserveList" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="projectId != null and projectId !=''">
                and a.projectId like concat('%', #{projectId}, '%')
            </if>
            <if test="projectName !=null and projectName !=''">
                and a.projectName like concat('%', #{projectName}, '%')
            </if>
            ${dataScope}
        </where>
    </select>

    <select id="findAssList" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select
        <include refid="projectColumns"/>,
        <include refid="assignmentColumns"/>
        from xm_material_project a
        left join xm_project_assignment c
        on a.reserveProjectName = c.reserveProjectName
        <where>
            1 = 1
            and
            a.secondPower = 0
            and a.whetherCloseStatus = '0'
            <if test="reserveList != null and  reserveList !='' ">
                and a.reserveProjectName in
                <foreach collection="reserveList" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="projectId != null and projectId !=''">
                and a.projectId like concat('%', #{projectId}, '%')
            </if>
            <if test="projectName !=null and projectName !=''">
                and a.projectName like concat('%', #{projectName}, '%')
            </if>
            ${dataScope}
        </where>
    </select>

    <select id="findPlanList" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select
        <include refid="planColumns"/>
        from xm_material_project a
        left join xm_project_basicinformation b
        on a.reserveProjectName = b.reserveProjectName
        left join xm_project_assignment c
        on a.reserveProjectName = c.reserveProjectName
        left join xm_project_disclosurePlan d
        on a.reserveProjectName = d.reserveProjectName
        <where>
            1 = 1
            and
            a.secondPower = 0
            and a.whetherCloseStatus = '0'
            <if test="reserveList != null and  reserveList !='' ">
                and a.reserveProjectName in
                <foreach collection="reserveList" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="projectId != null and projectId !=''">
                and a.projectId like concat('%', #{projectId}, '%')
            </if>
            <if test="projectName !=null and projectName !=''">
                and a.projectName like concat('%', #{projectName}, '%')
            </if>
            ${dataScope}
        </where>
    </select>

    <select id="findApprovalList" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select
        <include refid="projectColumns"/>,
        <include refid="approvalColumns"/>
        from xm_material_project a
        left join xm_project_approval e
        on a.projectId = e.projectId
        <where>
            1 = 1
            and
            a.secondPower = 0
            and a.projectid !='' and a.projectName !=''
            and a.whetherCloseStatus = '0'
            <if test="reserveList != null and  reserveList !='' ">
                and a.projectId in
                <foreach collection="reserveList" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            ${dataScope}
        </where>
    </select>

    <select id="findProcess" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select status,
               acquisitionStatus,
               advanceStatus,
               constructionStatus,
               whetherCloseStatus,
               settStatus,
               earlyMaterial,
               preConstruction
        from xm_material_project
        where reserveProjectName = #{name}
    </select>

    <insert id="insertBasic">
        replace into xm_project_basicinformation
        (id,
         create_by,
         create_date,
         update_by,
         update_date,
         del_flag,
         remarks,
         reserveProjectName,
         municipalCompany,
         countyCompany,
         projectNature,
         demandUnit,
         operationUnit,
         powerSupplyArea,
         gridNumber,
         cellNumber,
         projectReserveNo,
         gridProjectNo,
         erpNo,
         necessityContent,
         subStationName,
         lineName,
         projectType,
         whetherSummer,
         basicDescription,
         workAreaRemarks)
        values (#{id},
                #{createBy.id},
                #{createDate},
                #{updateBy.id},
                #{updateDate},
                #{delFlag},
                #{remarks},
                #{basicInformation.reserveProjectName},
                #{basicInformation.municipalCompany},
                #{basicInformation.countyCompany},
                #{basicInformation.projectNature},
                #{basicInformation.demandUnit},
                #{basicInformation.operationUnit},
                #{basicInformation.powerSupplyArea},
                #{basicInformation.gridNumber},
                #{basicInformation.cellNumber},
                #{basicInformation.projectReserveNo},
                #{basicInformation.gridProjectNo},
                #{basicInformation.erpNo},
                #{basicInformation.necessityContent},
                #{basicInformation.subStationName},
                #{basicInformation.lineName},
                #{basicInformation.projectType},
                #{basicInformation.whetherSummer},
                #{basicInformation.basicDescription},
                #{basicInformation.workAreaRemarks});
    </insert>

    <insert id="insertBasicList">
        insert into xm_project_basicinformation
        (
        id,
        create_by,
        create_date,
        update_by,
        update_date,
        del_flag,
        remarks,
        reserveProjectName,
        municipalCompany,
        countyCompany,
        projectNature,
        demandUnit,
        operationUnit,
        powerSupplyArea,
        gridNumber,
        cellNumber,
        projectReserveNo,
        gridProjectNo,
        erpNo,
        necessityContent,
        subStationName,
        lineName,
        projectType,
        whetherSummer,
        basicDescription,
        workAreaRemarks
        )
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.id},
            #{item.createBy.id},
            #{item.createDate},
            #{item.updateBy.id},
            #{item.updateDate},
            #{item.delFlag},
            #{item.remarks},
            #{item.basicInformation.reserveProjectName},
            #{item.basicInformation.municipalCompany},
            #{item.basicInformation.countyCompany},
            #{item.basicInformation.projectNature},
            #{item.basicInformation.demandUnit},
            #{item.basicInformation.operationUnit},
            #{item.basicInformation.powerSupplyArea},
            #{item.basicInformation.gridNumber},
            #{item.basicInformation.cellNumber},
            #{item.basicInformation.projectReserveNo},
            #{item.basicInformation.gridProjectNo},
            #{item.basicInformation.erpNo},
            #{item.basicInformation.necessityContent},
            #{item.basicInformation.subStationName},
            #{item.basicInformation.lineName},
            #{item.basicInformation.projectType},
            #{item.basicInformation.whetherSummer},
            #{item.basicInformation.basicDescription},
            #{item.basicInformation.workAreaRemarks}
            )
        </foreach>
    </insert>

    <insert id="insertAssList">
        insert into xm_project_assignment
        (
        id,
        create_by,
        create_date,
        update_by,
        update_date,
        del_flag,
        remarks,
        reserveProjectName,
        disclosureType,
        projectReleaseBatch,
        deliveryDate,
        packageNo,
        rate,
        assignedUnit,
        constructionUnit,
        constructionSubcontractor,
        behalf,
        constructionFullTime,
        constructionTechnical,
        constructionManage,
        constructionLeader,
        subcontractingContact,
        designer,
        designLeader,
        ownerManager,
        distribution,
        distributionFullTime,
        distributionSystem,
        distributionPolicy,
        centerLeader,
        centerTechnical,
        instituteRole,
        repUnit,
        inspectionUnit
        )
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.id},
            #{item.createBy.id},
            #{item.createDate},
            #{item.updateBy.id},
            #{item.updateDate},
            #{item.delFlag},
            #{item.remarks},
            #{item.assignment.reserveProjectName},
            #{item.assignment.disclosureType},
            #{item.assignment.projectReleaseBatch},
            #{item.assignment.deliveryDate},
            #{item.assignment.packageNo},
            #{item.assignment.rate},
            #{item.assignment.assignedUnit},
            #{item.assignment.constructionUnit},
            #{item.assignment.constructionSubcontractor},
            #{item.assignment.behalf},
            #{item.assignment.constructionFullTime},
            #{item.assignment.constructionTechnical},
            #{item.assignment.constructionManage},
            #{item.assignment.constructionLeader},
            #{item.assignment.subcontractingContact},
            #{item.assignment.designer},
            #{item.assignment.designLeader},
            #{item.assignment.ownerManager},
            #{item.assignment.distribution},
            #{item.assignment.distributionFullTime},
            #{item.assignment.distributionSystem},
            #{item.assignment.distributionPolicy},
            #{item.assignment.centerLeader},
            #{item.assignment.centerTechnical},
            #{item.assignment.instituteRole},
            #{item.assignment.repUnit},
            #{item.assignment.inspectionUnit}
            )
        </foreach>
    </insert>

    <insert id="insertPlanList">
        insert into xm_project_disclosureplan
        (
        id,
        create_by,
        create_date,
        update_by,
        update_date,
        del_flag,
        remarks,
        reserveProjectName,
        powerSupplyStation,
        maintenance,
        automationContacts,
        liveSurveyContact,
        inspector,
        disclosurePlanDate
        )
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.id},
            #{item.createBy.id},
            #{item.createDate},
            #{item.updateBy.id},
            #{item.updateDate},
            #{item.delFlag},
            #{item.remarks},
            #{item.reserveProjectName},
            #{item.disclosurePlan.powerSupplyStation},
            #{item.disclosurePlan.maintenance},
            #{item.disclosurePlan.automationContacts},
            #{item.disclosurePlan.liveSurveyContact},
            #{item.disclosurePlan.inspector},
            #{item.disclosurePlan.disclosurePlanDate}
            )
        </foreach>
    </insert>

    <insert id="insertApprovalList">
        insert into xm_project_approval
        (
        id,
        create_by,
        create_date,
        update_by,
        update_date,
        del_flag,
        remarks,
        projectId,
        projectPackage,
        projectBudget,
        enterSystemAmount,
        afterAmount,
        adjustmentReasons,
        constructionCost,
        materialCost,
        designFee,
        supervisionFee,
        policyFee,
        otherExpenses
        )
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.id},
            #{item.createBy.id},
            #{item.createDate},
            #{item.updateBy.id},
            #{item.updateDate},
            #{item.delFlag},
            #{item.remarks},
            #{item.projectId},
            #{item.approval.projectPackage},
            #{item.approval.projectBudget},
            #{item.approval.enterSystemAmount},
            #{item.approval.afterAmount},
            #{item.approval.adjustmentReasons},
            #{item.approval.constructionCost},
            #{item.approval.materialCost},
            #{item.approval.designFee},
            #{item.approval.supervisionFee},
            #{item.approval.policyFee},
            #{item.approval.otherExpenses}
            )
        </foreach>
    </insert>

    <update id="updatePlanList">
        <foreach collection="list" item="item" index="index" separator=";">
            update xm_project_disclosureplan
            set
            powerSupplyStation = #{item.disclosurePlan.powerSupplyStation},
            maintenance = #{item.disclosurePlan.maintenance},
            automationContacts = #{item.disclosurePlan.automationContacts},
            liveSurveyContact = #{item.disclosurePlan.liveSurveyContact},
            inspector = #{item.disclosurePlan.inspector},
            disclosurePlanDate = #{item.disclosurePlan.disclosurePlanDate}
            where reserveProjectName =#{item.reserveProjectName}
        </foreach>
    </update>

    <insert id="insertTearList">
           insert into xm_tear_down
               (
                id,
                create_by,
                create_date,
                update_by,
                update_date,
                remarks,
                del_flag,
                reserveProjectName,
                reservedName,
                reserveModel,
                reserveUnit,
                reserveNumber,
                reserveBalance,
                reserveNotes,
                confessionName,
                confessionModel,
                confessionUnit,
                confessionNumber,
                confessionDifference,
                confessionNotes,
                changeName,
                changeModel,
                changeUnit,
                changeNumber,
                changeDifference,
                changeNotes,
                actualName,
                actualModel,
                actualUnit,
                actualNumber,
                actualDifference,
                actualNotes
            ) values
        <foreach collection="list" item="item" index="index" separator=",">
        (
            #{item.id},
            #{item.createBy.id},
            #{item.createDate},
            #{item.updateBy.id},
            #{item.updateDate},
            #{item.remarks},
            #{item.delFlag},
            #{item.reserveProjectName},
            #{item.tearDown.reservedName},
            #{item.tearDown.reserveModel},
            #{item.tearDown.reserveUnit},
            #{item.tearDown.reserveNumber},
            #{item.tearDown.reserveBalance},
            #{item.tearDown.reserveNotes},
            #{item.tearDown.confessionName},
            #{item.tearDown.confessionModel},
            #{item.tearDown.confessionUnit},
            #{item.tearDown.confessionNumber},
            #{item.tearDown.confessionDifference},
            #{item.tearDown.confessionNotes},
            #{item.tearDown.changeName},
            #{item.tearDown.changeModel},
            #{item.tearDown.changeUnit},
            #{item.tearDown.changeNumber},
            #{item.tearDown.changeDifference},
            #{item.tearDown.changeNotes},
            #{item.tearDown.actualName},
            #{item.tearDown.actualModel},
            #{item.tearDown.actualUnit},
            #{item.tearDown.actualNumber},
            #{item.tearDown.actualDifference},
            #{item.tearDown.actualNotes}
            )
        </foreach>
    </insert>


    <update id="updateBasicList">
        <foreach collection="list" item="item" index="index" separator=";">
            update xm_project_basicinformation
            set
            powerSupplyArea = #{item.basicInformation.powerSupplyArea},
            gridNumber = #{item.basicInformation.gridNumber},
            cellNumber = #{item.basicInformation.cellNumber},
            projectReserveNo = #{item.basicInformation.projectReserveNo},
            gridProjectNo = #{item.basicInformation.gridProjectNo},
            necessityContent = #{item.basicInformation.necessityContent},
            subStationName = #{item.basicInformation.subStationName},
            lineName = #{item.basicInformation.lineName},
            whetherSummer=#{item.basicInformation.whetherSummer},
            basicDescription = #{item.basicInformation.basicDescription},
            workAreaRemarks = #{item.basicInformation.workAreaRemarks}
            where reserveProjectName =#{item.basicInformation.reserveProjectName}
        </foreach>
    </update>

    <update id="updateAssList">
        <foreach collection="list" item="item" index="index" separator=";">
            update xm_project_assignment
            set
            deliveryDate = #{item.assignment.deliveryDate},
            packageNo = #{item.assignment.packageNo},
            rate = #{item.assignment.rate},
            constructionSubcontractor = #{item.assignment.constructionSubcontractor},
            behalf = #{item.assignment.behalf},
            subcontractingContact = #{item.assignment.subcontractingContact},
            instituteRole = #{item.assignment.instituteRole}
            where reserveProjectName =#{item.reserveProjectName}
        </foreach>
    </update>

    <update id="updateApprovalList">
        <foreach collection="list" item="item" index="index" separator=";">
            update xm_project_approval
            set
            projectPackage = #{item.approval.projectPackage},
            projectBudget = #{item.approval.projectBudget},
            enterSystemAmount = #{item.approval.enterSystemAmount},
            afterAmount = #{item.approval.afterAmount},
            adjustmentReasons = #{item.approval.adjustmentReasons},
            constructionCost = #{item.approval.constructionCost},
            materialCost = #{item.approval.materialCost},
            designFee = #{item.approval.designFee},
            supervisionFee = #{item.approval.supervisionFee},
            policyFee = #{item.approval.policyFee},
            otherExpenses = #{item.approval.otherExpenses}
            where projectId =#{item.projectId}
        </foreach>
    </update>

    <select id="allProjectName" resultType="java.lang.String">
        select reserveProjectName
        from xm_material_project
    </select>

    <select id="allProjectId" resultType="java.lang.String">
        select projectId
        from xm_material_project
        where projectId != '' and secondPower = '0'
    </select>

    <select id="findProByName" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        SELECT
        <include refid="projectColumns"/>,
        <include refid="basicColumns"/>
        from xm_material_project a
        left join xm_project_basicinformation b
        on a.reserveProjectName = b.reserveProjectName
        WHERE b.reserveProjectName = #{name}
    </select>

    <select id="findTearByName" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        SELECT
        <include refid="projectColumns"/>,
        <include refid="tearColumns"/>
        from xm_material_project a
        left join xm_tear_down t
        on a.reserveProjectName = t.reserveProjectName
        WHERE t.reserveProjectName = #{name}
    </select>

    <select id="findAssByName" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        SELECT
        <include refid="projectColumns"/>,
        <include refid="assignmentColumns"/>
        from xm_material_project a
        left join xm_project_assignment c
        on a.reserveProjectName = c.reserveProjectName
        WHERE c.reserveProjectName = #{name}
    </select>

    <select id="findPlanByName" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select
        a.status,
        <include refid="planColumns"/>,
        <include refid="assignmentColumns"/>
        from xm_material_project a
        left join xm_project_basicinformation b
        on a.reserveProjectName = b.reserveProjectName
        left join xm_project_assignment c
        on a.reserveProjectName = c.reserveProjectName
        left join xm_project_disclosurePlan d
        on a.reserveProjectName = d.reserveProjectName
        WHERE d.reserveProjectName = #{name}
    </select>


    <select id="findApprovalByName" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select
        <include refid="projectColumns"/>,
        <include refid="approvalColumns"/>
        from xm_material_project a
        left join xm_project_approval e
        on a.projectId = e.projectId
        WHERE e.projectId = #{id}
    </select>

    <update id="updateBasic">
        update xm_project_basicinformation
        set powerSupplyArea  = #{basicInformation.powerSupplyArea},
            gridNumber       = #{basicInformation.gridNumber},
            cellNumber       = #{basicInformation.cellNumber},
            projectReserveNo = #{basicInformation.projectReserveNo},
            gridProjectNo    = #{basicInformation.gridProjectNo},
            necessityContent = #{basicInformation.necessityContent},
            subStationName   = #{basicInformation.subStationName},
            lineName         = #{basicInformation.lineName},
            whetherSummer=#{basicInformation.whetherSummer},
            basicDescription = #{basicInformation.basicDescription},
            workAreaRemarks  = #{basicInformation.workAreaRemarks}
        where reserveProjectName = #{basicInformation.reserveProjectName}
    </update>

    <select id="findAllList" resultType="Project">
        SELECT
        <include refid="projectColumns"/>
        FROM xm_project_details a
        <where>
            a.del_flag = #{DEL_FLAG_NORMAL}
            ${dataScope}
        </where>
        <choose>
            <when test="page !=null and page.orderBy != null and page.orderBy != ''">
                ORDER BY ${page.orderBy}
            </when>
            <otherwise>
                ORDER BY a.update_date DESC
            </otherwise>
        </choose>
    </select>

    <insert id="insert">
        INSERT INTO xm_project_details
        (id,
         create_by,
         create_date,
         update_by,
         update_date,
         remarks,
         del_flag,
         pro_type,
         demand_unit,
         bdz_name,
         line_name,
         require_name,
         project_id,
         project_name,
         project_number,
         project_manage_role,
         distribution_engineering,
         distribution_materials,
         distribution_system,
         distribution_policy,
         management_leader,
         run_unit,
         run_unit_role,
         through_research_role,
         construction_unit,
         construction_unit_role,
         construction_unit_manage,
         construction_unit_leader,
         design_unit,
         design_unit_manage,
         design_unit_leader,
         clarificaiton_type,
         build_classification_resons,
         bulbid_resons,
         asic_equipment,
         run_the_class,
         project_team,
         cost_estimate,
         whether_rhe_upwind,
         sure_da_date,
         text_remark,
         power_line,
         power_scope,
         project_type,
         power_flag_package,
         preliminary_judgment,
         flag_civil_engineering,
         steel_tube_pole,
         flag_approval_planning,
         equ_create_type,
         equ_create_size,
         flag_new_equ_name,
         include_bdz_news,
         flag_no_electrical,
         drawings_work,
         flag_automation,
         two_and_three_remote,
         phone_style,
         stay_open_area,
         ring_network_cabinet,
         station_dtu,
         reserve_number,
         run_unit_inspection_role,
         construction_contract_unit,
         construction_contract_rate,
         construction_contract_sub,
         construction_skill_by_full,
         automated_remarks,
         skill_by_full,
         status,
         acquisition_status,
         construction_status,
         whether_close_status,
         earlyMaterial,
         preConstruction,
         rezkey)
        VALUES (#{id},
                #{createBy.id},
                #{createDate},
                #{updateBy.id},
                #{updateDate},
                #{remarks},
                #{delFlag},
                #{type},
                #{demandUnit},
                #{bdzName},
                #{lineName},
                #{requireName},
                #{projectId},
                #{projectName},
                #{projectNumber},
                #{projectManageRole},
                #{distributionEngineering},
                #{distributionMaterials},
                #{distributionSystem},
                #{distributionPolicy},
                #{managementLeader},
                #{runUnit},
                #{runUnitRole},
                #{throughResearchRole},
                #{constructionUnit},
                #{constructionUnitRole},
                #{constructionUnitManage},
                #{constructionUnitLeader},
                #{designUnit},
                #{designUnitManage},
                #{designUnitLeader},
                #{clarificaitonType},
                #{bulidClassificationResons},
                #{bulbidResons},
                #{asicEquipment},
                #{runTheClass},
                #{projectTeam},
                #{costEstimate},
                #{whetherRheUpwind},
                #{sureDaDate},
                #{textRemark},
                #{powerLine},
                #{powerScope},
                #{projectType},
                #{powerFlagPackage},
                #{preliminaryJudgment},
                #{flagCivilEngineering},
                #{steelTubePole},
                #{flagApprovalPlanning},
                #{equCreateType},
                #{equCreateSize},
                #{flagNewEquName},
                #{includeBdzNews},
                #{flagNoElectrical},
                #{drawingsWork},
                #{flagAutomation},
                #{twoAndThreeRemote},
                #{phoneStyle},
                #{stayOpenArea},
                #{ringNetworkCabinet},
                #{stationDtu},
                #{reserveNumber},
                #{runUnitInspectionRole},
                #{constructionContractUnit},
                #{constructionContractRate},
                #{constructionContractSub},
                #{constructionSkillByFull},
                #{automatedRemarks},
                #{skillByFull},
                #{status},
                #{acquisitionStatus},
                #{constructionStatus},
                #{whetherCloseStatus},
                #{earlyMaterial},
                #{preConstruction},
                #{rezkey})
    </insert>

    <!--<insert id="insertList">
        replace INTO xm_project_details(
        id,
        create_by,
        create_date,
        update_by,
        update_date,
        remarks,
        del_flag,
        pro_type,
        demand_unit,
        bdz_name,
        line_name,
        require_name,
        project_id,
        project_name,
        project_number,
        project_manage_role,
        distribution_engineering,
        distribution_materials,
        distribution_system,
        distribution_policy,
        management_leader,
        run_unit,
        run_unit_role,
        through_research_role,
        construction_unit,
        construction_unit_role,
        construction_unit_manage,
        construction_unit_leader,
        design_unit,
        design_unit_manage,
        design_unit_leader,
        clarificaiton_type,
        build_classification_resons,
        bulbid_resons,
        asic_equipment,
        run_the_class,
        project_team,
        cost_estimate,
        whether_rhe_upwind,
        sure_da_date,
        text_remark,
        power_line,
        power_scope,
        project_type,
        power_flag_package,
        preliminary_judgment,
        flag_civil_engineering,
        steel_tube_pole,
        flag_approval_planning,
        equ_create_type,
        equ_create_size,
        flag_new_equ_name,
        include_bdz_news,
        flag_no_electrical,
        drawings_work,
        flag_automation,
        two_and_three_remote,
        phone_style,
        stay_open_area,
        ring_network_cabinet,
        station_dtu,
        reserve_number,
        run_unit_inspection_role,
        construction_contract_unit,
        construction_contract_rate,
        construction_contract_sub,
        construction_skill_by_full,
        automated_remarks,
        skill_by_full,
        status,
        acquisition_status,
        construction_status,
        whether_close_status,
        earlyMaterial,
        preConstruction,
        rezkey
        ) VALUES
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.id},
            #{item.createBy.id},
            #{item.createDate},
            #{item.updateBy.id},
            #{item.updateDate},
            #{item.remarks},
            #{item.delFlag},
            #{item.type},
            #{item.demandUnit},
            #{item.bdzName},
            #{item.lineName},
            #{item.requireName},
            #{item.projectId},
            #{item.projectName},
            #{item.projectNumber},
            #{item.projectManageRole},
            #{item.distributionEngineering},
            #{item.distributionMaterials},
            #{item.distributionSystem},
            #{item.distributionPolicy},
            #{item.managementLeader},
            #{item.runUnit},
            #{item.runUnitRole},
            #{item.throughResearchRole},
            #{item.constructionUnit},
            #{item.constructionUnitRole},
            #{item.constructionUnitManage},
            #{item.constructionUnitLeader},
            #{item.designUnit},
            #{item.designUnitManage},
            #{item.designUnitLeader},
            #{item.clarificaitonType},
            #{item.bulidClassificationResons},
            #{item.bulbidResons},
            #{item.asicEquipment},
            #{item.runTheClass},
            #{item.projectTeam},
            #{item.costEstimate},
            #{item.whetherRheUpwind},
            #{item.sureDaDate},
            #{item.textRemark},
            #{item.powerLine},
            #{item.powerScope},
            #{item.projectType},
            #{item.powerFlagPackage},
            #{item.preliminaryJudgment},
            #{item.flagCivilEngineering},
            #{item.steelTubePole},
            #{item.flagApprovalPlanning},
            #{item.equCreateType},
            #{item.equCreateSize},
            #{item.flagNewEquName},
            #{item.includeBdzNews},
            #{item.flagNoElectrical},
            #{item.drawingsWork},
            #{item.flagAutomation},
            #{item.twoAndThreeRemote},
            #{item.phoneStyle},
            #{item.stayOpenArea},
            #{item.ringNetworkCabinet},
            #{item.stationDtu},
            #{item.reserveNumber},
            #{item.runUnitInspectionRole},
            #{item.constructionContractUnit},
            #{item.constructionContractRate},
            #{item.constructionContractSub},
            #{item.constructionSkillByFull},
            #{item.automatedRemarks},
            #{item.skillByFull},
            #{item.status},
            #{item.acquisitionStatus},
            #{item.constructionStatus},
            #{item.whetherCloseStatus},
            #{item.earlyMaterial},
            #{item.preConstruction},
            #{item.rezkey}
            )
        </foreach>
    </insert>-->

    <insert id="insertSgProject">
        insert into xm_material_project(
            id,
            create_by,
            create_date,
            update_by,
            update_date,
            remarks,
            del_flag,
            projectName,
            projectId,
            projectType,
            attributionYear,
            arrageProject,
            secondPower,
            reserveProjectName
        )
        values(
                  #{id},
                  #{createBy.id},
                  #{createDate},
                  #{updateBy.id},
                  #{updateDate},
                  #{remarks},
                  #{delFlag},
                  #{projectName},
                  #{projectId},
                  #{projectType},
                  #{attributionYear},
                  #{arrageProject},
                  #{secondPower},
                  #{reserveProjectName}
         )ON DUPLICATE KEY UPDATE
           update_by = #{updateBy.id},
           update_date = #{updateDate}
    </insert>
    <insert id="insertSgQuantity">
        insert into xm_project_quantity(
            id,
            create_by,
            create_date,
            update_by,
            update_date,
            del_flag,
            remarks,
            reserveProjectName,
            includeAutomation,
            wayOf,
            assignmentStyle,
            operationSubstation,
            namingNumber,
            engineeringAcceptance,
            electricalAcceptance,
            blackoutLine,
            outageRange,
            policyIssues,
            processingType,
            processingDescription
        ) values (
             #{id},
             #{createBy.id},
             #{createDate},
             #{updateBy.id},
             #{updateDate},
             #{delFlag},
             #{remarks},
             #{reserveProjectName},
             #{includeAutomation},
             #{wayOf},
             #{assignmentStyle},
             #{operationSubstation},
             #{namingNumber},
             #{engineeringAcceptance},
             #{electricalAcceptance},
             #{blackoutLine},
             #{outageRange},
             #{policyIssues},
             #{processingType},
             #{processingDescription}
        )
    </insert>

    <update id="update">
        UPDATE xm_project_details
        SET update_by                  = #{updateBy.id},
            update_date                = #{updateDate},
            remarks                    = #{remarks},
            pro_type=#{type},
            demand_unit=#{demandUnit},
            bdz_name=#{bdzName},
            line_name=#{lineName},
            require_name=#{requireName},
            project_id=#{projectId},
            project_name=#{projectName},
            project_number=#{projectNumber},
            project_manage_role=#{projectManageRole},
            distribution_engineering=#{distributionEngineering},
            distribution_materials=#{distributionMaterials},
            distribution_system=#{distributionSystem},
            distribution_policy=#{distributionPolicy},
            management_leader=#{managementLeader},
            run_unit=#{runUnit},
            run_unit_role=#{runUnitRole},
            through_research_role=#{throughResearchRole},
            construction_unit=#{constructionUnit},
            construction_unit_role=#{constructionUnitRole},
            construction_unit_manage=#{constructionUnitManage},
            construction_unit_leader=#{constructionUnitLeader},
            design_unit=#{designUnit},
            design_unit_manage=#{designUnitManage},
            design_unit_leader=#{designUnitLeader},
            clarificaiton_type=#{clarificaitonType},
            build_classification_resons=#{bulidClassificationResons},
            bulbid_resons=#{bulbidResons},
            asic_equipment=#{asicEquipment},
            run_the_class=#{runTheClass},
            project_team=#{projectTeam},
            cost_estimate=#{costEstimate},
            whether_rhe_upwind=#{whetherRheUpwind},
            sure_da_date=#{sureDaDate},
            text_remark=#{textRemark},
            power_line=#{powerLine},
            power_scope=#{powerScope},
            project_type=#{projectType},
            power_flag_package=#{powerFlagPackage},
            preliminary_judgment=#{preliminaryJudgment},
            flag_civil_engineering=#{flagCivilEngineering},
            steel_tube_pole=#{steelTubePole},
            flag_approval_planning=#{flagApprovalPlanning},
            equ_create_type=#{equCreateType},
            equ_create_size=#{equCreateSize},
            flag_new_equ_name=#{flagNewEquName},
            include_bdz_news=#{includeBdzNews},
            flag_no_electrical=#{flagNoElectrical},
            drawings_work=#{drawingsWork},
            flag_automation=#{flagAutomation},
            two_and_three_remote=#{twoAndThreeRemote},
            phone_style=#{phoneStyle},
            stay_open_area=#{stayOpenArea},
            ring_network_cabinet=#{ringNetworkCabinet},
            station_dtu=#{stationDtu},
            reserve_number=#{reserveNumber},
            run_unit_inspection_role=#{runUnitInspectionRole},
            construction_contract_unit=#{constructionContractUnit},
            construction_contract_rate=#{constructionContractRate},
            construction_contract_sub=#{constructionContractSub},
            construction_skill_by_full=#{constructionSkillByFull},
            automated_remarks=#{automatedRemarks},
            skill_by_full=#{skillByFull}
        WHERE id = #{id}
    </update>

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

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


  <!--  &lt;!&ndash; 根据实体名称和字段名称和字段值获取唯一记录 &ndash;&gt;
    <select id="findUniqueByProperty" resultType="Project" statementType="STATEMENT">
        select *
        FROM xm_project_details
        where ${id} = '${value}'
    </select>
-->
    <!--根据项目名称修改项目施工交底状态0未发起施工交底，1施工交底过程中，2完成施工交底-->
<!--    <update id="updateStatusBy">
        update xm_material_project
        set acquisitionStatus = #{acquisitionStatus}
        where projectId = #{projectId}
    </update>-->
<!--
    &lt;!&ndash; 修改项目关闭状态&ndash;&gt;
    <update id="updateStatusByClose">
        update xm_project_details
        set whether_close_status = #{close}
        where require_name = (select project_name from xm_construction_clarificaiton where proc_ins_id = #{procInsId});
    </update>
-->

    <!--修改项目领料状态状态0未发起-->
<!--    <update id="updateAcquisitionStatus">
        update xm_project_details
        set acquisition_status = #{acquisitionStatus}
        where id = #{id};
    </update>-->

    <!--修改提前施工状态0未提前施工，1提前施工-->
<!--    <update id="updatePreConstruction">
        update xm_project_details
        set preConstruction = #{preConstruction}
        where id = #{id};
    </update>-->
    <update id="updateAdvanceStart">
        update xm_material_project
        set advanceStatus = #{numerical}
        where reserveProjectName = #{reserveProjectName};
    </update>
    <update id="updateAdvCon">
        update xm_material_project
        set advanceConstruction = #{status}
        where reserveProjectName = #{reserveProjectName}
    </update>


    <select id="findListById" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        SELECT
        <include refid="projectColumns"/>,
        <include refid="basicColumns"/>,
        <include refid="assignmentColumns"/>
        from xm_material_project a
        left join xm_project_basicinformation b
        on a.reserveProjectName = b.reserveProjectName
        left join xm_project_assignment c
        on a.reserveProjectName = c.reserveProjectName
        where a.id in
        <foreach collection="array" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>

<!--    <select id="findListProject" parameterType="java.util.List"
            resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select
        <include refid="projectColumns"/>
        FROM xm_project_details a
        WHERE a.del_flag = '0'
        and a.require_name in
        <if test="list != null">
            <foreach collection="list" index="index" item="item" open="("
                     separator="," close=")">
                #{item.requireName}
            </foreach>
        </if>
    </select>-->

    <select id="findUser" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select
        <include refid="assignmentColumns"/>
        FROM xm_project_assignment c
        WHERE reserveProjectName = (select reserveProjectName from xm_construction_clarificaiton where proc_ins_id =
        #{procInsId});
    </select>

    <select id="findTJUser" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select
        <include refid="assignmentColumns"/>
        FROM xm_project_assignment c
        WHERE reserveProjectName = (select reserveProjectName from xm_nonpower_process where proc_ins_id =
        #{procInsId});
    </select>

    <select id="findWZUser" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select
        <include refid="assignmentColumns"/>
        FROM xm_project_assignment c
        WHERE reserveProjectName = (
        select reserveProjectName
        from md_acquisition_process
        where proc_ins_id = #{procInsId});
    </select>

    <select id="findSGUser" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select
        <include refid="assignmentColumns"/>
        FROM xm_project_assignment c
        WHERE reserveProjectName = (
        select reserveProjectName
        from sg_construction_process
        where proc_ins_id = #{procInsId});
    </select>

    <!--<select id="findJSUser" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select id,
               demand_unit,
               project_manage_role,
               distribution_engineering,
               distribution_materials,
               distribution_system,
               distribution_policy,
               management_leader,
               run_unit,
               run_unit_role,
               through_research_role,
               construction_unit,
               construction_unit_role,
               construction_unit_manage,
               construction_unit_leader,
               design_unit,
               design_unit_manage,
               design_unit_leader
        FROM xm_project_details
        WHERE require_name = (select projectName from xm_settlement_process where proc_ins_id = #{procInsId});
    </select>-->

    <select id="findFundUser" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select
        <include refid="assignmentColumns"/>
        FROM xm_project_assignment c
        WHERE reserveProjectName = (
            select reserveProjectName
            from xm_fund_process
            where proc_ins_id =#{procInsId}
            );
    </select>

    <!--<select id="findUserById" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select id,
               project_name,
               demand_unit,
               project_manage_role,
               distribution_engineering,
               distribution_materials,
               distribution_system,
               distribution_policy,
               management_leader,
               run_unit,
               run_unit_role,
               through_research_role,
               construction_unit,
               construction_unit_role,
               construction_unit_manage,
               construction_unit_leader,
               design_unit,
               design_unit_manage,
               design_unit_leader
        FROM xm_project_details
        WHERE id = #{projectId}
    </select>-->


<!--    <select id="findListProjectRequisitions" parameterType="java.util.List"
            resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select
        <include refid="projectColumns"/>
        FROM xm_project_details a
        WHERE a.del_flag = '0'
        and a.project_number in
        <if test="list != null">
            <foreach collection="list" index="index" item="item" open="("
                     separator="," close=")">
                #{item.projectDefinition}
            </foreach>
        </if>
    </select>-->

<!--
    <select id="findAllUser" resultType="java.lang.String">
        &lt;!&ndash; 查询全部用户 &ndash;&gt;
        SELECT
        a.name AS "name"
        FROM sys_user a
        WHERE a.del_flag = '0'
    </select>
-->

    <select id="findDefId" resultType="java.lang.String">
        select ID_
        FROM act_re_procdef
        where KEY_ = #{key}
          and VERSION_ = (select MAX(VERSION_) FROM act_re_procdef where KEY_ = #{key})
    </select>

<!--    <select id="findIdConProc" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project1">
        select id, construction_unit_manage
        from xm_project_details
        where project_id = (
            select project_Id
            from xm_construction_clarificaiton
            where proc_ins_id = #{procInsId}
        )
    </select>-->

<!--    <select id="findProjectList" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select id, reserveProjectName, projectId, projectName
        from xm_material_project
        where projectId != ''
          and projectName != ''
    </select>-->
    <select id="reserveProjectNameById" resultType="java.lang.String">
        select reserveProjectName
        from xm_material_project
        where id = #{id}
    </select>
    <select id="demandByProcInsId" resultType="java.lang.String">
        select demandUnit
        from xm_project_basicinformation
        where reserveProjectName =
              (select reserveProjectName from xm_construction_clarificaiton where proc_ins_id = #{procInsId});
    </select>
    <select id="findPlanIdByName" resultType="java.lang.String">
        select id
        from xm_construction_clarificaiton
        where reserveProjectName = #{name};
    </select>
    <select id="findByProcInsId" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select a.reserveProjectName,
        a.projectId,
        a.projectName,
        a.acquisitionStatus,
        a.advanceStatus,
        <include refid="assignmentColumns"/>
        from xm_material_project a
        LEFT JOIN xm_construction_clarificaiton b
        on a.reserveProjectName = b.reserveProjectName
        left join xm_project_assignment c
        on a.reserveProjectName = c.reserveProjectName
        where b.proc_ins_id = #{procInsId};
    </select>
    <select id="findByName" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select
        a.id,
        a.reserveProjectName,
        a.projectId,
        a.projectName,
        a.status,
        a.acquisitionStatus,
        a.advanceStatus,
        a.constructionStatus,
        a.settStatus,
        a.policyStatus,
        a.whetherCloseStatus,
        a.canEnter,
        <include refid="assignmentColumns"/>
        from xm_material_project a
        LEFT JOIN xm_construction_clarificaiton b
        on a.reserveProjectName = b.reserveProjectName
        left join xm_project_assignment c
        on a.reserveProjectName = c.reserveProjectName
        where a.reserveProjectName = #{reserveProjectName};
    </select>
    <select id="findMaterialProject"
            resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select id, projectId, projectName
        from xm_material_project
        where id = #{id};
    </select>

    <select id="findAllInfo"
            resultType="com.jeeplus.modules.sg.managementcenter.materialinfo.entity.MaterialInfo">
        select project_name,
               material_code,
               material_name,
               extend_description,
               total_count,
               weight_kg,
               weight_ton,
               supply_type
        from xm_material_data
        where project_name = (select reserveProjectName from xm_material_project where id = #{id})
    </select>

    <select id="findSgInfo"
            resultType="com.jeeplus.modules.sg.managementcenter.materialinfo.entity.MaterialInfo">
        select project_name,
               material_code,
               material_name,
               extend_description,
               total_count,
               weight_kg,
               weight_ton,
               supply_type
        from xm_material_data
        where project_name = (select reserveProjectName from sg_construction_process where id = #{id})
    </select>

    <select id="findBlockAss" resultType="com.jeeplus.modules.sg.managementcenter.activiti.entity.Construction">
        SELECT
        a.reserveProjectName,
        a.projectId,
        a.projectName,
        xpq.blackoutLine as `quantity.blackoutLine`,
        <include refid="assignmentColumns"/>
        FROM
        xm_material_project a
        left join xm_project_quantity xpq
        on a.reserveProjectName = xpq.reserveProjectName
        LEFT JOIN xm_project_assignment c
        ON a.reserveProjectName = c.reserveProjectName
        WHERE xpq.reserveProjectName = (
        SELECT reserveProjectName
        FROM xm_material_project
        WHERE id = #{id}
        )
    </select>

    <select id="findWzAss" resultType="com.jeeplus.modules.sg.managementcenter.activiti.entity.Construction">
        SELECT
        a.reserveProjectName,
        a.projectId,
        a.projectName,
        xpq.blackoutLine as `quantity.blackoutLine`,
        <include refid="assignmentColumns"/>
        FROM
        xm_material_project a
        left join xm_project_quantity xpq
        on a.reserveProjectName = xpq.reserveProjectName
        LEFT JOIN xm_project_assignment c
        ON a.reserveProjectName = c.reserveProjectName
        WHERE xpq.reserveProjectName = (
        SELECT reserveProjectName
        FROM md_acquisition_process
        WHERE proc_ins_id = #{procInsId}
        )
    </select>

    <select id="findSgBlockAss"
            resultType="com.jeeplus.modules.sg.managementcenter.activiti.entity.Construction">
        SELECT
        a.reserveProjectName,
        a.projectId,
        a.projectName,
        xpq.blackoutLine as `quantity.blackoutLine`,
        <include refid="assignmentColumns"/>
        FROM
        xm_material_project a
        left join xm_project_quantity xpq
        on a.reserveProjectName = xpq.reserveProjectName
        LEFT JOIN xm_project_assignment c
        ON a.reserveProjectName = c.reserveProjectName
        WHERE xpq.reserveProjectName = (
        SELECT reserveProjectName
        FROM sg_construction_process
        WHERE id = #{id}
        )
    </select>

    <select id="findSgProject" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select *
        from xm_material_project
        where reserveProjectName = (
            select reserveProjectName
            from sg_construction_process
            where proc_ins_id = #{procInsId});
    </select>

    <select id="findSgAss" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Assignment">
        select *
        from xm_project_assignment
        where reserveProjectName = (
            select reserveProjectName
            from sg_construction_process
            where proc_ins_id = #{procInsId});
    </select>


    <select id="findSgQuantity" resultType="com.jeeplus.modules.sg.managementcenter.activiti.entity.Quantity">
        select *
        from xm_project_quantity
        where reserveProjectName =(
            select reserveProjectName
            from sg_construction_process
            where proc_ins_id = #{procInsId});
    </select>

    <update id="updateSgStatus">
        update xm_material_project
        set constructionStatus = #{status}
        where reserveProjectName =(
            select reserveProjectName
            from sg_construction_process
            where proc_ins_id = #{procInsId});
    </update>
    <update id="updateTjStatus">
        update xm_material_project
        set advanceStatus = #{status}
        where reserveProjectName =(
            select reserveProjectName
            from xm_nonpower_process
            where proc_ins_id = #{procInsId});
    </update>
    <update id="updateWzStatus">
        update xm_material_project
        set acquisitionStatus = #{status}
        where reserveProjectName =(
            select reserveProjectName
            from md_acquisition_process
            where proc_ins_id = #{procInsId});
    </update>
    <select id="findSgProcInsId" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select a.reserveProjectName,
        a.projectId,
        a.projectName,
        a.constructionStatus,
        a.advanceStatus,
        <include refid="assignmentColumns"/>
        from xm_material_project a
        left join xm_project_assignment c
        on a.reserveProjectName = c.reserveProjectName
        where
        a.reserveProjectName =(
            SELECT
            reserveProjectName
            FROM
            sg_construction_process
            WHERE
            proc_ins_id = #{procInsId})
    </select>
    <select id="findWzProcInsId" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select a.reserveProjectName,
        a.projectId,
        a.projectName,
        a.acquisitionStatus,
        a.constructionStatus,
        a.canEnter,
        xpq.blackoutLine as `quantity.blackoutLine`,
        <include refid="assignmentColumns"/>
        from xm_material_project a
        left join xm_project_assignment c
        on a.reserveProjectName = c.reserveProjectName
        left join xm_project_quantity xpq
        on a.reserveProjectName = xpq.reserveProjectName
        where a.reserveProjectName =(
        select reserveProjectName
        from md_acquisition_process
        where proc_ins_id = #{procInsId})
    </select>
    <select id="findTjProcInsId" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select a.reserveProjectName,
        a.projectId,
        a.projectName,
        a.constructionStatus,
        a.advanceStatus,
        <include refid="assignmentColumns"/>
        from xm_material_project a
        left join xm_project_assignment c
        on a.reserveProjectName = c.reserveProjectName
        where
        a.reserveProjectName =(
        SELECT
        reserveProjectName
        FROM
        xm_nonpower_process
        WHERE
        proc_ins_id = #{procInsId})
    </select>

    <select id="findWzInfo"
            resultType="com.jeeplus.modules.sg.managementcenter.materialinfo.entity.MaterialInfo">
        select project_name,
               material_code,
               material_name,
               extend_description,
               total_count,
               weight_kg,
               weight_ton,
               supply_type
        from xm_material_data
        where project_name = (select reserveProjectName from md_acquisition_process where proc_ins_id = #{porcInsId})
    </select>
    <select id="findTearDownList" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select
        t.id,
        a.projectId,
        a.projectName,
        a.reserveProjectName,
        <include refid="tearColumns"/>
        from xm_tear_down t
        left join xm_material_project a
        on t.reserveProjectName = a.reserveProjectName
        <where>
            1 = 1
            <if test="reserveList != null and  reserveList !='' ">
                and t.reserveProjectName in
                <foreach collection="reserveList" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="projectId != null and projectId !=''">
                and a.projectId like concat('%', #{projectId}, '%')
            </if>
            <if test="projectName !=null and projectName !=''">
                and a.projectName like concat('%', #{projectName}, '%')
            </if>
            ${dataScope}
        </where>
        order by a.reserveProjectName
    </select>
    <select id="getTear" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project">
        select
        t.id,
        a.projectId,
        a.projectName,
        a.reserveProjectName,
        <include refid="tearColumns"/>
        from xm_tear_down t
        left join xm_material_project a
        on t.reserveProjectName = a.reserveProjectName
        where t.id = #{id}
    </select>
    <select id="isNotByName" resultType="java.lang.Integer">
        select count(*) from xm_tear_down where reserveProjectName = #{reserveProjectName} and reservedName = #{reservedName}
    </select>
    <select id="findClosureManagementList" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.ClosureManage">
        SELECT
        <include refid="projectColumns"/>,
        <include refid="capitalPlanColumns"/>,
        <include refid="approvalColumns"/>
        FROM xm_material_project a
        left join xm_capital_plan cp
        on a.projectId = cp.projectId
        left join xm_project_approval e
        on a.projectId = e.projectId
        <where>
            1 = 1
            and a.secondPower = '0'
            <if test="reserveList != null and  reserveList !='' ">
                and t.reserveProjectName in
                <foreach collection="reserveList" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            ${dataScope}
        </where>
        order by a.reserveProjectName
    </select>
    <update id="updateJsStatus">
        update xm_material_project
        set settStatus = #{status}
        where reserveProjectName =#{reserveProjectName};
    </update>
    <update id="wzStatusByName">
        update xm_material_project
        set acquisitionStatus = #{status}
        where reserveProjectName =#{reserveProjectName};
    </update>
    <update id="tearEditSave">
        update xm_tear_down
        set reserveModel = #{tearDown.reserveModel},
            reserveUnit = #{tearDown.reserveUnit},
            reserveNumber = #{tearDown.reserveNumber},
            reserveNotes = #{tearDown.reserveNotes}
        where id = #{id}
    </update>
    <update id="updateTearList">
        <foreach collection="list" index="index" item="item" separator=";">
                update xm_tear_down
                set reserveModel = #{item.tearDown.reserveModel},
                    reserveUnit = #{item.tearDown.reserveUnit},
                    reserveNumber = #{item.tearDown.reserveNumber},
                    reserveNotes = #{item.tearDown.reserveNotes}
                where reserveProjectName = #{item.reserveProjectName}
                      and reservedName = #{item.tearDown.reservedName}
        </foreach>
    </update>
    <update id="updateDesTearList">
        <foreach collection="list" index="index" item="item" separator=";">
            update xm_tear_down
            set changeModel = #{item.tearDown.changeModel},
            changeUnit = #{item.tearDown.changeUnit},
            changeNumber = #{item.tearDown.changeNumber},
            changeNotes = #{item.tearDown.changeNotes}
            where reserveProjectName = #{item.reserveProjectName}
            and reservedName = #{item.tearDown.reservedName}
        </foreach>
    </update>
    <update id="updateConTearList">
        <foreach collection="list" index="index" item="item" separator=";">
            update xm_tear_down
            set confessionModel = #{item.tearDown.confessionModel},
            confessionUnit = #{item.tearDown.confessionUnit},
            confessionNumber = #{item.tearDown.confessionNumber},
            confessionNotes = #{item.tearDown.confessionNotes}
            where reserveProjectName = #{item.reserveProjectName}
            and reservedName = #{item.tearDown.reservedName}
        </foreach>
    </update>
    <update id="updateFinTearList">
        <foreach collection="list" index="index" item="item" separator=";">
            update xm_tear_down
            set actualModel = #{item.tearDown.actualModel},
            actualUnit = #{item.tearDown.actualUnit},
            actualNumber = #{item.tearDown.actualNumber},
            actualNotes = #{item.tearDown.actualNotes}
            where reserveProjectName = #{item.reserveProjectName}
            and reservedName = #{item.tearDown.reservedName}
        </foreach>
    </update>
    <update id="updateClosure">
        update xm_material_project
        set whetherCloseStatus = '1'
        where id  = #{id}
    </update>

    <select id="findBtnExport" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.BeforeExport">
        select
        <include refid="projectColumns"/>,
        b.municipalCompany,
        b.countyCompany,
        b.projectNature,
        b.demandUnit,
        b.operationUnit,
        b.powerSupplyArea,
        b.gridNumber,
        b.cellNumber,
        b.projectReserveNo,
        b.gridProjectNo,
        b.erpNo,
        b.necessityContent,
        b.subStationName,
        b.lineName,
        b.projectType,
        b.whetherSummer,
        b.basicDescription,
        b.workAreaRemarks
        from xm_material_project a
        left join xm_project_basicinformation b
        on a.reserveProjectName = b.reserveProjectName
        <where>
            1 = 1
            and
            a.secondPower = 0
            and a.whetherCloseStatus = '0'
            <if test="reserveProjectName!=null and reserveProjectName!=''">
                and a.reserveProjectName = #{reserveProjectName}
            </if>
            <if test="projectId!=null and projectId!=''">
                and a.projectId = #{projectId}
            </if>
            <if test="projectName!=null and projectName!=''">
                and a.projectName = #{projectName}
            </if>
            <if test="searchId!=null and searchId!=''">
                and a.id in
                <foreach collection="searchId" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
</mapper>