Przeglądaj źródła

fix: 功能资源导入接口自测完成

huangjy 4 lat temu
rodzic
commit
fed4e3b937

+ 1 - 1
dcuc-auth-api/src/main/java/com/dragoninfo/dcuc/auth/power/facade/IAppFunInfoFacade.java

@@ -155,5 +155,5 @@ public interface IAppFunInfoFacade {
      * @return
      */
     @PostMapping(value = "/import")
-    ResponseStatus impExcel(String fileId);
+    ResponseStatus impExcel(@RequestParam("fileId")String fileId);
 }

+ 1 - 1
dcuc-auth-model/src/main/java/com/dragoninfo/dcuc/auth/auth/entity/AppFunInfo.java

@@ -92,7 +92,6 @@ public class AppFunInfo implements IdEntity<String> {
 	private String designSecureType;
 	//columns END
 
-		
 	public void setId(String value) {
 		this.id = value;
 	}
@@ -236,5 +235,6 @@ public class AppFunInfo implements IdEntity<String> {
 	public void setDesignSecureType(String designSecureType) {
 		this.designSecureType = designSecureType;
 	}
+
 }
 

+ 63 - 48
dcuc-auth-service/src/main/java/com/dragoninfo/dcuc/auth/auth/service/impl/AppFunInfoService.java

@@ -287,11 +287,13 @@ public class AppFunInfoService extends BaseService<AppFunInfo, String> implement
     @Override
     public ResponseStatus impExcel(String fileId) {
         try {
-            fileId = JsonUtils.parseObject(fileId).getString("fileId");
             DocContentDTO fileContent = uploadhandler.getFileContent(fileId);
             byte[] fileData = fileContent.getFileData();
             InputStream inputStream = new ByteArrayInputStream(fileData);
             List<AppFunInfo> list = loadInfo(inputStream);
+            for (AppFunInfo funInfo: list){
+                save(funInfo);
+            }
         }catch (IOException e) {
             return ResponseStatus.fail("300","导入文件类型错误");
         } catch (NumberFormatException e) {
@@ -314,6 +316,7 @@ public class AppFunInfoService extends BaseService<AppFunInfo, String> implement
         Workbook wb0 = new HSSFWorkbook(inputStream);
         //获取Excel文档中的第一个表单
         Sheet sht0 = wb0.getSheetAt(0);
+        List<String> codeList = new ArrayList<>();
         for (Row r : sht0) {
             if (r.getRowNum() == 0) {
                 checkRowTitle(r);
@@ -323,8 +326,11 @@ public class AppFunInfoService extends BaseService<AppFunInfo, String> implement
                 AppFunInfo entity = new AppFunInfo();
                 for (int i = 0; i < 8; i++) {
                     Cell cell = r.getCell(i);
+                    if (cell != null){
+                        r.getCell(i).setCellType(Cell.CELL_TYPE_STRING);
+                    }
                     checkCellData(cell, i, r.getRowNum());
-                    checkCellDataValid(cell, i, r.getRowNum(), entity);
+                    checkCellDataValid(cell, i, r.getRowNum(), entity,codeList);
                 }
                 entity.setCreateTime(new Date());
                 entity.setModifiedTime(new Date());
@@ -343,7 +349,7 @@ public class AppFunInfoService extends BaseService<AppFunInfo, String> implement
      * @param row
      * @param resource
      */
-    private void checkCellDataValid(Cell cell, int num, int row, AppFunInfo resource) {
+    private void checkCellDataValid(Cell cell, int num, int row, AppFunInfo resource, List<String> codeList) {
         if (cell == null)
             return;
         String value = cell.getStringCellValue();
@@ -351,42 +357,55 @@ public class AppFunInfoService extends BaseService<AppFunInfo, String> implement
             case 0:
                 ApplyInfo applyInfo = applyInfoFacade.getAppByCode(value);
                 if (applyInfo == null){
-                    throw new NumberFormatException("第" + (row + 1) + "行''所属应用系统编号''不存在!");
+                    throw new NumberFormatException("第" + (row + 1) + "行'所属应用系统编号'不存在!");
                 }
+
                 resource.setAppId(applyInfo.getId());
                 break;
             case 1:
                 if (value.length() > 40) {
-                    throw new NumberFormatException("第" + (row + 1) + "行''功能编号''长度大于40!");
+                    throw new NumberFormatException("第" + (row + 1) + "行'功能编号'长度大于40!");
+                }
+                AppFunInfo appFunInfo = getByAppAndFuncCode(resource.getAppId(), value);
+                if (appFunInfo != null){
+                    throw new NumberFormatException("第" + (row + 1) + "行'功能编号'已存在!");
+                }
+                if (codeList.contains(resource.getAppId() + value)){
+                    throw new NumberFormatException("第" + (row + 1) + "行'功能编号'重复!");
                 }
+                codeList.add(resource.getAppId() + value);
                 resource.setCode(value);
                 break;
             case 2:
                 if (value.length() > 80) {
-                    throw new NumberFormatException("第" + (row + 1) + "行''功能名称''长度大于80!");
+                    throw new NumberFormatException("第" + (row + 1) + "行'功能名称'长度大于80!");
                 }
                 resource.setName(value);
                 break;
             case 3:
-                AppFunInfo funInfo = appFunInfoBPO.findByCode(value);
-                if (funInfo == null){
-                    throw new NumberFormatException("第" + (row + 1) + "行''上级功能编号''不存在!");
+                if (StringUtils.isNotBlank(value)){
+                    AppFunInfo funInfo = appFunInfoBPO.findByCode(value);
+                    if (funInfo == null){
+                        throw new NumberFormatException("第" + (row + 1) + "行'上级功能编号'不存在!");
+                    }
+                    resource.setParentId(funInfo.getId());
                 }
-                resource.setParentId(funInfo.getId());
                 break;
             case 4:
-                String activeCode = null;
-                if (value.equals("停用")){
-                    activeCode = "0";
-                }
-                if (value.equals("启用")){
-                    activeCode = "1";
+                if (StringUtils.isNotBlank(value)){
+                    String activeCode = null;
+                    if (value.equals("停用")){
+                        activeCode = "0";
+                    }
+                    if (value.equals("启用")){
+                        activeCode = "1";
 
+                    }
+                    if (StringUtils.isBlank(activeCode)){
+                        throw new NumberFormatException("第" + (row + 1) + "行'在用状态'不存在!");
+                    }
+                    resource.setIsActive(activeCode);
                 }
-                if (StringUtils.isBlank(activeCode)){
-                    throw new NumberFormatException("第" + (row + 1) + "行''在用状态''不存在!");
-                }
-                resource.setIsActive(activeCode);
                 break;
             case 5:
                 String code = "";
@@ -396,21 +415,21 @@ public class AppFunInfoService extends BaseService<AppFunInfo, String> implement
                     }
                 }
                 if (StringUtils.isBlank(code)){
-                    throw new NumberFormatException("第" + (row + 1) + "行''功能使用场景代码''不存在!");
+                    throw new NumberFormatException("第" + (row + 1) + "行'功能使用场景代码'不存在!");
                 }
                 resource.setFunctionUsageScenarios(code);
                 break;
             case 6:
-                if (StringUtils.isNotBlank(value)){
-                    String secureTypeEnumCode = "";
-                    for (DesignSecureTypeEnum secureTypeEnum: DesignSecureTypeEnum.values()){
-                        if (value.equals(secureTypeEnum.getLabel())){
-                            secureTypeEnumCode = secureTypeEnum.getValue();
-                        }
+                String secureTypeEnumCode = "";
+                for (DesignSecureTypeEnum secureTypeEnum: DesignSecureTypeEnum.values()){
+                    if (value.equals(secureTypeEnum.getLabel())){
+                        secureTypeEnumCode = secureTypeEnum.getValue();
                     }
-                    resource.setDesignSecureType(secureTypeEnumCode);
                 }
-
+                if (StringUtils.isBlank(secureTypeEnumCode)){
+                    throw new NumberFormatException("第" + (row + 1) + "行'设计安全隐私类别'不存在!");
+                }
+                resource.setDesignSecureType(secureTypeEnumCode);
                 break;
             case 7:
                 resource.setRemark(value);
@@ -432,21 +451,17 @@ public class AppFunInfoService extends BaseService<AppFunInfo, String> implement
         if (!(cell == null || StringUtils.isBlank(cell.getStringCellValue()))) {
             return;
         }
-        switch (row) {
+        switch (i) {
             case 0:
-                throw new NumberFormatException("第" + (row + 1) + "行''所属应用系统编号''为空!");
+                throw new NumberFormatException("第" + (row + 1) + "行'所属应用系统编号'为空!");
             case 1:
-                throw new NumberFormatException("第" + (row + 1) + "行''功能编号''为空!");
+                throw new NumberFormatException("第" + (row + 1) + "行'功能编号'为空!");
             case 2:
-                throw new NumberFormatException("第" + (row + 1) + "行''功能名称''为空!");
-            case 3:
-                throw new NumberFormatException("第" + (row + 1) + "行''上级功能编号''为空!");
-            case 4:
-                throw new NumberFormatException("第" + (row + 1) + "行''在用状态''为空!");
+                throw new NumberFormatException("第" + (row + 1) + "行'功能名称'为空!");
             case 5:
-                throw new NumberFormatException("第" + (row + 1) + "行''功能使用场景代码''为空!");
-            case 7:
-                throw new NumberFormatException("第" + (row + 1) + "行''功能说明''为空!");
+                throw new NumberFormatException("第" + (row + 1) + "行'功能使用场景代码'为空!");
+            case 6:
+                throw new NumberFormatException("第" + (row + 1) + "行'设计安全隐私类别'为空!");
             default:
                 break;
         }
@@ -459,28 +474,28 @@ public class AppFunInfoService extends BaseService<AppFunInfo, String> implement
      */
     private static void checkRowTitle(Row r) {
         if (!r.getCell(0).getStringCellValue().equals("所属应用系统编号")) {
-            throw new NumberFormatException("缺少''所属应用系统编号''列!");
+            throw new NumberFormatException("缺少'所属应用系统编号'列!");
         }
         if (!r.getCell(1).getStringCellValue().equals("功能编号")) {
-            throw new NumberFormatException("缺少''功能编号''列!");
+            throw new NumberFormatException("缺少'功能编号'列!");
         }
         if (!r.getCell(2).getStringCellValue().equals("功能名称")) {
-            throw new NumberFormatException("缺少''功能名称''列!");
+            throw new NumberFormatException("缺少'功能名称'列!");
         }
         if (!r.getCell(3).getStringCellValue().equals("上级功能编号")) {
-            throw new NumberFormatException("缺少''上级功能编号''列!");
+            throw new NumberFormatException("缺少'上级功能编号'列!");
         }
         if (!r.getCell(4).getStringCellValue().equals("在用状态")) {
-            throw new NumberFormatException("缺少''在用状态''列!");
+            throw new NumberFormatException("缺少'在用状态'列!");
         }
         if (!r.getCell(5).getStringCellValue().equals("功能使用场景代码")) {
-            throw new NumberFormatException("缺少''功能使用场景代码''列!");
+            throw new NumberFormatException("缺少'功能使用场景代码'列!");
         }
         if (!r.getCell(6).getStringCellValue().equals("设计安全隐私类别")) {
-            throw new NumberFormatException("缺少''设计安全隐私类别''列!");
+            throw new NumberFormatException("缺少'设计安全隐私类别'列!");
         }
         if (!r.getCell(7).getStringCellValue().equals("功能说明")) {
-            throw new NumberFormatException("缺少''功能说明''列!");
+            throw new NumberFormatException("缺少'功能说明'列!");
         }
     }