瀏覽代碼

计算工作日

cs 2 年之前
父節點
當前提交
2bdd128932

+ 11 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/LeaveSheetController.java

@@ -118,5 +118,16 @@ public class LeaveSheetController {
         String userId = request.getHeader("Token");
         return leaveSheetService.exportLeaveData(userId,exportLeave.getStatus(),exportLeave.getLeaveType(),exportLeave.getStartTime(),exportLeave.getEndTime());
     }
+
+    /**
+     * 计算请假的时长
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    @RequestMapping("/leaveDays")
+    public HttpRespMsg leaveDays (String startDate,String endDate){
+        return leaveSheetService.leaveDays(startDate,endDate);
+    }
 }
 

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

@@ -41,4 +41,6 @@ public interface LeaveSheetService extends IService<LeaveSheet> {
     HttpRespMsg auditList(LeaveSheet sheet, Integer pageIndex, Integer pageSize);
 
     float leaveTimeSum(Integer companyId, String startDate, String endDate, float standardHours, float allDay, List<LeaveSheet> leaveSheets);
+
+    HttpRespMsg leaveDays(String startDate, String endDate);
 }

+ 20 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/LeaveSheetServiceImpl.java

@@ -774,4 +774,24 @@ public class LeaveSheetServiceImpl extends ServiceImpl<LeaveSheetMapper, LeaveSh
         leaveTime = new BigDecimal(leaveTime).setScale(1,BigDecimal.ROUND_HALF_UP).floatValue();
         return leaveTime;
     }
+
+    /**
+     * 计算两个日期之间的工作日
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    @Override
+    public HttpRespMsg leaveDays(String startDate, String endDate) {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        Integer leaveDays = 0;
+        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        LocalDate localStartDate = LocalDate.parse(startDate, dateTimeFormatter);
+        LocalDate localEndDate = LocalDate.parse(endDate, dateTimeFormatter);
+        if (localStartDate.isBefore(localEndDate) || localStartDate.isEqual(localEndDate)){
+            leaveDays = WorkDayCalculateUtils.getWorkDaysListInRange(startDate, endDate, 0).size();
+        }
+        httpRespMsg.data = leaveDays;
+        return httpRespMsg;
+    }
 }