From 8608ce78f5e5ab1de5e8bfda3984a52a657acfe4 Mon Sep 17 00:00:00 2001 From: yubaolee Date: Wed, 26 May 2021 17:02:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E7=A8=8B=E5=A4=84=E7=90=86=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=B6=88=E6=81=AF=E6=A0=87=E8=AE=B0=E5=B7=B2=E8=AF=BB?= =?UTF-8?q?=E3=80=81=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OpenAuth.App/Base/IdRequest.cs | 14 ++++ OpenAuth.App/FlowInstance/FlowInstanceApp.cs | 14 +++- .../Request/QuerySysMessageListReq.cs | 5 +- OpenAuth.App/SysMessage/Request/ReadMsgReq.cs | 9 +++ OpenAuth.App/SysMessage/SysMessageApp.cs | 77 +++++++++++++++++-- .../Controllers/SysMessagesController.cs | 20 +++-- .../Controllers/SysMessagesController.cs | 39 ++++------ 7 files changed, 137 insertions(+), 41 deletions(-) create mode 100644 OpenAuth.App/Base/IdRequest.cs create mode 100644 OpenAuth.App/SysMessage/Request/ReadMsgReq.cs diff --git a/OpenAuth.App/Base/IdRequest.cs b/OpenAuth.App/Base/IdRequest.cs new file mode 100644 index 00000000..6f08a2eb --- /dev/null +++ b/OpenAuth.App/Base/IdRequest.cs @@ -0,0 +1,14 @@ +namespace OpenAuth.App.Request +{ + /// + /// 请求参数中只有Id + /// + /// + public class IdRequest + { + /// + /// 操作Id + /// + public T Id { get; set; } + } +} diff --git a/OpenAuth.App/FlowInstance/FlowInstanceApp.cs b/OpenAuth.App/FlowInstance/FlowInstanceApp.cs index 4f74cca8..a1d71bf3 100644 --- a/OpenAuth.App/FlowInstance/FlowInstanceApp.cs +++ b/OpenAuth.App/FlowInstance/FlowInstanceApp.cs @@ -41,11 +41,13 @@ namespace OpenAuth.App private FormApp _formApp; private IHttpClientFactory _httpClientFactory; private IServiceProvider _serviceProvider; + private SysMessageApp _messageApp; public FlowInstanceApp(IUnitWork unitWork, IRepository repository , RevelanceManagerApp app, FlowSchemeApp flowSchemeApp, FormApp formApp, - IHttpClientFactory httpClientFactory, IAuth auth, IServiceProvider serviceProvider) + IHttpClientFactory httpClientFactory, IAuth auth, IServiceProvider serviceProvider, + SysMessageApp messageApp) : base(unitWork, repository, auth) { _revelanceApp = app; @@ -53,6 +55,7 @@ namespace OpenAuth.App _formApp = formApp; _httpClientFactory = httpClientFactory; _serviceProvider = serviceProvider; + _messageApp = messageApp; } #region 流程处理API @@ -295,6 +298,11 @@ namespace OpenAuth.App UnitWork.Update(flowInstance); UnitWork.Add(flowInstanceOperationHistory); + + //给流程创建人发送通知信息 + _messageApp.SendMsgTo(flowInstance.CreateUserId, + $"你的流程[{flowInstance.CustomName}]已被{user.Name}处理。处理情况如下:{flowInstanceOperationHistory.Content}"); + UnitWork.Save(); wfruntime.NotifyThirdParty(_httpClientFactory.CreateClient(), tag); @@ -378,6 +386,10 @@ namespace OpenAuth.App + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】驳回,备注:" + reqest.VerificationOpinion }); + + //给流程创建人发送通知信息 + _messageApp.SendMsgTo(flowInstance.CreateUserId, + $"你的流程[{flowInstance.CustomName}]已被{user.Name}驳回。备注信息:{reqest.VerificationOpinion}"); UnitWork.Save(); diff --git a/OpenAuth.App/SysMessage/Request/QuerySysMessageListReq.cs b/OpenAuth.App/SysMessage/Request/QuerySysMessageListReq.cs index e7ce4b4a..895c93fc 100644 --- a/OpenAuth.App/SysMessage/Request/QuerySysMessageListReq.cs +++ b/OpenAuth.App/SysMessage/Request/QuerySysMessageListReq.cs @@ -2,6 +2,9 @@ { public class QuerySysMessageListReq : PageReq { - //todo:添加自己的请求字段 + /// + /// 消息状态 0:未读;1:已读; 999:全部 + /// + public int Status { get; set; } } } \ No newline at end of file diff --git a/OpenAuth.App/SysMessage/Request/ReadMsgReq.cs b/OpenAuth.App/SysMessage/Request/ReadMsgReq.cs new file mode 100644 index 00000000..e87182d5 --- /dev/null +++ b/OpenAuth.App/SysMessage/Request/ReadMsgReq.cs @@ -0,0 +1,9 @@ +namespace OpenAuth.App.Request +{ + /// + /// 阅读消息请求 + /// + public class ReadMsgReq : IdRequest + { + } +} \ No newline at end of file diff --git a/OpenAuth.App/SysMessage/SysMessageApp.cs b/OpenAuth.App/SysMessage/SysMessageApp.cs index 98bda001..de132fb2 100644 --- a/OpenAuth.App/SysMessage/SysMessageApp.cs +++ b/OpenAuth.App/SysMessage/SysMessageApp.cs @@ -1,6 +1,8 @@ -using System.Linq; +using System; +using System.Linq; using System.Threading.Tasks; using Infrastructure; +using Microsoft.Extensions.Logging; using OpenAuth.App.Interface; using OpenAuth.App.Request; using OpenAuth.App.Response; @@ -14,6 +16,7 @@ namespace OpenAuth.App public class SysMessageApp : BaseStringApp { private RevelanceManagerApp _revelanceApp; + private readonly ILogger _logger; /// /// 加载列表 @@ -27,12 +30,18 @@ namespace OpenAuth.App } var result = new TableData(); - var objs = UnitWork.Find(u =>u.ToId == loginContext.User.Id); + var objs = UnitWork.Find(u =>u.ToId == loginContext.User.Id && u.ToStatus != -1); if (!string.IsNullOrEmpty(request.key)) { objs = objs.Where(u => u.Title.Contains(request.key) || u.Id.Contains(request.key)); } + + //过滤消息状态 + if (request.Status != 999) + { + objs = objs.Where(u => u.ToStatus == request.Status); + } result.data = objs.OrderBy(u => u.Id) .Skip((request.page - 1) * request.limit) @@ -45,20 +54,74 @@ namespace OpenAuth.App { Repository.Add(obj); } - - public void Update(SysMessage obj) + + /// + /// 发送指定消息给用户 + /// + /// + /// + public void SendMsgTo(string userId, string message) { - UnitWork.Update(u => u.Id == obj.Id, u => new SysMessage + User user = null; + if (userId == Guid.Empty.ToString()) { - //todo:要修改的字段赋值 + user = new User + { + Name = Define.SYSTEM_USERNAME, + Id = userId + }; + } + else + { + user = UnitWork.FirstOrDefault(u => u.Id == userId); + } + if (user == null) + { + _logger.LogError($"未能找到用户{userId},不能给该用户发送消息"); + return; + } + Repository.Add(new SysMessage + { + ToId = user.Id, + ToName = user.Name, + TypeName = "系统消息", + TypeId ="SYS_MSG", + FromId = Guid.Empty.ToString(), + FromName = "系统管理员", + Content = message, + CreateTime = DateTime.Now + }); + } + + /// + /// 消息变为已读 + /// + /// + public void Read(ReadMsgReq req) + { + UnitWork.Update(u => u.Id == req.Id, u => new SysMessage + { + ToStatus = 1 + }); + } + /// + /// 消息采用逻辑删除 + /// + /// + public void Del(string[] ids) + { + UnitWork.Update(u => ids.Contains(u.Id), u => new SysMessage + { + ToStatus = -1 //逻辑删除 }); } public SysMessageApp(IUnitWork unitWork, IRepository repository, - RevelanceManagerApp app,IAuth auth) : base(unitWork, repository, auth) + RevelanceManagerApp app,IAuth auth, ILogger logger) : base(unitWork, repository, auth) { _revelanceApp = app; + _logger = logger; } } } \ No newline at end of file diff --git a/OpenAuth.Mvc/Controllers/SysMessagesController.cs b/OpenAuth.Mvc/Controllers/SysMessagesController.cs index 2ba2b5fb..f613a200 100644 --- a/OpenAuth.Mvc/Controllers/SysMessagesController.cs +++ b/OpenAuth.Mvc/Controllers/SysMessagesController.cs @@ -40,22 +40,28 @@ namespace OpenAuth.Mvc.Controllers } return JsonHelper.Instance.Serialize(Result); } - - //添加或修改 + + /// + /// 阅读消息(即消息置为已读) + /// + /// + /// [HttpPost] - public string Update(SysMessage obj) + public string Read(ReadMsgReq obj) { + var result = new Response(); try { - _app.Update(obj); + _app.Read(obj); } catch (Exception ex) { - Result.Code = 500; - Result.Message = ex.Message; + result.Code = 500; + result.Message = ex.InnerException?.Message ?? ex.Message; } - return JsonHelper.Instance.Serialize(Result); + + return JsonHelper.Instance.Serialize(result); } /// diff --git a/OpenAuth.WebApi/Controllers/SysMessagesController.cs b/OpenAuth.WebApi/Controllers/SysMessagesController.cs index 0d0f88d4..bb47f790 100644 --- a/OpenAuth.WebApi/Controllers/SysMessagesController.cs +++ b/OpenAuth.WebApi/Controllers/SysMessagesController.cs @@ -19,7 +19,11 @@ namespace OpenAuth.WebApi.Controllers { private readonly SysMessageApp _app; - //获取详情 + /// + /// 获取消息详情 + /// + /// + /// [HttpGet] public Response Get(string id) { @@ -37,14 +41,18 @@ namespace OpenAuth.WebApi.Controllers return result; } - //添加 + /// + /// 阅读消息(即消息置为已读) + /// + /// + /// [HttpPost] - public Response Add(SysMessage obj) + public Response Read(ReadMsgReq obj) { var result = new Response(); try { - _app.Add(obj); + _app.Read(obj); } catch (Exception ex) @@ -55,26 +63,7 @@ namespace OpenAuth.WebApi.Controllers return result; } - - //修改 - [HttpPost] - public Response Update(SysMessage obj) - { - var result = new Response(); - try - { - _app.Update(obj); - - } - catch (Exception ex) - { - result.Code = 500; - result.Message = ex.InnerException?.Message ?? ex.Message; - } - - return result; - } - + /// /// 加载列表 /// @@ -93,7 +82,7 @@ namespace OpenAuth.WebApi.Controllers var result = new Response(); try { - _app.Delete(ids); + _app.Del(ids); } catch (Exception ex)