Przeglądaj źródła

1.导入判断非空

wuhp 1 rok temu
rodzic
commit
6420d4abca

+ 48 - 36
src/main/java/com/ydtech/modules/fnc/service/impl/InsPlyIncomeServiceImpl.java

@@ -38,6 +38,7 @@ import com.ydtech.modules.inv.model.dto.*;
 import com.ydtech.modules.inv.model.excel.*;
 import com.ydtech.modules.inv.utils.CheckInsPlyComeUtils;
 import com.ydtech.modules.inv.utils.EasyExcelUtils;
+import com.ydtech.modules.inv.utils.ImportObjectUtils;
 import com.ydtech.modules.order.entity.BasePageResult;
 import com.ydtech.modules.order.entity.InsOrders;
 import com.ydtech.modules.order.entity.api.dajia.response.NVHLODR1001Response;
@@ -3896,13 +3897,15 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
             //车险手续费
             if(cxsxfList!=null && cxsxfList.size()>0){
                 for(AddTypeCXSXFExcel dto : cxsxfList){
-                    index++;
-                    Map<String, Object> map = CheckInsPlyComeUtils.checkDataDto1(dto);
-                    if(!"".equals(map.get("msg"))){
-                        throw new SystemException("第" + index + "行数据" + map.get("msg").toString());
-                    }else{
-                        InsPlyIncome insPlyIncome = (InsPlyIncome)map.get("dto");
-                        list.add(insPlyIncome);
+                    if(!ImportObjectUtils.allNull(dto)){
+                        index++;
+                        Map<String, Object> map = CheckInsPlyComeUtils.checkDataDto1(dto);
+                        if(!"".equals(map.get("msg"))){
+                            throw new SystemException("第" + index + "行数据" + map.get("msg").toString());
+                        }else{
+                            InsPlyIncome insPlyIncome = (InsPlyIncome)map.get("dto");
+                            list.add(insPlyIncome);
+                        }
                     }
                 }
             }
@@ -3911,13 +3914,15 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
             //车险跟单
             if(cxgdList!=null && cxgdList.size()>0){
                 for(AddTypeCXGDExcel dto : cxgdList){
-                    index++;
-                    Map<String, Object> map = CheckInsPlyComeUtils.checkDataDto2(dto);
-                    if(!"".equals(map.get("msg"))){
-                        throw new SystemException("第" + index + "行数据" + map.get("msg").toString());
-                    }else{
-                        InsPlyIncome insPlyIncome = (InsPlyIncome)map.get("dto");
-                        list.add(insPlyIncome);
+                    if(!ImportObjectUtils.allNull(dto)) {
+                        index++;
+                        Map<String, Object> map = CheckInsPlyComeUtils.checkDataDto2(dto);
+                        if (!"".equals(map.get("msg"))) {
+                            throw new SystemException("第" + index + "行数据" + map.get("msg").toString());
+                        } else {
+                            InsPlyIncome insPlyIncome = (InsPlyIncome) map.get("dto");
+                            list.add(insPlyIncome);
+                        }
                     }
                 }
             }
@@ -3925,13 +3930,15 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
             int index=1;
             if(fcsxfList!=null && fcsxfList.size()>0){
                 for(AddTypeFCSXFExcel dto : fcsxfList){
-                    index++;
-                    Map<String, Object> map = CheckInsPlyComeUtils.checkDataDto3(dto);
-                    if(!"".equals(map.get("msg"))){
-                        throw new SystemException("第" + index + "行数据" + map.get("msg").toString());
-                    }else{
-                        InsPlyIncome insPlyIncome = (InsPlyIncome)map.get("dto");
-                        list.add(insPlyIncome);
+                    if(!ImportObjectUtils.allNull(dto)) {
+                        index++;
+                        Map<String, Object> map = CheckInsPlyComeUtils.checkDataDto3(dto);
+                        if (!"".equals(map.get("msg"))) {
+                            throw new SystemException("第" + index + "行数据" + map.get("msg").toString());
+                        } else {
+                            InsPlyIncome insPlyIncome = (InsPlyIncome) map.get("dto");
+                            list.add(insPlyIncome);
+                        }
                     }
                 }
             }
@@ -3939,13 +3946,16 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
             int index=1;
             if(fcgdList!=null && fcgdList.size()>0){
                 for(AddTypeFCGDExcel dto : fcgdList){
-                    index++;
-                    Map<String, Object> map = CheckInsPlyComeUtils.checkDataDto4(dto);
-                    if(!"".equals(map.get("msg"))){
-                        throw new SystemException("第" + index + "行数据" + map.get("msg").toString());
-                    }else{
-                        InsPlyIncome insPlyIncome = (InsPlyIncome)map.get("dto");
-                        list.add(insPlyIncome);
+                    if(!ImportObjectUtils.allNull(dto)) {
+
+                        index++;
+                        Map<String, Object> map = CheckInsPlyComeUtils.checkDataDto4(dto);
+                        if (!"".equals(map.get("msg"))) {
+                            throw new SystemException("第" + index + "行数据" + map.get("msg").toString());
+                        } else {
+                            InsPlyIncome insPlyIncome = (InsPlyIncome) map.get("dto");
+                            list.add(insPlyIncome);
+                        }
                     }
                 }
             }
@@ -3953,14 +3963,16 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
         else if("5".equals(type)){
             int index=1;
             if(ptjsList!=null && ptjsList.size()>0){
-                for(AddTypePTJSExcel dto : ptjsList){
-                    index++;
-                    Map<String, Object> map = CheckInsPlyComeUtils.checkDataDto5(dto);
-                    if(!"".equals(map.get("msg"))){
-                        throw new SystemException("第" + index + "行数据" + map.get("msg").toString());
-                    }else{
-                        InsPlyIncome insPlyIncome = (InsPlyIncome)map.get("dto");
-                        list.add(insPlyIncome);
+                for(AddTypePTJSExcel dto : ptjsList) {
+                    if (!ImportObjectUtils.allNull(dto)) {
+                        index++;
+                        Map<String, Object> map = CheckInsPlyComeUtils.checkDataDto5(dto);
+                        if (!"".equals(map.get("msg"))) {
+                            throw new SystemException("第" + index + "行数据" + map.get("msg").toString());
+                        } else {
+                            InsPlyIncome insPlyIncome = (InsPlyIncome) map.get("dto");
+                            list.add(insPlyIncome);
+                        }
                     }
                 }
             }

+ 21 - 0
src/main/java/com/ydtech/modules/inv/utils/ImportObjectUtils.java

@@ -0,0 +1,21 @@
+package com.ydtech.modules.inv.utils;
+import java.lang.reflect.Field;
+public class ImportObjectUtils {
+    public static boolean allNull(Object obj)  {
+        if (obj == null) {
+            return true;
+        }
+        Field[] fields = obj.getClass().getDeclaredFields();
+        for (Field field : fields) {
+            field.setAccessible(true); // 使私有属性也可以访问
+            try {
+                if (field.get(obj) != null) {
+                    return false;
+                }
+            } catch (IllegalAccessException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        return true;
+    }
+}