Infrastructure/OpenAuth.App/BaseApp/Category/CategoryApp.cs

150 lines
4.7 KiB
C#
Raw Normal View History

2024-11-13 09:19:06 +08:00
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<SysCategory, SugarDbContext>
{
private DbExtension extension;
2024-11-20 16:09:32 +08:00
private readonly ISqlSugarClient client;
public CategoryApp(ISugarUnitOfWork<SugarDbContext> unitWork, ISimpleClient<SysCategory> repository, IAuth auth, DbExtension dbExtension, ISqlSugarClient client) : base(unitWork, repository, auth)
2024-11-13 09:19:06 +08:00
{
extension = dbExtension;
2024-11-20 16:09:32 +08:00
this.client = client;
2024-11-13 09:19:06 +08:00
}
/// <summary>
/// 加载列表
/// </summary>
public void Add(AddOrUpdateCategoryReq req)
{
var obj = req.MapTo<SysCategory>();
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);
}
/// <summary>
/// 加载一个分类类型里面的所有值,即字典的所有值
/// </summary>
/// <param name="typeId"></param>
/// <returns></returns>
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<SysCategory>()
.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);
}
2024-11-20 16:09:32 +08:00
#region 原航飞库
/// <summary>
/// 获取字典
/// </summary>
/// <param name="typeid"></param>
/// <returns></returns>
public List<OpenAuth.App.Request.Category> LoadList(string typeid)
{
var list = client.Queryable<SysDataItemDetail>().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
2024-11-13 09:19:06 +08:00
}
}