Kaynağa Gözat

教师考勤调整

dzx 1 ay önce
ebeveyn
işleme
e0afec4205

+ 1 - 0
src/main/java/com/xjrsoft/module/attendance/service/IAttendanceRuleCategoryService.java

@@ -63,4 +63,5 @@ public interface IAttendanceRuleCategoryService extends MPJBaseService<Attendanc
 
     List<AttendanceRuleDetails> getRules(Long id);
 
+    AttendanceRuleDetails getHolidayRuleByParam(Long userId);
 }

+ 17 - 0
src/main/java/com/xjrsoft/module/attendance/service/impl/AttendanceRuleCategoryServiceImpl.java

@@ -22,6 +22,7 @@ import com.xjrsoft.module.attendance.service.IAttendanceRuleCategoryService;
 import com.xjrsoft.module.attendance.vo.AttendanceRuleDetailsUserVo;
 import com.xjrsoft.module.attendance.vo.TimeRangeVo;
 import com.xjrsoft.module.concat.service.IXjrUserService;
+import com.xjrsoft.module.organization.entity.User;
 import com.xjrsoft.module.organization.entity.UserDeptRelation;
 import com.xjrsoft.module.student.entity.BaseStudent;
 import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
@@ -529,4 +530,20 @@ public class AttendanceRuleCategoryServiceImpl extends MPJBaseServiceImpl<Attend
         );
         return list;
     }
+
+    @Override
+    public AttendanceRuleDetails getHolidayRuleByParam(Long userId) {
+        List<AttendanceRuleDetails> list = detailsMapper.selectList(
+                new MPJLambdaWrapper<AttendanceRuleDetails>()
+                        .select(AttendanceRuleDetails::getId)
+                        .select(AttendanceRuleDetails.class, x -> VoToColumnUtil.fieldsToColumns(AttendanceRuleDetails.class).contains(x.getProperty()))
+                        .innerJoin(AttendanceUserRelation.class, AttendanceUserRelation::getAttendanceRuleCategoryId, AttendanceRuleDetails::getAttendanceRuleCategoryId)
+                        .eq(AttendanceUserRelation::getUserId, userId)
+                        .eq(AttendanceRuleDetails::getDateType, "holidays")
+        );
+        if(!list.isEmpty()){
+            return list.get(0);
+        }
+        return null;
+    }
 }

+ 5 - 3
src/main/java/com/xjrsoft/module/attendance/service/impl/AttendanceStatisticsServiceImpl.java

@@ -308,18 +308,20 @@ public class AttendanceStatisticsServiceImpl extends MPJBaseServiceImpl<Attendan
 
     private List<LocalDate> getDatesBetween(LocalDate startDate, LocalDate endDate, Map<String, AttendanceRuleDetails> ruleMap, Map<String, String> weekEnMap) {
         List<LocalDate> dates = new ArrayList<>();
-
+        List<Integer> list = Arrays.asList(1, 3);
         List<HolidayDate> holidayDates = holidayDateService.list(
                 new QueryWrapper<HolidayDate>().lambda()
-                        .eq(HolidayDate::getStatus, 3)
+                        .in(HolidayDate::getStatus, list)
         );
         List<String> holidayDateList = holidayDates.stream().map(HolidayDate::getDate).collect(Collectors.toList());
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        List<String> weekList =Arrays.asList("SUNDAY", "SATURDAY");
         long numOfDaysBetween = ChronoUnit.DAYS.between(startDate, endDate) + 1; // +1 包含结束日期
         for (long i = 0; i < numOfDaysBetween; i++) {
             LocalDate localDate = startDate.plusDays(i);
             AttendanceRuleDetails holidays = ruleMap.get("holidays");
-            if(holidayDateList.contains(localDate.format(formatter)) && (holidays.getIsAttendance() == null || holidays.getIsAttendance() == 0)){
+            Integer holidaysIsAttendance = holidays.getIsAttendance();
+            if((weekList.contains(localDate.getDayOfWeek().name()) || holidayDateList.contains(localDate.format(formatter))) && (holidaysIsAttendance == null || holidaysIsAttendance == 0)){
                 continue;
             }
             AttendanceRuleDetails ruleDetails = ruleMap.get(weekEnMap.get(localDate.getDayOfWeek().name()));

+ 31 - 8
src/main/java/com/xjrsoft/module/job/AttendanceRecordTask.java

@@ -1,13 +1,17 @@
 package com.xjrsoft.module.job;
 
 import cn.hutool.extra.spring.SpringUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.xjrsoft.common.enums.OutInStatusEnum;
 import com.xjrsoft.common.utils.VoToColumnUtil;
+import com.xjrsoft.module.attendance.entity.AttendanceRuleDetails;
 import com.xjrsoft.module.attendance.entity.TeacherAttendanceRecord;
 import com.xjrsoft.module.attendance.service.IAttendanceRuleCategoryService;
 import com.xjrsoft.module.attendance.service.ITeacherAttendanceRecordService;
 import com.xjrsoft.module.attendance.vo.AttendanceRuleDetailsUserVo;
+import com.xjrsoft.module.holiday.entity.HolidayDate;
+import com.xjrsoft.module.holiday.service.IHolidayDateService;
 import com.xjrsoft.module.organization.entity.User;
 import com.xjrsoft.module.organization.service.IUserService;
 import com.xjrsoft.module.outint.dto.TeacherOutInRecordDto;
@@ -29,7 +33,9 @@ import org.springframework.stereotype.Component;
 
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -64,6 +70,9 @@ public class AttendanceRecordTask {
     @Autowired
     private ITeacherAttendanceRecordService recordService;
 
+    @Autowired
+    private IHolidayDateService holidayDateService;
+
 
     @Scheduled(cron = "0 0 1 * * ?")
     public void execute() {
@@ -100,53 +109,67 @@ public class AttendanceRecordTask {
         List<Long> userIds = teacherList.stream().map(User::getId).collect(Collectors.toList());
         Map<Long, AttendanceRuleDetailsUserVo> teacherTodyRuleByUserId = ruleCategoryService.getTeacherTodyRuleByUserId(userIds);
 
+        List<Integer> holidayTypes = Arrays.asList(1, 3);
+        List<HolidayDate> holidayDates = holidayDateService.list(
+                new QueryWrapper<HolidayDate>().lambda()
+                        .in(HolidayDate::getStatus, holidayTypes)
+        );
+        List<String> holidayDateList = holidayDates.stream().map(HolidayDate::getDate).collect(Collectors.toList());
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
         LocalDate queryDate = startDateTime.toLocalDate();
         List<TeacherAttendanceRecord> insertList = new ArrayList<>();
+        List<String> weekList =Arrays.asList("SUNDAY", "SATURDAY");
         for (User user : teacherList) {
-
             TeacherAttendanceRecord record = new TeacherAttendanceRecord();
             record.setCreateDate(LocalDateTime.now());
             record.setAttendanceDate(queryDate);
             record.setUserId(user.getId());
             record.setTimeInterval(timePeriod);
             AttendanceRuleDetailsUserVo detailsUserVo = teacherTodyRuleByUserId.get(user.getId());
+
             if(detailsUserVo == null){
                 record.setAttendanceStatus("不考勤");
                 insertList.add(record);
                 continue;
             }
+            AttendanceRuleDetails holidayRule = ruleCategoryService.getHolidayRuleByParam(user.getId());
+            if((weekList.contains(queryDate.getDayOfWeek().name()) || holidayDateList.contains(queryDate.format(formatter))) && (holidayRule.getIsAttendance() == null || holidayRule.getIsAttendance() == 0)){
+                record.setAttendanceStatus("不考勤");
+                insertList.add(record);
+                continue;
+            }
 
             LocalDateTime startTime, endTime, amEndTime = null;
 
             if(timePeriod == 1){
                 startTime = queryDate.atTime(5, 0, 0);
-                if(detailsUserVo != null && detailsUserVo.getAmStartTime() != null){
+                if(detailsUserVo.getAmStartTime() != null){
                     startTime = queryDate.atTime(detailsUserVo.getAmStartTime());
                 }
                 endTime = queryDate.atTime(12, 0, 0);
-                if(detailsUserVo != null && detailsUserVo.getAmEndTime() != null){
+                if(detailsUserVo.getAmEndTime() != null){
                     endTime = queryDate.atTime(detailsUserVo.getAmEndTime());
                 }
             }else if(timePeriod == 2){
                 startTime = queryDate.atTime(12, 0, 0);
-                if(detailsUserVo != null && detailsUserVo.getPmStartTime() != null){
+                if(detailsUserVo.getPmStartTime() != null){
                     startTime = queryDate.atTime(detailsUserVo.getPmStartTime());
                 }
                 endTime = queryDate.atTime(18, 0, 0);
-                if(detailsUserVo != null && detailsUserVo.getPmEndTime() != null){
+                if(detailsUserVo.getPmEndTime() != null){
                     endTime = queryDate.atTime(detailsUserVo.getPmEndTime());
                 }
                 amEndTime  = queryDate.atTime(12, 0, 0);
-                if(detailsUserVo != null && detailsUserVo.getAmEndTime() != null){
+                if(detailsUserVo.getAmEndTime() != null){
                     amEndTime = queryDate.atTime(detailsUserVo.getAmEndTime());
                 }
             }else{
                 startTime = queryDate.atTime(0, 0, 0);
-                if(detailsUserVo != null && detailsUserVo.getEveningStartTime() != null){
+                if(detailsUserVo.getEveningStartTime() != null){
                     startTime = queryDate.atTime(detailsUserVo.getEveningStartTime());
                 }
                 endTime = queryDate.atTime(23, 59, 59);
-                if(detailsUserVo != null && detailsUserVo.getEveningEndTime() != null){
+                if(detailsUserVo.getEveningEndTime() != null){
                     endTime = queryDate.atTime(detailsUserVo.getEveningEndTime());
                 }
             }

+ 5 - 5
src/main/resources/mapper/attendance/TeacherAttendanceRecordMapper.xml

@@ -62,11 +62,11 @@
 
     <select id="getLeaveList" parameterType="com.xjrsoft.module.teacher.entity.WfTeacherleave" resultType="com.xjrsoft.module.attendance.entity.TeacherAttendanceRecord">
         SELECT * FROM teacher_attendance_record WHERE user_id = #{dto.userId}
-        AND
-        (
-            (#{dto.leaveStartTime} BETWEEN start_time and end_time)
-            OR
-            (#{dto.leaveEndTime} BETWEEN start_time AND end_time)
+        AND (
+            ( #{dto.leaveStartTime} BETWEEN start_time AND end_time)
+            OR (#{dto.leaveEndTime} BETWEEN start_time AND end_time)
+            OR (#{dto.leaveStartTime} > start_time AND end_time > #{dto.leaveEndTime})
+            OR (start_time > #{dto.leaveStartTime} AND #{dto.leaveEndTime} > end_time)
         )
     </select>
 </mapper>

+ 36 - 17
src/test/java/com/xjrsoft/module/job/AttendanceRecordTaskTest.java

@@ -1,13 +1,17 @@
 package com.xjrsoft.module.job;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.xjrsoft.XjrSoftApplication;
 import com.xjrsoft.common.enums.OutInStatusEnum;
 import com.xjrsoft.common.utils.VoToColumnUtil;
+import com.xjrsoft.module.attendance.entity.AttendanceRuleDetails;
 import com.xjrsoft.module.attendance.entity.TeacherAttendanceRecord;
 import com.xjrsoft.module.attendance.service.IAttendanceRuleCategoryService;
 import com.xjrsoft.module.attendance.service.ITeacherAttendanceRecordService;
 import com.xjrsoft.module.attendance.vo.AttendanceRuleDetailsUserVo;
+import com.xjrsoft.module.holiday.entity.HolidayDate;
+import com.xjrsoft.module.holiday.service.IHolidayDateService;
 import com.xjrsoft.module.organization.entity.User;
 import com.xjrsoft.module.organization.service.IUserService;
 import com.xjrsoft.module.outint.dto.TeacherOutInRecordDto;
@@ -30,7 +34,9 @@ import org.springframework.test.context.junit4.SpringRunner;
 
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -64,12 +70,13 @@ class AttendanceRecordTaskTest {
     @Autowired
     private ITeacherAttendanceRecordService recordService;
 
-
+    @Autowired
+    private IHolidayDateService holidayDateService;
     @Test
     public void execute() {
 
-        LocalDateTime now = LocalDateTime.of(2024, 10, 14, 0, 0, 0);
-        for (int i = 0; i < 7; i ++){
+        LocalDateTime now = LocalDateTime.of(2024, 10, 20, 0, 0, 0);
+        for (int i = 0; i < 1; i ++){
             LocalDateTime startDateTime = now.plusDays(i).withHour(0).withMinute(0).withSecond(0).withNano(0);
             LocalDateTime endDateTime = startDateTime.plusDays(i).withHour(23).withMinute(59).withSecond(59);
 
@@ -95,61 +102,73 @@ class AttendanceRecordTaskTest {
         List<Long> userIds = teacherList.stream().map(User::getId).collect(Collectors.toList());
         Map<Long, AttendanceRuleDetailsUserVo> teacherTodyRuleByUserId = ruleCategoryService.getTeacherTodyRuleByUserId(userIds);
 
+        List<Integer> holidayTypes = Arrays.asList(1, 3);
+        List<HolidayDate> holidayDates = holidayDateService.list(
+                new QueryWrapper<HolidayDate>().lambda()
+                        .in(HolidayDate::getStatus, holidayTypes)
+        );
+        List<String> holidayDateList = holidayDates.stream().map(HolidayDate::getDate).collect(Collectors.toList());
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
         LocalDate queryDate = startDateTime.toLocalDate();
         List<TeacherAttendanceRecord> insertList = new ArrayList<>();
+        List<String> weekList =Arrays.asList("SUNDAY", "SATURDAY");
         for (User user : teacherList) {
-
-            if(14954825256773L == user.getId()){
-                System.out.println(user.getName());
-            }
-
             TeacherAttendanceRecord record = new TeacherAttendanceRecord();
             record.setCreateDate(LocalDateTime.now());
+            record.setAttendanceDate(queryDate);
             record.setUserId(user.getId());
             record.setTimeInterval(timePeriod);
-            record.setAttendanceDate(queryDate);
             AttendanceRuleDetailsUserVo detailsUserVo = teacherTodyRuleByUserId.get(user.getId());
+
             if(detailsUserVo == null){
                 record.setAttendanceStatus("不考勤");
                 insertList.add(record);
                 continue;
             }
+            if(14954799823302L == user.getId()){
+                System.out.println(user.getName());
+            }
+            AttendanceRuleDetails holidayRule = ruleCategoryService.getHolidayRuleByParam(user.getId());
+            if((weekList.contains(queryDate.getDayOfWeek().name()) || holidayDateList.contains(queryDate.format(formatter))) && (holidayRule.getIsAttendance() == null || holidayRule.getIsAttendance() == 0)){
+                record.setAttendanceStatus("不考勤");
+                insertList.add(record);
+                continue;
+            }
 
             LocalDateTime startTime, endTime, amEndTime = null;
 
             if(timePeriod == 1){
                 startTime = queryDate.atTime(5, 0, 0);
-                if(detailsUserVo != null && detailsUserVo.getAmStartTime() != null){
+                if(detailsUserVo.getAmStartTime() != null){
                     startTime = queryDate.atTime(detailsUserVo.getAmStartTime());
                 }
                 endTime = queryDate.atTime(12, 0, 0);
-                if(detailsUserVo != null && detailsUserVo.getAmEndTime() != null){
+                if(detailsUserVo.getAmEndTime() != null){
                     endTime = queryDate.atTime(detailsUserVo.getAmEndTime());
                 }
             }else if(timePeriod == 2){
                 startTime = queryDate.atTime(12, 0, 0);
-                if(detailsUserVo != null && detailsUserVo.getPmStartTime() != null){
+                if(detailsUserVo.getPmStartTime() != null){
                     startTime = queryDate.atTime(detailsUserVo.getPmStartTime());
                 }
                 endTime = queryDate.atTime(18, 0, 0);
-                if(detailsUserVo != null && detailsUserVo.getPmEndTime() != null){
+                if(detailsUserVo.getPmEndTime() != null){
                     endTime = queryDate.atTime(detailsUserVo.getPmEndTime());
                 }
                 amEndTime  = queryDate.atTime(12, 0, 0);
-                if(detailsUserVo != null && detailsUserVo.getAmEndTime() != null){
+                if(detailsUserVo.getAmEndTime() != null){
                     amEndTime = queryDate.atTime(detailsUserVo.getAmEndTime());
                 }
             }else{
                 startTime = queryDate.atTime(0, 0, 0);
-                if(detailsUserVo != null && detailsUserVo.getEveningStartTime() != null){
+                if(detailsUserVo.getEveningStartTime() != null){
                     startTime = queryDate.atTime(detailsUserVo.getEveningStartTime());
                 }
                 endTime = queryDate.atTime(23, 59, 59);
-                if(detailsUserVo != null && detailsUserVo.getEveningEndTime() != null){
+                if(detailsUserVo.getEveningEndTime() != null){
                     endTime = queryDate.atTime(detailsUserVo.getEveningEndTime());
                 }
             }
-
             record.setStartTime(startTime);
             record.setEndTime(endTime);
 

+ 1 - 1
src/test/java/com/xjrsoft/module/liteflow/node/WfTeacherleaveNodeTest.java

@@ -23,7 +23,7 @@ class WfTeacherleaveNodeTest {
     @Test
     public void process() throws Exception {
         // 获取表单中数据编号
-        Long formId = 1848561918628917248L;
+        Long formId = 1848627799685918720L;
         if (formId != null) {
             // 数据处理
             wfTeacherleaveService.updateAttendancestatus(formId);