1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using OASystem.Domain.Dtos.System;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OASystem.Infrastructure.Repositories.System
- {
- public class MessageRepository : BaseRepository<Sys_Message, MessageView>
- {
- public MessageRepository(SqlSugarClient sqlSugar) : base(sqlSugar) { }
- /// <summary>
- /// 发布消息
- /// </summary>
- /// <param name="msgDto"></param>
- /// <returns></returns>
- public async Task<bool> AddMsg(MessageDto msgDto)
- {
- #region 参数处理
- if (msgDto == null) { return false; }
- if (string.IsNullOrEmpty(msgDto.Title)) { return false; }
- if (string.IsNullOrEmpty(msgDto.Content)) { return false; }
- if (msgDto.UIdList.Count <= 0) { return false; }
- #endregion
- _sqlSugar.BeginTran();
- try
- {
- Sys_Message message = new Sys_Message()
- {
- Type = msgDto.Type,
- IssuerId = msgDto.IssuerId,
- Title = msgDto.Title,
- Content = msgDto.Content,
- ReleaseTime = msgDto.ReleaseTime,
- CreateUserId = msgDto.IssuerId,
- CreateTime = DateTime.Now,
- DeleteUserId = null,
- DeleteTime = "1990-01-01 00:00:00.000",
- Remark = "",
- IsDel = 0
- };
- int? msgId = await _sqlSugar.Insertable(message).ExecuteReturnIdentityAsync();
- if (!msgId.HasValue) { _sqlSugar.RollbackTran(); return false; }
- List<Sys_MessageReadAuth> messageReadAuths = new List<Sys_MessageReadAuth>();
- foreach (int item in msgDto.UIdList)
- {
- Sys_MessageReadAuth messageReadAuth = new Sys_MessageReadAuth()
- {
- MsgId = msgId.Value,
- ReadableUId = item,
- ReadTime = new DateTime(1990,1,1),
- CreateUserId = msgDto.IssuerId,
- CreateTime = DateTime.Now,
- DeleteUserId = null,
- DeleteTime = "1990-01-01 00:00:00.000",
- Remark = "",
- IsDel = 0
- };
- messageReadAuths.Add(messageReadAuth);
- }
- int? readIds = await _sqlSugar.Insertable<Sys_MessageReadAuth>(messageReadAuths).ExecuteCommandAsync();
- if (!readIds.HasValue)
- {
- _sqlSugar.RollbackTran();
- return false;
- }
- _sqlSugar.CommitTran();
- }
- catch (Exception)
- {
- _sqlSugar.RollbackTran();
- return false;
- }
- return true;
- }
- }
- }
|