|
|
@ -1,19 +1,127 @@
|
|
|
|
package com.sztzjy.resource_center.controller.api;
|
|
|
|
package com.sztzjy.resource_center.controller.api;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.annotation.AnonymousAccess;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.entity.*;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.entity.dto.SysObjectiveQuestionsDto;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.mapper.SysObjectiveQuestionsMapper;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.mapper.SysOneCatalogMapper;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.mapper.SysTopicAndCourseMapper;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.util.ResultEntity;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.util.file.IFileUtil;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@Api(tags = "课程方面API")
|
|
|
|
@Api(tags = "课程方面API")
|
|
|
|
@RequestMapping("api/sys/ObjectiveApi")
|
|
|
|
@RequestMapping("api/sys/ObjectiveApi")
|
|
|
|
public class ObjectiveApi {
|
|
|
|
public class ObjectiveApi {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private SysObjectiveQuestionsMapper sysObjectiveQuestionMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private SysTopicAndCourseMapper sysTopicAndCourseMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
SysOneCatalogMapper oneCatalogMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
IFileUtil fileUtil;
|
|
|
|
|
|
|
|
@Value("${file.path}")
|
|
|
|
|
|
|
|
private String filePath;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private SysOneCatalog getSysOneCatalogs(String systemOwner) {
|
|
|
|
|
|
|
|
SysOneCatalogExample example = new SysOneCatalogExample();
|
|
|
|
|
|
|
|
example.createCriteria().andOneNameEqualTo(systemOwner);
|
|
|
|
|
|
|
|
List<SysOneCatalog> sysOneCatalogs = oneCatalogMapper.selectByExample(example);
|
|
|
|
|
|
|
|
return sysOneCatalogs.get(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 客观题新增
|
|
|
|
* 客观题新增
|
|
|
|
* 方法名:insertObjective
|
|
|
|
* 方法名:insertObjective
|
|
|
|
* 参数:SysObjectiveQuestions systemOwner schoolId
|
|
|
|
* 参数:SysObjectiveQuestions systemOwner
|
|
|
|
* return: boolean
|
|
|
|
* return: boolean
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
|
|
|
@ApiOperation("新增单个试题") //新增 题干不允许重复
|
|
|
|
|
|
|
|
@PostMapping("addTopic")
|
|
|
|
|
|
|
|
private Boolean addTopic(@RequestBody SysObjectiveQuestionsDto objectiveQuestion) {
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(objectiveQuestion.getContent())) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(objectiveQuestion.getAnswer())) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (objectiveQuestion.getScore() == null) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(objectiveQuestion.getType())) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(objectiveQuestion.getObjectiveId())) { //子系统的oneName放在这个字段传过来
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (objectiveQuestion.getType().equals("1") || objectiveQuestion.getType().equals("0")) {
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(objectiveQuestion.getQuestionA()) || StringUtils.isBlank(objectiveQuestion.getQuestionB())
|
|
|
|
|
|
|
|
|| StringUtils.isBlank(objectiveQuestion.getQuestionC()) || StringUtils.isBlank(objectiveQuestion.getQuestionD()))
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (objectiveQuestion.getType().equals("2")) {
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(objectiveQuestion.getQuestionA()) || StringUtils.isBlank(objectiveQuestion.getQuestionB()))
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SysOneCatalog sysOneCatalogs = getSysOneCatalogs(objectiveQuestion.getObjectiveId());
|
|
|
|
|
|
|
|
String oneId = sysOneCatalogs.getOneId();
|
|
|
|
|
|
|
|
SysObjectiveQuestionsExample example = new SysObjectiveQuestionsExample();
|
|
|
|
|
|
|
|
example.createCriteria().andContentEqualTo(objectiveQuestion.getContent());
|
|
|
|
|
|
|
|
List<SysObjectiveQuestions> sysObjectiveQuestions = sysObjectiveQuestionMapper.selectByExample(example);
|
|
|
|
|
|
|
|
if (!sysObjectiveQuestions.isEmpty()) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//新增题库表
|
|
|
|
|
|
|
|
String uuid = IdUtil.randomUUID();
|
|
|
|
|
|
|
|
objectiveQuestion.setObjectiveId(uuid);
|
|
|
|
|
|
|
|
objectiveQuestion.setCreateTime(new Date());
|
|
|
|
|
|
|
|
objectiveQuestion.setIsDelete(false);
|
|
|
|
|
|
|
|
objectiveQuestion.setOneID(oneId);
|
|
|
|
|
|
|
|
sysObjectiveQuestionMapper.insert(objectiveQuestion);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//新增题库关系表
|
|
|
|
|
|
|
|
SysTopicAndCourse sysTopicAndCourse = new SysTopicAndCourse();
|
|
|
|
|
|
|
|
sysTopicAndCourse.setId(IdUtil.randomUUID());
|
|
|
|
|
|
|
|
sysTopicAndCourse.setTopicId(uuid);
|
|
|
|
|
|
|
|
sysTopicAndCourse.setTopicType(objectiveQuestion.getType());
|
|
|
|
|
|
|
|
sysTopicAndCourse.setOneId(oneId);
|
|
|
|
|
|
|
|
sysTopicAndCourse.setOneName(objectiveQuestion.getObjectiveId()); //子系统的oneName放在这个字段传过来
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(objectiveQuestion.getTwoID())) {
|
|
|
|
|
|
|
|
sysTopicAndCourse.setTwoId(objectiveQuestion.getTwoID());
|
|
|
|
|
|
|
|
sysTopicAndCourse.setTwoName(objectiveQuestion.getTwoName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(objectiveQuestion.getThreeID())) {
|
|
|
|
|
|
|
|
sysTopicAndCourse.setThreeId(objectiveQuestion.getThreeID());
|
|
|
|
|
|
|
|
sysTopicAndCourse.setThreeName(objectiveQuestion.getThreeName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sysTopicAndCourseMapper.insert(sysTopicAndCourse);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 客观题批量删除
|
|
|
|
* 客观题批量删除
|
|
|
@ -21,6 +129,30 @@ public class ObjectiveApi {
|
|
|
|
* 参数:List<String> objIdList schoolId
|
|
|
|
* 参数:List<String> objIdList schoolId
|
|
|
|
* return: boolean
|
|
|
|
* return: boolean
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
|
|
|
@ApiOperation("客观题批量删除")
|
|
|
|
|
|
|
|
@PostMapping("batchDeleteObjective")
|
|
|
|
|
|
|
|
private Boolean batchDeleteObjective(@RequestBody List<String> objIdList,
|
|
|
|
|
|
|
|
@RequestParam String schoolId) {
|
|
|
|
|
|
|
|
SysObjectiveQuestionsExample example = new SysObjectiveQuestionsExample();
|
|
|
|
|
|
|
|
example.createCriteria().andObjectiveIdIn(objIdList);
|
|
|
|
|
|
|
|
List<SysObjectiveQuestions> sysObjectiveQuestions = sysObjectiveQuestionMapper.selectByExample(example);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> ids = new ArrayList<>();
|
|
|
|
|
|
|
|
for (SysObjectiveQuestions sysObjectiveQuestion : sysObjectiveQuestions) {
|
|
|
|
|
|
|
|
if (sysObjectiveQuestion.getSource().equals(schoolId)) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ids.add(sysObjectiveQuestion.getObjectiveId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
sysObjectiveQuestionMapper.batchDelete(ids);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 客观题列表查看
|
|
|
|
* 客观题列表查看
|
|
|
@ -28,6 +160,21 @@ public class ObjectiveApi {
|
|
|
|
* 参数:schoolId courseId type content index size
|
|
|
|
* 参数:schoolId courseId type content index size
|
|
|
|
* return:PageInfo<SysObjectiveQuestions>
|
|
|
|
* return:PageInfo<SysObjectiveQuestions>
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
|
|
|
@ApiOperation("课程配置/题目条件查询")
|
|
|
|
|
|
|
|
@PostMapping("getTopicByConfig") //todo 关于老师删除的题库如何查询
|
|
|
|
|
|
|
|
private PageInfo<SysObjectiveQuestionsDto> getTopicByConfig(@RequestParam Integer index,
|
|
|
|
|
|
|
|
@RequestParam Integer size,
|
|
|
|
|
|
|
|
@RequestParam(required = false) String courseId,
|
|
|
|
|
|
|
|
@RequestParam(required = false) String threeID,
|
|
|
|
|
|
|
|
@RequestParam(required = false) String type,
|
|
|
|
|
|
|
|
@RequestParam String schoolId,
|
|
|
|
|
|
|
|
@ApiParam("题干") @RequestParam(required = false) String content) {
|
|
|
|
|
|
|
|
PageHelper.startPage(index, size);
|
|
|
|
|
|
|
|
List<SysObjectiveQuestionsDto> list = sysObjectiveQuestionMapper.getTopicByConfig(null, courseId, threeID, type, schoolId, content);
|
|
|
|
|
|
|
|
PageInfo<SysObjectiveQuestionsDto> pageInfo = new PageInfo(list);
|
|
|
|
|
|
|
|
return (pageInfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 客观题单个详情查看
|
|
|
|
* 客观题单个详情查看
|
|
|
@ -35,6 +182,13 @@ public class ObjectiveApi {
|
|
|
|
* 参数:objectiveId
|
|
|
|
* 参数:objectiveId
|
|
|
|
* return:SysObjectiveQuestions
|
|
|
|
* return:SysObjectiveQuestions
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
|
|
|
@ApiOperation("客观题单个详情查看")
|
|
|
|
|
|
|
|
@PostMapping("selectObjectiveDetails")
|
|
|
|
|
|
|
|
private SysObjectiveQuestions getById(@RequestParam String objectiveId) {
|
|
|
|
|
|
|
|
SysObjectiveQuestions sysObjectiveQuestions = sysObjectiveQuestionMapper.selectByPrimaryKey(objectiveId);
|
|
|
|
|
|
|
|
return sysObjectiveQuestions;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 客观题导入模板下载
|
|
|
|
* 客观题导入模板下载
|
|
|
@ -42,11 +196,104 @@ public class ObjectiveApi {
|
|
|
|
* 参数:response
|
|
|
|
* 参数:response
|
|
|
|
* return:void
|
|
|
|
* return:void
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@GetMapping("downloadResource")
|
|
|
|
|
|
|
|
@ApiOperation("客观题导入模板下载")
|
|
|
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
|
|
|
public void downloadResource(HttpServletResponse response) {
|
|
|
|
|
|
|
|
fileUtil.download(response, "客观题导入模板.xlsx", filePath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 客观题批量导入
|
|
|
|
* 客观题批量导入
|
|
|
|
* 方法名:insertObjectiveByExcel
|
|
|
|
* 方法名:insertObjectiveByExcel
|
|
|
|
* 参数:MultipartFile schoolId
|
|
|
|
* 参数:MultipartFile schoolId
|
|
|
|
* return:void
|
|
|
|
* return:Boolean
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
|
|
|
@ApiOperation("本地excel导入试题")
|
|
|
|
|
|
|
|
@PostMapping("importTopicByLocal")
|
|
|
|
|
|
|
|
private Boolean importTopicByLocal(@RequestParam MultipartFile file,
|
|
|
|
|
|
|
|
@RequestParam String schoolId) throws IOException, InvalidFormatException {
|
|
|
|
|
|
|
|
if (file == null) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return insertObjectiveByExcel(file, schoolId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//如果是内置增加 则需要提供课程和章节信息
|
|
|
|
|
|
|
|
//如果是老师增加 则只需要提供课程信息
|
|
|
|
|
|
|
|
public Boolean insertObjectiveByExcel(MultipartFile file, String schoolId) throws IOException, InvalidFormatException {
|
|
|
|
|
|
|
|
List<SysObjectiveQuestions> 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);
|
|
|
|
|
|
|
|
//判断题的BCDE选项和解析可能为空
|
|
|
|
|
|
|
|
if (cell0 == null || cell1 == null || cell2 == null || cell6 == null || cell7 == null || cell9 == null) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SysObjectiveQuestions obj = new SysObjectiveQuestions();
|
|
|
|
|
|
|
|
obj.setObjectiveId(String.valueOf(UUID.randomUUID()));
|
|
|
|
|
|
|
|
obj.setContent(content);
|
|
|
|
|
|
|
|
obj.setType(type);
|
|
|
|
|
|
|
|
obj.setSource(schoolId);
|
|
|
|
|
|
|
|
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)));
|
|
|
|
|
|
|
|
obj.setCreateTime(new Date());
|
|
|
|
|
|
|
|
obj.setIsDelete(false);
|
|
|
|
|
|
|
|
objectiveQuestionList.add(obj);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = sysObjectiveQuestionMapper.insertBatch(objectiveQuestionList);
|
|
|
|
|
|
|
|
if (result > 0) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|