|
@@ -9,6 +9,7 @@ import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
@@ -26,6 +27,7 @@ public class ExcelParserService {
|
|
|
// 获取表头行
|
|
|
Row headerRow = sheet.getRow(0);
|
|
|
// 从第二行开始解析数据(假设第一行是表头)
|
|
|
+ boolean isHandlingNightWork = false;
|
|
|
for (int i = 2; i <= sheet.getLastRowNum(); i++) {
|
|
|
Row row = sheet.getRow(i);
|
|
|
if (row == null) continue;
|
|
@@ -51,14 +53,26 @@ public class ExcelParserService {
|
|
|
|
|
|
// 解析时间记录
|
|
|
String timeRecord = getCellValue(timeCell);
|
|
|
+ System.out.println("dateStr="+dateStr+", TImeRecord:"+timeRecord);
|
|
|
if (timeRecord == null || timeRecord.isEmpty() || "-".equals(timeRecord)) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
// 分割时间记录(可能有多个打卡时间)
|
|
|
String[] times = timeRecord.split("\n");
|
|
|
+ if (isHandlingNightWork) {
|
|
|
+ // 如果是处理夜班工作,忽略12:00前的打卡
|
|
|
+ times = java.util.Arrays.stream(times)
|
|
|
+ .filter(t -> t.compareTo("12:00") >= 0)
|
|
|
+ .toArray(String[]::new);
|
|
|
+ isHandlingNightWork = false;
|
|
|
+ }
|
|
|
|
|
|
if (times.length == 1) {
|
|
|
+ if (times[0].length() > "00:00".length()) {
|
|
|
+ //去掉后面的秒
|
|
|
+ times[0] = times[0].substring(0, "00:00".length());
|
|
|
+ }
|
|
|
//当前只有一次打卡,可能是晚班,要获取次日最晚打卡作为下班打卡。
|
|
|
if (times[0].compareTo("18:00") > 0) {
|
|
|
String sTime = times[0];
|
|
@@ -70,14 +84,17 @@ public class ExcelParserService {
|
|
|
String nextDayTimeStr = getCellValue(nextDayTime);
|
|
|
if (!StringUtils.isEmpty(nextDayTimeStr) && !"-".equals(nextDayTimeStr)) {
|
|
|
String[] nextDayTimes = nextDayTimeStr.split("\n");
|
|
|
- if (nextDayTimes[nextDayTimes.length -1].compareTo("12:00") < 0) {
|
|
|
+ //取次日12点前的最晚打卡
|
|
|
+ nextDayTimes = java.util.Arrays.stream(nextDayTimes)
|
|
|
+ .filter(t -> t.compareTo("12:00") < 0)
|
|
|
+ .toArray(String[]::new);
|
|
|
+ if (nextDayTimes.length > 0) {
|
|
|
//次日上午打卡结束
|
|
|
String nextDayEndTime = "次日"+nextDayTimes[nextDayTimes.length -1];
|
|
|
times = new String[2];
|
|
|
times[0] = sTime;
|
|
|
times[1] = nextDayEndTime;
|
|
|
- //跳过下一个日期
|
|
|
- col++;
|
|
|
+ isHandlingNightWork = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -131,7 +148,10 @@ public class ExcelParserService {
|
|
|
return cell.getStringCellValue().trim();
|
|
|
case NUMERIC:
|
|
|
if (DateUtil.isCellDateFormatted(cell)) {
|
|
|
- return cell.getDateCellValue().toString();
|
|
|
+ java.util.Date date = cell.getDateCellValue();
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
|
|
|
+ System.out.println("这是datecell:"+cell.getDateCellValue().toString());
|
|
|
+ return simpleDateFormat.format(date);
|
|
|
} else {
|
|
|
return String.valueOf(cell.getNumericCellValue());
|
|
|
}
|
|
@@ -145,8 +165,8 @@ public class ExcelParserService {
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- String startTime = "08:29";
|
|
|
- String endTime = "18:07";
|
|
|
+ String startTime = "20:06";
|
|
|
+ String endTime = "次日08:35";
|
|
|
double workHours = calculateZhengBeiWorkHours(startTime, endTime);
|
|
|
|
|
|
System.out.println("工作时长:" + workHours + "小时");
|
|
@@ -185,6 +205,10 @@ public class ExcelParserService {
|
|
|
if (startHour <= 17 && endHour >= 18) {
|
|
|
hours -= 0.5;
|
|
|
}
|
|
|
+ //夜班减去休息1.5小时
|
|
|
+ if (startHour >= 20 || endHour >= 30) {
|
|
|
+ hours -= 1.5;
|
|
|
+ }
|
|
|
double minPart = hours - (int)hours;
|
|
|
|
|
|
if (minPart > 0 && minPart < 0.5) {
|