using DS.Module.Core; using DS.Module.Core.Extensions; using DS.Module.UserModule; using DS.WMS.Core.System.Dtos; using DS.WMS.Core.System.Entity; using DS.WMS.Core.System.Interface; using Mapster; using Microsoft.Extensions.DependencyInjection; using SqlSugar; namespace DS.WMS.Core.System.Method; /// /// /// public class SysOrgService:ISysOrgService { private readonly IServiceProvider _serviceProvider; private readonly ISqlSugarClient db; private readonly IUser user; private readonly ICommonService _commonService; /// /// /// /// public SysOrgService(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; db = _serviceProvider.GetRequiredService(); user = _serviceProvider.GetRequiredService(); _commonService = _serviceProvider.GetRequiredService(); } public DataResult> GetListByPage(PageRequest request) { //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = db.Queryable() .Select() .Where(whereList).ToQueryPage(request.PageCondition); return data; } /// /// /// /// /// public DataResult EditOrg(SysOrgReq req) { if (req.Id == 0) { var isExist = db.Queryable().Where(x => x.OrgName == req.OrgName).First(); if (isExist != null) { return DataResult.Failed("机构名称已存在!",MultiLanguageConst.OrgNameExist); } var data = req.Adapt(); var entity = db.Insertable(data).ExecuteReturnEntity(); return DataResult.Successed("添加成功!", entity.Id,MultiLanguageConst.DataCreateSuccess); } else { var info = db.Queryable().Where(x => x.Id == req.Id).First(); info = req.Adapt(info); db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess); } } /// /// 获取机构信息 /// /// /// public DataResult GetOrgInfo(string id) { var data = db.Queryable() .Where(a => a.Id == long.Parse(id)) .Select() .First(); return DataResult.Success(data,MultiLanguageConst.DataQuerySuccess); } /// /// 获取树型机构 /// /// public DataResult> GetOrgTree() { var list = db.Queryable().Select(a => new OrgTree { Title = a.OrgName, Value = a.Id, ParentId = a.ParentId }).ToList(); var orgList = BuildTree(list); return DataResult>.Success("获取数据成功!", orgList); } /// /// 双层循环 /// /// /// public static List BuildTree(List treeNodes) { try { List trees = new List(); foreach (var treeNode in treeNodes) { if (0 == (treeNode.ParentId)) { trees.Add(treeNode); } foreach (var it in treeNodes) { if (it.ParentId == treeNode.Value) { treeNode.Children.Add(it); } } } return trees; } catch (Exception ex) { throw ex; } } }