diff --git a/Tiobon.Core.Api/Controllers/BaseApiController.cs b/Tiobon.Core.Api/Controllers/BaseApiController.cs index c6e8a7f5..69254a13 100644 --- a/Tiobon.Core.Api/Controllers/BaseApiController.cs +++ b/Tiobon.Core.Api/Controllers/BaseApiController.cs @@ -1,17 +1,19 @@ -namespace Tiobon.Core.Controllers +using Tiobon.Core.Model; + +namespace Tiobon.Core.Controllers { public class BaseApiController : Controller { [NonAction] - public MessageModel Success(T data, string msg = "成功") + public ServiceResult Success(T data, string msg = "成功") { - return new MessageModel() { success = true, msg = msg, response = data, }; + return new ServiceResult() { success = true, msg = msg, response = data, }; } // [NonAction] - //public MessageModel Success(T data, string msg = "成功",bool success = true) + //public ServiceResult Success(T data, string msg = "成功",bool success = true) //{ - // return new MessageModel() + // return new ServiceResult() // { // success = success, // msg = msg, @@ -19,33 +21,33 @@ // }; //} [NonAction] - public MessageModel Success(string msg = "成功") + public ServiceResult Success(string msg = "成功") { - return new MessageModel() { success = true, msg = msg, response = null, }; + return new ServiceResult() { success = true, msg = msg, response = null, }; } [NonAction] - public MessageModel Failed(string msg = "失败", int status = 500) + public ServiceResult Failed(string msg = "失败", int status = 500) { - return new MessageModel() { success = false, status = status, msg = msg, response = null, }; + return new ServiceResult() { success = false, status = status, msg = msg, response = null, }; } [NonAction] - public MessageModel Failed(string msg = "失败", int status = 500) + public ServiceResult Failed(string msg = "失败", int status = 500) { - return new MessageModel() { success = false, status = status, msg = msg, response = default, }; + return new ServiceResult() { success = false, status = status, msg = msg, response = default, }; } [NonAction] - public MessageModel> SuccessPage(int page, int dataCount, int pageSize, List data, int pageCount, string msg = "获取成功") + public ServiceResult> 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) }; + return new ServiceResult>() { success = true, msg = msg, response = new PageModel(page, dataCount, pageSize, data) }; } [NonAction] - public MessageModel> SuccessPage(PageModel pageModel, string msg = "获取成功") + public ServiceResult> SuccessPage(PageModel pageModel, string msg = "获取成功") { - return new MessageModel>() { success = true, msg = msg, response = pageModel }; + return new ServiceResult>() { 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 index 1b8d57df..b9c67587 100644 --- a/Tiobon.Core.Api/Controllers/BaseController.cs +++ b/Tiobon.Core.Api/Controllers/BaseController.cs @@ -1,4 +1,6 @@ -namespace Tiobon.Core.Controllers +using Tiobon.Core.Model; + +namespace Tiobon.Core.Controllers { public class BaseController : Controller { @@ -14,15 +16,15 @@ #endregion [NonAction] - public MessageModel Success(T data, string msg = "成功") + public ServiceResult Success(T data, string msg = "成功") { - return new MessageModel() { success = true, msg = msg, response = data, }; + return new ServiceResult() { success = true, msg = msg, response = data, }; } // [NonAction] - //public MessageModel Success(T data, string msg = "成功",bool success = true) + //public ServiceResult Success(T data, string msg = "成功",bool success = true) //{ - // return new MessageModel() + // return new ServiceResult() // { // success = success, // msg = msg, @@ -30,33 +32,33 @@ // }; //} [NonAction] - public MessageModel Success(string msg = "成功") + public ServiceResult Success(string msg = "成功") { - return new MessageModel() { success = true, msg = msg, response = null, }; + return new ServiceResult() { success = true, msg = msg, response = null, }; } [NonAction] - public MessageModel Failed(string msg = "失败", int status = 500) + public ServiceResult Failed(string msg = "失败", int status = 500) { - return new MessageModel() { success = false, status = status, msg = msg, response = null, }; + return new ServiceResult() { success = false, status = status, msg = msg, response = null, }; } [NonAction] - public MessageModel Failed(string msg = "失败", int status = 500) + public ServiceResult Failed(string msg = "失败", int status = 500) { - return new MessageModel() { success = false, status = status, msg = msg, response = default, }; + return new ServiceResult() { success = false, status = status, msg = msg, response = default, }; } [NonAction] - public MessageModel> SuccessPage(int page, int dataCount, int pageSize, List data, int pageCount, string msg = "获取成功") + public ServiceResult> 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) }; + return new ServiceResult>() { success = true, msg = msg, response = new PageModel(page, dataCount, pageSize, data) }; } [NonAction] - public MessageModel> SuccessPage(PageModel pageModel, string msg = "获取成功") + public ServiceResult> SuccessPage(PageModel pageModel, string msg = "获取成功") { - return new MessageModel>() { success = true, msg = msg, response = pageModel }; + return new ServiceResult>() { success = true, msg = msg, response = pageModel }; } } } \ No newline at end of file diff --git a/Tiobon.Core.Api/Controllers/BlogController.cs b/Tiobon.Core.Api/Controllers/BlogController.cs index 6645d9a2..3d12275a 100644 --- a/Tiobon.Core.Api/Controllers/BlogController.cs +++ b/Tiobon.Core.Api/Controllers/BlogController.cs @@ -34,7 +34,7 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public async Task>> Get(int id, int page = 1, string bcategory = "技术博文", string key = "") + public async Task>> Get(int id, int page = 1, string bcategory = "技术博文", string key = "") { int intPageSize = 6; if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key)) @@ -74,7 +74,7 @@ namespace Tiobon.Core.Controllers [HttpGet("{id}")] //[Authorize(Policy = "Scope_TiobonModule_Policy")] [Authorize] - public async Task> Get(long id) + public async Task> Get(long id) { return Success(await _TiobonArticleServices.GetTiobonDetails(id)); } @@ -87,7 +87,7 @@ namespace Tiobon.Core.Controllers /// [HttpGet] [Route("DetailNuxtNoPer")] - public async Task> DetailNuxtNoPer(long id) + public async Task> DetailNuxtNoPer(long id) { _logger.LogInformation("xxxxxxxxxxxxxxxxxxx"); Log.Information("yyyyyyyyyyyyyyyyy"); @@ -116,7 +116,7 @@ namespace Tiobon.Core.Controllers [HttpGet] [Route("GetTiobonsByTypesForMVP")] - public async Task>> GetTiobonsByTypesForMVP(string types = "", int id = 0) + public async Task>> GetTiobonsByTypesForMVP(string types = "", int id = 0) { if (types.IsNotEmptyOrNull()) { @@ -128,7 +128,7 @@ namespace Tiobon.Core.Controllers [HttpGet] [Route("GetTiobonByIdForMVP")] - public async Task> GetTiobonByIdForMVP(long id = 0) + public async Task> GetTiobonByIdForMVP(long id = 0) { if (id > 0) { @@ -149,7 +149,7 @@ namespace Tiobon.Core.Controllers //和上边的版本控制以及路由地址都是一样的 [CustomRoute(ApiVersions.V2, "Tiobontest")] - public MessageModel V2_Tiobontest() + public ServiceResult V2_Tiobontest() { return Success("我是第二版的博客信息"); } @@ -162,7 +162,7 @@ namespace Tiobon.Core.Controllers [HttpPost] //[Authorize(Policy = "Scope_TiobonModule_Policy")] [Authorize] - public async Task> Post([FromBody] TiobonArticle TiobonArticle) + public async Task> Post([FromBody] TiobonArticle TiobonArticle) { if (TiobonArticle.btitle.Length > 5 && TiobonArticle.bcontent.Length > 50) { @@ -189,7 +189,7 @@ namespace Tiobon.Core.Controllers [HttpPost] [Route("AddForMVP")] [Authorize(Permissions.Name)] - public async Task> AddForMVP([FromBody] TiobonArticle TiobonArticle) + public async Task> AddForMVP([FromBody] TiobonArticle TiobonArticle) { TiobonArticle.bCreateTime = DateTime.Now; TiobonArticle.bUpdateTime = DateTime.Now; @@ -206,7 +206,7 @@ namespace Tiobon.Core.Controllers [HttpPut] [Route("Update")] [Authorize(Permissions.Name)] - public async Task> Put([FromBody] TiobonArticle TiobonArticle) + public async Task> Put([FromBody] TiobonArticle TiobonArticle) { if (TiobonArticle != null && TiobonArticle.bID > 0) { @@ -239,7 +239,7 @@ namespace Tiobon.Core.Controllers [HttpDelete] [Authorize(Permissions.Name)] [Route("Delete")] - public async Task> Delete(long id) + public async Task> Delete(long id) { if (id > 0) { @@ -260,7 +260,7 @@ namespace Tiobon.Core.Controllers /// [HttpGet] [Route("ApacheTestUpdate")] - public async Task> ApacheTestUpdate() + public async Task> ApacheTestUpdate() { return Success(await _TiobonArticleServices.Update(new { bsubmitter = $"laozhang{DateTime.Now.Millisecond}", bID = 1 }), "更新成功"); } diff --git a/Tiobon.Core.Api/Controllers/DbFirst/DbFirstController.cs b/Tiobon.Core.Api/Controllers/DbFirst/DbFirstController.cs index 624f3e2f..69a48049 100644 --- a/Tiobon.Core.Api/Controllers/DbFirst/DbFirstController.cs +++ b/Tiobon.Core.Api/Controllers/DbFirst/DbFirstController.cs @@ -26,9 +26,9 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public MessageModel GetFrameFiles() + public ServiceResult GetFrameFiles() { - var data = new MessageModel() { success = true, msg = "" }; + var data = new ServiceResult() { success = true, msg = "" }; data.response += @"file path is:C:\my-file\}"; var isMuti = BaseDBConfig.IsMulti; if (Env.IsDevelopment()) @@ -64,12 +64,12 @@ namespace Tiobon.Core.Controllers /// 需要生成的表名 /// [HttpPost] - public MessageModel GetFrameFilesByTableNames([FromBody] string[] tableNames, [FromQuery] string ConnID = null) + public ServiceResult GetFrameFilesByTableNames([FromBody] string[] tableNames, [FromQuery] string ConnID = null) { ConnID = ConnID == null ? MainDb.CurrentDbConnId.ToLower() : ConnID; var isMuti = BaseDBConfig.IsMulti; - var data = new MessageModel() { success = true, msg = "" }; + var data = new ServiceResult() { success = true, msg = "" }; if (Env.IsDevelopment()) { data.response += $"库{ConnID}-IRepositorys层生成:{FrameSeed.CreateIRepositorys(_sqlSugarClient, ConnID, isMuti, tableNames)} || "; @@ -92,12 +92,12 @@ namespace Tiobon.Core.Controllers /// 需要生成的表名 /// [HttpPost] - public MessageModel GetFrameFilesByTableNamesForEntity([FromBody] string[] tableNames, [FromQuery] string ConnID = null) + public ServiceResult GetFrameFilesByTableNamesForEntity([FromBody] string[] tableNames, [FromQuery] string ConnID = null) { ConnID = ConnID == null ? MainDb.CurrentDbConnId.ToLower() : ConnID; var isMuti = BaseDBConfig.IsMulti; - var data = new MessageModel() { success = true, msg = "" }; + var data = new ServiceResult() { success = true, msg = "" }; if (Env.IsDevelopment()) { data.response += $"库{ConnID}-Models层生成:{FrameSeed.CreateModels(_sqlSugarClient, ConnID, isMuti, tableNames)}"; @@ -116,12 +116,12 @@ namespace Tiobon.Core.Controllers /// 需要生成的表名 /// [HttpPost] - public MessageModel GetFrameFilesByTableNamesForController([FromBody] string[] tableNames, [FromQuery] string ConnID = null) + public ServiceResult GetFrameFilesByTableNamesForController([FromBody] string[] tableNames, [FromQuery] string ConnID = null) { ConnID = ConnID == null ? MainDb.CurrentDbConnId.ToLower() : ConnID; var isMuti = BaseDBConfig.IsMulti; - var data = new MessageModel() { success = true, msg = "" }; + var data = new ServiceResult() { success = true, msg = "" }; if (Env.IsDevelopment()) { data.response += $"库{ConnID}-Controllers层生成:{FrameSeed.CreateControllers(_sqlSugarClient, ConnID, isMuti, tableNames)}"; @@ -141,14 +141,14 @@ namespace Tiobon.Core.Controllers /// 需要生成的表名 /// [HttpPost] - public MessageModel GetAllFrameFilesByTableNames([FromQuery] string tableName, [FromQuery] string ConnID = null) + public ServiceResult GetAllFrameFilesByTableNames([FromQuery] string tableName, [FromQuery] string ConnID = null) { string[] tableNames = new string[1]; tableNames[0] = tableName; ConnID = ConnID == null ? MainDb.CurrentDbConnId.ToLower() : ConnID; var isMuti = BaseDBConfig.IsMulti; - var data = new MessageModel() { success = true, msg = "" }; + var data = new ServiceResult() { success = true, msg = "" }; if (Env.IsDevelopment()) { _sqlSugarClient.ChangeDatabase(ConnID.ToLower()); diff --git a/Tiobon.Core.Api/Controllers/DbFirst/MigrateController.cs b/Tiobon.Core.Api/Controllers/DbFirst/MigrateController.cs index 2c69e503..2c2cf4a7 100644 --- a/Tiobon.Core.Api/Controllers/DbFirst/MigrateController.cs +++ b/Tiobon.Core.Api/Controllers/DbFirst/MigrateController.cs @@ -46,9 +46,9 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public async Task> DataMigrateFromOld2New() + public async Task> DataMigrateFromOld2New() { - var data = new MessageModel() { success = true, msg = "" }; + var data = new ServiceResult() { success = true, msg = "" }; var filterPermissionId = 122; if (_env.IsDevelopment()) { @@ -147,9 +147,9 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public async Task> SaveData2TsvAsync() + public async Task> SaveData2TsvAsync() { - var data = new MessageModel() { success = true, msg = "" }; + var data = new ServiceResult() { success = true, msg = "" }; if (_env.IsDevelopment()) { @@ -203,9 +203,9 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public async Task> SaveData2ExcelAsync() + public async Task> SaveData2ExcelAsync() { - var data = new MessageModel() { success = true, msg = "" }; + var data = new ServiceResult() { success = true, msg = "" }; if (_env.IsDevelopment()) { diff --git a/Tiobon.Core.Api/Controllers/DepartmentController.cs b/Tiobon.Core.Api/Controllers/DepartmentController.cs index 2e590bf3..c4cf10b8 100644 --- a/Tiobon.Core.Api/Controllers/DepartmentController.cs +++ b/Tiobon.Core.Api/Controllers/DepartmentController.cs @@ -15,7 +15,7 @@ } [HttpGet] - public async Task>> Get(int page = 1, string key = "", int intPageSize = 50) + public async Task>> Get(int page = 1, string key = "", int intPageSize = 50) { if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key)) { @@ -24,7 +24,7 @@ Expression> whereExpression = a => true; - return new MessageModel>() + return new ServiceResult>() { msg = "获取成功", success = true, @@ -34,9 +34,9 @@ } [HttpGet("{id}")] - public async Task> Get(string id) + public async Task> Get(string id) { - return new MessageModel() + return new ServiceResult() { msg = "获取成功", success = true, @@ -52,7 +52,7 @@ /// [HttpGet] [AllowAnonymous] - public async Task>> GetTreeTable(long f = 0, string key = "") + public async Task>> GetTreeTable(long f = 0, string key = "") { List departments = new List(); var departmentList = await _departmentServices.Query(d => d.IsDeleted == false); @@ -98,7 +98,7 @@ /// /// [HttpGet] - public async Task> GetDepartmentTree(long pid = 0) + public async Task> GetDepartmentTree(long pid = 0) { var departments = await _departmentServices.Query(d => d.IsDeleted == false); var departmentTrees = (from child in departments @@ -127,9 +127,9 @@ } [HttpPost] - public async Task> Post([FromBody] Department request) + public async Task> Post([FromBody] Department request) { - var data = new MessageModel(); + var data = new ServiceResult(); var id = await _departmentServices.Add(request); data.success = id > 0; @@ -143,9 +143,9 @@ } [HttpPut] - public async Task> Put([FromBody] Department request) + public async Task> Put([FromBody] Department request) { - var data = new MessageModel(); + var data = new ServiceResult(); data.success = await _departmentServices.Update(request); if (data.success) { @@ -157,9 +157,9 @@ } [HttpDelete] - public async Task> Delete(long id) + public async Task> Delete(long id) { - var data = new MessageModel(); + var data = new ServiceResult(); var model = await _departmentServices.QueryById(id); model.IsDeleted = true; data.success = await _departmentServices.Update(model); @@ -175,9 +175,9 @@ [HttpGet] [AllowAnonymous] - public async Task> SaveData2Tsv() + public async Task> SaveData2Tsv() { - var data = new MessageModel() { success = true, msg = "" }; + var data = new ServiceResult() { success = true, msg = "" }; if (_env.IsDevelopment()) { diff --git a/Tiobon.Core.Api/Controllers/Ghra_GradeController.cs b/Tiobon.Core.Api/Controllers/Ghra_GradeController.cs index 3ca5d019..b8513574 100644 --- a/Tiobon.Core.Api/Controllers/Ghra_GradeController.cs +++ b/Tiobon.Core.Api/Controllers/Ghra_GradeController.cs @@ -21,10 +21,10 @@ /// 条件 /// [HttpGet] - public async Task>> Get([FromFilter] QueryFilter filter) + public async Task>> Get([FromFilter] QueryFilter filter) { var response = await _service.QueryFilterPage(filter); - return new MessageModel>() { msg = "获取成功", success = true, response = response }; + return new ServiceResult>() { msg = "获取成功", success = true, response = response }; } /// @@ -33,13 +33,13 @@ /// 主键ID /// [HttpGet("{Id}")] - public async Task> Get(string Id) + public async Task> Get(string Id) { var entity = await _service.QueryById(Id); if (entity == null) - return MessageModel.Fail("获取失败"); + return ServiceResult.Fail("获取失败"); else - return new MessageModel() { msg = "获取成功", success = true, response = entity }; + return new ServiceResult() { msg = "获取成功", success = true, response = entity }; } #endregion @@ -50,9 +50,9 @@ /// /// [HttpPost] - public async Task> Post([FromBody] InsertGhra_GradeInput insertModel) + public async Task> Post([FromBody] InsertGhra_GradeInput insertModel) { - var data = MessageModel.Success("获取成功", null); + var data = ServiceResult.OprateSuccess("获取成功", null); var id = await _service.Add(insertModel); data.success = id > 0; @@ -71,9 +71,9 @@ /// /// [HttpPut("{Id}")] - public async Task Put(long Id, [FromBody] EditGhra_GradeInput editModel) + public async Task Put(long Id, [FromBody] EditGhra_GradeInput editModel) { - var data = MessageModel.Success("更新成功"); + var data = ServiceResult.OprateSuccess("更新成功"); data.success = await _service.Update(Id, editModel); if (!data.success) data.msg = "更新失败"; @@ -89,12 +89,12 @@ /// /// [HttpDelete("{Id}")] - public async Task Delete(long Id) + public async Task Delete(long Id) { - var data = MessageModel.Success("删除成功"); + var data = ServiceResult.OprateSuccess("删除成功"); var entity = await _service.QueryById(Id); if (entity == null) - return MessageModel.Fail("删除失败"); + return ServiceResult.OprateFailed("删除失败"); entity.IsEnable = 0; data.success = await _service.Update(entity); diff --git a/Tiobon.Core.Api/Controllers/ImgController.cs b/Tiobon.Core.Api/Controllers/ImgController.cs index 8e0759bd..73cf6dfd 100644 --- a/Tiobon.Core.Api/Controllers/ImgController.cs +++ b/Tiobon.Core.Api/Controllers/ImgController.cs @@ -46,7 +46,7 @@ /// [HttpPost] [Route("/images/Upload/Pic")] - public async Task> InsertPicture([FromForm] UploadFileDto dto) + public async Task> InsertPicture([FromForm] UploadFileDto dto) { if (dto.file == null || !dto.file.Any()) return Failed("请选择上传的文件。"); diff --git a/Tiobon.Core.Api/Controllers/LoginController.cs b/Tiobon.Core.Api/Controllers/LoginController.cs index 45e55436..ea6e50ec 100644 --- a/Tiobon.Core.Api/Controllers/LoginController.cs +++ b/Tiobon.Core.Api/Controllers/LoginController.cs @@ -55,7 +55,7 @@ namespace Tiobon.Core.Controllers /// [HttpGet] [Route("Token")] - public async Task> GetJwtStr(string name, string pass) + public async Task> GetJwtStr(string name, string pass) { string jwtStr = string.Empty; bool suc = false; @@ -74,7 +74,7 @@ namespace Tiobon.Core.Controllers jwtStr = "login fail!!!"; } - return new MessageModel() + return new ServiceResult() { success = suc, msg = suc ? "获取成功" : "获取失败", @@ -91,7 +91,7 @@ namespace Tiobon.Core.Controllers /// [HttpGet] [Route("GetTokenNuxt")] - public MessageModel GetJwtStrForNuxt(string name, string pass) + public ServiceResult GetJwtStrForNuxt(string name, string pass) { string jwtStr = string.Empty; bool suc = false; @@ -118,7 +118,7 @@ namespace Tiobon.Core.Controllers data = new {success = suc, token = jwtStr} }; - return new MessageModel() + return new ServiceResult() { success = suc, msg = suc ? "获取成功" : "获取失败", @@ -137,7 +137,7 @@ namespace Tiobon.Core.Controllers /// [HttpGet] [Route("JWTToken3.0")] - public async Task> GetJwtToken3(string name = "", string pass = "") + public async Task> GetJwtToken3(string name = "", string pass = "") { string jwtStr = string.Empty; @@ -193,7 +193,7 @@ namespace Tiobon.Core.Controllers [HttpGet] [Route("GetJwtTokenSecret")] - public async Task> GetJwtTokenSecret(string name = "", string pass = "") + public async Task> GetJwtTokenSecret(string name = "", string pass = "") { var rlt = await GetJwtToken3(name, pass); return rlt; @@ -206,7 +206,7 @@ namespace Tiobon.Core.Controllers /// [HttpGet] [Route("RefreshToken")] - public async Task> RefreshToken(string token = "") + public async Task> RefreshToken(string token = "") { string jwtStr = string.Empty; diff --git a/Tiobon.Core.Api/Controllers/ModuleController.cs b/Tiobon.Core.Api/Controllers/ModuleController.cs index 879e006d..62e1fb21 100644 --- a/Tiobon.Core.Api/Controllers/ModuleController.cs +++ b/Tiobon.Core.Api/Controllers/ModuleController.cs @@ -26,7 +26,7 @@ /// // GET: api/User [HttpGet] - public async Task>> Get(int page = 1, string key = "") + public async Task>> Get(int page = 1, string key = "") { if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key)) { @@ -68,7 +68,7 @@ /// // POST: api/User [HttpPost] - public async Task> Post([FromBody] Modules module) + public async Task> Post([FromBody] Modules module) { module.CreateId = _user.ID; module.CreateBy = _user.Name; @@ -84,9 +84,9 @@ /// // PUT: api/User/5 [HttpPut] - public async Task> Put([FromBody] Modules module) + public async Task> Put([FromBody] Modules module) { - //var data = new MessageModel(); + //var data = new ServiceResult(); //if (module != null && module.Id > 0) //{ //data.success = await _moduleServices.Update(module); @@ -111,7 +111,7 @@ /// // DELETE: api/ApiWithActions/5 [HttpDelete] - public async Task> Delete(long id) + public async Task> Delete(long id) { if (id <= 0) return Failed("缺少参数"); @@ -122,7 +122,7 @@ userDetail.IsDeleted = true; return await _moduleServices.Update(userDetail) ? Success(userDetail?.Id.ObjToString(), "删除成功") : Failed("删除失败"); - //var data = new MessageModel(); + //var data = new ServiceResult(); //if (id > 0) //{ // var userDetail = await _moduleServices.QueryById(id); @@ -144,7 +144,7 @@ /// // POST: api/User [HttpPost] - public async Task> BatchPost([FromBody] List modules) + public async Task> BatchPost([FromBody] List modules) { string ids = string.Empty; int sucCount = 0; diff --git a/Tiobon.Core.Api/Controllers/MonitorController.cs b/Tiobon.Core.Api/Controllers/MonitorController.cs index 391c0ac9..f0811aa5 100644 --- a/Tiobon.Core.Api/Controllers/MonitorController.cs +++ b/Tiobon.Core.Api/Controllers/MonitorController.cs @@ -29,7 +29,7 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public MessageModel Server() + public ServiceResult Server() { return Success(new ServerViewModel() { @@ -50,7 +50,7 @@ namespace Tiobon.Core.Controllers /// // GET: api/Logs [HttpGet] - public MessageModel> Get() + public ServiceResult> Get() { if (AppSettings.app(new string[] { "Middleware", "SignalRSendLog", "Enabled" }).ObjToBool()) { @@ -62,15 +62,15 @@ namespace Tiobon.Core.Controllers [HttpGet] - public MessageModel GetRequestApiinfoByWeek() + public ServiceResult GetRequestApiinfoByWeek() { return Success(LogLock.RequestApiinfoByWeek(), "成功"); } [HttpGet] - public MessageModel GetAccessApiByDate() + public ServiceResult GetAccessApiByDate() { - //return new MessageModel() + //return new ServiceResult() //{ // msg = "获取成功", // success = true, @@ -81,9 +81,9 @@ namespace Tiobon.Core.Controllers } [HttpGet] - public MessageModel GetAccessApiByHour() + public ServiceResult GetAccessApiByHour() { - //return new MessageModel() + //return new ServiceResult() //{ // msg = "获取成功", // success = true, @@ -159,7 +159,7 @@ namespace Tiobon.Core.Controllers } [HttpGet] - public MessageModel GetActiveUsers([FromServices] IWebHostEnvironment environment) + public ServiceResult GetActiveUsers([FromServices] IWebHostEnvironment environment) { var accessLogsToday = GetAccessLogsToday(environment).Where(d => d.BeginTime.ObjToDate() >= DateTime.Today); @@ -180,7 +180,7 @@ namespace Tiobon.Core.Controllers int activeUsersCount = activeUsers.Count; activeUsers = activeUsers.OrderByDescending(d => d.count).Take(10).ToList(); - //return new MessageModel() + //return new ServiceResult() //{ // msg = "获取成功", // success = true, @@ -205,7 +205,7 @@ namespace Tiobon.Core.Controllers } [HttpGet] - public async Task> GetIds4Users() + public async Task> GetIds4Users() { List apiDates = new List(); @@ -233,7 +233,7 @@ namespace Tiobon.Core.Controllers count = 0 }); } - //return new MessageModel() + //return new ServiceResult() //{ // msg = "获取成功", // success = true, diff --git a/Tiobon.Core.Api/Controllers/NacosController.cs b/Tiobon.Core.Api/Controllers/NacosController.cs index a36cc158..80e061cb 100644 --- a/Tiobon.Core.Api/Controllers/NacosController.cs +++ b/Tiobon.Core.Api/Controllers/NacosController.cs @@ -39,11 +39,11 @@ namespace Tiobon.Core.Api.Controllers /// [HttpGet] - public MessageModel CheckSystemStartFinish() + public ServiceResult CheckSystemStartFinish() { //********************* 用当前接口做基本健康检查 确定 基础服务 数据库 缓存都已正常启动***** // 然后再进行服务上线 - var data = new MessageModel(); + var data = new ServiceResult(); // *************** 此处请求一下db 跟redis连接等 项目中简介 保证项目已全部启动 data.success = true; data.msg = "SUCCESS"; @@ -57,9 +57,9 @@ namespace Tiobon.Core.Api.Controllers /// /// [HttpGet] - public async Task> GetStatus() + public async Task> GetStatus() { - var data = new MessageModel(); + var data = new ServiceResult(); var instances = await NacosNamingService.GetAllInstances(JsonConfigSettings.NacosServiceName); if (instances == null || instances.Count == 0) { @@ -99,9 +99,9 @@ namespace Tiobon.Core.Api.Controllers /// [HttpGet] - public async Task> Register() + public async Task> Register() { - var data = new MessageModel(); + var data = new ServiceResult(); var instance = new Nacos.V2.Naming.Dtos.Instance() { ServiceName = JsonConfigSettings.NacosServiceName, @@ -123,9 +123,9 @@ namespace Tiobon.Core.Api.Controllers /// /// [HttpGet] - public async Task> Deregister() + public async Task> Deregister() { - var data = new MessageModel(); + var data = new ServiceResult(); await NacosNamingService.DeregisterInstance(JsonConfigSettings.NacosServiceName, Nacos.V2.Common.Constants.DEFAULT_GROUP, IpHelper.GetCurrentIp(null), JsonConfigSettings.NacosPort); data.success = true; data.msg = "SUCCESS"; diff --git a/Tiobon.Core.Api/Controllers/PayController.cs b/Tiobon.Core.Api/Controllers/PayController.cs index 43de2918..d7264f9b 100644 --- a/Tiobon.Core.Api/Controllers/PayController.cs +++ b/Tiobon.Core.Api/Controllers/PayController.cs @@ -27,7 +27,7 @@ /// [HttpGet] [Route("Pay")] - public async Task> PayGet([FromQuery]PayNeedModel payModel) + public async Task> PayGet([FromQuery]PayNeedModel payModel) { return await _payServices.Pay(payModel); } @@ -38,7 +38,7 @@ /// [HttpPost] [Route("Pay")] - public async Task> PayPost([FromBody]PayNeedModel payModel) + public async Task> PayPost([FromBody]PayNeedModel payModel) { return await _payServices.Pay(payModel); } @@ -49,7 +49,7 @@ /// [HttpGet] [Route("PayCheck")] - public async Task> PayCheckGet([FromQuery]PayNeedModel payModel) + public async Task> PayCheckGet([FromQuery]PayNeedModel payModel) { return await _payServices.PayCheck(payModel, 1); } @@ -60,7 +60,7 @@ /// [HttpPost] [Route("PayCheck")] - public async Task> PayCheckPost([FromBody]PayNeedModel payModel) + public async Task> PayCheckPost([FromBody]PayNeedModel payModel) { return await _payServices.PayCheck(payModel, 1); } @@ -71,7 +71,7 @@ /// [HttpGet] [Route("PayRefund")] - public async Task> PayRefundGet([FromQuery]PayRefundNeedModel payModel) + public async Task> PayRefundGet([FromQuery]PayRefundNeedModel payModel) { return await _payServices.PayRefund(payModel); } @@ -82,7 +82,7 @@ /// [HttpPost] [Route("PayRefund")] - public async Task> PayRefundPost([FromBody]PayRefundNeedModel payModel) + public async Task> PayRefundPost([FromBody]PayRefundNeedModel payModel) { return await _payServices.PayRefund(payModel); } diff --git a/Tiobon.Core.Api/Controllers/PermissionController.cs b/Tiobon.Core.Api/Controllers/PermissionController.cs index 46df30a1..f0ff1610 100644 --- a/Tiobon.Core.Api/Controllers/PermissionController.cs +++ b/Tiobon.Core.Api/Controllers/PermissionController.cs @@ -61,7 +61,7 @@ namespace Tiobon.Core.Controllers /// // GET: api/User [HttpGet] - public async Task>> Get(int page = 1, string key = "", int pageSize = 50) + public async Task>> Get(int page = 1, string key = "", int pageSize = 50) { PageModel permissions = new PageModel(); if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key)) @@ -118,7 +118,7 @@ namespace Tiobon.Core.Controllers #endregion - //return new MessageModel>() + //return new ServiceResult>() //{ // msg = "获取成功", // success = permissions.dataCount >= 0, @@ -137,7 +137,7 @@ namespace Tiobon.Core.Controllers /// [HttpGet] [AllowAnonymous] - public async Task>> GetTreeTable(long f = 0, string key = "") + public async Task>> GetTreeTable(long f = 0, string key = "") { List permissions = new List(); var apiList = await _moduleServices.Query(d => d.IsDeleted == false); @@ -178,7 +178,7 @@ namespace Tiobon.Core.Controllers } - //return new MessageModel>() + //return new ServiceResult>() //{ // msg = "获取成功", // success = true, @@ -194,9 +194,9 @@ namespace Tiobon.Core.Controllers /// // POST: api/User [HttpPost] - public async Task> Post([FromBody] Permission permission) + public async Task> Post([FromBody] Permission permission) { - //var data = new MessageModel(); + //var data = new ServiceResult(); permission.CreateId = _user.ID; permission.CreateBy = _user.Name; @@ -219,7 +219,7 @@ namespace Tiobon.Core.Controllers /// /// [HttpPost] - public async Task> Assign([FromBody] AssignView assignView) + public async Task> Assign([FromBody] AssignView assignView) { if (assignView.rid > 0) { @@ -280,9 +280,9 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public async Task> GetPermissionTree(long pid = 0, bool needbtn = false) + public async Task> GetPermissionTree(long pid = 0, bool needbtn = false) { - //var data = new MessageModel(); + //var data = new ServiceResult(); var permissions = await _permissionServices.Query(d => d.IsDeleted == false); var permissionTrees = (from child in permissions @@ -325,10 +325,10 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public async Task> GetNavigationBar(long uid) + public async Task> GetNavigationBar(long uid) { - var data = new MessageModel(); + var data = new ServiceResult(); long uidInHttpcontext1 = 0; var roleIds = new List(); @@ -429,9 +429,9 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public async Task>> GetNavigationBarPro(long uid) + public async Task>> GetNavigationBarPro(long uid) { - var data = new MessageModel>(); + var data = new ServiceResult>(); long uidInHttpcontext1 = 0; var roleIds = new List(); @@ -518,9 +518,9 @@ namespace Tiobon.Core.Controllers /// [HttpGet] [AllowAnonymous] - public async Task> GetPermissionIdByRoleId(long rid = 0) + public async Task> GetPermissionIdByRoleId(long rid = 0) { - //var data = new MessageModel(); + //var data = new ServiceResult(); var rmps = await _roleModulePermissionServices.Query(d => d.IsDeleted == false && d.RoleId == rid); var permissionTrees = (from child in rmps @@ -567,9 +567,9 @@ namespace Tiobon.Core.Controllers /// // PUT: api/User/5 [HttpPut] - public async Task> Put([FromBody] Permission permission) + public async Task> Put([FromBody] Permission permission) { - var data = new MessageModel(); + var data = new ServiceResult(); if (permission != null && permission.Id > 0) { data.success = await _permissionServices.Update(permission); @@ -591,9 +591,9 @@ namespace Tiobon.Core.Controllers /// // DELETE: api/ApiWithActions/5 [HttpDelete] - public async Task> Delete(long id) + public async Task> Delete(long id) { - var data = new MessageModel(); + var data = new ServiceResult(); if (id > 0) { var userDetail = await _permissionServices.QueryById(id); @@ -616,9 +616,9 @@ namespace Tiobon.Core.Controllers /// // POST: api/User [HttpPost] - public async Task> BatchPost([FromBody] List permissions) + public async Task> BatchPost([FromBody] List permissions) { - var data = new MessageModel(); + var data = new ServiceResult(); string ids = string.Empty; int sucCount = 0; @@ -649,9 +649,9 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public async Task>> MigratePermission(string action = "", string token = "", string gatewayPrefix = "", string swaggerDomain = "", string controllerName = "", long pid = 0, bool isAction = false) + public async Task>> MigratePermission(string action = "", string token = "", string gatewayPrefix = "", string swaggerDomain = "", string controllerName = "", long pid = 0, bool isAction = false) { - var data = new MessageModel>(); + var data = new ServiceResult>(); if (controllerName.IsNullOrEmpty()) { data.msg = "必须填写要迁移的所属接口的控制器名称"; diff --git a/Tiobon.Core.Api/Controllers/RoleController.cs b/Tiobon.Core.Api/Controllers/RoleController.cs index db2c9902..7f273a2a 100644 --- a/Tiobon.Core.Api/Controllers/RoleController.cs +++ b/Tiobon.Core.Api/Controllers/RoleController.cs @@ -26,7 +26,7 @@ /// // GET: api/User [HttpGet] - public async Task>> Get(int page = 1, string key = "") + public async Task>> Get(int page = 1, string key = "") { if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key)) { @@ -37,7 +37,7 @@ var data = await _roleServices.QueryPage(a => a.IsDeleted != true && (a.Name != null && a.Name.Contains(key)), page, intPageSize, " Id desc "); - //return new MessageModel>() + //return new ServiceResult>() //{ // msg = "获取成功", // success = data.dataCount >= 0, @@ -62,7 +62,7 @@ /// // POST: api/User [HttpPost] - public async Task> Post([FromBody] Role role) + public async Task> Post([FromBody] Role role) { role.CreateId = _user.ID; role.CreateBy = _user.Name; @@ -78,14 +78,14 @@ /// // PUT: api/User/5 [HttpPut] - public async Task> Put([FromBody] Role role) + public async Task> Put([FromBody] Role role) { if (role == null || role.Id <= 0) return Failed("缺少参数"); return await _roleServices.Update(role) ? Success(role?.Id.ObjToString(),"更新成功") : Failed("更新失败"); - //var data = new MessageModel(); + //var data = new ServiceResult(); //if (role != null && role.Id > 0) //{ // data.success = await _roleServices.Update(role); @@ -105,10 +105,10 @@ /// // DELETE: api/ApiWithActions/5 [HttpDelete] - public async Task> Delete(long id) + public async Task> Delete(long id) { - var data = new MessageModel(); + var data = new ServiceResult(); //if (id > 0) //{ // var userDetail = await _roleServices.QueryById(id); diff --git a/Tiobon.Core.Api/Controllers/SplitDemoController.cs b/Tiobon.Core.Api/Controllers/SplitDemoController.cs index 81015a94..ed581c3d 100644 --- a/Tiobon.Core.Api/Controllers/SplitDemoController.cs +++ b/Tiobon.Core.Api/Controllers/SplitDemoController.cs @@ -27,7 +27,7 @@ /// [HttpGet] [AllowAnonymous] - public async Task>> Get(DateTime beginTime, DateTime endTime, int page = 1, string key = "", int pageSize = 10) + public async Task>> Get(DateTime beginTime, DateTime endTime, int page = 1, string key = "", int pageSize = 10) { if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key)) { @@ -35,7 +35,7 @@ } Expression> whereExpression = a => (a.Name != null && a.Name.Contains(key)); var data = await splitDemoServices.QueryPageSplit(whereExpression, beginTime, endTime, page, pageSize, " Id desc "); - return MessageModel>.Message(data.dataCount >= 0, "获取成功", data); + return ServiceResult>.Message(data.dataCount >= 0, "获取成功", data); } /// @@ -45,17 +45,17 @@ /// [HttpGet] [AllowAnonymous] - public async Task> GetById(long id) + public async Task> GetById(long id) { - var data = new MessageModel(); + var data = new ServiceResult(); var model = await splitDemoServices.QueryByIdSplit(id); if (model != null) { - return MessageModel.Success("获取成功", model); + return ServiceResult.OprateSuccess("获取成功", model); } else { - return MessageModel.Fail("获取失败"); + return ServiceResult.Fail("获取失败"); } } @@ -66,9 +66,9 @@ /// [HttpPost] [AllowAnonymous] - public async Task> Post([FromBody] SplitDemo splitDemo) + public async Task> Post([FromBody] SplitDemo splitDemo) { - var data = new MessageModel(); + var data = new ServiceResult(); //unitOfWorkManage.BeginTran(); var id = (await splitDemoServices.AddSplit(splitDemo)); data.success = (id == null ? false : true); @@ -105,9 +105,9 @@ /// [HttpPut] [AllowAnonymous] - public async Task> Put([FromBody] SplitDemo splitDemo) + public async Task> Put([FromBody] SplitDemo splitDemo) { - var data = new MessageModel(); + var data = new ServiceResult(); if (splitDemo != null && splitDemo.Id > 0) { unitOfWorkManage.BeginTran(); @@ -146,9 +146,9 @@ /// [HttpDelete] [AllowAnonymous] - public async Task> Delete(long id) + public async Task> Delete(long id) { - var data = new MessageModel(); + var data = new ServiceResult(); var model = await splitDemoServices.QueryByIdSplit(id); if (model != null) diff --git a/Tiobon.Core.Api/Controllers/Systems/CacheManageController.cs b/Tiobon.Core.Api/Controllers/Systems/CacheManageController.cs index a5dd1e26..76ab9848 100644 --- a/Tiobon.Core.Api/Controllers/Systems/CacheManageController.cs +++ b/Tiobon.Core.Api/Controllers/Systems/CacheManageController.cs @@ -1,4 +1,5 @@ using Tiobon.Core.Common.Caches; +using Tiobon.Core.Model; namespace Tiobon.Core.Api.Controllers.Systems; /// @@ -21,7 +22,7 @@ public class CacheManageController : BaseApiController /// /// [HttpGet] - public async Task>> Get() + public async Task>> Get() { return Success(await _caching.GetAllCacheKeysAsync()); } @@ -31,7 +32,7 @@ public class CacheManageController : BaseApiController /// /// [HttpGet("{key}")] - public async Task> Get(string key) + public async Task> Get(string key) { return Success(await _caching.GetStringAsync(key)); } @@ -41,7 +42,7 @@ public class CacheManageController : BaseApiController /// /// [HttpPost] - public async Task Post([FromQuery] string key, [FromQuery] string value, [FromQuery] int? expire) + public async Task Post([FromQuery] string key, [FromQuery] string value, [FromQuery] int? expire) { if (expire.HasValue) await _caching.SetStringAsync(key, value, TimeSpan.FromMilliseconds(expire.Value)); @@ -56,7 +57,7 @@ public class CacheManageController : BaseApiController /// /// [HttpDelete] - public async Task Delete() + public async Task Delete() { await _caching.RemoveAllAsync(); return Success(); @@ -68,7 +69,7 @@ public class CacheManageController : BaseApiController /// [Route("{key}")] [HttpDelete] - public async Task Delete(string key) + public async Task Delete(string key) { await _caching.RemoveAsync(key); return Success(); diff --git a/Tiobon.Core.Api/Controllers/Systems/DataBaseController.cs b/Tiobon.Core.Api/Controllers/Systems/DataBaseController.cs index 71179c53..5323e65e 100644 --- a/Tiobon.Core.Api/Controllers/Systems/DataBaseController.cs +++ b/Tiobon.Core.Api/Controllers/Systems/DataBaseController.cs @@ -4,6 +4,7 @@ using Tiobon.Core.Model.Systems.DataBase; using Tiobon.Core.Model.Tenants; using Mapster; using SqlSugar; +using Tiobon.Core.Model; namespace Tiobon.Core.Api.Controllers.Systems; @@ -51,7 +52,7 @@ public class DataBaseController : BaseApiController /// /// [HttpGet] - public async Task>> GetAllConfig() + public async Task>> GetAllConfig() { //增加多租户的连接 var allConfigs = new List(BaseDBConfig.AllConfigs); @@ -74,7 +75,7 @@ public class DataBaseController : BaseApiController /// 读取类型 /// [HttpGet] - public MessageModel> GetTableInfoList(string configId, + public ServiceResult> GetTableInfoList(string configId, DataBaseReadType readType = DataBaseReadType.Db) { if (configId.IsNullOrEmpty()) @@ -114,7 +115,7 @@ public class DataBaseController : BaseApiController /// 读取类型 /// [HttpGet] - public MessageModel> GetColumnInfosByTableName(string tableName, string configId = null, + public ServiceResult> GetColumnInfosByTableName(string tableName, string configId = null, DataBaseReadType readType = DataBaseReadType.Db) { if (string.IsNullOrWhiteSpace(tableName)) @@ -154,7 +155,7 @@ public class DataBaseController : BaseApiController /// /// [HttpPut] - public MessageModel PutTableEditRemark([FromBody] EditTableInput input) + public ServiceResult PutTableEditRemark([FromBody] EditTableInput input) { var provider = GetTenantDb(input.ConfigId); if (provider.DbMaintenance.IsAnyTableRemark(input.TableName)) @@ -171,7 +172,7 @@ public class DataBaseController : BaseApiController /// /// [HttpPut] - public MessageModel PutColumnEditRemark([FromBody] EditColumnInput input) + public ServiceResult PutColumnEditRemark([FromBody] EditColumnInput input) { var provider = GetTenantDb(input.ConfigId); if (provider.DbMaintenance.IsAnyColumnRemark(input.DbColumnName, input.TableName)) diff --git a/Tiobon.Core.Api/Controllers/Systems/DynamicCodeFirstController.cs b/Tiobon.Core.Api/Controllers/Systems/DynamicCodeFirstController.cs index 55be6cfd..b4e58c77 100644 --- a/Tiobon.Core.Api/Controllers/Systems/DynamicCodeFirstController.cs +++ b/Tiobon.Core.Api/Controllers/Systems/DynamicCodeFirstController.cs @@ -1,6 +1,7 @@ using Tiobon.Core.Common.DB.Extension; using Tiobon.Core.Model.Models.RootTkey; using SqlSugar; +using Tiobon.Core.Model; namespace Tiobon.Core.Api.Controllers.Systems; @@ -55,7 +56,7 @@ public class DynamicCodeFirstController : BaseApiController /// /// [HttpPost] - public MessageModel TestCreateTable() + public ServiceResult TestCreateTable() { var type = GetDynamicType(); _db.CodeFirst.InitTables(type); @@ -67,7 +68,7 @@ public class DynamicCodeFirstController : BaseApiController /// /// [HttpGet] - public MessageModel TestQuery() + public ServiceResult TestQuery() { var type = GetDynamicType(); return Success(_db.QueryableByObject(type).ToList()); @@ -78,7 +79,7 @@ public class DynamicCodeFirstController : BaseApiController /// /// [HttpPost] - public MessageModel TestInsert(string code, string name) + public ServiceResult TestInsert(string code, string name) { var type = GetDynamicType(); var entity = Activator.CreateInstance(type); diff --git a/Tiobon.Core.Api/Controllers/TasksQzController.cs b/Tiobon.Core.Api/Controllers/TasksQzController.cs index d591eac2..0a22dd2c 100644 --- a/Tiobon.Core.Api/Controllers/TasksQzController.cs +++ b/Tiobon.Core.Api/Controllers/TasksQzController.cs @@ -30,7 +30,7 @@ namespace Tiobon.Core.Controllers /// // GET: api/Buttons/5 [HttpGet] - public async Task>> Get(int page = 1, string key = "") + public async Task>> Get(int page = 1, string key = "") { if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key)) { @@ -48,7 +48,7 @@ namespace Tiobon.Core.Controllers item.Triggers = await _schedulerCenter.GetTaskStaus(item); } } - return MessageModel>.Message(data.dataCount >= 0, "获取成功", data); + return ServiceResult>.Message(data.dataCount >= 0, "获取成功", data); } /// @@ -57,9 +57,9 @@ namespace Tiobon.Core.Controllers /// /// [HttpPost] - public async Task> Post([FromBody] TasksQz tasksQz) + public async Task> Post([FromBody] TasksQz tasksQz) { - var data = new MessageModel(); + var data = new ServiceResult(); _unitOfWorkManage.BeginTran(); var id = (await _tasksQzServices.Add(tasksQz)); data.success = id > 0; @@ -112,9 +112,9 @@ namespace Tiobon.Core.Controllers /// /// [HttpPut] - public async Task> Put([FromBody] TasksQz tasksQz) + public async Task> Put([FromBody] TasksQz tasksQz) { - var data = new MessageModel(); + var data = new ServiceResult(); if (tasksQz != null && tasksQz.Id > 0) { _unitOfWorkManage.BeginTran(); @@ -164,9 +164,9 @@ namespace Tiobon.Core.Controllers /// /// [HttpDelete] - public async Task> Delete(long jobId) + public async Task> Delete(long jobId) { - var data = new MessageModel(); + var data = new ServiceResult(); var model = await _tasksQzServices.QueryById(jobId); if (model != null) @@ -213,9 +213,9 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public async Task> StartJob(long jobId) + public async Task> StartJob(long jobId) { - var data = new MessageModel(); + var data = new ServiceResult(); var model = await _tasksQzServices.QueryById(jobId); if (model != null) @@ -270,9 +270,9 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public async Task> StopJob(long jobId) + public async Task> StopJob(long jobId) { - var data = new MessageModel(); + var data = new ServiceResult(); var model = await _tasksQzServices.QueryById(jobId); if (model != null) @@ -310,9 +310,9 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public async Task> PauseJob(long jobId) + public async Task> PauseJob(long jobId) { - var data = new MessageModel(); + var data = new ServiceResult(); var model = await _tasksQzServices.QueryById(jobId); if (model != null) { @@ -364,9 +364,9 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public async Task> ResumeJob(long jobId) + public async Task> ResumeJob(long jobId) { - var data = new MessageModel(); + var data = new ServiceResult(); var model = await _tasksQzServices.QueryById(jobId); if (model != null) @@ -420,9 +420,9 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public async Task> ReCovery(long jobId) + public async Task> ReCovery(long jobId) { - var data = new MessageModel(); + var data = new ServiceResult(); var model = await _tasksQzServices.QueryById(jobId); if (model != null) { @@ -480,7 +480,7 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public MessageModel> GetTaskNameSpace() + public ServiceResult> GetTaskNameSpace() { var baseType = typeof(IJob); var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory; @@ -490,7 +490,7 @@ namespace Tiobon.Core.Controllers .Select(type => type.AsType()) .Where(x => x != baseType && baseType.IsAssignableFrom(x)).ToArray(); var implementTypes = types.Where(x => x.IsClass).Select(item => new QuartzReflectionViewModel { nameSpace = item.Namespace, nameClass = item.Name, remark = "" }).ToList(); - return MessageModel>.Success("获取成功", implementTypes); + return ServiceResult>.OprateSuccess("获取成功", implementTypes); } /// @@ -499,9 +499,9 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public async Task> ExecuteJob(long jobId) + public async Task> ExecuteJob(long jobId) { - var data = new MessageModel(); + var data = new ServiceResult(); var model = await _tasksQzServices.QueryById(jobId); if (model != null) @@ -519,20 +519,20 @@ namespace Tiobon.Core.Controllers /// /// [HttpGet] - public async Task>> GetTaskLogs(long jobId, int page = 1, int pageSize = 10, DateTime? runTimeStart = null, DateTime? runTimeEnd = null) + public async Task>> GetTaskLogs(long jobId, int page = 1, int pageSize = 10, DateTime? runTimeStart = null, DateTime? runTimeEnd = null) { var model = await _tasksLogServices.GetTaskLogs(jobId, page, pageSize, runTimeStart, runTimeEnd); - return MessageModel>.Message(model.dataCount >= 0, "获取成功", model); + return ServiceResult>.Message(model.dataCount >= 0, "获取成功", model); } /// /// 任务概况 /// /// [HttpGet] - public async Task> GetTaskOverview(long jobId, int page = 1, int pageSize = 10, DateTime? runTimeStart = null, DateTime? runTimeEnd = null, string type = "month") + public async Task> GetTaskOverview(long jobId, int page = 1, int pageSize = 10, DateTime? runTimeStart = null, DateTime? runTimeEnd = null, string type = "month") { var model = await _tasksLogServices.GetTaskOverview(jobId, runTimeStart, runTimeEnd, type); - return MessageModel.Message(true, "获取成功", model); + return ServiceResult.Message(true, "获取成功", model); } } diff --git a/Tiobon.Core.Api/Controllers/Tenant/TenantByDbController.cs b/Tiobon.Core.Api/Controllers/Tenant/TenantByDbController.cs index 0b480eca..e5978a98 100644 --- a/Tiobon.Core.Api/Controllers/Tenant/TenantByDbController.cs +++ b/Tiobon.Core.Api/Controllers/Tenant/TenantByDbController.cs @@ -1,4 +1,5 @@ using Tiobon.Core.IServices.BASE; +using Tiobon.Core.Model; namespace Tiobon.Core.Api.Controllers.Tenant; @@ -24,7 +25,7 @@ public class TenantByDbController : BaseApiController /// /// [HttpGet] - public async Task>> GetAll() + public async Task>> GetAll() { var data = await _services.Query(); return Success(data); @@ -35,7 +36,7 @@ public class TenantByDbController : BaseApiController /// /// [HttpPost] - public async Task Post(SubLibraryBusinessTable data) + public async Task Post(SubLibraryBusinessTable data) { await _services.Db.Insertable(data).ExecuteReturnSnowflakeIdAsync(); diff --git a/Tiobon.Core.Api/Controllers/Tenant/TenantByIdController.cs b/Tiobon.Core.Api/Controllers/Tenant/TenantByIdController.cs index b41e3b24..7a6481cc 100644 --- a/Tiobon.Core.Api/Controllers/Tenant/TenantByIdController.cs +++ b/Tiobon.Core.Api/Controllers/Tenant/TenantByIdController.cs @@ -24,7 +24,7 @@ public class TenantByIdController : BaseApiController /// /// [HttpGet] - public async Task>> GetAll() + public async Task>> GetAll() { var data = await _services.Query(); return Success(data); @@ -35,7 +35,7 @@ public class TenantByIdController : BaseApiController /// /// [HttpPost] - public async Task Post([FromBody] BusinessTable data) + public async Task Post([FromBody] BusinessTable data) { await _services.Db.Insertable(data).ExecuteReturnSnowflakeIdAsync(); return Success(); diff --git a/Tiobon.Core.Api/Controllers/Tenant/TenantByTableController.cs b/Tiobon.Core.Api/Controllers/Tenant/TenantByTableController.cs index 1bfffeeb..0bdb5671 100644 --- a/Tiobon.Core.Api/Controllers/Tenant/TenantByTableController.cs +++ b/Tiobon.Core.Api/Controllers/Tenant/TenantByTableController.cs @@ -1,4 +1,5 @@ using Tiobon.Core.IServices.BASE; +using Tiobon.Core.Model; namespace Tiobon.Core.Api.Controllers.Tenant; @@ -24,7 +25,7 @@ public class TenantByTableController : BaseApiController /// /// [HttpGet] - public async Task>> GetAll() + public async Task>> GetAll() { //查询 // var data = await _services.Query(); @@ -42,7 +43,7 @@ public class TenantByTableController : BaseApiController /// /// [HttpPost] - public async Task Post(MultiBusinessTable data) + public async Task Post(MultiBusinessTable data) { await _services.Db.Insertable(data).ExecuteReturnSnowflakeIdAsync(); diff --git a/Tiobon.Core.Api/Controllers/Tenant/TenantManagerController.cs b/Tiobon.Core.Api/Controllers/Tenant/TenantManagerController.cs index a84a8b8d..5e2b2f75 100644 --- a/Tiobon.Core.Api/Controllers/Tenant/TenantManagerController.cs +++ b/Tiobon.Core.Api/Controllers/Tenant/TenantManagerController.cs @@ -1,4 +1,6 @@ -namespace Tiobon.Core.Api.Controllers.Tenant; +using Tiobon.Core.Model; + +namespace Tiobon.Core.Api.Controllers.Tenant; /// /// 租户管理 @@ -21,7 +23,7 @@ public class TenantManagerController : BaseApiController /// /// [HttpGet] - public async Task>> GetAll() + public async Task>> GetAll() { var data = await _services.Query(); return Success(data); @@ -33,7 +35,7 @@ public class TenantManagerController : BaseApiController /// /// [HttpGet("{id}")] - public async Task> GetInfo(long id) + public async Task> GetInfo(long id) { var data = await _services.QueryById(id); return Success(data); @@ -45,7 +47,7 @@ public class TenantManagerController : BaseApiController /// /// [HttpPost] - public async Task Post(SysTenant tenant) + public async Task Post(SysTenant tenant) { await _services.SaveTenant(tenant); return Success(); @@ -57,7 +59,7 @@ public class TenantManagerController : BaseApiController /// /// [HttpPut] - public async Task Put(SysTenant tenant) + public async Task Put(SysTenant tenant) { await _services.SaveTenant(tenant); return Success(); @@ -69,7 +71,7 @@ public class TenantManagerController : BaseApiController /// /// [HttpDelete] - public async Task Delete(long id) + public async Task Delete(long id) { //是否删除租户库? //要根据实际情况而定 diff --git a/Tiobon.Core.Api/Controllers/TopicController.cs b/Tiobon.Core.Api/Controllers/TopicController.cs index 0fd0a9c7..66205cf0 100644 --- a/Tiobon.Core.Api/Controllers/TopicController.cs +++ b/Tiobon.Core.Api/Controllers/TopicController.cs @@ -25,9 +25,9 @@ /// // GET: api/Topic [HttpGet] - public async Task>> Get() + public async Task>> Get() { - var data = new MessageModel> {response = await _topicServices.GetTopics()}; + var data = new ServiceResult> {response = await _topicServices.GetTopics()}; if (data.response != null) { data.success = true; diff --git a/Tiobon.Core.Api/Controllers/TopicDetailController.cs b/Tiobon.Core.Api/Controllers/TopicDetailController.cs index 4fa5ed72..66da3a69 100644 --- a/Tiobon.Core.Api/Controllers/TopicDetailController.cs +++ b/Tiobon.Core.Api/Controllers/TopicDetailController.cs @@ -33,7 +33,7 @@ /// [HttpGet] [AllowAnonymous] - public async Task>> Get(int page = 1, string tname = "", string key = "", int intPageSize = 12) + public async Task>> Get(int page = 1, string tname = "", string key = "", int intPageSize = 12) { long tid = 0; @@ -57,7 +57,7 @@ - return new MessageModel>() + return new ServiceResult>() { msg = "获取成功", success = data.dataCount >= 0, @@ -74,9 +74,9 @@ // GET: api/TopicDetail/5 [HttpGet("{id}")] [AllowAnonymous] - public async Task> Get(long id) + public async Task> Get(long id) { - var data = new MessageModel(); + var data = new ServiceResult(); var response = id > 0 ? await _topicDetailServices.QueryById(id) : new TopicDetail(); data.response = (response?.tdIsDelete).ObjToBool() ? new TopicDetail() : response; if (data.response != null) @@ -96,9 +96,9 @@ // POST: api/TopicDetail [HttpPost] [AllowAnonymous] - public async Task> Post([FromBody] TopicDetail topicDetail) + public async Task> Post([FromBody] TopicDetail topicDetail) { - var data = new MessageModel(); + var data = new ServiceResult(); topicDetail.tdCreatetime = DateTime.Now; topicDetail.tdRead = 0; @@ -124,9 +124,9 @@ /// // PUT: api/TopicDetail/5 [HttpPut] - public async Task> Update([FromBody] TopicDetail topicDetail) + public async Task> Update([FromBody] TopicDetail topicDetail) { - var data = new MessageModel(); + var data = new ServiceResult(); if (topicDetail != null && topicDetail.Id > 0) { data.success = await _topicDetailServices.Update(topicDetail); @@ -147,9 +147,9 @@ /// // DELETE: api/ApiWithActions/5 [HttpDelete] - public async Task> Delete(long id) + public async Task> Delete(long id) { - var data = new MessageModel(); + var data = new ServiceResult(); if (id > 0) { var topicDetail = await _topicDetailServices.QueryById(id); diff --git a/Tiobon.Core.Api/Controllers/TransactionController.cs b/Tiobon.Core.Api/Controllers/TransactionController.cs index 0280e297..10fb859c 100644 --- a/Tiobon.Core.Api/Controllers/TransactionController.cs +++ b/Tiobon.Core.Api/Controllers/TransactionController.cs @@ -19,7 +19,7 @@ // GET: api/Transaction [HttpGet] - public async Task>> Get() + public async Task>> Get() { List returnMsg = new List() { }; try @@ -78,7 +78,7 @@ returnMsg.Add($"third time : the count of guestbooks is :{guestbooks.Count}"); } - return new MessageModel>() + return new ServiceResult>() { success = true, msg = "操作完成", @@ -88,7 +88,7 @@ // GET: api/Transaction/5 [HttpGet("{id}")] - public async Task> Get(long id) + public async Task> Get(long id) { return await _guestbookServices.TestTranInRepository(); } diff --git a/Tiobon.Core.Api/Controllers/UserController.cs b/Tiobon.Core.Api/Controllers/UserController.cs index 8843e282..a1c87fdc 100644 --- a/Tiobon.Core.Api/Controllers/UserController.cs +++ b/Tiobon.Core.Api/Controllers/UserController.cs @@ -54,7 +54,7 @@ namespace Tiobon.Core.Controllers /// // GET: api/User [HttpGet] - public async Task>> Get(int page = 1, string key = "") + public async Task>> Get(int page = 1, string key = "") { if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key)) { @@ -127,9 +127,9 @@ namespace Tiobon.Core.Controllers /// [HttpGet] [AllowAnonymous] - public async Task> GetInfoByToken(string token) + public async Task> GetInfoByToken(string token) { - var data = new MessageModel(); + var data = new ServiceResult(); if (!string.IsNullOrEmpty(token)) { var tokenModel = JwtHelper.SerializeJwt(token); @@ -155,9 +155,9 @@ namespace Tiobon.Core.Controllers /// // POST: api/User [HttpPost] - public async Task> Post([FromBody] SysUserInfoDto sysUserInfo) + public async Task> Post([FromBody] SysUserInfoDto sysUserInfo) { - var data = new MessageModel(); + var data = new ServiceResult(); sysUserInfo.uLoginPWD = MD5Helper.MD5Encrypt32(sysUserInfo.uLoginPWD); sysUserInfo.uRemark = _user.Name; @@ -180,10 +180,10 @@ namespace Tiobon.Core.Controllers /// // PUT: api/User/5 [HttpPut] - public async Task> Put([FromBody] SysUserInfoDto sysUserInfo) + public async Task> Put([FromBody] SysUserInfoDto sysUserInfo) { // 这里使用事务处理 - var data = new MessageModel(); + var data = new ServiceResult(); var oldUser = await _sysUserInfoServices.QueryById(sysUserInfo.uID); if (oldUser is not { Id: > 0 }) @@ -255,9 +255,9 @@ namespace Tiobon.Core.Controllers /// // DELETE: api/ApiWithActions/5 [HttpDelete] - public async Task> Delete(long id) + public async Task> Delete(long id) { - var data = new MessageModel(); + var data = new ServiceResult(); if (id > 0) { var userDetail = await _sysUserInfoServices.QueryById(id); diff --git a/Tiobon.Core.Api/Controllers/UserRoleController.cs b/Tiobon.Core.Api/Controllers/UserRoleController.cs index b48958e7..974d48cd 100644 --- a/Tiobon.Core.Api/Controllers/UserRoleController.cs +++ b/Tiobon.Core.Api/Controllers/UserRoleController.cs @@ -38,10 +38,10 @@ /// /// [HttpGet] - public async Task> AddUser(string loginName, string loginPwd) + public async Task> AddUser(string loginName, string loginPwd) { var userInfo = await _sysUserInfoServices.SaveUserInfo(loginName, loginPwd); - return new MessageModel() + return new ServiceResult() { success = true, msg = "添加成功", @@ -55,9 +55,9 @@ /// /// [HttpGet] - public async Task> AddRole(string roleName) + public async Task> AddRole(string roleName) { - return new MessageModel() + return new ServiceResult() { success = true, msg = "添加成功", @@ -72,9 +72,9 @@ /// /// [HttpGet] - public async Task> AddUserRole(long uid, long rid) + public async Task> AddUserRole(long uid, long rid) { - return new MessageModel() + return new ServiceResult() { success = true, msg = "添加成功", diff --git a/Tiobon.Core.Api/Controllers/ValuesController.cs b/Tiobon.Core.Api/Controllers/ValuesController.cs index 030d2c56..2916cdfc 100644 --- a/Tiobon.Core.Api/Controllers/ValuesController.cs +++ b/Tiobon.Core.Api/Controllers/ValuesController.cs @@ -113,9 +113,9 @@ namespace Tiobon.Core.Controllers } [HttpGet] - public MessageModel> MyClaims() + public ServiceResult> MyClaims() { - return new MessageModel>() + return new ServiceResult>() { success = true, response = (_user.GetClaimsIdentity().ToList()).Select(d => @@ -148,9 +148,9 @@ namespace Tiobon.Core.Controllers // GET api/values [HttpGet] [AllowAnonymous] - public async Task> Get() + public async Task> Get() { - var data = new MessageModel(); + var data = new ServiceResult(); /* * 测试 sql 查询 @@ -209,7 +209,7 @@ namespace Tiobon.Core.Controllers [HttpGet] [AllowAnonymous] - public async Task>> Test_Aop_Cache() + public async Task>> Test_Aop_Cache() { // 测试 AOP 缓存 var TiobonArticles = await _TiobonArticleServices.GetTiobons(); @@ -286,10 +286,10 @@ namespace Tiobon.Core.Controllers /// [HttpGet] [Route("/api/values/UserInfo")] - public MessageModel> GetUserInfo(string ClaimType = "jti") + public ServiceResult> GetUserInfo(string ClaimType = "jti") { var getUserInfoByToken = _user.GetUserInfoFromToken(ClaimType); - return new MessageModel>() + return new ServiceResult>() { success = _user.IsAuthenticated(), msg = _user.IsAuthenticated() ? _user.Name.ObjToString() : "未登录", diff --git a/Tiobon.Core.Api/Controllers/WeChatCompanyController.cs b/Tiobon.Core.Api/Controllers/WeChatCompanyController.cs index e3b79c6b..ac457b29 100644 --- a/Tiobon.Core.Api/Controllers/WeChatCompanyController.cs +++ b/Tiobon.Core.Api/Controllers/WeChatCompanyController.cs @@ -23,10 +23,10 @@ namespace Tiobon.Core.Controllers /// 分页条件 /// [HttpGet] - public async Task>> Get([FromQuery] PaginationModel pagination) + public async Task>> Get([FromQuery] PaginationModel pagination) { var data = await _WeChatCompanyServices.QueryPage(pagination); - return new MessageModel> { success = true, response = data}; + return new ServiceResult> { success = true, response = data}; } /// /// 获取(id) @@ -34,51 +34,51 @@ namespace Tiobon.Core.Controllers /// 主键ID /// [HttpGet("{id}")] - public async Task> Get(string id) + public async Task> Get(string id) { var data = await _WeChatCompanyServices.QueryById(id); - return new MessageModel { success = true, response = data }; + return new ServiceResult { success = true, response = data }; } /// /// 添加 /// /// [HttpPost] - public async Task> Post([FromBody] WeChatCompany obj) + public async Task> Post([FromBody] WeChatCompany obj) { await _WeChatCompanyServices.Add(obj); - return new MessageModel { success = true}; + return new ServiceResult { success = true}; } /// /// 更新 /// /// [HttpPut] - public async Task> Put([FromBody] WeChatCompany obj) + public async Task> Put([FromBody] WeChatCompany obj) { await _WeChatCompanyServices.Update(obj); - return new MessageModel { success = true}; + return new ServiceResult { success = true}; } /// /// 删除 /// /// [HttpDelete] - public async Task> Delete(string id) + public async Task> Delete(string id) { await _WeChatCompanyServices.DeleteById(id); - return new MessageModel { success = true}; + return new ServiceResult { success = true}; } /// /// 批量删除 /// /// [HttpDelete] - public async Task> BatchDelete(string ids) + public async Task> BatchDelete(string ids) { var i = ids.Split(","); await _WeChatCompanyServices.DeleteByIds(i); - return new MessageModel { success = true }; + return new ServiceResult { success = true }; } } diff --git a/Tiobon.Core.Api/Controllers/WeChatConfigController.cs b/Tiobon.Core.Api/Controllers/WeChatConfigController.cs index e7004719..b558564f 100644 --- a/Tiobon.Core.Api/Controllers/WeChatConfigController.cs +++ b/Tiobon.Core.Api/Controllers/WeChatConfigController.cs @@ -23,10 +23,10 @@ namespace Tiobon.Core.Controllers /// 分页条件 /// [HttpGet] - public async Task>> Get([FromQuery] PaginationModel pagination) + public async Task>> Get([FromQuery] PaginationModel pagination) { var data = await _WeChatConfigServices.QueryPage(pagination); - return new MessageModel> { success = true, response = data}; + return new ServiceResult> { success = true, response = data}; } /// /// 获取(id) @@ -34,51 +34,51 @@ namespace Tiobon.Core.Controllers /// 主键ID /// [HttpGet("{id}")] - public async Task> Get(string id) + public async Task> Get(string id) { var data = await _WeChatConfigServices.QueryById(id); - return new MessageModel { success = true, response = data }; + return new ServiceResult { success = true, response = data }; } /// /// 添加 /// /// [HttpPost] - public async Task> Post([FromBody] WeChatConfig obj) + public async Task> Post([FromBody] WeChatConfig obj) { await _WeChatConfigServices.Add(obj); - return new MessageModel { success = true}; + return new ServiceResult { success = true}; } /// /// 更新 /// /// [HttpPut] - public async Task> Put([FromBody] WeChatConfig obj) + public async Task> Put([FromBody] WeChatConfig obj) { await _WeChatConfigServices.Update(obj); - return new MessageModel { success = true}; + return new ServiceResult { success = true}; } /// /// 删除 /// /// [HttpDelete] - public async Task> Delete(string id) + public async Task> Delete(string id) { await _WeChatConfigServices.DeleteById(id); - return new MessageModel { success = true}; + return new ServiceResult { success = true}; } /// /// 批量删除 /// /// [HttpDelete] - public async Task> BatchDelete(string ids) + public async Task> BatchDelete(string ids) { var i = ids.Split(","); await _WeChatConfigServices.DeleteByIds(i); - return new MessageModel { success = true }; + return new ServiceResult { success = true }; } } diff --git a/Tiobon.Core.Api/Controllers/WeChatController.cs b/Tiobon.Core.Api/Controllers/WeChatController.cs index 1e9cedc7..68c93bbf 100644 --- a/Tiobon.Core.Api/Controllers/WeChatController.cs +++ b/Tiobon.Core.Api/Controllers/WeChatController.cs @@ -26,7 +26,7 @@ /// /// [HttpGet] - public async Task> GetToken(string id) + public async Task> GetToken(string id) { return await _weChatConfigServices.GetToken(id); @@ -37,7 +37,7 @@ /// /// [HttpGet] - public async Task> RefreshToken(string id) + public async Task> RefreshToken(string id) { return await _weChatConfigServices.RefreshToken(id); @@ -48,7 +48,7 @@ /// /// [HttpGet] - public async Task> GetTemplate(string id) + public async Task> GetTemplate(string id) { return await _weChatConfigServices.GetTemplate(id); } @@ -58,7 +58,7 @@ /// /// [HttpGet] - public async Task> GetMenu(string id) + public async Task> GetMenu(string id) { return await _weChatConfigServices.GetMenu(id); } @@ -69,7 +69,7 @@ /// /// [HttpPut] - public async Task> UpdateMenu(WeChatApiDto menu) + public async Task> UpdateMenu(WeChatApiDto menu) { return await _weChatConfigServices.UpdateMenu(menu); } @@ -79,7 +79,7 @@ /// /// [HttpGet] - public async Task> GetSubUsers(string id) + public async Task> GetSubUsers(string id) { return await _weChatConfigServices.GetSubUsers(id); } @@ -107,7 +107,7 @@ /// [HttpGet] [AllowAnonymous] - public async Task> GetSubUser(string id,string openid) + public async Task> GetSubUser(string id,string openid) { return await _weChatConfigServices.GetSubUser(id,openid); } @@ -118,7 +118,7 @@ /// [HttpGet] [AllowAnonymous] - public async Task> GetQRBind([FromQuery]WeChatUserInfo info) + public async Task> GetQRBind([FromQuery]WeChatUserInfo info) { return await _weChatConfigServices.GetQRBind(info); } @@ -129,7 +129,7 @@ /// [HttpPost] [AllowAnonymous] - public async Task> PushCardMsg(WeChatCardMsgDataDto msg) + public async Task> PushCardMsg(WeChatCardMsgDataDto msg) { string pushUserIP = $"{Request.HttpContext.Connection.RemoteIpAddress}:{Request.HttpContext.Connection.RemotePort}"; return await _weChatConfigServices.PushCardMsg(msg, pushUserIP); @@ -141,7 +141,7 @@ /// [HttpGet] [AllowAnonymous] - public async Task> PushCardMsgGet([FromQuery] WeChatCardMsgDataDto msg) + public async Task> PushCardMsgGet([FromQuery] WeChatCardMsgDataDto msg) { string pushUserIP = $"{Request.HttpContext.Connection.RemoteIpAddress}:{Request.HttpContext.Connection.RemotePort}"; return await _weChatConfigServices.PushCardMsg(msg, pushUserIP); @@ -153,7 +153,7 @@ /// [HttpPost] [AllowAnonymous] - public async Task> PushTxtMsg([FromBody] WeChatPushTestDto msg) + public async Task> PushTxtMsg([FromBody] WeChatPushTestDto msg) { return await _weChatConfigServices.PushTxtMsg(msg); } @@ -164,7 +164,7 @@ /// [HttpGet] [AllowAnonymous] - public async Task> GetBindUserInfo([FromQuery]WeChatUserInfo info) + public async Task> GetBindUserInfo([FromQuery]WeChatUserInfo info) { return await _weChatConfigServices.GetBindUserInfo(info); } @@ -175,7 +175,7 @@ /// [HttpGet] [AllowAnonymous] - public async Task> UnBind([FromQuery]WeChatUserInfo info) + public async Task> UnBind([FromQuery]WeChatUserInfo info) { return await _weChatConfigServices.UnBind(info); } diff --git a/Tiobon.Core.Api/Controllers/WeChatPushLogController.cs b/Tiobon.Core.Api/Controllers/WeChatPushLogController.cs index 644dbc55..ae1cac58 100644 --- a/Tiobon.Core.Api/Controllers/WeChatPushLogController.cs +++ b/Tiobon.Core.Api/Controllers/WeChatPushLogController.cs @@ -23,10 +23,10 @@ namespace Tiobon.Core.Controllers /// 分页条件 /// [HttpGet] - public async Task>> Get([FromQuery] PaginationModel pagination) + public async Task>> Get([FromQuery] PaginationModel pagination) { var data = await _WeChatPushLogServices.QueryPage(pagination); - return new MessageModel> { success = true, response = data}; + return new ServiceResult> { success = true, response = data}; } /// /// 获取(id) @@ -34,51 +34,51 @@ namespace Tiobon.Core.Controllers /// 主键ID /// [HttpGet("{id}")] - public async Task> Get(string id) + public async Task> Get(string id) { var data = await _WeChatPushLogServices.QueryById(id); - return new MessageModel { success = true, response = data }; + return new ServiceResult { success = true, response = data }; } /// /// 添加 /// /// [HttpPost] - public async Task> Post([FromBody] WeChatPushLog obj) + public async Task> Post([FromBody] WeChatPushLog obj) { await _WeChatPushLogServices.Add(obj); - return new MessageModel { success = true}; + return new ServiceResult { success = true}; } /// /// 更新 /// /// [HttpPut] - public async Task> Put([FromBody] WeChatPushLog obj) + public async Task> Put([FromBody] WeChatPushLog obj) { await _WeChatPushLogServices.Update(obj); - return new MessageModel { success = true}; + return new ServiceResult { success = true}; } /// /// 删除 /// /// [HttpDelete] - public async Task> Delete(string id) + public async Task> Delete(string id) { await _WeChatPushLogServices.DeleteById(id); - return new MessageModel { success = true}; + return new ServiceResult { success = true}; } /// /// 批量删除 /// /// [HttpDelete] - public async Task> BatchDelete(string ids) + public async Task> BatchDelete(string ids) { var i = ids.Split(","); await _WeChatPushLogServices.DeleteByIds(i); - return new MessageModel { success = true }; + return new ServiceResult { success = true }; } } diff --git a/Tiobon.Core.Api/Controllers/WeChatSubController.cs b/Tiobon.Core.Api/Controllers/WeChatSubController.cs index 6e034f6d..e334e12e 100644 --- a/Tiobon.Core.Api/Controllers/WeChatSubController.cs +++ b/Tiobon.Core.Api/Controllers/WeChatSubController.cs @@ -23,10 +23,10 @@ namespace Tiobon.Core.Controllers /// 分页条件 /// [HttpGet] - public async Task>> Get([FromQuery] PaginationModel pagination) + public async Task>> Get([FromQuery] PaginationModel pagination) { var data = await _WeChatSubServices.QueryPage(pagination); - return new MessageModel> { success = true, response = data}; + return new ServiceResult> { success = true, response = data}; } /// /// 获取(id) @@ -34,51 +34,51 @@ namespace Tiobon.Core.Controllers /// 主键ID /// [HttpGet("{id}")] - public async Task> Get(string id) + public async Task> Get(string id) { var data = await _WeChatSubServices.QueryById(id); - return new MessageModel { success = true, response = data }; + return new ServiceResult { success = true, response = data }; } /// /// 添加 /// /// [HttpPost] - public async Task> Post([FromBody] WeChatSub obj) + public async Task> Post([FromBody] WeChatSub obj) { await _WeChatSubServices.Add(obj); - return new MessageModel { success = true}; + return new ServiceResult { success = true}; } /// /// 更新 /// /// [HttpPut] - public async Task> Put([FromBody] WeChatSub obj) + public async Task> Put([FromBody] WeChatSub obj) { await _WeChatSubServices.Update(obj); - return new MessageModel { success = true}; + return new ServiceResult { success = true}; } /// /// 删除 /// /// [HttpDelete] - public async Task> Delete(string id) + public async Task> Delete(string id) { await _WeChatSubServices.DeleteById(id); - return new MessageModel { success = true}; + return new ServiceResult { success = true}; } /// /// 批量删除 /// /// [HttpDelete] - public async Task> BatchDelete(string ids) + public async Task> BatchDelete(string ids) { var i = ids.Split(","); await _WeChatSubServices.DeleteByIds(i); - return new MessageModel { success = true }; + return new ServiceResult { success = true }; } } diff --git a/Tiobon.Core.Api/Filter/GlobalActionFilter.cs b/Tiobon.Core.Api/Filter/GlobalActionFilter.cs index e3371cda..0657dc99 100644 --- a/Tiobon.Core.Api/Filter/GlobalActionFilter.cs +++ b/Tiobon.Core.Api/Filter/GlobalActionFilter.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc.Filters; using System.Security.Claims; +using Tiobon.Core.Model; namespace Tiobon.Core.Api.Filter { @@ -32,7 +33,7 @@ namespace Tiobon.Core.Api.Filter } } } - filterContext.Result = new JsonResult(MessageModel.Fail($"参数验证失败:{msg}")); + filterContext.Result = new JsonResult(ServiceResult.OprateFailed($"参数验证失败:{msg}")); return; } @@ -232,18 +233,18 @@ namespace Tiobon.Core.Api.Filter } } error += $":{sb.ToString()}"; - filterContext.Result = new JsonResult(MessageModel.Fail($"请求的数据类型不正确:{error}")); + filterContext.Result = new JsonResult(ServiceResult.OprateFailed($"请求的数据类型不正确:{error}")); } else { - filterContext.Result = new JsonResult(MessageModel.Fail(error)); + filterContext.Result = new JsonResult(ServiceResult.OprateFailed(error)); } //LoggerHelper.SendLog(error); return; } if (filterContext.Result is ObjectResult objectResult && objectResult.Value == null) { - filterContext.Result = new JsonResult(MessageModel.Success("查询成功")); + filterContext.Result = new JsonResult(ServiceResult.OprateSuccess("查询成功")); } base.OnResultExecuting(filterContext); diff --git a/Tiobon.Core.Api/Filter/GlobalExceptionFilter.cs b/Tiobon.Core.Api/Filter/GlobalExceptionFilter.cs index 777e39d6..6efe348d 100644 --- a/Tiobon.Core.Api/Filter/GlobalExceptionFilter.cs +++ b/Tiobon.Core.Api/Filter/GlobalExceptionFilter.cs @@ -23,7 +23,7 @@ namespace Tiobon.Core.Filter public void OnException(ExceptionContext context) { - var json = new MessageModel(); + var json = new ServiceResult(); json.msg = context.Exception.Message;//错误信息 json.status = 500;//500异常 @@ -38,7 +38,7 @@ namespace Tiobon.Core.Filter json.msgDev = context.Exception.StackTrace;//堆栈信息 } var res = new ContentResult(); - res.Content = JsonHelper.GetJSON>(json); + res.Content = JsonHelper.GetJSON>(json); context.Result = res; diff --git a/Tiobon.Core.Api/Tiobon.Core.Model.xml b/Tiobon.Core.Api/Tiobon.Core.Model.xml index bc78024d..f1dda205 100644 --- a/Tiobon.Core.Api/Tiobon.Core.Model.xml +++ b/Tiobon.Core.Api/Tiobon.Core.Model.xml @@ -1956,110 +1956,6 @@ 年龄 - - - 通用返回信息类 - - - - - 状态码 - - - - - 操作是否成功 - - - - - 返回信息 - - - - - 开发者信息 - - - - - 返回数据集合 - - - - - 返回成功 - - 消息 - - - - - 返回成功 - - 消息 - 数据 - - - - - 返回失败 - - 消息 - - - - - 返回失败 - - 消息 - 数据 - - - - - 返回消息 - - 失败/成功 - 消息 - 数据 - - - - - 状态码 - - - - - 操作是否成功 - - - - - 返回信息 - - - - - 返回数据集合 - - - - - 操作成功 - - - - - - - 操作失败 - - - - - 部门表 @@ -2227,6 +2123,115 @@ 找不到指定资源 + + + 服务层响应实体(泛型) + + + + + 状态码 + + + + + 操作是否成功 + + + + + 返回信息 + + + + + 开发者信息 + + + + + 返回数据集合 + + + + + 返回成功 + + 消息 + + + + + 返回成功 + + 消息 + 数据 + + + + + 返回失败 + + 消息 + + + + + 返回失败 + + 消息 + 数据 + + + + + 返回消息 + + 失败/成功 + 消息 + 数据 + + + + + 服务层响应实体 + + + + + 状态码 + + + + + 操作是否成功 + + + + + 返回信息 + + + + + 返回数据集合 + + + + + 操作成功 + + + + + + + 操作失败 + + + + + 数据库读取类型 diff --git a/Tiobon.Core.Common/Attribute/FromFilterAttribute.cs b/Tiobon.Core.Common/Attribute/FromFilterAttribute.cs index 2c11b6fd..3b78cefa 100644 --- a/Tiobon.Core.Common/Attribute/FromFilterAttribute.cs +++ b/Tiobon.Core.Common/Attribute/FromFilterAttribute.cs @@ -68,38 +68,38 @@ namespace Tiobon.Core.Common /// private static void SetPredicateValues(QueryFilter queryFilter, ModelBindingContext bindingContext) { - if (queryFilter?.PredicateValues == null || queryFilter.PredicateValues.Length == 0) - { - return; - } + //if (queryFilter?.PredicateValues == null || queryFilter.PredicateValues.Length == 0) + //{ + // return; + //} - for (int i = 0; i < queryFilter.PredicateValues.Length; i++) - { - if (queryFilter.PredicateValues[i] is JObject jObj) - { - var prop = jObj.Properties()?.FirstOrDefault(); - if (prop == null) - continue; - var type = StringConvertToType(prop.Name); - if (type == null) - continue; - try - { - var v = JsonConvert.DeserializeObject(prop.Value?.ToString(), type); - if (v != null) - { - queryFilter.PredicateValues[i] = v; - } - } - catch (Exception) - { - throw; - //LoggerHelper.SendLogError($"QueryFilter.PredicateValues[{i}] [{queryFilter.PredicateValues[i]}] 反序列化失败\r\n" + - // $"请求地址: {bindingContext.HttpContext.Request.GetEncodedUrl()}\r\n" + - // $"错误信息: {ex}"); - } - } - } + //for (int i = 0; i < queryFilter.PredicateValues.Length; i++) + //{ + // if (queryFilter.PredicateValues[i] is JObject jObj) + // { + // var prop = jObj.Properties()?.FirstOrDefault(); + // if (prop == null) + // continue; + // var type = StringConvertToType(prop.Name); + // if (type == null) + // continue; + // try + // { + // var v = JsonConvert.DeserializeObject(prop.Value?.ToString(), type); + // if (v != null) + // { + // queryFilter.PredicateValues[i] = v; + // } + // } + // catch (Exception) + // { + // throw; + // //LoggerHelper.SendLogError($"QueryFilter.PredicateValues[{i}] [{queryFilter.PredicateValues[i]}] 反序列化失败\r\n" + + // // $"请求地址: {bindingContext.HttpContext.Request.GetEncodedUrl()}\r\n" + + // // $"错误信息: {ex}"); + // } + // } + //} } diff --git a/Tiobon.Core.Common/HttpContextUser/AspNetUser.cs b/Tiobon.Core.Common/HttpContextUser/AspNetUser.cs index 969baea4..922c4de1 100644 --- a/Tiobon.Core.Common/HttpContextUser/AspNetUser.cs +++ b/Tiobon.Core.Common/HttpContextUser/AspNetUser.cs @@ -98,7 +98,7 @@ namespace Tiobon.Core.Common.HttpContextUser return new List() { }; } - public MessageModel MessageModel { get; set; } + public ServiceResult MessageModel { get; set; } public IEnumerable GetClaimsIdentity() { diff --git a/Tiobon.Core.Common/HttpContextUser/IUser.cs b/Tiobon.Core.Common/HttpContextUser/IUser.cs index 0b6f269c..da394f80 100644 --- a/Tiobon.Core.Common/HttpContextUser/IUser.cs +++ b/Tiobon.Core.Common/HttpContextUser/IUser.cs @@ -16,6 +16,6 @@ namespace Tiobon.Core.Common.HttpContextUser string GetToken(); List GetUserInfoFromToken(string ClaimType); - MessageModel MessageModel { get; set; } + ServiceResult MessageModel { get; set; } } } \ No newline at end of file diff --git a/Tiobon.Core.Common/Seed/FrameSeed.cs b/Tiobon.Core.Common/Seed/FrameSeed.cs index 9e9983fd..3795a87e 100644 --- a/Tiobon.Core.Common/Seed/FrameSeed.cs +++ b/Tiobon.Core.Common/Seed/FrameSeed.cs @@ -163,10 +163,10 @@ namespace Tiobon.Core.Common.Seed /// 条件 /// [HttpGet] - public async Task>> Get([FromFilter] QueryFilter filter) + public async Task>> Get([FromFilter] QueryFilter filter) { var response = await _{ClassName}Services.QueryFilterPage(filter); - return new MessageModel>() { msg = ""获取成功"", success = true, response = response }; + return new ServiceResult>() { msg = ""获取成功"", success = true, response = response }; } /// @@ -175,13 +175,13 @@ namespace Tiobon.Core.Common.Seed /// 主键ID /// [HttpGet(""{Id}"")] - public async Task> Get(string Id) + public async Task> Get(string Id) { var entity = await _{ClassName}Services.QueryById(Id); if (entity == null) - return MessageModel<{ClassName}Dto>.Fail(""获取失败""); + return ServiceResult<{ClassName}Dto>.Fail(""获取失败""); else - return new MessageModel<{ClassName}Dto>() { msg = ""获取成功"", success = true, response = entity }; + return new ServiceResult<{ClassName}Dto>() { msg = ""获取成功"", success = true, response = entity }; } #endregion @@ -192,9 +192,9 @@ namespace Tiobon.Core.Common.Seed /// /// [HttpPost] - public async Task> Post([FromBody] Insert{ClassName}Input insertModel) + public async Task> Post([FromBody] Insert{ClassName}Input insertModel) { - var data = MessageModel.Success(""获取成功"", null); + var data = ServiceResult.Success(""获取成功"", null); var id = await _{ClassName}Services.Add(insertModel); data.success = id > 0; @@ -213,7 +213,7 @@ namespace Tiobon.Core.Common.Seed /// /// [HttpPut(""{Id}"")] - public async Task Put(long Id, [FromBody] Edit{ClassName}Input editModel) + public async Task Put(long Id, [FromBody] Edit{ClassName}Input editModel) { var data = MessageModel.Success(""更新成功""); data.success = await _{ClassName}Services.Update(Id, editModel); @@ -231,7 +231,7 @@ namespace Tiobon.Core.Common.Seed /// /// [HttpDelete(""{Id}"")] - public async Task Delete(long Id) + public async Task Delete(long Id) { var data = MessageModel.Success(""删除成功""); var entity = await _{ClassName}Services.QueryById(Id); diff --git a/Tiobon.Core.Gateway/Controllers/UserController.cs b/Tiobon.Core.Gateway/Controllers/UserController.cs index ae07e4c2..e16f5bf5 100644 --- a/Tiobon.Core.Gateway/Controllers/UserController.cs +++ b/Tiobon.Core.Gateway/Controllers/UserController.cs @@ -19,9 +19,9 @@ namespace Tiobon.Core.Gateway.Controllers } [HttpGet] - public MessageModel> MyClaims() + public ServiceResult> MyClaims() { - return new MessageModel>() + return new ServiceResult>() { success = true, response = (_user.GetClaimsIdentity().ToList()).Select(d => diff --git a/Tiobon.Core.IServices/IGuestbookServices.cs b/Tiobon.Core.IServices/IGuestbookServices.cs index 30d7ccc5..6952b143 100644 --- a/Tiobon.Core.IServices/IGuestbookServices.cs +++ b/Tiobon.Core.IServices/IGuestbookServices.cs @@ -7,7 +7,7 @@ namespace Tiobon.Core.IServices { public partial interface IGuestbookServices : IBaseServices { - Task> TestTranInRepository(); + Task> TestTranInRepository(); Task TestTranInRepositoryAOP(); Task TestTranPropagation(); diff --git a/Tiobon.Core.IServices/IPayServices.cs b/Tiobon.Core.IServices/IPayServices.cs index 8ada1925..d40a67cf 100644 --- a/Tiobon.Core.IServices/IPayServices.cs +++ b/Tiobon.Core.IServices/IPayServices.cs @@ -15,20 +15,20 @@ namespace Tiobon.Core.IServices /// 被扫支付 /// /// - Task> Pay(PayNeedModel payModel); + Task> Pay(PayNeedModel payModel); /// /// 退款 /// /// /// - Task> PayRefund(PayRefundNeedModel payModel); + Task> PayRefund(PayRefundNeedModel payModel); /// /// 轮询查询 /// /// /// 轮询次数 /// - Task> PayCheck(PayNeedModel payModel,int times); + Task> PayCheck(PayNeedModel payModel,int times); /// /// 验证签名 /// diff --git a/Tiobon.Core.IServices/IWeChatConfigServices.cs b/Tiobon.Core.IServices/IWeChatConfigServices.cs index 9a46736a..9184a434 100644 --- a/Tiobon.Core.IServices/IWeChatConfigServices.cs +++ b/Tiobon.Core.IServices/IWeChatConfigServices.cs @@ -16,37 +16,37 @@ namespace Tiobon.Core.IServices /// /// /// - Task> GetToken(string id); + Task> GetToken(string id); /// /// 刷新微信token /// /// /// - Task> RefreshToken(string id); + Task> RefreshToken(string id); /// /// 获取模板信息 /// /// /// - Task> GetTemplate(string id); + Task> GetTemplate(string id); /// /// 获取菜单 /// /// /// - Task> GetMenu(string id); + Task> GetMenu(string id); /// /// 获取订阅用户 /// /// /// /// - Task> GetSubUser(string id,string openid); + Task> GetSubUser(string id,string openid); /// /// 获取订阅用户列表 /// /// - Task> GetSubUsers(string id); + Task> GetSubUsers(string id); /// /// 处理微信事件 /// @@ -66,37 +66,37 @@ namespace Tiobon.Core.IServices /// /// /// - Task> GetQRBind(WeChatUserInfo info); + Task> GetQRBind(WeChatUserInfo info); /// /// 推送卡片消息(绑定用户) /// /// /// /// - Task> PushCardMsg(WeChatCardMsgDataDto msg,string ip); + Task> PushCardMsg(WeChatCardMsgDataDto msg,string ip); /// /// 推送文本消息(绑定或订阅) /// /// /// - Task> PushTxtMsg(WeChatPushTestDto msg); + Task> PushTxtMsg(WeChatPushTestDto msg); /// /// 更新菜单 /// /// /// - Task> UpdateMenu(WeChatApiDto menu); + Task> UpdateMenu(WeChatApiDto menu); /// /// 通过绑定用户获取微信用户信息 /// /// /// - Task> GetBindUserInfo(WeChatUserInfo info); + Task> GetBindUserInfo(WeChatUserInfo info); /// /// 解除绑定用户 /// /// /// - Task> UnBind(WeChatUserInfo info); + Task> UnBind(WeChatUserInfo info); } } \ No newline at end of file diff --git a/Tiobon.Core.Model/ApiResponse.cs b/Tiobon.Core.Model/ApiResponse.cs index 378b84bc..1e4c604a 100644 --- a/Tiobon.Core.Model/ApiResponse.cs +++ b/Tiobon.Core.Model/ApiResponse.cs @@ -4,7 +4,7 @@ { public int Status { get; set; } = 200; public string Value { get; set; } = ""; - public MessageModel MessageModel = new MessageModel() { }; + public ServiceResult MessageModel = new ServiceResult() { }; public ApiResponse(StatusCode apiCode, string msg = null) { @@ -36,7 +36,7 @@ break; } - MessageModel = new MessageModel() + MessageModel = new ServiceResult() { status = Status, msg = Value, diff --git a/Tiobon.Core.Model/MessageModel.cs b/Tiobon.Core.Model/MessageModel.cs deleted file mode 100644 index 183d785e..00000000 --- a/Tiobon.Core.Model/MessageModel.cs +++ /dev/null @@ -1,130 +0,0 @@ -namespace Tiobon.Core.Model -{ - /// - /// 通用返回信息类 - /// - public class MessageModel - { - /// - /// 状态码 - /// - public int status { get; set; } = 200; - /// - /// 操作是否成功 - /// - public bool success { get; set; } = false; - /// - /// 返回信息 - /// - public string msg { get; set; } = ""; - /// - /// 开发者信息 - /// - public string msgDev { get; set; } - /// - /// 返回数据集合 - /// - public T response { get; set; } - - /// - /// 返回成功 - /// - /// 消息 - /// - public static MessageModel Success(string msg) - { - return Message(true, msg, default); - } - /// - /// 返回成功 - /// - /// 消息 - /// 数据 - /// - public static MessageModel Success(string msg, T response) - { - return Message(true, msg, response); - } - /// - /// 返回失败 - /// - /// 消息 - /// - public static MessageModel Fail(string msg) - { - return Message(false, msg, default); - } - /// - /// 返回失败 - /// - /// 消息 - /// 数据 - /// - public static MessageModel Fail(string msg, T response) - { - return Message(false, msg, response); - } - /// - /// 返回消息 - /// - /// 失败/成功 - /// 消息 - /// 数据 - /// - public static MessageModel Message(bool success, string msg, T response) - { - return new MessageModel() { msg = msg, response = response, success = success }; - } - } - - public class MessageModel - { - /// - /// 状态码 - /// - public int status { get; set; } = 200; - /// - /// 操作是否成功 - /// - public bool success { get; set; } = false; - /// - /// 返回信息 - /// - public string msg { get; set; } = ""; - /// - /// 返回数据集合 - /// - public object response { get; set; } - - /// - /// 操作成功 - /// - /// - /// - public static MessageModel Success(string msg = "操作成功") - { - return new MessageModel - { - msg = msg, - success = true, - response = null - }; - } - - /// - /// 操作失败 - /// - /// - /// - /// - public static MessageModel Fail(string msg = "操作失败", int status = 500) - { - return new MessageModel - { - msg = msg, - status = status, - response = null - }; - } - } -} diff --git a/Tiobon.Core.Model/ServiceResult.cs b/Tiobon.Core.Model/ServiceResult.cs new file mode 100644 index 00000000..cf126dbb --- /dev/null +++ b/Tiobon.Core.Model/ServiceResult.cs @@ -0,0 +1,133 @@ +namespace Tiobon.Core.Model; + +/// +/// 服务层响应实体(泛型) +/// +public class ServiceResult +{ + /// + /// 状态码 + /// + public int status { get; set; } = 200; + /// + /// 操作是否成功 + /// + public bool success { get; set; } = false; + /// + /// 返回信息 + /// + public string msg { get; set; } = ""; + /// + /// 开发者信息 + /// + public string msgDev { get; set; } + /// + /// 返回数据集合 + /// + public T response { get; set; } + + /// + /// 返回成功 + /// + /// 消息 + /// + public static ServiceResult OprateSuccess(string msg) + { + return Message(true, msg, default); + } + + /// + /// 返回成功 + /// + /// 消息 + /// 数据 + /// + public static ServiceResult OprateSuccess(string msg, T response) + { + return Message(true, msg, response); + } + /// + /// 返回失败 + /// + /// 消息 + /// + public static ServiceResult Fail(string msg) + { + return Message(false, msg, default); + } + /// + /// 返回失败 + /// + /// 消息 + /// 数据 + /// + public static ServiceResult Fail(string msg, T response) + { + return Message(false, msg, response); + } + /// + /// 返回消息 + /// + /// 失败/成功 + /// 消息 + /// 数据 + /// + public static ServiceResult Message(bool success, string msg, T response) + { + return new ServiceResult() { msg = msg, response = response, success = success }; + } +} + +/// +/// 服务层响应实体 +/// +public class ServiceResult +{ + /// + /// 状态码 + /// + public int status { get; set; } = 200; + /// + /// 操作是否成功 + /// + public bool success { get; set; } = false; + /// + /// 返回信息 + /// + public string msg { get; set; } = ""; + /// + /// 返回数据集合 + /// + public object response { get; set; } + + /// + /// 操作成功 + /// + /// + /// + public static ServiceResult OprateSuccess(string msg = "操作成功") + { + return new ServiceResult + { + msg = msg, + success = true, + response = null + }; + } + + /// + /// 操作失败 + /// + /// + /// + /// + public static ServiceResult OprateFailed(string msg = "操作失败", int status = 500) + { + return new ServiceResult + { + msg = msg, + status = status, + response = null + }; + } +} \ No newline at end of file diff --git a/Tiobon.Core.Services/GuestbookServices.cs b/Tiobon.Core.Services/GuestbookServices.cs index f176c572..3744a6c4 100644 --- a/Tiobon.Core.Services/GuestbookServices.cs +++ b/Tiobon.Core.Services/GuestbookServices.cs @@ -25,7 +25,7 @@ namespace Tiobon.Core.Services _passwordLibServices = passwordLibServices; } - public async Task> TestTranInRepository() + public async Task> TestTranInRepository() { try { @@ -72,7 +72,7 @@ namespace Tiobon.Core.Services uow.Commit(); } - return new MessageModel() + return new ServiceResult() { success = true, msg = "操作完成" @@ -86,7 +86,7 @@ namespace Tiobon.Core.Services var guestbooks = await BaseDal.Query(); Console.WriteLine($"third time : the count of guestbooks is :{guestbooks.Count}"); - return new MessageModel() + return new ServiceResult() { success = false, msg = "操作异常" diff --git a/Tiobon.Core.Services/PayServices.cs b/Tiobon.Core.Services/PayServices.cs index d7636cd7..d7fd1756 100644 --- a/Tiobon.Core.Services/PayServices.cs +++ b/Tiobon.Core.Services/PayServices.cs @@ -28,10 +28,10 @@ namespace Tiobon.Core.Services _httpContextAccessor = httpContextAccessor; } - public async Task> Pay(PayNeedModel payModel) + public async Task> Pay(PayNeedModel payModel) { _logger.LogInformation("支付开始"); - MessageModel messageModel = new MessageModel(); + ServiceResult messageModel = new ServiceResult(); messageModel.response = new PayReturnResultModel(); string url = string.Empty; string param = string.Empty; @@ -173,15 +173,15 @@ namespace Tiobon.Core.Services } finally { - _logger.LogInformation($"返回数据->{JsonHelper.GetJSON>(messageModel)}"); + _logger.LogInformation($"返回数据->{JsonHelper.GetJSON>(messageModel)}"); _logger.LogInformation("支付结束"); } return messageModel; } - public async Task> PayRefund(PayRefundNeedModel payModel) + public async Task> PayRefund(PayRefundNeedModel payModel) { _logger.LogInformation("退款开始"); - MessageModel messageModel = new MessageModel(); + ServiceResult messageModel = new ServiceResult(); messageModel.response = new PayRefundReturnResultModel(); try { @@ -253,18 +253,18 @@ namespace Tiobon.Core.Services } finally { - _logger.LogInformation($"返回数据->{JsonHelper.GetJSON>(messageModel)}"); + _logger.LogInformation($"返回数据->{JsonHelper.GetJSON>(messageModel)}"); _logger.LogInformation("退款结束"); } return messageModel; } - public async Task> PayCheck(PayNeedModel payModel, int times) + public async Task> PayCheck(PayNeedModel payModel, int times) { _logger.LogInformation("轮询开始"); - MessageModel messageModel = new MessageModel(); + ServiceResult messageModel = new ServiceResult(); messageModel.response = new PayReturnResultModel(); string url = string.Empty; string param = string.Empty; @@ -400,7 +400,7 @@ namespace Tiobon.Core.Services } finally { - _logger.LogInformation($"返回数据->{JsonHelper.GetJSON>(messageModel)}"); + _logger.LogInformation($"返回数据->{JsonHelper.GetJSON>(messageModel)}"); _logger.LogInformation("轮序结束"); } return messageModel; diff --git a/Tiobon.Core.Services/WeChatConfigServices.cs b/Tiobon.Core.Services/WeChatConfigServices.cs index a12100cb..e664a051 100644 --- a/Tiobon.Core.Services/WeChatConfigServices.cs +++ b/Tiobon.Core.Services/WeChatConfigServices.cs @@ -26,16 +26,16 @@ namespace Tiobon.Core.Services this._unitOfWorkManage = unitOfWorkManage; this._logger = logger; } - public async Task> GetToken(string publicAccount) + public async Task> GetToken(string publicAccount) { var config = await this.QueryById(publicAccount); - if (config == null) MessageModel.Success($"公众号{publicAccount}未维护至系统");//还没过期,直接返回 + if (config == null) ServiceResult.OprateSuccess($"公众号{publicAccount}未维护至系统");//还没过期,直接返回 if (config.tokenExpiration > DateTime.Now) { //再次判断token在微信服务器是否正确 var wechatIP = await WeChatHelper.GetWechatIP(config.token); if (wechatIP.errcode == 0) - MessageModel.Success("", new WeChatApiDto { access_token = config.token });//还没过期,直接返回 + ServiceResult.OprateSuccess("", new WeChatApiDto { access_token = config.token });//还没过期,直接返回 } //过期了,重新获取 var data = await WeChatHelper.GetToken(config.appid, config.appsecret); @@ -44,17 +44,17 @@ namespace Tiobon.Core.Services config.token = data.access_token; config.tokenExpiration = DateTime.Now.AddSeconds(data.expires_in); await this.Update(config); - return MessageModel.Success("",data); + return ServiceResult.OprateSuccess("",data); } else { - return MessageModel.Fail($"\r\n获取Token失败\r\n错误代码:{data.errcode}\r\n错误信息:{data.errmsg}"); + return ServiceResult.Fail($"\r\n获取Token失败\r\n错误代码:{data.errcode}\r\n错误信息:{data.errmsg}"); } } - public async Task> RefreshToken(string publicAccount) + public async Task> RefreshToken(string publicAccount) { var config = await this.QueryById(publicAccount); - if (config == null) MessageModel.Success($"公众号{publicAccount}未维护至系统");//还没过期,直接返回 + if (config == null) ServiceResult.OprateSuccess($"公众号{publicAccount}未维护至系统");//还没过期,直接返回 //过期了,重新获取 var data = await WeChatHelper.GetToken(config.appid, config.appsecret); if (data.errcode.Equals(0)) @@ -62,25 +62,25 @@ namespace Tiobon.Core.Services config.token = data.access_token; config.tokenExpiration = DateTime.Now.AddSeconds(data.expires_in); await this.Update(config); - return MessageModel.Success("", data); + return ServiceResult.OprateSuccess("", data); } else { - return MessageModel.Fail($"\r\n获取Token失败\r\n错误代码:{data.errcode}\r\n错误信息:{data.errmsg}"); + return ServiceResult.Fail($"\r\n获取Token失败\r\n错误代码:{data.errcode}\r\n错误信息:{data.errmsg}"); } } - public async Task> GetTemplate(string id) + public async Task> GetTemplate(string id) { var res = await GetToken(id); if (!res.success) return res; var data = await WeChatHelper.GetTemplate(res.response.access_token); if (data.errcode.Equals(0)) { - return MessageModel.Success("", data); + return ServiceResult.OprateSuccess("", data); } else { - return MessageModel.Success($"\r\n获取模板失败\r\n错误代码:{data.errcode}\r\n错误信息:{data.errmsg}", data); + return ServiceResult.OprateSuccess($"\r\n获取模板失败\r\n错误代码:{data.errcode}\r\n错误信息:{data.errmsg}", data); } } /// @@ -88,21 +88,21 @@ namespace Tiobon.Core.Services /// /// /// - public async Task> GetMenu(string id) + public async Task> GetMenu(string id) { var res = await GetToken(id); if (!res.success) return res; var data = await WeChatHelper.GetMenu(res.response.access_token); if (data.errcode.Equals(0)) { - return MessageModel.Success("", data); + return ServiceResult.OprateSuccess("", data); } else { - return MessageModel.Success($"\r\n获取菜单失败\r\n错误代码:{data.errcode}\r\n错误信息:{data.errmsg}", data); + return ServiceResult.OprateSuccess($"\r\n获取菜单失败\r\n错误代码:{data.errcode}\r\n错误信息:{data.errmsg}", data); } } - public async Task> GetSubUsers(string id) + public async Task> GetSubUsers(string id) { var res = await GetToken(id); if (!res.success) return res; @@ -114,25 +114,25 @@ namespace Tiobon.Core.Services { data.users.Add(await WeChatHelper.GetUserInfo(res.response.access_token, openid)); } - return MessageModel.Success("", data); + return ServiceResult.OprateSuccess("", data); } else { - return MessageModel.Success($"\r\n获取订阅用户失败\r\n错误代码:{data.errcode}\r\n错误信息:{data.errmsg}", data); + return ServiceResult.OprateSuccess($"\r\n获取订阅用户失败\r\n错误代码:{data.errcode}\r\n错误信息:{data.errmsg}", data); } } - public async Task> GetSubUser(string id,string openid) + public async Task> GetSubUser(string id,string openid) { var res = await GetToken(id); if (!res.success) return res; var data = await WeChatHelper.GetUserInfo(res.response.access_token,openid); if (data.errcode.Equals(0)) { - return MessageModel.Success("", data); + return ServiceResult.OprateSuccess("", data); } else { - return MessageModel.Success($"\r\n获取订阅用户失败\r\n错误代码:{data.errcode}\r\n错误信息:{data.errmsg}", data); + return ServiceResult.OprateSuccess($"\r\n获取订阅用户失败\r\n错误代码:{data.errcode}\r\n错误信息:{data.errmsg}", data); } } public async Task Valid(WeChatValidDto validDto,string body) @@ -203,10 +203,10 @@ namespace Tiobon.Core.Services } return objReturn; } - public async Task> GetQRBind(WeChatUserInfo info) + public async Task> GetQRBind(WeChatUserInfo info) { var res = await GetToken(info?.id); - if (!res.success) return MessageModel.Fail(res.msg); + if (!res.success) return ServiceResult.Fail(res.msg); var push = new WeChatQRDto { expire_seconds = 604800, @@ -236,16 +236,16 @@ namespace Tiobon.Core.Services data.id = info.userID; await this.BaseDal.Db.Insertable(weChatQR).ExecuteCommandAsync(); reData.usersData= data; - return MessageModel.Success("获取二维码成功", reData); + return ServiceResult.OprateSuccess("获取二维码成功", reData); } - public async Task> PushCardMsg(WeChatCardMsgDataDto msg,string ip) + public async Task> PushCardMsg(WeChatCardMsgDataDto msg,string ip) { var bindUser = await BaseDal.Db.Queryable().Where(t => t.SubFromPublicAccount == msg.info.id && t.CompanyID == msg.info.companyCode && t.IsUnBind == false && msg.info.userID.Contains(t.SubJobID)).SingleAsync(); if (bindUser == null) - return MessageModel.Fail("用户不存在或者已经解绑!"); + return ServiceResult.Fail("用户不存在或者已经解绑!"); var res = await GetToken(msg?.info?.id); if(!res.success) - return MessageModel.Fail(res.msg); + return ServiceResult.Fail(res.msg); WeChatResponseUserInfo reData = new WeChatResponseUserInfo(); reData.companyCode = msg.info.companyCode; reData.id = msg.info.id; @@ -321,22 +321,22 @@ namespace Tiobon.Core.Services } if (reData.usersData.errcode.Equals(0)) { - return MessageModel.Success("卡片消息推送成功", reData); + return ServiceResult.OprateSuccess("卡片消息推送成功", reData); } else { - return MessageModel.Success("卡片消息推送失败", reData); + return ServiceResult.OprateSuccess("卡片消息推送失败", reData); } } catch (Exception ex) { - return MessageModel.Success($"卡片消息推送错误=>{ex.Message}", reData); + return ServiceResult.OprateSuccess($"卡片消息推送错误=>{ex.Message}", reData); } } - public async Task> PushTxtMsg(WeChatPushTestDto msg) { + public async Task> PushTxtMsg(WeChatPushTestDto msg) { var res = await GetToken(msg.selectWeChat); if (!res.success) return res; var token = res.response.access_token; @@ -346,7 +346,7 @@ namespace Tiobon.Core.Services } else { - MessageModel messageModel = new MessageModel(); + ServiceResult messageModel = new ServiceResult(); messageModel.success = true; //绑定用户 if (msg.selectOperate.Equals("one")) @@ -383,7 +383,7 @@ namespace Tiobon.Core.Services } } - public async Task> PushText(string token,WeChatPushTestDto msg) { + public async Task> PushText(string token,WeChatPushTestDto msg) { object data = null; ; WeChatApiDto pushres = null; ; @@ -502,15 +502,15 @@ namespace Tiobon.Core.Services } if (pushres.errcode.Equals(0)) { - return MessageModel.Success("推送成功", pushres); + return ServiceResult.OprateSuccess("推送成功", pushres); } else { - return MessageModel.Fail($"\r\n推送失败\r\n错误代码:{pushres.errcode}\r\n错误信息:{pushres.errmsg}", pushres); + return ServiceResult.Fail($"\r\n推送失败\r\n错误代码:{pushres.errcode}\r\n错误信息:{pushres.errmsg}", pushres); } } - public async Task> UpdateMenu(WeChatApiDto menu) + public async Task> UpdateMenu(WeChatApiDto menu) { WeChatHelper.ConverMenuButtonForEvent(menu); var res = await GetToken(menu.id); @@ -519,19 +519,19 @@ namespace Tiobon.Core.Services if (data.errcode.Equals(0)) { - return MessageModel.Success("更新成功", data); + return ServiceResult.OprateSuccess("更新成功", data); } else { - return MessageModel.Success("更新失败", data); + return ServiceResult.OprateSuccess("更新失败", data); } } - public async Task> GetBindUserInfo(WeChatUserInfo info) + public async Task> GetBindUserInfo(WeChatUserInfo info) { var bindUser = await BaseDal.Db.Queryable().Where(t => t.SubFromPublicAccount == info.id && t.CompanyID == info.companyCode && info.userID.Equals(t.SubJobID) && t.IsUnBind == false ).FirstAsync(); - if (bindUser == null) return MessageModel.Fail("用户不存在或者已经解绑!"); + if (bindUser == null) return ServiceResult.Fail("用户不存在或者已经解绑!"); var res = await GetToken(info.id); - if(!res.success) return MessageModel.Fail(res.msg); + if(!res.success) return ServiceResult.Fail(res.msg); var token = res.response.access_token; WeChatResponseUserInfo reData = new WeChatResponseUserInfo(); reData.companyCode = info.companyCode; @@ -540,24 +540,24 @@ namespace Tiobon.Core.Services reData.usersData = data; if (data.errcode.Equals(0)) { - return MessageModel.Success("用户信息获取成功", reData); + return ServiceResult.OprateSuccess("用户信息获取成功", reData); } else { - return MessageModel.Fail("用户信息获取失败", reData); + return ServiceResult.Fail("用户信息获取失败", reData); } } - public async Task> UnBind(WeChatUserInfo info) + public async Task> UnBind(WeChatUserInfo info) { var bindUser = await BaseDal.Db.Queryable().Where(t => t.SubFromPublicAccount == info.id && t.CompanyID == info.companyCode && info.userID.Equals(t.SubJobID) && t.IsUnBind == false ).FirstAsync(); - if (bindUser == null) return MessageModel.Fail("用户不存在或者已经解绑!"); + if (bindUser == null) return ServiceResult.Fail("用户不存在或者已经解绑!"); WeChatResponseUserInfo reData = new WeChatResponseUserInfo(); reData.companyCode = info.companyCode; reData.id = info.id; bindUser.IsUnBind = true; bindUser.SubUserRefTime = DateTime.Now; await BaseDal.Db.Updateable(bindUser).UpdateColumns(t=> new{ t.IsUnBind,t.SubUserRefTime}).ExecuteCommandAsync(); - return MessageModel.Success("用户解绑成功", reData); + return ServiceResult.OprateSuccess("用户解绑成功", reData); } public async Task HandleWeChat(WeChatXMLDto weChat) diff --git a/Tiobon.Core.Tasks/QuartzNet/ISchedulerCenter.cs b/Tiobon.Core.Tasks/QuartzNet/ISchedulerCenter.cs index a558f84c..163482bb 100644 --- a/Tiobon.Core.Tasks/QuartzNet/ISchedulerCenter.cs +++ b/Tiobon.Core.Tasks/QuartzNet/ISchedulerCenter.cs @@ -16,24 +16,24 @@ namespace Tiobon.Core.Tasks /// 开启任务调度 /// /// - Task> StartScheduleAsync(); + Task> StartScheduleAsync(); /// /// 停止任务调度 /// /// - Task> StopScheduleAsync(); + Task> StopScheduleAsync(); /// /// /// /// /// - Task> AddScheduleJobAsync(TasksQz sysSchedule); + Task> AddScheduleJobAsync(TasksQz sysSchedule); /// /// 停止一个任务 /// /// /// - Task> StopScheduleJobAsync(TasksQz sysSchedule); + Task> StopScheduleJobAsync(TasksQz sysSchedule); /// /// 检测任务是否存在 /// @@ -45,13 +45,13 @@ namespace Tiobon.Core.Tasks /// /// /// - Task> PauseJob(TasksQz sysSchedule); + Task> PauseJob(TasksQz sysSchedule); /// /// 恢复一个任务 /// /// /// - Task> ResumeJob(TasksQz sysSchedule); + Task> ResumeJob(TasksQz sysSchedule); /// /// 获取任务触发器状态 @@ -71,7 +71,7 @@ namespace Tiobon.Core.Tasks /// /// /// - Task> ExecuteJobAsync(TasksQz tasksQz); + Task> ExecuteJobAsync(TasksQz tasksQz); } diff --git a/Tiobon.Core.Tasks/QuartzNet/SchedulerCenterServer.cs b/Tiobon.Core.Tasks/QuartzNet/SchedulerCenterServer.cs index 473d117b..dba470db 100644 --- a/Tiobon.Core.Tasks/QuartzNet/SchedulerCenterServer.cs +++ b/Tiobon.Core.Tasks/QuartzNet/SchedulerCenterServer.cs @@ -45,9 +45,9 @@ namespace Tiobon.Core.Tasks /// 开启任务调度 /// /// - public async Task> StartScheduleAsync() + public async Task> StartScheduleAsync() { - var result = new MessageModel(); + var result = new ServiceResult(); try { this._scheduler.Result.JobFactory = this._iocjobFactory; @@ -77,9 +77,9 @@ namespace Tiobon.Core.Tasks /// 停止任务调度 /// /// - public async Task> StopScheduleAsync() + public async Task> StopScheduleAsync() { - var result = new MessageModel(); + var result = new ServiceResult(); try { if (!this._scheduler.Result.IsShutdown) @@ -110,9 +110,9 @@ namespace Tiobon.Core.Tasks /// /// /// - public async Task> AddScheduleJobAsync(TasksQz tasksQz) + public async Task> AddScheduleJobAsync(TasksQz tasksQz) { - var result = new MessageModel(); + var result = new ServiceResult(); if (tasksQz != null) { @@ -224,9 +224,9 @@ namespace Tiobon.Core.Tasks /// 暂停一个指定的计划任务 /// /// - public async Task> StopScheduleJobAsync(TasksQz sysSchedule) + public async Task> StopScheduleJobAsync(TasksQz sysSchedule) { - var result = new MessageModel(); + var result = new ServiceResult(); try { JobKey jobKey = new JobKey(sysSchedule.Id.ToString(), sysSchedule.JobGroup); @@ -255,9 +255,9 @@ namespace Tiobon.Core.Tasks /// /// /// - public async Task> ResumeJob(TasksQz sysSchedule) + public async Task> ResumeJob(TasksQz sysSchedule) { - var result = new MessageModel(); + var result = new ServiceResult(); try { JobKey jobKey = new JobKey(sysSchedule.Id.ToString(), sysSchedule.JobGroup); @@ -282,9 +282,9 @@ namespace Tiobon.Core.Tasks /// /// /// - public async Task> PauseJob(TasksQz sysSchedule) + public async Task> PauseJob(TasksQz sysSchedule) { - var result = new MessageModel(); + var result = new ServiceResult(); try { JobKey jobKey = new JobKey(sysSchedule.Id.ToString(), sysSchedule.JobGroup); @@ -455,9 +455,9 @@ namespace Tiobon.Core.Tasks /// /// /// - public async Task> ExecuteJobAsync(TasksQz tasksQz) + public async Task> ExecuteJobAsync(TasksQz tasksQz) { - var result = new MessageModel(); + var result = new ServiceResult(); try { JobKey jobKey = new JobKey(tasksQz.Id.ToString(), tasksQz.JobGroup); diff --git a/Tiobon.Core.Tests/Controller_Test/BlogController_Should.cs b/Tiobon.Core.Tests/Controller_Test/BlogController_Should.cs index df5a5ce4..070ad4fd 100644 --- a/Tiobon.Core.Tests/Controller_Test/BlogController_Should.cs +++ b/Tiobon.Core.Tests/Controller_Test/BlogController_Should.cs @@ -44,7 +44,7 @@ namespace Tiobon.Core.Tests [Fact] public async void Get_Tiobon_Page_Test() { - MessageModel> Tiobons = await TiobonController.Get(1, 1, "技术博文", ""); + ServiceResult> Tiobons = await TiobonController.Get(1, 1, "技术博文", ""); Assert.NotNull(Tiobons); Assert.NotNull(Tiobons.response); Assert.True(Tiobons.response.dataCount >= 0); @@ -53,7 +53,7 @@ namespace Tiobon.Core.Tests [Fact] public async void Get_Tiobon_Test() { - MessageModel TiobonVo = await TiobonController.Get(1.ObjToLong()); + ServiceResult TiobonVo = await TiobonController.Get(1.ObjToLong()); Assert.NotNull(TiobonVo); } @@ -61,7 +61,7 @@ namespace Tiobon.Core.Tests [Fact] public async void Get_Tiobon_For_Nuxt_Test() { - MessageModel TiobonVo = await TiobonController.DetailNuxtNoPer(1); + ServiceResult TiobonVo = await TiobonController.DetailNuxtNoPer(1); Assert.NotNull(TiobonVo); } @@ -77,7 +77,7 @@ namespace Tiobon.Core.Tests [Fact] public async void Get_Tiobon_By_Type_For_MVP_Test() { - MessageModel> Tiobons = await TiobonController.GetTiobonsByTypesForMVP("技术博文"); + ServiceResult> Tiobons = await TiobonController.GetTiobonsByTypesForMVP("技术博文"); Assert.NotNull(Tiobons); Assert.True(Tiobons.success); @@ -88,7 +88,7 @@ namespace Tiobon.Core.Tests [Fact] public async void Get_Tiobon_By_Id_For_MVP_Test() { - MessageModel Tiobon = await TiobonController.GetTiobonByIdForMVP(1); + ServiceResult Tiobon = await TiobonController.GetTiobonByIdForMVP(1); Assert.NotNull(Tiobon); Assert.True(Tiobon.success);