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

namespace StorageMeterSystem
{
    public class BaseGlodDbCls
    {
        Log lg = Log.GetInstance();

        public bool getBaseDb()
        {
            #region 所有计量点数据
            MeterBaseSpotInfoService service = new MeterBaseSpotInfoService();
            RESTfulResult<List<MeterBaseSpotInfo>> rms = service.doQueryWf(new MeterBaseSpotInfo { validFlag = "1", spotTypeNo = "001002003" }); //获取成品秤数据
            if (rms.Succeed && rms.Data != null && rms.Data.Count > 0)
            {
                PbStorageGlodCache.sportInfos = rms.Data;
                if (PbStorageGlodCache.ltMonitor != null)
                {
                    foreach (MeterBaseSpotInfo sp in PbStorageGlodCache.sportInfos)
                    {
                        string pNo = PbStorageGlodCache.ltMonitor?.FirstOrDefault(s => s.baseSpotNo == sp.baseSpotNo)?.pointNo;
                        if (!string.IsNullOrEmpty(pNo))
                            sp.deleteManNo = pNo;
                    }
                }
            }
            else
            {
                lg.WriteLog(8, "MeterBaseSpotInfo");
                return false;
            }
            #endregion
            return true;
        }

        internal bool setBaseDb()
        {
            #region 监控表
            MeterWorkStockOnlineService staticMonitorService = new MeterWorkStockOnlineService();
            RESTfulResult<List<MeterWorkStockOnline>> rr = staticMonitorService.doQueryWf(new MeterWorkStockOnline { validFlag = "2" });
            if (rr.Succeed && rr.Data != null && rr.Data.Count > 0)
            {
                PbStorageGlodCache.ltMonitor = rr.Data;
            }
            else
            {
                lg.WriteLog(8, "未找到监控表信息MeterWorkStockOnline");
                return false;
            }
            #endregion
            return true;
        }
    }
}
