whycxzp
2022-09-07 414d8e938349358b43e6ff485f7ca819d10b7a41
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.whyc.service;
 
import com.whyc.pojo.Software;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.springframework.stereotype.Service;
 
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;
 
@Service
public class SoftwareService {
    @Autowired
    private SoftwareMapper mapper;
 
    public List<Software> excelParse(InputStream inputStream) throws IOException, InvalidFormatException, ParseException {
        List<Software> softwareList = new LinkedList<>();
 
        Workbook workbook = null;
        workbook = WorkbookFactory.create(inputStream);
        inputStream.close();
        //取第一个sheet表
        Sheet sheet = workbook.getSheetAt(0);
        int lastRowNum = sheet.getLastRowNum();
        //固定5列
        short cellNum = 5;
        //取固定部分值
        Software common = new Software();
        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行截止
        int applyModelNum = lastRowNum + 1 - 8;
        for (int i = 0; i < applyModelNum; i++) {
            Software software = new Software();
            BeanUtils.copyProperties(common,software);
            //取第3列,第5列
            software.setApplyMaterialCode(sheet.getRow(8+i).getCell(2).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;
 
    }
    //查询软件列表的信息
    public Response getAllSoftware(String fileName, int pageCurr, int pageSize) {
        PageHelper.startPage(pageCurr,pageSize);
        QueryWrapper wrapper=new QueryWrapper();
        if(fileName!=null&&!fileName.isEmpty()){
            wrapper.like("file_name",fileName);
        }
        wrapper.orderByAsc("file_name");
        wrapper.orderByAsc("version");
        List list=mapper.selectList(wrapper);
        return new Response().setII(1,list.size()>0,list,"软件信息返回");
    }
    //根据subcode查询软件列表
    public Response getSoftBySubCode(String subCode) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("sub_code",subCode);
        wrapper.orderByAsc("version");
        List list=mapper.selectList(wrapper);
        return new Response().setII(1,list.size()>0,list,"软件信息返回");
    }
}