|
|
@@ -4,10 +4,12 @@ import com.alibaba.excel.context.AnalysisContext;
|
|
|
import com.alibaba.excel.metadata.data.ReadCellData;
|
|
|
import com.alibaba.excel.read.listener.ReadListener;
|
|
|
import lombok.Data;
|
|
|
+import org.sky.core.log.exception.ServiceException;
|
|
|
import org.sky.core.tool.utils.StringUtil;
|
|
|
import org.sky.scientific.pojo.vo.DailyAttendance;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -24,6 +26,15 @@ public class AttendanceMonthlyDataListener implements ReadListener<Map<Integer,
|
|
|
private List<AttendanceMonthlyExcel> records = new ArrayList<>();
|
|
|
private boolean headersProcessed = false;
|
|
|
private String yearAndMonth;
|
|
|
+ private int daysInMonth;
|
|
|
+
|
|
|
+ public AttendanceMonthlyDataListener(String yearAndMonth) {
|
|
|
+ this.yearAndMonth = yearAndMonth;
|
|
|
+ int year = Integer.parseInt(yearAndMonth.substring(0, 4));
|
|
|
+ int month = Integer.parseInt(yearAndMonth.substring(4));
|
|
|
+ LocalDate startDate = LocalDate.of(year, month, 1);
|
|
|
+ this.daysInMonth = startDate.lengthOfMonth();
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) {
|
|
|
@@ -83,14 +94,16 @@ public class AttendanceMonthlyDataListener implements ReadListener<Map<Integer,
|
|
|
// 解析每日考勤数据
|
|
|
int maxDays = Math.min(dateHeaders.size(), dayOfWeekHeaders.size());
|
|
|
for (int i = 0; i < maxDays; i++) {
|
|
|
+ int everyDay = Integer.parseInt(dateHeaders.get(i));
|
|
|
+ if(everyDay > daysInMonth){
|
|
|
+ throw new ServiceException(yearAndMonth+"只有"+daysInMonth+"天,请核对日期表头");
|
|
|
+ }
|
|
|
String hoursStr = data.get(i + 5); // 考勤数据从第5列开始
|
|
|
//没有填报的日期,跳过
|
|
|
if (hoursStr != null && !hoursStr.trim().isEmpty()) {
|
|
|
try {
|
|
|
- String date = dateHeaders.get(i);
|
|
|
- String s = Integer.parseInt(date) <= 9 ? ("0" + date) : date;
|
|
|
DailyAttendance daily = new DailyAttendance();
|
|
|
- daily.setWorkDate(yearAndMonth + s);
|
|
|
+ daily.setWorkDate(yearAndMonth + (everyDay<10?"0"+everyDay:everyDay));
|
|
|
daily.setWorkHours(safeParseDouble(hoursStr));
|
|
|
record.getDailyAttendances().add(daily);
|
|
|
} catch (NumberFormatException e) {
|