| | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.highdatas.mdm.entity.*; |
| | | import com.highdatas.mdm.mapper.MasterAuthorMapper; |
| | | import com.highdatas.mdm.pojo.CodeMsg; |
| | | import com.highdatas.mdm.pojo.MasterAuthorType; |
| | | import com.highdatas.mdm.pojo.Result; |
| | | import com.highdatas.mdm.service.*; |
| | | import com.highdatas.mdm.util.Constant; |
| | | import com.highdatas.mdm.util.DbUtils; |
| | | import com.highdatas.mdm.util.RedisClient; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | IMasterAuthorService authorService; |
| | | @Autowired |
| | | IMasterAuthorDetailService authorDetailService; |
| | | @Autowired |
| | | ITUserRoleService userRoleService; |
| | | |
| | | @Autowired |
| | | IMenuMappingService menuMappingService; |
| | | @Autowired |
| | | ISysMenuService menuService; |
| | | @Autowired |
| | | MasterAuthorMapper masterAuthorMapper; |
| | | @Autowired |
| | | IMaintainFieldService maintainFieldService; |
| | | @Autowired |
| | | IMasterAuthorUnactiveService masterAuthorUnactiveService; |
| | | @Autowired |
| | | IMasterAuthorSubscribeService masterAuthorSubscribeService; |
| | | @Autowired |
| | | IMaintainService maintainService; |
| | | @Autowired |
| | | RedisClient redisClient; |
| | | |
| | | public static final String masterAuthorType = "masterAuthorType"; |
| | | public static final String masterId = "masterId"; |
| | |
| | | private String maintainFieldId = "maintainFieldId"; |
| | | private String maintain_field_id = "maintain_field_id"; |
| | | |
| | | /** |
| | | * |
| | | * @description: 添加或者更新权限 |
| | | * @return 权限数据 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/addOrUpdate", method = RequestMethod.POST) |
| | | public Result deleteModel(@RequestBody MasterAuthor masterAuthor) { |
| | | if (StringUtils.isEmpty(masterAuthor.getMaintainFieldId())) { |
| | | return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); |
| | | } |
| | | if (!StringUtils.isEmpty(masterAuthor.getId())) { |
| | | masterAuthor.setUpdateTime(new Date()); |
| | | }else { |
| | |
| | | |
| | | boolean b = masterAuthor.insertOrUpdate(); |
| | | if (b) { |
| | | redisClient.delByCharacter(masterAuthor.getCharacterId()); |
| | | return Result.success(masterAuthor); |
| | | }else { |
| | | return Result.error(CodeMsg.UPDATE_ERROR); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 通过系统用户获取权限 |
| | | * @param characterId 系统用户 |
| | | * @param isGroup 是否为用户组数据 |
| | | * @param type 用户类型 |
| | | * @return 具体数据 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/get/{characterId}", method = RequestMethod.GET) |
| | | public Result get(@PathVariable String characterId, @RequestParam MasterAuthorType type, HttpServletRequest request){ |
| | | List<MasterAuthor> masterAuthorList = authorService.selectList(new EntityWrapper<MasterAuthor>().eq("type", type.name()).eq("character_id", characterId)); |
| | | public Result get(@PathVariable String characterId,@RequestParam boolean isGroup, @RequestParam MasterAuthorType type, HttpServletRequest request){ |
| | | List<MasterAuthor> masterAuthorList = authorService.selectList(new EntityWrapper<MasterAuthor>().eq("user_group", isGroup).eq("type", type.name()).eq("character_id", characterId)); |
| | | if (type.equals(MasterAuthorType.role) && masterAuthorList.isEmpty()) { |
| | | return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); |
| | | }else if (type.equals(MasterAuthorType.user) && masterAuthorList.isEmpty()){ |
| | | //user 获取角色 多脚色混合 |
| | | String userId = characterId; |
| | | List<TUserRole> tUserRoles = userRoleService.selectList(new EntityWrapper<TUserRole>().eq(Constant.USERID, userId)); |
| | | List<String> roleIdList = tUserRoles.stream().map(tUserRole -> tUserRole.getRoleId()).collect(Collectors.toList()); |
| | | HashMap<String, MasterAuthor> tableMasterAuthor = authorService.merageRoleAuthor(roleIdList); |
| | | Set<String> roleIdSet; |
| | | if (isGroup) { |
| | | roleIdSet = DbUtils.getRoleByGroup(userId); |
| | | } else { |
| | | roleIdSet = DbUtils.getRoleByUser(userId); |
| | | } |
| | | if (roleIdSet.isEmpty()) { |
| | | return Result.success(null); |
| | | } |
| | | HashMap<String, MasterAuthor> tableMasterAuthor = authorService.merageRoleAuthor(roleIdSet); |
| | | if (tableMasterAuthor == null) { |
| | | Result.success(null); |
| | | } |
| | |
| | | |
| | | Set<String> collect = list.stream().map(masterAuthor -> masterAuthor.getMenuId()).collect(Collectors.toSet()); |
| | | LinkedHashSet<String> menuIds= new LinkedHashSet<>(collect); |
| | | LinkedHashSet<String> byParentId = menuService.getByParentId(menuIds); |
| | | List<SysMenu> sysMenus = menuService.selectBatchIds(byParentId); |
| | | List<SysMenu> sysMenus = menuService.getMenuByParentId(menuIds); |
| | | if (sysMenus == null) { |
| | | return Result.success(object); |
| | | } |
| | | object.fluentPut("audit",sysMenus); |
| | | return Result.success(object); |
| | | } |
| | |
| | | .eq(Constant.PARENT_ID, masterAuthor.getId())); |
| | | masterAuthor.setFields(masterAuthorDetails); |
| | | } |
| | | |
| | | JSONObject object = new JSONObject(); |
| | | object.fluentPut("type", type); |
| | | object.fluentPut("author",masterAuthorList); |
| | | |
| | | Set<String> collect = masterAuthorList.stream().map(masterAuthor -> masterAuthor.getMenuId()).collect(Collectors.toSet()); |
| | | LinkedHashSet<String> menuIds= new LinkedHashSet<>(collect); |
| | | LinkedHashSet<String> byParentId = menuService.getByParentId(menuIds); |
| | | List<SysMenu> sysMenus = menuService.selectBatchIds(byParentId); |
| | | List<SysMenu> sysMenus = menuService.getMenuByParentId(menuIds); |
| | | if (sysMenus == null) { |
| | | return Result.success(object); |
| | | } |
| | | |
| | | object.fluentPut("type", MasterAuthorType.user); |
| | | object.fluentPut("author",masterAuthorList); |
| | | object.fluentPut("audit",sysMenus); |
| | | return Result.success(object); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 通过系统用户删除权限 |
| | | * @param characterId 系统用户 |
| | | * @param type 用户类型 |
| | | * @return 是否删除成功 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/delete/{characterId}", method = RequestMethod.GET) |
| | | public Result delete(@PathVariable String characterId, @RequestParam MasterAuthorType type){ |
| | | List<MasterAuthor> masterAuthorList = authorService.selectList(new EntityWrapper<MasterAuthor>() |
| | | .eq(Constant.TYPE, type).eq(this.characterId, characterId)); |
| | | .eq(Constant.TYPE, type).eq(this.character_id, characterId)); |
| | | if (masterAuthorList.isEmpty()) { |
| | | return Result.success(null); |
| | | } |
| | |
| | | } |
| | | |
| | | if (delete) { |
| | | redisClient.delByCharacter(characterId); |
| | | return Result.success(CodeMsg.DELETE_SUCCESS); |
| | | }else { |
| | | return Result.error(CodeMsg.DELETE_ERROR); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @description: 通过主题删除权限 |
| | | * @param characterId 系统用户 |
| | | * @param menuId 主题id |
| | | * @param type 用户类型 |
| | | * @return 具体数据 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/delete/menu/{menuId}", method = RequestMethod.GET) |
| | | public Result deleteTable(@PathVariable String menuId, @RequestParam String characterId, @RequestParam MasterAuthorType type, HttpServletRequest request){ |
| | | String maintainFieldId = request.getParameter(this.maintainFieldId); |
| | |
| | | .eq(Constant.TYPE, type) |
| | | .eq(character_id, characterId) |
| | | .eq("menu_id", menuId); |
| | | Wrapper<MasterAuthor> menuWrapper = new EntityWrapper<MasterAuthor>() |
| | | .eq(Constant.TYPE, type) |
| | | .eq(character_id, characterId) |
| | | .eq("menu_id", menuId); |
| | | if (!StringUtils.isEmpty(maintainFieldId)) { |
| | | masterAuthorWrapper.eq(this.maintain_field_id, maintainFieldId); |
| | | } |
| | | |
| | | List<MasterAuthor> masterAuthorList = authorService.selectList(masterAuthorWrapper); |
| | | if (masterAuthorList.isEmpty()) { |
| | | int count = authorService.selectCount(menuWrapper); |
| | | boolean only = false; |
| | | if (count == 1 && !StringUtils.isEmpty(maintainFieldId)) { |
| | | only = true; |
| | | } |
| | | List<MasterAuthor> masterAuthors = authorService.selectList(masterAuthorWrapper); |
| | | if (masterAuthors == null || masterAuthors.isEmpty()) { |
| | | return Result.success(null); |
| | | } |
| | | boolean partDel = false; |
| | | if (masterAuthorList.size() == 1 && !StringUtils.isEmpty(maintainFieldId)) { |
| | | // 只有一个且删除 字段版本 保留本条 |
| | | partDel = true; |
| | | } |
| | | boolean delete = false; |
| | | for (MasterAuthor masterAuthor : masterAuthorList) { |
| | | for (MasterAuthor masterAuthor : masterAuthors) { |
| | | delete = authorDetailService.delete(new EntityWrapper<MasterAuthorDetail>().eq(Constant.PARENT_ID, masterAuthor.getId())); |
| | | if (delete) { |
| | | if (partDel) { |
| | | delete = masterAuthor.setMaintainFieldId(null).updateById(); |
| | | if (only){ |
| | | delete = masterAuthor.setMaintainFieldId(null).setFieldAuto(false).setMaintainAuto(false).setUpdateTime(new Date()).updateById(); |
| | | }else { |
| | | delete = masterAuthor.deleteById(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | if (delete) { |
| | | redisClient.delByCharacter(characterId); |
| | | return Result.success(CodeMsg.DELETE_SUCCESS); |
| | | }else { |
| | | return Result.error(CodeMsg.DELETE_ERROR); |
| | | } |
| | | } |
| | | |
| | | @RequestMapping(value = "/addRole/{roleId}", method = RequestMethod.GET) |
| | | public Result addRole(@PathVariable String roleId, HttpServletRequest request){ |
| | | /** |
| | | * |
| | | * @description: 用户组添加角色关联 |
| | | * @param groupId 用户组id |
| | | * @param roleId 角色id |
| | | * @return 是否添加成功 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/groupAddRole/{roleId}", method = RequestMethod.GET) |
| | | public Result addGroupRole(@PathVariable String roleId, @RequestParam String groupId, HttpServletRequest request){ |
| | | TUser user = DbUtils.getUser(request); |
| | | String userId = user.getUserId(); |
| | | List<TUserRole> tUserRoles = userRoleService.selectList(new EntityWrapper<TUserRole>().eq(Constant.USERID, userId)); |
| | | List<String> roleIdList = tUserRoles.stream().map(tUserRole -> tUserRole.getRoleId()).collect(Collectors.toList()); |
| | | roleIdList.add(roleId); |
| | | if (user == null){ |
| | | return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); |
| | | } |
| | | ArrayList<String> addRoleList = new ArrayList<>(); |
| | | Set<String> roleIdSet = DbUtils.getRoleByGroup(groupId); |
| | | addRoleList.addAll(roleIdSet); |
| | | addRoleList.add(roleId); |
| | | boolean b = DbUtils.groupAddOneRole(user.getUserId(),groupId, addRoleList); |
| | | if (!b) { |
| | | return Result.error(CodeMsg.INSERT_ERROR); |
| | | } |
| | | |
| | | HashMap<String, MasterAuthor> tableMasterAuthor = authorService.merageRoleAuthor(roleIdList); |
| | | roleIdSet.add(roleId); |
| | | |
| | | HashMap<String, MasterAuthor> tableMasterAuthor = authorService.merageRoleAuthor(roleIdSet); |
| | | if (tableMasterAuthor == null) { |
| | | Result.success(null); |
| | | } |
| | | return Result.success(tableMasterAuthor.values()); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 用户添加角色关联 |
| | | * @param userId 用户id |
| | | * @param roleId 角色id |
| | | * @return 是否添加成功 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/userAddRole/{roleId}", method = RequestMethod.GET) |
| | | public Result addRole(@PathVariable String roleId, @RequestParam String userId, HttpServletRequest request){ |
| | | TUser user = DbUtils.getUserById(userId); |
| | | if (user == null){ |
| | | return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); |
| | | } |
| | | ArrayList<String> addRoleList = new ArrayList<>(); |
| | | Set<String> roleIdSet = DbUtils.getRoleByUser(userId); |
| | | addRoleList.addAll(roleIdSet); |
| | | addRoleList.add(roleId); |
| | | boolean b = DbUtils.addOneRole(user, addRoleList); |
| | | if (!b) { |
| | | return Result.error(CodeMsg.INSERT_ERROR); |
| | | } |
| | | |
| | | roleIdSet.add(roleId); |
| | | |
| | | HashMap<String, MasterAuthor> tableMasterAuthor = authorService.merageRoleAuthor(roleIdSet); |
| | | if (tableMasterAuthor == null) { |
| | | Result.success(null); |
| | | } |
| | | return Result.success(tableMasterAuthor.values()); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 用户删除角色关联 |
| | | * @param userId 用户id |
| | | * @param roleId 角色id |
| | | * @return 是否删除成功 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/userDelRole/{roleId}", method = RequestMethod.GET) |
| | | public Result delRole(@PathVariable String roleId, @RequestParam String userId, HttpServletRequest request){ |
| | | ArrayList<String> delRoleList = new ArrayList<>(); |
| | | |
| | | delRoleList.add(roleId); |
| | | boolean b = DbUtils.delOneRole(userId, delRoleList); |
| | | if (!b) { |
| | | return Result.error(CodeMsg.INSERT_ERROR); |
| | | } |
| | | |
| | | Set<String> roleIdSet = DbUtils.getRoleByUser(userId); |
| | | HashMap<String, MasterAuthor> tableMasterAuthor = authorService.merageRoleAuthor(roleIdSet); |
| | | if (tableMasterAuthor == null) { |
| | | Result.success(null); |
| | | } |
| | | return Result.success(tableMasterAuthor.values()); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 用户组删除角色关联 |
| | | * @param groupId 用户组id |
| | | * @param roleId 角色id |
| | | * @return 是否删除成功 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/groupDelRole/{roleId}", method = RequestMethod.GET) |
| | | public Result delGroupRole(@PathVariable String roleId, @RequestParam String groupId, HttpServletRequest request){ |
| | | ArrayList<String> delRoleList = new ArrayList<>(); |
| | | |
| | | delRoleList.add(roleId); |
| | | boolean b = DbUtils.groupDelOneRole(groupId, delRoleList); |
| | | if (!b) { |
| | | return Result.error(CodeMsg.INSERT_ERROR); |
| | | } |
| | | |
| | | Set<String> roleIdSet = DbUtils.getRoleByGroup(groupId); |
| | | HashMap<String, MasterAuthor> tableMasterAuthor = authorService.merageRoleAuthor(roleIdSet); |
| | | if (tableMasterAuthor == null) { |
| | | Result.success(null); |
| | | } |
| | | return Result.success(tableMasterAuthor.values()); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 通过用户id获取已经注册list |
| | | * @param userId 用户id |
| | | * @return 已注册list |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/subscribeList/{userId}", method = RequestMethod.GET) |
| | | public Result subscribeList(@PathVariable String userId, HttpServletRequest request){ |
| | | TUser user = DbUtils.getUserById(userId); |
| | | if (user == null){ |
| | | return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); |
| | | } |
| | | |
| | | List<SysMenu> menuList = authorService.getMenuUnParent(user, true); |
| | | if (menuList == null) { |
| | | return Result.success(null); |
| | | } |
| | | List<MasterAuthor> userAuthor = authorService.getUserAuthor(userId, null); |
| | | |
| | | ArrayList<SysMenu> result = new ArrayList<>(); |
| | | for (SysMenu sysMenu : menuList) { |
| | | long count = userAuthor.stream().filter(masterAuthor -> masterAuthor.getMenuId().equalsIgnoreCase(sysMenu.getId())).count(); |
| | | if (count > 0) { |
| | | result.add(sysMenu); |
| | | } |
| | | } |
| | | LinkedHashSet<String> parentSet = new LinkedHashSet<>(); |
| | | |
| | | for (SysMenu menu : result) { |
| | | menu.setShow(false); |
| | | String menuId = menu.getId(); |
| | | String tableNameByMenu = menuMappingService.getTableNameByMenu(menuId); |
| | | menu.setTableName(tableNameByMenu); |
| | | parentSet.clear(); |
| | | parentSet.add(menuId); |
| | | List<SysMenu> sysMenus = menuService.getMenuByParentId(parentSet); |
| | | |
| | | menu.setParentMenuList(sysMenus); |
| | | int i = masterAuthorSubscribeService.selectCount(new EntityWrapper<MasterAuthorSubscribe>().eq("menu_id", menuId).eq("user_id", userId)); |
| | | if (i > 0) { |
| | | menu.setSubscribe(true); |
| | | } |
| | | } |
| | | return Result.success(result); |
| | | } |
| | | |
| | | // @RequestMapping(value = "/canLoadData/{userId}", method = RequestMethod.GET) |
| | | // public Result canLoadData(@PathVariable String userId, @RequestParam String tableName, HttpServletRequest request) { |
| | | // TUser user = DbUtils.getUserById(userId); |
| | | // if (user == null) { |
| | | // return Result.error(CodeMsg.USER_NOT_MATHED); |
| | | // } |
| | | // } |
| | | |
| | | /** |
| | | * |
| | | * @description: 通过userid获取有权限的主题 |
| | | * @param userId 用户id |
| | | * @return 主题列表 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/menu/{userId}", method = RequestMethod.GET) |
| | | public Result<List<SysMenu>> menuList(@PathVariable String userId, HttpServletRequest request) { |
| | | TUser user = DbUtils.getUserById(userId); |
| | | if (user == null) { |
| | | return Result.error(CodeMsg.USER_NOT_MATHED); |
| | | } |
| | | |
| | | List<SysMenu> menu = authorService.getMenu(user, true); |
| | | return Result.success(menu) ; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 通过userid获取有权限的主题数据 |
| | | * @param userId 用户id |
| | | * @return 获取有权限的数据数 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/getCnt/{userId}", method = RequestMethod.GET) |
| | | public Result cnt(@PathVariable String userId, HttpServletRequest request) { |
| | | //TODO active |
| | | TUser user = DbUtils.getUserById(userId); |
| | | if (user == null) { |
| | | return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); |
| | | } |
| | | List<MasterAuthor> userAuthor = authorService.getUserAuthor(userId, null); |
| | | |
| | | List<SysMenu> menuList = authorService.getMenuUnParent(user, true); |
| | | int totalCnt = 0; |
| | | int subscribeCnt = 0; |
| | | int activeCnt = 0; |
| | | if (menuList == null) { |
| | | JSONObject object = new JSONObject(); |
| | | object.fluentPut("totalCnt", 0); |
| | | object.fluentPut("activeCnt", 0); |
| | | object.fluentPut("subscribeCnt", 0); |
| | | return Result.success(object); |
| | | } |
| | | for (SysMenu sysMenu : menuList) { |
| | | List<MasterAuthor> authorMaintainFieldList = userAuthor.stream() |
| | | .filter(masterAuthor -> masterAuthor.getMenuId().equalsIgnoreCase(sysMenu.getId())) |
| | | .collect(Collectors.toList()); |
| | | int count = authorMaintainFieldList.size(); |
| | | if (count > 0) { |
| | | totalCnt++; |
| | | HashSet<Maintain> maintainSet = new HashSet<>(); |
| | | for (MasterAuthor masterAuthor : authorMaintainFieldList) { |
| | | String maintainFieldId = masterAuthor.getMaintainFieldId(); |
| | | String tableName = masterAuthor.getTableName(); |
| | | List<Maintain> maintainByMaintainField = maintainFieldService.getMaintainByMaintainField(maintainFieldId, tableName); |
| | | if (maintainByMaintainField != null) { |
| | | maintainSet.addAll(maintainByMaintainField); |
| | | } |
| | | |
| | | } |
| | | int unActiveCnt = masterAuthorUnactiveService.selectCount(new EntityWrapper<MasterAuthorUnactive>().in("maintain_id", maintainSet).eq("user_id", userId)); |
| | | if (maintainSet.size() != unActiveCnt) { |
| | | activeCnt++; |
| | | } |
| | | int oneSubscribeCnt = masterAuthorSubscribeService.selectCount(new EntityWrapper<MasterAuthorSubscribe>().eq("user_id", userId).eq("menu_id", sysMenu.getId())); |
| | | if (oneSubscribeCnt > 0){ |
| | | subscribeCnt++; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | JSONObject object = new JSONObject(); |
| | | object.fluentPut("totalCnt", totalCnt); |
| | | object.fluentPut("activeCnt", activeCnt); |
| | | object.fluentPut("subscribeCnt", subscribeCnt); |
| | | return Result.success(object); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 通过版本获取激活的主题 |
| | | * @param maintainId 主题id |
| | | * @param userId 用户id |
| | | * @param active 激活状态 |
| | | * @return 已激活的主题数 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/active/{maintainId}", method = RequestMethod.GET) |
| | | public Result active(@PathVariable String maintainId, @RequestParam String userId, @RequestParam Boolean active) { |
| | | TUser user = DbUtils.getUserById(userId); |
| | | if (user == null) { |
| | | return Result.error(CodeMsg.USER_NOT_MATHED); |
| | | } |
| | | MasterAuthorUnactive masterAuthorUnactive = masterAuthorUnactiveService.selectOne(new EntityWrapper<MasterAuthorUnactive>().eq(Constant.USERID, userId).eq("maintain_id", maintainId)); |
| | | if (masterAuthorUnactive == null && active) { |
| | | return Result.success(null); |
| | | } else if (masterAuthorUnactive == null && !active) { |
| | | boolean insert = new MasterAuthorUnactive().setId(DbUtils.getUUID()).setMaintainId(maintainId).setUserId(userId).insert(); |
| | | if (insert) { |
| | | return Result.success(null); |
| | | } else { |
| | | return Result.error(null); |
| | | } |
| | | } else if (active) { |
| | | boolean delete = masterAuthorUnactive.deleteById(); |
| | | if (delete) { |
| | | return Result.success(null); |
| | | } else { |
| | | return Result.error(null); |
| | | } |
| | | } else { |
| | | return Result.success(null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 获取有权限的list和用户map |
| | | * @return list和用户map列表 |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/cntList", method = RequestMethod.GET) |
| | | public Result cntList() { |
| | | HashMap<String, Long> result = new HashMap<>(); |
| | | //user |
| | | |
| | | Set<TUser> allUser = DbUtils.getAllUser(); |
| | | for (TUser user : allUser) { |
| | | int activeCnt = 0; |
| | | List<MasterAuthor> userAuthor = authorService.getUserAuthor(user.getUserId(), null); |
| | | |
| | | List<SysMenu> menuList = authorService.getMenuUnParent(user, true); |
| | | |
| | | if (menuList == null) { |
| | | continue; |
| | | } |
| | | for (SysMenu sysMenu : menuList) { |
| | | List<MasterAuthor> authorMaintainFieldList = userAuthor.stream() |
| | | .filter(masterAuthor -> masterAuthor.getMenuId().equalsIgnoreCase(sysMenu.getId())) |
| | | .collect(Collectors.toList()); |
| | | int count = authorMaintainFieldList.size(); |
| | | if (count > 0) { |
| | | HashSet<Maintain> maintainSet = new HashSet<>(); |
| | | for (MasterAuthor masterAuthor : authorMaintainFieldList) { |
| | | String maintainFieldId = masterAuthor.getMaintainFieldId(); |
| | | String tableName = masterAuthor.getTableName(); |
| | | List<Maintain> maintainByMaintainField = maintainFieldService.getMaintainByMaintainField(maintainFieldId, tableName); |
| | | maintainSet.addAll(maintainByMaintainField); |
| | | } |
| | | int unActiveCnt = masterAuthorUnactiveService.selectCount(new EntityWrapper<MasterAuthorUnactive>().in("maintain_id", maintainSet).eq("user_id", user.getUserId())); |
| | | if (maintainSet.size() != unActiveCnt) { |
| | | activeCnt++; |
| | | } |
| | | |
| | | } |
| | | result.put(user.getUserId(), Long.valueOf(activeCnt)); |
| | | } |
| | | } |
| | | |
| | | List<Map<String, Object>> userMapList = masterAuthorMapper.selectViewCnt(); |
| | | merageUserCnt(result, userMapList); |
| | | if (result.isEmpty()) { |
| | | return Result.success(null); |
| | | } |
| | | return Result.success(result); |
| | | } |
| | | /** |
| | | * |
| | | * @description: 通过表名获取有权限的版本list |
| | | * @param userId 用户id |
| | | * @param tableName 表名 |
| | | * @return 获取有权限的版本list |
| | | * |
| | | */ |
| | | @RequestMapping(value = "/maintainList/{userId}", method = RequestMethod.GET) |
| | | public Result maintainList(@PathVariable String userId, @RequestParam String tableName) { |
| | | TUser user = DbUtils.getUserById(userId); |
| | | if (user == null) { |
| | | return Result.error(CodeMsg.USER_NOT_MATHED); |
| | | } |
| | | Set<Maintain> maintainSet = authorService.getMaintainSet(tableName, user); |
| | | List<MasterAuthorUnactive> masterAuthorUnactives = masterAuthorUnactiveService.selectList(new EntityWrapper<MasterAuthorUnactive>().eq(Constant.USERID, userId)); |
| | | for (Maintain maintain : maintainSet) { |
| | | long count = masterAuthorUnactives.stream() |
| | | .filter(masterAuthorUnactive -> !StringUtils.isEmpty(masterAuthorUnactive.getMaintainId())) |
| | | .filter(masterAuthorUnactive -> masterAuthorUnactive.getMaintainId().equalsIgnoreCase(maintain.getId())) |
| | | .count(); |
| | | if (count > 0) { |
| | | maintain.setActive(false); |
| | | } else { |
| | | maintain.setActive(true); |
| | | } |
| | | } |
| | | return Result.success(maintainSet); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @description: 通过版本获取激活的主题 |
| | | * @param result 组装用户id, 数据的 map |
| | | * @param masterUserMapList 视图的数据list map |
| | | * @return result 用户id, 权限数据量的 map |
| | | * |
| | | */ |
| | | private void merageUserCnt(HashMap<String, Long> result, List<Map<String, Object>> masterUserMapList) { |
| | | for (Map<String, Object> stringStringMap : masterUserMapList) { |
| | | String user = stringStringMap.get(Constant.USERID).toString(); |
| | | long cnt = (long)(stringStringMap.get(Constant.CNT)); |
| | | |
| | | Long val = result.get(user); |
| | | if (val == null) { |
| | | result.put(user, Long.valueOf(cnt)); |
| | | } else { |
| | | val += Long.valueOf(cnt); |
| | | result.put(user, val); |
| | | } |
| | | } |
| | | } |
| | | } |