|
|
|
@ -0,0 +1,210 @@
|
|
|
|
|
package com.sztzjy.money_management.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
import com.sztzjy.money_management.entity.ObjectiveQuestionExample;
|
|
|
|
|
import com.sztzjy.money_management.entity.ObjectiveQuestionWithBLOBs;
|
|
|
|
|
import com.sztzjy.money_management.entity.StuTrainingExample;
|
|
|
|
|
import com.sztzjy.money_management.entity.StuTrainingWithBLOBs;
|
|
|
|
|
import com.sztzjy.money_management.entity.dto.ObjectiveQuestionDto;
|
|
|
|
|
import com.sztzjy.money_management.mapper.ObjectiveQuestionMapper;
|
|
|
|
|
import com.sztzjy.money_management.mapper.StuTrainingMapper;
|
|
|
|
|
import com.sztzjy.money_management.service.ObjectiveQuestionService;
|
|
|
|
|
import com.sztzjy.money_management.util.ResultEntity;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.math.BigInteger;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Author xcj
|
|
|
|
|
* @Date 2024/8/13
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
public class ObjectiveQuestionServiceImpl implements ObjectiveQuestionService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private ObjectiveQuestionMapper objectiveQuestionMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private StuTrainingMapper stuTrainingMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ResultEntity<HttpStatus> insertObjectiveByExcel(MultipartFile file, String source, String chapterID, String chapterName, String outLine, String subClass) throws Exception {
|
|
|
|
|
List<ObjectiveQuestionWithBLOBs> objectiveQuestionList = new ArrayList<>();
|
|
|
|
|
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);
|
|
|
|
|
Cell cell3 = row.getCell(3);
|
|
|
|
|
Cell cell4 = row.getCell(4);
|
|
|
|
|
Cell cell5 = row.getCell(5);
|
|
|
|
|
Cell cell6 = row.getCell(6);
|
|
|
|
|
Cell cell7 = row.getCell(7);
|
|
|
|
|
Cell cell8 = row.getCell(8);
|
|
|
|
|
Cell cell9 = row.getCell(9);
|
|
|
|
|
Cell cell10 = row.getCell(10);
|
|
|
|
|
|
|
|
|
|
//判断题的BCDE选项和解析可能为空
|
|
|
|
|
if (cell0 == null || cell1 == null || cell2 == null || cell6 == null || cell7 == null || cell9 == null) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "必填项不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String content = this.getCellValue(cell0);//题干
|
|
|
|
|
String a = this.getCellValue(cell1); //选项A
|
|
|
|
|
String b = this.getCellValue(cell2);//选项B
|
|
|
|
|
String type = this.getCellValue(cell6);//题型
|
|
|
|
|
String answer = this.getCellValue(cell7);//答案
|
|
|
|
|
String score = this.getCellValue(cell9);//分值
|
|
|
|
|
String c = cell3 != null ? this.getCellValue(cell3) : null;
|
|
|
|
|
String d = cell4 != null ? this.getCellValue(cell4) : null;
|
|
|
|
|
String e = cell5 != null ? this.getCellValue(cell5) : null;
|
|
|
|
|
String analyze = cell8 != null ? this.getCellValue(cell8) : null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ObjectiveQuestionWithBLOBs obj = new ObjectiveQuestionWithBLOBs();
|
|
|
|
|
String topicId = IdUtil.randomUUID();
|
|
|
|
|
obj.setObjectiveId(topicId);
|
|
|
|
|
obj.setContent(content);
|
|
|
|
|
obj.setType(Integer.valueOf(type));
|
|
|
|
|
obj.setSource(source);
|
|
|
|
|
obj.setQuestionA(a);
|
|
|
|
|
obj.setQuestionB(b);
|
|
|
|
|
obj.setQuestionC(c);
|
|
|
|
|
obj.setQuestionD(d);
|
|
|
|
|
obj.setQuestionE(e);
|
|
|
|
|
obj.setAnswer(answer);
|
|
|
|
|
obj.setAnalysis(analyze);
|
|
|
|
|
obj.setScore(BigDecimal.valueOf(Integer.parseInt(score)));
|
|
|
|
|
if (StringUtils.isNotBlank(chapterID)) {
|
|
|
|
|
obj.setChapterId(chapterID);
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(chapterName)) {
|
|
|
|
|
obj.setChapterName(chapterName);
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(subClass)) {
|
|
|
|
|
obj.setSubclass(subClass);
|
|
|
|
|
}
|
|
|
|
|
objectiveQuestionList.add(obj);
|
|
|
|
|
}
|
|
|
|
|
int result = objectiveQuestionMapper.insertBatch(objectiveQuestionList);
|
|
|
|
|
if (result > 0) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.OK, "批量导入成功!");
|
|
|
|
|
} else {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.INTERNAL_SERVER_ERROR, "批量导入失败,请联系管理员!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void commitObjectiveAnswer(List<ObjectiveQuestionDto> dtoList, String userId, String chapterId) {
|
|
|
|
|
StuTrainingExample stuTrainingExample = new StuTrainingExample();
|
|
|
|
|
stuTrainingExample.createCriteria().andUserIdEqualTo(userId).andChapterIdEqualTo(chapterId);
|
|
|
|
|
List<StuTrainingWithBLOBs> stuTrainingWithBLOBs = stuTrainingMapper.selectByExampleWithBLOBs(stuTrainingExample);
|
|
|
|
|
|
|
|
|
|
BigDecimal score = new BigDecimal(BigInteger.ZERO);
|
|
|
|
|
List<String> ids = new ArrayList<>();
|
|
|
|
|
List<String> answerList = new ArrayList<>();
|
|
|
|
|
int count = 0;
|
|
|
|
|
for (ObjectiveQuestionDto objectiveQuestionDto : dtoList) {
|
|
|
|
|
String dtoObjectiveId = objectiveQuestionDto.getObjectiveId();
|
|
|
|
|
ObjectiveQuestionWithBLOBs dataObjectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(dtoObjectiveId);
|
|
|
|
|
String rightAnswer = dataObjectiveQuestion.getAnswer();
|
|
|
|
|
String stuAnswer = objectiveQuestionDto.getUserAnswer();
|
|
|
|
|
if (rightAnswer.equals(stuAnswer)) {
|
|
|
|
|
score = score.add(dataObjectiveQuestion.getScore());
|
|
|
|
|
} else {
|
|
|
|
|
count += 1;
|
|
|
|
|
}
|
|
|
|
|
ids.add(dtoObjectiveId);
|
|
|
|
|
answerList.add(stuAnswer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stuTrainingWithBLOBs != null && !stuTrainingWithBLOBs.isEmpty()) {
|
|
|
|
|
StuTrainingWithBLOBs dataTraining = stuTrainingWithBLOBs.get(0);
|
|
|
|
|
//两个参数都为空说明第一次提交,进行算分
|
|
|
|
|
if (StringUtils.isBlank(dataTraining.getLearningEvalIdList())
|
|
|
|
|
&& StringUtils.isBlank(dataTraining.getLearningEvalAnswer())) {
|
|
|
|
|
|
|
|
|
|
dataTraining.setLearningEvalAnswer(String.valueOf(answerList));
|
|
|
|
|
dataTraining.setLearningEvalIdList(String.valueOf(ids));
|
|
|
|
|
dataTraining.setExpTrainingScore(score);
|
|
|
|
|
// dataTraining.setLearningEvalCompleteStatus(count);
|
|
|
|
|
|
|
|
|
|
stuTrainingMapper.updateByPrimaryKeySelective(dataTraining);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<ObjectiveQuestionDto> getObjectiveRecord(String chapterId, String trainingId) {
|
|
|
|
|
StuTrainingWithBLOBs stuTrainingWithBLOBs = stuTrainingMapper.selectByPrimaryKey(trainingId);
|
|
|
|
|
|
|
|
|
|
//沒提交过的展示十条随机
|
|
|
|
|
if (stuTrainingWithBLOBs == null
|
|
|
|
|
|| StringUtils.isBlank(stuTrainingWithBLOBs.getLearningEvalAnswer())
|
|
|
|
|
|| StringUtils.isBlank(stuTrainingWithBLOBs.getLearningEvalIdList())) {
|
|
|
|
|
return objectiveQuestionMapper.getObjectiveCount10(chapterId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//提交过 回显答题数据
|
|
|
|
|
String learningEvalIdList = stuTrainingWithBLOBs.getLearningEvalIdList(); //学生作答题目ID
|
|
|
|
|
String learningEvalAnswer = stuTrainingWithBLOBs.getLearningEvalAnswer(); //学生提交答案
|
|
|
|
|
|
|
|
|
|
List<String> idList = Arrays.asList(learningEvalIdList.split(","));
|
|
|
|
|
List<String> stuAnswerList = Arrays.asList(learningEvalAnswer.split(","));
|
|
|
|
|
|
|
|
|
|
// 确保 idList 和 stuAnswerList 大小相同且顺序匹配
|
|
|
|
|
if (idList.size() != stuAnswerList.size()) {
|
|
|
|
|
throw new IllegalArgumentException("ID 和答案数量不匹配");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建题目 ID 到答案的映射
|
|
|
|
|
Map<String, String> answerMap = new HashMap<>();
|
|
|
|
|
for (int i = 0; i < idList.size(); i++) {
|
|
|
|
|
answerMap.put(idList.get(i), stuAnswerList.get(i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ObjectiveQuestionExample example = new ObjectiveQuestionExample();
|
|
|
|
|
example.createCriteria().andObjectiveIdIn(idList);
|
|
|
|
|
List<ObjectiveQuestionWithBLOBs> list = objectiveQuestionMapper.selectByExampleWithBLOBs(example);
|
|
|
|
|
|
|
|
|
|
List<ObjectiveQuestionDto> resultList = new ArrayList<>();
|
|
|
|
|
for (ObjectiveQuestionWithBLOBs objectiveQuestionWithBLOBs : list) {
|
|
|
|
|
ObjectiveQuestionDto objectiveQuestionDto = new ObjectiveQuestionDto();
|
|
|
|
|
BeanUtils.copyProperties(objectiveQuestionWithBLOBs, objectiveQuestionDto);
|
|
|
|
|
|
|
|
|
|
// 获取对应题目的答案并设置
|
|
|
|
|
String userAnswer = answerMap.get(objectiveQuestionWithBLOBs.getObjectiveId());
|
|
|
|
|
objectiveQuestionDto.setUserAnswer(userAnswer);
|
|
|
|
|
list.add(objectiveQuestionDto);
|
|
|
|
|
}
|
|
|
|
|
return resultList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|