<?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.materialmodule.activiti.mapper.NonPowerMapper">

	<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>
	<update id="updateStart">
		update xm_nonpower_process
		set plannedStart = #{plannedStart},
			projectManager = #{projectManager},
			personInCharge = #{personInCharge},
			plannedEnd = #{plannedEnd},
			workPlace = #{workPlace},
			civilStartReport = #{civilStartReport}
		where proc_ins_id = #{procInsId};
	</update>

	<update id="updateEnd">
		update xm_nonpower_process
		set	civilEndReport = #{civilEndReport},
			actualStart = #{actualStart},
		    actualEnd = #{actualEnd}
		where proc_ins_id = #{procInsId};
	</update>

	<select id="get" resultType="NonPower">
		select a.id,
			   a.projectId,
			   a.projectName,
			   a.reserveProjectName,
			   b.municipalCompany   as buildingUnit,
			   b.erpNo              as projectNumber,
			   xpa.constructionUnit as constructionUnit,
			   a.plannedStart,
			   a.plannedEnd,
			   a.actualStart,
			   a.actualEnd,
			   a.projectManager,
			   b.lineName,
			   a.personInCharge,
			   a.workPlace,
			   a.civilStartReport,
			   a.civilEndReport,
			   xpq.engineeringAcceptance,
			   a.create_date
		from xm_nonpower_process a
				 LEFT JOIN xm_material_project p
						   on a.projectId = p.projectId
				 LEFT JOIN xm_project_basicinformation b
						   on p.reserveProjectName = b.reserveProjectName
				 left join xm_project_assignment xpa
						   on a.reserveProjectName = xpa.reserveProjectName
				 left join xm_project_quantity xpq
						   on a.reserveProjectName = xpq.reserveProjectName
		where a.id = #{id};
    </select>

    <select id="findList" resultType="NonPower">
		select
        a.id,
        a.projectId,
        a.projectName,
        a.reserveProjectName,
        b.municipalCompany as buildingUnit,
        b.erpNo as projectNumber,
        xpa.constructionUnit as constructionUnit,
        a.plannedStart,
        a.plannedEnd,
        a.projectManager,
        b.lineName,
        a.personInCharge,
        a.workPlace,
        a.constructionCivilWorks,
        a.civilStartReport,
        a.civilEndReport
        from xm_nonpower_process a
        LEFT JOIN xm_material_project p
        on a.projectId = p.projectId
        LEFT JOIN xm_project_basicinformation b
        on p.reserveProjectName = b.reserveProjectName
        left join xm_project_assignment xpa
        on a.reserveProjectName = xpa.reserveProjectName
        <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="findCivilWorks"
			resultType="com.jeeplus.modules.sg.managementcenter.activiti.entity.EngineeringAmount">
		select id,
			   create_by,
			   create_date,
			   update_by,
			   update_date,
			   del_flag,
			   remarks,
			   reserveProjectName,
			   civilWorks,
			   civilMaterials,
			   civilUnit
		from xm_engineering_amount
		where reserveProjectName = #{reserveProjectName};
	</select>


	<insert id="insert">
		insert into xm_nonpower_process (
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			del_flag,
			remarks,
			proc_ins_id,
			projectId,
            projectName,
		 	reserveProjectName
		)values
			(
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{delFlag},
			#{remarks},
			#{procInsId},
			#{projectId},
			#{projectName},
			#{reserveProjectName}
			)
	</insert>

	<select id="findIsNonPower" resultType="com.jeeplus.modules.sg.materialmodule.activiti.entity.NonPower">
		select id,
			   create_by,
			   create_date,
			   update_by,
			   update_date,
			   del_flag,
			   remarks,
			   proc_ins_id,
			   projectId,
			   plannedStart,
			   plannedEnd,
			   projectManager,
			   personInCharge,
			   workPlace,
			   constructionCivilWorks,
			   civilStartReport,
			   civilEndReport,
			   projectName,
			   reserveProjectName
		from xm_nonpower_process
		where reserveProjectName = #{reserveProjectName};
	</select>
	<select id="getById" resultType="com.jeeplus.modules.sg.materialmodule.activiti.entity.NonPower">
		select
			a.id,
			a.projectId,
			a.projectName,
			a.reserveProjectName,
			b.municipalCompany as buildingUnit,
			b.erpNo as projectNumber,
			xpa.constructionUnit as constructionUnit,
			a.plannedStart,
			a.plannedEnd,
			a.projectManager,
			b.lineName,
			a.personInCharge,
			a.workPlace,
			a.civilStartReport,
			a.civilEndReport,
			xpq.engineeringAcceptance,
			a.create_date
		from xm_nonpower_process a
		 LEFT JOIN xm_material_project p
				   on a.projectId = p.projectId
		 LEFT JOIN xm_project_basicinformation b
				   on p.reserveProjectName = b.reserveProjectName
		 left join xm_project_assignment xpa
				   on a.reserveProjectName = xpa.reserveProjectName
		 left join xm_project_quantity xpq
				   on a.reserveProjectName = xpq.reserveProjectName
		where a.id = #{id}
	</select>
    <select id="findListPage" resultType="com.jeeplus.modules.sg.materialmodule.activiti.entity.NonPower">
		select
		       xnp.id,
			   xnp.create_by,
			   xnp.create_date,
			   xnp.update_by,
			   xnp.update_date,
			   xnp.del_flag,
			   xnp.remarks,
			   xnp.proc_ins_id,
			   xnp.projectId,
			   xnp.plannedStart,
			   xnp.plannedEnd,
			   xnp.actualStart,
			   xnp.actualEnd,
			   xnp.projectManager,
			   xnp.personInCharge,
			   xnp.workPlace,
			   xnp.constructionCivilWorks,
			   xnp.civilStartReport,
			   xnp.civilEndReport,
			   xnp.projectName,
			   xnp.reserveProjectName
		from xm_nonpower_process xnp
		left join xm_project_assignment xpa
		on xnp.reserveProjectName = xpa.reserveProjectName
		<where>
			1=1
			<if test="projectId!=null and projectId != ''">
				and projectId = #{projectId}
			</if>
			<if test="projectName!=null and projectName != ''">
				and projectName = #{projectName}
			</if>
			<if test="reserveProjectName!=null and reserveProjectName != ''">
				and reserveProjectName = #{reserveProjectName}
			</if>
			<if test="dataScope != null and dataScope != ''">
				${dataScope}
			</if>
		</where>
	</select>
	<insert id="saveUpload">
		INSERT INTO xm_upload_images(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			imgName,
			path,
			proc_ins_id,
			uid,
			reserveProjectName
		) VALUES (
					 #{id},
					 #{createBy.id},
					 #{createDate},
					 #{updateBy.id},
					 #{updateDate},
					 #{remarks},
					 #{delFlag},
					 #{imgName},
					 #{path},
					 #{procInsId},
					 #{uid},
					 #{reserveProjectName}
				 )
	</insert>
</mapper>