Browse Source

班级考勤-学生考勤详情

dzx 1 year ago
parent
commit
267fed7415

+ 62 - 48
src/main/java/com/xjrsoft/module/attendance/controller/StudentStatisticsController.java

@@ -2,26 +2,31 @@ package com.xjrsoft.module.attendance.controller;
 
 import cn.dev33.satoken.annotation.SaCheckPermission;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 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.common.page.ConventPage;
+import com.xjrsoft.common.page.PageOutput;
 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.StudentStatisticsPageVo;
 import com.xjrsoft.module.attendance.vo.VisitorInfoVo;
+import com.xjrsoft.module.base.entity.BaseClass;
 import com.xjrsoft.module.base.service.IBaseClassService;
-import com.xjrsoft.module.concat.service.IXjrUserService;
+import com.xjrsoft.module.organization.entity.User;
+import com.xjrsoft.module.organization.service.IUserService;
 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.entity.BaseStudentSchoolRoll;
+import com.xjrsoft.module.student.entity.StudentLeave;
 import com.xjrsoft.module.student.service.IStudentLeaveService;
-import com.xjrsoft.module.teacher.entity.XjrUser;
+import com.xjrsoft.module.system.entity.DictionaryDetail;
 import com.xjrsoft.module.teacher.service.IWfTeacherleaveService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -39,6 +44,7 @@ import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.TemporalAdjusters;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -55,7 +61,7 @@ import java.util.Map;
 public class StudentStatisticsController {
 
 
-    private final IXjrUserService xjrUserService;
+    private final IUserService xjrUserService;
     private final ITeacherOutInRecordService teacherOutInRecordService;
     private final IStudentOutInRecordService studentOutInRecordService;
     private final IAttendanceRuleCategoryService ruleCategoryService;
@@ -67,7 +73,7 @@ public class StudentStatisticsController {
     @GetMapping(value = "/class-statistics")
     @ApiOperation(value="班级考勤统计")
     @SaCheckPermission("statistics:detail")
-    public RT<Page<ClassStatisticsVo>> teacherStatistics(@Valid AttendanceStatisticDto dto){
+    public RT<PageOutput<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()) {
@@ -136,26 +142,33 @@ public class StudentStatisticsController {
                 record.setAttendanceRate(divide.doubleValue());
             }
         }
-
-        return RT.ok(attendancePage);
+        PageOutput<ClassStatisticsVo> pageOutput = ConventPage.getPageOutput(attendancePage, ClassStatisticsVo.class);
+        return RT.ok(pageOutput);
     }
 
 
-    @GetMapping(value = "/student-statistics")
-    @ApiOperation(value="学生考勤统计")
+    @GetMapping(value = "/student-details")
+    @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);
+    public RT<PageOutput<StudentStatisticsPageVo>> studentDetails(@Valid AttendanceStatisticDto dto){
+        MPJLambdaWrapper<User> queryUser = new MPJLambdaWrapper<>();
+        queryUser.disableSubLogicDel().distinct()
+                .selectAs(BaseClass::getName, StudentStatisticsPageVo::getClassName)
+                .select("t3.name", StudentStatisticsPageVo::getTeacherName)
+                .selectAs(User::getName, StudentStatisticsPageVo::getStudentName)
+                .selectAs(User::getId, StudentStatisticsPageVo::getUserId)
+                .selectAs(DictionaryDetail::getName, StudentStatisticsPageVo::getStduyStatusCn)
+                .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, User::getId)
+                .innerJoin(BaseClass.class, BaseClass::getId, BaseStudentSchoolRoll::getClassId)
+                .leftJoin(User.class, User::getId, BaseClass::getTeacherId)
+                .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, BaseStudentSchoolRoll::getStduyStatus);
+        IPage<StudentStatisticsPageVo> voIPage = xjrUserService.selectJoinListPage(ConventPage.getPage(dto), StudentStatisticsPageVo.class, queryUser);
+
         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);
@@ -166,44 +179,45 @@ public class StudentStatisticsController {
                 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, AttendanceRuleDetailsUserVo> allTodyRule = ruleCategoryService.getAllTeacherTodyRule(queryDate.getDayOfWeek().name());
+            //查询当前时间段存在请假的学生
+            Map<Long, StudentLeave> leaveList = studentLeaveService.getLeaveList(startTime, endTime);
+            //查询进入记录
             List<StudentOutInRecord> outInRecords = studentOutInRecordService.list(
                     new QueryWrapper<StudentOutInRecord>().lambda()
                             .between(StudentOutInRecord::getRecordTime, startTime, endTime)
+                            .eq(StudentOutInRecord::getStatus, 0)
             );
-            //实到人数
-            statisticsVo.setActualCount(Long.valueOf(outInRecords.size()));
-
-            //查询教师请假人数
-            Long leaveCount = studentLeaveService.getLeaveCount(startTime, endTime);
-            if(leaveCount == null){
-                leaveCount = 0L;
+            Map<Long, StudentOutInRecord> outInMap = new HashMap<>();
+            for (StudentOutInRecord inRecord : outInRecords) {
+                outInMap.put(inRecord.getUserId(), inRecord);
             }
-            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 ++;
+            for (StudentStatisticsPageVo record : voIPage.getRecords()) {
+                StudentLeave studentLeave = leaveList.get(record.getUserId());
+                if(studentLeave != null){
+                    record.setStatus(studentLeave.getLeaveType());
+                }else{
+                    AttendanceRuleDetailsUserVo ruleUserVo = allTodyRule.get(record.getUserId());
+                    StudentOutInRecord outInRecord = outInMap.get(record.getUserId());
+                    if(ruleUserVo.getIsAllowInOutSchool() != null && ruleUserVo.getIsAllowInOutSchool() == 0){
+                        record.setStatus("不考核");
+                    }else{
+                        if(dto.getTimePeriod() == 1 && outInRecord.getRecordTime().toLocalTime().compareTo(ruleUserVo.getAmStartTime()) > 0){
+                            record.setStatus("迟到");
+                        }else if(dto.getTimePeriod() == 2 && outInRecord.getRecordTime().toLocalTime().compareTo(ruleUserVo.getPmStartTime()) > 0){
+                            record.setStatus("迟到");
+                        }else{
+                            record.setStatus("到校");
+                        }
+                    }
                 }
             }
-            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);
+        PageOutput<StudentStatisticsPageVo> pageOutput = ConventPage.getPageOutput(voIPage, StudentStatisticsPageVo.class);
+        return RT.ok(pageOutput);
     }
 
 

+ 35 - 0
src/main/java/com/xjrsoft/module/attendance/vo/StudentStatisticsPageVo.java

@@ -0,0 +1,35 @@
+package com.xjrsoft.module.attendance.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+* @title: 学生考勤统计列表
+* @Author dzx
+* @Date: 2024年5月24日
+* @Version 1.0
+*/
+@Data
+public class StudentStatisticsPageVo {
+
+    @ApiModelProperty("班级名称")
+    private String className;
+
+    @ApiModelProperty("班主任名称")
+    private String teacherName;
+
+    @ApiModelProperty("学生名称")
+    private String studentName;
+
+    @ApiModelProperty("身份证号")
+    private String credentialNumber;
+
+    @ApiModelProperty("就读方式")
+    private String stduyStatusCn;
+
+    @ApiModelProperty("考勤状态")
+    private String status;
+
+    @ApiModelProperty("学生userId")
+    private Long userId;
+}

+ 0 - 60
src/main/java/com/xjrsoft/module/job/HikvisionLeaveTask.java

@@ -33,65 +33,5 @@ public class HikvisionLeaveTask {
 
     @Scheduled(cron = "0 */15 * * * ?")
     public void RefreshConnectionPool() {
-        String active = SpringUtil.getActiveProfile();
-        if(!"prod".equals(active)){
-            log.info("非正式环境,无法执行数据推送");
-            return;
-        }
-        log.info("开始推送海康威视基础数据");
-        DataSource datasource = DatasourceUtil.getDataSource(GlobalConstant.DEFAULT_DATASOURCE_KEY);
-        try {
-            Db use = Db.use(datasource);
-            String sql = "SELECT distinct table_name FROM hikvision_data WHERE 1 = 1";
-            List<JianyueData> query = use.query(sql, JianyueData.class);
-            Set<String> tables = new HashSet<>();
-            for (JianyueData jianyueData : query) {
-                tables.add(jianyueData.getTableName());
-            }
-            sql = "SELECT * FROM hikvision_data WHERE 0 = 0";
-            List<HikvisionData> list = use.query(sql, HikvisionData.class);
-            Map<String, Map<String, String>> dataMap = new HashMap<>();
-            for (String table : tables) {
-                Map<String, String> tableData = new HashMap<>();
-                for (HikvisionData hikvisiondata : list) {
-                    if(!table.equals(hikvisiondata.getTableName())){
-                        continue;
-                    }
-                    tableData.put(hikvisiondata.getSourceId(), hikvisiondata.getHikvisionId());
-                }
-                dataMap.put(table, tableData);
-            }
-            DataUtil dataUtil = new DataUtil();
-            //查询根机构
-            //JsonArray schoolDistrictData = dataUtil.getSchoolDistrictData();
-            //推送组织机构
-            String tableName = "xjr_department";
-            Map<String, String> department = dataUtil.insertDepartment(use, tableName, dataMap.get(tableName));
-            if(department.isEmpty() && dataMap.get(tableName) != null){
-                department = dataMap.get(tableName);
-            }
-
-            //推送教职工
-            tableName = "base_teacher";
-            dataUtil.insertTeacher(use, tableName, dataMap.get(tableName), department);
-
-            //推送车辆
-            String carTableName = "car_message_apply";
-            Map<String, String> baseCar = dataMap.get(carTableName);
-            dataUtil.insertCar(use, carTableName, baseCar, faceImportMapper);
-
-            tableName = "base_class";
-            Map<String, String> baseClass = dataMap.get(tableName);
-            Map<String, String> classes = dataUtil.insertClass(use, tableName, baseClass);
-
-
-            tableName = "base_student";
-            Map<String, String> baseStudent = dataMap.get(tableName);
-            Map<String, String> student = dataUtil.insertStudentOne(use, tableName, baseStudent);
-
-            log.info("数据推送完成");
-        } catch (Exception e) {
-            log.error(e.getMessage(), e);
-        }
     }
 }

+ 3 - 0
src/main/java/com/xjrsoft/module/student/mapper/StudentLeaveMapper.java

@@ -22,4 +22,7 @@ public interface StudentLeaveMapper extends MPJBaseMapper<StudentLeave> {
     Long getLeaveCount(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);
 
     List<IdCountVo> getClassLeaveCount(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);
+
+
+    List<StudentLeave> getLeaveList(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);
 }

+ 5 - 0
src/main/java/com/xjrsoft/module/student/service/IStudentLeaveService.java

@@ -2,8 +2,10 @@ package com.xjrsoft.module.student.service;
 
 import com.github.yulichang.base.MPJBaseService;
 import com.xjrsoft.module.student.entity.StudentLeave;
+import org.apache.ibatis.annotations.Param;
 
 import java.time.LocalDateTime;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -20,4 +22,7 @@ public interface IStudentLeaveService extends MPJBaseService<StudentLeave> {
     Long getLeaveCount(LocalDateTime startTime, LocalDateTime endTime);
 
     Map<Long, Integer> getClassLeaveCount(LocalDateTime startTime, LocalDateTime endTime);
+
+
+    Map<Long, StudentLeave> getLeaveList(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);
 }

+ 10 - 0
src/main/java/com/xjrsoft/module/student/service/impl/StudentLeaveServiceImpl.java

@@ -93,6 +93,16 @@ public class StudentLeaveServiceImpl extends MPJBaseServiceImpl<StudentLeaveMapp
         return result;
     }
 
+    @Override
+    public Map<Long, StudentLeave> getLeaveList(LocalDateTime startTime, LocalDateTime endTime) {
+        List<StudentLeave> leaveList = this.baseMapper.getLeaveList(startTime, endTime);
+        Map<Long, StudentLeave> result = new HashMap<>();
+        for (StudentLeave studentLeave : leaveList) {
+            result.put(studentLeave.getStudentUserId(), studentLeave);
+        }
+        return result;
+    }
+
     JsonArray selectResource(ApiUtil apiUtil){
         String apiPath = "/api/irds/v2/resource/resourcesByParams";
         JsonObject jsonObject = new JsonObject();

+ 1 - 1
src/main/resources/mapper/base/BaseClass.xml

@@ -77,7 +77,7 @@
         WHERE t1.delete_mark = 0 AND t2.delete_mark = 0
     </select>
     <select id="getAttendanceClass" resultType="com.xjrsoft.module.attendance.vo.ClassStatisticsVo">
-        SELECT t1.id,t1.name AS class_name,t2.name AS teacher_name,
+        SELECT t1.id,t1.name,t2.name AS teacher_name,
         (SELECT COUNT(*) FROM base_student_school_roll c1
         INNER JOIN xjr_user c2 ON c1.user_id = c2.id
         WHERE c1.delete_mark = 0 AND c1.delete_mark = 0

+ 11 - 0
src/main/resources/mapper/student/StudentLeaveMapper.xml

@@ -25,4 +25,15 @@
         OR (#{startTime} > start_date and end_date > #{endTime})
         ) group by t1.class_id
     </select>
+    <select id="getLeaveList" resultType="com.xjrsoft.module.student.entity.StudentLeave">
+        SELECT t1.* FROM student_leave t1
+        INNER JOIN xjr_user t2 ON t1.user_id = t2.id
+        WHERE t1.status = 1 AND t2.delete_mark = 0
+        AND (
+        (start_date BETWEEN #{startTime} and #{endTime})
+        OR (end_date BETWEEN #{startTime} and #{endTime})
+        OR (start_date > #{startTime} and #{endTime} > end_date)
+        OR (#{startTime} > start_date and end_date > #{endTime})
+        )
+    </select>
 </mapper>