From f466eba1d85d1132767047b42653cda4540e028f Mon Sep 17 00:00:00 2001 From: mzh820631607 Date: Fri, 13 Nov 2020 18:42:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=98=E8=AE=B0=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../msdw/tms/api/UserInfoControllerApi.java | 1 + .../EvaluationRecordController.java | 6 +- .../tms/controller/UserInfoController.java | 6 +- .../com/msdw/tms/dao/FractionEntityDao.java | 2 +- .../java/com/msdw/tms/entity/vo/CheckVo.java | 8 ++- .../tms/service/FractionEntityService.java | 2 +- .../impl/FractionEntityServiceImpl.java | 4 +- .../tms/service/impl/UserInfoServiceImpl.java | 58 +++++++++++++------ .../mapper/tms/FractionEntityDao.xml | 2 +- 9 files changed, 60 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/msdw/tms/api/UserInfoControllerApi.java b/src/main/java/com/msdw/tms/api/UserInfoControllerApi.java index 49e38c5..9454264 100644 --- a/src/main/java/com/msdw/tms/api/UserInfoControllerApi.java +++ b/src/main/java/com/msdw/tms/api/UserInfoControllerApi.java @@ -33,6 +33,7 @@ public interface UserInfoControllerApi { @ApiParam(value = "发送类型(1邮箱,2手机)",required = true) Integer type); @ApiOperation(value = "校验验证码",notes = "校验验证码") +// R checkCode(@ApiParam(value = "用户id和验证码") String code,@ApiParam(value = "用户id和验证码")String opener); R checkCode(@ApiParam(value = "用户id和验证码") CheckVo checkVo); @ApiOperation(value = "设置新密码",notes = "设置新密码") diff --git a/src/main/java/com/msdw/tms/controller/EvaluationRecordController.java b/src/main/java/com/msdw/tms/controller/EvaluationRecordController.java index 32dc244..f7f1cd4 100644 --- a/src/main/java/com/msdw/tms/controller/EvaluationRecordController.java +++ b/src/main/java/com/msdw/tms/controller/EvaluationRecordController.java @@ -130,7 +130,8 @@ public class EvaluationRecordController implements EvaluationRecordControllerApi @Override @GetMapping("/openExercise") public R isOpenExercise(Integer userId){ - Integer id = fractionEntityService.queryScore(userId); + Integer type = 2; + Integer id = fractionEntityService.queryScore(userId,type); if (id>0){ Integer score = fractionEntityService.queryExerciseRecord(userId); if (score>=60){ @@ -147,7 +148,8 @@ public class EvaluationRecordController implements EvaluationRecordControllerApi @Override @GetMapping("/openTeaching") public R isOpenTeaching(Integer userId){ - Integer id = fractionEntityService.queryScore(userId); + Integer type = 3; + Integer id = fractionEntityService.queryScore(userId,type); if (id>0){ Integer score = fractionEntityService.queryTeachingRecord(userId); if (score>=60){ diff --git a/src/main/java/com/msdw/tms/controller/UserInfoController.java b/src/main/java/com/msdw/tms/controller/UserInfoController.java index d32bccd..3de55fa 100644 --- a/src/main/java/com/msdw/tms/controller/UserInfoController.java +++ b/src/main/java/com/msdw/tms/controller/UserInfoController.java @@ -158,17 +158,17 @@ public class UserInfoController implements UserInfoControllerApi { @GetMapping("/findPassword") public R findPassword(@RequestParam String account,@RequestParam Integer type){ R result = userInfoService.findPassword(account,type); - return R.ok(); + return result; } /** * 校验验证码 - * @param checkVo (userId 、 code) + * @param checkVo (opener 、 code) * @return */ @Override @PostMapping("/checkCode") - public R checkCode(@RequestBody CheckVo checkVo){ + public R checkCode(@RequestBody CheckVo checkVo){ R result =userInfoService.checkCode(checkVo); return result; } diff --git a/src/main/java/com/msdw/tms/dao/FractionEntityDao.java b/src/main/java/com/msdw/tms/dao/FractionEntityDao.java index b9214f2..19d01b2 100644 --- a/src/main/java/com/msdw/tms/dao/FractionEntityDao.java +++ b/src/main/java/com/msdw/tms/dao/FractionEntityDao.java @@ -12,5 +12,5 @@ public interface FractionEntityDao { Integer queryTeachingRecord(Integer userId); - Integer queryScore( Integer userId); + Integer queryScore( Integer userId,Integer type); } diff --git a/src/main/java/com/msdw/tms/entity/vo/CheckVo.java b/src/main/java/com/msdw/tms/entity/vo/CheckVo.java index b388ee9..b695754 100644 --- a/src/main/java/com/msdw/tms/entity/vo/CheckVo.java +++ b/src/main/java/com/msdw/tms/entity/vo/CheckVo.java @@ -1,11 +1,15 @@ package com.msdw.tms.entity.vo; +import io.swagger.annotations.ApiParam; import lombok.Data; import lombok.experimental.Accessors; +import java.io.Serializable; + @Data @Accessors(chain = true) -public class CheckVo { +public class CheckVo implements Serializable { + private static final long serialVersionUID = 1L; //用户id private Integer userId; //用户的邮箱地址 @@ -27,5 +31,7 @@ public class CheckVo { // private String mobile; //密码 private String password; + @ApiParam(value = "用户账号") + private String account; } diff --git a/src/main/java/com/msdw/tms/service/FractionEntityService.java b/src/main/java/com/msdw/tms/service/FractionEntityService.java index 4f18840..3f4dbf5 100644 --- a/src/main/java/com/msdw/tms/service/FractionEntityService.java +++ b/src/main/java/com/msdw/tms/service/FractionEntityService.java @@ -10,5 +10,5 @@ public interface FractionEntityService { Integer queryTeachingRecord(Integer userId); - Integer queryScore(Integer userId); + Integer queryScore(Integer userId,Integer type); } diff --git a/src/main/java/com/msdw/tms/service/impl/FractionEntityServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/FractionEntityServiceImpl.java index 699e3b5..7f6692c 100644 --- a/src/main/java/com/msdw/tms/service/impl/FractionEntityServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/FractionEntityServiceImpl.java @@ -33,8 +33,8 @@ public class FractionEntityServiceImpl implements FractionEntityService { } @Override - public Integer queryScore(Integer userId){ - Integer id = fractionMapper.queryScore(userId); + public Integer queryScore(Integer userId,Integer type){ + Integer id = fractionMapper.queryScore(userId,type); return id; } } diff --git a/src/main/java/com/msdw/tms/service/impl/UserInfoServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/UserInfoServiceImpl.java index 294a87e..bf9e347 100644 --- a/src/main/java/com/msdw/tms/service/impl/UserInfoServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/UserInfoServiceImpl.java @@ -21,12 +21,17 @@ import com.msdw.tms.entity.vo.UserProsonalEntityVo; import com.msdw.tms.service.UserInfoService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.data.redis.core.ValueOperations; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + @Slf4j @Service("userInfoService") public class UserInfoServiceImpl extends ServiceImpl implements UserInfoService { @@ -36,6 +41,9 @@ public class UserInfoServiceImpl extends ServiceImpl params) { @@ -160,25 +168,37 @@ public class UserInfoServiceImpl extends ServiceImpl ops = stringRedisTemplate.opsForValue(); + ops.set(account, code, 5*60, TimeUnit.SECONDS);//5分钟 + return R.ok().put("data",entity); + + + +// checkVo.setCheckCode(code).setSetTime(utils.letTimes(5)).setUserId(entity.getUserId()).setTypes(1); +// boolean result = userDao.saveCheckCode(checkVo); +// +// if (result) { +// return R.ok().put("data",entity); +// }else { +// return R.error("保存验证码异常"); +// } }else if (type==2){//通过手机验证 SendSMS.sendCode(entity.getPhone(),code); - checkVo.setCheckCode(code).setSetTime(utils.letTimes(5)).setUserId(entity.getUserId()).setTypes(2); - boolean result = userDao.saveCheckPhoneCode(checkVo); - if (result) { - return R.ok().put("data",entity); - }else { - return R.error("保存验证码异常"); - } + ValueOperations ops = stringRedisTemplate.opsForValue(); + ops.set(account, code, 5*60, TimeUnit.SECONDS);//5分钟 + return R.ok().put("data",entity); + +// checkVo.setCheckCode(code).setSetTime(utils.letTimes(5)).setUserId(entity.getUserId()).setTypes(2); +// boolean result = userDao.saveCheckPhoneCode(checkVo); +// if (result) { +// return R.ok().put("data",entity); +// }else { +// return R.error("保存验证码异常"); +// } }else { return R.error("请求验证类型不对!!!"); } @@ -192,10 +212,12 @@ public class UserInfoServiceImpl extends ServiceImpl ops = stringRedisTemplate.opsForValue(); + String opener = ops.get(checkVo.getAccount()); + if (opener==null){ + return R.error("验证码已过期或不存在,请重新发送验证码"); + }else if (opener.equals(checkVo.getCode())){ return R.ok(); }else { return R.error("failure"); diff --git a/src/main/resources/mapper/tms/FractionEntityDao.xml b/src/main/resources/mapper/tms/FractionEntityDao.xml index 73ecdd4..90f853e 100644 --- a/src/main/resources/mapper/tms/FractionEntityDao.xml +++ b/src/main/resources/mapper/tms/FractionEntityDao.xml @@ -15,6 +15,6 @@ \ No newline at end of file