| package com.xzx.gc.user.controller;  | 
|   | 
|   | 
| import cn.hutool.core.lang.Dict;  | 
| import com.xzx.gc.common.Result;  | 
| import com.xzx.gc.common.request.BaseController;  | 
| import com.xzx.gc.entity.UserAuth;  | 
| import com.xzx.gc.model.user.UserAuthDTO;  | 
| import com.xzx.gc.user.dto.AuthMenuDto;  | 
| import com.xzx.gc.user.service.UserAuthService;  | 
| import io.swagger.annotations.Api;  | 
| import io.swagger.annotations.ApiOperation;  | 
| import lombok.extern.slf4j.Slf4j;  | 
| import org.springframework.beans.factory.annotation.Autowired;  | 
| import org.springframework.validation.annotation.Validated;  | 
| import org.springframework.web.bind.annotation.*;  | 
|   | 
| import javax.servlet.http.HttpServletRequest;  | 
| import java.util.ArrayList;  | 
| import java.util.Comparator;  | 
| import java.util.List;  | 
| import java.util.stream.Collectors;  | 
|   | 
| @RestController  | 
| @RequestMapping("/auth/menu")  | 
| @Validated  | 
| @Slf4j  | 
| @Api(tags = "功能模块")  | 
| public class AuthController extends BaseController {  | 
|   | 
|     @Autowired  | 
|     private UserAuthService userAuthService;  | 
|   | 
|     @ApiOperation(value = "根据角色查询所有功能")  | 
|     @PostMapping("")  | 
|     public Result<List<AuthMenuDto>> find(HttpServletRequest request,@RequestBody UserAuthDTO userAuthDTO) {  | 
|         Result<List<AuthMenuDto>> result = new Result();  | 
|         List<AuthMenuDto> authMenuDtos=new ArrayList<>();  | 
|         List<UserAuth> menu = userAuthService.findMenu(getUserId(request),userAuthDTO.getHomePageType());  | 
|         //分组排序  | 
|         Dict dict=Dict.create();  | 
|         for (UserAuth userAuth : menu) {  | 
|             String categoryCode = userAuth.getCategoryCode();  | 
|             String categoryName = userAuth.getCategoryName();  | 
|             if(dict.containsKey(categoryCode)){  | 
|                 Dict dict1= (Dict) dict.get(categoryCode);  | 
|                 List<UserAuth> list= (List<UserAuth>) dict1.get("list");  | 
|                 list.add(userAuth);  | 
|                 dict1.set("list",list);  | 
|                 dict.set(categoryCode,dict1);  | 
|             }else{  | 
|                 List<UserAuth> res=new ArrayList<>();  | 
|                 res.add(userAuth);  | 
|                 Dict dict1=Dict.create();  | 
|                 dict1.set("list",res);  | 
|                 dict1.set("name",categoryName);  | 
|                 dict.set(categoryCode,dict1);  | 
|             }  | 
|         }  | 
|   | 
|         if(!dict.isEmpty()){  | 
|             for (String s : dict.keySet()) {  | 
|                 Dict dict1= (Dict) dict.get(s);  | 
|                 List<UserAuth> list= (List<UserAuth>) dict1.get("list");  | 
|                 String categoryName= dict1.getStr("name");  | 
|                 //排序  | 
|                 List<UserAuth> collect = list.stream().sorted(Comparator.comparing(UserAuth::getAuthOrder)).collect(Collectors.toList());  | 
|                 AuthMenuDto authMenuDto=new AuthMenuDto();  | 
|                 authMenuDto.setCategoryName(categoryName);  | 
|                 authMenuDto.setCategoryCode(s);  | 
|                 authMenuDto.setUserAuth(collect);  | 
|                 authMenuDtos.add(authMenuDto);  | 
|             }  | 
|         }  | 
|           | 
|         result.setData(authMenuDtos);  | 
|         return  result;  | 
|   | 
|     }  | 
|   | 
|   | 
| }  |