RoleService.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package com.nokia.service;
  2. import com.baomidou.mybatisplus.core.metadata.OrderItem;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.nokia.common.R;
  5. import com.nokia.dao.RoleDao;
  6. import com.nokia.vo.*;
  7. import org.springframework.stereotype.Service;
  8. import java.util.*;
  9. @Service
  10. public class RoleService {
  11. private final RoleDao roleDao;
  12. public RoleService(RoleDao roleDao) {
  13. this.roleDao = roleDao;
  14. }
  15. public R<PageVo<ListRoleVo>> list(ListRoleDto dto) {
  16. PageVo<ListRoleVo> vo = new PageVo<>();
  17. Page<ListRoleVo> page = new Page<>(dto.getCurrent(), dto.getPageSize());
  18. page.addOrder(OrderItem.asc("ar.\"system\""));
  19. List<ListRoleVo> list = roleDao.list(page, dto.getSystem(), dto.getRoleName());
  20. vo.setList(list);
  21. vo.setTotal(page.getTotal());
  22. return R.ok(vo);
  23. }
  24. public R<List<AllRoleVo>> all() {
  25. List<AllRoleBo> list = roleDao.all();
  26. Map<Object, Map<Object, List<AllRoleBo>>> map = new LinkedHashMap<>();
  27. for (AllRoleBo t : list) {
  28. map.putIfAbsent(t.getSystem(), new LinkedHashMap<>());
  29. map.get(t.getSystem()).putIfAbsent(t.getFunctionId(), new ArrayList<>());
  30. map.get(t.getSystem()).get(t.getFunctionId()).add(t);
  31. }
  32. List<AllRoleVo> vos = new ArrayList<>();
  33. for (Map<Object, List<AllRoleBo>> t : map.values()) {
  34. List<FunctionBo> functionBos = new ArrayList<>();
  35. AllRoleVo vo = new AllRoleVo();
  36. vo.setList(functionBos);
  37. vos.add(vo);
  38. for (List<AllRoleBo> tt : t.values()) {
  39. FunctionBo functionBo = new FunctionBo();
  40. functionBos.add(functionBo);
  41. List<RoleBo> roleBos = new ArrayList<>();
  42. functionBo.setList(roleBos);
  43. for (AllRoleBo ttt : tt) {
  44. vo.setSystem(ttt.getSystem());
  45. vo.setSystemName(ttt.getSystemName());
  46. functionBo.setFunctionId(ttt.getFunctionId());
  47. functionBo.setFunctionName(ttt.getFunctionName());
  48. RoleBo roleBo = new RoleBo();
  49. roleBo.setRoleId(ttt.getRoleId());
  50. roleBo.setRoleName(ttt.getRoleName());
  51. roleBos.add(roleBo);
  52. }
  53. }
  54. }
  55. return R.ok(vos);
  56. }
  57. }