Skip to content

Commit

Permalink
feat: 兼容阿里云oss
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyudong committed Aug 8, 2023
1 parent 58f179c commit 0e45336
Show file tree
Hide file tree
Showing 17 changed files with 234 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSClientBuilder;
import com.simple.keen.attachment.config.properties.OSSClientProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
Expand All @@ -15,8 +16,8 @@
* @date 2022/12/27
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "aliyun.oss.enable", havingValue = "true")
@EnableConfigurationProperties({OSSClientProperties.class})
@ConditionalOnExpression("T(com.simple.keen.common.utils.StringUtils).isNotBlank('${aliyun.oss.endpoint}')")
public class OSSClientConfig {

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.simple.keen.attachment.controller;

import com.simple.keen.attachment.model.query.AttachmentFolderAndInfoQuery;
import com.simple.keen.attachment.model.query.AttachmentQuery;
import com.simple.keen.attachment.service.IAttachmentService;
import com.simple.keen.common.base.Response;
import javax.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
package com.simple.keen.attachment.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.simple.keen.attachment.model.dto.AttachmentInfoDTO;
import com.simple.keen.attachment.model.entity.AttachmentStorage;
import com.simple.keen.attachment.model.query.AttachmentQuery;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface AttachmentStorageMapper extends BaseMapper<AttachmentStorage> {

@Select("<script> "
+ "select * from ("
+ "select "
+ "a.*, b.nickname 'fromName', c.nickname 'toName' "
+ "from "
+ "t_message_chat a "
+ "left join t_user b on a.from_id = b.id "
+ "left join t_user c on a.to_id = c.id "
+ ")a"
+ "<where>"
+ "<if test=\"fromName != null and fromName != ''\">"
+ "and fromName like concat('%', #{fromName}, '%') "
+ "</if>"
+ "</where>"
+ "</script>")
List<AttachmentInfoDTO> selectAttachmentList(AttachmentQuery attachmentQuery);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.simple.keen.attachment.model.dto;

import com.simple.keen.attachment.model.enums.AttachmentUploadPlatformType;
import java.time.LocalDateTime;
import lombok.Data;
import lombok.ToString;
Expand Down Expand Up @@ -70,4 +71,14 @@ public class AttachmentInfoDTO {
*/
private Integer folderId;

/**
* 上传url
*/
private String uploadUrl;

/**
* 上传平台类型
*/
private AttachmentUploadPlatformType uploadPlatformType;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.simple.keen.attachment.model.enums.AttachmentUploadPlatformType;
import java.time.LocalDateTime;
import lombok.Data;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -81,4 +82,17 @@ public class AttachmentInfo {
@TableField(value = "folder_id")
private Integer folderId;

/**
* 上传url(外部oss需要使用)
*/
@TableField(value = "upload_url")
private String uploadUrl;

/**
* 上传平台类型
*/
@TableField(value = "upload_platform_type")
private AttachmentUploadPlatformType uploadPlatformType;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.simple.keen.attachment.model.enums;

import com.simple.keen.common.base.enums.ValueEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
* 附件上传平台类型
*
* @author SinceNovember
* @date 2023/08/07
*/
@Getter
@AllArgsConstructor
public enum AttachmentUploadPlatformType implements ValueEnum<Integer> {

DATABASE(1, "数据库存储"),
ALIYUN(2, "阿里云存储");

private final Integer code;
private final String msg;


@Override
public Integer getValue() {
return code;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.simple.keen.attachment.model.vo;

import com.simple.keen.attachment.model.enums.AttachmentUploadPlatformType;
import java.time.LocalDateTime;
import lombok.Builder;
import lombok.Data;
import lombok.ToString;

Expand All @@ -11,32 +13,12 @@
* @date 2023/5/10
*/
@Data
@Builder
@ToString
public class AttachmentStorageVO {

/**
* id
*/
private Integer id;
private String uploadUrl;

/**
* 文件名
*/
private String storageData;

/**
* 文件名
*/
private String storageSize;

/**
* 附件标识
*/
private Integer attachmentId;

/**
* 创建时间
*/
private LocalDateTime createTime;
private AttachmentUploadPlatformType uploadPlatformType;

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.simple.keen.attachment.model.query.AttachmentFolderAndInfoQuery;
import com.simple.keen.attachment.model.vo.AttachmentFolderAndInfoVO;
import com.simple.keen.attachment.model.vo.AttachmentInfoSummaryVO;
import com.simple.keen.attachment.model.vo.AttachmentStorageVO;
import java.util.function.Consumer;
import org.springframework.web.multipart.MultipartFile;

public interface IAttachmentInfoService extends IService<AttachmentInfo> {
Expand Down Expand Up @@ -50,7 +52,8 @@ PageSerializable<AttachmentFolderAndInfoVO> pageAttachmentFolderAndInfo(
* @param folderId 文件夹id
* @return
*/
AttachmentInfo addAttachmentInfoByFile(MultipartFile file, Integer folderId);
AttachmentInfo addAttachmentInfoByFile(MultipartFile file, Integer folderId,
AttachmentStorageVO attachmentStorageVO);

/**
* 统计数量和计算存储大小综合
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ public interface IAttachmentStorageService extends IService<AttachmentStorage> {
* 保存附件文件
*
* @param file 文件
* @param attachmentId 附件标识
* @return
* @return 附件存储id
*/
void addAttachmentStorage(MultipartFile file, Integer attachmentId);
Integer addAttachmentStorage(MultipartFile file);

/**
* 根据附件id获取附件存储信息
Expand All @@ -25,12 +24,12 @@ public interface IAttachmentStorageService extends IService<AttachmentStorage> {
AttachmentStorage getStorageByAttachmentId(Integer attachmentId);

/**
* 根据附件id获取存储数据
* 根据id获取存储数据
*
* @param attachmentId 附件标识
* @return
*/
byte[] getStorageDataByAttachmentId(Integer attachmentId);
byte[] getStorageDataById(Integer attachmentId);

/**
* 通过id获取base64存储数据
Expand Down
Loading

0 comments on commit 0e45336

Please sign in to comment.