From 6c86c22efda8a03c5c46595034885450d4128dee Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Mon, 15 Apr 2024 15:34:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=A1=A8=E5=A2=9E=E5=88=A0?= =?UTF-8?q?=E6=9F=A5=E6=94=B9=EF=BC=8CDBFirst=E7=94=9F=E6=88=90=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Ghra_GradeController.cs | 34 ++++++++++--------- Tiobon.Core.Api/Filter/GlobalActionFilter.cs | 8 ++--- Tiobon.Core.Api/Tiobon.Core.Model.xml | 4 +-- Tiobon.Core.Api/Tiobon.Core.xml | 2 +- Tiobon.Core.Common/Seed/FrameSeed.cs | 34 ++++++++++--------- Tiobon.Core.IServices/BASE/IBaseServices1.cs | 7 ++++ .../Base/Ghra/Ghra_Grade.Dto.Base.cs | 2 +- .../Edit/Ghra/Ghra_Grade.Dto.EditInput.cs | 2 +- .../Insert/Ghra/Ghra_Grade.Dto.InsertInput.cs | 2 +- Tiobon.Core.Model/MessageModel.cs | 4 +-- Tiobon.Core.Model/Models/Ghra/Ghra_Grade.cs | 2 +- .../View/Ghra/Ghra_Grade.Dto.View.cs | 2 +- Tiobon.Core.Repository/BASE/BaseRepository.cs | 5 +++ Tiobon.Core.Services/BASE/BaseServices1.cs | 11 ++++++ 14 files changed, 73 insertions(+), 46 deletions(-) diff --git a/Tiobon.Core.Api/Controllers/Ghra_GradeController.cs b/Tiobon.Core.Api/Controllers/Ghra_GradeController.cs index 6ea01696..cf2c14ff 100644 --- a/Tiobon.Core.Api/Controllers/Ghra_GradeController.cs +++ b/Tiobon.Core.Api/Controllers/Ghra_GradeController.cs @@ -43,8 +43,11 @@ [HttpGet("{Id}")] public async Task> Get(string Id) { - var response = await _ghra_GradeServices.QueryById(Id); - return new MessageModel() { msg = "获取成功", success = true, response = response }; + var entity = await _ghra_GradeServices.QueryById(Id); + if (entity == null) + return MessageModel.Fail("获取失败"); + else + return new MessageModel() { msg = "获取成功", success = true, response = entity }; } #endregion @@ -76,9 +79,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("更新成功", null); + var data = MessageModel.Success("更新成功"); data.success = await _ghra_GradeServices.Update(Id, editModel); if (!data.success) data.msg = "更新失败"; @@ -91,21 +94,20 @@ /// /// Ghra_Grade -- 删除数据 /// - /// + /// /// - [HttpDelete] - public async Task> Delete(int id) + [HttpDelete("{Id}")] + public async Task Delete(int Id) { - var data = new MessageModel(); - var model = await _ghra_GradeServices.QueryById(id); - model.IsEnable = 1; - // data.success = await _departmentServices.Update(model); - if (data.success) - { - data.msg = "删除成功"; - data.response = model?.Id.ObjToString(); - } + var data = MessageModel.Success("删除成功"); + var entity = await _ghra_GradeServices.QueryById(Id); + if (entity == null) + return MessageModel.Fail("删除失败"); + entity.IsEnable = 0; + data.success = await _ghra_GradeServices.Update(entity); + if (!data.success) + data.msg = "删除失败"; return data; } #endregion diff --git a/Tiobon.Core.Api/Filter/GlobalActionFilter.cs b/Tiobon.Core.Api/Filter/GlobalActionFilter.cs index e94c207f..e3371cda 100644 --- a/Tiobon.Core.Api/Filter/GlobalActionFilter.cs +++ b/Tiobon.Core.Api/Filter/GlobalActionFilter.cs @@ -32,7 +32,7 @@ namespace Tiobon.Core.Api.Filter } } } - filterContext.Result = new JsonResult(MessageModel.OprateFailed($"参数验证失败:{msg}")); + filterContext.Result = new JsonResult(MessageModel.Fail($"参数验证失败:{msg}")); return; } @@ -232,18 +232,18 @@ namespace Tiobon.Core.Api.Filter } } error += $":{sb.ToString()}"; - filterContext.Result = new JsonResult(MessageModel.OprateFailed($"请求的数据类型不正确:{error}")); + filterContext.Result = new JsonResult(MessageModel.Fail($"请求的数据类型不正确:{error}")); } else { - filterContext.Result = new JsonResult(MessageModel.OprateFailed(error)); + filterContext.Result = new JsonResult(MessageModel.Fail(error)); } //LoggerHelper.SendLog(error); return; } if (filterContext.Result is ObjectResult objectResult && objectResult.Value == null) { - filterContext.Result = new JsonResult(MessageModel.OprateSuccess("查询成功")); + filterContext.Result = new JsonResult(MessageModel.Success("查询成功")); } base.OnResultExecuting(filterContext); diff --git a/Tiobon.Core.Api/Tiobon.Core.Model.xml b/Tiobon.Core.Api/Tiobon.Core.Model.xml index 6a62b8fe..e2741ac9 100644 --- a/Tiobon.Core.Api/Tiobon.Core.Model.xml +++ b/Tiobon.Core.Api/Tiobon.Core.Model.xml @@ -2045,14 +2045,14 @@ 返回数据集合 - + 操作成功 - + 操作失败 diff --git a/Tiobon.Core.Api/Tiobon.Core.xml b/Tiobon.Core.Api/Tiobon.Core.xml index ab2c830d..18356978 100644 --- a/Tiobon.Core.Api/Tiobon.Core.xml +++ b/Tiobon.Core.Api/Tiobon.Core.xml @@ -1259,7 +1259,7 @@ Ghra_Grade -- 删除数据 - + diff --git a/Tiobon.Core.Common/Seed/FrameSeed.cs b/Tiobon.Core.Common/Seed/FrameSeed.cs index d63d21c2..aa1f4db9 100644 --- a/Tiobon.Core.Common/Seed/FrameSeed.cs +++ b/Tiobon.Core.Common/Seed/FrameSeed.cs @@ -177,8 +177,11 @@ namespace Tiobon.Core.Common.Seed [HttpGet(""{Id}"")] public async Task> Get(string Id) { - var response = await _{ClassName}Services.QueryById(Id); - return new MessageModel<{ClassName}Dto>() { msg = ""获取成功"", success = true, response = response }; + var entity = await _{ClassName}Services.QueryById(Id); + if (entity == null) + return MessageModel<{ClassName}Dto>.Fail(""获取失败""); + else + return new MessageModel<{ClassName}Dto>() { msg = ""获取成功"", success = true, response = entity }; } #endregion @@ -212,10 +215,10 @@ namespace Tiobon.Core.Common.Seed [HttpPut(""{Id}"")] public async Task> Put(long Id, [FromBody] Edit{ClassName}Input editModel) { - var data = MessageModel.Success(""更新成功"", null); + var data = MessageModel.Success(""更新成功""); data.success = await _{ClassName}Services.Update(Id, editModel); if (!data.success) - data.msg = ""更新失败"";; + data.msg = ""更新失败""; return data; } @@ -225,21 +228,20 @@ namespace Tiobon.Core.Common.Seed /// /// {ClassName} -- 删除数据 /// - /// + /// /// - [HttpDelete] - public async Task> Delete(int id) + [HttpDelete(""{Id}"")] + public async Task> Delete(int Id) { - var data = new MessageModel(); - var model = await _{ClassName}Services.QueryById(id); - model.IsEnable = 1; - // data.success = await _departmentServices.Update(model); - if (data.success) - { - data.msg = ""删除成功""; - data.response = model?.Id.ObjToString(); - } + var data = MessageModel.Success(""删除成功"") + var entity = await _{ClassName}Services.QueryById(Id); + if (entity == null) + return MessageModel.Fail(""删除失败""); + entity.IsEnable = 0; + data.success = await _{ClassName}Services.Update(entity); + if (!data.success) + data.msg = ""删除失败""; return data; } #endregion diff --git a/Tiobon.Core.IServices/BASE/IBaseServices1.cs b/Tiobon.Core.IServices/BASE/IBaseServices1.cs index 31af230a..087d39eb 100644 --- a/Tiobon.Core.IServices/BASE/IBaseServices1.cs +++ b/Tiobon.Core.IServices/BASE/IBaseServices1.cs @@ -17,6 +17,13 @@ namespace Tiobon.Core.IServices.BASE { ISqlSugarClient Db { get; } + Task AnyAsync(object objId); + + /// + /// 根据ID查询实体数据是否存在 + /// + /// + /// Task QueryById(object objId); Task QueryById(object objId, bool blnUseCache = false); Task> QueryByIDs(object[] lstIds); diff --git a/Tiobon.Core.Model/Base/Ghra/Ghra_Grade.Dto.Base.cs b/Tiobon.Core.Model/Base/Ghra/Ghra_Grade.Dto.Base.cs index 98e5cc33..2bb44c74 100644 --- a/Tiobon.Core.Model/Base/Ghra/Ghra_Grade.Dto.Base.cs +++ b/Tiobon.Core.Model/Base/Ghra/Ghra_Grade.Dto.Base.cs @@ -6,7 +6,7 @@ * * Ver 变更日期 负责人 变更内容 * ─────────────────────────────────── -*V0.01 2024/4/15 14:57:43 SimonHsiao 初版 +*V0.01 2024/4/15 15:25:43 SimonHsiao 初版 * * Copyright(c) 2024 Tiobon Corporation. All Rights Reserved. *┌──────────────────────────────────┐ diff --git a/Tiobon.Core.Model/Edit/Ghra/Ghra_Grade.Dto.EditInput.cs b/Tiobon.Core.Model/Edit/Ghra/Ghra_Grade.Dto.EditInput.cs index 884245aa..82f38a7f 100644 --- a/Tiobon.Core.Model/Edit/Ghra/Ghra_Grade.Dto.EditInput.cs +++ b/Tiobon.Core.Model/Edit/Ghra/Ghra_Grade.Dto.EditInput.cs @@ -6,7 +6,7 @@ * * Ver 变更日期 负责人 变更内容 * ─────────────────────────────────── -*V0.01 2024/4/15 14:57:43 SimonHsiao 初版 +*V0.01 2024/4/15 15:25:43 SimonHsiao 初版 * * Copyright(c) 2024 Tiobon Corporation. All Rights Reserved. *┌──────────────────────────────────┐ diff --git a/Tiobon.Core.Model/Insert/Ghra/Ghra_Grade.Dto.InsertInput.cs b/Tiobon.Core.Model/Insert/Ghra/Ghra_Grade.Dto.InsertInput.cs index ac154986..cf3d6bcd 100644 --- a/Tiobon.Core.Model/Insert/Ghra/Ghra_Grade.Dto.InsertInput.cs +++ b/Tiobon.Core.Model/Insert/Ghra/Ghra_Grade.Dto.InsertInput.cs @@ -6,7 +6,7 @@ * * Ver 变更日期 负责人 变更内容 * ─────────────────────────────────── -*V0.01 2024/4/15 14:57:43 SimonHsiao 初版 +*V0.01 2024/4/15 15:25:43 SimonHsiao 初版 * * Copyright(c) 2024 Tiobon Corporation. All Rights Reserved. *┌──────────────────────────────────┐ diff --git a/Tiobon.Core.Model/MessageModel.cs b/Tiobon.Core.Model/MessageModel.cs index 64e1da07..183d785e 100644 --- a/Tiobon.Core.Model/MessageModel.cs +++ b/Tiobon.Core.Model/MessageModel.cs @@ -101,7 +101,7 @@ /// /// /// - public static MessageModel OprateSuccess(string msg = "操作成功") + public static MessageModel Success(string msg = "操作成功") { return new MessageModel { @@ -117,7 +117,7 @@ /// /// /// - public static MessageModel OprateFailed(string msg = "操作失败", int status = 500) + public static MessageModel Fail(string msg = "操作失败", int status = 500) { return new MessageModel { diff --git a/Tiobon.Core.Model/Models/Ghra/Ghra_Grade.cs b/Tiobon.Core.Model/Models/Ghra/Ghra_Grade.cs index c11ba894..49d226bf 100644 --- a/Tiobon.Core.Model/Models/Ghra/Ghra_Grade.cs +++ b/Tiobon.Core.Model/Models/Ghra/Ghra_Grade.cs @@ -6,7 +6,7 @@ * * Ver 变更日期 负责人 变更内容 * ─────────────────────────────────── -*V0.01 2024/4/15 14:57:43 SimonHsiao 初版 +*V0.01 2024/4/15 15:25:43 SimonHsiao 初版 * * Copyright(c) 2024 Tiobon Corporation. All Rights Reserved. *┌──────────────────────────────────┐ diff --git a/Tiobon.Core.Model/View/Ghra/Ghra_Grade.Dto.View.cs b/Tiobon.Core.Model/View/Ghra/Ghra_Grade.Dto.View.cs index 57333a42..35ee4ab9 100644 --- a/Tiobon.Core.Model/View/Ghra/Ghra_Grade.Dto.View.cs +++ b/Tiobon.Core.Model/View/Ghra/Ghra_Grade.Dto.View.cs @@ -6,7 +6,7 @@ * * Ver 变更日期 负责人 变更内容 * ─────────────────────────────────── -*V0.01 2024/4/15 14:57:43 SimonHsiao 初版 +*V0.01 2024/4/15 15:25:43 SimonHsiao 初版 * * Copyright(c) 2024 Tiobon Corporation. All Rights Reserved. *┌──────────────────────────────────┐ diff --git a/Tiobon.Core.Repository/BASE/BaseRepository.cs b/Tiobon.Core.Repository/BASE/BaseRepository.cs index 5d5c7b62..8690b17f 100644 --- a/Tiobon.Core.Repository/BASE/BaseRepository.cs +++ b/Tiobon.Core.Repository/BASE/BaseRepository.cs @@ -74,6 +74,11 @@ namespace Tiobon.Core.Repository.Base //return await Task.Run(() => _db.Queryable().InSingle(objId)); return await _db.Queryable().In(objId).SingleAsync(); } + /// + /// 查询实体数据是否存在 + /// + /// + /// public async Task AnyAsync(object objId) { return await _db.Queryable().In(objId).AnyAsync(); diff --git a/Tiobon.Core.Services/BASE/BaseServices1.cs b/Tiobon.Core.Services/BASE/BaseServices1.cs index 5a7a138c..163d7d1a 100644 --- a/Tiobon.Core.Services/BASE/BaseServices1.cs +++ b/Tiobon.Core.Services/BASE/BaseServices1.cs @@ -41,6 +41,17 @@ namespace Tiobon.Core.Services.BASE public ISqlSugarClient Db => BaseDal.Db; + /// + /// 根据ID查询实体数据是否存在 + /// + /// + /// + public async Task AnyAsync(object objId) + { + var data = await BaseDal.AnyAsync(objId); + return data; + } + public async Task QueryById(object objId) { var data = await BaseDal.QueryById(objId);