<?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.syswarning.dao.SysWarningLogDao">
    
	<sql id="sysWarningLogColumns">
		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.office_id AS "officeId",
		a.company_id AS "companyId",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",
		a.warning_id AS "warningId",
		a.warning_date AS "warningDate",
		a.user_id AS "userId",
		u.name as "user.name",
		o.name as "user.office.name",
		w.comment as "sysWarning.comment",
		w.name as "sysWarning.name",
		w.warning_type as "sysWarning.warningType"
	</sql>
	
	<sql id="sysWarningLogJoins">
		left join sys_user u on u.id=a.user_id
		left join sys_warning w on w.id=a.warning_id
		left join sys_office o on o.id=u.office_id
	</sql>
	
    
	<select id="get" resultType="SysWarningLog" >
		SELECT 
			<include refid="sysWarningLogColumns"/>
		FROM sys_warning_log a
		<include refid="sysWarningLogJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="SysWarningLog" >
		SELECT 
			<include refid="sysWarningLogColumns"/>
		FROM sys_warning_log a
		<include refid="sysWarningLogJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="sysWarning != null and sysWarning.warningType != null and sysWarning.warningType != ''">
				AND w.warning_type = #{sysWarning.warningType}
			</if>
			<if test="beginDate != null and endDate != null and beginDate != '' and endDate != ''">
				AND a.warning_date BETWEEN #{beginDate} AND #{endDate}
			</if>
			<if test="userId != null and userId != ''">
				AND a.user_id = #{userId}
			</if>
			<if test="companyId != null and companyId != ''">
				AND a.company_id = #{companyId}
			</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="SysWarningLog" >
		SELECT 
			<include refid="sysWarningLogColumns"/>
		FROM sys_warning_log a
		<include refid="sysWarningLogJoins"/>
		<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 sys_warning_log(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			warning_id,
			warning_date,
			user_id,
			office_id,
		    company_id
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{warningId},
			#{warningDate},
			#{userId},
			#{officeId},
			#{companyId}
		)
	</insert>
	
	<update id="update">
		UPDATE sys_warning_log SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			warning_id = #{warningId},
			warning_date = #{warningDate},
			user_id = #{userId},
			office_id = #{officeId},
			company_id = #{companyId}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM sys_warning_log
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE sys_warning_log SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="SysWarningLog" statementType="STATEMENT">
		select * FROM sys_warning_log  where ${propertyName} = '${value}'
	</select>
	
</mapper>