<?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.workfullexecute.dao.WorkFullExecuteDao">
    
	<sql id="workFullExecuteColumns">
		a.id AS "id",
		a.file_name AS "fileName",
		a.file_type AS "fileType",
		a.file_type_declare AS "fileTypeDeclare",
		a.start_time AS "startTime",
		a.end_time AS "endTime",
		a.work_full_manage_id AS "workFullManageId",
		a.process_instance_id AS "processInstanceId",
		a.company_id AS "companyId",
		a.office_id AS "officeId",
		a.status AS "status",
		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="workFullExecuteJoins">
		LEFT JOIN work_full_manage b ON  b.id = a.work_full_manage_id
	</sql>

	<update id="updateStatusOfWorkFullManage">
		UPDATE work_full_manage  w
		SET w.update_by = #{updateBy} ,
			w.update_date = #{updateDate},
			w.full_project_status = #{fullProjectStatus}
		WHERE w.id = #{id}
	</update>
	
	<select id="getByProcessInstanceId" resultType="WorkFullExecute">
		SELECT
		<include refid="workFullExecuteColumns"/>
		FROM work_full_execute a
		<include refid="workFullExecuteJoins"/>
		WHERE a.process_instance_id = #{processInstanceId}
	</select>
	
	<update id="updateProcessInstanceId">
		UPDATE work_full_execute SET process_instance_id = #{processInstanceId}
		WHERE id = #{id}
	</update>

	<update id="updateStatus">
		UPDATE work_full_execute SET status = #{status}
		WHERE id = #{id}
	</update>

	<select id="getListOfWorkFullManage" resultType="WorkFullManage">
		SELECT
			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.contract_id AS "contractId",
			a.full_project_number AS "fullProjectNumber",
			a.full_project_source AS "fullProjectSource",
			a.full_project_name AS "fullProjectName",
			a.full_industry_type AS "fullIndustryType",
			a.full_structure_type AS "fullStructureType",
			a.full_invest_money AS "fullInvestMoney",
			a.client_id AS "clientId",
			a.build_id AS "buildId",
			a.full_project_type AS "fullProjectType",
			a.full_project_address AS "fullProjectAddress",
			a.full_project_property AS "fullProjectProperty",
			a.full_project_scale AS "fullProjectScale",
			a.full_count_unit AS "fullCountUnit",
			a.full_project_feature AS "fullProjectFeature",
			a.full_project_status AS "fullProjectStatus",
			a.host_company AS "hostCompany.id",
			a.follow_company AS "followCompany.id",
			a.talk_start_time AS "talkStartTime",
			a.talk_end_time AS "talkEndTime",
			a.ask_pay_mode AS "askPayMode",
			a.standard_explain AS "standardExplain",
			a.fixed_price AS "fixedPrice",
			a.client_require AS "clientRequire",
			a.host_master AS "hostMaster",
			a.follow_master AS "followMaster",
			a.host_member AS "hostMember",
			a.follow_member AS "followMember",
			a.constructId AS "constructId.id",
			a.designId AS "designId.id",
			a.surveyId AS "surveyId.id",
			a.company_id AS "companyId",
			a.office_id AS "officeId",
			a.project_id AS "workProject.id",
			a.masterId AS "masterId",
			ci.`name` AS "ciName",
			a.ext,
			a.contractName,
			a.is_total AS "isTotal",
			a.total_full_id AS "totalFullId",
			(select full_project_name from work_full_manage where id = a.total_full_id) totalFullName
	  	FROM work_full_manage a
		LEFT JOIN sys_office hostCompany ON hostCompany.id = a.host_company
		LEFT JOIN sys_office followCompany ON followCompany.id = a.follow_company
		LEFT JOIN work_full_design designId on designId.id = a.designId
		LEFT JOIN work_full_survey surveyId on surveyId.id = a.surveyId
		LEFT JOIN work_full_construct constructId on constructId.id = a.constructId
		LEFT JOIN work_client_info ci on ci.id = a.client_id
		LEFT JOIN work_project workProject ON workProject.id = a.project_id
		LEFT JOIN sys_user u ON u.id = a.create_by
		JOIN sys_office o ON o.id = a.office_id
		JOIN sys_office s ON s.id = a.company_id
		  <where>
			  a.del_flag = #{DEL_FLAG_NORMAL}
			  <choose>
				  <when test="queryCon != null and queryCon != ''">
					  AND (
							  find_in_set(#{queryCon},a.host_master)
							  OR
							  find_in_set(#{queryCon},a.follow_master)
							  OR
							  find_in_set(#{queryCon},a.host_member)
							  OR
							  find_in_set(#{queryCon},a.follow_member)
							  OR
							  find_in_set(#{queryCon},a.masterId)
							  OR a.create_by = #{queryCon}
							  ${sqlMap.dsf}
					   )
				  </when>
				  <otherwise>
					  ${sqlMap.dsf}
				  </otherwise>
			  </choose>
			  <if test="fullProjectNumber != null and fullProjectNumber != ''">
				  AND a.full_project_number LIKE
					  <if test="dbName == 'oracle'">'%'||#{fullProjectNumber}||'%'</if>
					  <if test="dbName == 'mssql'">'%'+#{fullProjectNumber}+'%'</if>
					  <if test="dbName == 'mysql'">concat('%',#{fullProjectNumber},'%')</if>
			  </if>
			  <if test="fullProjectName != null and fullProjectName != ''">
				  AND a.full_project_name LIKE
					  <if test="dbName == 'oracle'">'%'||#{fullProjectName}||'%'</if>
					  <if test="dbName == 'mssql'">'%'+#{fullProjectName}+'%'</if>
					  <if test="dbName == 'mysql'">concat('%',#{fullProjectName},'%')</if>
			  </if>
			  <if test="totalFullIds != null and totalFullIds != ''">
				  AND a.total_full_ids LIKE
				  <if test="dbName == 'oracle'">'%'||#{totalFullIds}||'%'</if>
				  <if test="dbName == 'mssql'">'%'+#{totalFullIds}+'%'</if>
				  <if test="dbName == 'mysql'">concat('%',#{totalFullIds},'%')</if>
			  </if>
			  <if test="totalFullId != null and totalFullId != ''">
				  AND a.total_full_id =#{totalFullId}
			  </if>
			  <if test="isTotal != null and isTotal != ''">
				  AND a.is_total =#{isTotal}
			  </if>
		  </where>
			<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.create_date asc
			</otherwise>
		</choose>
	</select>
    
	<select id="get" resultType="WorkFullExecute" >
		SELECT 
			<include refid="workFullExecuteColumns"/>
		FROM work_full_execute a
		<include refid="workFullExecuteJoins"/>
		WHERE a.id = #{id}
	</select>

	<select id="findList" resultType="WorkFullExecute" >
		SELECT 
			<include refid="workFullExecuteColumns"/>
		FROM work_full_execute a
		<include refid="workFullExecuteJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="workFullManageId != null and workFullManageId !=''">
				AND a.work_full_manage_id = #{workFullManageId}
			</if>
			<if test="fileName != null and fileName != ''">
				AND a.file_name LIKE 
					<if test="dbName == 'oracle'">'%'||#{fileName}||'%'</if>
					<if test="dbName == 'mssql'">'%'+#{fileName}+'%'</if>
					<if test="dbName == 'mysql'">concat('%',#{fileName},'%')</if>
			</if>
			<if test="fileType != null and fileType != ''">
				AND a.file_type = #{fileType}
			</if>
			<if test="startTime != null and startTime != ''">
				AND a.start_time <![CDATA[>=]]>  #{startTime}
				<if test="endTime !=null and endTime != ''">
					AND a.end_time <![CDATA[<=]]> #{endTime}
				</if>
			</if>
			<if test="startTime == null or startTime == ''">
				<if test="endTime !=null and endTime !=''">
					AND a.end_time <![CDATA[<=]]> #{endTime}
				</if>
			</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="WorkFullExecute" >
		SELECT 
			<include refid="workFullExecuteColumns"/>
		FROM work_full_execute a
		<include refid="workFullExecuteJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</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 work_full_execute(
			id,
			file_name,
			file_type,
			file_type_declare,
			start_time,
			end_time,
			work_full_manage_id,
			process_instance_id,
			company_id,
			office_id,
			status,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag
		) VALUES (
			#{id},
			#{fileName},
			#{fileType},
			#{fileTypeDeclare},
			#{startTime},
			#{endTime},
			#{workFullManageId},
			#{processInstanceId},
			#{companyId},
			#{officeId},
			#{status},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag}
		)
	</insert>
	
	<update id="update">
		UPDATE work_full_execute SET 	
			file_name = #{fileName},
			file_type = #{fileType},
			file_type_declare = #{fileTypeDeclare},
			start_time = #{startTime},
			end_time = #{endTime},
			work_full_manage_id = #{workFullManageId},
			process_instance_id = #{processInstanceId},
			company_id = #{companyId},
			office_id = #{officeId},
			status = #{status},
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks}
		WHERE id = #{id}
	</update>


	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_full_execute
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_full_execute SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkFullExecute" statementType="STATEMENT">
		select * FROM work_full_execute  where ${propertyName} = '${value}'
	</select>
	
</mapper>