<?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.workexampleimplog.dao.WorkExampleImplogDao">
    
	<sql id="workExampleImplogColumns">
		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.company_id AS "companyId",
		a.office_id AS "officeId",
		a.example_id AS "exampleId",
		a.index_id AS "indexId",
		a.term_id AS "termId",
		a.reason AS "reason",
		a.flat AS "flat",
		w.name AS "exampleName",
		e.name AS "indexName",
		i.name AS "termName",
		u.name AS "userName"
	</sql>
	
	<sql id="workExampleImplogJoins">
        left join sys_user u on u.id=a.create_by
		left join work_example w on w.id=a.example_id
		left join work_example_indices e on e.id=a.index_id
		left join work_example_indices i on i.id=a.term_id
	</sql>
	
    
	<select id="get" resultType="WorkExampleImplog" >
		SELECT 
			<include refid="workExampleImplogColumns"/>
		FROM work_example_implog a
		<include refid="workExampleImplogJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkExampleImplog" >
		SELECT 
			<include refid="workExampleImplogColumns"/>
		FROM work_example_implog a
		<include refid="workExampleImplogJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="beginCreateDate != null and endCreateDate != null and beginCreateDate != '' and endCreateDate != ''">
				AND a.create_date BETWEEN #{beginCreateDate} AND #{endCreateDate}
			</if>
			<if test="companyId != null and companyId != ''">
				AND a.company_id = #{companyId}
			</if>
			<if test="officeId != null and officeId != ''">
				AND a.office_id = #{officeId}
			</if>
			<if test="exampleName != null and exampleName != ''">
				AND w.name LIKE
					<if test="dbName == 'oracle'">'%'||#{exampleName}||'%'</if>
					<if test="dbName == 'mssql'">'%'+#{exampleName}+'%'</if>
					<if test="dbName == 'mysql'">concat('%',#{exampleName},'%')</if>
			</if>
			<if test="indexName != null and indexName != ''">
				AND e.name LIKE
					<if test="dbName == 'oracle'">'%'||#{indexName}||'%'</if>
					<if test="dbName == 'mssql'">'%'+#{indexName}+'%'</if>
					<if test="dbName == 'mysql'">concat('%',#{indexName},'%')</if>
			</if>
			<if test="termId != null and termId != ''">
				AND a.term_id LIKE 
					<if test="dbName == 'oracle'">'%'||#{termId}||'%'</if>
					<if test="dbName == 'mssql'">'%'+#{termId}+'%'</if>
					<if test="dbName == 'mysql'">concat('%',#{termId},'%')</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="WorkExampleImplog" >
		SELECT 
			<include refid="workExampleImplogColumns"/>
		FROM work_example_implog a
		<include refid="workExampleImplogJoins"/>
		<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_example_implog(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			company_id,
			office_id,
			example_id,
			index_id,
			term_id,
			reason,
			flat
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{companyId},
			#{officeId},
			#{exampleId},
			#{indexId},
			#{termId},
			#{reason},
			#{flat}
		)
	</insert>
	
	<update id="update">
		UPDATE work_example_implog SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			company_id = #{companyId},
			office_id = #{officeId},
			example_id = #{exampleId},
			index_id = #{indexId},
			term_id = #{termId},
			reason = #{reason},
			flat = #{flat}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_example_implog
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_example_implog SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkExampleImplog" statementType="STATEMENT">
		select * FROM work_example_implog  where ${propertyName} = '${value}'
	</select>
	
</mapper>