yusm пре 1 недеља
родитељ
комит
540326a8c3

+ 98 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/controller/ApplyFormController.java

@@ -1,10 +1,30 @@
 package com.management.platform.controller;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.management.platform.entity.ApplyForm;
+import com.management.platform.entity.Attendance;
+import com.management.platform.entity.AttendanceStaff;
+import com.management.platform.entity.User;
+import com.management.platform.service.ApplyFormService;
+import com.management.platform.service.AttendanceService;
+import com.management.platform.service.UserService;
+import com.management.platform.util.HttpRespMsg;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.YearMonth;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
 /**
  * <p>
  *  前端控制器
@@ -17,5 +37,83 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/apply-form")
 public class ApplyFormController {
 
+    @Resource
+    private ApplyFormService applyFormService;
+
+    @Resource
+    private AttendanceService attendanceService;
+
+    @Resource
+    private UserService userService;
+
+    @RequestMapping("/synchrodataToAttendance")
+    public HttpRespMsg synchrodataToAttendance(String month) {
+        HttpRespMsg msg = new HttpRespMsg();
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
+        DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        YearMonth yearMonth = YearMonth.parse(month, formatter);
+        // 3. 生成该月所有日期的信息
+        List<AttendanceStaff> allList = new ArrayList<>();
+        LocalDate startDate = yearMonth.atDay(1);
+        LocalDate endDate = startDate.plusMonths(1);
+
+        List<User> userList = userService.list(new QueryWrapper<User>().eq("company_id", 7));
+        List<Attendance> attendanceList = attendanceService.list(new QueryWrapper<Attendance>().eq("month", month));
+
+
+        ArrayList<Attendance> attendances = new ArrayList<>();
+
+        //开始时间,结束时间都在这个月份的申请单数据
+        List<ApplyForm> applyFormList= applyFormService.getListByFirstDateAndLastDate(startDate,endDate);
+        List<ApplyForm> listLittle = applyFormList.stream().filter(a -> a.getSumTime().compareTo(BigDecimal.valueOf(8)) <= 0).collect(Collectors.toList());//申请单时长小于8
+        List<ApplyForm> listBig = applyFormList.stream().filter(a -> a.getSumTime().compareTo(BigDecimal.valueOf(8)) > 0).collect(Collectors.toList());//申请单时长大于8
+        for (ApplyForm applyForm : listLittle) {
+            if (applyForm.getType()!=6){
+                Attendance a = new Attendance();
+                Attendance b = new Attendance();
+                Optional<User> first = userList.stream().filter(u -> u.getJobNumber().equals(applyForm.getApplyId())).findFirst();
+                Optional<Attendance> first1 = attendanceList.stream().filter(u -> u.getJobNumber().equals(applyForm.getApplyId())).findFirst();
+                if (first.isPresent()&&first1.isPresent()){
+                    a.setMonth(month);
+                    a.setJobNumber(applyForm.getApplyId());
+                    a.setDeptName(first1.get().getDeptName());
+                    a.setName(first.get().getName());
+                    a.setClockTime(applyForm.getStartTime());
+                    attendances.add(a);
+
+                    b.setMonth(month);
+                    b.setJobNumber(applyForm.getApplyId());
+                    b.setDeptName(first1.get().getDeptName());
+                    b.setName(first.get().getName());
+                    b.setClockTime(applyForm.getStartTime());
+                    attendances.add(b);
+                }
+            } else {
+                Attendance a = new Attendance();
+                Optional<User> first = userList.stream().filter(u -> u.getJobNumber().equals(applyForm.getApplyId())).findFirst();
+                Optional<Attendance> first1 = attendanceList.stream().filter(u -> u.getJobNumber().equals(applyForm.getApplyId())).findFirst();
+                if (first.isPresent()&&first1.isPresent()){
+                    a.setMonth(month);
+                    a.setJobNumber(applyForm.getApplyId());
+                    a.setDeptName(first1.get().getDeptName());
+                    a.setName(first.get().getName());
+                    a.setClockTime(applyForm.getStartTime());
+                    attendances.add(a);
+                }
+            }
+        }
+
+        for (ApplyForm applyForm : listBig) {
+            LocalDateTime startTime = applyForm.getStartTime();
+            LocalDateTime endTime = applyForm.getEndTime();
+
+            for (LocalDate date = startTime.toLocalDate(); !date.isAfter(endTime.toLocalDate()); date = date.plusDays(1)) {
+
+            }
+        }
+        return msg;
+    }
+
+
 }
 

+ 93 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/demo/WorkingDaysRangeCalculator.java

@@ -0,0 +1,93 @@
+package com.management.platform.demo;
+
+import java.time.*;
+import java.util.*;
+import java.util.stream.*;
+
+public class WorkingDaysRangeCalculator {
+
+
+    /**
+     * 计算有效工作时间段(排除周末和节假日)
+     */
+    public static List<TimeRange> calculate(LocalDateTime startTime, LocalDateTime endTime) {
+        List<TimeRange> ranges = new ArrayList<>();
+
+        // 1. 检查时间范围有效性
+        if (endTime.isBefore(startTime)) {
+            return ranges;
+        }
+
+        // 2. 遍历每一天
+        LocalDate currentDate = startTime.toLocalDate();
+        LocalDate endDate = endTime.toLocalDate();
+
+        while (!currentDate.isAfter(endDate)) {
+            if (isWorkingDay(currentDate)) { // 只处理工作日
+                LocalDateTime dayStart = getDayStart(currentDate, startTime);
+                LocalDateTime dayEnd = getDayEnd(currentDate, endTime);
+
+                if (!dayStart.isAfter(dayEnd)) { // 避免无效时间段
+                    ranges.add(new TimeRange(dayStart, dayEnd));
+                }
+            }
+            currentDate = currentDate.plusDays(1);
+        }
+
+        return ranges;
+    }
+
+    /**
+     * 判断是否是工作日(非周末且非节假日)
+     */
+    private static boolean isWorkingDay(LocalDate date) {
+        DayOfWeek dayOfWeek = date.getDayOfWeek();
+        return !(dayOfWeek == DayOfWeek.SATURDAY || 
+                dayOfWeek == DayOfWeek.SUNDAY);
+    }
+
+    /**
+     * 获取某天的开始时间(如果是第一天,用实际 startTime;否则用 8:00)
+     */
+    private static LocalDateTime getDayStart(LocalDate date, LocalDateTime originalStart) {
+        if (date.equals(originalStart.toLocalDate())) {
+            return originalStart; // 第一天保持原时间
+        }
+        return date.atTime(8, 0); // 其他工作日从8:00开始
+    }
+
+    /**
+     * 获取某天的结束时间(如果是最后一天,用实际 endTime;否则用 17:00)
+     */
+    private static LocalDateTime getDayEnd(LocalDate date, LocalDateTime originalEnd) {
+        if (date.equals(originalEnd.toLocalDate())) {
+            return originalEnd; // 最后一天保持原时间
+        }
+        return date.atTime(17, 0); // 其他工作日到17:00结束
+    }
+
+    // 时间段类
+    public static class TimeRange {
+        private final LocalDateTime start;
+        private final LocalDateTime end;
+
+        public TimeRange(LocalDateTime start, LocalDateTime end) {
+            this.start = start;
+            this.end = end;
+        }
+
+        @Override
+        public String toString() {
+            return start + " → " + end + " (" + start.toLocalDate().getDayOfWeek() + ")";
+        }
+    }
+
+    public static void main(String[] args) {
+        // 测试案例
+        LocalDateTime start = LocalDateTime.of(2025, 6, 20, 18, 0); // 周一(工作日)
+        LocalDateTime end = LocalDateTime.of(2025, 6, 26, 16, 0);   // 周日(非工作日)
+
+        System.out.println("工作时间段(排除周末和节假日):");
+        calculate(start, end).forEach(System.out::println);
+    }
+}

+ 3 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/mapper/ApplyFormMapper.java

@@ -3,6 +3,7 @@ package com.management.platform.mapper;
 import com.management.platform.entity.ApplyForm;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
+import java.time.LocalDate;
 import java.util.List;
 
 /**
@@ -16,4 +17,6 @@ import java.util.List;
 public interface ApplyFormMapper extends BaseMapper<ApplyForm> {
 
     List<ApplyForm> getListByDate(String date,String userId);
+
+    List<ApplyForm> getListByFirstDateAndLastDate(LocalDate startDate, LocalDate endDate);
 }

+ 2 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/ApplyFormService.java

@@ -3,6 +3,7 @@ package com.management.platform.service;
 import com.management.platform.entity.ApplyForm;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.time.LocalDate;
 import java.util.List;
 
 /**
@@ -17,4 +18,5 @@ public interface ApplyFormService extends IService<ApplyForm> {
 
     List<ApplyForm> getListByDate(String date,String userId);
 
+    List<ApplyForm> getListByFirstDateAndLastDate(LocalDate startDate, LocalDate endDate);
 }

+ 6 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/impl/ApplyFormServiceImpl.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.time.LocalDate;
 import java.util.Collections;
 import java.util.List;
 
@@ -27,4 +28,9 @@ public class ApplyFormServiceImpl extends ServiceImpl<ApplyFormMapper, ApplyForm
     public List<ApplyForm> getListByDate(String date,String userId) {
         return applyFormMapper.getListByDate(date,userId);
     }
+
+    @Override
+    public List<ApplyForm> getListByFirstDateAndLastDate(LocalDate startDate, LocalDate endDate) {
+        return applyFormMapper.getListByFirstDateAndLastDate(startDate,endDate);
+    }
 }

+ 16 - 12
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/impl/AttendanceStaffServiceImpl.java

@@ -512,6 +512,7 @@ public class AttendanceStaffServiceImpl extends ServiceImpl<AttendanceStaffMappe
                         maplist.add(1,map);
                     }
                 }
+
                 staff.setMaplist(maplist);
             }
             else {
@@ -519,21 +520,24 @@ public class AttendanceStaffServiceImpl extends ServiceImpl<AttendanceStaffMappe
                 if (!applyFormList.isEmpty()){
                     StringBuilder stringBuilder = new StringBuilder();
                     for (ApplyForm applyForm : applyFormList) {
+                        stringBuilder.append(applyForm.getStartTime().format(formatter2))
+                                .append("-").append(applyForm.getEndTime().format(formatter2));
                         if (applyForm.getType()==3) {
-                            stringBuilder
-                                    .append(applyForm.getStartTime().format(formatter2))
-                                    .append("-").append(applyForm.getEndTime().format(formatter2))
-                                    .append(applyForm.getApplyBillName())
-                                    .append(" 时长")
-                                    .append(applyForm.getSumTime()).append("小时");
+                            stringBuilder.append(applyForm.getApplyBillName());
+                            if ((applyForm.getStartTime().getHour()==8||applyForm.getEndTime().getHour()==17)&&staff.getAttendanceTypeName().equals("班次异常")){
+                                staff.setAttendanceType(0);
+                                if (applyForm.getStartTime().getHour()==8) {
+                                    staff.setClockStartTime(LocalDateTime.of(clockDate, LocalTime.of(8, 0)));
+                                } else if (applyForm.getEndTime().getHour()==17) {
+                                    staff.setClockStartTime(LocalDateTime.of(clockDate, LocalTime.of(17, 0)));
+                                }
+                                staff.setAttendanceTypeName("白班");
+                            }
+
                         }else {
-                            stringBuilder
-                                    .append(applyForm.getStartTime().format(formatter2))
-                                    .append("-").append(applyForm.getEndTime().format(formatter2))
-                                    .append(applyForm.getTypeName())
-                                    .append(" 时长")
-                                    .append(applyForm.getSumTime()).append("小时");
+                            stringBuilder.append(applyForm.getTypeName());
                         }
+                        stringBuilder.append(" 时长: ").append(applyForm.getSumTime()).append("小时");
                     }
                     HashMap<String, Object> map = new HashMap<>();
                     map.put("res", stringBuilder.toString());

+ 5 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/resources/mapper/ApplyFormMapper.xml

@@ -26,5 +26,10 @@
         WHERE #{date} BETWEEN Date(a.start_time) and DATE(a.end_time)  AND `user`.id=#{userId}
         order by a.type asc
     </select>
+    <select id="getListByFirstDateAndLastDate" resultType="com.management.platform.entity.ApplyForm">
+        select a.* from apply_form a
+        WHERE  a.start_time &gt;= #{startDate}  and  a.end_time &lt; #{endDate}
+        order by a.type asc
+    </select>
 
 </mapper>