|
@@ -5,7 +5,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.gis.admin.entity.dto.*;
|
|
|
+import com.gis.admin.service.SysRoleService;
|
|
|
import com.gis.common.base.exception.BaseRuntimeException;
|
|
|
+import com.gis.common.base.service.impl.IBaseService;
|
|
|
+import com.gis.common.constant.ErrorEnum;
|
|
|
import com.gis.common.util.*;
|
|
|
import com.gis.admin.entity.po.SysUserEntity;
|
|
|
import com.gis.admin.mapper.SysUserMapper;
|
|
@@ -16,7 +19,6 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
@@ -33,11 +35,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity
|
|
|
private SysUserMapper entityMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- HttpServletRequest request;
|
|
|
+ IBaseService iBaseService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ SysRoleService roleService;
|
|
|
|
|
|
- /**重置密码redis key*/
|
|
|
- final static String RESET_PASSWORD_KEY = "reset:password:";
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -58,22 +60,35 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity
|
|
|
BeanUtils.copyProperties(param, entity);
|
|
|
entity.setIsAdmin(0);
|
|
|
entity.setPassword(PasswordUtils.encrypt(param.getUserName(), "123456", PasswordUtils.getStaticSalt()));
|
|
|
+ entity.setCreatorId(iBaseService.getUserId());
|
|
|
+
|
|
|
this.save(entity);
|
|
|
- } else {
|
|
|
- entity = this.getById(id);
|
|
|
- if (entity == null) {
|
|
|
- log.error("用户不存在: {}", id);
|
|
|
- return Result.failure("用户不存在");
|
|
|
- }
|
|
|
|
|
|
+ // 保存角色
|
|
|
+ roleService.saveUserRole(entity.getId(), param.getRoleId());
|
|
|
+
|
|
|
+ } else {
|
|
|
+ entity = this.mpFindById(id);
|
|
|
+ Long dbRoleId = entity.getRoleId();
|
|
|
+ BaseRuntimeException.isNull(entity, ErrorEnum.FAILURE_SYS_2001);
|
|
|
BeanUtils.copyProperties(param, entity);
|
|
|
this.updateById(entity);
|
|
|
+ Long roleId = param.getRoleId();
|
|
|
+ if (!roleId.equals(dbRoleId)){
|
|
|
+ // 更新用户角色中间表
|
|
|
+ roleService.updateUserRole(id, roleId);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public Result removes(String ids) {
|
|
|
List<String> idList = Arrays.asList(ids);
|
|
@@ -90,31 +105,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
-// @Override
|
|
|
-// public Result<SysUserEntity> search(PageDateDto param) {
|
|
|
-// BaseUtil.startPage(param);
|
|
|
-//
|
|
|
-// IPage<SysUserEntity> page = new Page<>(param.getPageNum() , param.getPageSize());
|
|
|
-// LambdaQueryWrapper<SysUserEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
-//
|
|
|
-//
|
|
|
-// String startTime = param.getStartTime();
|
|
|
-// String endTime = param.getEndTime();
|
|
|
-// if (StringUtils.isNotBlank(startTime) || StringUtils.isNotBlank(endTime)){
|
|
|
-// wrapper.between(SysUserEntity::getCreateTime, startTime, endTime);
|
|
|
-// }
|
|
|
-//
|
|
|
-// String searchKey = param.getSearchKey();
|
|
|
-// if (StringUtils.isNotBlank(searchKey)){
|
|
|
-// wrapper.like(SysUserEntity::getUserName, searchKey);
|
|
|
-// }
|
|
|
-//
|
|
|
-// wrapper.orderByDesc(SysUserEntity::getCreateTime);
|
|
|
-//
|
|
|
-// IPage<SysUserEntity> result = this.page(page, wrapper);
|
|
|
-//
|
|
|
-// return Result.success(result);
|
|
|
-// }
|
|
|
|
|
|
@Override
|
|
|
public Result<SysUserEntity> search(UserPageDateDto param) {
|
|
@@ -167,7 +157,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity
|
|
|
String oldPassword = Base64Converter.decodePassword(param.getOldPassword());
|
|
|
param.setNewPassword(newPassword);
|
|
|
param.setOldPassword(oldPassword);
|
|
|
- SysUserEntity user = this.findByUserName(JwtUtil.getUsername(request.getHeader("token")));
|
|
|
+ SysUserEntity user = this.findByUserName(iBaseService.getUserName());
|
|
|
updatePwd(param, user, true);
|
|
|
return Result.success();
|
|
|
}
|
|
@@ -281,6 +271,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity
|
|
|
return Result.success((Object) code);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public SysUserEntity mpFindById(Long id) {
|
|
|
+ return entityMapper.detailMapper(id);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|