修改导入相关的问题
This commit is contained in:
@ -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("导入失败,请检查信息采集内容是否正确");
|
||||
}
|
||||
|
@ -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<String, String> 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<String, String> 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;
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="gtYear != null "> and bynf <![CDATA[ >= ]]> #{gtYear}</if>
|
||||
<if test="ltYear != null "> and bynf <![CDATA[ <= ]]> #{ltYear}</if>
|
||||
</where>
|
||||
order by update_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectCjStudentByIds" resultMap="CjStudentResult">
|
||||
@ -92,6 +93,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<where>
|
||||
dbry is not null and dbry != '' and dbry != '无' and dbry != '暂无'
|
||||
</where>
|
||||
order by update_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectCjStudentById" parameterType="Long" resultMap="CjStudentResult">
|
||||
|
Reference in New Issue
Block a user