|
@@ -14,6 +14,7 @@ import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
@@ -56,6 +57,7 @@ public class AttendanceServiceImpl extends ServiceImpl<AttendanceMapper, Attenda
|
|
|
private AttendanceStaffService attendanceStaffService;
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public HttpRespMsg importAttendanceData(String month, MultipartFile file, HttpServletRequest request) {
|
|
|
HttpRespMsg msg=new HttpRespMsg();
|
|
|
try(InputStream inputStream= file.getInputStream()) {
|
|
@@ -159,21 +161,10 @@ public class AttendanceServiceImpl extends ServiceImpl<AttendanceMapper, Attenda
|
|
|
attendanceStaffService.refreshData(month);
|
|
|
msg.data=dataCount;
|
|
|
return msg;
|
|
|
- } catch (IOException e){
|
|
|
+ } catch (Exception e) { // 统一捕获所有异常
|
|
|
e.printStackTrace();
|
|
|
- //msg.setError("文件处理出错");
|
|
|
- msg.setError(MessageUtils.message("file.error"));
|
|
|
- return msg;
|
|
|
- } catch (InvalidFormatException e) {
|
|
|
- e.printStackTrace();
|
|
|
- //msg.setError("文件格式错误,如果安装了加密软件需要先解密再上传");
|
|
|
- msg.setError(MessageUtils.message("file.FormatErrorAndDecrypt"));
|
|
|
- return msg;
|
|
|
- } catch (EncryptedDocumentException e) {
|
|
|
- e.printStackTrace();
|
|
|
- //msg.setError("文件加密状态,需要先解除加密状态再上传");
|
|
|
- msg.setError(MessageUtils.message("file.encryption"));
|
|
|
- return msg;
|
|
|
+ msg.setError("导入失败: " + e.getMessage());
|
|
|
+ throw new RuntimeException(e); // 抛出运行时异常,触发回滚
|
|
|
}
|
|
|
}
|
|
|
|