using Furion.DependencyInjection;
using Nirvana.Common;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using YBDevice.Entity;

namespace YBDevice.NApi.Application.NoticeInfo
{
    public class NoticeService:INoticeService, ITransient
    {
        private readonly ISqlSugarRepository<YB_NoticeLog> repository;
        private readonly SqlSugarClient dbClient;
        public NoticeService(ISqlSugarRepository<YB_NoticeLog> sqlSugarRepository)
        {
            repository = sqlSugarRepository;
            dbClient = repository.Context;
        }
        /// <summary>
        /// 增加通知日志
        /// </summary>
        /// <param name="log"></param>
        /// <returns></returns>
        public async Task<int> InsertNoticeLogAsync(YB_NoticeLog log)
        {
            var data = new YB_NoticeLog
            {
                Ip = Net.Ip,
                CreateTime = DateTime.Now,
                FromInfo = log.FromInfo.ToStr(),
                Info = log.Info.ToStr(),
                UA = log.UA.ToStr(),
                UserInfo = log.UserInfo.ToStr()
            };
            int id = await dbClient.Insertable<YB_NoticeLog>(data).ExecuteReturnIdentityAsync();
            return id;
        }
    }
}
