|
@@ -4,10 +4,12 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.google.gson.reflect.TypeToken;
|
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.boot.core.enums.Platform;
|
|
|
import com.qmth.sop.business.bean.auth.AuthBean;
|
|
|
import com.qmth.sop.business.bean.auth.ExpireTimeBean;
|
|
|
+import com.qmth.sop.business.bean.dto.RoleDto;
|
|
|
import com.qmth.sop.business.bean.dto.UserDto;
|
|
|
import com.qmth.sop.business.bean.dto.VerifyCodeCheckDto;
|
|
|
import com.qmth.sop.business.bean.result.LoginResult;
|
|
@@ -25,10 +27,7 @@ import com.qmth.sop.common.contant.SystemConstant;
|
|
|
import com.qmth.sop.common.enums.AppSourceEnum;
|
|
|
import com.qmth.sop.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.sop.common.enums.FieldUniqueEnum;
|
|
|
-import com.qmth.sop.common.util.IpUtil;
|
|
|
-import com.qmth.sop.common.util.ResultUtil;
|
|
|
-import com.qmth.sop.common.util.ServletUtil;
|
|
|
-import com.qmth.sop.common.util.SessionUtil;
|
|
|
+import com.qmth.sop.common.util.*;
|
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -213,10 +212,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
userDtoIPage.getRecords().forEach(m -> {
|
|
|
//角色
|
|
|
List<SysRole> roles = sysRoleService.listRolesByUserId(Long.valueOf(m.getId()));
|
|
|
- m.setRoles(roles);
|
|
|
+ if (!CollectionUtils.isEmpty(roles)) {
|
|
|
+ m.setRoles(GsonUtil.fromJson(GsonUtil.toJson(roles), new TypeToken<List<RoleDto>>() {
|
|
|
+ }.getType()));
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
- return this.baseMapper.query(iPage, userInfo, orgId, roleId, enable);
|
|
|
+ return userDtoIPage;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -231,33 +233,29 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
SysUserService sysUserService = SpringContextHolder.getBean(SysUserService.class);
|
|
|
try {
|
|
|
SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
-
|
|
|
- // 手机号检验
|
|
|
- if (Objects.nonNull(sysUser.getMobileNumber())) {
|
|
|
- SysUser checkMobileNumber = this.getOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getOrgId, sysUser.getOrgId()).eq(SysUser::getEnable, true).eq(SysUser::getMobileNumber, sysUser.getMobileNumber()));
|
|
|
- if (Objects.nonNull(checkMobileNumber) && checkMobileNumber.getId().longValue() != sysUser.getId().longValue()) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("用户手机号[" + sysUser.getMobileNumber() + "]在系统中已使用");
|
|
|
- }
|
|
|
- }
|
|
|
if (Objects.isNull(sysUser.getId())) {//新增用户
|
|
|
sysUser.insertInfo(requestUser.getId());
|
|
|
sysUser.setPasswordInfo(sysUser.getMobileNumber());
|
|
|
sysUserService.save(sysUser);
|
|
|
sysUserRoleService.addUserRolePrivilege(sysUser, sysUser.getRoleIds());
|
|
|
} else {//修改用户
|
|
|
+ sysUser.updatePasswordInfo(sysUser.getMobileNumber());
|
|
|
+ SysUser dbUser = this.getById(sysUser.getId());
|
|
|
+ Optional.ofNullable(dbUser).orElseThrow(() -> ExceptionResultEnum.USER_NO_EXISTS.exception());
|
|
|
+
|
|
|
List<SysUserRole> sysUserRoleList = commonCacheService.userRolePrivilegeCache(sysUser.getId());
|
|
|
List<Long> userRolesList = Arrays.asList(sysUser.getRoleIds());
|
|
|
Set<Long> dbUserRolesList = sysUserRoleList.stream().map(SysUserRole::getRoleId).collect(Collectors.toSet());
|
|
|
int count = (int) dbUserRolesList.stream().filter(s -> !userRolesList.contains(s)).count();
|
|
|
- SysUser dbUser = sysUserService.getById(sysUser.getId());
|
|
|
sysUserService.update(new UpdateWrapper<SysUser>().lambda()
|
|
|
.eq(SysUser::getId, sysUser.getId())
|
|
|
.set(SysUser::getLoginName, sysUser.getLoginName())
|
|
|
.set(SysUser::getRealName, sysUser.getRealName())
|
|
|
.set(SysUser::getCode, sysUser.getCode())
|
|
|
.set(SysUser::getMobileNumber, sysUser.getMobileNumber())
|
|
|
+ .set(SysUser::getPassword, sysUser.getPassword())
|
|
|
+ .set(SysUser::getGender, sysUser.getGender())
|
|
|
.set(SysUser::getOrgId, sysUser.getOrgId())
|
|
|
- .set(SysUser::getEnable, dbUser.getEnable())
|
|
|
.set(SysUser::getUpdateId, requestUser.getId())
|
|
|
.set(SysUser::getUpdateTime, System.currentTimeMillis())
|
|
|
);
|
|
@@ -304,6 +302,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public Boolean enable(SysUser sysUser) throws NoSuchAlgorithmException {
|
|
|
+ Optional.ofNullable(sysUser).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("参数不能为空"));
|
|
|
+ Optional.ofNullable(sysUser.getId()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("id不能为空"));
|
|
|
+ Optional.ofNullable(sysUser.getEnable()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("启用/禁用不能为空"));
|
|
|
+
|
|
|
+ SysUser sysUserDb = this.getById(sysUser.getId());
|
|
|
+ Optional.ofNullable(sysUserDb).orElseThrow(() -> ExceptionResultEnum.USER_NO_EXISTS.exception());
|
|
|
+
|
|
|
this.update(new UpdateWrapper<SysUser>().lambda().set(SysUser::getEnable, sysUser.getEnable()).eq(SysUser::getId, sysUser.getId()));
|
|
|
commonCacheService.updateUserCache(sysUser.getId());
|
|
|
//如果状态为禁用,需要踢下线重新登录
|