/** * Description: 获取日前交易excel数据 * * @param file * @return */ private Map<String,List<SpotDailyDealImportVO>> SpotDailyDealLoadExcelData(MultipartFile file){ Map<String,List<SpotDailyDealImportVO>> map = new HashMap<>(); try { //获取所有sheet页 List<ReadSheet> readSheets = ExcelImportHelper.listSheet(file.getInputStream()); List<ReadSheet> arrayList = readSheets.stream().collect( // 将集合先放到 treeSet去重,然后将他们转换成list collectingAndThen( toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getSheetName()))) , ArrayList::new)); if (arrayList.size() < readSheets.size()){ throw new BusinessException("存在相同机组名称!"); } if (ObjectUtils.isNotEmpty(readSheets)){ //读取数据 int i = 0;//从第一页开始读 for (ReadSheet readSheet : readSheets){ map.put(readSheet.getSheetName(),ExcelImportHelper.loadExcelDataFully( ExcelImportHelper.getExcelTypeByName(file.getOriginalFilename()), file.getInputStream(), i , MagicNumConstant.ONE, SpotDailyDealImportVO.class)); i++; } }else throw new BusinessException("无法获取到sheet页信息!"); } catch (IOException e) { log.error("error",e); throw new BusinessException("上传文件格式不正确" + e.getMessage()); } if (map.size() == 0){ throw new BusinessException("数据异常,没有数据!"); } return map; }
工具类
/* * Project Name: fsc * File Name: ExcelImportHelper.java * Class Name: ExcelImportHelper * * Copyright 2018 Hengtian Software Inc * * Licensed under the Hengtiansoft * * http://www.hengtiansoft.com * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KI