<?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.keao.edu.common.dao.SysMessageConfigDao">

	<resultMap type="com.keao.edu.common.entity.SysMessageConfig"
		id="SysMessageConfig">
		<result column="id_" property="id" />
		<result column="message_type_" property="messageType" typeHandler="com.keao.edu.common.dal.CustomEnumTypeHandler" />
		<result column="content_" property="content" />
		<result column="description_" property="description" />
		<result column="modify_on_" property="modifyOn" />
		<result column="url_" property="url" />
		<result column="group_" property="group" />
		<result column="send_flag_" property="sendFlag" />
	</resultMap>

	<sql id="queryCondition">
		<where>
			<if test="messageType != null">
				and message_type_ =
				#{messageType,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
			</if>
			<if test="content != null">
				and content_ = #{content,jdbcType=VARCHAR},
			</if>
			<if test="description != null">
				and description_ = #{description,jdbcType=VARCHAR}
			</if>
			<if test="group != null">
				and group_ = #{group,jdbcType=VARCHAR}
			</if>
			<if test="sendFlag != null">
				and send_flag_ = #{sendFlag}
			</if>
		</where>
	</sql>

	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="SysMessageConfig">
		SELECT * FROM
		sys_message_config WHERE id_ = #{id}
	</select>

	<!-- 全查询 -->
	<select id="findAll" resultMap="SysMessageConfig">
		SELECT * FROM sys_message_config
		ORDER BY id_
	</select>

	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.keao.edu.common.entity.SysMessageConfig"
		useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		<!-- <selectKey resultClass="int" keyProperty="id" > SELECT SEQ_WSDEFINITION_ID.nextval 
			AS ID FROM DUAL </selectKey> -->
		INSERT INTO sys_message_config
		(id_,message_type_,content_,description_,modify_on_,url_,group_)
		VALUES(#{id},#{messageType},#{content},#{description},#{modifyOn},#{url},#{group})
	</insert>

	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.keao.edu.common.entity.SysMessageConfig">
		UPDATE sys_message_config
		<set>
			<if test="modifyOn != null">
				modify_on_ = #{modifyOn},
			</if>
			<if test="messageType != null">
				message_type_ = #{messageType},
			</if>
			<if test="id != null">
				id_ = #{id},
			</if>
			<if test="url != null">
				url_ = #{url},
			</if>
			<if test="group != null">
				group_ = #{group},
			</if>
			<if test="content != null">
				content_ = #{content},
			</if>
			<if test="description != null">
				description_ = #{description},
			</if>
			<if test="sendFlag != null">
				send_flag_ = #{sendFlag}
			</if>
		</set>
		WHERE id_ = #{id}
	</update>

	<!-- 根据主键删除一条记录 -->
	<delete id="delete">
		DELETE FROM sys_message_config WHERE id_ =
		#{id}
	</delete>

	<!-- 分页查询 -->
	<select id="queryPage" resultMap="SysMessageConfig"
		parameterType="map">
		select * from sys_message_config
		<include refid="queryCondition" />
		order by update_time_ desc
		<include refid="global.limit" />
	</select>

	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		select count(*) from sys_message_config
		<include refid="queryCondition" />
	</select>

	<select id="queryByType" resultMap="SysMessageConfig">
		SELECT * FROM sys_message_config WHERE message_type_ = #{messageType}
	</select>

    <select id="findContent" resultType="java.lang.String">
		SELECT content_ FROM sys_message_config WHERE message_type_ = #{messageType}
	</select>

	<select id="queryByEvent" resultMap="SysMessageConfig">
		SELECT * FROM sys_message_config WHERE event_ = #{event}
	</select>
</mapper>
