Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
2c019c6f
Commit
2c019c6f
authored
Aug 14, 2023
by
muhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改 小程序藏品和收藏册接口
parent
88f442b6
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
252 additions
and
34 deletions
+252
-34
ch-dao/src/main/java/com/wwdz/ch/db/impl/ItemDaoImpl.java
ch-dao/src/main/java/com/wwdz/ch/db/impl/ItemDaoImpl.java
+1
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/request/ItemRequestDto.java
...in/java/com/wwdz/ch/wx/entity/request/ItemRequestDto.java
+1
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/vo/FavoritesResponseVo.java
...in/java/com/wwdz/ch/wx/entity/vo/FavoritesResponseVo.java
+2
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/FavoritesServiceImpl.java
...c/main/java/com/wwdz/ch/wx/impl/FavoritesServiceImpl.java
+36
-4
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
...pi/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
+88
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
...pi/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
+6
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/WxLoginServiceImpl.java
...src/main/java/com/wwdz/ch/wx/impl/WxLoginServiceImpl.java
+32
-23
ch-wx-api/src/main/java/com/wwdz/ch/wx/interceptor/LoginInterceptor.java
...ain/java/com/wwdz/ch/wx/interceptor/LoginInterceptor.java
+1
-6
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/ItemService.java
...api/src/main/java/com/wwdz/ch/wx/service/ItemService.java
+4
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/UserTokenManager.java
...rc/main/java/com/wwdz/ch/wx/service/UserTokenManager.java
+25
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/WxLoginService.java
.../src/main/java/com/wwdz/ch/wx/service/WxLoginService.java
+2
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/WxItemController.java
...pi/src/main/java/com/wwdz/ch/wx/web/WxItemController.java
+54
-0
No files found.
ch-dao/src/main/java/com/wwdz/ch/db/impl/ItemDaoImpl.java
View file @
2c019c6f
...
...
@@ -47,6 +47,7 @@ public class ItemDaoImpl implements ItemDao {
JdbcHelper
.
ifPresent
(
coinRequestDto
.
getId
(),
criteria
::
andIdEqualTo
);
JdbcHelper
.
ifPresent
(
coinRequestDto
.
getName
(),
criteria
::
andNameLike
);
JdbcHelper
.
ifPresent
(
coinRequestDto
.
getCid
(),
criteria
::
andCidEqualTo
);
JdbcHelper
.
ifPresent
(
coinRequestDto
.
getIds
(),
criteria:
:
andIdIn
);
return
itemMapper
.
selectByExample
(
example
);
}
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/request/ItemRequestDto.java
View file @
2c019c6f
...
...
@@ -31,4 +31,5 @@ public class ItemRequestDto implements Entity {
private
String
price
;
private
Integer
page
;
private
Integer
size
;
private
String
path
;
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/vo/FavoritesResponseVo.java
View file @
2c019c6f
...
...
@@ -4,6 +4,7 @@ import com.xxdxxs.entity.Entity;
import
lombok.Data
;
import
java.util.Date
;
import
java.util.List
;
@Data
public
class
FavoritesResponseVo
implements
Entity
{
...
...
@@ -14,6 +15,6 @@ public class FavoritesResponseVo implements Entity {
private
Date
addTime
;
private
Date
updateTime
;
private
Boolean
deleted
;
private
String
images
;
private
List
<
String
>
images
;
private
long
count
;
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/FavoritesServiceImpl.java
View file @
2c019c6f
...
...
@@ -19,6 +19,7 @@ import com.wwdz.ch.wx.entity.vo.FavoritesResponseVo;
import
com.wwdz.ch.wx.entity.vo.ItemResponseVo
;
import
com.wwdz.ch.wx.service.FavoritesService
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -26,7 +27,10 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.stream.Collectors
;
@Service
...
...
@@ -90,7 +94,26 @@ public class FavoritesServiceImpl implements FavoritesService {
vo
.
setSort
(
favorites
.
getSort
());
vo
.
setDeleted
(
favorites
.
getDeleted
());
vo
.
setAddTime
(
favorites
.
getAddTime
());
vo
.
setImages
(
favorites
.
getImages
());
vo
.
setImages
(
new
ArrayList
<>());
// 获取藏品的图片
List
<
FavoritesItemsRelation
>
favoritesItemsRelations
=
favoritesItemsRelationDao
.
listByFavoritesId
(
favorites
.
getId
(),
null
);
if
(
CollectionUtils
.
isNotEmpty
(
favoritesItemsRelations
))
{
CoinRequestDto
coinRequestDto
=
new
CoinRequestDto
();
coinRequestDto
.
setIds
(
favoritesItemsRelations
.
stream
()
.
map
(
FavoritesItemsRelation:
:
getItemId
).
collect
(
Collectors
.
toList
()));
List
<
Item
>
items
=
itemDao
.
findList
(
coinRequestDto
);
items
=
items
.
stream
().
filter
(
s
->
StringUtils
.
isNotBlank
(
s
.
getImages
())).
collect
(
Collectors
.
toList
());
if
(
CollectionUtils
.
isNotEmpty
(
items
))
{
List
<
String
>
images
=
new
ArrayList
<>();
int
i
=
0
;
while
(
Objects
.
nonNull
(
items
.
get
(
i
))
&&
i
<
4
)
{
String
[]
image
=
items
.
get
(
i
).
getImages
().
split
(
";"
);
images
.
add
(
image
[
0
]);
i
++;
}
vo
.
setImages
(
images
);
}
}
vo
.
setUpdateTime
(
favorites
.
getUpdateTime
());
vo
.
setCount
(
favoritesItemsRelationDao
.
countByFavoritesId
(
favorites
.
getId
()));
agentTranceResponseVo
.
setDetail
(
vo
);
...
...
@@ -119,7 +142,7 @@ public class FavoritesServiceImpl implements FavoritesService {
vo
.
setSort
(
favorites
.
getSort
());
vo
.
setDeleted
(
favorites
.
getDeleted
());
vo
.
setAddTime
(
favorites
.
getAddTime
());
vo
.
setImages
(
favorites
.
getImages
());
//
vo.setImages(favorites.getImages());
vo
.
setUpdateTime
(
favorites
.
getUpdateTime
());
vo
.
setCount
(
favoritesItemsRelationDao
.
countByFavoritesId
(
favorites
.
getId
()));
result
.
add
(
vo
);
...
...
@@ -193,8 +216,17 @@ public class FavoritesServiceImpl implements FavoritesService {
if
(
Objects
.
isNull
(
favorites
))
{
return
Result
.
failed
(
"数据异常,记录不存在"
);
}
FavoritesResponseVo
vo
=
new
FavoritesResponseVo
();
vo
.
setId
(
favorites
.
getId
());
vo
.
setTitle
(
favorites
.
getTitle
());
vo
.
setDescription
(
favorites
.
getDescription
());
vo
.
setSort
(
favorites
.
getSort
());
vo
.
setDeleted
(
favorites
.
getDeleted
());
vo
.
setAddTime
(
favorites
.
getAddTime
());
vo
.
setUpdateTime
(
favorites
.
getUpdateTime
());
vo
.
setCount
(
favoritesItemsRelationDao
.
countByFavoritesId
(
favorites
.
getId
()));
logger
.
info
(
"【请求结束】查看收藏册详情成功"
);
return
Result
.
success
(
favorites
);
return
Result
.
success
(
vo
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"查看收藏册详情失败,原因:"
+
e
.
getMessage
(),
e
);
return
Result
.
failed
(
"查看收藏册详情失败"
);
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
View file @
2c019c6f
...
...
@@ -11,6 +11,11 @@ import com.wwdz.ch.wx.entity.vo.AgentTranceResponseVo;
import
com.wwdz.ch.wx.entity.vo.ItemResponseVo
;
import
com.wwdz.ch.wx.service.ItemService
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -18,6 +23,8 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
import
java.io.ByteArrayOutputStream
;
import
java.io.InputStream
;
import
java.util.*
;
@Service
...
...
@@ -43,6 +50,7 @@ public class ItemServiceImpl implements ItemService {
CoinRequestDto
coinRequestDto
=
new
CoinRequestDto
();
coinRequestDto
.
setPage
(
dto
.
getPage
());
coinRequestDto
.
setLimit
(
dto
.
getSize
());
coinRequestDto
.
setIsExcluded
(
1
);
PageInfo
<
Item
>
page
=
itemDao
.
findByPage
(
coinRequestDto
);
PageInfo
<
AgentTranceResponseVo
>
result
=
new
PageInfo
<>();
result
.
setPageNum
(
page
.
getPageNum
());
...
...
@@ -88,6 +96,59 @@ public class ItemServiceImpl implements ItemService {
}
}
@Override
public
Result
search
(
ItemRequestDto
dto
)
{
try
{
CoinRequestDto
coinRequestDto
=
new
CoinRequestDto
();
coinRequestDto
.
setPage
(
dto
.
getPage
());
coinRequestDto
.
setLimit
(
dto
.
getSize
());
coinRequestDto
.
setIsExcluded
(
1
);
coinRequestDto
.
setName
(
dto
.
getName
());
PageInfo
<
Item
>
page
=
itemDao
.
findByPage
(
coinRequestDto
);
PageInfo
<
AgentTranceResponseVo
>
result
=
new
PageInfo
<>();
result
.
setPageNum
(
page
.
getPageNum
());
result
.
setPageSize
(
page
.
getPageSize
());
result
.
setTotal
(
page
.
getTotal
());
result
.
setList
(
new
ArrayList
<>());
result
.
setHasNextPage
(
page
.
isHasNextPage
());
if
(
CollectionUtils
.
isEmpty
(
page
.
getList
()))
{
return
Result
.
success
(
result
);
}
List
<
AgentTranceResponseVo
>
resultList
=
new
ArrayList
<>();
for
(
Item
item
:
page
.
getList
())
{
ItemResponseVo
vo
=
new
ItemResponseVo
();
vo
.
setId
(
item
.
getId
());
vo
.
setName
(
item
.
getName
());
vo
.
setImages
(
item
.
getImages
());
vo
.
setPrice
(
String
.
valueOf
(
item
.
getPrice
()
*
100
));
vo
.
setDetail
(
item
.
getDetail
());
vo
.
setIsCollected
(
0
);
if
(!
dto
.
getUserId
().
equals
(
0L
))
{
vo
.
setIsCollected
(
favoritesItemsRelationDao
.
isCollected
(
dto
.
getUserId
(),
item
.
getId
())
?
1
:
0
);
vo
.
setIsMine
(
userItemsRelationDao
.
isExisted
(
dto
.
getUserId
(),
item
.
getId
())
?
1
:
0
);
}
long
count
=
favoritesItemsRelationDao
.
countByItemId
(
item
.
getId
());
if
(
item
.
getSourceType
().
equals
(
CommonEnum
.
SourceTypeEnum
.
USER_UPLOAD
.
getCode
()))
{
count
--;
}
vo
.
setCollectCount
(
count
);
vo
.
setSourceType
(
item
.
getSourceType
());
AgentTranceResponseVo
agentTranceResponseVo
=
new
AgentTranceResponseVo
();
agentTranceResponseVo
.
setAgentTraceInfo_
(
""
);
agentTranceResponseVo
.
setViewType
(
1
);
agentTranceResponseVo
.
setDetail
(
vo
);
resultList
.
add
(
agentTranceResponseVo
);
}
result
.
setList
(
resultList
);
logger
.
info
(
"【请求结束】查询首页搜索成功"
);
return
Result
.
success
(
result
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"查询首页搜索失败"
,
e
);
return
Result
.
failed
(
"搜索失败"
);
}
}
@Override
public
Result
list
(
ItemRequestDto
dto
)
{
return
null
;
...
...
@@ -194,6 +255,10 @@ public class ItemServiceImpl implements ItemService {
if
(
dto
.
getUserId
().
equals
(
0L
))
{
return
Result
.
failed
(
"您尚未登录,请先登录"
);
}
// 判断是否收藏过
if
(
favoritesItemsRelationDao
.
isCollected
(
dto
.
getUserId
(),
dto
.
getId
()))
{
Result
.
failed
(
"您已经收藏过该藏品"
);
}
// 查找默认收藏册
Favorites
favorites
=
favoritesDao
.
defaultFavorites
(
dto
.
getUserId
());
if
(
Objects
.
isNull
(
favorites
))
{
...
...
@@ -268,4 +333,27 @@ public class ItemServiceImpl implements ItemService {
return
Result
.
failed
(
"修改藏品失败"
);
}
}
@Override
public
Result
test
()
{
try
{
String
url
=
"https://cdn.wanwudezhi.com/static/web-static/video/53596700878a572ca4fae35243aaa819.mp4?vframe/jpg/offset/0"
;
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
HttpGet
get
=
new
HttpGet
(
url
);
HttpResponse
response
=
httpClient
.
execute
(
get
);
HttpEntity
entity
=
response
.
getEntity
();
InputStream
inputStream
=
entity
.
getContent
();
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
4096
];
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
outputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byte
[]
bytes
=
outputStream
.
toByteArray
();
return
Result
.
success
(
Base64
.
getEncoder
().
encodeToString
(
bytes
));
}
catch
(
Exception
e
)
{
logger
.
error
(
"error"
,
e
);
return
Result
.
failed
(
e
.
getMessage
());
}
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
View file @
2c019c6f
...
...
@@ -126,6 +126,9 @@ public class UserServiceImpl implements UserService {
}
}
// 先登出其他
userTokenManager
.
removeToken
(
user
.
getId
());
// token
UserToken
userToken
=
null
;
try
{
...
...
@@ -248,6 +251,9 @@ public class UserServiceImpl implements UserService {
}
}
// 先登出其他
userTokenManager
.
removeToken
(
user
.
getId
());
// token
UserToken
userToken
=
null
;
try
{
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/WxLoginServiceImpl.java
View file @
2c019c6f
...
...
@@ -11,7 +11,7 @@ import com.wwdz.ch.wx.entity.request.UserRequestDto;
import
com.wwdz.ch.wx.service.WxLoginService
;
import
com.wwdz.ch.wx.util.RedisUtil
;
import
com.xxdxxs.utils.JsonUtils
;
import
com.xxdxxs.utils
.StringUtils
;
import
org.apache.commons.lang3
.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -32,6 +32,7 @@ public class WxLoginServiceImpl implements WxLoginService {
private
static
final
String
GET_ACCESS_TOKEN_URL
=
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s"
;
private
static
final
String
GET_PHONE_URL
=
"https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=%s"
;
private
static
final
String
GET_WXACODE_URL
=
"https://api.weixin.qq.com/wxa/getwxacode?access_token=%s"
;
@Autowired
private
WxMaService
wxMaService
;
...
...
@@ -43,27 +44,9 @@ public class WxLoginServiceImpl implements WxLoginService {
public
String
getPhone
(
UserRequestDto
dto
)
{
String
phone
=
""
;
if
(
dto
.
getType
()
==
1
)
{
logger
.
info
(
"开始获取access_token----------------"
);
String
accessToken
=
""
;
if
(
redisUtil
.
hasKey
(
CacheCodeConstants
.
WX_ACCESS_TOKEN
))
{
accessToken
=
redisUtil
.
get
(
CacheCodeConstants
.
WX_ACCESS_TOKEN
).
toString
();
}
else
{
try
{
String
accessTokenUrl
=
String
.
format
(
GET_ACCESS_TOKEN_URL
,
appid
,
secret
);
String
res
=
OkHttpUtil
.
builder
().
url
(
accessTokenUrl
)
.
get
().
sync
();
logger
.
info
(
"获取access_token结果:"
+
res
);
if
(!
res
.
contains
(
"access_token"
))
{
logger
.
error
(
"获取accessToken出错,返回结果是:"
+
res
);
return
"false"
;
}
accessToken
=
JsonUtils
.
getValueByPath
(
res
,
"access_token"
);
String
expiresIn
=
JsonUtils
.
getValueByPath
(
res
,
"expires_in"
);
redisUtil
.
set
(
CacheCodeConstants
.
WX_ACCESS_TOKEN
,
accessToken
,
Long
.
parseLong
(
expiresIn
));
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取accessToken出错"
,
e
);
return
"false"
;
}
String
accessToken
=
getAccessToken
();
if
(
StringUtils
.
isBlank
(
accessToken
))
{
return
"false"
;
}
logger
.
info
(
"开始获取phone-----------------------"
);
...
...
@@ -90,7 +73,7 @@ public class WxLoginServiceImpl implements WxLoginService {
logger
.
error
(
"获取用户登录信息失败"
,
e
);
return
"sessionFalse"
;
}
if
(
StringUtils
.
is
Empty
(
sessionKey
))
{
if
(
StringUtils
.
is
Blank
(
sessionKey
))
{
logger
.
error
(
"微信登录,调用官方接口失败:{}"
,
dto
.
getCode
());
return
"sessionFalse"
;
}
...
...
@@ -107,4 +90,30 @@ public class WxLoginServiceImpl implements WxLoginService {
}
return
phone
;
}
@Override
public
String
getAccessToken
()
{
logger
.
info
(
"开始获取access_token----------------"
);
try
{
if
(
redisUtil
.
hasKey
(
CacheCodeConstants
.
WX_ACCESS_TOKEN
))
{
return
redisUtil
.
get
(
CacheCodeConstants
.
WX_ACCESS_TOKEN
).
toString
();
}
else
{
String
accessTokenUrl
=
String
.
format
(
GET_ACCESS_TOKEN_URL
,
appid
,
secret
);
String
res
=
OkHttpUtil
.
builder
().
url
(
accessTokenUrl
)
.
get
().
sync
();
logger
.
info
(
"获取access_token结果:"
+
res
);
if
(!
res
.
contains
(
"access_token"
))
{
logger
.
error
(
"获取accessToken出错,返回结果是:"
+
res
);
return
null
;
}
String
accessToken
=
JsonUtils
.
getValueByPath
(
res
,
"access_token"
);
String
expiresIn
=
JsonUtils
.
getValueByPath
(
res
,
"expires_in"
);
redisUtil
.
set
(
CacheCodeConstants
.
WX_ACCESS_TOKEN
,
accessToken
,
Long
.
parseLong
(
expiresIn
));
return
accessToken
;
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取access_token失败"
,
e
);
return
null
;
}
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/interceptor/LoginInterceptor.java
View file @
2c019c6f
...
...
@@ -14,7 +14,6 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Objects
;
@Component
public
class
LoginInterceptor
implements
HandlerInterceptor
{
...
...
@@ -32,12 +31,8 @@ public class LoginInterceptor implements HandlerInterceptor {
logger
.
info
(
"请求头名称:"
+
JSON
.
toJSONString
(
request
.
getHeaderNames
()));
String
token
=
request
.
getHeader
(
"Authorization"
);
logger
.
info
(
"token的值是:"
+
token
);
if
(
StringUtils
.
isBlank
(
token
))
{
return
true
;
}
if
(
StringUtils
.
isNotBlank
(
token
))
{
Long
userId
=
userTokenManager
.
getUserId
(
token
);
if
(
Objects
.
nonNull
(
userId
))
{
if
(
userTokenManager
.
checkLogin
(
token
))
{
return
true
;
}
}
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/ItemService.java
View file @
2c019c6f
...
...
@@ -6,6 +6,8 @@ import com.wwdz.ch.wx.entity.request.ItemRequestDto;
public
interface
ItemService
{
Result
page
(
ItemRequestDto
dto
);
Result
search
(
ItemRequestDto
dto
);
Result
list
(
ItemRequestDto
dto
);
Result
add
(
ItemRequestDto
dto
);
...
...
@@ -17,4 +19,6 @@ public interface ItemService {
Result
cancel
(
ItemRequestDto
dto
);
Result
update
(
ItemRequestDto
dto
);
Result
test
();
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/UserTokenManager.java
View file @
2c019c6f
...
...
@@ -4,12 +4,14 @@ import com.google.gson.Gson;
import
com.wwdz.ch.core.util.CharUtil
;
import
com.wwdz.ch.wx.dao.UserToken
;
import
com.wwdz.ch.wx.util.RedisUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Objects
;
/**
* 维护用户token
...
...
@@ -46,6 +48,29 @@ public class UserTokenManager {
return
userToken
.
getUserId
();
}
public
boolean
checkLogin
(
String
token
)
{
String
key
=
TOKEN_PREFIX
+
token
;
Object
tokenObj
=
redisUtil
.
get
(
key
);
if
(
Objects
.
isNull
(
tokenObj
))
{
return
false
;
}
UserToken
userToken
=
gson
.
fromJson
(
tokenObj
.
toString
(),
UserToken
.
class
);
if
(
userToken
.
getExpireTime
().
isBefore
(
LocalDateTime
.
now
()))
{
redisUtil
.
del
(
key
);
String
idKey
=
TOKEN_ID_PREFIX
+
userToken
.
getUserId
();
redisUtil
.
del
(
idKey
);
return
false
;
}
String
idKey
=
TOKEN_ID_PREFIX
+
userToken
.
getUserId
();
Object
idObj
=
redisUtil
.
get
(
idKey
);
if
(
Objects
.
isNull
(
idObj
))
{
return
false
;
}
UserToken
idUserToken
=
gson
.
fromJson
(
idObj
.
toString
(),
UserToken
.
class
);
String
idToken
=
idUserToken
.
getToken
();
return
StringUtils
.
equals
(
token
,
idToken
);
}
public
UserToken
generateToken
(
Long
id
)
{
UserToken
userToken
=
null
;
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/WxLoginService.java
View file @
2c019c6f
...
...
@@ -4,4 +4,6 @@ import com.wwdz.ch.wx.entity.request.UserRequestDto;
public
interface
WxLoginService
{
String
getPhone
(
UserRequestDto
dto
);
String
getAccessToken
();
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/WxItemController.java
View file @
2c019c6f
...
...
@@ -4,6 +4,7 @@ import com.wwdz.ch.core.type.Result;
import
com.wwdz.ch.wx.entity.request.ItemRequestDto
;
import
com.wwdz.ch.wx.entity.request.KlDataRequestDto
;
import
com.wwdz.ch.wx.service.ItemService
;
import
com.wwdz.ch.wx.service.WxLoginService
;
import
com.xxdxxs.utils.JsonUtils
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -15,6 +16,9 @@ import org.springframework.web.bind.annotation.RequestBody;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.HashMap
;
import
java.util.Map
;
@RestController
@RequestMapping
(
"/wx/item"
)
public
class
WxItemController
{
...
...
@@ -22,6 +26,8 @@ public class WxItemController {
@Autowired
private
ItemService
itemService
;
@Autowired
private
WxLoginService
wxLoginService
;
@ApiOperation
(
value
=
"分页查询"
)
@PostMapping
(
"/page"
)
...
...
@@ -48,6 +54,36 @@ public class WxItemController {
return
itemService
.
page
(
dto
);
}
@ApiOperation
(
value
=
"搜索分页查询"
)
@PostMapping
(
"/search"
)
public
Result
search
(
@RequestBody
KlDataRequestDto
klDataRequestDto
)
{
String
json
=
klDataRequestDto
.
getKl_data
();
logger
.
info
(
"【请求开始】藏品列表搜索,请求参数,kl_data:{}"
,
json
);
String
userId
=
JsonUtils
.
getValueByPath
(
json
,
"userId"
);
String
name
=
JsonUtils
.
getValueByPath
(
json
,
"name"
);
String
page
=
JsonUtils
.
getValueByPath
(
json
,
"page"
);
String
size
=
JsonUtils
.
getValueByPath
(
json
,
"size"
);
if
(
StringUtils
.
isBlank
(
page
))
{
return
Result
.
failed
(
"当前页不能为空"
);
}
if
(
StringUtils
.
isBlank
(
size
))
{
return
Result
.
failed
(
"页面大小不能为空"
);
}
if
(
StringUtils
.
isBlank
(
name
))
{
return
Result
.
failed
(
"搜索内容不能为空"
);
}
ItemRequestDto
dto
=
new
ItemRequestDto
();
dto
.
setUserId
(
0L
);
if
(
StringUtils
.
isNotBlank
(
userId
))
{
dto
.
setUserId
(
Long
.
parseLong
(
userId
));
}
dto
.
setPage
(
Integer
.
parseInt
(
page
));
dto
.
setSize
(
Integer
.
parseInt
(
size
));
dto
.
setName
(
name
);
return
itemService
.
search
(
dto
);
}
@ApiOperation
(
value
=
"列表查询"
)
@PostMapping
(
"/list"
)
public
Result
list
(
@RequestBody
ItemRequestDto
dto
)
{
...
...
@@ -202,4 +238,22 @@ public class WxItemController {
dto
.
setId
(
Long
.
parseLong
(
id
));
return
itemService
.
cancel
(
dto
);
}
@ApiOperation
(
value
=
"小程序授权码"
)
@PostMapping
(
"/getAccessToken"
)
public
Result
getAccessToken
()
{
String
accessToken
=
wxLoginService
.
getAccessToken
();
if
(
StringUtils
.
isBlank
(
accessToken
))
{
return
Result
.
failed
(
"获取access_token失败"
);
}
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"access_token"
,
accessToken
);
return
Result
.
success
(
map
);
}
@ApiOperation
(
value
=
"小程序授权码"
)
@PostMapping
(
"/test"
)
public
Result
test
()
{
return
itemService
.
test
();
}
}
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