|
@@ -2,13 +2,19 @@ package com.zd.system.controller;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.zd.common.core.constant.Constants;
|
|
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.PerFun;
|
|
|
import com.zd.common.core.domain.per.PerPrefix;
|
|
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.core.utils.file.ImageUtils;
|
|
|
import com.zd.common.security.utils.DictUtils;
|
|
import com.zd.common.security.utils.DictUtils;
|
|
|
import com.zd.system.api.RemoteDeptService;
|
|
import com.zd.system.api.RemoteDeptService;
|
|
@@ -24,6 +30,7 @@ import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -41,6 +48,8 @@ import com.zd.common.security.annotation.InnerAuth;
|
|
|
import com.zd.common.security.annotation.PreAuthorize;
|
|
import com.zd.common.security.annotation.PreAuthorize;
|
|
|
import com.zd.system.api.model.LoginUser;
|
|
import com.zd.system.api.model.LoginUser;
|
|
|
|
|
|
|
|
|
|
+import static com.zd.common.core.constant.Constants.CODE_EXPIRATION;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 用户信息
|
|
* 用户信息
|
|
|
*
|
|
*
|
|
@@ -76,6 +85,9 @@ public class SysUserController extends BaseController {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ISysDeptService deptService;
|
|
private ISysDeptService deptService;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private RedisTemplate<String,String> redisTemplate;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取用户列表 "system:user:list"
|
|
* 获取用户列表 "system:user:list"
|
|
@@ -430,14 +442,19 @@ public class SysUserController extends BaseController {
|
|
|
*/
|
|
*/
|
|
|
@Log(title = "用户自己修改手机号", businessType = BusinessType.UPDATE)
|
|
@Log(title = "用户自己修改手机号", businessType = BusinessType.UPDATE)
|
|
|
@PutMapping("/change/phone")
|
|
@PutMapping("/change/phone")
|
|
|
- public AjaxResult changePhone(SysUser user) {
|
|
|
|
|
- if (StringUtils.isNotEmpty(user.getPhonenumber())
|
|
|
|
|
- && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
|
|
|
|
|
- return AjaxResult.error("修改用户'" + SecurityUtils.getUsername() + "'失败,手机号码已存在");
|
|
|
|
|
|
|
+ public AjaxResult changePhone(SysUser user,String code) {
|
|
|
|
|
+
|
|
|
|
|
+ Boolean check = check(user.getPhonenumber(), code);
|
|
|
|
|
+ if (check){
|
|
|
|
|
+ if (StringUtils.isNotEmpty(user.getPhonenumber())
|
|
|
|
|
+ && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
|
|
|
|
|
+ return AjaxResult.error("修改用户'" + SecurityUtils.getUsername() + "'失败,手机号码已存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ user.setUpdateBy(SecurityUtils.getUsername());
|
|
|
|
|
+ user.setUserId(SecurityUtils.getUserId());
|
|
|
|
|
+ return toAjax(userService.updateUser(user));
|
|
|
}
|
|
}
|
|
|
- user.setUpdateBy(SecurityUtils.getUsername());
|
|
|
|
|
- user.setUserId(SecurityUtils.getUserId());
|
|
|
|
|
- return toAjax(userService.updateUser(user));
|
|
|
|
|
|
|
+ throw new ServiceException("验证码不正确,请重新输入");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -657,12 +674,10 @@ public class SysUserController extends BaseController {
|
|
|
*/
|
|
*/
|
|
|
@PostMapping("/querySignature")
|
|
@PostMapping("/querySignature")
|
|
|
public R querySignature(){
|
|
public R querySignature(){
|
|
|
-
|
|
|
|
|
SysUser user = userService.selectUserById(SecurityUtils.getUserId());
|
|
SysUser user = userService.selectUserById(SecurityUtils.getUserId());
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("isUpload", StringUtils.isNotBlank(user.getSignature()) ? true : false);
|
|
map.put("isUpload", StringUtils.isNotBlank(user.getSignature()) ? true : false);
|
|
|
map.put("signature", user.getSignature());
|
|
map.put("signature", user.getSignature());
|
|
|
-
|
|
|
|
|
return R.ok(map);
|
|
return R.ok(map);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -703,4 +718,46 @@ public class SysUserController extends BaseController {
|
|
|
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;
|
|
return deptId;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发送验证码
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping("/send/code")
|
|
|
|
|
+ public R<?> send(@RequestParam String phone) {
|
|
|
|
|
+ SysUser sysUser = userService.selectUserIdByPhone(phone);
|
|
|
|
|
+ if (sysUser==null){
|
|
|
|
|
+ throw new ServiceException("手机号:" + phone + " 关联用户不存在",530);
|
|
|
|
|
+ }
|
|
|
|
|
+ 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());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发送验证码
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping("/check/code")
|
|
|
|
|
+ public R<?> checkCode(@RequestParam("phone") String phone,@RequestParam("code")String code) {
|
|
|
|
|
+ return R.ok(check(phone, code));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|