| | |
| | | package com.mindskip.xzs.controller.admin; |
| | | |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.mindskip.xzs.base.BaseApiController; |
| | | import com.mindskip.xzs.base.RestResponse; |
| | | import com.mindskip.xzs.domain.ExamPaper; |
| | | import com.mindskip.xzs.domain.ExamPaperSubject; |
| | | import com.mindskip.xzs.domain.vo.ExamTemplatesVO; |
| | | import com.mindskip.xzs.domain.vo.PaperExcelVO; |
| | | import com.mindskip.xzs.domain.vo.UserVO; |
| | | import com.mindskip.xzs.service.ExamPaperDepartmentService; |
| | | import com.mindskip.xzs.service.ExamPaperService; |
| | | import com.mindskip.xzs.service.ExamPaperSubjectService; |
| | | import com.mindskip.xzs.service.ExamTemplatesUserCountService; |
| | | import com.mindskip.xzs.utility.DateTimeUtil; |
| | | import com.mindskip.xzs.utility.PageInfoHelper; |
| | | import com.mindskip.xzs.viewmodel.admin.exam.ExamPaperPageRequestVM; |
| | | import com.mindskip.xzs.viewmodel.admin.exam.ExamPaperEditRequestVM; |
| | | import com.mindskip.xzs.viewmodel.admin.exam.ExamResponseVM; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.mindskip.xzs.utility.excel.ExcelUtils; |
| | | import com.mindskip.xzs.viewmodel.admin.exam.*; |
| | | import lombok.SneakyThrows; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.validation.Valid; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | @RestController("AdminExamPaperController") |
| | | @RequestMapping(value = "/api/admin/exam/paper") |
| | |
| | | private final ExamPaperService examPaperService; |
| | | private final ExamPaperSubjectService examPaperSubjectService; |
| | | private final ExamPaperDepartmentService examPaperDepartmentService; |
| | | private final ExamTemplatesUserCountService examTemplatesUserCountService; |
| | | |
| | | @Autowired |
| | | public ExamPaperController(ExamPaperService examPaperService, ExamPaperSubjectService examPaperSubjectService, ExamPaperDepartmentService examPaperDepartmentService) { |
| | | public ExamPaperController(ExamPaperService examPaperService, ExamPaperSubjectService examPaperSubjectService, ExamPaperDepartmentService examPaperDepartmentService, ExamTemplatesUserCountService examTemplatesUserCountService) { |
| | | this.examPaperService = examPaperService; |
| | | this.examPaperSubjectService = examPaperSubjectService; |
| | | this.examPaperDepartmentService = examPaperDepartmentService; |
| | | this.examTemplatesUserCountService = examTemplatesUserCountService; |
| | | } |
| | | |
| | | @RequestMapping(value = "/page", method = RequestMethod.POST) |
| | | public RestResponse<PageInfo<ExamResponseVM>> pageList(@RequestBody ExamPaperPageRequestVM model) { |
| | | // model.setDeptIds(ObjectUtils.isNotEmpty(model.getDeptIds()) ? model.getDeptIds() : getAdminDeptIds()); |
| | | if (Objects.nonNull(model.getLevel())) { |
| | | model.setDeptIds(Collections.singletonList(model.getLevel())); |
| | | } |
| | | model.setType("0"); |
| | | PageInfo<ExamPaper> pageInfo = examPaperService.page(model); |
| | | PageInfo<ExamResponseVM> page = PageInfoHelper.copyMap(pageInfo, e -> { |
| | |
| | | vm.setCreateTime(DateTimeUtil.dateFormat(e.getCreateTime())); |
| | | vm.setSubjectId(examPaperSubjectService.getByExamPaperId(vm.getId()) |
| | | .stream().map(ExamPaperSubject::getSubjectId).toArray(Integer[]::new)); |
| | | vm.setCreateDepartment(examPaperDepartmentService.selectByUserId(vm.getCreateUser())); |
| | | return vm; |
| | | }); |
| | | return RestResponse.ok(page); |
| | |
| | | |
| | | |
| | | @RequestMapping(value = "/edit", method = RequestMethod.POST) |
| | | public RestResponse<ExamPaperEditRequestVM> edit(@RequestBody @Valid ExamPaperEditRequestVM model) throws Exception { |
| | | public RestResponse<ExamPaperEditRequestVO> edit(@RequestBody @Valid ExamPaperEditRequestVM model) throws Exception { |
| | | // Object[] obj = Arrays.stream(model.getUserIds()).sorted().distinct().toArray(); |
| | | // Integer[] userIds = new Integer[obj.length]; |
| | | // for(int i = 0;i<obj.length;i++) { |
| | | // userIds[i] = (Integer)obj[i]; |
| | | // } |
| | | // model.setUserIds(userIds); |
| | | ExamPaper examPaper = examPaperService.savePaperFromVM(model, getCurrentUser()); |
| | | ExamPaperEditRequestVM newVM = examPaperService.examPaperToVM(examPaper.getId()); |
| | | ExamPaperEditRequestVO newVM = examPaperService.examPaperToVM(examPaper.getId()); |
| | | |
| | | return RestResponse.ok(newVM); |
| | | } |
| | | |
| | | /** |
| | | * 补考 |
| | | * @param model 数据 |
| | | * @return 操作结果 |
| | | */ |
| | | @RequestMapping(value = "/missExam", method = RequestMethod.POST) |
| | | public RestResponse<String> missExam(@RequestBody ExamPaperEditRequestVM model) { |
| | | examPaperService.missExam(model); |
| | | return RestResponse.ok("操作成功"); |
| | | } |
| | | |
| | | /** |
| | | * 补考 |
| | | * @param model 数据 |
| | | * @return 操作结果 |
| | | */ |
| | | @RequestMapping(value = "/missExamByTemplateId", method = RequestMethod.POST) |
| | | public RestResponse<String> missExamByTemplateId(@RequestBody ExamTemplatesVO model) { |
| | | examPaperService.missExamByTemplateId(model); |
| | | return RestResponse.ok("操作成功"); |
| | | } |
| | | |
| | | @RequestMapping(value = "/select/{id}", method = RequestMethod.POST) |
| | | public RestResponse<ExamPaperEditRequestVM> select(@PathVariable Integer id) { |
| | | ExamPaperEditRequestVM vm = examPaperService.examPaperToVM(id); |
| | | public RestResponse<ExamPaperEditRequestVO> select(@PathVariable Integer id) { |
| | | ExamPaperEditRequestVO vm = examPaperService.examPaperToVM(id); |
| | | for (ExamPaperTitleItemVO titleItem : vm.getTitleItems()) { |
| | | titleItem.getQuestionItems().stream().forEach(question -> { |
| | | // 清空答案、解析 |
| | | question.setCorrect(""); |
| | | question.setAnalyze(""); |
| | | question.setCorrectArray(null); |
| | | }); |
| | | } |
| | | return RestResponse.ok(vm); |
| | | } |
| | | |
| | |
| | | examPaperSubjectService.removeByExamPaperId(id); |
| | | return RestResponse.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/exportTemplatesId/{id}", method = RequestMethod.GET) |
| | | @SneakyThrows |
| | | public void exportTemplatesId(@PathVariable("id") Integer id, HttpServletResponse response, HttpServletRequest request) { |
| | | List<PaperExcelVO> list = examPaperService.getPaperExcelById(id); |
| | | ExcelUtils.export(response,"个人练习",list,PaperExcelVO.class); |
| | | } |
| | | |
| | | @RequestMapping(value = "/list", method = RequestMethod.GET) |
| | | public RestResponse<List<ExamPaper>> list() { |
| | | List<Integer> deptIds = isDeptAdmin() ? getAdminDeptIds() : null; |
| | | return RestResponse.ok(examPaperService.list(deptIds)); |
| | | } |
| | | |
| | | @RequestMapping(value = "/selectStudent", method = RequestMethod.POST) |
| | | public RestResponse<PageInfo<UserVO>> selectStudent(@RequestBody UserVO userVO) { |
| | | List<Integer> adminDeptIds = getAdminDeptIds(); |
| | | return RestResponse.ok(examPaperService.selectStudent(userVO, adminDeptIds)); |
| | | } |
| | | |
| | | @RequestMapping(value = "/queryCondition", method = RequestMethod.GET) |
| | | public RestResponse<List<ExamPaper>> queryCondition() { |
| | | return RestResponse.ok(examPaperService.queryCondition()); |
| | | } |
| | | } |