<?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.nbclass.activity.mapper.CaseTypeMapper">

    <resultMap id="BaseResultMap" type="com.nbclass.activity.model.Content">
        <id column="id" property="id"/>
        <result column="title" property="title"/>
        <result column="praiseno" property="praiseno"/>
        <result column="listicon" property="listicon"/>
        <result column="comments" property="comments"/>
        <result column="userTotal" property="userTotal"/>
        <result column="TotalScore" property="TotalScore"/>

        <!--<collection property="tagList" ofType="com.nbclass.activity.model.ContentTags" column="id" select="getTagList">
            <id column="id" property="id"/>
            <result column="tagName" property="tagName"/>
        </collection>-->

    </resultMap>

    <select id="getTypeCase" resultType="com.nbclass.activity.model.DataDictItem">
        SELECT
        id,
        dictid,
        NAME
        FROM
        data_dict_item
        WHERE
        1 = 1
        <if test="dictId!=null and dictId!=0">
            and dictid = #{dictId}
        </if>
    </select>

    <select id="getDictionariesType" resultType="com.nbclass.activity.model.DataDict">
        select id,name from data_dict
    </select>

<!--    <select id="getSearchCase" resultType="com.nbclass.activity.model.Content">
        SELECT
        c.id,
        c.title,
        c.praiseno,
        c.listicon,
        item.name
        FROM
        content c
        LEFT JOIN content_tags t ON c.id = t.cid
        LEFT JOIN data_dict_item item ON t.tid = item.id
        where 1=1
        <if test="parameter!=null and parameter!=''">
            and (item.name like CONCAT('%',#{parameter},'%') or c.id = #{parameter} or c.title like CONCAT('%',#{parameter},'%'))
        </if>
        <if test="dictItemId!=null and dictItemId!=0">
            and item.id = #{dictItemId}
        </if>
        order by c.createtime desc
    </select>-->

    <select id="getListCase" resultMap="BaseResultMap">
        SELECT
            COUNT(s.content_id) as userTotal,
            IFNULL(SUM(s.score),0) AS TotalScore
        FROM
            content c
        LEFT JOIN scoring_table s ON c.id = s.content_id
        WHERE
            c.RELEASE = 2 and c.id = #{contentId}
        ORDER BY
            c.createtime DESC
    </select>


    <select id="getTagList" resultType="com.nbclass.activity.model.ContentTags">
        SELECT
            dict.id,
            item.`name` AS tagName
        FROM
            content_tags tags
                LEFT JOIN data_dict_item item ON tags.tid = item.id
                INNER JOIN data_dict dict ON dict.id = item.dictid
                AND dict.id IN ( 23, 24)
        WHERE
            tags.cid = #{id}
    </select>

    <select id="getContentTags" resultType="com.nbclass.activity.model.ContentTags">
        SELECT
            item.id,
            item.name as tagName
        FROM
            content_tags ts
        LEFT JOIN data_dict_item item ON ts.tid = item.id
        WHERE
            ts.cid = #{contentId}
    </select>

</mapper>
