<?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.workresignationtemplate.dao.WorkResignationTemplateDao">
    
	<sql id="workResignationTemplateColumns">
		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.office_id AS "officeId",
		a.auditor AS "auditor",
		a.comment AS "comment",
		a.status AS "status",
		a.resignation_id AS "resignationId",
		o.name as "officeName",
		u.name as "userName"
	</sql>
	
	<sql id="workResignationTemplateJoins">
		LEFT JOIN sys_office o on a.office_id = o.id
        LEFT JOIN sys_user u ON u.id = a.auditor
	</sql>
	
    
	<select id="get" resultType="WorkResignationTemplate" >
		SELECT 
			<include refid="workResignationTemplateColumns"/>
		FROM work_resignation_template a
		<include refid="workResignationTemplateJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkResignationTemplate" >
		SELECT 
			<include refid="workResignationTemplateColumns"/>
		FROM work_resignation_template a
		<include refid="workResignationTemplateJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="resignationId != null and resignationId != ''">
				AND a.resignation_id = #{resignationId}
			</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="WorkResignationTemplate" >
		SELECT 
			<include refid="workResignationTemplateColumns"/>
		FROM work_resignation_template a
		<include refid="workResignationTemplateJoins"/>
		<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_resignation_template(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			office_id,
			auditor,
			comment,
			status,
			resignation_id
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{officeId},
			#{auditor},
			#{comment},
			#{status},
			#{resignationId}
		)
	</insert>
	
	<update id="update">
		UPDATE work_resignation_template SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			office_id = #{officeId},
			auditor = #{auditor},
			comment = #{comment},
			status = #{status},
			resignation_id = #{resignationId}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_resignation_template
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_resignation_template SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkResignationTemplate" statementType="STATEMENT">
		select * FROM work_resignation_template  where ${propertyName} = '${value}'
	</select>
	
</mapper>