|
|
@@ -0,0 +1,218 @@
|
|
|
+package com.xjrsoft.module.attendance.controller;
|
|
|
+
|
|
|
+import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.github.yulichang.toolkit.MPJWrappers;
|
|
|
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
+import com.xjrsoft.common.model.result.RT;
|
|
|
+import com.xjrsoft.module.attendance.dto.AttendanceStatisticDto;
|
|
|
+import com.xjrsoft.module.attendance.service.IAttendanceRuleCategoryService;
|
|
|
+import com.xjrsoft.module.attendance.vo.AttendanceRuleDetailsUserVo;
|
|
|
+import com.xjrsoft.module.attendance.vo.ClassStatisticsVo;
|
|
|
+import com.xjrsoft.module.attendance.vo.TeacherStatisticsVo;
|
|
|
+import com.xjrsoft.module.attendance.vo.VisitorInfoVo;
|
|
|
+import com.xjrsoft.module.base.service.IBaseClassService;
|
|
|
+import com.xjrsoft.module.concat.service.IXjrUserService;
|
|
|
+import com.xjrsoft.module.outint.entity.StudentOutInRecord;
|
|
|
+import com.xjrsoft.module.outint.service.IStudentOutInRecordService;
|
|
|
+import com.xjrsoft.module.outint.service.ITeacherOutInRecordService;
|
|
|
+import com.xjrsoft.module.outint.vo.StudentOutInRecordVo;
|
|
|
+import com.xjrsoft.module.personnel.service.IReservationSchoolService;
|
|
|
+import com.xjrsoft.module.student.entity.BaseStudent;
|
|
|
+import com.xjrsoft.module.student.service.IStudentLeaveService;
|
|
|
+import com.xjrsoft.module.teacher.entity.XjrUser;
|
|
|
+import com.xjrsoft.module.teacher.service.IWfTeacherleaveService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.time.DayOfWeek;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.temporal.TemporalAdjusters;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+* @title: 考勤消息设置
|
|
|
+* @Author dzx
|
|
|
+* @Date: 2024-05-21
|
|
|
+* @Version 1.0
|
|
|
+*/
|
|
|
+@RestController
|
|
|
+@RequestMapping("/studentStatistics")
|
|
|
+@Api(value = "/studentStatistics" ,tags = "学生考勤统计")
|
|
|
+@AllArgsConstructor
|
|
|
+public class StudentStatisticsController {
|
|
|
+
|
|
|
+
|
|
|
+ private final IXjrUserService xjrUserService;
|
|
|
+ private final ITeacherOutInRecordService teacherOutInRecordService;
|
|
|
+ private final IStudentOutInRecordService studentOutInRecordService;
|
|
|
+ private final IAttendanceRuleCategoryService ruleCategoryService;
|
|
|
+ private final IWfTeacherleaveService wfTeacherleaveService;
|
|
|
+ private final IStudentLeaveService studentLeaveService;
|
|
|
+ private final IReservationSchoolService reservationSchoolService;
|
|
|
+ private final IBaseClassService classService;
|
|
|
+
|
|
|
+ @GetMapping(value = "/class-statistics")
|
|
|
+ @ApiOperation(value="班级考勤统计")
|
|
|
+ @SaCheckPermission("statistics:detail")
|
|
|
+ public RT<Page<ClassStatisticsVo>> teacherStatistics(@Valid AttendanceStatisticDto dto){
|
|
|
+ Page<ClassStatisticsVo> attendancePage = classService.getAttendancePage(new Page<>(dto.getLimit(), dto.getSize()), dto);
|
|
|
+ List<Long> classIds = new ArrayList<>();
|
|
|
+ for (ClassStatisticsVo record : attendancePage.getRecords()) {
|
|
|
+ classIds.add(record.getId());
|
|
|
+ }
|
|
|
+ if(dto.getDate() != null && !"".equals(dto.getDate())){
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE;
|
|
|
+ LocalDate queryDate = LocalDate.parse(dto.getDate(), formatter);
|
|
|
+ LocalDateTime startTime, endTime;
|
|
|
+
|
|
|
+
|
|
|
+ if(dto.getTimePeriod() == 1){
|
|
|
+ startTime = queryDate.atTime(9, 0, 0);
|
|
|
+ endTime = queryDate.atTime(12, 0, 0);
|
|
|
+ }else if(dto.getTimePeriod() == 2){
|
|
|
+ startTime = queryDate.atTime(12, 0, 0);
|
|
|
+ endTime = queryDate.atTime(18, 0, 0);
|
|
|
+ }else{
|
|
|
+ startTime = queryDate.atTime(0, 0, 0);
|
|
|
+ endTime = queryDate.atTime(23, 59, 59);
|
|
|
+ }
|
|
|
+ LocalDateTime lastSundayStart = startTime.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).plusDays(-1);
|
|
|
+ LocalDateTime lastSundayEnd = endTime.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).plusDays(-1);
|
|
|
+
|
|
|
+ //查询每个班的走读生实到人数
|
|
|
+ Map<Long, List<StudentOutInRecordVo>> notStayMap = studentOutInRecordService.getNotStayList(startTime, endTime, classIds);
|
|
|
+ //查询住校生的实到情况
|
|
|
+ Map<Long, List<StudentOutInRecordVo>> stayMap = studentOutInRecordService.getStayList(lastSundayStart, lastSundayEnd, classIds);
|
|
|
+
|
|
|
+ //查询各班的请假人数
|
|
|
+ Map<Long, Integer> classLeaveCount = studentLeaveService.getClassLeaveCount(startTime, endTime);
|
|
|
+
|
|
|
+ //查询走读生的考勤规则
|
|
|
+ Map<Long, AttendanceRuleDetailsUserVo> notStayTodyRule = ruleCategoryService.getAllStudentTodyRule(queryDate.getDayOfWeek().name());
|
|
|
+ //查询住校生生的考勤规则
|
|
|
+ Map<Long, AttendanceRuleDetailsUserVo> staySundayRule = ruleCategoryService.getAllStudentTodyRule(lastSundayStart.getDayOfWeek().name());
|
|
|
+
|
|
|
+ for (ClassStatisticsVo record: attendancePage.getRecords()) {
|
|
|
+ record.setLeaveCount(classLeaveCount.get(record.getId()));
|
|
|
+ record.setActualCount(notStayMap.get(record.getId()).size() + stayMap.get(record.getId()).size());
|
|
|
+
|
|
|
+ Integer lateCount = 0;
|
|
|
+ for (StudentOutInRecordVo outInRecord : notStayMap.get(record.getId())) {
|
|
|
+ AttendanceRuleDetailsUserVo ruleDetails = notStayTodyRule.get(outInRecord.getUserId());
|
|
|
+ if(dto.getTimePeriod() == 1 && outInRecord.getRecordTime().toLocalTime().compareTo(ruleDetails.getAmStartTime()) > 0){
|
|
|
+ lateCount ++;
|
|
|
+ }else if(dto.getTimePeriod() == 2 && outInRecord.getRecordTime().toLocalTime().compareTo(ruleDetails.getPmStartTime()) > 0){
|
|
|
+ lateCount ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (StudentOutInRecordVo outInRecord : stayMap.get(record.getId())) {
|
|
|
+ AttendanceRuleDetailsUserVo ruleDetails = staySundayRule.get(outInRecord.getUserId());
|
|
|
+ if(dto.getTimePeriod() == 1 && outInRecord.getRecordTime().toLocalTime().compareTo(ruleDetails.getAmStartTime()) > 0){
|
|
|
+ lateCount ++;
|
|
|
+ }else if(dto.getTimePeriod() == 2 && outInRecord.getRecordTime().toLocalTime().compareTo(ruleDetails.getPmStartTime()) > 0){
|
|
|
+ lateCount ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ record.setLateCount(lateCount);
|
|
|
+
|
|
|
+ //最后通过总人数-实到人数-请假人数计算出缺勤人数
|
|
|
+ record.setAbsenteeismCount(record.getStudentCount() - record.getLeaveCount() - record.getActualCount());
|
|
|
+
|
|
|
+ //计算出勤率
|
|
|
+ BigDecimal divide = BigDecimal.valueOf(record.getActualCount()).divide(BigDecimal.valueOf(record.getStudentCount()), 2, RoundingMode.HALF_UP);
|
|
|
+ record.setAttendanceRate(divide.doubleValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return RT.ok(attendancePage);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping(value = "/student-statistics")
|
|
|
+ @ApiOperation(value="学生考勤统计")
|
|
|
+ @SaCheckPermission("statistics:detail")
|
|
|
+ public RT<TeacherStatisticsVo> studentStatistics(@Valid AttendanceStatisticDto dto){
|
|
|
+ TeacherStatisticsVo statisticsVo = new TeacherStatisticsVo();
|
|
|
+ //查询总人数
|
|
|
+ MPJLambdaWrapper<XjrUser> queryWrapper = MPJWrappers.<XjrUser>lambdaJoin()
|
|
|
+ .disableSubLogicDel()
|
|
|
+ .innerJoin(BaseStudent.class, BaseStudent::getUserId, XjrUser::getId);
|
|
|
+ long allCount = xjrUserService.count(queryWrapper);
|
|
|
+ statisticsVo.setAllCount(allCount);
|
|
|
+ if(dto.getDate() != null && !"".equals(dto.getDate())){
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE;
|
|
|
+ LocalDate queryDate = LocalDate.parse(dto.getDate(), formatter);
|
|
|
+ LocalDateTime startTime, endTime;
|
|
|
+ if(dto.getTimePeriod() == 1){
|
|
|
+ startTime = queryDate.atTime(9, 0, 0);
|
|
|
+ endTime = queryDate.atTime(12, 0, 0);
|
|
|
+ }else if(dto.getTimePeriod() == 2){
|
|
|
+ startTime = queryDate.atTime(12, 0, 0);
|
|
|
+ endTime = queryDate.atTime(18, 0, 0);
|
|
|
+ }else{
|
|
|
+ startTime = queryDate.atTime(0, 0, 0);
|
|
|
+ endTime = queryDate.atTime(23, 59, 59);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<StudentOutInRecord> outInRecords = studentOutInRecordService.list(
|
|
|
+ new QueryWrapper<StudentOutInRecord>().lambda()
|
|
|
+ .between(StudentOutInRecord::getRecordTime, startTime, endTime)
|
|
|
+ );
|
|
|
+ //实到人数
|
|
|
+ statisticsVo.setActualCount(Long.valueOf(outInRecords.size()));
|
|
|
+
|
|
|
+ //查询教师请假人数
|
|
|
+ Long leaveCount = studentLeaveService.getLeaveCount(startTime, endTime);
|
|
|
+ if(leaveCount == null){
|
|
|
+ leaveCount = 0L;
|
|
|
+ }
|
|
|
+ statisticsVo.setLeaveCount(leaveCount);
|
|
|
+
|
|
|
+ //查询每个人当天的考勤规则
|
|
|
+ Map<Long, AttendanceRuleDetailsUserVo> allTeacherTodyRule = ruleCategoryService.getAllStudentTodyRule(queryDate.getDayOfWeek().name());
|
|
|
+ //通过考勤规则和实到人数信息,计算迟到的
|
|
|
+ Long lateCount = 0L;
|
|
|
+ for (StudentOutInRecord outInRecord : outInRecords) {
|
|
|
+ AttendanceRuleDetailsUserVo ruleDetails = allTeacherTodyRule.get(outInRecord.getUserId());
|
|
|
+ if(dto.getTimePeriod() == 1 && outInRecord.getRecordTime().toLocalTime().compareTo(ruleDetails.getAmStartTime()) > 0){
|
|
|
+ lateCount ++;
|
|
|
+ }else if(dto.getTimePeriod() == 2 && outInRecord.getRecordTime().toLocalTime().compareTo(ruleDetails.getPmStartTime()) > 0){
|
|
|
+ lateCount ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ statisticsVo.setLateCount(lateCount);
|
|
|
+
|
|
|
+ //最后通过总人数-实到人数-请假人数计算出缺勤人数
|
|
|
+ statisticsVo.setAbsenteeismCount(statisticsVo.getAllCount() - statisticsVo.getLeaveCount() - statisticsVo.getActualCount());
|
|
|
+
|
|
|
+ //计算出勤率
|
|
|
+ BigDecimal divide = BigDecimal.valueOf(statisticsVo.getActualCount()).divide(BigDecimal.valueOf(statisticsVo.getAllCount()), 2, RoundingMode.HALF_UP);
|
|
|
+ statisticsVo.setAttendanceRate(divide.doubleValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ return RT.ok(statisticsVo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping(value = "/visitor-list")
|
|
|
+ @ApiOperation(value="访客列表")
|
|
|
+ @SaCheckPermission("statistics:detail")
|
|
|
+ public RT<List<VisitorInfoVo>> visitorList(@Valid AttendanceStatisticDto dto){
|
|
|
+ List<VisitorInfoVo> visionList = reservationSchoolService.getVisionList(dto.getDate());
|
|
|
+ return RT.ok(visionList);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|