<?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.cslg.ppa.mapper.ArticleInfoMapper">

    <select id="selectArticleInfoList" resultType="com.cslg.ppa.vo.SelectArticleInfoVO">
        select ai.id as articleId,
               ai.title,
               ai.digest,
               ai.category_id,
               ai.source_id,
               ai.public_time,
               ai.create_time,
               ai.article_url,
               ai.wx_article_icon,
               ca.name as categoryName,
               si.source_name,
               si.source_type
        from article_info ai
        left join category ca on ca.id = ai.category_id
        left join source_info si on si.id = ai.source_id
        <where>
            <if test="vo.key != null and vo.key != ''">
                ai.title like concat('%',#{vo.key},'%')
            </if>
            <if test="vo.categoryId != null">
                and ai.category_id = #{vo.categoryId}
            </if>
            <if test="vo.sourceName != null and vo.sourceName != ''">
                and si.source_name like concat('%',#{vo.sourceName},'%')
            </if>
            <if test="vo.beginTime != null">
                and ai.public_time &gt;= #{vo.beginTime}
            </if>
            <if test="vo.endTime != null">
                and ai.public_time &lt;= #{vo.endTime}
            </if>
        </where>
        order by ai.public_time desc,ai.id desc
        <if test="vo.pageNum != null and vo.pageSize != null">
            limit
            ${(vo.pageNum -1) * vo.pageSize},${vo.pageSize}
        </if>
    </select>

    <select id="selectArticleInfoCount" resultType="java.lang.Long">
        select count(*)
        from article_info ai
        left join category ca on ca.id = ai.category_id
        left join source_info si on si.id = ai.source_id
        <where>
            <if test="vo.key != null and vo.key != ''">
                ai.title like concat('%',#{vo.key},'%')
            </if>
            <if test="vo.categoryId != null">
                and ai.category_id = #{vo.categoryId}
            </if>
            <if test="vo.sourceName != null and vo.sourceName != ''">
                and si.source_name like concat('%',#{vo.sourceName},'%')
            </if>
            <if test="vo.beginTime != null">
                and ai.public_time &gt;= #{vo.beginTime}
            </if>
            <if test="vo.endTime != null">
                and ai.public_time &lt;= #{vo.endTime}
            </if>
        </where>
    </select>


    <select id="selectArticleList" resultType="com.cslg.ppa.vo.OneClickExportVO">
        select ai.id as articleId,
        ai.title,
        ai.digest,
        ai.category_id,
        ai.public_time,
        ai.article_url,
        ca.name as categoryName
        from article_info ai
        left join category ca on ca.id = ai.category_id
        <where>
            ai.category_id in (1,2,3,4,5)
            <if test="vo.beginTime != null">
                and ai.public_time &gt;= #{vo.beginTime}
            </if>
            <if test="vo.endTime != null">
                and ai.public_time &lt;= #{vo.endTime}
            </if>
        </where>
        order by ai.public_time desc,ai.id desc
    </select>

</mapper>