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 data2_TableServiceImpl : BaseServiceImpl<data2_Table>, Idata2_TableService
    {
        private Repository<data2_Table> _repository2;
        private ILogger<data2_TableServiceImpl> _logger;
        public data2_TableServiceImpl(Repository<data2_Table> repository, ILogger<data2_TableServiceImpl> logger) :base(repository)
        {
            _logger = logger;
            _repository2 = repository;
        }
        public async Task<bool> UpdateAsync(data2_Table record)
        {
            try
            {
                bool result = await _rep.UpdateAsync(record);
                return result;
            }
            catch (Exception ex)
            {
                _logger.LogError($"量仪数据获取错误:{ex.Message}");
                return false;
            }

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