using System; using SqlSugar; using Infrastructure.Attribute; using Infrastructure.Extensions; using DOAN.Model; using DOAN.Model.Dto; using DOAN.Model.MES.group; using DOAN.Model.MES.group.Dto; using DOAN.Repository; using DOAN.Service.group.IService; using System.Linq; using DOAN.Common; namespace DOAN.Service.group { /// /// 岗位Service业务层处理 /// [AppService(ServiceType = typeof(IGroupPostService), ServiceLifetime = LifeTime.Transient)] public class GroupPostService : BaseService, IGroupPostService { /// /// 查询岗位列表 /// /// /// public PagedInfo GetList(GroupPostQueryDto parm) { var predicate = Expressionable.Create() .AndIF(!string.IsNullOrEmpty(parm.PostName), it => it.PostName.Contains(parm.PostName)); ; var response = Queryable() .Where(predicate.ToExpression()) .ToPage(parm); return response; } /// /// 获取详情 /// /// /// public GroupPost GetInfo(string Id) { var response = Queryable() .Where(x => x.Id == Id) .First(); return response; } /// /// 添加岗位 /// /// /// public GroupPost AddGroupPost(GroupPost model) { model.Id = XueHua; if (string.IsNullOrEmpty(model.ParentId)) { model.ParentId = "0"; } return Context.Insertable(model).ExecuteReturnEntity(); } /// /// 修改岗位 /// /// /// public int UpdateGroupPost(GroupPost model) { //var response = Update(w => w.Id == model.Id, it => new GroupPost() //{ // PostName = model.PostName, // Status = model.Status, // Remark = model.Remark, // CreatedBy = model.CreatedBy, // CreatedTime = model.CreatedTime, // UpdatedBy = model.UpdatedBy, // UpdatedTime = model.UpdatedTime, //}); //return response; return Update(model, true); } /// /// 删除岗位包括子 /// /// /// public int RemoveGroupPost(string[] ids) { List all_nodes = Context.Queryable().ToList(); List Descendants = GetDescendants(all_nodes, ids[0]); List children = Descendants.Select(it => it.Id).ToList(); children.Add(ids[0]); return Delete(children.ToArray()); } public List GetDescendants(List nodes, string rootId) { var descendants = new List(); void FindChildren(GroupPost node) { var children = nodes.Where(n => n.ParentId == node.Id).ToList(); foreach (var child in children) { descendants.Add(child); FindChildren(child); } } var rootNode = nodes.FirstOrDefault(n => n.Id == rootId); if (rootNode != null) { FindChildren(rootNode); } return descendants; } } }