12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package com.nokia.service;
- import com.baomidou.mybatisplus.core.metadata.OrderItem;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.nokia.common.R;
- import com.nokia.dao.RoleDao;
- import com.nokia.vo.*;
- import org.springframework.stereotype.Service;
- import java.util.*;
- @Service
- public class RoleService {
- private final RoleDao roleDao;
- public RoleService(RoleDao roleDao) {
- this.roleDao = roleDao;
- }
- public R<PageVo<ListRoleVo>> list(ListRoleDto dto) {
- PageVo<ListRoleVo> vo = new PageVo<>();
- Page<ListRoleVo> page = new Page<>(dto.getCurrent(), dto.getPageSize());
- page.addOrder(OrderItem.asc("ar.\"system\""));
- List<ListRoleVo> list = roleDao.list(page, dto.getSystem(), dto.getRoleName());
- vo.setList(list);
- vo.setTotal(page.getTotal());
- return R.ok(vo);
- }
- public R<List<AllRoleVo>> all() {
- List<AllRoleBo> list = roleDao.all();
- Map<Object, Map<Object, List<AllRoleBo>>> map = new LinkedHashMap<>();
- for (AllRoleBo t : list) {
- map.putIfAbsent(t.getSystem(), new LinkedHashMap<>());
- map.get(t.getSystem()).putIfAbsent(t.getFunctionId(), new ArrayList<>());
- map.get(t.getSystem()).get(t.getFunctionId()).add(t);
- }
- List<AllRoleVo> vos = new ArrayList<>();
- for (Map<Object, List<AllRoleBo>> t : map.values()) {
- List<FunctionBo> functionBos = new ArrayList<>();
- AllRoleVo vo = new AllRoleVo();
- vo.setList(functionBos);
- vos.add(vo);
- for (List<AllRoleBo> tt : t.values()) {
- FunctionBo functionBo = new FunctionBo();
- functionBos.add(functionBo);
- List<RoleBo> roleBos = new ArrayList<>();
- functionBo.setList(roleBos);
- for (AllRoleBo ttt : tt) {
- vo.setSystem(ttt.getSystem());
- vo.setSystemName(ttt.getSystemName());
- functionBo.setFunctionId(ttt.getFunctionId());
- functionBo.setFunctionName(ttt.getFunctionName());
- RoleBo roleBo = new RoleBo();
- roleBo.setRoleId(ttt.getRoleId());
- roleBo.setRoleName(ttt.getRoleName());
- roleBos.add(roleBo);
- }
- }
- }
- return R.ok(vos);
- }
- }
|