feat: 题目模块开发
This commit is contained in:
@@ -8,6 +8,18 @@
|
||||
</parent>
|
||||
|
||||
<artifactId>jc-club-domain</artifactId>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>jc-club-domain</name>
|
||||
|
@@ -0,0 +1,15 @@
|
||||
package com.landaiqing.subject.domain.convert;
|
||||
|
||||
import com.landaiqing.subject.domain.entity.SubjectInfoBO;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectBrief;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface BriefSubjectConverter {
|
||||
|
||||
BriefSubjectConverter INSTANCE = Mappers.getMapper(BriefSubjectConverter.class);
|
||||
|
||||
SubjectBrief convertBoToEntity(SubjectInfoBO subjectInfoBO);
|
||||
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package com.landaiqing.subject.domain.convert;
|
||||
|
||||
import com.landaiqing.subject.domain.entity.SubjectAnswerBO;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectJudge;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface JudgeSubjectConverter {
|
||||
|
||||
JudgeSubjectConverter INSTANCE = Mappers.getMapper(JudgeSubjectConverter.class);
|
||||
|
||||
List<SubjectAnswerBO> convertEntityToBoList(List<SubjectJudge> subjectJudgeList);
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package com.landaiqing.subject.domain.convert;
|
||||
|
||||
import com.landaiqing.subject.domain.entity.SubjectAnswerBO;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectMultiple;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface MultipleSubjectConverter {
|
||||
|
||||
MultipleSubjectConverter INSTANCE = Mappers.getMapper(MultipleSubjectConverter.class);
|
||||
|
||||
SubjectMultiple convertBoToEntity(SubjectAnswerBO subjectAnswerBO);
|
||||
|
||||
List<SubjectAnswerBO> convertEntityToBoList(List<SubjectMultiple> subjectMultipleList);
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package com.landaiqing.subject.domain.convert;
|
||||
|
||||
import com.landaiqing.subject.domain.entity.SubjectAnswerBO;
|
||||
import com.landaiqing.subject.domain.entity.SubjectInfoBO;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectInfo;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectRadio;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface RadioSubjectConverter {
|
||||
RadioSubjectConverter INSTANCE = Mappers.getMapper(RadioSubjectConverter.class);
|
||||
|
||||
SubjectRadio convertBoToEntity(SubjectAnswerBO subjectAnswerBO);
|
||||
List<SubjectAnswerBO> convertEntityToBoList(List<SubjectRadio> subjectRadioList);
|
||||
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package com.landaiqing.subject.domain.convert;
|
||||
|
||||
import com.landaiqing.subject.domain.entity.SubjectCategoryBO;
|
||||
import com.landaiqing.subject.domain.entity.SubjectInfoBO;
|
||||
import com.landaiqing.subject.domain.entity.SubjectOptionBO;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectCategory;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectInfo;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SubjectInfoConverter {
|
||||
SubjectInfoConverter INSTANCE = Mappers.getMapper(SubjectInfoConverter.class);
|
||||
|
||||
SubjectInfo convertBoToInfo(SubjectInfoBO subjectInfoBO);
|
||||
SubjectInfoBO convertOptionToBO(SubjectOptionBO subjectOptionBO);
|
||||
SubjectInfoBO convertOptionAndInfoToBO(SubjectOptionBO subjectOptionBO,SubjectInfo subjectInfo);
|
||||
List<SubjectInfoBO> convertListInfoBoToBO(List<SubjectInfo> subjectInfoList);
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package com.landaiqing.subject.domain.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 题目答案DTO
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2024-02-14 16:59:04
|
||||
*/
|
||||
@Data
|
||||
public class SubjectAnswerBO implements Serializable {
|
||||
/**
|
||||
* 答案选项标识
|
||||
*/
|
||||
private Integer optionType;
|
||||
/**
|
||||
* 答案
|
||||
*/
|
||||
private String optionContent;
|
||||
/**
|
||||
* 是否正确
|
||||
*/
|
||||
private Integer isCorrect;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,81 @@
|
||||
package com.landaiqing.subject.domain.entity;
|
||||
|
||||
import com.landaiqing.subject.common.entity.PageInfo;
|
||||
import com.landaiqing.subject.common.entity.PageResult;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 题目BO
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2024-02-14 16:59:04
|
||||
*/
|
||||
@Data
|
||||
public class SubjectInfoBO extends PageInfo implements Serializable {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 题目名称
|
||||
*/
|
||||
private String subjectName;
|
||||
/**
|
||||
* 题目难度
|
||||
*/
|
||||
private Integer subjectDifficult;
|
||||
/**
|
||||
* 出题人名
|
||||
*/
|
||||
private String settleName;
|
||||
/**
|
||||
* 题目类型 1单选 2多选 3判断 4简答
|
||||
*/
|
||||
private Integer subjectType;
|
||||
/**
|
||||
* 题目分数
|
||||
*/
|
||||
private Integer subjectScore;
|
||||
/**
|
||||
* 题目解析
|
||||
*/
|
||||
private String subjectParse;
|
||||
|
||||
private Integer isDeleted;
|
||||
|
||||
/**
|
||||
* 题目答案
|
||||
*/
|
||||
private String subjectAnswer;
|
||||
|
||||
/**
|
||||
* 分类id
|
||||
*/
|
||||
private List<Integer> categoryIds;
|
||||
|
||||
/**
|
||||
* 标签名称
|
||||
*/
|
||||
private List<String> labelName;
|
||||
|
||||
/**
|
||||
* 标签id
|
||||
*/
|
||||
private List<Integer> labelIds;
|
||||
/**
|
||||
* 答案选项
|
||||
*/
|
||||
private List<SubjectAnswerBO> optionList;
|
||||
|
||||
|
||||
private Long categoryId;
|
||||
private Long labelId;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,28 @@
|
||||
package com.landaiqing.subject.domain.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 题目dto
|
||||
*
|
||||
* @author: ChickenWing
|
||||
* @date: 2023/10/5
|
||||
*/
|
||||
@Data
|
||||
public class SubjectOptionBO implements Serializable {
|
||||
|
||||
/**
|
||||
* 题目答案
|
||||
*/
|
||||
private String subjectAnswer;
|
||||
|
||||
/**
|
||||
* 答案选项
|
||||
*/
|
||||
private List<SubjectAnswerBO> optionList;
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,50 @@
|
||||
package com.landaiqing.subject.domain.handler.subject;
|
||||
|
||||
import com.landaiqing.subject.common.enums.IsDeletedFlagEnum;
|
||||
import com.landaiqing.subject.common.enums.SubjectInfoTypeEnum;
|
||||
import com.landaiqing.subject.domain.convert.BriefSubjectConverter;
|
||||
import com.landaiqing.subject.domain.entity.SubjectInfoBO;
|
||||
import com.landaiqing.subject.domain.entity.SubjectOptionBO;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectBrief;
|
||||
import com.landaiqing.subject.infra.basic.service.SubjectBriefService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @Classname RadioTypeHandler
|
||||
* @BelongsProject: jc-club
|
||||
* @BelongsPackage: com.landaiqing.subject.domain.handler.subject
|
||||
* @Author: landaiqing
|
||||
* @CreateTime: 2024-02-15 15:59
|
||||
* @Description: 简答题目的策略类
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Component
|
||||
public class BriefTypeHandler implements SubjectTypeHandler {
|
||||
|
||||
@Resource
|
||||
private SubjectBriefService subjectBriefService;
|
||||
@Override
|
||||
public SubjectInfoTypeEnum getHandlerType() {
|
||||
return SubjectInfoTypeEnum.BRIEF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(SubjectInfoBO subjectInfoBO) {
|
||||
//简答题目的插入
|
||||
SubjectBrief subjectBrief = BriefSubjectConverter.INSTANCE.convertBoToEntity(subjectInfoBO);
|
||||
subjectBrief.setSubjectId(subjectInfoBO.getId().intValue());
|
||||
subjectBrief.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||
subjectBriefService.insert(subjectBrief);
|
||||
}
|
||||
@Override
|
||||
public SubjectOptionBO query(int subjectId) {
|
||||
SubjectBrief subjectBrief = new SubjectBrief();
|
||||
subjectBrief.setSubjectId(subjectId);
|
||||
SubjectBrief result = subjectBriefService.queryByCondition(subjectBrief);
|
||||
SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
|
||||
subjectOptionBO.setSubjectAnswer(result.getSubjectAnswer());
|
||||
return subjectOptionBO;
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
package com.landaiqing.subject.domain.handler.subject;
|
||||
|
||||
import com.landaiqing.subject.common.enums.IsDeletedFlagEnum;
|
||||
import com.landaiqing.subject.common.enums.SubjectInfoTypeEnum;
|
||||
import com.landaiqing.subject.domain.convert.JudgeSubjectConverter;
|
||||
import com.landaiqing.subject.domain.entity.SubjectAnswerBO;
|
||||
import com.landaiqing.subject.domain.entity.SubjectInfoBO;
|
||||
import com.landaiqing.subject.domain.entity.SubjectOptionBO;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectJudge;
|
||||
import com.landaiqing.subject.infra.basic.service.SubjectJudgeService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @Classname RadioTypeHandler
|
||||
* @BelongsProject: jc-club
|
||||
* @BelongsPackage: com.landaiqing.subject.domain.handler.subject
|
||||
* @Author: landaiqing
|
||||
* @CreateTime: 2024-02-15 15:59
|
||||
* @Description: 判断题目的策略类
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Component
|
||||
public class JudgeTypeHandler implements SubjectTypeHandler {
|
||||
|
||||
@Resource
|
||||
private SubjectJudgeService subjectJudgeService;
|
||||
@Override
|
||||
public SubjectInfoTypeEnum getHandlerType() {
|
||||
return SubjectInfoTypeEnum.JUDGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(SubjectInfoBO subjectInfoBO) {
|
||||
//判断题目的插入
|
||||
SubjectJudge subjectJudge = new SubjectJudge();
|
||||
SubjectAnswerBO subjectAnswerBO = subjectInfoBO.getOptionList().get(0);
|
||||
subjectJudge.setSubjectId(subjectInfoBO.getId());
|
||||
subjectJudge.setIsCorrect(subjectAnswerBO.getIsCorrect());
|
||||
subjectJudge.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||
subjectJudgeService.insert(subjectJudge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubjectOptionBO query(int subjectId) {
|
||||
SubjectJudge subjectJudge = new SubjectJudge();
|
||||
subjectJudge.setSubjectId((long) subjectId);
|
||||
List<SubjectJudge> result = subjectJudgeService.queryByCondition(subjectJudge);
|
||||
List<SubjectAnswerBO> subjectAnswerBOList = JudgeSubjectConverter.INSTANCE.convertEntityToBoList(result);
|
||||
SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
|
||||
subjectOptionBO.setOptionList(subjectAnswerBOList);
|
||||
return subjectOptionBO;
|
||||
}
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
package com.landaiqing.subject.domain.handler.subject;
|
||||
|
||||
import com.landaiqing.subject.common.enums.IsDeletedFlagEnum;
|
||||
import com.landaiqing.subject.common.enums.SubjectInfoTypeEnum;
|
||||
import com.landaiqing.subject.domain.convert.MultipleSubjectConverter;
|
||||
import com.landaiqing.subject.domain.entity.SubjectAnswerBO;
|
||||
import com.landaiqing.subject.domain.entity.SubjectInfoBO;
|
||||
import com.landaiqing.subject.domain.entity.SubjectOptionBO;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectMultiple;
|
||||
import com.landaiqing.subject.infra.basic.service.SubjectMultipleService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Classname RadioTypeHandler
|
||||
* @BelongsProject: jc-club
|
||||
* @BelongsPackage: com.landaiqing.subject.domain.handler.subject
|
||||
* @Author: landaiqing
|
||||
* @CreateTime: 2024-02-15 15:59
|
||||
* @Description: 多选题目的策略类
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Component
|
||||
public class MultipleTypeHandler implements SubjectTypeHandler {
|
||||
|
||||
@Resource
|
||||
private SubjectMultipleService subjectMultipleService;
|
||||
@Override
|
||||
public SubjectInfoTypeEnum getHandlerType() {
|
||||
return SubjectInfoTypeEnum.MULTIPLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(SubjectInfoBO subjectInfoBO) {
|
||||
//多选题目的插入
|
||||
List<SubjectMultiple> subjectMultipleList = new LinkedList<>();
|
||||
subjectInfoBO.getOptionList().forEach(option -> {
|
||||
SubjectMultiple subjectMultiple = MultipleSubjectConverter.INSTANCE.convertBoToEntity(option);
|
||||
subjectMultiple.setSubjectId(subjectInfoBO.getId());
|
||||
subjectMultiple.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||
subjectMultipleList.add(subjectMultiple);
|
||||
});
|
||||
subjectMultipleService.batchInsert(subjectMultipleList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubjectOptionBO query(int subjectId) {
|
||||
SubjectMultiple subjectMultiple = new SubjectMultiple();
|
||||
subjectMultiple.setSubjectId(Long.valueOf(subjectId));
|
||||
List<SubjectMultiple> result = subjectMultipleService.queryByCondition(subjectMultiple);
|
||||
List<SubjectAnswerBO> subjectAnswerBOList = MultipleSubjectConverter.INSTANCE.convertEntityToBoList(result);
|
||||
SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
|
||||
subjectOptionBO.setOptionList(subjectAnswerBOList);
|
||||
return subjectOptionBO;
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
package com.landaiqing.subject.domain.handler.subject;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.landaiqing.subject.common.enums.IsDeletedFlagEnum;
|
||||
import com.landaiqing.subject.common.enums.SubjectInfoTypeEnum;
|
||||
import com.landaiqing.subject.domain.convert.RadioSubjectConverter;
|
||||
import com.landaiqing.subject.domain.entity.SubjectAnswerBO;
|
||||
import com.landaiqing.subject.domain.entity.SubjectInfoBO;
|
||||
import com.landaiqing.subject.domain.entity.SubjectOptionBO;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectRadio;
|
||||
import com.landaiqing.subject.infra.basic.service.SubjectRadioService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Classname RadioTypeHandler
|
||||
* @BelongsProject: jc-club
|
||||
* @BelongsPackage: com.landaiqing.subject.domain.handler.subject
|
||||
* @Author: landaiqing
|
||||
* @CreateTime: 2024-02-15 15:59
|
||||
* @Description: 单选题目的策略类
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Component
|
||||
public class RadioTypeHandler implements SubjectTypeHandler {
|
||||
@Resource
|
||||
private SubjectRadioService subjectRadioService;
|
||||
@Override
|
||||
public SubjectInfoTypeEnum getHandlerType() {
|
||||
return SubjectInfoTypeEnum.RADIO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(SubjectInfoBO subjectInfoBO) {
|
||||
//单选题目的插入
|
||||
List<SubjectRadio> subjectRadioList = new LinkedList<>();
|
||||
if (subjectInfoBO.getOptionList() == null && subjectInfoBO.getOptionList().size() < 0) {
|
||||
return;
|
||||
}
|
||||
subjectInfoBO.getOptionList().forEach(option -> {
|
||||
SubjectRadio subjectRadio = RadioSubjectConverter.INSTANCE.convertBoToEntity(option);
|
||||
subjectRadio.setId(subjectInfoBO.getId());
|
||||
subjectRadio.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||
subjectRadioList.add(subjectRadio);
|
||||
});
|
||||
subjectRadioService.batchInsert(subjectRadioList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubjectOptionBO query(int subjectId) {
|
||||
SubjectRadio subjectRadio = new SubjectRadio();
|
||||
subjectRadio.setSubjectId(Long.valueOf(subjectId));
|
||||
List<SubjectRadio> result = subjectRadioService.queryByCondition(subjectRadio);
|
||||
List<SubjectAnswerBO> subjectAnswerBOList = RadioSubjectConverter.INSTANCE.convertEntityToBoList(result);
|
||||
SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
|
||||
subjectOptionBO.setOptionList(subjectAnswerBOList);
|
||||
return subjectOptionBO;
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package com.landaiqing.subject.domain.handler.subject;
|
||||
|
||||
import com.landaiqing.subject.common.enums.SubjectInfoTypeEnum;
|
||||
import com.landaiqing.subject.domain.entity.SubjectInfoBO;
|
||||
import com.landaiqing.subject.domain.entity.SubjectOptionBO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public interface SubjectTypeHandler {
|
||||
/**
|
||||
* @description: 枚举身份的识别
|
||||
* @param: []
|
||||
* @return: com.landaiqing.subject.common.enums.SubjectInfoTypeEnum
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/15 16:26
|
||||
*/
|
||||
SubjectInfoTypeEnum getHandlerType();
|
||||
/**
|
||||
* @description: 实际题目的插入
|
||||
* @param: [subjectInfoBO]
|
||||
* @return: void
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/15 15:58
|
||||
*/
|
||||
void add (SubjectInfoBO subjectInfoBO);
|
||||
|
||||
SubjectOptionBO query(int subjectId);
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package com.landaiqing.subject.domain.handler.subject;
|
||||
|
||||
import com.landaiqing.subject.common.enums.SubjectInfoTypeEnum;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Classname SubjectTypeFactory
|
||||
* @BelongsProject: jc-club
|
||||
* @BelongsPackage: com.landaiqing.subject.domain.handler.subject
|
||||
* @Author: landaiqing
|
||||
* @CreateTime: 2024-02-15 16:05
|
||||
* @Description: 题目类型工厂
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Component
|
||||
public class SubjectTypeHandlerFactory implements InitializingBean {
|
||||
@Resource
|
||||
private List<SubjectTypeHandler> subjectTypeHandlerList;
|
||||
|
||||
private Map<SubjectInfoTypeEnum,SubjectTypeHandler> handlerMap =new HashMap<>();
|
||||
|
||||
public SubjectTypeHandler getHandler(int subjectType){
|
||||
SubjectInfoTypeEnum subjectInfoTypeEnum = SubjectInfoTypeEnum.getByCode(subjectType);
|
||||
return handlerMap.get(subjectInfoTypeEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
for(SubjectTypeHandler subjectTypeHandler : subjectTypeHandlerList){
|
||||
handlerMap.put(subjectTypeHandler.getHandlerType(),subjectTypeHandler);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package com.landaiqing.subject.domain.service;
|
||||
|
||||
import com.landaiqing.subject.common.entity.PageResult;
|
||||
import com.landaiqing.subject.domain.entity.SubjectInfoBO;
|
||||
import com.landaiqing.subject.domain.entity.SubjectLabelBO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @description: 题目领域服务
|
||||
*
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/14 17:22
|
||||
*/
|
||||
public interface SubjectInfoDomainService {
|
||||
/**
|
||||
* 新增题目
|
||||
*/
|
||||
void add(SubjectInfoBO subjectInfoBO);
|
||||
/**
|
||||
* @description: 分页查询
|
||||
* @param: [subjectInfoBO]
|
||||
* @return: com.landaiqing.subject.common.entity.PageResult<com.landaiqing.subject.domain.entity.SubjectInfoBO>
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/16 12:22
|
||||
*/
|
||||
PageResult<SubjectInfoBO> getSubjectPage(SubjectInfoBO subjectInfoBO);
|
||||
/**
|
||||
* @description: 查询题目信息
|
||||
* @param: [subjectInfoBO]
|
||||
* @return: com.landaiqing.subject.domain.entity.SubjectInfoBO
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/16 13:54
|
||||
*/
|
||||
SubjectInfoBO querySubjectInfo(SubjectInfoBO subjectInfoBO);
|
||||
}
|
@@ -0,0 +1,123 @@
|
||||
package com.landaiqing.subject.domain.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.landaiqing.subject.common.entity.PageResult;
|
||||
import com.landaiqing.subject.common.enums.IsDeletedFlagEnum;
|
||||
import com.landaiqing.subject.domain.convert.SubjectInfoConverter;
|
||||
import com.landaiqing.subject.domain.entity.SubjectInfoBO;
|
||||
import com.landaiqing.subject.domain.entity.SubjectOptionBO;
|
||||
import com.landaiqing.subject.domain.handler.subject.SubjectTypeHandler;
|
||||
import com.landaiqing.subject.domain.handler.subject.SubjectTypeHandlerFactory;
|
||||
import com.landaiqing.subject.domain.service.SubjectInfoDomainService;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectInfo;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectLabel;
|
||||
import com.landaiqing.subject.infra.basic.entity.SubjectMapping;
|
||||
import com.landaiqing.subject.infra.basic.service.SubjectInfoService;
|
||||
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.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SubjectInfoDomainServiceImpl implements SubjectInfoDomainService {
|
||||
@Resource
|
||||
private SubjectInfoService subjectInfoService;
|
||||
@Resource
|
||||
private SubjectMappingService subjectMappingService;
|
||||
@Resource
|
||||
private SubjectTypeHandlerFactory subjectTypeHandlerFactory;
|
||||
|
||||
@Resource
|
||||
private SubjectLabelService subjectLabelService;
|
||||
|
||||
|
||||
/**
|
||||
* @description: 新增标签
|
||||
* @param: [subjectLabelBO]
|
||||
* @return: java.lang.Boolean
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/14 17:27
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void add(SubjectInfoBO subjectInfoBO) {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("SubjectInfoDomainServiceImpl.add.bo:{}", JSON.toJSONString(subjectInfoBO));
|
||||
}
|
||||
SubjectInfo subjectInfo = SubjectInfoConverter.INSTANCE.convertBoToInfo(subjectInfoBO);
|
||||
subjectInfo.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||
subjectInfoService.insert(subjectInfo);
|
||||
SubjectTypeHandler handler = subjectTypeHandlerFactory.getHandler(subjectInfo.getSubjectType());
|
||||
subjectInfoBO.setId(subjectInfo.getId());
|
||||
handler.add(subjectInfoBO);
|
||||
List<Integer> categoryIds = subjectInfoBO.getCategoryIds();
|
||||
List<Integer> labelIds = subjectInfoBO.getLabelIds();
|
||||
List<SubjectMapping> mappingList = new LinkedList<>();
|
||||
categoryIds.forEach(categoryId -> {
|
||||
labelIds.forEach(labelId -> {
|
||||
SubjectMapping subjectMapping = new SubjectMapping();
|
||||
subjectMapping.setSubjectId(subjectInfo.getId());
|
||||
subjectMapping.setCategoryId(Long.valueOf(categoryId));
|
||||
subjectMapping.setLabelId(Long.valueOf(labelId));
|
||||
subjectMapping.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||
mappingList.add(subjectMapping);
|
||||
});
|
||||
});
|
||||
subjectMappingService.batchInsert(mappingList);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 分页查询
|
||||
* @param: [subjectInfoBO]
|
||||
* @return: com.landaiqing.subject.common.entity.PageResult<com.landaiqing.subject.domain.entity.SubjectInfoBO>
|
||||
* @author landaiqing
|
||||
* @date: 2024/2/16 12:21
|
||||
*/
|
||||
@Override
|
||||
public PageResult<SubjectInfoBO> getSubjectPage(SubjectInfoBO subjectInfoBO) {
|
||||
PageResult<SubjectInfoBO> pageResult = new PageResult<>();
|
||||
pageResult.setPageNo(subjectInfoBO.getPageNo());
|
||||
pageResult.setPageSize(subjectInfoBO.getPageSize());
|
||||
int start = (subjectInfoBO.getPageNo() - 1) * subjectInfoBO.getPageSize();
|
||||
SubjectInfo subjectInfo = SubjectInfoConverter.INSTANCE.convertBoToInfo(subjectInfoBO);
|
||||
|
||||
int count = subjectInfoService.countByCondition(subjectInfo, subjectInfoBO.getLabelId(), subjectInfoBO.getCategoryId());
|
||||
if (count == 0) {
|
||||
return pageResult;
|
||||
}
|
||||
List<SubjectInfo> subjectInfoList = subjectInfoService.queryPage(subjectInfo, subjectInfoBO.getCategoryId(), subjectInfoBO.getLabelId(),
|
||||
start, subjectInfoBO.getPageSize());
|
||||
List<SubjectInfoBO> subjectInfoBOS = SubjectInfoConverter.INSTANCE.convertListInfoBoToBO(subjectInfoList);
|
||||
pageResult.setRecords(subjectInfoBOS);
|
||||
pageResult.setTotal(count);
|
||||
return pageResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubjectInfoBO querySubjectInfo(SubjectInfoBO subjectInfoBO) {
|
||||
SubjectInfo subjectInfo = subjectInfoService.queryById(subjectInfoBO.getId());
|
||||
Integer subjectType = subjectInfo.getSubjectType();
|
||||
SubjectTypeHandler handler = subjectTypeHandlerFactory.getHandler(subjectInfo.getSubjectType());
|
||||
SubjectOptionBO optionBO = handler.query(subjectInfo.getId().intValue());
|
||||
SubjectInfoBO bo = SubjectInfoConverter.INSTANCE.convertOptionAndInfoToBO(optionBO, subjectInfo);
|
||||
SubjectMapping subjectMapping = new SubjectMapping();
|
||||
subjectMapping.setSubjectId(subjectInfo.getId());
|
||||
subjectMapping.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||
List<SubjectMapping> mappingList = subjectMappingService.queryLabelId(subjectMapping);
|
||||
List<Long> labelIdList = mappingList.stream().map(SubjectMapping::getLabelId).collect(Collectors.toList());
|
||||
List<SubjectLabel> labelList = subjectLabelService.batchQueryById(labelIdList);
|
||||
List<String> labelNameList = labelList.stream().map(SubjectLabel::getLabelName).collect(Collectors.toList());
|
||||
bo.setLabelName(labelNameList);
|
||||
return bo;
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user