feat: 题目模块开发

This commit is contained in:
2024-02-16 19:17:52 +08:00
parent 37fb0ea196
commit 7028b350bd
59 changed files with 3135 additions and 27 deletions

View File

@@ -0,0 +1,37 @@
package com.landaiqing.subject.application.config;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import java.util.List;
/**
* @Classname GlobalConfig
* @BelongsProject: jc-club
* @BelongsPackage: com.landaiqing.subject.application.config
* @Author: landaiqing
* @CreateTime: 2024-02-16 15:57
* @Description: MVC全局处理
* @Version: 1.0
*/
@Configuration
public class GlobalConfig extends WebMvcConfigurationSupport {
@Override
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
super.configureMessageConverters(converters);
converters.add(mappingJackson2HttpMessageConverter());
}
private MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(){
ObjectMapper objectMapper=new ObjectMapper();
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
MappingJackson2HttpMessageConverter converter=new MappingJackson2HttpMessageConverter(objectMapper);
return converter;
}
}

View File

@@ -1,11 +1,22 @@
package com.landaiqing.subject.application.controller;
import com.landaiqing.subject.infra.basic.entity.SubjectCategory;
import com.landaiqing.subject.infra.basic.service.SubjectCategoryService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Preconditions;
import com.landaiqing.subject.application.convert.SubjectAnswerDTOConverter;
import com.landaiqing.subject.application.convert.SubjectInfoDTOConverter;
import com.landaiqing.subject.application.dto.SubjectInfoDTO;
import com.landaiqing.subject.common.entity.PageResult;
import com.landaiqing.subject.common.entity.Result;
import com.landaiqing.subject.domain.entity.SubjectAnswerBO;
import com.landaiqing.subject.domain.entity.SubjectInfoBO;
import com.landaiqing.subject.domain.service.SubjectInfoDomainService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 刷题controller
@@ -14,13 +25,95 @@ import javax.annotation.Resource;
* @date: 2024/2/7
*/
@RestController
@RequestMapping("/subject/")
@Slf4j
public class SubjectController {
@Resource
private SubjectCategoryService subjectCategoryService;
@GetMapping("/test")
public String test(){
SubjectCategory subjectCategory = subjectCategoryService.queryById(1L);
return subjectCategory.getCategoryName();
private SubjectInfoDomainService subjectInfoDomainService;
/**
* @description: 新增题目
* @param: [subjectInfoDTO]
* @return: com.landaiqing.subject.common.entity.Result<java.lang.Boolean>
* @author landaiqing
* @date: 2024/2/15 15:06
*/
@PostMapping("/add")
public Result<Boolean> add(@RequestBody SubjectInfoDTO subjectInfoDTO) {
try {
if (log.isInfoEnabled()) {
log.info("SubjectController.add.dto:{}", JSON.toJSONString(subjectInfoDTO));
}
Preconditions.checkArgument(!StringUtils.isBlank(subjectInfoDTO.getSubjectName()), "题目的名称不能为空!");
Preconditions.checkNotNull(subjectInfoDTO.getSubjectDifficult(), "题目难度不能为空!");
Preconditions.checkNotNull(subjectInfoDTO.getSubjectType(), "题目类型不能为空!");
Preconditions.checkNotNull(subjectInfoDTO.getSubjectScore(), "分数不能为空!");
Preconditions.checkArgument(!CollectionUtils.isEmpty(subjectInfoDTO.getCategoryIds()), "分类id不能为空");
Preconditions.checkArgument(!CollectionUtils.isEmpty(subjectInfoDTO.getLabelIds()), "标签id不能为空");
SubjectInfoBO subjectInfoBO = SubjectInfoDTOConverter.INSTANCE.convertDtoToBO(subjectInfoDTO);
List<SubjectAnswerBO> subjectAnswerBOS = SubjectAnswerDTOConverter.INSTANCE.convertListDtoToBO(subjectInfoDTO.getOptionList());
subjectInfoBO.setOptionList(subjectAnswerBOS);
subjectInfoDomainService.add(subjectInfoBO);
return Result.ok(true);
} catch (Exception e) {
log.error("SubjectController.add.error:{}", e.getMessage(), e);
return Result.fail("新增题目失败!");
}
}
/**
* @description: 查询题目列表
* @param: [subjectInfoDTO]
* @return: com.landaiqing.subject.common.entity.Result<com.landaiqing.subject.common.entity.PageResult < com.landaiqing.subject.application.dto.SubjectInfoDTO>>
* @author landaiqing
* @date: 2024/2/16 12:16
*/
@PostMapping("/getSubjectPage")
public Result<PageResult<SubjectInfoDTO>> getSubjectPage(@RequestBody SubjectInfoDTO subjectInfoDTO) {
try {
if (log.isInfoEnabled()) {
log.info("SubjectController.getSubjectPage.dto:{}", JSON.toJSONString(subjectInfoDTO));
}
Preconditions.checkNotNull(subjectInfoDTO.getCategoryId(), "分类id不能为空");
Preconditions.checkNotNull(subjectInfoDTO.getLabelId(), "标签id不能为空");
SubjectInfoBO subjectInfoBO = SubjectInfoDTOConverter.INSTANCE.convertDtoToBO(subjectInfoDTO);
PageResult<SubjectInfoBO> boPageResult = subjectInfoDomainService.getSubjectPage(subjectInfoBO);
return Result.ok(boPageResult);
} catch (Exception e) {
log.error("SubjectController.getSubjectPage.error:{}", e.getMessage(), e);
return Result.fail("查询题目列表失败!");
}
}
/**
* @description: 查询题目详情
* @param: [subjectInfoDTO]
* @return: com.landaiqing.subject.common.entity.Result<com.landaiqing.subject.application.dto.SubjectInfoDTO>
* @author landaiqing
* @date: 2024/2/16 15:44
*/
@PostMapping("/querySubjectInfo")
public Result<SubjectInfoDTO> querySubjectInfo(@RequestBody SubjectInfoDTO subjectInfoDTO) {
try {
if (log.isInfoEnabled()) {
log.info("SubjectController.querySubjectInfo.dto:{}", JSON.toJSONString(subjectInfoDTO));
}
Preconditions.checkNotNull(subjectInfoDTO.getId(), "题目id不能为空");
SubjectInfoBO subjectInfoBO = SubjectInfoDTOConverter.INSTANCE.convertDtoToBO(subjectInfoDTO);
SubjectInfoBO boResult = subjectInfoDomainService.querySubjectInfo(subjectInfoBO);
SubjectInfoDTO dtoResult = SubjectInfoDTOConverter.INSTANCE.convertBOToDTO(boResult);
return Result.ok(dtoResult);
} catch (Exception e) {
log.error("SubjectController.querySubjectInfo.error:{}", e.getMessage(), e);
return Result.fail("查询题目详情失败!");
}
}
}

View File

@@ -0,0 +1,26 @@
package com.landaiqing.subject.application.convert;
import com.landaiqing.subject.application.dto.SubjectAnswerDTO;
import com.landaiqing.subject.application.dto.SubjectInfoDTO;
import com.landaiqing.subject.domain.entity.SubjectAnswerBO;
import com.landaiqing.subject.domain.entity.SubjectInfoBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 题目答案dto转换器
*
* @author: landaiqing
* @date: 2024/2/13
*/
@Mapper
public interface SubjectAnswerDTOConverter {
SubjectAnswerDTOConverter INSTANCE = Mappers.getMapper(SubjectAnswerDTOConverter.class);
SubjectAnswerBO convertDtoToBO(SubjectAnswerDTO subjectAnswerDTO);
List<SubjectAnswerBO> convertListDtoToBO(List<SubjectAnswerDTO> dtoList);
}

View File

@@ -0,0 +1,26 @@
package com.landaiqing.subject.application.convert;
import com.landaiqing.subject.application.dto.SubjectCategoryDTO;
import com.landaiqing.subject.application.dto.SubjectInfoDTO;
import com.landaiqing.subject.domain.entity.SubjectCategoryBO;
import com.landaiqing.subject.domain.entity.SubjectInfoBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 题目分类dto转换器
*
* @author: landaiqing
* @date: 2024/2/13
*/
@Mapper
public interface SubjectInfoDTOConverter {
SubjectInfoDTOConverter INSTANCE = Mappers.getMapper(SubjectInfoDTOConverter.class);
SubjectInfoBO convertDtoToBO(SubjectInfoDTO subjectInfoDTO);
SubjectInfoDTO convertBOToDTO(SubjectInfoBO subjectInfoBO);
}

View File

@@ -0,0 +1,34 @@
package com.landaiqing.subject.application.dto;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 题目答案DTO
*
* @author landaiqing
* @since 2024-02-14 16:59:04
*/
@Data
public class SubjectAnswerDTO implements Serializable {
/**
* 答案选项标识
*/
private Integer optionType;
/**
* 答案
*/
private String optionContent;
/**
* 是否正确
*/
private Integer isCorrect;
}

View File

@@ -8,7 +8,7 @@ import java.util.List;
/**
* 题目分类(SubjectCategory)实体类
*
* @author makejava
* @author landaiqing
* @since 2024-02-07 16:17:17
*/
@Data

View File

@@ -0,0 +1,78 @@
package com.landaiqing.subject.application.dto;
import com.landaiqing.subject.common.entity.PageInfo;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* 题目DTO
*
* @author landaiqing
* @since 2024-02-14 16:59:04
*/
@Data
public class SubjectInfoDTO 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;
/**
* 标签id
*/
private List<Integer> labelIds;
/**
* 答案选项
*/
private List<SubjectAnswerDTO> optionList;
private Long categoryId;
private Long labelId;
/**
* 标签名称
*/
private List<String> labelName;
}

View File

@@ -8,7 +8,7 @@ import java.util.Date;
/**
* 题目标签DTO
*
* @author makejava
* @author landaiqing
* @since 2024-02-14 17:08:06
*/
@Data