using Infrastructure; using OpenAuth.App.Base; using OpenAuth.App.BaseApp.Base; using OpenAuth.App.Interface; using OpenAuth.App.Request; using OpenAuth.App.Response; using OpenAuth.Repository; using OpenAuth.Repository.Domain; using SqlSugar; namespace OpenAuth.App { public class CategoryApp : SqlSugarBaseApp { private DbExtension extension; private readonly ISqlSugarClient client; public CategoryApp(ISugarUnitOfWork unitWork, ISimpleClient repository, IAuth auth, DbExtension dbExtension, ISqlSugarClient client) : base(unitWork, repository, auth) { extension = dbExtension; this.client = client; } /// /// 加载列表 /// public void Add(AddOrUpdateCategoryReq req) { var obj = req.MapTo(); obj.CreateTime = DateTime.Now; var user = _auth.GetCurrentUser().User; obj.CreateUserId = user.Id; obj.CreateUserName = user.Name; Repository.Insert(obj); } public void Update(AddOrUpdateCategoryReq obj) { var user = _auth.GetCurrentUser().User; Repository.Update(u => new SysCategory { Name = obj.Name, Enable = obj.Enable, DtValue = obj.DtValue, DtCode = obj.DtCode, TypeId = obj.TypeId, UpdateTime = DateTime.Now, UpdateUserId = user.Id, UpdateUserName = user.Name //todo:要修改的字段赋值 }, u => u.Id == obj.Id); } /// /// 加载一个分类类型里面的所有值,即字典的所有值 /// /// /// public dynamic LoadByTypeId(string typeId, int page, int limit) { var loginContext = _auth.GetCurrentUser(); var properties = extension.GetProperties(typeof(SysCategory)); var p = new PageModel() { PageIndex = page, PageSize = limit }; var exp = Expressionable.Create() .AndIF(!string.IsNullOrEmpty(typeId), u => u.TypeId == typeId) .ToExpression(); var list = Repository.GetPageList(exp, p); //return new TableData //{ // code = 200, // count = p.TotalCount, // data = list, // msg = "success" //}; return new { code = 200, columnHeaders = properties, count = p.TotalCount, data = list, msg = "success" }; } public TableData QueryCategory(string type) { var table = base.Repository.AsQueryable() .Where(a => a.TypeId == type) .OrderBy(a => a.SortNo) .Select(a => new { a.Name, a.DtCode, a.DtValue }).ToList(); return new TableData() { count = table.Count, data = table }; } public void Delete(string[] ids) { Repository.DeleteByIds(ids); } public SysCategory Get(string id) { return Repository.GetById(id); } #region 原航飞库 /// /// 获取字典 /// /// /// public List LoadList(string typeid) { var list = client.Queryable().Where(c => c.ItemCode == typeid).OrderByDescending(c => c.CreateDate) .Select(c => new App.Request.Category { Id = c.ItemDetailId, Name = c.ItemName, DtCode = c.ItemCode, DtValue = c.ItemValue, SortNo = c.SortCode, Description = c.Description, Enable = c.EnabledMark, TypeId = c.ItemCode, CreateTime = c.CreateDate, CreateUserId = c.CreateUserId, CreateUserName = c.CreateUserName, UpdateTime = c.ModifyDate, UpdateUserId = c.ModifyUserId, UpdateUserName = c.ModifyUserName }) .ToList(); return list; } #endregion } }