feat: 题目标签开发
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.landaiqing.subject.domain.convert;
|
||||
|
||||
import com.landaiqing.subject.domain.entity.SubjectCategoryBO;
|
||||
import com.landaiqing.subject.domain.entity.SubjectLabelBO;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectCategory;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectLabel;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SubjectLabelConverter {
|
||||
SubjectLabelConverter INSTANCE = Mappers.getMapper(SubjectLabelConverter.class);
|
||||
|
||||
SubjectLabel convertBoToLabel(SubjectLabelBO subjectLabelBO);
|
||||
List<SubjectLabelBO> convertLabelToBoList(List<SubjectLabel> subjectLabelList);
|
||||
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
package com.landaiqing.subject.domain.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 题目标签Bo
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2024-02-14 17:08:06
|
||||
*/
|
||||
@Data
|
||||
public class SubjectLabelBO implements Serializable {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 分类id
|
||||
*/
|
||||
private Long categoryId;
|
||||
/**
|
||||
* 标签分类
|
||||
*/
|
||||
private String labelName;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sortNum;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,34 @@
|
||||
package com.landaiqing.subject.domain.service;
|
||||
|
||||
import com.landaiqing.subject.domain.entity.SubjectLabelBO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @description: 题目标签领域服务
|
||||
*
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/14 17:22
|
||||
*/
|
||||
public interface SubjectLabelDomainService {
|
||||
/**
|
||||
* 新增标签
|
||||
*/
|
||||
Boolean add(SubjectLabelBO subjectLabelBO);
|
||||
|
||||
/**
|
||||
* 更新标签
|
||||
*/
|
||||
Boolean update(SubjectLabelBO subjectLabelBO);
|
||||
|
||||
/**
|
||||
* 删除标签
|
||||
*/
|
||||
Boolean delete(SubjectLabelBO subjectLabelBO);
|
||||
|
||||
/**
|
||||
* 查询分类下标签
|
||||
*/
|
||||
List<SubjectLabelBO> queryLabelByCategoryId(SubjectLabelBO subjectLabelBO);
|
||||
}
|
@@ -0,0 +1,114 @@
|
||||
package com.landaiqing.subject.domain.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.landaiqing.subject.common.enums.IsDeletedFlagEnum;
|
||||
import com.landaiqing.subject.domain.convert.SubjectLabelConverter;
|
||||
import com.landaiqing.subject.domain.entity.SubjectLabelBO;
|
||||
import com.landaiqing.subject.domain.service.SubjectLabelDomainService;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectLabel;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectMapping;
|
||||
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.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SubjectLabelDomainServiceImpl implements SubjectLabelDomainService {
|
||||
@Resource
|
||||
private SubjectLabelService subjectLabelService;
|
||||
@Resource
|
||||
private SubjectMappingService subjectMappingService;
|
||||
|
||||
/**
|
||||
* @description: 新增标签
|
||||
* @param: [subjectLabelBO]
|
||||
* @return: java.lang.Boolean
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/14 17:27
|
||||
*/
|
||||
@Override
|
||||
public Boolean add(SubjectLabelBO subjectLabelBO) {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("SubjectLabelDomainServiceImpl.add.bo:{}", JSON.toJSONString(subjectLabelBO));
|
||||
}
|
||||
SubjectLabel subjectLabel = SubjectLabelConverter.INSTANCE
|
||||
.convertBoToLabel(subjectLabelBO);
|
||||
subjectLabel.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||
int count = subjectLabelService.insert(subjectLabel);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 更新标签
|
||||
* @param: [subjectLabelBO]
|
||||
* @return: java.lang.Boolean
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/14 18:33
|
||||
*/
|
||||
@Override
|
||||
public Boolean update(SubjectLabelBO subjectLabelBO) {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("SubjectLabelDomainServiceImpl.update.bo:{}", JSON.toJSONString(subjectLabelBO));
|
||||
}
|
||||
SubjectLabel subjectLabel = SubjectLabelConverter.INSTANCE
|
||||
.convertBoToLabel(subjectLabelBO);
|
||||
int count = subjectLabelService.update(subjectLabel);
|
||||
return count > 0;
|
||||
}
|
||||
/**
|
||||
* @description: 删除标签
|
||||
* @param: [subjectLabelBO]
|
||||
* @return: java.lang.Boolean
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/14 18:58
|
||||
*/
|
||||
@Override
|
||||
public Boolean delete(SubjectLabelBO subjectLabelBO) {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("SubjectLabelDomainServiceImpl.update.bo:{}", JSON.toJSONString(subjectLabelBO));
|
||||
}
|
||||
SubjectLabel subjectLabel = SubjectLabelConverter.INSTANCE
|
||||
.convertBoToLabel(subjectLabelBO);
|
||||
subjectLabel.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
|
||||
int count = subjectLabelService.update(subjectLabel);
|
||||
return count > 0;
|
||||
}
|
||||
/**
|
||||
* @description: 查询分类下的标签
|
||||
* @param: [subjectLabelBO]
|
||||
* @return: java.util.List<com.landaiqing.subject.domain.entity.SubjectLabelBO>
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/14 19:08
|
||||
*/
|
||||
@Override
|
||||
public List<SubjectLabelBO> queryLabelByCategoryId(SubjectLabelBO subjectLabelBO) {
|
||||
Long categoryId = subjectLabelBO.getCategoryId();
|
||||
SubjectMapping subjectMapping=new SubjectMapping();
|
||||
subjectMapping.setCategoryId(categoryId);
|
||||
subjectMapping.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||
List<SubjectMapping> mappingList= subjectMappingService.queryLabelId(subjectMapping);
|
||||
if(CollectionUtils.isEmpty(mappingList)){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Long> labelIdList = mappingList.stream().map(SubjectMapping::getLabelId).collect(Collectors.toList());
|
||||
List<SubjectLabel> labelList= subjectLabelService.batchQueryById(labelIdList);
|
||||
List<SubjectLabelBO> boList=new LinkedList<>();
|
||||
labelList.forEach(label->{
|
||||
SubjectLabelBO bo=new SubjectLabelBO();
|
||||
bo.setId(label.getId());
|
||||
bo.setLabelName(label.getLabelName());
|
||||
bo.setCategoryId(categoryId);
|
||||
bo.setSortNum(label.getSortNum());
|
||||
boList.add(bo);
|
||||
});
|
||||
return boList;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user