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
e55f7237
Commit
e55f7237
authored
Jul 28, 2023
by
muhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增修改 小程序相关接口
parent
0c44b7f3
Changes
26
Show whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
694 additions
and
50 deletions
+694
-50
ch-dao/src/main/java/com/wwdz/ch/db/dao/FavoritesItemsRelationDao.java
...in/java/com/wwdz/ch/db/dao/FavoritesItemsRelationDao.java
+2
-0
ch-dao/src/main/java/com/wwdz/ch/db/dao/FootPrintDao.java
ch-dao/src/main/java/com/wwdz/ch/db/dao/FootPrintDao.java
+15
-0
ch-dao/src/main/java/com/wwdz/ch/db/dao/UserItemsRelationDao.java
...rc/main/java/com/wwdz/ch/db/dao/UserItemsRelationDao.java
+1
-0
ch-dao/src/main/java/com/wwdz/ch/db/dao/impl/FavoritesItemsRelationDaoImpl.java
...om/wwdz/ch/db/dao/impl/FavoritesItemsRelationDaoImpl.java
+17
-0
ch-dao/src/main/java/com/wwdz/ch/db/dao/impl/FootPrintDaoImpl.java
...c/main/java/com/wwdz/ch/db/dao/impl/FootPrintDaoImpl.java
+79
-0
ch-dao/src/main/java/com/wwdz/ch/db/dao/impl/ItemManagerImpl.java
...rc/main/java/com/wwdz/ch/db/dao/impl/ItemManagerImpl.java
+3
-1
ch-dao/src/main/java/com/wwdz/ch/db/dao/impl/UserItemsRelationDaoImpl.java
...ava/com/wwdz/ch/db/dao/impl/UserItemsRelationDaoImpl.java
+9
-0
ch-dao/src/main/java/com/wwdz/ch/db/mapper/FootprintMapper.java
.../src/main/java/com/wwdz/ch/db/mapper/FootprintMapper.java
+2
-0
ch-dao/src/main/java/com/wwdz/ch/db/mapper/UserMapper.java
ch-dao/src/main/java/com/wwdz/ch/db/mapper/UserMapper.java
+2
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/request/CategoryRequestDto.java
...ava/com/wwdz/ch/wx/entity/request/CategoryRequestDto.java
+12
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/request/FootPrintRequestDto.java
...va/com/wwdz/ch/wx/entity/request/FootPrintRequestDto.java
+17
-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
+2
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/request/UserRequestDto.java
...in/java/com/wwdz/ch/wx/entity/request/UserRequestDto.java
+1
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/vo/FootPrintResponseVo.java
...in/java/com/wwdz/ch/wx/entity/vo/FootPrintResponseVo.java
+12
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/vo/ItemResponseVo.java
...rc/main/java/com/wwdz/ch/wx/entity/vo/ItemResponseVo.java
+3
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/CategoryImpl.java
...x-api/src/main/java/com/wwdz/ch/wx/impl/CategoryImpl.java
+0
-9
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/CategoryServiceImpl.java
...rc/main/java/com/wwdz/ch/wx/impl/CategoryServiceImpl.java
+37
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/FootPrintServiceImpl.java
...c/main/java/com/wwdz/ch/wx/impl/FootPrintServiceImpl.java
+240
-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
+48
-12
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
...pi/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
+75
-14
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/CategoryService.java
...src/main/java/com/wwdz/ch/wx/service/CategoryService.java
+5
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/FootPrintService.java
...rc/main/java/com/wwdz/ch/wx/service/FootPrintService.java
+11
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/UserService.java
...api/src/main/java/com/wwdz/ch/wx/service/UserService.java
+2
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/WxCategoryController.java
...rc/main/java/com/wwdz/ch/wx/web/WxCategoryController.java
+34
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/WxFootprintController.java
...c/main/java/com/wwdz/ch/wx/web/WxFootprintController.java
+33
-4
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/WxUserController.java
...pi/src/main/java/com/wwdz/ch/wx/web/WxUserController.java
+32
-9
No files found.
ch-dao/src/main/java/com/wwdz/ch/db/dao/FavoritesItemsRelationDao.java
View file @
e55f7237
...
...
@@ -13,4 +13,6 @@ public interface FavoritesItemsRelationDao {
List
<
FavoritesItemsRelation
>
listByFavoritesId
(
Long
favoritesId
,
List
<
Long
>
favoritesIds
);
FavoritesItemsRelation
selectByUserIdItemId
(
Long
userId
,
Long
itemId
);
PageInfo
<
FavoritesItemsRelation
>
pageByFavoritesId
(
Long
favoritesId
,
int
page
,
int
size
);
long
count
(
Long
itemId
);
boolean
isCollected
(
Long
userId
,
Long
itemId
);
}
ch-dao/src/main/java/com/wwdz/ch/db/dao/FootPrintDao.java
0 → 100644
View file @
e55f7237
package
com.wwdz.ch.db.dao
;
import
com.wwdz.ch.db.domain.Footprint
;
import
java.util.List
;
public
interface
FootPrintDao
{
List
<
Footprint
>
listByUserId
(
Long
userId
);
List
<
Footprint
>
pageByUserId
(
Long
userId
,
Integer
page
,
Integer
size
);
long
countByUserId
(
Long
userId
);
int
delete
(
List
<
Long
>
ids
);
Footprint
selectByUserIdItem
(
Long
userId
,
Long
itemId
);
int
insert
(
Footprint
footprint
);
int
upateTime
(
Footprint
footprint
);
}
ch-dao/src/main/java/com/wwdz/ch/db/dao/UserItemsRelationDao.java
View file @
e55f7237
...
...
@@ -7,4 +7,5 @@ import java.util.List;
public
interface
UserItemsRelationDao
{
int
insert
(
UserItemsRelation
record
);
List
<
UserItemsRelation
>
listByUserIds
(
Long
userId
,
List
<
Long
>
userIds
);
boolean
isExisted
(
Long
userId
,
Long
itemId
);
}
ch-dao/src/main/java/com/wwdz/ch/db/dao/impl/FavoritesItemsRelationDaoImpl.java
View file @
e55f7237
...
...
@@ -68,4 +68,21 @@ public class FavoritesItemsRelationDaoImpl implements FavoritesItemsRelationDao
List
<
FavoritesItemsRelation
>
list
=
favoritesItemsRelationMapper
.
selectByExample
(
example
);
return
new
PageInfo
<>(
list
);
}
@Override
public
long
count
(
Long
itemId
)
{
FavoritesItemsRelationExample
example
=
new
FavoritesItemsRelationExample
();
FavoritesItemsRelationExample
.
Criteria
criteria
=
example
.
createCriteria
();
criteria
.
andItemIdEqualTo
(
itemId
);
return
favoritesItemsRelationMapper
.
countByExample
(
example
);
}
@Override
public
boolean
isCollected
(
Long
userId
,
Long
itemId
)
{
FavoritesItemsRelationExample
example
=
new
FavoritesItemsRelationExample
();
FavoritesItemsRelationExample
.
Criteria
criteria
=
example
.
createCriteria
();
criteria
.
andUserIdEqualTo
(
userId
);
criteria
.
andItemIdEqualTo
(
itemId
);
return
favoritesItemsRelationMapper
.
countByExample
(
example
)
>
0
;
}
}
ch-dao/src/main/java/com/wwdz/ch/db/dao/impl/FootPrintDaoImpl.java
0 → 100644
View file @
e55f7237
package
com.wwdz.ch.db.dao.impl
;
import
com.github.pagehelper.PageHelper
;
import
com.wwdz.ch.db.dao.FootPrintDao
;
import
com.wwdz.ch.db.domain.Footprint
;
import
com.wwdz.ch.db.domain.FootprintExample
;
import
com.wwdz.ch.db.mapper.FootprintMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Repository
;
import
java.util.Date
;
import
java.util.List
;
@Repository
public
class
FootPrintDaoImpl
implements
FootPrintDao
{
@Autowired
private
FootprintMapper
footprintMapper
;
@Override
public
List
<
Footprint
>
listByUserId
(
Long
userId
)
{
FootprintExample
example
=
new
FootprintExample
();
FootprintExample
.
Criteria
criteria
=
example
.
createCriteria
();
criteria
.
andUserIdEqualTo
(
userId
);
criteria
.
andDeletedEqualTo
(
false
);
example
.
orderBy
(
"update_time desc"
);
return
footprintMapper
.
selectByExample
(
example
);
}
@Override
public
List
<
Footprint
>
pageByUserId
(
Long
userId
,
Integer
page
,
Integer
size
)
{
FootprintExample
example
=
new
FootprintExample
();
FootprintExample
.
Criteria
criteria
=
example
.
createCriteria
();
criteria
.
andUserIdEqualTo
(
userId
);
criteria
.
andDeletedEqualTo
(
false
);
example
.
orderBy
(
"update_time desc"
);
PageHelper
.
startPage
(
page
,
size
);
return
footprintMapper
.
selectByExample
(
example
);
}
@Override
public
long
countByUserId
(
Long
userId
)
{
FootprintExample
example
=
new
FootprintExample
();
FootprintExample
.
Criteria
criteria
=
example
.
createCriteria
();
criteria
.
andUserIdEqualTo
(
userId
);
criteria
.
andDeletedEqualTo
(
false
);
return
footprintMapper
.
countByExample
(
example
);
}
@Override
public
int
delete
(
List
<
Long
>
ids
)
{
FootprintExample
example
=
new
FootprintExample
();
FootprintExample
.
Criteria
criteria
=
example
.
createCriteria
();
criteria
.
andIdIn
(
ids
);
Footprint
footprint
=
new
Footprint
();
footprint
.
setDeleted
(
true
);
footprint
.
setUpdateTime
(
new
Date
());
return
footprintMapper
.
updateByExampleSelective
(
footprint
,
example
);
}
@Override
public
Footprint
selectByUserIdItem
(
Long
userId
,
Long
itemId
)
{
FootprintExample
example
=
new
FootprintExample
();
FootprintExample
.
Criteria
criteria
=
example
.
createCriteria
();
criteria
.
andUserIdEqualTo
(
userId
);
criteria
.
andItemIdEqualTo
(
itemId
);
criteria
.
andDeletedEqualTo
(
false
);
return
footprintMapper
.
selectOneByExample
(
example
);
}
@Override
public
int
insert
(
Footprint
footprint
)
{
return
footprintMapper
.
insert
(
footprint
);
}
@Override
public
int
upateTime
(
Footprint
footprint
)
{
return
footprintMapper
.
updateByPrimaryKey
(
footprint
);
}
}
ch-dao/src/main/java/com/wwdz/ch/db/dao/impl/ItemManagerImpl.java
View file @
e55f7237
...
...
@@ -51,11 +51,13 @@ public class ItemManagerImpl implements ItemManager {
public
PageInfo
<
Item
>
findByPage
(
CoinRequestDto
coinRequestDto
)
{
ItemExample
example
=
new
ItemExample
();
ItemExample
.
Criteria
criteria
=
example
.
createCriteria
();
criteria
.
andIsDeletedEqualTo
(
false
);
example
.
orderBy
(
"update_time desc"
);
JdbcHelper
.
ifPresent
(
coinRequestDto
.
getId
(),
criteria
::
andIdEqualTo
);
JdbcHelper
.
ifPresent
(
coinRequestDto
.
getName
(),
criteria
::
andNameLike
);
JdbcHelper
.
ifPresent
(
coinRequestDto
.
getCid
(),
criteria
::
andCidEqualTo
);
PageHelper
.
startPage
(
coinRequestDto
.
getPage
(),
coinRequestDto
.
getLimit
());
List
<
Item
>
list
=
itemMapper
.
selectByExample
(
example
);
List
<
Item
>
list
=
itemMapper
.
selectByExample
WithBLOBs
(
example
);
return
new
PageInfo
<>(
list
);
}
...
...
ch-dao/src/main/java/com/wwdz/ch/db/dao/impl/UserItemsRelationDaoImpl.java
View file @
e55f7237
...
...
@@ -28,4 +28,13 @@ public class UserItemsRelationDaoImpl implements UserItemsRelationDao {
JdbcHelper
.
ifPresent
(
userIds
,
criteria:
:
andUserIdIn
);
return
usersItemsRelationMapper
.
selectByExample
(
example
);
}
@Override
public
boolean
isExisted
(
Long
userId
,
Long
itemId
)
{
UserItemsRelationExample
example
=
new
UserItemsRelationExample
();
UserItemsRelationExample
.
Criteria
criteria
=
example
.
createCriteria
();
criteria
.
andUserIdEqualTo
(
userId
);
criteria
.
andItemIdEqualTo
(
itemId
);
return
usersItemsRelationMapper
.
countByExample
(
example
)
>
0
;
}
}
ch-dao/src/main/java/com/wwdz/ch/db/mapper/FootprintMapper.java
View file @
e55f7237
...
...
@@ -2,10 +2,12 @@ package com.wwdz.ch.db.mapper;
import
com.wwdz.ch.db.domain.Footprint
;
import
com.wwdz.ch.db.domain.FootprintExample
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
@Mapper
public
interface
FootprintMapper
{
long
countByExample
(
FootprintExample
example
);
...
...
ch-dao/src/main/java/com/wwdz/ch/db/mapper/UserMapper.java
View file @
e55f7237
...
...
@@ -2,10 +2,12 @@ package com.wwdz.ch.db.mapper;
import
com.wwdz.ch.db.domain.User
;
import
com.wwdz.ch.db.domain.UserExample
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
@Mapper
public
interface
UserMapper
{
long
countByExample
(
UserExample
example
);
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/request/CategoryRequestDto.java
0 → 100644
View file @
e55f7237
package
com.wwdz.ch.wx.entity.request
;
import
com.xxdxxs.entity.Entity
;
import
lombok.Data
;
@Data
public
class
CategoryRequestDto
implements
Entity
{
private
Integer
id
;
private
Integer
level
;
private
Integer
page
;
private
Integer
size
;
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/request/FootPrintRequestDto.java
0 → 100644
View file @
e55f7237
package
com.wwdz.ch.wx.entity.request
;
import
com.xxdxxs.entity.Entity
;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
FootPrintRequestDto
implements
Entity
{
private
Long
id
;
private
Long
userId
;
private
Long
itemId
;
private
Integer
when
;
private
Integer
page
;
private
Integer
size
;
private
List
<
Long
>
ids
;
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/request/ItemRequestDto.java
View file @
e55f7237
...
...
@@ -29,4 +29,6 @@ public class ItemRequestDto implements Entity {
private
String
detail
;
// 藏品价格
private
String
price
;
private
Integer
page
;
private
Integer
size
;
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/request/UserRequestDto.java
View file @
e55f7237
...
...
@@ -8,6 +8,7 @@ public class UserRequestDto implements Entity {
private
Long
userId
;
private
String
mobile
;
private
String
code
;
private
String
smsCode
;
private
String
avatarUrl
;
private
Long
shareUserId
;
private
String
nickname
;
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/vo/FootPrintResponseVo.java
0 → 100644
View file @
e55f7237
package
com.wwdz.ch.wx.entity.vo
;
import
com.xxdxxs.entity.Entity
;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
FootPrintResponseVo
implements
Entity
{
private
Integer
timeType
;
private
List
<
ItemResponseVo
>
items
;
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/vo/ItemResponseVo.java
View file @
e55f7237
...
...
@@ -5,6 +5,7 @@ import lombok.Data;
@Data
public
class
ItemResponseVo
{
private
Long
id
;
private
Long
itemId
;
private
Integer
cid
;
private
String
categoryName
;
private
String
name
;
...
...
@@ -14,4 +15,6 @@ public class ItemResponseVo {
private
Integer
sourceType
;
private
Integer
isCollected
;
private
Long
favoritesId
;
private
long
collectCount
;
private
Integer
isMine
;
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/CategoryImpl.java
deleted
100644 → 0
View file @
0c44b7f3
package
com.wwdz.ch.wx.impl
;
import
com.wwdz.ch.wx.service.CategoryService
;
import
org.springframework.stereotype.Service
;
@Service
public
class
CategoryImpl
implements
CategoryService
{
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/CategoryServiceImpl.java
0 → 100644
View file @
e55f7237
package
com.wwdz.ch.wx.impl
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.db.dao.CategoryManager
;
import
com.wwdz.ch.wx.entity.request.CategoryRequestDto
;
import
com.wwdz.ch.wx.service.CategoryService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
@Service
public
class
CategoryServiceImpl
implements
CategoryService
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CategoryServiceImpl
.
class
);
@Autowired
private
CategoryManager
categoryManager
;
@Override
public
Result
top
(
CategoryRequestDto
dto
)
{
try
{
return
Result
.
success
(
categoryManager
.
queryByLevel
(
dto
.
getLevel
(),
dto
.
getPage
(),
dto
.
getSize
()));
}
catch
(
Exception
e
)
{
logger
.
error
(
"查询分类类目失败"
,
e
);
return
Result
.
failed
(
"查询分类类目失败"
);
}
}
@Override
public
Result
child
(
CategoryRequestDto
dto
)
{
try
{
return
Result
.
success
(
categoryManager
.
queryByPid
(
dto
.
getId
()));
}
catch
(
Exception
e
)
{
logger
.
error
(
"查询子类目失败"
,
e
);
return
Result
.
failed
(
"查询子类目失败"
);
}
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/FootPrintServiceImpl.java
0 → 100644
View file @
e55f7237
package
com.wwdz.ch.wx.impl
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.db.dao.FavoritesItemsRelationDao
;
import
com.wwdz.ch.db.dao.FootPrintDao
;
import
com.wwdz.ch.db.dao.ItemManager
;
import
com.wwdz.ch.db.domain.Footprint
;
import
com.wwdz.ch.db.domain.Item
;
import
com.wwdz.ch.wx.entity.request.FootPrintRequestDto
;
import
com.wwdz.ch.wx.entity.vo.FootPrintResponseVo
;
import
com.wwdz.ch.wx.entity.vo.ItemResponseVo
;
import
com.wwdz.ch.wx.service.FootPrintService
;
import
com.xxdxxs.utils.DateUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
@Service
public
class
FootPrintServiceImpl
implements
FootPrintService
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
FootPrintServiceImpl
.
class
);
@Autowired
private
FootPrintDao
footPrintDao
;
@Autowired
private
ItemManager
itemManager
;
@Autowired
private
FavoritesItemsRelationDao
favoritesItemsRelationDao
;
@Override
public
Result
listAll
(
FootPrintRequestDto
dto
)
{
try
{
List
<
FootPrintResponseVo
>
result
=
new
ArrayList
<>();
List
<
Footprint
>
list
=
footPrintDao
.
listByUserId
(
dto
.
getUserId
());
if
(
CollectionUtils
.
isEmpty
(
list
))
{
return
Result
.
success
(
result
);
}
// 现在
Date
now
=
new
Date
();
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
String
todayFormat
=
simpleDateFormat
.
format
(
new
Date
())
+
" 00:00:00"
;
// 今天
Date
today
=
DateUtils
.
parseString
(
todayFormat
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
today
);
calendar
.
add
(
Calendar
.
DATE
,
-
1
);
// 昨天
Date
yesterday
=
calendar
.
getTime
();
// 一周内
calendar
.
setTime
(
now
);
calendar
.
add
(
Calendar
.
DATE
,
-
7
);
Date
week
=
calendar
.
getTime
();
// 一月内
calendar
.
setTime
(
now
);
calendar
.
add
(
Calendar
.
MONTH
,
-
1
);
Date
month
=
calendar
.
getTime
();
List
<
ItemResponseVo
>
todayList
=
new
ArrayList
<>();
List
<
ItemResponseVo
>
yesterdayList
=
new
ArrayList
<>();
List
<
ItemResponseVo
>
weekList
=
new
ArrayList
<>();
List
<
ItemResponseVo
>
monthList
=
new
ArrayList
<>();
for
(
Footprint
footprint
:
list
)
{
Item
item
=
itemManager
.
findDetails
(
footprint
.
getItemId
());
ItemResponseVo
itemResponseVo
=
new
ItemResponseVo
();
itemResponseVo
.
setId
(
footprint
.
getId
());
itemResponseVo
.
setItemId
(
item
.
getId
());
itemResponseVo
.
setName
(
item
.
getName
());
itemResponseVo
.
setImages
(
item
.
getImages
());
itemResponseVo
.
setDetail
(
item
.
getDetail
());
itemResponseVo
.
setPrice
(
String
.
valueOf
(
item
.
getPrice
()
/
100
));
itemResponseVo
.
setIsCollected
(
favoritesItemsRelationDao
.
isCollected
(
dto
.
getUserId
(),
footprint
.
getItemId
())
?
1
:
0
);
itemResponseVo
.
setCollectCount
(
favoritesItemsRelationDao
.
count
(
footprint
.
getItemId
()));
if
(
footprint
.
getAddTime
().
compareTo
(
today
)
>=
0
)
{
todayList
.
add
(
itemResponseVo
);
}
if
(
footprint
.
getAddTime
().
compareTo
(
yesterday
)
>=
0
&&
footprint
.
getAddTime
().
compareTo
(
today
)
<=
0
)
{
yesterdayList
.
add
(
itemResponseVo
);
}
if
(
footprint
.
getAddTime
().
compareTo
(
week
)
>=
0
&&
footprint
.
getAddTime
().
compareTo
(
yesterday
)
<=
0
)
{
weekList
.
add
(
itemResponseVo
);
}
if
(
footprint
.
getAddTime
().
compareTo
(
month
)
>=
0
&&
footprint
.
getAddTime
().
compareTo
(
week
)
<=
0
)
{
monthList
.
add
(
itemResponseVo
);
}
}
FootPrintResponseVo
todayVo
=
new
FootPrintResponseVo
();
todayVo
.
setTimeType
(
1
);
todayVo
.
setItems
(
todayList
);
result
.
add
(
todayVo
);
FootPrintResponseVo
yesterdayVo
=
new
FootPrintResponseVo
();
yesterdayVo
.
setTimeType
(
2
);
yesterdayVo
.
setItems
(
yesterdayList
);
result
.
add
(
yesterdayVo
);
FootPrintResponseVo
weekVo
=
new
FootPrintResponseVo
();
weekVo
.
setTimeType
(
3
);
weekVo
.
setItems
(
weekList
);
result
.
add
(
weekVo
);
FootPrintResponseVo
monthVo
=
new
FootPrintResponseVo
();
monthVo
.
setTimeType
(
4
);
monthVo
.
setItems
(
monthList
);
result
.
add
(
monthVo
);
return
Result
.
success
(
result
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"查询用户足迹列表失败"
,
e
);
return
Result
.
failed
(
"查询用户足迹列表失败"
);
}
}
@Override
public
Result
page
(
FootPrintRequestDto
dto
)
{
try
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"pageNum"
,
dto
.
getPage
());
map
.
put
(
"pageSize"
,
dto
.
getSize
());
map
.
put
(
"total"
,
0
);
map
.
put
(
"list"
,
new
ArrayList
<>());
List
<
FootPrintResponseVo
>
result
=
new
ArrayList
<>();
List
<
Footprint
>
list
=
footPrintDao
.
pageByUserId
(
dto
.
getUserId
(),
dto
.
getPage
(),
dto
.
getSize
());
if
(
CollectionUtils
.
isEmpty
(
list
))
{
return
Result
.
success
(
map
);
}
map
.
put
(
"total"
,
footPrintDao
.
countByUserId
(
dto
.
getUserId
()));
// 现在
Date
now
=
new
Date
();
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
String
todayFormat
=
simpleDateFormat
.
format
(
new
Date
())
+
" 00:00:00"
;
// 今天
Date
today
=
DateUtils
.
parseString
(
todayFormat
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
today
);
calendar
.
add
(
Calendar
.
DATE
,
-
1
);
// 昨天
Date
yesterday
=
calendar
.
getTime
();
// 一周内
calendar
.
setTime
(
now
);
calendar
.
add
(
Calendar
.
DATE
,
-
7
);
Date
week
=
calendar
.
getTime
();
// 一月内
calendar
.
setTime
(
now
);
calendar
.
add
(
Calendar
.
MONTH
,
-
1
);
Date
month
=
calendar
.
getTime
();
List
<
ItemResponseVo
>
todayList
=
new
ArrayList
<>();
List
<
ItemResponseVo
>
yesterdayList
=
new
ArrayList
<>();
List
<
ItemResponseVo
>
weekList
=
new
ArrayList
<>();
List
<
ItemResponseVo
>
monthList
=
new
ArrayList
<>();
for
(
Footprint
footprint
:
list
)
{
Item
item
=
itemManager
.
findDetails
(
footprint
.
getItemId
());
ItemResponseVo
itemResponseVo
=
new
ItemResponseVo
();
itemResponseVo
.
setId
(
footprint
.
getId
());
itemResponseVo
.
setItemId
(
item
.
getId
());
itemResponseVo
.
setName
(
item
.
getName
());
itemResponseVo
.
setImages
(
item
.
getImages
());
itemResponseVo
.
setDetail
(
item
.
getDetail
());
itemResponseVo
.
setPrice
(
String
.
valueOf
(
item
.
getPrice
()
/
100
));
itemResponseVo
.
setIsCollected
(
favoritesItemsRelationDao
.
isCollected
(
dto
.
getUserId
(),
footprint
.
getItemId
())
?
1
:
0
);
itemResponseVo
.
setCollectCount
(
favoritesItemsRelationDao
.
count
(
footprint
.
getItemId
()));
if
(
footprint
.
getAddTime
().
compareTo
(
today
)
>=
0
)
{
todayList
.
add
(
itemResponseVo
);
}
if
(
footprint
.
getAddTime
().
compareTo
(
yesterday
)
>=
0
&&
footprint
.
getAddTime
().
compareTo
(
today
)
<=
0
)
{
yesterdayList
.
add
(
itemResponseVo
);
}
if
(
footprint
.
getAddTime
().
compareTo
(
week
)
>=
0
&&
footprint
.
getAddTime
().
compareTo
(
yesterday
)
<=
0
)
{
weekList
.
add
(
itemResponseVo
);
}
if
(
footprint
.
getAddTime
().
compareTo
(
month
)
>=
0
&&
footprint
.
getAddTime
().
compareTo
(
week
)
<=
0
)
{
monthList
.
add
(
itemResponseVo
);
}
}
FootPrintResponseVo
todayVo
=
new
FootPrintResponseVo
();
todayVo
.
setTimeType
(
1
);
todayVo
.
setItems
(
todayList
);
result
.
add
(
todayVo
);
FootPrintResponseVo
yesterdayVo
=
new
FootPrintResponseVo
();
yesterdayVo
.
setTimeType
(
2
);
yesterdayVo
.
setItems
(
yesterdayList
);
result
.
add
(
yesterdayVo
);
FootPrintResponseVo
weekVo
=
new
FootPrintResponseVo
();
weekVo
.
setTimeType
(
3
);
weekVo
.
setItems
(
weekList
);
result
.
add
(
weekVo
);
FootPrintResponseVo
monthVo
=
new
FootPrintResponseVo
();
monthVo
.
setTimeType
(
4
);
monthVo
.
setItems
(
monthList
);
result
.
add
(
monthVo
);
map
.
put
(
"dataList"
,
result
);
return
Result
.
success
(
map
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"分页查询用户足迹列表失败"
,
e
);
return
Result
.
failed
(
"查询失败"
);
}
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
public
Result
delete
(
FootPrintRequestDto
dto
)
{
try
{
footPrintDao
.
delete
(
dto
.
getIds
());
return
Result
.
success
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"删除用户足迹失败"
,
e
);
return
Result
.
failed
(
"删除足迹失败"
);
}
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
public
Result
add
(
FootPrintRequestDto
dto
)
{
try
{
Footprint
footprint
=
footPrintDao
.
selectByUserIdItem
(
dto
.
getUserId
(),
dto
.
getItemId
());
Date
now
=
new
Date
();
if
(
Objects
.
isNull
(
footprint
))
{
Footprint
newVo
=
new
Footprint
();
newVo
.
setUserId
(
dto
.
getUserId
());
newVo
.
setItemId
(
dto
.
getItemId
());
newVo
.
setDeleted
(
false
);
newVo
.
setAddTime
(
now
);
newVo
.
setUpdateTime
(
now
);
footPrintDao
.
insert
(
newVo
);
}
else
{
footprint
.
setUpdateTime
(
now
);
footPrintDao
.
upateTime
(
footprint
);
}
return
Result
.
success
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"用户浏览藏品后添加或更新足迹失败"
,
e
);
TransactionAspectSupport
.
currentTransactionStatus
().
setRollbackOnly
();
return
Result
.
failed
();
}
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
View file @
e55f7237
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.CategoryManager
;
...
...
@@ -10,9 +11,11 @@ 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.dto.request.CoinRequestDto
;
import
com.wwdz.ch.wx.entity.request.ItemRequestDto
;
import
com.wwdz.ch.wx.entity.vo.ItemResponseVo
;
import
com.wwdz.ch.wx.service.ItemService
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -31,16 +34,46 @@ public class ItemServiceImpl implements ItemService {
@Autowired
private
ItemManager
itemManager
;
@Autowired
private
UserItemsRelationDao
userItemsRelation
Manager
;
private
UserItemsRelationDao
userItemsRelation
Dao
;
@Autowired
private
FavoritesItemsRelationDao
favoritesItemsRelation
Manager
;
private
FavoritesItemsRelationDao
favoritesItemsRelation
Dao
;
@Autowired
private
CategoryManager
categoryManager
;
@Override
public
Result
page
(
ItemRequestDto
dto
)
{
return
null
;
try
{
CoinRequestDto
coinRequestDto
=
new
CoinRequestDto
();
coinRequestDto
.
setPage
(
dto
.
getPage
());
coinRequestDto
.
setLimit
(
dto
.
getSize
());
PageInfo
<
Item
>
page
=
itemManager
.
findByPage
(
coinRequestDto
);
PageInfo
<
ItemResponseVo
>
result
=
new
PageInfo
<>();
result
.
setPageNum
(
page
.
getPageNum
());
result
.
setPageSize
(
page
.
getPageSize
());
result
.
setTotal
(
page
.
getTotal
());
result
.
setList
(
new
ArrayList
<>());
if
(
CollectionUtils
.
isEmpty
(
page
.
getList
()))
{
return
Result
.
success
(
result
);
}
List
<
ItemResponseVo
>
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
(
favoritesItemsRelationDao
.
isCollected
(
dto
.
getUserId
(),
item
.
getId
())
?
1
:
0
);
vo
.
setCollectCount
(
favoritesItemsRelationDao
.
count
(
item
.
getId
()));
resultList
.
add
(
vo
);
}
result
.
setList
(
resultList
);
return
Result
.
success
(
result
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"查询首页列表失败"
,
e
);
return
Result
.
failed
(
"查询首页列表失败"
);
}
}
@Override
...
...
@@ -60,7 +93,7 @@ public class ItemServiceImpl implements ItemService {
item
.
setIsStd
(
false
);
item
.
setSort
(
100
);
item
.
setImages
(
dto
.
getImages
());
item
.
setPrice
(
Long
.
parseLong
(
dto
.
getPrice
())
*
100
);
item
.
setPrice
(
Long
.
parseLong
(
dto
.
getPrice
())
/
100
);
item
.
setDetail
(
dto
.
getDetail
());
Date
now
=
new
Date
();
item
.
setCreateTime
(
now
);
...
...
@@ -73,14 +106,14 @@ public class ItemServiceImpl implements ItemService {
UserItemsRelation
userItemsRelation
=
new
UserItemsRelation
();
userItemsRelation
.
setUserId
(
dto
.
getUserId
());
userItemsRelation
.
setItemId
(
item
.
getId
());
userItemsRelation
Manager
.
insert
(
userItemsRelation
);
userItemsRelation
Dao
.
insert
(
userItemsRelation
);
// 新增收藏册和藏品关联记录
FavoritesItemsRelation
favoritesItemsRelation
=
new
FavoritesItemsRelation
();
favoritesItemsRelation
.
setFavoritesId
(
dto
.
getFavoritesId
());
favoritesItemsRelation
.
setItemId
(
item
.
getId
());
favoritesItemsRelation
.
setAddTime
(
now
);
favoritesItemsRelation
Manager
.
insert
(
favoritesItemsRelation
);
favoritesItemsRelation
Dao
.
insert
(
favoritesItemsRelation
);
return
Result
.
success
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"发布藏品失败,原因:"
+
e
.
getMessage
(),
e
);
...
...
@@ -106,13 +139,16 @@ public class ItemServiceImpl implements ItemService {
if
(
Objects
.
nonNull
(
category
))
{
itemResponseVo
.
setCategoryName
(
category
.
getName
());
}
itemResponseVo
.
setPrice
(
String
.
valueOf
(
item
.
getPrice
()
/
100
));
itemResponseVo
.
setPrice
(
String
.
valueOf
(
item
.
getPrice
()
*
100
));
itemResponseVo
.
setSourceType
(
item
.
getSourceType
());
FavoritesItemsRelation
favoritesItemsRelation
=
favoritesItemsRelation
Manager
.
selectByUserIdItemId
(
dto
.
getUserId
(),
item
.
getId
());
FavoritesItemsRelation
favoritesItemsRelation
=
favoritesItemsRelation
Dao
.
selectByUserIdItemId
(
dto
.
getUserId
(),
item
.
getId
());
if
(
Objects
.
nonNull
(
favoritesItemsRelation
))
{
itemResponseVo
.
setIsCollected
(
1
);
itemResponseVo
.
setFavoritesId
(
favoritesItemsRelation
.
getFavoritesId
());
}
else
{
itemResponseVo
.
setIsCollected
(
0
);
}
itemResponseVo
.
setIsMine
(
userItemsRelationDao
.
isExisted
(
dto
.
getUserId
(),
item
.
getId
())
?
1
:
0
);
return
Result
.
success
(
itemResponseVo
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"查看藏品详情失败,原因:"
+
e
.
getMessage
(),
e
);
...
...
@@ -131,7 +167,7 @@ public class ItemServiceImpl implements ItemService {
item
.
setName
(
dto
.
getName
());
item
.
setCid
(
dto
.
getCid
());
item
.
setImages
(
dto
.
getImages
());
item
.
setPrice
(
Long
.
parseLong
(
dto
.
getPrice
())
*
100
);
item
.
setPrice
(
Long
.
parseLong
(
dto
.
getPrice
())
/
100
);
item
.
setDetail
(
dto
.
getDetail
());
Date
now
=
new
Date
();
item
.
setUpdateTime
(
now
);
...
...
@@ -142,14 +178,14 @@ public class ItemServiceImpl implements ItemService {
// 删除藏品和原收藏册关联
List
<
Long
>
itemIds
=
new
ArrayList
<>();
itemIds
.
add
(
item
.
getId
());
favoritesItemsRelation
Manager
.
deleteByChosen
(
dto
.
getBeforeFavoritesId
(),
itemIds
);
favoritesItemsRelation
Dao
.
deleteByChosen
(
dto
.
getBeforeFavoritesId
(),
itemIds
);
// 新增藏品和新收藏册关联
FavoritesItemsRelation
favoritesItemsRelation
=
new
FavoritesItemsRelation
();
favoritesItemsRelation
.
setUserId
(
dto
.
getUserId
());
favoritesItemsRelation
.
setFavoritesId
(
dto
.
getAfterFavoritesId
());
favoritesItemsRelation
.
setItemId
(
item
.
getId
());
favoritesItemsRelation
Manager
.
insert
(
favoritesItemsRelation
);
favoritesItemsRelation
Dao
.
insert
(
favoritesItemsRelation
);
return
Result
.
success
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"修改藏品失败,原因:"
+
e
.
getMessage
(),
e
);
...
...
@@ -170,7 +206,7 @@ public class ItemServiceImpl implements ItemService {
favoritesItemsRelation
.
setUserId
(
dto
.
getUserId
());
favoritesItemsRelation
.
setFavoritesId
(
dto
.
getFavoritesId
());
favoritesItemsRelation
.
setItemId
(
item
.
getId
());
favoritesItemsRelation
Manager
.
insert
(
favoritesItemsRelation
);
favoritesItemsRelation
Dao
.
insert
(
favoritesItemsRelation
);
return
Result
.
success
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"收藏藏品失败,原因:"
+
e
.
getMessage
(),
e
);
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
View file @
e55f7237
...
...
@@ -3,23 +3,32 @@ package com.wwdz.ch.wx.impl;
import
cn.binarywang.wx.miniapp.api.WxMaService
;
import
cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult
;
import
com.alibaba.fastjson.JSONObject
;
import
com.wwdz.ch.core.notify.NotifyService
;
import
com.wwdz.ch.core.notify.NotifyType
;
import
com.wwdz.ch.core.notify.SmsResult
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.type.UserTypeEnum
;
import
com.wwdz.ch.core.util.CharUtil
;
import
com.wwdz.ch.core.util.RegexUtil
;
import
com.wwdz.ch.db.dao.UserDao
;
import
com.wwdz.ch.db.domain.User
;
import
com.wwdz.ch.wx.dao.UserInfo
;
import
com.wwdz.ch.wx.dao.UserToken
;
import
com.wwdz.ch.wx.dao.WxLoginInfo
;
import
com.wwdz.ch.wx.entity.request.FavoritesRequestDto
;
import
com.wwdz.ch.wx.entity.request.UserRequestDto
;
import
com.wwdz.ch.wx.service.CaptchaCodeManager
;
import
com.wwdz.ch.core.captcha.CaptchaCodeManager
;
import
com.wwdz.ch.wx.service.FavoritesService
;
import
com.wwdz.ch.wx.service.UserService
;
import
com.wwdz.ch.wx.service.UserTokenManager
;
import
com.wwdz.ch.wx.util.IpUtil
;
import
com.wwdz.ch.wx.util.StringUtil
;
import
com.wwdz.ch.wx.util.WxResponseCode
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
...
...
@@ -40,6 +49,12 @@ public class UserServiceImpl implements UserService {
private
WxMaService
wxMaService
;
@Autowired
private
UserTokenManager
userTokenManager
;
@Autowired
private
NotifyService
notifyService
;
@Autowired
private
ApplicationContext
applicationContext
;
@Autowired
private
FavoritesService
favoritesService
;
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
...
...
@@ -84,6 +99,10 @@ public class UserServiceImpl implements UserService {
user
.
setLastLoginIp
(
IpUtil
.
client
(
request
));
user
.
setShareUserId
(
shareUserId
);
userDao
.
insert
(
user
);
FavoritesRequestDto
dto
=
new
FavoritesRequestDto
();
dto
.
setUserId
(
user
.
getId
());
favoritesService
.
addDefault
(
dto
);
}
else
{
user
.
setLastLoginTime
(
new
Date
());
user
.
setLastLoginIp
(
IpUtil
.
client
(
request
));
...
...
@@ -132,20 +151,54 @@ public class UserServiceImpl implements UserService {
}
@Override
public
Result
regCaptcha
(
UserRequestDto
dto
)
{
try
{
if
(!
RegexUtil
.
isMobileExact
(
dto
.
getMobile
()))
{
return
Result
.
failed
(
"手机号格式不正确"
);
}
if
(!
notifyService
.
isSmsEnable
())
{
logger
.
error
(
"请求验证码出错:{}"
,
WxResponseCode
.
AUTH_CAPTCHA_UNSUPPORT
.
desc
());
return
Result
.
failed
(
WxResponseCode
.
AUTH_CAPTCHA_UNSUPPORT
.
desc
());
}
String
activeProfile
=
applicationContext
.
getEnvironment
().
getActiveProfiles
()[
0
];
String
code
=
"123456"
;
if
(!
StringUtils
.
equals
(
"dev"
,
activeProfile
))
{
code
=
CharUtil
.
getRandomNum
(
6
);
SmsResult
smsResult
=
notifyService
.
notifySmsTemplate
(
dto
.
getMobile
(),
NotifyType
.
CAPTCHA
,
new
String
[]{
code
,
"1"
});
if
(
smsResult
!=
null
)
{
logger
.
info
(
"*****腾讯云短信发送->请求验证码,短信发送结果:{}"
,
JSONObject
.
toJSONString
(
smsResult
));
}
}
boolean
successful
=
CaptchaCodeManager
.
addToCache
(
dto
.
getMobile
(),
code
,
1
);
if
(!
successful
)
{
logger
.
error
(
"请求验证码出错:{}"
,
WxResponseCode
.
AUTH_CAPTCHA_FREQUENCY
.
desc
());
return
Result
.
failed
(
WxResponseCode
.
AUTH_CAPTCHA_FREQUENCY
.
desc
());
}
logger
.
info
(
"【请求结束】请求验证码成功"
);
return
Result
.
success
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"请求验证码失败"
,
e
);
return
Result
.
failed
(
"请求验证码失败"
);
}
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
public
Result
loginByMobile
(
UserRequestDto
dto
,
HttpServletRequest
request
)
{
try
{
String
mobileCode
=
CaptchaCodeManager
.
getCachedCaptcha
(
dto
.
getMobile
());
if
(!
StringUtils
.
equals
(
dto
.
getCode
(),
mobileCode
))
{
if
(!
StringUtils
.
equals
(
dto
.
get
Sms
Code
(),
mobileCode
))
{
return
Result
.
failed
(
"验证码不正确"
);
}
User
user
=
userDao
.
queryByMobile
(
dto
.
getMobile
());
if
(
Objects
.
isNull
(
user
))
{
String
openId
=
""
;
String
sessionKey
=
""
;
try
{
WxMaJscode2SessionResult
result
=
wxMaService
.
getUserService
().
getSessionInfo
(
dto
.
getCode
());
openId
=
result
.
getOpenid
();
sessionKey
=
result
.
getSessionKey
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"微信登录,调用官方接口失败:{}"
,
dto
.
getCode
(),
e
);
return
Result
.
failed
(
"手机号登录失败,获取openid失败"
);
...
...
@@ -154,10 +207,13 @@ public class UserServiceImpl implements UserService {
if
(
StringUtils
.
isBlank
(
openId
))
{
return
Result
.
failed
(
"手机号登录失败,获取openid失败"
);
}
User
user
=
userDao
.
queryByMobile
(
dto
.
getMobile
());
if
(
Objects
.
isNull
(
user
))
{
user
=
new
User
();
user
.
setUsername
(
openId
);
user
.
setPassword
(
openId
);
user
.
setWeixinOpenid
(
openId
);
user
.
setMobile
(
dto
.
getMobile
());
user
.
setAvatar
(
dto
.
getAvatarUrl
());
user
.
setNickname
(
"微信用户"
+
StringUtil
.
generateRandomString
(
10
));
user
.
setGender
((
byte
)
0
);
...
...
@@ -167,6 +223,10 @@ public class UserServiceImpl implements UserService {
user
.
setLastLoginIp
(
IpUtil
.
client
(
request
));
user
.
setShareUserId
(
dto
.
getShareUserId
());
userDao
.
insert
(
user
);
FavoritesRequestDto
favoritesRequestDto
=
new
FavoritesRequestDto
();
favoritesRequestDto
.
setUserId
(
user
.
getId
());
favoritesService
.
addDefault
(
favoritesRequestDto
);
}
else
{
user
.
setLastLoginTime
(
new
Date
());
user
.
setLastLoginIp
(
IpUtil
.
client
(
request
));
...
...
@@ -183,6 +243,7 @@ public class UserServiceImpl implements UserService {
logger
.
error
(
"手机号登录失败,生成token失败:{}"
,
user
.
getId
(),
e
);
return
Result
.
failed
(
"手机号登录失败,生成token失败"
);
}
userToken
.
setSessionKey
(
sessionKey
);
Map
<
Object
,
Object
>
result
=
new
HashMap
<
Object
,
Object
>();
result
.
put
(
"token"
,
userToken
.
getToken
());
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/CategoryService.java
View file @
e55f7237
package
com.wwdz.ch.wx.service
;
public
interface
CategoryService
{
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.wx.entity.request.CategoryRequestDto
;
public
interface
CategoryService
{
Result
top
(
CategoryRequestDto
dto
);
Result
child
(
CategoryRequestDto
dto
);
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/FootPrintService.java
0 → 100644
View file @
e55f7237
package
com.wwdz.ch.wx.service
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.wx.entity.request.FootPrintRequestDto
;
public
interface
FootPrintService
{
Result
listAll
(
FootPrintRequestDto
dto
);
Result
page
(
FootPrintRequestDto
dto
);
Result
delete
(
FootPrintRequestDto
dto
);
Result
add
(
FootPrintRequestDto
dto
);
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/UserService.java
View file @
e55f7237
...
...
@@ -9,6 +9,8 @@ import javax.servlet.http.HttpServletRequest;
public
interface
UserService
{
Result
loginByWx
(
WxLoginInfo
wxLoginInfo
,
HttpServletRequest
request
);
Result
regCaptcha
(
UserRequestDto
dto
);
Result
loginByMobile
(
UserRequestDto
dto
,
HttpServletRequest
request
);
Result
updateNickname
(
UserRequestDto
dto
);
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/WxCategoryController.java
0 → 100644
View file @
e55f7237
package
com.wwdz.ch.wx.web
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.wx.entity.request.CategoryRequestDto
;
import
com.wwdz.ch.wx.service.CategoryService
;
import
io.swagger.annotations.ApiOperation
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
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
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RequestMapping
(
"/wx/category"
)
public
class
WxCategoryController
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
WxCategoryController
.
class
);
@Autowired
private
CategoryService
categoryService
;
@ApiOperation
(
value
=
"分类分页"
)
@PostMapping
(
value
=
"/top"
)
public
Result
top
(
@RequestBody
CategoryRequestDto
dto
)
{
return
categoryService
.
top
(
dto
);
}
@ApiOperation
(
value
=
"子分类"
)
@PostMapping
(
value
=
"/child"
)
public
Result
child
(
@RequestBody
CategoryRequestDto
dto
)
{
return
categoryService
.
child
(
dto
);
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/WxFootprintController.java
View file @
e55f7237
...
...
@@ -2,6 +2,7 @@ package com.wwdz.ch.wx.web;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.pagehelper.PageInfo
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.util.JacksonUtil
;
import
com.wwdz.ch.core.util.ResponseUtil
;
import
com.wwdz.ch.db.domain.Footprint
;
...
...
@@ -9,16 +10,16 @@ import com.wwdz.ch.db.domain.Item;
import
com.wwdz.ch.db.service.DtsFootprintService
;
import
com.wwdz.ch.db.service.ItemService
;
import
com.wwdz.ch.wx.annotation.LoginUser
;
import
com.wwdz.ch.wx.entity.request.FootPrintRequestDto
;
import
com.wwdz.ch.wx.service.FootPrintService
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
/**
* 用户访问足迹服务
...
...
@@ -33,6 +34,8 @@ public class WxFootprintController {
private
DtsFootprintService
footprintService
;
@Autowired
private
ItemService
itemService
;
@Autowired
private
FootPrintService
footPrintService
;
/**
* 删除用户足迹
...
...
@@ -120,4 +123,30 @@ public class WxFootprintController {
return
ResponseUtil
.
ok
(
result
);
}
@PostMapping
(
"/page"
)
public
Result
page
(
@RequestBody
FootPrintRequestDto
dto
)
{
logger
.
info
(
"【请求开始】用户足迹列表查询,请求参数,userId:{}"
,
dto
.
getUserId
());
if
(
Objects
.
isNull
(
dto
.
getUserId
()))
{
return
Result
.
failed
(
"用户id不能为空"
);
}
if
(
Objects
.
isNull
(
dto
.
getPage
()))
{
return
Result
.
failed
(
"当前页不能为空"
);
}
if
(
Objects
.
isNull
(
dto
.
getSize
()))
{
return
Result
.
failed
(
"页面大小不能为空"
);
}
return
footPrintService
.
page
(
dto
);
}
@PostMapping
(
"/del"
)
public
Result
delete
(
@RequestBody
FootPrintRequestDto
dto
)
{
logger
.
info
(
"【请求开始】用户足迹删除,请求参数,ids:{}"
,
dto
.
getIds
());
if
(
CollectionUtils
.
isEmpty
(
dto
.
getIds
()))
{
return
Result
.
failed
(
"请选择足迹"
);
}
return
footPrintService
.
delete
(
dto
);
}
}
\ No newline at end of file
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/WxUserController.java
View file @
e55f7237
package
com.wwdz.ch.wx.web
;
import
java.util.HashMap
;
import
java.util.Map
;
import
com.alibaba.fastjson.JSONObject
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.util.ResponseUtil
;
import
com.wwdz.ch.db.domain.UserAccountObsolete
;
import
com.wwdz.ch.db.service.DtsAccountService
;
import
com.wwdz.ch.db.service.DtsUserService
;
import
com.wwdz.ch.wx.annotation.LoginUser
;
import
com.wwdz.ch.wx.dao.WxLoginInfo
;
import
com.wwdz.ch.wx.entity.request.UserRequestDto
;
import
com.wwdz.ch.wx.service.UserService
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
com.alibaba.fastjson.JSONObject
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 用户服务
...
...
@@ -33,7 +34,7 @@ public class WxUserController {
private
DtsAccountService
accountService
;
@Autowired
private
Dts
UserService
userService
;
private
UserService
userService
;
/**
...
...
@@ -84,4 +85,26 @@ public class WxUserController {
logger
.
info
(
"【请求结束】获取用户推广二维码图片URL,响应结果:{}"
,
JSONObject
.
toJSONString
(
data
));
return
ResponseUtil
.
ok
(
data
);
}
@PostMapping
(
"/loginByWx"
)
public
Result
loginByWx
(
@RequestBody
WxLoginInfo
wxLoginInfo
,
HttpServletRequest
request
)
{
logger
.
info
(
"【请求开始】微信登录,请求参数,wxLoginInfo:{}"
,
JSONObject
.
toJSONString
(
wxLoginInfo
));
return
userService
.
loginByWx
(
wxLoginInfo
,
request
);
}
@PostMapping
(
"/regCaptcha"
)
public
Object
registerCaptcha
(
@RequestBody
UserRequestDto
dto
)
{
logger
.
info
(
"【请求开始】请求验证码,请求参数,mobile:{}"
,
dto
.
getMobile
());
if
(
StringUtils
.
isBlank
(
dto
.
getMobile
()))
{
return
Result
.
failed
(
"手机号不能为空"
);
}
return
userService
.
regCaptcha
(
dto
);
}
@PostMapping
(
"/loginByMobile"
)
public
Result
loginByMobile
(
@RequestBody
UserRequestDto
dto
,
HttpServletRequest
request
)
{
logger
.
info
(
"【请求开始】手机号登录,请求参数,wxLoginInfo:{}"
,
JSONObject
.
toJSONString
(
dto
));
return
userService
.
loginByMobile
(
dto
,
request
);
}
}
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