<?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.scm.contract.dao.message.MessageCenterDao">

	<sql id="columns">
		a.`id` AS "id",
		a.`data_time` AS "dataTime",
		a.`tag_type_id` AS "tagTypeId",
		a.`is_alarm` AS "isAlarm",
		a.`content` AS "content"
	</sql>

	<sql id="joins">
	</sql>

    <select id="list" resultType="com.scm.contract.model.message.MessageCenter">
		SELECT
		<include refid="columns"/>
		FROM message_center a
		<include refid="joins"/>
	</select>

	<select id="findList" resultType="com.scm.contract.model.message.MessageCenter">
		SELECT
		<include refid="columns"/>
		FROM message_center a
		<include refid="joins"/>
		<where>
			<if test="id != null and id != ''">
				AND a.id = #{id}
			</if>
			<if test="beginTime != null and endTime != null ">
				AND a.data_time BETWEEN #{beginTime} AND #{endTime}
			</if>
			<if test="content != null and content != ''">
				AND a.`content` LIKE '%' #{content} '%'
			</if>
			<if test="isAlarm != null and isAlarm != ''">
				AND a.`is_alarm` = #{isAlarm}
			</if>
			<if test="tagTypeId != null and tagTypeId != ''">
				AND a.`tag_type_id` = #{tagTypeId}
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
		</choose>
	</select>

	<select id="listByIds" resultType="com.scm.contract.model.message.MessageCenter">
		SELECT
		<include refid="columns"/>
		FROM message_center a
		<include refid="joins"/>
		WHERE a.id IN
		<foreach item="id" index="index" collection="ids" open="(" separator="," close=")">
			#{id}
		</foreach>
	</select>

	<insert id="saveOrUpdateBash">
		INSERT INTO
		message_center
		(`id`,
		`data_time`,
		`tag_type_id`,
		`is_alarm`,
		`content`)
		VALUES
		<foreach item="messageCenter" index="index" collection="messageCenters" separator=",">
			(
			#{messageCenter.id},
			#{messageCenter.dataTime},
			#{messageCenter.tagTypeId},
			#{messageCenter.isAlarm},
			#{messageCenter.content}
			)
		</foreach>
		ON DUPLICATE KEY UPDATE
		`id`=values(`id`),`data_time`=values(`data_time`),`tag_type_id`=values(`tag_type_id`),`is_alarm`=values(`is_alarm`),`content`=values(`content`)
	</insert>

</mapper>
