<?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.projectPlanArrage.mapper.ProjectPlanArrageMapper">
    
	<sql id="constructionColumns">
		a.id AS "id",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.projectName AS "projectName",
		a.projectNumber AS "projectNumber",
		a.projectLine AS "projectLine",
		a.projectPowerRange AS "projectPowerRange",
		a.projectSwitch AS "projectSwitch",
		a.projectMonthDate AS "projectMonthDate",
		a.projectDate AS "projectDate",
		a.projectPowerOut AS "projectPowerOut",
		a.status AS "status",
		a.associatedBag AS "associatedBag",
		a.powerPackage AS "powerPackage"
	</sql>

	<sql id="infoColumns">
        a.id AS "id",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",
		a.reserveProjectName,
		a.reserveCode,
		a.projectType,
		a.batchPlan,
		a.issuePlan,
		a.monthPlan,
		a.hasPlan,
		a.halfPlan,
		a.projectName,
		a.projectId
    </sql>

	<sql id="quantityColumns">
		 a.id AS "id",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",
		a.reserveProjectName AS "reserveProjectName",
		a.includeAutomation AS "includeAutomation",
		a.wayOf AS "wayOf",
		a.assignmentStyle AS "assignmentStyle",
		a.operationSubstation AS "operationSubstation",
		a.namingNumber AS "namingNumber",
		a.engineeringAcceptance AS "engineeringAcceptance",
		a.electricalAcceptance AS "electricalAcceptance",
		a.blackoutLine AS "blackoutLine",
		a.outageRange AS "outageRange",
		a.policyIssues AS "policyIssues",
		a.processingType AS "processingType",
		a.processingDescription AS "processingDescription"
	</sql>

	<select id="findListMaterialProject" resultType="com.jeeplus.modules.sg.managementcenter.materialproject.entity.MaterialProject">
		SELECT
		<include refid="infoColumns"/>
		FROM xm_material_project a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
			<if test="attributionYear != null and attributionYear != ''">
				AND a.attributionYear = #{attributionYear}
			</if>
			<if test="arrageProject != null and arrageProject != ''">
				AND a.arrageProject in(#{arrageProject},#{arrageProject1})
			</if>
		</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>

	<select id="findListQuantity" resultType="com.jeeplus.modules.sg.managementcenter.projectPlanArrage.entity.ProjectQuantity">
		SELECT
		<include refid="quantityColumns"/>
		FROM xm_project_quantity a
		where a.reserveProjectName in
		<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
			#{item.projectName}
		</foreach>
	</select>

	<select id="get" resultType="com.jeeplus.modules.sg.managementcenter.projectPlanArrage.entity.ProjectPlanArrage" >
		SELECT 
			<include refid="constructionColumns"/>
		FROM xm_project_plan_arrange a
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="com.jeeplus.modules.sg.managementcenter.projectPlanArrage.entity.ProjectPlanArrage" >
		SELECT
			<include refid="constructionColumns"/>
		FROM xm_project_plan_arrange 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_plan_arrange(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			projectName,
			projectNumber,
			projectLine,
			projectPowerRange,
			projectSwitch,
			projectMonthDate,
			projectDate,
			projectPowerOut,
			status,
			associatedBag,
			powerPackage
		) VALUES
		(
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{projectName},
			#{projectNumber},
			#{projectLine},
			#{projectPowerRange},
			#{projectSwitch},
			#{projectMonthDate},
			#{projectDate},
			#{projectPowerOut},
			#{status},
			#{associatedBag},
			#{powerPackage}
		)
	</insert>

	<insert id="insertList">
		replace INTO xm_project_plan_arrange(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			projectName,
			projectNumber,
			projectLine,
			projectPowerRange,
			projectSwitch,
			projectMonthDate,
			projectDate,
			projectPowerOut	,
			status,
			associatedBag,
			powerPackage
		) 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.projectName},
			#{item.projectNumber},
			#{item.projectLine},
			#{item.projectPowerRange},
			#{item.projectSwitch},
			#{item.projectMonthDate},
			#{item.projectDate},
			#{item.projectPowerOut},
			#{item.status},
			#{item.associatedBag},
			#{item.powerPackage}
			)
		</foreach>
	</insert>

	<update id="update">
		UPDATE xm_project_plan_arrange SET

		WHERE id = #{id}
	</update>

	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="com.jeeplus.modules.sg.managementcenter.projectPlanArrage.entity.ProjectPlanArrage" statementType="STATEMENT">
		select * FROM xm_project_plan_arrange where ${id} = '${value}'
	</select>

	<sql id="assignmentColumns">
		a.id AS "id",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.reserveProjectName AS "reserveProjectName",
		a.disclosureType AS "disclosureType",
		a.projectReleaseBatch AS "projectReleaseBatch",
		a.deliveryDate AS "deliveryDate",
		a.packageNo AS "packageNo",
		a.rate AS "rate",
		a.assignedUnit AS "assignedUnit",
		a.constructionUnit AS "constructionUnit",
		a.constructionSubcontractor AS "constructionSubcontractor",
		a.behalf AS "behalf",
		a.constructionFullTime AS "constructionFullTime",
		a.constructionTechnical AS "constructionTechnical",
		a.constructionManage AS "constructionManage",
		a.constructionLeader AS "constructionLeader",
		a.subcontractingContact AS "subcontractingContact",
		a.designer AS "designer",
		a.designLeader AS "designLeader",
		a.ownerManager AS "ownerManager",
		a.distribution AS "distribution",
		a.distributionFullTime AS "distributionFullTime",
		a.distributionSystem AS "distributionSystem",
		a.distributionPolicy AS "distributionPolicy",
		a.centerLeader AS "centerLeader",
		a.centerTechnical AS "centerTechnical",
		a.instituteRole AS "instituteRole",
		a.repUnit AS "repUnit",
		a.inspectionUnit AS "inspectionUnit"
	</sql>


	<select id="findListAssignment" resultType="com.jeeplus.modules.sg.managementcenter.projectPlanArrage.entity.ProjectAssignment">
		SELECT
		<include refid="assignmentColumns"/>
		FROM xm_project_assignment a
		where a.reserveProjectName in
		<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
			#{item.projectName}
		</foreach>
	</select>

	<delete id="deleteMainAll">
		delete from xm_project_plan_arrange
		where id in
		<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
			#{item}
		</foreach>
	</delete>
</mapper>