流程处理增加消息通知

修复消息标记已读、删除
This commit is contained in:
yubaolee 2021-05-26 17:02:05 +08:00
parent c0d47e37bf
commit 8608ce78f5
7 changed files with 137 additions and 41 deletions

View File

@ -0,0 +1,14 @@
namespace OpenAuth.App.Request
{
/// <summary>
/// 请求参数中只有Id
/// </summary>
/// <typeparam name="T"></typeparam>
public class IdRequest<T>
{
/// <summary>
/// 操作Id
/// </summary>
public T Id { get; set; }
}
}

View File

@ -41,11 +41,13 @@ namespace OpenAuth.App
private FormApp _formApp;
private IHttpClientFactory _httpClientFactory;
private IServiceProvider _serviceProvider;
private SysMessageApp _messageApp;
public FlowInstanceApp(IUnitWork<OpenAuthDBContext> unitWork,
IRepository<FlowInstance, OpenAuthDBContext> 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();

View File

@ -2,6 +2,9 @@
{
public class QuerySysMessageListReq : PageReq
{
//todo:添加自己的请求字段
/// <summary>
/// 消息状态 0:未读1已读 999:全部
/// </summary>
public int Status { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace OpenAuth.App.Request
{
/// <summary>
/// 阅读消息请求
/// </summary>
public class ReadMsgReq : IdRequest<string>
{
}
}

View File

@ -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<SysMessage,OpenAuthDBContext>
{
private RevelanceManagerApp _revelanceApp;
private readonly ILogger<SysMessageApp> _logger;
/// <summary>
/// 加载列表
@ -27,12 +30,18 @@ namespace OpenAuth.App
}
var result = new TableData();
var objs = UnitWork.Find<SysMessage>(u =>u.ToId == loginContext.User.Id);
var objs = UnitWork.Find<SysMessage>(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)
/// <summary>
/// 发送指定消息给用户
/// </summary>
/// <param name="user"></param>
/// <param name="message"></param>
public void SendMsgTo(string userId, string message)
{
UnitWork.Update<SysMessage>(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<User>(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
});
}
/// <summary>
/// 消息变为已读
/// </summary>
/// <param name="msgid"></param>
public void Read(ReadMsgReq req)
{
UnitWork.Update<SysMessage>(u => u.Id == req.Id, u => new SysMessage
{
ToStatus = 1
});
}
/// <summary>
/// 消息采用逻辑删除
/// </summary>
/// <param name="ids"></param>
public void Del(string[] ids)
{
UnitWork.Update<SysMessage>(u => ids.Contains(u.Id), u => new SysMessage
{
ToStatus = -1 //逻辑删除
});
}
public SysMessageApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<SysMessage,OpenAuthDBContext> repository,
RevelanceManagerApp app,IAuth auth) : base(unitWork, repository, auth)
RevelanceManagerApp app,IAuth auth, ILogger<SysMessageApp> logger) : base(unitWork, repository, auth)
{
_revelanceApp = app;
_logger = logger;
}
}
}

View File

@ -40,22 +40,28 @@ namespace OpenAuth.Mvc.Controllers
}
return JsonHelper.Instance.Serialize(Result);
}
//添加或修改
/// <summary>
/// 阅读消息(即消息置为已读)
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
[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);
}
/// <summary>

View File

@ -19,7 +19,11 @@ namespace OpenAuth.WebApi.Controllers
{
private readonly SysMessageApp _app;
//获取详情
/// <summary>
/// 获取消息详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
public Response<SysMessage> Get(string id)
{
@ -37,14 +41,18 @@ namespace OpenAuth.WebApi.Controllers
return result;
}
//添加
/// <summary>
/// 阅读消息(即消息置为已读)
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
[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;
}
/// <summary>
/// 加载列表
/// </summary>
@ -93,7 +82,7 @@ namespace OpenAuth.WebApi.Controllers
var result = new Response();
try
{
_app.Delete(ids);
_app.Del(ids);
}
catch (Exception ex)