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.ExamPaperAnswer; import com.mindskip.xzs.domain.User; import com.mindskip.xzs.domain.UserDepartment; import com.mindskip.xzs.domain.vo.ScoreTemplatesCountVO; import com.mindskip.xzs.repository.ExamPaperAnswerMapper; 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.ArrayList; import java.util.List; @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; private final ExamPaperAnswerMapper examPaperAnswerMapper; @Autowired public ExamPaperGradeController(ExamPaperAnswerService examPaperAnswerService, SubjectService subjectService, UserService userService, ExamPaperSubjectService examPaperSubjectService, ScoreTemplatesUserCountService scoreTemplatesUserCountService, ExamPaperUserService examPaperUserService, UserDepartMentService userDepartMentService, ExamPaperAnswerMapper examPaperAnswerMapper) { this.examPaperAnswerService = examPaperAnswerService; this.subjectService = subjectService; this.userService = userService; this.examPaperSubjectService = examPaperSubjectService; this.scoreTemplatesUserCountService = scoreTemplatesUserCountService; this.examPaperUserService = examPaperUserService; this.userDepartMentService = userDepartMentService; this.examPaperAnswerMapper = examPaperAnswerMapper; } // @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 filteredList9 = new ArrayList<>(); PageInfo info = PageHelper.startPage(grade.getPageIndex(), grade.getPageSize(), "id desc").doSelectPageInfo(() -> userService.getUsers()); for (User user : info.getList()) { if("管理员".equals(user.getRealName())){ continue; } ExamPaperAnswer answer = new ExamPaperAnswer(); answer.setCreateUser(user.getId()); answer.setUserName(user.getRealName()); ScoreTemplatesCountVO vo = new ScoreTemplatesCountVO(); vo.setCreateUser(user.getId()); List byCreatUser = examPaperAnswerMapper.getByCreatUser(vo); answer.setCounts(byCreatUser.size()); filteredList9.add(answer); } PageHelper.startPage(grade.getPageIndex(), grade.getPageSize()); PageInfo pageInfoPageInfo = new PageInfo<>(filteredList9); pageInfoPageInfo.setTotal(info.getTotal()); return RestResponse.ok(pageInfoPageInfo); } @RequestMapping(value = "/details", method = RequestMethod.POST) public RestResponse> selectSource(@RequestBody ScoreTemplatesCountVO scoreTemplatesCountVO) throws Exception { return RestResponse.ok(examPaperAnswerService.getByCreatUser(scoreTemplatesCountVO)); } @RequestMapping(value = "/updates", method = RequestMethod.GET) public void updateDepartment() { List users = userService.getUsers(); for (User user : users) { Integer id = user.getId(); Integer userLevel = user.getUserLevel(); UserDepartment userDepartment = new UserDepartment(); userDepartment.setUserId(id); userDepartment.setDepartmentId(userLevel); userDepartMentService.insert(userDepartment); } } }