|
@@ -18,6 +18,7 @@ import com.jeeplus.common.SecurityUtils;
|
|
import com.jeeplus.common.constant.CommonConstants;
|
|
import com.jeeplus.common.constant.CommonConstants;
|
|
import com.jeeplus.common.excel.ExcelOptions;
|
|
import com.jeeplus.common.excel.ExcelOptions;
|
|
import com.jeeplus.common.excel.annotation.ExportMode;
|
|
import com.jeeplus.common.excel.annotation.ExportMode;
|
|
|
|
+import com.jeeplus.common.redis.RedisUtils;
|
|
import com.jeeplus.common.utils.ResponseUtil;
|
|
import com.jeeplus.common.utils.ResponseUtil;
|
|
import com.jeeplus.core.query.QueryWrapperGenerator;
|
|
import com.jeeplus.core.query.QueryWrapperGenerator;
|
|
import com.jeeplus.logging.annotation.ApiLog;
|
|
import com.jeeplus.logging.annotation.ApiLog;
|
|
@@ -39,6 +40,7 @@ import io.swagger.annotations.ApiOperation;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
@@ -46,6 +48,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
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;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -66,6 +69,9 @@ public class UserController {
|
|
@Autowired
|
|
@Autowired
|
|
private OfficeService officeService;
|
|
private OfficeService officeService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisUtils redisUtils;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 根据ids查询用户基本信息(姓名、手机、角色、部门)
|
|
* 根据ids查询用户基本信息(姓名、手机、角色、部门)
|
|
*
|
|
*
|
|
@@ -535,7 +541,7 @@ public class UserController {
|
|
*/
|
|
*/
|
|
@DemoMode
|
|
@DemoMode
|
|
@ApiLog("修改密码")
|
|
@ApiLog("修改密码")
|
|
- @RequestMapping("savePwd")
|
|
|
|
|
|
+ @PostMapping("/savePwd")
|
|
public ResponseEntity savePwd(String oldPassword, String newPassword) {
|
|
public ResponseEntity savePwd(String oldPassword, String newPassword) {
|
|
UserDTO userDTO = UserUtils.getCurrentUserDTO ( );
|
|
UserDTO userDTO = UserUtils.getCurrentUserDTO ( );
|
|
if ( StrUtil.isNotBlank ( oldPassword ) && StrUtil.isNotBlank ( newPassword ) ) {
|
|
if ( StrUtil.isNotBlank ( oldPassword ) && StrUtil.isNotBlank ( newPassword ) ) {
|
|
@@ -612,7 +618,117 @@ public class UserController {
|
|
@GetMapping("isAdmin")
|
|
@GetMapping("isAdmin")
|
|
@ApiOperation(value = "判断当前用户是否是管理员")
|
|
@ApiOperation(value = "判断当前用户是否是管理员")
|
|
public Boolean isAdmin() {
|
|
public Boolean isAdmin() {
|
|
|
|
+
|
|
return UserUtils.getCurrentUserDTO().isAdmin();
|
|
return UserUtils.getCurrentUserDTO().isAdmin();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 通过手机号获取验证码(忘记密码)
|
|
|
|
+ * @param mobile 手机号码
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "通过手机号获取验证码(忘记密码)")
|
|
|
|
+ @GetMapping(value = "/getPhoneCode")
|
|
|
|
+ public ResponseEntity<HashMap<String,Object>> getPhoneCode(@RequestParam("mobile") String mobile) {
|
|
|
|
+ HashMap<String,Object> j = new HashMap<String,Object>();
|
|
|
|
+ //验证该手机号是否已经进行注册
|
|
|
|
+ User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getMobile, mobile));
|
|
|
|
+ if (ObjectUtil.isNotEmpty( user )) {
|
|
|
|
+ //生成四位随机验证码
|
|
|
|
+ String randomCode = String.valueOf((int) (Math.random() * 9000 + 1000));
|
|
|
|
+
|
|
|
|
+ HashMap<String,Object> result = null;
|
|
|
|
+ try{
|
|
|
|
+ //调用工具类返回结果
|
|
|
|
+ result = UserUtils.sendRandomCodes(mobile, randomCode);
|
|
|
|
+ String statusCode = (String) result.get("statusCode");
|
|
|
|
+ if (("000000").equals(statusCode)) {
|
|
|
|
+ j.put("success",true);
|
|
|
|
+ j.put("message","短信发送成功!");
|
|
|
|
+ //存放验证码
|
|
|
|
+ //以手机号+为key 五分钟为时效 将验证码进行短期存储
|
|
|
|
+ redisUtils.setEx(mobile+ "resetPassword", randomCode, 300, TimeUnit.SECONDS);
|
|
|
|
+ }else if(statusCode.equals("160040")){
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","手机号获取验证码次数已达每日上限!");
|
|
|
|
+ }else{
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","短信发送失败,错误代码:101,请联系管理员!");
|
|
|
|
+ j.put("ErrorXml",result);
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","短信发送失败!");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","当前手机号未注册!请联系管理员");
|
|
|
|
+ }
|
|
|
|
+ return ResponseEntity.ok(j);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改密码
|
|
|
|
+ * @param mobile
|
|
|
|
+ * @param code
|
|
|
|
+ * @param newPassword
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @GetMapping(value = "/saveNewPassword")
|
|
|
|
+ @ApiOperation(value = "保存新密码")
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public ResponseEntity<HashMap<String,Object>> saveNewPassword(@RequestParam("mobile") String mobile,
|
|
|
|
+ @RequestParam("code") String code,
|
|
|
|
+ @RequestParam("newPassword") String newPassword) {
|
|
|
|
+ HashMap<String,Object> j = new HashMap<String,Object>();
|
|
|
|
+ // 判断当前页面输入的验证码是否与redis中存储的验证码匹配
|
|
|
|
+ String redisCode = (String) redisUtils.get(mobile + "resetPassword");
|
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(redisCode)) {
|
|
|
|
+ if (redisCode.equals( code )) {
|
|
|
|
+ // 进行密码修改操作
|
|
|
|
+ User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getMobile, mobile));
|
|
|
|
+ if (ObjectUtil.isNotEmpty( user )) {
|
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank( newPassword )) {
|
|
|
|
+ user.setPassword(SecurityUtils.encryptPassword ( newPassword ));
|
|
|
|
+ user.setUpPassword( "1" );
|
|
|
|
+ userService.updateById( user ); // 修改密码
|
|
|
|
+ redisUtils.delete(mobile + "resetPassword"); // 删除redis中的key
|
|
|
|
+ j.put("success",true);
|
|
|
|
+ j.put("message","密码修改成功!");
|
|
|
|
+ } else {
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","请输入有效密码!");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","当前手机号未注册!");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","验证码输入不正确!");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ j.put("success",false);
|
|
|
|
+ j.put("message","当前手机验证码已失效,请重新发送验证码!");
|
|
|
|
+ }
|
|
|
|
+ return ResponseEntity.ok(j);
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 获取当前用户是否已经修改过密码
|
|
|
|
+ *
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @ApiLog("获取当前用户是否已经修改过密码")
|
|
|
|
+ @GetMapping("isUpdatePassword")
|
|
|
|
+ @ApiOperation(value = "获取当前用户是否已经修改过密码")
|
|
|
|
+ public ResponseEntity<Boolean> isUpdatePassword() {
|
|
|
|
+ // 返回结果 true为以修改 false为未修改
|
|
|
|
+ UserDTO userDTO = UserUtils.getCurrentUserDTO();
|
|
|
|
+ Boolean updatePassword = userService.isUpdatePassword(userDTO.getId());
|
|
|
|
+ return ResponseEntity.ok(updatePassword);
|
|
|
|
+ }
|
|
}
|
|
}
|