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
f1ed8e80
Commit
f1ed8e80
authored
Nov 22, 2024
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
签到
parent
f35e3c30
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
157 additions
and
561 deletions
+157
-561
ch-core/src/main/java/com/wwdz/ch/core/entity/SignDateRecord.java
...src/main/java/com/wwdz/ch/core/entity/SignDateRecord.java
+59
-0
ch-dao/src/main/java/com/wwdz/ch/db/dao/UserSigninDao.java
ch-dao/src/main/java/com/wwdz/ch/db/dao/UserSigninDao.java
+2
-0
ch-dao/src/main/java/com/wwdz/ch/db/impl/UserSigninDaoImpl.java
.../src/main/java/com/wwdz/ch/db/impl/UserSigninDaoImpl.java
+10
-0
ch-dao/src/main/resources/com/wwdz/ch/db/mapper/UserSigninMapper.xml
...main/resources/com/wwdz/ch/db/mapper/UserSigninMapper.xml
+0
-542
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserSigninServiceImpl.java
.../main/java/com/wwdz/ch/wx/impl/UserSigninServiceImpl.java
+81
-14
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/UserSigninService.java
...c/main/java/com/wwdz/ch/wx/service/UserSigninService.java
+1
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/UserSigninController.java
...rc/main/java/com/wwdz/ch/wx/web/UserSigninController.java
+4
-4
No files found.
ch-core/src/main/java/com/wwdz/ch/core/entity/SignDateRecord.java
0 → 100644
View file @
f1ed8e80
package
com.wwdz.ch.core.entity
;
import
com.xxdxxs.entity.Entity
;
import
lombok.Data
;
@Data
public
class
SignDateRecord
implements
Entity
{
/**
* 日期字符串
* 不含月份
*/
private
Integer
dayStr
;
/**
* 签到日期
* 2024-11-22
*/
private
String
signDate
;
/**
* 是否达到了奖励的签到天数
*/
private
Boolean
isReward
;
/**
* 奖励
*/
private
String
rewardImageUrl
;
/**
* 连续天数
*/
private
Integer
consecutiveDays
;
/**
* 奖励等级
*/
private
Integer
rewardLevel
;
/**
* 是否领取奖励
*/
private
Boolean
isGet
;
/**
* 是否签到过
*/
private
Boolean
isSignIn
;
/**
* 日期的状态
* 0过去,1当前,2未来
*/
private
Integer
dateState
;
}
ch-dao/src/main/java/com/wwdz/ch/db/dao/UserSigninDao.java
View file @
f1ed8e80
...
@@ -20,6 +20,8 @@ public interface UserSigninDao {
...
@@ -20,6 +20,8 @@ public interface UserSigninDao {
*/
*/
UserSignIn
findYesterdayRecord
(
long
userId
);
UserSignIn
findYesterdayRecord
(
long
userId
);
UserSignIn
findTodayRecord
(
long
userId
);
/**
/**
* 判断某一日期是否签到过
* 判断某一日期是否签到过
* @param userId
* @param userId
...
...
ch-dao/src/main/java/com/wwdz/ch/db/impl/UserSigninDaoImpl.java
View file @
f1ed8e80
...
@@ -54,6 +54,16 @@ public class UserSigninDaoImpl implements UserSigninDao {
...
@@ -54,6 +54,16 @@ public class UserSigninDaoImpl implements UserSigninDao {
return
userSignInMapper
.
selectOneByExample
(
example
);
return
userSignInMapper
.
selectOneByExample
(
example
);
}
}
@Override
public
UserSignIn
findTodayRecord
(
long
userId
)
{
LocalDate
today
=
LocalDate
.
now
();
String
todayString
=
DateUtils
.
DATE
.
format
(
today
);
UserSignInExample
example
=
new
UserSignInExample
();
UserSignInExample
.
Criteria
criteria
=
example
.
createCriteria
();
criteria
.
andUserIdEqualTo
(
userId
);
criteria
.
andSignInDateEqualTo
(
todayString
);
return
userSignInMapper
.
selectOneByExample
(
example
);
}
@Override
@Override
public
boolean
isExisted
(
long
userId
,
String
date
)
{
public
boolean
isExisted
(
long
userId
,
String
date
)
{
...
...
ch-dao/src/main/resources/com/wwdz/ch/db/mapper/UserSigninMapper.xml
View file @
f1ed8e80
This diff is collapsed.
Click to expand it.
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserSigninServiceImpl.java
View file @
f1ed8e80
...
@@ -21,10 +21,12 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -21,10 +21,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
import
org.springframework.util.CollectionUtils
;
import
java.time.LocalDate
;
import
java.time.LocalDate
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.
Date
;
import
java.util.
*
;
import
java.util.
List
;
import
java.util.
function.Function
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
@Service
@Service
...
@@ -39,7 +41,7 @@ public class UserSigninServiceImpl implements UserSigninService {
...
@@ -39,7 +41,7 @@ public class UserSigninServiceImpl implements UserSigninService {
DistributionOrderDao
distributionOrderDao
;
DistributionOrderDao
distributionOrderDao
;
@Override
@Override
public
Result
sign
i
n
(
UserSignInRequestDto
dto
)
{
public
Result
sign
I
n
(
UserSignInRequestDto
dto
)
{
try
{
try
{
long
userId
=
dto
.
getUserId
();
long
userId
=
dto
.
getUserId
();
//检查是否已签到过
//检查是否已签到过
...
@@ -66,8 +68,11 @@ public class UserSigninServiceImpl implements UserSigninService {
...
@@ -66,8 +68,11 @@ public class UserSigninServiceImpl implements UserSigninService {
userSignin
.
setSignInDate
(
todayStr
);
userSignin
.
setSignInDate
(
todayStr
);
userSignin
.
setCreateTime
(
new
Date
());
userSignin
.
setCreateTime
(
new
Date
());
userSignin
.
setUpdateTime
(
new
Date
());
userSignin
.
setUpdateTime
(
new
Date
());
//连续签到天数
int
consecutiveDays
=
1
;
int
consecutiveDays
=
yesterdaySignin
.
getConsecutiveDays
()
+
1
;
//连续签到天数, 21天清零重新计算
if
(
yesterdaySignin
.
getConsecutiveDays
()
!=
21
)
{
consecutiveDays
=
yesterdaySignin
.
getConsecutiveDays
()
+
1
;
}
userSignin
.
setConsecutiveDays
(
consecutiveDays
);
userSignin
.
setConsecutiveDays
(
consecutiveDays
);
switch
(
consecutiveDays
)
{
switch
(
consecutiveDays
)
{
case
7
:
case
7
:
...
@@ -143,6 +148,34 @@ public class UserSigninServiceImpl implements UserSigninService {
...
@@ -143,6 +148,34 @@ public class UserSigninServiceImpl implements UserSigninService {
@Override
@Override
public
Result
findList
(
UserSignInRequestDto
dto
)
{
public
Result
findList
(
UserSignInRequestDto
dto
)
{
try
{
try
{
long
userId
=
dto
.
getUserId
();
Map
<
String
,
Object
>
resultMap
=
new
HashMap
<>();
//检查昨天是否打过卡
UserSignIn
yesterdaySignIn
=
userSigninDao
.
findYesterdayRecord
(
userId
);
if
(
yesterdaySignIn
==
null
)
{
//连续签到天数
resultMap
.
put
(
"consecutiveDays"
,
0
);
//还需签到的天数
resultMap
.
put
(
"needConsecutiveDays"
,
7
);
}
else
{
//查询今天的打卡记录
UserSignIn
todayRecord
=
userSigninDao
.
findLastedRecord
(
userId
);
if
(
todayRecord
!=
null
)
{
resultMap
.
put
(
"consecutiveDays"
,
todayRecord
.
getConsecutiveDays
());
}
else
{
resultMap
.
put
(
"consecutiveDays"
,
yesterdaySignIn
.
getConsecutiveDays
());
}
int
consecutiveDays
=
Integer
.
valueOf
(
resultMap
.
get
(
"consecutiveDays"
).
toString
());
if
(
yesterdaySignIn
.
getConsecutiveDays
()
<
7
)
{
resultMap
.
put
(
"needConsecutiveDays"
,
7
-
consecutiveDays
);
}
else
if
(
consecutiveDays
>=
7
&&
consecutiveDays
<
14
)
{
resultMap
.
put
(
"needConsecutiveDays"
,
14
-
consecutiveDays
);
}
else
{
resultMap
.
put
(
"needConsecutiveDays"
,
21
-
consecutiveDays
);
}
}
//当前是几号
//当前是几号
LocalDate
today
=
LocalDate
.
now
();
LocalDate
today
=
LocalDate
.
now
();
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyyMMdd"
);
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyyMMdd"
);
...
@@ -155,8 +188,15 @@ public class UserSigninServiceImpl implements UserSigninService {
...
@@ -155,8 +188,15 @@ public class UserSigninServiceImpl implements UserSigninService {
if
(
StringUtils
.
isEmpty
(
dto
.
getYear
())
||
StringUtils
.
isEmpty
(
dto
.
getMonth
()))
{
if
(
StringUtils
.
isEmpty
(
dto
.
getYear
())
||
StringUtils
.
isEmpty
(
dto
.
getMonth
()))
{
dto
.
setYearMonth
(
year
+
"-"
+
month
);
dto
.
setYearMonth
(
year
+
"-"
+
month
);
}
else
{
}
else
{
year
=
Integer
.
parseInt
(
dto
.
getYear
());
month
=
Integer
.
parseInt
(
dto
.
getMonth
());
dto
.
setYearMonth
(
dto
.
getYear
()
+
"-"
+
dto
.
getMonth
());
dto
.
setYearMonth
(
dto
.
getYear
()
+
"-"
+
dto
.
getMonth
());
}
}
resultMap
.
put
(
"year"
,
year
);
resultMap
.
put
(
"month"
,
month
);
//每个月一号是周几
resultMap
.
put
(
"firstDayOfWeek"
,
DateTimeUtil
.
getFirstDayOfMonth
(
year
,
month
));
//该月份所有的日期
//该月份所有的日期
List
<
String
>
dateList
=
DateTimeUtil
.
getMonthDates
(
dto
.
getYearMonth
());
List
<
String
>
dateList
=
DateTimeUtil
.
getMonthDates
(
dto
.
getYearMonth
());
Date
startTime
=
DateTimeUtil
.
getDateWithMinTime
(
dateList
.
get
(
0
));
Date
startTime
=
DateTimeUtil
.
getDateWithMinTime
(
dateList
.
get
(
0
));
...
@@ -165,8 +205,12 @@ public class UserSigninServiceImpl implements UserSigninService {
...
@@ -165,8 +205,12 @@ public class UserSigninServiceImpl implements UserSigninService {
dto
.
setEndQueryTime
(
endTime
);
dto
.
setEndQueryTime
(
endTime
);
List
<
UserSignIn
>
userSignInList
=
userSigninDao
.
findList
(
dto
);
List
<
UserSignIn
>
userSignInList
=
userSigninDao
.
findList
(
dto
);
List
<
String
>
signDateList
=
userSignInList
.
stream
().
map
(
UserSignIn:
:
getSignInDate
).
collect
(
Collectors
.
toList
());
List
<
String
>
signDateList
=
userSignInList
.
stream
().
map
(
UserSignIn:
:
getSignInDate
).
collect
(
Collectors
.
toList
());
Map
<
String
,
UserSignIn
>
signDateMap
=
userSignInList
.
stream
().
collect
(
Collectors
.
toMap
(
UserSignIn:
:
getSignInDate
,
Function
.
identity
(),
(
k1
,
k2
)
->
k1
));
List
<
SignDateRecord
>
calendar
=
new
ArrayList
<>();
for
(
String
dateStr
:
dateList
)
{
for
(
String
dateStr
:
dateList
)
{
SignDateRecord
signDateRecord
=
new
SignDateRecord
();
SignDateRecord
signDateRecord
=
new
SignDateRecord
();
signDateRecord
.
setDayStr
(
DateTimeUtil
.
getDayFromDateString
(
dateStr
));
signDateRecord
.
setSignDate
(
dateStr
);
int
day
=
Integer
.
parseInt
(
dateStr
.
replace
(
"-"
,
""
));
int
day
=
Integer
.
parseInt
(
dateStr
.
replace
(
"-"
,
""
));
if
(
day
<
currentDay
)
{
if
(
day
<
currentDay
)
{
signDateRecord
.
setDateState
(
SigninEnum
.
DateStateEnum
.
PASS
.
getCode
());
signDateRecord
.
setDateState
(
SigninEnum
.
DateStateEnum
.
PASS
.
getCode
());
...
@@ -174,14 +218,44 @@ public class UserSigninServiceImpl implements UserSigninService {
...
@@ -174,14 +218,44 @@ public class UserSigninServiceImpl implements UserSigninService {
signDateRecord
.
setDateState
(
SigninEnum
.
DateStateEnum
.
CURRENT
.
getCode
());
signDateRecord
.
setDateState
(
SigninEnum
.
DateStateEnum
.
CURRENT
.
getCode
());
}
else
{
}
else
{
signDateRecord
.
setDateState
(
SigninEnum
.
DateStateEnum
.
FUTURE
.
getCode
());
signDateRecord
.
setDateState
(
SigninEnum
.
DateStateEnum
.
FUTURE
.
getCode
());
if
(
yesterdaySignIn
==
null
)
{
//昨天没签到就以今天的时间预测之后的奖励日期
if
(
today
.
plusDays
(
6
).
format
(
formatter
).
equals
(
dateStr
)
||
today
.
plusDays
(
13
).
format
(
formatter
).
equals
(
dateStr
)
||
today
.
plusDays
(
20
).
format
(
formatter
).
equals
(
dateStr
))
{
signDateRecord
.
setIsReward
(
true
);
signDateRecord
.
setIsGet
(
false
);
}
}
else
{
//如果昨天签到了,就以昨天的时间作为预测会拿到签到奖励的起始时间
int
ConsecutiveDays
=
yesterdaySignIn
.
getConsecutiveDays
();
if
(
today
.
plusDays
(
6
-
ConsecutiveDays
).
format
(
formatter
).
equals
(
dateStr
)
||
today
.
plusDays
(
13
-
ConsecutiveDays
).
format
(
formatter
).
equals
(
dateStr
)
||
today
.
plusDays
(
20
-
ConsecutiveDays
).
format
(
formatter
).
equals
(
dateStr
))
{
signDateRecord
.
setIsReward
(
true
);
signDateRecord
.
setIsGet
(
false
);
}
}
}
}
//签到记录里包含该日期则表示已签到
//签到记录里包含该日期则表示已签到
if
(
signDateList
.
contains
(
dateStr
))
{
if
(
signDateList
.
contains
(
dateStr
))
{
signDateRecord
.
setIsSignIn
(
true
);
signDateRecord
.
setIsSignIn
(
true
);
signDateRecord
.
setIsReward
(
signDateMap
.
get
(
dateStr
).
getIsReward
());
signDateRecord
.
setIsGet
(
signDateMap
.
get
(
dateStr
).
getIsGet
());
signDateRecord
.
setRewardLevel
(
signDateMap
.
get
(
dateStr
).
getRewardLevel
());
signDateRecord
.
setConsecutiveDays
(
signDateMap
.
get
(
dateStr
).
getConsecutiveDays
());
}
else
{
signDateRecord
.
setIsSignIn
(
false
);
signDateRecord
.
setIsReward
(
false
);
signDateRecord
.
setIsGet
(
false
);
signDateRecord
.
setRewardLevel
(
SigninEnum
.
LevelEnum
.
ZERO
.
getCode
());
signDateRecord
.
setConsecutiveDays
(
0
);
}
}
calendar
.
add
(
signDateRecord
);
}
}
//日历数据
return
Result
.
success
();
resultMap
.
put
(
"calendar"
,
calendar
);
//签到进度
resultMap
.
put
(
"rate"
,
(
int
)
Math
.
ceil
((
Double
.
valueOf
(
resultMap
.
get
(
"consecutiveDays"
).
toString
())
/
21
)
*
100
));
return
Result
.
success
(
resultMap
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"查询签到记录失败 error : {}"
,
e
);
logger
.
error
(
"查询签到记录失败 error : {}"
,
e
);
}
}
...
@@ -200,11 +274,4 @@ public class UserSigninServiceImpl implements UserSigninService {
...
@@ -200,11 +274,4 @@ public class UserSigninServiceImpl implements UserSigninService {
}
}
public
static
void
main
(
String
[]
args
)
{
List
<
String
>
dateList
=
DateTimeUtil
.
getMonthDates
(
"2024-11"
);
Date
startTime
=
DateTimeUtil
.
getDateWithMinTime
(
dateList
.
get
(
0
));
Date
endTime
=
DateTimeUtil
.
getDateWithMaxTime
(
dateList
.
get
((
dateList
.
size
()
-
1
)));
System
.
out
.
println
(
startTime
);
System
.
out
.
println
(
endTime
);
}
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/UserSigninService.java
View file @
f1ed8e80
...
@@ -10,7 +10,7 @@ public interface UserSigninService {
...
@@ -10,7 +10,7 @@ public interface UserSigninService {
* @param dto
* @param dto
* @return
* @return
*/
*/
Result
sign
i
n
(
UserSignInRequestDto
dto
);
Result
sign
I
n
(
UserSignInRequestDto
dto
);
/**
/**
* 领取奖励
* 领取奖励
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/UserSigninController.java
View file @
f1ed8e80
...
@@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
...
@@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RestController
@RequestMapping
(
"/wx/userSign
i
n"
)
@RequestMapping
(
"/wx/userSign
I
n"
)
public
class
UserSigninController
{
public
class
UserSigninController
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
UserSigninController
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
UserSigninController
.
class
);
...
@@ -26,8 +26,8 @@ public class UserSigninController {
...
@@ -26,8 +26,8 @@ public class UserSigninController {
UserSigninService
userSigninService
;
UserSigninService
userSigninService
;
@ApiOperation
(
value
=
"用户签到"
)
@ApiOperation
(
value
=
"用户签到"
)
@PostMapping
(
"/
checkAbleToOpenShop
"
)
@PostMapping
(
"/
signIn
"
)
public
Result
checkAbleToOpenShop
(
@RequestBody
UserSignInRequestDto
dto
)
{
public
Result
signIn
(
@RequestBody
UserSignInRequestDto
dto
)
{
logger
.
info
(
"【请求开始】用户签到,请求参数:{}"
,
JSON
.
toJSONString
(
dto
));
logger
.
info
(
"【请求开始】用户签到,请求参数:{}"
,
JSON
.
toJSONString
(
dto
));
Validator
validator
=
new
Validator
(
FormHandler
.
ofEntity
(
dto
));
Validator
validator
=
new
Validator
(
FormHandler
.
ofEntity
(
dto
));
validator
.
set
(
"userId"
,
"用户id"
).
must
().
number
()
validator
.
set
(
"userId"
,
"用户id"
).
must
().
number
()
...
@@ -35,7 +35,7 @@ public class UserSigninController {
...
@@ -35,7 +35,7 @@ public class UserSigninController {
if
(!
validator
.
isValid
())
{
if
(!
validator
.
isValid
())
{
return
Result
.
failed
(
ResultCode
.
PARAM_ERROR
);
return
Result
.
failed
(
ResultCode
.
PARAM_ERROR
);
}
}
return
userSigninService
.
sign
i
n
(
dto
);
return
userSigninService
.
sign
I
n
(
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