|
|
@@ -3,6 +3,7 @@ package com.yingyangfly.core.service.impl;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.excel.util.StringUtils;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
@@ -18,8 +19,6 @@ import com.yingyangfly.common.utils.DateUtils;
|
|
|
import com.yingyangfly.core.api.ImApi;
|
|
|
import com.yingyangfly.core.domain.*;
|
|
|
import com.yingyangfly.core.dto.*;
|
|
|
-import com.yingyangfly.core.enums.MsgTemplateEnums;
|
|
|
-import com.yingyangfly.core.enums.RedisStatusEnums;
|
|
|
import com.yingyangfly.core.enums.StatusEnums;
|
|
|
import com.yingyangfly.core.mapper.*;
|
|
|
import com.yingyangfly.core.recommend.RecommendFacade;
|
|
|
@@ -27,7 +26,6 @@ import com.yingyangfly.core.security.util.TokenUtil;
|
|
|
import com.yingyangfly.core.service.*;
|
|
|
import com.yingyangfly.core.util.AmountUtils;
|
|
|
import com.yingyangfly.core.util.Sm4Util;
|
|
|
-import com.yingyangfly.core.util.SmgUtil;
|
|
|
import com.yingyangfly.redis.client.RedisClient;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.assertj.core.util.Sets;
|
|
|
@@ -40,10 +38,11 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -470,7 +469,7 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
|
|
|
}
|
|
|
patientDto.setEquipmentPledge(AmountUtils.F2Y4STR(appUser.getEquipmentPledge()));
|
|
|
//查询科室
|
|
|
- if(!StringUtils.isEmpty(appUser.getHospitalDepartment())){
|
|
|
+ if(!org.springframework.util.StringUtils.isEmpty(appUser.getHospitalDepartment())){
|
|
|
Department department = departmentService.getById(appUser.getHospitalDepartment());
|
|
|
if(department!=null){
|
|
|
patientDto.setHospitalDepartmentName(department.getDepartmentName());
|
|
|
@@ -510,6 +509,7 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
|
|
|
}
|
|
|
String encrypt = Sm4Util.encrypt(mobile);
|
|
|
AppUser appUser = this.selectByMobile(encrypt,"0");
|
|
|
+
|
|
|
AppCurrentLoginUser userDetails = (AppCurrentLoginUser) createAppLoginUser(appUser);
|
|
|
if(StrUtil.isNotBlank(sn)){
|
|
|
Equipment equipment = equipmentService.getOne(new LambdaQueryWrapper<Equipment>().eq(Equipment::getSn,sn));
|
|
|
@@ -520,7 +520,8 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
|
|
|
return ResultResponse.fail("不存在此用户信息");
|
|
|
}
|
|
|
}
|
|
|
- String token = tokenUtil.generateToken(userDetails, false,"app");
|
|
|
+ String token = tokenUtil.generateToken(userDetails, false,"app_large_screen");
|
|
|
+
|
|
|
//记录登录历史
|
|
|
LoginRecord loginRecord = new LoginRecord();
|
|
|
loginRecord.setCreateTime(new Date());
|
|
|
@@ -536,8 +537,60 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
|
|
|
redisClient.del(redisKey);
|
|
|
return ResultResponse.success(token);
|
|
|
}
|
|
|
+
|
|
|
public ResultResponse loginMsg(String checkCode, String mobile) {
|
|
|
- return loginMsg(checkCode,mobile,null);
|
|
|
+ String redisKey = "hcp:mobile:" + mobile;
|
|
|
+ String checkCodeRedis = redisClient.get(redisKey, "");
|
|
|
+ if (StringUtils.isEmpty(checkCodeRedis)) {
|
|
|
+ return ResultResponse.fail("验证码已经过期");
|
|
|
+ }
|
|
|
+ String errorNumKey = "app:error:num:"+mobile;
|
|
|
+ String errorNumRedis = redisClient.get(errorNumKey, "");
|
|
|
+ if (ObjectUtils.isNotNull(errorNumRedis)){
|
|
|
+ if (Integer.parseInt(errorNumRedis) >= 3){
|
|
|
+ return ResultResponse.fail("验证码错误了3次,账户锁定10分钟");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!checkCodeRedis.equals(checkCode)) {
|
|
|
+ Integer errorNum = 0;
|
|
|
+ if (ObjectUtils.isNotNull(errorNumRedis)){
|
|
|
+ errorNum = Integer.parseInt(errorNumRedis);
|
|
|
+ }
|
|
|
+ errorNum++;
|
|
|
+ redisClient.set(errorNumKey,String.valueOf(errorNum),600);
|
|
|
+ return ResultResponse.fail("验证码输入错误");
|
|
|
+ }
|
|
|
+ String encrypt = Sm4Util.encrypt(mobile);
|
|
|
+ AppUser appUser = this.selectByMobile(encrypt,"0");
|
|
|
+ if (ObjectUtils.isNull(appUser.getOrderEndTime())){
|
|
|
+ return ResultResponse.fail("请充值后在进行登录");
|
|
|
+ }
|
|
|
+ if (LocalDate.parse(appUser.getOrderEndTime()).isBefore(LocalDate.now())){
|
|
|
+ return ResultResponse.fail("你的套餐已到期,请充值后登录!");
|
|
|
+ }
|
|
|
+ AppCurrentLoginUser userDetails = (AppCurrentLoginUser) createAppLoginUser(appUser);
|
|
|
+
|
|
|
+ String token = tokenUtil.generateToken(userDetails, false,"app");
|
|
|
+ String tokenRedis = redisClient.get(String.format("%s%s", "token:app:", mobile),"");
|
|
|
+ if (StringUtils.isNotBlank(tokenRedis)){
|
|
|
+ redisClient.del(String.format("%s%s", "token:app:", mobile));
|
|
|
+ }
|
|
|
+ redisClient.set(String.format("%s%s", "token:app:", mobile),token);
|
|
|
+
|
|
|
+ //记录登录历史
|
|
|
+ LoginRecord loginRecord = new LoginRecord();
|
|
|
+ loginRecord.setCreateTime(new Date());
|
|
|
+ loginRecord.setUpdateTime(new Date());
|
|
|
+ loginRecord.setLoginName(userDetails.getUsername());
|
|
|
+ loginRecord.setUserType("0");
|
|
|
+ loginRecord.setLoginUserId(userDetails.getId());
|
|
|
+ loginRecord.setOrgCode(userDetails.getOrgCode());
|
|
|
+ loginRecord.setOrgName(userDetails.getOrgName());
|
|
|
+ loginRecordMapper.insert(loginRecord);
|
|
|
+ log.info("{}", JSON.toJSONString(tokenUtil.getAppCurrentLoginUser()));
|
|
|
+ log.info("<<<<<<<<<<<登陆成功删除 redis 短信信息>>>>>>>>>>>>");
|
|
|
+ redisClient.del(redisKey);
|
|
|
+ return ResultResponse.success(token);
|
|
|
}
|
|
|
|
|
|
public ResultResponse getCheckCode(String mobile) {
|
|
|
@@ -551,17 +604,25 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
|
|
|
if (appUser == null) {
|
|
|
return ResultResponse.fail("患者不存在");
|
|
|
}
|
|
|
- Random rand = new Random();
|
|
|
- int randomNumber = rand.nextInt(1000000);
|
|
|
- String random = String.format("%06d", randomNumber);
|
|
|
+ if (ObjectUtils.isNull(appUser.getOrderEndTime())){
|
|
|
+ return ResultResponse.success(false);
|
|
|
+ }
|
|
|
+ if (LocalDate.parse(appUser.getOrderEndTime()).isBefore(LocalDate.now())){
|
|
|
+ return ResultResponse.success(false);
|
|
|
+ }
|
|
|
+// Random rand = new Random();
|
|
|
+// int randomNumber = rand.nextInt(1000000);
|
|
|
+// String random = String.format("%06d", randomNumber);
|
|
|
//6位随机数
|
|
|
- Boolean isSuccess = SmgUtil.sendCheckCode(mobile, MsgTemplateEnums.GET_CHECK_CODE.getTempalteCode(), random);
|
|
|
+// Boolean isSuccess = SmgUtil.sendCheckCode(mobile, MsgTemplateEnums.GET_CHECK_CODE.getTempalteCode(), random);
|
|
|
+ String random = "123456";
|
|
|
+ Boolean isSuccess = true;
|
|
|
if (isSuccess) {
|
|
|
// 防机器
|
|
|
redisClient.set("hcp:sms:mobile:"+mobile,random,60);
|
|
|
//存入redis
|
|
|
redisClient.set("hcp:mobile:" + mobile, random, 120);
|
|
|
- return ResultResponse.success();
|
|
|
+ return ResultResponse.success(true);
|
|
|
} else {
|
|
|
return ResultResponse.fail("发送异常");
|
|
|
}
|
|
|
@@ -800,4 +861,17 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
|
|
|
}
|
|
|
appUserMapper.updateById(appUser);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除缓存的token 实现自动退出
|
|
|
+ */
|
|
|
+ public void expireLogOutJob(){
|
|
|
+ LambdaQueryWrapper<AppUser> appUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ appUserLambdaQueryWrapper.or(wrapper -> wrapper.isNull(AppUser::getOrderEndTime)
|
|
|
+ .or().lt(AppUser::getOrderEndTime, new Date()));
|
|
|
+ List<AppUser> appUserList = appUserMapper.selectList(appUserLambdaQueryWrapper);
|
|
|
+ for (AppUser appUser : appUserList) {
|
|
|
+ redisClient.del(String.format("%s%s", "token:app:", Sm4Util.decrypt(appUser.getMobile())));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|