<?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.goafanti.common.dao.JtNewsMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.JtNews">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="title" jdbcType="VARCHAR" property="title" />
    <result column="publisher" jdbcType="VARCHAR" property="publisher" />
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="picture_url" jdbcType="VARCHAR" property="pictureUrl" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="sort" jdbcType="INTEGER" property="sort" />
    <result column="content" jdbcType="VARCHAR" property="content" />
    <result column="release_status" jdbcType="INTEGER" property="releaseStatus" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="release_time" jdbcType="TIMESTAMP" property="releaseTime" />
  </resultMap>
  <sql id="Base_Column_List">
    id, title, publisher, `type`, picture_url, `status`, sort, content, release_status,
    create_time, release_time
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from jt_news
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from jt_news
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.JtNews">
    insert into jt_news (id, title, publisher,
      `type`, picture_url, `status`,
      sort, content, release_status,
      create_time, release_time)
    values (#{id,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, #{publisher,jdbcType=VARCHAR},
      #{type,jdbcType=INTEGER}, #{pictureUrl,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},
      #{sort,jdbcType=INTEGER}, #{content,jdbcType=VARCHAR}, #{releaseStatus,jdbcType=INTEGER},
      #{createTime,jdbcType=TIMESTAMP}, #{releaseTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.JtNews">
    insert into jt_news
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="title != null">
        title,
      </if>
      <if test="publisher != null">
        publisher,
      </if>
      <if test="type != null">
        `type`,
      </if>
      <if test="pictureUrl != null">
        picture_url,
      </if>
      <if test="status != null">
        `status`,
      </if>
      <if test="sort != null">
        sort,
      </if>
      <if test="content != null">
        content,
      </if>
      <if test="releaseStatus != null">
        release_status,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="releaseTime != null">
        release_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="title != null">
        #{title,jdbcType=VARCHAR},
      </if>
      <if test="publisher != null">
        #{publisher,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        #{type,jdbcType=INTEGER},
      </if>
      <if test="pictureUrl != null">
        #{pictureUrl,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
      <if test="sort != null">
        #{sort,jdbcType=INTEGER},
      </if>
      <if test="content != null">
        #{content,jdbcType=VARCHAR},
      </if>
      <if test="releaseStatus != null">
        #{releaseStatus,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="releaseTime != null">
        #{releaseTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.JtNews">
    update jt_news
    <set>
      <if test="title != null">
        title = #{title,jdbcType=VARCHAR},
      </if>
      <if test="publisher != null">
        publisher = #{publisher,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        `type` = #{type,jdbcType=INTEGER},
      </if>
      <if test="pictureUrl != null">
        picture_url = #{pictureUrl,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        `status` = #{status,jdbcType=INTEGER},
      </if>
      <if test="sort != null">
        sort = #{sort,jdbcType=INTEGER},
      </if>
      <if test="content != null">
        content = #{content,jdbcType=VARCHAR},
      </if>
      <if test="releaseStatus != null">
        release_status = #{releaseStatus,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="releaseTime != null">
        release_time = #{releaseTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.JtNews">
    update jt_news
    set title = #{title,jdbcType=VARCHAR},
      publisher = #{publisher,jdbcType=VARCHAR},
      `type` = #{type,jdbcType=INTEGER},
      picture_url = #{pictureUrl,jdbcType=VARCHAR},
      `status` = #{status,jdbcType=INTEGER},
      sort = #{sort,jdbcType=INTEGER},
      content = #{content,jdbcType=VARCHAR},
      release_status = #{releaseStatus,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      release_time = #{releaseTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>


  <select id="findNewsList" resultType="com.goafanti.news.bo.OutJtNews">
    select id,title,publisher,`type`,picture_url pictureUrl,status,sort,content,release_status releaseStatus,
    date_format(create_time,'%Y-%m-%d %H:%i:%S' ) as createTimes,date_format(release_time,'%Y-%m-%d %H:%i:%S' ) as releaseTimes,
    create_time createTime ,release_time releaseTime
    from jt_news where 1=1
    <if test="n.id!=null">
      and id = #{n.id}
    </if>
    <if test="n.title!=null">
      and title like concat('%',#{n.title},'%')
    </if>
    <if test="n.releaseStatus!=null">
      and release_status = #{n.releaseStatus}
    </if>
    <if test="n.status!=null">
      and status = #{n.status}
    </if>
    <if test="n.type!=null">
      and type = #{n.type}
    </if>
    order by releaseStatus desc,sort desc,id desc
    <if test="page_sql!=null">
      ${page_sql}
    </if>
  </select>

  <select id="findNewsCount" resultType="java.lang.Integer">
    select count(*)
    from jt_news where 1=1
    <if test="n.id!=null">
      and id = #{n.id}
    </if>
    <if test="n.title!=null">
      and title like concat('%',#{n.title},'%')
    </if>
    <if test="n.releaseStatus!=null">
      and release_status = #{n.releaseStatus}
    </if>
    <if test="n.status!=null">
      and status = #{n.status}
    </if>
    <if test="n.type!=null">
      and type = #{n.type}
    </if>
  </select>
  <select id="selectByid" resultType="com.goafanti.news.bo.OutJtNews">
    select id, title, publisher, type, picture_url pictureUrl, status, sort, release_status releaseStatus,content,
           date_format(create_time,'%Y-%m-%d %H:%i:%S') as createTimes,create_time createTime,
           date_format(release_time,'%Y-%m-%d %H:%i:%S') as releaseTimes ,release_time releaseTime
    from jt_news where id = #{id,jdbcType=INTEGER}
  </select>
</mapper>
