<?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.workfullsupervisorsheet.dao.WorkFullSupervisorsheetDao">
    
	<sql id="workFullSupervisorsheetColumns">
		a.id AS "id",
		a.work_full_manage_id AS "workFullManageId",
		a.process_instance_id AS "processInstanceId",
		a.status AS "status",
		a.company_id AS "companyId",
		a.office_id AS "officeId",
		a.supervisorsheet_number AS "supervisorsheetNumber",
		a.supervisorsheet_topic AS "supervisorsheetTopic",
		a.reported_company AS "reportedCompany",
		a.accept_company AS "acceptCompany",
		a.project_number AS "projectNumber",
		a.construct_section AS "constructSection",
		a.cost_increase_decrease AS "costIncreaseDecrease",
		a.proprietor_comment AS "proprietorComment",
		a.change_context AS "changeContext",
		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="workFullSupervisorsheetJoins">
		LEFT JOIN work_full_manage b ON  b.id = a.work_full_manage_id
	</sql>

	<select id="getByProcessInstanceId" resultType="WorkFullSupervisorsheet">
		SELECT
		<include refid="workFullSupervisorsheetColumns"/>
		FROM work_full_supervisorsheet a
		<include refid="workFullSupervisorsheetJoins"/>
		WHERE a.process_instance_id = #{processInstanceId}
	</select>
	<update id="updateStatus">
		UPDATE work_full_supervisorsheet SET status = #{status}
		WHERE id = #{id}
	</update>
	<update id="updateProcessInstanceId">
		UPDATE `work_full_supervisorsheet` SET process_instance_id = #{processInstanceId}
		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="WorkFullSupervisorsheet" >
		SELECT 
			<include refid="workFullSupervisorsheetColumns"/>
		FROM work_full_supervisorsheet a
		<include refid="workFullSupervisorsheetJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkFullSupervisorsheet" >
		SELECT 
			<include refid="workFullSupervisorsheetColumns"/>
		FROM work_full_supervisorsheet a
		<include refid="workFullSupervisorsheetJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="workFullManageId != null and workFullManageId !=''">
				AND a.work_full_manage_id = #{workFullManageId}
			</if>
			<if test="supervisorsheetNumber != null and supervisorsheetNumber != ''">
				AND a.supervisorsheet_number LIKE
				<if test="dbName == 'oracle'">'%'||#{supervisorsheetNumber}||'%'</if>
				<if test="dbName == 'mssql'">'%'+#{supervisorsheetNumber}+'%'</if>
				<if test="dbName == 'mysql'">concat('%',#{supervisorsheetNumber},'%')</if>
			</if>
			<if test="supervisorsheetTopic != null and supervisorsheetTopic != ''">
				AND a.supervisorsheet_topic LIKE
				<if test="dbName == 'oracle'">'%'||#{supervisorsheetTopic}||'%'</if>
				<if test="dbName == 'mssql'">'%'+#{supervisorsheetTopic}+'%'</if>
				<if test="dbName == 'mysql'">concat('%',#{supervisorsheetTopic},'%')</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="WorkFullSupervisorsheet" >
		SELECT 
			<include refid="workFullSupervisorsheetColumns"/>
		FROM work_full_supervisorsheet a
		<include refid="workFullSupervisorsheetJoins"/>
		<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_supervisorsheet(
			id,
			work_full_manage_id,
			process_instance_id,
			status,
			company_id,
			office_id,
			supervisorsheet_number,
			supervisorsheet_topic,
			reported_company,
			accept_company,
			project_number,
			construct_section,
			cost_increase_decrease,
			proprietor_comment,
			change_context,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag
		) VALUES (
			#{id},
			#{workFullManageId},
			#{processInstanceId},
			#{status},
			#{companyId},
			#{officeId},
			#{supervisorsheetNumber},
			#{supervisorsheetTopic},
			#{reportedCompany},
			#{acceptCompany},
			#{projectNumber},
			#{constructSection},
			#{costIncreaseDecrease},
			#{proprietorComment},
			#{changeContext},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag}
		)
	</insert>
	
	<update id="update">
		UPDATE work_full_supervisorsheet SET 	
			work_full_manage_id = #{workFullManageId},
			process_instance_id = #{processInstanceId},
			status = #{status},
			company_id = #{companyId},
			office_id = #{officeId},
			supervisorsheet_number = #{supervisorsheetNumber},
			supervisorsheet_topic = #{supervisorsheetTopic},
			reported_company = #{reportedCompany},
			accept_company = #{acceptCompany},
			project_number = #{projectNumber},
			construct_section = #{constructSection},
			cost_increase_decrease = #{costIncreaseDecrease},
			proprietor_comment = #{proprietorComment},
			change_context = #{changeContext},
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_full_supervisorsheet
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_full_supervisorsheet SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkFullSupervisorsheet" statementType="STATEMENT">
		select * FROM work_full_supervisorsheet  where ${propertyName} = '${value}'
	</select>
	
</mapper>