<?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.activiti.mapper.UploadImagesMapper">
    
	<sql id="constructionColumns">
		a.id AS "id",
		a.uId AS "uid",
		a.imgName AS "imgName",
		a.path AS "path",
		a.proc_ins_id AS "procInsId",
		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",
	</sql>

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


	<select id="get" resultType="com.jeeplus.modules.sg.managementcenter.activiti.entity.UploadImages" >
		SELECT *
		FROM xm_upolad_images a
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="UploadImages" >
		SELECT a.*,<include refid="projectColumns"/>
		FROM xm_upolad_images a
		LEFT JOIN xm_project_details b
		on a.projectId = b.id
		<where>
			<if test="dataScope != null and dataScope != ''">
				${dataScope}
			</if>
			<if test="uId != null and uId != ''">
				AND a.uId = #{uId}
			</if>
			<if test="imgName!=null and imgName!=''">
				AND a.imgName = #{imgName}
			</if>
			<if test="project.requireName != null and project.requireName != ''">
				and b.require_name =#{project.requireName}
			</if>
			<if test="project.projectId != null and project.projectId != ''">
				and b.project_id =#{project.projectId}
			</if>
			<if test="procInsId!=null and procInsId!=''">
				and a.proc_ins_id = #{procInsId}
			</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="findMaterialImg" resultType="com.jeeplus.modules.sg.managementcenter.activiti.entity.UploadImages">
		select imgName,path,proc_ins_id,uId from xm_upolad_images where proc_ins_id = #{procInsId}
	</select>
	
	<select id="findAllList" resultType="UploadImages" >
		SELECT *
		FROM xm_upolad_images 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_upolad_images(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			imgName,
			path,
			proc_ins_id,
			uId,
			projectId
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{imgName},
			#{path},
			#{procInsId},
			#{uId},
			#{projectId}
		)
	</insert>
	
	<update id="update">
		UPDATE xm_upolad_images SET
			path = #{path},
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks}
		WHERE id = #{id}
	</update>

	<!--物理删除-->
	<update id="delete">
		DELETE FROM xm_upolad_images
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE xm_upolad_images SET
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>

	<select id="findPathByProcInsID" resultType="java.lang.String">
		select path from xm_upolad_images where proc_ins_id = #{procInsId};
	</select>

	<select id="findProjectNameByProcInsId" resultType="java.lang.String">
		select project_name from xm_construction_clarificaiton where proc_ins_id = #{procInsId};
	</select>
	
	<select id="findJdById" resultType="com.jeeplus.modules.sg.managementcenter.activiti.entity.UploadImages">
		select require_name,project_id from xm_project_details where id = (select project_id from xm_construction_clarificaiton where proc_ins_id = #{procInsId})
	</select>

	<select id="findWzById" resultType="com.jeeplus.modules.sg.managementcenter.activiti.entity.UploadImages">
		select require_name,project_id from xm_project_details where id = (select project_id from md_acquisition_process where proc_ins_id = #{procInsId})
	</select>

	<select id="findSgById" resultType="com.jeeplus.modules.sg.managementcenter.activiti.entity.UploadImages">
		select require_name,project_id from xm_project_details where id = (select project_id from sg_construction_process where proc_ins_id = #{procInsId})
	</select>
</mapper>