Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
O
online-edu-backend
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
online-edu
online-edu-backend
Commits
dfe2b2e4
Commit
dfe2b2e4
authored
Apr 30, 2021
by
liuyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
上传文件后存入资源表
parent
30d7a620
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
156 additions
and
21 deletions
+156
-21
AliyunOSSCallbackController.java
...ta/biz/aliyun/controller/AliyunOSSCallbackController.java
+26
-2
AliyunService.java
...ain/java/com/qkdata/biz/aliyun/service/AliyunService.java
+10
-1
AliyunCallbackRespModel.java
...ava/com/qkdata/biz/aliyun/vo/AliyunCallbackRespModel.java
+1
-13
ResourceController.java
.../qkdata/biz/management/controller/ResourceController.java
+22
-0
ResourcePO.java
...ain/java/com/qkdata/biz/management/entity/ResourcePO.java
+49
-0
ResourceMapper.java
...java/com/qkdata/biz/management/mapper/ResourceMapper.java
+18
-0
ResourceService.java
...va/com/qkdata/biz/management/service/ResourceService.java
+20
-0
V1.0.0__init.sql
src/main/resources/db/migration/V1.0.0__init.sql
+5
-5
resourceMapper.xml
src/main/resources/mappers/management/resourceMapper.xml
+5
-0
No files found.
src/main/java/com/qkdata/biz/aliyun/controller/AliyunOSSCallbackController.java
View file @
dfe2b2e4
package
com
.
qkdata
.
biz
.
aliyun
.
controller
;
import
com.alibaba.fastjson.JSONObject
;
import
com.qkdata.biz.aliyun.service.AliyunService
;
import
com.qkdata.biz.aliyun.vo.AliyunCallbackRespModel
;
import
com.qkdata.biz.management.entity.ResourcePO
;
import
com.qkdata.biz.management.service.ResourceService
;
import
com.qkdata.common.annotation.SysLog
;
import
com.qkdata.common.base.model.Result
;
import
io.swagger.annotations.Api
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -17,10 +21,30 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping
(
"/aliyun"
)
public
class
AliyunOSSCallbackController
{
@Autowired
private
AliyunService
aliyunService
;
@Autowired
private
ResourceService
resourceService
;
@SysLog
(
"oss上传回调"
)
@PostMapping
(
"/oss/callback"
)
public
Result
<
String
>
callback
(
@RequestBody
AliyunCallbackRespModel
model
){
public
Result
<
JSONObject
>
callback
(
@RequestBody
String
callbackData
){
log
.
info
(
callbackData
);
AliyunCallbackRespModel
model
=
JSONObject
.
parseObject
(
callbackData
,
AliyunCallbackRespModel
.
class
);
String
url
=
aliyunService
.
generateUrl
(
model
.
getFileName
());
Long
resourceId
=
saveToResource
(
model
);
JSONObject
data
=
new
JSONObject
();
data
.
put
(
"ressourceId"
,
resourceId
);
data
.
put
(
"url"
,
aliyunService
.
generateUrl
(
model
.
getFileName
()));
return
Result
.
succeed
(
data
);
}
return
Result
.
succeed
(
"ok"
);
private
Long
saveToResource
(
AliyunCallbackRespModel
model
)
{
ResourcePO
po
=
new
ResourcePO
();
po
.
setName
(
model
.
getFileName
());
po
.
setBucket
(
model
.
getBucket
());
po
.
setSize
(
model
.
getSize
());
resourceService
.
save
(
po
);
return
po
.
getId
();
}
}
src/main/java/com/qkdata/biz/aliyun/service/AliyunService.java
View file @
dfe2b2e4
...
...
@@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
import
javax.annotation.PostConstruct
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URL
;
import
java.util.Date
;
@Service
...
...
@@ -59,10 +60,18 @@ public class AliyunService {
JSONObject
jsonCallback
=
new
JSONObject
();
jsonCallback
.
put
(
"callbackUrl"
,
frontendDomain
+
serverContextPath
+
"/aliyun/oss/callback"
);
jsonCallback
.
put
(
"callbackBody"
,
"{\"bucket\":${bucket},\"imageWidth\":
${imageInfo.width},\"imageFormat\":${imageInfo.format},\"fileName\":${object},\"size\":${size},\"etag\":${etag},\"mimeType\":${mimeType},\"imageHeight\":${imageInfo.height}
}"
);
jsonCallback
.
put
(
"callbackBody"
,
"{\"bucket\":${bucket},\"imageWidth\":
\"${imageInfo.width}\",\"imageFormat\":${imageInfo.format},\"fileName\":${object},\"size\":\"${size}\",\"etag\":${etag},\"mimeType\":${mimeType},\"imageHeight\":\"${imageInfo.height}\"
}"
);
jsonCallback
.
put
(
"callbackBodyType"
,
"application/json"
);
String
base64CallbackBody
=
BinaryUtil
.
toBase64String
(
jsonCallback
.
toString
().
getBytes
());
model
.
setCallback
(
base64CallbackBody
);
return
model
;
}
public
String
generateUrl
(
String
fileName
)
{
// 设置URL过期时间为1小时。
Date
expiration
=
new
Date
(
new
Date
().
getTime
()
+
expireTime
*
1000
);
// 生成以GET方法访问的签名URL,访客可以直接通过浏览器访问相关内容。
URL
url
=
ossClient
.
generatePresignedUrl
(
aliyunConfig
.
getBucket
(),
fileName
,
expiration
);
return
url
.
toString
();
}
}
src/main/java/com/qkdata/biz/aliyun/vo/AliyunCallbackRespModel.java
View file @
dfe2b2e4
...
...
@@ -2,21 +2,9 @@ package com.qkdata.biz.aliyun.vo;
import
lombok.Data
;
/**
* {
* "bucket": ""qkdata-online-edu"",
* "fileName": ""pjMwzsYBwD.png"",
* "etag": ""367FA509D3CCB1838ADE75533E779DAC"",
* "size": "1079945",
* "mimeType": ""image/png"",
* "imageHeight": "573",
* "imageWidth": "1400",
* "imageFormat": ""png""
* }
*/
@Data
public
class
AliyunCallbackRespModel
{
private
String
buket
;
private
String
bu
c
ket
;
private
String
fileName
;
private
String
etag
;
private
Long
size
;
...
...
src/main/java/com/qkdata/biz/management/controller/ResourceController.java
0 → 100644
View file @
dfe2b2e4
package
com
.
qkdata
.
biz
.
management
.
controller
;
import
io.swagger.annotations.Api
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* <p>
* 资源 前端控制器
* </p>
*
* @author liuyang
* @since 2021-04-30
*/
@Api
(
tags
=
"资源管理"
)
@RestController
@RequestMapping
(
"/api/management/resource-po"
)
public
class
ResourceController
{
}
src/main/java/com/qkdata/biz/management/entity/ResourcePO.java
0 → 100644
View file @
dfe2b2e4
package
com
.
qkdata
.
biz
.
management
.
entity
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.qkdata.common.base.entity.BasePO
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
/**
* <p>
* 资源
* </p>
*
* @author liuyang
* @since 2021-04-30
*/
@Data
@EqualsAndHashCode
(
callSuper
=
true
)
@TableName
(
"resource"
)
public
class
ResourcePO
extends
BasePO
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 名称
*/
private
String
name
;
/**
* bucket名称
*/
private
String
bucket
;
/**
* 资源大小
*/
private
Long
size
;
/**
* 访问url
*/
private
String
url
;
/**
* 视频时长
*/
private
Float
videoDuration
;
}
src/main/java/com/qkdata/biz/management/mapper/ResourceMapper.java
0 → 100644
View file @
dfe2b2e4
package
com
.
qkdata
.
biz
.
management
.
mapper
;
import
com.qkdata.biz.management.entity.ResourcePO
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
org.apache.ibatis.annotations.Mapper
;
/**
* <p>
* 资源 Mapper 接口
* </p>
*
* @author liuyang
* @since 2021-04-30
*/
@Mapper
public
interface
ResourceMapper
extends
BaseMapper
<
ResourcePO
>
{
}
src/main/java/com/qkdata/biz/management/service/ResourceService.java
0 → 100644
View file @
dfe2b2e4
package
com
.
qkdata
.
biz
.
management
.
service
;
import
com.qkdata.biz.management.entity.ResourcePO
;
import
com.qkdata.biz.management.mapper.ResourceMapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.springframework.stereotype.Service
;
/**
* <p>
* $!{table.comment} 服务类
* </p>
*
* @author liuyang
* @since 2021-04-30
*/
@Service
public
class
ResourceService
extends
ServiceImpl
<
ResourceMapper
,
ResourcePO
>
{
}
\ No newline at end of file
src/main/resources/db/migration/V1.0.0__init.sql
View file @
dfe2b2e4
...
...
@@ -246,18 +246,18 @@ CREATE TABLE `recommend_config` (
DROP
TABLE
IF
EXISTS
`resource`
;
CREATE
TABLE
`resource`
(
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
COMMENT
'主键'
,
`oss_id`
varchar
(
255
)
DEFAULT
NULL
COMMENT
'第三方存储ID'
,
`status`
varchar
(
20
)
DEFAULT
NULL
COMMENT
'状态(待上传、上传失败、上传成功)'
,
`size`
float
DEFAULT
NULL
COMMENT
'资源大小'
,
`video_duration`
float
DEFAULT
NULL
COMMENT
'视频时长'
,
`url`
varchar
(
255
)
DEFAULT
NULL
COMMENT
'访问url'
,
`name`
varchar
(
255
)
DEFAULT
NULL
COMMENT
'名称'
,
`bucket`
varchar
(
255
)
DEFAULT
NULL
COMMENT
'bucket名称'
,
`size`
bigint
(
20
)
DEFAULT
NULL
COMMENT
'资源大小'
,
`url`
varchar
(
255
)
DEFAULT
NULL
COMMENT
'访问url'
,
`video_duration`
float
DEFAULT
NULL
COMMENT
'视频时长'
,
`create_time`
datetime
DEFAULT
NULL
,
`update_time`
datetime
DEFAULT
NULL
,
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COMMENT
=
'资源'
;
-- ----------------------------
-- Table structure for swiper_config
-- ----------------------------
...
...
src/main/resources/mappers/management/resourceMapper.xml
0 → 100644
View file @
dfe2b2e4
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.qkdata.biz.management.mapper.ResourceMapper"
>
</mapper>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment