| | |
| | | import org.springblade.common.utils.arg; |
| | | import org.springblade.modules.exam.entity.ExamSubjectChoices; |
| | | import org.springblade.modules.exam.entity.ExamSubjectOption; |
| | | import org.springblade.modules.exam.excel.ExamSubjectExcel; |
| | | import org.springblade.modules.exam.mapper.ExamSubjectChoicesMapper; |
| | | import org.springblade.modules.exam.service.ExamSubjectChoicesService; |
| | | import org.springblade.modules.exam.service.ExamSubjectOptionService; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveSubjectChoicesAndOption(ExamSubjectChoicesVO examSubjectChoices) { |
| | | ExamSubjectChoices subjectChoices = new ExamSubjectChoices(); |
| | | subjectChoices.setCreateDate(new Date()); |
| | | subjectChoices.setDelFlag(0); |
| | | subjectChoices.setAnswer(examSubjectChoices.getAnswer()); |
| | | if (null!=examSubjectChoices.getAnalysis() && examSubjectChoices.getAnalysis()!=""){ |
| | | subjectChoices.setAnalysis(examSubjectChoices.getAnalysis()); |
| | | boolean status = false; |
| | | //新增 |
| | | if (null == examSubjectChoices.getId()) { |
| | | ExamSubjectChoices subjectChoices = new ExamSubjectChoices(); |
| | | subjectChoices.setCreateDate(new Date()); |
| | | subjectChoices.setDelFlag(0); |
| | | subjectChoices.setAnswer(examSubjectChoices.getAnswer()); |
| | | if (null != examSubjectChoices.getAnalysis() && examSubjectChoices.getAnalysis() != "") { |
| | | subjectChoices.setAnalysis(examSubjectChoices.getAnalysis()); |
| | | } |
| | | subjectChoices.setCreator(examSubjectChoices.getCreator()); |
| | | subjectChoices.setChoicesType(examSubjectChoices.getChoicesType()); |
| | | subjectChoices.setSubjectName(examSubjectChoices.getSubjectName()); |
| | | subjectChoices.setScore(examSubjectChoices.getScore()); |
| | | subjectChoices.setTktype(examSubjectChoices.getTktype()); |
| | | //题目新增 |
| | | status = this.save(subjectChoices); |
| | | //判断类型,单选,多选,实操 |
| | | if (examSubjectChoices.getChoicesType() == 0 || examSubjectChoices.getChoicesType() == 1 || examSubjectChoices.getChoicesType() == 3) { |
| | | //选项新增 |
| | | List<ExamSubjectOption> examSubjectOptions = examSubjectChoices.getExamSubjectOptions(); |
| | | examSubjectOptions.forEach(examSubjectOption -> { |
| | | examSubjectOption.setSubjectChoicesId(subjectChoices.getId()); |
| | | examSubjectOption.setCreateDate(new Date()); |
| | | examSubjectOption.setDelFlag(0); |
| | | //新增 |
| | | examSubjectOptionService.save(examSubjectOption); |
| | | }); |
| | | return true; |
| | | } |
| | | //内网数据同步 |
| | | try { |
| | | // arg.test01(arg.url+"/examSubjectChoices/saveSubjectChoicesAndOption",examSubjectChoices); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }else { |
| | | //修改 |
| | | ExamSubjectChoices subjectChoices = new ExamSubjectChoices(); |
| | | subjectChoices.setId(examSubjectChoices.getId()); |
| | | subjectChoices.setModifyDate(new Date()); |
| | | subjectChoices.setAnswer(examSubjectChoices.getAnswer()); |
| | | if (null != examSubjectChoices.getAnalysis() && examSubjectChoices.getAnalysis() != "") { |
| | | subjectChoices.setAnalysis(examSubjectChoices.getAnalysis()); |
| | | } |
| | | subjectChoices.setModifier(examSubjectChoices.getCreator()); |
| | | subjectChoices.setChoicesType(examSubjectChoices.getChoicesType()); |
| | | subjectChoices.setSubjectName(examSubjectChoices.getSubjectName()); |
| | | subjectChoices.setScore(examSubjectChoices.getScore()); |
| | | subjectChoices.setTktype(examSubjectChoices.getTktype()); |
| | | //题目修改 |
| | | status = this.updateById(subjectChoices); |
| | | //判断类型,单选,多选 |
| | | if (examSubjectChoices.getChoicesType() == 0 || examSubjectChoices.getChoicesType() == 1) { |
| | | //选项修改 |
| | | List<ExamSubjectOption> examSubjectOptions = examSubjectChoices.getExamSubjectOptions(); |
| | | examSubjectOptions.forEach(examSubjectOption -> { |
| | | examSubjectOption.setSubjectChoicesId(subjectChoices.getId()); |
| | | examSubjectOption.setModifyDate(new Date()); |
| | | examSubjectOption.setModifier(examSubjectChoices.getCreator()); |
| | | //修改 |
| | | examSubjectOptionService.updateById(examSubjectOption); |
| | | }); |
| | | return true; |
| | | } |
| | | //实操 |
| | | if (examSubjectChoices.getChoicesType() == 3) { |
| | | //先将选项删除 |
| | | baseMapper.removeBySubjectId(examSubjectChoices.getId()); |
| | | //选项新增 |
| | | List<ExamSubjectOption> examSubjectOptions = examSubjectChoices.getExamSubjectOptions(); |
| | | examSubjectOptions.forEach(examSubjectOption -> { |
| | | examSubjectOption.setSubjectChoicesId(subjectChoices.getId()); |
| | | examSubjectOption.setCreateDate(new Date()); |
| | | examSubjectOption.setDelFlag(0); |
| | | //新增 |
| | | examSubjectOptionService.save(examSubjectOption); |
| | | }); |
| | | return true; |
| | | } |
| | | //内网数据同步 |
| | | try { |
| | | // arg.test01(arg.url+"/examSubjectChoices/saveSubjectChoicesAndOption",examSubjectChoices); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | subjectChoices.setCreator(examSubjectChoices.getCreator()); |
| | | subjectChoices.setChoicesType(examSubjectChoices.getChoicesType()); |
| | | subjectChoices.setSubjectName(examSubjectChoices.getSubjectName()); |
| | | subjectChoices.setScore(examSubjectChoices.getScore()); |
| | | subjectChoices.setTktype(examSubjectChoices.getTktype()); |
| | | //题目新增 |
| | | boolean status = this.save(subjectChoices); |
| | | //判断类型,单选,多选 |
| | | if (examSubjectChoices.getChoicesType()==0 || examSubjectChoices.getChoicesType()==1 || examSubjectChoices.getChoicesType()==3){ |
| | | //选项新增 |
| | | List<ExamSubjectOption> examSubjectOptions = examSubjectChoices.getExamSubjectOptions(); |
| | | examSubjectOptions.forEach(examSubjectOption -> { |
| | | return status; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 题库导入 |
| | | * @param data 导入数据 |
| | | * @param isCovered |
| | | */ |
| | | @Override |
| | | public void importSubject(List<ExamSubjectExcel> data, Boolean isCovered) { |
| | | data.forEach(examSubjectExcel -> { |
| | | //题目对象 |
| | | ExamSubjectChoices subjectChoices = new ExamSubjectChoices(); |
| | | subjectChoices.setCreateDate(new Date()); |
| | | subjectChoices.setDelFlag(0); |
| | | subjectChoices.setAnswer(examSubjectExcel.getAnswer()); |
| | | if (null != examSubjectExcel.getAnalysis() && examSubjectExcel.getAnalysis() != "") { |
| | | subjectChoices.setAnalysis(examSubjectExcel.getAnalysis()); |
| | | } |
| | | subjectChoices.setChoicesType(examSubjectExcel.getChoicesType()); |
| | | subjectChoices.setSubjectName(examSubjectExcel.getSubjectName()); |
| | | subjectChoices.setScore(examSubjectExcel.getScore()); |
| | | subjectChoices.setTktype(examSubjectExcel.getTktype()); |
| | | //题目新增 |
| | | this.save(subjectChoices); |
| | | |
| | | |
| | | //判断类型,单选,多选选项新增 |
| | | if (examSubjectExcel.getChoicesType() == 0 || examSubjectExcel.getChoicesType() == 1) { |
| | | //A选项新增 |
| | | ExamSubjectOption examSubjectOption = new ExamSubjectOption(); |
| | | //选项新增 |
| | | examSubjectOption.setSubjectChoicesId(subjectChoices.getId()); |
| | | examSubjectOption.setCreateDate(new Date()); |
| | | examSubjectOption.setDelFlag(0); |
| | | examSubjectOption.setOptionName("A"); |
| | | examSubjectOption.setOptionContent(examSubjectExcel.getOptionContentA()); |
| | | //新增 |
| | | examSubjectOptionService.save(examSubjectOption); |
| | | }); |
| | | return true; |
| | | } |
| | | //内网数据同步 |
| | | try { |
| | | |
| | | //B选项新增 |
| | | ExamSubjectOption examSubjectOption1 = new ExamSubjectOption(); |
| | | //选项新增 |
| | | examSubjectOption1.setSubjectChoicesId(subjectChoices.getId()); |
| | | examSubjectOption1.setCreateDate(new Date()); |
| | | examSubjectOption1.setDelFlag(0); |
| | | examSubjectOption1.setOptionName("B"); |
| | | examSubjectOption1.setOptionContent(examSubjectExcel.getOptionContentB()); |
| | | //新增 |
| | | examSubjectOptionService.save(examSubjectOption1); |
| | | |
| | | //C选项新增 |
| | | ExamSubjectOption examSubjectOption2 = new ExamSubjectOption(); |
| | | //选项新增 |
| | | examSubjectOption2.setSubjectChoicesId(subjectChoices.getId()); |
| | | examSubjectOption2.setCreateDate(new Date()); |
| | | examSubjectOption2.setDelFlag(0); |
| | | examSubjectOption2.setOptionName("C"); |
| | | examSubjectOption2.setOptionContent(examSubjectExcel.getOptionContentC()); |
| | | //新增 |
| | | examSubjectOptionService.save(examSubjectOption2); |
| | | |
| | | //D选项新增 |
| | | ExamSubjectOption examSubjectOption3 = new ExamSubjectOption(); |
| | | //选项新增 |
| | | examSubjectOption3.setSubjectChoicesId(subjectChoices.getId()); |
| | | examSubjectOption3.setCreateDate(new Date()); |
| | | examSubjectOption3.setDelFlag(0); |
| | | examSubjectOption3.setOptionName("D"); |
| | | examSubjectOption3.setOptionContent(examSubjectExcel.getOptionContentD()); |
| | | //新增 |
| | | examSubjectOptionService.save(examSubjectOption3); |
| | | } |
| | | |
| | | |
| | | //多选选项新增 |
| | | if (examSubjectExcel.getChoicesType() == 3) { |
| | | //1选项新增 |
| | | if (null!=examSubjectExcel.getOptionContentA() && examSubjectExcel.getOptionContentA()!="") { |
| | | ExamSubjectOption examSubjectOption = new ExamSubjectOption(); |
| | | //选项新增 |
| | | examSubjectOption.setSubjectChoicesId(subjectChoices.getId()); |
| | | examSubjectOption.setCreateDate(new Date()); |
| | | examSubjectOption.setDelFlag(0); |
| | | examSubjectOption.setOptionName("1"); |
| | | examSubjectOption.setOptionContent(examSubjectExcel.getOptionContentA()); |
| | | //新增 |
| | | examSubjectOptionService.save(examSubjectOption); |
| | | } |
| | | |
| | | //2选项新增 |
| | | if (null!=examSubjectExcel.getOptionContentB() && examSubjectExcel.getOptionContentB()!="") { |
| | | ExamSubjectOption examSubjectOption1 = new ExamSubjectOption(); |
| | | //选项新增 |
| | | examSubjectOption1.setSubjectChoicesId(subjectChoices.getId()); |
| | | examSubjectOption1.setCreateDate(new Date()); |
| | | examSubjectOption1.setDelFlag(0); |
| | | examSubjectOption1.setOptionName("2"); |
| | | examSubjectOption1.setOptionContent(examSubjectExcel.getOptionContentB()); |
| | | //新增 |
| | | examSubjectOptionService.save(examSubjectOption1); |
| | | } |
| | | |
| | | //3选项新增 |
| | | if (null!=examSubjectExcel.getOptionContentC() && examSubjectExcel.getOptionContentC()!="") { |
| | | ExamSubjectOption examSubjectOption2 = new ExamSubjectOption(); |
| | | //选项新增 |
| | | examSubjectOption2.setSubjectChoicesId(subjectChoices.getId()); |
| | | examSubjectOption2.setCreateDate(new Date()); |
| | | examSubjectOption2.setDelFlag(0); |
| | | examSubjectOption2.setOptionName("3"); |
| | | examSubjectOption2.setOptionContent(examSubjectExcel.getOptionContentC()); |
| | | //新增 |
| | | examSubjectOptionService.save(examSubjectOption2); |
| | | } |
| | | |
| | | //4选项新增 |
| | | if (null!=examSubjectExcel.getOptionContentD() && examSubjectExcel.getOptionContentD()!="") { |
| | | ExamSubjectOption examSubjectOption3 = new ExamSubjectOption(); |
| | | //选项新增 |
| | | examSubjectOption3.setSubjectChoicesId(subjectChoices.getId()); |
| | | examSubjectOption3.setCreateDate(new Date()); |
| | | examSubjectOption3.setDelFlag(0); |
| | | examSubjectOption3.setOptionName("4"); |
| | | examSubjectOption3.setOptionContent(examSubjectExcel.getOptionContentD()); |
| | | //新增 |
| | | examSubjectOptionService.save(examSubjectOption3); |
| | | } |
| | | |
| | | |
| | | //5选项新增 |
| | | if (null!=examSubjectExcel.getOptionContentE() && examSubjectExcel.getOptionContentE()!="") { |
| | | ExamSubjectOption examSubjectOption4 = new ExamSubjectOption(); |
| | | //选项新增 |
| | | examSubjectOption4.setSubjectChoicesId(subjectChoices.getId()); |
| | | examSubjectOption4.setCreateDate(new Date()); |
| | | examSubjectOption4.setDelFlag(0); |
| | | examSubjectOption4.setOptionName("5"); |
| | | examSubjectOption4.setOptionContent(examSubjectExcel.getOptionContentE()); |
| | | //新增 |
| | | examSubjectOptionService.save(examSubjectOption4); |
| | | } |
| | | } |
| | | |
| | | //内网数据同步 |
| | | try { |
| | | // arg.test01(arg.url+"/examSubjectChoices/saveSubjectChoicesAndOption",examSubjectChoices); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return status; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |