BaseNewStudentReportController.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. package com.xjrsoft.module.student.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.dev33.satoken.stp.StpUtil;
  4. import cn.hutool.core.bean.BeanUtil;
  5. import com.alibaba.excel.EasyExcel;
  6. import com.alibaba.excel.support.ExcelTypeEnum;
  7. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  8. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  9. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  10. import com.xjrsoft.common.annotation.XjrLog;
  11. import com.xjrsoft.common.enums.DeleteMark;
  12. import com.xjrsoft.common.enums.EnabledMark;
  13. import com.xjrsoft.common.enums.EnrollTypeEnum;
  14. import com.xjrsoft.common.enums.GenderDictionaryEnum;
  15. import com.xjrsoft.common.enums.RoleCodeEnum;
  16. import com.xjrsoft.common.enums.StudyStatusEnum;
  17. import com.xjrsoft.common.model.result.RT;
  18. import com.xjrsoft.common.page.ConventPage;
  19. import com.xjrsoft.common.page.PageOutput;
  20. import com.xjrsoft.common.utils.VoToColumnUtil;
  21. import com.xjrsoft.module.banding.dto.BandingTaskClassPageDto;
  22. import com.xjrsoft.module.banding.entity.BandingTask;
  23. import com.xjrsoft.module.banding.service.IBandingTaskClassService;
  24. import com.xjrsoft.module.banding.service.IBandingTaskClassStudentService;
  25. import com.xjrsoft.module.banding.service.IBandingTaskService;
  26. import com.xjrsoft.module.banding.vo.BandingTaskClassPageVo;
  27. import com.xjrsoft.module.banding.vo.BandingTaskClassReportStatisticsVo;
  28. import com.xjrsoft.module.base.entity.BaseGrade;
  29. import com.xjrsoft.module.base.service.IBaseGradeService;
  30. import com.xjrsoft.module.base.service.IBaseSemesterService;
  31. import com.xjrsoft.module.databoard.vo.ItemCountVo;
  32. import com.xjrsoft.module.organization.service.IUserService;
  33. import com.xjrsoft.module.student.dto.StudentReportRecordPageDto;
  34. import com.xjrsoft.module.student.dto.StudentReportRecordStatisticsDto;
  35. import com.xjrsoft.module.student.dto.StudentTryReadingReportPageDto;
  36. import com.xjrsoft.module.student.entity.EnrollmentPlan;
  37. import com.xjrsoft.module.student.entity.StudentReportPlan;
  38. import com.xjrsoft.module.student.service.IBaseNewStudentService;
  39. import com.xjrsoft.module.student.service.IBaseStudentSchoolRollService;
  40. import com.xjrsoft.module.student.service.IEnrollmentPlanService;
  41. import com.xjrsoft.module.student.service.IStudentReportPlanService;
  42. import com.xjrsoft.module.student.service.IStudentReportRecordService;
  43. import com.xjrsoft.module.student.vo.StudentReportRecordExcelVo;
  44. import com.xjrsoft.module.student.vo.StudentReportRecordItemVo;
  45. import com.xjrsoft.module.student.vo.StudentReportRecordPlanPageVo;
  46. import com.xjrsoft.module.student.vo.StudentReportRecordStatisticsVo;
  47. import io.swagger.annotations.Api;
  48. import io.swagger.annotations.ApiOperation;
  49. import lombok.AllArgsConstructor;
  50. import org.springframework.http.ResponseEntity;
  51. import org.springframework.web.bind.annotation.GetMapping;
  52. import org.springframework.web.bind.annotation.PostMapping;
  53. import org.springframework.web.bind.annotation.RequestBody;
  54. import org.springframework.web.bind.annotation.RequestMapping;
  55. import org.springframework.web.bind.annotation.RequestParam;
  56. import org.springframework.web.bind.annotation.RestController;
  57. import javax.validation.Valid;
  58. import java.io.ByteArrayOutputStream;
  59. import java.math.BigDecimal;
  60. import java.math.RoundingMode;
  61. import java.text.SimpleDateFormat;
  62. import java.util.ArrayList;
  63. import java.util.Collections;
  64. import java.util.Comparator;
  65. import java.util.List;
  66. import java.util.Map;
  67. import java.util.stream.Collectors;
  68. /**
  69. * @title: 新生报到信息
  70. * @Author dzx
  71. * @Date: 2025年3月19日
  72. * @Version 1.0
  73. */
  74. @RestController
  75. @RequestMapping("/student" + "/baseNewStudentReport")
  76. @Api(value = "/student" + "/baseNewStudent", tags = "新生报到模块代码")
  77. @AllArgsConstructor
  78. public class BaseNewStudentReportController {
  79. private final IStudentReportRecordService recordService;
  80. private final IStudentReportPlanService reportPlanService;
  81. private final IBandingTaskClassService bandingTaskClassService;
  82. private final IBaseSemesterService semesterService;
  83. private final IBaseGradeService gradeService;
  84. private final IEnrollmentPlanService enrollmentPlanService;
  85. private final IBandingTaskService bandingTaskService;
  86. @GetMapping(value = "/page")
  87. @ApiOperation(value = "新生维护信息列表(分页)")
  88. @SaCheckPermission("basenewstudent:detail")
  89. @XjrLog(value = "新生维护信息列表(分页)")
  90. public RT<PageOutput<StudentReportRecordPlanPageVo>> page(@Valid StudentTryReadingReportPageDto dto){
  91. dto.setReportCategory(3);
  92. List<String> roleList = StpUtil.getRoleList();
  93. if(roleList.contains("CLASSTE") && roleList.contains("TEACHER")){
  94. dto.setTeacherId(StpUtil.getLoginIdAsLong());
  95. }
  96. if(dto.getIsMoible() != null && dto.getIsMoible() == 1){
  97. StudentReportPlan plan = reportPlanService.getLastNewStudentReportPlan();
  98. dto.setStudentReportPlanId(plan.getId());
  99. BandingTask bandingTask = bandingTaskService.getById(plan.getBandingTaskId());
  100. List<EnrollmentPlan> enrollmentPlans = enrollmentPlanService.list(
  101. new QueryWrapper<EnrollmentPlan>().lambda()
  102. .eq(EnrollmentPlan::getDeleteMark, DeleteMark.NODELETE.getCode())
  103. .eq(EnrollmentPlan::getEnabledMark, EnabledMark.ENABLED.getCode())
  104. .eq(EnrollmentPlan::getEnrollType, bandingTask.getEnrollType())
  105. .eq(EnrollmentPlan::getEnrollType, bandingTask.getEnrollType())
  106. .eq(EnrollmentPlan::getGradeId, bandingTask.getGradeId())
  107. .orderByDesc(EnrollmentPlan::getId)
  108. );
  109. if(!enrollmentPlans.isEmpty()){
  110. dto.setEnrollmentPlanId(enrollmentPlans.get(0).getId());
  111. }
  112. }
  113. Page<StudentReportRecordPlanPageVo> page = recordService.getTryReadingPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
  114. PageOutput<StudentReportRecordPlanPageVo> pageOutput = ConventPage.getPageOutput(page, StudentReportRecordPlanPageVo.class);
  115. return RT.ok(pageOutput);
  116. }
  117. @GetMapping(value = "/class-statistics")
  118. @ApiOperation(value="班级数据统计")
  119. @SaCheckPermission("studentreportrecord:detail")
  120. @XjrLog(value = "班级数据统计")
  121. public RT<BandingTaskClassReportStatisticsVo> classStatistics(@RequestParam Long classId){
  122. return RT.ok(bandingTaskClassService.getTryReadingReportClassStatistics(new StudentTryReadingReportPageDto(){{
  123. setClassId(classId);
  124. setReportCategory(3);
  125. }}));
  126. }
  127. @GetMapping(value = "/statistics")
  128. @ApiOperation(value="领导统计")
  129. @SaCheckPermission("studentreportrecord:detail")
  130. @XjrLog(value = "领导统计")
  131. public RT<StudentReportRecordStatisticsVo> statistics(@Valid StudentReportRecordStatisticsDto dto){
  132. if(dto.getGradeId() == null && (dto.getCategory() == null || dto.getCategory() == 1)){
  133. LambdaQueryWrapper<BaseGrade> queryWrapper = new LambdaQueryWrapper<>();
  134. queryWrapper
  135. .orderByDesc(BaseGrade::getTitle)
  136. .select(BaseGrade.class,x -> VoToColumnUtil.fieldsToColumns(BaseGrade.class).contains(x.getProperty()));
  137. List<BaseGrade> gradeList = gradeService.list(queryWrapper);
  138. if(!gradeList.isEmpty()){
  139. dto.setGradeId(gradeList.get(0).getId());
  140. }
  141. }
  142. if(dto.getEnrollType() == null || dto.getEnrollType().isEmpty()){
  143. dto.setEnrollType(EnrollTypeEnum.AUTUMN_ENROLLMENT.getCode());
  144. }
  145. if(dto.getCategory() != null && dto.getCategory() == 2 && dto.getBaseSemesterId() == null){
  146. dto.setBaseSemesterId(semesterService.getLastSemester());
  147. }
  148. List<EnrollmentPlan> enrollmentPlanList = enrollmentPlanService.list(
  149. new QueryWrapper<EnrollmentPlan>().lambda()
  150. .eq(EnrollmentPlan::getEnrollType, dto.getEnrollType())
  151. .eq(EnrollmentPlan::getGradeId, dto.getGradeId())
  152. .eq(EnrollmentPlan::getDeleteMark, DeleteMark.NODELETE.getCode())
  153. .eq(EnrollmentPlan::getEnabledMark, EnabledMark.ENABLED.getCode())
  154. .orderByDesc(EnrollmentPlan::getId)
  155. );
  156. if(enrollmentPlanList.isEmpty()){
  157. return RT.ok(new StudentReportRecordStatisticsVo());
  158. }
  159. StudentTryReadingReportPageDto recordPageDto = new StudentTryReadingReportPageDto();
  160. recordPageDto.setEnrollmentPlanId(enrollmentPlanList.get(0).getId());
  161. recordPageDto.setReportCategory(3);
  162. List<StudentReportRecordPlanPageVo> dataList = recordService.getTryReadingList(recordPageDto);
  163. StudentReportRecordStatisticsVo statisticsVo = new StudentReportRecordStatisticsVo();
  164. statisticsVo.setAllCount(dataList.stream().count());
  165. statisticsVo.setArrivedCount(dataList.stream().filter(x -> x.getReportTime() != null).count());
  166. statisticsVo.setNotArrivedCount(dataList.stream().filter(x -> x.getReportTime() == null).count());
  167. statisticsVo.setArrivedMaleCount(dataList.stream().filter(x -> x.getReportTime() != null && GenderDictionaryEnum.MALE.getValue().equals(x.getGender())).count());
  168. statisticsVo.setArrivedFemaleCount(dataList.stream().filter(x -> x.getReportTime() != null && GenderDictionaryEnum.FEMALE.getValue().equals(x.getGender())).count());
  169. statisticsVo.setStayMaleCount(dataList.stream().filter(
  170. x -> GenderDictionaryEnum.MALE.getValue().equals(x.getGender())
  171. && StudyStatusEnum.InResidence.getCode().equals(x.getStduyStatusCn())
  172. && x.getReportTime() != null
  173. ).count());
  174. statisticsVo.setStayFemaleCount(dataList.stream().filter(
  175. x -> GenderDictionaryEnum.FEMALE.getValue().equals(x.getGender())
  176. && StudyStatusEnum.InResidence.getCode().equals(x.getStduyStatusCn())
  177. && x.getReportTime() != null
  178. ).count());
  179. statisticsVo.setNotStayMaleCount(dataList.stream().filter(
  180. x -> GenderDictionaryEnum.MALE.getValue().equals(x.getGender())
  181. && StudyStatusEnum.AttendDaySchool.getCode().equals(x.getStduyStatusCn())
  182. && x.getReportTime() != null
  183. ).count());
  184. statisticsVo.setNotStayFemaleCount(dataList.stream().filter(
  185. x -> GenderDictionaryEnum.FEMALE.getValue().equals(x.getGender())
  186. && StudyStatusEnum.AttendDaySchool.getCode().equals(x.getStduyStatusCn())
  187. && x.getReportTime() != null
  188. ).count());
  189. if(dto.getCategory() != null && dto.getCategory() == 3){
  190. Map<String, List<StudentReportRecordPlanPageVo>> graduatedUniversityMap = dataList.stream().filter(x -> x.getReportTime() != null && x.getGraduateSchool() != null)
  191. .collect(Collectors.groupingBy(StudentReportRecordPlanPageVo::getGraduateSchool));
  192. List<ItemCountVo> graduatedUniversityList = new ArrayList<>();
  193. for (String graduatedUniversity : graduatedUniversityMap.keySet()) {
  194. graduatedUniversityList.add(
  195. new ItemCountVo(){{
  196. setItem(graduatedUniversity);
  197. setCount(graduatedUniversityMap.get(graduatedUniversity).size());
  198. }}
  199. );
  200. }
  201. statisticsVo.setGraduatedUniversityList(graduatedUniversityList);
  202. }
  203. Map<String, List<StudentReportRecordPlanPageVo>> classMap = dataList.stream().filter(x -> x.getReportTime() != null && x.getClassName() != null)
  204. .collect(Collectors.groupingBy(StudentReportRecordPlanPageVo::getClassName));
  205. Map<String, List<StudentReportRecordPlanPageVo>> classNotMap = dataList.stream().filter(x -> x.getReportTime() == null && x.getClassName() != null)
  206. .collect(Collectors.groupingBy(StudentReportRecordPlanPageVo::getClassName));
  207. List<StudentReportRecordItemVo> classList = new ArrayList<>();
  208. for (String className : classMap.keySet()) {
  209. classList.add(
  210. new StudentReportRecordItemVo(){{
  211. setItem(className);
  212. setCount(classMap.get(className).size());
  213. if(classNotMap.get(className) != null && !(classNotMap.get(className).isEmpty())){
  214. setCount2(classNotMap.get(className).size());
  215. }
  216. }}
  217. );
  218. }
  219. statisticsVo.setClassList(classList);
  220. Map<String, List<StudentReportRecordPlanPageVo>> classTypeMap = dataList.stream().filter(x -> x.getReportTime() != null && x.getClassType() != null)
  221. .collect(Collectors.groupingBy(StudentReportRecordPlanPageVo::getClassType));
  222. Map<String, List<StudentReportRecordPlanPageVo>> classTypeNotMap = dataList.stream().filter(x -> x.getReportTime() == null && x.getClassType() != null)
  223. .collect(Collectors.groupingBy(StudentReportRecordPlanPageVo::getClassType));
  224. List<StudentReportRecordItemVo> classTypeList = new ArrayList<>();
  225. for (String classType : classTypeMap.keySet()) {
  226. classTypeList.add(
  227. new StudentReportRecordItemVo(){{
  228. setItem(classType);
  229. setCount(classTypeMap.get(classType).size());
  230. if(classTypeNotMap.get(classType) != null && !(classTypeNotMap.get(classType).isEmpty())){
  231. setCount2(classTypeNotMap.get(classType).size());
  232. }
  233. }}
  234. );
  235. }
  236. statisticsVo.setClassTypeList(classTypeList);
  237. Map<String, List<StudentReportRecordPlanPageVo>> majorMap = dataList.stream().filter(x -> x.getReportTime() != null && x.getMajorName() != null).collect(Collectors.groupingBy(StudentReportRecordPlanPageVo::getMajorName));
  238. Map<String, List<StudentReportRecordPlanPageVo>> majorNotMap = dataList.stream().filter(x -> x.getReportTime() == null && x.getMajorName() != null).collect(Collectors.groupingBy(StudentReportRecordPlanPageVo::getMajorName));
  239. List<StudentReportRecordItemVo> majorList = new ArrayList<>();
  240. for (String majorName : majorMap.keySet()) {
  241. majorList.add(
  242. new StudentReportRecordItemVo(){{
  243. setItem(majorName);
  244. setCount(majorMap.get(majorName).size());
  245. if(majorNotMap.get(majorName) != null && !(majorNotMap.get(majorName).isEmpty())){
  246. setCount2(majorNotMap.get(majorName).size());
  247. }
  248. }}
  249. );
  250. }
  251. statisticsVo.setMajorList(majorList);
  252. Map<String, List<StudentReportRecordPlanPageVo>> deptMap = dataList.stream().filter(x -> x.getReportTime() != null && x.getDeptName() != null).collect(Collectors.groupingBy(StudentReportRecordPlanPageVo::getDeptName));
  253. List<ItemCountVo> deptList = new ArrayList<>();
  254. for (String deptName : deptMap.keySet()) {
  255. deptList.add(
  256. new ItemCountVo(){{
  257. setItem(deptName);
  258. setCount(deptMap.get(deptName).size());
  259. }}
  260. );
  261. }
  262. statisticsVo.setDeptList(deptList);
  263. BigDecimal divide = BigDecimal.ZERO;
  264. if( statisticsVo.getAllCount() != 0){
  265. divide = BigDecimal.valueOf(statisticsVo.getArrivedCount()).divide(BigDecimal.valueOf(statisticsVo.getAllCount()), 4, RoundingMode.HALF_UP);
  266. }
  267. statisticsVo.setReportRate(divide.doubleValue());
  268. //查询年级趋势
  269. List<BaseGrade> gradeList = gradeService.list(
  270. new QueryWrapper<BaseGrade>().lambda()
  271. .eq(BaseGrade::getDeleteMark, DeleteMark.NODELETE.getCode())
  272. .eq(BaseGrade::getEnabledMark, EnabledMark.ENABLED.getCode())
  273. .eq(BaseGrade::getStatus, 1)
  274. .orderByDesc(BaseGrade::getTitle)
  275. );
  276. List<ItemCountVo> gradeDataList = new ArrayList<>();
  277. for (int i = 0; i < 3; i ++){
  278. BaseGrade baseGrade = gradeList.get(i);
  279. List<EnrollmentPlan> enrollmentPlans = enrollmentPlanService.list(
  280. new QueryWrapper<EnrollmentPlan>().lambda()
  281. .eq(EnrollmentPlan::getGradeId, baseGrade.getId())
  282. .eq(EnrollmentPlan::getDeleteMark, DeleteMark.NODELETE.getCode())
  283. .eq(EnrollmentPlan::getEnabledMark, EnabledMark.ENABLED.getCode())
  284. .orderByDesc(EnrollmentPlan::getId)
  285. );
  286. int gradeCount = 0;
  287. for (EnrollmentPlan enrollmentPlan : enrollmentPlans) {
  288. StudentTryReadingReportPageDto gradeRecordPageDto = new StudentTryReadingReportPageDto();
  289. gradeRecordPageDto.setEnrollmentPlanId(enrollmentPlan.getId());
  290. gradeRecordPageDto.setIsReport(1);
  291. gradeRecordPageDto.setReportCategory(3);
  292. gradeCount += recordService.getTryReadingList(gradeRecordPageDto).size();
  293. }
  294. ItemCountVo itemCountVo = new ItemCountVo();
  295. itemCountVo.setItem(baseGrade.getName());
  296. itemCountVo.setCount(gradeCount);
  297. gradeDataList.add(itemCountVo);
  298. }
  299. Collections.sort(gradeDataList, Comparator.comparing(ItemCountVo::getItem));
  300. statisticsVo.setGradeList(gradeDataList);
  301. return RT.ok(statisticsVo);
  302. }
  303. @PostMapping(value = "/export-query")
  304. @ApiOperation(value="导出")
  305. @SaCheckPermission("studentreportrecord:detail")
  306. @XjrLog(value = "导出")
  307. public ResponseEntity<byte[]> exportQuerty(@Valid @RequestBody StudentTryReadingReportPageDto dto){
  308. List<StudentReportRecordExcelVo> dataList = new ArrayList<>();
  309. List<String> roleList = StpUtil.getRoleList();
  310. if(roleList.contains(RoleCodeEnum.TEACHER.getCode()) && roleList.contains(RoleCodeEnum.CLASSTE.getCode())){
  311. if(dto.getClassId() == null){
  312. dto.setTeacherId(StpUtil.getLoginIdAsLong());
  313. }
  314. }
  315. dto.setReportCategory(3);
  316. List<StudentReportRecordPlanPageVo> planPageList = recordService.getTryReadingList(dto);
  317. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  318. for (StudentReportRecordPlanPageVo pageVo : planPageList) {
  319. StudentReportRecordExcelVo excelVo = BeanUtil.toBean(pageVo, StudentReportRecordExcelVo.class);
  320. if(pageVo.getReportTime() != null){
  321. excelVo.setReportTime(sdf.format(pageVo.getReportTime()));
  322. }
  323. excelVo.setIsReport("否");
  324. if(pageVo.getIsReport() != null && pageVo.getIsReport() == 1){
  325. excelVo.setIsReport("是");
  326. }
  327. dataList.add(excelVo);
  328. }
  329. ByteArrayOutputStream bot = new ByteArrayOutputStream();
  330. EasyExcel.write(bot, StudentReportRecordExcelVo.class).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(dataList);
  331. String fileName = "exportQuerty" + ExcelTypeEnum.XLSX.getValue();
  332. return RT.fileStream(bot.toByteArray(), fileName);
  333. }
  334. @GetMapping(value = "/class-list")
  335. @ApiOperation(value="查询班级信息")
  336. @SaCheckPermission("studentreportrecord:detail")
  337. @XjrLog(value = "查询班级信息")
  338. public RT<List<BandingTaskClassPageVo>> classList(@Valid StudentReportRecordPageDto dto){
  339. BandingTaskClassPageDto classDto = new BandingTaskClassPageDto();
  340. if(dto.getEnrollmentPlanId() == null){
  341. if(dto.getTeacherId() != null){
  342. classDto.setTeacherId(dto.getTeacherId());
  343. }else{
  344. classDto.setTeacherId(StpUtil.getLoginIdAsLong());
  345. }
  346. StudentReportPlan plan = reportPlanService.getLastNewStudentReportPlan();
  347. if(plan == null){
  348. return RT.ok(new ArrayList<>());
  349. }
  350. classDto.setBandingTaskId(plan.getBandingTaskId());
  351. }else{
  352. EnrollmentPlan enrollmentPlan = enrollmentPlanService.getById(dto.getEnrollmentPlanId());
  353. if(enrollmentPlan != null){
  354. List<BandingTask> list = bandingTaskService.list(
  355. new QueryWrapper<BandingTask>().lambda()
  356. .eq(BandingTask::getEnrollType, enrollmentPlan.getEnrollType())
  357. .eq(BandingTask::getGradeId, enrollmentPlan.getGradeId())
  358. .eq(BandingTask::getDeleteMark, DeleteMark.NODELETE.getCode())
  359. .eq(BandingTask::getEnabledMark, EnabledMark.ENABLED.getCode())
  360. .orderByDesc(BandingTask::getId)
  361. );
  362. if(!list.isEmpty()){
  363. classDto.setBandingTaskId(list.get(0).getId());
  364. }
  365. }
  366. List<String> roleList = StpUtil.getRoleList();
  367. if(roleList.contains("CLASSTE") && roleList.contains("TEACHER")){
  368. classDto.setTeacherId(StpUtil.getLoginIdAsLong());
  369. }
  370. }
  371. List<BandingTaskClassPageVo> list = bandingTaskClassService.getList(classDto);
  372. return RT.ok(list);
  373. }
  374. }