<?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.constructionProject.mapper.ConstructionProjectMapper">
    
	<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",
		cityCompany AS "cityCompany",
		countyCompany AS "countyCompany",
		projectNature AS "projectNature",
		powerSupplyArea AS "powerSupplyArea",
		gridNumber AS "gridNumber",
		cellNumber AS "cellNumber",
		reserveNumber AS "reserveNumber",
		projectName AS "projectName",
		projectNumber AS "projectNumber",
		substationName AS "substationName",
		lineName AS "lineName",
		projectType AS "projectType",
		instructions AS "instructions",
		workAreaNote AS "workAreaNote",
		contructiveContent AS "contructiveContent",
		costEstimate AS "costEstimate",
		whetherGraceProject AS "whetherGraceProject",
		projectNote AS "projectNote",
		constructionUnit AS "constructionUnit",
		arrangeTime AS "arrangeTime",
		specificTime AS "specificTime",
		projectStatus AS "projectStatus"
	</sql>

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

	<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.project_number in
			<if test="list!= null">
				<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
					#{item}
				</foreach>
			</if>
		</where>
	</select>

	<select id="findAllListProject" resultType="com.jeeplus.modules.sg.managementcenter.project.entity.Project" >
		SELECT
		<include refid="projectColumns"/>
		FROM xm_project_details a
		<where>
			a.del_flag = '0'
			<if test="rezkey != null and  rezkey != ''">
				AND a.rezkey = #{rezkey}
			</if>
		</where>
	</select>
	<select id="get" resultType="com.jeeplus.modules.sg.managementcenter.constructionProject.entity.ConstructionProject" >
		SELECT 
			<include refid="constructionColumns"/>
		FROM ms_construction_project a
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="com.jeeplus.modules.sg.managementcenter.constructionProject.entity.ConstructionProject" >
		SELECT
			<include refid="constructionColumns"/>
		FROM ms_construction_project a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
			<if test="projectName != null and projectName != ''">
				AND a.projectName = #{projectName}
			</if>
			<if test="projectNumber != null and projectNumber != ''">
				AND a.projectNumber = #{projectNumber}
			</if>
			<if test="arrangeTime != null">
				AND a.arrangeTime = #{arrangeTime}
			</if>
			<if test="specificTime != null">
				AND a.specificTime = #{specificTime}
			</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="findAllList" resultType="com.jeeplus.modules.sg.managementcenter.constructionProject.entity.ConstructionProject" >
		SELECT
		<include refid="constructionColumns"/>
		FROM ms_construction_project 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 ms_construction_project(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			cityCompany,
			countyCompany,
			projectNature,
			powerSupplyArea,
			gridNumber,
			cellNumber,
			reserveNumber,
			projectName,
			projectNumber,
			substationName,
			lineName,
			projectType,
			instructions,
			workAreaNote,
			contructiveContent,
			costEstimate,
			whetherGraceProject,
			projectNote,
			constructionUnit,
			arrangeTime,
			specificTime,
			projectStatus
		) VALUES
		(
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{cityCompany},
			#{countyCompany},
			#{projectNature},
			#{powerSupplyArea},
			#{gridNumber},
			#{cellNumber},
			#{reserveNumber},
			#{projectName},
			#{projectNumber},
			#{substationName},
			#{lineName},
			#{projectType},
			#{instructions},
			#{workAreaNote},
			#{contructiveContent},
			#{costEstimate},
			#{whetherGraceProject},
			#{projectNote},
			#{constructionUnit},
			#{arrangeTime},
			#{specificTime},
			#{projectStatus}
		)
	</insert>

	<insert id="insertList">
		replace INTO ms_construction_project(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			cityCompany,
			countyCompany,
			projectNature,
			powerSupplyArea,
			gridNumber,
			cellNumber,
			reserveNumber,
			projectName,
			projectNumber,
			substationName,
			lineName,
			projectType,
			instructions,
			workAreaNote,
			contructiveContent,
			costEstimate,
			whetherGraceProject,
			projectNote,
			constructionUnit,
			arrangeTime,
			specificTime,
			projectStatus
		) 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.cityCompany},
			#{item.countyCompany},
			#{item.projectNature},
			#{item.powerSupplyArea},
			#{item.gridNumber},
			#{item.cellNumber},
			#{item.reserveNumber},
			#{item.projectName},
			#{item.projectNumber},
			#{item.substationName},
			#{item.lineName},
			#{item.projectType},
			#{item.instructions},
			#{item.workAreaNote},
			#{item.contructiveContent},
			#{item.costEstimate},
			#{item.whetherGraceProject},
			#{item.projectNote},
			#{item.constructionUnit},
			#{item.arrangeTime},
			#{item.specificTime},
			#{item.projectStatus}
			)
		</foreach>
	</insert>

	<update id="update">
		UPDATE ms_construction_project SET

		WHERE id = #{id}
	</update>

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


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

	<!--安排计划项目-->
	<update id="updateStatus">
		UPDATE ms_construction_project SET
			arrangeTime = #{arrangeTime},
			projectStatus = #{projectStatus}
		WHERE id = #{id}
	</update>

	<!--安排计划项目具体时间单独-->
	<update id="updateSpecificTime">
		UPDATE ms_construction_project SET
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			specificTime = #{specificTime}
		WHERE id = #{id}
	</update>

	<!--安排计划项目具体时间，根据项目进行分类-->
	<update id="updateSpecificLine">
		<foreach collection="list" item="item" index="index" open="" close="" separator=",">
			UPDATE ms_construction_project SET
				update_by = #{item.updateBy.id},
				update_date = #{item.updateDate},
				specificTime = #{item.specificTime}
			WHERE id = #{item.id}
		</foreach>
	</update>

	<update id="updateListProject">
		<foreach collection="list" item="item" index="index" open="" close="" separator=",">
			UPDATE xm_project_details SET
			rezkey = #{item.rezkey}
			WHERE project_number = #{item.projectNumber}
		</foreach>
	</update>

	<!--安排计划项目具体时间，根据项目进行分类-->
	<update id="updateArrangeTimeLine">
		<foreach collection="list" item="item" index="index" open="" close="" separator=",">
			UPDATE ms_construction_project SET
			update_by = #{item.updateBy.id},
			update_date = #{item.updateDate},
			arrangeTime = #{item.arrangeTime}
			WHERE id = #{item.id}
		</foreach>
	</update>
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="com.jeeplus.modules.sg.managementcenter.constructionProject.entity.ConstructionProject" statementType="STATEMENT">
		select * FROM ms_construction_project  where ${id} = '${value}'
	</select>

</mapper>