修改导入相关的问题
This commit is contained in:
@ -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("导入失败,请检查信息采集内容是否正确");
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
xmCell.setCellType(CellType.STRING);
|
if (xmCell != null) {
|
||||||
cjStudent.setXm(xmCell.getStringCellValue().trim());
|
xmCell.setCellType(CellType.STRING);
|
||||||
|
cjStudent.setXm(xmCell.getStringCellValue().trim());
|
||||||
|
}
|
||||||
Cell xbCell = row.getCell(2);
|
Cell xbCell = row.getCell(2);
|
||||||
xbCell.setCellType(CellType.STRING);
|
if (xbCell != null) {
|
||||||
cjStudent.setXb(xbCell.getStringCellValue().trim());
|
xbCell.setCellType(CellType.STRING);
|
||||||
|
cjStudent.setXb(xbCell.getStringCellValue().trim());
|
||||||
|
}
|
||||||
cjStudent.setXh(xh);
|
cjStudent.setXh(xh);
|
||||||
Cell xyCell = row.getCell(4);
|
Cell xyCell = row.getCell(4);
|
||||||
xyCell.setCellType(CellType.STRING);
|
if (xyCell != null) {
|
||||||
cjStudent.setXy(xyCell.getStringCellValue().trim());
|
xyCell.setCellType(CellType.STRING);
|
||||||
|
cjStudent.setXy(xyCell.getStringCellValue().trim());
|
||||||
|
}
|
||||||
Cell zyCell = row.getCell(5);
|
Cell zyCell = row.getCell(5);
|
||||||
zyCell.setCellType(CellType.STRING);
|
if (zyCell != null) {
|
||||||
cjStudent.setZy(zyCell.getStringCellValue().trim());
|
zyCell.setCellType(CellType.STRING);
|
||||||
|
cjStudent.setZy(zyCell.getStringCellValue().trim());
|
||||||
|
}
|
||||||
Cell bjCell = row.getCell(6);
|
Cell bjCell = row.getCell(6);
|
||||||
bjCell.setCellType(CellType.STRING);
|
if (bjCell != null) {
|
||||||
cjStudent.setBj(bjCell.getStringCellValue().trim());
|
bjCell.setCellType(CellType.STRING);
|
||||||
|
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,55 +268,80 @@ public class CjStudentServiceImpl implements ICjStudentService
|
|||||||
cjStudent.setBynf(null);
|
cjStudent.setBynf(null);
|
||||||
}
|
}
|
||||||
Cell zgxlCell = row.getCell(8);
|
Cell zgxlCell = row.getCell(8);
|
||||||
zgxlCell.setCellType(CellType.STRING);
|
if (zgxlCell != null) {
|
||||||
cjStudent.setZgyl(zgxlCell.getStringCellValue().trim());
|
zgxlCell.setCellType(CellType.STRING);
|
||||||
|
cjStudent.setZgyl(zgxlCell.getStringCellValue().trim());
|
||||||
|
}
|
||||||
Cell gzdwCell = row.getCell(9);
|
Cell gzdwCell = row.getCell(9);
|
||||||
gzdwCell.setCellType(CellType.STRING);
|
if (gzdwCell != null) {
|
||||||
cjStudent.setGzdw(gzdwCell.getStringCellValue().trim());
|
gzdwCell.setCellType(CellType.STRING);
|
||||||
|
cjStudent.setGzdw(gzdwCell.getStringCellValue().trim());
|
||||||
|
}
|
||||||
Cell dwxzCell = row.getCell(10);
|
Cell dwxzCell = row.getCell(10);
|
||||||
dwxzCell.setCellType(CellType.STRING);
|
if (dwxzCell != null) {
|
||||||
cjStudent.setDwxz(dwxzCell.getStringCellValue().trim());
|
dwxzCell.setCellType(CellType.STRING);
|
||||||
|
cjStudent.setDwxz(dwxzCell.getStringCellValue().trim());
|
||||||
|
}
|
||||||
Cell dwdzCell = row.getCell(11);
|
Cell dwdzCell = row.getCell(11);
|
||||||
dwdzCell.setCellType(CellType.STRING);
|
if (dwdzCell != null) {
|
||||||
cjStudent.setDwdz(dwdzCell.getStringCellValue().trim());
|
dwdzCell.setCellType(CellType.STRING);
|
||||||
|
cjStudent.setDwdz(dwdzCell.getStringCellValue().trim());
|
||||||
|
}
|
||||||
Cell czdCell = row.getCell(12);
|
Cell czdCell = row.getCell(12);
|
||||||
czdCell.setCellType(CellType.STRING);
|
if (czdCell != null) {
|
||||||
String czd = czdCell.getStringCellValue().trim();
|
czdCell.setCellType(CellType.STRING);
|
||||||
Map<String, String> pac = extractProvinceAndCity(czd);
|
String czd = czdCell.getStringCellValue().trim();
|
||||||
if (pac != null){
|
Map<String, String> pac = extractProvinceAndCity(czd);
|
||||||
cjStudent.setSydsh(pac.get("province"));
|
if (pac != null){
|
||||||
cjStudent.setSydshi(pac.get("city"));
|
cjStudent.setSydsh(pac.get("province"));
|
||||||
|
cjStudent.setSydshi(pac.get("city"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Cell zwjbCell = row.getCell(13);
|
Cell zwjbCell = row.getCell(13);
|
||||||
zwjbCell.setCellType(CellType.STRING);
|
if (zwjbCell != null) {
|
||||||
cjStudent.setZwjb(zwjbCell.getStringCellValue().trim());
|
zwjbCell.setCellType(CellType.STRING);
|
||||||
|
cjStudent.setZwjb(zwjbCell.getStringCellValue().trim());
|
||||||
|
}
|
||||||
Cell shjzCell = row.getCell(14);
|
Cell shjzCell = row.getCell(14);
|
||||||
shjzCell.setCellType(CellType.STRING);
|
if (shjzCell != null) {
|
||||||
cjStudent.setShjz(shjzCell.getStringCellValue().trim());
|
shjzCell.setCellType(CellType.STRING);
|
||||||
|
cjStudent.setShjz(shjzCell.getStringCellValue().trim());
|
||||||
|
}
|
||||||
Cell dbryCell = row.getCell(15);
|
Cell dbryCell = row.getCell(15);
|
||||||
dbryCell.setCellType(CellType.STRING);
|
if (dbryCell != null) {
|
||||||
cjStudent.setDbry(dbryCell.getStringCellValue().trim());
|
dbryCell.setCellType(CellType.STRING);
|
||||||
|
cjStudent.setDbry(dbryCell.getStringCellValue().trim());
|
||||||
|
}
|
||||||
Cell rysfzsCell = row.getCell(16);
|
Cell rysfzsCell = row.getCell(16);
|
||||||
rysfzsCell.setCellType(CellType.STRING);
|
if (rysfzsCell != null) {
|
||||||
String rysfzs = rysfzsCell.getStringCellValue().trim();
|
rysfzsCell.setCellType(CellType.STRING);
|
||||||
if ("是".equals(rysfzs)){
|
String rysfzs = rysfzsCell.getStringCellValue().trim();
|
||||||
cjStudent.setRysfzs(1L);
|
if ("是".equals(rysfzs)){
|
||||||
|
cjStudent.setRysfzs(1L);
|
||||||
|
}else {
|
||||||
|
cjStudent.setRysfzs(0L);
|
||||||
|
}
|
||||||
}else {
|
}else {
|
||||||
cjStudent.setRysfzs(0L);
|
cjStudent.setRysfzs(0L);
|
||||||
}
|
}
|
||||||
Cell sjCell = row.getCell(17);
|
Cell sjCell = row.getCell(17);
|
||||||
sjCell.setCellType(CellType.STRING);
|
if (sjCell != null) {
|
||||||
cjStudent.setSj(sjCell.getStringCellValue());
|
sjCell.setCellType(CellType.STRING);
|
||||||
|
cjStudent.setSj(sjCell.getStringCellValue());
|
||||||
|
}
|
||||||
Cell yxCell = row.getCell(18);
|
Cell yxCell = row.getCell(18);
|
||||||
yxCell.setCellType(CellType.STRING);
|
if (yxCell != null) {
|
||||||
cjStudent.setYx(yxCell.getStringCellValue().trim());
|
yxCell.setCellType(CellType.STRING);
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
@ -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">
|
||||||
|
Reference in New Issue
Block a user