|
@@ -46,7 +46,6 @@ import cn.com.qmth.examcloud.core.questions.dao.entity.QuesOption;
|
|
import cn.com.qmth.examcloud.core.questions.dao.entity.QuesProperty;
|
|
import cn.com.qmth.examcloud.core.questions.dao.entity.QuesProperty;
|
|
import cn.com.qmth.examcloud.core.questions.dao.entity.QuesTypeName;
|
|
import cn.com.qmth.examcloud.core.questions.dao.entity.QuesTypeName;
|
|
import cn.com.qmth.examcloud.core.questions.dao.entity.Question;
|
|
import cn.com.qmth.examcloud.core.questions.dao.entity.Question;
|
|
-import cn.com.qmth.examcloud.core.questions.service.PaperService;
|
|
|
|
import cn.com.qmth.examcloud.web.config.SystemProperties;
|
|
import cn.com.qmth.examcloud.web.config.SystemProperties;
|
|
|
|
|
|
@Component
|
|
@Component
|
|
@@ -58,8 +57,6 @@ public class YunkaiService {
|
|
@Autowired
|
|
@Autowired
|
|
private PaperRepo paperRepo;
|
|
private PaperRepo paperRepo;
|
|
@Autowired
|
|
@Autowired
|
|
- private PaperService paperService;
|
|
|
|
- @Autowired
|
|
|
|
private PaperDetailRepo paperDetailRepo;
|
|
private PaperDetailRepo paperDetailRepo;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -71,12 +68,66 @@ public class YunkaiService {
|
|
private QuesTypeNameRepo quesTypeNameRepo;
|
|
private QuesTypeNameRepo quesTypeNameRepo;
|
|
@Autowired
|
|
@Autowired
|
|
private SystemProperties systemProperties;
|
|
private SystemProperties systemProperties;
|
|
-
|
|
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private PropertyRepo propertyRepo;
|
|
private PropertyRepo propertyRepo;
|
|
|
|
|
|
|
|
+ private void savePropOneCourse(User user, File zfile, Long rootOrgId, String courseCode, String batch) {
|
|
|
|
+ GetCourseReq req = new GetCourseReq();
|
|
|
|
+ req.setRootOrgId(rootOrgId);
|
|
|
|
+ req.setCode(courseCode);
|
|
|
|
+ GetCourseResp res = courseCloudService.getCourse(req);
|
|
|
|
+
|
|
|
|
+ CourseProperty cp = new CourseProperty();
|
|
|
|
+ cp.setCourseCode(courseCode);
|
|
|
|
+ cp.setCourseId(res.getCourseBean().getId());
|
|
|
|
+ cp.setCourseName(res.getCourseBean().getName());
|
|
|
|
+ cp.setEnable(true);
|
|
|
|
+ cp.setOrgId(rootOrgId);
|
|
|
|
+ cp.setName(res.getCourseBean().getName() + "课程属性" + batch);
|
|
|
|
+ cp.setBatch(batch);
|
|
|
|
+ coursePropertyRepo.save(cp);
|
|
|
|
+ String json;
|
|
|
|
+ try {
|
|
|
|
+ json = FileUtils.readFileToString(zfile, "utf-8");
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw new StatusException("500", "文件读取出错", e);
|
|
|
|
+ }
|
|
|
|
+ List<PropertyDto> pds = JSON.parseArray(json, PropertyDto.class);
|
|
|
|
+ int num = 0;
|
|
|
|
+ for (PropertyDto pd : pds) {
|
|
|
|
+ num++;
|
|
|
|
+ Property p = new Property();
|
|
|
|
+ p.setCode(pd.getName());
|
|
|
|
+ p.setCoursePropertyId(cp.getId());
|
|
|
|
+ p.setName(pd.getName());
|
|
|
|
+ p.setNumber(num);
|
|
|
|
+ p.setOrgId(rootOrgId);
|
|
|
|
+ p.setParentId("0");
|
|
|
|
+ p.setFromId(pd.getId().toString());
|
|
|
|
+ propertyRepo.save(p);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(pd.getSubPropertyDto())) {
|
|
|
|
+ int subnum = 0;
|
|
|
|
+ List<Property> ps = new ArrayList<>();
|
|
|
|
+ for (PropertyDto subpd : pd.getSubPropertyDto()) {
|
|
|
|
+ subnum++;
|
|
|
|
+ Property subp = new Property();
|
|
|
|
+ subp.setCode(subpd.getName());
|
|
|
|
+ subp.setCoursePropertyId(cp.getId());
|
|
|
|
+ subp.setName(subpd.getName());
|
|
|
|
+ subp.setNumber(subnum);
|
|
|
|
+ subp.setOrgId(rootOrgId);
|
|
|
|
+ subp.setParentId(p.getId());
|
|
|
|
+ subp.setFromId(subpd.getId().toString());
|
|
|
|
+ ps.add(subp);
|
|
|
|
+ }
|
|
|
|
+ propertyRepo.saveAll(ps);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@Transactional
|
|
@Transactional
|
|
- public void saveProp(User user, MultipartFile dataFile, Long rootOrgId, String courseCode, String batch) {
|
|
|
|
|
|
+ public void saveProp(User user, MultipartFile dataFile, Long rootOrgId, List<String> courseCodes, String batch) {
|
|
String tempDir = systemProperties.getTempDataDir();
|
|
String tempDir = systemProperties.getTempDataDir();
|
|
String dir = tempDir + File.separator + UUID.randomUUID() + File.separator;
|
|
String dir = tempDir + File.separator + UUID.randomUUID() + File.separator;
|
|
try {
|
|
try {
|
|
@@ -85,51 +136,8 @@ public class YunkaiService {
|
|
File zfile = new File(dir + dataFile.getOriginalFilename());
|
|
File zfile = new File(dir + dataFile.getOriginalFilename());
|
|
zfile.createNewFile();
|
|
zfile.createNewFile();
|
|
dataFile.transferTo(zfile);
|
|
dataFile.transferTo(zfile);
|
|
- GetCourseReq req = new GetCourseReq();
|
|
|
|
- req.setRootOrgId(rootOrgId);
|
|
|
|
- req.setCode(courseCode);
|
|
|
|
- GetCourseResp res = courseCloudService.getCourse(req);
|
|
|
|
-
|
|
|
|
- CourseProperty cp = new CourseProperty();
|
|
|
|
- cp.setCourseCode(courseCode);
|
|
|
|
- cp.setCourseId(res.getCourseBean().getId());
|
|
|
|
- cp.setCourseName(res.getCourseBean().getName());
|
|
|
|
- cp.setEnable(true);
|
|
|
|
- cp.setOrgId(rootOrgId);
|
|
|
|
- cp.setName(res.getCourseBean().getName() + "课程属性" + batch);
|
|
|
|
- cp.setBatch(batch);
|
|
|
|
- coursePropertyRepo.save(cp);
|
|
|
|
- String json = FileUtils.readFileToString(zfile, "utf-8");
|
|
|
|
- List<PropertyDto> pds = JSON.parseArray(json, PropertyDto.class);
|
|
|
|
- int num = 0;
|
|
|
|
- for (PropertyDto pd : pds) {
|
|
|
|
- num++;
|
|
|
|
- Property p = new Property();
|
|
|
|
- p.setCode(pd.getName());
|
|
|
|
- p.setCoursePropertyId(cp.getId());
|
|
|
|
- p.setName(pd.getName());
|
|
|
|
- p.setNumber(num);
|
|
|
|
- p.setOrgId(rootOrgId);
|
|
|
|
- p.setParentId("0");
|
|
|
|
- p.setFromId(pd.getId().toString());
|
|
|
|
- propertyRepo.save(p);
|
|
|
|
- if (CollectionUtils.isNotEmpty(pd.getSubPropertyDto())) {
|
|
|
|
- int subnum = 0;
|
|
|
|
- List<Property> ps = new ArrayList<>();
|
|
|
|
- for (PropertyDto subpd : pd.getSubPropertyDto()) {
|
|
|
|
- subnum++;
|
|
|
|
- Property subp = new Property();
|
|
|
|
- subp.setCode(subpd.getName());
|
|
|
|
- subp.setCoursePropertyId(cp.getId());
|
|
|
|
- subp.setName(subpd.getName());
|
|
|
|
- subp.setNumber(subnum);
|
|
|
|
- subp.setOrgId(rootOrgId);
|
|
|
|
- subp.setParentId(p.getId());
|
|
|
|
- subp.setFromId(subpd.getId().toString());
|
|
|
|
- ps.add(subp);
|
|
|
|
- }
|
|
|
|
- propertyRepo.saveAll(ps);
|
|
|
|
- }
|
|
|
|
|
|
+ for (String courseCode : courseCodes) {
|
|
|
|
+ savePropOneCourse(user, zfile, rootOrgId, courseCode, batch);
|
|
}
|
|
}
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
throw new StatusException("500", "出错", e);
|
|
throw new StatusException("500", "出错", e);
|
|
@@ -180,30 +188,33 @@ public class YunkaiService {
|
|
private void resolvingFile(File file, YunkaiImportPaperParam p) {
|
|
private void resolvingFile(File file, YunkaiImportPaperParam p) {
|
|
List<File> files = new ArrayList<>();
|
|
List<File> files = new ArrayList<>();
|
|
getPaperFile(file, files);
|
|
getPaperFile(file, files);
|
|
- GetCourseReq req = new GetCourseReq();
|
|
|
|
- req.setRootOrgId(p.getRootOrgId());
|
|
|
|
- req.setCode(p.getCourseCode());
|
|
|
|
- GetCourseResp res = courseCloudService.getCourse(req);
|
|
|
|
- Course c=new Course();
|
|
|
|
- c.setId(res.getCourseBean().getId().toString());
|
|
|
|
- c.setCode(res.getCourseBean().getCode());
|
|
|
|
- c.setEnable(res.getCourseBean().getEnable().toString());
|
|
|
|
- c.setLevel(res.getCourseBean().getLevel());
|
|
|
|
- c.setName(res.getCourseBean().getName());
|
|
|
|
- c.setOrgId(res.getCourseBean().getRootOrgId().toString());
|
|
|
|
- p.setCourse(c);
|
|
|
|
- List<CourseProperty> cps=coursePropertyRepo.findByOrgIdAndCourseCodeAndEnable(p.getRootOrgId(),p.getCourseCode(), true);
|
|
|
|
- if(CollectionUtils.isNotEmpty(cps)) {
|
|
|
|
- p.setCourseProperty(cps.get(0));
|
|
|
|
- }
|
|
|
|
- for (File paperFile : files) {
|
|
|
|
- KdPaper kpaper = JSONObject.parseObject(FileUtil.readFileContent(paperFile), KdPaper.class);
|
|
|
|
- kpaper.setCourseCode(p.getCourseCode());
|
|
|
|
- savePaper(kpaper,p);
|
|
|
|
|
|
+ for (String courseCode : p.getCourseCodes()) {
|
|
|
|
+ GetCourseReq req = new GetCourseReq();
|
|
|
|
+ req.setRootOrgId(p.getRootOrgId());
|
|
|
|
+ req.setCode(courseCode);
|
|
|
|
+ GetCourseResp res = courseCloudService.getCourse(req);
|
|
|
|
+ Course c = new Course();
|
|
|
|
+ c.setId(res.getCourseBean().getId().toString());
|
|
|
|
+ c.setCode(res.getCourseBean().getCode());
|
|
|
|
+ c.setEnable(res.getCourseBean().getEnable().toString());
|
|
|
|
+ c.setLevel(res.getCourseBean().getLevel());
|
|
|
|
+ c.setName(res.getCourseBean().getName());
|
|
|
|
+ c.setOrgId(res.getCourseBean().getRootOrgId().toString());
|
|
|
|
+ p.setCourse(c);
|
|
|
|
+ List<CourseProperty> cps = coursePropertyRepo.findByOrgIdAndCourseCodeAndEnable(p.getRootOrgId(),
|
|
|
|
+ courseCode, true);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(cps)) {
|
|
|
|
+ p.setCourseProperty(cps.get(0));
|
|
|
|
+ }
|
|
|
|
+ for (File paperFile : files) {
|
|
|
|
+ KdPaper kpaper = JSONObject.parseObject(FileUtil.readFileContent(paperFile), KdPaper.class);
|
|
|
|
+ kpaper.setCourseCode(courseCode);
|
|
|
|
+ savePaper(kpaper, p);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void savePaper(KdPaper kpaper,YunkaiImportPaperParam p) {
|
|
|
|
|
|
+ private void savePaper(KdPaper kpaper, YunkaiImportPaperParam p) {
|
|
int questionNum = 0;
|
|
int questionNum = 0;
|
|
Paper paper = initPaper(kpaper, p);
|
|
Paper paper = initPaper(kpaper, p);
|
|
paper.setDifficultyDegree(0.5);
|
|
paper.setDifficultyDegree(0.5);
|
|
@@ -221,7 +232,8 @@ public class YunkaiService {
|
|
questionNum++;
|
|
questionNum++;
|
|
Question question = initQuestion(que, p);
|
|
Question question = initQuestion(que, p);
|
|
questions.add(question);
|
|
questions.add(question);
|
|
- PaperDetailUnit paperDetailUnit = initPaperDetailUnit(paper, paperDetail, question, questionNum,p.getUser());
|
|
|
|
|
|
+ PaperDetailUnit paperDetailUnit = initPaperDetailUnit(paper, paperDetail, question, questionNum,
|
|
|
|
+ p.getUser());
|
|
paperDetailUnits.add(paperDetailUnit);
|
|
paperDetailUnits.add(paperDetailUnit);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -272,7 +284,6 @@ public class YunkaiService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
private Paper initPaper(KdPaper kpaper, YunkaiImportPaperParam p) {
|
|
private Paper initPaper(KdPaper kpaper, YunkaiImportPaperParam p) {
|
|
int unitCount = 0;
|
|
int unitCount = 0;
|
|
for (KdDetail de : kpaper.getDetails()) {
|
|
for (KdDetail de : kpaper.getDetails()) {
|
|
@@ -301,7 +312,6 @@ public class YunkaiService {
|
|
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
|
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
private PaperDetail initPaperDetail(KdDetail de, Paper paper) {
|
|
private PaperDetail initPaperDetail(KdDetail de, Paper paper) {
|
|
PaperDetail paperDetail = new PaperDetail();
|
|
PaperDetail paperDetail = new PaperDetail();
|
|
if (de.getQuestions() != null && de.getQuestions().size() > 0) {
|
|
if (de.getQuestions() != null && de.getQuestions().size() > 0) {
|
|
@@ -318,7 +328,7 @@ public class YunkaiService {
|
|
return paperDetail;
|
|
return paperDetail;
|
|
}
|
|
}
|
|
|
|
|
|
- private Question initQuestion(KdQuestion que,YunkaiImportPaperParam p) {
|
|
|
|
|
|
+ private Question initQuestion(KdQuestion que, YunkaiImportPaperParam p) {
|
|
Question question = new Question();
|
|
Question question = new Question();
|
|
question.setFromId(que.getId().toString());
|
|
question.setFromId(que.getId().toString());
|
|
question.setCreateTime(getCurDateTime());
|
|
question.setCreateTime(getCurDateTime());
|
|
@@ -326,10 +336,10 @@ public class YunkaiService {
|
|
question.setCourse(p.getCourse());
|
|
question.setCourse(p.getCourse());
|
|
question.setOrgId(p.getRootOrgId().toString());
|
|
question.setOrgId(p.getRootOrgId().toString());
|
|
question.setHasAudio(false);
|
|
question.setHasAudio(false);
|
|
- if(que.getDifficulty()==null) {
|
|
|
|
|
|
+ if (que.getDifficulty() == null) {
|
|
question.setDifficulty("易");
|
|
question.setDifficulty("易");
|
|
question.setDifficultyDegree(0.5);
|
|
question.setDifficultyDegree(0.5);
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
question.setDifficulty(que.getDifficulty().getDesc());
|
|
question.setDifficulty(que.getDifficulty().getDesc());
|
|
question.setDifficultyDegree(que.getDifficulty().getType());
|
|
question.setDifficultyDegree(que.getDifficulty().getType());
|
|
}
|
|
}
|
|
@@ -339,23 +349,23 @@ public class YunkaiService {
|
|
question.setCreateTime(getCurDateTime());
|
|
question.setCreateTime(getCurDateTime());
|
|
// 按试题分类初始化题干,答案,选项
|
|
// 按试题分类初始化题干,答案,选项
|
|
initQuestionInfo(question, que);
|
|
initQuestionInfo(question, que);
|
|
- initQuestionProp(question, que,p);
|
|
|
|
|
|
+ initQuestionProp(question, que, p);
|
|
return question;
|
|
return question;
|
|
}
|
|
}
|
|
-
|
|
|
|
- private void initQuestionProp(Question question, KdQuestion que,YunkaiImportPaperParam p) {
|
|
|
|
- if(CollectionUtils.isEmpty(que.getPropIds())) {
|
|
|
|
|
|
+
|
|
|
|
+ private void initQuestionProp(Question question, KdQuestion que, YunkaiImportPaperParam p) {
|
|
|
|
+ if (CollectionUtils.isEmpty(que.getPropIds())) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- List<QuesProperty> quesProperties=new ArrayList<>();
|
|
|
|
- for(Long id:que.getPropIds()) {
|
|
|
|
- Property prop=propertyRepo.findByCoursePropertyIdAndFromId(p.getCourseProperty().getId(),id.toString());
|
|
|
|
- QuesProperty qp=new QuesProperty();
|
|
|
|
|
|
+ List<QuesProperty> quesProperties = new ArrayList<>();
|
|
|
|
+ for (Long id : que.getPropIds()) {
|
|
|
|
+ Property prop = propertyRepo.findByCoursePropertyIdAndFromId(p.getCourseProperty().getId(), id.toString());
|
|
|
|
+ QuesProperty qp = new QuesProperty();
|
|
quesProperties.add(qp);
|
|
quesProperties.add(qp);
|
|
qp.setCoursePropertyName(p.getCourseProperty().getName());
|
|
qp.setCoursePropertyName(p.getCourseProperty().getName());
|
|
- if("0".equals(prop.getParentId())) {
|
|
|
|
|
|
+ if ("0".equals(prop.getParentId())) {
|
|
qp.setFirstProperty(prop);
|
|
qp.setFirstProperty(prop);
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
Property fprop = Model.of(propertyRepo.findById(prop.getParentId()));
|
|
Property fprop = Model.of(propertyRepo.findById(prop.getParentId()));
|
|
qp.setFirstProperty(fprop);
|
|
qp.setFirstProperty(fprop);
|
|
qp.setSecondProperty(prop);
|
|
qp.setSecondProperty(prop);
|
|
@@ -441,7 +451,7 @@ public class YunkaiService {
|
|
question.setQuestionType(QuesStructType.FILL_BLANK_QUESTION);
|
|
question.setQuestionType(QuesStructType.FILL_BLANK_QUESTION);
|
|
String answer = que.getAnswer();
|
|
String answer = que.getAnswer();
|
|
question.setQuesAnswer(answer);
|
|
question.setQuesAnswer(answer);
|
|
- } else {//全是问答题
|
|
|
|
|
|
+ } else {// 全是问答题
|
|
String quesBody = que.getBody();
|
|
String quesBody = que.getBody();
|
|
question.setQuesBody(quesBody);
|
|
question.setQuesBody(quesBody);
|
|
question.setQuestionType(QuesStructType.TEXT_ANSWER_QUESTION);
|
|
question.setQuestionType(QuesStructType.TEXT_ANSWER_QUESTION);
|
|
@@ -460,7 +470,7 @@ public class YunkaiService {
|
|
}
|
|
}
|
|
|
|
|
|
private PaperDetailUnit initPaperDetailUnit(Paper paper, PaperDetail paperDetail, Question question,
|
|
private PaperDetailUnit initPaperDetailUnit(Paper paper, PaperDetail paperDetail, Question question,
|
|
- int questionNum,User user) {
|
|
|
|
|
|
+ int questionNum, User user) {
|
|
PaperDetailUnit paperDetailUnit = new PaperDetailUnit();
|
|
PaperDetailUnit paperDetailUnit = new PaperDetailUnit();
|
|
paperDetailUnit.setPaper(paper);
|
|
paperDetailUnit.setPaper(paper);
|
|
paperDetailUnit.setNumber(questionNum);
|
|
paperDetailUnit.setNumber(questionNum);
|