<?xml version="1.0" encoding="UTF-8"?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.sunxiansheng.practice.server.dao.SubjectCategoryDao"><selectid="getPrimaryCategory"resultType="com.sunxiansheng.practice.server.entity.po.PrimaryCategoryPO">
select count(distinct a.subject_id) as subjectCount,
b.parent_id as parentId
from subject_mapping a,
subject_category b,
subject_info c
where a.category_id = b.id
and a.subject_id = c.id
and a.is_deleted = 0
and b.is_deleted = 0
and c.is_deleted = 0
and c.subject_type in
<foreachcollection="subjectTypeList"item="item"open="("close=")"separator=",">
#{item}
</foreach>
group by b.parent_id
</select><selectid="selectById"resultType="com.sunxiansheng.practice.server.entity.po.CategoryPO">
select category_name as categoryName
from subject_category
where is_deleted = 0
and id = #{id}
</select><selectid="selectList"resultType="com.sunxiansheng.practice.server.entity.po.CategoryPO">
select id,
category_name as categoryName,
category_type as categoryType,
parent_id as parentId
from subject_category
where is_deleted = 0
and parent_id = #{parentId}
and category_type = #{categoryType}
</select><selectid="getPrimaryCategoryHasSubject"resultType="com.sunxiansheng.practice.server.entity.po.PrimaryCategoryPO">
select distinct parent_id as id
from subject_category a,
subject_mapping b,
subject_info c
where a.id = b.category_id
and c.id = b.subject_id
and a.is_deleted = 0
and b.is_deleted = 0
and c.is_deleted = 0
and category_type = 2
and subject_type in
<foreachcollection="subjectTypeList"item="item"open="("separator=","close=")">
#{item}
</foreach></select><selectid="getSecondCategoryByPrimaryId"resultType="com.sunxiansheng.practice.server.entity.po.SecondCategoryPO">
select distinct category_id as id,
category_name as categoryName
from subject_mapping a,
subject_category b
where a.category_id = b.id
and a.is_deleted = 0
and b.is_deleted = 0
and parent_id = #{primaryCategoryId}
</select></mapper>
2.SubjectLabelDao.xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.sunxiansheng.practice.server.dao.SubjectLabelDao"><resultMapid="SubjectLabelPOResultMap"type="com.sunxiansheng.practice.server.entity.po.SubjectLabelPO"><idcolumn="id"property="id"/><resultcolumn="label_name"property="labelName"/><resultcolumn="sort_num"property="sortNum"/><resultcolumn="category_id"property="categoryId"/><resultcolumn="created_by"property="createdBy"/><resultcolumn="created_time"property="createdTime"/><resultcolumn="update_by"property="updateBy"/><resultcolumn="update_time"property="updateTime"/><resultcolumn="is_deleted"property="isDeleted"/></resultMap><selectid="queryById"resultMap="SubjectLabelPOResultMap">
select id,
label_name,
category_id,
sort_num,
created_by,
created_time,
update_by,
is_deleted,
update_time
from subject_label
where id = #{id}
</select></mapper>
3.SubjectMappingDao.xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.sunxiansheng.practice.server.dao.SubjectMappingDao"><selectid="getLabelSubjectCount"resultType="com.sunxiansheng.practice.server.entity.po.LabelCountPO">
select count(distinct a.subject_id) as count,
a.label_id as labelId
from subject_mapping a,
subject_info b
where a.subject_id = b.id
and a.is_deleted = 0
and b.is_deleted = 0
and a.category_id = #{categoryId}
and b.subject_type in
<foreachcollection="subjectTypeList"item="item"open="("close=")"separator=",">
#{item}
</foreach>
group by a.label_id
</select><selectid="getLabelIdAndName"resultType="com.sunxiansheng.practice.server.entity.po.LabelCountPO">
select label_id as labelId,
c.label_name as labelName
from subject_mapping a,
subject_category b,
subject_label c,
subject_info d
where a.category_id = b.id
and a.label_id = c.id
and a.subject_id = d.id
and a.is_deleted = 0
and b.is_deleted = 0
and c.is_deleted = 0
and d.is_deleted = 0
and subject_type in
<foreachcollection="subjectTypeList"item="item"open="("close=")"separator=",">
#{item}
</foreach>
and a.category_id = #{categoryId}
group by label_id, label_name
</select></mapper>