using HighWayIot.Log4net;
using HighWayIot.Repository.domain;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace HighWayIot.Repository.service
{
    public class ZxSchedulingService
    {
        private static readonly Lazy<ZxSchedulingService> lazy = new Lazy<ZxSchedulingService>(() => new ZxSchedulingService());

        public static ZxSchedulingService Instance
        {
            get
            {
                return lazy.Value;
            }
        }

        private LogHelper log = LogHelper.Instance;
        Repository<ZxSchedulingEntity> _repository => new Repository<ZxSchedulingEntity>("sqlserver");

        /// <summary>
        /// 查询所有排程信息
        /// </summary>
        /// <returns></returns>
        public List<ZxSchedulingEntity> GetSchedulingInfo(Expression<Func<ZxSchedulingEntity, bool>> expression = null)
        {
            try
            {
                List<ZxSchedulingEntity> entity;
                if (expression != null)
                {
                    entity = _repository.GetList(expression);
                }
                else
                {
                    entity = _repository.GetList();
                }
                return entity;
            }
            catch (Exception ex)
            {
                log.Error("排程信息获取异常", ex);
                return null;
            }
        }

        ///// <summary>
        ///// 添加排程信息
        ///// </summary>
        ///// <param name="entity"></param>
        ///// <returns></returns>
        //public bool InsertSchedulingInfo(ZxSchedulingEntity entity)
        //{
        //    try
        //    {
        //        return _repository.Insert(entity);
        //    }
        //    catch (Exception ex)
        //    {
        //        log.Error("排程信息插入异常", ex);
        //        return false;
        //    }
        //}

        /// <summary>
        /// 修改排程信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool UpdateSchedulingInfo(List<ZxSchedulingEntity> entity)
        {
            try
            {
                return _repository.UpdateRange(entity);
            }
            catch (Exception ex)
            {
                log.Error("排程信息修改异常", ex);
                return false;
            }
        }
    }
}
