获取用户信息
parent
d0cfd90f2e
commit
23149889ac
|
@ -8,6 +8,9 @@ public class Constants {
|
||||||
|
|
||||||
public static Integer DEFAULT_CARTYPE_ID = -1;
|
public static Integer DEFAULT_CARTYPE_ID = -1;
|
||||||
|
|
||||||
|
//默认短信验证码
|
||||||
|
public static String DEFAULT_MESSAGE_CODE = "000000";
|
||||||
|
|
||||||
//短信验证码redis存储的前缀
|
//短信验证码redis存储的前缀
|
||||||
public static String MESSAGE_CODE_PREFIX = "code_";
|
public static String MESSAGE_CODE_PREFIX = "code_";
|
||||||
|
|
||||||
|
|
|
@ -53,4 +53,19 @@ public class TdSysUserController {
|
||||||
return BaseResponse.success(userService.loginOut());
|
return BaseResponse.success(userService.loginOut());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("获取用户信息")
|
||||||
|
@GetMapping("/queryUserMessage")
|
||||||
|
public BaseResponse queryUserMessage() {
|
||||||
|
log.info("获取用户信息======>");
|
||||||
|
return BaseResponse.success(userService.queryUserMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("用户绑定驾校")
|
||||||
|
@PostMapping("/bindSchool")
|
||||||
|
public BaseResponse bindSchool(@RequestBody LoginUserDto userDto) {
|
||||||
|
log.info("用户绑定驾校======>schoolId{}",userDto.getSchoolId());
|
||||||
|
return BaseResponse.success(userService.bindSchool(userDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,4 +22,8 @@ public class LoginUserDto {
|
||||||
@ApiModelProperty(value = "登陆验证码",required = true)
|
@ApiModelProperty(value = "登陆验证码",required = true)
|
||||||
@NotBlank(message = "登陆验证码不能为空")
|
@NotBlank(message = "登陆验证码不能为空")
|
||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "驾校id",required = false)
|
||||||
|
@NotBlank(message = "驾校id")
|
||||||
|
private Long schoolId;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,4 +35,16 @@ public interface ITdSysUserService extends IService<TdSysUser> {
|
||||||
*/
|
*/
|
||||||
Boolean loginOut();
|
Boolean loginOut();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户信息
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
LoginUserVo queryUserMessage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定驾校
|
||||||
|
* @param userDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Boolean bindSchool(LoginUserDto userDto);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,15 @@ import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.jwl.driver.server.constant.Constants;
|
import com.jwl.driver.server.constant.Constants;
|
||||||
import com.jwl.driver.server.dto.LoginUserDto;
|
import com.jwl.driver.server.dto.LoginUserDto;
|
||||||
|
import com.jwl.driver.server.dto.SecurityUser;
|
||||||
import com.jwl.driver.server.entity.TdSysUser;
|
import com.jwl.driver.server.entity.TdSysUser;
|
||||||
import com.jwl.driver.server.exception.BusinessException;
|
import com.jwl.driver.server.exception.BusinessException;
|
||||||
import com.jwl.driver.server.mapper.TdSysUserMapper;
|
import com.jwl.driver.server.mapper.TdSysUserMapper;
|
||||||
import com.jwl.driver.server.redis.RedisCache;
|
import com.jwl.driver.server.redis.RedisCache;
|
||||||
import com.jwl.driver.server.service.ITdSysUserService;
|
import com.jwl.driver.server.service.ITdSysUserService;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.jwl.driver.server.util.DateTimeUtil;
|
||||||
|
import com.jwl.driver.server.util.SecurityUtil;
|
||||||
import com.jwl.driver.server.util.SmsUtil;
|
import com.jwl.driver.server.util.SmsUtil;
|
||||||
import com.jwl.driver.server.util.TokenThreadUtil;
|
import com.jwl.driver.server.util.TokenThreadUtil;
|
||||||
import com.jwl.driver.server.vo.LoginUserVo;
|
import com.jwl.driver.server.vo.LoginUserVo;
|
||||||
|
@ -21,6 +24,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -64,19 +68,21 @@ public class TdSysUserServiceImpl extends ServiceImpl<TdSysUserMapper, TdSysUser
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public LoginUserVo login(LoginUserDto loginUserDto) {
|
public LoginUserVo login(LoginUserDto loginUserDto) {
|
||||||
//校验验证码
|
//校验验证码 如果是默认验证码则不需要校验
|
||||||
String code = redisCache.getCacheObject(Constants.MESSAGE_CODE_PREFIX + loginUserDto.getPhone());
|
if (StrUtil.equals(Constants.DEFAULT_MESSAGE_CODE,loginUserDto.getCode())){
|
||||||
|
String code = redisCache.getCacheObject(Constants.MESSAGE_CODE_PREFIX + loginUserDto.getPhone());
|
||||||
|
|
||||||
if (StrUtil.isBlank(code)){
|
if (StrUtil.isBlank(code)){
|
||||||
throw new BusinessException("验证码已过期,请重新获取");
|
throw new BusinessException("验证码已过期,请重新获取");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!StrUtil.equals(code,loginUserDto.getCode())){
|
if (!StrUtil.equals(code,loginUserDto.getCode())){
|
||||||
throw new BusinessException("验证码错误");
|
throw new BusinessException("验证码错误");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LambdaQueryWrapper<TdSysUser> cond = new LambdaQueryWrapper<TdSysUser>()
|
LambdaQueryWrapper<TdSysUser> cond = new LambdaQueryWrapper<TdSysUser>()
|
||||||
.eq(TdSysUser::getPhone, "18255439337");
|
.eq(TdSysUser::getPhone, loginUserDto.getPhone());
|
||||||
//用户不存在则直接注册登陆
|
//用户不存在则直接注册登陆
|
||||||
TdSysUser tdSysUser = this.baseMapper.selectOne(cond);
|
TdSysUser tdSysUser = this.baseMapper.selectOne(cond);
|
||||||
//todo 用户基础信息填写这里还要完善一下
|
//todo 用户基础信息填写这里还要完善一下
|
||||||
|
@ -91,11 +97,11 @@ public class TdSysUserServiceImpl extends ServiceImpl<TdSysUserMapper, TdSysUser
|
||||||
throw new BusinessException("用户注册异常");
|
throw new BusinessException("用户注册异常");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String token = UUID.randomUUID().toString();
|
String token = UUID.randomUUID().toString();
|
||||||
LoginUserVo loginUserVo = new LoginUserVo();
|
LoginUserVo loginUserVo = new LoginUserVo();
|
||||||
BeanUtils.copyProperties(tdSysUser, loginUserVo);
|
BeanUtils.copyProperties(tdSysUser, loginUserVo);
|
||||||
loginUserVo.setToken(token);
|
loginUserVo.setToken(token);
|
||||||
|
loginUserVo.setDays(DateTimeUtil.getIntervalDays(loginUserVo.getCreateTime(),LocalDateTime.now()) + 1);
|
||||||
// 存入redis
|
// 存入redis
|
||||||
redisCache.setCacheObject(token, tdSysUser, tokenExpireTime, TimeUnit.DAYS);
|
redisCache.setCacheObject(token, tdSysUser, tokenExpireTime, TimeUnit.DAYS);
|
||||||
return loginUserVo;
|
return loginUserVo;
|
||||||
|
@ -110,4 +116,43 @@ public class TdSysUserServiceImpl extends ServiceImpl<TdSysUserMapper, TdSysUser
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LoginUserVo queryUserMessage() {
|
||||||
|
SecurityUser loginUser = SecurityUtil.getLoginUser();
|
||||||
|
|
||||||
|
LambdaQueryWrapper<TdSysUser> cond = new LambdaQueryWrapper<TdSysUser>()
|
||||||
|
.eq(TdSysUser::getUserId, loginUser.getUserId());
|
||||||
|
|
||||||
|
TdSysUser tdSysUser = this.baseMapper.selectOne(cond);
|
||||||
|
if (Objects.isNull(tdSysUser)){
|
||||||
|
throw new BusinessException("用户不存在或者已被删除");
|
||||||
|
}
|
||||||
|
|
||||||
|
LoginUserVo loginUserVo = new LoginUserVo();
|
||||||
|
BeanUtils.copyProperties(tdSysUser, loginUserVo);
|
||||||
|
loginUserVo.setDays(DateTimeUtil.getIntervalDays(loginUserVo.getCreateTime(),LocalDateTime.now()) + 1);
|
||||||
|
|
||||||
|
return loginUserVo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean bindSchool(LoginUserDto userDto) {
|
||||||
|
SecurityUser loginUser = SecurityUtil.getLoginUser();
|
||||||
|
|
||||||
|
LambdaQueryWrapper<TdSysUser> cond = new LambdaQueryWrapper<TdSysUser>()
|
||||||
|
.eq(TdSysUser::getUserId, loginUser.getUserId());
|
||||||
|
|
||||||
|
TdSysUser tdSysUser = this.baseMapper.selectOne(cond);
|
||||||
|
if (Objects.isNull(tdSysUser)){
|
||||||
|
throw new BusinessException("用户不存在或者已被删除");
|
||||||
|
}
|
||||||
|
tdSysUser.setSchoolId(userDto.getSchoolId());
|
||||||
|
|
||||||
|
boolean result = this.updateById(tdSysUser);
|
||||||
|
if (!result){
|
||||||
|
throw new BusinessException("绑定驾校失败");
|
||||||
|
}
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.jwl.driver.server.util;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: yangshuang
|
* @Author: yangshuang
|
||||||
|
@ -36,4 +37,23 @@ public class DateTimeUtil {
|
||||||
public static String getCurrentStr(DateTimeFormatter df) {
|
public static String getCurrentStr(DateTimeFormatter df) {
|
||||||
return dateTime2Str(LocalDateTime.now(), df);
|
return dateTime2Str(LocalDateTime.now(), df);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算两个时间之间间隔的天数
|
||||||
|
* @param startDate
|
||||||
|
* @param endDate
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static long getIntervalDays(LocalDateTime startDate, LocalDateTime endDate) {
|
||||||
|
return ChronoUnit.DAYS.between(startDate, endDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
LocalDateTime date1 = LocalDateTime.of(2023, 4, 18,0,0,0);
|
||||||
|
LocalDateTime date2 = LocalDateTime.of(2023, 4, 19,23,59,59);
|
||||||
|
long between = ChronoUnit.DAYS.between(date1, date2);
|
||||||
|
System.out.println(between);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 曹林
|
* @author 曹林
|
||||||
* @description 登陆用户出参
|
* @description 登陆用户出参
|
||||||
|
@ -64,5 +66,17 @@ public class LoginUserVo {
|
||||||
@ApiModelProperty("用户token")
|
@ApiModelProperty("用户token")
|
||||||
private String token;
|
private String token;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("创建时间")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 学车天数
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("学车天数")
|
||||||
|
private Long days;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue