using Hotline.KnowledgeBase.Notifies; using Hotline.KnowledgeBase; using Hotline.Push; using Hotline.Repository.SqlSugar.Extensions; using Hotline.Share.Dtos; using Hotline.Share.Dtos.Push; using MapsterMapper; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using MediatR; using Hotline.Push.Notifies; using Hotline.Share.Enums.Push; namespace Hotline.Api.Controllers { public class PushMessageController : BaseController { private readonly IMessageRepository _messageRepository; private readonly IMapper _mapper; private readonly IPushDomainService _pushDomainService; /// /// /// /// /// /// /// public PushMessageController(IMessageRepository messageRepository, IMapper mapper, IPushDomainService pushDomainService) { _messageRepository = messageRepository; _mapper = mapper; _pushDomainService = pushDomainService; } /// /// 新增 /// /// /// [HttpPut("add")] public async Task AddMessage([FromBody] MessageDto dto) { await _pushDomainService.PushAsync(dto, HttpContext.RequestAborted); } /// /// 查询短信剩余数量 /// /// [HttpGet("query")] public async Task GetAccountNum() { return await _pushDomainService.GetAccountNum(); } #region 短信发送状态回调接口 /// /// 短信发送状态回调接口 /// /// 短信回传账号 /// 短信回传密码 /// 短信中心短信待发送ID,同短信发送接口返回值ID /// 短信发送时间 /// 发送短信使用的数量 /// 发送状态:0:未发送 1:发送中 2:发送失败 3:发送成功 /// 错误消息 /// 短信中心短信已发送ID /// 手机号码 /// 短信签名 /// [HttpPost("receiveobtain")] [AllowAnonymous] public async Task ReceiveObtain(string account, string pswd, string msgid, string sendtime, int msgcount, int state, string errormsg, int sfid, string telnumall, string sign) { ReceiveMessageDto receiveMessageDto = new() { account = account, pswd = pswd, msgid = msgid, sendtime = sendtime, msgcount = msgcount, state = state, errormsg = errormsg, sfid = sfid, telnumall = telnumall, sign = sign }; return await _pushDomainService.ReceiveObtain(receiveMessageDto); } #endregion #region 短信接收 /// /// 短信接收 /// /// 短信回传账号 /// 短信回传密码 /// 回复短信内容 /// 回复手机号码 /// 短信接收平台号码 /// 回复时间 /// 短信平台回复短信ID /// [HttpPost("receivesms")] [AllowAnonymous] public string ReceiveSms(string account, string pswd, string msg, string mobile, string destcode, string motime, string fsfid) { // 短信回传账号:fwkj // 短信回传密码:fwkj12 string strResult = "error,缺少参数"; // 成功返回值必须是ok strResult = "ok"; return strResult; } #endregion /// /// 查询短信 /// /// /// [HttpGet("getlist")] public async Task> AllMessage([FromQuery] MessagePagedDto pagedDto) { var (total, items) = await _messageRepository .Queryable() .Includes(it => it.User) .Includes(it => it.SystemOrganize) .Includes(it => it.Order) .WhereIF(pagedDto.PushBusiness.HasValue, d => d.PushBusiness == pagedDto.PushBusiness) .WhereIF(pagedDto.Status.HasValue, d => d.Status == pagedDto.Status) .WhereIF(!string.IsNullOrEmpty(pagedDto.Keyword), d => d.Name.Contains(pagedDto.Keyword!) || d.Content.Contains(pagedDto.Keyword!) || d.TelNumber.Contains(pagedDto.Keyword!) || d.User.Name.Contains(pagedDto.Keyword!) || d.SystemOrganize.OrgName.Contains(pagedDto.Keyword!)) .WhereIF(pagedDto.StartTime.HasValue, d => d.SendTime >= pagedDto.StartTime) .WhereIF(pagedDto.EndTime.HasValue, d => d.SendTime <= pagedDto.EndTime) .OrderByDescending(it => it.CreationTime) .ToPagedListAsync(pagedDto.PageIndex, pagedDto.PageSize, HttpContext.RequestAborted); return new PagedDto(total, _mapper.Map>(items)); } } }