新增shiro Realm权限过滤注入,新增根据用户获取菜单列表,树状表格菜单列表,修改角色和角色组删除为逻辑删除

This commit is contained in:
lhc
2021-04-26 15:42:31 +08:00
parent fc2d4330f0
commit f490b1f6de
16 changed files with 740 additions and 107 deletions

View File

@@ -1,13 +1,17 @@
package com.hcframe.user.common.config;
import com.hcframe.base.module.auth.dao.FtUserDao;
import com.hcframe.base.module.auth.entity.FtUser;
import com.hcframe.base.module.data.module.BaseMapper;
import com.hcframe.base.module.data.module.BaseMapperImpl;
import com.hcframe.base.module.shiro.service.ShiroType;
import com.hcframe.base.module.shiro.service.SystemRealm;
import com.hcframe.user.module.auth.service.AuthService;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
/**
* @author lhc
@@ -17,11 +21,13 @@ import java.util.LinkedHashMap;
@Component
public class ShiroRealmConfig implements SystemRealm {
final
FtUserDao ftUserDao;
final BaseMapper baseMapper;
final AuthService authService;
public ShiroRealmConfig(FtUserDao ftUserDao) {
this.ftUserDao = ftUserDao;
public ShiroRealmConfig(@Qualifier(BaseMapperImpl.BASE)BaseMapper baseMapper,
AuthService authService){
this.baseMapper = baseMapper;
this.authService = authService;
}
/**
@@ -31,7 +37,13 @@ public class ShiroRealmConfig implements SystemRealm {
*/
@Override
public SimpleAuthorizationInfo setAuthoriztion(Object user) {
return new SimpleAuthorizationInfo();
Map<String, Object> map = (Map<String, Object>) user;
SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
Set<String> set = authService.getUserAuth(String.valueOf(map.get("ID")));
for (String auth : set) {
simpleAuthorizationInfo.addStringPermission(auth);
}
return simpleAuthorizationInfo;
}
/**
@@ -41,7 +53,7 @@ public class ShiroRealmConfig implements SystemRealm {
*/
@Override
public Object findByUserId(String userId) {
return ftUserDao.selectOne(FtUser.builder().userId(Integer.parseInt(userId)).build());
return null;
}
/**

View File

@@ -0,0 +1,68 @@
package com.hcframe.user.module.auth.controller;
import com.hcframe.base.common.ResultVO;
import com.hcframe.base.module.auth.entity.OsSysMenu;
import com.hcframe.base.module.data.module.BaseMapper;
import com.hcframe.base.module.data.module.BaseMapperImpl;
import com.hcframe.user.module.auth.service.AuthService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import java.util.*;
/**
* @author lhc
* @version 1.0
* @className AuthController
* @date 2021年04月21日 11:04 上午
* @description 描述
*/
@RestController
@RequestMapping("auth")
public class AuthController {
final AuthService authService;
final BaseMapper baseMapper;
public AuthController(AuthService authService,
@Qualifier(BaseMapperImpl.BASE) BaseMapper baseMapper) {
this.authService = authService;
this.baseMapper = baseMapper;
}
@GetMapping()
public ResultVO<Object> get() {
return ResultVO.getSuccess(authService.getUserAuth("6478745544359298274"));
}
@GetMapping("menu")
public ResultVO getMenuResult() {
Map<String, Object> map = (Map<String, Object>)SecurityUtils.getSubject().getPrincipal();
if (map == null) {
return ResultVO.getNoLogin();
}
List<OsSysMenu> menus;
Set<String> set;
if ("admin".equals(map.get("LOGIN_NAME"))) {
set = authService.getAllAuth();
menus = authService.getMenuResult();
} else {
set = authService.getUserAuth(String.valueOf(map.get("ID")));
menus = authService.getUserMenuResult(set);
}
if (menus == null || menus.size() == 0) {
return ResultVO.getSuccess(new ArrayList<>());
}
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("menu", authService.formatMenu(menus));
resultMap.put("auth", set);
return ResultVO.getSuccess(resultMap);
}
@GetMapping("menuList")
public ResultVO<List<Map<String,Object>>> getMenuList(OsSysMenu osSysMenu) {
return ResultVO.getSuccess(authService.getMenuResultList(osSysMenu));
}
}

View File

@@ -0,0 +1,17 @@
package com.hcframe.user.module.auth.mapper;
import com.hcframe.base.module.auth.entity.OsSysMenu;
import java.util.List;
import java.util.Map;
/**
* @author lhc
* @version 1.0
* @className AuthDao
* @date 2021年04月25日 3:30 下午
* @description 描述
*/
public interface AuthDao {
List<Map<String,Object>> selectMenuList(OsSysMenu osSysMenu);
}

View File

@@ -0,0 +1,70 @@
package com.hcframe.user.module.auth.mapper.impl;
import com.hcframe.base.module.auth.entity.OsSysMenu;
import com.hcframe.base.module.data.module.BaseMapper;
import com.hcframe.base.module.data.module.BaseMapperImpl;
import com.hcframe.user.module.auth.mapper.AuthDao;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
/**
* @author lhc
* @version 1.0
* @className AuthDaoImpl
* @date 2021年04月25日 3:30 下午
* @description 描述
*/
@Component
public class AuthDaoImpl implements AuthDao {
final BaseMapper baseMapper;
public AuthDaoImpl(@Qualifier(BaseMapperImpl.BASE) BaseMapper baseMapper) {
this.baseMapper = baseMapper;
}
@Override
public List<Map<String,Object>> selectMenuList(OsSysMenu osSysMenu) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(" SELECT OS_SYS_MENU.MENU_ID,\n" +
" OS_SYS_MENU.MENU_NAME,\n" +
" OS_SYS_MENU.PARENT_ID,\n" +
" OS_SYS_MENU.PATH,\n" +
" OS_SYS_MENU.COMPONENT,\n" +
" OS_SYS_MENU.IS_CACHE,\n" +
" OS_SYS_MENU.VISIBLE,\n" +
" OS_SYS_MENU.IS_FRAME,\n" +
" OS_SYS_MENU.MENU_TYPE,\n" +
" OS_SYS_MENU.ORDER_NUM,\n" +
" OS_SYS_MENU.MENU_STATUS,\n" +
" OS_SYS_MENU.PERMS,\n" +
" OS_SYS_MENU.AFFIX,\n" +
" OS_SYS_MENU.BREADCRUMB,\n" +
" OS_SYS_MENU.AlWAYSSHOW,\n" +
" OS_SYS_MENU.REMARK,\n" +
" OS_SYS_MENU.UPDATE_TIME,\n" +
" OS_SYS_MENU.CREATE_TIME,\n" +
" OS_SYS_MENU.ICON,\n" +
" OS_SYS_MENU.OS_ID,\n" +
" OS_SYS_MENU.VERSION,\n" +
" OS_SYS_MENU.DELETED\n" +
" FROM OS_SYS_MENU\n" +
" WHERE DELETED = 1");
if (!StringUtils.isEmpty(osSysMenu.getMenuName())) {
stringBuilder.append(" AND MENU_NAME like '%").append(osSysMenu.getMenuName()).append("%' ");
}
if (!StringUtils.isEmpty(osSysMenu.getOsId())) {
stringBuilder.append(" AND OS_ID = ").append(osSysMenu.getOsId()).append(" ");
}
if (!StringUtils.isEmpty(osSysMenu.getStatus())) {
stringBuilder.append("AND MENU_STATUS = '").append(osSysMenu.getStatus()).append("'");
}
stringBuilder.append("ORDER BY OS_SYS_MENU.PARENT_ID ASC,\n" +
" OS_SYS_MENU.ORDER_NUM ASC");
return baseMapper.selectSql(stringBuilder.toString());
}
}

View File

@@ -0,0 +1,39 @@
package com.hcframe.user.module.auth.service;
import com.hcframe.base.module.auth.entity.OsSysMenu;
import com.hcframe.base.module.auth.vo.RouterVo;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author lhc
* @version 1.0
* @className AuthService
* @date 2021年04月21日 10:41 上午
* @description 描述
*/
public interface AuthService {
List<String> getUserRoleAuth(String userId);
List<String> getUserRoleGroupAuth(String userId);
List<String> getOrgRoleAuth(String orgCode);
List<String> getOrgGroupAuth(String orgCode);
Set<String> getUserAuth(String userId);
List<OsSysMenu> getMenuResult();
List<RouterVo> formatMenu(List<OsSysMenu> menus);
List<OsSysMenu> getUserMenuResult(Set<String> set);
Set<String> getAllAuth();
List<Map<String,Object>> getMenuResultList(OsSysMenu osSysMenu);
}

View File

@@ -0,0 +1,388 @@
package com.hcframe.user.module.auth.service.impl;
import com.hcframe.base.common.utils.StringUtils;
import com.hcframe.base.module.auth.constants.AuthConstants;
import com.hcframe.base.module.auth.dao.OsSysMenuDao;
import com.hcframe.base.module.auth.entity.OsSysMenu;
import com.hcframe.base.module.auth.vo.MetaVo;
import com.hcframe.base.module.auth.vo.RouterVo;
import com.hcframe.base.module.data.module.*;
import com.hcframe.redis.RedisUtil;
import com.hcframe.user.module.auth.mapper.AuthDao;
import com.hcframe.user.module.auth.service.AuthService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* @author lhc
* @version 1.0
* @className AuthServiceImpl
* @date 2021年04月21日 10:41 上午
* @description 描述
*/
@Service
public class AuthServiceImpl implements AuthService {
final BaseMapper baseMapper;
final RedisUtil redisUtil;
final OsSysMenuDao osSysMenuDao;
final AuthDao authDao;
public AuthServiceImpl(@Qualifier(BaseMapperImpl.BASE) BaseMapper baseMapper,
RedisUtil redisUtil,
OsSysMenuDao osSysMenuDao,
AuthDao authDao) {
this.baseMapper = baseMapper;
this.redisUtil = redisUtil;
this.osSysMenuDao = osSysMenuDao;
this.authDao = authDao;
}
@Override
public List<String> getUserRoleAuth(String userId) {
SelectCondition selectCondition = SelectCondition
.sqlJoinBuilder("OS_REL_USER_ROLE")
.field("OS_SYS_MENU.PATH")
.join("OS_REL_ROLE_MENU")
.on("ROLE_ID", "OS_REL_USER_ROLE", "ROLE_ID")
.join("OS_SYS_MENU")
.on("MENU_ID", "OS_REL_ROLE_MENU", "MENU_ID")
.join("OS_SYS_ROLE")
.on("ROLE_ID", "OS_REL_USER_ROLE", "ROLE_ID")
.build();
Condition condition = Condition.creatCriteria(selectCondition)
.andEqual("OS_SYS_ROLE.DELETED", 1)
.andEqual("OS_SYS_MENU.DELETED", 1)
.andEqual("OS_SYS_MENU.MENU_STATUS",1)
.andEqual("OS_SYS_MENU.OS_ID", 8)
.andEqual("OS_REL_USER_ROLE.USER_ID", userId.replaceAll("\"", ""))
.build();
return getPaths(condition);
}
@Override
public List<String> getUserRoleGroupAuth(String userId) {
SelectCondition selectCondition = SelectCondition
.sqlJoinBuilder("OS_REL_USER_GROUP")
.field("OS_SYS_MENU.PATH")
.join("OS_SYS_ROLE_GROUP")
.on("GROUP_ID", "OS_REL_USER_GROUP", "GROUP_ID")
.join("OS_REL_GROUP_ROLE")
.on("GROUP_ID", "OS_REL_USER_GROUP", "GROUP_ID")
.join("OS_SYS_ROLE")
.on("ROLE_ID", "OS_REL_GROUP_ROLE", "ROLE_ID")
.join("OS_REL_ROLE_MENU")
.on("ROLE_ID", "OS_REL_GROUP_ROLE", "ROLE_ID")
.join("OS_SYS_MENU")
.on("MENU_ID", "OS_REL_ROLE_MENU", "MENU_ID")
.build();
Condition condition = Condition.creatCriteria(selectCondition)
.andEqual("OS_SYS_ROLE.DELETED", 1)
.andEqual("OS_SYS_MENU.DELETED", 1)
.andEqual("OS_SYS_MENU.OS_ID", 8)
.andEqual("OS_SYS_MENU.MENU_STATUS",1)
.andEqual("OS_SYS_ROLE_GROUP.DELETED", 1)
.andEqual("OS_REL_USER_GROUP.USER_ID", userId.replaceAll("\"", ""))
.build();
return getPaths(condition);
}
private List<String> getPaths(Condition condition) {
List<Map<String, Object>> list = baseMapper.selectByCondition(condition);
List<String> resultList = new ArrayList<>();
if (list != null && list.size() > 0) {
for (Map<String, Object> objectMap : list) {
resultList.add(String.valueOf(objectMap.get("PATH")));
}
}
return resultList;
}
@Override
public List<String> getOrgRoleAuth(String orgCode) {
DataMap<Object> dataMap = DataMap.builder().tableName("GB_CAS_DEPT").fields("ID").build();
Map<String, Object> org = baseMapper.selectOneByCondition(Condition.creatCriteria(dataMap).andEqual("CODE", orgCode).build());
SelectCondition selectCondition = SelectCondition
.sqlJoinBuilder("OS_REL_DEPT_ROLE")
.field("OS_SYS_MENU.PATH")
.join("OS_SYS_ROLE")
.on("ROLE_ID", "OS_REL_DEPT_ROLE", "ROLE_ID")
.join("OS_REL_ROLE_MENU")
.on("ROLE_ID", "OS_REL_DEPT_ROLE", "ROLE_ID")
.join("OS_SYS_MENU")
.on("MENU_ID", "OS_REL_ROLE_MENU", "MENU_ID")
.build();
Condition condition = Condition.creatCriteria(selectCondition)
.andEqual("OS_SYS_ROLE.DELETED", 1)
.andEqual("OS_SYS_MENU.DELETED", 1)
.andEqual("OS_SYS_MENU.OS_ID", 8)
.andEqual("OS_SYS_MENU.MENU_STATUS",1)
.andEqual("OS_REL_DEPT_ROLE.DEPT_ID", org.get("ID")).build();
return getPaths(condition);
}
@Override
public List<String> getOrgGroupAuth(String orgCode) {
DataMap<Object> dataMap = DataMap.builder().tableName("GB_CAS_DEPT").fields("ID").build();
Map<String, Object> org = baseMapper.selectOneByCondition(Condition.creatCriteria(dataMap).andEqual("CODE", orgCode).build());
SelectCondition selectCondition = SelectCondition
.sqlJoinBuilder("OS_REL_DEPT_GROUP")
.field("OS_SYS_MENU.PATH")
.join("OS_SYS_ROLE_GROUP")
.on("GROUP_ID", "OS_REL_DEPT_GROUP", "GROUP_ID")
.join("OS_REL_GROUP_ROLE")
.on("GROUP_ID", "OS_REL_DEPT_GROUP", "GROUP_ID")
.join("OS_SYS_ROLE")
.on("ROLE_ID", "OS_REL_GROUP_ROLE", "ROLE_ID")
.join("OS_REL_ROLE_MENU")
.on("ROLE_ID", "OS_REL_GROUP_ROLE", "ROLE_ID")
.join("OS_SYS_MENU")
.on("MENU_ID", "OS_REL_ROLE_MENU", "MENU_ID")
.build();
Condition condition = Condition.creatCriteria(selectCondition)
.andEqual("OS_SYS_ROLE.DELETED", 1)
.andEqual("OS_SYS_MENU.DELETED", 1)
.andEqual("OS_SYS_ROLE_GROUP.DELETED", 1)
.andEqual("OS_SYS_MENU.OS_ID", 8)
.andEqual("OS_SYS_MENU.MENU_STATUS",1)
.andEqual("OS_REL_DEPT_GROUP.DEPT_ID", org.get("ID"))
.build();
return getPaths(condition);
}
@Override
public Set<String> getUserAuth(String userId) {
Set<String> authSet = (Set<String>) redisUtil.hget("auth", userId);
if (authSet == null) {
Map<String, Object> user = baseMapper.selectByPk(DataMap.builder().tableName("GB_CAS_MEMBER").pkName("ID").pkValue(userId).build());
if ("admin".equals(user.get("NAME"))) {
authSet = getAllAuth();
redisUtil.hset("auth", userId,authSet,24 * 3600);
return getAllAuth();
}
List<String> roleAuth = getUserRoleAuth(String.valueOf(user.get("ID")));
List<String> groupAuth = getUserRoleAuth(String.valueOf(user.get("ID")));
List<String> orgAui = getOrgRoleAuth(String.valueOf(user.get("DEPT_CODE")));
List<String> orgGroupAuth = getOrgGroupAuth(String.valueOf(user.get("DEPT_CODE")));
List<String> orgGuobo = getOrgGroupAuth("guobo");
List<String> orgGuoboGroup = getOrgGroupAuth("guobo");
authSet = new HashSet<>(roleAuth);
authSet.addAll(groupAuth);
authSet.addAll(orgAui);
authSet.addAll(orgGroupAuth);
authSet.addAll(orgGuobo);
authSet.addAll(orgGuoboGroup);
if (String.valueOf(user.get("DEPT_CODE")).length() == 6) {
String code = String.valueOf(user.get("DEPT_CODE"));
code = code.substring(0, 4);
List<String> orgAuiParent = getOrgGroupAuth(code);
List<String> orgGroupAuthParent = getOrgGroupAuth(code);
authSet.addAll(orgAuiParent);
authSet.addAll(orgGroupAuthParent);
}
redisUtil.hset("auth", userId,authSet,24 * 3600);
}
return authSet;
}
@Override
public List<OsSysMenu> getMenuResult() {
List<OsSysMenu> osSysMenus = osSysMenuDao.selectMenu();
return getChildPerms(osSysMenus, 0);
}
/**
* 根据父节点的ID获取所有子节点
*
* @param list 分类表
* @param parentId 传入的父节点ID
* @return String
*/
public List<OsSysMenu> getChildPerms(List<OsSysMenu> list, long parentId) {
List<OsSysMenu> returnList = new ArrayList<OsSysMenu>();
for (Iterator<OsSysMenu> iterator = list.iterator(); iterator.hasNext(); ) {
OsSysMenu t = iterator.next();
// 一、根据传入的某个父节点ID,遍历该父节点的所有子节点
if (t.getParentId() == parentId) {
recursionFn(list, t);
returnList.add(t);
}
}
return returnList;
}
/**
* 递归列表
*
* @param list
* @param t
*/
private void recursionFn(List<OsSysMenu> list, OsSysMenu t) {
// 得到子节点列表
List<OsSysMenu> childList = getChildList(list, t);
t.setChildren(childList);
for (OsSysMenu tChild : childList) {
if (hasChild(list, tChild)) {
recursionFn(list, tChild);
}
}
}
/**
* 得到子节点列表
*/
private List<OsSysMenu> getChildList(List<OsSysMenu> list, OsSysMenu t) {
List<OsSysMenu> tlist = new ArrayList<OsSysMenu>();
Iterator<OsSysMenu> it = list.iterator();
while (it.hasNext()) {
OsSysMenu n = it.next();
if (n.getParentId().longValue() == t.getMenuId().longValue()) {
tlist.add(n);
}
}
return tlist;
}
private boolean hasChild(List<OsSysMenu> list, OsSysMenu t) {
return getChildList(list, t).size() > 0;
}
@Override
public List<RouterVo> formatMenu(List<OsSysMenu> menus) {
List<RouterVo> routers = new LinkedList<RouterVo>();
for (OsSysMenu menu : menus) {
RouterVo router = new RouterVo();
router.setName(getRouteName(menu));
router.setPath(getRouterPath(menu));
router.setComponent(getComponent(menu));
MetaVo metaVo = MetaVo
.builder()
.title(menu.getMenuName())
.icon(menu.getIcon())
.noCache(StringUtils.equals("0", menu.getIsCache()))
.hidden("0".equals(menu.getVisible()))
.breadcrumb("1".equals(menu.getBreadcrumb()))
.affix("1".equals(menu.getAffix()))
.alwaysShow("1".equals(menu.getAlwaysShow()))
.build();
List<OsSysMenu> cMenus = menu.getChildren();
if (cMenus != null && !cMenus.isEmpty() && AuthConstants.TYPE_DIR.equals(menu.getMenuType())) {
router.setRedirect("noredirect");
router.setChildren(formatMenu(cMenus));
} else if (isMeunFrame(menu)) {
List<RouterVo> childrenList = new ArrayList<RouterVo>();
RouterVo children = new RouterVo();
children.setPath(menu.getPath());
children.setComponent(menu.getComponent());
children.setName(StringUtils.capitalize(menu.getPath()));
metaVo = metaVo.toBuilder()
.title(menu.getMenuName())
.icon(menu.getIcon())
.noCache(StringUtils.equals("0", menu.getIsCache()))
.alwaysShow("1".equals(menu.getAlwaysShow()))
.build();
childrenList.add(children);
router.setChildren(childrenList);
} else if (cMenus == null || cMenus.isEmpty()) {
metaVo.setAlwaysShow(false);
}
router.setMeta(metaVo);
routers.add(router);
}
return routers;
}
@Override
public List<OsSysMenu> getUserMenuResult(Set<String> set) {
StringBuilder stringBuilder = new StringBuilder();
for (String str : set) {
stringBuilder.append("'").append(str).append("'").append(",");
}
List<OsSysMenu> list=osSysMenuDao.selectMenuByUser(stringBuilder.substring(0, stringBuilder.length() - 1));
return getChildPerms(list, 0);
}
@Override
public Set<String> getAllAuth() {
return osSysMenuDao.selectAllAuth();
}
@Override
public List<Map<String,Object>> getMenuResultList(OsSysMenu osSysMenu) {
return authDao.selectMenuList(osSysMenu);
}
/**
* 获取路由名称
*
* @param menu 菜单信息
* @return 路由名称
*/
public String getRouteName(OsSysMenu menu) {
String routerName = StringUtils.capitalize(menu.getPath());
// 非外链并且是一级目录(类型为目录)
if (isMeunFrame(menu)) {
routerName = StringUtils.EMPTY;
}
return routerName;
}
/**
* 获取路由地址
*
* @param menu 菜单信息
* @return 路由地址
*/
public String getRouterPath(OsSysMenu menu) {
String routerPath = menu.getPath();
// 非外链并且是一级目录(类型为目录)
if (0 == menu.getParentId().intValue() && AuthConstants.TYPE_DIR.equals(menu.getMenuType())
&& AuthConstants.NO_FRAME.equals(menu.getIsFrame())) {
routerPath = "/" + menu.getPath();
}
// 非外链并且是一级目录(类型为菜单)
else if (isMeunFrame(menu)) {
routerPath = "/";
}
return routerPath;
}
/**
* 获取组件信息
*
* @param menu 菜单信息
* @return 组件信息
*/
public String getComponent(OsSysMenu menu) {
String component = AuthConstants.LAYOUT;
if (StringUtils.isNotEmpty(menu.getComponent()) && !isMeunFrame(menu)) {
component = menu.getComponent();
}
if (StringUtils.isEmpty(menu.getComponent())&&isNotParentMenuFrame(menu)) {
component = AuthConstants.UN_LAYOUT;
}
return component;
}
/**
* 是否为菜单内部跳转
*
* @param menu 菜单信息
* @return 结果
*/
public boolean isMeunFrame(OsSysMenu menu) {
return menu.getParentId().intValue() == 0 && AuthConstants.TYPE_MENU.equals(menu.getMenuType())
&& menu.getIsFrame().equals(AuthConstants.NO_FRAME);
}
public boolean isNotParentMenuFrame(OsSysMenu menu) {
return menu.getParentId().intValue() != 0 && AuthConstants.TYPE_DIR.equals(menu.getMenuType())
&& menu.getIsFrame().equals(AuthConstants.NO_FRAME);
}
}

View File

@@ -32,7 +32,6 @@ public class RoleGroupServiceImpl implements RoleGroupServie {
private static final String PK_ID = "GROUP_ID";
private static final String TABLE_NAME = "OS_SYS_ROLE_GROUP";
private static final String OS_SYS_ROLE = "OS_SYS_ROLE";
private static final String ROLE_ID = "ROLE_ID";
private static final String OS_REL_GROUP_ROLE = "OS_REL_GROUP_ROLE";
private static final String ROLE_GROUP_ID = "ROLE_GROUP_ID";
@@ -63,13 +62,7 @@ public class RoleGroupServiceImpl implements RoleGroupServie {
@Override
@Transactional(rollbackFor = Exception.class)
public ResultVO<Integer> delete(String ids) {
tableService.delete(TABLE_INFO, ids);
baseMapper.deleteInPk(DataMap
.builder()
.tableName(OS_SYS_ROLE)
.pkName(ROLE_ID)
.ids(ids)
.build());
tableService.logicDelete(TABLE_INFO, ids);
return ResultVO.getSuccess();
}
@@ -110,6 +103,6 @@ public class RoleGroupServiceImpl implements RoleGroupServie {
@Override
public ResultVO<Object> getAll() {
return ResultVO.getSuccess(baseMapper.selectAll(TABLE_NAME));
return ResultVO.getSuccess( baseMapper.selectByCondition(TABLE_NAME, Condition.creatCriteria().andEqual("DELETED", 1).build()));
}
}

View File

@@ -59,8 +59,7 @@ public class RoleServiceImpl implements RoleService {
@Override
@Transactional(rollbackFor = Exception.class)
public ResultVO<Object> deleteRole(String ids) {
// TODO 补全需要删除的关联表
tableService.delete(TABLE_INFO, ids);
tableService.logicDelete(TABLE_INFO, ids);
return ResultVO.getSuccess();
}
@@ -81,6 +80,6 @@ public class RoleServiceImpl implements RoleService {
@Override
public ResultVO<List<Map<String, Object>>> getAll() {
return ResultVO.getSuccess(roleDao.getAllList());
return ResultVO.getSuccess(baseMapper.selectByCondition(TABLE_NAME, Condition.creatCriteria().andEqual("DELETED", 1).build()));
}
}

View File

@@ -81,14 +81,14 @@ public class RoleUserServiceImpl implements RoleUserService {
@Override
public ResultVO<Object> getUserRole(String userId) {
Condition condition = Condition.creatCriteria().andEqual("USER_ID",userId).build();
Condition condition = Condition.creatCriteria().andEqual("USER_ID",userId).andEqual("DELETED",1).build();
List<Map<String,Object>> list = baseMapper.selectByCondition(OS_REL_USER_ROLE, condition);
return ResultVO.getSuccess(list);
}
@Override
public ResultVO<Object> getUserGroup(String userId) {
Condition condition = Condition.creatCriteria().andEqual("USER_ID",userId).build();
Condition condition = Condition.creatCriteria().andEqual("USER_ID",userId).andEqual("DELETED",1).build();
List<Map<String,Object>> list = baseMapper.selectByCondition(OS_REL_USER_GROUP, condition);
return ResultVO.getSuccess(list);
}

View File

@@ -6,6 +6,7 @@ import com.hcframe.base.common.WebPageInfo;
import com.hcframe.user.module.manage.service.ManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@@ -62,11 +63,12 @@ public class ManageController {
}
@PutMapping("/resetPassword/{version}")
@ApiOperation(value = "重置密码",notes = "用户启用禁用")
@ApiOperation(value = "重置密码")
@RequiresPermissions(value = { "systemManage" })
public ResultVO<Integer> resetPassword(String userId,@PathVariable Integer version) {
return manageService.resetPassword(userId,version);
}
@PutMapping("changePassword")
@ApiOperation(value = "修改密码",notes = "用户输入原密码和新密码")
public ResultVO<Integer> changePassword(String pwd,String npwd,String npwd2) {

View File

@@ -1,24 +1,15 @@
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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* @author wewe
@@ -29,15 +20,15 @@ import io.swagger.annotations.ApiOperation;
@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) {
@@ -51,9 +42,9 @@ public class ManageGwController {
}
@GetMapping()
@ApiOperation(value = "获取用户列表", notes = "删除后职位也会被删除")
public ResultVO<PageInfo<Map<String,Object>>> getUserList(String data, WebPageInfo webPageInfo) {
return service.getUserList(data, webPageInfo);
@ApiOperation(value = "获取用户列表" )
public ResultVO<PageInfo<Map<String,Object>>> getUserList(String data, WebPageInfo webPageInfo,String orgId) {
return service.getUserList(data, webPageInfo,orgId);
}
@PutMapping("disable/{version}")
@@ -68,5 +59,10 @@ public class ManageGwController {
return service.resetPassword(userId,version);
}
@GetMapping("valid")
@ApiOperation(value = "校验用户名")
public ResultVO<Object> valid(String loginName) {
return service.valid(loginName);
}
}

View File

@@ -1,28 +1,29 @@
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;
import java.util.Map;
/**
* @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<PageInfo<Map<String, Object>>> getUserList(String data, WebPageInfo webPageInfo,String orgId);
ResultVO<Integer> resetPassword(String userId, Integer version);
ResultVO<Integer> disable(Boolean enabled, String userId, Integer version);
ResultVO<Object> valid(String loginName);
}

View File

@@ -1,27 +1,33 @@
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.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
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.module.Condition;
import com.hcframe.base.module.data.module.DataMap;
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;
import org.apache.shiro.SecurityUtils;
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 java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author wewe
@@ -30,19 +36,24 @@ import com.hcframe.user.module.manage.service.ManageGwService;
*/
@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"),"用户名不能为空");
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");
Map<String,Object> currentUser= (Map<String,Object>)SecurityUtils.getSubject().getPrincipal();
user.put("ADD_NAME", currentUser.get("NAME"));
user.put("ADD_LOGIN_NAME", currentUser.get("LOGIN_NAME"));
if (!StringUtils.isEmpty(user.get("ORG_ACCOUNT_ID"))) {
String orgAcId = String.valueOf(user.get("ORG_ACCOUNT_ID"));
user.put("ORG_ACCOUNT_ID", orgAcId.replaceAll("\"", ""));
@@ -52,17 +63,18 @@ public class ManageGwServiceImpl implements ManageGwService {
user.put("ORG_DEPARTMENT_ID", orgDeptId.replaceAll("\"", ""));
}
try {
user.put("PASSWORD",MD5Utils.encode((String) user.get("PASSWORD")));
user.put("PASSWORD", MD5Utils.encode("Guobo@123"));
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
logger.error("新增用户失败",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");
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("\"", ""));
@@ -71,15 +83,40 @@ public class ManageGwServiceImpl implements ManageGwService {
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);
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, String orgId) {
DataMap<Object> dataMap = DataMap.builder().sysOsTable(GB_CAS_MEMBER).build();
Condition.ConditionBuilder builder = Condition.creatCriteria(dataMap);
if (!StringUtils.isEmpty(orgId)&&!orgId.equals("guobo")) {
orgId = orgId.replaceAll("\"", "");
String sql = "select CODE from GB_CAS_DEPT where CODE like '"+orgId+"%'";
List<Map<String, Object>> list = baseMapper.selectSql(sql);
List<Object> idList = new ArrayList<>();
for (Map<String, Object> code : list) {
idList.add(code.get("CODE"));
}
builder.andIn("DEPT_CODE",idList);
}
builder.andEqual("USER_TYPE", "GW");
if (!StringUtils.isEmpty(data)) {
try {
data = URLDecoder.decode(data, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new ServiceException(e);
}
JSONArray jsonArray = JSON.parseArray(data);
builder = tableService.getQueryBuilder(jsonArray, builder);
}
builder.andEqual("DELETED", 1);
PageInfo<Map<String,Object>> page = baseMapper.selectByCondition(builder.build(), webPageInfo);
List<Map<String,Object>> list = page.getList();
for (Map<String, Object> map : list) {
map.remove("PASSWORD");
@@ -87,24 +124,35 @@ public class ManageGwServiceImpl implements ManageGwService {
}
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("\"",""));
}
@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"));
map.put("PASSWORD", MD5Utils.encode("123456"));
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
logger.error("重置密码失败",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);
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);
}
return tableService.updateWithDate(GB_CAS_MEMBER, map, version);
}
@Override
public ResultVO<Object> valid(String loginName) {
Long count = baseMapper.count("GB_CAS_MEMBER", Condition.creatCriteria().andEqual("LOGIN_NAME",loginName).build());
if (count > 0) {
return ResultVO.getFailed("用户名已存在");
}
return ResultVO.getSuccess();
}
}

View File

@@ -112,15 +112,15 @@ public class ManageServiceDataImpl implements ManageService {
public ResultVO<PageInfo<Map<String, Object>>> getUserList(String data, WebPageInfo webPageInfo, String orgId) {
DataMap<Object> dataMap = DataMap.builder().sysOsTable(TABLE_INFO).build();
Condition.ConditionBuilder builder = Condition.creatCriteria(dataMap);
if (!StringUtils.isEmpty(orgId)) {
if (!StringUtils.isEmpty(orgId)&&!orgId.equals("guobo")) {
orgId = orgId.replaceAll("\"", "");
String sql = "select ID from GB_CAS_DEPT start with ID="+orgId+" connect by prior ID=ORG_ACCOUNT_ID";
String sql = "select CODE from GB_CAS_DEPT where CODE like '"+orgId+"%'";
List<Map<String, Object>> list = baseMapper.selectSql(sql);
List<Object> idList = new ArrayList<>();
for (Map<String, Object> code : list) {
idList.add(code.get("ID"));
idList.add(code.get("CODE"));
}
builder.andIn("ORG_DEPARTMENT_ID",idList);
builder.andIn("DEPT_CODE",idList);
}
builder.andEqual("USER_TYPE", "GN");
if (!StringUtils.isEmpty(data)) {

View File

@@ -75,7 +75,7 @@ public class DeptServiceImpl implements DeptService {
@Override
public ResultVO<List<Map<String, Object>>> getDeptTree() {
// 获取全部
String sql = "SELECT " + ID + "," + PATH + "," + TYPE + "," + NAME + " FROM " + GB_CAS_DEPT + " ORDER BY " + SORT_ID;
String sql = "SELECT " + ID + "," + PATH + "," + TYPE + "," + NAME + ",CODE FROM " + GB_CAS_DEPT + " ORDER BY " + SORT_ID;
List<Map<String, Object>> allDataList = baseMapper.selectSql(sql);
// 根节点
List<Map<String, Object>> rootList = new ArrayList<>();

View File

@@ -52,7 +52,7 @@ spring:
druid:
# 配置sqlite文件路径需要填写绝对路径推荐将sqlite文件放入到服务器上而非程序jar包或war包中
driver-class-name: dm.jdbc.driver.DmDriver
url: jdbc:dm://10.10.28.165:5236/GBCAS?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8
url: jdbc:dm://192.168.100.98:5236/GBCAS?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8
username: GBCAS
password: 123456789
#使用Druid数据源