master
parent
231925537f
commit
98c1fb0c0a
|
|
@ -83,7 +83,26 @@ public class DictDeserializer extends JsonDeserializer<Dict> {
|
||||||
|
|
||||||
Class<?> valueClazz = currentValue.getClass();
|
Class<?> valueClazz = currentValue.getClass();
|
||||||
try {
|
try {
|
||||||
Field field = valueClazz.getDeclaredField(currentName);
|
Field[] declaredFields = valueClazz.getDeclaredFields();
|
||||||
|
Field field = null;
|
||||||
|
for (Field field_ : declaredFields) {
|
||||||
|
if (field_.getName().equals(currentName)) {
|
||||||
|
field = field_;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (field == null) {
|
||||||
|
declaredFields = valueClazz.getSuperclass().getDeclaredFields();
|
||||||
|
for (Field field_ : declaredFields) {
|
||||||
|
if (field_.getName().equals(currentName)) {
|
||||||
|
field = field_;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (field == null) {
|
||||||
|
throw new NoSuchFieldException("字段不存在:" + currentName);
|
||||||
|
}
|
||||||
Class<?> clazz = field.getType();
|
Class<?> clazz = field.getType();
|
||||||
if (DictStr.class.isAssignableFrom(clazz)) {
|
if (DictStr.class.isAssignableFrom(clazz)) {
|
||||||
String val = p.getValueAsString();
|
String val = p.getValueAsString();
|
||||||
|
|
|
||||||
|
|
@ -19,5 +19,6 @@ public enum AuthWay implements DictStr {
|
||||||
;
|
;
|
||||||
|
|
||||||
private final String val;
|
private final String val;
|
||||||
|
|
||||||
private final String txt;
|
private final String txt;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.njzscloud.common.security.contant;
|
package com.njzscloud.common.security.contant;
|
||||||
|
|
||||||
|
import com.njzscloud.common.core.ienum.DictInt;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
|
@ -9,18 +10,21 @@ import lombok.RequiredArgsConstructor;
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public enum ClientCode {
|
public enum ClientCode implements DictInt {
|
||||||
pc(1),
|
PC(0, "电脑端"),
|
||||||
wx_app(2),
|
WX_MINI_APP(1, "微信小程序"),
|
||||||
app(4);
|
;
|
||||||
|
|
||||||
private final int permission;
|
private final Integer val;
|
||||||
|
|
||||||
|
private final String txt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查是否有登录权限
|
* 检查是否有登录权限
|
||||||
*/
|
*/
|
||||||
public boolean hasPermission(int permission) {
|
public boolean hasPermission(int clientCode) {
|
||||||
return !((this.permission & permission) == this.permission);
|
var mask = 1 << this.val;
|
||||||
|
return (clientCode & mask) == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.njzscloud.common.security.support;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import com.njzscloud.common.core.ex.ExceptionMsg;
|
import com.njzscloud.common.core.ex.ExceptionMsg;
|
||||||
|
import com.njzscloud.common.security.contant.ClientCode;
|
||||||
import com.njzscloud.common.security.contant.Constants;
|
import com.njzscloud.common.security.contant.Constants;
|
||||||
import com.njzscloud.common.security.ex.UserLoginException;
|
import com.njzscloud.common.security.ex.UserLoginException;
|
||||||
import org.springframework.security.authentication.AccountStatusException;
|
import org.springframework.security.authentication.AccountStatusException;
|
||||||
|
|
@ -112,9 +113,10 @@ public abstract class AbstractAuthenticationProvider implements AuthenticationPr
|
||||||
* @throws AccountStatusException 账号状态校验失败时抛出
|
* @throws AccountStatusException 账号状态校验失败时抛出
|
||||||
*/
|
*/
|
||||||
protected void lastCheck(LoginForm loginForm, UserDetail userDetail) throws UserLoginException {
|
protected void lastCheck(LoginForm loginForm, UserDetail userDetail) throws UserLoginException {
|
||||||
if (userDetail.getDisabled() == Boolean.TRUE) {
|
Assert.isFalse(userDetail.getDisabled(), () -> new UserLoginException(ExceptionMsg.CLI_ERR_MSG, "用户已被禁用"));
|
||||||
throw new UserLoginException(ExceptionMsg.CLI_ERR_MSG, "用户已被禁用");
|
ClientCode clientCode = loginForm.getClientCode();
|
||||||
}
|
Integer code = userDetail.getClientCode();
|
||||||
|
Assert.isTrue(clientCode.hasPermission(code), () -> new UserLoginException(ExceptionMsg.CLI_ERR_MSG, "当前用户无权使用:" + clientCode.getTxt()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,14 @@ import com.njzscloud.common.core.tuple.Tuple2;
|
||||||
import com.njzscloud.common.mvc.validator.Constrained;
|
import com.njzscloud.common.mvc.validator.Constrained;
|
||||||
import com.njzscloud.common.mvc.validator.ValidRule;
|
import com.njzscloud.common.mvc.validator.ValidRule;
|
||||||
import com.njzscloud.common.security.contant.AuthWay;
|
import com.njzscloud.common.security.contant.AuthWay;
|
||||||
|
import com.njzscloud.common.security.contant.ClientCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.security.Principal;
|
import java.security.Principal;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
|
@ -22,9 +24,13 @@ public abstract class LoginForm implements Constrained, Principal {
|
||||||
*/
|
*/
|
||||||
private final AuthWay authWay;
|
private final AuthWay authWay;
|
||||||
|
|
||||||
|
private ClientCode clientCode;
|
||||||
|
|
||||||
public Tuple2<Boolean, String> validate() {
|
public Tuple2<Boolean, String> validate() {
|
||||||
ValidRule[] rules = rules();
|
ValidRule[] rules = rules();
|
||||||
String message = Arrays.stream(rules)
|
List<ValidRule> ruleList = Arrays.stream(rules).collect(Collectors.toList());
|
||||||
|
ruleList.add(ValidRule.of(() -> clientCode != null, "未指定要使用的客户端"));
|
||||||
|
String message = ruleList.stream()
|
||||||
.filter(it -> !it.predicate.get())
|
.filter(it -> !it.predicate.get())
|
||||||
.map(it -> it.message)
|
.map(it -> it.message)
|
||||||
.collect(Collectors.joining("\n"));
|
.collect(Collectors.joining("\n"));
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ public class UserDetail implements CredentialsContainer, Principal {
|
||||||
*/
|
*/
|
||||||
private Long accountId;
|
private Long accountId;
|
||||||
private Long tenantId;
|
private Long tenantId;
|
||||||
|
private Integer clientCode;
|
||||||
private String tenantName;
|
private String tenantName;
|
||||||
/**
|
/**
|
||||||
* 登录方式
|
* 登录方式
|
||||||
|
|
|
||||||
|
|
@ -36,4 +36,9 @@ public class ResourceController {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/list_role_res")
|
||||||
|
public R<List<ResourceEntity>> listRoleRes(@RequestParam(value = "roleId") String roleId) {
|
||||||
|
return R.success(resourceService.listRoleRes(roleId));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,4 +15,6 @@ import java.util.List;
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface ResourceMapper extends BaseMapper<ResourceEntity> {
|
public interface ResourceMapper extends BaseMapper<ResourceEntity> {
|
||||||
List<String> occupied(@Param(Constants.WRAPPER) QueryWrapper<Object> ew);
|
List<String> occupied(@Param(Constants.WRAPPER) QueryWrapper<Object> ew);
|
||||||
|
|
||||||
|
List<ResourceEntity> listRoleRes(@Param("roleId") String roleId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,4 +41,8 @@ public class ResourceService extends ServiceImpl<ResourceMapper, ResourceEntity>
|
||||||
.in("a.data_id", dataIds));
|
.in("a.data_id", dataIds));
|
||||||
return !roles.isEmpty();
|
return !roles.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ResourceEntity> listRoleRes(String roleId) {
|
||||||
|
return baseMapper.listRoleRes(roleId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import com.njzscloud.common.core.utils.R;
|
||||||
import com.njzscloud.common.mp.support.PageParam;
|
import com.njzscloud.common.mp.support.PageParam;
|
||||||
import com.njzscloud.common.mp.support.PageResult;
|
import com.njzscloud.common.mp.support.PageResult;
|
||||||
import com.njzscloud.supervisory.sys.role.pojo.entity.RoleEntity;
|
import com.njzscloud.supervisory.sys.role.pojo.entity.RoleEntity;
|
||||||
|
import com.njzscloud.supervisory.sys.role.pojo.param.BindResParam;
|
||||||
import com.njzscloud.supervisory.sys.role.pojo.param.RoleAddParam;
|
import com.njzscloud.supervisory.sys.role.pojo.param.RoleAddParam;
|
||||||
import com.njzscloud.supervisory.sys.role.pojo.param.RoleModifyParam;
|
import com.njzscloud.supervisory.sys.role.pojo.param.RoleModifyParam;
|
||||||
import com.njzscloud.supervisory.sys.role.pojo.param.RoleQueryParam;
|
import com.njzscloud.supervisory.sys.role.pojo.param.RoleQueryParam;
|
||||||
|
|
@ -61,7 +62,7 @@ public class RoleController {
|
||||||
* 详情
|
* 详情
|
||||||
*/
|
*/
|
||||||
@GetMapping("/detail")
|
@GetMapping("/detail")
|
||||||
public R<RoleDetailResult> detail(@RequestParam Long id) {
|
public R<RoleDetailResult> detail(@RequestParam("id") Long id) {
|
||||||
return R.success(roleService.detail(id));
|
return R.success(roleService.detail(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,6 +74,23 @@ public class RoleController {
|
||||||
return R.success(roleService.list(Wrappers.lambdaQuery(RoleEntity.class).like(StrUtil.isNotBlank(roleName), RoleEntity::getRoleName, roleName)));
|
return R.success(roleService.list(Wrappers.lambdaQuery(RoleEntity.class).like(StrUtil.isNotBlank(roleName), RoleEntity::getRoleName, roleName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定资源
|
||||||
|
*/
|
||||||
|
@PostMapping("/bind_res")
|
||||||
|
public R<?> bindRole(@RequestBody BindResParam bindResParam) {
|
||||||
|
roleService.bindRes(bindResParam);
|
||||||
|
return R.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询用户拥有的角色
|
||||||
|
*/
|
||||||
|
@GetMapping("/list_user_role")
|
||||||
|
public R<List<RoleEntity>> listUserRole(@RequestParam(value = "userId") Long userId) {
|
||||||
|
return R.success(roleService.listUserRole(userId));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询
|
* 分页查询
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.njzscloud.supervisory.sys.role.mapper;
|
package com.njzscloud.supervisory.sys.role.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||||
|
|
@ -8,6 +9,8 @@ import com.njzscloud.supervisory.sys.role.pojo.entity.RoleEntity;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>sys_role</p>
|
* <p>sys_role</p>
|
||||||
* <p>角色表</p>
|
* <p>角色表</p>
|
||||||
|
|
@ -19,4 +22,8 @@ public interface RoleMapper extends BaseMapper<RoleEntity> {
|
||||||
* 分页查询
|
* 分页查询
|
||||||
*/
|
*/
|
||||||
IPage<RoleEntity> paging(IPage<RoleEntity> page, @Param(Constants.WRAPPER) Wrapper<RoleEntity> ew);
|
IPage<RoleEntity> paging(IPage<RoleEntity> page, @Param(Constants.WRAPPER) Wrapper<RoleEntity> ew);
|
||||||
|
|
||||||
|
List<RoleEntity> listUserRole(@Param("userId") Long userId);
|
||||||
|
|
||||||
|
Boolean candel(@Param("ew") QueryWrapper<Object> ew);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.njzscloud.supervisory.sys.role.pojo.param;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class BindResParam {
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 资源 Id 列表
|
||||||
|
*/
|
||||||
|
private Set<Long> res;
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.Set;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
|
@ -28,5 +28,5 @@ public class RoleAddParam {
|
||||||
*/
|
*/
|
||||||
private String memo;
|
private String memo;
|
||||||
|
|
||||||
private List<Long> resIds;
|
private Set<Long> resIds;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.Set;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
|
@ -29,6 +29,6 @@ public class RoleModifyParam {
|
||||||
*/
|
*/
|
||||||
private String memo;
|
private String memo;
|
||||||
|
|
||||||
private List<Long> resIds;
|
private Set<Long> resIds;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -89,7 +90,7 @@ public class RoleResService extends ServiceImpl<RoleResMapper, RoleResourceEntit
|
||||||
* 为角色绑定资源
|
* 为角色绑定资源
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void bindRes(Long roleId, List<Long> resIds) {
|
public void bindRoleRes(Long roleId, Set<Long> resIds) {
|
||||||
if (CollUtil.isEmpty(resIds)) return;
|
if (CollUtil.isEmpty(resIds)) return;
|
||||||
List<ResourceEntity> sysMenuEntities = resourceService.listByIds(resIds);
|
List<ResourceEntity> sysMenuEntities = resourceService.listByIds(resIds);
|
||||||
Assert.isTrue(sysMenuEntities.size() == resIds.size(), () -> Exceptions.exception("资源不存在"));
|
Assert.isTrue(sysMenuEntities.size() == resIds.size(), () -> Exceptions.exception("资源不存在"));
|
||||||
|
|
@ -110,4 +111,6 @@ public class RoleResService extends ServiceImpl<RoleResMapper, RoleResourceEntit
|
||||||
|
|
||||||
this.saveBatch(list);
|
this.saveBatch(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import com.njzscloud.common.mp.support.PageResult;
|
||||||
import com.njzscloud.supervisory.sys.role.mapper.RoleMapper;
|
import com.njzscloud.supervisory.sys.role.mapper.RoleMapper;
|
||||||
import com.njzscloud.supervisory.sys.role.pojo.entity.RoleEntity;
|
import com.njzscloud.supervisory.sys.role.pojo.entity.RoleEntity;
|
||||||
import com.njzscloud.supervisory.sys.role.pojo.entity.RoleResourceEntity;
|
import com.njzscloud.supervisory.sys.role.pojo.entity.RoleResourceEntity;
|
||||||
|
import com.njzscloud.supervisory.sys.role.pojo.param.BindResParam;
|
||||||
import com.njzscloud.supervisory.sys.role.pojo.param.RoleAddParam;
|
import com.njzscloud.supervisory.sys.role.pojo.param.RoleAddParam;
|
||||||
import com.njzscloud.supervisory.sys.role.pojo.param.RoleModifyParam;
|
import com.njzscloud.supervisory.sys.role.pojo.param.RoleModifyParam;
|
||||||
import com.njzscloud.supervisory.sys.role.pojo.param.RoleQueryParam;
|
import com.njzscloud.supervisory.sys.role.pojo.param.RoleQueryParam;
|
||||||
|
|
@ -23,6 +24,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.njzscloud.common.security.contant.Constants.ROLE_ADMIN;
|
import static com.njzscloud.common.security.contant.Constants.ROLE_ADMIN;
|
||||||
|
|
@ -53,8 +55,8 @@ public class RoleService extends ServiceImpl<RoleMapper, RoleEntity> implements
|
||||||
this.save(roleEntity);
|
this.save(roleEntity);
|
||||||
|
|
||||||
Long roleEntityId = roleEntity.getId();
|
Long roleEntityId = roleEntity.getId();
|
||||||
List<Long> resIds = roleAddParam.getResIds();
|
Set<Long> resIds = roleAddParam.getResIds();
|
||||||
roleResService.bindRes(roleEntityId, resIds);
|
roleResService.bindRoleRes(roleEntityId, resIds);
|
||||||
return roleEntityId;
|
return roleEntityId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,8 +70,8 @@ public class RoleService extends ServiceImpl<RoleMapper, RoleEntity> implements
|
||||||
Assert.isTrue(exists, () -> Exceptions.clierr("角色不存在"));
|
Assert.isTrue(exists, () -> Exceptions.clierr("角色不存在"));
|
||||||
RoleEntity roleEntity = BeanUtil.copyProperties(roleModifyParam, RoleEntity.class);
|
RoleEntity roleEntity = BeanUtil.copyProperties(roleModifyParam, RoleEntity.class);
|
||||||
this.updateById(roleEntity);
|
this.updateById(roleEntity);
|
||||||
List<Long> resIds = roleModifyParam.getResIds();
|
Set<Long> resIds = roleModifyParam.getResIds();
|
||||||
roleResService.bindRes(roleId, resIds);
|
roleResService.bindRoleRes(roleId, resIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -84,6 +86,8 @@ public class RoleService extends ServiceImpl<RoleMapper, RoleEntity> implements
|
||||||
return roleCode.equals(ROLE_ADMIN);
|
return roleCode.equals(ROLE_ADMIN);
|
||||||
}
|
}
|
||||||
), () -> Exceptions.exception("管理员角色不允许删除"));
|
), () -> Exceptions.exception("管理员角色不允许删除"));
|
||||||
|
Boolean candel = baseMapper.candel(Wrappers.query().in("a.id", ids));
|
||||||
|
Assert.isTrue(candel, () -> Exceptions.exception("角色已在使用不能删除"));
|
||||||
this.removeBatchByIds(ids);
|
this.removeBatchByIds(ids);
|
||||||
roleResService.remove(Wrappers.<RoleResourceEntity>lambdaQuery().in(RoleResourceEntity::getRoleId, ids));
|
roleResService.remove(Wrappers.<RoleResourceEntity>lambdaQuery().in(RoleResourceEntity::getRoleId, ids));
|
||||||
}
|
}
|
||||||
|
|
@ -110,4 +114,17 @@ public class RoleService extends ServiceImpl<RoleMapper, RoleEntity> implements
|
||||||
.like(StrUtil.isNotBlank(roleName), RoleEntity::getRoleName, roleName);
|
.like(StrUtil.isNotBlank(roleName), RoleEntity::getRoleName, roleName);
|
||||||
return PageResult.of(baseMapper.paging(page, ew).convert(it -> BeanUtil.copyProperties(it, RoleDetailResult.class)));
|
return PageResult.of(baseMapper.paging(page, ew).convert(it -> BeanUtil.copyProperties(it, RoleDetailResult.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<RoleEntity> listUserRole(Long userId) {
|
||||||
|
return baseMapper.listUserRole(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bindRes(BindResParam bindResParam) {
|
||||||
|
Long id = bindResParam.getId();
|
||||||
|
RoleEntity userEntity = this.getById(id);
|
||||||
|
Assert.notNull(userEntity, () -> Exceptions.clierr("角色不存在"));
|
||||||
|
Set<Long> res = bindResParam.getRes();
|
||||||
|
Assert.notEmpty(res, () -> Exceptions.clierr("未指定资源"));
|
||||||
|
roleResService.bindRoleRes(id, res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,33 @@ public class UserController {
|
||||||
return R.success(userService.detail(id));
|
return R.success(userService.detail(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 禁用
|
||||||
|
*/
|
||||||
|
@GetMapping("/disable")
|
||||||
|
public R<?> detail(@RequestParam("id") Long id, @RequestParam("disable") Boolean disable) {
|
||||||
|
userService.disable(id, disable);
|
||||||
|
return R.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定角色
|
||||||
|
*/
|
||||||
|
@PostMapping("/bind_role")
|
||||||
|
public R<?> bindRole(@RequestBody BindRoleParam bindRoleParam) {
|
||||||
|
userService.bindRole(bindRoleParam);
|
||||||
|
return R.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 授权客户端
|
||||||
|
*/
|
||||||
|
@GetMapping("/bind_client")
|
||||||
|
public R<?> bindClient(@RequestParam("id") Long id, @RequestParam("clientCode") Integer clientCode) {
|
||||||
|
userService.bindClient(id, clientCode);
|
||||||
|
return R.success();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询
|
* 分页查询
|
||||||
*/
|
*/
|
||||||
|
|
@ -87,4 +114,13 @@ public class UserController {
|
||||||
userService.modifyPasswd(modifyPasswdParam);
|
userService.modifyPasswd(modifyPasswdParam);
|
||||||
return R.success();
|
return R.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置密码
|
||||||
|
*/
|
||||||
|
@GetMapping("/reset_passwd")
|
||||||
|
public R<?> resetPasswd(@RequestParam("id") Long id) {
|
||||||
|
userService.resetPasswd(id);
|
||||||
|
return R.success(true, "重置成功,新密码:8个8");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,6 @@ public class UserAccountEntity {
|
||||||
*/
|
*/
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
/**
|
|
||||||
* 邮箱
|
|
||||||
*/
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手机号
|
* 手机号
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package com.njzscloud.supervisory.sys.user.pojo.entity;
|
package com.njzscloud.supervisory.sys.user.pojo.entity;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
import com.njzscloud.supervisory.sys.user.contant.Gender;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
@ -25,11 +24,6 @@ public class UserEntity {
|
||||||
@TableId(type = IdType.ASSIGN_ID)
|
@TableId(type = IdType.ASSIGN_ID)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
|
||||||
* 租户 Id
|
|
||||||
*/
|
|
||||||
private Long tenantId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 昵称
|
* 昵称
|
||||||
*/
|
*/
|
||||||
|
|
@ -40,16 +34,6 @@ public class UserEntity {
|
||||||
*/
|
*/
|
||||||
private String avatar;
|
private String avatar;
|
||||||
|
|
||||||
/**
|
|
||||||
* 性别; 字典代码:gender
|
|
||||||
*/
|
|
||||||
private Gender gender;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 邮箱
|
|
||||||
*/
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手机号
|
* 手机号
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.njzscloud.supervisory.sys.user.pojo.param;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class BindRoleParam {
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 角色 Id 列表
|
||||||
|
*/
|
||||||
|
private Set<Long> roles;
|
||||||
|
}
|
||||||
|
|
@ -18,10 +18,6 @@ public class UserAccountDetailResult {
|
||||||
* 用户名
|
* 用户名
|
||||||
*/
|
*/
|
||||||
private String username;
|
private String username;
|
||||||
/**
|
|
||||||
* 邮箱
|
|
||||||
*/
|
|
||||||
private String email;
|
|
||||||
/**
|
/**
|
||||||
* 手机号
|
* 手机号
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package com.njzscloud.supervisory.sys.user.pojo.result;
|
package com.njzscloud.supervisory.sys.user.pojo.result;
|
||||||
|
|
||||||
import com.njzscloud.supervisory.sys.role.pojo.result.RoleDetailResult;
|
import com.njzscloud.supervisory.sys.role.pojo.result.RoleDetailResult;
|
||||||
import com.njzscloud.supervisory.sys.user.contant.Gender;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
@ -19,11 +18,6 @@ public class UserDetailResult {
|
||||||
*/
|
*/
|
||||||
private String nickname;
|
private String nickname;
|
||||||
|
|
||||||
/**
|
|
||||||
* 性别; 字典代码:gender
|
|
||||||
*/
|
|
||||||
private Gender gender;
|
|
||||||
|
|
||||||
private String avatar;
|
private String avatar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -34,7 +28,6 @@ public class UserDetailResult {
|
||||||
* 手机号
|
* 手机号
|
||||||
*/
|
*/
|
||||||
private String phone;
|
private String phone;
|
||||||
private Long tenantId;
|
|
||||||
/**
|
/**
|
||||||
* 账号信息
|
* 账号信息
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ public class UserAccountService extends ServiceImpl<UserAccountMapper, UserAccou
|
||||||
|
|
||||||
List<UserAccountEntity> oldSysUserList = this.list(Wrappers.<UserAccountEntity>lambdaQuery()
|
List<UserAccountEntity> oldSysUserList = this.list(Wrappers.<UserAccountEntity>lambdaQuery()
|
||||||
.eq(StrUtil.isNotBlank(username), UserAccountEntity::getUsername, username)
|
.eq(StrUtil.isNotBlank(username), UserAccountEntity::getUsername, username)
|
||||||
.or().eq(StrUtil.isNotBlank(email), UserAccountEntity::getEmail, email)
|
|
||||||
.or().eq(StrUtil.isNotBlank(phone), UserAccountEntity::getPhone, phone)
|
.or().eq(StrUtil.isNotBlank(phone), UserAccountEntity::getPhone, phone)
|
||||||
.or(StrUtil.isNotBlank(wechatOpenid), it -> it
|
.or(StrUtil.isNotBlank(wechatOpenid), it -> it
|
||||||
.eq(UserAccountEntity::getWechatOpenid, wechatOpenid)
|
.eq(UserAccountEntity::getWechatOpenid, wechatOpenid)
|
||||||
|
|
@ -51,10 +50,6 @@ public class UserAccountService extends ServiceImpl<UserAccountMapper, UserAccou
|
||||||
Assert.notBlank(secret, () -> Exceptions.clierr("密码不能为空"));
|
Assert.notBlank(secret, () -> Exceptions.clierr("密码不能为空"));
|
||||||
Assert.isTrue(oldSysUserList.stream().noneMatch(it -> username.equals(it.getUsername())), () -> Exceptions.exception("用户名【{}】已被使用", username));
|
Assert.isTrue(oldSysUserList.stream().noneMatch(it -> username.equals(it.getUsername())), () -> Exceptions.exception("用户名【{}】已被使用", username));
|
||||||
}
|
}
|
||||||
if (StrUtil.isNotBlank(email)) {
|
|
||||||
Assert.notBlank(secret, () -> Exceptions.clierr("密码不能为空"));
|
|
||||||
Assert.isTrue(oldSysUserList.stream().noneMatch(it -> email.equals(it.getEmail())), () -> Exceptions.exception("邮箱【{}】已被使用", email));
|
|
||||||
}
|
|
||||||
if (StrUtil.isNotBlank(phone)) {
|
if (StrUtil.isNotBlank(phone)) {
|
||||||
Assert.notBlank(secret, () -> Exceptions.clierr("密码不能为空"));
|
Assert.notBlank(secret, () -> Exceptions.clierr("密码不能为空"));
|
||||||
Assert.isTrue(oldSysUserList.stream().noneMatch(it -> phone.equals(it.getPhone())), () -> Exceptions.exception("手机号【{}】已被使用", phone));
|
Assert.isTrue(oldSysUserList.stream().noneMatch(it -> phone.equals(it.getPhone())), () -> Exceptions.exception("手机号【{}】已被使用", phone));
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import com.njzscloud.common.core.ex.Exceptions;
|
||||||
import com.njzscloud.common.mp.support.PageParam;
|
import com.njzscloud.common.mp.support.PageParam;
|
||||||
import com.njzscloud.common.mp.support.PageResult;
|
import com.njzscloud.common.mp.support.PageResult;
|
||||||
import com.njzscloud.common.security.support.UserDetail;
|
import com.njzscloud.common.security.support.UserDetail;
|
||||||
|
import com.njzscloud.common.security.util.EncryptUtil;
|
||||||
import com.njzscloud.common.security.util.SecurityUtil;
|
import com.njzscloud.common.security.util.SecurityUtil;
|
||||||
import com.njzscloud.supervisory.sys.role.pojo.result.RoleDetailResult;
|
import com.njzscloud.supervisory.sys.role.pojo.result.RoleDetailResult;
|
||||||
import com.njzscloud.supervisory.sys.user.contant.Gender;
|
import com.njzscloud.supervisory.sys.user.contant.Gender;
|
||||||
|
|
@ -26,6 +27,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -76,6 +78,9 @@ public class UserService extends ServiceImpl<UserMapper, UserEntity> implements
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void del(List<Long> ids) {
|
public void del(List<Long> ids) {
|
||||||
|
if (ids.contains(1L)) {
|
||||||
|
throw Exceptions.clierr("不能删除管理员");
|
||||||
|
}
|
||||||
this.removeByIds(ids);
|
this.removeByIds(ids);
|
||||||
userAccountService.delByUserIds(ids);
|
userAccountService.delByUserIds(ids);
|
||||||
userRoleService.delByUserIds(ids);
|
userRoleService.delByUserIds(ids);
|
||||||
|
|
@ -93,7 +98,6 @@ public class UserService extends ServiceImpl<UserMapper, UserEntity> implements
|
||||||
UserAccountDetailResult userAccountDetailResult = BeanUtil.copyProperties(userAccountEntity, UserAccountDetailResult.class);
|
UserAccountDetailResult userAccountDetailResult = BeanUtil.copyProperties(userAccountEntity, UserAccountDetailResult.class);
|
||||||
List<RoleDetailResult> roleDetailResults = userRoleService.listRole(id);
|
List<RoleDetailResult> roleDetailResults = userRoleService.listRole(id);
|
||||||
return userDetailResult
|
return userDetailResult
|
||||||
.setTenantId(userEntity.getTenantId())
|
|
||||||
.setAccount(userAccountDetailResult)
|
.setAccount(userAccountDetailResult)
|
||||||
.setRoles(roleDetailResults);
|
.setRoles(roleDetailResults);
|
||||||
}
|
}
|
||||||
|
|
@ -144,4 +148,29 @@ public class UserService extends ServiceImpl<UserMapper, UserEntity> implements
|
||||||
Long userId = SecurityUtil.currentUserId();
|
Long userId = SecurityUtil.currentUserId();
|
||||||
userAccountService.modifyPasswd(userId, modifyPasswdParam);
|
userAccountService.modifyPasswd(userId, modifyPasswdParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void disable(Long id, Boolean disable) {
|
||||||
|
userAccountService.update(Wrappers.<UserAccountEntity>lambdaUpdate().eq(UserAccountEntity::getUserId, id)
|
||||||
|
.set(UserAccountEntity::getDisabled, disable));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bindRole(BindRoleParam bindRoleParam) {
|
||||||
|
Long id = bindRoleParam.getId();
|
||||||
|
UserEntity userEntity = this.getById(id);
|
||||||
|
Assert.notNull(userEntity, () -> Exceptions.clierr("用户不存在"));
|
||||||
|
Set<Long> roles = bindRoleParam.getRoles();
|
||||||
|
Assert.notEmpty(roles, () -> Exceptions.clierr("未指定角色"));
|
||||||
|
userRoleService.bindUserRole(id, roles);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bindClient(Long id, Integer clientCode) {
|
||||||
|
userAccountService.update(Wrappers.<UserAccountEntity>lambdaUpdate().eq(UserAccountEntity::getUserId, id)
|
||||||
|
.set(UserAccountEntity::getClientCode, clientCode));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetPasswd(Long id) {
|
||||||
|
userAccountService.update(Wrappers.<UserAccountEntity>lambdaUpdate().eq(UserAccountEntity::getUserId, id)
|
||||||
|
.set(UserAccountEntity::getSecret, EncryptUtil.encrypt("88888888")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
<result property="secret" column="secret"/>
|
<result property="secret" column="secret"/>
|
||||||
<result property="nickname" column="nickname"/>
|
<result property="nickname" column="nickname"/>
|
||||||
<result property="disabled" column="disabled"/>
|
<result property="disabled" column="disabled"/>
|
||||||
|
<result property="clientCode" column="client_code"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<select id="selectUser" resultMap="selectUserMap">
|
<select id="selectUser" resultMap="selectUserMap">
|
||||||
SELECT a.id account_id,
|
SELECT a.id account_id,
|
||||||
|
|
@ -17,7 +18,8 @@
|
||||||
b.nickname,
|
b.nickname,
|
||||||
b.avatar,
|
b.avatar,
|
||||||
b.phone,
|
b.phone,
|
||||||
a.disabled
|
a.disabled,
|
||||||
|
a.client_code
|
||||||
FROM sys_user_account a
|
FROM sys_user_account a
|
||||||
INNER JOIN sys_user b ON a.user_id = b.id AND b.deleted = 0
|
INNER JOIN sys_user b ON a.user_id = b.id AND b.deleted = 0
|
||||||
<if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
|
<if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
|
||||||
|
|
|
||||||
|
|
@ -11,4 +11,14 @@
|
||||||
${ew.customSqlSegment}
|
${ew.customSqlSegment}
|
||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="listRoleRes" resultType="com.njzscloud.supervisory.sys.resource.pojo.entity.ResourceEntity">
|
||||||
|
SELECT a.id,
|
||||||
|
a.sn,
|
||||||
|
a.table_name,
|
||||||
|
a.data_id,
|
||||||
|
a.memo
|
||||||
|
FROM sys_resource a
|
||||||
|
INNER JOIN sys_role_resource b ON b.res_id = a.id
|
||||||
|
WHERE b.role_id = ${roleId}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,23 @@
|
||||||
SELECT id,
|
SELECT id,
|
||||||
role_code,
|
role_code,
|
||||||
role_name,
|
role_name,
|
||||||
memo,
|
memo
|
||||||
creator_id,
|
|
||||||
modifier_id,
|
|
||||||
create_time,
|
|
||||||
modify_time,
|
|
||||||
deleted
|
|
||||||
FROM sys_role
|
FROM sys_role
|
||||||
<if test="ew != null and ew.customSqlSegment != null and ew.customSqlSegment !=''">
|
<if test="ew != null and ew.customSqlSegment != null and ew.customSqlSegment !=''">
|
||||||
${ew.customSqlSegment}
|
${ew.customSqlSegment}
|
||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="listUserRole" resultType="com.njzscloud.supervisory.sys.role.pojo.entity.RoleEntity">
|
||||||
|
SELECT a.role_code, a.id, a.role_name, a.memo
|
||||||
|
FROM sys_role a
|
||||||
|
INNER JOIN sys_user_role b ON b.role_id = a.id AND b.user_id = #{userId}
|
||||||
|
</select>
|
||||||
|
<select id="candel" resultType="java.lang.Boolean">
|
||||||
|
SELECT COUNT(*) = 0
|
||||||
|
FROM sys_role a
|
||||||
|
INNER JOIN sys_user_role b ON b.role_id = a.id
|
||||||
|
<if test="ew != null and ew.customSqlSegment != null and ew.customSqlSegment !=''">
|
||||||
|
${ew.customSqlSegment}
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
b.role_name,
|
b.role_name,
|
||||||
b.memo
|
b.memo
|
||||||
FROM sys_user_role a
|
FROM sys_user_role a
|
||||||
INNER JOIN sys_role b ON b.id = a.role_id AND b.deleted = 0
|
INNER JOIN sys_role b ON b.id = a.role_id
|
||||||
<if test="ew != null and ew.customSqlSegment != null and ew.customSqlSegment !=''">
|
<if test="ew != null and ew.customSqlSegment != null and ew.customSqlSegment !=''">
|
||||||
${ew.customSqlSegment}
|
${ew.customSqlSegment}
|
||||||
</if>
|
</if>
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,10 @@
|
||||||
<select id="paging" resultMap="pagingResultMap">
|
<select id="paging" resultMap="pagingResultMap">
|
||||||
SELECT a.id,
|
SELECT a.id,
|
||||||
a.nickname,
|
a.nickname,
|
||||||
a.gender,
|
|
||||||
a.avatar,
|
a.avatar,
|
||||||
a.email,
|
|
||||||
a.phone,
|
a.phone,
|
||||||
b.id account_id,
|
b.id account_id,
|
||||||
b.username,
|
b.username,
|
||||||
b.email,
|
|
||||||
b.phone account_phone,
|
b.phone account_phone,
|
||||||
b.secret,
|
b.secret,
|
||||||
b.wechat_openid,
|
b.wechat_openid,
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue