ezhizao_zx 1 éve
szülő
commit
853a5bbee4

+ 18 - 0
src/main/java/cn/ezhizao/common/utils/poi/ExcelUtil.java

@@ -1754,4 +1754,22 @@ public class ExcelUtil<T>
         }
         return method;
     }
+
+    //读取表头
+    public List<String> readExcelHeaders(InputStream inputStream) throws IOException {
+        List<String> headers = new ArrayList<>();
+
+        Workbook workbook = WorkbookFactory.create(inputStream);
+        Sheet sheet = workbook.getSheetAt(0); // Assuming the header is in the first row
+
+        Row headerRow = sheet.getRow(0);
+
+        Iterator<Cell> cellIterator = headerRow.cellIterator();
+        while (cellIterator.hasNext()) {
+            Cell cell = cellIterator.next();
+            headers.add(cell.getStringCellValue());
+        }
+
+        return headers;
+    }
 }

+ 14 - 0
src/main/java/cn/ezhizao/project/business/housingFund/controller/BizHousingFundConfirmController.java

@@ -46,6 +46,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.StringWriter;
 import java.io.Writer;
+import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
@@ -396,6 +397,19 @@ public class BizHousingFundConfirmController extends BaseController {
     {
         ExcelUtil<BizHousingFundConfirmDetailEmployee> util = new ExcelUtil<>(BizHousingFundConfirmDetailEmployee.class);
         List<BizHousingFundConfirmDetailEmployee> detailList = util.importExcel(file.getInputStream());
+
+        // 获取 入Excel 表头字段
+        List<String> excelHeaders = util.readExcelHeaders(file.getInputStream());
+        // 获取实体类字段
+        Field[] entityFields = BizHousingFundConfirmDetailEmployee.class.getDeclaredFields();
+        //获取导入表头
+        List<String> entityFieldNames = Arrays.stream(entityFields)
+                .map(Field::getName)
+                .collect(Collectors.toList());
+        //如果不存在模板中的字段,返回错误
+        if (!excelHeaders.containsAll(entityFieldNames)) {
+            return error("导入数据与模板不匹配!");
+        }
         String message=housingFundConfirmService.importSalary(detailList,year,month,getTenantId()==null?0:getTenantId());
         return success(message);
     }

+ 2 - 2
src/main/java/cn/ezhizao/project/business/housingFund/service/impl/BizHousingFundConfirmServiceImpl.java

@@ -60,7 +60,7 @@ public class BizHousingFundConfirmServiceImpl extends ServiceImpl<BizHousingFund
         int failureNum = 0;
         StringBuilder successMsg = new StringBuilder();
         StringBuilder failureMsg = new StringBuilder();
-        //获取工资信息
+        //获取信息
         for(BizHousingFundConfirmDetailEmployee l : detailList){
             BizHousingFundConfirm housingFundConfirm=new BizHousingFundConfirm();
             housingFundConfirm.setCompanyName(l.getCompanyName());
@@ -78,7 +78,7 @@ public class BizHousingFundConfirmServiceImpl extends ServiceImpl<BizHousingFund
                 continue;
             }
             housingFundConfirm=list.get(0);
-            //获取工资明细
+            //获取明细
             BizHousingFundConfirmDetail detail=new BizHousingFundConfirmDetail();
             detail.setHousingFundConfirmId(housingFundConfirm.getId());
             detail.setMonth(month);

+ 14 - 0
src/main/java/cn/ezhizao/project/business/salary/controller/BizFinancialSalaryController.java

@@ -4,6 +4,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.StringWriter;
 import java.io.Writer;
+import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.sql.Timestamp;
@@ -204,6 +205,19 @@ public class BizFinancialSalaryController extends BaseController {
     {
         ExcelUtil<BizFinancialSalaryDetailEmployee> util = new ExcelUtil<>(BizFinancialSalaryDetailEmployee.class);
         List<BizFinancialSalaryDetailEmployee> detailList = util.importExcel(file.getInputStream());
+
+        // 获取 入Excel 表头字段
+        List<String> excelHeaders = util.readExcelHeaders(file.getInputStream());
+        // 获取实体类字段
+        Field[] entityFields = BizFinancialSalaryDetailEmployee.class.getDeclaredFields();
+        //获取导入表头
+        List<String> entityFieldNames = Arrays.stream(entityFields)
+                .map(Field::getName)
+                .collect(Collectors.toList());
+        //如果不存在模板中的字段,返回错误
+        if (!excelHeaders.containsAll(entityFieldNames)) {
+            return error("导入数据与模板不匹配!");
+        }
         String message=bizFinancialSalaryService.importSalary(detailList,year,month,getTenantId()==null?0:getTenantId(),0);
         return success(message);
     }

+ 16 - 0
src/main/java/cn/ezhizao/project/business/salary/controller/BizFinancialSalaryZeroController.java

@@ -36,8 +36,10 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
+import java.lang.reflect.Field;
 import java.sql.Timestamp;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -102,6 +104,20 @@ public class BizFinancialSalaryZeroController extends BaseController {
     {
         ExcelUtil<BizFinancialSalaryDetailEmployee> util = new ExcelUtil<>(BizFinancialSalaryDetailEmployee.class);
         List<BizFinancialSalaryDetailEmployee> detailList = util.importExcel(file.getInputStream());
+
+        // 获取 入Excel 表头字段
+        List<String> excelHeaders = util.readExcelHeaders(file.getInputStream());
+        // 获取实体类字段
+        Field[] entityFields = BizFinancialSalaryDetailEmployee.class.getDeclaredFields();
+        //获取导入表头
+        List<String> entityFieldNames = Arrays.stream(entityFields)
+                .map(Field::getName)
+                .collect(Collectors.toList());
+        //如果不存在模板中的字段,返回错误
+        if (!excelHeaders.containsAll(entityFieldNames)) {
+            return error("导入数据与模板不匹配!");
+        }
+
         String message=bizFinancialSalaryService.importSalary(detailList,year,month,getTenantId()==null?0:getTenantId(),1);
         return success(message);
     }

+ 15 - 0
src/main/java/cn/ezhizao/project/business/socialSecurity/controller/SocialSecurityConfirmController.java

@@ -49,6 +49,7 @@ import java.io.IOException;
 import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
+import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.net.URLEncoder;
@@ -287,6 +288,20 @@ public class SocialSecurityConfirmController extends BaseController {
     {
         ExcelUtil<BizSocialSecurityConfirmDetailEmployee> util = new ExcelUtil<>(BizSocialSecurityConfirmDetailEmployee.class);
         List<BizSocialSecurityConfirmDetailEmployee> detailList = util.importExcel(file.getInputStream());
+
+        // 获取 入Excel 表头字段
+        List<String> excelHeaders = util.readExcelHeaders(file.getInputStream());
+        // 获取实体类字段
+        Field[] entityFields = BizSocialSecurityConfirmDetailEmployee.class.getDeclaredFields();
+        //获取导入表头
+        List<String> entityFieldNames = Arrays.stream(entityFields)
+                .map(Field::getName)
+                .collect(Collectors.toList());
+        //如果不存在模板中的字段,返回错误
+        if (!excelHeaders.containsAll(entityFieldNames)) {
+            return error("导入数据与模板不匹配!");
+        }
+
         String message=socialSecurityConfirmService.importSalary(detailList,year,month,getTenantId()==null?0:getTenantId());
         return success(message);
     }