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
679a1eca
Commit
679a1eca
authored
Aug 11, 2023
by
muhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改 小程序收藏
parent
e5d19519
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
111 additions
and
40 deletions
+111
-40
ch-dao/src/main/java/com/wwdz/ch/db/dao/FavoritesDao.java
ch-dao/src/main/java/com/wwdz/ch/db/dao/FavoritesDao.java
+1
-4
ch-dao/src/main/java/com/wwdz/ch/db/impl/FavoritesDaoImpl.java
...o/src/main/java/com/wwdz/ch/db/impl/FavoritesDaoImpl.java
+9
-0
ch-dao/src/main/java/com/wwdz/ch/db/impl/FavoritesItemsRelationDaoImpl.java
...va/com/wwdz/ch/db/impl/FavoritesItemsRelationDaoImpl.java
+1
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/FavoritesServiceImpl.java
...c/main/java/com/wwdz/ch/wx/impl/FavoritesServiceImpl.java
+5
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
...pi/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
+51
-31
ch-wx-api/src/main/java/com/wwdz/ch/wx/interceptor/LoginInterceptor.java
...ain/java/com/wwdz/ch/wx/interceptor/LoginInterceptor.java
+1
-4
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/ItemService.java
...api/src/main/java/com/wwdz/ch/wx/service/ItemService.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
+41
-1
No files found.
ch-dao/src/main/java/com/wwdz/ch/db/dao/FavoritesDao.java
View file @
679a1eca
...
...
@@ -10,12 +10,9 @@ public interface FavoritesDao {
int
delete
(
Long
id
);
int
update
(
Favorites
record
);
Favorites
info
(
Long
id
);
List
<
Favorites
>
listByUserId
(
Long
userId
);
PageInfo
<
Favorites
>
pageByUserId
(
Long
userId
,
int
page
,
int
size
);
boolean
isExisted
(
Long
id
,
Long
userId
,
String
title
);
int
delete
(
Long
id
,
List
<
Long
>
ids
);
Favorites
defaultFavorites
(
Long
userId
);
}
ch-dao/src/main/java/com/wwdz/ch/db/impl/FavoritesDaoImpl.java
View file @
679a1eca
...
...
@@ -89,4 +89,13 @@ public class FavoritesDaoImpl implements FavoritesDao {
favorites
.
setUpdateTime
(
new
Date
());
return
favoritesMapper
.
updateByExampleSelective
(
favorites
,
example
);
}
@Override
public
Favorites
defaultFavorites
(
Long
userId
)
{
FavoritesExample
example
=
new
FavoritesExample
();
FavoritesExample
.
Criteria
criteria
=
example
.
createCriteria
();
criteria
.
andUserIdEqualTo
(
userId
);
criteria
.
andSortEqualTo
(
1
);
return
favoritesMapper
.
selectOneByExample
(
example
);
}
}
ch-dao/src/main/java/com/wwdz/ch/db/impl/FavoritesItemsRelationDaoImpl.java
View file @
679a1eca
...
...
@@ -2,6 +2,7 @@ package com.wwdz.ch.db.impl;
import
com.github.pagehelper.PageHelper
;
import
com.github.pagehelper.PageInfo
;
import
com.wwdz.ch.db.domain.Favorites
;
import
com.wwdz.ch.db.mapper.FavoritesItemsRelationMapper
;
import
com.wwdz.ch.db.domain.FavoritesItemsRelation
;
import
com.wwdz.ch.db.domain.FavoritesItemsRelationExample
;
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/FavoritesServiceImpl.java
View file @
679a1eca
...
...
@@ -359,6 +359,10 @@ public class FavoritesServiceImpl implements FavoritesService {
@Override
public
Result
moveItem
(
ItemRequestDto
dto
)
{
try
{
Favorites
favorites
=
favoritesDao
.
info
(
dto
.
getAfterFavoritesId
());
if
(
Objects
.
isNull
(
favorites
))
{
return
Result
.
failed
(
"数据异常,目标收藏册不存在"
);
}
// 删除原收藏册和藏品关联记录
favoritesItemsRelationDao
.
deleteByChosen
(
dto
.
getBeforeFavoritesId
(),
dto
.
getItemIds
());
...
...
@@ -368,6 +372,7 @@ public class FavoritesServiceImpl implements FavoritesService {
for
(
Long
itemId
:
dto
.
getItemIds
())
{
FavoritesItemsRelation
record
=
new
FavoritesItemsRelation
();
record
.
setFavoritesId
(
dto
.
getAfterFavoritesId
());
record
.
setUserId
(
favorites
.
getUserId
());
record
.
setItemId
(
itemId
);
record
.
setAddTime
(
now
);
list
.
add
(
record
);
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
View file @
679a1eca
...
...
@@ -3,14 +3,8 @@ package com.wwdz.ch.wx.impl;
import
com.github.pagehelper.PageInfo
;
import
com.wwdz.ch.core.consts.CommonEnum
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.db.dao.CategoryDao
;
import
com.wwdz.ch.db.dao.FavoritesItemsRelationDao
;
import
com.wwdz.ch.db.dao.ItemDao
;
import
com.wwdz.ch.db.dao.UserItemsRelationDao
;
import
com.wwdz.ch.db.domain.Category
;
import
com.wwdz.ch.db.domain.FavoritesItemsRelation
;
import
com.wwdz.ch.db.domain.Item
;
import
com.wwdz.ch.db.domain.UserItemsRelation
;
import
com.wwdz.ch.db.dao.*
;
import
com.wwdz.ch.db.domain.*
;
import
com.wwdz.ch.db.dto.request.CoinRequestDto
;
import
com.wwdz.ch.wx.entity.request.ItemRequestDto
;
import
com.wwdz.ch.wx.entity.vo.AgentTranceResponseVo
;
...
...
@@ -37,6 +31,10 @@ public class ItemServiceImpl implements ItemService {
private
FavoritesItemsRelationDao
favoritesItemsRelationDao
;
@Autowired
private
CategoryDao
categoryDao
;
@Autowired
private
FootPrintDao
footPrintDao
;
@Autowired
private
FavoritesDao
favoritesDao
;
@Override
...
...
@@ -66,6 +64,7 @@ public class ItemServiceImpl implements ItemService {
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
()))
{
...
...
@@ -73,7 +72,6 @@ public class ItemServiceImpl implements ItemService {
}
vo
.
setCollectCount
(
count
);
vo
.
setSourceType
(
item
.
getSourceType
());
vo
.
setIsMine
(
0
);
AgentTranceResponseVo
agentTranceResponseVo
=
new
AgentTranceResponseVo
();
agentTranceResponseVo
.
setAgentTraceInfo_
(
""
);
...
...
@@ -170,6 +168,16 @@ public class ItemServiceImpl implements ItemService {
itemResponseVo
.
setIsCollected
(
0
);
}
itemResponseVo
.
setIsMine
(
userItemsRelationDao
.
isExisted
(
dto
.
getUserId
(),
item
.
getId
())
?
1
:
0
);
// 添加用户足迹
Footprint
footprint
=
new
Footprint
();
footprint
.
setUserId
(
dto
.
getUserId
());
footprint
.
setItemId
(
item
.
getId
());
Date
now
=
new
Date
();
footprint
.
setAddTime
(
now
);
footprint
.
setUpdateTime
(
now
);
footprint
.
setDeleted
(
false
);
footPrintDao
.
insert
(
footprint
);
}
logger
.
info
(
"【请求结束】查看藏品详情成功"
);
return
Result
.
success
(
itemResponseVo
);
...
...
@@ -183,36 +191,48 @@ public class ItemServiceImpl implements ItemService {
@Override
public
Result
collect
(
ItemRequestDto
dto
)
{
try
{
Item
item
=
itemDao
.
findDetails
(
dto
.
getId
());
if
(
null
==
item
.
getId
())
{
return
Result
.
failed
(
"数据异常,该藏品不存在"
);
if
(
dto
.
getUserId
().
equals
(
0L
))
{
return
Result
.
failed
(
"您尚未登录,请先登录"
);
}
// 查找默认收藏册
Favorites
favorites
=
favoritesDao
.
defaultFavorites
(
dto
.
getUserId
());
if
(
Objects
.
isNull
(
favorites
))
{
return
Result
.
failed
(
"数据异常,查询不到用户的默认收藏册"
);
}
item
.
setName
(
dto
.
getName
());
item
.
setCid
(
dto
.
getCid
());
item
.
setImages
(
dto
.
getImages
());
item
.
setPrice
(
Long
.
parseLong
(
dto
.
getPrice
())
/
100
);
item
.
setDetail
(
dto
.
getDetail
());
Date
now
=
new
Date
();
item
.
setUpdateTime
(
now
);
item
.
setSourceType
(
CommonEnum
.
SourceTypeEnum
.
USER_UPLOAD
.
getCode
());
item
.
setIsDeleted
(
false
);
itemDao
.
update
(
item
);
// 删除藏品和原收藏册关联
List
<
Long
>
itemIds
=
new
ArrayList
<>();
itemIds
.
add
(
item
.
getId
());
favoritesItemsRelationDao
.
deleteByChosen
(
dto
.
getBeforeFavoritesId
(),
itemIds
);
// 新增藏品和新收藏册关联
FavoritesItemsRelation
favoritesItemsRelation
=
new
FavoritesItemsRelation
();
favoritesItemsRelation
.
setUserId
(
dto
.
getUserId
());
favoritesItemsRelation
.
setFavoritesId
(
dto
.
getAfterFavorites
Id
());
favoritesItemsRelation
.
setItemId
(
item
.
getId
());
favoritesItemsRelation
.
setFavoritesId
(
favorites
.
get
Id
());
favoritesItemsRelation
.
setItemId
(
dto
.
getId
());
favoritesItemsRelationDao
.
insert
(
favoritesItemsRelation
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"favoritesId"
,
favorites
.
getId
());
return
Result
.
success
(
map
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"首页收藏失败,原因:"
+
e
.
getMessage
(),
e
);
return
Result
.
failed
(
"首页收藏失败"
);
}
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
public
Result
cancel
(
ItemRequestDto
dto
)
{
try
{
if
(
dto
.
getUserId
().
equals
(
0L
))
{
return
Result
.
failed
(
"您尚未登录,请先登录"
);
}
if
(
userItemsRelationDao
.
isExisted
(
dto
.
getUserId
(),
dto
.
getId
()))
{
return
Result
.
failed
(
"操作失败,无法取消收藏"
);
}
// 删除藏品和收藏册关联
favoritesItemsRelationDao
.
deleteByUserIdItemId
(
dto
.
getUserId
(),
dto
.
getId
());
return
Result
.
success
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"
修改藏品
失败,原因:"
+
e
.
getMessage
(),
e
);
return
Result
.
failed
(
"
修改藏品
失败"
);
logger
.
error
(
"
首页取消收藏
失败,原因:"
+
e
.
getMessage
(),
e
);
return
Result
.
failed
(
"
首页取消收藏
失败"
);
}
}
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/interceptor/LoginInterceptor.java
View file @
679a1eca
...
...
@@ -30,10 +30,7 @@ public class LoginInterceptor implements HandlerInterceptor {
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
logger
.
info
(
"-------------进入拦截器"
);
logger
.
info
(
"请求头名称:"
+
JSON
.
toJSONString
(
request
.
getHeaderNames
()));
String
token
=
request
.
getHeader
(
"kl_token"
);
if
(
StringUtils
.
isBlank
(
token
))
{
token
=
request
.
getHeader
(
"kltoken"
);
}
String
token
=
request
.
getHeader
(
"Authorization"
);
logger
.
info
(
"token的值是:"
+
token
);
if
(
StringUtils
.
isBlank
(
token
))
{
return
true
;
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/ItemService.java
View file @
679a1eca
...
...
@@ -14,5 +14,7 @@ public interface ItemService {
Result
collect
(
ItemRequestDto
dto
);
Result
cancel
(
ItemRequestDto
dto
);
Result
update
(
ItemRequestDto
dto
);
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/WxItemController.java
View file @
679a1eca
...
...
@@ -151,7 +151,7 @@ public class WxItemController {
String
userId
=
JsonUtils
.
getValueByPath
(
json
,
"userId"
);
String
id
=
JsonUtils
.
getValueByPath
(
json
,
"id"
);
if
(
StringUtils
.
isBlank
(
id
))
{
return
Result
.
failed
(
"
当前页
不能为空"
);
return
Result
.
failed
(
"
藏品id
不能为空"
);
}
ItemRequestDto
dto
=
new
ItemRequestDto
();
...
...
@@ -162,4 +162,44 @@ public class WxItemController {
dto
.
setId
(
Long
.
parseLong
(
id
));
return
itemService
.
info
(
dto
);
}
@ApiOperation
(
value
=
"收藏"
)
@PostMapping
(
"/collect"
)
public
Result
collect
(
@RequestBody
KlDataRequestDto
klDataRequestDto
)
{
String
json
=
klDataRequestDto
.
getKl_data
();
logger
.
info
(
"【请求开始】首页收藏,请求参数,kl_data:{}"
,
json
);
String
userId
=
JsonUtils
.
getValueByPath
(
json
,
"userId"
);
String
id
=
JsonUtils
.
getValueByPath
(
json
,
"id"
);
if
(
StringUtils
.
isBlank
(
id
))
{
return
Result
.
failed
(
"藏品id不能为空"
);
}
ItemRequestDto
dto
=
new
ItemRequestDto
();
dto
.
setUserId
(
0L
);
if
(
StringUtils
.
isNotBlank
(
userId
))
{
dto
.
setUserId
(
Long
.
parseLong
(
userId
));
}
dto
.
setId
(
Long
.
parseLong
(
id
));
return
itemService
.
collect
(
dto
);
}
@ApiOperation
(
value
=
"取消收藏"
)
@PostMapping
(
"/cancel"
)
public
Result
cancel
(
@RequestBody
KlDataRequestDto
klDataRequestDto
)
{
String
json
=
klDataRequestDto
.
getKl_data
();
logger
.
info
(
"【请求开始】首页取消收藏,请求参数,kl_data:{}"
,
json
);
String
userId
=
JsonUtils
.
getValueByPath
(
json
,
"userId"
);
String
id
=
JsonUtils
.
getValueByPath
(
json
,
"id"
);
if
(
StringUtils
.
isBlank
(
id
))
{
return
Result
.
failed
(
"藏品id不能为空"
);
}
ItemRequestDto
dto
=
new
ItemRequestDto
();
dto
.
setUserId
(
0L
);
if
(
StringUtils
.
isNotBlank
(
userId
))
{
dto
.
setUserId
(
Long
.
parseLong
(
userId
));
}
dto
.
setId
(
Long
.
parseLong
(
id
));
return
itemService
.
cancel
(
dto
);
}
}
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