feat: bug修复

This commit is contained in:
2024-02-26 21:50:29 +08:00
parent 85d0b1e6c9
commit e13b3f7c2d
13 changed files with 226 additions and 27 deletions

View File

@@ -3,7 +3,9 @@ package com.landaiqing.subject.application.controller;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Preconditions;
import com.landaiqing.subject.application.convert.SubjectCategoryDTOConverter;
import com.landaiqing.subject.application.convert.SubjectLabelDTOConverter;
import com.landaiqing.subject.application.dto.SubjectCategoryDTO;
import com.landaiqing.subject.application.dto.SubjectLabelDTO;
import com.landaiqing.subject.common.entity.Result;
import com.landaiqing.subject.domain.entity.SubjectCategoryBO;
import com.landaiqing.subject.domain.service.SubjectCategoryDomainService;
@@ -12,6 +14,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;
/**
@@ -152,4 +155,37 @@ public class SubjectCategoryController {
}
}
/**
* @description: 查询分类及标签一次性
* @param: [subjectCategoryDTO]
* @return: com.landaiqing.subject.common.entity.Result<java.util.List < com.landaiqing.subject.application.dto.SubjectCategoryDTO>>
* @author landaiqing
* @date: 2024/2/26 20:43
*/
@PostMapping("/queryCategoryAndLabel")
public Result<List<SubjectCategoryDTO>> queryCategoryAndLabel(@RequestBody SubjectCategoryDTO subjectCategoryDTO) {
try {
if (log.isInfoEnabled()) {
log.info("SubjectCategoryController.queryCategoryAndLabel.dto:{}"
, JSON.toJSONString(subjectCategoryDTO));
}
Preconditions.checkNotNull(subjectCategoryDTO.getId(), "分类id不能为空");
SubjectCategoryBO subjectCategoryBO = SubjectCategoryDTOConverter.INSTANCE.
convertDtoToCategoryBO(subjectCategoryDTO);
List<SubjectCategoryBO> subjectCategoryBOList = subjectCategoryDomainService.queryCategoryAndLabel(subjectCategoryBO);
List<SubjectCategoryDTO> dtoList = new LinkedList<>();
subjectCategoryBOList.forEach(bo -> {
SubjectCategoryDTO dto = SubjectCategoryDTOConverter.INSTANCE.convertBoToCategoryDTO(bo);
List<SubjectLabelDTO> labelDTOList = SubjectLabelDTOConverter.INSTANCE.convertBOToLabelDTOList(bo.getLabelBOList());
dto.setLabelDTOList(labelDTOList);
dtoList.add(dto);
});
return Result.ok(dtoList);
} catch (Exception e) {
log.error("SubjectCategoryController.queryCategoryAndLabel.error:{}", e.getMessage(), e);
return Result.fail("查询失败");
}
}
}

View File

@@ -20,6 +20,7 @@ public interface SubjectCategoryDTOConverter {
SubjectCategoryBO convertDtoToCategoryBO(SubjectCategoryDTO subjectCategoryDTO);
SubjectCategoryDTO convertBoToCategoryDTO(SubjectCategoryBO subjectCategoryBO);
List<SubjectCategoryDTO> convertBoToCategoryDTOList(List<SubjectCategoryBO> subjectCategoryDTO);
}

View File

@@ -42,7 +42,10 @@ public class SubjectCategoryDTO implements Serializable {
* 数量
*/
private Integer count;
/**
* 标签信息
*/
private List<SubjectLabelDTO> labelDTOList;
}

View File

@@ -4,6 +4,7 @@ import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* 题目分类(SubjectCategory)实体类
@@ -33,7 +34,15 @@ public class SubjectCategoryBO implements Serializable {
* 父级id
*/
private Long parentId;
/**
* 数量
*/
private Integer count;
/**
* 变迁bo数量
*/
private List<SubjectLabelBO> labelBOList;
}

View File

@@ -35,4 +35,12 @@ public interface SubjectCategoryDomainService {
* @date: 2024/2/14 14:58
*/
Boolean delete(SubjectCategoryBO subjectCategoryBO);
/**
* @description: 查询及标签
* @param: [subjectCategoryBO]
* @return: java.util.List<com.landaiqing.subject.domain.entity.SubjectCategoryBO>
* @author landaiqing
* @date: 2024/2/26 21:14
*/
List<SubjectCategoryBO> queryCategoryAndLabel(SubjectCategoryBO subjectCategoryBO);
}

View File

@@ -5,14 +5,23 @@ import com.landaiqing.subject.common.enums.CategoryTypeEnum;
import com.landaiqing.subject.common.enums.IsDeletedFlagEnum;
import com.landaiqing.subject.domain.convert.SubjectCategoryConverter;
import com.landaiqing.subject.domain.entity.SubjectCategoryBO;
import com.landaiqing.subject.domain.entity.SubjectLabelBO;
import com.landaiqing.subject.domain.service.SubjectCategoryDomainService;
import com.landaiqing.subject.infra.basic.entity.SubjectCategory;
import com.landaiqing.subject.infra.basic.entity.SubjectLabel;
import com.landaiqing.subject.infra.basic.entity.SubjectMapping;
import com.landaiqing.subject.infra.basic.service.SubjectCategoryService;
import com.landaiqing.subject.infra.basic.service.SubjectLabelService;
import com.landaiqing.subject.infra.basic.service.SubjectMappingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service
@Slf4j
@@ -20,6 +29,11 @@ public class SubjectCategoryDomainServiceImpl implements SubjectCategoryDomainSe
@Resource
private SubjectCategoryService subjectCategoryService;
@Resource
private SubjectMappingService subjectMappingService;
@Resource
private SubjectLabelService subjectLabelService;
/**
* @description: 新增分类
* @param: [subjectCategoryBO]
@@ -56,6 +70,10 @@ public class SubjectCategoryDomainServiceImpl implements SubjectCategoryDomainSe
if (log.isInfoEnabled()) {
log.info("SubjectCategoryController.queryPrimaryCategory.boList:{}", JSON.toJSONString(boList));
}
boList.forEach(bo -> {
Integer subjectCount = subjectCategoryService.querySubjectCount(bo.getId());
bo.setCount(subjectCount);
});
return boList;
}
@@ -87,4 +105,49 @@ public class SubjectCategoryDomainServiceImpl implements SubjectCategoryDomainSe
int count = subjectCategoryService.update(subjectCategory);
return count > 0;
}
/**
* @description: 查询分类及标签
* @param: [subjectCategoryBO]
* @return: java.util.List<com.landaiqing.subject.domain.entity.SubjectCategoryBO>
* @author landaiqing
* @date: 2024/2/26 20:46
*/
@Override
public List<SubjectCategoryBO> queryCategoryAndLabel(SubjectCategoryBO subjectCategoryBO) {
// 查询当前分类下的所以的分类
SubjectCategory subjectCategory = new SubjectCategory();
subjectCategory.setParentId(subjectCategoryBO.getId());
subjectCategory.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
List<SubjectCategory> subjectCategoryList = subjectCategoryService.queryCategory(subjectCategory);
if (log.isInfoEnabled()) {
log.info("SubjectCategoryController.queryCategoryAndLabel.subjectCategoryList:{}"
, JSON.toJSONString(subjectCategoryList));
}
List<SubjectCategoryBO> categoryBOList = SubjectCategoryConverter.INSTANCE.convertBoToCategory(subjectCategoryList);
// 一次获取标签信息
categoryBOList.forEach(category -> {
SubjectMapping subjectMapping = new SubjectMapping();
subjectMapping.setCategoryId(category.getId());
List<SubjectMapping> mappingList = subjectMappingService.queryLabelId(subjectMapping);
if (CollectionUtils.isEmpty(mappingList)) {
return;
}
List<Long> labelIdList = mappingList.stream().map(SubjectMapping::getLabelId).collect(Collectors.toList());
List<SubjectLabel> subjectLabelList = subjectLabelService.batchQueryById(labelIdList);
List<SubjectLabelBO> labelBOList = new LinkedList<>();
subjectLabelList.forEach(label -> {
SubjectLabelBO subjectLabelBO = new SubjectLabelBO();
subjectLabelBO.setId(label.getId());
subjectLabelBO.setLabelName(label.getLabelName());
subjectLabelBO.setCategoryId(label.getCategoryId());
subjectLabelBO.setSortNum(label.getSortNum());
labelBOList.add(subjectLabelBO);
});
category.setLabelBOList(labelBOList);
});
return categoryBOList;
}
}

View File

@@ -70,5 +70,7 @@ public interface SubjectCategoryDao {
int deleteById(Long id);
List<SubjectCategory> queryCategory(SubjectCategory subjectCategory);
Integer querySubjectCount(Long id);
}

View File

@@ -49,4 +49,6 @@ public interface SubjectCategoryService {
* @return
*/
List<SubjectCategory> queryCategory(SubjectCategory subjectCategory);
Integer querySubjectCount(Long id);
}

View File

@@ -75,4 +75,9 @@ public class SubjectCategoryServiceImpl implements SubjectCategoryService {
public List<SubjectCategory> queryCategory(SubjectCategory subjectCategory) {
return this.subjectCategoryDao.queryCategory(subjectCategory);
}
@Override
public Integer querySubjectCount(Long id) {
return this.subjectCategoryDao.querySubjectCount(id);
}
}

View File

@@ -105,6 +105,13 @@
</if>
</where>
</select>
<select id="querySubjectCount" resultType="java.lang.Integer">
select count(distinct subject_id)
from subject_mapping a,
subject_label b
where a.label_id=b.id
and b.category_id=#{id}
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">