|
@@ -1,16 +1,17 @@
|
|
|
package com.management.platform.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.management.platform.entity.Attendance;
|
|
|
-import com.management.platform.entity.CustomerInfo;
|
|
|
-import com.management.platform.entity.User;
|
|
|
+import com.management.platform.entity.*;
|
|
|
import com.management.platform.mapper.AttendanceMapper;
|
|
|
import com.management.platform.service.AttendanceService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.management.platform.service.CustomerInfoService;
|
|
|
+import com.management.platform.service.SpecialDateSetService;
|
|
|
import com.management.platform.service.UserService;
|
|
|
import com.management.platform.util.ExcelUtil;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
import com.management.platform.util.MessageUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.poi.EncryptedDocumentException;
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
@@ -26,12 +27,12 @@ import java.io.InputStream;
|
|
|
import java.text.DateFormat;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.DayOfWeek;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.YearMonth;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -42,6 +43,7 @@ import java.util.stream.Collectors;
|
|
|
* @author Seyason
|
|
|
* @since 2025-06-16
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class AttendanceServiceImpl extends ServiceImpl<AttendanceMapper, Attendance> implements AttendanceService {
|
|
|
@Resource
|
|
@@ -50,6 +52,9 @@ public class AttendanceServiceImpl extends ServiceImpl<AttendanceMapper, Attenda
|
|
|
@Resource
|
|
|
private AttendanceService attendanceService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private SpecialDateSetService specialDateSetService;
|
|
|
+
|
|
|
@Override
|
|
|
public HttpRespMsg importAttendanceData(String month, MultipartFile file, HttpServletRequest request) {
|
|
|
HttpRespMsg msg=new HttpRespMsg();
|
|
@@ -172,4 +177,123 @@ public class AttendanceServiceImpl extends ServiceImpl<AttendanceMapper, Attenda
|
|
|
return msg;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getCalendarByMonth(String month) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ try {
|
|
|
+ // 1. 解析月份参数
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
|
|
|
+ YearMonth yearMonth = YearMonth.parse(month, formatter);
|
|
|
+
|
|
|
+ // 2. 获取自定义休息日列表
|
|
|
+ List<LocalDate> customHolidays = getCustomHolidays(yearMonth);
|
|
|
+
|
|
|
+ // 2.1 获取自定义休息日列表
|
|
|
+ List<LocalDate> workdays = getWorkDays(yearMonth);
|
|
|
+
|
|
|
+ // 3. 生成该月所有日期的信息
|
|
|
+ List<DayInfo> calendar = new ArrayList<>();
|
|
|
+ LocalDate startDate = yearMonth.atDay(1);
|
|
|
+ LocalDate endDate = yearMonth.atEndOfMonth();
|
|
|
+
|
|
|
+ for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) {
|
|
|
+ DayInfo dayInfo = new DayInfo();
|
|
|
+ dayInfo.setDate(date.format(DateTimeFormatter.ISO_LOCAL_DATE));
|
|
|
+ dayInfo.setDayOfWeek(date.getDayOfWeek().getValue()); // 1-7 (Monday-Sunday)
|
|
|
+
|
|
|
+ // 判断是否为休息日(周末或自定义假日)
|
|
|
+ if (date.getDayOfWeek() == DayOfWeek.SATURDAY
|
|
|
+ || date.getDayOfWeek() == DayOfWeek.SUNDAY
|
|
|
+ || customHolidays.contains(date)) {
|
|
|
+ dayInfo.setType(0); // 休息日
|
|
|
+ }else {
|
|
|
+ dayInfo.setType(1);//工作日
|
|
|
+ }
|
|
|
+
|
|
|
+ if (workdays.contains(date)){
|
|
|
+ dayInfo.setType(1);//工作日
|
|
|
+ }
|
|
|
+
|
|
|
+ calendar.add(dayInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 设置返回结果
|
|
|
+ msg.setData(calendar);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ msg.setError("获取日历信息失败: " + e.getMessage());
|
|
|
+ log.info("获取日历信息失败, month: {}, error: {}", month, e.getMessage(), e);
|
|
|
+ }
|
|
|
+
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<LocalDate> getWorkDays(YearMonth yearMonth) {
|
|
|
+ List<LocalDate> workDays = new ArrayList<>();
|
|
|
+ LocalDate endOfMonth = yearMonth.atEndOfMonth();
|
|
|
+ LocalDate startOfMonth = yearMonth.atDay(1);
|
|
|
+ List<SpecialDateSet> dateSetList = specialDateSetService.list(new QueryWrapper<SpecialDateSet>()
|
|
|
+ .between("special_date", startOfMonth, endOfMonth).eq("type",1));
|
|
|
+ List<String> collect2 = new ArrayList<>();
|
|
|
+ if (!dateSetList.isEmpty()){
|
|
|
+ List<Date> collect = dateSetList.stream().map(SpecialDateSet::getSpecialDate).collect(Collectors.toList());
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ List<String> collect1 = collect.stream()
|
|
|
+ .map(sdf::format)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ collect2.addAll(collect1);
|
|
|
+ }
|
|
|
+ // 将字符串日期转换为LocalDate并添加到列表中
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
|
|
|
+ for (String dateStr : collect2) {
|
|
|
+ LocalDate holiday = LocalDate.parse(dateStr, formatter);
|
|
|
+ if (holiday.getYear() == yearMonth.getYear() &&
|
|
|
+ holiday.getMonth() == yearMonth.getMonth()) {
|
|
|
+ workDays.add(holiday);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return workDays;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 辅助方法:获取自定义休息日列表(示例)
|
|
|
+ private List<LocalDate> getCustomHolidays(YearMonth yearMonth) {
|
|
|
+ List<LocalDate> holidays = new ArrayList<>();
|
|
|
+
|
|
|
+ // 2025年中国法定节假日列表
|
|
|
+ String[] holidayDates = {
|
|
|
+ "2025-01-01", // 元旦
|
|
|
+ "2025-01-28", "2025-01-29", "2025-01-30", "2025-01-31", "2025-02-03", "2025-02-04", // 春节
|
|
|
+ "2025-04-04", // 清明节
|
|
|
+ "2025-05-01", "2025-05-02", "2025-05-05", // 劳动节
|
|
|
+ "2025-06-02", // 端午节
|
|
|
+ "2025-10-01", "2025-10-02", "2025-10-03", "2025-10-06", "2025-10-07", "2025-10-08" // 国庆节
|
|
|
+ };
|
|
|
+ List<String> collect2 = Arrays.stream(holidayDates).collect(Collectors.toList());
|
|
|
+
|
|
|
+ LocalDate endOfMonth = yearMonth.atEndOfMonth();
|
|
|
+ LocalDate startOfMonth = yearMonth.atDay(1);
|
|
|
+ List<SpecialDateSet> dateSetList = specialDateSetService.list(new QueryWrapper<SpecialDateSet>()
|
|
|
+ .between("special_date", startOfMonth, endOfMonth).eq("type",0));
|
|
|
+ if (!dateSetList.isEmpty()){
|
|
|
+ List<Date> collect = dateSetList.stream().map(SpecialDateSet::getSpecialDate).collect(Collectors.toList());
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ List<String> collect1 = collect.stream()
|
|
|
+ .map(sdf::format)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ collect2.addAll(collect1);
|
|
|
+ }
|
|
|
+ // 将字符串日期转换为LocalDate并添加到列表中
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
|
|
|
+ for (String dateStr : collect2) {
|
|
|
+ LocalDate holiday = LocalDate.parse(dateStr, formatter);
|
|
|
+ if (holiday.getYear() == yearMonth.getYear() &&
|
|
|
+ holiday.getMonth() == yearMonth.getMonth()) {
|
|
|
+ holidays.add(holiday);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return holidays;
|
|
|
+ }
|
|
|
}
|