<?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.ConstructionProjectTemporaryMapper">
    
	<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.line_name AS "lineName",
		a.project_name AS "projectName",
		a.project_number AS "projectNumber",
		a.power_line AS "powerLine",
		a.power_scope AS "powerScope",
		a.power_flag_package AS "powerFlagPackage",
		a.parent_id AS "parentId",
		a.parent_ids AS "parentIds",
	  	a.arrange_time AS "arrangeTime",
		a.plan_time AS "planTime",
		a.flagPower AS "flagPower",
		a.htmlStatus AS "htmlStatus",
		a.status AS "status"
	</sql>

	<select id="get" resultType="com.jeeplus.modules.sg.managementcenter.constructionProject.entity.ConstructionProjectTemporary" >
		SELECT 
			<include refid="constructionColumns"/>
		FROM ms_construction_project_temporary a
		WHERE a.id = #{id}
	</select>

	<select id="findListTemporary" parameterType="java.util.List" resultType="com.jeeplus.modules.sg.managementcenter.constructionProject.entity.ConstructionProjectTemporary" >
		SELECT
		<include refid="constructionColumns"/>
		FROM ms_construction_project_temporary a
		<where>
			a.del_flag = '0'
			<if test="projectNumbers != null">
				and a.project_number
				<foreach collection="projectNumbers" index="index" item="item" open="(" separator="," close=")">
					#{item}
				</foreach>
			</if>
		</where>
	</select>

	<select id="findList" resultType="com.jeeplus.modules.sg.managementcenter.constructionProject.entity.ConstructionProjectTemporary" >
		SELECT
			<include refid="constructionColumns"/>
		FROM ms_construction_project_temporary a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
			<if test="status != null and status != ''">
				AND a.status = #{status}
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.htmlStatus DESC
			</otherwise>
		</choose>
	</select>

	<select id="findTreeList" resultType="com.jeeplus.modules.sg.managementcenter.constructionProject.entity.ConstructionProjectTemporary" >
		SELECT
		<include refid="constructionColumns"/>
		FROM ms_construction_project_temporary a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
			<if test="status != null and status != ''">
				AND a.status = '2' or a.status = '1'
			</if>
		</where>
	</select>

	<select id="findAllList" resultType="com.jeeplus.modules.sg.managementcenter.constructionProject.entity.ConstructionProjectTemporary" >
		SELECT
		<include refid="constructionColumns"/>
		FROM ms_construction_project_temporary a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
			<if test="status != null and status != ''">
				AND a.status = '2' or a.status = '0'
			</if>
			<if test="parentId != null and parentId != ''">
				AND a.parent_id = #{parentId}
			</if>
		</where>
	</select>
	
	<insert id="insert">
		  INSERT INTO ms_construction_project_temporary(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			line_name,
			project_name,
			project_number,
			power_line,
			power_scope,
			power_flag_package,
			parent_id,
			parent_ids,
			status
		) VALUES
		(
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{lineName},
			#{projectName},
			#{projectNumber},
			#{powerLine},
			#{powerScope},
			#{powerFlagPackage},
			#{parentId},
			#{parentIds},
			#{status}
	</insert>

	<insert id="insertList">
		replace INTO ms_construction_project_temporary(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			line_name,
			project_name,
			project_number,
			power_line,
			power_scope,
			power_flag_package,
			parent_id,
			parent_ids,
			arrange_time,
			flagPower,
			htmlStatus,
			plan_time,
			status
		) 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.lineName},
			#{item.projectName},
			#{item.projectNumber},
			#{item.powerLine},
			#{item.powerScope},
			#{item.powerFlagPackage},
			#{item.parentId},
			#{item.parentIds},
			#{item.arrangeTime},
			#{item.flagPower},
			#{item.htmlStatus},
			#{item.planTime},
			#{item.status}
			)
		</foreach>
	</insert>
	<delete id="deleteAll">
		DELETE FROM ms_construction_project_temporary
	</delete>
	<!--安排计划项目-->
	<update id="updateStatus">
		UPDATE ms_construction_project_temporary SET
			status = #{status}
		WHERE id = #{id}
	</update>

	<update id="updatePower">
		UPDATE ms_construction_project_temporary SET
			status = #{status},
			htmlStatus = #{htmlStatus},
			flagPower = #{flagPower}
		WHERE id = #{id}
	</update>
	<!--物理删除-->
	<update id="delete">
		DELETE FROM ms_construction_project_temporary
		WHERE id = #{id}
	</update>


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

	<update id="updateTime">
		UPDATE ms_construction_project_temporary SET
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			plan_time =#{planTime}
		WHERE id = #{id}
	</update>
</mapper>