Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
涂亚平
/
subsidy
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a74b24ef
authored
Feb 08, 2022
by
邓敏
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
签到数据同步到数据库和Redis中
1 parent
d60823da
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
98 additions
and
0 deletions
src/main/java/com/subsidy/jobs/Scheduler.java
src/main/java/com/subsidy/mapper/SignInRecordMapper.java
src/main/java/com/subsidy/service/impl/SignInRecordServiceImpl.java
src/main/java/com/subsidy/util/DateFormatUtil.java
src/main/resources/mapper/SignInRecordMapper.xml
src/main/java/com/subsidy/jobs/Scheduler.java
View file @
a74b24e
package
com
.
subsidy
.
jobs
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.subsidy.common.RedisPrefixConstant
;
import
com.subsidy.mapper.OprAdmDictMapper
;
import
com.subsidy.mapper.OprMemDictMapper
;
import
com.subsidy.mapper.SignInRecordMapper
;
import
com.subsidy.mapper.VodPlayHistoryMapper
;
import
com.subsidy.model.OprAdmDictDO
;
import
com.subsidy.model.SignInRecordDO
;
import
com.subsidy.util.DateFormatUtil
;
import
com.subsidy.util.RedisUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Set
;
/**
* <p>
...
...
@@ -33,6 +43,9 @@ public class Scheduler {
private
VodPlayHistoryMapper
vodPlayHistoryMapper
;
@Autowired
private
SignInRecordMapper
signInRecordMapper
;
@Autowired
private
RedisUtil
redisUtil
;
@Autowired
...
...
@@ -103,4 +116,35 @@ public class Scheduler {
// }
// }
/**
* 定时同步Redis签到数据
* 1天前的
* 增量版
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
synchronizeSignInRecord
()
{
List
<
SignInRecordDO
>
list
=
signInRecordMapper
.
getSignInRecord
();
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
for
(
SignInRecordDO
signInRecordDO
:
list
)
{
redisUtil
.
set
(
RedisPrefixConstant
.
SUBSIDY_SIGN_INFO_PREFIX
+
signInRecordDO
.
getMemberId
()
+
":classId:"
+
signInRecordDO
.
getClassId
()
+
":"
+
DateFormatUtil
.
format
(
signInRecordDO
.
getSignInDate
(),
"yyyy-MM-dd"
)
+
":"
+
DateFormatUtil
.
LocalDateTimeToSecond
(
signInRecordDO
.
getSignInDate
()),
null
);
}
}
}
/**
* 全部同步Redis签到数据
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
synchronizeSignInRecordAll
()
{
Set
<
String
>
set
=
redisUtil
.
scan
(
RedisPrefixConstant
.
SUBSIDY_SIGN_INFO_PREFIX
+
"*"
);
if
(
set
!=
null
&&
set
.
size
()
>
0
)
{
redisUtil
.
del
(
set
);
}
List
<
SignInRecordDO
>
list
=
signInRecordMapper
.
selectList
(
new
QueryWrapper
<>());
for
(
SignInRecordDO
signInRecordDO
:
list
)
{
redisUtil
.
set
(
RedisPrefixConstant
.
SUBSIDY_SIGN_INFO_PREFIX
+
signInRecordDO
.
getMemberId
()
+
":classId:"
+
signInRecordDO
.
getClassId
()
+
":"
+
DateFormatUtil
.
format
(
signInRecordDO
.
getSignInDate
(),
"yyyy-MM-dd"
)
+
":"
+
DateFormatUtil
.
LocalDateTimeToSecond
(
signInRecordDO
.
getSignInDate
()),
null
);
}
}
}
src/main/java/com/subsidy/mapper/SignInRecordMapper.java
View file @
a74b24e
...
...
@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import
com.subsidy.vo.sign.ClassSignInfoVO
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
@Repository
public
interface
SignInRecordMapper
extends
BaseMapper
<
SignInRecordDO
>
{
...
...
@@ -16,4 +18,5 @@ public interface SignInRecordMapper extends BaseMapper<SignInRecordDO> {
IPage
<
ClassSignInfoVO
>
classSignInfo
(
IPage
iPage
,
String
className
,
String
courseName
,
Integer
id
);
List
<
SignInRecordDO
>
getSignInRecord
();
}
src/main/java/com/subsidy/service/impl/SignInRecordServiceImpl.java
View file @
a74b24e
...
...
@@ -85,6 +85,21 @@ public class SignInRecordServiceImpl extends ServiceImpl<SignInRecordMapper, Sig
for
(
ClassDictDO
classDictDO
:
classDictDOS
)
{
redisUtil
.
set
(
RedisPrefixConstant
.
SUBSIDY_SIGN_INFO_PREFIX
+
signInRecordDO
.
getMemberId
()
+
":classId:"
+
classDictDO
.
getId
()
+
":"
+
DateFormatUtil
.
format
(
new
Date
(),
"yyyy-MM-dd"
)
+
":"
+
System
.
currentTimeMillis
(),
null
);
// 存储到缓存到同时保存到数据库
SignInRecordDO
sign
=
this
.
baseMapper
.
selectOne
(
new
QueryWrapper
<
SignInRecordDO
>()
.
lambda
()
.
eq
(
SignInRecordDO:
:
getMemberId
,
signInRecordDO
.
getMemberId
())
.
eq
(
SignInRecordDO:
:
getClassId
,
classDictDO
.
getId
())
.
like
(
SignInRecordDO:
:
getSignInDate
,
DateFormatUtil
.
format
(
new
Date
(),
"yyyy-MM-dd"
)));
if
(
sign
!=
null
)
{
this
.
baseMapper
.
deleteById
(
sign
.
getId
());
}
signInRecordDO
.
setClassId
(
classDictDO
.
getId
());
signInRecordDO
.
setSignInDate
(
LocalDateTime
.
now
());
signInRecordDO
.
setCreateDate
(
LocalDateTime
.
now
());
this
.
baseMapper
.
insert
(
signInRecordDO
);
}
return
ConstantUtils
.
ADD_SUCCESS
;
...
...
src/main/java/com/subsidy/util/DateFormatUtil.java
View file @
a74b24e
package
com
.
subsidy
.
util
;
import
java.awt.SystemTray
;
import
java.text.SimpleDateFormat
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
...
...
@@ -41,6 +42,22 @@ public class DateFormatUtil {
}
/**
* LocalDateTime转String,自定义格式
* @param localDateTime
* @param pattern
* @return
*/
public
static
String
format
(
LocalDateTime
localDateTime
,
String
pattern
)
{
try
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
pattern
);
return
sdf
.
format
(
localDateTime
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* String转Date,自定义格式
* @param date
* @param pattern
...
...
@@ -93,4 +110,11 @@ public class DateFormatUtil {
}
return
LocalDateTime
.
now
();
}
public
static
Long
LocalDateTimeToSecond
(
LocalDateTime
localDateTime
)
{
if
(
localDateTime
!=
null
)
{
return
localDateTime
.
atZone
(
ZoneOffset
.
ofHours
(
8
)).
toInstant
().
toEpochMilli
();
}
return
System
.
currentTimeMillis
();
}
}
src/main/resources/mapper/SignInRecordMapper.xml
View file @
a74b24e
...
...
@@ -47,4 +47,16 @@
</if>
</select>
<select
id=
"getSignInRecord"
resultType=
"com.subsidy.model.SignInRecordDO"
>
SELECT
*
FROM
sign_in_record
WHERE
delete_date IS NULL
AND date(sign_in_date) = date_sub(
curdate(),
INTERVAL 1 DAY)
</select>
</mapper>
@TYP
涂亚平
@TYP
mentioned in commit
761eaf22
Feb 11, 2022
mentioned in commit
761eaf22
Toggle commit list
Write
Preview
Markdown
is supported
Attach a file
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 post a comment