Ejemplo n.º 1
0
        // 二供执行体辅助工具
        private PandaToken GetToken()
        {
            PandaToken token     = null;
            string     AppKey    = param.appKey;
            string     appSecret = param.appSecret;
            string     url       = param.getTokenUrl;
            IDictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("AppKey", AppKey);
            parameters.Add("appSecret", appSecret);
            HttpRequestUtil requestUtil = new HttpRequestUtil(ContentType.XWwwFromUrlencoded);

            requestUtil.CreateSyncPostHttpRequest(url, parameters, (successData) =>
            {
                token = ByteUtil.ToDeserializeObject <PandaToken>(successData);
                if (token == null)
                {
                    TraceManagerForWeb.AppendErrMsg("获取熊猫二供接口token失败:" + "返回的数据格式不正确");
                    return;
                }
                if (token.code == "200")
                {
                    TraceManagerForWeb.AppendDebug("获取熊猫二供接口token成功");
                    return;
                }
                else if (token.code == "10005")
                {
                    TraceManagerForWeb.AppendErrMsg("获取熊猫二供接口token失败:" + "参数为空或格式不正确,确认appKey是否正确");
                    token = null;
                    return;
                }
                else if (token.code == "10006")
                {
                    TraceManagerForWeb.AppendErrMsg("获取熊猫二供接口token失败:" + "Appkey和AppSecret不匹配");
                    token = null;
                    return;
                }
                else if (token.code == "49999")
                {
                    TraceManagerForWeb.AppendErrMsg("获取熊猫二供接口token失败:" + "接口调用异常");
                    token = null;
                    return;
                }
                else
                {
                    TraceManagerForWeb.AppendErrMsg("获取熊猫二供接口token失败:" + "错误的返回码");
                    token = null;
                    return;
                }
            }, (failData) => {
                token = null;
                TraceManagerForWeb.AppendErrMsg("获取熊猫二供接口token失败" + failData);
            }, (doErrorData) => {
                token = null;
                TraceManagerForWeb.AppendErrMsg("处理熊猫二供接口token数据失败" + doErrorData);
            });

            return(token);
        }
Ejemplo n.º 2
0
        private void CollectAndSavePoints()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start(); //  开始监视代码运行时间

            #region 查询点表
            string    sqlPoints = @"select t.*,t1.数据业务地址,t1.名称 from PointAddressEntry t,PumpPointAddressDetail t1  where t.点明细ID=t1.ID 
                                     and t.版本ID in(select distinct PointAddressID  from PumpJZ x,pump x1 where PumpJZReadMode='WEB-PUMP' and (x.是否删除=0 or x.是否删除 is null) and (x1.是否删除=0 or x1.是否删除 is null));";
            DataTable dtPoints  = DBUtil.ExecuteDataTable(sqlPoints, out string errMsg);
            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                TraceManagerForWeb.AppendErrMsg("查询二供点表版本失败:" + errMsg);
                return;
            }
            pointsCache = new Dictionary <int, List <Point> >();
            foreach (DataRow dr in dtPoints.Rows)
            {
                int   versionID = DataUtil.ToInt(dr["版本ID"]);
                Point point     = new Point()
                {
                    pointID           = DataUtil.ToInt(dr["ID"]),
                    versionID         = versionID,
                    name              = DataUtil.ToString(dr["名称"]),
                    dataSourceAddress = DataUtil.ToString(dr["数据源地址"]).Trim(),
                    offsetAddress     = DataUtil.ToString(dr["偏移地址"]).Trim(),
                    dbSAddress        = DataUtil.ToString(dr["数据业务地址"]).Trim(),
                    type              = Point.ToType(DataUtil.ToString(dr["数据类型"])),
                    isActive          = DataUtil.ToInt(dr["是否激活"]),
                    isWrite           = DataUtil.ToInt(dr["是否写入"]),
                    scale             = DataUtil.ToDouble(dr["倍率"])
                };
                if (pointsCache.Keys.Contains(versionID))
                {
                    pointsCache[versionID].Add(point);
                }
                else
                {
                    pointsCache.Add(versionID, new List <Point>()
                    {
                        point
                    });
                }
            }
            if (pointsCache.Keys.Count == 0)
            {
                TraceManagerForWeb.AppendWarning("机组表没有读取模式关于WEB-PUMP的点表");
                return;
            }
            #endregion

            #region 查询JZ表
            string sqlJZ = @"select CONVERT(varchar(50),t1.ID) as BASEID ,t.PName as PumpName,t1.PumpJZName , t1.PointAddressID,t1.JZCode  
                             from Pump t, PumpJZ t1 where t.ID=t1.PumpId and t1.PumpJZReadMode='WEB-PUMP' and (t.是否删除=0 or t.是否删除 is null)  and (t1.是否删除=0 or t1.是否删除 is null) ;";

            DataTable dtJZIDs = DBUtil.ExecuteDataTable(sqlJZ, out errMsg);
            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                TraceManagerForWeb.AppendErrMsg("查询二供机组ID列表失败:" + errMsg);
                return;
            }
            List <PumpJZ> jzs = new List <PumpJZ>();
            foreach (DataRow dr in dtJZIDs.Rows)
            {
                int          versionID  = DataUtil.ToInt(dr["PointAddressID"]);
                List <Point> points     = pointsCache[versionID];
                Point[]      pointsCopy = ByteUtil.DeepClone <List <Point> >(points).ToArray();// 一定要深度辅助一个副本,防止引用类型
                PumpJZ       jz         = new PumpJZ()
                {
                    _ID             = DataUtil.ToString(dr["BASEID"]),
                    _PumpName       = DataUtil.ToString(dr["PumpName"]),
                    _PumpJZName     = DataUtil.ToString(dr["PumpJZName"]),
                    _PandaPumpJZID  = DataUtil.ToString(dr["JZCode"]),
                    pointsVersionID = versionID,
                    points          = pointsCopy
                };
                jzs.Add(jz);
                // 生成机组更新日期字典
                if (!_LastUpdateDays.Keys.Contains(jz._ID))
                {
                    _LastUpdateDays.Add(jz._ID, "");
                }
            }
            if (jzs.Count == 0)
            {
                TraceManagerForWeb.AppendWarning("机组表没有读取模式为WEB-PUMP的有效机组");
                return;
            }
            #endregion

            #region 查询天表
            string    sqlHisDayDatas = @"select BASEID,TempTime from(
                                      select row_number() over(partition by BASEID order by TempTime desc) nRow ,* from PumpHisDayData tt) t where t.nRow=1";
            DataTable dtHisDayDatas  = DBUtil.ExecuteDataTable(sqlHisDayDatas, out errMsg);
            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                TraceManagerForWeb.AppendErrMsg("查询二供历史天表缓存信息失败:" + errMsg);
                return;
            }
            String[] keyArr = _LastUpdateDays.Keys.ToArray <String>();
            for (int i = 0; i < keyArr.Length; i++)
            {
                DataRow[] drs = dtHisDayDatas.Select("BASEID='" + keyArr[i] + "'");
                if (drs != null && drs.Length > 0)
                {
                    _LastUpdateDays[keyArr[i]] = DataUtil.ToDateString(drs[0]["TempTime"]);
                }
            }
            #endregion

            #region 是否需求请求新token
            if (tokenCache == null || DateTime.Compare(DateTime.Now, DataUtil.ToDateTime(tokenCache.data.expireTime)) > 0)
            {
                tokenCache = GetToken();
            }
            if (tokenCache == null)
            {
                return;
            }
            if (DateTime.Compare(DateTime.Now, DataUtil.ToDateTime(tokenCache.data.expireTime)) > 0)
            {
                TraceManagerForWeb.AppendErrMsg("获取二供标记参数为过期标记");
                return;// 获取后还是过期秘钥
            }
            #endregion

            #region 请求二供数据并存入
            List <PandaPumpJZ> pandaJZs = GetWebPumpData();
            Collect(pandaJZs, ref jzs);
            string saveSQL = GetSavePointsSQL(jzs);
            if (string.IsNullOrWhiteSpace(saveSQL))
            {
                TraceManagerForWeb.AppendWarning(string.Format(@"采集机组数量{0}获取存入数据库SQL失败,可能原因没有在线的机组", jzs.Count));
                return;
            }
            DBUtil.ExecuteNonQuery(saveSQL, out string err);
            stopwatch.Stop();                                   //  停止监视
            TimeSpan timespan     = stopwatch.Elapsed;          //  获取当前实例测量得出的总时间
            double   milliseconds = timespan.TotalMilliseconds; //  总毫秒数

            if (!string.IsNullOrWhiteSpace(err))
            {
                TraceManagerForWeb.AppendErrMsg("更新二供实时数据失败" + ",耗时:" + milliseconds.ToString() + "毫秒," + err);
            }
            else
            {
                TraceManagerForWeb.AppendDebug("更新二供实时数据成功" + ",耗时:" + milliseconds.ToString() + "毫秒");
            }
            #endregion
        }
Ejemplo n.º 3
0
        private void CollectAndSaveSnesors()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start(); //  开始监视代码运行时间

            Dictionary <int, Station> dicStations = new Dictionary <int, Station>();

            #region 查询sensor表
            string    sqlSensors = @"select * from( select t.ID stationID, t.GUID as stationCode,t.Name stationName,t1.ID sensorID,t1.Name sensorName,t1.PointAddressID 
                                                 from SCADA_Station t ,SCADA_Sensor t1 where t.ID=t1.StationID and t.ReadMode='WEB-ZHCD') x
                                                 left join PointAddressEntry x1 on x.PointAddressID=x1.ID;";
            DataTable dtSensors  = DBUtil.ExecuteDataTable(sqlSensors, out string errMsg);
            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                TraceManagerForWeb.AppendErrMsg("查询sensor列表失败:" + errMsg);
                return;
            }
            foreach (DataRow dr in dtSensors.Rows)
            {
                Station station = new Station()
                {
                    _ID     = DataUtil.ToInt(dr["stationID"]),
                    _GUID   = DataUtil.ToString(dr["stationCode"]),
                    _Name   = DataUtil.ToString(dr["stationName"]),
                    sensors = new List <Sensor>()
                };
                Sensor sensor = new Sensor()
                {
                    sensorID          = DataUtil.ToString(dr["sensorID"]),
                    sensorName        = DataUtil.ToString(dr["sensorName"]),
                    _PointAddressID   = DataUtil.ToInt(dr["PointAddressID"]),
                    versionID         = DataUtil.ToInt(dr["版本ID"]),
                    dataSourceAddress = DataUtil.ToString(dr["数据源地址"]).Trim(),
                    type     = Point.ToType(DataUtil.ToString(dr["数据类型"])),
                    isActive = DataUtil.ToInt(dr["是否激活"]),
                    scale    = DataUtil.ToDouble(dr["倍率"])
                };

                if (dicStations.Keys.Contains(station._ID))
                {
                    dicStations[station._ID].sensors.Add(sensor);
                }
                else
                {
                    station.sensors.Add(sensor);
                    dicStations.Add(station._ID, station);
                }
            }
            if (dicStations.Keys.Count == 0)
            {
                TraceManagerForWeb.AppendWarning("站点表没有读取模式:WEB-ZHCD的站点表");
                return;
            }
            #endregion

            #region 是否需求请求新token
            if (tokenCache == null || DateTime.Compare(DateTime.Now, DataUtil.ToDateTime(tokenCache.data.expireTime)) > 0)
            {
                tokenCache = GetToken();
            }
            if (tokenCache == null)
            {
                return;
            }
            if (DateTime.Compare(DateTime.Now, DataUtil.ToDateTime(tokenCache.data.expireTime)) > 0)
            {
                TraceManagerForWeb.AppendErrMsg("获取熊猫标记参数为过期标记");
                return;// 获取后还是过期秘钥
            }
            #endregion

            #region 请求监测点数据并存入
            List <ZongHeCeDian> ceDians = GetWebCeDianData();
            Collect(ceDians, ref dicStations);
            string saveSQL = GetSaveSensorsSQL(dicStations);
            if (string.IsNullOrWhiteSpace(saveSQL))
            {
                TraceManagerForWeb.AppendWarning(string.Format(@"采集WEB-综合测点数量{0}获取存入数据库SQL失败,可能原因没有在线的站点", dicStations.Keys.Count));
                return;
            }
            DBUtil.ExecuteNonQuery(saveSQL, out string err);
            stopwatch.Stop();                                   //  停止监视
            TimeSpan timespan     = stopwatch.Elapsed;          //  获取当前实例测量得出的总时间
            double   milliseconds = timespan.TotalMilliseconds; //  总毫秒数

            if (!string.IsNullOrWhiteSpace(err))
            {
                TraceManagerForWeb.AppendErrMsg("更新WEB-综合测点实时数据失败" + ",耗时:" + milliseconds.ToString() + "毫秒," + err);
            }
            else
            {
                TraceManagerForWeb.AppendDebug("更新WEB-综合测点实时数据成功" + ",耗时:" + milliseconds.ToString() + "毫秒");
            }
            #endregion
        }