<?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>
    
	<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="projectStatus != null and  projectStatus != ''">
				AND a.projectStatus = #{projectStatus}
			</if>
			<if test="id != null and id != ''">
				AND a.id = #{id}
			</if>
			<if test="lineName != null and lineName != ''">
				AND a.lineName = #{lineName}
			</if>
			<if test="arrangeTime != null">
				AND a.arrangeTime = #{arrangeTime}
			</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="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>