| | |
| | | import com.aliyun.oss.common.auth.DefaultCredentialProvider; |
| | | import com.kidgrow.common.constant.SecurityConstants; |
| | | import com.kidgrow.common.utils.DateUtil; |
| | | import com.kidgrow.common.utils.StringUtils; |
| | | import com.kidgrow.filecenter.model.FileInfo; |
| | | import com.kidgrow.filecenter.properties.FileServerProperties; |
| | | import com.kidgrow.filecenter.service.impl.AbstractIFileService; |
| | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.InputStream; |
| | | import java.util.Date; |
| | | import java.util.UUID; |
| | | |
| | |
| | | String fileName= UUID.randomUUID().toString().replaceAll("-","")+fileType; |
| | | String fileFolder = ""; |
| | | if(clientID.equals("hospital")){//医院端平台, |
| | | |
| | | if ((fileInfo.getImgType() != null)) { |
| | | // 光片需要按照根据医院ID,科室ID,日期进行OSS存储 |
| | | if (fileInfo.getImgType().toLowerCase().equals("xray")) { |
| | | String hospitalID = httpServletRequest.getHeader(SecurityConstants.USER_HOSPITAL_ID_HEADER); |
| | | String depID = httpServletRequest.getHeader(SecurityConstants.USER_DEP_ID_HEADER); |
| | | fileFolder = "Xray/" + hospitalID + "/" + depID + "/"+ folderByDate + "/"; |
| | | } |
| | | // 医院Logo只保存在一个目录中 |
| | | else if (fileInfo.getImgType().toLowerCase().equals("logo")) { |
| | | fileFolder = "HospitalLogo/"; |
| | | }else if (fileInfo.getImgType().toLowerCase().equals("doctor")) { |
| | | fileFolder = "DoctorImage/"; |
| | | } |
| | | else { |
| | | fileFolder = "OtherImage/"+ folderByDate + "/"; |
| | | } |
| | | |
| | | } else { |
| | | fileFolder = "OtherImage/"+ folderByDate + "/"; |
| | | } |
| | | |
| | | ossClient.putObject(fileProperties.getOss().getBucketName(), fileFolder + fileName, file.getInputStream()); |
| | | fileInfo.setUrl(fileProperties.getOss().getDomain() + fileFolder + fileName); |
| | | |
| | | fileFolder=FilePath(fileInfo.getImgType(),folderByDate); |
| | | fileUpLoadOss(fileInfo,fileFolder + fileName,file.getInputStream()); |
| | | } |
| | | else { |
| | | ossClient.putObject(fileProperties.getOss().getBucketName(), fileProperties.getOss().getFolder() + folderByDate + "/" + fileName, file.getInputStream()); |
| | | fileInfo.setUrl(fileProperties.getOss().getDomain() + fileProperties.getOss().getFolder() + folderByDate + "/" + fileName); |
| | | fileUpLoadOss(fileInfo,fileProperties.getOss().getFolder() + folderByDate + "/" + fileName,file.getInputStream()); |
| | | } |
| | | } |
| | | |
| | |
| | | ossClient.deleteObject(fileProperties.getOss().getBucketName(), fileInfo.getName()); |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 给OSS上上传文件 |
| | | * @param fileInfo 返回对象 |
| | | * @param newFilePath 上传到的文件路径 |
| | | * @param fileStream 要上传的文件流 |
| | | */ |
| | | public void fileUpLoadOss(FileInfo fileInfo,String newFilePath, InputStream fileStream) |
| | | { |
| | | ossClient.putObject(fileProperties.getOss().getBucketName(), newFilePath, fileStream); |
| | | fileInfo.setUrl(fileProperties.getOss().getDomain() + newFilePath); |
| | | } |
| | | /** |
| | | * 组合sso上的文件路径 |
| | | * @param imgType |
| | | * @return |
| | | */ |
| | | public String FilePath(String imgType,String folderByDate) |
| | | { |
| | | //返回的文件路径 |
| | | String fileFolder=""; |
| | | if (StringUtils.isNotBlank(imgType)) { |
| | | // 光片需要按照根据医院ID,科室ID,日期进行OSS存储 |
| | | if (imgType.toLowerCase().equals("xray")) { |
| | | String hospitalID = httpServletRequest.getHeader(SecurityConstants.USER_HOSPITAL_ID_HEADER); |
| | | String depID = httpServletRequest.getHeader(SecurityConstants.USER_DEP_ID_HEADER); |
| | | fileFolder = "Xray/" + hospitalID + "/" + depID + "/"+ folderByDate + "/"; |
| | | } |
| | | // 医院Logo只保存在一个目录中 |
| | | else if (imgType.toLowerCase().equals("logo")) { |
| | | fileFolder = "HospitalLogo/"; |
| | | }else if (imgType.toLowerCase().equals("doctor")) { |
| | | fileFolder = "DoctorImage/"; |
| | | } |
| | | else { |
| | | fileFolder = "OtherImage/"+ folderByDate + "/"; |
| | | } |
| | | |
| | | } else { |
| | | fileFolder = "OtherImage/"+ folderByDate + "/"; |
| | | } |
| | | return fileFolder; |
| | | } |
| | | } |
| | | } |