新框架,系统管理,权限管理等
parent
fe3483f3bd
commit
d505666984
@ -0,0 +1,36 @@
|
||||
package com.glxp.api.admin.controller;
|
||||
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.glxp.api.admin.constant.Constant;
|
||||
import com.glxp.api.admin.entity.auth.AuthAdmin;
|
||||
import com.glxp.api.admin.service.auth.CustomerService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class BaseController {
|
||||
|
||||
@Resource
|
||||
CustomerService customerService;
|
||||
|
||||
/**
|
||||
* 页面跳转
|
||||
*/
|
||||
public String redirect(String url) {
|
||||
return StrUtil.format("redirect:{}", url);
|
||||
}
|
||||
|
||||
|
||||
public boolean isAdmin(Long userId) {
|
||||
return Constant.ADMIN_ID.equals(userId);
|
||||
}
|
||||
|
||||
|
||||
public AuthAdmin getUser() {
|
||||
return customerService.getUserBean();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package com.glxp.api.admin.controller.auth;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.glxp.api.admin.controller.BaseController;
|
||||
import com.glxp.api.admin.entity.auth.SysDictData;
|
||||
import com.glxp.api.admin.req.auth.SysDictDataRequest;
|
||||
import com.glxp.api.admin.service.auth.ISysDictDataService;
|
||||
import com.glxp.api.admin.service.auth.ISysDictTypeService;
|
||||
import com.glxp.api.common.res.BaseResponse;
|
||||
import com.glxp.api.common.util.ResultVOUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据字典信息
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/system/dict/data")
|
||||
public class SysDictDataController extends BaseController {
|
||||
|
||||
private final ISysDictDataService dictDataService;
|
||||
private final ISysDictTypeService dictTypeService;
|
||||
|
||||
/**
|
||||
* 查询字典数据列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public BaseResponse list(SysDictDataRequest sysDictDataRequest) {
|
||||
|
||||
return ResultVOUtils.success(dictDataService.selectDictDataList(sysDictDataRequest));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询字典数据详细
|
||||
*
|
||||
* @param dictCode 字典code
|
||||
*/
|
||||
@GetMapping(value = "/{dictCode}")
|
||||
public BaseResponse getInfo(@PathVariable Long dictCode) {
|
||||
return ResultVOUtils.success(dictDataService.selectDictDataById(dictCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典类型查询字典数据信息
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
*/
|
||||
@GetMapping(value = "/type/{dictType}")
|
||||
public BaseResponse dictType(@PathVariable String dictType) {
|
||||
List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
|
||||
if (ObjectUtil.isNull(data)) {
|
||||
data = new ArrayList<>();
|
||||
}
|
||||
return ResultVOUtils.success(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增字典类型
|
||||
*/
|
||||
@PostMapping
|
||||
public BaseResponse add(@Validated @RequestBody SysDictData dict) {
|
||||
dictDataService.insertDictData(dict);
|
||||
return ResultVOUtils.success("添加成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改保存字典类型
|
||||
*/
|
||||
@SaCheckPermission("system:dict:edit")
|
||||
@PutMapping
|
||||
public BaseResponse edit(@Validated @RequestBody SysDictData dict) {
|
||||
dictDataService.updateDictData(dict);
|
||||
return ResultVOUtils.success("修改成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除字典类型
|
||||
*
|
||||
* @param dictCodes 字典code串
|
||||
*/
|
||||
@SaCheckPermission("system:dict:remove")
|
||||
@DeleteMapping("/{dictCodes}")
|
||||
public BaseResponse remove(@PathVariable Long[] dictCodes) {
|
||||
dictDataService.deleteDictDataByIds(dictCodes);
|
||||
return ResultVOUtils.success("移除成功!");
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package com.glxp.api.admin.controller.auth;
|
||||
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.glxp.api.admin.constant.Constant;
|
||||
import com.glxp.api.admin.controller.BaseController;
|
||||
import com.glxp.api.admin.entity.auth.SysDictType;
|
||||
import com.glxp.api.admin.req.auth.SysDictTypeRequest;
|
||||
import com.glxp.api.admin.res.PageSimpleResponse;
|
||||
import com.glxp.api.admin.service.auth.ISysDictTypeService;
|
||||
import com.glxp.api.common.res.BaseResponse;
|
||||
import com.glxp.api.common.util.ResultVOUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据字典信息
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/system/dict/type")
|
||||
public class SysDictTypeController extends BaseController {
|
||||
@Resource
|
||||
ISysDictTypeService dictTypeService;
|
||||
|
||||
/**
|
||||
* 查询字典类型列表
|
||||
*/
|
||||
@SaCheckPermission("system:dict:list")
|
||||
@GetMapping("/list")
|
||||
public BaseResponse list(SysDictTypeRequest sysDictTypeRequest) {
|
||||
List<SysDictType> sysDictTypes = dictTypeService.selectDictTypeList(sysDictTypeRequest);
|
||||
PageInfo<SysDictType> pageInfo = new PageInfo<>(sysDictTypes);
|
||||
PageSimpleResponse<SysDictType> deptEntityPageSimpleResponse = new PageSimpleResponse<>();
|
||||
deptEntityPageSimpleResponse.setTotal(pageInfo.getTotal());
|
||||
deptEntityPageSimpleResponse.setList(sysDictTypes);
|
||||
return ResultVOUtils.success(deptEntityPageSimpleResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询字典类型详细
|
||||
*
|
||||
* @param dictId 字典ID
|
||||
*/
|
||||
@GetMapping(value = "/{dictId}")
|
||||
public BaseResponse getInfo(@PathVariable Long dictId) {
|
||||
return ResultVOUtils.success(dictTypeService.selectDictTypeById(dictId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增字典类型
|
||||
*/
|
||||
@PostMapping
|
||||
public BaseResponse add(@Validated @RequestBody SysDictType dict) {
|
||||
if (Constant.NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict))) {
|
||||
return ResultVOUtils.error(500, "新增字典'" + dict.getDictName() + "'失败,字典类型已存在");
|
||||
}
|
||||
dictTypeService.insertDictType(dict);
|
||||
return ResultVOUtils.success("新增成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改字典类型
|
||||
*/
|
||||
@PutMapping
|
||||
public BaseResponse edit(@Validated @RequestBody SysDictType dict) {
|
||||
// if (Constant.NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict))) {
|
||||
// return R.fail("修改字典'" + dict.getDictName() + "'失败,字典类型已存在");
|
||||
// }
|
||||
dictTypeService.updateDictType(dict);
|
||||
return ResultVOUtils.success("修改成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除字典类型
|
||||
*
|
||||
* @param dictIds 字典ID串
|
||||
*/
|
||||
@SaCheckPermission("system:dict:remove")
|
||||
@DeleteMapping("/{dictIds}")
|
||||
public BaseResponse remove(@PathVariable Long[] dictIds) {
|
||||
dictTypeService.deleteDictTypeByIds(dictIds);
|
||||
return ResultVOUtils.success("删除成功!");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取字典选择框列表
|
||||
*/
|
||||
@GetMapping("/optionselect")
|
||||
public BaseResponse optionselect() {
|
||||
List<SysDictType> dictTypes = dictTypeService.selectDictTypeAll();
|
||||
return ResultVOUtils.success(dictTypes);
|
||||
}
|
||||
}
|
@ -0,0 +1,219 @@
|
||||
package com.glxp.api.admin.controller.auth;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.glxp.api.admin.constant.Constant;
|
||||
import com.glxp.api.admin.controller.BaseController;
|
||||
import com.glxp.api.admin.entity.auth.AuthAdmin;
|
||||
import com.glxp.api.admin.entity.auth.SysRole;
|
||||
import com.glxp.api.admin.entity.auth.SysUserRole;
|
||||
import com.glxp.api.admin.req.auth.AuthAdminQueryRequest;
|
||||
import com.glxp.api.admin.req.auth.SysRoleRequest;
|
||||
import com.glxp.api.admin.res.PageSimpleResponse;
|
||||
import com.glxp.api.admin.service.auth.AuthAdminService;
|
||||
import com.glxp.api.admin.service.auth.ISysRoleService;
|
||||
import com.glxp.api.admin.service.auth.SysPermissionService;
|
||||
import com.glxp.api.common.res.BaseResponse;
|
||||
import com.glxp.api.common.util.ResultVOUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/system/role")
|
||||
public class SysRoleController extends BaseController {
|
||||
@Resource
|
||||
ISysRoleService roleService;
|
||||
@Resource
|
||||
AuthAdminService userService;
|
||||
@Resource
|
||||
SysPermissionService permissionService;
|
||||
|
||||
/**
|
||||
* 获取角色信息列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public BaseResponse list(SysRoleRequest sysRoleRequest) {
|
||||
|
||||
List<SysRole> sysRoles = roleService.selectPageRoleList(sysRoleRequest);
|
||||
PageInfo<SysRole> pageInfo = new PageInfo<>(sysRoles);
|
||||
PageSimpleResponse<SysRole> pageSimpleResponse = new PageSimpleResponse<>();
|
||||
pageSimpleResponse.setTotal(pageInfo.getTotal());
|
||||
pageSimpleResponse.setList(sysRoles);
|
||||
return ResultVOUtils.success(pageSimpleResponse);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据角色编号获取详细信息
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
*/
|
||||
@GetMapping(value = "/{roleId}")
|
||||
public BaseResponse getInfo(@PathVariable Long roleId) {
|
||||
roleService.checkRoleDataScope(roleId);
|
||||
return ResultVOUtils.success(roleService.selectRoleById(roleId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增角色
|
||||
*/
|
||||
@PostMapping
|
||||
public BaseResponse add(@Validated @RequestBody SysRole role) {
|
||||
|
||||
if (Constant.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role))) {
|
||||
return ResultVOUtils.error(500, "新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
||||
} else if (Constant.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role))) {
|
||||
return ResultVOUtils.error(500, "新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
||||
}
|
||||
|
||||
role.setCreateBy(getUser().getId() + "");
|
||||
role.setCreateTime(new Date());
|
||||
int i = roleService.insertRole(role);
|
||||
return ResultVOUtils.success("新增成功!");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改保存角色
|
||||
*/
|
||||
@PutMapping
|
||||
public BaseResponse edit(@Validated @RequestBody SysRole role) {
|
||||
roleService.checkRoleAllowed(role);
|
||||
roleService.checkRoleDataScope(role.getRoleId());
|
||||
if (Constant.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role))) {
|
||||
return ResultVOUtils.error(500, "修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
||||
} else if (Constant.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role))) {
|
||||
return ResultVOUtils.error(500, "修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
||||
}
|
||||
|
||||
role.setUpdateTime(new Date());
|
||||
role.setUpdateBy(getUser().getId() + "");
|
||||
if (roleService.updateRole(role) > 0) {
|
||||
// 更新缓存用户权限
|
||||
return ResultVOUtils.success("修改成功!");
|
||||
}
|
||||
return ResultVOUtils.error(500, "修改角色'" + role.getRoleName() + "'失败,请联系管理员");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改保存数据权限
|
||||
*/
|
||||
@PutMapping("/dataScope")
|
||||
public BaseResponse dataScope(@RequestBody SysRole role) {
|
||||
roleService.checkRoleAllowed(role);
|
||||
roleService.checkRoleDataScope(role.getRoleId());
|
||||
|
||||
|
||||
int i = roleService.authDataScope(role);
|
||||
return ResultVOUtils.success("修改成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态修改
|
||||
*/
|
||||
@PutMapping("/changeStatus")
|
||||
public BaseResponse changeStatus(@RequestBody SysRole role) {
|
||||
roleService.checkRoleAllowed(role);
|
||||
roleService.checkRoleDataScope(role.getRoleId());
|
||||
int i = roleService.updateRoleStatus(role);
|
||||
return ResultVOUtils.success("修改成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除角色
|
||||
*
|
||||
* @param roleIds 角色ID串
|
||||
*/
|
||||
@DeleteMapping("/{roleIds}")
|
||||
public BaseResponse remove(@PathVariable Long[] roleIds) {
|
||||
int i = roleService.deleteRoleByIds(roleIds);
|
||||
return ResultVOUtils.success("修改成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色选择框列表
|
||||
*/
|
||||
@SaCheckPermission("system:role:query")
|
||||
@GetMapping("/optionselect")
|
||||
public BaseResponse optionselect() {
|
||||
|
||||
return ResultVOUtils.success(roleService.selectRoleAll());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询已分配用户角色列表
|
||||
*/
|
||||
@GetMapping("/authUser/allocatedList")
|
||||
public BaseResponse allocatedList(AuthAdminQueryRequest authAdminQueryRequest) {
|
||||
|
||||
|
||||
List<AuthAdmin> authAdminList = userService.selectAllocatedList(authAdminQueryRequest);
|
||||
PageInfo<AuthAdmin> pageInfo = new PageInfo<>(authAdminList);
|
||||
PageSimpleResponse<AuthAdmin> pageSimpleResponse = new PageSimpleResponse<>();
|
||||
pageSimpleResponse.setTotal(pageInfo.getTotal());
|
||||
pageSimpleResponse.setList(authAdminList);
|
||||
return ResultVOUtils.success(pageSimpleResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询未分配用户角色列表
|
||||
*/
|
||||
@GetMapping("/authUser/unallocatedList")
|
||||
public BaseResponse unallocatedList(AuthAdminQueryRequest authAdminQueryRequest) {
|
||||
|
||||
|
||||
List<AuthAdmin> authAdminList = userService.selectUnallocatedList(authAdminQueryRequest);
|
||||
PageInfo<AuthAdmin> pageInfo = new PageInfo<>(authAdminList);
|
||||
PageSimpleResponse<AuthAdmin> pageSimpleResponse = new PageSimpleResponse<>();
|
||||
pageSimpleResponse.setTotal(pageInfo.getTotal());
|
||||
pageSimpleResponse.setList(authAdminList);
|
||||
return ResultVOUtils.success(pageSimpleResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消授权用户
|
||||
*/
|
||||
@PutMapping("/authUser/cancel")
|
||||
public BaseResponse cancelAuthUser(@RequestBody SysUserRole userRole) {
|
||||
int i = roleService.deleteAuthUser(userRole);
|
||||
return ResultVOUtils.success("取消成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量取消授权用户
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param userIds 用户ID串
|
||||
*/
|
||||
@SaCheckPermission("system:role:edit")
|
||||
@PutMapping("/authUser/cancelAll")
|
||||
public BaseResponse cancelAuthUserAll(Long roleId, Long[] userIds) {
|
||||
|
||||
int i = roleService.deleteAuthUsers(roleId, userIds);
|
||||
return ResultVOUtils.success("取消成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量选择用户授权
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param userIds 用户ID串
|
||||
*/
|
||||
@SaCheckPermission("system:role:edit")
|
||||
@PutMapping("/authUser/selectAll")
|
||||
public BaseResponse selectAuthUserAll(Long roleId, Long[] userIds) {
|
||||
roleService.checkRoleDataScope(roleId);
|
||||
roleService.insertAuthUsers(roleId, userIds);
|
||||
return ResultVOUtils.success("授权成功!");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,235 @@
|
||||
package com.glxp.api.admin.controller.auth;
|
||||
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.glxp.api.admin.controller.BaseController;
|
||||
import com.glxp.api.admin.entity.auth.AuthAdmin;
|
||||
import com.glxp.api.admin.entity.auth.AuthRoleAdmin;
|
||||
import com.glxp.api.admin.entity.auth.SysMenu;
|
||||
import com.glxp.api.admin.entity.auth.SysRole;
|
||||
import com.glxp.api.admin.req.auth.AuthAdminQueryRequest;
|
||||
import com.glxp.api.admin.req.auth.AuthAdminSaveRequest;
|
||||
import com.glxp.api.admin.res.PageSimpleResponse;
|
||||
import com.glxp.api.admin.res.auth.AuthAdminResponse;
|
||||
import com.glxp.api.admin.service.auth.AuthAdminService;
|
||||
import com.glxp.api.admin.service.auth.AuthRoleAdminService;
|
||||
import com.glxp.api.admin.service.auth.ISysMenuService;
|
||||
import com.glxp.api.admin.service.auth.ISysRoleService;
|
||||
import com.glxp.api.admin.util.PasswordUtils;
|
||||
import com.glxp.api.admin.util.StreamUtils;
|
||||
import com.glxp.api.common.enums.ResultEnum;
|
||||
import com.glxp.api.common.res.BaseResponse;
|
||||
import com.glxp.api.common.util.ResultVOUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/system/user")
|
||||
public class SysUserController extends BaseController {
|
||||
|
||||
private final AuthAdminService userService;
|
||||
private final ISysRoleService roleService;
|
||||
@Resource
|
||||
private AuthRoleAdminService authRoleAdminService;
|
||||
@Resource
|
||||
ISysRoleService sysRoleService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public BaseResponse list(AuthAdminQueryRequest authAdminQueryRequest, BindingResult bindingResult) {
|
||||
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
||||
}
|
||||
|
||||
if (authAdminQueryRequest.getRoleId() != null) {
|
||||
List<AuthRoleAdmin> authRoleAdmins = authRoleAdminService.listByRoleId(authAdminQueryRequest.getRoleId());
|
||||
List<Long> ids = new ArrayList<>();
|
||||
if (authRoleAdmins != null && !authRoleAdmins.isEmpty()) {
|
||||
ids = authRoleAdmins.stream().map(AuthRoleAdmin::getAdmin_id).collect(Collectors.toList());
|
||||
}
|
||||
authAdminQueryRequest.setIds(ids);
|
||||
}
|
||||
List<AuthAdmin> authAdminList = userService.listAdminPage(authAdminQueryRequest);
|
||||
// 查询所有的权限
|
||||
List<Long> adminIds = authAdminList.stream().map(AuthAdmin::getId).collect(Collectors.toList());
|
||||
|
||||
|
||||
// 视图列表
|
||||
List<AuthAdminResponse> authAdminResponseList = authAdminList.stream().map(item -> {
|
||||
AuthAdminResponse authAdminResponse = new AuthAdminResponse();
|
||||
BeanUtils.copyProperties(item, authAdminResponse);
|
||||
// List<Long> roles = authRoleAdminList.stream()
|
||||
// .filter(authRoleAdmin -> authAdminResponse.getId().equals(authRoleAdmin.getAdmin_id()))
|
||||
// .map(AuthRoleAdmin::getRole_id)
|
||||
// .collect(Collectors.toList());
|
||||
List<Long> roles = sysRoleService.selectRoleListByUserId(authAdminResponse.getId());
|
||||
authAdminResponse.setRoles(roles);
|
||||
return authAdminResponse;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
PageInfo<AuthAdmin> authAdminPageInfo = new PageInfo<>(authAdminList);
|
||||
PageSimpleResponse<AuthAdminResponse> authAdminPageSimpleResponse = new PageSimpleResponse<>();
|
||||
authAdminPageSimpleResponse.setTotal(authAdminPageInfo.getTotal());
|
||||
authAdminPageSimpleResponse.setList(authAdminResponseList);
|
||||
|
||||
return ResultVOUtils.success(authAdminPageSimpleResponse);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据用户编号获取详细信息
|
||||
*
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
@SaCheckPermission("system:user:query")
|
||||
@GetMapping(value = {"/", "/{userId}"})
|
||||
public BaseResponse getInfo(@PathVariable(value = "userId", required = false) Long userId) {
|
||||
Map<String, Object> ajax = new HashMap<>();
|
||||
List<SysRole> roles = roleService.selectRoleAll();
|
||||
ajax.put("roles", isAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isAdmin()));
|
||||
if (ObjectUtil.isNotNull(userId)) {
|
||||
AuthAdmin sysUser = userService.findById(userId);
|
||||
ajax.put("user", sysUser);
|
||||
ajax.put("roleIds", StreamUtils.toList(sysUser.getRoles(), SysRole::getRoleId));
|
||||
}
|
||||
return ResultVOUtils.success(ajax);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据用户编号获取授权角色
|
||||
*
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
@SaCheckPermission("system:user:query")
|
||||
@GetMapping("/authRole/{userId}")
|
||||
public BaseResponse authRole(@PathVariable Long userId) {
|
||||
AuthAdmin user = userService.findById(userId);
|
||||
List<SysRole> roles = roleService.selectRolesByUserId(userId);
|
||||
Map<String, Object> ajax = new HashMap<>();
|
||||
ajax.put("user", user);
|
||||
ajax.put("roles", isAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isAdmin()));
|
||||
return ResultVOUtils.success(ajax);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户授权角色
|
||||
*
|
||||
* @param userId 用户Id
|
||||
* @param roleIds 角色ID串
|
||||
*/
|
||||
@SaCheckPermission("system:user:edit")
|
||||
@PutMapping("/authRole")
|
||||
public BaseResponse inseinsertUserAuthrtAuthRole(Long userId, Long[] roleIds) {
|
||||
userService.insertUserAuth(userId, CollUtil.toList(roleIds));
|
||||
return ResultVOUtils.success("授权成功!");
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/save")
|
||||
public BaseResponse save(@RequestBody @Valid AuthAdminSaveRequest authAdminSaveRequest,
|
||||
BindingResult bindingResult) {
|
||||
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
||||
}
|
||||
AuthAdmin curUser = getUser();
|
||||
// if (!curUser.getCustomerId().equals("110")) {
|
||||
// CustomerInfoEntity customerInfoEntity = customerInfoService.selectById(curUser.getCustomerId());
|
||||
// int max = customerInfoEntity.getUserMax();
|
||||
// int count = userService.findCountByCustomerId(authAdminSaveRequest.getCustomerId());
|
||||
// if (count >= max) {
|
||||
// return ResultVOUtils.error(ResultEnum.DATA_REPEAT, "已超过最大用户数");
|
||||
// }
|
||||
// }
|
||||
|
||||
// 检查是否存在相同名称的管理员
|
||||
AuthAdmin byUserName = userService.findByUserName(authAdminSaveRequest.getUserName());
|
||||
if (byUserName != null) {
|
||||
return ResultVOUtils.error(ResultEnum.DATA_REPEAT, "当前管理员已存在");
|
||||
}
|
||||
|
||||
AuthAdmin authAdmin = new AuthAdmin();
|
||||
BeanUtils.copyProperties(authAdminSaveRequest, authAdmin);
|
||||
|
||||
if (authAdmin.getPassWord() != null) {
|
||||
authAdmin.setPassWord(PasswordUtils.authAdminPwd(authAdmin.getPassWord()));
|
||||
}
|
||||
authAdmin.setCustomerId(curUser.getCustomerId());
|
||||
authAdmin.setLastModifyTime(new Date());
|
||||
boolean b = userService.insertAuthAdmin(authAdmin);
|
||||
authAdmin = userService.findByUserName(authAdmin.getUserName());
|
||||
if (!b) {
|
||||
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
|
||||
}
|
||||
|
||||
// 插入角色
|
||||
if (authAdminSaveRequest.getRoles() != null) {
|
||||
userService.insertUserAuth(authAdmin.getId(), authAdminSaveRequest.getRoles());
|
||||
}
|
||||
|
||||
Map<String, Long> res = new HashMap<>();
|
||||
res.put("id", authAdmin.getId());
|
||||
return ResultVOUtils.success(res);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
*/
|
||||
@PostMapping("/edit")
|
||||
public BaseResponse edit(@RequestBody @Valid AuthAdminSaveRequest authAdminSaveRequest,
|
||||
BindingResult bindingResult) {
|
||||
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
||||
}
|
||||
if (authAdminSaveRequest.getId() == null) {
|
||||
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "参数错误!");
|
||||
}
|
||||
// 检查是否存在除了当前管理员的其它名称的管理员
|
||||
AuthAdmin byUserName = userService.findByUserName(authAdminSaveRequest.getUserName());
|
||||
if (byUserName != null && !authAdminSaveRequest.getId().equals(byUserName.getId())) {
|
||||
return ResultVOUtils.error(ResultEnum.DATA_REPEAT, "当前管理员已存在");
|
||||
}
|
||||
|
||||
AuthAdmin authAdmin = new AuthAdmin();
|
||||
BeanUtils.copyProperties(authAdminSaveRequest, authAdmin);
|
||||
if (authAdmin.getPassWord() != null) {
|
||||
authAdmin.setPassWord(PasswordUtils.authAdminPwd(authAdmin.getPassWord()));
|
||||
}
|
||||
authAdmin.setLastModifyTime(new Date());
|
||||
boolean b = userService.updateAuthAdmin(authAdmin);
|
||||
|
||||
if (!b) {
|
||||
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
|
||||
}
|
||||
// 修改角色
|
||||
if (authAdminSaveRequest.getRoles() != null && authAdminSaveRequest.getRoles().size() > 0) {
|
||||
userService.insertUserAuth(authAdmin.getId(), authAdminSaveRequest.getRoles());
|
||||
}
|
||||
|
||||
return ResultVOUtils.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.glxp.api.admin.dao.auth;
|
||||
|
||||
import com.glxp.api.admin.entity.auth.SysDictData;
|
||||
import com.glxp.api.admin.req.auth.SysDictDataRequest;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典表 数据层
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysDictDataMapper {
|
||||
|
||||
List<SysDictData> selectDictDataList(SysDictDataRequest sysDictDataRequest);
|
||||
|
||||
SysDictData selectById(@Param("dictCode") Long dictCode);
|
||||
|
||||
int deleteById(Long dictCode);
|
||||
|
||||
int insert(SysDictData sysDictData);
|
||||
|
||||
int updateById(SysDictData sysDictData);
|
||||
|
||||
int updateByType(SysDictData sysDictData);
|
||||
|
||||
SysDictData exists(SysDictDataRequest sysDictDataRequest);
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.glxp.api.admin.dao.auth;
|
||||
|
||||
|
||||
import com.glxp.api.admin.entity.auth.SysDictType;
|
||||
import com.glxp.api.admin.req.auth.SysDictTypeRequest;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典表 数据层
|
||||
*/
|
||||
|
||||
@Mapper
|
||||
public interface SysDictTypeMapper {
|
||||
|
||||
List<SysDictType> selectDictTypeList(SysDictTypeRequest sysDictTypeRequest);
|
||||
|
||||
SysDictType selectById(Long dictId);
|
||||
|
||||
int deleteBatchIds(@Param("dictIds") List<Long> dictIds);
|
||||
|
||||
int insert(SysDictType sysDictType);
|
||||
|
||||
int updateById(SysDictType sysDictType);
|
||||
|
||||
SysDictType exists(SysDictTypeRequest sysDictTypeRequest);
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package com.glxp.api.admin.dao.auth;
|
||||
|
||||
import com.glxp.api.admin.entity.auth.SysMenu;
|
||||
import com.glxp.api.admin.req.auth.SysMenuRequest;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysMenuDao {
|
||||
|
||||
|
||||
SysMenu selectById(Long id);
|
||||
|
||||
|
||||
int insert(SysMenu menu);
|
||||
|
||||
int updateById(SysMenu menu);
|
||||
|
||||
int deleteById(Long id);
|
||||
|
||||
|
||||
List<SysMenu> selectMenuList(SysMenuRequest sysMenuRequest);
|
||||
|
||||
|
||||
/**
|
||||
* 根据用户所有权限
|
||||
*
|
||||
* @return 权限列表
|
||||
*/
|
||||
List<String> selectMenuPerms();
|
||||
|
||||
/**
|
||||
* 根据用户查询系统菜单列表
|
||||
*
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenu> selectMenuListByUserId(SysMenuRequest sysMenuRequest);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询权限
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 权限列表
|
||||
*/
|
||||
List<String> selectMenuPermsByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据角色ID查询权限
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 权限列表
|
||||
*/
|
||||
List<String> selectMenuPermsByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询菜单
|
||||
*
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenu> selectMenuTreeAll();
|
||||
|
||||
/**
|
||||
* 根据用户ID查询菜单
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenu> selectMenuTreeByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据角色ID查询菜单树信息
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param menuCheckStrictly 菜单树选择项是否关联显示
|
||||
* @return 选中菜单列表
|
||||
*/
|
||||
List<Long> selectMenuListByRoleId(@Param("roleId") Long roleId, @Param("menuCheckStrictly") boolean menuCheckStrictly);
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.glxp.api.admin.dao.auth;
|
||||
|
||||
import com.glxp.api.admin.entity.auth.SysRole;
|
||||
import com.glxp.api.admin.req.auth.SysRoleRequest;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysRoleMapper {
|
||||
|
||||
|
||||
int insert(SysRole sysRole);
|
||||
|
||||
int updateById(SysRole sysRole);
|
||||
|
||||
int delete(Long id);
|
||||
|
||||
SysRole selectById(Long id);
|
||||
|
||||
int deleteBatchIds(@Param("ids") List<Long> ids);
|
||||
|
||||
|
||||
/**
|
||||
* 根据条件分页查询角色数据
|
||||
*
|
||||
* @return 角色数据集合信息
|
||||
*/
|
||||
List<SysRole> selectRoleList(SysRoleRequest sysRoleRequest);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRole> selectRolePermissionByUserId(Long userId);
|
||||
|
||||
|
||||
/**
|
||||
* 根据用户ID获取角色选择框列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 选中角色ID列表
|
||||
*/
|
||||
List<Long> selectRoleListByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRole> selectRolesByUserName(String userName);
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.glxp.api.admin.dao.auth;
|
||||
|
||||
import com.glxp.api.admin.entity.auth.SysRoleMenu;
|
||||
import com.glxp.api.admin.req.auth.SysRoleMenuRequest;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysRoleMenuMapper {
|
||||
|
||||
|
||||
List<SysRoleMenu> selectRoleMenuList(SysRoleMenuRequest sysRoleMenu);
|
||||
|
||||
|
||||
int deleteById(Long id);
|
||||
|
||||
|
||||
int deleteByList(@Param("ids") List<Long> ids);
|
||||
|
||||
int insertBatch(List<SysRoleMenu> list);
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.glxp.api.admin.dao.auth;
|
||||
|
||||
|
||||
import com.glxp.api.admin.entity.auth.SysUserRole;
|
||||
import com.glxp.api.admin.req.auth.SysUserRoleRequest;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SysUserRoleMapper {
|
||||
|
||||
List<Long> selectUserIdsByRoleId(Long roleId);
|
||||
|
||||
int delete(SysUserRoleRequest sysUserRoleRequest);
|
||||
|
||||
int insertBatch(@Param("sysUserRoles") List<SysUserRole> sysUserRoles);
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.glxp.api.admin.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Data
|
||||
public class BaseEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 搜索值
|
||||
*/
|
||||
private String searchValue;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 请求参数
|
||||
*/
|
||||
private Map<String, Object> params = new HashMap<>();
|
||||
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package com.glxp.api.admin.entity.auth;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class LoginUser implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
*/
|
||||
private String deptId;
|
||||
|
||||
/**
|
||||
* 部门名
|
||||
*/
|
||||
private String deptName;
|
||||
|
||||
/**
|
||||
* 用户唯一标识
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 用户类型
|
||||
*/
|
||||
private String userType;
|
||||
|
||||
/**
|
||||
* 登录时间
|
||||
*/
|
||||
private Long loginTime;
|
||||
|
||||
/**
|
||||
* 过期时间
|
||||
*/
|
||||
private Long expireTime;
|
||||
|
||||
/**
|
||||
* 登录IP地址
|
||||
*/
|
||||
private String ipaddr;
|
||||
|
||||
/**
|
||||
* 登录地点
|
||||
*/
|
||||
private String loginLocation;
|
||||
|
||||
/**
|
||||
* 浏览器类型
|
||||
*/
|
||||
private String browser;
|
||||
|
||||
/**
|
||||
* 操作系统
|
||||
*/
|
||||
private String os;
|
||||
|
||||
/**
|
||||
* 菜单权限
|
||||
*/
|
||||
private Set<String> menuPermission;
|
||||
|
||||
/**
|
||||
* 角色权限
|
||||
*/
|
||||
private Set<String> rolePermission;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 角色对象
|
||||
*/
|
||||
private List<RoleEntity> roles;
|
||||
|
||||
/**
|
||||
* 数据权限 当前角色ID
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.glxp.api.admin.entity.auth;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SysRoleMenu {
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
private Long menuId;
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.glxp.api.admin.entity.auth;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 用户和角色关联 sys_user_role
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class SysUserRole {
|
||||
|
||||
private Long userId;
|
||||
private Long roleId;
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.glxp.api.admin.entity.auth;
|
||||
|
||||
import com.glxp.api.admin.entity.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tree基类
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class TreeEntity<T> extends BaseEntity {
|
||||
|
||||
|
||||
/**
|
||||
* 父菜单名称
|
||||
*/
|
||||
private String parentName;
|
||||
|
||||
/**
|
||||
* 父菜单ID
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 子部门
|
||||
*/
|
||||
private List<T> children = new ArrayList<>();
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.glxp.api.admin.req.auth;
|
||||
|
||||
import com.glxp.api.admin.req.ListPageRequest;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SysDictDataRequest extends ListPageRequest {
|
||||
|
||||
private String dictType;
|
||||
private String status;
|
||||
private String dictLabel;
|
||||
private String dictValue;
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.glxp.api.admin.req.auth;
|
||||
|
||||
import com.glxp.api.admin.req.ListPageRequest;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SysDictTypeRequest extends ListPageRequest {
|
||||
|
||||
private Long dictId;
|
||||
|
||||
private String dictName;
|
||||
|
||||
private String dictType;
|
||||
|
||||
private String status;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.glxp.api.admin.req.auth;
|
||||
|
||||
import com.glxp.api.admin.req.ListPageRequest;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SysRoleMenuRequest extends ListPageRequest {
|
||||
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
private Long menuId;
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.glxp.api.admin.req.auth;
|
||||
|
||||
import com.glxp.api.admin.req.ListPageRequest;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SysRoleRequest extends ListPageRequest {
|
||||
|
||||
private Long roleId;
|
||||
private String roleName;
|
||||
private String roleKey;
|
||||
|
||||
|
||||
private String neRoleName;
|
||||
private String neRoleKey;
|
||||
private Long neRoleId;
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.glxp.api.admin.req.auth;
|
||||
|
||||
import com.glxp.api.admin.req.ListPageRequest;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SysUserRoleRequest extends ListPageRequest {
|
||||
|
||||
|
||||
private Long userId;
|
||||
private Long roleId;
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.glxp.api.admin.service.auth;
|
||||
|
||||
|
||||
import com.glxp.api.admin.entity.auth.SysDictData;
|
||||
import com.glxp.api.admin.req.auth.SysDictDataRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典 业务层
|
||||
*/
|
||||
public interface ISysDictDataService {
|
||||
|
||||
|
||||
/**
|
||||
* 根据条件分页查询字典数据
|
||||
*
|
||||
* @param dictData 字典数据信息
|
||||
* @return 字典数据集合信息
|
||||
*/
|
||||
List<SysDictData> selectDictDataList(SysDictDataRequest sysDictDataRequest);
|
||||
|
||||
/**
|
||||
* 根据字典类型和字典键值查询字典数据信息
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @param dictValue 字典键值
|
||||
* @return 字典标签
|
||||
*/
|
||||
String selectDictLabel(String dictType, String dictValue);
|
||||
|
||||
/**
|
||||
* 根据字典数据ID查询信息
|
||||
*
|
||||
* @param dictCode 字典数据ID
|
||||
* @return 字典数据
|
||||
*/
|
||||
SysDictData selectDictDataById(Long dictCode);
|
||||
|
||||
/**
|
||||
* 批量删除字典数据信息
|
||||
*
|
||||
* @param dictCodes 需要删除的字典数据ID
|
||||
*/
|
||||
void deleteDictDataByIds(Long[] dictCodes);
|
||||
|
||||
/**
|
||||
* 新增保存字典数据信息
|
||||
*
|
||||
* @param dictData 字典数据信息
|
||||
* @return 结果
|
||||
*/
|
||||
List<SysDictData> insertDictData(SysDictData dictData);
|
||||
|
||||
/**
|
||||
* 修改保存字典数据信息
|
||||
*
|
||||
* @param dictData 字典数据信息
|
||||
* @return 结果
|
||||
*/
|
||||
List<SysDictData> updateDictData(SysDictData dictData);
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package com.glxp.api.admin.service.auth;
|
||||
|
||||
|
||||
import com.glxp.api.admin.entity.auth.SysDictData;
|
||||
import com.glxp.api.admin.entity.auth.SysDictType;
|
||||
import com.glxp.api.admin.req.auth.SysDictTypeRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典 业务层
|
||||
*/
|
||||
public interface ISysDictTypeService {
|
||||
|
||||
|
||||
List<SysDictType> selectDictTypeList(SysDictTypeRequest sysDictTypeRequest);
|
||||
|
||||
/**
|
||||
* 根据所有字典类型
|
||||
*
|
||||
* @return 字典类型集合信息
|
||||
*/
|
||||
List<SysDictType> selectDictTypeAll();
|
||||
|
||||
/**
|
||||
* 根据字典类型查询字典数据
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @return 字典数据集合信息
|
||||
*/
|
||||
List<SysDictData> selectDictDataByType(String dictType);
|
||||
|
||||
/**
|
||||
* 根据字典类型ID查询信息
|
||||
*
|
||||
* @param dictId 字典类型ID
|
||||
* @return 字典类型
|
||||
*/
|
||||
SysDictType selectDictTypeById(Long dictId);
|
||||
|
||||
/**
|
||||
* 根据字典类型查询信息
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @return 字典类型
|
||||
*/
|
||||
SysDictType selectDictTypeByType(String dictType);
|
||||
|
||||
/**
|
||||
* 批量删除字典信息
|
||||
*
|
||||
* @param dictIds 需要删除的字典ID
|
||||
*/
|
||||
void deleteDictTypeByIds(Long[] dictIds);
|
||||
|
||||
/**
|
||||
* 重置字典缓存数据
|
||||
*/
|
||||
void resetDictCache();
|
||||
|
||||
/**
|
||||
* 新增保存字典类型信息
|
||||
*
|
||||
* @param dictType 字典类型信息
|
||||
* @return 结果
|
||||
*/
|
||||
List<SysDictData> insertDictType(SysDictType dictType);
|
||||
|
||||
/**
|
||||
* 修改保存字典类型信息
|
||||
*
|
||||
* @param dictType 字典类型信息
|
||||
* @return 结果
|
||||
*/
|
||||
List<SysDictData> updateDictType(SysDictType dictType);
|
||||
|
||||
/**
|
||||
* 校验字典类型称是否唯一
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @return 结果
|
||||
*/
|
||||
String checkDictTypeUnique(SysDictType dictType);
|
||||
|
||||
|
||||
String getDictLabel(String dictType, String dictValue, String separator);
|
||||
|
||||
/**
|
||||
* 根据字典类型和字典标签获取字典值
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @param dictLabel 字典标签
|
||||
* @param separator 分隔符
|
||||
* @return 字典值
|
||||
*/
|
||||
String getDictValue(String dictType, String dictLabel, String separator);
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
package com.glxp.api.admin.service.auth;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import com.glxp.api.admin.entity.auth.RouterEntity;
|
||||
import com.glxp.api.admin.entity.auth.SysMenu;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface ISysMenuService {
|
||||
|
||||
/**
|
||||
* 根据用户查询系统菜单列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenu> selectMenuList(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户查询系统菜单列表
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @param userId 用户ID
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenu> selectMenuList(SysMenu menu, Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询权限
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 权限列表
|
||||
*/
|
||||
Set<String> selectMenuPermsByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据角色ID查询权限
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 权限列表
|
||||
*/
|
||||
Set<String> selectMenuPermsByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询菜单树信息
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenu> selectMenuTreeByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据角色ID查询菜单树信息
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 选中菜单列表
|
||||
*/
|
||||
List<Long> selectMenuListByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 构建前端路由所需要的菜单
|
||||
*
|
||||
* @param menus 菜单列表
|
||||
* @return 路由列表
|
||||
*/
|
||||
List<RouterEntity> buildMenus(List<SysMenu> menus);
|
||||
|
||||
/**
|
||||
* 构建前端所需要下拉树结构
|
||||
*
|
||||
* @param menus 菜单列表
|
||||
* @return 下拉树结构列表
|
||||
*/
|
||||
List<Tree<Long>> buildMenuTreeSelect(List<SysMenu> menus);
|
||||
|
||||
/**
|
||||
* 根据菜单ID查询信息
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 菜单信息
|
||||
*/
|
||||
SysMenu selectMenuById(Long menuId);
|
||||
|
||||
/**
|
||||
* 是否存在菜单子节点
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 结果 true 存在 false 不存在
|
||||
*/
|
||||
boolean hasChildByMenuId(Long menuId);
|
||||
|
||||
/**
|
||||
* 查询菜单是否存在角色
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 结果 true 存在 false 不存在
|
||||
*/
|
||||
boolean checkMenuExistRole(Long menuId);
|
||||
|
||||
/**
|
||||
* 新增保存菜单信息
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 结果
|
||||
*/
|
||||
int insertMenu(SysMenu menu);
|
||||
|
||||
/**
|
||||
* 修改保存菜单信息
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 结果
|
||||
*/
|
||||
int updateMenu(SysMenu menu);
|
||||
|
||||
/**
|
||||
* 删除菜单管理信息
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteMenuById(Long menuId);
|
||||
|
||||
/**
|
||||
* 校验菜单名称是否唯一
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 结果
|
||||
*/
|
||||
String checkMenuNameUnique(SysMenu menu);
|
||||
}
|
@ -0,0 +1,176 @@
|
||||
package com.glxp.api.admin.service.auth;
|
||||
|
||||
|
||||
import com.glxp.api.admin.entity.auth.SysRole;
|
||||
import com.glxp.api.admin.entity.auth.SysUserRole;
|
||||
import com.glxp.api.admin.req.auth.SysRoleRequest;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 角色业务层
|
||||
*/
|
||||
public interface ISysRoleService {
|
||||
|
||||
|
||||
List<SysRole> selectPageRoleList(SysRoleRequest sysRoleRequest);
|
||||
|
||||
/**
|
||||
* 根据条件分页查询角色数据
|
||||
*
|
||||
* @return 角色数据集合信息
|
||||
*/
|
||||
List<SysRole> selectRoleList(SysRoleRequest sysRoleRequest);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRole> selectRolesByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色权限
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 权限列表
|
||||
*/
|
||||
Set<String> selectRolePermissionByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 查询所有角色
|
||||
*
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRole> selectRoleAll();
|
||||
|
||||
/**
|
||||
* 根据用户ID获取角色选择框列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 选中角色ID列表
|
||||
*/
|
||||
List<Long> selectRoleListByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 通过角色ID查询角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 角色对象信息
|
||||
*/
|
||||
SysRole selectRoleById(Long roleId);
|
||||
|
||||
/**
|
||||
* 校验角色名称是否唯一
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
String checkRoleNameUnique(SysRole role);
|
||||
|
||||
/**
|
||||
* 校验角色权限是否唯一
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
String checkRoleKeyUnique(SysRole role);
|
||||
|
||||
/**
|
||||
* 校验角色是否允许操作
|
||||
*
|
||||
* @param role 角色信息
|
||||
*/
|
||||
void checkRoleAllowed(SysRole role);
|
||||
|
||||
/**
|
||||
* 校验角色是否有数据权限
|
||||
*
|
||||
* @param roleId 角色id
|
||||
*/
|
||||
void checkRoleDataScope(Long roleId);
|
||||
|
||||
/**
|
||||
* 通过角色ID查询角色使用数量
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
long countUserRoleByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 新增保存角色信息
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
int insertRole(SysRole role);
|
||||
|
||||
/**
|
||||
* 修改保存角色信息
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
int updateRole(SysRole role);
|
||||
|
||||
/**
|
||||
* 修改角色状态
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
int updateRoleStatus(SysRole role);
|
||||
|
||||
/**
|
||||
* 修改数据权限信息
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
int authDataScope(SysRole role);
|
||||
|
||||
/**
|
||||
* 通过角色ID删除角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteRoleById(Long roleId);
|
||||
|
||||
/**
|
||||
* 批量删除角色信息
|
||||
*
|
||||
* @param roleIds 需要删除的角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteRoleByIds(Long[] roleIds);
|
||||
|
||||
/**
|
||||
* 取消授权用户角色
|
||||
*
|
||||
* @param userRole 用户和角色关联信息
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteAuthUser(SysUserRole userRole);
|
||||
|
||||
/**
|
||||
* 批量取消授权用户角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param userIds 需要取消授权的用户数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteAuthUsers(Long roleId, Long[] userIds);
|
||||
|
||||
/**
|
||||
* 批量选择授权用户角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param userIds 需要删除的用户数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
int insertAuthUsers(Long roleId, Long[] userIds);
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package com.glxp.api.admin.service.auth.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.glxp.api.admin.dao.auth.SysDictDataMapper;
|
||||
import com.glxp.api.admin.entity.auth.SysDictData;
|
||||
import com.glxp.api.admin.exception.ServiceException;
|
||||
import com.glxp.api.admin.req.auth.SysDictDataRequest;
|
||||
import com.glxp.api.admin.service.auth.ISysDictDataService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典 业务层处理
|
||||
*/
|
||||
@Service
|
||||
public class SysDictDataServiceImpl implements ISysDictDataService {
|
||||
@Resource
|
||||
SysDictDataMapper baseMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public List<SysDictData> selectDictDataList(SysDictDataRequest sysDictDataRequest) {
|
||||
|
||||
if (sysDictDataRequest.getPage() != null) {
|
||||
int offset = (sysDictDataRequest.getPage() - 1) * sysDictDataRequest.getLimit();
|
||||
PageHelper.offsetPage(offset, sysDictDataRequest.getLimit());
|
||||
}
|
||||
|
||||
return baseMapper.selectDictDataList(sysDictDataRequest);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String selectDictLabel(String dictType, String dictValue) {
|
||||
|
||||
SysDictDataRequest sysDictDataRequest = new SysDictDataRequest();
|
||||
sysDictDataRequest.setDictType(dictType);
|
||||
sysDictDataRequest.setDictValue(dictValue);
|
||||
List<SysDictData> dictData = baseMapper.selectDictDataList(sysDictDataRequest);
|
||||
if (CollUtil.isNotEmpty(dictData))
|
||||
return dictData.get(0).getDictLabel();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysDictData selectDictDataById(Long dictCode) {
|
||||
return baseMapper.selectById(dictCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDictDataByIds(Long[] dictCodes) {
|
||||
for (Long dictCode : dictCodes) {
|
||||
SysDictData data = selectDictDataById(dictCode);
|
||||
baseMapper.deleteById(dictCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDictData> insertDictData(SysDictData data) {
|
||||
int row = baseMapper.insert(data);
|
||||
if (row > 0) {
|
||||
SysDictDataRequest sysDictDataRequest = new SysDictDataRequest();
|
||||
sysDictDataRequest.setDictType(data.getDictType());
|
||||
return baseMapper.selectDictDataList(sysDictDataRequest);
|
||||
}
|
||||
throw new ServiceException("操作失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDictData> updateDictData(SysDictData data) {
|
||||
int row = baseMapper.updateById(data);
|
||||
if (row > 0) {
|
||||
SysDictDataRequest sysDictDataRequest = new SysDictDataRequest();
|
||||
sysDictDataRequest.setDictType(data.getDictType());
|
||||
return baseMapper.selectDictDataList(sysDictDataRequest);
|
||||
}
|
||||
throw new ServiceException("操作失败");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,239 @@
|
||||
package com.glxp.api.admin.service.auth.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.glxp.api.admin.constant.Constant;
|
||||
import com.glxp.api.admin.dao.auth.SysDictDataMapper;
|
||||
import com.glxp.api.admin.dao.auth.SysDictTypeMapper;
|
||||
import com.glxp.api.admin.entity.auth.SysDictData;
|
||||
import com.glxp.api.admin.entity.auth.SysDictType;
|
||||
import com.glxp.api.admin.exception.ServiceException;
|
||||
import com.glxp.api.admin.req.auth.SysDictDataRequest;
|
||||
import com.glxp.api.admin.req.auth.SysDictTypeRequest;
|
||||
import com.glxp.api.admin.service.auth.ISysDictTypeService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典 业务层处理
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class SysDictTypeServiceImpl implements ISysDictTypeService {
|
||||
|
||||
private final SysDictTypeMapper baseMapper;
|
||||
private final SysDictDataMapper dictDataMapper;
|
||||
|
||||
@Override
|
||||
public List<SysDictType> selectDictTypeList(SysDictTypeRequest sysDictTypeRequest) {
|
||||
if (sysDictTypeRequest.getPage() != null) {
|
||||
int offset = (sysDictTypeRequest.getPage() - 1) * sysDictTypeRequest.getLimit();
|
||||
PageHelper.offsetPage(offset, sysDictTypeRequest.getLimit());
|
||||
}
|
||||
return baseMapper.selectDictTypeList(sysDictTypeRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDictType> selectDictTypeAll() {
|
||||
return baseMapper.selectDictTypeList(new SysDictTypeRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典类型查询字典数据
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @return 字典数据集合信息
|
||||
*/
|
||||
@Override
|
||||
public List<SysDictData> selectDictDataByType(String dictType) {
|
||||
SysDictDataRequest sysDictTypeRequest = new SysDictDataRequest();
|
||||
sysDictTypeRequest.setDictType(dictType);
|
||||
List<SysDictData> dictDatas = dictDataMapper.selectDictDataList(sysDictTypeRequest);
|
||||
if (CollUtil.isNotEmpty(dictDatas)) {
|
||||
return dictDatas;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典类型ID查询信息
|
||||
*
|
||||
* @param dictId 字典类型ID
|
||||
* @return 字典类型
|
||||
*/
|
||||
@Override
|
||||
public SysDictType selectDictTypeById(Long dictId) {
|
||||
return baseMapper.selectById(dictId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典类型查询信息
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @return 字典类型
|
||||
*/
|
||||
@Override
|
||||
public SysDictType selectDictTypeByType(String dictType) {
|
||||
SysDictTypeRequest sysDictTypeRequest = new SysDictTypeRequest();
|
||||
sysDictTypeRequest.setDictType(dictType);
|
||||
List<SysDictType> sysDictTypes = baseMapper.selectDictTypeList(sysDictTypeRequest);
|
||||
if (CollUtil.isNotEmpty(sysDictTypes)) {
|
||||
return sysDictTypes.get(0);
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除字典类型信息
|
||||
*
|
||||
* @param dictIds 需要删除的字典ID
|
||||
*/
|
||||
@Override
|
||||
public void deleteDictTypeByIds(Long[] dictIds) {
|
||||
for (Long dictId : dictIds) {
|
||||
SysDictType dictType = selectDictTypeById(dictId);
|
||||
|
||||
SysDictDataRequest sysDictDataRequest = new SysDictDataRequest();
|
||||
sysDictDataRequest.setDictType(dictType.getDictType());
|
||||
SysDictData sysDictData = dictDataMapper.exists(sysDictDataRequest);
|
||||
|
||||
if (sysDictData != null) {
|
||||
throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
|
||||
}
|
||||
}
|
||||
baseMapper.deleteBatchIds(Arrays.asList(dictIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置字典缓存数据
|
||||
*/
|
||||
@Override
|
||||
public void resetDictCache() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增保存字典类型信息
|
||||
*
|
||||
* @param dict 字典类型信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public List<SysDictData> insertDictType(SysDictType dict) {
|
||||
int row = baseMapper.insert(dict);
|
||||
if (row > 0) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
throw new ServiceException("操作失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改保存字典类型信息
|
||||
*
|
||||
* @param dict 字典类型信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<SysDictData> updateDictType(SysDictType dict) {
|
||||
SysDictType oldDict = baseMapper.selectById(dict.getDictId());
|
||||
// dictDataMapper.updateByType(null, new LambdaUpdateWrapper<SysDictData>()
|
||||
// .set(SysDictData::getDictType, dict.getDictType())
|
||||
// .eq(SysDictData::getDictType, oldDict.getDictType()));
|
||||
int row = baseMapper.updateById(dict);
|
||||
if (row > 0) {
|
||||
SysDictDataRequest sysDictDataRequest = new SysDictDataRequest();
|
||||
sysDictDataRequest.setDictType(dict.getDictType());
|
||||
return dictDataMapper.selectDictDataList(sysDictDataRequest);
|
||||
}
|
||||
throw new ServiceException("操作失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验字典类型称是否唯一
|
||||
*
|
||||
* @param dict 字典类型
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public String checkDictTypeUnique(SysDictType dict) {
|
||||
|
||||
SysDictTypeRequest sysDictTypeRequest = new SysDictTypeRequest();
|
||||
sysDictTypeRequest.setDictType(dict.getDictType());
|
||||
SysDictType exist = baseMapper.exists(sysDictTypeRequest);
|
||||
if (exist == null) {
|
||||
return Constant.NOT_UNIQUE;
|
||||
}
|
||||
return Constant.UNIQUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典类型和字典值获取字典标签
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @param dictValue 字典值
|
||||
* @param separator 分隔符
|
||||
* @return 字典标签
|
||||
*/
|
||||
@Override
|
||||
public String getDictLabel(String dictType, String dictValue, String separator) {
|
||||
StringBuilder propertyString = new StringBuilder();
|
||||
List<SysDictData> datas = selectDictDataByType(dictType);
|
||||
|
||||
if (StringUtils.containsAny(dictValue, separator) && CollUtil.isNotEmpty(datas)) {
|
||||
for (SysDictData dict : datas) {
|
||||
for (String value : dictValue.split(separator)) {
|
||||
if (value.equals(dict.getDictValue())) {
|
||||
propertyString.append(dict.getDictLabel() + separator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (SysDictData dict : datas) {
|
||||
if (dictValue.equals(dict.getDictValue())) {
|
||||
return dict.getDictLabel();
|
||||
}
|
||||
}
|
||||
}
|
||||
return StringUtils.stripEnd(propertyString.toString(), separator);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典类型和字典标签获取字典值
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @param dictLabel 字典标签
|
||||
* @param separator 分隔符
|
||||
* @return 字典值
|
||||
*/
|
||||
@Override
|
||||
public String getDictValue(String dictType, String dictLabel, String separator) {
|
||||
StringBuilder propertyString = new StringBuilder();
|
||||
List<SysDictData> datas = selectDictDataByType(dictType);
|
||||
|
||||
if (StringUtils.containsAny(dictLabel, separator) && CollUtil.isNotEmpty(datas)) {
|
||||
for (SysDictData dict : datas) {
|
||||
for (String label : dictLabel.split(separator)) {
|
||||
if (label.equals(dict.getDictLabel())) {
|
||||
propertyString.append(dict.getDictValue() + separator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (SysDictData dict : datas) {
|
||||
if (dictLabel.equals(dict.getDictLabel())) {
|
||||
return dict.getDictValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return StringUtils.stripEnd(propertyString.toString(), separator);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,460 @@
|
||||
package com.glxp.api.admin.service.auth.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.glxp.api.admin.constant.Constant;
|
||||
import com.glxp.api.admin.dao.auth.SysMenuDao;
|
||||
import com.glxp.api.admin.dao.auth.SysRoleMapper;
|
||||
import com.glxp.api.admin.dao.auth.SysRoleMenuMapper;
|
||||
import com.glxp.api.admin.entity.auth.*;
|
||||
import com.glxp.api.admin.req.auth.SysMenuRequest;
|
||||
import com.glxp.api.admin.req.auth.SysRoleMenuRequest;
|
||||
import com.glxp.api.admin.service.auth.ISysMenuService;
|
||||
import com.glxp.api.admin.util.TreeBuildUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 菜单 业务层处理
|
||||
*/
|
||||
@Service
|
||||
public class SysMenuServiceImpl implements ISysMenuService {
|
||||
|
||||
|
||||
@Resource
|
||||
SysMenuDao sysMenuDao;
|
||||
@Resource
|
||||
SysRoleMapper sysRoleMapper;
|
||||
@Resource
|
||||
SysRoleMenuMapper sysRoleMenuMapper;
|
||||
|
||||
/**
|
||||
* 根据用户查询系统菜单列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 菜单列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> selectMenuList(Long userId) {
|
||||
return selectMenuList(new SysMenu(), userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询系统菜单列表
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 菜单列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> selectMenuList(SysMenu menu, Long userId) {
|
||||
List<SysMenu> menuList = null;
|
||||
// 管理员显示所有菜单信息
|
||||
SysMenuRequest sysMenuRequest = new SysMenuRequest();
|
||||
BeanUtils.copyProperties(menu, sysMenuRequest);
|
||||
if (Constant.ADMIN_ID.equals(userId + "")) {
|
||||
menuList = sysMenuDao.selectMenuList(sysMenuRequest);
|
||||
} else {
|
||||
menuList = sysMenuDao.selectMenuListByUserId(sysMenuRequest);
|
||||
}
|
||||
return menuList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询权限
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 权限列表
|
||||
*/
|
||||
@Override
|
||||
public Set<String> selectMenuPermsByUserId(Long userId) {
|
||||
List<String> perms = sysMenuDao.selectMenuPermsByUserId(userId);
|
||||
Set<String> permsSet = new HashSet<>();
|
||||
for (String perm : perms) {
|
||||
if (StringUtils.isNotEmpty(perm)) {
|
||||
permsSet.addAll(Arrays.asList(perm.trim().split(",")));
|
||||
}
|
||||
}
|
||||
return permsSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色ID查询权限
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 权限列表
|
||||
*/
|
||||
@Override
|
||||
public Set<String> selectMenuPermsByRoleId(Long roleId) {
|
||||
List<String> perms = sysMenuDao.selectMenuPermsByRoleId(roleId);
|
||||
Set<String> permsSet = new HashSet<>();
|
||||
for (String perm : perms) {
|
||||
if (StringUtils.isNotEmpty(perm)) {
|
||||
permsSet.addAll(Arrays.asList(perm.trim().split(",")));
|
||||
}
|
||||
}
|
||||
return permsSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询菜单
|
||||
*
|
||||
* @param userId 用户名称
|
||||
* @return 菜单列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> selectMenuTreeByUserId(Long userId) {
|
||||
List<SysMenu> menus = null;
|
||||
if (Constant.ADMIN_ID.equals(userId + "")) {
|
||||
menus = sysMenuDao.selectMenuTreeAll();
|
||||
} else {
|
||||
menus = sysMenuDao.selectMenuTreeByUserId(userId);
|
||||
}
|
||||
return getChildPerms(menus, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色ID查询菜单树信息
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 选中菜单列表
|
||||
*/
|
||||
@Override
|
||||
public List<Long> selectMenuListByRoleId(Long roleId) {
|
||||
SysRole role = sysRoleMapper.selectById(roleId);
|
||||
return sysMenuDao.selectMenuListByRoleId(roleId, role.getMenuCheckStrictly());
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建前端路由所需要的菜单
|
||||
*
|
||||
* @param menus 菜单列表
|
||||
* @return 路由列表
|
||||
*/
|
||||
@Override
|
||||
public List<RouterEntity> buildMenus(List<SysMenu> menus) {
|
||||
List<RouterEntity> routers = new LinkedList<RouterEntity>();
|
||||
for (SysMenu menu : menus) {
|
||||
RouterEntity router = new RouterEntity();
|
||||
router.setHidden("1".equals(menu.getVisible()));
|
||||
router.setName(getRouteName(menu));
|
||||
router.setPath(getRouterPath(menu));
|
||||
router.setComponent(getComponent(menu));
|
||||
router.setQuery(menu.getQueryParam());
|
||||
router.setMeta(new MetaEntity(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath()));
|
||||
List<SysMenu> cMenus = menu.getChildren();
|
||||
if (!cMenus.isEmpty() && Constant.TYPE_DIR.equals(menu.getMenuType())) {
|
||||
router.setAlwaysShow(true);
|
||||
router.setRedirect("noRedirect");
|
||||
router.setChildren(buildMenus(cMenus));
|
||||
} else if (isMenuFrame(menu)) {
|
||||
router.setMeta(null);
|
||||
List<RouterEntity> childrenList = new ArrayList<RouterEntity>();
|
||||
RouterEntity children = new RouterEntity();
|
||||
children.setPath(menu.getPath());
|
||||
children.setComponent(menu.getComponent());
|
||||
children.setName(StringUtils.capitalize(menu.getPath()));
|
||||
children.setMeta(new MetaEntity(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath()));
|
||||
children.setQuery(menu.getQueryParam());
|
||||
childrenList.add(children);
|
||||
router.setChildren(childrenList);
|
||||
} else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) {
|
||||
router.setMeta(new MetaEntity(menu.getMenuName(), menu.getIcon()));
|
||||
router.setPath("/");
|
||||
List<RouterEntity> childrenList = new ArrayList<RouterEntity>();
|
||||
RouterEntity children = new RouterEntity();
|
||||
String routerPath = innerLinkReplaceEach(menu.getPath());
|
||||
children.setPath(routerPath);
|
||||
children.setComponent(Constant.INNER_LINK);
|
||||
children.setName(StringUtils.capitalize(routerPath));
|
||||
children.setMeta(new MetaEntity(menu.getMenuName(), menu.getIcon(), menu.getPath()));
|
||||
childrenList.add(children);
|
||||
router.setChildren(childrenList);
|
||||
}
|
||||
routers.add(router);
|
||||
}
|
||||
return routers;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建前端所需要下拉树结构
|
||||
*
|
||||
* @param menus 菜单列表
|
||||
* @return 下拉树结构列表
|
||||
*/
|
||||
@Override
|
||||
public List<Tree<Long>> buildMenuTreeSelect(List<SysMenu> menus) {
|
||||
if (CollUtil.isEmpty(menus)) {
|
||||
return CollUtil.newArrayList();
|
||||
}
|
||||
return TreeBuildUtils.build(menus, (menu, tree) ->
|
||||
tree.setId(menu.getMenuId())
|
||||
.setParentId(menu.getParentId())
|
||||
.setName(menu.getMenuName())
|
||||
.setWeight(menu.getOrderNum()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据菜单ID查询信息
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 菜单信息
|
||||
*/
|
||||
@Override
|
||||
public SysMenu selectMenuById(Long menuId) {
|
||||
return sysMenuDao.selectById(menuId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否存在菜单子节点
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean hasChildByMenuId(Long menuId) {
|
||||
|
||||
|
||||
SysMenuRequest sysMenuRequest = new SysMenuRequest();
|
||||
sysMenuRequest.setParentId(menuId);
|
||||
List<SysMenu> menuList = sysMenuDao.selectMenuList(sysMenuRequest);
|
||||
|
||||
|
||||
if (CollUtil.isEmpty(menuList)) {
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询菜单使用数量
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean checkMenuExistRole(Long menuId) {
|
||||
|
||||
|
||||
SysRoleMenuRequest sysRoleRequest = new SysRoleMenuRequest();
|
||||
sysRoleRequest.setMenuId(menuId);
|
||||
List<SysRoleMenu> sysRoleMenus = sysRoleMenuMapper.selectRoleMenuList(sysRoleRequest);
|
||||
if (CollUtil.isEmpty(sysRoleMenus)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增保存菜单信息
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertMenu(SysMenu menu) {
|
||||
return sysMenuDao.insert(menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改保存菜单信息
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateMenu(SysMenu menu) {
|
||||
return sysMenuDao.updateById(menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单管理信息
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteMenuById(Long menuId) {
|
||||
return sysMenuDao.deleteById(menuId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验菜单名称是否唯一
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public String checkMenuNameUnique(SysMenu menu) {
|
||||
|
||||
|
||||
SysMenuRequest sysMenuRequest = new SysMenuRequest();
|
||||
sysMenuRequest.setParentId(menu.getParentId());
|
||||
sysMenuRequest.setMenuName(menu.getMenuName());
|
||||
List<SysMenu> menuList = sysMenuDao.selectMenuList(sysMenuRequest);
|
||||
if (CollUtil.isEmpty(menuList)) {
|
||||
return Constant.UNIQUE;
|
||||
} else
|
||||
return Constant.NOT_UNIQUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取路由名称
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 路由名称
|
||||
*/
|
||||
public String getRouteName(SysMenu menu) {
|
||||
String routerName = StringUtils.capitalize(menu.getPath());
|
||||
// 非外链并且是一级目录(类型为目录)
|
||||
if (isMenuFrame(menu)) {
|
||||
routerName = StringUtils.EMPTY;
|
||||
}
|
||||
return routerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取路由地址
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 路由地址
|
||||
*/
|
||||
public String getRouterPath(SysMenu menu) {
|
||||
String routerPath = menu.getPath();
|
||||
// 内链打开外网方式
|
||||
if (menu.getParentId().intValue() != 0 && isInnerLink(menu)) {
|
||||
routerPath = innerLinkReplaceEach(routerPath);
|
||||
}
|
||||
// 非外链并且是一级目录(类型为目录)
|
||||
if (0 == menu.getParentId().intValue() && Constant.TYPE_DIR.equals(menu.getMenuType())
|
||||
&& Constant.NO_FRAME.equals(menu.getIsFrame())) {
|
||||
routerPath = "/" + menu.getPath();
|
||||
}
|
||||
// 非外链并且是一级目录(类型为菜单)
|
||||
else if (isMenuFrame(menu)) {
|
||||
routerPath = "/";
|
||||
}
|
||||
return routerPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取组件信息
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 组件信息
|
||||
*/
|
||||
public String getComponent(SysMenu menu) {
|
||||
String component = Constant.LAYOUT;
|
||||
if (StringUtils.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu)) {
|
||||
component = menu.getComponent();
|
||||
} else if (StringUtils.isEmpty(menu.getComponent()) && menu.getParentId().intValue() != 0 && isInnerLink(menu)) {
|
||||
component = Constant.INNER_LINK;
|
||||
} else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu)) {
|
||||
component = Constant.PARENT_VIEW;
|
||||
}
|
||||
return component;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为菜单内部跳转
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean isMenuFrame(SysMenu menu) {
|
||||
return menu.getParentId().intValue() == 0 && Constant.TYPE_MENU.equals(menu.getMenuType())
|
||||
&& menu.getIsFrame().equals(Constant.NO_FRAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为内链组件
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean isInnerLink(SysMenu menu) {
|
||||
return menu.getIsFrame().equals(Constant.NO_FRAME) && HttpUtil.isHttp(menu.getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为parent_view组件
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean isParentView(SysMenu menu) {
|
||||
return menu.getParentId().intValue() != 0 && Constant.TYPE_DIR.equals(menu.getMenuType());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据父节点的ID获取所有子节点
|
||||
*
|
||||
* @param list 分类表
|
||||
* @param parentId 传入的父节点ID
|
||||
* @return String
|
||||
*/
|
||||
public List<SysMenu> getChildPerms(List<SysMenu> list, int parentId) {
|
||||
List<SysMenu> returnList = new ArrayList<SysMenu>();
|
||||
for (SysMenu t : list) {
|
||||
// 一、根据传入的某个父节点ID,遍历该父节点的所有子节点
|
||||
if (t.getParentId() == parentId) {
|
||||
recursionFn(list, t);
|
||||
returnList.add(t);
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归列表
|
||||
*
|
||||
* @param list
|
||||
* @param t
|
||||
*/
|
||||
private void recursionFn(List<SysMenu> list, SysMenu t) {
|
||||
// 得到子节点列表
|
||||
List<SysMenu> childList = getChildList(list, t);
|
||||
t.setChildren(childList);
|
||||
for (SysMenu tChild : childList) {
|
||||
if (hasChild(list, tChild)) {
|
||||
recursionFn(list, tChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到子节点列表
|
||||
*/
|
||||
private List<SysMenu> getChildList(List<SysMenu> list, SysMenu t) {
|
||||
List<SysMenu> tlist = new ArrayList<SysMenu>();
|
||||
for (SysMenu n : list) {
|
||||
if (n.getParentId().longValue() == t.getMenuId().longValue()) {
|
||||
tlist.add(n);
|
||||
}
|
||||
}
|
||||
return tlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否有子节点
|
||||
*/
|
||||
private boolean hasChild(List<SysMenu> list, SysMenu t) {
|
||||
return getChildList(list, t).size() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 内链域名特殊字符替换
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String innerLinkReplaceEach(String path) {
|
||||
return StringUtils.replaceEach(path, new String[]{Constant.HTTP, Constant.HTTPS, Constant.WWW, "."},
|
||||
new String[]{"", ""});
|
||||
}
|
||||
}
|
@ -0,0 +1,409 @@
|
||||
package com.glxp.api.admin.service.auth.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.glxp.api.admin.constant.Constant;
|
||||
import com.glxp.api.admin.dao.auth.SysRoleMapper;
|
||||
import com.glxp.api.admin.dao.auth.SysRoleMenuMapper;
|
||||
import com.glxp.api.admin.dao.auth.SysUserRoleMapper;
|
||||
import com.glxp.api.admin.entity.auth.SysRole;
|
||||
import com.glxp.api.admin.entity.auth.SysRoleMenu;
|
||||
import com.glxp.api.admin.entity.auth.SysUserRole;
|
||||
import com.glxp.api.admin.exception.ServiceException;
|
||||
import com.glxp.api.admin.req.auth.SysRoleRequest;
|
||||
import com.glxp.api.admin.req.auth.SysUserRoleRequest;
|
||||
import com.glxp.api.admin.service.auth.ISysRoleService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 角色 业务层处理
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class SysRoleServiceImpl implements ISysRoleService {
|
||||
|
||||
|
||||
@Resource
|
||||
SysRoleMapper sysRoleMapper;
|
||||
@Resource
|
||||
SysRoleMenuMapper roleMenuMapper;
|
||||
@Resource
|
||||
SysUserRoleMapper sysUserRoleMapper;
|
||||
|
||||
@Override
|
||||
public List<SysRole> selectPageRoleList(SysRoleRequest sysRoleRequest) {
|
||||
|
||||
if (sysRoleRequest.getPage() != null) {
|
||||
int offset = (sysRoleRequest.getPage() - 1) * sysRoleRequest.getLimit();
|
||||
PageHelper.offsetPage(offset, sysRoleRequest.getLimit());
|
||||
}
|
||||
return sysRoleMapper.selectRoleList(sysRoleRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据条件分页查询角色数据
|
||||
*/
|
||||
@Override
|
||||
public List<SysRole> selectRoleList(SysRoleRequest sysRoleRequest) {
|
||||
return sysRoleMapper.selectRoleList(sysRoleRequest);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色
|
||||
*/
|
||||
@Override
|
||||
public List<SysRole> selectRolesByUserId(Long userId) {
|
||||
List<SysRole> userRoles = sysRoleMapper.selectRolePermissionByUserId(userId);
|
||||
List<SysRole> roles = selectRoleAll();
|
||||
for (SysRole role : roles) {
|
||||
for (SysRole userRole : userRoles) {
|
||||
if (role.getRoleId().longValue() == userRole.getRoleId().longValue()) {
|
||||
role.setFlag(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询权限
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 权限列表
|
||||
*/
|
||||
@Override
|
||||
public Set<String> selectRolePermissionByUserId(Long userId) {
|
||||
List<SysRole> perms = sysRoleMapper.selectRolePermissionByUserId(userId);
|
||||
Set<String> permsSet = new HashSet<>();
|
||||
for (SysRole perm : perms) {
|
||||
if (ObjectUtil.isNotNull(perm)) {
|
||||
permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(",")));
|
||||
}
|
||||
}
|
||||
return permsSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有角色
|
||||
*
|
||||
* @return 角色列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysRole> selectRoleAll() {
|
||||
return this.selectRoleList(new SysRoleRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID获取角色选择框列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 选中角色ID列表
|
||||
*/
|
||||
@Override
|
||||
public List<Long> selectRoleListByUserId(Long userId) {
|
||||
return sysRoleMapper.selectRoleListByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过角色ID查询角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 角色对象信息
|
||||
*/
|
||||
@Override
|
||||
public SysRole selectRoleById(Long roleId) {
|
||||
return sysRoleMapper.selectById(roleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验角色名称是否唯一
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public String checkRoleNameUnique(SysRole role) {
|
||||
|
||||
SysRoleRequest sysRoleRequest = new SysRoleRequest();
|
||||
sysRoleRequest.setRoleName(role.getRoleName());
|
||||
sysRoleRequest.setNeRoleId(role.getRoleId());
|
||||
List<SysRole> sysRoles = sysRoleMapper.selectRoleList(sysRoleRequest);
|
||||
if (CollUtil.isNotEmpty(sysRoles)) {
|
||||
return Constant.NOT_UNIQUE;
|
||||
} else {
|
||||
return Constant.UNIQUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验角色权限是否唯一
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public String checkRoleKeyUnique(SysRole role) {
|
||||
|
||||
|
||||
SysRoleRequest sysRoleRequest = new SysRoleRequest();
|
||||
sysRoleRequest.setRoleKey(role.getRoleKey());
|
||||
sysRoleRequest.setNeRoleId(role.getRoleId());
|
||||
List<SysRole> sysRoles = sysRoleMapper.selectRoleList(sysRoleRequest);
|
||||
if (CollUtil.isNotEmpty(sysRoles)) {
|
||||
return Constant.NOT_UNIQUE;
|
||||
} else {
|
||||
return Constant.UNIQUE;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验角色是否允许操作
|
||||
*
|
||||
* @param role 角色信息
|
||||
*/
|
||||
@Override
|
||||
public void checkRoleAllowed(SysRole role) {
|
||||
if (ObjectUtil.isNotNull(role.getRoleId()) && role.isAdmin()) {
|
||||
throw new ServiceException("不允许操作超级管理员角色");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验角色是否有数据权限
|
||||
*
|
||||
* @param roleId 角色id
|
||||
*/
|
||||
@Override
|
||||
public void checkRoleDataScope(Long roleId) {
|
||||
if (roleId != 1) {
|
||||
SysRoleRequest roleRequest = new SysRoleRequest();
|
||||
roleRequest.setRoleId(roleId);
|
||||
List<SysRole> roles = this.selectRoleList(roleRequest);
|
||||
if (CollUtil.isEmpty(roles)) {
|
||||
throw new ServiceException("没有权限访问角色数据!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过角色ID查询角色使用数量
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public long countUserRoleByRoleId(Long roleId) {
|
||||
List<Long> ids = sysUserRoleMapper.selectUserIdsByRoleId(roleId);
|
||||
return ids.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增保存角色信息
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int insertRole(SysRole role) {
|
||||
// 新增角色信息
|
||||
sysRoleMapper.insert(role);
|
||||
return insertRoleMenu(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改保存角色信息
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int updateRole(SysRole role) {
|
||||
// 修改角色信息
|
||||
sysRoleMapper.updateById(role);
|
||||
// 删除角色与菜单关联
|
||||
roleMenuMapper.deleteById(role.getRoleId());
|
||||
return insertRoleMenu(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改角色状态
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateRoleStatus(SysRole role) {
|
||||
return sysRoleMapper.updateById(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据权限信息
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int authDataScope(SysRole role) {
|
||||
// 修改角色信息
|
||||
sysRoleMapper.updateById(role);
|
||||
// 删除角色与部门关联
|
||||
// roleDeptMapper.delete(new LambdaQueryWrapper<SysRoleDept>().eq(SysRoleDept::getRoleId, role.getRoleId()));
|
||||
// // 新增角色和部门信息(数据权限)
|
||||
// return insertRoleDept(role);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增角色菜单信息
|
||||
*
|
||||
* @param role 角色对象
|
||||
*/
|
||||
public int insertRoleMenu(SysRole role) {
|
||||
int rows = 1;
|
||||
// 新增用户与角色管理
|
||||
List<SysRoleMenu> list = new ArrayList<SysRoleMenu>();
|
||||
for (Long menuId : role.getMenuIds()) {
|
||||
SysRoleMenu rm = new SysRoleMenu();
|
||||
rm.setRoleId(role.getRoleId());
|
||||
rm.setMenuId(menuId);
|
||||
list.add(rm);
|
||||
}
|
||||
if (list.size() > 0) {
|
||||
roleMenuMapper.insertBatch(list);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增角色部门信息(数据权限)
|
||||
*
|
||||
* @param role 角色对象
|
||||
*/
|
||||
// public int insertRoleDept(SysRole role) {
|
||||
// int rows = 1;
|
||||
// // 新增角色与部门(数据权限)管理
|
||||
// List<SysRoleDept> list = new ArrayList<SysRoleDept>();
|
||||
// for (Long deptId : role.getDeptIds()) {
|
||||
// SysRoleDept rd = new SysRoleDept();
|
||||
// rd.setRoleId(role.getRoleId());
|
||||
// rd.setDeptId(deptId);
|
||||
// list.add(rd);
|
||||
// }
|
||||
// if (list.size() > 0) {
|
||||
// rows = roleDeptMapper.insertBatch(list) ? list.size() : 0;
|
||||
// }
|
||||
// return rows;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 通过角色ID删除角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int deleteRoleById(Long roleId) {
|
||||
// 删除角色与菜单关联
|
||||
roleMenuMapper.deleteById(roleId);
|
||||
// 删除角色与部门关联
|
||||
return sysRoleMapper.delete(roleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除角色信息
|
||||
*
|
||||
* @param roleIds 需要删除的角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int deleteRoleByIds(Long[] roleIds) {
|
||||
for (Long roleId : roleIds) {
|
||||
checkRoleAllowed(new SysRole(roleId));
|
||||
checkRoleDataScope(roleId);
|
||||
SysRole role = selectRoleById(roleId);
|
||||
if (countUserRoleByRoleId(roleId) > 0) {
|
||||
throw new ServiceException(String.format("%1$s已分配,不能删除", role.getRoleName()));
|
||||
}
|
||||
}
|
||||
List<Long> ids = Arrays.asList(roleIds);
|
||||
// 删除角色与菜单关联
|
||||
roleMenuMapper.deleteByList(ids);
|
||||
// 删除角色与部门关联
|
||||
// roleDeptMapper.delete(new LambdaQueryWrapper<SysRoleDept>().in(SysRoleDept::getRoleId, ids));
|
||||
return sysRoleMapper.deleteBatchIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消授权用户角色
|
||||
*
|
||||
* @param userRole 用户和角色关联信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteAuthUser(SysUserRole userRole) {
|
||||
SysUserRoleRequest sysUserRoleRequest = new SysUserRoleRequest();
|
||||
|
||||
return sysUserRoleMapper.delete(sysUserRoleRequest);
|
||||
|
||||
// return sysUserRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>()
|
||||
// .eq(SysUserRole::getRoleId, userRole.getRoleId())
|
||||
// .eq(SysUserRole::getUserId, userRole.getUserId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量取消授权用户角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param userIds 需要取消授权的用户数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteAuthUsers(Long roleId, Long[] userIds) {
|
||||
|
||||
|
||||
SysUserRoleRequest sysUserRoleRequest = new SysUserRoleRequest();
|
||||
return sysUserRoleMapper.delete(sysUserRoleRequest);
|
||||
// return sysUserRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>()
|
||||
// .eq(SysUserRole::getRoleId, roleId)
|
||||
// .in(SysUserRole::getUserId, Arrays.asList(userIds)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量选择授权用户角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param userIds 需要授权的用户数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertAuthUsers(Long roleId, Long[] userIds) {
|
||||
// 新增用户与角色管理
|
||||
int rows = 1;
|
||||
List<SysUserRole> list = new ArrayList<SysUserRole>();
|
||||
for (Long userId : userIds) {
|
||||
SysUserRole ur = new SysUserRole();
|
||||
ur.setUserId(userId);
|
||||
ur.setRoleId(roleId);
|
||||
list.add(ur);
|
||||
}
|
||||
if (list.size() > 0) {
|
||||
sysUserRoleMapper.insertBatch(list);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.glxp.api.admin.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.lang.tree.TreeNodeConfig;
|
||||
import cn.hutool.core.lang.tree.TreeUtil;
|
||||
import cn.hutool.core.lang.tree.parser.NodeParser;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 扩展 hutool TreeUtil 封装系统树构建
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class TreeBuildUtils extends TreeUtil {
|
||||
|
||||
/**
|
||||
* 根据前端定制差异化字段
|
||||
*/
|
||||
public static final TreeNodeConfig DEFAULT_CONFIG = TreeNodeConfig.DEFAULT_CONFIG.setNameKey("label");
|
||||
|
||||
public static <T, K> List<Tree<K>> build(List<T> list, NodeParser<T, K> nodeParser) {
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return null;
|
||||
}
|
||||
K k = ReflectUtils.invokeGetter(list.get(0), "parentId");
|
||||
return TreeUtil.build(list, k, DEFAULT_CONFIG, nodeParser);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.glxp.api.admin.dao.auth.SysDictDataMapper">
|
||||
|
||||
<resultMap type="com.glxp.api.admin.entity.auth.SysDictData" id="SysDictDataResult">
|
||||
<id property="dictCode" column="dict_code"/>
|
||||
<result property="dictSort" column="dict_sort"/>
|
||||
<result property="dictLabel" column="dict_label"/>
|
||||
<result property="dictValue" column="dict_value"/>
|
||||
<result property="dictType" column="dict_type"/>
|
||||
<result property="cssClass" column="css_class"/>
|
||||
<result property="listClass" column="list_class"/>
|
||||
<result property="isDefault" column="is_default"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
<select id="selectDictDataList" parameterType="com.glxp.api.admin.req.auth.SysDictDataRequest"
|
||||
resultMap="SysDictDataResult">
|
||||
SELECT *
|
||||
FROM sys_dict_data
|
||||
<where>
|
||||
<if test="dictType != null ">
|
||||
and dict_type = #{dictType}
|
||||
</if>
|
||||
<if test="status != null ">
|
||||
and status = #{status}
|
||||
</if>
|
||||
<if test="dictLabel != null ">
|
||||
and dict_label = #{dictLabel}
|
||||
</if>
|
||||
<if test="dictValue != null ">
|
||||
and dict_value = #{dictValue}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectById" parameterType="Map"
|
||||
resultMap="SysDictDataResult">
|
||||
SELECT *
|
||||
FROM sys_dict_data
|
||||
WHERE dict_code = #{dictCode}
|
||||
</select>
|
||||
<delete id="deleteById" parameterType="java.lang.Long">
|
||||
delete
|
||||
from sys_dict_data
|
||||
where dict_code = #{dictCode}
|
||||
</delete>
|
||||
|
||||
|
||||
<insert id="insert" keyProperty="id" useGeneratedKeys="true"
|
||||
parameterType="com.glxp.api.admin.entity.auth.SysDictData">
|
||||
INSERT INTO sys_dict_data(`dict_code`, `dict_sort`, dict_label, dict_value
|
||||
, dict_type, css_class, list_class, is_default, status, remark,
|
||||
create_by, create_time, update_by)
|
||||
values (#{dictCode},
|
||||
#{dictSort}, #{dictLabel}, #{dictValue}, #{dictType}, #{cssClass}, #{listClass}
|
||||
, #{isDefault}, #{status}, #{remark}, #{createBy}, #{createTime}, #{updateBy})
|
||||
</insert>
|
||||
|
||||
|
||||
<update id="updateById" parameterType="com.glxp.api.admin.entity.auth.SysRole">
|
||||
UPDATE sys_dict_data
|
||||
<trim prefix="set" suffixOverrides=",">
|
||||
<if test="dictCode != null">`dict_code`=#{dictCode},</if>
|
||||
<if test="dictSort != null">`dict_sort`=#{dictSort},</if>
|
||||
<if test="dictLabel != null">dict_label=#{dictLabel},</if>
|
||||
<if test="dictValue != null">`dict_value`=#{dictValue},</if>
|
||||
<if test="dictType != null">dict_type=#{dictType},</if>
|
||||
<if test="cssClass != null">`css_class`=#{cssClass},</if>
|
||||
<if test="listClass != null">`list_class`=#{listClass},</if>
|
||||
<if test="isDefault != null">is_default=#{isDefault},</if>
|
||||
<if test="status != null">status=#{status},</if>
|
||||
<if test="remark != null">remark=#{remark},</if>
|
||||
<if test="createBy != null">create_by=#{createBy},</if>
|
||||
<if test="createTime != null">`create_time`=#{createTime},</if>
|
||||
<if test="updateBy != null">`update_by`=#{updateBy},</if>
|
||||
</trim>
|
||||
WHERE dict_code=#{dictCode}
|
||||
</update>
|
||||
|
||||
|
||||
<select id="exists" parameterType="com.glxp.api.admin.req.auth.SysDictDataRequest"
|
||||
resultMap="SysDictDataResult">
|
||||
SELECT *
|
||||
FROM sys_dict_data
|
||||
<where>
|
||||
<if test="dictType != null ">
|
||||
and dict_type = #{dictType}
|
||||
</if>
|
||||
<if test="status != null ">
|
||||
and status = #{status}
|
||||
</if>
|
||||
<if test="dictLabel != null ">
|
||||
and dict_label = #{dictLabel}
|
||||
</if>
|
||||
<if test="dictValue != null ">
|
||||
and dict_value = #{dictValue}
|
||||
</if>
|
||||
</where>
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -0,0 +1,113 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.glxp.api.admin.dao.auth.SysDictTypeMapper">
|
||||
|
||||
<resultMap type="com.glxp.api.admin.entity.auth.SysDictType" id="SysDictTypeResult">
|
||||
<id property="dictId" column="dict_id"/>
|
||||
<result property="dictName" column="dict_name"/>
|
||||
<result property="dictType" column="dict_type"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
<select id="selectDictTypeList" parameterType="com.glxp.api.admin.req.auth.SysDictTypeRequest"
|
||||
resultMap="SysDictTypeResult">
|
||||
SELECT *
|
||||
FROM sys_dict_type
|
||||
<where>
|
||||
<if test="dictId != null ">
|
||||
and dict_type = #{dictId}
|
||||
</if>
|
||||
<if test="dictName != null ">
|
||||
and status = #{dictName}
|
||||
</if>
|
||||
<if test="dictType != null ">
|
||||
and dict_label = #{dictType}
|
||||
</if>
|
||||
<if test="status != null ">
|
||||
and status = #{status}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="selectById" parameterType="Map"
|
||||
resultMap="SysDictTypeResult">
|
||||
SELECT *
|
||||
FROM sys_dict_type
|
||||
WHERE dict_id = #{dictId}
|
||||
</select>
|
||||
|
||||
<delete id="deleteById" parameterType="java.lang.Long">
|
||||
delete
|
||||
from sys_dict_type
|
||||
where dict_id = #{dictId}
|
||||
</delete>
|
||||
|
||||
|
||||
<delete id="deleteBatchIds" parameterType="java.util.List"
|
||||
>
|
||||
delete
|
||||
from sys_dict_type
|
||||
where dict_id in
|
||||
<foreach item="item" index="index" collection="dictIds" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
|
||||
</delete>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<insert id="insert" keyProperty="id" useGeneratedKeys="true"
|
||||
parameterType="com.glxp.api.admin.entity.auth.SysDictData">
|
||||
INSERT INTO sys_dict_type(`dict_id`, dict_name, `dict_type`, status
|
||||
create_by, create_time, update_by, update_time)
|
||||
values (#{dictId},
|
||||
#{dictName}, #{dictType}, #{status}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime})
|
||||
</insert>
|
||||
|
||||
|
||||
<update id="updateById" parameterType="com.glxp.api.admin.entity.auth.SysRole">
|
||||
UPDATE sys_dict_type
|
||||
<trim prefix="set" suffixOverrides=",">
|
||||
<if test="dictName != null">`dict_name`=#{dictName},</if>
|
||||
<if test="dictType != null">dict_type=#{dictType},</if>
|
||||
<if test="status != null">`status`=#{status},</if>
|
||||
<if test="updateTime != null">update_time=#{updateTime},</if>
|
||||
<if test="createBy != null">create_by=#{createBy},</if>
|
||||
<if test="createTime != null">`create_time`=#{createTime},</if>
|
||||
<if test="updateBy != null">`update_by`=#{updateBy},</if>
|
||||
</trim>
|
||||
WHERE dict_id=#{dictId}
|
||||
</update>
|
||||
|
||||
|
||||
<select id="exists" parameterType="com.glxp.api.admin.req.auth.SysDictTypeRequest"
|
||||
resultMap="SysDictTypeResult">
|
||||
SELECT *
|
||||
FROM sys_dict_type
|
||||
<where>
|
||||
<if test="dictType != null ">
|
||||
and dict_type = #{dictType}
|
||||
</if>
|
||||
<if test="status != null ">
|
||||
and status = #{status}
|
||||
</if>
|
||||
<if test="dictLabel != null ">
|
||||
and dict_label = #{dictLabel}
|
||||
</if>
|
||||
<if test="dictValue != null ">
|
||||
and dict_value = #{dictValue}
|
||||
</if>
|
||||
</where>
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
@ -0,0 +1,210 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.glxp.api.admin.dao.auth.SysMenuDao">
|
||||
|
||||
<resultMap type="com.glxp.api.admin.entity.auth.SysMenu" id="SysMenuResult">
|
||||
<id property="menuId" column="menu_id"/>
|
||||
<result property="menuName" column="menu_name"/>
|
||||
<result property="parentName" column="parent_name"/>
|
||||
<result property="parentId" column="parent_id"/>
|
||||
<result property="orderNum" column="order_num"/>
|
||||
<result property="path" column="path"/>
|
||||
<result property="component" column="component"/>
|
||||
<result property="queryParam" column="query_param"/>
|
||||
<result property="isFrame" column="is_frame"/>
|
||||
<result property="isCache" column="is_cache"/>
|
||||
<result property="menuType" column="menu_type"/>
|
||||
<result property="visible" column="visible"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="perms" column="perms"/>
|
||||
<result property="icon" column="icon"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="remark" column="remark"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
<select id="selectById" parameterType="java.lang.Long"
|
||||
resultMap="SysMenuResult">
|
||||
select *
|
||||
FROM sys_menu
|
||||
WHERE menu_id = #{id}
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="insert" keyProperty="id" parameterType="com.glxp.api.admin.entity.auth.SysMenu">
|
||||
INSERT INTO sys_menu(`menu_id`, `menu_name`, parent_id, `order_num`, `path`, component
|
||||
, query_param, is_frame, is_cache, menu_type, visible, status, perms, icon,
|
||||
remark, create_by, create_time, update_time, update_by)
|
||||
values (#{menuId},
|
||||
#{menuName}, #{parentId},
|
||||
#{orderNum}, #{path}, #{component}, #{queryParam}, #{isFrame}, #{isCache}
|
||||
, #{menuType}, #{visible}, #{status}, #{perms}, #{icon}, #{remark}
|
||||
, #{createBy}, #{createTime}, #{updateTime}, #{updateBy})
|
||||
</insert>
|
||||
|
||||
<update id="updateById" parameterType="com.glxp.api.admin.entity.auth.SysMenu">
|
||||
UPDATE sys_menu
|
||||
<trim prefix="set" suffixOverrides=",">
|
||||
<if test="menuName != null">`menu_name`=#{menuName},</if>
|
||||
<if test="parentId != null">`parent_id`=#{parentId},</if>
|
||||
<if test="orderNum != null">order_num=#{orderNum},</if>
|
||||
<if test="path != null">`path`=#{path},</if>
|
||||
<if test="component != null">component=#{component},</if>
|
||||
<if test="queryParam != null">`query_param`=#{queryParam},</if>
|
||||
<if test="isFrame != null">is_frame=#{isFrame},</if>
|
||||
<if test="isCache != null">is_cache=#{isCache},</if>
|
||||
<if test="updateTime != null">updateTime=#{updateTime},</if>
|
||||
<if test="menuType != null">`menu_type`=#{menuType},</if>
|
||||
<if test="visible != null">`visible`=#{visible},</if>
|
||||
<if test="status != null">status=#{status},</if>
|
||||
<if test="perms != null">perms=#{perms},</if>
|
||||
<if test="icon != null">icon=#{icon},</if>
|
||||
<if test="remark != null">remark=#{remark},</if>
|
||||
<if test="createBy != null">create_by=#{createBy},</if>
|
||||
<if test="createTime != null">create_time=#{createTime},</if>
|
||||
<if test="updateTime != null">update_time=#{updateTime},</if>
|
||||
<if test="updateBy != null">update_by=#{updateBy},</if>
|
||||
</trim>
|
||||
WHERE menu_id=#{menuId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteById" parameterType="java.lang.Long">
|
||||
delete
|
||||
from sys_menu
|
||||
where menu_id = #{id}
|
||||
</delete>
|
||||
|
||||
<select id="selectMenuTreeAll" parameterType="com.glxp.api.admin.entity.auth.SysMenu"
|
||||
resultMap="SysMenuResult">
|
||||
|
||||
select *
|
||||
FROM sys_menu
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectMenuList" parameterType="com.glxp.api.admin.req.auth.SysMenuRequest"
|
||||
resultMap="SysMenuResult">
|
||||
|
||||
select *
|
||||
FROM sys_menu
|
||||
<where>
|
||||
<if test="menuId != null ">
|
||||
and menu_id = #{menuId}
|
||||
</if>
|
||||
<if test="menuName != null and menuName != '' ">
|
||||
AND `menu_name` = #{menuName}
|
||||
</if>
|
||||
<if test="parentName != null and parentName != '' ">
|
||||
AND `parent_name` = #{parentName}
|
||||
</if>
|
||||
<if test="parentId != null ">
|
||||
AND `parent_id` = #{parentId}
|
||||
</if>
|
||||
<if test="orderNum != null ">
|
||||
AND `order_num` = #{orderNum}
|
||||
</if>
|
||||
|
||||
<if test="neMenuId != null ">
|
||||
and menu_id <![CDATA[ <> ]]> #{neMenuId}
|
||||
</if>
|
||||
|
||||
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectMenuListByUserId" parameterType="com.glxp.api.admin.entity.auth.SysMenu"
|
||||
resultMap="SysMenuResult">
|
||||
select distinct m.menu_id,
|
||||
m.parent_id,
|
||||
m.menu_name,
|
||||
m.path,
|
||||
m.component,
|
||||
m.query_param,
|
||||
m.visible,
|
||||
m.status,
|
||||
m.perms,
|
||||
m.is_frame,
|
||||
m.is_cache,
|
||||
m.menu_type,
|
||||
m.icon,
|
||||
m.order_num,
|
||||
m.create_time
|
||||
from sys_menu m
|
||||
left join sys_role_menu rm on m.menu_id = rm.menu_id
|
||||
left join sys_user_role sur on rm.role_id = sur.role_id
|
||||
left join sys_role ro on sur.role_id = ro.role_id
|
||||
</select>
|
||||
|
||||
<select id="selectMenuTreeByUserId" parameterType="Long" resultMap="SysMenuResult">
|
||||
select distinct m.menu_id,
|
||||
m.parent_id,
|
||||
m.menu_name,
|
||||
m.path,
|
||||
m.component,
|
||||
m.query_param,
|
||||
m.visible,
|
||||
m.status,
|
||||
m.perms,
|
||||
m.is_frame,
|
||||
m.is_cache,
|
||||
m.menu_type,
|
||||
m.icon,
|
||||
m.order_num,
|
||||
m.create_time
|
||||
from sys_menu m
|
||||
left join sys_role_menu rm on m.menu_id = rm.menu_id
|
||||
left join sys_user_role sur on rm.role_id = sur.role_id
|
||||
left join sys_role ro on sur.role_id = ro.role_id
|
||||
left join auth_user u on sur.user_id = u.id
|
||||
where u.id = #{userId}
|
||||
and m.menu_type in ('M', 'C')
|
||||
and m.status = '0'
|
||||
and ro.status = '0'
|
||||
order by m.parent_id, m.order_num
|
||||
</select>
|
||||
|
||||
<select id="selectMenuListByRoleId" resultType="Long">
|
||||
select m.menu_id
|
||||
from sys_menu m
|
||||
left join sys_role_menu rm on m.menu_id = rm.menu_id
|
||||
where rm.role_id = #{roleId}
|
||||
<if test="menuCheckStrictly">
|
||||
and m.menu_id not in (select m.parent_id from sys_menu m inner join sys_role_menu rm on m.menu_id =
|
||||
rm.menu_id and rm.role_id = #{roleId})
|
||||
</if>
|
||||
order by m.parent_id, m.order_num
|
||||
</select>
|
||||
|
||||
<select id="selectMenuPerms" resultType="String">
|
||||
select distinct m.perms
|
||||
from sys_menu m
|
||||
left join sys_role_menu rm on m.menu_id = rm.menu_id
|
||||
left join sys_user_role sur on rm.role_id = sur.role_id
|
||||
</select>
|
||||
|
||||
<select id="selectMenuPermsByUserId" parameterType="Long" resultType="String">
|
||||
select distinct m.perms
|
||||
from sys_menu m
|
||||
left join sys_role_menu rm on m.menu_id = rm.menu_id
|
||||
left join sys_user_role sur on rm.role_id = sur.role_id
|
||||
left join sys_role r on r.role_id = sur.role_id
|
||||
where m.status = '0'
|
||||
and r.status = '0'
|
||||
and sur.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="selectMenuPermsByRoleId" parameterType="Long" resultType="String">
|
||||
select distinct m.perms
|
||||
from sys_menu m
|
||||
left join sys_role_menu rm on m.menu_id = rm.menu_id
|
||||
where m.status = '0'
|
||||
and rm.role_id = #{roleId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -0,0 +1,174 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.glxp.api.admin.dao.auth.SysRoleMapper">
|
||||
|
||||
<resultMap type="com.glxp.api.admin.entity.auth.SysRole" id="SysRoleResult">
|
||||
<id property="roleId" column="role_id"/>
|
||||
<result property="roleName" column="role_name"/>
|
||||
<result property="roleKey" column="role_key"/>
|
||||
<result property="roleSort" column="role_sort"/>
|
||||
<result property="dataScope" column="data_scope"/>
|
||||
<result property="menuCheckStrictly" column="menu_check_strictly"/>
|
||||
<result property="deptCheckStrictly" column="dept_check_strictly"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="delFlag" column="del_flag"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="remark" column="remark"/>
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert" keyProperty="roleId" useGeneratedKeys="true"
|
||||
parameterType="com.glxp.api.admin.entity.auth.SysRole">
|
||||
INSERT INTO sys_role(`role_name`, `role_key`, role_sort, data_scope
|
||||
, menu_check_strictly, dept_check_strictly, status, del_flag, remark,
|
||||
create_by, create_time, update_by)
|
||||
values (#{roleName},
|
||||
#{roleKey}, #{roleSort}, #{dataScope}, #{menuCheckStrictly}, #{deptCheckStrictly}, #{status}
|
||||
, #{delFlag}, #{remark}, #{createBy}, #{createTime}, #{updateBy})
|
||||
</insert>
|
||||
|
||||
|
||||
<update id="updateById" parameterType="com.glxp.api.admin.entity.auth.SysRole">
|
||||
UPDATE sys_role
|
||||
<trim prefix="set" suffixOverrides=",">
|
||||
<if test="roleName != null">`role_name`=#{roleName},</if>
|
||||
<if test="roleKey != null">`role_key`=#{roleKey},</if>
|
||||
<if test="roleSort != null">role_sort=#{roleSort},</if>
|
||||
<if test="dataScope != null">`data_scope`=#{dataScope},</if>
|
||||
<if test="menuCheckStrictly != null">menu_check_strictly=#{menuCheckStrictly},</if>
|
||||
<if test="deptCheckStrictly != null">`dept_check_strictly`=#{deptCheckStrictly},</if>
|
||||
<if test="status != null">`status`=#{status},</if>
|
||||
<if test="delFlag != null">del_flag=#{delFlag},</if>
|
||||
<if test="remark != null">remark=#{remark},</if>
|
||||
<if test="createBy != null">create_by=#{createBy},</if>
|
||||
<if test="createTime != null">`create_time`=#{createTime},</if>
|
||||
<if test="updateBy != null">`update_by`=#{updateBy},</if>
|
||||
<if test="updateTime != null">`update_time`=#{updateTime},</if>
|
||||
</trim>
|
||||
WHERE role_id=#{roleId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteBatchIds" parameterType="java.util.List"
|
||||
>
|
||||
delete
|
||||
from sys_role
|
||||
where role_id in
|
||||
<foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
|
||||
</delete>
|
||||
|
||||
|
||||
<delete id="deleteById" parameterType="java.lang.Long">
|
||||
delete
|
||||
from sys_role
|
||||
where role_id = #{id}
|
||||
</delete>
|
||||
|
||||
|
||||
<select id="selectById" parameterType="java.lang.Long"
|
||||
resultMap="SysRoleResult">
|
||||
select *
|
||||
FROM sys_role
|
||||
WHERE role_id = #{id}
|
||||
</select>
|
||||
|
||||
<sql id="selectRoleVo">
|
||||
select distinct r.role_id,
|
||||
r.role_name,
|
||||
r.role_key,
|
||||
r.role_sort,
|
||||
r.data_scope,
|
||||
r.menu_check_strictly,
|
||||
r.dept_check_strictly,
|
||||
r.status,
|
||||
r.del_flag,
|
||||
r.create_time,
|
||||
r.remark
|
||||
from sys_role r
|
||||
left join sys_user_role sur on sur.role_id = r.role_id
|
||||
left join auth_user u on u.id = sur.user_id
|
||||
</sql>
|
||||
|
||||
|
||||
<select id="selectRoleList" parameterType="com.glxp.api.admin.req.auth.SysRoleRequest"
|
||||
resultMap="SysRoleResult">
|
||||
SELECT *
|
||||
FROM sys_role
|
||||
<where>
|
||||
<if test="roleId != null ">
|
||||
and role_id = #{roleId}
|
||||
</if>
|
||||
<if test="roleName != null and roleName != ''">
|
||||
AND `role_name` = #{roleName}
|
||||
</if>
|
||||
<if test="roleKey != null and roleKey != ''">
|
||||
AND `role_key` = #{roleKey}
|
||||
</if>
|
||||
<if test="neRoleName != null and neRoleName != ''">
|
||||
AND `role_name` <![CDATA[ <> ]]> #{neRoleName}
|
||||
</if>
|
||||
<if test="neRoleKey != null and neRoleKey != ''">
|
||||
AND `role_key` <![CDATA[ <> ]]> #{neRoleKey}
|
||||
</if>
|
||||
<if test="neRoleId != null ">
|
||||
AND `role_id` <![CDATA[ <> ]]> #{neRoleId}
|
||||
</if>
|
||||
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult">
|
||||
|
||||
select distinct r.role_id,
|
||||
r.role_name,
|
||||
r.role_key,
|
||||
r.role_sort,
|
||||
r.data_scope,
|
||||
r.menu_check_strictly,
|
||||
r.dept_check_strictly,
|
||||
r.status,
|
||||
r.del_flag,
|
||||
r.create_time,
|
||||
r.remark
|
||||
from sys_role r
|
||||
left join sys_user_role sur on sur.role_id = r.role_id
|
||||
left join auth_user u on u.id = sur.user_id
|
||||
WHERE sur.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="selectRoleListByUserId" parameterType="Long" resultType="Long">
|
||||
select r.role_id
|
||||
from sys_role r
|
||||
left join sys_user_role sur on sur.role_id = r.role_id
|
||||
left join auth_user u on u.id = sur.user_id
|
||||
where u.id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="selectRolesByUserName" parameterType="String" resultMap="SysRoleResult">
|
||||
|
||||
select distinct r.role_id,
|
||||
r.role_name,
|
||||
r.role_key,
|
||||
r.role_sort,
|
||||
r.data_scope,
|
||||
r.menu_check_strictly,
|
||||
r.dept_check_strictly,
|
||||
r.status,
|
||||
r.del_flag,
|
||||
r.create_time,
|
||||
r.remark
|
||||
from sys_role r
|
||||
left join sys_user_role sur on sur.role_id = r.role_id
|
||||
left join auth_user u on u.id = sur.user_id
|
||||
|
||||
WHERE u.userName = #{userName}
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.glxp.api.admin.dao.auth.SysRoleMenuMapper">
|
||||
|
||||
<resultMap type="com.glxp.api.admin.entity.auth.SysRoleMenu" id="SysRoleMenuResult">
|
||||
<result property="roleId" column="role_id"/>
|
||||
<result property="menuId" column="menu_id"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
<select id="selectRoleMenuList" parameterType="com.glxp.api.admin.req.auth.SysRoleMenuRequest"
|
||||
resultMap="SysRoleMenuResult">
|
||||
SELECT *
|
||||
FROM sys_role_menu
|
||||
<where>
|
||||
<if test="roleId != null ">
|
||||
and role_id = #{roleId}
|
||||
</if>
|
||||
<if test="menuId != null ">
|
||||
and menu_id = #{menuId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<delete id="deleteById" parameterType="java.lang.Long">
|
||||
delete
|
||||
from sys_role_menu
|
||||
where role_id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByList" parameterType="java.util.List"
|
||||
>
|
||||
delete
|
||||
from sys_role_menu
|
||||
where role_id in
|
||||
<foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
|
||||
</delete>
|
||||
|
||||
|
||||
<insert id="insertBatch" keyProperty="id" parameterType="java.util.List">
|
||||
insert INTO sys_role_menu
|
||||
(
|
||||
role_id,menu_id
|
||||
)
|
||||
values
|
||||
<foreach collection="list" item="item" index="index"
|
||||
separator=",">
|
||||
(
|
||||
#{item.roleId},
|
||||
#{item.menuId}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.glxp.api.admin.dao.auth.SysUserRoleMapper">
|
||||
|
||||
<resultMap type="com.glxp.api.admin.entity.auth.SysUserRole" id="SysUserRoleResult">
|
||||
<result property="userId" column="user_id"/>
|
||||
<result property="roleId" column="role_id"/>
|
||||
</resultMap>
|
||||
<select id="selectUserIdsByRoleId" resultType="Long">
|
||||
select u.id
|
||||
from auth_user u
|
||||
inner join sys_user_role sur
|
||||
on u.id = sur.user_id and sur.role_id = #{roleId}
|
||||
</select>
|
||||
|
||||
|
||||
<delete id="delete" parameterType="com.glxp.api.admin.req.auth.SysUserRoleRequest">
|
||||
DELETE
|
||||
FROM sys_user_role
|
||||
<where>
|
||||
<if test="userId != '' and userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
<if test="roleId != '' and roleId != null">
|
||||
AND role_id = #{roleId}
|
||||
</if>
|
||||
</where>
|
||||
</delete>
|
||||
|
||||
|
||||
<insert id="insertBatch" keyProperty="id" parameterType="java.util.List">
|
||||
insert INTO sys_user_role
|
||||
(
|
||||
user_id,role_id
|
||||
)
|
||||
values
|
||||
<foreach collection="sysUserRoles" item="item" index="index"
|
||||
separator=",">
|
||||
(
|
||||
#{item.userId},
|
||||
#{item.roleId}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
Loading…
Reference in New Issue