<?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.DataDictItemMapper">


	<select id="getList" resultType="com.nbclass.activity.model.DataDictItem" parameterType="com.nbclass.activity.model.DataDictItem">
		SELECT * FROM data_dict_item where 1=1
		<if test="dictid != null and dictid > 0">
		    AND dictid = #{dictid}
		</if>
		order by data_dict_item.sort asc, data_dict_item.id desc
	</select>

  	<select id="checkExist" parameterType="com.nbclass.activity.model.DataDictItem" resultType="java.lang.Long">
  		<![CDATA[
  		select count(*) from data_dict_item
  		where dictid = #{dictid} and (value = #{value} or name = #{name})
  		and id <> #{id}
  		]]>
  	</select>

  	<select id="checkContentTag" parameterType="java.lang.Long" resultType="java.lang.Long">
  		select count(*) from content_tags where tid = #{id}
  	</select>

  	<select id="checkContentFrom" parameterType="java.lang.Long" resultType="java.lang.Long">
  		select count(*) from content where fromid = #{id}
  	</select>

	<select id="getDropDownBox" resultType="com.nbclass.activity.model.ContentTags">
		SELECT
			dict.id as dictId,
		    item.id as tid,
			item.`name` as tagName
		FROM
			data_dict_item item
		LEFT JOIN data_dict dict ON item.dictid = dict.id
	</select>

	<select id="getTagId" resultType="java.lang.String">
		select
			item.dictid
		from content_tags tags
		left join data_dict_item item on tags.tid = item.id
		where item.name like concat('%',#{name},'%')
	</select>

	<select id="getContentDict" resultType="java.lang.Long">
		SELECT DISTINCT
			tags.tid
		FROM
			content c
		INNER JOIN content_tags tags ON c.id = tags.cid
	</select>

</mapper>
