Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
9b3092b3
提交
9b3092b3
authored
6月 15, 2022
作者:
YunaiV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成 FileApi 的 feign 支持
上级
4c6e915d
隐藏空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
114 行增加
和
71 行删除
+114
-71
FileApi.java
.../java/cn/iocoder/yudao/module/infra/api/file/FileApi.java
+41
-10
FileCreateReqDTO.java
...der/yudao/module/infra/api/file/dto/FileCreateReqDTO.java
+23
-0
ApiErrorLogCreateReqDTO.java
.../module/infra/api/logger/dto/ApiErrorLogCreateReqDTO.java
+1
-1
FileApiImpl.java
...a/cn/iocoder/yudao/module/infra/api/file/FileApiImpl.java
+14
-8
FileController.java
...ao/module/infra/controller/admin/file/FileController.java
+1
-1
FileDO.java
...ocoder/yudao/module/infra/dal/dataobject/file/FileDO.java
+4
-0
FileService.java
.../iocoder/yudao/module/infra/service/file/FileService.java
+3
-2
FileServiceImpl.java
...oder/yudao/module/infra/service/file/FileServiceImpl.java
+9
-2
FileServiceTest.java
...oder/yudao/module/infra/service/file/FileServiceTest.java
+2
-2
OperateLogCreateReqDTO.java
.../module/system/api/logger/dto/OperateLogCreateReqDTO.java
+1
-1
TmpConfiguration.java
...coder/yudao/module/system/framework/TmpConfiguration.java
+0
-44
RpcConfiguration.java
.../module/system/framework/rpc/config/RpcConfiguration.java
+11
-0
package-info.java
...coder/yudao/module/system/framework/rpc/package-info.java
+4
-0
没有找到文件。
yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/file/FileApi.java
浏览文件 @
9b3092b3
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
api
.
file
;
import
cn.hutool.core.util.IdUtil
;
import
cn.iocoder.yudao.framework.common.pojo.CommonResult
;
import
cn.iocoder.yudao.module.infra.api.file.dto.FileCreateReqDTO
;
import
cn.iocoder.yudao.module.infra.enums.ApiConstants
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestParam
;
/**
* 文件 API 接口
*
* @author 芋道源码
*/
import
javax.validation.Valid
;
@FeignClient
(
name
=
ApiConstants
.
NAME
)
// TODO 芋艿:fallbackFactory =
@Api
(
tags
=
"RPC 服务 - 文件"
)
public
interface
FileApi
{
String
PREFIX
=
ApiConstants
.
PREFIX
+
"/file"
;
/**
* 保存文件,并返回文件的访问路径
*
* @param content 文件内容
* @return 文件路径
*/
default
String
createFile
(
byte
[]
content
)
throws
Exception
{
return
createFile
(
IdUtil
.
fastUUID
()
,
content
);
}
default
String
createFile
(
byte
[]
content
)
{
return
createFile
(
null
,
null
,
content
);
}
/**
* 保存文件,并返回文件的访问路径
...
...
@@ -26,6 +35,28 @@ public interface FileApi {
* @param content 文件内容
* @return 文件路径
*/
String
createFile
(
String
path
,
byte
[]
content
)
throws
Exception
;
default
String
createFile
(
String
path
,
byte
[]
content
)
{
return
createFile
(
null
,
path
,
content
);
}
/**
* 保存文件,并返回文件的访问路径
*
* @param name 原文件名称
* @param path 文件路径
* @param content 文件内容
* @return 文件路径
*/
default
String
createFile
(
@RequestParam
(
"name"
)
String
name
,
@RequestParam
(
"path"
)
String
path
,
@RequestParam
(
"content"
)
byte
[]
content
)
{
CommonResult
<
String
>
result
=
createFile
(
new
FileCreateReqDTO
().
setName
(
name
).
setPath
(
path
).
setContent
(
content
));
result
.
checkError
();
return
result
.
getData
();
}
@PostMapping
(
PREFIX
+
"/create"
)
@ApiOperation
(
"保存文件,并返回文件的访问路径"
)
CommonResult
<
String
>
createFile
(
@Valid
@RequestBody
FileCreateReqDTO
createReqDTO
);
}
yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/file/dto/FileCreateReqDTO.java
0 → 100644
浏览文件 @
9b3092b3
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
api
.
file
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
javax.validation.constraints.NotEmpty
;
@ApiModel
(
"RPC 服务 - 文件创建 Request DTO"
)
@Data
public
class
FileCreateReqDTO
{
@ApiModelProperty
(
value
=
"原文件名称"
,
example
=
"xxx.png"
)
private
String
name
;
@ApiModelProperty
(
value
=
"文件路径"
,
example
=
"xxx.png"
)
private
String
path
;
@ApiModelProperty
(
value
=
"文件内容"
,
required
=
true
)
@NotEmpty
(
message
=
"文件内容不能为空"
)
private
byte
[]
content
;
}
yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/logger/dto/ApiErrorLogCreateReqDTO.java
浏览文件 @
9b3092b3
...
...
@@ -7,7 +7,7 @@ import lombok.Data;
import
javax.validation.constraints.NotNull
;
import
java.util.Date
;
@ApiModel
(
"API 错误日志创建 Request DTO"
)
@ApiModel
(
"
RPC 服务 -
API 错误日志创建 Request DTO"
)
@Data
public
class
ApiErrorLogCreateReqDTO
{
...
...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/api/file/FileApiImpl.java
浏览文件 @
9b3092b3
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
api
.
file
;
import
cn.iocoder.yudao.framework.common.pojo.CommonResult
;
import
cn.iocoder.yudao.module.infra.api.file.dto.FileCreateReqDTO
;
import
cn.iocoder.yudao.module.infra.service.file.FileService
;
import
org.apache.commons.fileupload.FileItem
;
import
org.apache.dubbo.config.annotation.DubboService
;
import
org.springframework.stereotype.Service
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.commons.CommonsMultipartFile
;
import
javax.annotation.Resource
;
/**
* 文件 API 实现类
*
* @author 芋道源码
*/
@Service
import
static
cn
.
iocoder
.
yudao
.
framework
.
common
.
pojo
.
CommonResult
.
success
;
import
static
cn
.
iocoder
.
yudao
.
module
.
system
.
enums
.
ApiConstants
.
VERSION
;
@RestController
// 提供 RESTful API 接口,给 Feign 调用
@DubboService
(
version
=
VERSION
)
// 提供 Dubbo RPC 接口,给 Dubbo Consumer 调用
@Validated
public
class
FileApiImpl
implements
FileApi
{
...
...
@@ -19,8 +24,9 @@ public class FileApiImpl implements FileApi {
private
FileService
fileService
;
@Override
public
String
createFile
(
String
path
,
byte
[]
content
)
throws
Exception
{
return
fileService
.
createFile
(
path
,
content
);
public
CommonResult
<
String
>
createFile
(
FileCreateReqDTO
createReqDTO
)
{
return
success
(
fileService
.
createFile
(
createReqDTO
.
getName
(),
createReqDTO
.
getPath
(),
createReqDTO
.
getContent
()));
}
}
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java
浏览文件 @
9b3092b3
...
...
@@ -46,7 +46,7 @@ public class FileController {
@OperateLog
(
logArgs
=
false
)
// 上传文件,没有记录操作日志的必要
public
CommonResult
<
String
>
uploadFile
(
@RequestParam
(
"file"
)
MultipartFile
file
,
@RequestParam
(
value
=
"path"
,
required
=
false
)
String
path
)
throws
Exception
{
return
success
(
fileService
.
createFile
(
path
,
IoUtil
.
readBytes
(
file
.
getInputStream
())));
return
success
(
fileService
.
createFile
(
file
.
getOriginalFilename
(),
path
,
IoUtil
.
readBytes
(
file
.
getInputStream
())));
}
@DeleteMapping
(
"/delete"
)
...
...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/file/FileDO.java
浏览文件 @
9b3092b3
...
...
@@ -33,6 +33,10 @@ public class FileDO extends BaseDO {
* 关联 {@link FileConfigDO#getId()}
*/
private
Long
configId
;
/**
* 原文件名
*/
private
String
name
;
/**
* 路径,即文件名
*/
...
...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileService.java
浏览文件 @
9b3092b3
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
service
.
file
;
import
cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO
;
import
cn.iocoder.yudao.framework.common.pojo.PageResult
;
import
cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO
;
import
cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO
;
/**
...
...
@@ -22,11 +22,12 @@ public interface FileService {
/**
* 保存文件,并返回文件的访问路径
*
* @param name 原文件名称
* @param path 文件路径
* @param content 文件内容
* @return 文件路径
*/
String
createFile
(
String
path
,
byte
[]
content
)
throws
Exception
;
String
createFile
(
String
name
,
String
path
,
byte
[]
content
)
;
/**
* 删除文件
...
...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java
浏览文件 @
9b3092b3
...
...
@@ -9,6 +9,7 @@ import cn.iocoder.yudao.framework.file.core.client.FileClient;
import
cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO
;
import
cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO
;
import
cn.iocoder.yudao.module.infra.dal.mysql.file.FileMapper
;
import
lombok.SneakyThrows
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
...
...
@@ -37,12 +38,17 @@ public class FileServiceImpl implements FileService {
}
@Override
public
String
createFile
(
String
path
,
byte
[]
content
)
throws
Exception
{
@SneakyThrows
public
String
createFile
(
String
name
,
String
path
,
byte
[]
content
)
{
// 计算默认的 path 名
String
type
=
FileTypeUtil
.
getType
(
new
ByteArrayInputStream
(
content
),
path
);
String
type
=
FileTypeUtil
.
getType
(
new
ByteArrayInputStream
(
content
),
name
);
if
(
StrUtil
.
isEmpty
(
path
))
{
path
=
DigestUtil
.
md5Hex
(
content
)
+
'.'
+
type
;
}
// 如果 name 为空,则使用 path 填充
if
(
StrUtil
.
isEmpty
(
name
))
{
name
=
path
;
}
// 上传到文件存储器
FileClient
client
=
fileConfigService
.
getMasterFileClient
();
...
...
@@ -52,6 +58,7 @@ public class FileServiceImpl implements FileService {
// 保存到数据库
FileDO
file
=
new
FileDO
();
file
.
setConfigId
(
client
.
getId
());
file
.
setName
(
name
);
file
.
setPath
(
path
);
file
.
setUrl
(
url
);
file
.
setType
(
type
);
...
...
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java
浏览文件 @
9b3092b3
...
...
@@ -80,9 +80,9 @@ public class FileServiceTest extends BaseDbUnitTest {
String
url
=
randomString
();
when
(
client
.
upload
(
same
(
content
),
same
(
path
))).
thenReturn
(
url
);
when
(
client
.
getId
()).
thenReturn
(
10L
);
String
name
=
"单测文件名"
;
// 调用
String
result
=
fileService
.
createFile
(
path
,
content
);
String
result
=
fileService
.
createFile
(
name
,
path
,
content
);
// 断言
assertEquals
(
result
,
url
);
// 校验数据
...
...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/logger/dto/OperateLogCreateReqDTO.java
浏览文件 @
9b3092b3
...
...
@@ -9,7 +9,7 @@ import javax.validation.constraints.NotNull;
import
java.util.Date
;
import
java.util.Map
;
@ApiModel
(
"操作日志创建 Request DTO"
)
@ApiModel
(
"
RPC 服务 -
操作日志创建 Request DTO"
)
@Data
public
class
OperateLogCreateReqDTO
{
...
...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/TmpConfiguration.java
deleted
100644 → 0
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
module
.
system
.
framework
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLog
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLog
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService
;
import
cn.iocoder.yudao.module.infra.api.file.FileApi
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
public
class
TmpConfiguration
{
@Bean
public
FileApi
fileApi
()
{
return
new
FileApi
()
{
@Override
public
String
createFile
(
String
path
,
byte
[]
content
)
throws
Exception
{
return
null
;
}
};
}
@Bean
public
ApiAccessLogFrameworkService
apiAccessLogFrameworkService
()
{
return
new
ApiAccessLogFrameworkService
()
{
@Override
public
void
createApiAccessLog
(
ApiAccessLog
apiAccessLog
)
{
}
};
}
@Bean
public
ApiErrorLogFrameworkService
apiErrorLogFrameworkService
()
{
return
new
ApiErrorLogFrameworkService
()
{
@Override
public
void
createApiErrorLog
(
ApiErrorLog
apiErrorLog
)
{
}
};
}
}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/rpc/config/RpcConfiguration.java
0 → 100644
浏览文件 @
9b3092b3
package
cn
.
iocoder
.
yudao
.
module
.
system
.
framework
.
rpc
.
config
;
import
cn.iocoder.yudao.module.infra.api.file.FileApi
;
import
cn.iocoder.yudao.module.system.api.user.AdminUserApi
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
(
proxyBeanMethods
=
false
)
@EnableFeignClients
(
clients
=
FileApi
.
class
)
public
class
RpcConfiguration
{
}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/rpc/package-info.java
0 → 100644
浏览文件 @
9b3092b3
/**
* 占位
*/
package
cn
.
iocoder
.
yudao
.
module
.
system
.
framework
.
rpc
;
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论