<?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.workfullmanage.dao.WorkFullRecordDao">
    
	<sql id="workFullRecordColumns">
		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.record_name AS "recordName",
		a.record_number AS "recordNumber",
		a.back_record_number AS "backRecordNumber",
		a.record_lib_number AS "recordLibNumber",
		a.back_record_year AS "backRecordYear",
		a.back_record_dept AS "backRecordDept.id",
		o.name AS "backRecordDept.name",
		a.comple_organization AS "compleOrganization",
		a.retention_period AS "retentionPeriod",
		a.start_time AS "startTime",
		a.end_time AS "endTime",
		a.record_secret_level AS "recordSecretLevel",
		a.fonds_number AS "fondsNumber",
		a.lists_number AS "listsNumber",
		a.record_pro_number AS "recordProNumber",
		a.strongbox_number AS "strongboxNumber",
		a.micro_number AS "microNumber",
		a.ekko_bstyp_one AS "ekkoBstypOne",
		a.ekko_bstyp_two AS "ekkoBstypTwo",
		a.report_number AS "reportNumber",
		a.page_number AS "pageNumber",
		a.manage_user AS "manageUser",
		a.ekko_type AS "ekkoType",
		a.work_full_manage_id AS "workFullManage.id",
		a.work_full_manage_id AS "workEngineeringProject.id",
		a.work_full_manage_id AS "workContractInfo.id",
		a.work_full_manage_id AS "workBidingProject.id",
		a.work_full_manage_id AS "workProject.id",
		a.company_id AS "companyId",
		a.office_id AS "officeId",
		a.back_record_status AS "backRecordStatus",
		a.process_instance_id AS "processInstanceId",
		a.type AS "type"
	</sql>
	
	<sql id="workFullRecordJoins">
		LEFT JOIN sys_office o ON o.id = a.back_record_dept
		LEFT JOIN work_full_manage wf ON wf.id = a.work_full_manage_id
	</sql>
	
    
	<select id="get" resultType="WorkFullRecord" >
		SELECT 
			<include refid="workFullRecordColumns"/>
		FROM work_full_record a
		<include refid="workFullRecordJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkFullRecord" >
		SELECT 
			<include refid="workFullRecordColumns"/>
		FROM work_full_record a
		<include refid="workFullRecordJoins"/>
		<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>
	
	<select id="findAllList" resultType="WorkFullRecord" >
		SELECT 
			<include refid="workFullRecordColumns"/>
		FROM work_full_record a
		<include refid="workFullRecordJoins"/>
		<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_record(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			record_name,
			record_number,
			back_record_number,
			record_lib_number,
			back_record_year,
			back_record_dept,
			comple_organization,
			retention_period,
			start_time,
			end_time,
			record_secret_level,
			fonds_number,
			lists_number,
			record_pro_number,
			strongbox_number,
			micro_number,
			ekko_bstyp_one,
			ekko_bstyp_two,
			report_number,
			page_number,
			manage_user,
			ekko_type,
			work_full_manage_id,
			company_id,
			office_id,
			back_record_status,
			type
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{recordName},
			#{recordNumber},
			#{backRecordNumber},
			#{recordLibNumber},
			#{backRecordYear},
			#{backRecordDept.id},
			#{compleOrganization},
			#{retentionPeriod},
			#{startTime},
			#{endTime},
			#{recordSecretLevel},
			#{fondsNumber},
			#{listsNumber},
			#{recordProNumber},
			#{strongboxNumber},
			#{microNumber},
			#{ekkoBstypOne},
			#{ekkoBstypTwo},
			#{reportNumber},
			#{pageNumber},
			#{manageUser},
			#{ekkoType},
			#{workFullManage.id},
			#{companyId},
			#{officeId},
			#{backRecordStatus},
			#{type}
		)
	</insert>
	
	<update id="update">
		UPDATE work_full_record SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			record_name = #{recordName},
			record_number = #{recordNumber},
			back_record_number = #{backRecordNumber},
			record_lib_number = #{recordLibNumber},
			back_record_year = #{backRecordYear},
			back_record_dept = #{backRecordDept.id},
			comple_organization = #{compleOrganization},
			retention_period = #{retentionPeriod},
			start_time = #{startTime},
			end_time = #{endTime},
			record_secret_level = #{recordSecretLevel},
			fonds_number = #{fondsNumber},
			lists_number = #{listsNumber},
			record_pro_number = #{recordProNumber},
			strongbox_number = #{strongboxNumber},
			micro_number = #{microNumber},
			ekko_bstyp_one = #{ekkoBstypOne},
			ekko_bstyp_two = #{ekkoBstypTwo},
			report_number = #{reportNumber},
			page_number = #{pageNumber},
			manage_user = #{manageUser},
			ekko_type = #{ekkoType},
			work_full_manage_id = #{workFullManage.id},
			company_id = #{companyId},
			office_id = #{officeId},
			back_record_status = #{backRecordStatus},
			type = #{type}
		WHERE id = #{id}
	</update>

	<update id="updateProcessInstanceId">
		UPDATE work_full_record SET
		process_instance_id = #{processInstanceId}
		WHERE id = #{id}
	</update>

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

	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkFullRecord" statementType="STATEMENT">
		select
		<include refid="workFullRecordColumns"/>
		FROM work_full_record a
		<include refid="workFullRecordJoins"/>
		where ${propertyName} = '${value}'
	</select>
	<!-- 获取流程ID -->
	<select id="getByProcessInstanceId" resultType="WorkFullRecord">
		SELECT
		<include refid="workFullRecordColumns"/>
		FROM work_full_record a
		<include refid="workFullRecordJoins"/>
		WHERE a.process_instance_id = #{processInstanceId}
	</select>

	<!-- 查询文件管理员 -->
	<select id="queryWjgly" parameterType="java.util.HashMap" resultType="java.util.HashMap">
		select a.id,a.login_name,c.enname,a.company_id from sys_user a
			INNER JOIN sys_user_role b ON a.id = b.user_id
			INNER JOIN sys_role c on b.role_id = c.id
			where a.company_id = #{company_id}
			and c.enname like concat('%',#{enname},'%') limit 1
	</select>
</mapper>