|
|
@@ -14,12 +14,15 @@ import com.sundot.airport.exam.domain.ExamMonthlyScore;
|
|
14
|
14
|
import com.sundot.airport.exam.dto.ExamMonthlyScoreImportVO;
|
|
15
|
15
|
import com.sundot.airport.exam.service.IExamMonthlyScoreService;
|
|
16
|
16
|
import com.sundot.airport.system.service.ISysUserService;
|
|
|
17
|
+import org.apache.poi.ss.usermodel.DateUtil;
|
|
17
|
18
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
18
|
19
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
19
|
20
|
import org.springframework.web.bind.annotation.*;
|
|
20
|
21
|
import org.springframework.web.multipart.MultipartFile;
|
|
21
|
22
|
|
|
22
|
23
|
import javax.servlet.http.HttpServletResponse;
|
|
|
24
|
+import java.text.SimpleDateFormat;
|
|
|
25
|
+import java.util.Date;
|
|
23
|
26
|
import java.util.List;
|
|
24
|
27
|
|
|
25
|
28
|
/**
|
|
|
@@ -182,6 +185,11 @@ public class ExamMonthlyScoreController extends BaseController {
|
|
182
|
185
|
int rowNum = i + 2;
|
|
183
|
186
|
|
|
184
|
187
|
try {
|
|
|
188
|
+ // 判断是否为空行(所有字段都为空)
|
|
|
189
|
+ if (isEmptyRow(vo)) {
|
|
|
190
|
+ continue; // 跳过空行
|
|
|
191
|
+ }
|
|
|
192
|
+
|
|
185
|
193
|
// 验证必填字段
|
|
186
|
194
|
if (StrUtil.isBlank(vo.getStudentName())) {
|
|
187
|
195
|
failureNum++;
|
|
|
@@ -203,8 +211,8 @@ public class ExamMonthlyScoreController extends BaseController {
|
|
203
|
211
|
continue;
|
|
204
|
212
|
}
|
|
205
|
213
|
|
|
206
|
|
- // 转换年月格式
|
|
207
|
|
- String yearMonth = convertYearMonth(vo.getYearMonth());
|
|
|
214
|
+ // 转换年月格式为 yyyy-MM
|
|
|
215
|
+ String yearMonth = formatYearMonth(vo.getYearMonth());
|
|
208
|
216
|
|
|
209
|
217
|
// 从缓存中检查是否已存在
|
|
210
|
218
|
String key = user.getUserId() + "_" + yearMonth;
|
|
|
@@ -269,32 +277,74 @@ public class ExamMonthlyScoreController extends BaseController {
|
|
269
|
277
|
}
|
|
270
|
278
|
|
|
271
|
279
|
/**
|
|
272
|
|
- * 转换年月格式
|
|
|
280
|
+ * 判断是否为空行(所有字段都为空)
|
|
|
281
|
+ */
|
|
|
282
|
+ private boolean isEmptyRow(ExamMonthlyScoreImportVO vo) {
|
|
|
283
|
+ return StrUtil.isBlank(vo.getYearMonth())
|
|
|
284
|
+ && StrUtil.isBlank(vo.getStudentName())
|
|
|
285
|
+ && StrUtil.isBlank(vo.getTeam())
|
|
|
286
|
+ && StrUtil.isBlank(vo.getJobPosition())
|
|
|
287
|
+ && vo.getComprehensiveScore() == null
|
|
|
288
|
+ && StrUtil.isBlank(vo.getComprehensiveTime())
|
|
|
289
|
+ && vo.getSpecialScore() == null
|
|
|
290
|
+ && StrUtil.isBlank(vo.getSpecialTime());
|
|
|
291
|
+ }
|
|
|
292
|
+
|
|
|
293
|
+ /**
|
|
|
294
|
+ * 格式化年月为 yyyy-MM 格式(支持多种输入格式)
|
|
273
|
295
|
*/
|
|
274
|
|
- private String convertYearMonth(String yearMonth) {
|
|
|
296
|
+ private String formatYearMonth(String yearMonth) {
|
|
275
|
297
|
if (StrUtil.isBlank(yearMonth)) {
|
|
276
|
298
|
return yearMonth;
|
|
277
|
299
|
}
|
|
278
|
300
|
|
|
279
|
301
|
yearMonth = yearMonth.trim();
|
|
280
|
302
|
|
|
|
303
|
+ // 1. 尝试解析为数字(Excel日期序列号,如46082)
|
|
|
304
|
+ try {
|
|
|
305
|
+ double serialNumber = Double.parseDouble(yearMonth);
|
|
|
306
|
+ if (serialNumber > 1000 && serialNumber < 100000) {
|
|
|
307
|
+ Date date = DateUtil.getJavaDate(serialNumber);
|
|
|
308
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
|
|
|
309
|
+ return sdf.format(date);
|
|
|
310
|
+ }
|
|
|
311
|
+ } catch (NumberFormatException e) {
|
|
|
312
|
+ // 不是数字,继续其他解析方式
|
|
|
313
|
+ }
|
|
|
314
|
+
|
|
|
315
|
+ // 2. 处理中文格式:2026年3月、2026年03月等
|
|
281
|
316
|
if (yearMonth.contains("年") && yearMonth.contains("月")) {
|
|
282
|
317
|
yearMonth = yearMonth.replace("年", "-").replace("月", "");
|
|
283
|
318
|
}
|
|
284
|
319
|
|
|
|
320
|
+ // 3. 处理点号分隔:2026.03、2026.3等
|
|
285
|
321
|
if (yearMonth.contains(".")) {
|
|
286
|
322
|
yearMonth = yearMonth.replace(".", "-");
|
|
287
|
323
|
}
|
|
288
|
324
|
|
|
|
325
|
+ // 4. 处理斜杠分隔:2026/03、2026/3等
|
|
|
326
|
+ if (yearMonth.contains("/")) {
|
|
|
327
|
+ yearMonth = yearMonth.replace("/", "-");
|
|
|
328
|
+ }
|
|
|
329
|
+
|
|
|
330
|
+ // 5. 标准化月份格式
|
|
289
|
331
|
String[] parts = yearMonth.split("-");
|
|
290
|
|
- if (parts.length == 2) {
|
|
291
|
|
- String month = parts[1];
|
|
292
|
|
- if (month.length() == 1) {
|
|
293
|
|
- month = "0" + month;
|
|
|
332
|
+ if (parts.length >= 2) {
|
|
|
333
|
+ String year = parts[0].trim();
|
|
|
334
|
+ String month = parts[1].trim();
|
|
|
335
|
+
|
|
|
336
|
+ // 验证年份和月份是否为有效数字
|
|
|
337
|
+ if (year.matches("\\d{4}") && month.matches("\\d{1,2}")) {
|
|
|
338
|
+ int monthNum = Integer.parseInt(month);
|
|
|
339
|
+ if (monthNum >= 1 && monthNum <= 12) {
|
|
|
340
|
+ // 格式化月份为两位数
|
|
|
341
|
+ String formattedMonth = String.format("%02d", monthNum);
|
|
|
342
|
+ return year + "-" + formattedMonth;
|
|
|
343
|
+ }
|
|
294
|
344
|
}
|
|
295
|
|
- yearMonth = parts[0] + "-" + month;
|
|
296
|
345
|
}
|
|
297
|
346
|
|
|
|
347
|
+ // 如果无法解析,返回原始值
|
|
298
|
348
|
return yearMonth;
|
|
299
|
349
|
}
|
|
300
|
350
|
}
|