whycxzp
2022-09-09 db95f1a014aae02f59f3e8a95a576e5ac7964c5b
src/main/java/com/whyc/service/SoftwareService.java
@@ -40,7 +40,7 @@
    @Autowired
    private DocLogService logService;
    public List<Software> excelParse(InputStream inputStream) throws IOException, InvalidFormatException, ParseException {
    public Response<Object> excelParse(InputStream inputStream) throws IOException, InvalidFormatException, ParseException {
        List<Software> softwareList = new LinkedList<>();
        Workbook workbook = null;
@@ -54,7 +54,11 @@
        //取固定部分值
        Software common = new Software();
        common.setFileName(sheet.getRow(2).getCell(2).getStringCellValue());
        String typeStr = sheet.getRow(3).getCell(2).getStringCellValue();
        Cell cellBoardNumber = sheet.getRow(3).getCell(2);
        if(cellBoardNumber != null){
            common.setBoardNumber(cellBoardNumber.getStringCellValue());
        }
        String typeStr = sheet.getRow(4).getCell(2).getStringCellValue();
        String[] typeArr = typeStr.split(" ");
        for (int i = 0; i < typeArr.length; i++) {
            //excel单元格中的✔对应字符
@@ -63,31 +67,37 @@
                break;
            }
        }
        common.setVersion(sheet.getRow(4).getCell(2).getStringCellValue());
        common.setBasedVersion(sheet.getRow(4).getCell(4).getStringCellValue());
        //检验
        if(!common.getType().equals("应用软件")){
            if(common.getBoardNumber() == null){
                return new Response().set(1,false,"当是BootLoader 软件、操作系统软件(核心板)软件时,需填写PCB的规格型号");
            }
        }
        common.setVersion(sheet.getRow(5).getCell(2).getStringCellValue());
        common.setBasedVersion(sheet.getRow(5).getCell(4).getStringCellValue());
        common.setOwner(sheet.getRow(5).getCell(2).getStringCellValue());
        common.setFilingDate(sheet.getRow(5).getCell(4).getStringCellValue());
        common.setOwner(sheet.getRow(6).getCell(2).getStringCellValue());
        common.setFilingDate(sheet.getRow(6).getCell(4).getStringCellValue());
        //最后一行,取发布说明
        common.setReleaseNotes(sheet.getRow(lastRowNum).getCell(2).getStringCellValue());
        //第8行开始,倒数第2行截止
        int applyModelNum = lastRowNum + 1 - 8;
        //第9行开始,倒数第2行截止
        int applyModelNum = lastRowNum + 1 - 9;
        for (int i = 0; i < applyModelNum; i++) {
            Software software = new Software();
            BeanUtils.copyProperties(common,software);
            //取第3列,第5列
            Cell cell = sheet.getRow(7 + i).getCell(2);
            Cell cell = sheet.getRow(8 + i).getCell(2);
            cell.setCellType(Cell.CELL_TYPE_STRING);
            software.setApplyMaterialCode(cell.getStringCellValue());
            software.setApplyModel(sheet.getRow(7+i).getCell(4).getStringCellValue());
            software.setApplyModel(sheet.getRow(8+i).getCell(4).getStringCellValue());
            softwareList.add(software);
        }
        softwareList = softwareList.stream().filter(software -> !software.getApplyMaterialCode().equals("")).collect(Collectors.toList());
        return softwareList;
        return new Response().setII(1,true,softwareList,"文件解析成功");
    }
    //查询软件列表的信息
@@ -145,6 +155,9 @@
        String file1Name = file1.getOriginalFilename();
        String file2Name = file2.getOriginalFilename();
        Software software = softwareList.get(0);
        if(!software.getFileName().equals(file1Name.substring(0,file1Name.lastIndexOf(".")))){
            return new Response().set(1,false,"附件的文件名与软件发布记录excel内的文件名称不一致");
        }
        Date date = new Date();
        String dateUnion = DateUtil.YYYY_MM_DD_HH_MM_SS_UNION.format(date);
        //文件重命名
@@ -168,7 +181,7 @@
        }
        //写入数据库
        insertBatch(softwareList);
        return new Response().setII(1,"上传完成");
        return new Response().set(1,true,"上传完成");
    }
    private void insertBatch(List<Software> softwareList){