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

namespace HighWayIot.Repository.service.Impl
{
    public class BaseHeartbeatServiceImpl : IHeartbeatService
    {
        private LogHelper log = LogHelper.Instance;
        Repository<RFIDHeartbeat> _repository => new Repository<RFIDHeartbeat>("mysql");

        public List<RFIDHeartbeat> GetHeartbeatInfos()
        {
            try
            {
                List<RFIDHeartbeat> deviceInfo = _repository.GetList();
                return deviceInfo;
            }catch (Exception ex)
            {
                log.Error("RFID心跳信息获取异常", ex);
                return null;
            }
        }

        public void AddHeartbeatInfo(RFIDHeartbeat heartbeat)
        {
            try
            {
                _repository.Insert(heartbeat);
            }
            catch (Exception ex)
            {
                log.Error("RFID心跳信息插入异常", ex);
            }
        }

        public int UpdateHeartbeatInfo(int deviceno)
        {
            try
            {
                return _repository.AsUpdateable().SetColumns(x => x.BeatTime == DateTime.Now).Where(x => x.DeviceNo == deviceno).ExecuteCommand();
            }
            catch(Exception ex)
            {
                log.Error("RFID心跳信息更新异常", ex);
                return -1;
            }
        }
    }
}
