using Microsoft.Extensions.Logging;
using SlnMesnac.Common;
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.@base;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace SlnMesnac.Repository.service.Impl
{
    public class data4_TableServiceImpl : BaseServiceImpl<data4_Table>, Idata4_TableService
    {
        private Repository<data4_Table> _repository;
        private ILogger<data4_TableServiceImpl> _logger;
        public data4_TableServiceImpl(Repository<data4_Table> repository, ILogger<data4_TableServiceImpl> logger) :base(repository)
        {
            _repository = repository;
            _logger = logger;
        }

        public async Task<List<data4_Table>> GetTableListAsync(DateTime start ,DateTime end)
        {
            List<data4_Table> list = null;
            try
            {
                Expression<Func<data4_Table, bool>> exp = x => true;
                exp = exp.And(x =>
                    (x.flag != "F" && x.time >= start && x.time < end)
                  );
                list = _repository.GetList(exp);
            }
            catch (Exception ex)
            {
                _logger.LogError($"量仪数据获取错误:{ex.Message}");
            }
            return list;
        }
        public async Task<bool> UpdateAsync(data4_Table record)
        {
            try
            {
                bool result = await _rep.UpdateAsync(record);
                return result;
            }
            catch (Exception ex)
            {
                _logger.LogError($"量仪数据获取错误:{ex.Message}");
                return false;
            }

        }
    }
}