From 4fbbc31a642e32631e90b894c0fabc316068f44c Mon Sep 17 00:00:00 2001 From: sunyugang Date: Tue, 5 Aug 2025 09:28:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=BC=E5=85=A5=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dw/controller/CjStudentController.java | 4 +- .../dw/service/impl/CjStudentServiceImpl.java | 118 ++++++++++++------ .../resources/mapper/dw/CjStudentMapper.xml | 2 + 3 files changed, 84 insertions(+), 40 deletions(-) diff --git a/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/CjStudentController.java b/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/CjStudentController.java index f80bdfa..5ca9adc 100644 --- a/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/CjStudentController.java +++ b/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/CjStudentController.java @@ -146,7 +146,9 @@ public class CjStudentController extends BaseController public AjaxResult importData(MultipartFile file) { int successNum = cjStudentService.importData(file); if (successNum > 0) { - return AjaxResult.success("导入成功"); + return AjaxResult.success("成功导入" + successNum + "条数据"); + }else if (successNum == 0){ + return AjaxResult.success("导入数据量为0,请检查导入的Excel是否与模板相同"); }else { return AjaxResult.error("导入失败,请检查信息采集内容是否正确"); } diff --git a/ruoyi-dw/src/main/java/com/ruoyi/dw/service/impl/CjStudentServiceImpl.java b/ruoyi-dw/src/main/java/com/ruoyi/dw/service/impl/CjStudentServiceImpl.java index 26c35f7..c2f6e71 100644 --- a/ruoyi-dw/src/main/java/com/ruoyi/dw/service/impl/CjStudentServiceImpl.java +++ b/ruoyi-dw/src/main/java/com/ruoyi/dw/service/impl/CjStudentServiceImpl.java @@ -6,6 +6,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import com.ruoyi.common.core.redis.RedisCache; +import com.ruoyi.common.utils.StringUtils; import org.apache.poi.ss.usermodel.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -214,6 +215,7 @@ public class CjStudentServiceImpl implements ICjStudentService Workbook workbook = WorkbookFactory.create(file.getInputStream()); Sheet sheet = workbook.getSheetAt(0); int rows = sheet.getLastRowNum(); + int j = 0; for (int i = 2; i <= rows; i++) { Row row = sheet.getRow(i); if (row == null) { @@ -222,6 +224,9 @@ public class CjStudentServiceImpl implements ICjStudentService Cell xhCell = row.getCell(3); xhCell.setCellType(CellType.STRING); String xh = xhCell.getStringCellValue().trim(); + if (!StringUtils.isNumeric(xh)){ + continue; + } boolean isInsert = false; CjStudent cjStudent = cjStudentMapper.selectCjStudentByXh(xh); if (cjStudent == null){ @@ -229,21 +234,31 @@ public class CjStudentServiceImpl implements ICjStudentService isInsert = true; } Cell xmCell = row.getCell(1); - xmCell.setCellType(CellType.STRING); - cjStudent.setXm(xmCell.getStringCellValue().trim()); + if (xmCell != null) { + xmCell.setCellType(CellType.STRING); + cjStudent.setXm(xmCell.getStringCellValue().trim()); + } Cell xbCell = row.getCell(2); - xbCell.setCellType(CellType.STRING); - cjStudent.setXb(xbCell.getStringCellValue().trim()); + if (xbCell != null) { + xbCell.setCellType(CellType.STRING); + cjStudent.setXb(xbCell.getStringCellValue().trim()); + } cjStudent.setXh(xh); Cell xyCell = row.getCell(4); - xyCell.setCellType(CellType.STRING); - cjStudent.setXy(xyCell.getStringCellValue().trim()); + if (xyCell != null) { + xyCell.setCellType(CellType.STRING); + cjStudent.setXy(xyCell.getStringCellValue().trim()); + } Cell zyCell = row.getCell(5); - zyCell.setCellType(CellType.STRING); - cjStudent.setZy(zyCell.getStringCellValue().trim()); + if (zyCell != null) { + zyCell.setCellType(CellType.STRING); + cjStudent.setZy(zyCell.getStringCellValue().trim()); + } Cell bjCell = row.getCell(6); - bjCell.setCellType(CellType.STRING); - cjStudent.setBj(bjCell.getStringCellValue().trim()); + if (bjCell != null) { + bjCell.setCellType(CellType.STRING); + cjStudent.setBj(bjCell.getStringCellValue().trim()); + } Cell bybfCell = row.getCell(7); bybfCell.setCellType(CellType.STRING); try { @@ -253,55 +268,80 @@ public class CjStudentServiceImpl implements ICjStudentService cjStudent.setBynf(null); } Cell zgxlCell = row.getCell(8); - zgxlCell.setCellType(CellType.STRING); - cjStudent.setZgyl(zgxlCell.getStringCellValue().trim()); + if (zgxlCell != null) { + zgxlCell.setCellType(CellType.STRING); + cjStudent.setZgyl(zgxlCell.getStringCellValue().trim()); + } Cell gzdwCell = row.getCell(9); - gzdwCell.setCellType(CellType.STRING); - cjStudent.setGzdw(gzdwCell.getStringCellValue().trim()); + if (gzdwCell != null) { + gzdwCell.setCellType(CellType.STRING); + cjStudent.setGzdw(gzdwCell.getStringCellValue().trim()); + } Cell dwxzCell = row.getCell(10); - dwxzCell.setCellType(CellType.STRING); - cjStudent.setDwxz(dwxzCell.getStringCellValue().trim()); + if (dwxzCell != null) { + dwxzCell.setCellType(CellType.STRING); + cjStudent.setDwxz(dwxzCell.getStringCellValue().trim()); + } Cell dwdzCell = row.getCell(11); - dwdzCell.setCellType(CellType.STRING); - cjStudent.setDwdz(dwdzCell.getStringCellValue().trim()); + if (dwdzCell != null) { + dwdzCell.setCellType(CellType.STRING); + cjStudent.setDwdz(dwdzCell.getStringCellValue().trim()); + } Cell czdCell = row.getCell(12); - czdCell.setCellType(CellType.STRING); - String czd = czdCell.getStringCellValue().trim(); - Map pac = extractProvinceAndCity(czd); - if (pac != null){ - cjStudent.setSydsh(pac.get("province")); - cjStudent.setSydshi(pac.get("city")); + if (czdCell != null) { + czdCell.setCellType(CellType.STRING); + String czd = czdCell.getStringCellValue().trim(); + Map pac = extractProvinceAndCity(czd); + if (pac != null){ + cjStudent.setSydsh(pac.get("province")); + cjStudent.setSydshi(pac.get("city")); + } } Cell zwjbCell = row.getCell(13); - zwjbCell.setCellType(CellType.STRING); - cjStudent.setZwjb(zwjbCell.getStringCellValue().trim()); + if (zwjbCell != null) { + zwjbCell.setCellType(CellType.STRING); + cjStudent.setZwjb(zwjbCell.getStringCellValue().trim()); + } Cell shjzCell = row.getCell(14); - shjzCell.setCellType(CellType.STRING); - cjStudent.setShjz(shjzCell.getStringCellValue().trim()); + if (shjzCell != null) { + shjzCell.setCellType(CellType.STRING); + cjStudent.setShjz(shjzCell.getStringCellValue().trim()); + } Cell dbryCell = row.getCell(15); - dbryCell.setCellType(CellType.STRING); - cjStudent.setDbry(dbryCell.getStringCellValue().trim()); + if (dbryCell != null) { + dbryCell.setCellType(CellType.STRING); + cjStudent.setDbry(dbryCell.getStringCellValue().trim()); + } Cell rysfzsCell = row.getCell(16); - rysfzsCell.setCellType(CellType.STRING); - String rysfzs = rysfzsCell.getStringCellValue().trim(); - if ("是".equals(rysfzs)){ - cjStudent.setRysfzs(1L); + if (rysfzsCell != null) { + rysfzsCell.setCellType(CellType.STRING); + String rysfzs = rysfzsCell.getStringCellValue().trim(); + if ("是".equals(rysfzs)){ + cjStudent.setRysfzs(1L); + }else { + cjStudent.setRysfzs(0L); + } }else { cjStudent.setRysfzs(0L); } Cell sjCell = row.getCell(17); - sjCell.setCellType(CellType.STRING); - cjStudent.setSj(sjCell.getStringCellValue()); + if (sjCell != null) { + sjCell.setCellType(CellType.STRING); + cjStudent.setSj(sjCell.getStringCellValue()); + } Cell yxCell = row.getCell(18); - yxCell.setCellType(CellType.STRING); - cjStudent.setYx(yxCell.getStringCellValue().trim()); + if (yxCell != null) { + yxCell.setCellType(CellType.STRING); + cjStudent.setYx(yxCell.getStringCellValue().trim()); + } cjStudent.setSfqr(1L); if (isInsert) cjStudentMapper.insertCjStudent(cjStudent); else cjStudentMapper.updateCjStudent(cjStudent); + j++; } - return rows-2; + return j; }catch (Exception e) { return -1; } diff --git a/ruoyi-dw/src/main/resources/mapper/dw/CjStudentMapper.xml b/ruoyi-dw/src/main/resources/mapper/dw/CjStudentMapper.xml index 47cf3c4..ee82994 100644 --- a/ruoyi-dw/src/main/resources/mapper/dw/CjStudentMapper.xml +++ b/ruoyi-dw/src/main/resources/mapper/dw/CjStudentMapper.xml @@ -60,6 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and bynf = ]]> #{gtYear} and bynf #{ltYear} + order by update_time desc