using APT.BaseData.Domain.Enums; using APT.Infrastructure.Core; using APT.MS.Domain.Entities.OG; using APT.Utility; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; namespace APT.SC.WebApi.Controllers.Api.OG { [Route("api/OG/OGAgency")] public class OGAgencyController : AuthorizeTreeApiController { /// /// 查询包含上级部门级本部门 /// /// /// [HttpPost, Route("OrderPagedOther")] public PagedActionResult OrderPagedOther([FromBody] KeywordPageFilter pageFilter) { List list = GetEntities(t => t.ORG_ID == pageFilter.OrgId, new BaseFilter()).ToList(); var departmentA = new T_OG_AGENCY { ID = new Guid("00000000-0000-0000-0000-000000000000"), ORG_ID = pageFilter.OrgId, NAME = "通知部门" }; var departmentB = new T_OG_AGENCY { ID = new Guid("99999999-9999-9999-9999-999999999999"), ORG_ID = pageFilter.OrgId, NAME = "上级部门" }; list.Add(departmentA); list.Add(departmentB); return WitOrderPaged(null, pageFilter); } /// /// 查询公司级/部门级部门及车间级部门,除班组级部门 /// /// /// [HttpPost, Route("OrderPagedWithOutClassDep")] public JsonActionResult> OrderPagedWithOutClassDep([FromBody] KeywordPageFilter pageFilter) { var list = GetEntities(t => t.LEVEL == FMDepartmentType.公司 || t.LEVEL == FMDepartmentType.部门 || t.LEVEL == FMDepartmentType.车间, new BaseFilter()).ToList(); JsonActionResult> result = new JsonActionResult>(); result.Data = list.OrderBy(t => t.LEVEL).ToList(); result.IsSuccessful = true; result.TotalCount = list.Count(); return result; } /// /// 更新 /// /// /// [HttpPost, Route("Update")] public JsonActionResult Update([FromBody] T_OG_AGENCY entity) { return SafeExecute(() => { if (entity.PARENT_ID != null) { var parent = GetEntity(entity.PARENT_ID.ToString()); if (parent != null) { parent.IS_LEAF = false; UpdateEntity(parent); } } var users = entity.Nav_Users; entity.Nav_Users = null; if (users != null) { users.ForEach(t => { t.AGENCY_ID = entity.ID; t.ORG_ID = entity.ORG_ID; t.Nav_User = null; }); } UnifiedCommit(() => { UpdateEntityNoCommit(entity); if (users != null) BantchSaveEntityNoCommit(users); }); return true; }); } /// /// 更新(含人员) /// /// /// [HttpPost, Route("FullUpdate")] public JsonActionResult FullUpdate([FromBody] T_OG_AGENCY entity) { T_OG_AGENCY parent = new T_OG_AGENCY(); if (entity.PARENT_ID != null) { parent = GetEntity(entity.PARENT_ID.ToString()); } var users = entity.Nav_Users; entity.Nav_Users = null; if (users != null) { users.ForEach(t => { t.AGENCY_ID = entity.ID; t.ORG_ID = entity.ORG_ID; t.Nav_User = null; }); } WitCommitTransaction(() => { UpdateEntity(entity); if (parent != null) { parent.IS_LEAF = false; UpdateEntity(parent); } if (users != null) BantchSaveEntity(users); }); return SafeExecute(() => { return true; }); } /// /// 获得单条实体数据 /// /// 过滤实体 /// [HttpPost, Route("GetOrder")] public JsonActionResult GetOrder([FromBody] KeywordFilter filter) { return SafeExecute(() => { var result = GetEntity(null, filter, null); if (result.Nav_Users != null && result.Nav_Users.Any()) { result.Nav_Users = result.Nav_Users.OrderBy(e => e.NUM).ToList(); } return result; }); } } }