whycxzp
2022-09-09 db95f1a014aae02f59f3e8a95a576e5ac7964c5b
更新
3个文件已修改
52 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/SoftwareController.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/Software.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/SoftwareService.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/SoftwareController.java
@@ -35,8 +35,7 @@
        if(!name.substring(name.length()-4).equals(".xls") && !name.substring(name.length()-5).equals(".xlsx")){
            response.set(1,false,"文件解析错误:上传格式非excel格式");
        }else{
            List<Software> list = service.excelParse(multipartFile.getInputStream());
            response.setII(1,true,list,"文件解析成功");
            response =  service.excelParse(multipartFile.getInputStream());
        }
        return response;
    }
src/main/java/com/whyc/pojo/Software.java
@@ -1,12 +1,10 @@
package com.whyc.pojo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import org.apache.ibatis.type.Alias;
import java.util.Date;
import java.util.List;
@TableName(schema = "db_doc",value = "tb_software")
@Alias("Software")
@@ -18,7 +16,8 @@
    private String fileName;
    private String fileUrl;
    private String excelUrl;
    @ApiModelProperty("版号")
    private String boardNumber;
    @ApiModelProperty("软件类型")
    private String type;
@@ -148,4 +147,11 @@
        this.excelUrl = excelUrl;
    }
    public String getBoardNumber() {
        return boardNumber;
    }
    public void setBoardNumber(String boardNumber) {
        this.boardNumber = boardNumber;
    }
}
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){