Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fzm-joying
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
lei
fzm-joying
Commits
73a24985
Commit
73a24985
authored
Jul 15, 2021
by
tangtuo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改保存nft的接口
parent
6d09c43b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
46 deletions
+32
-46
Nft.java
joying-common/src/main/java/com/fzm/common/entity/Nft.java
+13
-0
GlobalExceptionHandler.java
.../fzm/common/exception/handler/GlobalExceptionHandler.java
+12
-5
NftServiceImpl.java
...main/java/com/fzm/common/service/impl/NftServiceImpl.java
+3
-1
NftController.java
...rc/main/java/com/fzm/portal/controller/NftController.java
+4
-40
No files found.
joying-common/src/main/java/com/fzm/common/entity/Nft.java
View file @
73a24985
...
@@ -5,7 +5,10 @@ import io.swagger.annotations.ApiModel;
...
@@ -5,7 +5,10 @@ import io.swagger.annotations.ApiModel;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
import
lombok.experimental.Accessors
;
import
org.hibernate.validator.constraints.Length
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
java.util.Date
;
import
java.util.Date
;
/**
/**
...
@@ -18,24 +21,32 @@ import java.util.Date;
...
@@ -18,24 +21,32 @@ import java.util.Date;
@TableName
(
"tb_nft"
)
@TableName
(
"tb_nft"
)
public
class
Nft
extends
BaseEntity
{
public
class
Nft
extends
BaseEntity
{
@NotNull
(
message
=
"类目id不能为空"
)
@ApiModelProperty
(
"类目id"
)
@ApiModelProperty
(
"类目id"
)
private
Integer
categoryId
;
private
Integer
categoryId
;
@ApiModelProperty
(
"用户id"
)
@ApiModelProperty
(
"用户id"
)
private
Integer
userId
;
private
Integer
userId
;
@NotBlank
(
message
=
"名称不能为空"
)
@Length
(
max
=
20
,
message
=
"名称最大长度为20"
)
@ApiModelProperty
(
"名称"
)
@ApiModelProperty
(
"名称"
)
private
String
name
;
private
String
name
;
@ApiModelProperty
(
"封面"
)
@ApiModelProperty
(
"封面"
)
private
String
cover
;
private
String
cover
;
@NotBlank
(
message
=
"作者不能为空"
)
@Length
(
max
=
20
,
message
=
"作者最大长度为20"
)
@ApiModelProperty
(
"作者"
)
@ApiModelProperty
(
"作者"
)
private
String
author
;
private
String
author
;
@NotBlank
(
message
=
"主题不能为空"
)
@ApiModelProperty
(
"主题,多个用逗号,隔开"
)
@ApiModelProperty
(
"主题,多个用逗号,隔开"
)
private
String
theme
;
private
String
theme
;
@NotBlank
(
message
=
"简介不能为空"
)
@Length
(
max
=
500
,
message
=
"简介最大长度为500"
)
@ApiModelProperty
(
"简介"
)
@ApiModelProperty
(
"简介"
)
private
String
synopsis
;
private
String
synopsis
;
...
@@ -45,9 +56,11 @@ public class Nft extends BaseEntity {
...
@@ -45,9 +56,11 @@ public class Nft extends BaseEntity {
@ApiModelProperty
(
"文件地址--用户选择不存档的情况下为空"
)
@ApiModelProperty
(
"文件地址--用户选择不存档的情况下为空"
)
private
String
fileUrl
;
private
String
fileUrl
;
@NotBlank
(
message
=
"作品哈希不能为空"
)
@ApiModelProperty
(
"文件hash"
)
@ApiModelProperty
(
"文件hash"
)
private
String
fileHash
;
private
String
fileHash
;
@NotNull
(
message
=
"平台存档不能为空"
)
@ApiModelProperty
(
"平台存档 0-不存档 1-加密存档"
)
@ApiModelProperty
(
"平台存档 0-不存档 1-加密存档"
)
private
Integer
isArchives
;
private
Integer
isArchives
;
...
...
joying-common/src/main/java/com/fzm/common/exception/handler/GlobalExceptionHandler.java
View file @
73a24985
...
@@ -5,6 +5,7 @@ import com.fzm.common.exception.GlobalException;
...
@@ -5,6 +5,7 @@ import com.fzm.common.exception.GlobalException;
import
com.fzm.common.model.ResponseModel
;
import
com.fzm.common.model.ResponseModel
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.context.support.DefaultMessageSourceResolvable
;
import
org.springframework.context.support.DefaultMessageSourceResolvable
;
import
org.springframework.validation.BindException
;
import
org.springframework.validation.ObjectError
;
import
org.springframework.validation.ObjectError
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
...
@@ -24,11 +25,6 @@ import java.util.stream.Collectors;
...
@@ -24,11 +25,6 @@ import java.util.stream.Collectors;
@RestControllerAdvice
@RestControllerAdvice
public
class
GlobalExceptionHandler
{
public
class
GlobalExceptionHandler
{
@Resource
private
HttpServletResponse
response
;
@Resource
private
HttpServletRequest
request
;
@ExceptionHandler
(
value
=
GlobalException
.
class
)
@ExceptionHandler
(
value
=
GlobalException
.
class
)
public
ResponseModel
<
String
>
handlerGlobalException
(
GlobalException
globalException
)
{
public
ResponseModel
<
String
>
handlerGlobalException
(
GlobalException
globalException
)
{
...
@@ -53,4 +49,15 @@ public class GlobalExceptionHandler {
...
@@ -53,4 +49,15 @@ public class GlobalExceptionHandler {
collect
(
Collectors
.
joining
(
"、"
));
collect
(
Collectors
.
joining
(
"、"
));
return
ResponseModel
.
fail
(
ResultCode
.
VALIDATE_FAILED
,
errorMsg
);
return
ResponseModel
.
fail
(
ResultCode
.
VALIDATE_FAILED
,
errorMsg
);
}
}
@ExceptionHandler
(
value
=
{
BindException
.
class
})
public
ResponseModel
<
String
>
handleBindException
(
BindException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
List
<
ObjectError
>
allErrors
=
e
.
getBindingResult
().
getAllErrors
();
String
errorMsg
=
allErrors
.
stream
().
map
(
DefaultMessageSourceResolvable:
:
getDefaultMessage
).
collect
(
Collectors
.
joining
(
"、"
));
return
ResponseModel
.
fail
(
ResultCode
.
VALIDATE_FAILED
,
errorMsg
);
}
}
}
joying-common/src/main/java/com/fzm/common/service/impl/NftServiceImpl.java
View file @
73a24985
...
@@ -78,8 +78,10 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
...
@@ -78,8 +78,10 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
@Override
@Override
public
NftDto
saveNft
(
Nft
nft
)
{
public
NftDto
saveNft
(
Nft
nft
)
{
User
user
=
userService
.
getById
(
JwtUtil
.
getUserIdFromToken
(
request
.
getHeader
(
"Authorization"
)));
Integer
userId
=
JwtUtil
.
getUserIdFromToken
(
request
.
getHeader
(
"Authorization"
));
nft
.
setUserId
(
userId
);
save
(
nft
);
save
(
nft
);
User
user
=
userService
.
getById
(
userId
);
NftDto
nftDto
=
new
NftDto
();
NftDto
nftDto
=
new
NftDto
();
// 获取用户的钱包地址
// 获取用户的钱包地址
String
wallet
=
user
.
getWallet
();
String
wallet
=
user
.
getWallet
();
...
...
joying-portal/src/main/java/com/fzm/portal/controller/NftController.java
View file @
73a24985
...
@@ -70,48 +70,12 @@ public class NftController {
...
@@ -70,48 +70,12 @@ public class NftController {
@Authentication
@Authentication
@PostMapping
(
"/save"
)
@PostMapping
(
"/save"
)
@ApiOperation
(
value
=
"nft基本信息保存(基本信息和加密上链两个步骤)"
)
@ApiOperation
(
value
=
"nft基本信息保存(基本信息和加密上链两个步骤)"
)
public
ResponseModel
<
NftDto
>
save
(
@ApiParam
(
value
=
"类目id"
,
required
=
true
)
Integer
categoryId
,
public
ResponseModel
<
NftDto
>
save
(
@Validated
@ModelAttribute
Nft
nft
)
{
@ApiParam
(
value
=
"名称"
,
required
=
true
)
String
name
,
if
(
SystemConstant
.
BOOLEAN_DATA_TRUE
.
equals
(
nft
.
getIsArchives
()))
{
@ApiParam
(
value
=
"作者"
,
required
=
true
)
String
author
,
if
(
StringUtils
.
isAnyBlank
(
nft
.
getFileUrl
(),
nft
.
getName
())
||
nft
.
getIsGrant
()
==
null
)
{
@ApiParam
(
value
=
"主题"
,
required
=
true
)
String
theme
,
throw
GlobalException
.
newException
(
ResultCode
.
VALIDATE_FAILED
,
"当选择平台存档时,文件名和文件路径必传"
);
@ApiParam
(
value
=
"简介"
,
required
=
true
)
String
synopsis
,
@ApiParam
(
value
=
"文件"
)
MultipartFile
file
,
@ApiParam
(
value
=
"文件hash"
,
required
=
true
)
String
fileHash
,
@ApiParam
(
value
=
"平台存档 0-不存档 1-加密存档"
,
required
=
true
)
Integer
isArchives
,
@ApiParam
(
value
=
"授权阅读 0-不需要授权 1-需要授权"
)
Integer
isGrant
)
throws
IOException
{
if
(
StringUtils
.
isAnyBlank
(
name
,
author
,
theme
,
synopsis
,
fileHash
)
||
categoryId
==
null
||
isArchives
==
null
)
{
throw
GlobalException
.
newException
(
ResultCode
.
VALIDATE_FAILED
,
"缺失必填参数"
);
}
if
(
name
.
length
()
>
20
)
{
throw
GlobalException
.
newException
(
ResultCode
.
VALIDATE_FAILED
,
"作品名称长度不能大于20"
);
}
if
(
author
.
length
()
>
20
)
{
throw
GlobalException
.
newException
(
ResultCode
.
VALIDATE_FAILED
,
"作者长度不能大于20"
);
}
if
(
synopsis
.
length
()
>
500
)
{
throw
GlobalException
.
newException
(
ResultCode
.
VALIDATE_FAILED
,
"简介长度不能大于500"
);
}
Nft
nft
=
new
Nft
();
// 当平台存档选择加密存档时,文件必传
if
(
SystemConstant
.
BOOLEAN_DATA_TRUE
.
equals
(
isArchives
))
{
if
(
file
==
null
||
isGrant
==
null
)
{
throw
GlobalException
.
newException
(
ResultCode
.
VALIDATE_FAILED
,
"当选择加密存档的时候,文件和授权阅读不能为空"
);
}
// 判断文件的hash是否被篡改过
if
(!
SecureUtil
.
md5
(
file
.
getInputStream
()).
equals
(
fileHash
))
{
throw
GlobalException
.
newException
(
ResultCode
.
VALIDATE_FAILED
,
"文件hash和文件内容不匹配"
);
}
}
String
fileUrl
=
ossUtil
.
putEncryptObject
(
file
);
nft
.
setFileUrl
(
fileUrl
).
setIsGrant
(
isGrant
).
setFileName
(
file
.
getOriginalFilename
());
}
}
nft
.
setCategoryId
(
categoryId
)
.
setUserId
(
JwtUtil
.
getUserIdFromToken
(
request
.
getHeader
(
"Authorization"
)))
.
setName
(
name
)
.
setAuthor
(
author
)
.
setTheme
(
theme
)
.
setSynopsis
(
synopsis
)
.
setFileHash
(
fileHash
)
.
setIsArchives
(
isArchives
);
return
ResponseModel
.
success
(
nftService
.
saveNft
(
nft
));
return
ResponseModel
.
success
(
nftService
.
saveNft
(
nft
));
}
}
...
...
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