From 9cb0e31627c5050991940d149affc2dbdd86c833 Mon Sep 17 00:00:00 2001 From: qirong <2032486488@qq.com> Date: 星期四, 15 六月 2023 11:57:47 +0800 Subject: [PATCH] 多选部门标签 --- src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java | 49 ++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java b/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java index b35f36f..5bdb50a 100644 --- a/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java +++ b/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java @@ -8,10 +8,7 @@ import com.mindskip.xzs.domain.other.KeyValue; import com.mindskip.xzs.repository.ExamPaperMapper; import com.mindskip.xzs.repository.QuestionMapper; -import com.mindskip.xzs.service.ExamPaperService; -import com.mindskip.xzs.service.QuestionService; -import com.mindskip.xzs.service.SubjectService; -import com.mindskip.xzs.service.TextContentService; +import com.mindskip.xzs.service.*; import com.mindskip.xzs.service.enums.ActionEnum; import com.mindskip.xzs.utility.DateTimeUtil; import com.mindskip.xzs.utility.JsonUtil; @@ -49,15 +46,19 @@ private final TextContentService textContentService; private final QuestionService questionService; private final SubjectService subjectService; + private final ExamPaperDepartmentService examPaperDepartmentService; + private final ExamPaperSubjectService examPaperSubjectService; @Autowired - public ExamPaperServiceImpl(ExamPaperMapper examPaperMapper, QuestionMapper questionMapper, TextContentService textContentService, QuestionService questionService, SubjectService subjectService) { + public ExamPaperServiceImpl(ExamPaperMapper examPaperMapper, QuestionMapper questionMapper, TextContentService textContentService, QuestionService questionService, SubjectService subjectService, ExamPaperDepartmentService examPaperDepartmentService, ExamPaperSubjectService examPaperSubjectService) { super(examPaperMapper); this.examPaperMapper = examPaperMapper; this.questionMapper = questionMapper; this.textContentService = textContentService; this.questionService = questionService; this.subjectService = subjectService; + this.examPaperDepartmentService = examPaperDepartmentService; + this.examPaperSubjectService = examPaperSubjectService; } @@ -100,6 +101,7 @@ examPaper.setDeleted(false); examPaperFromVM(examPaperEditRequestVM, examPaper, titleItemsVM); examPaperMapper.insertSelective(examPaper); + } else { examPaper = examPaperMapper.selectByPrimaryKey(examPaperEditRequestVM.getId()); TextContent frameTextContent = textContentService.selectById(examPaper.getFrameTextContentId()); @@ -108,7 +110,12 @@ modelMapper.map(examPaperEditRequestVM, examPaper); examPaperFromVM(examPaperEditRequestVM, examPaper, titleItemsVM); examPaperMapper.updateByPrimaryKeySelective(examPaper); + //鎵归噺淇敼 + examPaperDepartmentService.removeByExamPaperId(examPaper.getId()); + examPaperSubjectService.removeByExamPaperId(examPaper.getId()); } + addExamPaperDepartment(examPaperEditRequestVM,examPaper); + addExamPaperSubject(examPaperEditRequestVM,examPaper); return examPaper; } @@ -141,6 +148,12 @@ List<String> limitDateTime = Arrays.asList(DateTimeUtil.dateFormat(examPaper.getLimitStartTime()), DateTimeUtil.dateFormat(examPaper.getLimitEndTime())); vm.setLimitDateTime(limitDateTime); } + + //鏌ヨ閮ㄩ棬鍜岃鐩� + vm.setSubjectId(examPaperSubjectService.getByExamPaperId(examPaper.getId()) + .stream().map(ExamPaperSubject::getSubjectId).toArray(Integer[]::new)); + vm.setDepartmentIds(examPaperDepartmentService.getByExamPaperId(examPaper.getId()) + .stream().map(ExamPaperDepartment::getDepartmentId).toArray(Integer[]::new)); return vm; } @@ -168,7 +181,7 @@ } private void examPaperFromVM(ExamPaperEditRequestVM examPaperEditRequestVM, ExamPaper examPaper, List<ExamPaperTitleItemVM> titleItemsVM) { - Integer gradeLevel = subjectService.levelBySubjectId(examPaperEditRequestVM.getSubjectId()); +// Integer gradeLevel = subjectService.levelBySubjectId(examPaperEditRequestVM.getSubjectId()); Integer questionCount = titleItemsVM.stream() .mapToInt(t -> t.getQuestionItems().size()).sum(); Integer score = titleItemsVM.stream(). @@ -177,7 +190,7 @@ ).sum(); examPaper.setQuestionCount(questionCount); examPaper.setScore(score); - examPaper.setGradeLevel(gradeLevel); + examPaper.setGradeLevel(null); List<String> dateTimes = examPaperEditRequestVM.getLimitDateTime(); if (ExamPaperTypeEnum.TimeLimit == ExamPaperTypeEnum.fromCode(examPaper.getPaperType())) { examPaper.setLimitStartTime(DateTimeUtil.parse(dateTimes.get(0), DateTimeUtil.STANDER_FORMAT)); @@ -200,4 +213,26 @@ return titleItem; }).collect(Collectors.toList()); } + + private void addExamPaperDepartment(ExamPaperEditRequestVM examPaperEditRequestVM, ExamPaper examPaper){ + List<ExamPaperDepartment> list = Arrays.asList(examPaperEditRequestVM.getDepartmentIds()).stream().map(e->{ + ExamPaperDepartment examPaperDepartment = new ExamPaperDepartment(); + examPaperDepartment.setExamPaperId(examPaper.getId()); + examPaperDepartment.setDepartmentId(e); + examPaperDepartment.setDeleted("0"); + return examPaperDepartment; + }).collect(Collectors.toList()); + examPaperDepartmentService.saves(list); + } + + private void addExamPaperSubject(ExamPaperEditRequestVM examPaperEditRequestVM, ExamPaper examPaper){ + List<ExamPaperSubject> subjectList = Arrays.asList(examPaperEditRequestVM.getSubjectId()).stream().map(e->{ + ExamPaperSubject examPaperSubject = new ExamPaperSubject(); + examPaperSubject.setSubjectId(e); + examPaperSubject.setExamPaperId(examPaper.getId()); + examPaperSubject.setDeleted("0"); + return examPaperSubject; + }).collect(Collectors.toList()); + examPaperSubjectService.saves(subjectList); + } } -- Gitblit v1.8.0