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
eec97329
Commit
eec97329
authored
Jul 09, 2021
by
tangtuo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改token有效期
修改用户收藏的接口
parent
01262836
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
172 additions
and
23 deletions
+172
-23
application-dev.yml
joying-admin/src/main/resources/application-dev.yml
+0
-2
application-local.yml
joying-admin/src/main/resources/application-local.yml
+0
-2
application-test.yml
joying-admin/src/main/resources/application-test.yml
+0
-2
TbCollection.java
...mon/src/main/java/com/fzm/common/entity/TbCollection.java
+38
-0
CollectionMapper.java
...src/main/java/com/fzm/common/mapper/CollectionMapper.java
+22
-0
CollectionService.java
...c/main/java/com/fzm/common/service/CollectionService.java
+29
-0
CollectionServiceImpl.java
...va/com/fzm/common/service/impl/CollectionServiceImpl.java
+34
-0
NftServiceImpl.java
...main/java/com/fzm/common/service/impl/NftServiceImpl.java
+27
-5
CollectionMapper.xml
joying-common/src/main/resources/mapper/CollectionMapper.xml
+12
-0
application-dev.yml
joying-portal/src/main/resources/application-dev.yml
+0
-2
application-local.yml
joying-portal/src/main/resources/application-local.yml
+2
-4
application-test.yml
joying-portal/src/main/resources/application-test.yml
+0
-2
joying.sql
sql/joying.sql
+8
-4
No files found.
joying-admin/src/main/resources/application-dev.yml
View file @
eec97329
...
@@ -54,8 +54,6 @@ spring:
...
@@ -54,8 +54,6 @@ spring:
token-name
:
Authorization
token-name
:
Authorization
# token有效期,单位s, -1代表永不过期
# token有效期,单位s, -1代表永不过期
timeout
:
7200
timeout
:
7200
# token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
activity-timeout
:
3600
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
is-share
:
false
is-share
:
false
# token风格
# token风格
...
...
joying-admin/src/main/resources/application-local.yml
View file @
eec97329
...
@@ -54,8 +54,6 @@ spring:
...
@@ -54,8 +54,6 @@ spring:
token-name
:
Authorization
token-name
:
Authorization
# token有效期,单位s 默认30天, -1代表永不过期
# token有效期,单位s 默认30天, -1代表永不过期
timeout
:
7200
timeout
:
7200
# token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
activity-timeout
:
3600
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
is-share
:
false
is-share
:
false
# token风格
# token风格
...
...
joying-admin/src/main/resources/application-test.yml
View file @
eec97329
...
@@ -54,8 +54,6 @@ spring:
...
@@ -54,8 +54,6 @@ spring:
token-name
:
Authorization
token-name
:
Authorization
# token有效期,单位s, -1代表永不过期
# token有效期,单位s, -1代表永不过期
timeout
:
7200
timeout
:
7200
# token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
activity-timeout
:
3600
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
is-share
:
false
is-share
:
false
# token风格
# token风格
...
...
joying-common/src/main/java/com/fzm/common/entity/TbCollection.java
0 → 100644
View file @
eec97329
package
com
.
fzm
.
common
.
entity
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
import
java.util.Date
;
/**
* @author tangtuo
* @date 2021/6/23 11:54
*/
@Data
@Accessors
(
chain
=
true
)
@ApiModel
(
"收藏"
)
@TableName
(
"tb_collection"
)
public
class
TbCollection
{
@TableId
(
type
=
IdType
.
AUTO
)
private
Integer
id
;
@ApiModelProperty
(
"用户主键"
)
private
Integer
userId
;
@ApiModelProperty
(
"nft主键"
)
private
Integer
nftId
;
@ApiModelProperty
(
"创建时间"
)
private
Date
createDate
;
@ApiModelProperty
(
"修改时间"
)
private
Date
updateDate
;
}
joying-common/src/main/java/com/fzm/common/mapper/CollectionMapper.java
0 → 100644
View file @
eec97329
package
com
.
fzm
.
common
.
mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.fzm.common.entity.TbCollection
;
import
org.apache.ibatis.annotations.Mapper
;
import
java.util.List
;
/**
* @author tangtuo
* @date 2021/7/1 14:35
*/
@Mapper
public
interface
CollectionMapper
extends
BaseMapper
<
TbCollection
>
{
/**
* 根据用户id查询所有收藏的nftId
* @param userId
* @return
*/
List
<
Integer
>
getNftIdListByUserId
(
int
userId
);
}
joying-common/src/main/java/com/fzm/common/service/CollectionService.java
0 → 100644
View file @
eec97329
package
com
.
fzm
.
common
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.fzm.common.entity.TbCollection
;
import
java.util.List
;
/**
* @author tangtuo
* @date 2021/7/1 14:35
*/
public
interface
CollectionService
extends
IService
<
TbCollection
>
{
/**
* 根据用户id和nftId删除记录
*
* @param userId
* @param nftId
*/
void
deleteByUserIdAndNftId
(
int
userId
,
Integer
nftId
);
/**
* 根据用户id查询所有收藏的nftId
*
* @param userId
* @return
*/
List
<
Integer
>
getNftIdListByUserId
(
int
userId
);
}
joying-common/src/main/java/com/fzm/common/service/impl/CollectionServiceImpl.java
0 → 100644
View file @
eec97329
package
com
.
fzm
.
common
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.fzm.common.entity.TbCollection
;
import
com.fzm.common.mapper.CollectionMapper
;
import
com.fzm.common.service.CollectionService
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.List
;
/**
* @author tangtuo
* @date 2021/7/1 14:36
*/
@Service
public
class
CollectionServiceImpl
extends
ServiceImpl
<
CollectionMapper
,
TbCollection
>
implements
CollectionService
{
@Resource
private
CollectionMapper
collectionMapper
;
@Override
public
void
deleteByUserIdAndNftId
(
int
userId
,
Integer
nftId
)
{
QueryWrapper
<
TbCollection
>
wrapper
=
new
QueryWrapper
<>();
wrapper
.
eq
(
"user_id"
,
userId
).
eq
(
"nft_id"
,
nftId
);
remove
(
wrapper
);
}
@Override
public
List
<
Integer
>
getNftIdListByUserId
(
int
userId
)
{
return
collectionMapper
.
getNftIdListByUserId
(
userId
);
}
}
joying-common/src/main/java/com/fzm/common/service/impl/NftServiceImpl.java
View file @
eec97329
...
@@ -13,12 +13,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
...
@@ -13,12 +13,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import
com.fzm.common.constant.RedisConstant
;
import
com.fzm.common.constant.RedisConstant
;
import
com.fzm.common.constant.SystemConstant
;
import
com.fzm.common.constant.SystemConstant
;
import
com.fzm.common.entity.*
;
import
com.fzm.common.entity.*
;
import
com.fzm.common.entity.TbCollection
;
import
com.fzm.common.entity.vo.CollectionNftVo
;
import
com.fzm.common.entity.vo.CollectionNftVo
;
import
com.fzm.common.entity.vo.NftListVo
;
import
com.fzm.common.entity.vo.NftListVo
;
import
com.fzm.common.enums.ResultCode
;
import
com.fzm.common.enums.ResultCode
;
import
com.fzm.common.exception.GlobalException
;
import
com.fzm.common.exception.GlobalException
;
import
com.fzm.common.mapper.NftMapper
;
import
com.fzm.common.mapper.NftMapper
;
import
com.fzm.common.service.CategoryService
;
import
com.fzm.common.service.CategoryService
;
import
com.fzm.common.service.CollectionService
;
import
com.fzm.common.service.NftService
;
import
com.fzm.common.service.NftService
;
import
com.fzm.common.service.UserService
;
import
com.fzm.common.service.UserService
;
import
com.fzm.common.utils.JsonUtil
;
import
com.fzm.common.utils.JsonUtil
;
...
@@ -29,6 +31,7 @@ import com.github.pagehelper.PageInfo;
...
@@ -29,6 +31,7 @@ import com.github.pagehelper.PageInfo;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.dao.DuplicateKeyException
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -61,6 +64,9 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
...
@@ -61,6 +64,9 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
private
CategoryService
categoryService
;
private
CategoryService
categoryService
;
@Resource
@Resource
private
CollectionService
collectionService
;
@Resource
private
OssUtil
ossUtil
;
private
OssUtil
ossUtil
;
@Value
(
"${chain.para.contract-name}"
)
@Value
(
"${chain.para.contract-name}"
)
...
@@ -146,11 +152,19 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
...
@@ -146,11 +152,19 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
@Override
@Override
public
Boolean
collection
(
Integer
id
)
{
public
Boolean
collection
(
Integer
id
)
{
String
key
=
RedisConstant
.
COLLECTION_USER_PREFIX
+
StpUtil
.
getLoginIdAsInt
();
int
userId
=
StpUtil
.
getLoginIdAsInt
();
String
key
=
RedisConstant
.
COLLECTION_USER_PREFIX
+
userId
;
// 如果用户收藏的nft已经存在列表里,那么就是取消收藏
// 如果用户收藏的nft已经存在列表里,那么就是取消收藏
if
(
redisUtil
.
sIsMember
(
key
,
id
.
toString
()))
{
if
(
redisUtil
.
sIsMember
(
key
,
id
.
toString
()))
{
collectionService
.
deleteByUserIdAndNftId
(
userId
,
id
);
return
redisUtil
.
sRemove
(
key
,
id
.
toString
())
==
1
;
return
redisUtil
.
sRemove
(
key
,
id
.
toString
())
==
1
;
}
else
{
}
else
{
TbCollection
collection
=
new
TbCollection
().
setNftId
(
id
).
setUserId
(
userId
);
try
{
collectionService
.
save
(
collection
);
}
catch
(
DuplicateKeyException
e
)
{
collectionService
.
deleteByUserIdAndNftId
(
userId
,
id
);
}
return
redisUtil
.
sAdd
(
key
,
id
.
toString
())
==
1
;
return
redisUtil
.
sAdd
(
key
,
id
.
toString
())
==
1
;
}
}
}
}
...
@@ -158,13 +172,21 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
...
@@ -158,13 +172,21 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
@Override
@Override
public
List
<
CollectionNftVo
>
getCollectionList
()
{
public
List
<
CollectionNftVo
>
getCollectionList
()
{
String
key
=
RedisConstant
.
COLLECTION_USER_PREFIX
+
StpUtil
.
getLoginIdAsInt
();
int
userId
=
StpUtil
.
getLoginIdAsInt
();
Set
<
String
>
set
=
redisUtil
.
setMembers
(
key
);
// 从redis里获取当前用户的收藏列表
Set
<
String
>
set
=
redisUtil
.
setMembers
(
RedisConstant
.
COLLECTION_USER_PREFIX
+
StpUtil
.
getLoginIdAsInt
());
List
<
Integer
>
list
;
if
(
CollectionUtil
.
isEmpty
(
set
))
{
if
(
CollectionUtil
.
isEmpty
(
set
))
{
// redis里为空,再从mysql里查一次
list
=
collectionService
.
getNftIdListByUserId
(
userId
);
}
else
{
list
=
set
.
stream
().
map
(
Integer:
:
valueOf
).
collect
(
Collectors
.
toList
());
}
// mysql和redis里都为空,直接返回空集合
if
(
CollectionUtil
.
isEmpty
(
list
))
{
return
new
ArrayList
<>();
return
new
ArrayList
<>();
}
}
List
<
Integer
>
ids
=
set
.
stream
().
map
(
Integer:
:
valueOf
).
collect
(
Collectors
.
toList
());
return
nftMapper
.
getCollectionList
(
list
);
return
nftMapper
.
getCollectionList
(
ids
);
}
}
@Override
@Override
...
...
joying-common/src/main/resources/mapper/CollectionMapper.xml
0 → 100644
View file @
eec97329
<?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.fzm.common.mapper.CollectionMapper"
>
<select
id=
"getNftIdListByUserId"
resultType=
"java.lang.Integer"
>
select nft_id
from tb_collection
where user_id = #{userId}
</select>
</mapper>
\ No newline at end of file
joying-portal/src/main/resources/application-dev.yml
View file @
eec97329
...
@@ -58,8 +58,6 @@ spring:
...
@@ -58,8 +58,6 @@ spring:
token-name
:
Authorization
token-name
:
Authorization
# token有效期,单位s 默认30天, -1代表永不过期
# token有效期,单位s 默认30天, -1代表永不过期
timeout
:
86400
timeout
:
86400
# token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
activity-timeout
:
3600
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
is-share
:
false
is-share
:
false
# token风格
# token风格
...
...
joying-portal/src/main/resources/application-local.yml
View file @
eec97329
...
@@ -27,7 +27,7 @@ spring:
...
@@ -27,7 +27,7 @@ spring:
connection-properties
:
druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
connection-properties
:
druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
useGlobalDataSourceStat
:
true
useGlobalDataSourceStat
:
true
redis
:
redis
:
host
:
172.16.101.135
host
:
localhost
port
:
6379
port
:
6379
password
:
123456
password
:
123456
lettuce
:
lettuce
:
...
@@ -56,10 +56,8 @@ spring:
...
@@ -56,10 +56,8 @@ spring:
sa-token
:
sa-token
:
# token名称 (同时也是cookie名称)
# token名称 (同时也是cookie名称)
token-name
:
Authorization
token-name
:
Authorization
# token有效期,单位s 默认30天, -1代表永不过期
timeout
:
86400
# token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
# token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
activity-timeout
:
36
00
timeout
:
864
00
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
is-share
:
false
is-share
:
false
# token风格
# token风格
...
...
joying-portal/src/main/resources/application-test.yml
View file @
eec97329
...
@@ -58,8 +58,6 @@ spring:
...
@@ -58,8 +58,6 @@ spring:
token-name
:
Authorization
token-name
:
Authorization
# token有效期,单位s 默认30天, -1代表永不过期
# token有效期,单位s 默认30天, -1代表永不过期
timeout
:
86400
timeout
:
86400
# token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
activity-timeout
:
3600
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
is-share
:
false
is-share
:
false
# token风格
# token风格
...
...
sql/joying.sql
View file @
eec97329
...
@@ -103,10 +103,14 @@ VALUES (7, '其他', 'OTHER', '2021-07-01 06:30:50', '2021-07-01 06:30:50', NULL
...
@@ -103,10 +103,14 @@ VALUES (7, '其他', 'OTHER', '2021-07-01 06:30:50', '2021-07-01 06:30:50', NULL
DROP
TABLE
IF
EXISTS
`tb_collection`
;
DROP
TABLE
IF
EXISTS
`tb_collection`
;
CREATE
TABLE
`tb_collection`
CREATE
TABLE
`tb_collection`
(
(
`user_id`
int
(
11
)
NOT
NULL
COMMENT
'用户主键'
,
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
COMMENT
'主键'
,
`nft_id`
int
(
11
)
NOT
NULL
COMMENT
'nft主键'
,
`user_id`
int
(
11
)
NOT
NULL
COMMENT
'用户主键'
,
PRIMARY
KEY
(
`user_id`
,
`nft_id`
)
USING
BTREE
`nft_id`
int
(
11
)
NOT
NULL
COMMENT
'nft主键'
,
)
ENGINE
=
InnoDB
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Dynamic
;
`create_date`
datetime
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`update_date`
datetime
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
ON
UPDATE
CURRENT_TIMESTAMP
,
PRIMARY
KEY
(
`id`
)
USING
BTREE
,
UNIQUE
KEY
`idx_userid_nftid`
(
`user_id`
,
`nft_id`
)
USING
BTREE
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
-- ----------------------------
-- ----------------------------
-- Table structure for tb_label
-- Table structure for tb_label
...
...
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