Quellcode durchsuchen

通信设备导入

jichaobo vor 3 Jahren
Ursprung
Commit
19707ffd5a

+ 10 - 3
fiveep-service/src/main/java/com/bizmatics/service/impl/DeviceServiceImpl.java

@@ -33,6 +33,8 @@ import com.bizmatics.service.vo.DeviceImportVo;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
@@ -475,11 +477,13 @@ public class DeviceServiceImpl extends AbstractCrudService<DeviceMapper, Device>
     }
 
 
+    @Transactional
     @Override
     public void deviceImport(MultipartFile multipartFile) {
         SysUser user = SecurityUtils.getLoginUser().getUser();
         ImportParams params = new ImportParams();
         params.setHeadRows(1);
+        String err="文件导入失败";
         try {
             List<DeviceImportVo> deviceImportVos = ExcelImportUtil.importExcel(multipartFile.getInputStream(),
                     DeviceImportVo.class, params);
@@ -501,15 +505,18 @@ public class DeviceServiceImpl extends AbstractCrudService<DeviceMapper, Device>
                         deviceStatus.setSiteId(siteId);
                         deviceStatusService.save(deviceStatus);
                     }catch (Exception e){
-                        throw  new BusinessException("文件导入失败,第"+rot+"行数据导入失败");
+                        err="文件导入失败,第"+rot+"行数据导入失败";
+//                        throw  new BusinessException("文件导入失败,第"+rot+"行数据导入失败");
                     }
                     rot++;
                 }
             }else {
-                throw new BusinessException("文件不能为空");
+                err="文件不能为空";
+//                throw new BusinessException("文件不能为空");
             }
         }catch (Exception e){
-            throw  new BusinessException("文件导入失败"+e.getMessage());
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            throw  new BusinessException(err);
         }
     }