<?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="jnpf.culture.mapper.CultureTextSettingMapper" >

    <!-- 判定标题+内容是否重复 -->
    <select id="getDistinctCount" resultType="java.lang.Integer">
        select count(1)
        from ftb_culture_text_setting
        where F_DeleteMark = 0
        and F_CultureTitle = #{cultureTitle}
        and F_CultureContent = #{cultureContent}
        <if test="null != id and '' != id">
            and F_Id != #{id}
        </if>
    </select>
    <!-- 查询文字配置列表 -->
    <select id="getCultureTextSettingList" resultType="jnpf.model.culture.vo.CultureTextSettingVo">
        select t.F_Id id, t.F_CultureTitle cultureTitle, t.F_CultureContent cultureContent, count(r.F_Id) clockInTimes,
               t.F_LastModifyUserId lastModifyUserId, t.F_LastModifyTime lastModifyTime, t.F_CreatorTime creatorTime
        from ftb_culture_text_setting t
        left join ftb_culture_clock_in r on r.F_ContentId = t.F_Id and r.F_DeleteMark = 0
        where t.F_DeleteMark = 0 and (
          instr(t.F_CultureTitle, #{keyword}) > 0 or instr(t.F_CultureContent, #{keyword}) > 0
        )
        group by t.F_Id, t.F_CultureTitle, t.F_CultureContent, t.F_LastModifyUserId, t.F_LastModifyTime, t.F_CreatorTime
        order by t.F_LastModifyTime desc, t.F_Id asc
    </select>
    <!-- 查询数据库存在的配置的index -->
    <select id="getDistinctCountBatch" resultType="java.lang.Integer">
        select t.idx
        from (
        <foreach collection="list" item="item" separator=" UNION ALL ">
            select #{item.index} as idx,
            #{item.cultureTitle} as cultureTitle,
            #{item.cultureContent} as cultureContent
        </foreach>
        ) t
        join ftb_culture_text_setting c on t.cultureTitle = c.F_CultureTitle and t.cultureContent = c.F_CultureContent and c.F_DeleteMark = 0
    </select>
    <!-- 查询所有可用的id -->
    <select id="selectAllIds" resultType="java.lang.String">
        select F_Id from ftb_culture_text_setting where F_DeleteMark = 0
    </select>
    <!-- 查询时段内被删除的ids -->
    <select id="getDelIdsByDate" resultType="java.lang.String">
        select F_Id from ftb_culture_text_setting
        where F_DeleteTime is not null
        and F_DeleteTime <![CDATA[ >= ]]> #{startTime}
        and F_DeleteTime <![CDATA[ < ]]> #{endTime}
    </select>
</mapper>