<?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.pcloud.book.applet.dao.impl.AppletNewsDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.applet.entity.AppletNews" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="news_name" property="newsName" jdbcType="VARCHAR" />
    <result column="source" property="source" jdbcType="VARCHAR" />
    <result column="news_classify_id" property="newsClassifyId" jdbcType="BIGINT" />
    <result column="pro_label_id" property="proLabelId" jdbcType="BIGINT" />
    <result column="dep_label_id" property="depLabelId" jdbcType="BIGINT" />
    <result column="pur_label_id" property="purLabelId" jdbcType="BIGINT" />
    <result column="type" property="type" jdbcType="INTEGER" />
    <result column="digest" property="digest" jdbcType="VARCHAR" />
    <result column="pic1" property="pic1" jdbcType="VARCHAR" />
    <result column="pic2" property="pic2" jdbcType="VARCHAR" />
    <result column="pic3" property="pic3" jdbcType="VARCHAR" />
    <result column="content" property="content" jdbcType="VARCHAR" />
    <result column="show_state" property="showState" jdbcType="BOOLEAN" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    <result column="first_classify" property="firstClassify" jdbcType="BIGINT" />
    <result column="second_classify" property="secondClassify" jdbcType="BIGINT" />
    <result column="grade_label_id" property="gradeLabelId" jdbcType="BIGINT" />
    <result column="subject_label_id" property="subjectLabelId" jdbcType="BIGINT" />
    <result column="rights_classify_id" property="rightsClassifyId" jdbcType="BIGINT" />
    <result column="jump_type" property="jumpType" jdbcType="INTEGER" />
    <result column="jump_url" property="jumpUrl" jdbcType="VARCHAR" />
    <result column="url_number" property="urlNumber" jdbcType="VARCHAR" />
    <result column="custom_tag_id" property="customTagId" jdbcType="BIGINT" />
    <result column="show_source" property="showSource" jdbcType="INTEGER" />
    <result column="show_link" property="showLink" jdbcType="INTEGER" />
    <result column="business_card_id" property="businessCardId" jdbcType="BIGINT" />
    <result column="business_card_type" property="businessCardType" jdbcType="TINYINT" />
    <result column="business_card_isOpen" property="businessCardIsOpen" jdbcType="TINYINT" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, news_name, source, news_classify_id, pro_label_id, dep_label_id, pur_label_id, type, digest,
     pic1, pic2, pic3, content, show_state, create_time, update_time, first_classify, second_classify, grade_label_id, subject_label_id, rights_classify_id,
     jump_type, jump_url, url_number, custom_tag_id, show_source, show_link,business_card_id,business_card_type,business_card_isOpen
  </sql>

  <insert id="insert" parameterType="com.pcloud.book.applet.entity.AppletNews" useGeneratedKeys="true" keyProperty="id">
    insert into applet_news(
     news_name, source, news_classify_id, pro_label_id, dep_label_id, pur_label_id, type, digest,
     pic1, pic2, pic3, content, show_state, create_time, update_time , first_classify, second_classify, grade_label_id, subject_label_id, rights_classify_id,
     jump_type, jump_url,url_number, custom_tag_id, show_source, show_link,business_card_id,business_card_type,business_card_isOpen
      )
    values (
      #{newsName}, #{source}, #{newsClassifyId}, #{proLabelId}, #{depLabelId}, #{purLabelId}, #{type}, #{digest},
      #{pic1}, #{pic2}, #{pic3}, #{content}, #{showState}, NOW(), NOW(), #{firstClassify,jdbcType=BIGINT}, #{secondClassify,jdbcType=BIGINT},
      #{gradeLabelId,jdbcType=BIGINT}, #{subjectLabelId,jdbcType=BIGINT}, #{rightsClassifyId,jdbcType=BIGINT},
      #{jumpType}, #{jumpUrl}, #{urlNumber}, #{customTagId}, #{showSource}, #{showLink}, #{businessCardId}, #{businessCardType}, #{businessCardIsOpen}
      )
  </insert>

  <update id="update" parameterType="com.pcloud.book.applet.entity.AppletNews">
    update applet_news
    <set>
      <if test="newsName != null">
        news_name = #{newsName},
      </if>
      <if test="source != null">
        source = #{source},
      </if>
        news_classify_id = #{newsClassifyId},
        pro_label_id = #{proLabelId},
        dep_label_id = #{depLabelId},
        pur_label_id = #{purLabelId},
      <if test="type != null">
        type = #{type},
      </if>
      digest = #{digest},
      pic1 = #{pic1},
      pic2 = #{pic2},
      pic3 = #{pic3},
      <if test="content != null">
        content = #{content},
      </if>
      <if test="showState != null">
        show_state = #{showState,jdbcType=BOOLEAN},
      </if>
      first_classify = #{firstClassify,jdbcType=BIGINT},
      second_classify = #{secondClassify,jdbcType=BIGINT},
      grade_label_id = #{gradeLabelId,jdbcType=BIGINT},
      subject_label_id = #{subjectLabelId,jdbcType=BIGINT},
      rights_classify_id = #{rightsClassifyId,jdbcType=BIGINT},
      <if test="jumpType != null">
        jump_type = #{jumpType},
      </if>
      <if test="showSource != null">
        show_source = #{showSource},
      </if>
      <if test="showLink != null">
        show_link = #{showLink},
      </if>
      jump_url = #{jumpUrl},
      url_number = #{urlNumber},
      business_card_id = #{businessCardId},
      business_card_type = #{businessCardType},
      business_card_isOpen = #{businessCardIsOpen},
      update_time=NOW()
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  
  <update id="updateNewsShowState" parameterType="com.pcloud.book.applet.entity.AppletNews">
     update applet_news
     set show_state = #{showState,jdbcType=BOOLEAN}
     where id = #{id,jdbcType=BIGINT}
  </update>

  <select id="getById" parameterType="long" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"/>
    from applet_news
    where id=#{id}
  </select>

  <delete id="deleteById" parameterType="long">
    delete from applet_news
    where id=#{id}
  </delete>

  <select id="listAppletNews" parameterType="map" resultType="com.pcloud.book.applet.dto.AppletNewsDTO">
    SELECT
    n.id,
    n.news_name newsName,
    n.source,
    n.news_classify_id newsClassifyId,
    n.pro_label_id proLabelId,
    n.dep_label_id depLabelId,
    n.pur_label_id purLabelId,
    n.type,
    n.digest,
    n.pic1,
    n.pic2,
    n.pic3,
    n.content,
    n.show_state showState,
    c.news_classify newsClassify,
    n.create_time createTime,
    n.first_classify firstClassify,
    n.second_classify secondClassify,
    n.grade_label_id gradeLabelId,
    n.subject_label_id subjectLabelId,
    n.rights_classify_id rightsClassifyId,
    d.classify rightsClassifyContent,
    n.jump_type jumpType,
    n.jump_url jumpUrl,
    n.url_number urlNumber,
    n.custom_tag_id customTagId,
    t.custom_tag customTag,
    n.show_source showSource,
    n.show_link showLink
    FROM applet_news n
      LEFT JOIN applet_news_classify c ON n.news_classify_id=c.id
      LEFT JOIN rights_setting_classify d ON n.rights_classify_id = d.id
      LEFT JOIN applet_news_custom_tag t ON n.custom_tag_id = t.id
    WHERE 1=1
    <if test="name != null">
    AND (n.news_name LIKE CONCAT("%",#{name},"%") OR n.url_number LIKE CONCAT("%",#{name},"%"))
    </if>
    <if test="newsClassifyId >0">
      AND n.news_classify_id = #{newsClassifyId}
    </if>
    <if test="showState != null">
      AND n.show_state = #{showState}
    </if>
    <if test="firstClassify!=null">
      AND n.first_classify =#{firstClassify}
    </if>
    <if test="secondClassify!=null">
      AND n.second_classify =#{secondClassify}
    </if>
    <if test="gradeLabelId != null">
      AND n.grade_label_id = #{gradeLabelId}
    </if>
    <if test="subjectLabelId != null">
      AND n.subject_label_id = #{subjectLabelId}
    </if>
    <if test="rightsClassifyId!=null">
      AND n.rights_classify_id =#{rightsClassifyId}
    </if>
    <if test="source != null">
     AND n.source = #{source}
    </if>
    <if test="customTagId != null">
     AND n.custom_tag_id = #{customTagId}
    </if>
    ORDER BY n.create_time DESC
  </select>

  <select id="getCountByBusinessCardId" parameterType="long" resultType="long">
    select count(1)
    from applet_news
    where business_card_id=#{businessCardId}
  </select>


  <select id="getByNewsClassifyId" parameterType="long" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"/>
    from applet_news
    where news_classify_id=#{newsClassifyId}
  </select>

  <select id="getByNewsByTempletLabel" parameterType="map" resultType="com.pcloud.book.applet.dto.AppletNewsDTO">
    SELECT
    n.id,
    n.news_name newsName,
    n.source,
    n.news_classify_id newsClassifyId,
    n.pro_label_id proLabelId,
    n.dep_label_id depLabelId,
    n.pur_label_id purLabelId,
    n.type,
    n.digest,
    n.pic1,
    n.pic2,
    n.pic3,
    n.content,
    n.show_state showState,
    n.create_time createTime,
    n.first_classify firstClassify,
    n.second_classify secondClassify,
    n.grade_label_id gradeLabelId,
    n.subject_label_id subjectLabelId,
    n.rights_classify_id rightsClassifyId,
    n.jump_type jumpType,
    n.jump_url jumpUrl,
    n.url_number urlNumber,
    n.show_source showSource,
    n.show_link showLink
    FROM applet_news n
    WHERE 1=1
    and n.show_state = 1
    <if test="firstClassify != null">
      and n.first_classify = #{firstClassify}
    </if>
    <if test="secondClassify != null">
      and n.second_classify = #{secondClassify}
    </if>
    <if test="gradeLabelId != null">
      and n.grade_label_id = #{gradeLabelId}
    </if>
    <if test="subjectLabelId != null">
      and n.subject_label_id = #{subjectLabelId}
    </if>
    AND n.rights_classify_id IN(
    SELECT id FROM rights_setting_classify WHERE 1=1
    <if test="rightsType != null" >
      AND rights_type = #{rightsType}
    </if>
    )
    ORDER BY n.create_time DESC
  </select>

  <select id="getByTempletAndClassify" parameterType="map" resultMap="BaseResultMap">
    SELECT
        <include refid="Base_Column_List"/>
    FROM
        applet_news t
    WHERE
        t.show_state = 1
    <if test="firstClassify!=null">
      AND t.first_classify =#{firstClassify}
    </if>
    <if test="secondClassify!=null">
      AND t.second_classify =#{secondClassify}
    </if>
    <if test="gradeLabelId != null">
      AND t.grade_label_id = #{gradeLabelId}
    </if>
    <if test="subjectLabelId != null">
      AND t.subject_label_id = #{subjectLabelId}
    </if>
    <if test="rightsClassifyId!=null">
      AND t.rights_classify_id =#{rightsClassifyId}
    </if>
    ORDER BY
        t.create_time DESC
    LIMIT #{top}
  </select>

  <update id="batchUpdateClassify" parameterType="map">
    UPDATE applet_news
    SET
      first_classify = #{firstClassify,jdbcType=BIGINT},
      second_classify = #{secondClassify,jdbcType=BIGINT},
      grade_label_id = #{gradeLabelId,jdbcType=BIGINT},
      subject_label_id = #{subjectLabelId,jdbcType=BIGINT},
      rights_classify_id = #{rightsClassifyId,jdbcType=BIGINT},
      <if test="newsClassifyId != null">
        news_classify_id = #{newsClassifyId},
      </if>
      update_time=NOW()
    WHERE id IN
    <foreach collection="ids" item="item" separator="," open="(" close=")" >
      ${item}
    </foreach>
  </update>

  <update id="batchUpdateShowState" parameterType="map">
    UPDATE applet_news
    SET
    show_state = #{showState},
    update_time=NOW()
    WHERE id IN
    <foreach collection="ids" item="item" separator="," open="(" close=")" >
      ${item}
    </foreach>
  </update>

  <delete id="batchDeleteAppletNews" parameterType="list">
    DELETE FROM applet_news
    WHERE id IN
    <foreach collection="list" item="item" separator="," open="(" close=")" >
      ${item}
    </foreach>
  </delete>

  <select id="insertSource" parameterType="string">
      INSERT INTO applet_news_source (source) VALUES (#{source})
  </select>

  <select id="getNewsSourceList" resultType="string">
    SELECT source FROM applet_news_source
  </select>

  <select id="getAppletNewsSourceCount" resultType="integer" parameterType="string">
    SELECT COUNT(1) FROM applet_news WHERE source = #{source}
  </select>

  <delete id="deleteSource" parameterType="string">
    DELETE FROM applet_news_source WHERE source = #{source}
  </delete>

  <select id="newsSourceExist" parameterType="string" resultType="boolean">
    SELECT EXISTS(
    SELECT id FROM applet_news_source   WHERE source=#{source}
    )
  </select>

  <select id="getUrlNumberByJumpUrl" parameterType="string" resultType="string">
    SELECT url_number
    FROM applet_news
    WHERE jump_url = #{jumpUrl}
    AND jump_type = 2
    AND url_number IS NOT NULL
    LIMIT 1
  </select>

  <select id="urlNumberExist" parameterType="map" resultType="boolean">
    SELECT EXISTS (
      SELECT id
      FROM  applet_news
      WHERE
          url_number = #{urlNumber}
      <if test="id>0">
        AND id != #{id}
      </if>
    )
  </select>

  <select id="listAppletNews4Analysis" parameterType="map" resultType="com.pcloud.book.applet.dto.AppletNewsDTO">
    SELECT
    n.id,
    n.news_name newsName,
    n.source,
    n.news_classify_id newsClassifyId,
    n.pro_label_id proLabelId,
    n.dep_label_id depLabelId,
    n.pur_label_id purLabelId,
    n.type,
    n.digest,
    n.pic1,
    n.pic2,
    n.pic3,
    n.content,
    n.show_state showState,
    c.news_classify newsClassify,
    n.create_time createTime,
    n.first_classify firstClassify,
    n.second_classify secondClassify,
    n.grade_label_id gradeLabelId,
    n.subject_label_id subjectLabelId,
    n.rights_classify_id rightsClassifyId,
    d.classify rightsClassifyContent,
    n.jump_type jumpType,
    n.jump_url jumpUrl,
    n.url_number urlNumber,
    n.show_source showSource,
    n.show_link showLink
    FROM applet_news n
    LEFT JOIN applet_news_classify c ON n.news_classify_id=c.id
    LEFT JOIN rights_setting_classify d ON n.rights_classify_id = d.id
    WHERE 1=1
    <if test="name != null">
      AND (n.news_name LIKE CONCAT("%",#{name},"%") or n.url_number LIKE CONCAT("%",#{name},"%"))
    </if>
    <if test="firstClassify!=null">
      AND n.first_classify =#{firstClassify}
    </if>
    <if test="secondClassify!=null">
      AND n.second_classify =#{secondClassify}
    </if>
    <if test="gradeLabelId != null">
      AND n.grade_label_id = #{gradeLabelId}
    </if>
    <if test="subjectLabelId != null">
      AND n.subject_label_id = #{subjectLabelId}
    </if>
    <if test="linkOnly == 1">
      and n.jump_type = 2
    </if>
    <if test="rightsClassifyId!=null">
      AND n.rights_classify_id =#{rightsClassifyId}
    </if>
    <if test="source!=null">
      AND n.source =#{source}
    </if>
    ORDER BY n.create_time DESC
  </select>

  <select id="getByIds" resultType="com.pcloud.book.applet.dto.AppletNewsDTO">
    SELECT
    n.id,
    n.news_name newsName,
    n.source,
    n.news_classify_id newsClassifyId,
    n.pro_label_id proLabelId,
    n.dep_label_id depLabelId,
    n.pur_label_id purLabelId,
    n.type,
    n.digest,
    n.pic1,
    n.pic2,
    n.pic3,
    n.show_state showState,
    n.create_time createTime,
    n.first_classify firstClassify,
    n.second_classify secondClassify,
    n.grade_label_id gradeLabelId,
    n.subject_label_id subjectLabelId,
    n.rights_classify_id rightsClassifyId,
    n.jump_type jumpType,
    n.jump_url jumpUrl,
    n.url_number urlNumber,
    n.show_source showSource,
    n.show_link showLink
    FROM applet_news n
    WHERE n.show_state = 1
    AND n.id IN
    <foreach collection="list" item="item" separator="," open="(" close=")" >
      ${item}
    </foreach>
    ORDER BY n.create_time DESC
  </select>


  <select id="listAppletNews4Wechat" parameterType="map" resultType="com.pcloud.book.applet.dto.AppletNewsDTO">
    SELECT
    n.id,
    n.news_name newsName,
    n.source,
    n.news_classify_id newsClassifyId,
    n.pro_label_id proLabelId,
    n.dep_label_id depLabelId,
    n.pur_label_id purLabelId,
    n.type,
    n.digest,
    n.pic1,
    n.pic2,
    n.pic3,
    n.content,
    n.show_state showState,
    c.news_classify newsClassify,
    n.create_time createTime,
    n.first_classify firstClassify,
    n.second_classify secondClassify,
    n.grade_label_id gradeLabelId,
    n.subject_label_id subjectLabelId,
    n.rights_classify_id rightsClassifyId,
    n.jump_type jumpType,
    n.jump_url jumpUrl,
    n.show_source showSource,
    n.show_link showLink
    FROM applet_news n
    LEFT JOIN applet_news_classify c ON n.news_classify_id=c.id
    WHERE n.show_state = 1
    <if test="newsClassifyId >0">
      AND n.news_classify_id = #{newsClassifyId}
    </if>
    <if test="newsClassifyIdList != null">
      AND n.news_classify_id in
      <foreach collection="newsClassifyIdList" item="item" open="(" separator="," close=")">
        ${item}
      </foreach>
    </if>
    <if test="firstPageIds != null and firstPageIds.size() > 0">
      and n.id not in
      <foreach collection="firstPageIds" item="item" open="(" separator="," close=")">
        ${item}
      </foreach>
    </if>
    <choose>
      <when test="order>0 and order == 1">
        ORDER BY RAND()
      </when>
      <otherwise>
        ORDER BY n.create_time DESC
      </otherwise>
    </choose>
  </select>


  <update id="batchUpdateNewsClassify" parameterType="map">
    UPDATE applet_news
    SET
      news_classify_id = #{newsClassifyId},
      update_time=NOW()
    WHERE id IN
    <foreach collection="ids" item="item" separator="," open="(" close=")" >
      ${item}
    </foreach>
  </update>

  <update id="batchUpdateCustomTagId" parameterType="map">
    UPDATE applet_news
    SET
    custom_tag_id = #{customTagId},
    update_time=NOW()
    WHERE id IN
    <foreach collection="ids" item="item" separator="," open="(" close=")" >
      ${item}
    </foreach>
  </update>

  <insert id="insertCustomTag" parameterType="com.pcloud.book.applet.entity.AppletNewsCustomTag" useGeneratedKeys="true" keyProperty="id">
    INSERT INTO applet_news_custom_tag(custom_tag, create_time) VALUES (#{customTag}, now())
  </insert>

  <update id="updateCustomTag" parameterType="com.pcloud.book.applet.entity.AppletNewsCustomTag">
    UPDATE applet_news_custom_tag SET custom_tag = #{customTag}, create_time = now()
    where id = #{id}
  </update>

  <select id="getCustomTagList" resultType="com.pcloud.book.applet.dto.AppletNewsCustomTagDTO">
    SELECT
    id customTagId,
	custom_tag customTag
    FROM
        applet_news_custom_tag
    ORDER BY
        create_time DESC, id DESC
  </select>

  <select id="customTagExist" parameterType="map" resultType="boolean">
    SELECT EXISTS (
      SELECT id
      FROM  applet_news_custom_tag
      WHERE
      custom_tag = #{customTag}
    )
  </select>

  <select id="getNewsIdListByCustomTagId" parameterType="long" resultType="long">
    SELECT id from applet_news
    WHERE custom_tag_id = #{customTagId}
    ORDER BY create_time DESC
  </select>

  <select id="getPageByNewsByTempletLabel" parameterType="map" resultType="com.pcloud.book.applet.dto.AppletNewsDTO">
    SELECT
    n.id,
    n.news_name newsName,
    n.source,
    n.news_classify_id newsClassifyId,
    n.pro_label_id proLabelId,
    n.dep_label_id depLabelId,
    n.pur_label_id purLabelId,
    n.type,
    n.digest,
    n.pic1,
    n.pic2,
    n.pic3,
    n.content,
    n.show_state showState,
    n.create_time createTime,
    n.first_classify firstClassify,
    n.second_classify secondClassify,
    n.grade_label_id gradeLabelId,
    n.subject_label_id subjectLabelId,
    n.rights_classify_id rightsClassifyId,
    n.jump_type jumpType,
    n.jump_url jumpUrl,
    n.url_number urlNumber,
    n.show_source showSource,
    n.show_link showLink
    FROM applet_news n
    WHERE 1=1
    and n.show_state = 1
    <if test="firstClassify != null">
      and n.first_classify = #{firstClassify}
    </if>
    <if test="secondClassify != null">
      and n.second_classify = #{secondClassify}
    </if>
    <if test="gradeLabelId != null">
      and n.grade_label_id = #{gradeLabelId}
    </if>
    <if test="subjectLabelId != null">
      and n.subject_label_id = #{subjectLabelId}
    </if>
    AND n.rights_classify_id IN(
    SELECT id FROM rights_setting_classify WHERE 1=1
    <if test="rightsType != null" >
      AND rights_type = #{rightsType}
    </if>
    )
    ORDER BY n.create_time DESC
  </select>

  <select id="getClassifyNewsByTempletLabel" parameterType="map" resultType="com.pcloud.book.applet.dto.AppletNewsDTO">
    SELECT
      n.id,
      n.news_name newsName,
      n.source,
      n.news_classify_id newsClassifyId,
      n.pro_label_id proLabelId,
      n.dep_label_id depLabelId,
      n.pur_label_id purLabelId,
      n.type,
      n.digest,
      n.pic1,
      n.pic2,
      n.pic3,
      n.content,
      n.show_state showState,
      n.create_time createTime,
      n.first_classify firstClassify,
      n.second_classify secondClassify,
      n.grade_label_id gradeLabelId,
      n.subject_label_id subjectLabelId,
      n.rights_classify_id rightsClassifyId,
      n.jump_type jumpType,
      n.jump_url jumpUrl,
      n.url_number urlNumber,
      n.show_source showSource,
      n.show_link showLink
    FROM
      applet_news n
        LEFT JOIN rights_setting_item_detail d ON d.serve_id = n.id
        LEFT JOIN rights_setting_item i ON d.rights_setting_item_id = i.id
        LEFT JOIN rights_setting s ON s.id = i.rights_setting_id
    WHERE
      s.rights_setting_type = 1 AND i.open_state = 1 AND i.rights_type = 'WEEK' AND i.rights_classify_id = 10 AND d.serve_type = 'NEWS'
      <if test="firstClassify != null">
        and s.first_classify = #{firstClassify}
      </if>
      <if test="secondClassify != null">
        and s.second_classify = #{secondClassify}
      </if>
      <if test="gradeLabelId != null">
        and s.grade_label_id = #{gradeLabelId}
      </if>
      <if test="subjectLabelId != null">
        and s.subject_label_id = #{subjectLabelId}
      </if>
      <if test="deepRead!=null">
        AND i.deep_read = #{deepRead}
      </if>
      <if test="easyRead!=null">
        AND i.easy_read = #{easyRead}
      </if>
      <if test="efficientRead!=null">
        AND i.efficient_read = #{efficientRead}
      </if>
    ORDER BY n.create_time DESC
  </select>

  <insert id="batchInsert" parameterType="com.pcloud.book.applet.entity.AppletNews" useGeneratedKeys="true"
          keyProperty="id">
    insert into applet_news(
    news_name, source, news_classify_id, pro_label_id, dep_label_id, pur_label_id, type, digest,
    pic1, pic2, pic3, content, show_state, create_time, update_time , first_classify, second_classify, grade_label_id,
    subject_label_id, rights_classify_id,
    jump_type, jump_url,url_number, custom_tag_id, show_source, show_link
    )
    values
    <foreach collection="list" item="item" index="index" separator=",">
      (
      #{item.newsName}, #{item.source}, #{item.newsClassifyId}, #{item.proLabelId}, #{item.depLabelId}, #{item.purLabelId}, #{item.type}, #{item.digest},
      #{item.pic1}, #{item.pic2}, #{item.pic3}, #{item.content}, #{item.showState}, NOW(), NOW(), #{item.firstClassify,jdbcType=BIGINT},
      #{item.secondClassify,jdbcType=BIGINT},
      #{item.gradeLabelId,jdbcType=BIGINT}, #{item.subjectLabelId,jdbcType=BIGINT}, #{item.rightsClassifyId,jdbcType=BIGINT},
      #{item.jumpType}, #{item.jumpUrl}, #{item.urlNumber}, #{item.customTagId}, #{item.showSource}, #{item.showLink}
      )
    </foreach>
  </insert>

  <select id="listAppletNews4WechatCount" parameterType="map" resultType="integer">
    select
    count(1)
    FROM applet_news n
    LEFT JOIN applet_news_classify c ON n.news_classify_id=c.id
    WHERE n.show_state = 1
    <if test="newsClassifyId >0">
      AND n.news_classify_id = #{newsClassifyId}
    </if>
    <if test="newsClassifyIdList != null">
      AND n.news_classify_id in
      <foreach collection="newsClassifyIdList" item="item" open="(" separator="," close=")">
        ${item}
      </foreach>
    </if>
  </select>

</mapper>
