|
|
|
@ -18,6 +18,7 @@ import com.ibeetl.jlw.entity.*;
|
|
|
|
|
import com.ibeetl.jlw.entity.dto.QuestionSettingDTO;
|
|
|
|
|
import com.ibeetl.jlw.entity.vo.ImportQuestionByWordTemplateResultVO;
|
|
|
|
|
import com.ibeetl.jlw.entity.vo.QuestionTypeCountVO;
|
|
|
|
|
import com.ibeetl.jlw.entity.vo.ResourcesCourseInfoAuthDetailsVO;
|
|
|
|
|
import com.ibeetl.jlw.enums.MatchTypeEnum;
|
|
|
|
|
import com.ibeetl.jlw.enums.QuestionBusinessTypeEnum;
|
|
|
|
|
import com.ibeetl.jlw.enums.ResourcesQuestionTypeEnum;
|
|
|
|
@ -27,6 +28,7 @@ import com.ibeetl.jlw.web.query.CourseInfoQuery;
|
|
|
|
|
import com.ibeetl.jlw.web.query.ResourcesQuestionQuery;
|
|
|
|
|
import lombok.Cleanup;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.logging.log4j.util.Strings;
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
|
@ -58,13 +60,16 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static cn.hutool.core.util.ArrayUtil.join;
|
|
|
|
|
import static com.ibeetl.admin.core.util.StreamUtils.listJoin;
|
|
|
|
|
import static com.ibeetl.jlw.entity.ResourcesQuestion.LINE_8;
|
|
|
|
|
import static com.ibeetl.jlw.entity.ResourcesQuestion.SPLIT_;
|
|
|
|
|
import static com.ibeetl.jlw.entity.ResourcesQuestionOptionEntity.shuffleOrderOptions;
|
|
|
|
|
import static com.ibeetl.jlw.enums.AddTypeEnum.ADMIN_ADD;
|
|
|
|
|
import static com.ibeetl.jlw.enums.AddTypeEnum.FACULTY_ADD;
|
|
|
|
|
import static com.ibeetl.jlw.enums.CourseLabelTypeEnum.THEORY;
|
|
|
|
|
import static com.ibeetl.jlw.service.strategy.StrategyContext.QuestionParagraphTypeEnum.OTHER;
|
|
|
|
|
import static com.ibeetl.jlw.service.strategy.StrategyContext.QuestionTypeConcatEnum.*;
|
|
|
|
|
import static com.ibeetl.jlw.service.strategy.WordQuestionOption.OPTION_REGEX;
|
|
|
|
@ -81,17 +86,34 @@ import static java.util.stream.Collectors.joining;
|
|
|
|
|
@Transactional
|
|
|
|
|
public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion> {
|
|
|
|
|
|
|
|
|
|
@Autowired private ResourcesQuestionDao resourcesQuestionDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ResourcesQuestionDao resourcesQuestionDao;
|
|
|
|
|
|
|
|
|
|
@Autowired private CourseInfoService courseInfoService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private CourseInfoService courseInfoService;
|
|
|
|
|
|
|
|
|
|
@Autowired private CourseInfoDao courseInfoDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private CourseInfoDao courseInfoDao;
|
|
|
|
|
|
|
|
|
|
@Autowired private CorePlatformService platformService;
|
|
|
|
|
@Autowired private ResourcesQuestionService resourcesQuestionService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private CorePlatformService platformService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ResourcesQuestionService resourcesQuestionService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private StrategyContext strategyContext;
|
|
|
|
|
@Autowired
|
|
|
|
|
private QuestionValidator questionValidator;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CourseLabelService courseLabelService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CorePlatformService corePlatformService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private UniversitiesCollegesJurisdictionCurriculumResourcesService universitiesCollegesJurisdictionCurriculumResourcesService;
|
|
|
|
|
|
|
|
|
|
@Autowired private StrategyContext strategyContext;
|
|
|
|
|
@Autowired private QuestionValidator questionValidator;
|
|
|
|
|
|
|
|
|
|
public PageQuery<ResourcesQuestion> queryByCondition(PageQuery query) {
|
|
|
|
|
PageQuery ret = resourcesQuestionDao.queryByCondition(query);
|
|
|
|
@ -175,6 +197,7 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
public List<ResourcesQuestion> getValuesByQuery(ResourcesQuestionQuery resourcesQuestionQuery) {
|
|
|
|
|
return resourcesQuestionDao.getValuesByQuery(resourcesQuestionQuery);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ResourcesQuestion> getValuesByQueryNotWithPermission(ResourcesQuestionQuery resourcesQuestionQuery) {
|
|
|
|
|
return resourcesQuestionDao.getValuesByQueryNotWithPermission(resourcesQuestionQuery);
|
|
|
|
|
}
|
|
|
|
@ -311,11 +334,12 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public JsonResult importTemplate(FileEntity fileEntity){
|
|
|
|
|
public JsonResult importTemplate(FileEntity fileEntity, CoreUser coreUser) {
|
|
|
|
|
if (null != fileEntity) {
|
|
|
|
|
Map<String, CourseInfo> courseInfoCache = new HashMap<>();
|
|
|
|
|
Map<String, Map<String, List<CourseInfo>>> chapterCache = new HashMap<>();
|
|
|
|
|
File file = new File(fileEntity.getAbsoluteUrl());
|
|
|
|
|
if (file.exists() && file.isFile() && file.canRead() && ToolUtils.findInSet("xls,xlsx", fileEntity.getFormat())) {
|
|
|
|
|
|
|
|
|
|
Workbook wb = null;
|
|
|
|
|
InputStream is = null;
|
|
|
|
|
try {
|
|
|
|
@ -325,8 +349,6 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
} else if ("xlsx".equals(fileEntity.getFormat())) {
|
|
|
|
|
wb = new XSSFWorkbook(is);
|
|
|
|
|
}
|
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
@ -340,7 +362,6 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
|
|
|
|
|
if (wb != null) {
|
|
|
|
|
List<String[]> errMsg = new ArrayList<>();
|
|
|
|
|
String msg ="";
|
|
|
|
|
|
|
|
|
|
//获取Sheet1
|
|
|
|
|
Sheet sheet = wb.getSheet("Sheet1");
|
|
|
|
@ -351,7 +372,7 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
//获取最大列数
|
|
|
|
|
int colNum = firstRow.getPhysicalNumberOfCells();
|
|
|
|
|
|
|
|
|
|
String[] columns = {"归属课程","归属章节","题型","分值","题干","选项A","选项B","选项C","选项D","选项E","答案","解析"};
|
|
|
|
|
String[] columns = {"归属课程", "理论课程分类", "归属章节", "题型", "分值", "题干", "选项A", "选项B", "选项C", "选项D", "选项E", "答案", "解析"};
|
|
|
|
|
|
|
|
|
|
Map<String, Integer> map = new HashMap<>();//获取需要的表头的列
|
|
|
|
|
|
|
|
|
@ -373,12 +394,23 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (flag != columns.length) {
|
|
|
|
|
return JsonResult.failMessage("导入失败,表格表头应包含 \"归属课程\",\"归属章节\",\"题型\",\"分值\",\"题干\",\"选项A\",\"选项B\",\"选项C\",\"选项D\",\"选项E\",\"答案\",\"解析\"");
|
|
|
|
|
return JsonResult.failMessage("导入失败,表格表头应包含 \"归属课程\",\"理论课程分类\",\"归属章节\",\"题型\",\"分值\",\"题干\",\"选项A\",\"选项B\",\"选项C\",\"选项D\",\"选项E\",\"答案\",\"解析\"");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
CourseInfoQuery baseCourseInfo = new CourseInfoQuery();
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
if (coreUser.isUniAdmin()) {
|
|
|
|
|
baseCourseInfo.setOrgIdPlural(join(Arrays.asList(coreUser.getOrgId(), 1L).toArray(), ","));
|
|
|
|
|
|
|
|
|
|
ResourcesCourseInfoAuthDetailsVO resourcesCourseInfoAuthDetails =
|
|
|
|
|
universitiesCollegesJurisdictionCurriculumResourcesService.getResourcesCourseInfoAuthDetails(coreUser.getOrgId());
|
|
|
|
|
Serializable ifNullCourseInfoIds = listJoin(resourcesCourseInfoAuthDetails.getTheoryCourseList(), CourseInfo::getCourseInfoId);
|
|
|
|
|
String ids = Arrays.stream(ifNullCourseInfoIds.toString().split(",")).map(item -> "_" + item + "_").collect(Collectors.joining("|"));
|
|
|
|
|
// 如果为空字符串,那么代表这个学校,还没有授权的课程,所以是不会显示任何东西的。
|
|
|
|
|
baseCourseInfo.setCourseInfoIdPlural(StrUtil.blankToDefault(ids, "未授权应用"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < rowNum; i++) {
|
|
|
|
|
Row row = sheet.getRow(i);
|
|
|
|
@ -387,75 +419,223 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
errMsg.add(new String[]{"第" + (i + 1) + "数据为空"});
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
String courseInfoName = getCellFormatValue(row.getCell(map.get(columns[0])));
|
|
|
|
|
String courseLabelName = getCellFormatValue(row.getCell(map.get(columns[1])));
|
|
|
|
|
String chapterName = getCellFormatValue(row.getCell(map.get(columns[2])));
|
|
|
|
|
String questionType = getCellFormatValue(row.getCell(map.get(columns[3])));
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(questionType)) {
|
|
|
|
|
questionType = questionType.replace("题", "").trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String courseInfoName = getCellFormatValue(row.getCell(map.get(columns[1])));
|
|
|
|
|
String questionType = getCellFormatValue(row.getCell(map.get(columns[2])));
|
|
|
|
|
String questionScore = getCellFormatValue(row.getCell(map.get(columns[3])));
|
|
|
|
|
String questionStem = getCellFormatValue(row.getCell(map.get(columns[4])));
|
|
|
|
|
String questionScore = getCellFormatValue(row.getCell(map.get(columns[4])));
|
|
|
|
|
String questionStem = getCellFormatValue(row.getCell(map.get(columns[5])));
|
|
|
|
|
|
|
|
|
|
String questionOptionA = getCellFormatValue(row.getCell(map.get(columns[5])));
|
|
|
|
|
String questionOptionB = getCellFormatValue(row.getCell(map.get(columns[6])));
|
|
|
|
|
String questionOptionC = getCellFormatValue(row.getCell(map.get(columns[7])));
|
|
|
|
|
String questionOptionD = getCellFormatValue(row.getCell(map.get(columns[8])));
|
|
|
|
|
String questionOptionE = getCellFormatValue(row.getCell(map.get(columns[9])));
|
|
|
|
|
String questionOptionA = getCellFormatValue(row.getCell(map.get(columns[6])));
|
|
|
|
|
String questionOptionB = getCellFormatValue(row.getCell(map.get(columns[7])));
|
|
|
|
|
String questionOptionC = getCellFormatValue(row.getCell(map.get(columns[8])));
|
|
|
|
|
String questionOptionD = getCellFormatValue(row.getCell(map.get(columns[9])));
|
|
|
|
|
String questionOptionE = getCellFormatValue(row.getCell(map.get(columns[10])));
|
|
|
|
|
|
|
|
|
|
String questionAnswer = getCellFormatValue(row.getCell(map.get(columns[10])));
|
|
|
|
|
String questionAnswer = getCellFormatValue(row.getCell(map.get(columns[11])));
|
|
|
|
|
questionAnswer = answerFormat(questionType, questionAnswer);//格式化
|
|
|
|
|
String questionAnalysis = getCellFormatValue(row.getCell(map.get(columns[11])));
|
|
|
|
|
String questionAnalysis = getCellFormatValue(row.getCell(map.get(columns[12])));
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(questionScore)) {
|
|
|
|
|
questionScore = "1";//默认一分
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(StringUtils.isNotBlank(questionType)){
|
|
|
|
|
questionType = questionType.replace("题","");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String m = "";
|
|
|
|
|
if (StringUtils.isNotBlank(questionAnswer)) {
|
|
|
|
|
m = judge(questionType, questionOptionA, questionOptionB, questionOptionC, questionOptionD, questionOptionE, questionAnswer);
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isBlank(courseInfoName)) {
|
|
|
|
|
errMsg.add(new String[]{"第"+ToolUtils.numberToLetter(map.get(columns[1])+1)+"列,第"+(i+1)+"行归属章节为空"});
|
|
|
|
|
errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[0]) + 1) + "列,第" + (i + 1) + "行课程为空"});
|
|
|
|
|
continue;
|
|
|
|
|
}else if(courseInfoName.split("__ID").length != 2){
|
|
|
|
|
errMsg.add(new String[]{"第"+ToolUtils.numberToLetter(map.get(columns[1])+1)+"列,第"+(i+1)+"行章节ID丢失"});
|
|
|
|
|
} else if (StringUtils.isBlank(chapterName)) {
|
|
|
|
|
errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[2]) + 1) + "列,第" + (i + 1) + "行归属章节为空"});
|
|
|
|
|
continue;
|
|
|
|
|
}else if(StringUtils.isBlank(questionType)){
|
|
|
|
|
errMsg.add(new String[]{"第"+ToolUtils.numberToLetter(map.get(columns[2])+1)+"列,第"+(i+1)+"行题型为空"});
|
|
|
|
|
}
|
|
|
|
|
//else if (courseInfoName.split("__ID").length != 2) {
|
|
|
|
|
// errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[1]) + 1) + "列,第" + (i + 1) + "行章节ID丢失"});
|
|
|
|
|
// continue;
|
|
|
|
|
//}
|
|
|
|
|
else if (StringUtils.isBlank(questionType)) {
|
|
|
|
|
errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[3]) + 1) + "列,第" + (i + 1) + "行题型为空"});
|
|
|
|
|
continue;
|
|
|
|
|
}else if(ToolUtils.findInSet("单选,多选,判断",questionType)){
|
|
|
|
|
errMsg.add(new String[]{"第"+ToolUtils.numberToLetter(map.get(columns[2])+1)+"列,第"+(i+1)+"行题型异常"});
|
|
|
|
|
} else if (!ToolUtils.findInSet("单选,多选,判断", questionType)) {
|
|
|
|
|
errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[3]) + 1) + "列,第" + (i + 1) + "行题型异常"});
|
|
|
|
|
continue;
|
|
|
|
|
} else if (StringUtils.isBlank(questionScore)) {
|
|
|
|
|
errMsg.add(new String[]{"第"+ToolUtils.numberToLetter(map.get(columns[3])+1)+"列,第"+(i+1)+"行分值为空"});
|
|
|
|
|
errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[4]) + 1) + "列,第" + (i + 1) + "行分值为空"});
|
|
|
|
|
continue;
|
|
|
|
|
} else if (StringUtils.isBlank(questionStem)) {
|
|
|
|
|
errMsg.add(new String[]{"第"+ToolUtils.numberToLetter(map.get(columns[4])+1)+"列,第"+(i+1)+"行题干为空"});
|
|
|
|
|
errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[5]) + 1) + "列,第" + (i + 1) + "行题干为空"});
|
|
|
|
|
continue;
|
|
|
|
|
} else if (StringUtils.isBlank(questionAnswer)) {
|
|
|
|
|
errMsg.add(new String[]{"第"+ToolUtils.numberToLetter(map.get(columns[10])+1)+"列,第"+(i+1)+"行答案为空"});
|
|
|
|
|
errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[11]) + 1) + "列,第" + (i + 1) + "行答案为空"});
|
|
|
|
|
continue;
|
|
|
|
|
} else if (StringUtils.isNotBlank(m)) {
|
|
|
|
|
errMsg.add(new String[]{"第" + (i + 1) + "行" + m});
|
|
|
|
|
continue;
|
|
|
|
|
}else {
|
|
|
|
|
ResourcesQuestion rq = new ResourcesQuestion();
|
|
|
|
|
rq.setQuestionStem(questionStem);
|
|
|
|
|
if(resourcesQuestionDao.template(rq).size()>0){
|
|
|
|
|
errMsg.add(new String[]{"第"+(i+1)+"行题目重复"});
|
|
|
|
|
} else if (!NumberUtil.isNumber(questionScore)) {
|
|
|
|
|
errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[4]) + 1) + "列,第" + (i + 1) + "行分值数值格式错误"});
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
questionAnswer = questionAnswer.trim();
|
|
|
|
|
courseInfoName = courseInfoName.trim();
|
|
|
|
|
chapterName = chapterName.trim();
|
|
|
|
|
questionType = questionType.trim();
|
|
|
|
|
questionScore = questionScore.trim();
|
|
|
|
|
questionStem = questionStem.trim();
|
|
|
|
|
questionAnswer = questionAnswer.trim();
|
|
|
|
|
if (!StringUtils.isBlank(courseLabelName)) {
|
|
|
|
|
courseLabelName = courseLabelName.trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//去掉最后一个逗号
|
|
|
|
|
if (StringUtils.isNotBlank(questionAnswer)) {
|
|
|
|
|
if (questionAnswer.lastIndexOf(",") == questionAnswer.length() - 1) {
|
|
|
|
|
questionAnswer = questionAnswer.substring(0, questionAnswer.length() - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CourseInfo courseInfo = null;
|
|
|
|
|
if (courseInfoCache.containsKey(courseInfoName)) {
|
|
|
|
|
courseInfo = courseInfoCache.get(courseInfoName);
|
|
|
|
|
if (Objects.equals(courseInfo.getCourseInfoStatus(),2)){
|
|
|
|
|
errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[0]) + 1) + "列,第" + (i + 1) + "行课程处于禁止状态,禁止导入"});
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
//查课程
|
|
|
|
|
CourseInfoQuery courseInfoQuery = new CourseInfoQuery();
|
|
|
|
|
courseInfoQuery.setCourseLabelStatus(1);
|
|
|
|
|
courseInfoQuery.setCourseInfoType(1);
|
|
|
|
|
courseInfoQuery.setCourseInfoStatusPlural("1,2");
|
|
|
|
|
courseInfoQuery.setCourseInfoName(courseInfoName);
|
|
|
|
|
courseInfoQuery.setOrgIdPlural(baseCourseInfo.getOrgIdPlural());
|
|
|
|
|
courseInfoQuery.setCourseInfoIdPlural(baseCourseInfo.getCourseInfoIdPlural());
|
|
|
|
|
|
|
|
|
|
//调现有的接口去查
|
|
|
|
|
List<CourseInfo> courseInfoList = courseInfoService.getCourseInfoValues(courseInfoQuery);
|
|
|
|
|
|
|
|
|
|
//没有课程,添加课程
|
|
|
|
|
if (CollectionUtils.isEmpty(courseInfoList)) {
|
|
|
|
|
if (StringUtils.isBlank(courseLabelName)) {
|
|
|
|
|
errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[1]) + 1) + "列,第" + (i + 1) + "行此课程不存在,并且理论课程分类栏目为空"});
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
CourseLabel courseLabel = new CourseLabel();
|
|
|
|
|
courseLabel.setCourseLabelType(THEORY.getType());
|
|
|
|
|
courseLabel.setCourseLabelName(courseLabelName.trim());
|
|
|
|
|
courseLabel.setCourseLabelStatus(1);
|
|
|
|
|
CourseLabel once = courseLabelService.getOnce(courseLabel);
|
|
|
|
|
if (once == null) {
|
|
|
|
|
errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[1]) + 1) + "列,第" + (i + 1) + "行此课程不存在,并且理论课程分类栏目的数据在数据库中检索为空"});
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
CourseInfoQuery paras = new CourseInfoQuery();
|
|
|
|
|
paras.setCourseInfoType(1);
|
|
|
|
|
paras.setCourseLabelId(once.getCourseLabelId());
|
|
|
|
|
paras.setCourseInfoStatus(1);
|
|
|
|
|
paras.setCourseInfoName(courseInfoName);
|
|
|
|
|
paras.setOrgId(coreUser.getOrgId());
|
|
|
|
|
paras.setUserId(coreUser.getId());
|
|
|
|
|
paras.setAddTime(now);
|
|
|
|
|
paras.setCourseInfoType(1);
|
|
|
|
|
paras.setCourseInfoContent(courseInfoName);
|
|
|
|
|
|
|
|
|
|
CourseInfo addCourseInfo = courseInfoService.add(paras);
|
|
|
|
|
|
|
|
|
|
if (addCourseInfo == null || addCourseInfo.getCourseInfoId() == null) {
|
|
|
|
|
errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[0]) + 1) + "列,第" + (i + 1) + "行添加课程到系统失败"});
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//移除缓存
|
|
|
|
|
courseInfoService.flushCache(addCourseInfo.getCourseInfoId());
|
|
|
|
|
corePlatformService.clearDictCache();
|
|
|
|
|
courseInfoCache.put(courseInfoName, addCourseInfo);
|
|
|
|
|
} else {
|
|
|
|
|
courseInfoCache.put(courseInfoName, courseInfoList.get(0));
|
|
|
|
|
List<CourseInfo> chapterList = new ArrayList<>();
|
|
|
|
|
//处理子节点章节
|
|
|
|
|
Object o = courseInfoList.get(0).get("chapter");
|
|
|
|
|
if (o != null) {
|
|
|
|
|
String[] split = o.toString().split(",");
|
|
|
|
|
for (String s : split) {
|
|
|
|
|
// 第1章认识Python软件1__ID2, 第2章Python进阶操作__ID3, 第3章金融数据爬取__ID4, 第4章资产定价模型__ID5,第5章如何计算收益与风险?__ID6, 第6章股票价格涨跌趋势预测__ID7, 第7章上市公司综合评价__ID8, 第8章多因子选股策略__ID9, 第9章基于网络舆情的投资者情绪分析__ID10, 第10章个人信用违约预测与评分卡建立__ID11, 第11章银行产品精准营销__ID12, 第12章保险欺诈识别__ID13
|
|
|
|
|
|
|
|
|
|
CourseInfo item = new CourseInfo();
|
|
|
|
|
item.setCourseInfoName(s.split("__")[0].trim());
|
|
|
|
|
item.setCourseInfoId(Long.valueOf(s.split("__")[1].replace("ID", "").trim()));
|
|
|
|
|
item.setCourseInfoParentId(courseInfoList.get(0).getCourseInfoId());
|
|
|
|
|
chapterList.add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Map<String, List<CourseInfo>> collect = chapterList.stream().collect(groupingBy(CourseInfo::getCourseInfoName));
|
|
|
|
|
chapterCache.put(courseInfoName, collect);
|
|
|
|
|
}
|
|
|
|
|
courseInfo = courseInfoCache.get(courseInfoName);
|
|
|
|
|
if (Objects.equals(courseInfo.getCourseInfoStatus(),2)){
|
|
|
|
|
errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[0]) + 1) + "列,第" + (i + 1) + "行课程处于禁止状态,禁止导入"});
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//查章节
|
|
|
|
|
CourseInfo chapterCourseInfo = null;
|
|
|
|
|
Map<String, List<CourseInfo>> chapterMap = chapterCache.get(courseInfoName);
|
|
|
|
|
|
|
|
|
|
if (chapterMap == null) {
|
|
|
|
|
chapterMap = new HashMap<>();
|
|
|
|
|
chapterCache.put(courseInfoName, chapterMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(chapterMap.get(chapterName))) {
|
|
|
|
|
//没有这个子章节,新建,为什么不再去查呢,因为上面查课程已经顺路查了,就的话早就查出来了
|
|
|
|
|
CourseInfoQuery child = new CourseInfoQuery();
|
|
|
|
|
child.setCourseInfoParentId(courseInfo.getCourseInfoId());
|
|
|
|
|
child.setOrgId(courseInfo.getOrgId());
|
|
|
|
|
child.setUserId(courseInfo.getUserId());
|
|
|
|
|
child.setCourseInfoName(chapterName);
|
|
|
|
|
child.setAddTime(now);
|
|
|
|
|
child.setCourseInfoContent(chapterName);
|
|
|
|
|
child.setCourseInfoStatus(1);
|
|
|
|
|
child.setCourseInfoType(2);
|
|
|
|
|
CourseInfo addChild = courseInfoService.add(child);
|
|
|
|
|
|
|
|
|
|
if (addChild == null || addChild.getCourseInfoId() == null) {
|
|
|
|
|
errMsg.add(new String[]{"第" + ToolUtils.numberToLetter(map.get(columns[2]) + 1) + "列,第" + (i + 1) + "行添加章节到系统失败"});
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//移除缓存
|
|
|
|
|
courseInfoService.flushCache(addChild.getCourseInfoId());
|
|
|
|
|
corePlatformService.clearDictCache();
|
|
|
|
|
courseInfoCache.put(courseInfoName, addChild);
|
|
|
|
|
|
|
|
|
|
chapterMap.put(chapterName, new ArrayList<CourseInfo>() {{
|
|
|
|
|
add(addChild);
|
|
|
|
|
}});
|
|
|
|
|
chapterCourseInfo = addChild;
|
|
|
|
|
} else {
|
|
|
|
|
chapterCourseInfo = chapterMap.get(chapterName).get(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResourcesQuestion rq = new ResourcesQuestion();
|
|
|
|
|
rq.setQuestionStem(questionStem);
|
|
|
|
|
rq.setCourseInfoId(chapterCourseInfo.getCourseInfoId());
|
|
|
|
|
if (resourcesQuestionDao.template(rq).size() > 0) {
|
|
|
|
|
errMsg.add(new String[]{"第" + (i + 1) + "行题目重复"});
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//插入题目
|
|
|
|
|
ResourcesQuestion pojo = new ResourcesQuestion();
|
|
|
|
|
|
|
|
|
|
pojo.setCourseInfoId(Long.parseLong(courseInfoName.split("__ID")[1]));
|
|
|
|
|
pojo.setCourseInfoId(chapterCourseInfo.getCourseInfoId());
|
|
|
|
|
pojo.setQuestionType("单选".equals(questionType) ? 1 : "多选".equals(questionType) ? 2 : 3);
|
|
|
|
|
pojo.setQuestionScore(StringUtils.isNotBlank(questionScore) ? new BigDecimal(questionScore) : BigDecimal.ONE);
|
|
|
|
|
pojo.setQuestionStem(questionStem);
|
|
|
|
@ -472,18 +652,23 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
pojo.setQuestionAnalysis(questionAnalysis);
|
|
|
|
|
// 默认导入上架状态
|
|
|
|
|
pojo.setQuestionStatus(1);
|
|
|
|
|
if (coreUser.isUniAdmin()) {
|
|
|
|
|
pojo.setAddType(FACULTY_ADD);
|
|
|
|
|
}else {
|
|
|
|
|
pojo.setAddType(ADMIN_ADD);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
insert(pojo);
|
|
|
|
|
|
|
|
|
|
CourseInfo courseInfo = courseInfoDao.single(pojo.getCourseInfoId());
|
|
|
|
|
insert(pojo);
|
|
|
|
|
|
|
|
|
|
if(null != courseInfo){
|
|
|
|
|
//更新章节
|
|
|
|
|
CourseInfo c = new CourseInfo();
|
|
|
|
|
c.setCourseInfoId(courseInfo.getCourseInfoId());
|
|
|
|
|
c.setResourcesQuestionIds(StringUtils.isNotBlank(courseInfo.getResourcesQuestionIds())?(courseInfo.getResourcesQuestionIds()+","+pojo.getResourcesQuestionId()):pojo.getResourcesQuestionId().toString());
|
|
|
|
|
c.setCourseInfoId(chapterCourseInfo.getCourseInfoId());
|
|
|
|
|
c.setResourcesQuestionIds(StringUtils.isNotBlank(chapterCourseInfo.getResourcesQuestionIds()) ? (chapterCourseInfo.getResourcesQuestionIds() + "," + pojo.getResourcesQuestionId()) : pojo.getResourcesQuestionId().toString());
|
|
|
|
|
courseInfoDao.updateTemplateById(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新本地缓存中章节中的题目ids
|
|
|
|
|
chapterCourseInfo.setResourcesQuestionIds(c.getResourcesQuestionIds());
|
|
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
@ -493,10 +678,14 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
JsonResult jsonResult = new JsonResult();
|
|
|
|
|
jsonResult.setCode(JsonReturnCode.SUCCESS.getCode());
|
|
|
|
|
jsonResult.setData(errMsg);
|
|
|
|
|
jsonResult.setMsg("导入成功,共导入"+count+"条"+(StringUtils.isNotBlank(msg)?"<br>"+msg:""));
|
|
|
|
|
jsonResult.setMsg("导入成功,共导入" + count + "条。");
|
|
|
|
|
return jsonResult;
|
|
|
|
|
} else {
|
|
|
|
|
return JsonResult.failMessage("导入失败"+(StringUtils.isNotBlank(msg)?"<br>"+msg:""));
|
|
|
|
|
JsonResult jsonResult = new JsonResult();
|
|
|
|
|
jsonResult.setCode(JsonReturnCode.FAIL.getCode());
|
|
|
|
|
jsonResult.setData(errMsg);
|
|
|
|
|
jsonResult.setMsg("导入全部失败,请查看下面的失败列表");
|
|
|
|
|
return jsonResult;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return JsonResult.failMessage("导入失败");
|
|
|
|
@ -513,6 +702,7 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
public String answerFormat(Integer questionType, String questionAnswer) {
|
|
|
|
|
return answerFormat(((Integer) 1).equals(questionType) ? "单选" : ((Integer) 2).equals(questionType) ? "多选" : "判断", questionAnswer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//答案格式化
|
|
|
|
|
public String answerFormat(String questionType, String questionAnswer) {
|
|
|
|
|
if (StringUtils.isNotBlank(questionType)) {
|
|
|
|
@ -664,6 +854,7 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据题目类型分类指定题目
|
|
|
|
|
*
|
|
|
|
|
* @param resourcesApplicationIds
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
@ -675,6 +866,7 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 随机打乱题目中选项的顺序
|
|
|
|
|
*
|
|
|
|
|
* @param questionList
|
|
|
|
|
*/
|
|
|
|
|
public void orderOptions(List<ResourcesQuestion> questionList) {
|
|
|
|
@ -786,6 +978,7 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据开课ID获取下面的题目类型和类型下的总题数
|
|
|
|
|
*
|
|
|
|
|
* @param courseInfoQuery
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
@ -797,6 +990,7 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据机构ids和课程分类查询题目类型对应的数量
|
|
|
|
|
*
|
|
|
|
|
* @param courseInfoQuery
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
@ -959,10 +1153,14 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
resultVO.setQuestionCount(recordsCount.get());
|
|
|
|
|
resultVO.setQuestionList(questionList);
|
|
|
|
|
|
|
|
|
|
} catch (Exception ex) { ex.printStackTrace(); }
|
|
|
|
|
finally {
|
|
|
|
|
try {xDocument.get().close(); }
|
|
|
|
|
catch (Exception ioe) { ioe.printStackTrace(); }
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
try {
|
|
|
|
|
xDocument.get().close();
|
|
|
|
|
} catch (Exception ioe) {
|
|
|
|
|
ioe.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return resultVO;
|
|
|
|
@ -970,6 +1168,7 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据传入的参数,模糊匹配课程ID,并放在返回值中
|
|
|
|
|
*
|
|
|
|
|
* @param fileEntityList 文件列表
|
|
|
|
|
* @param businessType 来源类型
|
|
|
|
|
* @param matchType 匹配类型
|
|
|
|
@ -1001,6 +1200,7 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 给题目添加选项
|
|
|
|
|
*
|
|
|
|
|
* @param text 单个选项的内容
|
|
|
|
|
* @param question 题目实体
|
|
|
|
|
*/
|
|
|
|
@ -1039,7 +1239,8 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
String replacedText = questionStem.get().replaceAll(LINE_8, SPLIT_);
|
|
|
|
|
question.get().setQuestionOptionA(String.valueOf(StrUtil.count(replacedText, SPLIT_)));
|
|
|
|
|
question.get().setQuestionStem(replacedText);
|
|
|
|
|
} break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
/** 选项 */
|
|
|
|
|
case OPTION: {
|
|
|
|
|
|
|
|
|
@ -1055,17 +1256,20 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
else if (FILL_QUESTION.equals(typeConcatEnum.get())) {
|
|
|
|
|
question.get().setQuestionOptionA(String.valueOf(StrUtil.count(question.get().getQuestionOptionB(), SPLIT_)));
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
/** 答案 */
|
|
|
|
|
case ANSWER: {
|
|
|
|
|
questionAnswer.set(secondFormat(questionAnswer.get().concat(v), typeConcatEnum.get()));
|
|
|
|
|
question.get().setQuestionAnswer(questionAnswer.get());
|
|
|
|
|
} break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询是否存在,不存在则插入新数据
|
|
|
|
|
*
|
|
|
|
|
* @param typeConcatEnum
|
|
|
|
|
*/
|
|
|
|
|
public ResourcesQuestionTypeEnum selectQuestionType(StrategyContext.QuestionTypeConcatEnum typeConcatEnum) {
|
|
|
|
@ -1075,10 +1279,13 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
/**
|
|
|
|
|
* 验证本地待上传的题库 是否存在重复,
|
|
|
|
|
* 本次上传的题目判断唯一性
|
|
|
|
|
*
|
|
|
|
|
* @param questionList
|
|
|
|
|
*/
|
|
|
|
|
private void checkLocalQuestionsUnique(List<ResourcesQuestion> questionList) {
|
|
|
|
|
if (ObjectUtil.isEmpty(questionList)) { return; }
|
|
|
|
|
if (ObjectUtil.isEmpty(questionList)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 默认给50道题的容量
|
|
|
|
|
final Set<String> hashSet = new LinkedHashSet<>(50);
|
|
|
|
|
final List<String> strings = new ArrayList<>(50);
|
|
|
|
@ -1088,8 +1295,9 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
if (!hashSet.add(questionToString)) {
|
|
|
|
|
// 告知前端 错误异常
|
|
|
|
|
question.set("errMsg", String.format("可能与上面的第 【%s】 题重复", strings.indexOf(questionToString) + 1));
|
|
|
|
|
} else {
|
|
|
|
|
strings.add(questionToString);
|
|
|
|
|
}
|
|
|
|
|
else { strings.add(questionToString); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hashSet.clear();
|
|
|
|
@ -1098,6 +1306,7 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检测题目唯一
|
|
|
|
|
*
|
|
|
|
|
* @param question
|
|
|
|
|
*/
|
|
|
|
|
public void checkUnique(@NotNull ResourcesQuestion question) {
|
|
|
|
@ -1132,7 +1341,9 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public String secondFormat(String questionAnswer, StrategyContext.QuestionTypeConcatEnum typeConcatEnum) {
|
|
|
|
|
if (StringUtils.isBlank(questionAnswer)) { return questionAnswer; }
|
|
|
|
|
if (StringUtils.isBlank(questionAnswer)) {
|
|
|
|
|
return questionAnswer;
|
|
|
|
|
}
|
|
|
|
|
// 去除各种空格
|
|
|
|
|
questionAnswer = org.springframework.util.StringUtils.trimAllWhitespace(questionAnswer);
|
|
|
|
|
// <p>ABC</p> 只获取ABC 删除所有</>标签元素。
|
|
|
|
|