<?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.yeejoin.amos.knowledgebase.face.orm.dao.InteractionCountMapper">

    <select id="queryTagQuoteAll" resultType="com.yeejoin.amos.knowledgebase.face.orm.entity.KnowledgeInteractionCount">
        select
            cast(TAG_SEQ as char) entityId,
            operateCount,
            t.AGENCY_CODE agencyCode
        from (
            select
                TAG_SEQ,
                count(1) operateCount
            from
                knowledge_tag_instance
            group by
                TAG_SEQ ) tmp
          left join knowledge_tag t on
            TAG_SEQ = t.SEQUENCE_NBR
    </select>

    <select id="queryTagQuotePublish" resultType="com.yeejoin.amos.knowledgebase.face.orm.entity.KnowledgeInteractionCount">
        select
            cast(TAG_SEQ as char) entityId,
            operateCount,
            t.AGENCY_CODE agencyCode
        from
            (
            select
                TAG_SEQ,
                count(1) operateCount
            from
                knowledge_tag_instance ti
            inner join knowledge_doc_content doc on
                ti.TARGET_SEQ = doc.SEQUENCE_NBR
            where
                doc.DOC_STATUS = 'PUBLISHED'
            group by
                TAG_SEQ ) tmp
        left join knowledge_tag t on
            TAG_SEQ = t.SEQUENCE_NBR
    </select>

    <delete id="deleteByEntityType" parameterType="string">
        delete from knowledge_interaction_count where ENTITY_TYPE = #{entityType}
    </delete>
</mapper>
