| | |
| | | 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; |
| | |
| | | IMenuMappingService menuMappingService; |
| | | @Autowired |
| | | ISysMenuService menuService; |
| | | @Autowired |
| | | MasterAuthorMapper masterAuthorMapper; |
| | | @Autowired |
| | | IMaintainFieldService maintainFieldService; |
| | | @Autowired |
| | | IMasterAuthorUnactiveService masterAuthorUnactiveService; |
| | | @Autowired |
| | | IMasterAuthorSubscribeService masterAuthorSubscribeService; |
| | | |
| | | public static final String masterAuthorType = "masterAuthorType"; |
| | | public static final String masterId = "masterId"; |
| | |
| | | |
| | | @RequestMapping(value = "/get/{characterId}", method = RequestMethod.GET) |
| | | 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); |
| | |
| | | |
| | | Set<String> collect = list.stream().map(masterAuthor -> masterAuthor.getMenuId()).collect(Collectors.toSet()); |
| | | LinkedHashSet<String> menuIds= new LinkedHashSet<>(collect); |
| | | LinkedHashSet<String> byParentId = menuService.getByParentId(menuIds); |
| | | if (byParentId == null) { |
| | | List<SysMenu> sysMenus = menuService.getMenuByParentId(menuIds); |
| | | if (sysMenus == null) { |
| | | return Result.success(object); |
| | | } |
| | | List<SysMenu> sysMenus = menuService.selectBatchIds(byParentId); |
| | | object.fluentPut("audit",sysMenus); |
| | | return Result.success(object); |
| | | } |
| | |
| | | |
| | | Set<String> collect = masterAuthorList.stream().map(masterAuthor -> masterAuthor.getMenuId()).collect(Collectors.toSet()); |
| | | LinkedHashSet<String> menuIds= new LinkedHashSet<>(collect); |
| | | LinkedHashSet<String> byParentId = menuService.getByParentId(menuIds); |
| | | if (byParentId == null) { |
| | | List<SysMenu> sysMenus = menuService.getMenuByParentId(menuIds); |
| | | if (sysMenus == null) { |
| | | return Result.success(object); |
| | | } |
| | | List<SysMenu> sysMenus = menuService.selectBatchIds(byParentId); |
| | | |
| | | object.fluentPut("audit",sysMenus); |
| | | return Result.success(object); |
| | |
| | | return Result.success(tableMasterAuthor.values()); |
| | | } |
| | | |
| | | @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 = "/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) ; |
| | | } |
| | | |
| | | |
| | | @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); |
| | | 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); |
| | | } |
| | | |
| | | @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); |
| | | } |
| | | } |
| | | |
| | | |
| | | @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); |
| | | } |
| | | |
| | | @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); |
| | | } |
| | | |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | } |