package com.dragoninfo.dcuc.authweb.restcontroller.auth; import com.dragoninfo.dcuc.auth.auth.entity.AppFunInfo; import com.dragoninfo.dcuc.auth.auth.vo.EventInfoVO; import com.dragoninfo.dcuc.auth.auth.vo.TreeInfoVO; import com.dragoninfo.dcuc.auth.power.facade.IAppFunInfoFacade; import com.dragoninfo.dcuc.auth.power.facade.IFunEventFacade; import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.AppFunInfoVo; import com.dragoninfo.duceap.core.response.Result; import com.dragonsoft.duceap.commons.util.collections.CollectionUtils; import com.dragonsoft.duceap.commons.util.tree.SimpleTreeNodeItemResolver; import com.dragonsoft.duceap.commons.util.tree.TreeNodeUtils; import com.dragonsoft.duceap.web.annotation.Permission; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; /** * 菜单功能信息 * * @author Administrator */ @Api(tags = {"授权模块-菜单管理接口"}) @Permission(value = "power_config") @RestController @RequestMapping(value = "authsvr/v2/appfuninfo") public class AppFunInfoController { public static Logger logger = LoggerFactory.getLogger(AppFunInfoController.class); @Autowired private IAppFunInfoFacade iAppFunInfoFacade; @Autowired private IFunEventFacade iFunEventFacade; /** * 获取所有菜单信息列表 * * @return */ @ApiOperation(value = "获取所有菜单信息列表") @ApiImplicitParam(name = "appId", value = "应用id") @GetMapping(value = "/menuTreeList") public Result>> getMenuTreeList(@RequestParam(value = "appId") String appId) { List funList = iAppFunInfoFacade.getAllTreeList(appId); List> maps = TreeNodeUtils.generateTree(funList, new SimpleTreeNodeItemResolver("code", "pid")); for (Map map : maps) { List children = (List) map.get("children"); if (CollectionUtils.isNotEmpty(children)) { map.put("isParent", true); } } return Result.success(maps); } @ApiOperation(value = "根据id获取应用的菜单") @ApiImplicitParams({@ApiImplicitParam(paramType = "path", name = "id", value = "菜单ID", required = true , example = "40288a8b699fc2500169a33b20540000")}) @GetMapping(value = "/menuCode/{id}") public Result> getMenuCode(@PathVariable("id") String codeId) { List resultList = iAppFunInfoFacade.getCode(codeId); List vos = new ArrayList<>(); for (AppFunInfo source : resultList) { AppFunInfoVo vo = new AppFunInfoVo(); BeanUtils.copyProperties(source, vo); vos.add(vo); } return Result.success(vos); } /** * 获取菜单、功能初始化 * * @param * @return */ @ApiOperation(value = "根据id获取应用的菜单") @ApiImplicitParam(name = "appId", value = "应用id") @GetMapping(value = "/menu/{appId}") public Result>> getMenu(@PathVariable("appId") String appId) { //获取该应用的所有节点 List appAllTreeList = iAppFunInfoFacade.getAllTreeList(appId); for (TreeInfoVO treeInfoVO : appAllTreeList) { getPreterMission(treeInfoVO); } List> maps = TreeNodeUtils.generateTree(appAllTreeList, new SimpleTreeNodeItemResolver("code", "pid")); for (Map map : maps) { List children = (List) map.get("children"); if (CollectionUtils.isNotEmpty(children)) { map.put("isParent", true); } } return Result.success(maps); } public List getChildTreeObjects(List list, String parentCode) { List returnList = new ArrayList(); for (Iterator iterator = list.iterator(); iterator .hasNext(); ) { TreeInfoVO treeInfoVo = iterator.next(); //获取指定parentCode节点的子节点列表 String treePid = null; if (null == treeInfoVo.getPid()) { treePid = ""; } else { treePid = treeInfoVo.getPid(); } //获取指定parentCode节点的子节点列表 if (parentCode.equals(treePid)) { //递归获取当前节点的子节点 recursionFn(list, treeInfoVo); getPreterMission(treeInfoVo); returnList.add(treeInfoVo); } } return returnList; } public void recursionFn(List list, TreeInfoVO t) { //获取子节点列表 List childsList = getChildList(list, t); // 设置子节点列表 t.setChildren(childsList); for (TreeInfoVO nextChild : childsList) { // 判断子节点是否有子节点 if (hasChild(list, nextChild)) { // 有子节点,递归获取 recursionFn(list, nextChild); /* Iterator it = childsList.iterator(); while (it.hasNext()) { TreeInfoVO node = it.next(); //递归获取子节点 recursionFn(list, node); } */ } getPreterMission(nextChild); } } public static List getChildList(List list, TreeInfoVO t) { List childsList = new ArrayList(); Iterator it = list.iterator(); while (it.hasNext()) { TreeInfoVO child = it.next(); if (t.getId().equals(child.getPid())) { childsList.add(child); } } return childsList; } public static boolean hasChild(List list, TreeInfoVO t) { return getChildList(list, t).size() > 0; } /** * 组装菜单按钮 * * @param nextChild */ public void getPreterMission(TreeInfoVO nextChild) { List eventInfoVOList = iFunEventFacade.getEventByTreeId(nextChild.getId()); String pretermission = ""; for (EventInfoVO eventInfoVO : eventInfoVOList) { pretermission += "  " + eventInfoVO.getName() + ""; } nextChild.setDesc(pretermission); } }