Example #1
0
        /// <summary>
        /// 缓存采集器发电量统计
        /// 要进行修正缓存丢失
        ///
        /// </summary>
        /// <param name="tcpmessage"></param>
        private static void CacheCollectorEnergyData(IDictionary <string, double?> collectorEnergyMap)
        {
            int collectorID;

            string[]  keyArr;
            int       year;
            int       month;
            int       day;
            float?    data;
            Collector collector = null;

            //string[] keys = collectorEnergyMap.Keys.ToArray();
            foreach (string ekey in collectorEnergyMap.Keys)
            {
                try
                {
                    keyArr = ekey.Split(':');

                    collectorID = int.Parse(keyArr[0]);
                    //原来是通过消息头部取得,现在改为
                    data = collectorEnergyMap[ekey] == null ? 0 : float.Parse(collectorEnergyMap[ekey].ToString());
                    if (data == 0)//如果头部未传或者为0则再从设备累计下看看
                    {
                        //现在改为通过采集器的设备的今日电量来累加
                        collector = CollectorInfoService.GetInstance().Get(collectorID);
                        if (keyArr.Length < 4 || (string.IsNullOrEmpty(keyArr[1]) || string.IsNullOrEmpty(keyArr[2]) || string.IsNullOrEmpty(keyArr[3])))
                        {
                            continue;
                        }
                        data = collector.deviceTodayEnergy(keyArr[1] + keyArr[2] + keyArr[3]);
                    }
                    year  = int.Parse(keyArr[1]);
                    month = int.Parse(keyArr[2]);
                    day   = int.Parse(keyArr[3]);
                    string d_column = "d_" + day;

                    //取得月天数据对象
                    CollectorMonthDayData collectorMonthDayData = CollectorMonthDayDataService.GetInstance().GetCollectorMonthDayData(year, collectorID, month);
                    collectorMonthDayData.curDay = day;
                    //给相应属性赋值
                    if (collectorMonthDayData != null)
                    {
                        object ovalue = ReflectionUtil.getProperty(collectorMonthDayData, d_column);
                        if (ovalue == null || float.Parse(ovalue.ToString()) < data)
                        {
                            ReflectionUtil.setProperty(collectorMonthDayData, d_column, data);
                        }
                    }
                    CollectorMonthDayDataService.GetInstance().Cache(collectorMonthDayData);

                    //更新年月发电量数据
                    //统计年月
                    string m_column = "m_" + month;
                    float? m_value  = collectorMonthDayData.count();
                    CollectorYearMonthData ymdData = CollectorYearMonthDataService.GetInstance().GetCollectorYearMonthData(collectorID, year);;
                    ymdData.curMonth = month;
                    //给年月数据对象相应属性赋值
                    if (ymdData != null)
                    {
                        object ovalue = ReflectionUtil.getProperty(ymdData, m_column);
                        if (ovalue == null || float.Parse(ovalue.ToString()) < m_value)
                        {
                            ReflectionUtil.setProperty(ymdData, m_column, m_value);
                        }
                    }
                    CollectorYearMonthDataService.GetInstance().Cache(ymdData);

                    //统计总体发电量
                    float?            y_value = ymdData.count();
                    CollectorYearData yd      = CollectorYearDataService.GetInstance().GetCollectorYearData(collectorID, year);
                    if (yd == null)
                    {
                        yd = new CollectorYearData()
                        {
                            dataValue = 0, collectorID = collectorID, year = year
                        }
                    }
                    ;
                    yd.localAcceptTime = DateTime.Now;
                    //给年月数据对象相应属性赋值
                    if (yd != null)
                    {
                        object ovalue = yd.dataValue;
                        if (ovalue == null || float.Parse(ovalue.ToString()) < y_value)
                        {
                            yd.dataValue = y_value == null ? 0 : float.Parse(y_value.ToString());
                        }
                    }
                    CollectorYearDataService.GetInstance().Cache(yd);
                }
                catch (Exception onee) {//捕获单个异常,保证一个错误不影响其他采集器数据处理
                    LogUtil.error("Cache collectorEnergyMap of ekey is " + ekey + " error:" + onee.Message);
                }
            }
        }
Example #2
0
        /// <summary>
        /// 缓存采集器发电量统计
        /// 要进行修正缓存丢失
        ///
        /// </summary>
        /// <param name="tcpmessage"></param>
        private static void CacheCollectorEnergyData(IDictionary <string, double> collectorEnergyMap)
        {
            int collectorID;

            string[]  keyArr;
            int       year;
            int       month;
            int       day;
            float?    data;
            Collector collector = null;

            //string[] keys = collectorEnergyMap.Keys.ToArray();
            foreach (string ekey in collectorEnergyMap.Keys)
            {
                //原来是通过消息头部取得,现在改为
                //data = float.Parse(collectorEnergyMap[ekey].ToString());
                //现在改为通过采集器的设备的今日电量来累加
                keyArr      = ekey.Split(':');
                collectorID = int.Parse(keyArr[0]);
                collector   = CollectorInfoService.GetInstance().Get(collectorID);
                data        = collector.TodayEnergy(keyArr[1] + keyArr[2] + keyArr[3]);

                //改为通过所含设备的
                year  = int.Parse(keyArr[1]);
                month = int.Parse(keyArr[2]);
                day   = int.Parse(keyArr[3]);
                string d_column = "d_" + day;

                //取得月天数据对象
                CollectorMonthDayData collectorMonthDayData = CollectorMonthDayDataService.GetInstance().GetCollectorMonthDayData(year, collectorID, month);
                collectorMonthDayData.curDay = day;
                //给相应属性赋值
                if (collectorMonthDayData != null)
                {
                    object ovalue = ReflectionUtil.getProperty(collectorMonthDayData, d_column);
                    //if (ovalue == null || float.Parse(ovalue.ToString()) < data)
                    //{
                    ReflectionUtil.setProperty(collectorMonthDayData, d_column, data);
                    //}
                }
                CollectorMonthDayDataService.GetInstance().Cache(collectorMonthDayData);

                //更新年月发电量数据
                //统计年月
                string m_column = "m_" + month;
                float? m_value  = collectorMonthDayData.count();
                CollectorYearMonthData ymdData = CollectorYearMonthDataService.GetInstance().GetCollectorYearMonthData(collectorID, year);;
                ymdData.curMonth = month;
                //给年月数据对象相应属性赋值
                if (ymdData != null)
                {
                    object ovalue = ReflectionUtil.getProperty(ymdData, m_column);
                    if (ovalue == null || float.Parse(ovalue.ToString()) < m_value)
                    {
                        ReflectionUtil.setProperty(ymdData, m_column, m_value);
                    }
                }
                CollectorYearMonthDataService.GetInstance().Cache(ymdData);

                //统计总体发电量
                float?            y_value = ymdData.count();
                CollectorYearData yd      = CollectorYearDataService.GetInstance().GetCollectorYearData(collectorID, year);
                if (yd == null)
                {
                    yd = new CollectorYearData()
                    {
                        dataValue = 0, collectorID = collectorID, year = year
                    }
                }
                ;
                yd.localAcceptTime = DateTime.Now;
                //给年月数据对象相应属性赋值
                if (yd != null)
                {
                    object ovalue = yd.dataValue;
                    if (ovalue == null || float.Parse(ovalue.ToString()) < y_value)
                    {
                        yd.dataValue = y_value == null ? 0 : float.Parse(y_value.ToString());
                    }
                }
                CollectorYearDataService.GetInstance().Cache(yd);
            }
        }
    }