whycxzp
2022-09-07 414d8e938349358b43e6ff485f7ca819d10b7a41
软件excel解析
2个文件已修改
45 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/SoftwareController.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/SoftwareService.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/SoftwareController.java
@@ -12,6 +12,7 @@
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;
@Api(tags = "软件管理-新版")
@@ -24,7 +25,7 @@
    @ApiModelProperty("excel解析")
    @PostMapping("excelParse")
    public Response excelParse(@RequestParam MultipartFile multipartFile) throws IOException, InvalidFormatException {
    public Response excelParse(@RequestParam MultipartFile multipartFile) throws IOException, InvalidFormatException, ParseException {
        Response<Object> response = new Response<>();
        String name=multipartFile.getOriginalFilename();
        assert name != null;
src/main/java/com/whyc/service/SoftwareService.java
@@ -1,13 +1,8 @@
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;
@@ -20,7 +15,7 @@
    @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;
@@ -36,26 +31,37 @@
        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;
    }