mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2026-04-17 19:18:03 +08:00
增加撤销与启动,详见:#I3ILBG
调整工程结构,采用模块化机制
This commit is contained in:
98
OpenAuth.App/Category/CategoryApp.cs
Normal file
98
OpenAuth.App/Category/CategoryApp.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class CategoryApp : BaseStringApp<Category,OpenAuthDBContext>
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载列表
|
||||
/// </summary>
|
||||
public async Task<TableData> Load(QueryCategoryListReq request)
|
||||
{
|
||||
var loginContext = _auth.GetCurrentUser();
|
||||
if (loginContext == null)
|
||||
{
|
||||
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
|
||||
}
|
||||
|
||||
var properties = loginContext.GetProperties("Category");
|
||||
|
||||
if (properties == null || properties.Count == 0)
|
||||
{
|
||||
throw new Exception("当前登录用户没有访问该模块字段的权限,请联系管理员配置");
|
||||
}
|
||||
|
||||
var result = new TableData();
|
||||
var objs = UnitWork.Find<Category>(null);
|
||||
if (!string.IsNullOrEmpty(request.TypeId))
|
||||
{
|
||||
objs = objs.Where(u => u.TypeId == request.TypeId);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
objs = objs.Where(u => u.Id.Contains(request.key) || u.Name.Contains(request.key));
|
||||
}
|
||||
|
||||
var propertyStr = string.Join(',', properties.Select(u =>u.Key));
|
||||
result.columnHeaders = properties;
|
||||
result.data = objs.OrderBy(u => u.DtCode)
|
||||
.Skip((request.page - 1) * request.limit)
|
||||
.Take(request.limit).Select($"new ({propertyStr})");
|
||||
result.count = objs.Count();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Add(AddOrUpdateCategoryReq req)
|
||||
{
|
||||
var obj = req.MapTo<Category>();
|
||||
obj.CreateTime = DateTime.Now;
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
obj.CreateUserId = user.Id;
|
||||
obj.CreateUserName = user.Name;
|
||||
Repository.Add(obj);
|
||||
}
|
||||
|
||||
public void Update(AddOrUpdateCategoryReq obj)
|
||||
{
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
UnitWork.Update<Category>(u => u.Id == obj.Id, u => new Category
|
||||
{
|
||||
Enable = obj.Enable,
|
||||
DtValue = obj.DtValue,
|
||||
DtCode = obj.DtCode,
|
||||
TypeId = obj.TypeId,
|
||||
UpdateTime = DateTime.Now,
|
||||
UpdateUserId = user.Id,
|
||||
UpdateUserName = user.Name
|
||||
//todo:要修改的字段赋值
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载一个分类类型里面的所有值,即字典的所有值
|
||||
/// </summary>
|
||||
/// <param name="typeId"></param>
|
||||
/// <returns></returns>
|
||||
public List<Category> LoadByTypeId(string typeId)
|
||||
{
|
||||
return Repository.Find(u => u.TypeId == typeId).ToList();
|
||||
}
|
||||
|
||||
public CategoryApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Category,OpenAuthDBContext> repository,IAuth auth) : base(unitWork, repository, auth)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
81
OpenAuth.App/Category/CategoryTypeApp.cs
Normal file
81
OpenAuth.App/Category/CategoryTypeApp.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class CategoryTypeApp : BaseStringApp<CategoryType,OpenAuthDBContext>
|
||||
{
|
||||
private RevelanceManagerApp _revelanceApp;
|
||||
|
||||
/// <summary>
|
||||
/// 加载列表
|
||||
/// </summary>
|
||||
public async Task<TableData> Load(QueryCategoryTypeListReq request)
|
||||
{
|
||||
var result = new TableData();
|
||||
var objs = UnitWork.Find<CategoryType>(null);
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
objs = objs.Where(u => u.Id.Contains(request.key) || u.Name.Contains(request.key));
|
||||
}
|
||||
|
||||
result.data = objs.OrderBy(u => u.Name)
|
||||
.Skip((request.page - 1) * request.limit)
|
||||
.Take(request.limit);
|
||||
result.count = objs.Count();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Add(AddOrUpdateCategoryTypeReq req)
|
||||
{
|
||||
var obj = req.MapTo<CategoryType>();
|
||||
//todo:补充或调整自己需要的字段
|
||||
obj.CreateTime = DateTime.Now;
|
||||
Repository.Add(obj);
|
||||
}
|
||||
|
||||
public void Update(AddOrUpdateCategoryTypeReq obj)
|
||||
{
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
UnitWork.Update<CategoryType>(u => u.Id == obj.Id, u => new CategoryType
|
||||
{
|
||||
Name = obj.Name,
|
||||
CreateTime = DateTime.Now
|
||||
//todo:补充或调整自己需要的字段
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public new void Delete(string[] ids)
|
||||
{
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
UnitWork.Delete<CategoryType>(u=>ids.Contains(u.Id));
|
||||
UnitWork.Delete<Category>(u=>ids.Contains(u.TypeId));
|
||||
UnitWork.Save();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public List<CategoryType> AllTypes()
|
||||
{
|
||||
return UnitWork.Find<CategoryType>(null).ToList();
|
||||
}
|
||||
|
||||
public CategoryTypeApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<CategoryType,OpenAuthDBContext> repository,
|
||||
RevelanceManagerApp app, IAuth auth) : base(unitWork, repository,auth)
|
||||
{
|
||||
_revelanceApp = app;
|
||||
}
|
||||
}
|
||||
}
|
||||
51
OpenAuth.App/Category/Request/AddOrUpdateCategoryReq.cs
Normal file
51
OpenAuth.App/Category/Request/AddOrUpdateCategoryReq.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <autogenerated>
|
||||
// This code was generated by a CodeSmith Template.
|
||||
//
|
||||
// DO NOT MODIFY contents of this file. Changes to this
|
||||
// file will be lost if the code is regenerated.
|
||||
// Author:Yubao Li
|
||||
// </autogenerated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// 分类表,也可用作数据字典。表示一个全集,比如:男、女、未知。关联的分类类型表示按什么进行的分类,如:按照性别对人类对象集
|
||||
/// </summary>
|
||||
public class AddOrUpdateCategoryReq
|
||||
{
|
||||
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分类名称或描述
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// 分类标识
|
||||
/// </summary>
|
||||
public string DtCode { get; set; }
|
||||
/// <summary>
|
||||
/// 通常与分类标识一致,但万一有不一样的情况呢?
|
||||
/// </summary>
|
||||
public string DtValue { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool Enable { get; set; }
|
||||
/// <summary>
|
||||
/// 排序号
|
||||
/// </summary>
|
||||
public int SortNo { get; set; }
|
||||
/// <summary>
|
||||
/// 详细说明,基本没啥用
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
/// <summary>
|
||||
/// 分类的ID
|
||||
/// </summary>
|
||||
public string TypeId { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
31
OpenAuth.App/Category/Request/AddOrUpdateCategoryTypeReq.cs
Normal file
31
OpenAuth.App/Category/Request/AddOrUpdateCategoryTypeReq.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <autogenerated>
|
||||
// This code was generated by a CodeSmith Template.
|
||||
//
|
||||
// DO NOT MODIFY contents of this file. Changes to this
|
||||
// file will be lost if the code is regenerated.
|
||||
// Author:Yubao Li
|
||||
// </autogenerated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// 分类类型
|
||||
/// </summary>
|
||||
[Table("CategoryType")]
|
||||
public partial class AddOrUpdateCategoryTypeReq
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 分类表ID
|
||||
/// </summary>
|
||||
public string Id { get; set; }
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
11
OpenAuth.App/Category/Request/QueryCategoryListReq.cs
Normal file
11
OpenAuth.App/Category/Request/QueryCategoryListReq.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class QueryCategoryListReq : PageReq
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// TypeID
|
||||
/// </summary>
|
||||
public string TypeId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class QueryCategoryTypeListReq : PageReq
|
||||
{
|
||||
//todo:添加自己的请求字段
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user