package com.mindskip.xzs.controller.admin; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.mindskip.xzs.base.BaseApiController; import com.mindskip.xzs.base.RestResponse; import com.mindskip.xzs.domain.*; import com.mindskip.xzs.domain.vo.ScoreTemplatesCountVO; import com.mindskip.xzs.service.*; import com.mindskip.xzs.viewmodel.admin.paper.ExamPaperGradePageRequestVM; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import java.util.*; import java.util.stream.Collectors; @RestController("AdminExamPaperGradeController") @RequestMapping(value = "/api/admin/examPaperGrade") public class ExamPaperGradeController extends BaseApiController { private final ExamPaperAnswerService examPaperAnswerService; private final SubjectService subjectService; private final UserService userService; private final ExamPaperSubjectService examPaperSubjectService; private final ScoreTemplatesUserCountService scoreTemplatesUserCountService; private final ExamPaperUserService examPaperUserService; private final UserDepartMentService userDepartMentService; @Autowired public ExamPaperGradeController(ExamPaperAnswerService examPaperAnswerService, SubjectService subjectService, UserService userService, ExamPaperSubjectService examPaperSubjectService, ScoreTemplatesUserCountService scoreTemplatesUserCountService,ExamPaperUserService examPaperUserService,UserDepartMentService userDepartMentService) { this.examPaperAnswerService = examPaperAnswerService; this.subjectService = subjectService; this.userService = userService; this.examPaperSubjectService = examPaperSubjectService; this.scoreTemplatesUserCountService = scoreTemplatesUserCountService; this.examPaperUserService = examPaperUserService; this.userDepartMentService = userDepartMentService; } // @RequestMapping(value = "/page", method = RequestMethod.POST) // public RestResponse> pageJudgeList(@RequestBody ExamPaperGradePageRequestVM grade) { // PageInfo pageInfo = examPaperAnswerService.adminPageByGrade(grade); // PageInfo page = PageInfoHelper.copyMap(pageInfo, e -> { // ExamPaperAnswerPageResponseVM vm = modelMapper.map(e, ExamPaperAnswerPageResponseVM.class); // User user = userService.selectByIdName(e.getCreateUser(), grade.getUserName()); // if (user == null) { // return null; // } // ExamPaperAnswer examPaperAnswer = examPaperAnswerService.getById(vm.getId()); // Integer[] ids = examPaperSubjectService.getByExamPaperId(examPaperAnswer.getExamPaperId()) // .stream().map(ExamPaperSubject::getSubjectId).toArray(Integer[]::new); // String name = ""; // if (ids.length > 0) { // name = subjectService.selectByIds(ids) // .stream().map(Subject::getName).collect(Collectors.joining(",")); // } // Integer userId = examPaperUserService.getByPaperIdAndCreatUser(e.getExamPaperId(),e.getCreateUser()); // if(userId == null){ // return null; // } // vm.setCreateUser(e.getCreateUser()); // vm.setUserId(userId); // vm.setSubjectName(name); // vm.setCreateTime(DateTimeUtil.dateFormat(e.getCreateTime())); // vm.setUserName(user.getRealName()); // return vm; // }); // List list = page.getList(); // List filteredList = list.stream() // .filter(exam -> exam != null) // .collect(Collectors.toList()); // ArrayList list2 = new ArrayList<>(); // Map collect = filteredList.stream().collect(Collectors.groupingBy(ExamPaperAnswerPageResponseVM::getPaperName, Collectors.counting())); // filteredList.forEach(vm -> vm.setCounts(Math.toIntExact(collect.getOrDefault(vm.getPaperName(), 0L)))); // Map> collect1 = filteredList.stream().collect(Collectors.groupingBy(ExamPaperAnswerPageResponseVM::getUserName)); // List filteredList1 = new ArrayList<>(); // Set uniqueUserNames = new HashSet<>(); // collect1.forEach((key, value) -> { // value.forEach(item -> { // item.setUserName(key); // item.setCounts(value.size()); // }); // list2.addAll(value); // }); // for (ExamPaperAnswerPageResponseVM item : list2) { // if (uniqueUserNames.add(item.getUserName())) { // filteredList1.add(item); // } // } // page.setList(filteredList1); // return RestResponse.ok(page); // } @RequestMapping(value = "/page", method = RequestMethod.POST) public RestResponse> pageJudgeList(@RequestBody ExamPaperGradePageRequestVM grade) { List list = examPaperAnswerService.adminPageByGrade(grade); for (ExamPaperAnswer e : list) { User user = userService.selectByIdName(e.getCreateUser(), grade.getUserName()); if (user==null){ return null; } ExamPaperAnswer examPaperAnswer = examPaperAnswerService.getById(e.getId()); Integer[] ids = examPaperSubjectService.getByExamPaperId(examPaperAnswer.getExamPaperId()).stream().map(ExamPaperSubject::getSubjectId).toArray(Integer[]::new); String names = ""; if (ids.length > 0) { names = subjectService.selectByIds(ids) .stream().map(Subject::getName).collect(Collectors.joining(",")); } Integer userId = examPaperUserService.getByPaperIdAndCreatUser(e.getExamPaperId(), e.getCreateUser()); if(userId == null){ return null; } e.setUserName(user.getRealName()); } List collect = list.stream() .filter(exam -> exam != null) .collect(Collectors.toList()); ArrayList list2 = new ArrayList<>(); Map collect1 = collect.stream().collect(Collectors.groupingBy(ExamPaperAnswer::getPaperName, Collectors.counting())); collect.forEach(t->t.setCounts(Math.toIntExact(collect1.getOrDefault(t.getPaperName(),0L)))); Map> collect2 = collect.stream().collect(Collectors.groupingBy(ExamPaperAnswer::getUserName)); List filteredList1 = new ArrayList<>(); Set uniqueUserNames = new HashSet<>(); collect2.forEach((key, value) -> { value.forEach(item -> { item.setUserName(key); item.setCounts(value.size()); }); list2.addAll(value); }); for (ExamPaperAnswer item : list2) { if (uniqueUserNames.add(item.getUserName())) { filteredList1.add(item); } } PageHelper.startPage(grade.getPageIndex(), grade.getPageSize()); PageInfo pageInfoPageInfo = new PageInfo<>(filteredList1); return RestResponse.ok(pageInfoPageInfo); } @RequestMapping(value = "/details", method = RequestMethod.POST) public RestResponse> selectSource(@RequestBody ScoreTemplatesCountVO scoreTemplatesCountVO) throws Exception { PageHelper.startPage(scoreTemplatesCountVO.getPageIndex(), scoreTemplatesCountVO.getPageSize()); List byCreatUser = examPaperAnswerService.getByCreatUser(scoreTemplatesCountVO); PageInfo pageInfoPageInfo = new PageInfo<>(byCreatUser); return RestResponse.ok(pageInfoPageInfo); } @RequestMapping(value = "/updates", method = RequestMethod.POST) public void updateDepartment(){ List users = userService.getUsers(); for (User user : users) { Integer id = user.getId(); Integer userLevel = user.getUserLevel(); UserDepartment userDepartment = userDepartMentService.selectByUser(id); if (userDepartment!=null){ userDepartment.setDepartmentId(userLevel); userDepartMentService.updateUserDepartMent(userDepartment); } } } }