修改题目相关功能

master
xiaoCJ 6 months ago
parent 5b034247f8
commit 88e01b4b63

@ -55,7 +55,7 @@ public class BaseController extends Base {
String token = request.getHeader("Tz-Token");
if(StringUtils.isEmpty(token)){
// throw new BaseException("没有权限");
return null;
return null;
}
try {
DecodedJWT d = JWTUtil.verify(token);

@ -7,11 +7,13 @@ import lombok.Getter;
@AllArgsConstructor
public enum QuestionTypeEnum {
//单选
SINGLE(1,"单选"),
SINGLE(1,"单选"),
//多选
MULTY(2,"多选"),
MULTY(2,"多选"),
//判断
JUDGE(3,"判断");
JUDGE(3,"判断题"),
//填空
GAPFILLING(4,"填空题");
/**
*
*/

@ -29,7 +29,7 @@ public class ExcelUtil {
private InputStream is;
private Workbook excel;
//获取第一个sheet
public Sheet sheet0 ;
public static Sheet sheet0 ;
private Font defaultFont;
@ -37,6 +37,9 @@ public class ExcelUtil {
private CellStyle numStyle ;
public static void initSheet(Workbook workbook) {
sheet0 = workbook.getSheetAt(0);
}
public ExcelUtil(){
initNumStyle();

@ -65,6 +65,15 @@ public class TeamMemberImportBiz {
e.printStackTrace();
}
// // 过滤掉全空或字段都是null的记录 这个操作暂时不做
// personList = personList.stream()
// .filter(person -> person != null
// && (person.getStudentNo() != null && !person.getStudentNo().trim().isEmpty()
// || person.getName() != null && !person.getName().trim().isEmpty()
// || person.getClassName() != null && !person.getClassName().trim().isEmpty()
// || person.getSchoolName() != null && !person.getSchoolName().trim().isEmpty()))
// .collect(Collectors.toList());
//
List<String> collect = personList.stream().map(p -> p.getStudentNo()).filter(Objects::nonNull).collect(Collectors.toList());
List<User> allStu = userDao.findAllByStudentNoIn(collect);
if (allStu.isEmpty()){
@ -129,12 +138,12 @@ public class TeamMemberImportBiz {
List<CompetitionMember> newMembers = competitionMembers.stream()
.filter(member -> memberDao.findByCompetitionIdAndStudentNoAndSchool(competitionId,member.getStudentNo(), member.getSchool()).isEmpty())
.collect(Collectors.toList());
if (!newMembers.isEmpty()) {
memberDao.saveAll(newMembers);
if (!competitionMembers.isEmpty()) {
memberDao.saveAll(competitionMembers);
updatePeopleCount(competitionId);
return Result.success("success");
} else {
return Result.success("No new members to save.");
return Result.error("没有正确的用户");
}
}

@ -9,4 +9,5 @@ public class QuestionContDTO implements Serializable {
private Integer singleCount;
private Integer multiCount;
private Integer judgeCount;
private Integer gapFilling;
}

@ -11,6 +11,8 @@ import com.tz.platform.pc.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(value = "/pc/question")
public class PCQuestionController extends BaseController {
@ -19,42 +21,51 @@ public class PCQuestionController extends BaseController {
private PCQuestionBiz questionBiz;
@PostMapping(value = "list")
public Result<PageQuestionDTO> list(@RequestBody PageQuestionVO questionVO){
public Result<PageQuestionDTO> list(@RequestBody PageQuestionVO questionVO) {
return questionBiz.list(questionVO);
}
@PostMapping(value = "add")
public Result<Long> add(@RequestBody QuestionVO questionVo){
public Result<Long> add(@RequestBody QuestionVO questionVo) {
return questionBiz.add(questionVo);
}
@PostMapping(value = "update")
public Result<String> update(@RequestBody QuestionUpdateVO questionVo){
public Result<String> update(@RequestBody QuestionUpdateVO questionVo) {
return questionBiz.update(questionVo);
}
@PostMapping(value = "delete")
public Result<String> delete(@RequestBody QuestionVO questionVO){
public Result<String> delete(@RequestBody QuestionVO questionVO) {
return questionBiz.delete(questionVO);
}
@PostMapping(value = "get")
public Result<QuestionDTO> get(@RequestBody QuestionVO questionVO){
return questionBiz.get(questionVO);
public Result<QuestionDTO> get(@RequestBody QuestionVO questionVO) {
return questionBiz.get(questionVO);
}
@PostMapping(value = "batchupdate")
public Result<String> batchUpate(@RequestBody BatchQuestionVO vo){
public Result<String> batchUpate(@RequestBody BatchQuestionVO vo) {
return questionBiz.batch(vo);
}
@PostMapping(value = "listByIds")
public Result<ListQuestionDTO> listByIds(@RequestBody ListQuestionVO vo){
public Result<ListQuestionDTO> listByIds(@RequestBody ListQuestionVO vo) {
return questionBiz.listByIds(vo);
}
@GetMapping(value = "getCount")
public Result<QuestionContDTO> getCount(){
return questionBiz.getCount();
public Result<QuestionContDTO> getCount(@RequestBody(required = false) List<Long> ids) {
return questionBiz.getCount(ids);
}
//todo 随机抽取逻辑
//1、展示所有课程信息供选择使用。已有 使用下拉框
//2、根据选择的一个或多个课程ID查出总共的题型数量 改造完成 getCount
//3、根据用户设置的各个题型的数量组成考试这一步应该是前端完成
}

@ -3,22 +3,28 @@ package com.tz.platform.pc;
import com.tz.platform.common.core.base.BaseController;
import com.tz.platform.common.core.base.Result;
import com.tz.platform.pc.biz.QuestionImportBiz;
import com.tz.platform.pc.dto.ListQuestionImportDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value = "/api/question/")
@RequestMapping(value = "/api/question")
public class PCQuestionImportController extends BaseController {
@Autowired
private QuestionImportBiz importBiz;
// @PostMapping(value = "importExcel")
// public Result<ListQuestionImportDTO> importExcel(MultipartFile file) {
// return importBiz.importExcel(file,getUserNo());
// }
@PostMapping(value = "importExcel")
public Result<ListQuestionImportDTO> importExcell(MultipartFile file){
return importBiz.importExcel(file,getUserNo());
public Result<String> importExcel(MultipartFile file,
@RequestParam Long courseId) throws Exception {
return importBiz.importExcel11(file, getUserNo(), courseId);
}
}

@ -27,106 +27,107 @@ public class PCQuestionBiz {
private QuestionDao questionDao;
@Autowired
private IFeignUser feignUser ;
private IFeignUser feignUser;
public Result<PageQuestionDTO> list(PageQuestionVO questionVO){
public Result<PageQuestionDTO> list(PageQuestionVO questionVO) {
PageQuestionDTO questionDTO = new PageQuestionDTO();
Integer pageNo = questionVO.getPageNo()-1;
if(pageNo< 0){
Integer pageNo = questionVO.getPageNo() - 1;
if (pageNo < 0) {
pageNo = 0;
}
if(questionVO.getPageSize()==null){
if (questionVO.getPageSize() == null) {
questionVO.setPageSize(20);
}
Sort sort = Sort.by(Sort.Direction.DESC,"id");
Pageable pageable = PageRequest.of(pageNo,questionVO.getPageSize(),sort);
Page<Question> questions =null;
Sort sort = Sort.by(Sort.Direction.DESC, "id");
Pageable pageable = PageRequest.of(pageNo, questionVO.getPageSize(), sort);
Page<Question> questions = null;
Long questionId = 0L;
if(StringUtils.hasText(questionVO.getStem())){
if (StringUtils.hasText(questionVO.getStem())) {
String regex = "\\d+";
if(questionVO.getStem().matches(regex)){
if (questionVO.getStem().matches(regex)) {
questionId = Long.parseLong(questionVO.getStem());
List<Long> ids = new ArrayList<>();
ids.add(questionId);
questions = questionDao.findAllByIdIn(ids,pageable);
questions = questionDao.findAllByIdIn(ids, pageable);
return Result.success(questionDTO.setPage(questions));
}
}
Question question = new Question();
BeanUtils.copyProperties(questionVO,question);
if(question.getScore()!=null&&question.getScore() == 0){
BeanUtils.copyProperties(questionVO, question);
if (question.getScore() != null && question.getScore() == 0) {
question.setScore(null);
}
ExampleMatcher exampleMatcher = ExampleMatcher.matching().withIgnoreNullValues();
if(StringUtils.isEmpty(questionVO.getStem())){
if (StringUtils.isEmpty(questionVO.getStem())) {
exampleMatcher = exampleMatcher.withIgnorePaths("stem");
}
Example example = Example.of(question,exampleMatcher);
questions = questionDao.findAll( example ,pageable);
return Result.success(questionDTO.setPage(questions));
Example example = Example.of(question, exampleMatcher);
questions = questionDao.findAll(example, pageable);
return Result.success(questionDTO.setPage(questions));
}
public Result<Long> add(QuestionVO questionVo){
Result<Long> v = valid(questionVo);
if(v.getCode()!=200){
public Result<Long> add(QuestionVO questionVo) {
Result<Long> v = valid(questionVo);
if (v.getCode() != 200) {
return v;
}
UserVo user =feignUser.getByUserNo(questionVo.getUserNo());
UserVo user = feignUser.getByUserNo(questionVo.getUserNo());
Question question = new Question();
BeanUtils.copyProperties(questionVo,question);
BeanUtils.copyProperties(questionVo, question);
question.setCreatorId(questionVo.getUserNo());
question.setCreateTime(new Date());
question.setCreator(user.getName());
question.setStatus(0);
question = questionDao.save(question);
return Result.success(question.getId());
return Result.success(question.getId());
}
public Result<String> update(QuestionUpdateVO questionVO){
if(!StringUtils.hasText(questionVO.getStem())){
public Result<String> update(QuestionUpdateVO questionVO) {
if (!StringUtils.hasText(questionVO.getStem())) {
return Result.error("题干不能为空");
}
if(!StringUtils.hasText(questionVO.getAnalysis())){
if (!StringUtils.hasText(questionVO.getAnalysis())) {
return Result.error("解析不能为空");
}
if(questionVO.getAnswerId() == null ||questionVO.getAnswerId().size()<=0){
if (questionVO.getAnswerId() == null || questionVO.getAnswerId().size() <= 0) {
return Result.error("答案不能为空");
}
if(questionVO.getCourseId()==null||questionVO.getCourseId()<=0){
return Result.error("请选择课程");
if (questionVO.getCourseId() == null || questionVO.getCourseId() <= 0) {
return Result.error("请选择课程");
}
if(questionVO.getLevelId()==null||questionVO.getLevelId()<=0){
if (questionVO.getLevelId() == null || questionVO.getLevelId() <= 0) {
return Result.error("请选择课程层次");
}
Question question = questionDao.getById(questionVO.getId());
BeanUtils.copyProperties(questionVO,question);
BeanUtils.copyProperties(questionVO, question);
questionDao.save(question);
return Result.success("success");
}
private Result<Long> valid(QuestionVO questionVO){
if(!StringUtils.hasText(questionVO.getStem())){
private Result<Long> valid(QuestionVO questionVO) {
if (!StringUtils.hasText(questionVO.getStem())) {
return Result.error("题干不能为空");
}
if(!StringUtils.hasText(questionVO.getAnalysis())){
if (!StringUtils.hasText(questionVO.getAnalysis())) {
return Result.error("解析不能为空");
}
if(questionVO.getAnswerId() == null ||questionVO.getAnswerId().size()<=0){
if (questionVO.getAnswerId() == null || questionVO.getAnswerId().size() <= 0) {
return Result.error("答案不能为空");
}
if(questionVO.getCourseId()==null||questionVO.getCourseId()<=0){
return Result.error("请选择课程");
if (questionVO.getCourseId() == null || questionVO.getCourseId() <= 0) {
return Result.error("请选择课程");
}
if(questionVO.getLevelId()==null||questionVO.getLevelId()<=0){
if (questionVO.getLevelId() == null || questionVO.getLevelId() <= 0) {
return Result.error("请选择课程层次");
}
@ -136,42 +137,57 @@ public class PCQuestionBiz {
return Result.success(0L);
}
public Result<String> delete(QuestionVO questionVO){
public Result<String> delete(QuestionVO questionVO) {
questionDao.deleteById(questionVO.getId());
return Result.success("success");
}
public Result<QuestionDTO> get(QuestionVO questionVO){
Question question = questionDao.getById(questionVO.getId());
if(question == null){
return Result.error("没有数据");
}
QuestionDTO questionDTO = new QuestionDTO();
BeanUtils.copyProperties(question,questionDTO);
return Result.success(questionDTO);
public Result<QuestionDTO> get(QuestionVO questionVO) {
Question question = questionDao.getById(questionVO.getId());
if (question == null) {
return Result.error("没有数据");
}
QuestionDTO questionDTO = new QuestionDTO();
BeanUtils.copyProperties(question, questionDTO);
return Result.success(questionDTO);
}
public Result<String> batch(BatchQuestionVO vo){
questionDao.batchUpdate(vo.getStatus(),vo.getIds());
public Result<String> batch(BatchQuestionVO vo) {
questionDao.batchUpdate(vo.getStatus(), vo.getIds());
return Result.success("success");
}
public Result<ListQuestionDTO> listByIds(ListQuestionVO vo){
public Result<ListQuestionDTO> listByIds(ListQuestionVO vo) {
List<Question> list = questionDao.findAllByIdIn(vo.getQuestionIds());
ListQuestionDTO dto = new ListQuestionDTO();
dto.setList(list);
return Result.success(dto);
}
public Result<QuestionContDTO> getCount(){
int singleCount = questionDao.countByQuestionTypeAndType(QuestionTypeEnum.SINGLE.getCode(),0);
int multiCount = questionDao.countByQuestionTypeAndType(QuestionTypeEnum.MULTY.getCode(),0);
int judgeCount = questionDao.countByQuestionTypeAndType(QuestionTypeEnum.JUDGE.getCode(),0);
QuestionContDTO dto = new QuestionContDTO();
dto.setJudgeCount(judgeCount);
dto.setMultiCount(multiCount);
dto.setSingleCount(singleCount);
return Result.success(dto);
public Result<QuestionContDTO> getCount(List<Long> ids) {
int singleCount;
int multiCount;
int judgeCount;
int gapFilling;
if (ids != null && !ids.isEmpty()) {
singleCount = questionDao.countByQuestionTypeAndTypeAndCourseIdIn(QuestionTypeEnum.SINGLE.getCode(), 0, ids);
multiCount = questionDao.countByQuestionTypeAndTypeAndCourseIdIn(QuestionTypeEnum.MULTY.getCode(), 0, ids);
judgeCount = questionDao.countByQuestionTypeAndTypeAndCourseIdIn(QuestionTypeEnum.JUDGE.getCode(), 0, ids);
gapFilling = questionDao.countByQuestionTypeAndTypeAndCourseIdIn(QuestionTypeEnum.GAPFILLING.getCode(), 0, ids);
} else {
singleCount = questionDao.countByQuestionTypeAndType(QuestionTypeEnum.SINGLE.getCode(), 0);
multiCount = questionDao.countByQuestionTypeAndType(QuestionTypeEnum.MULTY.getCode(), 0);
judgeCount = questionDao.countByQuestionTypeAndType(QuestionTypeEnum.JUDGE.getCode(), 0);
gapFilling = questionDao.countByQuestionTypeAndType(QuestionTypeEnum.GAPFILLING.getCode(), 0);
}
QuestionContDTO dto = new QuestionContDTO();
dto.setJudgeCount(judgeCount);
dto.setMultiCount(multiCount);
dto.setSingleCount(singleCount);
dto.setGapFilling(gapFilling);
return Result.success(dto);
}
}

@ -15,18 +15,14 @@ import com.tz.platform.pc.dto.ListQuestionImportDTO;
import com.tz.platform.pc.dto.QuestionImportDTO;
import com.tz.platform.repository.CourseDao;
import com.tz.platform.repository.QuestionDao;
import org.apache.catalina.User;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.*;
@Component
public class QuestionImportBiz {
@ -42,12 +38,12 @@ public class QuestionImportBiz {
@Autowired
private IFeignStudentLevel feignStudentLevel;
public Result<ListQuestionImportDTO> importExcel(MultipartFile file,Long userNo){
if(userNo == null ||userNo<=0){
public Result<ListQuestionImportDTO> importExcel(MultipartFile file, Long userNo) {
if (userNo == null || userNo <= 0) {
return Result.error("无权操作");
}
UserVo user = feignUser.getByUserNo(userNo);
if(user==null||user.getUserType()< UserTypeEnum.TEACHER.getCode()){
if (user == null || user.getUserType() < UserTypeEnum.TEACHER.getCode()) {
return Result.error("无权操作");
}
ListQuestionImportDTO dto = new ListQuestionImportDTO();
@ -57,18 +53,22 @@ public class QuestionImportBiz {
ExcelUtil util = new ExcelUtil(file.getInputStream());
int lastRowNum = util.getLastRowNum();
List<QuestionImportDTO> list = new ArrayList<>();
for(int rowNo = 1;rowNo<=lastRowNum;){
int lineCount = util.getMergedRegionLineCount(rowNo,1);
if(lineCount <=0){
return Result.error("格式错误");
Workbook workbook = new XSSFWorkbook(file.getInputStream());
ExcelUtil.initSheet(workbook);
for (int rowNo = 1; rowNo <= lastRowNum; ) {
int lineCount = util.getMergedRegionLineCount(rowNo, 1);
if (lineCount <= 0) {
return Result.error("格式错误");
}
QuestionImportDTO subDto = new QuestionImportDTO();
String stem = util.getMergedRegionValue(rowNo,0);
String questType = util.getMergedRegionValue(rowNo,1);
String levelNamme = util.getMergedRegionValue(rowNo,2);
String courseName = util.getMergedRegionValue(rowNo,3);
String score = util.getMergedRegionValue(rowNo,4);
String analysis = util.getMergedRegionValue(rowNo,5);
String stem = util.getMergedRegionValue(rowNo, 0);
String questType = util.getMergedRegionValue(rowNo, 1);
String levelNamme = util.getMergedRegionValue(rowNo, 2);
String courseName = util.getMergedRegionValue(rowNo, 3);
String score = util.getMergedRegionValue(rowNo, 4);
String analysis = util.getMergedRegionValue(rowNo, 5);
subDto.setStem(stem);
subDto.setQuestionType(questType);
@ -82,7 +82,7 @@ public class QuestionImportBiz {
if (StringUtils.isEmpty(stem)) {
subDto.setStatus("题干为空");
}else{
} else {
Question temp = questionDao.getByStem(stem);
if (temp != null) {
subDto.setStatus("题干已存在");
@ -98,7 +98,7 @@ public class QuestionImportBiz {
question.setLevelId(levelVo.getId());
question.setLevelName(levelNamme);
}
//todo 兼容填空题
question.setStem(stem);
question.setUserNo(userNo);
question.setCreateTime(new Date());
@ -111,41 +111,43 @@ public class QuestionImportBiz {
question.setAnalysis(analysis);
question.setCourseId(course.getId());
QuestionTypeEnum qt = null;
if(questType.equals(QuestionTypeEnum.SINGLE.getDesc())){
if (questType.equals(QuestionTypeEnum.SINGLE.getDesc())) {
qt = QuestionTypeEnum.SINGLE;
}else if(questType.equals(QuestionTypeEnum.MULTY.getDesc())){
} else if (questType.equals(QuestionTypeEnum.MULTY.getDesc())) {
qt = QuestionTypeEnum.MULTY;
}else if(questType.equals(QuestionTypeEnum.JUDGE.getDesc())) {
qt= QuestionTypeEnum.JUDGE;
} else if (questType.equals(QuestionTypeEnum.JUDGE.getDesc())) {
qt = QuestionTypeEnum.JUDGE;
} else if (questType.equals(QuestionTypeEnum.GAPFILLING.getDesc())) {
qt = QuestionTypeEnum.GAPFILLING;
}
if(qt == null){
if (qt == null) {
subDto.setStatus("题型未匹配");
}else{
} else {
List<Answer> answerList = new ArrayList<>();
List<Integer> answerIds = new ArrayList<>();
for(int i = 0 ;i<lineCount;i++){
Row row = util.getRow(rowNo +i);
for (int i = 0; i < lineCount; i++) {
Row row = util.getRow(rowNo + i);
String itemStem = util.getCellValue(row.getCell(6));
String isAnwser = util.getCellValue(row.getCell(7));
if(StringUtils.isEmpty(itemStem)){
if (StringUtils.isEmpty(itemStem)) {
continue;
}
Answer answer = new Answer();
answer.setId(i+1);
answer.setId(i + 1);
answer.setTitle(itemStem);
if(isAnwser.contains("是")){
answerIds.add(i+1);
if (isAnwser.contains("是")) {
answerIds.add(i + 1);
}
answerList.add(answer);
}
if(answerIds.size() == 0){
if (answerIds.size() == 0) {
subDto.setStatus("无答案");
}
if(answerList.size()==0){
if (answerList.size() == 0) {
subDto.setStatus("无选项");
}
if(answerIds.size()>0&&answerList.size()>0&&qt!=null){
//todo 兼容填空题
if (answerIds.size() > 0 && answerList.size() > 0) {
question.setQuestionType(qt.getCode());
question.setAnswerList(answerList);
question.setAnswerId(answerIds);
@ -156,11 +158,11 @@ public class QuestionImportBiz {
}
}
}
}catch (Exception ex){
} catch (Exception ex) {
subDto.setStatus("数据异常");
}
list.add(subDto);
rowNo+=lineCount;
rowNo += lineCount;
}
dto.setList(list);
} catch (Exception e) {
@ -169,4 +171,159 @@ public class QuestionImportBiz {
return Result.success(dto);
}
public Result<String> importExcel11(MultipartFile file, Long userNo, Long courseId) throws Exception {
//身份校验
if (userNo == null || userNo <= 0) {
return Result.error("无权操作");
}
UserVo user = feignUser.getByUserNo(userNo);
if (user == null || user.getUserType() < UserTypeEnum.TEACHER.getCode()) {
return Result.error("无权操作");
}
List<Question> questionList = new ArrayList<>();
try {
Workbook workbook = WorkbookFactory.create(file.getInputStream());
Sheet sheet = workbook.getSheetAt(0);
// 迭代每一行
Iterator<Row> iterator = sheet.iterator();
iterator.next();
while (iterator.hasNext()) {
Row row = iterator.next();
/*解析列下标从0开始*/
Cell cell0 = row.getCell(0); //题型
Cell cell1 = row.getCell(1);//题干
Cell cell2 = row.getCell(2);//A
Cell cell3 = row.getCell(3);//B
Cell cell4 = row.getCell(4);//C
Cell cell5 = row.getCell(5);//D
Cell cell6 = row.getCell(6);//E
Cell cell7 = row.getCell(7);//答案
Cell cell8 = row.getCell(8);//分数
Cell cell9 = row.getCell(9);//解析
//判断题的BCDE选项和解析可能为空
if (cell0 == null || cell1 == null || cell2 == null || cell3 == null || cell7 == null || cell8 == null) {
return Result.error("必填项不能为空!");
}
String questType = this.getCellValue(cell0);//题型
String a = null;
String b = null;
if (!questType.equals("填空题")) {
a = this.getCellValue(cell2); //选项A
b = this.getCellValue(cell3);//选项B
}
String stem = this.getCellValue(cell1);//题干
String answer = this.getCellValue(cell7);//答案
String score = this.getCellValue(cell8);//分值
String c = cell4 != null ? this.getCellValue(cell4) : null;
String d = cell5 != null ? this.getCellValue(cell5) : null;
String e = cell6 != null ? this.getCellValue(cell6) : null;
String analysis = cell9 != null ? this.getCellValue(cell9) : null; //答案解析
Course course = courseDao.getById(courseId);
if (course == null) {
return Result.error("课程不存在");
}
Question temp = questionDao.getByStem(stem);
if (temp != null) {
return Result.error("题干已存在");
}
QuestionTypeEnum qt = null;
if (questType.equals(QuestionTypeEnum.SINGLE.getDesc())) {
qt = QuestionTypeEnum.SINGLE;
} else if (questType.equals(QuestionTypeEnum.MULTY.getDesc())) {
qt = QuestionTypeEnum.MULTY;
} else if (questType.equals(QuestionTypeEnum.JUDGE.getDesc())) {
qt = QuestionTypeEnum.JUDGE;
} else if (questType.equals(QuestionTypeEnum.GAPFILLING.getDesc())) {
qt = QuestionTypeEnum.GAPFILLING;
}
if (qt == null) {
return Result.error("题型未匹配");
}
Question question = new Question();
question.setStem(stem);
question.setUserNo(userNo);
question.setCreateTime(new Date());
question.setStatus(0);
question.setScore(Long.parseLong(score));
question.setCreatorId(userNo);
question.setCreator(user.getName());
question.setType(0);
question.setAnalysis(analysis);
question.setCourseId(course.getId());
question.setLevelId(0);
question.setLevelName("通用");
question.setQuestionType(qt.getCode());
question.setCourseName(course.getName());
List<Answer> answerList = new ArrayList<>();
List<Integer> answerIds = new ArrayList<>();
String[] split = answer.split(",");
int id = 1; // 选项的ID
if (questType.equals("填空题")) {
Answer answerData = new Answer();
answerData.setId(id);
answerData.setTitle(answer);
answerList.add(answerData);
} else {
String[] options = {a, b, c, d, e}; // 选项文本
for (String option : options) {
if (com.alibaba.cloud.commons.lang.StringUtils.isNotBlank(option)) {
Answer answerData = new Answer();
answerData.setId(id);
answerData.setTitle(option);
answerList.add(answerData);
}
id++; // 每次循环递增ID
}
}
for (String s : split) {
int answerId = 1; // 默认A选项对应ID为1
if (s.equals("A")) {
answerId = 1;
} else if (s.equals("B")) {
answerId = 2;
} else if (s.equals("C")) {
answerId = 3;
} else if (s.equals("D")) {
answerId = 4;
} else if (s.equals("E")) {
answerId = 5;
}
answerIds.add(answerId);
}
question.setAnswerList(answerList);
question.setAnswerId(answerIds);
questionList.add(question);
}
questionDao.saveAll(questionList);
} catch (Exception e) {
e.printStackTrace();
return Result.error("系统异常,请联系管理员");
}
return Result.success("导入成功!");
}
public String getCellValue(Cell cell) {
if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
return String.valueOf(cell.getBooleanCellValue());
} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
Double d = cell.getNumericCellValue();
return String.valueOf(d.intValue());
}
return String.valueOf(cell.getStringCellValue());
}
}

@ -21,7 +21,7 @@ public class QuestionVO {
private String stemImg;
private Long creatorId;
List<Answer> answerList;
private String analysis;
private String analysis; //[题目选项]
private Integer status;
private List<Integer> answerId;
private List<Integer> answerId; //正确答案 [1]
}

@ -11,5 +11,6 @@ import org.springframework.stereotype.Repository;
public interface CourseDao extends JpaRepository<Course,Long> {
Page<Course> findAll(Pageable pageable);
Course getById(Long id);
Course getByName(String name);
Course getByOuterId(Integer outerId);
}

@ -15,25 +15,28 @@ import java.util.List;
@Repository
public interface QuestionDao extends JpaRepository<Question,Long> {
public interface QuestionDao extends JpaRepository<Question, Long> {
Question getById(Long id);
Page<Question> findAll(Pageable pageable);
Page<Question> findAllByStemAndType(String stem,Integer type,Pageable pageable);
Page<Question> findAllByStemAndType(String stem, Integer type, Pageable pageable);
Page<Question> findAllByCourseIdAndType(Long courseId,Integer type,Pageable pageable);
Page<Question> findAllByCourseIdAndType(Long courseId, Integer type, Pageable pageable);
Page<Question> findAllByType(Integer type,Pageable pageable);
Page<Question> findAllByType(Integer type, Pageable pageable);
Page<Question> findAllByCourseIdAndStemAndType(Long courseId,String stem,Integer type ,Pageable pageable);
Page<Question> findAllByCourseIdAndStemAndType(Long courseId, String stem, Integer type, Pageable pageable);
Page<Question> findAllByIdIn(List<Long> id,Pageable pageable);
Page<Question> findAllByIdIn(List<Long> id, Pageable pageable);
Page<Question> findAll(Example example,Pageable pageable);
Page<Question> findAll(Example example, Pageable pageable);
List<Question> findAllByIdIn(List<Long> ids);
int countByQuestionTypeAndType(Integer qtype,Integer type);
int countByQuestionTypeAndTypeAndCourseIdIn(Integer qtype, Integer type, List<Long> courseId);
int countByQuestionTypeAndType(Integer qtype, Integer type);
Question getByStem(String stem);
@ -41,6 +44,6 @@ public interface QuestionDao extends JpaRepository<Question,Long> {
@Transactional
@Modifying
@Query(value = "update question_sale set status=:status where id in (:ids)",nativeQuery = true)
void batchUpdate(@Param("status") int status,@Param("ids") List<Long> ids);
@Query(value = "update question_sale set status=:status where id in (:ids)", nativeQuery = true)
void batchUpdate(@Param("status") int status, @Param("ids") List<Long> ids);
}

Loading…
Cancel
Save