upd sing method
parent
0a2c3e35d5
commit
888ccac2ed
|
@ -32,4 +32,9 @@ public class Sign {
|
||||||
签到次数
|
签到次数
|
||||||
*/
|
*/
|
||||||
private Integer signAmount;
|
private Integer signAmount;
|
||||||
|
|
||||||
|
/*
|
||||||
|
用户标识当前有无签到过 默认是0
|
||||||
|
*/
|
||||||
|
private Integer status=0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@ public class SysSignController {
|
||||||
Long userId = SecurityUtils.getUserId();
|
Long userId = SecurityUtils.getUserId();
|
||||||
System.out.println("当前登录人时"+userId);
|
System.out.println("当前登录人时"+userId);
|
||||||
Sign sign= sysSignService.searchSignByUserId(userId);
|
Sign sign= sysSignService.searchSignByUserId(userId);
|
||||||
|
//可以根据查询出来的signAmount来显示进度条
|
||||||
|
//其次可以根据查询出来的最近一条签到的记录来查看自己当天有无签到,当天签到过签到按钮则变灰色禁用显示已完成
|
||||||
return Result.success(sign);
|
return Result.success(sign);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,50 +29,58 @@ public class SysSignServiceImpl implements SysSignService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Sign searchSignByUserId(Long userId) {
|
public Sign searchSignByUserId(Long userId) {
|
||||||
|
//获取当天的日期 是第几日
|
||||||
|
int today = new Date().getDate();
|
||||||
|
System.out.println("当天是:"+today);
|
||||||
//先从redis中获取连续签到次数
|
//先从redis中获取连续签到次数
|
||||||
if (redisService.hasKey("sign:"+userId)){
|
if (redisService.hasKey("sign:"+userId)){
|
||||||
Sign redisSign = redisService.getCacheObject("sign:" + userId);
|
Sign redisSign = redisService.getCacheObject("sign:" + userId);
|
||||||
|
redisSign.setStatus(1);
|
||||||
return redisSign;
|
return redisSign;
|
||||||
}
|
}
|
||||||
//redis没有从数据库中获取
|
//redis没有从数据库中获取
|
||||||
//查询出当前登录人的最近一条的签到记录
|
//查询出当前登录人的最近一条的签到记录
|
||||||
Sign sign = sysSignMapper.searchSignByUserId(userId);
|
Sign sign = sysSignMapper.searchSignByUserId(userId);
|
||||||
//获取当天的日期 是第几日
|
|
||||||
int today = new Date().getDate();
|
|
||||||
System.out.println("当天是:"+today);
|
|
||||||
//获取最近一次签到的日期 是第几日
|
//获取最近一次签到的日期 是第几日
|
||||||
int recentDay = sign.getSignTime().getDate();
|
int recentDay = sign.getSignTime().getDate();
|
||||||
System.out.println("最近签到是"+recentDay);
|
System.out.println("最近签到是"+recentDay);
|
||||||
//判断是否已经断签了
|
//判断是否已经断签了
|
||||||
if (today-recentDay>1){
|
if (today-recentDay!=1){
|
||||||
System.out.println("断签了!!!!");
|
System.out.println("断签了!!!!");
|
||||||
sign.setSignAmount(0);
|
sign.setSignAmount(0);
|
||||||
//其次将签到次数signAmount改为0
|
//其次将签到次数signAmount改为0
|
||||||
sysSignMapper.updateSingAmountByUserId(sign);
|
sysSignMapper.updateSingAmountByUserId(sign);
|
||||||
redisService.deleteObject("sign:"+userId);
|
|
||||||
redisService.setCacheObject("sign:"+userId,sign);
|
|
||||||
System.out.println(sign);
|
System.out.println(sign);
|
||||||
return sign;
|
return sign;
|
||||||
}
|
}
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
// 将时间设置为第二天凌晨0点
|
||||||
|
long expireTime = getExpireTime(calendar);
|
||||||
|
redisService.setCacheObject("sign:"+userId,sign,expireTime,TimeUnit.SECONDS);
|
||||||
System.out.println("没有断签!!!");
|
System.out.println("没有断签!!!");
|
||||||
System.out.println(sign);
|
System.out.println(sign);
|
||||||
//没有断签 直接返回当前查询出来的签到记录
|
//没有断签 直接返回当前查询出来的签到记录
|
||||||
return sign;
|
return sign;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long getExpireTime(Calendar calendar) {
|
||||||
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
|
calendar.set(Calendar.MINUTE, 0);
|
||||||
|
calendar.set(Calendar.SECOND, 0);
|
||||||
|
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
long expireTime = (calendar.getTimeInMillis() - System.currentTimeMillis()) / 1000;
|
||||||
|
return expireTime;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void signByUserId(Long userId) {
|
public void signByUserId(Long userId) {
|
||||||
Sign sign = this.searchSignByUserId(userId);
|
Sign sign = this.searchSignByUserId(userId);
|
||||||
sign.setSignAmount(sign.getSignAmount()+1);
|
sign.setSignAmount(sign.getSignAmount()+1);
|
||||||
sysSignMapper.signByUserId(sign);
|
sysSignMapper.signByUserId(sign);
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
// 将时间设置为第二天凌晨0点
|
||||||
// 将时间设置为第二天凌晨0点
|
long expireTime = getExpireTime(calendar);
|
||||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
||||||
calendar.set(Calendar.MINUTE, 0);
|
|
||||||
calendar.set(Calendar.SECOND, 0);
|
|
||||||
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
||||||
long expireTime = (calendar.getTimeInMillis() - System.currentTimeMillis()) / 1000;
|
|
||||||
redisService.setCacheObject("sign:"+userId,sign,expireTime, TimeUnit.SECONDS);
|
redisService.setCacheObject("sign:"+userId,sign,expireTime, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue