功能级权限、角色权限、馆外用户
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package com.hcframe.user.module.auth.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.hcframe.base.common.ResultVO;
|
||||
import com.hcframe.base.common.WebPageInfo;
|
||||
import com.hcframe.user.module.auth.service.MenuService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
/**
|
||||
* @author wewe
|
||||
* @date 2021年4月13日
|
||||
* @description 角色管理
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "功能级权限管理")
|
||||
@RequestMapping("menu")
|
||||
public class MenuController {
|
||||
|
||||
@Autowired MenuService menuService;
|
||||
|
||||
@PostMapping()
|
||||
@ApiOperation(value = "新增功能级权限", notes = "给后台传key-value对象模式即可")
|
||||
public ResultVO<Object> addMenu(@RequestParam Map<String, Object> data) {
|
||||
return menuService.addMenu(data);
|
||||
}
|
||||
|
||||
@DeleteMapping()
|
||||
@ApiOperation(value = "删除功能级权限", notes = "删除后关联表数据也会被删除")
|
||||
public ResultVO<Object> deleteMenu(@RequestParam List<Long> ids) {
|
||||
return menuService.deleteMenu(ids);
|
||||
}
|
||||
|
||||
@PutMapping("/{version}")
|
||||
@ApiOperation(value = "更新功能级权限")
|
||||
public ResultVO<Integer> updateMenu(@RequestParam Map<String, Object> data, @PathVariable Integer version) {
|
||||
return menuService.updateMenu(data, version);
|
||||
}
|
||||
|
||||
@GetMapping()
|
||||
@ApiOperation(value = "查询功能级权限列表")
|
||||
public ResultVO<PageInfo<Map<String, Object>>> getMenuList(String data, WebPageInfo webPageInfo) {
|
||||
return menuService.getMenuList(data, webPageInfo);
|
||||
}
|
||||
|
||||
@PostMapping()
|
||||
@ApiOperation(value = "角色授权", notes = "roleIds,menuIds,中间用逗号连接")
|
||||
public ResultVO<Object> addRoleMenu(@RequestParam List<Long> roleIds,@RequestParam List<Long> menuIds) {
|
||||
return menuService.addRoleMenu(roleIds, menuIds);
|
||||
}
|
||||
|
||||
@PostMapping()
|
||||
@ApiOperation(value = "删除角色授权", notes = "ids,中间用逗号连接")
|
||||
public ResultVO<Object> deleteRoleMenu(@RequestParam String ids) {
|
||||
return menuService.deleteRoleMenu(ids);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.hcframe.user.module.auth.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.hcframe.base.common.ResultVO;
|
||||
import com.hcframe.base.common.WebPageInfo;
|
||||
|
||||
/**
|
||||
* @author wewe
|
||||
* @date 2021年4月14日
|
||||
* @description 功能级权限增删改查
|
||||
*/
|
||||
public interface MenuService {
|
||||
|
||||
ResultVO<Object> addMenu(Map<String, Object> data);
|
||||
|
||||
ResultVO<Object> deleteMenu(List<Long> ids);
|
||||
|
||||
ResultVO<Integer> updateMenu(Map<String, Object> data, Integer version);
|
||||
|
||||
ResultVO<PageInfo<Map<String, Object>>> getMenuList(String data, WebPageInfo webPageInfo);
|
||||
|
||||
ResultVO<Object> addRoleMenu(List<Long> roleIds, List<Long> menuIds);
|
||||
|
||||
ResultVO<Object> deleteRoleMenu(String ids);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.hcframe.user.module.auth.service.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.hcframe.base.common.ResultVO;
|
||||
import com.hcframe.base.common.WebPageInfo;
|
||||
import com.hcframe.base.module.data.module.BaseMapper;
|
||||
import com.hcframe.base.module.data.module.Condition;
|
||||
import com.hcframe.base.module.data.service.TableService;
|
||||
import com.hcframe.base.module.tableconfig.entity.OsSysTable;
|
||||
import com.hcframe.user.module.auth.service.MenuService;
|
||||
|
||||
/**
|
||||
* @author wewe
|
||||
* @date 2021年4月14日
|
||||
* @description 功能级权限增删改查
|
||||
*/
|
||||
@Service
|
||||
public class MenuServiceImpl implements MenuService {
|
||||
|
||||
private static final OsSysTable OS_SYS_MENU = OsSysTable.builder().tableName("OS_SYS_MENU").tablePk("MENU_ID").build();
|
||||
private static final OsSysTable OS_REL_ROLE_MENU = OsSysTable.builder().tableName("OS_REL_ROLE_MENU").tablePk("ROLE_MENU_ID").build();
|
||||
|
||||
@Autowired BaseMapper baseMapper;
|
||||
@Autowired TableService tableService;
|
||||
|
||||
@Override
|
||||
public ResultVO<Object> addMenu(Map<String, Object> data) {
|
||||
if (null == data.get("OS_ID")) {
|
||||
return ResultVO.getFailed("操作系统ID不能为空");
|
||||
}
|
||||
if (StringUtils.isBlank((String) data.get("MENU_NAME"))) {
|
||||
return ResultVO.getFailed("菜单名称不能为空");
|
||||
}
|
||||
Condition condition = Condition.creatCriteria().andEqual("MENU_NAME", data.get("MENU_NAME")).andEqual("DELETED",1).build();
|
||||
Long i = baseMapper.count("OS_SYS_MENU", condition);
|
||||
if (i > 0L) {
|
||||
return ResultVO.getFailed("菜单名称不能重复");
|
||||
}
|
||||
tableService.saveWithDate(OS_SYS_MENU, data);
|
||||
return ResultVO.getSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResultVO<Object> deleteMenu(List<Long> ids) {
|
||||
ids.forEach(id -> {
|
||||
// 删除菜单及子菜单
|
||||
String familyIds = getCascadeList(id);
|
||||
tableService.logicDelete(OS_SYS_MENU, familyIds);
|
||||
// 删除角色与系统功能关联表OS_REL_ROLE_MENU
|
||||
String rmIds = getRmList(familyIds);
|
||||
tableService.logicDelete(OS_REL_ROLE_MENU, rmIds);
|
||||
});
|
||||
return ResultVO.getSuccess();
|
||||
}
|
||||
|
||||
private String getRmList(String familyIds) {
|
||||
String sql = "select ROLE_MENU_ID from OS_REL_ROLE_MENU where MENU_ID in(" + familyIds + ")";
|
||||
List<Map<String,Object>> ids = baseMapper.selectSql(sql);
|
||||
StringJoiner joiner = new StringJoiner(",");
|
||||
for (Map<String,Object> idm: ids) {
|
||||
joiner.add(idm.get("ROLE_MENU_ID").toString());
|
||||
}
|
||||
return joiner.toString();
|
||||
}
|
||||
|
||||
private String getCascadeList(Long id) {
|
||||
String sql = "select MENU_ID from OS_SYS_MENU start with MENU_ID=" + id + " connect by prior MENU_ID=PARENT_ID";
|
||||
List<Map<String,Object>> ids = baseMapper.selectSql(sql);
|
||||
StringJoiner joiner = new StringJoiner(",");
|
||||
for (Map<String,Object> idm: ids) {
|
||||
joiner.add(idm.get("MENU_ID").toString());
|
||||
}
|
||||
return joiner.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultVO<Integer> updateMenu(Map<String, Object> data, Integer version) {
|
||||
return tableService.updateWithDate(OS_SYS_MENU, data, version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultVO<PageInfo<Map<String, Object>>> getMenuList(String data, WebPageInfo webPageInfo) {
|
||||
return ResultVO.getSuccess(tableService.searchSingleTables(data, OS_SYS_MENU, webPageInfo));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultVO<Object> addRoleMenu(List<Long> roleIds, List<Long> menuIds) {
|
||||
roleIds.forEach(roleId -> {
|
||||
menuIds.forEach(menuId -> {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("ROLE_ID", roleId);
|
||||
data.put("MENU_ID", menuId);
|
||||
data.put("VERSION", 1);
|
||||
data.put("DELETED", 1);
|
||||
tableService.saveWithDate(OS_REL_ROLE_MENU, data);
|
||||
});
|
||||
});
|
||||
return ResultVO.getSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultVO<Object> deleteRoleMenu(String ids) {
|
||||
tableService.logicDelete(OS_REL_ROLE_MENU, ids);
|
||||
return ResultVO.getSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,8 +27,8 @@ import java.util.Map;
|
||||
@Service
|
||||
public class RoleServiceImpl implements RoleService {
|
||||
|
||||
private static final String PK_ID = "ROLE_ID";
|
||||
private static final String TABLE_NAME = "OS_SYS_ROLE";
|
||||
private static final String PK_ID = "MENU_ID";
|
||||
private static final String TABLE_NAME = "OS_SYS_MENU";
|
||||
private static final OsSysTable TABLE_INFO = OsSysTable.builder().tableName(TABLE_NAME).tablePk(PK_ID).build();
|
||||
|
||||
final BaseMapper baseMapper;
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.hcframe.user.module.manage.controller;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.hcframe.base.common.ResultVO;
|
||||
import com.hcframe.base.common.WebPageInfo;
|
||||
import com.hcframe.user.module.manage.service.ManageGwService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* @author wewe
|
||||
* @date 2021年4月19日
|
||||
* @description 馆外用户增删改查
|
||||
*/
|
||||
@Api(tags = "馆外用户管理")
|
||||
@RequestMapping("manage-gw")
|
||||
@RestController
|
||||
public class ManageGwController {
|
||||
|
||||
@Autowired ManageGwService service;
|
||||
|
||||
@PostMapping()
|
||||
@ApiOperation(value = "新增用户信息", notes = "将自动传承ey-value对象模式即可")
|
||||
public ResultVO<Map<String,Object>> addUser(@RequestParam Map<String,Object> user) {
|
||||
return service.addUser(user);
|
||||
}
|
||||
|
||||
@PutMapping("/{version}")
|
||||
@ApiOperation(value = "更新用户信息")
|
||||
public ResultVO<Integer> updateUser(@RequestParam Map<String,Object> user,@PathVariable Integer version) {
|
||||
return service.updateUser(user,version);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation(value = "删除用户(逻辑删除)", notes = "删除后职位也会被删除")
|
||||
public ResultVO<Integer> deleteUser(@PathVariable String ids) {
|
||||
return service.deleteUser(ids);
|
||||
}
|
||||
|
||||
@GetMapping()
|
||||
@ApiOperation(value = "获取用户列表", notes = "删除后职位也会被删除")
|
||||
public ResultVO<PageInfo<Map<String,Object>>> getUserList(String data, WebPageInfo webPageInfo) {
|
||||
return service.getUserList(data, webPageInfo);
|
||||
}
|
||||
|
||||
@PutMapping("disable/{version}")
|
||||
@ApiOperation(value = "启用/禁用",notes = "用户启用禁用")
|
||||
public ResultVO<Integer> disable(Boolean enabled,String userId,@PathVariable Integer version) {
|
||||
return service.disable(enabled,userId,version);
|
||||
}
|
||||
|
||||
@PutMapping("/resetPassword/{version}")
|
||||
@ApiOperation(value = "重置密码",notes = "用户启用禁用")
|
||||
public ResultVO<Integer> resetPassword(String userId,@PathVariable Integer version) {
|
||||
return service.resetPassword(userId,version);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.hcframe.user.module.manage.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.hcframe.base.common.ResultVO;
|
||||
import com.hcframe.base.common.WebPageInfo;
|
||||
|
||||
/**
|
||||
* @author wewe
|
||||
* @date 2021年4月19日
|
||||
* @description 馆外用户管理接口
|
||||
*/
|
||||
public interface ManageGwService {
|
||||
|
||||
ResultVO<Map<String,Object>> addUser(Map<String, Object> user);
|
||||
|
||||
ResultVO<Integer> updateUser(Map<String, Object> user, Integer version);
|
||||
|
||||
ResultVO<Integer> deleteUser(String ids);
|
||||
|
||||
ResultVO<PageInfo<Map<String, Object>>> getUserList(String data, WebPageInfo webPageInfo);
|
||||
|
||||
ResultVO<Integer> resetPassword(String userId, Integer version);
|
||||
|
||||
ResultVO<Integer> disable(Boolean enabled, String userId, Integer version);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.hcframe.user.module.manage.service.impl;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.hcframe.base.common.ResultVO;
|
||||
import com.hcframe.base.common.ServiceException;
|
||||
import com.hcframe.base.common.WebPageInfo;
|
||||
import com.hcframe.base.common.utils.JudgeException;
|
||||
import com.hcframe.base.module.data.module.BaseMapper;
|
||||
import com.hcframe.base.module.data.service.TableService;
|
||||
import com.hcframe.base.module.tableconfig.entity.OsSysTable;
|
||||
import com.hcframe.user.common.utils.MD5Utils;
|
||||
import com.hcframe.user.module.manage.service.ManageGwService;
|
||||
|
||||
/**
|
||||
* @author wewe
|
||||
* @date 2021年4月19日
|
||||
* @description 馆外用户管理
|
||||
*/
|
||||
@Service
|
||||
public class ManageGwServiceImpl implements ManageGwService {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(ManageGwServiceImpl.class);
|
||||
private static final String ID = "ID";
|
||||
private static final OsSysTable GB_CAS_MEMBER = OsSysTable.builder().tableName("GB_CAS_MEMBER").tablePk(ID).build();
|
||||
|
||||
@Autowired BaseMapper baseMapper;
|
||||
@Autowired TableService tableService;
|
||||
|
||||
@Override
|
||||
public ResultVO<Map<String, Object>> addUser(Map<String, Object> user) {
|
||||
JudgeException.isNull(user.get("PASSWORD"),"密码不能为空");
|
||||
JudgeException.isNull(user.get("LOGIN_NAME"),"用户名不能为空");
|
||||
user.put("USER_TYPE", "GW");
|
||||
if (!StringUtils.isEmpty(user.get("ORG_ACCOUNT_ID"))) {
|
||||
String orgAcId = String.valueOf(user.get("ORG_ACCOUNT_ID"));
|
||||
user.put("ORG_ACCOUNT_ID", orgAcId.replaceAll("\"", ""));
|
||||
}
|
||||
if (!StringUtils.isEmpty(user.get("ORG_DEPARTMENT_ID"))) {
|
||||
String orgDeptId = String.valueOf(user.get("ORG_DEPARTMENT_ID"));
|
||||
user.put("ORG_DEPARTMENT_ID", orgDeptId.replaceAll("\"", ""));
|
||||
}
|
||||
try {
|
||||
user.put("PASSWORD",MD5Utils.encode((String) user.get("PASSWORD")));
|
||||
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
|
||||
logger.error("新增用户失败",e);
|
||||
throw new ServiceException(e);
|
||||
}
|
||||
return tableService.saveWithDate(GB_CAS_MEMBER,user);
|
||||
}
|
||||
@Override
|
||||
public ResultVO<Integer> updateUser(Map<String, Object> user, Integer version) {
|
||||
user.put("USER_TYPE", "GW");
|
||||
user.remove("PASSWORD");
|
||||
if (!StringUtils.isEmpty(user.get("ORG_ACCOUNT_ID"))) {
|
||||
String orgAcId = String.valueOf(user.get("ORG_ACCOUNT_ID"));
|
||||
user.put("ORG_ACCOUNT_ID", orgAcId.replaceAll("\"", ""));
|
||||
}
|
||||
if (!StringUtils.isEmpty(user.get("ORG_DEPARTMENT_ID"))) {
|
||||
String orgDeptId = String.valueOf(user.get("ORG_DEPARTMENT_ID"));
|
||||
user.put("ORG_DEPARTMENT_ID", orgDeptId.replaceAll("\"", ""));
|
||||
}
|
||||
return tableService.updateWithDate(GB_CAS_MEMBER,user,version);
|
||||
}
|
||||
@Override
|
||||
public ResultVO<Integer> deleteUser(String ids) {
|
||||
return tableService.logicDelete(GB_CAS_MEMBER,ids);
|
||||
}
|
||||
@Override
|
||||
public ResultVO<PageInfo<Map<String, Object>>> getUserList(String data, WebPageInfo webPageInfo) {
|
||||
PageInfo<Map<String, Object>> page = tableService.searchSingleTables(data, GB_CAS_MEMBER, webPageInfo);
|
||||
List<Map<String,Object>> list = page.getList();
|
||||
for (Map<String, Object> map : list) {
|
||||
map.remove("PASSWORD");
|
||||
map.put("PASSWORD", "******");
|
||||
}
|
||||
page.setList(list);
|
||||
return ResultVO.getSuccess(page);
|
||||
}
|
||||
@Override
|
||||
public ResultVO<Integer> resetPassword(String userId, Integer version) {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put(ID, userId.replaceAll("\"",""));
|
||||
try {
|
||||
map.put("PASSWORD",MD5Utils.encode("123456"));
|
||||
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
|
||||
logger.error("重置密码失败",e);
|
||||
throw new ServiceException(e);
|
||||
}
|
||||
return tableService.updateWithDate(GB_CAS_MEMBER,map,version);
|
||||
}
|
||||
@Override
|
||||
public ResultVO<Integer> disable(Boolean enabled, String userId, Integer version) {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put(ID, userId);
|
||||
map.put("DISABLED", enabled);
|
||||
return tableService.updateWithDate(GB_CAS_MEMBER,map,version);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user