标准excel导入
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package com.adc.da.slrs.ImportExcelDatas.POIUtil;
|
||||
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.DateUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
@Component
|
||||
public class POIUtil {
|
||||
|
||||
|
||||
//获取单元格各类型值,返回字符串类型
|
||||
public static String getCellValueByCell(Cell cell) {
|
||||
//判断是否为null或空串
|
||||
if (cell==null || cell.toString().trim().equals("")) {
|
||||
return "";
|
||||
}
|
||||
String cellValue = "";
|
||||
CellType cellType = cell.getCellType();
|
||||
cell.getCellType();
|
||||
switch (cellType) {
|
||||
case NUMERIC: // 数字
|
||||
short format = cell.getCellStyle().getDataFormat();
|
||||
if (DateUtil.isCellDateFormatted(cell)) {
|
||||
SimpleDateFormat sdf = null;
|
||||
//System.out.println("cell.getCellStyle().getDataFormat()="+cell.getCellStyle().getDataFormat());
|
||||
if (format == 20 || format == 32) {
|
||||
sdf = new SimpleDateFormat("HH:mm");
|
||||
} else if (format == 14 || format == 31 || format == 57 || format == 58) {
|
||||
// 处理自定义日期格式:m月d日(通过判断单元格的格式id解决,id的值是58)
|
||||
sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
double value = cell.getNumericCellValue();
|
||||
Date date = org.apache.poi.ss.usermodel.DateUtil
|
||||
.getJavaDate(value);
|
||||
cellValue = sdf.format(date);
|
||||
}else {// 日期
|
||||
sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
}
|
||||
try {
|
||||
cellValue = sdf.format(cell.getDateCellValue());// 日期
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
throw new Exception("exception on get date data !".concat(e.toString()));
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}finally{
|
||||
sdf = null;
|
||||
}
|
||||
} else {
|
||||
BigDecimal bd = new BigDecimal(cell.getNumericCellValue());
|
||||
cellValue = bd.toPlainString();// 数值 这种用BigDecimal包装再获取plainString,可以防止获取到科学计数值
|
||||
}
|
||||
break;
|
||||
case STRING: // 字符串
|
||||
cellValue = cell.getStringCellValue();
|
||||
break;
|
||||
case BOOLEAN: // Boolean
|
||||
cellValue = cell.getBooleanCellValue()+"";;
|
||||
break;
|
||||
case FORMULA: // 公式
|
||||
cellValue = cell.getCellFormula();
|
||||
break;
|
||||
case BLANK: // 空值
|
||||
cellValue = "";
|
||||
break;
|
||||
case ERROR: // 故障
|
||||
cellValue = "ERROR VALUE";
|
||||
break;
|
||||
default:
|
||||
cellValue = "UNKNOW VALUE";
|
||||
break;
|
||||
}
|
||||
return cellValue;
|
||||
}
|
||||
}
|
||||
+40
-22
@@ -1,10 +1,11 @@
|
||||
package com.adc.da.slrs.ImportExcelDatas.comment;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.poi.xssf.usermodel.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -18,46 +19,64 @@ import java.util.HashMap;
|
||||
public class PathMatcher {
|
||||
private static final Logger logger = LoggerFactory.getLogger(PathMatcher.class);
|
||||
|
||||
public void run(MultipartFile target,MultipartFile attach) throws IOException {
|
||||
|
||||
|
||||
public void run(MultipartFile target, MultipartFile attach) throws IOException {
|
||||
InputStream inputStream = target.getInputStream();
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
|
||||
|
||||
XSSFSheet sheet = workbook.getSheetAt(0);
|
||||
XSSFSheet mySheet = workbook.getSheetAt(0);
|
||||
|
||||
HashMap<String, String> fileMap = getFileMap(attach);
|
||||
|
||||
|
||||
for (Row row : sheet) {
|
||||
if(row.getCell(1)==null || row.getCell(10)==null){
|
||||
for (Row row : mySheet) {
|
||||
if (row.getCell(1) == null || row.getCell(10) == null) {
|
||||
logger.info("+");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
String latter = row.getCell(1).getStringCellValue().trim();//标准号
|
||||
String fileId="";
|
||||
|
||||
fileId = row.getCell(10).getStringCellValue().trim();//文档id
|
||||
String[] fileIdArray = row.getCell(10).getStringCellValue().trim().split(",");//文档id
|
||||
|
||||
HashMap<String, String> idMapPath = new HashMap<>(); //文件id和路径的键值对
|
||||
|
||||
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(fileId)
|
||||
.append(latter);
|
||||
if (fileMap.containsKey(builder.toString())){
|
||||
Cell cell = row.createCell(9);
|
||||
cell.setCellType(CellType.STRING);
|
||||
cell.setCellValue(fileMap.get(builder.toString()));
|
||||
logger.info("*");
|
||||
}else {
|
||||
logger.info("-");
|
||||
|
||||
for (String fileId : fileIdArray) { //遍历文件id
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(fileId)
|
||||
.append(latter);//拼接文件id和标准号
|
||||
|
||||
|
||||
if (!fileMap.containsKey(builder.toString())) {
|
||||
logger.info("-");
|
||||
continue;
|
||||
}else {
|
||||
Cell cell = row.createCell(9);
|
||||
|
||||
|
||||
idMapPath.put(fileId,fileMap.get(builder.toString()));
|
||||
String json = JSON.toJSONString(idMapPath);
|
||||
|
||||
cell.setCellType(CellType.STRING);
|
||||
cell.setCellValue(json);
|
||||
logger.info("*");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
File file = new File("C:\\Users\\22501\\Desktop\\foton标准数据\\匹配带入文件路径-企标.xlsx");
|
||||
File file = new File("C:\\Users\\22501\\Desktop\\foton标准数据\\匹配带入文件路径-国内-多个路径.xlsx");
|
||||
FileOutputStream os = new FileOutputStream(file);
|
||||
workbook.write(os);
|
||||
|
||||
@@ -65,8 +84,7 @@ public class PathMatcher {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private HashMap<String,String> getFileMap(MultipartFile excel) throws IOException {
|
||||
private HashMap<String, String> getFileMap(MultipartFile excel) throws IOException {
|
||||
|
||||
InputStream inputStream = excel.getInputStream();
|
||||
|
||||
@@ -88,7 +106,7 @@ public class PathMatcher {
|
||||
|
||||
String path = strArray[3];
|
||||
|
||||
resultMap.put(builder.toString(),path);
|
||||
resultMap.put(builder.toString(), path);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+26
-11
@@ -38,16 +38,23 @@ public class StandMatcher {
|
||||
|
||||
for (Row row : sheet) {
|
||||
|
||||
/**
|
||||
* 企标
|
||||
*/
|
||||
// String letter =convertCellValueToString(row.getCell(1));//标准号
|
||||
// String publish = convertCellValueToString(row.getCell(4));//发布日期
|
||||
// String impl= convertCellValueToString(row.getCell(5));//实施日期
|
||||
// String state = convertCellValueToString(row.getCell(3));//状态
|
||||
// String replace= convertCellValueToString(row.getCell(6));//代替标准号
|
||||
|
||||
/**
|
||||
* 国内
|
||||
*/
|
||||
String letter =convertCellValueToString(row.getCell(1));//标准号
|
||||
|
||||
String publish = convertCellValueToString(row.getCell(4));//发布日期
|
||||
|
||||
String impl= convertCellValueToString(row.getCell(5));//实施日期
|
||||
|
||||
String state = convertCellValueToString(row.getCell(3));//状态
|
||||
|
||||
String replace= convertCellValueToString(row.getCell(6));//代替标准号
|
||||
|
||||
String publish = convertCellValueToString(row.getCell(3));//发布日期
|
||||
String impl= convertCellValueToString(row.getCell(4));//实施日期
|
||||
String state = convertCellValueToString(row.getCell(2));//状态
|
||||
String replace= convertCellValueToString(row.getCell(5));//代替标准号
|
||||
|
||||
|
||||
|
||||
@@ -72,7 +79,7 @@ public class StandMatcher {
|
||||
|
||||
}
|
||||
|
||||
File result = new File("C:\\Users\\22501\\Desktop\\foton标准数据\\匹配带入文件id-企标.xlsx");
|
||||
File result = new File("C:\\Users\\22501\\Desktop\\foton标准数据\\匹配带入文件id-国内-多个文件id.xlsx");
|
||||
FileOutputStream os = new FileOutputStream(result);
|
||||
workbook.write(os);
|
||||
}
|
||||
@@ -115,7 +122,15 @@ public class StandMatcher {
|
||||
if (row.getCell(7).getCellType()== NUMERIC){
|
||||
String s = row.getCell(7).toString();
|
||||
String fileId =s.substring(0,s.length()-2);//文件id
|
||||
resultSet.put(strBuilder.toString(),fileId);
|
||||
String standStr = strBuilder.toString();
|
||||
if(resultSet.containsKey(standStr)){
|
||||
String s1 = resultSet.get(standStr);
|
||||
|
||||
resultSet.replace(standStr,s1+","+fileId);
|
||||
}else {
|
||||
resultSet.put(standStr,fileId);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
package com.adc.da.slrs.ImportExcelDatas.comment;
|
||||
|
||||
import com.adc.da.att.service.IAttFileEOService;
|
||||
import com.adc.da.att.vo.AttFileVo;
|
||||
import com.adc.da.slrs.ImportExcelDatas.POIUtil.POIUtil;
|
||||
import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo;
|
||||
import com.adc.da.utils.util.InitStandAttrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@Component
|
||||
public class Standard {
|
||||
|
||||
|
||||
@Autowired
|
||||
private IAttFileEOService attFileEOService;
|
||||
|
||||
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Standard.class);
|
||||
Map<String,String> standAttrMap = new TreeMap<>();
|
||||
private String standType="";
|
||||
|
||||
|
||||
|
||||
Standard(){
|
||||
/**
|
||||
* 初始化国内外标准属性字段
|
||||
*/
|
||||
List<String> listStandField = InitStandAttrUtil.queryFieldList;
|
||||
listStandField.forEach(item ->{
|
||||
this.standAttrMap.put(item,"");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setStandType(String standType) {
|
||||
|
||||
if (!"INLAND,FOREIGN".contains(standType)){
|
||||
logger.error("标准类别错误");
|
||||
}else {
|
||||
this.standType = standType;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public SarStandardsInfo getStandardsInfo(Row row){
|
||||
|
||||
|
||||
SarStandardsInfo sarStandardsInfo = new SarStandardsInfo();
|
||||
|
||||
|
||||
if ("".equals(standType)){
|
||||
logger.error("未设置标准类型");
|
||||
}else {
|
||||
sarStandardsInfo.setStandType(standType);
|
||||
}
|
||||
|
||||
|
||||
sarStandardsInfo.setValidFlag("0");
|
||||
Map<String, String> fieldMap = standAttrMap;//标准字段初化
|
||||
for (int i=0;i<10;i++){
|
||||
Cell cell = row.getCell(i);
|
||||
String value = POIUtil.getCellValueByCell(cell);
|
||||
switch (i){
|
||||
case 0://标准名称
|
||||
sarStandardsInfo.setStandName(value);
|
||||
break;
|
||||
case 2://标准状态
|
||||
//TODO 标准状态转换为代码
|
||||
switch (value){
|
||||
case "有效":
|
||||
value="vsaga7nwub";
|
||||
break;
|
||||
case "作废":
|
||||
value="chblaarg77";
|
||||
break;
|
||||
case "参考":
|
||||
value="-";
|
||||
break;
|
||||
case "0":
|
||||
value="-";
|
||||
break;
|
||||
default:value="-";
|
||||
}
|
||||
sarStandardsInfo.setTextStatus(value);
|
||||
break;
|
||||
case 3://发布日期
|
||||
//日期格式转换 1970/1/1 时发布日期为空
|
||||
if ("1970/1/1".equals(value.trim())){
|
||||
value="";
|
||||
}
|
||||
sarStandardsInfo.setIssueTime(value);
|
||||
break;
|
||||
case 4://实施日期
|
||||
fieldMap.put("SSRQ", value);
|
||||
break;
|
||||
case 5://代替标准号
|
||||
fieldMap.put("DTBJH", value);
|
||||
break;
|
||||
case 6://标准类别
|
||||
sarStandardsInfo.setStandSort(value);
|
||||
break;
|
||||
case 7://标准号
|
||||
sarStandardsInfo.setStandNumber(value);
|
||||
break;
|
||||
case 8://标准年份
|
||||
sarStandardsInfo.setStandYear(value);
|
||||
break;
|
||||
case 9://附件路径 ->上传
|
||||
HashMap<String,String> pathMap = JSON.parseObject(value, HashMap.class);
|
||||
if (pathMap!=null){
|
||||
Cell standCodeCell = row.getCell(1);
|
||||
String standCode = POIUtil.getCellValueByCell(standCodeCell);
|
||||
|
||||
StringBuilder fileNameBuilder = new StringBuilder();
|
||||
fileNameBuilder.append(standCode) //标准号
|
||||
.append(sarStandardsInfo.getStandName());//标准名称
|
||||
AttFileVo fileInfo = importFile(pathMap,fileNameBuilder.toString());//上传文件
|
||||
fieldMap.put("FBGBJBD", fileInfo.getAttId());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Gson gson = new Gson();
|
||||
String attrInfoJson = gson.toJson(fieldMap);
|
||||
sarStandardsInfo.setSarStandAttrEOStr(attrInfoJson);//新增修改时属性表信息
|
||||
|
||||
return sarStandardsInfo;
|
||||
}
|
||||
|
||||
|
||||
private AttFileVo importFile(HashMap<String,String> pathMap,String customName){
|
||||
String realPath = "";
|
||||
|
||||
for(String path: pathMap.values()) {
|
||||
String filePath[] = path.split("/");
|
||||
for (int i = 3; i < filePath.length; i++) {
|
||||
realPath = realPath + "/" + filePath[i];
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
File file = new File("/data/from12/Attach_swf_bak" + realPath);
|
||||
|
||||
|
||||
return attFileEOService.insertFileInfo(file,customName);
|
||||
}
|
||||
|
||||
}
|
||||
+13
-1
@@ -4,6 +4,7 @@ import com.adc.da.base.web.BaseController;
|
||||
import com.adc.da.common.ReadExcel;
|
||||
import com.adc.da.slrs.ImportExcelDatas.comment.*;
|
||||
import com.adc.da.slrs.ImportExcelDatas.entity.ImportDto;
|
||||
import com.adc.da.slrs.ImportExcelDatas.service.IImportStandExcelService;
|
||||
import com.adc.da.slrs.ImportExcelDatas.service.ImportExcelService;
|
||||
import com.adc.da.util.exception.AdcDaBaseException;
|
||||
import com.adc.da.util.utils.IOUtils;
|
||||
@@ -155,7 +156,7 @@ public class ImportExcelController extends BaseController<ImportDto> {
|
||||
|
||||
|
||||
|
||||
@ApiOperation("匹配文件id")
|
||||
@ApiOperation("匹配文件id(多个id)")
|
||||
@PostMapping("/matching")
|
||||
public void matching(MultipartFile targetExcel,MultipartFile attachExcel) throws IOException {
|
||||
StandMatcher standMatcher = new StandMatcher();
|
||||
@@ -171,4 +172,15 @@ public class ImportExcelController extends BaseController<ImportDto> {
|
||||
pathMatcher.run(targetExcel,attachExcel);
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
private IImportStandExcelService iImportStandExcelService;
|
||||
|
||||
@ApiOperation("根据分解后的excel表 导入标准数据和附件")
|
||||
@PostMapping("importStandFormExcel")
|
||||
public void importStandFormExcel(MultipartFile targetExcel,String standType) throws IOException {
|
||||
iImportStandExcelService.importStandExcel(targetExcel,standType);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+5
@@ -18,4 +18,9 @@ public interface ImportExcelService extends IService<ImportDto> {
|
||||
|
||||
|
||||
public String isExist(MultipartFile exclFile);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+8
-5
@@ -324,11 +324,14 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
|
||||
List<DicTypeEO> isExist = dicTypeEOService.getTypeIdByDicIdAndTypeName("JKSADFH564S", null, null, null);
|
||||
isExist.forEach(item->{
|
||||
sarSort.add(item.getDicTypeCode());
|
||||
});
|
||||
});//标准类别集合
|
||||
|
||||
|
||||
error = importListMap.get("error");
|
||||
|
||||
/**
|
||||
* 计数
|
||||
*/
|
||||
AtomicInteger QYBZcount= new AtomicInteger();
|
||||
AtomicInteger QYBZcountUpdate= new AtomicInteger();
|
||||
AtomicInteger HWBZcount= new AtomicInteger();
|
||||
@@ -350,7 +353,7 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
|
||||
*/
|
||||
|
||||
|
||||
/*importListMap.get("HWBZ").forEach(item -> {
|
||||
importListMap.get("HWBZ").forEach(item -> {
|
||||
if (true ) {
|
||||
String standID = UUIDUtils.randomUUID20();
|
||||
|
||||
@@ -409,14 +412,14 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
|
||||
|
||||
|
||||
|
||||
});*/
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* 国内标准
|
||||
*/
|
||||
|
||||
/*importListMap.get("GNBZ").forEach(item -> {
|
||||
importListMap.get("GNBZ").forEach(item -> {
|
||||
|
||||
|
||||
if (true) {
|
||||
@@ -472,7 +475,7 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
|
||||
|
||||
}
|
||||
|
||||
});*/
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package com.adc.da.slrs.ImportExcelDatas.service.impl;
|
||||
|
||||
import com.adc.da.att.service.IAttFileEOService;
|
||||
import com.adc.da.att.vo.AttFileVo;
|
||||
import com.adc.da.slrs.ImportExcelDatas.POIUtil.POIUtil;
|
||||
import com.adc.da.slrs.ImportExcelDatas.comment.PathMatcher;
|
||||
import com.adc.da.slrs.ImportExcelDatas.comment.Standard;
|
||||
import com.adc.da.slrs.ImportExcelDatas.entity.ImportDto;
|
||||
import com.adc.da.slrs.ImportExcelDatas.service.IImportStandExcelService;
|
||||
import com.adc.da.slrs.sarBussionessStand.entity.SarBussionessStand;
|
||||
import com.adc.da.slrs.sarBussionessStand.service.ISarBussionessStandService;
|
||||
import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo;
|
||||
import com.adc.da.slrs.sarStandardsInfo.service.ISarStandardsInfoService;
|
||||
import com.adc.da.sys.service.impl.DicTypeEOServiceImpl;
|
||||
import com.adc.da.utils.util.InitStandAttrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Service
|
||||
public class ImportStandExcelServiceImpl implements IImportStandExcelService {
|
||||
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PathMatcher.class);
|
||||
@Autowired
|
||||
private ISarStandardsInfoService sarStandardsInfoService;
|
||||
|
||||
@Autowired
|
||||
private Standard standard;
|
||||
|
||||
private List<ImportDto> error = new ArrayList<>();
|
||||
|
||||
private List<ImportDto> fileError = new ArrayList<>();
|
||||
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public String importStandExcel(MultipartFile file,String standType) throws IOException {
|
||||
|
||||
AtomicInteger countUpdate= new AtomicInteger();//更新 数量
|
||||
AtomicInteger countInsert= new AtomicInteger();//新增 数量
|
||||
|
||||
InputStream inputStream = file.getInputStream();
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
|
||||
XSSFSheet sheet = workbook.getSheetAt(0);
|
||||
|
||||
standard.setStandType(standType);
|
||||
|
||||
int lastRowNum = sheet.getLastRowNum();
|
||||
|
||||
for (int i = 1; i < lastRowNum; i++) {
|
||||
XSSFRow row = sheet.getRow(i);
|
||||
SarStandardsInfo standardsInfo = standard.getStandardsInfo(row);
|
||||
|
||||
QueryWrapper<SarStandardsInfo> standSaveWrapper = new QueryWrapper<>();
|
||||
standSaveWrapper
|
||||
.eq("STAND_SORT", standardsInfo.getStandSort())
|
||||
.eq("STAND_NUMBER", standardsInfo.getStandNumber())
|
||||
.eq("STAND_YEAR", standardsInfo.getStandYear());
|
||||
|
||||
|
||||
SarStandardsInfo one = sarStandardsInfoService.getOne(standSaveWrapper);
|
||||
if (one != null) {
|
||||
|
||||
|
||||
standardsInfo.setId(one.getId());
|
||||
try {
|
||||
sarStandardsInfoService.updateSarStandardsInfo(standardsInfo);
|
||||
countUpdate.getAndIncrement();
|
||||
logger.info("执行更新"+countUpdate+"条数据");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
try {
|
||||
sarStandardsInfoService.createSarStandardsInfo(standardsInfo);
|
||||
countInsert.getAndIncrement();
|
||||
logger.info("执行新增"+countInsert+"条数据");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "success";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user