| | |
| | | package com.kidgrow.filecenter.config; |
| | | |
| | | import com.aliyun.oss.OSSClient; |
| | | import com.aliyun.oss.common.auth.DefaultCredentialProvider; |
| | | import com.kidgrow.common.constant.SecurityConstants; |
| | | import com.kidgrow.common.utils.DateUtil; |
| | | import com.kidgrow.filecenter.model.FileInfo; |
| | | import com.kidgrow.filecenter.properties.FileServerProperties; |
| | | import com.kidgrow.filecenter.service.impl.AbstractIFileService; |
| | |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | import com.aliyun.oss.OSSClient; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | |
| | | public class AliyunOSSAutoConfigure { |
| | | @Autowired |
| | | private FileServerProperties fileProperties; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 阿里云文件存储client |
| | |
| | | @Autowired |
| | | private OSSClient ossClient; |
| | | |
| | | @Autowired |
| | | private HttpServletRequest httpServletRequest; |
| | | |
| | | @Override |
| | | protected String fileType() { |
| | | return fileProperties.getType(); |
| | |
| | | |
| | | @Override |
| | | protected void uploadFile(MultipartFile file, FileInfo fileInfo) throws Exception { |
| | | ossClient.putObject(fileProperties.getOss().getBucketName(), fileInfo.getName(), file.getInputStream()); |
| | | fileInfo.setUrl(fileProperties.getOss().getDomain() + "/" + fileInfo.getName()); |
| | | String clientID= httpServletRequest.getHeader(SecurityConstants.CLIENT_HEADER); |
| | | String folderByDate =DateUtil.formatDate(new Date()); |
| | | if(clientID=="hospital"){//医院端平台,根据医院ID,科室ID进行OSS存储 |
| | | String orgID=httpServletRequest.getHeader(SecurityConstants.USER_ORG_ID_HEADER); |
| | | String depID=httpServletRequest.getHeader(SecurityConstants.USER_DEP_ID_HEADER); |
| | | String fileFolder="KidgrowAI/"+orgID+"/"+depID+"/"; |
| | | ossClient.putObject(fileProperties.getOss().getBucketName(), fileFolder + folderByDate + "/" + fileInfo.getName(), file.getInputStream()); |
| | | fileInfo.setUrl(fileProperties.getOss().getDomain() + fileFolder + folderByDate + "/" + fileInfo.getName()); |
| | | } |
| | | else { |
| | | ossClient.putObject(fileProperties.getOss().getBucketName(), fileProperties.getOss().getFolder() + folderByDate + "/" + fileInfo.getName(), file.getInputStream()); |
| | | fileInfo.setUrl(fileProperties.getOss().getDomain() + fileProperties.getOss().getFolder() + folderByDate + "/" + fileInfo.getName()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | protected boolean deleteFile(FileInfo fileInfo) { |
| | | |
| | | ossClient.deleteObject(fileProperties.getOss().getBucketName(), fileInfo.getName()); |
| | | return true; |
| | | } |