using APT.BaseData.Domain.Entities; using APT.BaseData.Domain.IServices; using APT.Infrastructure.Core; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using APT.Utility; using APT.Utility;namespace APT.PF.WebApiControllers.Api.PF { [Route("api/PF/AppMenu")] public class AppMenuController : AuthorizeTreeApiController { IPFAppMenuService MenuService { get; set; } public AppMenuController(IPFAppMenuService 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) { 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_APPMENU entity) { return SafeExecute(() => { T_PF_APPMENU parentMenu = null; if (entity.PARENT_ID != null) { parentMenu = this.GetEntity(entity.PARENT_ID.ToString()); 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; }); } /// /// 获取子菜单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.Any()) { 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); } } }