企业标准导入功能测试
This commit is contained in:
+3
-2
@@ -563,8 +563,9 @@ public class SarBussionessStandController extends BaseController<SarBussionessSt
|
||||
@ApiOperation(value = "导入功能 测试")
|
||||
@PostMapping("/importSarBussionessStandFile2")
|
||||
public ResponseMessage<SarBussionessStand> importSarBussionessStandFile2(@RequestParam(value = "file",required = false)MultipartFile file) throws Exception{
|
||||
sarBussionessStandEOService.importSarBussionessStandFile2(file);
|
||||
return Result.success();
|
||||
|
||||
sarBussionessStandEOService.importSarBussionessStandFile2(file);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+35
-8
@@ -3,6 +3,7 @@ package com.adc.da.slrs.sarBussionessStand.service.impl;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.adc.da.att.entity.AttFileEO;
|
||||
import com.adc.da.att.service.IAttFileEOService;
|
||||
import com.adc.da.att.vo.AttFileVo;
|
||||
import com.adc.da.common.*;
|
||||
import com.adc.da.http.ResponseMessage;
|
||||
import com.adc.da.http.Result;
|
||||
@@ -1986,6 +1987,9 @@ public class SarBussionessStandServiceImpl extends ServiceImpl<SarBussionessStan
|
||||
*/
|
||||
@Override
|
||||
public ResponseMessage<SarBussionessStand> importSarBussionessStandFile2(MultipartFile file) throws Exception {
|
||||
//给出头部信息
|
||||
String[] headerExcel = {"企标编号,中文名称,英文名称,文本状态,发布日期,企标实施日期,企标制修订状态,起草部门,废止日期,代替企标编号,复审日期,起草人,被代替企标编号,采用标准,文件上传人员,采标程度,引用标准,适用车型,能源类型,适用产品线,上传时间,体系类别,备案日期,关联模块-乘用车VPPS编码,关联模块--乘用车vpps中文名称,关联模块--卡车VPPS编码,关联模块--卡车vpps中文名称,附件,"};
|
||||
|
||||
//获取文件全称
|
||||
String fileNameStr = file.getOriginalFilename();
|
||||
//获取最后.的位置
|
||||
@@ -2017,14 +2021,17 @@ public class SarBussionessStandServiceImpl extends ServiceImpl<SarBussionessStan
|
||||
if (fileList.size() < 1){
|
||||
return Result.error("上传的文件是空文件");
|
||||
}
|
||||
File excelfile = fileList.get(0);
|
||||
if (excelfile.getName().contains(".xls") || excelfile.getName().contains("xlsx")) {
|
||||
for (File file1 : fileList){
|
||||
excelfile = file1;
|
||||
}
|
||||
//File excelfile = fileList.get(0);
|
||||
int excel = 0;
|
||||
for (File fileInfo:fileList){
|
||||
if (fileInfo.getName().contains(".xls") || fileInfo.getName().contains(".xlsx")) {
|
||||
excel =excel+1;
|
||||
if (excel > 1){
|
||||
return Result.error("导入了多个Excel文件");
|
||||
}
|
||||
Workbook workbook = null;
|
||||
try {
|
||||
workbook = WorkbookFactory.create(excelfile);
|
||||
workbook = WorkbookFactory.create(fileInfo);
|
||||
List<Map<String, String>> dataList = new ArrayList<>();
|
||||
if (workbook != null){
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
@@ -2038,7 +2045,26 @@ public class SarBussionessStandServiceImpl extends ServiceImpl<SarBussionessStan
|
||||
Row row = sheet.getRow(i);
|
||||
Row headerRow = sheet.getRow(0);
|
||||
boolean isBlank = sarLawsInfoEOService.isRowEmpty(row);
|
||||
String s = "";
|
||||
if (row != null && !isBlank) {
|
||||
if (i != 0){
|
||||
SarBussStandAttrInfo sarBussStandAttrInfo = new SarBussStandAttrInfo();
|
||||
String str = "";
|
||||
String[] split = str.split(",");
|
||||
if (split.length != 0){
|
||||
for (int j = 0;j < split.length;j++){
|
||||
File files = new File("/");
|
||||
AttFileVo attFileVo = attFileEOService.saveFileInfo(files);
|
||||
if (StringUtils.isNotBlank(s)){
|
||||
s = "," + attFileVo.getAttId();
|
||||
}else {
|
||||
s = attFileVo.getAttId();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
int columNos = headerRow.getLastCellNum();// 表头总共的列数
|
||||
Map<String, String> rowList = new LinkedHashMap<>();
|
||||
for (int j = 0; j < columNos; j++) {
|
||||
@@ -2068,7 +2094,7 @@ public class SarBussionessStandServiceImpl extends ServiceImpl<SarBussionessStan
|
||||
}
|
||||
}
|
||||
}
|
||||
String fields = FieldConvertUtil.exportBaseFieldNamesBuss + "," + FieldConvertUtil.exportBaseFieldNamesBussCode + ",";
|
||||
String fields = StringUtils.join(headerExcel);
|
||||
String excelHeader = sb.toString();
|
||||
if (!fields.equals(excelHeader)) {
|
||||
workbook.close();
|
||||
@@ -2088,8 +2114,9 @@ public class SarBussionessStandServiceImpl extends ServiceImpl<SarBussionessStan
|
||||
}
|
||||
|
||||
}else {
|
||||
Result.error("您上传的文件中没有Excel文件");
|
||||
Result.error("请上传Excel文件");
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
Result.error("导入失败,没有可导入的数据,请检查!");
|
||||
|
||||
Reference in New Issue
Block a user