using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using com.hnshituo.core.webapp.vo;

namespace Common
{
    /// <summary>
    /// 监控表
    /// </summary>
    public class MeterWorkMonitorService
    {
        public RESTfulResult<List<MeterWorkMonitor>> doQueryOneWf(MeterWorkMonitor info)
        {
            DbHelper db = new DbHelper();
            RESTfulResult<PageList<List<MeterWorkMonitor>>> rm = db.doOption<PageList<List<MeterWorkMonitor>>>("meterworkmonitors", "/", new object[] { info }, 0);

            RESTfulResult<List<MeterWorkMonitor>> result = new RESTfulResult<List<MeterWorkMonitor>>();
            result.Succeed = rm.Succeed;
            result.Status = rm.Status;
            result.Message = rm.Message;
            result.ResultMessage = rm.ResultMessage;
            result.Code = rm.Code;
            if (rm.Succeed && rm.Data != null && rm.Data.list != null && rm.Data.list.Count == 1)
            {
                PbCache.monitor = rm.Data.list[0];
                result.Data = rm.Data.list;
            }
            else
            {
                PbCache.monitor = new MeterWorkMonitor();
            }
            return result;
        }

        public RESTfulResult<List<MeterWorkMonitor>> doQueryAllWf(MeterWorkMonitor info)
        {
            DbHelper db = new DbHelper();
            RESTfulResult<PageList<List<MeterWorkMonitor>>> rm = db.doOption<PageList<List<MeterWorkMonitor>>>("meterworkmonitors", "/", new object[] { info }, 0);

            RESTfulResult<List<MeterWorkMonitor>> result = new RESTfulResult<List<MeterWorkMonitor>>();
            result.Succeed = rm.Succeed;
            result.Status = rm.Status;
            result.Message = rm.Message;
            result.ResultMessage = rm.ResultMessage;
            result.Code = rm.Code;
            if (rm.Succeed && rm.Data != null && rm.Data.list != null && rm.Data.list.Count > 0)
            {
                if (PbCache.sportInfo != null)
                {
                    PbCache.monitor = rm.Data.list.Where(s => s.pointNo == PbCache.sportInfo.baseSpotNo).FirstOrDefault();
                }
                result.Data = rm.Data.list;
            }
            else
            {
                PbCache.monitor = new MeterWorkMonitor();
            }
            return result;
        }

        /// <summary>
        /// 修改
        /// </summary>
        public RESTfulResult<string> doUpdateWf(MeterWorkMonitor info)
        {
            DbHelper db = new DbHelper();
            RESTfulResult<string> rm = db.doOption<string>("meterworkmonitors", "doUpdateWf", new object[] { info }, 1);
            return rm;
        }


    }
}
