增加考试模块

This commit is contained in:
wanggeng 2022-05-12 18:25:39 +08:00
parent 00975c85b6
commit 56da58ce95
9 changed files with 1519 additions and 0 deletions

View File

@ -0,0 +1,228 @@
package ink.wgink.module.examine.controller.test;
import com.cm.study.enums.QuestionTypeEnum;
import com.cm.study.pojo.dtos.question.QuestionDTO;
import com.cm.study.pojo.vos.question.QuestionVO;
import com.cm.study.service.question.IQuestionService;
import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.common.component.SecurityComponent;
import ink.wgink.exceptions.ParamsException;
import ink.wgink.exceptions.RemoveException;
import ink.wgink.exceptions.SearchException;
import ink.wgink.interfaces.consts.IFileConstant;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.*;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* @ClassName: TestQuestionController
* @Description: 试题管理
* @Author: WenG
* @Date: 2020-09-09 21:00
* @Version: 1.0
**/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "试题管理接口")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/test/question")
public class TestQuestionController extends DefaultBaseController {
@Autowired
private IQuestionService questionService;
@Autowired
private SecurityComponent securityComponent;
@ApiOperation(value = "新增试题管理", notes = "新增试题管理接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("save")
@CheckRequestBodyAnnotation
public SuccessResult saveQuestion(@RequestBody QuestionVO questionVO) throws Exception {
boolean hanOption = StringUtils.equals(questionVO.getType(), QuestionTypeEnum.CHOICE.getValue())
|| StringUtils.equals(questionVO.getType(), QuestionTypeEnum.TURE_OR_FALSE.getValue());
if (hanOption && questionVO.getQuestionOptions().isEmpty()) {
throw new ParamsException("选择或判断选项不能为空");
}
return questionService.saveQuestion(questionVO);
}
@ApiOperation(value = "删除试题管理(id列表)", notes = "删除试题管理(id列表)接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "ids", value = "ID列表用下划线分隔", paramType = "path", example = "1_2_3")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@DeleteMapping("removequestion/{ids}")
public SuccessResult removeQuestion(@PathVariable("ids") String ids) throws RemoveException {
questionService.removeQuestion(Arrays.asList(ids.split("\\_")));
return new SuccessResult();
}
@ApiOperation(value = "修改试题管理", notes = "修改试题管理接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "questionId", value = "试题管理ID", paramType = "path")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PutMapping("updatequestion/{questionId}")
@CheckRequestBodyAnnotation
public SuccessResult updateQuestion(@PathVariable("questionId") String questionId, @RequestBody QuestionVO questionVO) throws Exception {
boolean hanOption = StringUtils.equals(questionVO.getType(), QuestionTypeEnum.CHOICE.getValue())
|| StringUtils.equals(questionVO.getType(), QuestionTypeEnum.TURE_OR_FALSE.getValue());
if (hanOption && questionVO.getQuestionOptions().isEmpty()) {
throw new ParamsException("选择或判断选项不能为空");
}
return questionService.updateQuestion(questionId, questionVO);
}
@ApiOperation(value = "试题管理详情(通过ID)", notes = "试题管理详情(通过ID)接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "questionId", value = "试题管理ID", paramType = "path")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("getquestionbyid/{questionId}")
public QuestionDTO getQuestionById(@PathVariable("questionId") String questionId) throws SearchException {
return questionService.getQuestionById(questionId);
}
@ApiOperation(value = "试题管理列表", notes = "试题管理列表接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listquestion")
public List<QuestionDTO> listQuestion() throws SearchException {
Map<String, Object> params = requestParams();
return questionService.listQuestion(params);
}
@ApiOperation(value = "试题管理分页列表", notes = "试题管理分页列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
@ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
@ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listpagequestion")
public SuccessResultList<List<QuestionDTO>> listPageQuestion(ListPage page) throws SearchException {
Map<String, Object> params = requestParams();
page.setParams(params);
return questionService.listPageQuestion(page);
}
@ApiOperation(value = "试题管理分页(管理员)列表", notes = "试题管理分页(管理员)列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
@ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
@ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listpageadmin")
public SuccessResultList<List<QuestionDTO>> listPageAdmin(ListPage page) throws SearchException {
Map<String, Object> params = requestParams();
page.setParams(params);
return questionService.listPageAdmin(page);
}
@ApiOperation(value = "试题管理分页(老师)列表", notes = "试题管理分页(老师)列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
@ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
@ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listpageteacher")
public SuccessResultList<List<QuestionDTO>> listPageTeacher(ListPage page) throws SearchException {
Map<String, Object> params = requestParams();
page.setParams(params);
return questionService.listPageTeacher(page);
}
@ApiOperation(value = "试题管理统计", notes = "试题管理统计接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("countquestion")
SuccessResultData<Integer> countQuestion() throws SearchException {
Map<String, Object> params = requestParams();
return questionService.countQuestion(params);
}
@ApiOperation(value = "试题管理(排除)分页列表", notes = "试题管理(排除)分页列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "classInfoId", value = "班级ID", paramType = "path"),
@ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
@ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
@ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listpageexcept/{classInfoId}")
public SuccessResultList<List<QuestionDTO>> listPageExcept(@PathVariable("classInfoId") String classInfoId, ListPage page) {
Map<String, Object> params = requestParams();
page.setParams(params);
return questionService.listPageExcept(classInfoId, page);
}
@ApiOperation(value = "试题管理(排除)分页列表(管理员)", notes = "试题管理(排除)分页列表(管理员)接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "classInfoId", value = "当前页码", paramType = "path"),
@ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
@ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
@ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listpageexceptadmin/{classInfoId}")
public SuccessResultList<List<QuestionDTO>> listPageExceptAdmin(@PathVariable("classInfoId") String classInfoId, ListPage page) {
Map<String, Object> params = requestParams();
page.setParams(params);
return questionService.listPageExceptAdmin(classInfoId, page);
}
@ApiOperation(value = "试题管理(排除)分页列表(老师)", notes = "试题管理(排除)分页列表(老师)接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "classInfoId", value = "当前页码", paramType = "path"),
@ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
@ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
@ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listpageexceptteacher/{classInfoId}")
public SuccessResultList<List<QuestionDTO>> listPageExceptTeachers(@PathVariable("classInfoId") String classInfoId, ListPage page) {
Map<String, Object> params = requestParams();
page.setParams(params);
return questionService.listPageExceptTeacher(classInfoId, page);
}
@ApiOperation(value = "试题导入Excel", notes = "试题导入Excel接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "excel", value = "文件名称", paramType = "query"),
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("import-excel")
public UploadExcelResultDTO importExcel(MultipartFile excel) throws IOException {
if (Objects.isNull(excel)) {
throw new ParamsException("Excel不能为空");
}
if (!excel.getOriginalFilename().endsWith(IFileConstant.EXCEL_SUFFIX_XLS) &&
!excel.getOriginalFilename().endsWith(IFileConstant.EXCEL_SUFFIX_XLSX)) {
throw new ParamsException("文件格式为Excel");
}
return questionService.importExcel(excel);
}
}

View File

@ -0,0 +1,126 @@
package ink.wgink.module.examine.dao;
import com.cm.study.pojo.dtos.question.QuestionDTO;
import com.cm.study.pojo.pos.question.QuestionPO;
import ink.wgink.exceptions.RemoveException;
import ink.wgink.exceptions.SaveException;
import ink.wgink.exceptions.SearchException;
import ink.wgink.exceptions.UpdateException;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;
/**
* @ClassName: IQuestionDao
* @Description: 试题管理
* @Author: WenG
* @Date: 2020-09-09 21:00
* @Version: 1.0
**/
@Repository
public interface ITestQuestionDao {
/**
* 新增试题管理
*
* @param params
* @throws SaveException
*/
void save(Map<String, Object> params) throws SaveException;
/**
* 删除试题管理
*
* @param params
* @throws RemoveException
*/
void remove(Map<String, Object> params) throws RemoveException;
/**
* 删除试题管理物理
*
* @param params
* @throws RemoveException
*/
void delete(Map<String, Object> params) throws RemoveException;
/**
* 修改试题管理
*
* @param params
* @throws UpdateException
*/
void update(Map<String, Object> params) throws UpdateException;
/**
* 试题管理详情
*
* @param params
* @return
* @throws SearchException
*/
QuestionDTO get(Map<String, Object> params) throws SearchException;
/**
* 详情
*
* @param params
* @return
* @throws SearchException
*/
QuestionPO getPO(Map<String, Object> params) throws SearchException;
/**
* 试题管理列表
*
* @param params
* @return
* @throws SearchException
*/
List<QuestionDTO> list(Map<String, Object> params) throws SearchException;
/**
* 试题管理统计
*
* @param params
* @return
* @throws SearchException
*/
Integer count(Map<String, Object> params) throws SearchException;
/**
* 试题ID列表
*
* @param params
* @return
* @throws SearchException
*/
List<String> listIds(Map<String, Object> params) throws SearchException;
/**
* 获取试题列表通过试卷ID
*
* @param examinationPaperId
* @return
* @throws SearchException
*/
List<QuestionDTO> listQuestionByExaminationPagerId(String examinationPaperId) throws SearchException;
/**
* 试题列表
*
* @param params
* @return
* @throws SearchException
*/
List<QuestionPO> listPO(Map<String, Object> params) throws SearchException;
/**
* 更新自定义试题类型
*
* @param params
* @throws UpdateException
*/
void updateCustomQuestionType(Map<String, Object> params) throws UpdateException;
}

View File

@ -0,0 +1,53 @@
package ink.wgink.module.examine.pojo.dtos.test;
import com.cm.study.pojo.dtos.questionoptions.QuestionOptionsDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @ClassName: QuestionDTO
* @Description: 试题管理
* @Author: WenG
* @Date: 2020-09-09 21:00
* @Version: 1.0
**/
@ApiModel
public class TestQuestionDTO {
@ApiModelProperty(name = "questionId", value = "主键")
private String questionId;
@ApiModelProperty(name = "subject", value = "题目")
private String subject;
@ApiModelProperty(name = "questionType", value = "试题类型")
private String questionType;
@ApiModelProperty(name = "questionTypeName", value = "试题类型名称")
private String questionTypeName;
@ApiModelProperty(name = "customQuestionType", value = "自定义试题类型")
private String customQuestionType;
@ApiModelProperty(name = "customQuestionTypeName", value = "自定义试题类型名称")
private String customQuestionTypeName;
@ApiModelProperty(name = "type", value = "种类choice选择tureOrFalse判断fillInTheBlanks填空answer解答")
private String type;
@ApiModelProperty(name = "choiceType", value = "选择类别single单选multiple多选")
private String choiceType;
@ApiModelProperty(name = "analysis", value = "解析")
private String analysis;
@ApiModelProperty(name = "parentId", value = "上级试题")
private String parentId;
@ApiModelProperty(name = "difficulty", value = "难度")
private Integer difficulty;
@ApiModelProperty(name = "source", value = "来源")
private String source;
@ApiModelProperty(name = "answer", value = "答案")
private String answer;
@ApiModelProperty(name = "gmtCreate", value = "创建时间")
private String gmtCreate;
@ApiModelProperty(name = "isUsed", value = "是否被使用")
private boolean isUsed;
@ApiModelProperty(name = "questionOptions", value = "选项")
private List<QuestionOptionsDTO> questionOptions;
}

View File

@ -0,0 +1,63 @@
package ink.wgink.module.examine.pojo.dtos.test;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;
/**
* @ClassName: TestQuestionOptionsDTO
* @Description: 试题选项
* @Author: WenG
* @Date: 2020-09-09 21:00
* @Version: 1.0
**/
@ApiModel
public class TestQuestionOptionsDTO implements Comparable {
@ApiModelProperty(name = "questionOptionsId", value = "主键")
private String questionOptionsId;
@ApiModelProperty(name = "questionId", value = "试题")
private String questionId;
@ApiModelProperty(name = "option", value = "标识")
private String option;
@ApiModelProperty(name = "content", value = "内容")
private String content;
public String getQuestionOptionsId() {
return questionOptionsId == null ? "" : questionOptionsId.trim();
}
public void setQuestionOptionsId(String questionOptionsId) {
this.questionOptionsId = questionOptionsId;
}
public String getQuestionId() {
return questionId == null ? "" : questionId.trim();
}
public void setQuestionId(String questionId) {
this.questionId = questionId;
}
public String getOption() {
return option == null ? "" : option.trim();
}
public void setOption(String option) {
this.option = option;
}
public String getContent() {
return content == null ? "" : content.trim();
}
public void setContent(String content) {
this.content = content;
}
@Override
public int compareTo(Object o) {
return StringUtils.compare(option, ((TestQuestionOptionsDTO) o).getOption());
}
}

View File

@ -0,0 +1,62 @@
package ink.wgink.module.examine.pojo.vos.test;
import ink.wgink.annotation.CheckEmptyAnnotation;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
*
* @ClassName: QuestionOptionsVO
* @Description: 试题选项
* @Author: WenG
* @Date: 2020-09-09 21:00
* @Version: 1.0
**/
@ApiModel
public class TestQuestionOptionsVO {
@ApiModelProperty(name = "questionId", value = "试题")
private String questionId;
@ApiModelProperty(name = "option", value = "标识")
@CheckEmptyAnnotation(name = "标识")
private String option;
@ApiModelProperty(name = "content", value = "内容")
private String content;
public String getQuestionId() {
return questionId == null ? "" : questionId.trim();
}
public void setQuestionId(String questionId) {
this.questionId = questionId;
}
public String getOption() {
return option == null ? "" : option.trim();
}
public void setOption(String option) {
this.option = option;
}
public String getContent() {
return content == null ? "" : content.trim();
}
public void setContent(String content) {
this.content = content;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("{");
sb.append("\"questionId\":\"")
.append(questionId).append('\"');
sb.append(",\"option\":\"")
.append(option).append('\"');
sb.append(",\"content\":\"")
.append(content).append('\"');
sb.append('}');
return sb.toString();
}
}

View File

@ -0,0 +1,165 @@
package ink.wgink.module.examine.pojo.vos.test;
import ink.wgink.annotation.CheckEmptyAnnotation;
import ink.wgink.annotation.CheckNumberAnnotation;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;
/**
* @ClassName: QuestionVO
* @Description: 试题管理
* @Author: WenG
* @Date: 2020-09-09 21:00
* @Version: 1.0
**/
@ApiModel
public class TestQuestionVO {
@ApiModelProperty(name = "subject", value = "题目")
@CheckEmptyAnnotation(name = "题目")
private String subject;
@ApiModelProperty(name = "questionType", value = "试题类型")
private String questionType;
@ApiModelProperty(name = "customQuestionType", value = "自定义试题类型")
private String customQuestionType;
@ApiModelProperty(name = "type", value = "种类")
@CheckEmptyAnnotation(name = "种类", types = {"choice", "tureOrFalse", "fillInTheBlanks", "answer"})
private String type;
@ApiModelProperty(name = "choiceType", value = "选择类别")
private String choiceType;
@ApiModelProperty(name = "analysis", value = "解析")
@CheckEmptyAnnotation(name = "解析")
private String analysis;
@ApiModelProperty(name = "parentId", value = "上级试题")
private String parentId;
@ApiModelProperty(name = "difficulty", value = "难度")
@CheckNumberAnnotation(name = "难度")
private Integer difficulty;
@ApiModelProperty(name = "source", value = "来源")
private String source;
@ApiModelProperty(name = "answer", value = "答案")
@CheckEmptyAnnotation(name = "答案")
private String answer;
@ApiModelProperty(name = "questionOptions", value = "问题选项")
private List<TestQuestionOptionsVO> options;
public String getSubject() {
return subject == null ? "" : subject.trim();
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getQuestionType() {
return questionType == null ? "" : questionType.trim();
}
public void setQuestionType(String questionType) {
this.questionType = questionType;
}
public String getCustomQuestionType() {
return customQuestionType == null ? "" : customQuestionType.trim();
}
public void setCustomQuestionType(String customQuestionType) {
this.customQuestionType = customQuestionType;
}
public String getType() {
return type == null ? "" : type.trim();
}
public void setType(String type) {
this.type = type;
}
public String getChoiceType() {
return choiceType == null ? "" : choiceType.trim();
}
public void setChoiceType(String choiceType) {
this.choiceType = choiceType;
}
public String getAnalysis() {
return analysis == null ? "" : analysis.trim();
}
public void setAnalysis(String analysis) {
this.analysis = analysis;
}
public String getParentId() {
return parentId == null ? "" : parentId.trim();
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public Integer getDifficulty() {
return difficulty == null ? 0 : difficulty;
}
public void setDifficulty(Integer difficulty) {
this.difficulty = difficulty;
}
public String getSource() {
return source == null ? "" : source.trim();
}
public void setSource(String source) {
this.source = source;
}
public String getAnswer() {
return answer == null ? "" : answer.trim();
}
public void setAnswer(String answer) {
this.answer = answer;
}
public List<TestQuestionOptionsVO> getOptions() {
return options == null ? new ArrayList() : options;
}
public void setOptions(List<TestQuestionOptionsVO> options) {
this.options = options;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("{");
sb.append("\"subject\":\"")
.append(subject).append('\"');
sb.append(",\"questionType\":\"")
.append(questionType).append('\"');
sb.append(",\"customQuestionType\":\"")
.append(customQuestionType).append('\"');
sb.append(",\"type\":\"")
.append(type).append('\"');
sb.append(",\"choiceType\":\"")
.append(choiceType).append('\"');
sb.append(",\"analysis\":\"")
.append(analysis).append('\"');
sb.append(",\"parentId\":\"")
.append(parentId).append('\"');
sb.append(",\"difficulty\":")
.append(difficulty);
sb.append(",\"source\":\"")
.append(source).append('\"');
sb.append(",\"answer\":\"")
.append(answer).append('\"');
sb.append(",\"options\":")
.append(options);
sb.append('}');
return sb.toString();
}
}

View File

@ -0,0 +1,181 @@
package ink.wgink.module.examine.service.test;
import com.cm.study.enums.QuestionChoiceTypeEnum;
import com.cm.study.enums.QuestionTypeEnum;
import com.cm.study.pojo.dtos.classquestion.ClassQuestionDTO;
import com.cm.study.pojo.dtos.question.QuestionDTO;
import com.cm.study.pojo.vos.question.TestQuestionVO;
import ink.wgink.exceptions.RemoveException;
import ink.wgink.exceptions.SearchException;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.pojo.result.SuccessResultData;
import ink.wgink.pojo.result.SuccessResultList;
import ink.wgink.pojo.result.UploadExcelResultDTO;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* @ClassName: IQuestionService
* @Description: 试题管理
* @Author: WenG
* @Date: 2020-09-09 21:00
* @Version: 1.0
**/
public interface ITestQuestionService {
/**
* 新增试题管理
*
* @param questionVO
* @return
* @throws Exception
*/
SuccessResult save(TestQuestionVO questionVO) throws Exception;
/**
* @return
* @throws Exception
*/
SuccessResult saveByToken(String token, TestQuestionVO questionVO) throws Exception;
/**
* 新增试题管理
*
* @param questionVO
* @return questionId
* @throws Exception
*/
String saveReturnId(TestQuestionVO questionVO) throws Exception;
/**
* 新增试题管理(APP)
*
* @param token
* @param questionVO
* @return questionId
* @throws Exception
*/
String saveByTokenReturnId(String token, TestQuestionVO questionVO) throws Exception;
/**
* 删除试题管理
*
* @param ids
* @return
* @throws RemoveException
*/
void remove(List<String> ids) throws RemoveException;
/**
* 删除试题管理物理删除
*
* @param ids
* @throws RemoveException
*/
void delete(String ids) throws RemoveException;
/**
* 删除试题管理(APP)
*
* @param token
* @param ids
* @return
* @throws RemoveException
*/
void removeByToken(String token, List<String> ids) throws RemoveException;
/**
* 修改试题管理
*
* @param questionId
* @param questionVO
* @return
* @throws Exception
*/
SuccessResult update(String questionId, TestQuestionVO questionVO) throws Exception;
/**
* 修改试题管理(APP)
*
* @param token
* @param questionId
* @param questionVO
* @return
* @throws Exception
*/
SuccessResult updateByToken(String token, String questionId, TestQuestionVO questionVO) throws Exception;
/**
* 试题管理详情(通过ID)
*
* @param questionId
* @return
* @throws SearchException
*/
QuestionDTO getById(String questionId) throws SearchException;
/**
* 试题管理列表
*
* @param params
* @return
* @throws SearchException
*/
List<QuestionDTO> list(Map<String, Object> params) throws SearchException;
/**
* 试题列表
*
* @param questionIds
* @return
*/
List<QuestionDTO> listByIds(List<String> questionIds);
/**
* 试题管理分页列表
*
* @param page
* @return
* @throws SearchException
*/
SuccessResultList<List<QuestionDTO>> listPage(ListPage page) throws SearchException;
/**
* 试题管理统计
*
* @param params
* @return
* @throws SearchException
*/
Integer countNumberQuestion(Map<String, Object> params) throws SearchException;
/**
* 试题导入Excel
* @param excel
* @return
* @throws IOException
*/
UploadExcelResultDTO importExcel(MultipartFile excel) throws IOException;
/**
* 更新自定义问题类型
*
* @param updateType
* @param questionTypeId
* @param questionIds
*/
void updateCustomQuestionType(String questionTypeId, List<String> questionIds);
/**
* 删除自定义问题类型
*
* @param updateType
* @param questionTypeId
* @param questionIds
*/
void removeCustomQuestionType(String questionTypeId, List<String> questionIds);
}

View File

@ -0,0 +1,634 @@
package ink.wgink.module.examine.service.test.impl;
import com.alibaba.excel.EasyExcel;
import com.cm.study.dao.question.IQuestionDao;
import com.cm.study.enums.QuestionChoiceTypeEnum;
import com.cm.study.enums.QuestionTypeEnum;
import com.cm.study.listener.question.QuestionExcel;
import com.cm.study.listener.question.QuestionExcelError;
import com.cm.study.listener.question.QuestionExcelListener;
import com.cm.study.pojo.dtos.classquestion.ClassQuestionDTO;
import com.cm.study.pojo.dtos.question.QuestionDTO;
import com.cm.study.pojo.dtos.questionoptions.QuestionOptionsDTO;
import com.cm.study.pojo.dtos.questiontype.QuestionTypeDTO;
import com.cm.study.pojo.dtos.schoolteacher.SchoolTeacherDTO;
import com.cm.study.pojo.pos.question.QuestionPO;
import com.cm.study.pojo.vos.question.QuestionVO;
import com.cm.study.pojo.vos.questionoptions.QuestionOptionsVO;
import com.cm.study.service.BaseService;
import com.cm.study.service.classquestion.IClassQuestionService;
import com.cm.study.service.examinationpaperquestion.IExaminationPaperQuestionService;
import com.cm.study.service.question.IQuestionService;
import com.cm.study.service.questionoptions.IQuestionOptionsService;
import com.cm.study.service.questiontype.IQuestionTypeService;
import com.cm.study.service.schoolteacher.ISchoolTeacherService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.exceptions.RemoveException;
import ink.wgink.exceptions.SearchException;
import ink.wgink.module.dictionary.pojo.dtos.DataDTO;
import ink.wgink.module.dictionary.service.IDataService;
import ink.wgink.module.examine.service.test.ITestQuestionService;
import ink.wgink.module.file.excel.error.AbstractErrorExcelHandler;
import ink.wgink.module.file.service.IFileService;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.pojo.result.SuccessResultData;
import ink.wgink.pojo.result.SuccessResultList;
import ink.wgink.pojo.result.UploadExcelResultDTO;
import ink.wgink.util.UUIDUtil;
import ink.wgink.util.map.HashMapUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.*;
/**
* @ClassName: QuestionServiceImpl
* @Description: 试题管理
* @Author: WenG
* @Date: 2020-09-09 21:00
* @Version: 1.0
**/
@Service
public class TestQuestionServiceImpl extends DefaultBaseService implements ITestQuestionService {
@Autowired
private IQuestionDao questionDao;
@Autowired
private IQuestionOptionsService questionOptionsService;
@Autowired
private IClassQuestionService classQuestionService;
@Autowired
private ISchoolTeacherService schoolTeacherService;
@Autowired
private IDataService dataService;
@Autowired
private IFileService fileService;
@Autowired
private IQuestionTypeService questionTypeService;
@Autowired
private IExaminationPaperQuestionService examinationPaperQuestionService;
@Override
public SuccessResult saveQuestion(QuestionVO questionVO) throws Exception {
saveQuestionInfo(null, questionVO);
return new SuccessResult();
}
@Override
public SuccessResult saveQuestionByToken(String token, QuestionVO questionVO) throws Exception {
saveQuestionInfo(token, questionVO);
return new SuccessResult();
}
@Override
public String saveQuestionReturnId(QuestionVO questionVO) throws Exception {
return saveQuestionInfo(null, questionVO);
}
@Override
public String saveQuestionByTokenReturnId(String token, QuestionVO questionVO) throws Exception {
return saveQuestionInfo(token, questionVO);
}
/**
* 新增试题管理
*
* @param token
* @param questionVO
* @throws Exception
*/
private String saveQuestionInfo(String token, QuestionVO questionVO) throws Exception {
String questionId = saveQuestionInfoReturnId(token, questionVO);
boolean hasOption = StringUtils.equals(questionVO.getType(), QuestionTypeEnum.CHOICE.getValue())
|| StringUtils.equals(questionVO.getType(), QuestionTypeEnum.TURE_OR_FALSE.getValue());
if (!hasOption) {
return questionId;
}
// 保存选项
for (QuestionOptionsVO questionOptionsVO : questionVO.getQuestionOptions()) {
questionOptionsVO.setQuestionId(questionId);
questionOptionsService.saveQuestionOptionsByToken(token, questionOptionsVO);
}
return questionId;
}
/**
* 新增试题管理
*
* @param token
* @param questionVO
* @return questionId
* @throws Exception
*/
private String saveQuestionInfoReturnId(String token, QuestionVO questionVO) throws Exception {
questionVO.setSubject(questionVO.getSubject().replaceAll("\\s", ""));
QuestionPO questionPO = getPO(questionVO.getSubject());
if (questionPO != null) {
throw new SearchException("题目已经存在");
}
String questionId = UUIDUtil.getUUID();
Map<String, Object> params = HashMapUtil.beanToMap(questionVO);
params.put("questionId", questionId);
if (token != null) {
setAppSaveInfo(token, params);
} else {
setSaveInfo(params);
}
questionDao.saveQuestion(params);
return questionId;
}
@Override
public void removeQuestion(List<String> ids) throws RemoveException {
removeQuestionInfo(null, ids);
}
@Override
public void removeQuestionByToken(String token, List<String> ids) throws RemoveException {
removeQuestionInfo(token, ids);
}
/**
* 删除试题管理
*
* @param token
* @param ids
*/
private void removeQuestionInfo(String token, List<String> ids) {
checkQuestionUse(ids);
Map<String, Object> params = getHashMap(3);
params.put("questionIds", ids);
if (token != null) {
setAppUpdateInfo(token, params);
} else {
setUpdateInfo(params);
}
questionDao.removeQuestion(params);
}
@Override
public void deleteQuestion(String ids) throws RemoveException {
Map<String, Object> params = getHashMap(3);
params.put("questionIds", Arrays.asList(ids.split("_")));
questionDao.deleteQuestion(params);
}
@Override
public SuccessResult updateQuestion(String questionId, QuestionVO questionVO) throws Exception {
updateQuestionInfo(null, questionId, questionVO);
return new SuccessResult();
}
@Override
public SuccessResult updateQuestionByToken(String token, String questionId, QuestionVO questionVO) throws Exception {
updateQuestionInfo(token, questionId, questionVO);
return new SuccessResult();
}
/**
* 修改试题管理
*
* @param token
* @param questionId
* @param questionVO
*/
private void updateQuestionInfo(String token, String questionId, QuestionVO questionVO) throws Exception {
checkQuestionUse(Arrays.asList(questionId));
Map<String, Object> params = HashMapUtil.beanToMap(questionVO);
params.put("questionId", questionId);
if (token != null) {
setAppUpdateInfo(token, params);
} else {
setUpdateInfo(params);
}
questionDao.updateQuestion(params);
// 判断是否更新选项
boolean hasOption = StringUtils.equals(questionVO.getType(), QuestionTypeEnum.CHOICE.getValue())
|| StringUtils.equals(questionVO.getType(), QuestionTypeEnum.TURE_OR_FALSE.getValue());
if (!hasOption) {
return;
}
// 删除原有选项
questionOptionsService.deleteQuestionOptionsByQuestionId(questionId);
// 重新添加新选项
for (QuestionOptionsVO questionOptionsVO : questionVO.getQuestionOptions()) {
questionOptionsVO.setQuestionId(questionId);
questionOptionsService.saveQuestionOptionsByToken(token, questionOptionsVO);
}
}
/**
* 判断试题是否已经使用已经使用的试题无法修改
*
* @param questionIds
*/
private void checkQuestionUse(List<String> questionIds) {
List<String> useQuestionIds = examinationPaperQuestionService.listQuestionIds(questionIds);
if (!useQuestionIds.isEmpty()) {
throw new SearchException("无法处理,试题已经被使用");
}
}
private QuestionPO getPO(Map<String, Object> params) {
return questionDao.getPO(params);
}
public QuestionPO getPO(String subject) {
Map<String, Object> params = getHashMap(2);
params.put("subject", subject);
return getPO(params);
}
@Override
public QuestionDTO getQuestionById(String questionId) throws SearchException {
Map<String, Object> params = super.getHashMap(1);
params.put("questionId", questionId);
QuestionDTO questionDTO = questionDao.getQuestion(params);
boolean hasOption = StringUtils.equals(questionDTO.getType(), QuestionTypeEnum.CHOICE.getValue())
|| StringUtils.equals(questionDTO.getType(), QuestionTypeEnum.TURE_OR_FALSE.getValue());
if (hasOption) {
List<QuestionOptionsDTO> questionOptionsDTOs = questionOptionsService.listQuestionOptionsByQuestionId(questionId);
questionDTO.setQuestionOptions(questionOptionsDTOs);
}
if (!StringUtils.isBlank(questionDTO.getCustomQuestionType())) {
// 加载自定义问题类型
List<String> questionTypeIds = Arrays.asList(questionDTO.getCustomQuestionType().split(","));
List<QuestionTypeDTO> questionTypeDTOs = questionTypeService.list(questionTypeIds);
questionDTO.setCustomQuestionTypeName(getCustomQuestionTypeNames(questionDTO.getCustomQuestionType(), questionTypeDTOs));
}
return questionDTO;
}
@Override
public List<QuestionDTO> listQuestion(Map<String, Object> params) throws SearchException {
if (params.get("customQuestionType") != null && !StringUtils.isBlank(params.get("customQuestionType").toString())) {
params.put("customQuestionTypes", Arrays.asList(params.get("customQuestionType").toString().split(",")));
params.remove("customQuestionType");
}
List<QuestionDTO> questionDTOs = questionDao.listQuestion(params);
// 试题类型
List<DataDTO> dataDTOs = dataService.listByParentId(QUESTION_TYPE_ID);
for (QuestionDTO questionDTO : questionDTOs) {
String questionTypeName = questionDTO.getQuestionType();
if (StringUtils.isBlank(questionTypeName)) {
continue;
}
for (DataDTO dataDTO : dataDTOs) {
questionTypeName = questionTypeName.replace(dataDTO.getDataId(), dataDTO.getDataName());
}
questionDTO.setQuestionTypeName(questionTypeName);
}
// 自定义试题类型
Set<String> customQuestionTypeSet = new HashSet<>();
for (QuestionDTO questionDTO : questionDTOs) {
String customQuestionTypes = questionDTO.getCustomQuestionType();
if (StringUtils.isBlank(customQuestionTypes)) {
continue;
}
String[] customQuestionTypeArray = customQuestionTypes.split(",");
for (String customQuestionType : customQuestionTypeArray) {
if (StringUtils.isBlank(customQuestionType)) {
continue;
}
customQuestionTypeSet.add(customQuestionType);
}
}
if (!customQuestionTypeSet.isEmpty()) {
String[] customQuestionTypeArray = new String[customQuestionTypeSet.size()];
List<String> questionTypeIds = Arrays.asList(customQuestionTypeSet.toArray(customQuestionTypeArray));
List<QuestionTypeDTO> questionTypeDTOs = questionTypeService.list(questionTypeIds);
for (QuestionDTO questionDTO : questionDTOs) {
String customQuestionTypes = questionDTO.getCustomQuestionType();
if (StringUtils.isBlank(customQuestionTypes)) {
continue;
}
questionDTO.setCustomQuestionTypeName(getCustomQuestionTypeNames(customQuestionTypes, questionTypeDTOs));
}
}
// 设置试题使用状态
setQuestionUsed(questionDTOs);
return questionDTOs;
}
@Override
public List<QuestionDTO> listByIds(List<String> questionIds) {
Map<String, Object> params = getHashMap(2);
params.put("questionIds", questionIds);
return listQuestion(params);
}
/**
* 设置试题是否被使用
*
* @param questionDTOs
*/
private void setQuestionUsed(List<QuestionDTO> questionDTOs) {
if (questionDTOs.isEmpty()) {
return;
}
Set<String> questionIdSet = new HashSet<>();
questionDTOs.forEach(questionDTO -> questionIdSet.add(questionDTO.getQuestionId()));
List<String> useQuestionIds = examinationPaperQuestionService.listQuestionIds(new ArrayList<>(questionIdSet));
questionDTOs.forEach(questionDTO -> {
for (String questionId : useQuestionIds) {
if (StringUtils.equals(questionDTO.getQuestionId(), questionId)) {
questionDTO.setUsed(true);
}
}
});
}
/**
* 处理自定义问题类型名称
*
* @param customQuestionTypes
* @param questionTypeDTOs
* @return
*/
private String getCustomQuestionTypeNames(String customQuestionTypes, List<QuestionTypeDTO> questionTypeDTOs) {
String customQuestionTypeNames = "";
for (QuestionTypeDTO questionTypeDTO : questionTypeDTOs) {
if (!customQuestionTypes.contains(questionTypeDTO.getQuestionTypeId())) {
continue;
}
if (customQuestionTypeNames.length() > 0) {
customQuestionTypeNames += ",";
}
customQuestionTypeNames += questionTypeDTO.getTypeName();
}
return customQuestionTypeNames;
}
@Override
public SuccessResultList<List<QuestionDTO>> listPageQuestion(ListPage page) throws SearchException {
PageHelper.startPage(page.getPage(), page.getRows());
List<QuestionDTO> questionDTOs = listQuestion(page.getParams());
PageInfo<QuestionDTO> pageInfo = new PageInfo<>(questionDTOs);
return new SuccessResultList<>(questionDTOs, pageInfo.getPageNum(), pageInfo.getTotal());
}
@Override
public SuccessResultList<List<QuestionDTO>> listPageAdmin(ListPage page) throws SearchException {
List<SchoolTeacherDTO> schoolTeacherDTOs = schoolTeacherService.listSimpleBySchoolId(getAdminSchoolId());
List<String> creators = new ArrayList<>();
creators.add(securityComponent.getCurrentUser().getUserId());
for (SchoolTeacherDTO schoolTeacherDTO : schoolTeacherDTOs) {
creators.add(schoolTeacherDTO.getUserId());
}
page.getParams().put("creators", creators);
return listPageQuestion(page);
}
@Override
public SuccessResultList<List<QuestionDTO>> listPageTeacher(ListPage page) throws SearchException {
page.getParams().put("creator", securityComponent.getCurrentUser().getUserId());
return listPageQuestion(page);
}
@Override
public Integer countNumberQuestion(Map<String, Object> params) throws SearchException {
Integer count = questionDao.countQuestion(params);
return count == null ? 0 : count;
}
@Override
public SuccessResultData<Integer> countQuestion(Map<String, Object> params) throws SearchException {
return new SuccessResultData<>(countNumberQuestion(params));
}
@Override
public List<String> listRandomQuestionIdByRandomCountAndTypeAndChoiceType(int randomCount, QuestionTypeEnum type, QuestionChoiceTypeEnum choiceType) throws SearchException {
Map<String, Object> params = getHashMap(4);
params.put("type", type.getValue());
params.put("choiceType", choiceType == null ? null : choiceType.getValue());
List<String> questionIds = questionDao.listQuestionIds(params);
// 试题数小于随机总数返回全部试题ID
if (questionIds.size() <= randomCount) {
return questionIds;
}
Random random = new Random(System.currentTimeMillis());
Map<Integer, String> randomMap = new HashMap<>(randomCount * 2);
while (randomMap.size() < randomCount) {
int randomNumber = random.nextInt(questionIds.size());
randomMap.put(randomNumber, questionIds.get(randomNumber));
}
List<String> randomQuestionIds = new ArrayList<>();
for (Map.Entry<Integer, String> kv : randomMap.entrySet()) {
randomQuestionIds.add(kv.getValue());
}
return randomQuestionIds;
}
@Override
public List<QuestionDTO> listQuestionByExaminationPagerId(String examinationPaperId) throws SearchException {
return questionDao.listQuestionByExaminationPagerId(examinationPaperId);
}
@Override
public SuccessResultList<List<QuestionDTO>> listPageExcept(ListPage page) {
return null;
}
@Override
public SuccessResultList<List<QuestionDTO>> listPageExcept(String classInfoId, ListPage page) throws SearchException {
List<ClassQuestionDTO> classQuestionDTOs = classQuestionService.listSimple(classInfoId);
List<String> withoutQuestionIds = new ArrayList<>();
for (ClassQuestionDTO classQuestionDTO : classQuestionDTOs) {
withoutQuestionIds.add(classQuestionDTO.getQuestionId());
}
page.getParams().put("withoutQuestionIds", withoutQuestionIds);
return listPageQuestion(page);
}
@Override
public SuccessResultList<List<QuestionDTO>> listPageExceptAdmin(String classInfoId, ListPage page) throws SearchException {
List<SchoolTeacherDTO> schoolTeacherDTOs = schoolTeacherService.listSimpleBySchoolId(getAdminSchoolId());
// 学校列表列出超级管理员当前管理员和全部学校老师的试题
List<String> creators = new ArrayList<>();
creators.add(securityComponent.getCurrentUser().getUserId());
creators.add("1");
for (SchoolTeacherDTO schoolTeacherDTO : schoolTeacherDTOs) {
creators.add(schoolTeacherDTO.getUserId());
}
page.getParams().put("creators", creators);
return listPageExcept(classInfoId, page);
}
@Override
public SuccessResultList<List<QuestionDTO>> listPageExceptTeacher(String classInfoId, ListPage page) throws SearchException {
List<String> creators = new ArrayList<>();
// 列出超级管理员当前老师的试题
creators.add(securityComponent.getCurrentUser().getUserId());
creators.add("1");
page.getParams().put("creators", creators);
return listPageExcept(classInfoId, page);
}
@Override
public SuccessResultList<List<ClassQuestionDTO>> listPageOfMine(String token, String classInfoId, ListPage page) {
page.getParams().put(KEY_IS_STUDENT, "isStudent");
return classQuestionService.listPage(classInfoId, page);
}
@Override
public UploadExcelResultDTO importExcel(MultipartFile excel) throws IOException {
Map<String, Object> params = getHashMap(16);
// 错误列表
List<QuestionExcelError> questionExcelErrors = new ArrayList<>();
long startTime = System.currentTimeMillis();
LOG.debug("读取Excel");
EasyExcel.read(excel.getInputStream(), QuestionExcel.class, new QuestionExcelListener() {
@Override
public void readList(List<QuestionExcel> questionExcels) {
for (QuestionExcel questionExcel : questionExcels) {
try {
QuestionVO questionVO = new QuestionVO();
if (StringUtils.equals(QuestionExcelListener.QUESTION_CHOICE, questionExcel.getType())) {
questionVO.setType(QuestionTypeEnum.CHOICE.getValue());
if (StringUtils.equals(QuestionExcelListener.QUESTION_CHOICE_SINGLE, questionExcel.getKind())) {
questionVO.setChoiceType(QuestionChoiceTypeEnum.SINGLE.getValue());
} else if (StringUtils.equals(QuestionExcelListener.QUESTION_CHOICE_MULTIPLE, questionExcel.getKind())) {
questionVO.setChoiceType(QuestionChoiceTypeEnum.MULTIPLE.getValue());
} else {
throw new Exception("选择类型错误,只能是“单选”,“多选”");
}
if (questionExcel.getOptions().isEmpty()) {
throw new Exception("选择选项不能为空");
}
} else if (StringUtils.equals(QuestionExcelListener.QUESTION_TRUE_OR_FALSE, questionExcel.getType())) {
questionVO.setType(QuestionTypeEnum.TURE_OR_FALSE.getValue());
} else if (StringUtils.equals(QuestionExcelListener.QUESTION_FILL_IN_THE_BLANKS, questionExcel.getType())) {
questionVO.setType(QuestionTypeEnum.FILL_IN_THE_BLANKS.getValue());
} else if (StringUtils.equals(QuestionExcelListener.QUESTION_ANSWER, questionExcel.getType())) {
questionVO.setType(QuestionTypeEnum.ANSWER.getValue());
} else {
throw new Exception("选择类型错误,只能是“选择题”,“判断题”,“填空题”,“解答题”");
}
if (!StringUtils.equals(QuestionExcelListener.QUESTION_ANSWER, questionExcel.getType()) &&
!StringUtils.equals(QuestionExcelListener.QUESTION_FILL_IN_THE_BLANKS, questionExcel.getType())) {
if (questionExcel.getOptions().isEmpty()) {
throw new Exception("选项不能为空");
}
List<QuestionOptionsVO> questionOptions = new ArrayList<>();
for (int i = 0; i < questionExcel.getOptions().size(); i++) {
String optionContent = questionExcel.getOptions().get(i);
if (StringUtils.isBlank(optionContent)) {
throw new Exception("选线有空值");
}
QuestionOptionsVO questionOptionsVO = new QuestionOptionsVO();
questionOptionsVO.setOption(Character.toString((char) (65 + i)));
questionOptionsVO.setContent(optionContent);
questionOptions.add(questionOptionsVO);
}
questionVO.setQuestionOptions(questionOptions);
}
questionVO.setAnalysis("<p>" + questionExcel.getAnalysis() + "<br></p>");
questionVO.setAnswer(questionExcel.getAnswer().replaceAll(",", "\\$_WenG_\\$").replaceAll("\\s", ""));
questionVO.setDifficulty(questionExcel.getDifficulty());
questionVO.setSubject("<p>" + questionExcel.getTitle() + "<br></p>");
saveQuestionInfo(null, questionVO);
} catch (Exception e) {
e.printStackTrace();
questionExcelErrors.add(getQuestionExcelError(questionExcel.getNo(), questionExcel.getTitle(), e.getMessage()));
}
}
}
}).headRowNumber(2).sheet().doRead();
long endTime = System.currentTimeMillis();
String excelFileId = null;
if (questionExcelErrors.size() > 0) {
excelFileId = new AbstractErrorExcelHandler<QuestionExcelError>(fileService) {
@Override
public List<List<String>> excelHeaderNames() {
return simpleExcelHeader(new String[]{"序号", "标题", "错误原因"});
}
}.saveErrorExcel(questionExcelErrors);
}
return new UploadExcelResultDTO(questionExcelErrors.size(), endTime - startTime, excelFileId);
}
@Override
public void updateCustomQuestionType(String questionTypeId, List<String> questionIds) {
if (questionIds.isEmpty()) {
return;
}
List<QuestionPO> questionPOs = listPOByIds(questionIds);
Map<String, Object> params = getHashMap(4);
for (QuestionPO questionPO : questionPOs) {
String customQuestionType = questionPO.getCustomQuestionType();
if (customQuestionType != null && customQuestionType.contains(questionTypeId)) {
continue;
}
if (StringUtils.isBlank(customQuestionType)) {
customQuestionType = questionTypeId;
} else {
customQuestionType += ("," + questionTypeId);
}
params.put("customQuestionType", customQuestionType);
params.put("questionId", questionPO.getQuestionId());
questionDao.updateCustomQuestionType(params);
}
}
@Override
public void removeCustomQuestionType(String questionTypeId, List<String> questionIds) {
if (questionIds.isEmpty()) {
return;
}
List<QuestionPO> questionPOs = listPOByIds(questionIds);
Map<String, Object> params = getHashMap(4);
for (QuestionPO questionPO : questionPOs) {
String customQuestionType = questionPO.getCustomQuestionType();
if (customQuestionType == null || !customQuestionType.contains(questionTypeId)) {
continue;
}
customQuestionType = customQuestionType.replaceAll(questionTypeId, "");
// 去除中间逗号
customQuestionType = customQuestionType.replaceAll(",,", ",");
// 去除第一个逗号
if (customQuestionType.startsWith(",")) {
customQuestionType = customQuestionType.substring(1);
}
// 去除最后逗号
if (customQuestionType.endsWith(",")) {
customQuestionType = customQuestionType.substring(0, customQuestionType.length() - 1);
}
params.put("customQuestionType", customQuestionType);
params.put("questionId", questionPO.getQuestionId());
questionDao.updateCustomQuestionType(params);
}
}
private List<QuestionPO> listPOByIds(List<String> questionIds) {
Map<String, Object> params = getHashMap(2);
params.put("questionIds", questionIds);
return questionDao.listPO(params);
}
/**
* Excel错误信息
*
* @param no
* @param title
* @param reason
* @return
*/
private QuestionExcelError getQuestionExcelError(Integer no, String title, String reason) {
QuestionExcelError questionExcelError = new QuestionExcelError();
questionExcelError.setNo(no);
questionExcelError.setTitle(title);
questionExcelError.setReason(reason);
return questionExcelError;
}
}

File diff suppressed because one or more lines are too long