| | |
| | | import com.kidgrow.common.model.PageResult; |
| | | import com.kidgrow.common.model.ResultBody; |
| | | import com.kidgrow.common.utils.DateUtil; |
| | | import com.kidgrow.common.utils.MultipartFileUtils; |
| | | import com.kidgrow.common.utils.RandomValueUtils; |
| | | import com.kidgrow.common.utils.StringUtils; |
| | | import com.kidgrow.filecenter.mapper.FileMapper; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import net.coobird.thumbnailator.Thumbnails; |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import sun.misc.BASE64Decoder; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import sun.misc.BASE64Encoder; |
| | | |
| | | import java.io.*; |
| | |
| | | |
| | | @Value("${kidgrow.file-server.oss.domain}") |
| | | private String DOMAIN; |
| | | @Value("${spring.profiles.active}") |
| | | private String OssPathEn; |
| | | @Override |
| | | public FileInfo upload(MultipartFile file) throws Exception { |
| | | FileInfo fileInfo = FileUtil.getFileInfo(file); |
| | |
| | | */ |
| | | protected abstract void uploadFile(MultipartFile file, FileInfo fileInfo) throws Exception; |
| | | protected abstract void fileUpLoadOss(FileInfo fileInfo,String newFilePath, InputStream fileStream); |
| | | protected abstract String FilePath(String imgType,String folderByDate); |
| | | protected abstract String FilePath(String imgType,String folderByDate,String hospitalId,String departmentId); |
| | | protected abstract OSSObject down(String url); |
| | | |
| | | /** |
| | |
| | | //将生成的文件转换为流 |
| | | InputStream inputStream=new FileInputStream(thuFile); |
| | | String folderByDate = DateUtil.formatDate(new Date()); |
| | | String filefloder=this.FilePath(imgType,folderByDate); |
| | | String filefloder=this.FilePath(imgType,folderByDate,null,null); |
| | | FileInfo newfileInfo=new FileInfo(); |
| | | newfileInfo.setName(newFileName); |
| | | newfileInfo.setId(IdUtil.fastSimpleUUID()); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public FileInfo baseUplaod(String file, String imgType) { |
| | | public FileInfo baseUplaod(String file, String imgType, String hospitalId, String departmentId) { |
| | | if(file==null||"".equals(file.trim())){ |
| | | return null; |
| | | } |
| | |
| | | newfileInfo.setSource("aliyun"); |
| | | newfileInfo.setImgType(imgType); |
| | | newfileInfo.setCreateTime(new Date()); |
| | | this.fileUpLoadOss(newfileInfo,"HospitalLogo/"+newFileName,input); |
| | | String folderByDate =DateUtil.formatDate(new Date()); |
| | | String filePath = FilePath(imgType, folderByDate, hospitalId, departmentId); |
| | | this.fileUpLoadOss(newfileInfo,filePath+newFileName,input); |
| | | input.close(); |
| | | baseMapper.insert(newfileInfo); |
| | | return newfileInfo; |
| | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public FileInfo byteUplaod(String fileName, InputStream inputStream,int size) { |
| | | String houzhui=fileName.substring(fileName.lastIndexOf(".")+1); |
| | | String newFileName= RandomValueUtils.uuid()+"."+houzhui; |
| | | FileInfo newfileInfo=new FileInfo(); |
| | | newfileInfo.setName(newFileName); |
| | | newfileInfo.setId(IdUtil.fastSimpleUUID()); |
| | | newfileInfo.setSize(size); |
| | | newfileInfo.setIsImg(false); |
| | | newfileInfo.setContentType("byte[]"); |
| | | newfileInfo.setSource("aliyun"); |
| | | newfileInfo.setImgType(houzhui); |
| | | newfileInfo.setCreateTime(new Date()); |
| | | this.fileUpLoadOss(newfileInfo,OssPathEn+"pdf/"+newFileName,inputStream); |
| | | baseMapper.insert(newfileInfo); |
| | | return newfileInfo; |
| | | } |
| | | |
| | | @Override |
| | | public FileInfo feignUploadHosIdAndDepId(MultipartFile file, String imgType, String hospitalId, String departmentId) throws Exception { |
| | | List<String> lassStr= Arrays.asList("png","bmp","dib","gif","jfif","jpe","jpeg","jpg","tif","tiff","ico"); |
| | | String suffix=file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1); |
| | | if(!lassStr.contains(suffix)){ |
| | | return null; |
| | | } |
| | | String name = file.getOriginalFilename(); |
| | | String fileName= UUID.randomUUID().toString().replaceAll("-",""); |
| | | //image/jpeg;base64 |
| | | String newFileName=fileName+name.substring(name.lastIndexOf(".")); |
| | | FileInfo newfileInfo=new FileInfo(); |
| | | newfileInfo.setName(newFileName); |
| | | newfileInfo.setId(IdUtil.fastSimpleUUID()); |
| | | newfileInfo.setSize(file.getSize()); |
| | | newfileInfo.setIsImg(true); |
| | | newfileInfo.setContentType("image/jpeg"); |
| | | newfileInfo.setSource("aliyun"); |
| | | newfileInfo.setImgType(imgType); |
| | | newfileInfo.setCreateTime(new Date()); |
| | | String folderByDate =DateUtil.formatDate(new Date()); |
| | | String filePath = FilePath(imgType, folderByDate, hospitalId, departmentId); |
| | | InputStream inputStream = file.getInputStream(); |
| | | this.fileUpLoadOss(newfileInfo,filePath+newFileName,inputStream); |
| | | inputStream.close(); |
| | | baseMapper.insert(newfileInfo); |
| | | return newfileInfo; |
| | | } |
| | | } |
| | | |