Browse Source

白名单导入调整

dzx 4 months ago
parent
commit
2481d2fe12

+ 27 - 4
src/main/java/com/xjrsoft/module/base/controller/WhitelistManagementController.java

@@ -33,7 +33,10 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.validation.Valid;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.CompletableFuture;
 
 /**
@@ -122,10 +125,30 @@ public class WhitelistManagementController {
 
     @PostMapping("/import")
     @ApiOperation(value = "导入")
-    public RT<Boolean> importData(@RequestParam MultipartFile file) throws IOException {
-        List<WhitelistManagementPageVo> savedDataList = EasyExcel.read(file.getInputStream()).headRowNumber(3).head(WhitelistManagementPageVo.class).sheet().doReadSync();
-        Boolean b = whitelistManagementService.importData(savedDataList);
-        return RT.ok(b);
+    public RT<List<Map<String, String>>> importData(@RequestParam MultipartFile file) throws IOException {
+        List<Map<Integer, Object>> excelDataList = EasyExcel.read(file.getInputStream()).sheet().headRowNumber(3).doReadSync();
+        List<Map<Integer, Object>> errorList = whitelistManagementService.importData(excelDataList);
+        List<Map<String, String>> result = new ArrayList<>();
+
+        for (Map<Integer, Object> objectMap : errorList) {
+            Map<String, String> object = new LinkedHashMap<>();
+            List<String> errorMsg = new ArrayList<>();
+            if(objectMap.get(0) == null){
+                errorMsg.add("姓名未填写");
+            }
+            if(objectMap.get(1) == null){
+                errorMsg.add("身份证未填写");
+            }
+            if(objectMap.get(2) == null){
+                errorMsg.add("手机号未填写");
+            }
+            object.put("姓名", objectMap.get(0)==null?"":objectMap.get(0).toString());
+            object.put("身份证", objectMap.get(1)==null?"":objectMap.get(1).toString());
+            object.put("手机号", objectMap.get(13)==null?"":objectMap.get(13).toString());
+            object.put("错误信息", errorMsg.toString().replace("[","").replace("]", ""));
+            result.add(object);
+        }
+        return RT.ok(result);
     }
 
 }

+ 2 - 1
src/main/java/com/xjrsoft/module/base/service/IWhitelistManagementService.java

@@ -8,6 +8,7 @@ import com.xjrsoft.module.base.entity.WhitelistManagement;
 import com.xjrsoft.module.base.vo.WhitelistManagementPageVo;
 
 import java.util.List;
+import java.util.Map;
 
 /**
 * @title: 白名单管理
@@ -36,5 +37,5 @@ public interface IWhitelistManagementService extends MPJBaseService<WhitelistMan
      */
     void loadCaches();
 
-    Boolean importData(List<WhitelistManagementPageVo> savedDataList);
+    List<Map<Integer, Object>> importData(List<Map<Integer, Object>> savedDataList);
 }

+ 28 - 24
src/main/java/com/xjrsoft/module/base/service/impl/WhitelistManagementServiceImpl.java

@@ -110,32 +110,36 @@ public class WhitelistManagementServiceImpl extends MPJBaseServiceImpl<Whitelist
     }
 
     @Override
-    public Boolean importData(List<WhitelistManagementPageVo> savedDataList) {
+    public List<Map<Integer, Object>> importData(List<Map<Integer, Object>> savedDataList) {
+        List<Map<Integer, Object>> errorList = new ArrayList<>();
+
         List<WhitelistManagement> whitelistManagements = new ArrayList<>();
         List<String> errorLogs = new ArrayList<>();
 
-        for (WhitelistManagementPageVo vo : savedDataList) {
-            try {
-                if (this.checkExist(vo.getCredentialNumber())) continue;
-
-                String name = this.GetName(vo.getName());
-                String credentialNumber = this.GetCredentialNumber(vo.getCredentialNumber());
-                Long userId = this.getUserId(credentialNumber);
-                String phone = this.GetPhone(vo.getPhone().toString());
-
-                if (!name.isEmpty() && !credentialNumber.isEmpty() && !phone.isEmpty()) {
-                    WhitelistManagement whitelistManagement = new WhitelistManagement();
-                    whitelistManagement.setCreateDate(new Date());
-                    whitelistManagement.setDeleteMark(0);
-                    whitelistManagement.setEnabledMark(0);
-                    whitelistManagement.setUserId(userId);
-                    whitelistManagement.setName(name);
-                    whitelistManagement.setCredentialNumber(credentialNumber);
-                    whitelistManagement.setPhone(phone);
-                    whitelistManagements.add(whitelistManagement);
-                }
-            } catch (Exception e) {
-                errorLogs.add(String.format("[意外错误(检查输入的是否正确且存在,输入错误可能返回 null)] 姓名: %s, 身份证: %s, 手机号: %s - 错误信息:%s", vo.getName(), vo.getCredentialNumber(), vo.getPhone(), e.getMessage()));
+        for (Map<Integer, Object> vo : savedDataList) {
+            if(vo.get(0) == null || vo.get(1) == null || vo.get(2) == null){
+                errorList.add(vo);
+                continue;
+            }
+            if (this.checkExist(vo.get(1).toString())) {
+                continue;
+            }
+
+            String name = this.GetName(vo.get(0).toString());
+            String credentialNumber = this.GetCredentialNumber(vo.get(1).toString());
+            Long userId = this.getUserId(credentialNumber);
+            String phone = this.GetPhone(vo.get(2).toString());
+
+            if (!name.isEmpty() && !credentialNumber.isEmpty() && !phone.isEmpty()) {
+                WhitelistManagement whitelistManagement = new WhitelistManagement();
+                whitelistManagement.setCreateDate(new Date());
+                whitelistManagement.setDeleteMark(0);
+                whitelistManagement.setEnabledMark(0);
+                whitelistManagement.setUserId(userId);
+                whitelistManagement.setName(name);
+                whitelistManagement.setCredentialNumber(credentialNumber);
+                whitelistManagement.setPhone(phone);
+                whitelistManagements.add(whitelistManagement);
             }
         }
 
@@ -150,6 +154,6 @@ public class WhitelistManagementServiceImpl extends MPJBaseServiceImpl<Whitelist
             throw new MyException(detailedMessage);
         }
 
-        return result;
+        return errorList;
     }
 }