|
@@ -1,13 +1,17 @@
|
|
|
package com.gis.admin.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
+import com.gis.admin.entity.dto.ResetPasswordDto;
|
|
|
import com.gis.admin.entity.po.SysRoleEntity;
|
|
|
import com.gis.common.base.aop.WebControllerLog;
|
|
|
import com.gis.common.base.entity.dto.PageDto;
|
|
|
+import com.gis.common.base.entity.dto.UserPageDateDto;
|
|
|
import com.gis.common.base.entity.po.LogEntity;
|
|
|
import com.gis.common.base.exception.BaseRuntimeException;
|
|
|
import com.gis.common.base.mapper.IBaseMapper;
|
|
|
import com.gis.common.base.service.LogService;
|
|
|
import com.gis.common.base.service.impl.IBaseServiceImpl;
|
|
|
+import com.gis.common.constant.MsgCode;
|
|
|
import com.gis.common.util.JwtUtil;
|
|
|
import com.gis.common.util.PasswordUtils;
|
|
|
import com.gis.common.util.Result;
|
|
@@ -20,11 +24,13 @@ import com.gis.admin.service.SysRoleService;
|
|
|
import com.gis.admin.service.SysUserService;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.RandomUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import tk.mybatis.mapper.entity.Condition;
|
|
|
|
|
|
+import javax.validation.constraints.NotBlank;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
@@ -46,6 +52,9 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
@Autowired
|
|
|
LogService logService;
|
|
|
|
|
|
+ /**重置密码redis key*/
|
|
|
+ final static String RESET_PASSWORD_KEY = "reset_password_";
|
|
|
+
|
|
|
@Override
|
|
|
public IBaseMapper<SysUserEntity, Long> getBaseMapper() {
|
|
|
return this.entityMapper;
|
|
@@ -63,7 +72,7 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
if (id == null) {
|
|
|
entity = this.findByUserName(param.getUserName());
|
|
|
if (entity != null) {
|
|
|
- return Result.failure("身份证号已存在");
|
|
|
+ return Result.failure("身份码已存在");
|
|
|
}
|
|
|
entity = new SysUserEntity();
|
|
|
BeanUtils.copyProperties(param, entity);
|
|
@@ -124,9 +133,9 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result<SysUserEntity> search(PageDto param) {
|
|
|
+ public Result<SysUserEntity> search(UserPageDateDto param) {
|
|
|
startPage(param);
|
|
|
- PageInfo<SysUserEntity> page = new PageInfo<>(entityMapper.findListMapper());
|
|
|
+ PageInfo<SysUserEntity> page = new PageInfo<>(entityMapper.search(param));
|
|
|
return Result.success(page);
|
|
|
}
|
|
|
|
|
@@ -149,18 +158,22 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
@Override
|
|
|
public Result updatePwd(PasswordDto param) {
|
|
|
SysUserEntity user = this.findByUserName(JwtUtil.getUsername(getToken()));
|
|
|
+ updatePwd(param, user);
|
|
|
+
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
|
|
|
+ private void updatePwd(PasswordDto param, SysUserEntity user){
|
|
|
// 验证原密码
|
|
|
Boolean isBoolean = PasswordUtils.decrypt(user.getPassword(), param.getOldPassword(), PasswordUtils.getStaticSalt());
|
|
|
if (!isBoolean) {
|
|
|
log.error("原始密码错误");
|
|
|
- return Result.failure("原始密码错误");
|
|
|
+ throw new BaseRuntimeException("原始密码错误");
|
|
|
}
|
|
|
|
|
|
user.setPassword(PasswordUtils.encrypt(user.getUserName(), param.getNewPassword(), PasswordUtils.getStaticSalt()));
|
|
|
user.setUpdateTime(LocalDateTime.now());
|
|
|
this.update(user);
|
|
|
- return Result.success();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -209,8 +222,8 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
|
|
|
SysUserEntity entity = this.findByUserName(param.getUserName());
|
|
|
if (entity != null) {
|
|
|
- log.error("该身份证号已注册: {}", param.getUserName());
|
|
|
- return Result.failure("该身份证号已注册");
|
|
|
+ log.error("该身份码已注册: {}", param.getUserName());
|
|
|
+ return Result.failure("该身份码已注册");
|
|
|
}
|
|
|
|
|
|
entity = new SysUserEntity();
|
|
@@ -246,5 +259,50 @@ public class SysUserServiceImpl extends IBaseServiceImpl<SysUserEntity, Long> im
|
|
|
return Result.success(user);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 不正确返回空
|
|
|
+ * 正确返回 code
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result retrievePassword(ResetPasswordDto param) {
|
|
|
+ String userName = param.getUserName();
|
|
|
+ SysUserEntity entity = entityMapper.findByUserName(param.getUserName());
|
|
|
+ if (entity == null) {
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!param.getRealName().equals(entity.getRealName())) {
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ String redisKey = RESET_PASSWORD_KEY + userName;
|
|
|
+ String code = RandomUtil.randomString(9);
|
|
|
+
|
|
|
+ // code 有效期5分钟
|
|
|
+ redisUtil.set(redisKey, code , 300);
|
|
|
+ return Result.success(code);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result updatePwdByWeb(PasswordDto param) {
|
|
|
+ String userName = param.getUserName();
|
|
|
+ SysUserEntity entity = entityMapper.findByUserName(userName);
|
|
|
+ if (entity == null) {
|
|
|
+ return Result.failure(MsgCode.e3001, "对象不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ String redisKey = RESET_PASSWORD_KEY + userName;
|
|
|
+ String redisCode = (String)redisUtil.get(redisKey);
|
|
|
+ if (!redisCode.equals(param.getCode())) {
|
|
|
+ return Result.failure(MsgCode.e3005, "验证码失效");
|
|
|
+ }
|
|
|
+
|
|
|
+ updatePwd(param, entity);
|
|
|
+
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|