|
|
|
package com.qs.serve.controller;
|
|
|
|
|
|
|
|
import cn.hutool.crypto.SecureUtil;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
import com.qs.serve.common.framework.redis.RedisService;
|
|
|
|
import com.qs.serve.common.model.annotation.LimitSubmit;
|
|
|
|
import com.qs.serve.common.model.annotation.SysLog;
|
|
|
|
import com.qs.serve.common.model.consts.RedisCacheKeys;
|
|
|
|
import com.qs.serve.common.model.dto.R;
|
|
|
|
import com.qs.serve.common.model.enums.BizType;
|
|
|
|
import com.qs.serve.common.util.IdUtil;
|
|
|
|
import com.qs.serve.modules.sys.entity.SysTenant;
|
|
|
|
import com.qs.serve.modules.sys.entity.SysUser;
|
|
|
|
import com.qs.serve.modules.sys.entity.dto.SysLoginByPhoneParam;
|
|
|
|
import com.qs.serve.modules.sys.entity.dto.SysLoginParam;
|
|
|
|
import com.qs.serve.modules.sys.entity.dto.SysResetPwdByPhoneParam;
|
|
|
|
import com.qs.serve.modules.sys.mapper.SysNoticeUserMapper;
|
|
|
|
import com.qs.serve.modules.sys.service.SysTenantService;
|
|
|
|
import com.qs.serve.modules.sys.service.SysUserLoginService;
|
|
|
|
import com.qs.serve.modules.sys.service.SysUserService;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 门户:后台接口
|
|
|
|
* @author YenHex
|
|
|
|
* @since 2022/3/2
|
|
|
|
*/
|
|
|
|
@Slf4j
|
|
|
|
@AllArgsConstructor
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("portal")
|
|
|
|
public class AdminPortalController {
|
|
|
|
|
|
|
|
private SysTenantService sysTenantService;
|
|
|
|
private SysUserLoginService sysUserLoginService;
|
|
|
|
private RedisService redisService;
|
|
|
|
private SysUserService sysUserService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取所有租户
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@GetMapping("/listTenant")
|
|
|
|
public R<List<SysTenant>> getList(){
|
|
|
|
List<SysTenant> list = sysTenantService.list2();
|
|
|
|
return R.ok(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 登录接口
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@LimitSubmit
|
|
|
|
@SysLog(title = "人员",desc = "后台登录",biz = BizType.LOGIN,saveReqParam = false)
|
|
|
|
@PostMapping("/login")
|
|
|
|
public R<?> login(@RequestBody @Valid SysLoginParam param){
|
|
|
|
return R.ok(sysUserLoginService.login(param));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 手机登陆
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@LimitSubmit
|
|
|
|
@SysLog(title = "人员",desc = "手机登陆",biz = BizType.LOGIN,saveReqParam = false)
|
|
|
|
@PostMapping("/phoneLogin")
|
|
|
|
public R<?> phoneLogin(@RequestBody @Valid SysLoginByPhoneParam param){
|
|
|
|
return R.ok(sysUserLoginService.login(param));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 登出接口
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@SysLog(title = "人员",desc = "退出登录",biz = BizType.LOGOUT,saveReqParam = false)
|
|
|
|
@GetMapping("/logout")
|
|
|
|
public R<?> login(){
|
|
|
|
return R.ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取用户手机验证码
|
|
|
|
*/
|
|
|
|
@LimitSubmit(interval = 10000,message = "请10秒后尝试")
|
|
|
|
@SysLog(title = "人员",desc = "获取用户手机验证码",biz = BizType.OTHER)
|
|
|
|
@GetMapping("/userPhoneCode/{phone}")
|
|
|
|
public R<?> phoneCode(@PathVariable("phone") String phone){
|
|
|
|
LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
wrapper.eq(SysUser::getAccount,phone);
|
|
|
|
Long count = sysUserService.count(wrapper);
|
|
|
|
if(count<1L){
|
|
|
|
return R.error("无效手机号,请重新输入");
|
|
|
|
}
|
|
|
|
String key = RedisCacheKeys.PHONE_KEY+phone;
|
|
|
|
String code = redisService.getString(key);
|
|
|
|
if(code==null){
|
|
|
|
code = IdUtil.genCode(6);
|
|
|
|
}
|
|
|
|
redisService.set(key,code,1, TimeUnit.MINUTES);
|
|
|
|
//TODO send msg
|
|
|
|
return R.ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 重置手机用户密码
|
|
|
|
*/
|
|
|
|
@LimitSubmit(interval = 10000,message = "请10秒后尝试")
|
|
|
|
@SysLog(title = "人员",desc = "重置手机用户密码",biz = BizType.RESET)
|
|
|
|
@PostMapping("/resetPwdByPhone")
|
|
|
|
public R<?> phoneCode(@RequestBody @Valid SysResetPwdByPhoneParam param){
|
|
|
|
LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
wrapper.eq(SysUser::getAccount,param.getPhone());
|
|
|
|
List<SysUser> userList = sysUserService.list(wrapper);
|
|
|
|
if(userList.size()<1){
|
|
|
|
return R.error("无效手机号,请重新输入");
|
|
|
|
}
|
|
|
|
String key = RedisCacheKeys.PHONE_KEY+param.getPhone();
|
|
|
|
String code = redisService.getString(key);
|
|
|
|
if(!param.getCode().equals(code)){
|
|
|
|
return R.error("验证码无效或过期");
|
|
|
|
}
|
|
|
|
SysUser sysUser = new SysUser();
|
|
|
|
sysUser.setId(userList.get(0).getId());
|
|
|
|
sysUser.setPassword(SecureUtil.md5(param.getNewPwd()));
|
|
|
|
sysUserService.updateById(sysUser);
|
|
|
|
return R.ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|