|
@@ -4,6 +4,7 @@ import com.management.platform.entity.UserCorpwxTime;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.IOException;
|
|
@@ -23,7 +24,6 @@ public class ExcelParserService {
|
|
|
|
|
|
// 获取表头行
|
|
|
Row headerRow = sheet.getRow(0);
|
|
|
- List<String> ignoreDates = new ArrayList<>();
|
|
|
// 从第二行开始解析数据(假设第一行是表头)
|
|
|
for (int i = 2; i <= sheet.getLastRowNum(); i++) {
|
|
|
Row row = sheet.getRow(i);
|
|
@@ -31,8 +31,6 @@ public class ExcelParserService {
|
|
|
|
|
|
// 获取姓名和部门
|
|
|
String name = getCellValue(row.getCell(0));
|
|
|
- String department = getCellValue(row.getCell(2));
|
|
|
-
|
|
|
// 从第4列开始是日期列
|
|
|
for (int col = 3; col < row.getLastCellNum(); col++) {
|
|
|
Cell dateCell = headerRow.getCell(col);
|
|
@@ -42,7 +40,6 @@ public class ExcelParserService {
|
|
|
|
|
|
// 解析日期(格式如:03-01\n周六)
|
|
|
String dateStr = getCellValue(dateCell);
|
|
|
- if (ignoreDates.contains(dateStr)) continue;
|
|
|
String[] dateParts = dateStr.split("\n");
|
|
|
if (dateParts.length < 1) continue;
|
|
|
|
|
@@ -67,16 +64,21 @@ public class ExcelParserService {
|
|
|
//次日最晚打卡
|
|
|
Cell nextDateCell = headerRow.getCell(col + 1);
|
|
|
String nextDateStr = getCellValue(nextDateCell);
|
|
|
- Cell nextDayTime = row.getCell(col + 1);
|
|
|
- String nextDayTimeStr = getCellValue(nextDayTime);
|
|
|
- String[] nextDayTimes = nextDayTimeStr.split("\n");
|
|
|
- if (nextDayTimes[nextDayTimes.length -1].compareTo("12:00") < 0) {
|
|
|
- //次日上午打卡结束
|
|
|
- String nextDayEndTime = "次日"+nextDayTimes[nextDayTimes.length -1];
|
|
|
- times = new String[2];
|
|
|
- times[0] = sTime;
|
|
|
- times[1] = nextDayEndTime;
|
|
|
- ignoreDates.add(nextDateStr);
|
|
|
+ if (!StringUtils.isEmpty(nextDateStr)) {
|
|
|
+ Cell nextDayTime = row.getCell(col + 1);
|
|
|
+ String nextDayTimeStr = getCellValue(nextDayTime);
|
|
|
+ if (!StringUtils.isEmpty(nextDayTimeStr) && !"-".equals(nextDayTimeStr)) {
|
|
|
+ String[] nextDayTimes = nextDayTimeStr.split("\n");
|
|
|
+ if (nextDayTimes[nextDayTimes.length -1].compareTo("12:00") < 0) {
|
|
|
+ //次日上午打卡结束
|
|
|
+ String nextDayEndTime = "次日"+nextDayTimes[nextDayTimes.length -1];
|
|
|
+ times = new String[2];
|
|
|
+ times[0] = sTime;
|
|
|
+ times[1] = nextDayEndTime;
|
|
|
+ //跳过下一个日期
|
|
|
+ col++;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -145,11 +147,16 @@ public class ExcelParserService {
|
|
|
// 简单计算工作时长(小时)
|
|
|
// 实际应用中需要更精确的计算,考虑午休时间等
|
|
|
String[] startParts = startTime.split(":");
|
|
|
+ boolean isEndNextDay = endTime.startsWith("次日");
|
|
|
+ if (endTime.startsWith("次日")) {
|
|
|
+ endTime = endTime.substring(3);
|
|
|
+ System.out.println("去掉次日后="+endTime);
|
|
|
+ }
|
|
|
String[] endParts = endTime.split(":");
|
|
|
|
|
|
int startHour = Integer.parseInt(startParts[0]);
|
|
|
int startMinute = Integer.parseInt(startParts[1]);
|
|
|
- int endHour = Integer.parseInt(endParts[0]);
|
|
|
+ int endHour = Integer.parseInt(endParts[0]) + (isEndNextDay ? 24 : 0);
|
|
|
int endMinute = Integer.parseInt(endParts[1]);
|
|
|
|
|
|
double hours = (endHour - startHour) + (endMinute - startMinute) / 60.0;
|