| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.constant.UserOperation; |
| | | import com.whyc.dto.FileDirPath; |
| | | import com.whyc.dto.Response; |
| | |
| | | @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; |
| | |
| | | //取固定部分值 |
| | | 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单元格中的✔对应字符 |
| | |
| | | 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,"文件解析成功"); |
| | | |
| | | } |
| | | //查询软件列表的信息 |
| | | public Response getAllSoftware(String fileName, int pageCurr, int pageSize) { |
| | | public Response getAllSoftware(String fileName,String applyMaterialCode,String applyModel,String owner, 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,"软件信息返回"); |
| | | List list=mapper.getFileUrl(fileName,applyMaterialCode,applyModel,owner); |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().setII(1,list.size()>0,pageInfo,"软件信息返回"); |
| | | } |
| | | //根据subcode查询软件列表 |
| | | public Response getSoftBySubCode(String subCode) { |
| | |
| | | try { |
| | | // 转码防止乱码 |
| | | //resp.addHeader("Content-Disposition", "attachment;filename=" + new String(softwareName.getBytes("UTF-8"), "ISO8859-1")); |
| | | resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode ( software.getFileName(), "utf-8")); |
| | | resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode ( software.getFileName()+".zip", "utf-8")); |
| | | OutputStream out = resp.getOutputStream(); |
| | | FileInputStream in = new FileInputStream(fileDirName+File.separator+software.getFileUrl()); |
| | | int len=0; |
| | |
| | | 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); |
| | | //文件重命名 |
| | |
| | | file2Name = file2Name.substring(0,file2Name.lastIndexOf(".")) + "_" + dateUnion +file2Name.substring(file2Name.lastIndexOf(".")); |
| | | //存储路径 |
| | | String rootFile = CommonUtil.getRootFile(); |
| | | String softwareDir = rootFile + software.getOwner() + File.separator + dateUnion; |
| | | String softwareDir = rootFile + "software" + File.separator + software.getOwner(); |
| | | String softwareHttpUrl = softwareDir.substring(softwareDir.lastIndexOf("doc_file"+ File.separator + "software")); |
| | | File softwareDirFile = new File(softwareDir); |
| | | if(!softwareDirFile.exists()){ |
| | | softwareDirFile.mkdirs(); |
| | |
| | | file1.transferTo(new File(softwareDir+File.separator+file1Name)); |
| | | file2.transferTo(new File(softwareDir+File.separator+file2Name)); |
| | | //设置路径 |
| | | softwareList.forEach(software1 -> { |
| | | software1.setFileUrl(softwareDir); |
| | | for (Software software1:softwareList){ |
| | | software1.setFileUrl(softwareHttpUrl+File.separator+file1Name); |
| | | software1.setExcelUrl(softwareHttpUrl+File.separator+file2Name); |
| | | software1.setCreateTime(date); |
| | | }); |
| | | } |
| | | //写入数据库 |
| | | insertBatch(softwareList); |
| | | return new Response().setII(1,"上传完成"); |
| | | return new Response().set(1,true,"上传完成"); |
| | | } |
| | | |
| | | private void insertBatch(List<Software> softwareList){ |