| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | 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; |
| | | import com.whyc.mapper.SoftwareMapper; |
| | | import com.whyc.pojo.AttachLock; |
| | | import com.whyc.pojo.DocUser; |
| | | import com.whyc.pojo.Software; |
| | | import com.whyc.util.ActionUtil; |
| | |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | @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, String boardNumber,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); |
| | | List list=mapper.getFileUrl(fileName,applyMaterialCode,applyModel,owner,boardNumber); |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().setII(1,list.size()>0,pageInfo,"软件信息返回"); |
| | | } |
| | |
| | | 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内的文件名称不一致"); |
| | | } |
| | | Software softExists = getByFilename(software.getFileName()); |
| | | if(softExists != null){ //文件名:规格型号_软件版本,已存在,不能重复上传;这种情况属于追加机型,别处更新 |
| | | return new Response().set(1,false,"文件名称("+softExists.getFileName()+")已存在,不能重复上传"); |
| | | } |
| | | Date date = new Date(); |
| | | String dateUnion = DateUtil.YYYY_MM_DD_HH_MM_SS_UNION.format(date); |
| | | //文件重命名 |
| | | file1Name = file1Name.substring(0,file1Name.lastIndexOf(".")) + "_" + dateUnion +file1Name.substring(file1Name.lastIndexOf(".")); |
| | | file2Name = file2Name.substring(0,file2Name.lastIndexOf(".")) + "_" + dateUnion +file2Name.substring(file2Name.lastIndexOf(".")); |
| | | //文件重命名(暂不需要,严格遵守名称规则的情况下不会重名) |
| | | //file1Name = file1Name.substring(0,file1Name.lastIndexOf(".")) + "_" + dateUnion +file1Name.substring(file1Name.lastIndexOf(".")); |
| | | //file2Name = file2Name.substring(0,file2Name.lastIndexOf(".")) + "_" + dateUnion +file2Name.substring(file2Name.lastIndexOf(".")); |
| | | //存储路径 |
| | | String rootFile = CommonUtil.getRootFile(); |
| | | String softwareDir = rootFile + "software" + File.separator + software.getOwner(); |
| | | String softwareDir = rootFile + "software" + File.separator + software.getOwner()+ File.separator + software.getFileName(); |
| | | String softwareHttpUrl = softwareDir.substring(softwareDir.lastIndexOf("doc_file"+ File.separator + "software")); |
| | | File softwareDirFile = new File(softwareDir); |
| | | if(!softwareDirFile.exists()){ |
| | |
| | | } |
| | | //写入数据库 |
| | | insertBatch(softwareList); |
| | | return new Response().setII(1,"上传完成"); |
| | | return new Response().set(1,true,"上传完成"); |
| | | } |
| | | |
| | | private Software getByFilename(String fileName) { |
| | | QueryWrapper<Software> query = Wrappers.query(); |
| | | query.eq("file_name",fileName).last(" limit 1"); |
| | | return mapper.selectOne(query); |
| | | } |
| | | |
| | | private void insertBatch(List<Software> softwareList){ |
| | | mapper.insertBatchSomeColumn(softwareList); |
| | | } |
| | | |
| | | @Transactional |
| | | public Response updateApplyModel(MultipartFile multipartFile, List<Software> softwareList) throws IOException { |
| | | String originalFilename = multipartFile.getOriginalFilename(); |
| | | Software software = softwareList.get(0); |
| | | QueryWrapper<Software> query = Wrappers.query(); |
| | | query.eq("file_name", software.getFileName()).last(" limit 1"); |
| | | Software softwareDB = mapper.selectOne(query); |
| | | if(softwareDB == null){ |
| | | return new Response().set(1,false,"对应的软件并未上传过,无法更新适用机型"); |
| | | }else{ |
| | | //写入新增的软件发布记录excel |
| | | String rootFile = CommonUtil.getRootFile(); |
| | | String softwareDir = rootFile + "software" + File.separator + software.getOwner()+ File.separator + software.getFileName(); |
| | | String softwareHttpUrl = softwareDir.substring(softwareDir.lastIndexOf("doc_file"+ File.separator + "software")); |
| | | multipartFile.transferTo(new File(softwareDir + File.separator + originalFilename)); |
| | | //先删除对应的适用机型,再新增适用机型记录 |
| | | UpdateWrapper<Software> update = Wrappers.update(); |
| | | update.eq("file_name",softwareDB.getFileName()); |
| | | mapper.delete(update); |
| | | softwareList.forEach(software2 -> { |
| | | software2.setFileUrl(softwareDB.getFileUrl()); |
| | | software2.setExcelUrl(softwareHttpUrl + File.separator + originalFilename); |
| | | software2.setCreateTime(new Date()); |
| | | }); |
| | | mapper.insertBatchSomeColumn(softwareList); |
| | | |
| | | return new Response().set(1,true,"更新完成"); |
| | | } |
| | | } |
| | | //根据软件id修改软件锁定状态 |
| | | public Response updateSoftwareLock(String fileUrl,int lockFlag,String localReason) { |
| | | UpdateWrapper uwrapper=new UpdateWrapper(); |
| | | uwrapper.set("lock_flag",lockFlag); |
| | | uwrapper.set("local_reason",localReason); |
| | | uwrapper.eq("file_url",fileUrl); |
| | | int flag=mapper.update(null,uwrapper); |
| | | return new Response().set(1,flag>0,"锁定/解锁成功"); |
| | | } |
| | | } |