| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.SoftwareMapper; |
| | | import com.whyc.pojo.Software; |
| | | import org.apache.poi.openxml4j.exceptions.InvalidFormatException; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.IOException; |
| | |
| | | @Autowired |
| | | private SoftwareMapper mapper; |
| | | |
| | | public List<Software> excelParse(InputStream inputStream) throws IOException, InvalidFormatException { |
| | | public List<Software> excelParse(InputStream inputStream) throws IOException, InvalidFormatException, ParseException { |
| | | List<Software> softwareList = new LinkedList<>(); |
| | | |
| | | Workbook workbook = null; |
| | |
| | | common.setFileName(sheet.getRow(2).getCell(2).getStringCellValue()); |
| | | String typeStr = sheet.getRow(3).getCell(2).getStringCellValue(); |
| | | String[] typeArr = typeStr.split(" "); |
| | | for (int i = 0; i < typeArr.length; i++) { |
| | | //excel单元格中的✔对应字符 |
| | | if(typeArr[i].contains("þ")){ |
| | | common.setType(typeArr[i].trim()); |
| | | break; |
| | | } |
| | | } |
| | | common.setVersion(sheet.getRow(4).getCell(2).getStringCellValue()); |
| | | common.setBasedVersion(sheet.getRow(4).getCell(4).getStringCellValue()); |
| | | |
| | | common.setOwner(sheet.getRow(5).getCell(2).getStringCellValue()); |
| | | String filingDateStr = sheet.getRow(5).getCell(4).getStringCellValue(); |
| | | Date filingDate = DateUtil.YYYY_MM_DD.parse(filingDateStr); |
| | | common.setFilingDate(filingDate); |
| | | //最后一行,取发布说明 |
| | | common.setReleaseNotes(sheet.getRow(lastRowNum).getCell(2).getStringCellValue()); |
| | | |
| | | //第8行开始,倒数第2行截止 |
| | | for (int i = 0; i < lastRowNum+1; i++) { |
| | | int applyModelNum = lastRowNum + 1 - 8; |
| | | for (int i = 0; i < applyModelNum; i++) { |
| | | Software software = new Software(); |
| | | BeanUtils.copyProperties(common,software); |
| | | //取第3列,第5列 |
| | | for (int j = 1; j < cellNum; j++) { |
| | | Row row = sheet.getRow(i); |
| | | Cell cell = row.getCell(j); |
| | | if(j == 2){ |
| | | cell.setCellType(Cell.CELL_TYPE_STRING); |
| | | } |
| | | String cellValue = cell.getStringCellValue(); |
| | | software.setApplyMaterialCode(sheet.getRow(8+i).getCell(2).getStringCellValue()); |
| | | software.setApplyModel(sheet.getRow(8+i).getCell(4).getStringCellValue()); |
| | | |
| | | switch (j){ |
| | | |
| | | } |
| | | } |
| | | softwareList.add(software); |
| | | } |
| | | |
| | | softwareList = softwareList.stream().filter(software -> !software.getApplyMaterialCode().equals("")).collect(Collectors.toList()); |
| | | |
| | | return softwareList; |
| | | |
| | | } |