package jnpf.base.controller; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import jnpf.base.ActionResult; import jnpf.base.entity.*; import jnpf.base.model.module.*; import jnpf.base.model.online.VisualMenuModel; import jnpf.base.service.*; import jnpf.base.util.visualUtil.PubulishUtil; import jnpf.base.vo.DownloadVO; import jnpf.base.vo.ListVO; import jnpf.base.vo.PaginationVO; import jnpf.config.ConfigValueUtil; import jnpf.constant.JnpfConst; import jnpf.constant.MsgCode; import jnpf.constant.PermissionConst; import jnpf.database.util.TenantDataSourceUtil; import jnpf.emnus.ModuleTypeEnum; import jnpf.exception.DataException; import jnpf.exception.WorkFlowException; import jnpf.model.FlowWorkModel; import jnpf.model.UserMenuModel; import jnpf.model.tenant.*; import jnpf.permission.entity.AuthorizeEntity; import jnpf.permission.entity.PermissionGroupEntity; import jnpf.permission.model.user.vo.BaseInfoVo; import jnpf.permission.service.AuthorizeService; import jnpf.permission.service.PermissionGroupService; import jnpf.permission.service.UserService; import jnpf.util.*; import jnpf.util.context.RequestContext; import jnpf.util.treeutil.ListToTreeUtil; import jnpf.util.treeutil.SumTree; import jnpf.util.treeutil.TreeViewModel; import jnpf.util.treeutil.newtreeutil.TreeDotUtils; import jnpf.util.type.AuthorizeType; import jnpf.workflow.service.TemplateApi; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; /** * 系统功能 * * @author JNPF开发平台组 * @version V3.1.0 * @copyright 引迈信息技术有限公司 * @date 2019年9月27日 上午9:18 */ @Tag(name = "系统菜单", description = "menu") @RestController @RequestMapping("/api/system/Menu") public class ModuleController extends SuperController { @Autowired private ModuleService moduleService; @Autowired private RedisUtil redisUtil; @Autowired private CacheKeyUtil cacheKeyUtil; @Autowired private SystemService systemService; @Autowired private ConfigValueUtil configValueUtil; @Autowired private TemplateApi templateApi; @Autowired private PubulishUtil pubulishUtil; @Operation(summary = "获取菜单列表") @Parameters({ @Parameter(name = "systemId", description = "系统id", required = true) }) @GetMapping("/ModuleBySystem") public ActionResult> list(PaginationMenu paginationMenu) { String appCode = RequestContext.getAppCode(); List data = moduleService.getList(appCode, paginationMenu.getCategory(), paginationMenu.getKeyword(), paginationMenu.getType(), paginationMenu.getEnabledMark(), null, false); // 递归查上级 Map moduleEntityMap = data.stream().collect(Collectors.toMap(ModuleEntity::getId, Function.identity())); if (StringUtil.isNotEmpty(paginationMenu.getKeyword())) { moduleService.getParentModule(data, moduleEntityMap); } List list = JsonUtil.getJsonToList(moduleEntityMap.values(), UserMenuModel.class); for (UserMenuModel item : list) { if (Objects.equals(item.getType(), 3)) { if (Objects.equals(item.getIsButtonAuthorize(), 1) || Objects.equals(item.getIsColumnAuthorize(), 1) || Objects.equals(item.getIsDataAuthorize(), 1) || Objects.equals(item.getIsFormAuthorize(), 1)) { item.setHasPermission(1); } //添加视图标识 if (StringUtil.isNotEmpty(item.getPropertyJson())) { PropertyJsonModel model = JsonUtil.getJsonToBean(item.getPropertyJson(), PropertyJsonModel.class); item.setWebType(model.getWebType()); if (Objects.equals(model.getWebType(), 4)) { item.setHasPermission(0); } } } else { item.setHasPermission(1); } } list = list.stream().sorted(Comparator.comparing(UserMenuModel::getSortCode, Comparator.nullsLast(Comparator.naturalOrder())).thenComparing(UserMenuModel::getCreatorTime, Comparator.nullsLast(Comparator.reverseOrder()))).collect(Collectors.toList()); List> menuList = TreeDotUtils.convertListToTreeDot(list); List menuvo = JsonUtil.getJsonToList(menuList, MenuListVO.class); ListVO vo = new ListVO(); vo.setList(menuvo); return ActionResult.success(vo); } @Operation(summary = "新建系统功能") @Parameters({ @Parameter(name = "moduleCrForm", description = "实体对象", required = true) }) @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR) @PostMapping public ActionResult create(@RequestBody @Valid ModuleCrForm moduleCrForm) { SystemEntity info = systemService.getInfoByEnCode(RequestContext.getAppCode()); moduleCrForm.setSystemId(info.getId()); ModuleEntity entity = JsonUtil.getJsonToBean(moduleCrForm, ModuleEntity.class); if (entity.getUrlAddress() != null) { entity.setUrlAddress(entity.getUrlAddress().trim()); } if (moduleService.isExistByFullName(entity, moduleCrForm.getCategory(), moduleCrForm.getSystemId())) { return ActionResult.fail(MsgCode.EXIST001.get()); } if (moduleService.isExistByEnCode(entity, moduleCrForm.getCategory(), moduleCrForm.getSystemId())) { return ActionResult.fail(MsgCode.EXIST002.get()); } if (moduleService.isExistByAddress(entity, moduleCrForm.getCategory(), moduleCrForm.getSystemId())) { return ActionResult.fail(MsgCode.EXIST104.get()); } moduleService.create(entity); return ActionResult.success(MsgCode.SU001.get()); } @Operation(summary = "更新系统功能") @Parameters({ @Parameter(name = "id", description = "主键值", required = true), @Parameter(name = "moduleUpForm", description = "实体对象", required = true) }) @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR) @PutMapping("/{id}") public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid ModuleUpForm moduleUpForm) { SystemEntity info = systemService.getInfoByEnCode(RequestContext.getAppCode()); moduleUpForm.setSystemId(info.getId()); ModuleEntity entity = JsonUtil.getJsonToBean(moduleUpForm, ModuleEntity.class); //判断如果是目录则不能修改类型 ModuleEntity moduleEntity = moduleService.getInfo(id); if (moduleEntity != null && moduleEntity.getType() == 1 && entity.getType() != 1 && moduleService.getListByParentId(moduleEntity.getId()).size() > 0) { return ActionResult.fail(MsgCode.SYS016.get()); } entity.setId(id); if (entity.getUrlAddress() != null) { entity.setUrlAddress(entity.getUrlAddress().trim()); } if (moduleService.isExistByFullName(entity, moduleUpForm.getCategory(), moduleUpForm.getSystemId())) { return ActionResult.fail(MsgCode.EXIST001.get()); } if (moduleService.isExistByEnCode(entity, moduleUpForm.getCategory(), moduleUpForm.getSystemId())) { return ActionResult.fail(MsgCode.EXIST002.get()); } if (moduleService.isExistByAddress(entity, moduleUpForm.getCategory(), moduleUpForm.getSystemId())) { return ActionResult.fail(MsgCode.EXIST104.get()); } boolean flag = moduleService.update(id, entity); if (!flag) { return ActionResult.fail(MsgCode.FA002.get()); } return ActionResult.success(MsgCode.SU004.get()); } @Operation(summary = "删除系统功能") @Parameters({ @Parameter(name = "id", description = "主键值", required = true) }) @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR) @DeleteMapping("/{id}") public ActionResult delete(@PathVariable("id") String id) { ModuleEntity entity = moduleService.getInfo(id); if (entity != null) { List list = moduleService.getList(false, new ArrayList<>(), new ArrayList<>()).stream().filter(t -> t.getParentId().equals(entity.getId())).collect(Collectors.toList()); if (list.size() > 0) { return ActionResult.fail(MsgCode.SYS017.get()); } moduleService.delete(entity); return ActionResult.success(MsgCode.SU003.get()); } return ActionResult.fail(MsgCode.FA003.get()); } @Operation(summary = "获取菜单信息") @Parameters({ @Parameter(name = "id", description = "主键值", required = true) }) @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR) @GetMapping("/{id}") public ActionResult info(@PathVariable("id") String id) throws DataException { ModuleEntity entity = moduleService.getInfo(id); ModuleInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, ModuleInfoVO.class); return ActionResult.success(vo); } //+++++++++++++++++++++++++++增删改查end+++++++++++++++++++++++++++++++++++++++++++++++ /** * 获取菜单列表(下拉框) * * @param category 分类 * @param id 主键 * @return ignore */ @Operation(summary = "获取菜单列表(下拉框)") @Parameters({ @Parameter(name = "category", description = "分类"), @Parameter(name = "id", description = "主键", required = true) }) @GetMapping("/Selector/{id}") public ActionResult> treeView(String category, @PathVariable("id") String id) { //应用编码 String appCode = RequestContext.getAppCode(); List data = moduleService.getList(appCode, category, null, 1, null, null, false); if (!"0".equals(id)) { data.remove(moduleService.getInfo(id)); } List list = JsonUtil.getJsonToList(data, UserMenuModel.class); List> menuList = TreeDotUtils.convertListToTreeDotFilter(list); List menuvo = JsonUtil.getJsonToList(menuList, MenuSelectVO.class); ListVO vo = new ListVO(); vo.setList(menuvo); return ActionResult.success(vo); } /** * 获取开发平台菜单 * * @return ignore */ @Operation(summary = "获取开发平台菜单") @GetMapping("/SystemSelector") public ActionResult> mainSystemSelector() { SystemEntity mainSystem = systemService.getInfoByEnCode(JnpfConst.MAIN_SYSTEM_CODE); List data = moduleService.getList(mainSystem.getId(), null, null, null, 1, null, false); List list = JsonUtil.getJsonToList(data, UserMenuModel.class); list.forEach(t -> { if ("-1".equals(t.getParentId())) { t.setParentId(t.getSystemId()); } }); UserMenuModel userMenuModel = JsonUtil.getJsonToBean(mainSystem, UserMenuModel.class); userMenuModel.setType(0); userMenuModel.setParentId("-1"); list.add(userMenuModel); List> menuList = TreeDotUtils.convertListToTreeDotFilter(list); List menuvo = JsonUtil.getJsonToList(menuList, MenuSelectVO.class); ListVO vo = new ListVO(); vo.setList(menuvo); return ActionResult.success(vo); } /** * 通过系统id获取菜单列表(下拉框) * * @param category 分类 * @param id 主键 * @return ignore */ @Operation(summary = "通过系统id获取菜单列表(下拉框)") @Parameters({ @Parameter(name = "id", description = "主键", required = true), @Parameter(name = "systemId", description = "系统主键", required = true), @Parameter(name = "enabledMark", description = "查询类型:null-全部,0-禁用,1-启用", required = false) }) @GetMapping("/Selector/{id}/{systemId}") public ActionResult> treeView(@PathVariable("id") String id, @PathVariable("systemId") String systemId, @RequestParam("category") String category, @RequestParam(value = "enabledMark", required = false) Integer enabledMark) { List data = moduleService.getList(systemId, category, null, 1, enabledMark, null, true); if (!"0".equals(id)) { data.remove(moduleService.getInfo(id)); } List list = JsonUtil.getJsonToList(data, UserMenuModel.class); if ("0".equals(systemId)) { List moduleAuthorize = new ArrayList<>(); if (configValueUtil.isMultiTenancy()) { TenantAuthorizeModel tenantAuthorizeModel = TenantDataSourceUtil.getCacheModuleAuthorize(UserProvider.getUser().getTenantId()); moduleAuthorize = tenantAuthorizeModel.getModuleIdList(); } List list1 = systemService.getList(null, true, false, true, false, moduleAuthorize); list.forEach(t -> { if ("-1".equals(t.getParentId())) { t.setParentId(t.getSystemId()); } }); List jsonToList = JsonUtil.getJsonToList(list1, UserMenuModel.class); jsonToList.forEach(t -> { t.setType(0); t.setParentId("-1"); }); list.addAll(jsonToList); } List> menuList = TreeDotUtils.convertListToTreeDotFilter(list); List menuvo = JsonUtil.getJsonToList(menuList, MenuSelectAllVO.class); ListVO vo = new ListVO(); vo.setList(menuvo); return ActionResult.success(vo); } /** * 通过系统id获取菜单列表(下拉框) * * @param category 分类 * @return ignore */ @Operation(summary = "通过系统id获取菜单列表(下拉框)") @Parameters({ @Parameter(name = "id", description = "主键", required = true), @Parameter(name = "systemId", description = "系统主键", required = true) }) @GetMapping("/SelectorFilter/{visualId}") public ActionResult> SelectorFilter(String category, @PathVariable("visualId") String visualId) { String appCode = RequestContext.getAppCode(); SystemEntity systemEntity = systemService.getInfoByEnCode(appCode); List data = moduleService.getList(appCode, category, null, 1, 1, null, true); List moduleList = moduleService.getModuleList(visualId); List moduleIds = new ArrayList<>(); List systemIds = new ArrayList<>(); if (CollectionUtils.isNotEmpty(moduleList)) { for (ModuleEntity item : moduleList) { if ("-1".equals(item.getParentId())) { systemIds.add(item.getSystemId()); } else { moduleIds.add(item.getParentId()); } } } List list = JsonUtil.getJsonToList(data, UserMenuModel.class); List list1 = new ArrayList<>(); list1.add(systemEntity); list.forEach(t -> { if ("-1".equals(t.getParentId())) { t.setParentId(t.getSystemId()); } }); List jsonToList = JsonUtil.getJsonToList(list1, UserMenuModel.class); jsonToList.forEach(t -> { t.setType(0); t.setParentId("-1"); }); list.addAll(jsonToList); for (UserMenuModel userMenuModel : list) { if (moduleIds.contains(userMenuModel.getId()) || systemIds.contains(userMenuModel.getId())) { userMenuModel.setDisabled(true); } } List> menuList = TreeDotUtils.convertListToTreeDotFilter(list); List menuvo = JsonUtil.getJsonToList(menuList, MenuSelectAllVO.class); ListVO vo = new ListVO(); vo.setList(menuvo); return ActionResult.success(vo); } /** * 获取菜单列表(下拉框) * * @param category 分类 * @return ignore */ @Operation(summary = "获取菜单列表下拉框") @GetMapping("/Selector/All") public ActionResult> menuSelect(String category) { List data = moduleService.getList(RequestContext.getAppCode(), category, null, null, 1, null, false); List list = JsonUtil.getJsonToList(data, UserMenuModel.class); List moduleAuthorize = new ArrayList<>(); if (configValueUtil.isMultiTenancy()) { TenantAuthorizeModel tenantAuthorizeModel = TenantDataSourceUtil.getCacheModuleAuthorize(UserProvider.getUser().getTenantId()); moduleAuthorize = tenantAuthorizeModel.getModuleIdList(); } List list1 = systemService.getList(null, true, false, false, false, moduleAuthorize); list.forEach(t -> { t.setHasModule(!"1".equals(String.valueOf(t.getType()))); if ("-1".equals(t.getParentId())) { t.setParentId(t.getSystemId()); } }); List jsonToList = JsonUtil.getJsonToList(list1, UserMenuModel.class); jsonToList.forEach(t -> { t.setType(0); t.setHasModule(false); t.setParentId("-1"); }); list.addAll(jsonToList); List> menuList = TreeDotUtils.convertListToTreeDotFilter(list); List menuvo = JsonUtil.getJsonToList(menuList, MenuSelectAllVO.class); ListVO vo = new ListVO(); vo.setList(menuvo); return ActionResult.success(vo); } /** * 系统功能类别树形 * * @return ignore */ @Operation(summary = "系统功能类别树形") @GetMapping("/{systemId}/TreeView") public ActionResult treeView(@PathVariable("systemId") String systemId) { List moduleList = moduleService.getList(systemId, null, null, null, null, "0", true); List treeList = new ArrayList<>(); TreeViewModel treeViewModel = new TreeViewModel(); treeViewModel.setId("apply"); treeViewModel.setText("软件开发平台"); treeViewModel.setParentId("0"); treeViewModel.setImg("fa fa-windows apply"); treeList.add(treeViewModel); for (ModuleEntity entity : moduleList) { TreeViewModel treeModel = new TreeViewModel(); treeModel.setId(entity.getId()); treeModel.setText(entity.getFullName()); treeModel.setParentId("apply"); treeModel.setImg("fa fa-tags"); treeList.add(treeModel); } return ActionResult.success(ListToTreeUtil.toTreeView(treeList)); } /** * 更新菜单状态 * * @param id 主键值 * @return ignore */ @Operation(summary = "更新菜单状态") @Parameters({ @Parameter(name = "id", description = "主键值", required = true) }) @SaCheckPermission("permission.menu") @PutMapping("/{id}/Actions/State") public ActionResult upState(@PathVariable("id") String id) { ModuleEntity entity = moduleService.getInfo(id); if (entity != null) { if (entity.getEnabledMark() == null || "1".equals(String.valueOf(entity.getEnabledMark()))) { entity.setEnabledMark(0); } else { entity.setEnabledMark(1); } moduleService.update(id, entity); //清除redis权限 String cacheKey = cacheKeyUtil.getUserAuthorize() + UserProvider.getUser().getUserId(); if (redisUtil.exists(cacheKey)) { redisUtil.remove(cacheKey); } return ActionResult.success(MsgCode.SU004.get()); } return ActionResult.fail(MsgCode.FA002.get()); } /** * 系统菜单导出功能 * * @param id 接口id * @return ignore */ @Operation(summary = "导出系统菜单数据") @Parameters({ @Parameter(name = "id", description = "主键值", required = true) }) @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR) @GetMapping("/{id}/Actions/Export") public ActionResult exportFile(@PathVariable("id") String id) { DownloadVO downloadVO = moduleService.exportData(id); return ActionResult.success(downloadVO); } /** * 系统菜单导入功能 * @param multipartFile 文件 * @param parentId 父级id * @param category 分类 * @return ignore */ @Operation(summary = "系统菜单导入功能") @Parameters({ @Parameter(name = "systemId", description = "系统id", required = true), }) @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR) @PostMapping(value = "/Actions/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ActionResult importFile(@RequestPart("file") MultipartFile multipartFile, @RequestParam("parentId") String parentId, @RequestParam("category") String category, @RequestParam("type") Integer type) throws DataException { SystemEntity systemEntity = systemService.getInfoByEnCode(RequestContext.getAppCode()); //判断是否为.bm结尾 if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.SYSTEM_MODULE.getTableName())) { return ActionResult.fail(MsgCode.IMP002.get()); } try { //读取文件内容 String fileContent = FileUtil.getFileContent(multipartFile); //转model后导入 ModuleExportModel exportModel = JsonUtil.getJsonToBean(fileContent, ModuleExportModel.class); ModuleEntity moduleEntity = exportModel.getModuleEntity(); if (!category.equals(moduleEntity.getCategory())) { return ActionResult.fail(MsgCode.SYS018.get(category.toUpperCase())); } if (JnpfConst.APP.equals(moduleEntity.getCategory()) && "-1".equals(parentId)) { return ActionResult.fail(MsgCode.SYS019.get()); } // 设置系统id然后重新赋值 if (!systemEntity.getId().equals(moduleEntity.getSystemId())) { moduleEntity.setId(RandomUtil.uuId()); moduleEntity.setEnCode(null); moduleService.setAutoEnCode(moduleEntity); moduleEntity.setSystemId(systemEntity.getId()); } moduleEntity.setParentId(parentId); //清空同步菜单记录 避免重复 moduleEntity.setModuleId(null); moduleEntity.setCreatorTime(new Date()); // String enCode = moduleEntity.getEnCode(); // moduleEntity.setEnCode(moduleEntity.getEnCode() + "_" + RandomUtil.getRandomCode()); // if (moduleEntity.getType() == 3) { // moduleEntity.setUrlAddress(moduleEntity.getUrlAddress().replace(enCode, moduleEntity.getEnCode())); // } exportModel.setModuleEntity(moduleEntity); return moduleService.importData(exportModel, type); } catch (Exception e) { throw new DataException(MsgCode.IMP004.get()); } } // ------------------多租户调用 /** * 通过租户id获取菜单 * * @param tenantMenuModel 模型 * @return ignore */ @Operation(summary = "通过租户id获取菜单") @Parameters({ @Parameter(name = "tenantMenuModel", description = "模型", required = true) }) @NoDataSourceBind @PostMapping("/Tenant/Menu") public TenantMenuVO menu(@RequestBody TenantMenuModel tenantMenuModel) throws DataException { if (configValueUtil.isMultiTenancy()) { TenantDataSourceUtil.switchTenant(tenantMenuModel.getTenantId()); } List systemEntityList = systemService.getList(); List ids = new ArrayList<>(); if (Objects.nonNull(tenantMenuModel.getIds())) { ids = tenantMenuModel.getIds(); } List urlAddressList = new ArrayList<>(); if (Objects.nonNull(tenantMenuModel.getIds())) { urlAddressList = tenantMenuModel.getUrlAddressList(); } List moduleEntityList = moduleService.getList(true, new ArrayList<>(), new ArrayList<>()); TenantMenuVO module = module(systemEntityList, moduleEntityList, ids, urlAddressList); return module; } /** * 功能权限 * * @param moduleEntityList 所有菜单 * @param systemEntityList 所有应用 * @return */ private TenantMenuVO module(List systemEntityList, List moduleEntityList, List ids, List urlAddressList) { TenantMenuVO vo = new TenantMenuVO(); // 转树前所有数据 List moduleAllList = new ArrayList<>(); List systemList = JsonUtil.getJsonToList(systemEntityList, TenantMenuTreeModel.class); systemList.forEach(t -> t.setParentId("-1")); moduleAllList.addAll(systemList); Map> moduleMap = moduleEntityList.stream().collect(Collectors.groupingBy(t -> { if (JnpfConst.WEB.equals(t.getCategory())) { return JnpfConst.WEB; } else { return JnpfConst.APP; } })); List webModuleList = moduleMap.get(JnpfConst.WEB) == null ? new ArrayList<>() : moduleMap.get(JnpfConst.WEB); List appModuleList = moduleMap.get(JnpfConst.APP) == null ? new ArrayList<>() : moduleMap.get(JnpfConst.APP); Map appModuleMap = appModuleList.stream().collect(Collectors.toMap(ModuleEntity::getId, Function.identity())); Map webIds = new HashMap<>(16); List temWebList = webModuleList.stream().filter(t -> "-1".equals(t.getParentId())).collect(Collectors.toList()); temWebList.stream().filter(t -> "-1".equals(t.getParentId())).forEach(t -> { if (!webIds.containsKey(t.getSystemId())) { ModuleEntity webData = new ModuleEntity(); webData.setId(t.getSystemId() + "1"); t.setParentId(webData.getId()); webData.setFullName("WEB菜单"); webData.setIcon(PermissionConst.PC_ICON); webData.setParentId(t.getSystemId()); webData.setSystemId(t.getSystemId()); webModuleList.add(webData); webIds.put(t.getSystemId(), webData.getId()); } else { t.setParentId(webIds.get(t.getSystemId()) + ""); } }); List webReturnModuleList = JsonUtil.getJsonToList(webModuleList, TenantMenuTreeModel.class); moduleAllList.addAll(webReturnModuleList); // 处理App菜单 List temList = appModuleList.stream().filter(t -> "-1".equals(t.getParentId()) && !JnpfConst.MAIN_SYSTEM_CODE.equals(t.getEnCode())).collect(Collectors.toList()); Map appIds = new HashMap<>(16); for (ModuleEntity appModuleEntity : temList) { if (StringUtil.isEmpty(appIds.get(appModuleEntity.getSystemId()))) { ModuleEntity appData = new ModuleEntity(); appData.setId(appModuleEntity.getSystemId() + appModuleEntity.getSystemId() + "2"); appModuleEntity.setParentId(appData.getId()); appData.setFullName("APP菜单"); appData.setIcon(PermissionConst.APP_ICON); appData.setParentId(appModuleEntity.getSystemId()); appData.setSystemId(appModuleEntity.getSystemId()); appModuleList.add(appData); appIds.put(appModuleEntity.getSystemId(), appData.getId()); } else { appModuleList.remove(appModuleEntity); ModuleEntity entity = appModuleMap.get(appModuleEntity.getId()); entity.setParentId(appIds.get(appModuleEntity.getSystemId())); appModuleList.add(entity); } } List appReturnModuleList = JsonUtil.getJsonToList(appModuleList, TenantMenuTreeModel.class); moduleAllList.addAll(appReturnModuleList); List> sumTrees = TreeDotUtils.convertListToTreeDot(moduleAllList); List data = new ArrayList<>(); TenantMenuTreeReturnModel workFlowEnabled = new TenantMenuTreeReturnModel(); workFlowEnabled.setId("-999"); workFlowEnabled.setFullName("协同办公"); data.add(workFlowEnabled); data.addAll(JsonUtil.getJsonToList(sumTrees, TenantMenuTreeReturnModel.class)); vo.setList(data); List allId = moduleAllList.stream().map(TenantMenuTreeModel::getId).collect(Collectors.toList()); allId.add(workFlowEnabled.getId()); vo.setAll(allId); List ids0 = moduleService.getListByUrlAddress(ids, urlAddressList).stream().map(ModuleEntity::getId).collect(Collectors.toList()); List selectorIds = allId.stream().filter(t -> !ids0.contains(t)).collect(Collectors.toList()); if (ids.contains("-999")) { selectorIds.remove("-999"); } vo.setIds(selectorIds); return vo; } /** * 通过租户id及菜单id获取菜单 * * @param tenantMenuModel 模型 * @return ignore */ @Operation(summary = "通过租户id及菜单id获取菜单") @Parameters({ @Parameter(name = "tenantMenuModel", description = "模型", required = true) }) @NoDataSourceBind @PostMapping("/Tenant/MenuByIds") public Map MenuByIds(@RequestBody TenantMenuModel tenantMenuModel) throws DataException { if (configValueUtil.isMultiTenancy()) { TenantDataSourceUtil.switchTenant(tenantMenuModel.getTenantId()); } List list = moduleService.getListTenant(); return list.stream().collect(Collectors.toMap(ModuleEntity::getId, ModuleEntity::getUrlAddress)); } /** * 获取在线开发“表单”和“流程”类型的菜单数据 */ @Operation(summary = "菜单获取表单列表") @GetMapping("/Selector/Form") @Parameters({ @Parameter(name = "systemId", description = "系统id", required = false), }) public ActionResult getFormList(ModulePagination pagination) { List list = moduleService.getFormMenuList(pagination); list.stream().forEach(t -> { t.setTypeName(Objects.equals(t.getType(), 3) ? "表单" : "流程"); PropertyJsonModel model = JsonUtil.getJsonToBean(t.getPropertyJson(), PropertyJsonModel.class); if (Objects.equals(t.getType(), 3)) { t.setFormId(model.getModuleId()); } else { t.setFlowId(model.getModuleId()); t.setFormId(templateApi.getFormByFlowId(model.getModuleId())); } }); PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class); return ActionResult.page(list, paginationVO); } @Operation(summary = "根据type获取菜单列表") @GetMapping("/Selector/Page") public ActionResult getPageList(ModulePagination pagination) { SystemEntity info = systemService.getInfoByEnCode(RequestContext.getAppCode()); pagination.setSystemId(info.getId()); List list = moduleService.getPageList(pagination); // PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class); return ActionResult.page(list, null); } /** * 报表发布菜单 * * @return ignore */ @Operation(summary = "报表发布菜单") @Parameters({ @Parameter(name = "menuModel", description = "模型", required = true) }) @PostMapping("/saveReportMenu") public ActionResult saveReportMenu(@RequestBody VisualMenuModel menuModel) { try { pubulishUtil.publishMenu(menuModel); return ActionResult.success(); } catch (WorkFlowException e) { return ActionResult.fail(e.getMessage()); } } /** * 报表发布菜单 * * @return ignore */ @Operation(summary = "获取报表发布菜单") @Parameters({ @Parameter(name = "id", description = "主键值", required = true) }) @PostMapping("/getReportMenu") public ActionResult getReportMenu(@RequestBody VisualMenuModel menuModel) { ModuleNameVO moduleNameVO = moduleService.getModuleNameList(menuModel.getId()); return ActionResult.success(moduleNameVO); } /** * 获取系统菜单列表(下拉树形) */ @Operation(summary = "获取系统菜单列表(下拉树形)") @GetMapping("/getSystemMenu") public ActionResult> getSystemMenu() { List systemMenu = moduleService.getSystemMenu(3, Arrays.asList(2, 4), Arrays.asList("web")); return ActionResult.success(systemMenu); } @Operation(summary = "资源管理菜单") @Parameters({ @Parameter(name = "systemId", description = "系统id", required = true) }) @GetMapping("/ResourceManage") public ActionResult> resourceManage(PaginationMenu paginationMenu) { String appCode = RequestContext.getAppCode(); List data = moduleService.getList(appCode, null, paginationMenu.getKeyword(), null, 1, null, false); // 递归查上级 Map moduleEntityMap = data.stream().collect(Collectors.toMap(ModuleEntity::getId, Function.identity())); if (StringUtil.isNotEmpty(paginationMenu.getKeyword())) { moduleService.getParentModule(data, moduleEntityMap); } List list = JsonUtil.getJsonToList(moduleEntityMap.values(), UserMenuModel.class); list = list.stream().sorted(Comparator.comparing(UserMenuModel::getSortCode, Comparator.nullsLast(Comparator.naturalOrder())).thenComparing(UserMenuModel::getCreatorTime, Comparator.nullsLast(Comparator.reverseOrder()))).collect(Collectors.toList()); List> menuList = TreeDotUtils.convertListToTreeDot(list); List menuvo = JsonUtil.getJsonToList(menuList, MenuListVO.class); ListVO vo = new ListVO(); vo.setList(menuvo); return ActionResult.success(vo); } }