You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
5.1 KiB
C#

using Myshipping.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Linq;
using System.Threading.Tasks;
using Furion.Logging;
using Microsoft.Extensions.Logging;
using Myshipping.Core.Entity;
using Furion.FriendlyException;
using System;
using Furion.EventBus;
namespace Myshipping.Core.Service
{
/// <summary>
/// 大简云消息服务
/// </summary>
[ApiDescriptionSettings(Name = "DjyMessage", Order = 1)]
public class DjyMessageService : IDjyMessageService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<DjyMessage> _rep;
private readonly ISysCacheService _cacheService;
private readonly ILogger<DjyMessageService> _logger;
private readonly IEventPublisher _publisher;
public DjyMessageService(SqlSugarRepository<DjyMessage> rep, ILogger<DjyMessageService> logger, ISysCacheService cacheService,
IEventPublisher publisher)
{
_rep = rep;
_logger = logger;
_cacheService = cacheService;
this._publisher = publisher;
}
/// <summary>
/// 消息列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/DjyMessage/Page")]
public async Task<SqlSugarPagedList<DjyMessageListOutput>> Page(DjyMessageQueryInput input)
{
var query = _rep.AsQueryable()
.WhereIF(input.TypeCode.HasValue, x => x.TypeCode == input.TypeCode.Value.ToString())
.WhereIF(input.Module.HasValue, x => x.Module == input.Module.Value.ToString())
.WhereIF(input.IsRead.HasValue, x => x.IsRead == input.IsRead)
.WhereIF(input.ProcStatus.HasValue, x => x.ProcStatus == input.ProcStatus.Value.ToString());
if (!string.IsNullOrEmpty(input.SortField) || input.MultiSort == null || input.MultiSort.Count == 0)
{
query = query.OrderBy(PageInputOrder.OrderBuilder(input.SortField, input.DescSort));
}
else
{
query = query.OrderBy(PageInputOrder.MultiOrderBuilder(input.MultiSort));
}
var entities = await query.ToPagedListAsync(input.PageNo, input.PageSize);
var list = entities.Adapt<SqlSugarPagedList<DjyMessageListOutput>>();
return list;
}
/// <summary>
/// 消息删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost("/DjyMessage/Delete")]
public async Task Delete(long id)
{
await _rep.AsUpdateable(new DjyMessage() { Id = id, IsDeleted = true }).UpdateColumns(x => new { x.IsDeleted }).ExecuteCommandAsync();
}
/// <summary>
/// 保存消息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/DjyMessage/Save")]
public Task<long> Save(DjyMessageSaveInput input)
{
throw new System.NotImplementedException();
}
/// <summary>
/// 消息详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost("/DjyMessage/Get")]
public async Task<DjyMessageDetailOutput> Get(long id)
{
var msg = await _rep.FirstOrDefaultAsync(x => x.Id == id);
return msg.Adapt<DjyMessageDetailOutput>();
}
/// <summary>
/// 读取消息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost("/DjyMessage/Read")]
public async Task Read(long id)
{
await _rep.AsUpdateable(new DjyMessage()
{
Id = id,
IsRead = true,
ReadTime = DateTime.Now,
ReadUser = UserManager.Name
}).UpdateColumns(x => new { x.IsRead, x.ReadTime, x.ReadUser }).ExecuteCommandAsync();
}
/// <summary>
/// 处理消息
/// </summary>
/// <returns></returns>
[HttpPost("/DjyMessage/Process")]
public async Task Process(DjyMessageProcessInput input)
{
var msg = await _rep.FirstOrDefaultAsync(x => x.Id == input.Id);
if (msg.ProcStatus != MessageProcessStatus.UnProcess.ToString())
{
throw Oops.Bah($"当前消息已被{msg.ProcUser}在{(msg.ProcTime.HasValue ? msg.ProcTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : "")}处理过");
}
msg.ProcStatus = input.ProcStatus.ToString();
msg.ProcResult = input.Comment;
msg.ProcUser = UserManager.Name;
msg.ProcTime = DateTime.Now;
await _rep.AsUpdateable(msg).UpdateColumns(x => new { x.ProcStatus, x.ProcResult, x.ProcUser }).ExecuteCommandAsync();
//发布已处理事件消息
await _publisher.PublishAsync(new ChannelEventSource($"Message:Process:{msg.Module}:{msg.TypeCode}", input.Id));
}
}
}