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;
|
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 {
|
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(" ");
|
|
//第8行开始,倒数第2行截止
|
for (int i = 0; i < lastRowNum+1; i++) {
|
Software software = new 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();
|
|
switch (j){
|
|
}
|
}
|
softwareList.add(software);
|
}
|
|
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,"软件信息返回");
|
}
|
}
|