<?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.ruoyi.syzy.mapper.BWwwNewsMapper">

  <resultMap type="BWwwNews" id="BWwwNewsResult">
    <result property="id" column="id" />
    <result property="type" column="type" />
    <result property="title" column="title" />
    <result property="f" column="f" />
    <result property="sendDate" column="sendDate" />
    <result property="content" column="content" />
    <result property="createTime" column="createTime" />
    <result property="clicked" column="clicked" />
    <result property="status" column="status" />
    <result property="keywords" column="keywords" />
    <result property="description" column="description" />
    <result property="isTop" column="isTop" />
    <result property="location" column="location" />
  </resultMap>

  <sql id="selectBWwwNewsVo">
    select id, type, title, f, sendDate, content, createTime, clicked, status,keywords,description,isTop,location from b_www_news
  </sql>

  <select id="selectBWwwNewsList" parameterType="BWwwNews" resultMap="BWwwNewsResult">
    <include refid="selectBWwwNewsVo" />
    <where>
      <if test="type != null  and type != ''"> and type like concat ('%', #{type},'%')</if>
      <if test="title != null  and title != ''"> and title like concat ('%', #{title},'%')</if>
      <if test="f != null  and f != ''"> and f = #{f}</if>
      <if test="sendDate != null "> and sendDate = #{sendDate}</if>
      <if test="content != null  and content != ''"> and content = #{content}</if>
      <if test="createTime != null "> and createTime = #{createTime}</if>
      <if test="clicked != null "> and clicked = #{clicked}</if>
      <if test="status != null "> and status = #{status}</if>
      <if test="isTop != null "> and isTop = #{isTop}</if>
      <if test="description != null  and description != ''"> and description = #{description}</if>
      <if test="keywords != null  and keywords != ''"> and keywords = #{keywords}</if>
      <if test="location != null  and location != ''"> and location like concat ('%', #{location},'%')</if>
      <if test="ids!= null">
        and id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
          #{id}
        </foreach>
      </if>
    </where>
    <if test="tag=='hot'"> order by clicked desc,createTime desc,id desc </if>
    <if test="tag==null"> order by createTime desc,id desc  </if>
  </select>

  <select id="selectBWwwNewsById" parameterType="Long" resultMap="BWwwNewsResult">
    <include refid="selectBWwwNewsVo" />
    where id = #{id}
  </select>

  <insert id="insertBWwwNews" parameterType="BWwwNews" useGeneratedKeys="true" keyProperty="id">
    insert into b_www_news
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="type != null">type,</if>
      <if test="title != null">title,</if>
      <if test="f != null">f,</if>
      <if test="sendDate != null">sendDate,</if>
      <if test="content != null">content,</if>
      <if test="createTime != null">createTime,</if>
      <if test="clicked != null">clicked,</if>
      <if test="status != null">status,</if>
      <if test="location != null and location != '' ">location,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="type != null">#{type},</if>
      <if test="title != null">#{title},</if>
      <if test="f != null">#{f},</if>
      <if test="sendDate != null">#{sendDate},</if>
      <if test="content != null">#{content},</if>
      <if test="createTime != null">#{createTime},</if>
      <if test="clicked != null">#{clicked},</if>
      <if test="status != null">#{status},</if>
      <if test="location != null and location != '' ">#{location},</if>
    </trim>
  </insert>

  <update id="updateBWwwNews" parameterType="BWwwNews">
    update b_www_news
    <trim prefix="SET" suffixOverrides=",">
      <if test="type != null">type = #{type},</if>
      <if test="title != null">title = #{title},</if>
      <if test="f != null">f = #{f},</if>
      <if test="sendDate != null">sendDate = #{sendDate},</if>
      <if test="content != null">content = #{content},</if>
      <if test="createTime != null">createTime = #{createTime},</if>
      <if test="clicked != null">clicked = #{clicked},</if>
      <if test="status != null">status = #{status},</if>
      <if test="isTop != null">isTop = #{isTop},</if>
      <if test="location != null and location != ''">location = #{location},</if>
    </trim>
    where id = #{id}
  </update>

  <delete id="deleteBWwwNewsById" parameterType="Long">
    delete from b_www_news where id = #{id}
  </delete>

  <delete id="deleteBWwwNewsByIds" parameterType="String">
    delete from b_www_news where id in
    <foreach item="id" collection="array" open="(" separator="," close=")">
      #{id}
    </foreach>
  </delete>
</mapper>
