<?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.steerinfo.baseinfo.meterbasesystemnews.mapper.MeterBaseSystemNewsMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.baseinfo.meterbasesystemnews.model.MeterBaseSystemNews">
    <id column="CAR_NEWS_NO" jdbcType="VARCHAR" property="carNewsNo" />
    <result column="CAR_NO" jdbcType="VARCHAR" property="carNo" />
    <result column="SYSTEM_MESSAGE_NO" jdbcType="VARCHAR" property="systemMessageNo" />
    <result column="IS_READ" jdbcType="VARCHAR" property="isRead" />
  </resultMap>
  <sql id="columns">
    CAR_NEWS_NO, CAR_NO, SYSTEM_MESSAGE_NO, IS_READ
  </sql>
  <sql id="columns_alias">
    t.CAR_NEWS_NO, t.CAR_NO, t.SYSTEM_MESSAGE_NO, t.IS_READ
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM METER_BASE_SYSTEM_NEWS
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM METER_BASE_SYSTEM_NEWS t
  </sql>
  <sql id="where">
    <where> 
      <if test="carNewsNo != null and carNewsNo != ''">
        and CAR_NEWS_NO = #{carNewsNo}
      </if>
      <if test="carNo != null and carNo != ''">
        and CAR_NO = #{carNo}
      </if>
      <if test="systemMessageNo != null and systemMessageNo != ''">
        and SYSTEM_MESSAGE_NO = #{systemMessageNo}
      </if>
      <if test="isRead != null and isRead != ''">
        and IS_READ = #{isRead}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="carNewsNo != null and carNewsNo != ''">
        and CAR_NEWS_NO LIKE '%${carNewsNo}%'
      </if>
      <if test="carNo != null and carNo != ''">
        and CAR_NO LIKE '%${carNo}%'
      </if>
      <if test="systemMessageNo != null and systemMessageNo != ''">
        and SYSTEM_MESSAGE_NO LIKE '%${systemMessageNo}%'
      </if>
      <if test="isRead != null and isRead != ''">
        and IS_READ LIKE '%${isRead}%'
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from METER_BASE_SYSTEM_NEWS
    where CAR_NEWS_NO = #{carNewsNo,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from METER_BASE_SYSTEM_NEWS
    where 1!=1 
      <if test="carNo != null and carNo != ''">
        or CAR_NO = #{carNo}
      </if>
      <if test="systemMessageNo != null and systemMessageNo != ''">
        or SYSTEM_MESSAGE_NO = #{systemMessageNo}
      </if>
      <if test="isRead != null and isRead != ''">
        or IS_READ = #{isRead}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.baseinfo.meterbasesystemnews.model.MeterBaseSystemNews">
    insert into METER_BASE_SYSTEM_NEWS (CAR_NEWS_NO, CAR_NO, SYSTEM_MESSAGE_NO, 
      IS_READ)
    values (#{carNewsNo,jdbcType=VARCHAR}, #{carNo,jdbcType=VARCHAR}, #{systemMessageNo,jdbcType=VARCHAR}, 
      #{isRead,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.baseinfo.meterbasesystemnews.model.MeterBaseSystemNews">
    insert into METER_BASE_SYSTEM_NEWS
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="carNewsNo != null">
        CAR_NEWS_NO,
      </if>
      <if test="carNo != null">
        CAR_NO,
      </if>
      <if test="systemMessageNo != null">
        SYSTEM_MESSAGE_NO,
      </if>
      <if test="isRead != null">
        IS_READ,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="carNewsNo != null">
        #{carNewsNo,jdbcType=VARCHAR},
      </if>
      <if test="carNo != null">
        #{carNo,jdbcType=VARCHAR},
      </if>
      <if test="systemMessageNo != null">
        #{systemMessageNo,jdbcType=VARCHAR},
      </if>
      <if test="isRead != null">
        #{isRead,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.baseinfo.meterbasesystemnews.model.MeterBaseSystemNews">
    update METER_BASE_SYSTEM_NEWS
    set CAR_NO = #{carNo,jdbcType=VARCHAR},
      SYSTEM_MESSAGE_NO = #{systemMessageNo,jdbcType=VARCHAR},
      IS_READ = #{isRead,jdbcType=VARCHAR}
    where CAR_NEWS_NO = #{carNewsNo,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.baseinfo.meterbasesystemnews.model.MeterBaseSystemNews">
    update METER_BASE_SYSTEM_NEWS
    <set>
      <if test="carNo != null">
        CAR_NO = #{carNo,jdbcType=VARCHAR},
      </if>
      <if test="systemMessageNo != null">
        SYSTEM_MESSAGE_NO = #{systemMessageNo,jdbcType=VARCHAR},
      </if>
      <if test="isRead != null">
        IS_READ = #{isRead,jdbcType=VARCHAR},
      </if>
    </set>
    where CAR_NEWS_NO = #{carNewsNo,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select"/>
    where CAR_NEWS_NO = #{carNewsNo,jdbcType=VARCHAR}
  </select>
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="where"/>
  </select>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="whereLike"/>
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into METER_BASE_SYSTEM_NEWS 
      (CAR_NEWS_NO, 
      CAR_NO, SYSTEM_MESSAGE_NO, IS_READ
      )
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.carNewsNo,jdbcType=VARCHAR}, 
      #{item.carNo,jdbcType=VARCHAR}, #{item.systemMessageNo,jdbcType=VARCHAR}, #{item.isRead,jdbcType=VARCHAR}
       from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update METER_BASE_SYSTEM_NEWS
     set
       CAR_NEWS_NO=
       <foreach collection="list" item="item" index="index" separator=" " open="case CAR_NEWS_NO" close="end">
          when #{item.carNewsNo,jdbcType=VARCHAR} then #{item.carNewsNo,jdbcType=VARCHAR}
       </foreach>
       ,CAR_NO=
       <foreach collection="list" item="item" index="index" separator=" " open="case CAR_NEWS_NO" close="end">
          when #{item.carNewsNo,jdbcType=VARCHAR} then #{item.carNo,jdbcType=VARCHAR}
       </foreach>
       ,SYSTEM_MESSAGE_NO=
       <foreach collection="list" item="item" index="index" separator=" " open="case CAR_NEWS_NO" close="end">
          when #{item.carNewsNo,jdbcType=VARCHAR} then #{item.systemMessageNo,jdbcType=VARCHAR}
       </foreach>
       ,IS_READ=
       <foreach collection="list" item="item" index="index" separator=" " open="case CAR_NEWS_NO" close="end">
          when #{item.carNewsNo,jdbcType=VARCHAR} then #{item.isRead,jdbcType=VARCHAR}
       </foreach>
     where CAR_NEWS_NO in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.carNewsNo,jdbcType=VARCHAR}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from METER_BASE_SYSTEM_NEWS
    where CAR_NEWS_NO in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  <select id="distinctMessageNo" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select distinct SYSTEM_MESSAGE_NO
        from METER_BASE_SYSTEM_NEWS
    where 1 = 1
        <if test="carNo != null and carNo !=''">
          and car_no = #{carNo}
        </if>
  </select>

  <update id="updateIsRead" parameterType="java.lang.String">
    update METER_BASE_SYSTEM_NEWS set IS_READ = '1' where car_news_no = #{systemMessageNo}
  </update>
</mapper>