diff --git a/Tiobon.Core.Api/Controllers/BaseApiController.cs b/Tiobon.Core.Api/Controllers/BaseApiController.cs index 4ac75933..c6e8a7f5 100644 --- a/Tiobon.Core.Api/Controllers/BaseApiController.cs +++ b/Tiobon.Core.Api/Controllers/BaseApiController.cs @@ -1,84 +1,51 @@ namespace Tiobon.Core.Controllers { public class BaseApiController : Controller - { - [NonAction] - public MessageModel Success(T data, string msg = "成功") - { - return new MessageModel() - { - success = true, - msg = msg, - response = data, - }; - } + { + [NonAction] + public MessageModel Success(T data, string msg = "成功") + { + return new MessageModel() { success = true, msg = msg, response = data, }; + } - // [NonAction] - //public MessageModel Success(T data, string msg = "成功",bool success = true) - //{ - // return new MessageModel() - // { - // success = success, - // msg = msg, - // response = data, - // }; - //} - [NonAction] - public MessageModel Success(string msg = "成功") - { - return new MessageModel() - { - success = true, - msg = msg, - response = null, - }; - } - - [NonAction] - public MessageModel Failed(string msg = "失败", int status = 500) - { - return new MessageModel() - { - success = false, - status = status, - msg = msg, - response = null, - }; - } + // [NonAction] + //public MessageModel Success(T data, string msg = "成功",bool success = true) + //{ + // return new MessageModel() + // { + // success = success, + // msg = msg, + // response = data, + // }; + //} + [NonAction] + public MessageModel Success(string msg = "成功") + { + return new MessageModel() { success = true, msg = msg, response = null, }; + } - [NonAction] - public MessageModel Failed(string msg = "失败", int status = 500) - { - return new MessageModel() - { - success = false, - status = status, - msg = msg, - response = default, - }; - } + [NonAction] + public MessageModel Failed(string msg = "失败", int status = 500) + { + return new MessageModel() { success = false, status = status, msg = msg, response = null, }; + } - [NonAction] - public MessageModel> SuccessPage(int page, int dataCount, int pageSize, List data, - int pageCount, string msg = "获取成功") - { - return new MessageModel>() - { - success = true, - msg = msg, - response = new PageModel(page, dataCount, pageSize, data) - }; - } + [NonAction] + public MessageModel Failed(string msg = "失败", int status = 500) + { + return new MessageModel() { success = false, status = status, msg = msg, response = default, }; + } - [NonAction] - public MessageModel> SuccessPage(PageModel pageModel, string msg = "获取成功") - { - return new MessageModel>() - { - success = true, - msg = msg, - response = pageModel - }; - } - } + [NonAction] + public MessageModel> SuccessPage(int page, int dataCount, int pageSize, List data, int pageCount, string msg = "获取成功") + { + return new MessageModel>() { success = true, msg = msg, response = new PageModel(page, dataCount, pageSize, data) }; + } + + [NonAction] + public MessageModel> SuccessPage(PageModel pageModel, string msg = "获取成功") + { + return new MessageModel>() { success = true, msg = msg, response = pageModel }; + } + } } \ No newline at end of file diff --git a/Tiobon.Core.Api/Controllers/BaseController.cs b/Tiobon.Core.Api/Controllers/BaseController.cs new file mode 100644 index 00000000..1b8d57df --- /dev/null +++ b/Tiobon.Core.Api/Controllers/BaseController.cs @@ -0,0 +1,62 @@ +namespace Tiobon.Core.Controllers +{ + public class BaseController : Controller + { + #region 初始化 + protected IServiceBase _service; + /// + /// + /// + public BaseController(IServiceBase service) + { + _service = service; + } + #endregion + + [NonAction] + public MessageModel Success(T data, string msg = "成功") + { + return new MessageModel() { success = true, msg = msg, response = data, }; + } + + // [NonAction] + //public MessageModel Success(T data, string msg = "成功",bool success = true) + //{ + // return new MessageModel() + // { + // success = success, + // msg = msg, + // response = data, + // }; + //} + [NonAction] + public MessageModel Success(string msg = "成功") + { + return new MessageModel() { success = true, msg = msg, response = null, }; + } + + [NonAction] + public MessageModel Failed(string msg = "失败", int status = 500) + { + return new MessageModel() { success = false, status = status, msg = msg, response = null, }; + } + + [NonAction] + public MessageModel Failed(string msg = "失败", int status = 500) + { + return new MessageModel() { success = false, status = status, msg = msg, response = default, }; + } + + [NonAction] + public MessageModel> SuccessPage(int page, int dataCount, int pageSize, List data, int pageCount, string msg = "获取成功") + { + return new MessageModel>() { success = true, msg = msg, response = new PageModel(page, dataCount, pageSize, data) }; + } + + [NonAction] + public MessageModel> SuccessPage(PageModel pageModel, string msg = "获取成功") + { + return new MessageModel>() { success = true, msg = msg, response = pageModel }; + } + } +} \ No newline at end of file diff --git a/Tiobon.Core.Api/Controllers/Ghra_GradeController.cs b/Tiobon.Core.Api/Controllers/Ghra_GradeController.cs index 8a522272..3ca5d019 100644 --- a/Tiobon.Core.Api/Controllers/Ghra_GradeController.cs +++ b/Tiobon.Core.Api/Controllers/Ghra_GradeController.cs @@ -6,19 +6,11 @@ [Route("api/[controller]")] [ApiController, GlobalActionFilter] [Authorize(Permissions.Name), ApiExplorerSettings(GroupName = Grouping.GroupName_Ghra)] - public class Ghra_GradeController : ControllerBase + public class Ghra_GradeController : BaseController { - #region 初始化 - /// - /// 服务器接口,因为是模板生成,所以首字母是大写的,自己可以重构下 - /// - private readonly IGhra_GradeServices _ghra_GradeServices; - - public Ghra_GradeController(IGhra_GradeServices Ghra_GradeServices) + public Ghra_GradeController(IGhra_GradeServices service) : base(service) { - _ghra_GradeServices = Ghra_GradeServices; } - #endregion #region 基础接口 @@ -31,7 +23,7 @@ [HttpGet] public async Task>> Get([FromFilter] QueryFilter filter) { - var response = await _ghra_GradeServices.QueryFilterPage(filter); + var response = await _service.QueryFilterPage(filter); return new MessageModel>() { msg = "获取成功", success = true, response = response }; } @@ -43,7 +35,7 @@ [HttpGet("{Id}")] public async Task> Get(string Id) { - var entity = await _ghra_GradeServices.QueryById(Id); + var entity = await _service.QueryById(Id); if (entity == null) return MessageModel.Fail("获取失败"); else @@ -62,7 +54,7 @@ { var data = MessageModel.Success("获取成功", null); - var id = await _ghra_GradeServices.Add(insertModel); + var id = await _service.Add(insertModel); data.success = id > 0; if (data.success) data.response = id.ObjToString(); @@ -82,7 +74,7 @@ public async Task Put(long Id, [FromBody] EditGhra_GradeInput editModel) { var data = MessageModel.Success("更新成功"); - data.success = await _ghra_GradeServices.Update(Id, editModel); + data.success = await _service.Update(Id, editModel); if (!data.success) data.msg = "更新失败"; @@ -100,12 +92,12 @@ public async Task Delete(long Id) { var data = MessageModel.Success("删除成功"); - var entity = await _ghra_GradeServices.QueryById(Id); + var entity = await _service.QueryById(Id); if (entity == null) return MessageModel.Fail("删除失败"); entity.IsEnable = 0; - data.success = await _ghra_GradeServices.Update(entity); + data.success = await _service.Update(entity); if (!data.success) data.msg = "删除失败"; return data; diff --git a/Tiobon.Core.Api/Tiobon.Core.xml b/Tiobon.Core.Api/Tiobon.Core.xml index e254f144..3559a6cf 100644 --- a/Tiobon.Core.Api/Tiobon.Core.xml +++ b/Tiobon.Core.Api/Tiobon.Core.xml @@ -4,6 +4,11 @@ Tiobon.Core.Api + + + + + 博客管理 @@ -1221,11 +1226,6 @@ Ghra_Grade - - - 服务器接口,因为是模板生成,所以首字母是大写的,自己可以重构下 - - Ghra_Grade -- 根据条件查询数据 diff --git a/Tiobon.Core.Common/Attribute/QueryFilter.cs b/Tiobon.Core.Common/Attribute/QueryFilter.cs index bfa45dc4..b5f0b8d3 100644 --- a/Tiobon.Core.Common/Attribute/QueryFilter.cs +++ b/Tiobon.Core.Common/Attribute/QueryFilter.cs @@ -1,89 +1,61 @@ using System.ComponentModel.DataAnnotations; -namespace Tiobon.Core.Common +namespace Tiobon.Core.Common; + +/// +/// 动态查询条件 +/// +public class QueryFilter { + private int _pageIndex; /// - /// 动态查询条件 + /// 起始位置(e.g. 0) /// - public class QueryFilter + [Required] + public int PageIndex { - private int _pageIndex; - /// - /// 起始位置(e.g. 0) - /// - [Required] - public int PageIndex + get { return _pageIndex; } + set { - get { return _pageIndex; } - set - { - //前端默认从分页显示默认1开始,所以后端需要-1 - if (value >= 1) - value -= 1; - _pageIndex = value; - } + //前端默认从分页显示默认1开始,所以后端需要-1 + if (value >= 1) + value -= 1; + _pageIndex = value; } - /// - /// 每页数量(e.g. 10) - /// - [Required] - public int PageSize { get; set; } - private string _predicate; - /// - /// 查询条件表达式(e.g. LoginName.Contains(@0)) - /// - public string Predicate + } + /// + /// 每页数量(e.g. 10) + /// + [Required] + public int PageSize { get; set; } + private string _conditions; + /// + /// 查询条件( 例如:id = 1 and name = 小明) + /// + public string Conditions + { + get { return _conditions; } + set { - get { return _predicate; } - set - { - //前端默认从分页显示默认1开始,所以后端需要-1 - if (value == "1=1") - value = null; - _predicate = value; - } + //前端默认从分页显示默认1开始,所以后端需要-1 + if (value == "1=1") + value = null; + _conditions = value; } - /// - /// 查询条件表达式参数(e.g. LoginName) - /// - public object[] PredicateValues { get; set; } - /// - /// 排序条件表达式(e.g. LoginName ASC,Name DESC) - /// - public string Sorting { get; set; } - ///// - ///// 患者关键字(姓名、别名、拼音、五笔)模糊查询 - ///// - //public string PatientKey { get; set; } - ///// - ///// 报表患者过滤条件 - ///// - //public PatientFilter PatientFilter { get; set; } - ///// - ///// 分组条件(e.g. [10,20,30]) - ///// - //public List GroupValues { get; set; } - ///// - ///// 导出字段,按照顺序填写(e.g. [{ Key: 'PatientNameFull', Name: '患者姓名' }, { Key: 'DeviceCode', Name: '设备编号' }]) - ///// - //public List ExportFields { get; set; } - ///// - ///// 导出字段的宽度(默认20),按照顺序与字段一一对应填写(e.g. [20,50,20]) - ///// - //public List ExportFieldsWidth { get; set; } - /// - /// 缺省值 - /// - public static QueryFilter Default => new QueryFilter - { - PageIndex = 1, - PageSize = 100000, - Sorting = string.Empty, - Predicate = string.Empty, - PredicateValues = Array.Empty(), - //GroupValues = new List(), - //ExportFields = new List(), - //ExportFieldsWidth = new List() - }; } -} + + /// + /// 排序条件表达式(e.g. LoginName ASC,Name DESC) + /// + public string Sorting { get; set; } + /// + /// 缺省值 + /// + public static QueryFilter Default => new QueryFilter + { + PageIndex = 1, + PageSize = 100000, + Sorting = string.Empty, + Conditions = string.Empty + }; +} \ No newline at end of file diff --git a/Tiobon.Core.Repository/BASE/BaseRepository.cs b/Tiobon.Core.Repository/BASE/BaseRepository.cs index 8171c778..89d5f6ce 100644 --- a/Tiobon.Core.Repository/BASE/BaseRepository.cs +++ b/Tiobon.Core.Repository/BASE/BaseRepository.cs @@ -455,14 +455,9 @@ namespace Tiobon.Core.Repository.Base { RefAsync totalCount = 0; var query = _db.Queryable(); - if (!filter.Predicate.IsNullOrEmpty()) - { - for (int i = 0; i < filter.PredicateValues.Length; i++) - { - filter.Predicate = filter.Predicate.Replace($"@{i}", filter.PredicateValues[i].ToString()); - } - query = query.Where(filter.Predicate); - } + if (!filter.Conditions.IsNullOrEmpty()) + query = query.Where(filter.Conditions); + var list = await query .OrderByIF(!string.IsNullOrEmpty(filter.Sorting), filter.Sorting) diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs index 51dde1b1..9fb96efa 100644 --- a/Tiobon.Core.Services/BASE/BaseServices.cs +++ b/Tiobon.Core.Services/BASE/BaseServices.cs @@ -816,8 +816,7 @@ namespace Tiobon.Core.Services.BASE PageIndex = 1, PageSize = 1, Sorting = string.Empty, - Predicate = "Id=@0", - PredicateValues = new object[] { id } + Conditions = string.Empty }; } #endregion