老数据 读取
This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
||||
package com.adc.da.slrs.ImportExcelDatas.controller;
|
||||
|
||||
import com.adc.da.base.web.BaseController;
|
||||
import com.adc.da.http.ResponseMessage;
|
||||
import com.adc.da.slrs.ImportExcelDatas.entity.ImportDto;
|
||||
import com.adc.da.slrs.ImportExcelDatas.service.ImportExcelService;
|
||||
import com.adc.da.slrs.ImportExcelDatas.service.impl.ImportExcelServiceImpl;
|
||||
import com.adc.da.slrs.sarPersonalCenter.entity.SarUserStar;
|
||||
import com.adc.da.slrs.sarPersonalCenter.entity.SarUserStarEO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@Api(description = "|SarStandPutTime|")
|
||||
@RequestMapping("/ImportExcel")
|
||||
public class ImportExcelController extends BaseController<ImportDto> {
|
||||
|
||||
@Autowired
|
||||
private ImportExcelService importExcelService;
|
||||
|
||||
@ApiOperation("批量删除用户收藏")
|
||||
@PostMapping("/import")
|
||||
public ResponseMessage<Boolean> deleteList(MultipartFile file,MultipartFile file2) {
|
||||
Map<String, List<ImportDto>> mapMap=importExcelService.getExcelData(file,file2);
|
||||
ResponseMessage responseMessage=new ResponseMessage();
|
||||
responseMessage.setMessage(mapMap.toString());
|
||||
responseMessage.isOk();
|
||||
return responseMessage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.adc.da.slrs.ImportExcelDatas.dao;
|
||||
|
||||
import com.adc.da.slrs.ImportExcelDatas.entity.ImportDto;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ImportExcelDao extends BaseMapper<ImportDto> {
|
||||
|
||||
Map<String,Map<String, List<ImportDto>>> getExcelData(MultipartFile file);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.adc.da.slrs.ImportExcelDatas.entity;
|
||||
|
||||
import com.adc.da.base.entity.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ImportDto extends BaseEntity {
|
||||
|
||||
// 标准号
|
||||
private String standId;
|
||||
// 标准名称
|
||||
private String standName;
|
||||
// 英文名称
|
||||
private String standNameEN;
|
||||
// 发布时间
|
||||
private String publishTime;
|
||||
// 实施时间
|
||||
private String implementedTime;
|
||||
// 标准状态
|
||||
private String standStatus;
|
||||
// 代替标准号
|
||||
private String replaceId;
|
||||
// 附件路径
|
||||
private String path;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.adc.da.slrs.ImportExcelDatas.service;
|
||||
|
||||
import com.adc.da.slrs.ImportExcelDatas.entity.ImportDto;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ImportExcelService extends IService<ImportDto> {
|
||||
|
||||
Map<String, List<ImportDto>> getExcelData(MultipartFile file,MultipartFile file2);
|
||||
|
||||
}
|
||||
+230
@@ -0,0 +1,230 @@
|
||||
package com.adc.da.slrs.ImportExcelDatas.service.impl;
|
||||
|
||||
import com.adc.da.slrs.ImportExcelDatas.dao.ImportExcelDao;
|
||||
import com.adc.da.slrs.ImportExcelDatas.entity.ImportDto;
|
||||
import com.adc.da.slrs.ImportExcelDatas.service.ImportExcelService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDto> implements ImportExcelService {
|
||||
|
||||
|
||||
private final static String GN = "GB,GB/T,QC/T,GJB,JB,JT,HG,YV,SY,SH,GA,HJ,QB,JG,NB,JC,YS/T,FZ/T,TB/T,JJG,SJ/T,T/TBPS" +
|
||||
",NB/T,CJ/T,YS/T,SJ/T,BB/T,SN/T,SB/T,MH/T,DB11,SZDB/Z,HKG,T/ZSA,CSAE,T/CAS,T/CADA,T/CHTS,T/ITS,T/BJQC";
|
||||
private final static String QB = "Q/QCBFC,Q/FT,Q/FL,Q/QCFLC,Q/BQB,Q/SGT," +
|
||||
"Q-AMSN,QB-NE,Q-IOUM,Q房/AYJ,KNT";
|
||||
private final static String DATE = "-2008,—2008,-2009,—2009,-2010,—2010,-2011,—2011,-2012,—2012,-2013,—2013," +
|
||||
"- 2008,— 2008,- 2009,— 2009,- 2010,— 2010,- 2011,— 2011,- 2012,— 2012,- 2013,— 2013" +
|
||||
",-2014,—2014,-2015,—2015,-2016,—2016,-2017,—2017,-2018,—2018,-2019,—2019,-2020,—2020,-2021,—2021" +
|
||||
",- 2014,— 2014,- 2015,— 2015,- 2016,— 2016,- 2017,— 2017,- 2018,— 2018,- 2019,— 2019,- 2020,— 2020,- 2021,— 2021";
|
||||
|
||||
|
||||
// file 为主 file2 为附件
|
||||
@Override
|
||||
public Map<String, List<ImportDto>> getExcelData(MultipartFile file, MultipartFile file2) {
|
||||
|
||||
if (file == null || file.getSize() == 0) {
|
||||
log.error("文件上传错误,重新上传");
|
||||
}
|
||||
String filename = file.getOriginalFilename();
|
||||
if (!(filename.endsWith(".xls") || filename.endsWith(".xlsx"))) {
|
||||
log.error("文件上传格式错误,请重新上传");
|
||||
}
|
||||
|
||||
if (file2 == null || file2.getSize() == 0) {
|
||||
log.error("文件上传错误,重新上传");
|
||||
}
|
||||
String filename2 = file2.getOriginalFilename();
|
||||
if (!(filename2.endsWith(".xls") || filename2.endsWith(".xlsx"))) {
|
||||
log.error("文件上传格式错误,请重新上传");
|
||||
}
|
||||
|
||||
List<String> datas = new ArrayList<>();
|
||||
List<String> fujian = new ArrayList<>();
|
||||
try {
|
||||
if (filename.endsWith(".xls")) {
|
||||
datas = isXls(file);
|
||||
} else {
|
||||
datas = isXlsx(file);
|
||||
}
|
||||
|
||||
if (filename2.endsWith(".xls")) {
|
||||
fujian = isXls(file2);
|
||||
} else {
|
||||
fujian = isXlsx(file2);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
Map<String, List<ImportDto>> res = new HashMap<>();
|
||||
// 国内标准
|
||||
List<String> GNS = new ArrayList<>(Arrays.asList(GN.split(",")));
|
||||
// 企业标准
|
||||
List<String> QBS = new ArrayList<>(Arrays.asList(QB.split(",")));
|
||||
//处理数据
|
||||
List<ImportDto> InCountry = new ArrayList<>();
|
||||
List<ImportDto> OutCountry = new ArrayList<>();
|
||||
List<ImportDto> QiBiao = new ArrayList<>();
|
||||
List<ImportDto> error = new ArrayList<>();
|
||||
//中间的Map 判断标准号属于哪种类型
|
||||
Map<String, String> middle = new HashMap<>();
|
||||
datas.forEach(items -> {
|
||||
//判断是否是正确的数据
|
||||
String[] as = items.split(",");
|
||||
if (!inDate(as[0])) {
|
||||
ImportDto importDto = getImportDto(as);
|
||||
error.add(importDto);
|
||||
middle.put(as[0].trim(), "error-"+error.size());
|
||||
} else {
|
||||
//数据二次拆解 针对标准进行拆解
|
||||
String[] step2 = as[0].trim().split(" ");
|
||||
// 是否国内? 企标 ? 海外
|
||||
if (isCheck(GNS, step2[0].trim())) {
|
||||
ImportDto importDto = getImportDto(as);
|
||||
InCountry.add(importDto);
|
||||
middle.put(as[0].trim(), "GNBZ-"+InCountry.size());
|
||||
} else if (isCheck(QBS, step2[0].trim())) {
|
||||
ImportDto importDto = getImportDto(as);
|
||||
QiBiao.add(importDto);
|
||||
middle.put(as[0].trim(), "QYBZ-"+QiBiao.size());
|
||||
} else {
|
||||
ImportDto importDto = getImportDto(as);
|
||||
OutCountry.add(importDto);
|
||||
middle.put(as[0].trim(), "HWBZ-"+OutCountry.size());
|
||||
}
|
||||
}
|
||||
});
|
||||
res.put("error", error);
|
||||
res.put("GNBZ", InCountry);
|
||||
res.put("QYBZ", QiBiao);
|
||||
res.put("HWBZ", OutCountry);
|
||||
|
||||
fujian.forEach(items2 ->{
|
||||
String[] fj=items2.split(",");
|
||||
if (fj.length>2) {
|
||||
if (null != middle.get(null != fj[2] ? fj[2].trim() : "")) {
|
||||
//对应数据位置
|
||||
String[] location = middle.get(fj[2].trim()).split("-");
|
||||
res.get(location[0]).get(Integer.parseInt(location[1])-1).setPath(fj[3]);
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private boolean inDate(String as) {
|
||||
List<String> dates = new ArrayList<>(Arrays.asList(DATE.split(",")));
|
||||
if (null != as && !"".equals(as)) {
|
||||
for (String s : dates) {
|
||||
if (s.equals(as.trim())) {
|
||||
return true;
|
||||
} else if (as.trim().contains(s)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private boolean isCheck(List<String> QB, String item) {
|
||||
for (String s : QB) {
|
||||
if (s.equals(item)) {
|
||||
return true;
|
||||
} else if (item.contains(s) && item.startsWith(s)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//赋值方法
|
||||
private ImportDto getImportDto(String[] as) {
|
||||
ImportDto importDto = new ImportDto();
|
||||
if (as.length == 7) {
|
||||
importDto.setStandId(null != as[0] ? as[0].trim() : "");
|
||||
importDto.setStandName(null != as[1] ? as[1].trim() : "");
|
||||
importDto.setStandNameEN(null != as[2] ? as[2].trim() : "");
|
||||
importDto.setPublishTime(null != as[3] ? as[3].trim() : "");
|
||||
importDto.setImplementedTime(null != as[4] ? as[4].trim() : "");
|
||||
importDto.setStandStatus(null != as[5] ? as[5].trim() : "");
|
||||
importDto.setReplaceId(null != as[6] ? as[6].trim() : "");
|
||||
} else if (as.length == 6) {
|
||||
importDto.setStandId(null != as[0] ? as[0].trim() : "");
|
||||
importDto.setStandName(null != as[1] ? as[1].trim() : "");
|
||||
importDto.setStandNameEN(null != as[2] ? as[2].trim() : "");
|
||||
importDto.setPublishTime(null != as[3] ? as[3].trim() : "");
|
||||
importDto.setImplementedTime(null != as[4] ? as[4].trim() : "");
|
||||
importDto.setStandStatus(null != as[5] ? as[5].trim() : "");
|
||||
importDto.setReplaceId("");
|
||||
}
|
||||
return importDto;
|
||||
}
|
||||
|
||||
|
||||
private List<String> isXls(MultipartFile multipartFile) {
|
||||
List<String> strings = new ArrayList<>();
|
||||
try {
|
||||
InputStream inputStream = multipartFile.getInputStream();
|
||||
HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
|
||||
// 读取有多少页
|
||||
int sheetNum = workbook.getNumberOfSheets();
|
||||
// 遍历sheet页
|
||||
for (int i = 0; i < sheetNum; i++) {
|
||||
HSSFSheet sheet = workbook.getSheetAt(i);
|
||||
// 获取有多少行
|
||||
int lastNum = sheet.getLastRowNum();
|
||||
for (int j = 1; j <= lastNum; j++) {
|
||||
HSSFRow row = sheet.getRow(j);
|
||||
if (null != row) {
|
||||
strings.add(row.getCell(0).getStringCellValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return strings;
|
||||
}
|
||||
|
||||
private List<String> isXlsx(MultipartFile multipartFile) {
|
||||
List<String> strings = new ArrayList<>();
|
||||
try {
|
||||
InputStream inputStream = multipartFile.getInputStream();
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
|
||||
// 读取有多少页
|
||||
int sheetNum = workbook.getNumberOfSheets();
|
||||
// 遍历sheet页
|
||||
for (int i = 0; i <= sheetNum; i++) {
|
||||
XSSFSheet sheet = workbook.getSheetAt(i);
|
||||
// 获取有多少行
|
||||
int lastNum = sheet.getLastRowNum();
|
||||
for (int j = 1; j <= lastNum; j++) {
|
||||
XSSFRow row = sheet.getRow(j);
|
||||
if (null != row) {
|
||||
strings.add(row.getCell(0).getStringCellValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return strings;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user