<?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.lightinit.hsdataplatform.mapper.NewsMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdataplatform.entity.News">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="news_state" jdbcType="VARCHAR" property="newsState" />
    <result column="news_category" jdbcType="VARCHAR" property="newsCategory" />
    <result column="news_title" jdbcType="VARCHAR" property="newsTitle" />
    <result column="sub_title" jdbcType="VARCHAR" property="subTitle" />
    <result column="publish_by" jdbcType="BIGINT" property="publishBy" />
    <result column="publish_at" jdbcType="TIMESTAMP" property="publishAt" />
    <result column="audited_by" jdbcType="BIGINT" property="auditedBy" />
    <result column="audited_at" jdbcType="TIMESTAMP" property="auditedAt" />
    <result column="audit_result" jdbcType="VARCHAR" property="auditResult" />
    <result column="audit_opinion" jdbcType="VARCHAR" property="auditOpinion" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="created_by" jdbcType="BIGINT" property="createdBy" />
    <result column="deleted_at" jdbcType="TIMESTAMP" property="deletedAt" />
    <result column="deleted_by" jdbcType="BIGINT" property="deletedBy" />
  </resultMap>
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.lightinit.hsdataplatform.entity.NewsWithBLOBs">
    <result column="screenshot" jdbcType="LONGVARCHAR" property="screenshot" />
    <result column="video_url" jdbcType="LONGVARCHAR" property="videoUrl" />
    <result column="video_screenshot" jdbcType="LONGVARCHAR" property="videoScreenshot" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    id, news_state, news_category, news_title, sub_title, publish_by, publish_at, audited_by, 
    audited_at, audit_result, audit_opinion, created_at, created_by, deleted_at, deleted_by
  </sql>
  <sql id="Blob_Column_List">
    screenshot, video_url, video_screenshot
  </sql>
  <select id="selectByExampleWithBLOBs" parameterType="com.lightinit.hsdataplatform.entity.NewsExample" resultMap="ResultMapWithBLOBs">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from news
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByExample" parameterType="com.lightinit.hsdataplatform.entity.NewsExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from news
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="ResultMapWithBLOBs">
    select 
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from news
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from news
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.lightinit.hsdataplatform.entity.NewsExample">
    delete from news
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdataplatform.entity.NewsWithBLOBs">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into news (news_state, news_category, news_title, 
      sub_title, publish_by, publish_at, 
      audited_by, audited_at, audit_result, 
      audit_opinion, created_at, created_by, 
      deleted_at, deleted_by, screenshot, 
      video_url, video_screenshot)
    values (#{newsState,jdbcType=VARCHAR}, #{newsCategory,jdbcType=VARCHAR}, #{newsTitle,jdbcType=VARCHAR}, 
      #{subTitle,jdbcType=VARCHAR}, #{publishBy,jdbcType=BIGINT}, #{publishAt,jdbcType=TIMESTAMP}, 
      #{auditedBy,jdbcType=BIGINT}, #{auditedAt,jdbcType=TIMESTAMP}, #{auditResult,jdbcType=VARCHAR}, 
      #{auditOpinion,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=BIGINT}, 
      #{deletedAt,jdbcType=TIMESTAMP}, #{deletedBy,jdbcType=BIGINT}, #{screenshot,jdbcType=LONGVARCHAR}, 
      #{videoUrl,jdbcType=LONGVARCHAR}, #{videoScreenshot,jdbcType=LONGVARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.lightinit.hsdataplatform.entity.NewsWithBLOBs">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into news
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="newsState != null">
        news_state,
      </if>
      <if test="newsCategory != null">
        news_category,
      </if>
      <if test="newsTitle != null">
        news_title,
      </if>
      <if test="subTitle != null">
        sub_title,
      </if>
      <if test="publishBy != null">
        publish_by,
      </if>
      <if test="publishAt != null">
        publish_at,
      </if>
      <if test="auditedBy != null">
        audited_by,
      </if>
      <if test="auditedAt != null">
        audited_at,
      </if>
      <if test="auditResult != null">
        audit_result,
      </if>
      <if test="auditOpinion != null">
        audit_opinion,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
      <if test="deletedAt != null">
        deleted_at,
      </if>
      <if test="deletedBy != null">
        deleted_by,
      </if>
      <if test="screenshot != null">
        screenshot,
      </if>
      <if test="videoUrl != null">
        video_url,
      </if>
      <if test="videoScreenshot != null">
        video_screenshot,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="newsState != null">
        #{newsState,jdbcType=VARCHAR},
      </if>
      <if test="newsCategory != null">
        #{newsCategory,jdbcType=VARCHAR},
      </if>
      <if test="newsTitle != null">
        #{newsTitle,jdbcType=VARCHAR},
      </if>
      <if test="subTitle != null">
        #{subTitle,jdbcType=VARCHAR},
      </if>
      <if test="publishBy != null">
        #{publishBy,jdbcType=BIGINT},
      </if>
      <if test="publishAt != null">
        #{publishAt,jdbcType=TIMESTAMP},
      </if>
      <if test="auditedBy != null">
        #{auditedBy,jdbcType=BIGINT},
      </if>
      <if test="auditedAt != null">
        #{auditedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="auditResult != null">
        #{auditResult,jdbcType=VARCHAR},
      </if>
      <if test="auditOpinion != null">
        #{auditOpinion,jdbcType=VARCHAR},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="deletedAt != null">
        #{deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedBy != null">
        #{deletedBy,jdbcType=BIGINT},
      </if>
      <if test="screenshot != null">
        #{screenshot,jdbcType=LONGVARCHAR},
      </if>
      <if test="videoUrl != null">
        #{videoUrl,jdbcType=LONGVARCHAR},
      </if>
      <if test="videoScreenshot != null">
        #{videoScreenshot,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.lightinit.hsdataplatform.entity.NewsExample" resultType="java.lang.Long">
    select count(*) from news
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update news
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.newsState != null">
        news_state = #{record.newsState,jdbcType=VARCHAR},
      </if>
      <if test="record.newsCategory != null">
        news_category = #{record.newsCategory,jdbcType=VARCHAR},
      </if>
      <if test="record.newsTitle != null">
        news_title = #{record.newsTitle,jdbcType=VARCHAR},
      </if>
      <if test="record.subTitle != null">
        sub_title = #{record.subTitle,jdbcType=VARCHAR},
      </if>
      <if test="record.publishBy != null">
        publish_by = #{record.publishBy,jdbcType=BIGINT},
      </if>
      <if test="record.publishAt != null">
        publish_at = #{record.publishAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.auditedBy != null">
        audited_by = #{record.auditedBy,jdbcType=BIGINT},
      </if>
      <if test="record.auditedAt != null">
        audited_at = #{record.auditedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.auditResult != null">
        audit_result = #{record.auditResult,jdbcType=VARCHAR},
      </if>
      <if test="record.auditOpinion != null">
        audit_opinion = #{record.auditOpinion,jdbcType=VARCHAR},
      </if>
      <if test="record.createdAt != null">
        created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createdBy != null">
        created_by = #{record.createdBy,jdbcType=BIGINT},
      </if>
      <if test="record.deletedAt != null">
        deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.deletedBy != null">
        deleted_by = #{record.deletedBy,jdbcType=BIGINT},
      </if>
      <if test="record.screenshot != null">
        screenshot = #{record.screenshot,jdbcType=LONGVARCHAR},
      </if>
      <if test="record.videoUrl != null">
        video_url = #{record.videoUrl,jdbcType=LONGVARCHAR},
      </if>
      <if test="record.videoScreenshot != null">
        video_screenshot = #{record.videoScreenshot,jdbcType=LONGVARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExampleWithBLOBs" parameterType="map">
    update news
    set id = #{record.id,jdbcType=BIGINT},
      news_state = #{record.newsState,jdbcType=VARCHAR},
      news_category = #{record.newsCategory,jdbcType=VARCHAR},
      news_title = #{record.newsTitle,jdbcType=VARCHAR},
      sub_title = #{record.subTitle,jdbcType=VARCHAR},
      publish_by = #{record.publishBy,jdbcType=BIGINT},
      publish_at = #{record.publishAt,jdbcType=TIMESTAMP},
      audited_by = #{record.auditedBy,jdbcType=BIGINT},
      audited_at = #{record.auditedAt,jdbcType=TIMESTAMP},
      audit_result = #{record.auditResult,jdbcType=VARCHAR},
      audit_opinion = #{record.auditOpinion,jdbcType=VARCHAR},
      created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      created_by = #{record.createdBy,jdbcType=BIGINT},
      deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{record.deletedBy,jdbcType=BIGINT},
      screenshot = #{record.screenshot,jdbcType=LONGVARCHAR},
      video_url = #{record.videoUrl,jdbcType=LONGVARCHAR},
      video_screenshot = #{record.videoScreenshot,jdbcType=LONGVARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update news
    set id = #{record.id,jdbcType=BIGINT},
      news_state = #{record.newsState,jdbcType=VARCHAR},
      news_category = #{record.newsCategory,jdbcType=VARCHAR},
      news_title = #{record.newsTitle,jdbcType=VARCHAR},
      sub_title = #{record.subTitle,jdbcType=VARCHAR},
      publish_by = #{record.publishBy,jdbcType=BIGINT},
      publish_at = #{record.publishAt,jdbcType=TIMESTAMP},
      audited_by = #{record.auditedBy,jdbcType=BIGINT},
      audited_at = #{record.auditedAt,jdbcType=TIMESTAMP},
      audit_result = #{record.auditResult,jdbcType=VARCHAR},
      audit_opinion = #{record.auditOpinion,jdbcType=VARCHAR},
      created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      created_by = #{record.createdBy,jdbcType=BIGINT},
      deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{record.deletedBy,jdbcType=BIGINT}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.lightinit.hsdataplatform.entity.NewsWithBLOBs">
    update news
    <set>
      <if test="newsState != null">
        news_state = #{newsState,jdbcType=VARCHAR},
      </if>
      <if test="newsCategory != null">
        news_category = #{newsCategory,jdbcType=VARCHAR},
      </if>
      <if test="newsTitle != null">
        news_title = #{newsTitle,jdbcType=VARCHAR},
      </if>
      <if test="subTitle != null">
        sub_title = #{subTitle,jdbcType=VARCHAR},
      </if>
      <if test="publishBy != null">
        publish_by = #{publishBy,jdbcType=BIGINT},
      </if>
      <if test="publishAt != null">
        publish_at = #{publishAt,jdbcType=TIMESTAMP},
      </if>
      <if test="auditedBy != null">
        audited_by = #{auditedBy,jdbcType=BIGINT},
      </if>
      <if test="auditedAt != null">
        audited_at = #{auditedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="auditResult != null">
        audit_result = #{auditResult,jdbcType=VARCHAR},
      </if>
      <if test="auditOpinion != null">
        audit_opinion = #{auditOpinion,jdbcType=VARCHAR},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="deletedAt != null">
        deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedBy != null">
        deleted_by = #{deletedBy,jdbcType=BIGINT},
      </if>
      <if test="screenshot != null">
        screenshot = #{screenshot,jdbcType=LONGVARCHAR},
      </if>
      <if test="videoUrl != null">
        video_url = #{videoUrl,jdbcType=LONGVARCHAR},
      </if>
      <if test="videoScreenshot != null">
        video_screenshot = #{videoScreenshot,jdbcType=LONGVARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.lightinit.hsdataplatform.entity.NewsWithBLOBs">
    update news
    set news_state = #{newsState,jdbcType=VARCHAR},
      news_category = #{newsCategory,jdbcType=VARCHAR},
      news_title = #{newsTitle,jdbcType=VARCHAR},
      sub_title = #{subTitle,jdbcType=VARCHAR},
      publish_by = #{publishBy,jdbcType=BIGINT},
      publish_at = #{publishAt,jdbcType=TIMESTAMP},
      audited_by = #{auditedBy,jdbcType=BIGINT},
      audited_at = #{auditedAt,jdbcType=TIMESTAMP},
      audit_result = #{auditResult,jdbcType=VARCHAR},
      audit_opinion = #{auditOpinion,jdbcType=VARCHAR},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{deletedBy,jdbcType=BIGINT},
      screenshot = #{screenshot,jdbcType=LONGVARCHAR},
      video_url = #{videoUrl,jdbcType=LONGVARCHAR},
      video_screenshot = #{videoScreenshot,jdbcType=LONGVARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.lightinit.hsdataplatform.entity.News">
    update news
    set news_state = #{newsState,jdbcType=VARCHAR},
      news_category = #{newsCategory,jdbcType=VARCHAR},
      news_title = #{newsTitle,jdbcType=VARCHAR},
      sub_title = #{subTitle,jdbcType=VARCHAR},
      publish_by = #{publishBy,jdbcType=BIGINT},
      publish_at = #{publishAt,jdbcType=TIMESTAMP},
      audited_by = #{auditedBy,jdbcType=BIGINT},
      audited_at = #{auditedAt,jdbcType=TIMESTAMP},
      audit_result = #{auditResult,jdbcType=VARCHAR},
      audit_opinion = #{auditOpinion,jdbcType=VARCHAR},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{deletedBy,jdbcType=BIGINT}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <!--sun-->
  <select id="getNewsList" parameterType="com.lightinit.hsdataplatform.model.admin.ConsultSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.NewModel">
    <if test="newsTitle !=null and newsTitle!=''">
      <bind name="newsTitleLike" value="'%'+newsTitle+'%'"></bind>
    </if>
    SELECT n.id,n.news_title,n.sub_title,n.publish_by,n.news_category,a.showname,nc.news_content,n.created_at,n.publish_at,n.news_state,n.video_url FROM news n
    LEFT JOIN news_content nc ON n.id=nc.id
    LEFT JOIN admin a ON n.publish_by=a.id
    <where>
      <if test="newsTitle !=null and newsTitle!=''">
        n.news_title like #{newsTitleLike}
      </if>
      <if test="newsState !=null and newsState!=''">
        n.news_state = #{newsState}
      </if>
      <if test="publishAt !=null">
        Date(n.publish_at) = #{newsState}
      </if>
        <if test="id !=null">
        n.id = #{id}
      </if>
    </where>
    ORDER BY id DESC
    <if test="page != null" >
      limit ${page.beginIndex},${page.pageSize}
    </if>
  </select>
  <!--sun-->
  <select id="queryNewsCount" parameterType="com.lightinit.hsdataplatform.model.admin.ConsultSearchModel" resultType="int">
    <if test="newsTitle !=null and newsTitle!=''">
      <bind name="newsTitleLike" value="'%'+newsTitle+'%'"></bind>
    </if>
    SELECT count(*) FROM news n
    LEFT JOIN news_content nc ON n.id=nc.id
    LEFT JOIN admin a ON n.publish_by=a.id
    <where>
      <if test="newsTitle !=null and newsTitle!=''">
        n.news_title like #{newsTitleLike}
      </if>
      <if test="newsState !=null and newsState!=''">
        n.news_state = #{newsState}
      </if>
      <if test="publishAt !=null">
        Date(n.publish_at) = #{newsState}
      </if>
    </where>
  </select>
</mapper>