<?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.sunxiansheng.practice.server.dao.SubjectCategoryDao">
<select id="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
<foreach collection="subjectTypeList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
group by b.parent_id
</select>
<select id="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>
<select id="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>
<select id="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
<foreach collection="subjectTypeList" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="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>
<?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.sunxiansheng.practice.server.dao.SubjectMappingDao">
<select id="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
<foreach collection="subjectTypeList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
group by a.label_id
</select>
<select id="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
<foreach collection="subjectTypeList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
and a.category_id = #{categoryId}
group by label_id, label_name
</select>
</mapper>
5.entity
1.dto
CategoryDTO.java
java复制代码
package com.sunxiansheng.practice.server.entity.dto;
import lombok.Data;
import java.util.List;
/**
* Description:
* @Author sun
* @Create 2024/6/25 17:15
* @Version 1.0
*/
@Data
public class CategoryDTO {
private Long id;
private List<Integer> subjectTypeList;
private Integer categoryType;
private Long parentId;
}
2.po
1.CategoryPO.java
java复制代码
package com.sunxiansheng.practice.server.entity.po;
import lombok.Data;
/**
* Description: 大类PO,对应DB中的字段
* @Author sun
* @Create 2024/6/25 17:28
* @Version 1.0
*/
@Data
public class CategoryPO {
private Long id;
private String categoryName;
private Integer categoryType;
private Long parentId;
}
2.LabelCountPO.java
java复制代码
package com.sunxiansheng.practice.server.entity.po;
import lombok.Data;
/**
* Description:
* @Author sun
* @Create 2024/6/26 14:40
* @Version 1.0
*/
@Data
public class LabelCountPO {
private Long labelId;
private Integer count;
private String labelName;
}
3.PrimaryCategoryPO.java
java复制代码
package com.sunxiansheng.practice.server.entity.po;
import lombok.Data;
/**
* Description: 大类PO,对应DB中的字段
* @Author sun
* @Create 2024/6/25 17:28
* @Version 1.0
*/
@Data
public class PrimaryCategoryPO {
private Long id;
private String categoryName;
private Integer categoryType;
private Long parentId;
}
4.SecondCategoryPO.java
java复制代码
package com.sunxiansheng.practice.server.entity.po;
import lombok.Data;
/**
* Description:
* @Author sun
* @Create 2024/6/26 17:46
* @Version 1.0
*/
@Data
public class SecondCategoryPO {
private String categoryName;
private Long id;
}