修改导入相关的问题

This commit is contained in:
2025-08-05 09:28:52 +08:00
parent 55ac707a8c
commit 4fbbc31a64
3 changed files with 84 additions and 40 deletions

View File

@ -146,7 +146,9 @@ public class CjStudentController extends BaseController
public AjaxResult importData(MultipartFile file) { public AjaxResult importData(MultipartFile file) {
int successNum = cjStudentService.importData(file); int successNum = cjStudentService.importData(file);
if (successNum > 0) { if (successNum > 0) {
return AjaxResult.success("导入成功"); return AjaxResult.success("成功导入" + successNum + "条数据");
}else if (successNum == 0){
return AjaxResult.success("导入数据量为0,请检查导入的Excel是否与模板相同");
}else { }else {
return AjaxResult.error("导入失败,请检查信息采集内容是否正确"); return AjaxResult.error("导入失败,请检查信息采集内容是否正确");
} }

View File

@ -6,6 +6,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.StringUtils;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -214,6 +215,7 @@ public class CjStudentServiceImpl implements ICjStudentService
Workbook workbook = WorkbookFactory.create(file.getInputStream()); Workbook workbook = WorkbookFactory.create(file.getInputStream());
Sheet sheet = workbook.getSheetAt(0); Sheet sheet = workbook.getSheetAt(0);
int rows = sheet.getLastRowNum(); int rows = sheet.getLastRowNum();
int j = 0;
for (int i = 2; i <= rows; i++) { for (int i = 2; i <= rows; i++) {
Row row = sheet.getRow(i); Row row = sheet.getRow(i);
if (row == null) { if (row == null) {
@ -222,6 +224,9 @@ public class CjStudentServiceImpl implements ICjStudentService
Cell xhCell = row.getCell(3); Cell xhCell = row.getCell(3);
xhCell.setCellType(CellType.STRING); xhCell.setCellType(CellType.STRING);
String xh = xhCell.getStringCellValue().trim(); String xh = xhCell.getStringCellValue().trim();
if (!StringUtils.isNumeric(xh)){
continue;
}
boolean isInsert = false; boolean isInsert = false;
CjStudent cjStudent = cjStudentMapper.selectCjStudentByXh(xh); CjStudent cjStudent = cjStudentMapper.selectCjStudentByXh(xh);
if (cjStudent == null){ if (cjStudent == null){
@ -229,21 +234,31 @@ public class CjStudentServiceImpl implements ICjStudentService
isInsert = true; isInsert = true;
} }
Cell xmCell = row.getCell(1); Cell xmCell = row.getCell(1);
if (xmCell != null) {
xmCell.setCellType(CellType.STRING); xmCell.setCellType(CellType.STRING);
cjStudent.setXm(xmCell.getStringCellValue().trim()); cjStudent.setXm(xmCell.getStringCellValue().trim());
}
Cell xbCell = row.getCell(2); Cell xbCell = row.getCell(2);
if (xbCell != null) {
xbCell.setCellType(CellType.STRING); xbCell.setCellType(CellType.STRING);
cjStudent.setXb(xbCell.getStringCellValue().trim()); cjStudent.setXb(xbCell.getStringCellValue().trim());
}
cjStudent.setXh(xh); cjStudent.setXh(xh);
Cell xyCell = row.getCell(4); Cell xyCell = row.getCell(4);
if (xyCell != null) {
xyCell.setCellType(CellType.STRING); xyCell.setCellType(CellType.STRING);
cjStudent.setXy(xyCell.getStringCellValue().trim()); cjStudent.setXy(xyCell.getStringCellValue().trim());
}
Cell zyCell = row.getCell(5); Cell zyCell = row.getCell(5);
if (zyCell != null) {
zyCell.setCellType(CellType.STRING); zyCell.setCellType(CellType.STRING);
cjStudent.setZy(zyCell.getStringCellValue().trim()); cjStudent.setZy(zyCell.getStringCellValue().trim());
}
Cell bjCell = row.getCell(6); Cell bjCell = row.getCell(6);
if (bjCell != null) {
bjCell.setCellType(CellType.STRING); bjCell.setCellType(CellType.STRING);
cjStudent.setBj(bjCell.getStringCellValue().trim()); cjStudent.setBj(bjCell.getStringCellValue().trim());
}
Cell bybfCell = row.getCell(7); Cell bybfCell = row.getCell(7);
bybfCell.setCellType(CellType.STRING); bybfCell.setCellType(CellType.STRING);
try { try {
@ -253,18 +268,27 @@ public class CjStudentServiceImpl implements ICjStudentService
cjStudent.setBynf(null); cjStudent.setBynf(null);
} }
Cell zgxlCell = row.getCell(8); Cell zgxlCell = row.getCell(8);
if (zgxlCell != null) {
zgxlCell.setCellType(CellType.STRING); zgxlCell.setCellType(CellType.STRING);
cjStudent.setZgyl(zgxlCell.getStringCellValue().trim()); cjStudent.setZgyl(zgxlCell.getStringCellValue().trim());
}
Cell gzdwCell = row.getCell(9); Cell gzdwCell = row.getCell(9);
if (gzdwCell != null) {
gzdwCell.setCellType(CellType.STRING); gzdwCell.setCellType(CellType.STRING);
cjStudent.setGzdw(gzdwCell.getStringCellValue().trim()); cjStudent.setGzdw(gzdwCell.getStringCellValue().trim());
}
Cell dwxzCell = row.getCell(10); Cell dwxzCell = row.getCell(10);
if (dwxzCell != null) {
dwxzCell.setCellType(CellType.STRING); dwxzCell.setCellType(CellType.STRING);
cjStudent.setDwxz(dwxzCell.getStringCellValue().trim()); cjStudent.setDwxz(dwxzCell.getStringCellValue().trim());
}
Cell dwdzCell = row.getCell(11); Cell dwdzCell = row.getCell(11);
if (dwdzCell != null) {
dwdzCell.setCellType(CellType.STRING); dwdzCell.setCellType(CellType.STRING);
cjStudent.setDwdz(dwdzCell.getStringCellValue().trim()); cjStudent.setDwdz(dwdzCell.getStringCellValue().trim());
}
Cell czdCell = row.getCell(12); Cell czdCell = row.getCell(12);
if (czdCell != null) {
czdCell.setCellType(CellType.STRING); czdCell.setCellType(CellType.STRING);
String czd = czdCell.getStringCellValue().trim(); String czd = czdCell.getStringCellValue().trim();
Map<String, String> pac = extractProvinceAndCity(czd); Map<String, String> pac = extractProvinceAndCity(czd);
@ -272,16 +296,24 @@ public class CjStudentServiceImpl implements ICjStudentService
cjStudent.setSydsh(pac.get("province")); cjStudent.setSydsh(pac.get("province"));
cjStudent.setSydshi(pac.get("city")); cjStudent.setSydshi(pac.get("city"));
} }
}
Cell zwjbCell = row.getCell(13); Cell zwjbCell = row.getCell(13);
if (zwjbCell != null) {
zwjbCell.setCellType(CellType.STRING); zwjbCell.setCellType(CellType.STRING);
cjStudent.setZwjb(zwjbCell.getStringCellValue().trim()); cjStudent.setZwjb(zwjbCell.getStringCellValue().trim());
}
Cell shjzCell = row.getCell(14); Cell shjzCell = row.getCell(14);
if (shjzCell != null) {
shjzCell.setCellType(CellType.STRING); shjzCell.setCellType(CellType.STRING);
cjStudent.setShjz(shjzCell.getStringCellValue().trim()); cjStudent.setShjz(shjzCell.getStringCellValue().trim());
}
Cell dbryCell = row.getCell(15); Cell dbryCell = row.getCell(15);
if (dbryCell != null) {
dbryCell.setCellType(CellType.STRING); dbryCell.setCellType(CellType.STRING);
cjStudent.setDbry(dbryCell.getStringCellValue().trim()); cjStudent.setDbry(dbryCell.getStringCellValue().trim());
}
Cell rysfzsCell = row.getCell(16); Cell rysfzsCell = row.getCell(16);
if (rysfzsCell != null) {
rysfzsCell.setCellType(CellType.STRING); rysfzsCell.setCellType(CellType.STRING);
String rysfzs = rysfzsCell.getStringCellValue().trim(); String rysfzs = rysfzsCell.getStringCellValue().trim();
if ("".equals(rysfzs)){ if ("".equals(rysfzs)){
@ -289,19 +321,27 @@ public class CjStudentServiceImpl implements ICjStudentService
}else { }else {
cjStudent.setRysfzs(0L); cjStudent.setRysfzs(0L);
} }
}else {
cjStudent.setRysfzs(0L);
}
Cell sjCell = row.getCell(17); Cell sjCell = row.getCell(17);
if (sjCell != null) {
sjCell.setCellType(CellType.STRING); sjCell.setCellType(CellType.STRING);
cjStudent.setSj(sjCell.getStringCellValue()); cjStudent.setSj(sjCell.getStringCellValue());
}
Cell yxCell = row.getCell(18); Cell yxCell = row.getCell(18);
if (yxCell != null) {
yxCell.setCellType(CellType.STRING); yxCell.setCellType(CellType.STRING);
cjStudent.setYx(yxCell.getStringCellValue().trim()); cjStudent.setYx(yxCell.getStringCellValue().trim());
}
cjStudent.setSfqr(1L); cjStudent.setSfqr(1L);
if (isInsert) if (isInsert)
cjStudentMapper.insertCjStudent(cjStudent); cjStudentMapper.insertCjStudent(cjStudent);
else else
cjStudentMapper.updateCjStudent(cjStudent); cjStudentMapper.updateCjStudent(cjStudent);
j++;
} }
return rows-2; return j;
}catch (Exception e) { }catch (Exception e) {
return -1; return -1;
} }

View File

@ -60,6 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="gtYear != null "> and bynf <![CDATA[ >= ]]> #{gtYear}</if> <if test="gtYear != null "> and bynf <![CDATA[ >= ]]> #{gtYear}</if>
<if test="ltYear != null "> and bynf <![CDATA[ <= ]]> #{ltYear}</if> <if test="ltYear != null "> and bynf <![CDATA[ <= ]]> #{ltYear}</if>
</where> </where>
order by update_time desc
</select> </select>
<select id="selectCjStudentByIds" resultMap="CjStudentResult"> <select id="selectCjStudentByIds" resultMap="CjStudentResult">
@ -92,6 +93,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<where> <where>
dbry is not null and dbry != '' and dbry != '无' and dbry != '暂无' dbry is not null and dbry != '' and dbry != '无' and dbry != '暂无'
</where> </where>
order by update_time desc
</select> </select>
<select id="selectCjStudentById" parameterType="Long" resultMap="CjStudentResult"> <select id="selectCjStudentById" parameterType="Long" resultMap="CjStudentResult">