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 6eb1cd4..381c95f 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 @@ -44,7 +44,6 @@ public class CjStudentController extends BaseController @GetMapping("/list") public TableDataInfo list(CjStudent cjStudent) { - startPage(); Long deptId = SecurityUtils.getLoginUser().getDeptId(); if (deptId.intValue() != 100){ SysDept dept = sysDeptService.selectDeptById(deptId); @@ -60,6 +59,7 @@ public class CjStudentController extends BaseController cjStudent.setLtYear(currentYear); } } + startPage(); List list = cjStudentService.selectCjStudentList(cjStudent); return getDataTable(list); } @@ -77,6 +77,17 @@ public class CjStudentController extends BaseController util.exportExcel(response, list, "采集学生信息数据"); } + /** + * 导出采集学生信息列表 + */ + @Log(title = "采集学生信息", businessType = BusinessType.EXPORT) + @PostMapping("/importData") + public void importSData(MultipartFile file) + { + cjStudentService.importCjStudent(file); + } + + /** * 获取采集学生信息详细信息 */ diff --git a/ruoyi-dw/src/main/java/com/ruoyi/dw/domain/CjStudent.java b/ruoyi-dw/src/main/java/com/ruoyi/dw/domain/CjStudent.java index 1e1e07e..05bf106 100644 --- a/ruoyi-dw/src/main/java/com/ruoyi/dw/domain/CjStudent.java +++ b/ruoyi-dw/src/main/java/com/ruoyi/dw/domain/CjStudent.java @@ -1,11 +1,14 @@ package com.ruoyi.dw.domain; +import com.fasterxml.jackson.annotation.JsonFormat; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.core.domain.BaseEntity; import org.springframework.data.annotation.Transient; +import java.util.Date; + /** * 采集学生信息对象 cj_student * @@ -34,6 +37,9 @@ public class CjStudent @Excel(name = "专业") private String zy; + @Excel(name = "班级") + private String bj; + /** 学院 */ @Excel(name = "学院") private String xy; @@ -107,6 +113,10 @@ public class CjStudent @Transient private Integer gtYear; + /** 更新时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date updateTime; + public void setId(Long id) { this.id = id; @@ -331,6 +341,22 @@ public class CjStudent this.gtYear = gtYear; } + public String getBj() { + return bj; + } + + public void setBj(String bj) { + this.bj = bj; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-dw/src/main/java/com/ruoyi/dw/service/ICjStudentService.java b/ruoyi-dw/src/main/java/com/ruoyi/dw/service/ICjStudentService.java index 4552ed7..253f285 100644 --- a/ruoyi-dw/src/main/java/com/ruoyi/dw/service/ICjStudentService.java +++ b/ruoyi-dw/src/main/java/com/ruoyi/dw/service/ICjStudentService.java @@ -82,4 +82,6 @@ public interface ICjStudentService * @return */ public int importData(MultipartFile file); + + public int importCjStudent(MultipartFile file); } 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 e93b4a8..56ecc09 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 @@ -1,8 +1,11 @@ package com.ruoyi.dw.service.impl; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import com.ruoyi.common.core.redis.RedisCache; import org.apache.poi.ss.usermodel.*; @@ -190,5 +193,51 @@ public class CjStudentServiceImpl implements ICjStudentService return -1; } } + public static int findFirstDigitIndexRegex(String str) { + if (str == null || str.isEmpty()) { + return -1; + } + + Pattern pattern = Pattern.compile("\\d"); // 匹配任意数字 + Matcher matcher = pattern.matcher(str); + + if (matcher.find()) { + return matcher.start(); // 返回第一个匹配数字字符的起始位置 + } + + return -1; // 没有找到数字 + } + + @Override + public int importCjStudent(MultipartFile file) { + try { + Workbook workbook = WorkbookFactory.create(file.getInputStream()); + Sheet sheet = workbook.getSheetAt(0); + int rows = sheet.getLastRowNum(); + for (int i = 3; i <= rows; i++) { + Row row = sheet.getRow(i); + CjStudent cjStudent = new CjStudent(); + Cell xmCell = row.getCell(1); + cjStudent.setXm(xmCell.getStringCellValue()); + Cell xhCell = row.getCell(2); + cjStudent.setXh(xhCell.getStringCellValue()); + Cell xyCell = row.getCell(3); + cjStudent.setXy(xyCell.getStringCellValue()); + Cell bjCell = row.getCell(4); + String bj = bjCell.getStringCellValue(); + cjStudent.setBj(bj); + int a = findFirstDigitIndexRegex(bj); + String zy = bj.substring(0,a); + String bynfStr = "20" + bj.substring(a,a+2); + cjStudent.setZy(zy); + cjStudent.setBynf(Integer.valueOf(bynfStr)); + cjStudentMapper.insertCjStudent(cjStudent); + } + + }catch (IOException e) { + + } + return 0; + } } diff --git a/ruoyi-dw/src/main/resources/mapper/dw/CjStudentMapper.xml b/ruoyi-dw/src/main/resources/mapper/dw/CjStudentMapper.xml index 45be9d6..7fdaf72 100644 --- a/ruoyi-dw/src/main/resources/mapper/dw/CjStudentMapper.xml +++ b/ruoyi-dw/src/main/resources/mapper/dw/CjStudentMapper.xml @@ -26,20 +26,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + - select id, xm,xh, xb, zy,xy,sydsh, sydshi, bynf, zgyl, gzdw, dwxz, dwdz, zwjb, shjz, dbry, rysfzs,sj, yx, qt, sfqr from cj_student + select id, xm,xh,bj, xb, zy,xy,sydsh, sydshi, bynf, zgyl, gzdw, dwxz, dwdz, zwjb, shjz, dbry, rysfzs,sj, yx, qt, sfqr,update_time from cj_student + +