using APT.BaseData.Domain.Entities; using APT.BaseData.Domain.IServices; using APT.Infrastructure.Core; using APT.Utility; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using APT.Utility; using APT.BaseData.Domain.Entities.BD; using APT.BaseData.Domain.Entities.FM; using APT.BaseData.Services.Services.FM; using APT.BaseData.Domain.Enums; namespace APT.PF.WebApiControllers.Api.PF { [Route("api/PF/Menu")] public class MenuController : AuthorizeTreeApiController { IPFMenuService MenuService { get; set; } public MenuController(IPFMenuService menuService) { MenuService = menuService; } /// /// 查询 /// /// /// [HttpPost, Route("Entities")] public JsonActionResult> Entities([FromBody] KeywordFilter filter) { return WitEntities(null, filter); } /// /// 查询 /// /// /// [HttpPost, Route("OrderEntities")] public JsonActionResult> OrderEntities([FromBody] KeywordFilter filter) { filter.FilterGroup.Rules.Add(new FilterRule() { Field = "PLATFORM_CATEGORY", Operate = FilterOperate.Equal, Value = 0 }); return WitOrderEntities(null, filter); } /// /// 查询 /// /// /// [HttpPost, Route("NWOrderEntities")] public JsonActionResult> NWOrderEntities([FromBody] KeywordFilter filter) { filter.FilterGroup.Rules.Add(new FilterRule() { Field = "PLATFORM_CATEGORY", Operate = FilterOperate.Equal, Value = 1 }); return WitOrderEntities(null, filter); } /// /// 查询 /// /// /// [HttpPost, Route("Paged")] public PagedActionResult Paged([FromBody] KeywordPageFilter pageFilter) { return WitPaged(null, pageFilter); } /// /// 查询 /// /// /// [HttpPost, Route("OrderPaged")] public PagedActionResult OrderPaged([FromBody] KeywordPageFilter pageFilter) { return WitOrderPaged(null, pageFilter); } [HttpPost, Route("Update")] public JsonActionResult Update([FromBody] T_PF_MENU entity) { return SafeExecute(() => { //查所有下级菜单 //List parendIds = new List(); //parendIds.Add(entity.ID); //List childIds = new List() { entity.ID }; //var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value; //GetChildIds(parendIds, childIds); //var menuList = this.GetEntities(t => childIds.Contains(t.ID), new BaseFilter(orgId)).ToList(); //menuList.ForEach(t => t.MineType = entity.MineType); //T_PF_MENU parentMenu = null; //if (entity.PARENT_ID != null) //{ // parentMenu = this.GetEntity(entity.PARENT_ID.ToString(),true); // parentMenu.HAS_CHILDREN = true; // entity.MENU_LEVEL = parentMenu.MENU_LEVEL + 1; // parentMenu.IS_LEAF = false; //} //else // entity.MENU_LEVEL = 1; //UnifiedCommit(() => //{ // this.TreeUpdateEntityNoCommit(entity); // if (parentMenu != null) // this.TreeUpdateEntityNoCommit(parentMenu); //}); //return true; entity.IS_PERMISSION_MENU = true; //this.UnifiedCommit(() => //{ // if (entity != null) // this.UpdateEntityNoCommit(entity); // if (menuList != null && menuList.Any()) // this.BantchSaveEntityNoCommit(menuList); //}); return this.UpdateEntity(entity); ; }); } [HttpPost, Route("NWUpdate")] public JsonActionResult NWUpdate([FromBody] T_PF_MENU entity) { return SafeExecute(() => { entity.PLATFORM_CATEGORY = 1; entity.IS_PERMISSION_MENU = true; return this.UpdateEntity(entity); }); } /// /// 获取子菜单ID /// /// /// private void GetChildIds(List parendIds, List childIds) { var tmp = this.GetEntities(t => parendIds.Contains(t.PARENT_ID ?? Guid.Empty), new BaseFilter()).Select(t => t.ID).ToList(); if (tmp != null && tmp.Count > 0) { childIds.AddRange(tmp); GetChildIds(tmp, childIds); } } /// /// 删除 /// /// /// [HttpGet, Route("Delete")] public JsonActionResult Delete(string id) { return SafeExecute(() => { if (string.IsNullOrEmpty(id)) return false; List deleteIds = new List(); deleteIds.Add(new Guid(id)); List parendIds = new List(); parendIds.Add(new Guid(id)); GetChildIds(parendIds, deleteIds); this.TreeDeleteEntity(t => deleteIds.Contains(t.ID)); return true; }); } /// /// 批量删除 /// /// /// [HttpGet, Route("BatchDelete")] public JsonActionResult BatchDelete(string ids) { return SafeExecute(() => { if (string.IsNullOrEmpty(ids)) return false; string[] tmp = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (tmp == null || tmp.Length == 0) return false; List deleteIds = new List(); List parendIds = new List(); tmp.ForEach(t => { deleteIds.Add(new Guid(t)); parendIds.Add(new Guid(t)); }); GetChildIds(parendIds, deleteIds); this.TreeDeleteEntity(t => deleteIds.Contains(t.ID)); return true; }); } /// /// 根据ID获得实体数据 /// /// /// [HttpPost, Route("Get")] public JsonActionResult Get([FromBody] KeywordFilter filter) { return WitEntity(null, filter); } /// /// 获取菜单图片图标 /// /// /// [HttpPost, Route("OrderPagedIcon")] public PagedActionResult OrderPagedIcon([FromBody] KeywordPageFilter filter) { return SafeGetPagedData((result) => { var enumCode = "MENUICON"; var enumId = GetEntity(x => x.CODE == enumCode); var data = GetOrderPageEntities(x => x.ENUM_ID == enumId.ID, filter, "Nav_PictureFiles"); result.Data = data.Data; result.TotalCount = data.TotalCount; }); } /// /// 获取菜单图片图标 /// /// /// [HttpPost, Route("AppMenuPic")] public PagedActionResult AppMenuPic([FromBody] KeywordPageFilter filter) { return SafeGetPagedData((result) => { var enumCode = "APPPIC"; var enumId = GetEntity(x => x.CODE == enumCode); var data = GetOrderPageEntities(x => x.ENUM_ID == enumId.ID, filter, "Nav_PictureFiles"); result.Data = data.Data; result.TotalCount = data.TotalCount; }); } } }