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 a91e9ad7
authored
Dec 21, 2021
by
涂亚平
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redis
vod_play_history新加字段
1 parent
93b423e7
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
896 additions
and
57 deletions
pom.xml
src/main/java/com/subsidy/common/configure/RedisConfig.java
src/main/java/com/subsidy/controller/AdministerController.java
src/main/java/com/subsidy/controller/MemberController.java
src/main/java/com/subsidy/controller/SignInRecordController.java
src/main/java/com/subsidy/model/VodPlayHistoryDO.java
src/main/java/com/subsidy/service/AdministerService.java
src/main/java/com/subsidy/service/MemberService.java
src/main/java/com/subsidy/service/SignInRecordService.java
src/main/java/com/subsidy/service/impl/AdministerServiceImpl.java
src/main/java/com/subsidy/service/impl/ClassHourDictServiceImpl.java
src/main/java/com/subsidy/service/impl/MemberServiceImpl.java
src/main/java/com/subsidy/service/impl/SignInRecordServiceImpl.java
src/main/java/com/subsidy/service/impl/SmsVerifyCodeServiceImpl.java
src/main/java/com/subsidy/util/RedisUtil.java
src/main/resources/application-dev.properties
src/main/resources/application-prod.properties
src/main/resources/application.properties
pom.xml
View file @
a91e9ad
...
...
@@ -31,6 +31,7 @@
<itext-asian.version>
5.2.0
</itext-asian.version>
<itextpdf.version>
5.4.1
</itextpdf.version>
<java-jwt.version>
3.10.3
</java-jwt.version>
<jedis.version>
3.3.0
</jedis.version>
</properties>
<dependencies>
...
...
@@ -190,6 +191,18 @@
<artifactId>
jlatexmath
</artifactId>
<version>
1.0.7
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
</dependency>
<dependency>
<groupId>
redis.clients
</groupId>
<artifactId>
jedis
</artifactId>
<version>
${jedis.version}
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/subsidy/common/configure/RedisConfig.java
0 → 100644
View file @
a91e9ad
package
com
.
subsidy
.
common
.
configure
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.springframework.cache.annotation.CachingConfigurerSupport
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.core.*
;
import
org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
@EnableCaching
/**
* <p>
* Redis
* </p>
*
* @author DengMin
* @since 2020/12/14
*/
@Configuration
public
class
RedisConfig
extends
CachingConfigurerSupport
{
/**
* retemplate相关配置
* @param factory
* @return
*/
@Bean
public
RedisTemplate
<
String
,
Object
>
redisTemplate
(
RedisConnectionFactory
factory
)
{
RedisTemplate
<
String
,
Object
>
template
=
new
RedisTemplate
<>();
// 配置连接工厂
template
.
setConnectionFactory
(
factory
);
//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)
Jackson2JsonRedisSerializer
jacksonSeial
=
new
Jackson2JsonRedisSerializer
(
Object
.
class
);
ObjectMapper
om
=
new
ObjectMapper
();
// 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public
om
.
setVisibility
(
PropertyAccessor
.
ALL
,
JsonAutoDetect
.
Visibility
.
ANY
);
// 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常
om
.
enableDefaultTyping
(
ObjectMapper
.
DefaultTyping
.
NON_FINAL
);
jacksonSeial
.
setObjectMapper
(
om
);
// 值采用json序列化
template
.
setValueSerializer
(
jacksonSeial
);
//使用StringRedisSerializer来序列化和反序列化redis的key值
template
.
setKeySerializer
(
new
StringRedisSerializer
());
// 设置hash key 和value序列化模式
template
.
setHashKeySerializer
(
new
StringRedisSerializer
());
template
.
setHashValueSerializer
(
jacksonSeial
);
template
.
afterPropertiesSet
();
return
template
;
}
/**
* 对hash类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
HashOperations
<
String
,
String
,
Object
>
hashOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForHash
();
}
/**
* 对redis字符串类型数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
ValueOperations
<
String
,
Object
>
valueOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForValue
();
}
/**
* 对链表类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
ListOperations
<
String
,
Object
>
listOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForList
();
}
/**
* 对无序集合类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
SetOperations
<
String
,
Object
>
setOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForSet
();
}
/**
* 对有序集合类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
ZSetOperations
<
String
,
Object
>
zSetOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForZSet
();
}
}
\ No newline at end of file
src/main/java/com/subsidy/controller/AdministerController.java
View file @
a91e9ad
...
...
@@ -103,14 +103,14 @@ public class AdministerController {
@PostMapping
(
"classDetail"
)
@ApiOperation
(
"** 班级管理--班级成员 id 班级id userName"
)
//
@LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE})
@LoginRequired
(
value
=
{
ConstantUtils
.
ADMINISTER_TERMINATE
})
public
ResponseVO
classDetail
(
@RequestBody
ClassDetailDTO
classDetailDTO
){
return
ResponseData
.
generateCreatedResponse
(
0
,
administerService
.
classDetail
(
classDetailDTO
));
}
@PostMapping
(
"exportClassDetail"
)
@ApiOperation
(
"** 班级管理--班级成员--导出 id 班级id userName"
)
//
@LoginRequired(value = {ConstantUtils.ADMINISTER_TERMINATE})
@LoginRequired
(
value
=
{
ConstantUtils
.
ADMINISTER_TERMINATE
})
public
void
exportClassDetail
(
@RequestBody
ClassDetailDTO
classDetailDTO
)
throws
Exception
{
classDetailDTO
.
setFlag
(
true
);
administerService
.
exportClassDetail
(
classDetailDTO
);
...
...
@@ -200,6 +200,11 @@ public class AdministerController {
return
ResponseData
.
generateCreatedResponse
(
0
,
administerService
.
importMember
(
companyId
,
file
));
}
@PostMapping
(
"importRedis"
)
@ApiOperation
(
"导入老师账号到redis"
)
public
void
importRedis
(){
administerService
.
importRedis
();
}
}
src/main/java/com/subsidy/controller/MemberController.java
View file @
a91e9ad
...
...
@@ -137,9 +137,11 @@ public class MemberController {
return
ResponseData
.
generateCreatedResponse
(
0
,
memberService
.
checkTimes
(
exerciseDoneResultDO
));
}
@PostMapping
(
"replace"
)
public
void
replace
(){
memberService
.
replace
();
@PostMapping
(
"importRedis"
)
@ApiOperation
(
"导入学生账号到redis"
)
public
void
importRedis
(){
memberService
.
importRedis
();
}
}
src/main/java/com/subsidy/controller/SignInRecordController.java
View file @
a91e9ad
...
...
@@ -61,4 +61,9 @@ public class SignInRecordController {
return
ResponseData
.
generateCreatedResponse
(
0
,
signInRecordService
.
signInStatus
(
signInRecordDO
));
}
@PostMapping
(
"getRedisData"
)
public
ResponseVO
test
(){
return
ResponseData
.
generateCreatedResponse
(
0
,
signInRecordService
.
test
());
}
}
src/main/java/com/subsidy/model/VodPlayHistoryDO.java
View file @
a91e9ad
...
...
@@ -50,5 +50,10 @@ public class VodPlayHistoryDO extends BaseModel {
*/
private
Integer
playRecord
;
/**
* 聚合
*/
private
Integer
playCount
;
}
src/main/java/com/subsidy/service/AdministerService.java
View file @
a91e9ad
...
...
@@ -68,4 +68,5 @@ public interface AdministerService extends IService<AdministerDO> {
String
importMember
(
Long
companyId
,
MultipartFile
multipartFile
);
void
importRedis
();
}
src/main/java/com/subsidy/service/MemberService.java
View file @
a91e9ad
...
...
@@ -11,6 +11,7 @@ import com.subsidy.vo.administer.UserRoleVO;
import
com.subsidy.vo.member.*
;
import
com.subsidy.vo.paper.QueryPapersVO
;
import
java.lang.reflect.Member
;
import
java.util.List
;
/**
...
...
@@ -33,7 +34,7 @@ public interface MemberService extends IService<MemberDO> {
UserRoleVO
login
(
VerifyCodeDTO
verifyCodeDTO
);
UserRoleV
O
passwordLogin
(
PasswordLoginDTO
passwordLoginDTO
);
MemberD
O
passwordLogin
(
PasswordLoginDTO
passwordLoginDTO
);
String
updatePassword
(
MemberDO
memberDO
);
...
...
@@ -55,5 +56,6 @@ public interface MemberService extends IService<MemberDO> {
String
checkTimes
(
ExerciseDoneResultDO
exerciseDoneResultDO
);
void
replace
();
void
importRedis
();
}
src/main/java/com/subsidy/service/SignInRecordService.java
View file @
a91e9ad
...
...
@@ -28,4 +28,6 @@ public interface SignInRecordService extends IService<SignInRecordDO> {
IPage
classSignInfo
(
ClassSignInfoDTO
classSignInfoDTO
);
SignInStatusVO
signInStatus
(
SignInRecordDO
signInRecordDO
);
Object
test
();
}
src/main/java/com/subsidy/service/impl/AdministerServiceImpl.java
View file @
a91e9ad
...
...
@@ -39,6 +39,7 @@ import org.apache.poi.xssf.streaming.SXSSFSheet;
import
org.apache.poi.xssf.streaming.SXSSFWorkbook
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.context.request.RequestContextHolder
;
...
...
@@ -110,16 +111,29 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
@Autowired
private
OprAdmDictMapper
oprAdmDictMapper
;
@Autowired
private
RedisUtil
redisUtil
;
public
LoginVO
login
(
AdministerDO
administerDO
)
{
LoginVO
loginVO
=
new
LoginVO
();
AdministerDO
administerDO1
=
this
.
baseMapper
.
selectOne
(
new
QueryWrapper
<
AdministerDO
>()
.
lambda
()
.
eq
(
AdministerDO:
:
getAccountName
,
administerDO
.
getAccountName
()));
/**
* 先从redis里拿
*/
AdministerDO
administerDO1
=
(
AdministerDO
)
redisUtil
.
get
(
"subsidyAdminister_"
+
administerDO
.
getAccountName
());
if
(
null
==
administerDO1
){
/**
* 查表,并将数据写入到redis
*/
administerDO1
=
this
.
baseMapper
.
selectOne
(
new
QueryWrapper
<
AdministerDO
>()
.
lambda
()
.
eq
(
AdministerDO:
:
getAccountName
,
administerDO
.
getAccountName
()));
redisUtil
.
set
(
"subsidyAdminister_"
+
administerDO
.
getAccountName
(),
administerDO1
);
}
/**
* 最近5次都输入失败,5分钟后再验证
* 最近5次都输入失败,5分钟后再验证
待优化
*/
List
<
OprAdmDictDO
>
oprAdmDictDOS
=
oprAdmDictMapper
.
getLoginInfo
(
administerDO1
.
getId
());
...
...
@@ -268,6 +282,9 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
throw
new
HttpException
(
20002
);
}
this
.
baseMapper
.
updateById
(
administerDO
);
AdministerDO
administerDO1
=
this
.
baseMapper
.
selectById
(
administerDO
.
getId
());
//更新redis里该老师的数据
redisUtil
.
set
(
"subsidyAdminister_"
+
administerDO1
.
getAccountName
(),
administerDO1
);
return
ConstantUtils
.
SET_SUCCESS
;
}
...
...
@@ -981,6 +998,13 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
return
ConstantUtils
.
ADD_SUCCESS
;
}
public
void
importRedis
(){
List
<
AdministerDO
>
administerDOS
=
this
.
baseMapper
.
selectList
(
null
);
for
(
AdministerDO
administerDO:
administerDOS
){
redisUtil
.
set
(
"subsidyAdmin_"
+
administerDO
.
getAccountName
(),
administerDO
);
}
}
public
String
userName
(
String
originName
,
int
i
,
Long
companyId
)
{
i
++;
List
<
MemberDO
>
memberDOS
=
memberMapper
.
selectList
(
new
QueryWrapper
<
MemberDO
>()
...
...
src/main/java/com/subsidy/service/impl/ClassHourDictServiceImpl.java
View file @
a91e9ad
...
...
@@ -74,7 +74,7 @@ public class ClassHourDictServiceImpl extends ServiceImpl<ClassHourDictMapper, C
ClassHourDictDO
classHourDictDO
=
classHourDictMapper
.
selectOne
(
new
QueryWrapper
<
ClassHourDictDO
>()
.
lambda
()
.
eq
(
ClassHourDictDO:
:
getStatus
,
1
)
.
eq
(
ClassHourDictDO:
:
getCompanyId
,
memberDO
.
getCompanyId
()));
.
gt
(
ClassHourDictDO:
:
getCompanyId
,
memberDO
.
getCompanyId
()));
if
(
null
==
classHourDictDO
){
pollingGetVO
.
setBool
(
false
);
return
pollingGetVO
;
...
...
src/main/java/com/subsidy/service/impl/MemberServiceImpl.java
View file @
a91e9ad
...
...
@@ -13,6 +13,7 @@ import com.subsidy.service.MemberService;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.subsidy.util.ConstantUtils
;
import
com.subsidy.util.MathUtil
;
import
com.subsidy.util.RedisUtil
;
import
com.subsidy.vo.administer.UserRoleVO
;
import
com.subsidy.vo.course.QueryCoursesVO
;
import
com.subsidy.vo.member.*
;
...
...
@@ -83,6 +84,9 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> imple
@Autowired
private
OprMemDictMapper
oprMemDictMapper
;
@Autowired
private
RedisUtil
redisUtil
;
public
IPage
<
GetAllVO
>
getAll
(
GetAllDTO
getAllDTO
)
{
Page
pager
=
new
Page
(
getAllDTO
.
getPageNum
(),
getAllDTO
.
getPageSize
());
IPage
iPage
=
this
.
baseMapper
.
getMembers
(
pager
,
getAllDTO
.
getDepartmentId
(),
getAllDTO
.
getUserName
(),
getAllDTO
.
getStatus
());
...
...
@@ -223,12 +227,14 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> imple
}
BeanUtils
.
copyProperties
(
memberDO
,
userRoleVO
);
SmsVerifyCodeDO
smsCodeDO
=
smsVerifyCodeMapper
.
selectOne
(
new
QueryWrapper
<
SmsVerifyCodeDO
>()
.
lambda
()
.
eq
(
SmsVerifyCodeDO:
:
getTelephone
,
verifyCodeDTO
.
getTelephone
())
.
eq
(
SmsVerifyCodeDO:
:
getVerifyCode
,
verifyCodeDTO
.
getVerifyCode
())
.
gt
(
SmsVerifyCodeDO:
:
getCreateDate
,
LocalDateTime
.
now
().
minusMinutes
(
30L
)));
if
(
smsCodeDO
==
null
)
{
String
code
=
redisUtil
.
get
(
"subsidySmsCode_"
+
verifyCodeDTO
.
getTelephone
()).
toString
();
//SmsVerifyCodeDO smsCodeDO = smsVerifyCodeMapper.selectOne(new QueryWrapper<SmsVerifyCodeDO>()
// .lambda()
// .eq(SmsVerifyCodeDO::getTelephone, verifyCodeDTO.getTelephone())
// .eq(SmsVerifyCodeDO::getVerifyCode, verifyCodeDTO.getVerifyCode())
// .gt(SmsVerifyCodeDO::getCreateDate, LocalDateTime.now().minusMinutes(30L)));
if
(
code
==
null
||
!
verifyCodeDTO
.
getVerifyCode
().
equals
(
code
)
)
{
OprMemDictDO
oprMemDictDO
=
new
OprMemDictDO
();
oprMemDictDO
.
setUserId
(
memberDO
.
getId
());
oprMemDictDO
.
setOprType
(
"登录"
);
...
...
@@ -242,46 +248,63 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> imple
oprMemDictDO
.
setResult
(
1
);
oprMemDictMapper
.
insert
(
oprMemDictDO
);
//将学员信息写到redis
redisUtil
.
set
(
"subsidyMember_"
+
memberDO
.
getCompanyId
()+
":"
+
memberDO
.
getAccountName
(),
memberDO
);
return
userRoleVO
;
}
public
UserRoleVO
passwordLogin
(
PasswordLoginDTO
passwordLoginDTO
)
{
UserRoleVO
userRoleVO
=
this
.
baseMapper
.
passwordLogin
(
passwordLoginDTO
);
if
(
userRoleVO
==
null
)
{
public
MemberDO
passwordLogin
(
PasswordLoginDTO
passwordLoginDTO
)
{
//UserRoleVO userRoleVO = this.baseMapper.passwordLogin(passwordLoginDTO);
/**
* 先从redis里查
*/
MemberDO
memberDO
=
(
MemberDO
)
redisUtil
.
get
(
"subsidyMember_"
+
passwordLoginDTO
.
getCompanyId
()+
":"
+
passwordLoginDTO
.
getAccountName
());
if
(
null
==
memberDO
){
/**
* redis里没有,从数据库里查
*/
memberDO
=
this
.
baseMapper
.
selectOne
(
new
QueryWrapper
<
MemberDO
>()
.
lambda
()
.
eq
(
MemberDO:
:
getCompanyId
,
passwordLoginDTO
.
getCompanyId
())
.
eq
(
MemberDO:
:
getAccountName
,
passwordLoginDTO
.
getAccountName
()));
}
if
(
memberDO
==
null
)
{
throw
new
HttpException
(
10017
);
}
if
(!
userRoleVO
.
getPassword
().
equals
(
passwordLoginDTO
.
getPassword
()))
{
if
(!
memberDO
.
getPassword
().
equals
(
passwordLoginDTO
.
getPassword
()))
{
OprMemDictDO
oprMemDictDO
=
new
OprMemDictDO
();
oprMemDictDO
.
setUserId
(
userRoleV
O
.
getId
());
oprMemDictDO
.
setUserId
(
memberD
O
.
getId
());
oprMemDictDO
.
setOprType
(
"登录"
);
oprMemDictDO
.
setResult
(
0
);
oprMemDictMapper
.
insert
(
oprMemDictDO
);
throw
new
HttpException
(
10016
);
}
if
(
0
==
userRoleVO
.
getFirstLogin
())
{
if
(
0
==
memberDO
.
getFirstLogin
())
{
OprMemDictDO
oprMemDictDO
=
new
OprMemDictDO
();
oprMemDictDO
.
setUserId
(
userRoleV
O
.
getId
());
oprMemDictDO
.
setUserId
(
memberD
O
.
getId
());
oprMemDictDO
.
setOprType
(
"登录"
);
oprMemDictDO
.
setResult
(
0
);
oprMemDictMapper
.
insert
(
oprMemDictDO
);
throw
new
HttpException
(
10015
);
}
if
(
"冻结"
.
equals
(
userRoleV
O
.
getStatus
()))
{
if
(
"冻结"
.
equals
(
memberD
O
.
getStatus
()))
{
throw
new
HttpException
(
10014
);
}
OprMemDictDO
oprMemDictDO
=
new
OprMemDictDO
();
oprMemDictDO
.
setUserId
(
userRoleV
O
.
getId
());
oprMemDictDO
.
setUserId
(
memberD
O
.
getId
());
oprMemDictDO
.
setOprType
(
"登录"
);
oprMemDictDO
.
setResult
(
1
);
oprMemDictMapper
.
insert
(
oprMemDictDO
);
return
userRoleV
O
;
return
memberD
O
;
}
public
String
updatePassword
(
MemberDO
memberDO
)
{
this
.
baseMapper
.
updateById
(
memberDO
);
MemberDO
memberDO1
=
this
.
baseMapper
.
selectById
(
memberDO
.
getId
());
redisUtil
.
set
(
"subsidyMember_"
+
memberDO1
.
getCompanyId
()+
":"
+
memberDO
.
getAccountName
(),
memberDO
);
return
ConstantUtils
.
SET_SUCCESS
;
}
...
...
@@ -600,27 +623,11 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> imple
return
ConstantUtils
.
CHECK_STATUS
;
}
public
void
replace
(){
public
void
importRedis
()
{
List
<
MemberDO
>
memberDOS
=
this
.
baseMapper
.
selectList
(
null
);
HanyuPinyinOutputFormat
format
=
new
HanyuPinyinOutputFormat
();
//拼音小写
format
.
setCaseType
(
HanyuPinyinCaseType
.
LOWERCASE
);
//不带声调
format
.
setToneType
(
HanyuPinyinToneType
.
WITHOUT_TONE
);
try
{
for
(
MemberDO
memberDO
:
memberDOS
)
{
String
accountName
=
PinyinHelper
.
toHanYuPinyinString
(
memberDO
.
getUserName
(),
format
,
""
,
true
);
memberDO
.
setAccountName
(
accountName
);
this
.
baseMapper
.
updateById
(
memberDO
);
}
}
catch
(
Exception
e
){
for
(
MemberDO
memberDO
:
memberDOS
)
{
redisUtil
.
set
(
"subsidyMember_"
+
memberDO
.
getCompanyId
()+
":"
+
memberDO
.
getAccountName
(),
memberDO
);
}
}
}
src/main/java/com/subsidy/service/impl/SignInRecordServiceImpl.java
View file @
a91e9ad
...
...
@@ -12,6 +12,7 @@ import com.subsidy.service.SignInRecordService;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.subsidy.util.ConstantUtils
;
import
com.subsidy.util.MathUtil
;
import
com.subsidy.util.RedisUtil
;
import
com.subsidy.vo.member.GetMemberSignInfoVO
;
import
com.subsidy.vo.sign.ClassSignInfoVO
;
import
com.subsidy.vo.sign.SignInStatusVO
;
...
...
@@ -21,6 +22,7 @@ import org.springframework.stereotype.Service;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.util.List
;
import
java.util.Set
;
/**
* <p>
...
...
@@ -48,6 +50,9 @@ public class SignInRecordServiceImpl extends ServiceImpl<SignInRecordMapper, Sig
@Autowired
private
AnsweringQuestionMapper
answeringQuestionMapper
;
@Autowired
private
RedisUtil
redisUtil
;
public
IPage
<
GetMemberSignInfoVO
>
getMemberSignInfo
(
GetMemberSignInfoDTO
getMemberSignInfoDTO
)
{
Page
pager
=
new
Page
(
getMemberSignInfoDTO
.
getPageNum
(),
getMemberSignInfoDTO
.
getPageSize
());
...
...
@@ -74,6 +79,8 @@ public class SignInRecordServiceImpl extends ServiceImpl<SignInRecordMapper, Sig
signInRecordDO1
.
setClassId
(
classDictDO
.
getId
());
signInRecordDO1
.
setMemberId
(
signInRecordDO
.
getMemberId
());
signInRecordDO1
.
setSignInDate
(
LocalDateTime
.
now
());
//redisUtil.set("signInStatus"+signInRecordDO.getMemberId()+classDictDO.getId(),LocalDateTime.now());
this
.
baseMapper
.
insert
(
signInRecordDO1
);
}
...
...
@@ -122,7 +129,7 @@ public class SignInRecordServiceImpl extends ServiceImpl<SignInRecordMapper, Sig
}
}
}
classSignInfoVO
.
setStudyVodCounts
(
MathUtil
.
intDivCeil
(
totalStudyVods
,
classMemberMappingDOS
.
size
()
));
classSignInfoVO
.
setStudyVodCounts
(
MathUtil
.
intDivCeil
(
totalStudyVods
,
classMemberMappingDOS
.
size
()));
//平均完成时长 学生观看课程视频的全部时长/总人数
int
avg
=
MathUtil
.
intDivCeil
(
totalStudyLength
,
classMemberMappingDOS
.
size
());
...
...
@@ -178,6 +185,8 @@ public class SignInRecordServiceImpl extends ServiceImpl<SignInRecordMapper, Sig
.
eq
(
SignInRecordDO:
:
getMemberId
,
signInRecordDO
.
getMemberId
())
.
gt
(
SignInRecordDO:
:
getSignInDate
,
LocalDate
.
now
()));
//String count = redisUtil.get("signInStatus:"+signInRecordDO.getMemberId()+":"+classDictDO.getId()).toString();
if
(
count
==
0
)
{
flag
=
false
;
//没有签到
}
...
...
@@ -188,8 +197,14 @@ public class SignInRecordServiceImpl extends ServiceImpl<SignInRecordMapper, Sig
}
//public static void main(String[] args) {
// System.out.println(LocalDate.now().plusDays(1));
//}
public
Object
test
()
{
Set
set
=
redisUtil
.
keys
(
"*subsidyMember*"
);
for
(
Object
str
:
set
)
{
System
.
out
.
println
(
str
);
}
return
null
;
}
}
src/main/java/com/subsidy/service/impl/SmsVerifyCodeServiceImpl.java
View file @
a91e9ad
...
...
@@ -11,6 +11,7 @@ import com.subsidy.service.MemberService;
import
com.subsidy.service.SmsVerifyCodeService
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.subsidy.util.RandomUtil
;
import
com.subsidy.util.RedisUtil
;
import
com.subsidy.util.SMSUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -34,6 +35,9 @@ public class SmsVerifyCodeServiceImpl extends ServiceImpl<SmsVerifyCodeMapper, S
@Autowired
private
MemberMapper
memberMapper
;
@Autowired
private
RedisUtil
redisUtil
;
public
void
sendVerifyCode
(
SendVerifyCodeDTO
sendVerifyCodeDTO
){
MemberDO
memberDO
=
memberMapper
.
selectOne
(
new
QueryWrapper
<
MemberDO
>()
.
lambda
()
...
...
@@ -45,10 +49,15 @@ public class SmsVerifyCodeServiceImpl extends ServiceImpl<SmsVerifyCodeMapper, S
String
code
=
RandomUtil
.
getRandomCode
(
6
);
smsUtils
.
send
(
sendVerifyCodeDTO
.
getTelephone
(),
code
);
SmsVerifyCodeDO
smsCodeDO
=
new
SmsVerifyCodeDO
();
smsCodeDO
.
setVerifyCode
(
code
);
smsCodeDO
.
setTelephone
(
sendVerifyCodeDTO
.
getTelephone
());
this
.
baseMapper
.
insert
(
smsCodeDO
);
//SmsVerifyCodeDO smsCodeDO = new SmsVerifyCodeDO();
//smsCodeDO.setVerifyCode(code);
//smsCodeDO.setTelephone(sendVerifyCodeDTO.getTelephone());
//this.baseMapper.insert(smsCodeDO);
/**
* 验证码存在redis
*/
redisUtil
.
set
(
"subsidySmsCode_"
+
sendVerifyCodeDTO
.
getTelephone
(),
code
,
30
*
60
);
}
...
...
src/main/java/com/subsidy/util/RedisUtil.java
0 → 100644
View file @
a91e9ad
package
com
.
subsidy
.
util
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.BoundListOperations
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
java.io.Serializable
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
/**
* <p>
* redisTemplate封装
* </p>
*
* @author DengMin
* @since 2020/12/17
*/
@Component
public
class
RedisUtil
{
@Autowired
private
RedisTemplate
<
String
,
Object
>
redisTemplate
;
public
RedisUtil
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
this
.
redisTemplate
=
redisTemplate
;
}
/**
* 指定缓存失效时间
* @param key 键
* @param time 时间(秒)
* @return
*/
public
boolean
expire
(
String
key
,
long
time
){
try
{
if
(
time
>
0
){
redisTemplate
.
expire
(
key
,
time
,
TimeUnit
.
SECONDS
);
}
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 根据key 获取过期时间
* @param key 键 不能为null
* @return 时间(秒) 返回0代表为永久有效
*/
public
long
getExpire
(
String
key
){
return
redisTemplate
.
getExpire
(
key
,
TimeUnit
.
SECONDS
);
}
/**
* 判断key是否存在
* @param key 键
* @return true 存在 false不存在
*/
public
boolean
hasKey
(
String
key
){
try
{
return
redisTemplate
.
hasKey
(
key
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 删除缓存
* @param key 可以传一个值 或多个
*/
@SuppressWarnings
(
"unchecked"
)
public
void
del
(
String
...
key
){
if
(
key
!=
null
&&
key
.
length
>
0
){
if
(
key
.
length
==
1
){
redisTemplate
.
delete
(
key
[
0
]);
}
else
{
redisTemplate
.
delete
(
CollectionUtils
.
arrayToList
(
key
));
}
}
}
//============================String=============================
/**
* 普通缓存获取
* @param key 键
* @return 值
*/
public
Object
get
(
String
key
){
return
key
==
null
?
null
:
redisTemplate
.
opsForValue
().
get
(
key
);
}
/**
* 普通缓存放入
* @param key 键
* @param value 值
* @return true成功 false失败
*/
public
boolean
set
(
String
key
,
Object
value
)
{
try
{
redisTemplate
.
opsForValue
().
set
(
key
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 普通缓存放入并设置时间
* @param key 键
* @param value 值
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
* @return true成功 false 失败
*/
public
boolean
set
(
String
key
,
Object
value
,
long
time
){
try
{
if
(
time
>
0
){
redisTemplate
.
opsForValue
().
set
(
key
,
value
,
time
,
TimeUnit
.
SECONDS
);
}
else
{
set
(
key
,
value
);
}
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 递增
* @param key 键
* @param delta 要增加几(大于0)
* @return
*/
public
long
incr
(
String
key
,
long
delta
){
if
(
delta
<
0
){
throw
new
RuntimeException
(
"递增因子必须大于0"
);
}
return
redisTemplate
.
opsForValue
().
increment
(
key
,
delta
);
}
/**
* 递减
* @param key 键
* @param delta 要减少几(小于0)
* @return
*/
public
long
decr
(
String
key
,
long
delta
){
if
(
delta
<
0
){
throw
new
RuntimeException
(
"递减因子必须大于0"
);
}
return
redisTemplate
.
opsForValue
().
increment
(
key
,
-
delta
);
}
//================================Map=================================
/**
* HashGet
* @param key 键 不能为null
* @param item 项 不能为null
* @return 值
*/
public
Object
hget
(
String
key
,
String
item
){
return
redisTemplate
.
opsForHash
().
get
(
key
,
item
);
}
/**
* 获取hashKey对应的所有键值
* @param key 键
* @return 对应的多个键值
*/
public
Map
<
Object
,
Object
>
hmget
(
String
key
){
return
redisTemplate
.
opsForHash
().
entries
(
key
);
}
/**
* HashSet
* @param key 键
* @param map 对应多个键值
* @return true 成功 false 失败
*/
public
boolean
hmset
(
String
key
,
Map
<
String
,
Object
>
map
){
try
{
redisTemplate
.
opsForHash
().
putAll
(
key
,
map
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* HashSet 并设置时间
* @param key 键
* @param map 对应多个键值
* @param time 时间(秒)
* @return true成功 false失败
*/
public
boolean
hmset
(
String
key
,
Map
<
String
,
Object
>
map
,
long
time
){
try
{
redisTemplate
.
opsForHash
().
putAll
(
key
,
map
);
if
(
time
>
0
){
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 向一张hash表中放入数据,如果不存在将创建
* @param key 键
* @param item 项
* @param value 值
* @return true 成功 false失败
*/
public
boolean
hset
(
String
key
,
String
item
,
Object
value
)
{
try
{
redisTemplate
.
opsForHash
().
put
(
key
,
item
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 向一张hash表中放入数据,如果不存在将创建
* @param key 键
* @param item 项
* @param value 值
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
* @return true 成功 false失败
*/
public
boolean
hset
(
String
key
,
String
item
,
Object
value
,
long
time
)
{
try
{
redisTemplate
.
opsForHash
().
put
(
key
,
item
,
value
);
if
(
time
>
0
){
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 删除hash表中的值
* @param key 键 不能为null
* @param item 项 可以使多个 不能为null
*/
public
void
hdel
(
String
key
,
Object
...
item
){
redisTemplate
.
opsForHash
().
delete
(
key
,
item
);
}
/**
* 判断hash表中是否有该项的值
* @param key 键 不能为null
* @param item 项 不能为null
* @return true 存在 false不存在
*/
public
boolean
hHasKey
(
String
key
,
String
item
){
return
redisTemplate
.
opsForHash
().
hasKey
(
key
,
item
);
}
/**
* hash递增 如果不存在,就会创建一个 并把新增后的值返回
* @param key 键
* @param item 项
* @param by 要增加几(大于0)
* @return
*/
public
double
hincr
(
String
key
,
String
item
,
double
by
){
return
redisTemplate
.
opsForHash
().
increment
(
key
,
item
,
by
);
}
/**
* hash递减
* @param key 键
* @param item 项
* @param by 要减少记(小于0)
* @return
*/
public
double
hdecr
(
String
key
,
String
item
,
double
by
){
return
redisTemplate
.
opsForHash
().
increment
(
key
,
item
,-
by
);
}
//============================set=============================
/**
* 根据key获取Set中的所有值
* @param key 键
* @return
*/
public
Set
<
Object
>
sGet
(
String
key
){
try
{
return
redisTemplate
.
opsForSet
().
members
(
key
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* 根据value从一个set中查询,是否存在
* @param key 键
* @param value 值
* @return true 存在 false不存在
*/
public
boolean
sHasKey
(
String
key
,
Object
value
){
try
{
return
redisTemplate
.
opsForSet
().
isMember
(
key
,
value
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 将数据放入set缓存
* @param key 键
* @param values 值 可以是多个
* @return 成功个数
*/
public
long
sSet
(
String
key
,
Object
...
values
)
{
try
{
return
redisTemplate
.
opsForSet
().
add
(
key
,
values
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
0
;
}
}
/**
* 将set数据放入缓存
* @param key 键
* @param time 时间(秒)
* @param values 值 可以是多个
* @return 成功个数
*/
public
long
sSetAndTime
(
String
key
,
long
time
,
Object
...
values
)
{
try
{
Long
count
=
redisTemplate
.
opsForSet
().
add
(
key
,
values
);
if
(
time
>
0
)
{
expire
(
key
,
time
);
}
return
count
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
0
;
}
}
/**
* 获取set缓存的长度
* @param key 键
* @return
*/
public
long
sGetSetSize
(
String
key
){
try
{
return
redisTemplate
.
opsForSet
().
size
(
key
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
0
;
}
}
/**
* 移除值为value的
* @param key 键
* @param values 值 可以是多个
* @return 移除的个数
*/
public
long
setRemove
(
String
key
,
Object
...
values
)
{
try
{
Long
count
=
redisTemplate
.
opsForSet
().
remove
(
key
,
values
);
return
count
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
0
;
}
}
//===============================list=================================
/**
* 获取list缓存的内容
* @param key 键
* @param start 开始
* @param end 结束 0 到 -1代表所有值
* @return
*/
public
List
<
Object
>
lGet
(
String
key
,
long
start
,
long
end
){
try
{
return
redisTemplate
.
opsForList
().
range
(
key
,
start
,
end
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* 获取list缓存的长度
* @param key 键
* @return
*/
public
long
lGetListSize
(
String
key
){
try
{
return
redisTemplate
.
opsForList
().
size
(
key
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
0
;
}
}
/**
* 通过索引 获取list中的值
* @param key 键
* @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推
* @return
*/
public
Object
lGetIndex
(
String
key
,
long
index
){
try
{
return
redisTemplate
.
opsForList
().
index
(
key
,
index
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* 将list放入缓存
* @param key 键
* @param value 值
* @return
*/
public
boolean
lSet
(
String
key
,
Object
value
)
{
try
{
redisTemplate
.
opsForList
().
rightPush
(
key
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 将list放入缓存
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public
boolean
lSet
(
String
key
,
Object
value
,
long
time
)
{
try
{
redisTemplate
.
opsForList
().
rightPush
(
key
,
value
);
if
(
time
>
0
)
{
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 将list放入缓存
* @param key 键
* @param value 值
* @return
*/
public
boolean
lSet
(
String
key
,
List
<
Object
>
value
)
{
try
{
redisTemplate
.
opsForList
().
rightPushAll
(
key
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 将list放入缓存
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public
boolean
lSet
(
String
key
,
List
<
Object
>
value
,
long
time
)
{
try
{
redisTemplate
.
opsForList
().
rightPushAll
(
key
,
value
);
if
(
time
>
0
)
{
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 根据索引修改list中的某条数据
* @param key 键
* @param index 索引
* @param value 值
* @return
*/
public
boolean
lUpdateIndex
(
String
key
,
long
index
,
Object
value
)
{
try
{
redisTemplate
.
opsForList
().
set
(
key
,
index
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 移除N个值为value
* @param key 键
* @param count 移除多少个
* @param value 值
* @return 移除的个数
*/
public
long
lRemove
(
String
key
,
long
count
,
Object
value
)
{
try
{
Long
remove
=
redisTemplate
.
opsForList
().
remove
(
key
,
count
,
value
);
return
remove
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
0
;
}
}
/**
* 模糊查询获取key值
* @param pattern
* @return
*/
public
Set
keys
(
String
pattern
){
return
redisTemplate
.
keys
(
pattern
);
}
/**
* 使用Redis的消息队列
* @param channel
* @param message 消息内容
*/
public
void
convertAndSend
(
String
channel
,
Object
message
){
redisTemplate
.
convertAndSend
(
channel
,
message
);
}
//=========BoundListOperations 用法 start============
/**
* 根据起始结束序号遍历Redis中的list
* @param listKey
* @param start 起始序号
* @param end 结束序号
* @return
*/
public
List
<
Object
>
rangeList
(
String
listKey
,
long
start
,
long
end
)
{
//绑定操作
BoundListOperations
<
String
,
Object
>
boundValueOperations
=
redisTemplate
.
boundListOps
(
listKey
);
//查询数据
return
boundValueOperations
.
range
(
start
,
end
);
}
/**
* 弹出右边的值 --- 并且移除这个值
* @param listKey
*/
public
Object
rifhtPop
(
String
listKey
){
//绑定操作
BoundListOperations
<
String
,
Object
>
boundValueOperations
=
redisTemplate
.
boundListOps
(
listKey
);
return
boundValueOperations
.
rightPop
();
}
//=========BoundListOperations 用法 End============
}
\ No newline at end of file
src/main/resources/application-dev.properties
View file @
a91e9ad
...
...
@@ -24,4 +24,11 @@ spring.datasource.druid.maxPoolPreparedStatementPerConnectionSize=20
spring.datasource.druid.useGlobalDataSourceStat
=
true
# 控制台日志打印
mybatis-plus.configuration.log-
impl
=
org.apache.ibatis.logging.stdout.StdOutImpl
\ No newline at end of file
mybatis-plus.configuration.log-
impl
=
org.apache.ibatis.logging.stdout.StdOutImpl
spring.redis.host
=
47.97.19.66
spring.redis.password
=
Ykhl@208
spring.redis.port
=
6389
spring.redis.lettuce.pool.max-
idle
=
16
spring.redis.lettuce.pool.max-
active
=
32
spring.redis.lettuce.pool.min-
idle
=
8
\ No newline at end of file
src/main/resources/application-prod.properties
View file @
a91e9ad
...
...
@@ -31,3 +31,9 @@ spring.servlet.multipart.max-request-size=4098KB
#wechat.appSecret= 25d57cad61fc1b45b3afa46d4c35e8f6
#wechat.msgUrl= https://teachai.youkehulian.com/login
#wechat.templateId= Z1HNPLOrKiHEjfR1KMP-cC-uH3BWqDJIHv365Ev20yQ
spring.redis.cluster.nodes
=
47.97.19.66:6377,47.97.19.66:6378,47.97.16.66:6379
spring.redis.password
=
Ykhl@208
spring.redis.lettuce.pool.max-
idle
=
16
spring.redis.lettuce.pool.max-
active
=
32
spring.redis.lettuce.pool.min-
idle
=
8
\ No newline at end of file
src/main/resources/application.properties
View file @
a91e9ad
...
...
@@ -63,3 +63,19 @@ spring.quartz.overwrite-existing-jobs=false
# 自动建表,如果已经存在表请勿使用,会覆盖数据表
#spring.quartz.jdbc.initialize-schema=always
#spring.datasource.initialization-mode=embedded
#spring.redis.cluster.nodes=47.97.19.66:6377,47.97.19.66:6378,47.97.19.66:6379
##spring.redis.port=6379
#spring.redis.password=Ykhl@208
## spring.redis.cluster.max-redirects=3
#spring.redis.lettuce.pool.max-idle=16
#spring.redis.lettuce.pool.max-active=32
#spring.redis.lettuce.pool.min-idle=8
#spring.redis.host=47.97.19.66
#spring.redis.password=Ykhl@208
#spring.redis.port=6389
#spring.redis.lettuce.pool.max-idle=16
#spring.redis.lettuce.pool.max-active=32
#spring.redis.lettuce.pool.min-
idle
=
8
\ No newline at end of file
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