From 79d5402492a82421b94fcbf90be01adbf3c8e0e5 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期四, 11 十二月 2025 11:51:06 +0800
Subject: [PATCH] bug修改

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TLargeSocialWorkerController.java |   30 ++++++++++++++++++++++++------
 1 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TLargeSocialWorkerController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TLargeSocialWorkerController.java
index 61d2617..d982c12 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TLargeSocialWorkerController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TLargeSocialWorkerController.java
@@ -5,6 +5,8 @@
 import cn.afterturn.easypoi.excel.ExcelImportUtil;
 import cn.afterturn.easypoi.excel.entity.ExportParams;
 import cn.afterturn.easypoi.excel.entity.ImportParams;
+import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
+import cn.hutool.core.io.resource.ClassPathResource;
 import cn.hutool.json.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.ruoyi.common.annotation.Log;
@@ -38,7 +40,9 @@
 import java.io.InputStream;
 import java.net.URLEncoder;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -138,14 +142,16 @@
     @ApiOperation(value = "社会工作者信息导入模板下载")
     @GetMapping("/import-template")
     public void importTemplate() {
-        List<LargeSocialWorkerImport> largeLargeSocialWorkerImports = new ArrayList<>();
-        LargeSocialWorkerImport largeLargeSocialWorkerImport = new LargeSocialWorkerImport();
-        largeLargeSocialWorkerImports.add(largeLargeSocialWorkerImport);
-        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), LargeSocialWorkerImport.class, largeLargeSocialWorkerImports);
+        Map<String, Object> result = new HashMap<>();
+        ClassPathResource classPathResource = new ClassPathResource("template/社会工作者导入模板.xlsx");
+        TemplateExportParams params = new TemplateExportParams(classPathResource.getPath());
+        Workbook workbook = ExcelExportUtil.exportExcel(params, result);
         HttpServletResponse response = WebUtils.response();
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding("utf-8");
         ServletOutputStream outputStream = null;
         try {
-            String fileName = URLEncoder.encode("社会工作者信息导入模板.xls", "utf-8");
+            String fileName = URLEncoder.encode("社会工作者信息导入模板.xlsx", "utf-8");
             response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
             response.setHeader("content-Type", "application/vnd.ms-excel");
             response.setHeader("Pragma", "no-cache");
@@ -196,38 +202,47 @@
         for (LargeSocialWorkerImport largeSocialWorkerImport : largeSocialWorkerImports) {
             if (!StringUtils.hasLength(largeSocialWorkerImport.getUserName())){
                 result.append("第"+i+"行:[", "姓名"+"]不能为空");
+                i++;
                 continue;
             }
             if (!StringUtils.hasLength(largeSocialWorkerImport.getUserSexStr())){
                 result.append("第"+i+"行:[", "性别"+"]不能为空");
+                i++;
                 continue;
             }
             if (!StringUtils.hasLength(largeSocialWorkerImport.getBirthDateStr())){
                 result.append("第"+i+"行:[", "出生日期"+"]不能为空");
+                i++;
                 continue;
             }
             if (!StringUtils.hasLength(largeSocialWorkerImport.getEducationalLevel())){
                 result.append("第"+i+"行:[", "文化程度"+"]不能为空");
+                i++;
                 continue;
             }
             if (!StringUtils.hasLength(largeSocialWorkerImport.getPoliticalStatus())){
                 result.append("第"+i+"行:[", "政治面貌"+"]不能为空");
+                i++;
                 continue;
             }
             if (!StringUtils.hasLength(largeSocialWorkerImport.getContactNumber())){
                 result.append("第"+i+"行:[", "联系电话"+"]不能为空");
+                i++;
                 continue;
             }
-            if (largeSocialWorkerImport.getContactNumber().matches("^1[3-9]\\\\d{9}$")){
+            if (!largeSocialWorkerImport.getContactNumber().matches("^$|^1[3-9]\\d{9}$")){
                 result.append("第"+i+"行:[", "联系电话"+"]格式不正确");
+                i++;
                 continue;
             }
             if (!StringUtils.hasLength(largeSocialWorkerImport.getEmployerPosition())){
                 result.append("第"+i+"行:[", "工作单位及职务"+"]不能为空");
+                i++;
                 continue;
             }
             if (!StringUtils.hasLength(largeSocialWorkerImport.getQualificationLevelStr())){
                 result.append("第"+i+"行:[", "职业资格等级"+"]不能为空");
+                i++;
                 continue;
             }
             TLargeSocialWorker largeSocialWorker = new TLargeSocialWorker();
@@ -242,6 +257,7 @@
                     break;
                 default:
                     result.append("第"+i+"行:[", "性别"+"]格式错误");
+                    i++;
                     continue;
             }
 
@@ -257,12 +273,14 @@
                     break;
                 default:
                     result.append("第"+i+"行:[", "职业资格等级"+"]格式错误");
+                    i++;
                     continue;
             }
             try{
                 largeSocialWorker.setBirthDate(DateUtils.stringToLocalDate(largeSocialWorkerImport.getBirthDateStr()));
             }catch (Exception e){
                 result.append("第"+i+"行:[", "出生日期"+"]格式错误");
+                i++;
                 continue;
             }
             largeSocialWorkers.add(largeSocialWorker);

--
Gitblit v1.7.1