 
using XYY.Core.Standard.Data.Infrastructure;
using Dapper;
using System.Threading.Tasks;
using XYY.Model.Standard.Task;

namespace XYY.Data.Standard.Tasks
{
    /// <summary>
    ///  大任务监控服务
    /// </summary>
    public class TaskTrackDataRepository : ITaskTrackDataRepository
    {
        public IUnitOfWork _unitOfWork;

        public TaskTrackDataRepository(IUnitOfWork unitOfWork)
        {
            _unitOfWork = unitOfWork;
        }
        /// <summary>
        /// 启动跟踪
        /// </summary>
        public async Task<int> InitTaskTrack(TaskTrackModel model)
        {
            return (int)(await _unitOfWork.InsertAsync(model));
        }

        public async Task Success(int qty, int taskid)
        {
            await _unitOfWork.ExecuteAsync($"update taskTrackModel set SuccessQty += {qty} ,WaitQty -= { qty} where id = {taskid}");
        }

        public async Task Error(int qty, int taskid)
        {
            await _unitOfWork.ExecuteAsync($"update taskTrackModel set ErrorQty -= {qty} ,WaitQty -= { qty} where id = {taskid}");
        }


    }
}
