|
|
@@ -2,13 +2,19 @@ package com.zd.system.controller;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.zd.common.core.constant.Constants;
|
|
|
+import com.zd.common.core.constant.HttpStatus;
|
|
|
+import com.zd.common.core.constant.SecurityConstants;
|
|
|
import com.zd.common.core.domain.per.PerFun;
|
|
|
import com.zd.common.core.domain.per.PerPrefix;
|
|
|
+import com.zd.common.core.exception.ServiceException;
|
|
|
import com.zd.common.core.utils.file.ImageUtils;
|
|
|
import com.zd.common.security.utils.DictUtils;
|
|
|
import com.zd.system.api.RemoteDeptService;
|
|
|
@@ -19,11 +25,10 @@ import com.zd.system.api.model.SimpleUserVO;
|
|
|
import com.zd.system.domain.SysLogoConfig;
|
|
|
import com.zd.system.domain.SysPost;
|
|
|
import com.zd.system.service.*;
|
|
|
-import io.swagger.annotations.Api;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
-import io.swagger.annotations.ApiParam;
|
|
|
+import io.swagger.annotations.*;
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
@@ -41,6 +46,8 @@ import com.zd.common.security.annotation.InnerAuth;
|
|
|
import com.zd.common.security.annotation.PreAuthorize;
|
|
|
import com.zd.system.api.model.LoginUser;
|
|
|
|
|
|
+import static com.zd.common.core.constant.Constants.CODE_EXPIRATION;
|
|
|
+
|
|
|
/**
|
|
|
* 用户信息
|
|
|
*
|
|
|
@@ -76,11 +83,14 @@ public class SysUserController extends BaseController {
|
|
|
@Autowired
|
|
|
private ISysDeptService deptService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private RedisTemplate<String, String> redisTemplate;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 获取用户列表 "system:user:list"
|
|
|
*/
|
|
|
- @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER+ PerFun.LIST)
|
|
|
+ @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER + PerFun.LIST)
|
|
|
@ApiOperation("查询用户列表")
|
|
|
@GetMapping("/list")
|
|
|
public TableDataInfo list(SysUser user) {
|
|
|
@@ -108,8 +118,8 @@ public class SysUserController extends BaseController {
|
|
|
@RequestMapping("/getUserByPhone/{phone}")
|
|
|
public R<SysUser> getUserByPhone(@PathVariable("phone") String phone) {
|
|
|
SysUser sysUser = null;
|
|
|
- if(StringUtils.isNotEmpty(phone)){
|
|
|
- Long userId= userService.selectUserIdByPhone(phone).getUserId();
|
|
|
+ if (StringUtils.isNotEmpty(phone)) {
|
|
|
+ Long userId = userService.selectUserIdByPhone(phone).getUserId();
|
|
|
sysUser = userService.selectUserById(userId);
|
|
|
}
|
|
|
return R.ok(sysUser);
|
|
|
@@ -121,7 +131,7 @@ public class SysUserController extends BaseController {
|
|
|
// @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER+ PerFun.LIST)
|
|
|
@GetMapping("/selectlist")
|
|
|
public List<SelectUserVO> selectlist(String nickName) {
|
|
|
- if(StrUtil.isBlank(nickName)) return Collections.EMPTY_LIST;
|
|
|
+ if (StrUtil.isBlank(nickName)) return Collections.EMPTY_LIST;
|
|
|
SysUser user = new SysUser();
|
|
|
user.setNickName(nickName);
|
|
|
List<SysUser> list = userService.selectUserList(user);
|
|
|
@@ -151,7 +161,7 @@ public class SysUserController extends BaseController {
|
|
|
// @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER+ PerFun.LIST)
|
|
|
@GetMapping("/selectTeacherList")
|
|
|
public List<SelectUserVO> selectTeacherList(String nickName) {
|
|
|
- if(StrUtil.isBlank(nickName)) return Collections.EMPTY_LIST;
|
|
|
+ if (StrUtil.isBlank(nickName)) return Collections.EMPTY_LIST;
|
|
|
SysUser user = new SysUser();
|
|
|
user.setNickName(nickName);
|
|
|
user.setUserType("11");
|
|
|
@@ -178,7 +188,7 @@ public class SysUserController extends BaseController {
|
|
|
|
|
|
//"system:user:export"
|
|
|
@Log(title = "用户管理", businessType = BusinessType.EXPORT)
|
|
|
- @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER+ PerFun.EXPORT)
|
|
|
+ @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER + PerFun.EXPORT)
|
|
|
@PostMapping("/export")
|
|
|
public void export(HttpServletResponse response, SysUser user) throws IOException {
|
|
|
List<SysUser> list = userService.selectUserList(user);
|
|
|
@@ -188,7 +198,7 @@ public class SysUserController extends BaseController {
|
|
|
|
|
|
//"system:user:import"
|
|
|
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
|
|
|
- @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER+ PerFun.IMPORT)
|
|
|
+ @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER + PerFun.IMPORT)
|
|
|
@PostMapping("/importData")
|
|
|
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
|
|
|
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
|
|
|
@@ -206,30 +216,31 @@ public class SysUserController extends BaseController {
|
|
|
|
|
|
/**
|
|
|
* 获取当前用户信息
|
|
|
+ *
|
|
|
* @param loginType 区分小程序端登录/PC 端登录 1 PC ,2 小程序
|
|
|
*/
|
|
|
@InnerAuth
|
|
|
@GetMapping(value = {"/info/{username}", "/info/{username}/{loginType}"})
|
|
|
public R<LoginUser> info(@PathVariable("username") String username,
|
|
|
- @PathVariable(value = "loginType", required = false) Integer loginType) {
|
|
|
+ @PathVariable(value = "loginType", required = false) Integer loginType) {
|
|
|
SysUser sysUser = userService.selectUserByUserName(username);
|
|
|
if (StringUtils.isNull(sysUser)) {
|
|
|
- return R.fail(503,"用户名或密码错误");
|
|
|
+ return R.fail(503, "用户名或密码错误");
|
|
|
}
|
|
|
|
|
|
LoginUser sysUserVo = new LoginUser();
|
|
|
- if(loginType!=null && UserConstants.USER_LOGIN_HXP == loginType){
|
|
|
+ if (loginType != null && UserConstants.USER_LOGIN_HXP == loginType) {
|
|
|
List<SysLogoConfig> list = sysLogoConfigService.selectSysLogoConfigList(new SysLogoConfig());
|
|
|
- if(list.size() > 0 && list.get(0) != null){
|
|
|
- if(sysUser.getUserType().equals(list.get(0).getUserType()) && "-1".equals(list.get(0).getUserType())){
|
|
|
+ if (list.size() > 0 && list.get(0) != null) {
|
|
|
+ if (sysUser.getUserType().equals(list.get(0).getUserType()) && "-1".equals(list.get(0).getUserType())) {
|
|
|
return R.fail("登录失败,没有使用权限!");
|
|
|
}
|
|
|
// TODO 校验是否有柜锁权限
|
|
|
Optional.ofNullable(list.get(0).getSmartLock()).ifPresent(a -> {
|
|
|
- sysUserVo.setCabinetLock(a != null && a == 1 ? true:false);
|
|
|
+ sysUserVo.setCabinetLock(a != null && a == 1 ? true : false);
|
|
|
});
|
|
|
Optional.ofNullable(list.get(0).getAirBottle()).ifPresent(a -> {
|
|
|
- sysUserVo.setAirBottle(a != null && a == 1 ? true:false);
|
|
|
+ sysUserVo.setAirBottle(a != null && a == 1 ? true : false);
|
|
|
});
|
|
|
|
|
|
}
|
|
|
@@ -238,15 +249,15 @@ public class SysUserController extends BaseController {
|
|
|
sysUserVo.setSysUser(sysUser);
|
|
|
|
|
|
// if(loginType != null && loginType == UserConstants.USER_LOGIN_PC){
|
|
|
- // 权限集合
|
|
|
- Set<String> permissions = permissionService.getMenuPermission(sysUser);
|
|
|
- sysUserVo.setPermissions(permissions);
|
|
|
+ // 权限集合
|
|
|
+ Set<String> permissions = permissionService.getMenuPermission(sysUser);
|
|
|
+ sysUserVo.setPermissions(permissions);
|
|
|
|
|
|
- sysUser.setPermits(sysPermitMenuService.selectPerMitByUserId(sysUser));
|
|
|
+ sysUser.setPermits(sysPermitMenuService.selectPerMitByUserId(sysUser));
|
|
|
|
|
|
- // 角色集合
|
|
|
- //Set<String> roles = permissionService.getRolePermission(sysUser.getUserId());
|
|
|
- //sysUserVo.setRoles(roles);
|
|
|
+ // 角色集合
|
|
|
+ //Set<String> roles = permissionService.getRolePermission(sysUser.getUserId());
|
|
|
+ //sysUserVo.setRoles(roles);
|
|
|
// }else {
|
|
|
// sysUser.setPermits(ListUtil.empty());
|
|
|
// }
|
|
|
@@ -269,9 +280,8 @@ public class SysUserController extends BaseController {
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@GetMapping("/phone/{ids}")
|
|
|
- public R<List<String>> getPhoneByUserIDS(@PathVariable("ids") Long... ids)
|
|
|
- {
|
|
|
- return R.ok(userService.queryPhoneByIds(ids));
|
|
|
+ public R<List<String>> getPhoneByUserIDS(@PathVariable("ids") Long... ids) {
|
|
|
+ return R.ok(userService.queryPhoneByIds(ids));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -281,26 +291,21 @@ public class SysUserController extends BaseController {
|
|
|
@GetMapping("/my/info/Simple")
|
|
|
public R<SimpleUserVO> myInfoSimple() {
|
|
|
SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
|
|
|
- if(sysUser!=null)
|
|
|
- {
|
|
|
+ if (sysUser != null) {
|
|
|
SimpleUserVO simpleUserVO = new SimpleUserVO();
|
|
|
simpleUserVO.setUserName(sysUser.getNickName());
|
|
|
simpleUserVO.setDeptName(Optional.ofNullable(sysUser.getDept())
|
|
|
- .map(a->a.getDeptName())
|
|
|
+ .map(a -> a.getDeptName())
|
|
|
.orElse(StrUtil.EMPTY));
|
|
|
simpleUserVO.setAvatar(sysUser.getAvatar());
|
|
|
//判断职称
|
|
|
//如果用户类型为00
|
|
|
- if("00".equals(sysUser.getUserType()))
|
|
|
- {
|
|
|
+ if ("00".equals(sysUser.getUserType())) {
|
|
|
simpleUserVO.setProfessional("管理员");
|
|
|
}
|
|
|
- if(UserConstants.USER_TYPE_STUDENT.equals(sysUser.getUserType()))
|
|
|
- {
|
|
|
+ if (UserConstants.USER_TYPE_STUDENT.equals(sysUser.getUserType())) {
|
|
|
simpleUserVO.setProfessional("学生");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
String professional = Optional.ofNullable(sysUser.getPosition())
|
|
|
.map(a -> DictUtils.getDictCacheLable("professional", a))
|
|
|
.orElse(StrUtil.EMPTY);
|
|
|
@@ -324,6 +329,7 @@ public class SysUserController extends BaseController {
|
|
|
SysUser sysUser = userService.selectUserByUserName(username);
|
|
|
return R.ok(sysUser);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 获取当前用户信息
|
|
|
*/
|
|
|
@@ -333,6 +339,7 @@ public class SysUserController extends BaseController {
|
|
|
SysUser sysUser = userService.selectUserByCardNum(cardnum);
|
|
|
return R.ok(sysUser);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 注册用户信息
|
|
|
*/
|
|
|
@@ -369,7 +376,7 @@ public class SysUserController extends BaseController {
|
|
|
/**
|
|
|
* 根据用户编号获取详细信息 "system:user:query"
|
|
|
*/
|
|
|
- @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER+ PerFun.QUERY)
|
|
|
+ @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER + PerFun.QUERY)
|
|
|
@GetMapping(value = {"/", "/{userId}"})
|
|
|
public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) {
|
|
|
AjaxResult ajax = AjaxResult.success();
|
|
|
@@ -387,7 +394,7 @@ public class SysUserController extends BaseController {
|
|
|
/**
|
|
|
* 新增用户 "system:user:add"
|
|
|
*/
|
|
|
- @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER+ PerFun.ADD)
|
|
|
+ @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER + PerFun.ADD)
|
|
|
@Log(title = "用户管理", businessType = BusinessType.INSERT)
|
|
|
@PostMapping
|
|
|
public AjaxResult add(@Validated @RequestBody SysUser user) {
|
|
|
@@ -408,7 +415,7 @@ public class SysUserController extends BaseController {
|
|
|
/**
|
|
|
* 修改用户 "system:user:edit"
|
|
|
*/
|
|
|
- @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER+ PerFun.EDIT)
|
|
|
+ @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER + PerFun.EDIT)
|
|
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
|
|
@PutMapping
|
|
|
public AjaxResult edit(@Validated @RequestBody SysUser user) {
|
|
|
@@ -430,7 +437,7 @@ public class SysUserController extends BaseController {
|
|
|
*/
|
|
|
@Log(title = "用户自己修改手机号", businessType = BusinessType.UPDATE)
|
|
|
@PutMapping("/change/phone")
|
|
|
- public AjaxResult changePhone(SysUser user) {
|
|
|
+ public AjaxResult changePhone(SysUser user, String code) {
|
|
|
if (StringUtils.isNotEmpty(user.getPhonenumber())
|
|
|
&& UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
|
|
|
return AjaxResult.error("修改用户'" + SecurityUtils.getUsername() + "'失败,手机号码已存在");
|
|
|
@@ -456,7 +463,7 @@ public class SysUserController extends BaseController {
|
|
|
/**
|
|
|
* 重置密码 "system:user:edit"
|
|
|
*/
|
|
|
- @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER+ PerFun.EDIT)
|
|
|
+ @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER + PerFun.EDIT)
|
|
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
|
|
@PutMapping("/resetPwd")
|
|
|
public AjaxResult resetPwd(@RequestBody SysUser user) {
|
|
|
@@ -469,7 +476,7 @@ public class SysUserController extends BaseController {
|
|
|
/**
|
|
|
* 状态修改 "system:user:edit"
|
|
|
*/
|
|
|
- @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER+ PerFun.EDIT)
|
|
|
+ @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER + PerFun.EDIT)
|
|
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
|
|
@PutMapping("/changeStatus")
|
|
|
public AjaxResult changeStatus(@RequestBody SysUser user) {
|
|
|
@@ -481,7 +488,7 @@ public class SysUserController extends BaseController {
|
|
|
/**
|
|
|
* 根据用户编号获取授权角色 "system:user:query"
|
|
|
*/
|
|
|
- @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER+ PerFun.QUERY)
|
|
|
+ @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER + PerFun.QUERY)
|
|
|
@GetMapping("/authRole/{userId}")
|
|
|
public AjaxResult authRole(@PathVariable("userId") Long userId) {
|
|
|
AjaxResult ajax = AjaxResult.success();
|
|
|
@@ -495,7 +502,7 @@ public class SysUserController extends BaseController {
|
|
|
/**
|
|
|
* 用户授权角色 "system:user:edit"
|
|
|
*/
|
|
|
- @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER+ PerFun.EDIT)
|
|
|
+ @PreAuthorize(hasPermi = PerPrefix.SYSTEM_USER + PerFun.EDIT)
|
|
|
@Log(title = "用户管理", businessType = BusinessType.GRANT)
|
|
|
@PutMapping("/authRole")
|
|
|
public AjaxResult insertAuthRole(Long userId, Long[] roleIds) {
|
|
|
@@ -539,14 +546,15 @@ public class SysUserController extends BaseController {
|
|
|
|
|
|
/**
|
|
|
* 根据用户名查询
|
|
|
+ *
|
|
|
* @param nickName
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping("/selectUserListByName")
|
|
|
- public List<SysUser> selectUserListByName(String nickName,String userType) {
|
|
|
- if(StrUtil.isBlank(nickName)) return Collections.EMPTY_LIST;
|
|
|
+ public List<SysUser> selectUserListByName(String nickName, String userType) {
|
|
|
+ if (StrUtil.isBlank(nickName)) return Collections.EMPTY_LIST;
|
|
|
SysUser user = new SysUser();
|
|
|
- user.setUserType(StrUtil.isBlank(userType)?"11":userType);//用户身份 11教职工 22学生
|
|
|
+ user.setUserType(StrUtil.isBlank(userType) ? "11" : userType);//用户身份 11教职工 22学生
|
|
|
user.setNickName(nickName);
|
|
|
startPage();
|
|
|
List<SysUser> list = userService.selectUserListByName(user);
|
|
|
@@ -556,12 +564,13 @@ public class SysUserController extends BaseController {
|
|
|
|
|
|
/**
|
|
|
* 根据用户名查询不在白名单的用户
|
|
|
+ *
|
|
|
* @param nickName
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping("/selectUserListByNotWhite")
|
|
|
public List<SysUser> selectUserListByNotWhite(String nickName) {
|
|
|
- if(StrUtil.isBlank(nickName)) return Collections.EMPTY_LIST;
|
|
|
+ if (StrUtil.isBlank(nickName)) return Collections.EMPTY_LIST;
|
|
|
SysUser user = new SysUser();
|
|
|
//当前登录用户所属院校部门集合
|
|
|
List<Long> deptIds = userService.getLogingUserDeptids();
|
|
|
@@ -574,6 +583,7 @@ public class SysUserController extends BaseController {
|
|
|
|
|
|
/**
|
|
|
* 获取职位下的人员
|
|
|
+ *
|
|
|
* @param user
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -587,6 +597,7 @@ public class SysUserController extends BaseController {
|
|
|
|
|
|
/**
|
|
|
* 获取没有关联职位的人员
|
|
|
+ *
|
|
|
* @param user
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -622,11 +633,12 @@ public class SysUserController extends BaseController {
|
|
|
|
|
|
/**
|
|
|
* 电子签名抠图生成图片
|
|
|
+ *
|
|
|
* @return base64 图片
|
|
|
*/
|
|
|
@PostMapping("/genSign")
|
|
|
@ApiOperation("电子签名抠图生成图片")
|
|
|
- public R<String> getPsPictureSign(@RequestParam("file") MultipartFile file){
|
|
|
+ public R<String> getPsPictureSign(@RequestParam("file") MultipartFile file) {
|
|
|
try {
|
|
|
return R.ok(ImageUtils.transparent(file.getInputStream(), 152));
|
|
|
} catch (Exception e) {
|
|
|
@@ -637,7 +649,7 @@ public class SysUserController extends BaseController {
|
|
|
|
|
|
@PostMapping("/updateSignature")
|
|
|
@ApiOperation("修改用户电子签名")
|
|
|
- public R updateSignature(@ApiParam("签名图片") @RequestParam("file") MultipartFile file){
|
|
|
+ public R updateSignature(@ApiParam("签名图片") @RequestParam("file") MultipartFile file) {
|
|
|
|
|
|
//保存
|
|
|
R<SysFile> fileResult = remoteFileService.upload(file);
|
|
|
@@ -656,18 +668,15 @@ public class SysUserController extends BaseController {
|
|
|
* 查询用户是否已经上传签名
|
|
|
*/
|
|
|
@PostMapping("/querySignature")
|
|
|
- public R querySignature(){
|
|
|
-
|
|
|
+ public R querySignature() {
|
|
|
SysUser user = userService.selectUserById(SecurityUtils.getUserId());
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("isUpload", StringUtils.isNotBlank(user.getSignature()) ? true : false);
|
|
|
map.put("signature", user.getSignature());
|
|
|
-
|
|
|
return R.ok(map);
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 获取安全负责人用户列表
|
|
|
*/
|
|
|
@@ -695,12 +704,102 @@ public class SysUserController extends BaseController {
|
|
|
*/
|
|
|
@ApiOperation("获取当前登录用户所属学校的deptid")
|
|
|
@GetMapping("/getLoginUserSchoolDeptid")
|
|
|
- public Long getLoginUserSchoolDeptid(){
|
|
|
+ public Long getLoginUserSchoolDeptid() {
|
|
|
//获取当前登录用户信息
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
SysUser sysUser = userService.selectUserById(userId);
|
|
|
SysDept sysDept = deptService.selectDeptById(sysUser.getDept().getDeptId());
|
|
|
- Long deptId ="0".equals(sysDept.getAncestors())==true?sysDept.getDeptId():Long.valueOf(sysDept.getAncestors().split(",")[1]);
|
|
|
+ Long deptId = "0".equals(sysDept.getAncestors()) == true ? sysDept.getDeptId() : Long.valueOf(sysDept.getAncestors().split(",")[1]);
|
|
|
return deptId;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送验证码
|
|
|
+ * @param phone 手机号码
|
|
|
+ * @return 验证码
|
|
|
+ */
|
|
|
+ @ApiOperation("发送验证码")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "phone",required = true,value = "手机号")
|
|
|
+ })
|
|
|
+ @PostMapping("/send/code")
|
|
|
+ public R<?> send(@RequestParam String phone) {
|
|
|
+ String key = Constants.DEFAULT_CODE_KEY + Constants.UPDATE_TYPE_MOBILE + "@" + phone;
|
|
|
+ String code = RandomUtil.randomNumbers(6);
|
|
|
+ redisTemplate.opsForValue().set(key, code, CODE_EXPIRATION, TimeUnit.MINUTES);
|
|
|
+ logger.info("========================>{}<=========================", code);
|
|
|
+ return R.ok(code);
|
|
|
+// return stockService.sendSydSms(code, 2, null, form.getUsername());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证码校验
|
|
|
+ * @param phone 手机号
|
|
|
+ * @param code 验证码
|
|
|
+ * @return 校对结果
|
|
|
+ */
|
|
|
+ @ApiOperation("验证码校验")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "phone",required = true,value = "手机号"),
|
|
|
+ @ApiImplicitParam(name = "code",required = true,value = "验证码")
|
|
|
+ })
|
|
|
+ @GetMapping("/check/code")
|
|
|
+ public R<?> checkCode(@RequestParam("phone") String phone, @RequestParam("code") String code) {
|
|
|
+ return R.ok(check(phone, code));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户修改手机号
|
|
|
+ * @param oldPhone 原手机号
|
|
|
+ * @param newPhone 新手机号
|
|
|
+ * @param code 验证码
|
|
|
+ * @return AjaxResult
|
|
|
+ */
|
|
|
+ @ApiOperation("修改手机号")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "oldPhone",required = true,value = "原手机号"),
|
|
|
+ @ApiImplicitParam(name = "newPhone",required = true,value = "新手机号"),
|
|
|
+ @ApiImplicitParam(name = "code",required = true,value = "验证码")
|
|
|
+ })
|
|
|
+ @Log(title = "用户修改手机号", businessType = BusinessType.UPDATE)
|
|
|
+ @PutMapping("/update/phone")
|
|
|
+ public AjaxResult updatePhone(@RequestParam("oldPhone") String oldPhone,@RequestParam("newPhone") String newPhone,@RequestParam("code") String code) {
|
|
|
+ if (StringUtils.isEmpty(oldPhone) || StringUtils.isEmpty(newPhone)){
|
|
|
+ throw new ServiceException("原密码或新密码不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ SysUser user = userService.selectUserIdByPhone(oldPhone);
|
|
|
+ if(user==null){
|
|
|
+ throw new ServiceException("用户查询失败");
|
|
|
+ }
|
|
|
+ user.setPhonenumber(newPhone);
|
|
|
+ if (StringUtils.isNotEmpty(user.getPhonenumber())
|
|
|
+ && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
|
|
|
+ return AjaxResult.error("修改用户'" + SecurityUtils.getUsername() + "'失败,手机号码已存在");
|
|
|
+ }
|
|
|
+ Boolean check = check(newPhone, code);
|
|
|
+ if (Boolean.TRUE.equals(check)){
|
|
|
+ user.setUpdateBy(SecurityUtils.getUsername());
|
|
|
+ user.setUserId(SecurityUtils.getUserId());
|
|
|
+ return toAjax(userService.updateUser(user));
|
|
|
+ }
|
|
|
+ throw new ServiceException("验证码不正确,请重新输入");
|
|
|
+ }
|
|
|
+
|
|
|
+ private Boolean check(String phone, String code) {
|
|
|
+ if (StringUtils.isEmpty(phone)) {
|
|
|
+ throw new ServiceException("请输入手机号");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(code)) {
|
|
|
+ throw new ServiceException("请输入验证码");
|
|
|
+ }
|
|
|
+ String key = Constants.DEFAULT_CODE_KEY + Constants.UPDATE_TYPE_MOBILE + "@" + phone;
|
|
|
+
|
|
|
+ String temp = redisTemplate.opsForValue().get(key);
|
|
|
+ if (temp == null) {
|
|
|
+ throw new ServiceException("验证码已过期");
|
|
|
+ }
|
|
|
+ logger.info("========================>{}:{}<=========================", code, temp);
|
|
|
+ return temp.equals(code);
|
|
|
+ }
|
|
|
}
|