| | |
| | | if(file.getSize() == 0){ |
| | | throw new ServiceException("程序文件不可为空文件"); |
| | | } |
| | | if(exists(file.getOriginalFilename(),uploadVO.getProcessInstanceId())){ |
| | | throw new ServiceException("同名文件已存在:"+file.getOriginalFilename()); |
| | | } |
| | | |
| | | if(FlowProgramFile.TYPE_PROGRAM.equals(uploadVO.getFileType())) { |
| | | ProgramFileNameCheckUtil.checkFilename(file.getOriginalFilename(), progProps); |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 判断那流程下是否有同名问题 |
| | | * @param filename 文件名 |
| | | * @param processInstanceId 流程实例id |
| | | * @return 是否 |
| | | */ |
| | | boolean exists(String filename,String processInstanceId){ |
| | | return lambdaQuery().eq(FlowProgramFile::getName, filename).eq(FlowProgramFile::getProcessInstanceId, processInstanceId).count()>0; |
| | | } |
| | | /** |
| | | * 获取文件内容 |
| | | * @param id 文件id |
| | |
| | | String fileName = programFile.getOssName(); |
| | | try (InputStream inputStream = ossTemplate.statFileStream(fileName)) { |
| | | ByteArrayInputStream bos = new ByteArrayInputStream(inputStream.readAllBytes()); |
| | | boolean isText= FileContentUtil.isTextFile(bos); |
| | | boolean isText = StringUtils.endsWithIgnoreCase(fileName,".txt") || StringUtils.endsWithIgnoreCase(fileName,".nc")|| StringUtils.endsWithIgnoreCase(fileName,".xml"); |
| | | if(!isText){ |
| | | isText= FileContentUtil.isTextFile(bos); |
| | | } |
| | | if(isText){ |
| | | bos.reset(); |
| | | bos.reset(); |
| | | result = FileContentUtil.getContentFromStream(bos); |
| | | }else{ |
| | | result = "<非文本文件>"; |
| | |
| | | IOUtils.copy(ins,response.getOutputStream()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取关于流程的所有文件 |
| | | * @param processInstanceId 流程实例id |
| | | * @return 流程关联的文件列表 |
| | | */ |
| | | public List<FlowProgramFile> listByProcessInstanceId(String processInstanceId){ |
| | | return lambdaQuery() |
| | | .eq(FlowProgramFile::getProcessInstanceId, processInstanceId).list(); |
| | | } |
| | | } |