/*********************************************************************** * Project: baifenBinfa * ProjectName: 百分兵法管理系统 * Web: http://chuanyin.com * Author: * Email: * CreateTime: 202403/02 * Description: 暂无 ***********************************************************************/ using System; using System.Threading.Tasks; using CoreCms.Net.Configuration; using CoreCms.Net.IRepository; using CoreCms.Net.IRepository.UnitOfWork; using CoreCms.Net.IServices; using CoreCms.Net.Loging; using CoreCms.Net.Model.Entities; using CoreCms.Net.Model.ViewModels.UI; using CoreCms.Net.Utility.Helper; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace CoreCms.Net.Services { /// /// 消息发送表 接口实现 /// public class CoreCmsMessageServices : BaseServices, ICoreCmsMessageServices { private readonly ICoreCmsMessageRepository _dal; private readonly IUnitOfWork _unitOfWork; public CoreCmsMessageServices(IUnitOfWork unitOfWork, ICoreCmsMessageRepository dal) { this._dal = dal; base.BaseDal = dal; _unitOfWork = unitOfWork; } /// /// 站内消息 /// /// 接受者id /// 模板编码 /// 参数 /// public async Task Send(int userId, string code, JObject parameters) { var jm = new WebApiCallBack(); var content = MessageHelper.GetTemp(code, parameters); if (string.IsNullOrEmpty(content)) { jm.msg = GlobalErrorCodeVars.Code10009; return jm; } var msg = new CoreCmsMessage { userId = userId, code = code, parameters = JsonConvert.SerializeObject(parameters), contentBody = content, status = false, createTime = DateTime.Now }; var bl = await _dal.InsertAsync(msg) > 0; jm.status = bl; jm.msg = bl ? "站内消息发布成功" : "站内消息发布失败"; return jm; } /// /// 消息查看,更新已读状态 /// /// /// /// public async Task info(int userId, int id) { var jm = new WebApiCallBack { status = true }; var info = await _dal.QueryByClauseAsync(p => p.userId == userId && p.id == id); if (info != null) { await _dal.UpdateAsync(p => new CoreCmsMessage() { status = true }, p => p.id == info.id); } return jm; } /// /// 判断是否有新消息 /// /// /// public async Task HasNew(int userId) { var bl = await _dal.ExistsAsync(p => p.userId == userId && p.status == false); return bl; } } }