Пример #1
0
        /// <summary>
        /// 放入缓存
        /// </summary>
        /// <param name="deviceYearData"></param>
        public void Cache(DeviceYearData deviceYearData)
        {
            string cacheKey = CacheKeyUtil.buildDeviceEnergyTotalCountKey(deviceYearData.deviceID, deviceYearData.year);

            if (!persistentListKey.Contains(cacheKey)) persistentListKey.Add(cacheKey);

            MemcachedClientSatat.getInstance().Set(cacheKey, deviceYearData);
        }
Пример #2
0
        /// <summary>
        /// 判断
        /// </summary>
        /// <param name="deviceID"></param>
        /// <param name="monitorCode"></param>
        /// <param name="year"></param>
        /// <returns></returns>
        public DeviceYearData GetDeviceYearData(int deviceID, int year)
        {
            string cacheKey = CacheKeyUtil.buildDeviceEnergyTotalCountKey(deviceID, year);
            object obj = MemcachedClientSatat.getInstance().Get(cacheKey);

            DeviceYearData deviceYearData;
            if (obj == null)
            {//从数据库中取得
                deviceYearData = _deviceTotalDataDao.Get(deviceID, year);
                if (deviceYearData == null)//构造一个新实例
                    deviceYearData = new DeviceYearData() { year = year, deviceID = deviceID , dataValue=0 };
                deviceYearData.localAcceptTime = DateTime.Now;
                MemcachedClientSatat.getInstance().Set(cacheKey, deviceYearData);
            }
            else
                deviceYearData = (DeviceYearData)obj;

            return deviceYearData;
        }
Пример #3
0
 /// <summary>
 /// 保存年度数据
 /// </summary>
 /// <param name="yeardata"></param>
 public void SaveTotalData(DeviceYearData yeardata)
 {
     DeviceYearData data = GetDeviceYearData(yeardata.deviceID, yeardata.year);
     if (null == data)
     {
         _deviceTotalDataDao.Insert(yeardata);
     }
     else
     {
         yeardata.id = data.id;
         _deviceTotalDataDao.Update(yeardata);
     }
 }
Пример #4
0
        /// <summary>
        /// 缓存设备发电量统计
        /// 要进行修正缓存丢失
        /// </summary>
        /// <param name="tcpmessage"></param>
        private static void CacheDeviceEnergyData(IDictionary<string, double> deviceEnergyMap)
        {
            int deviceID;
            string yearMonth;
            int year;
            int month;
            int day;
            float? data;
            //string[] keys = deviceEnergyMap.Keys.ToArray();
            foreach (string ekey in deviceEnergyMap.Keys)
            {
                try
                {
                    deviceID = int.Parse(ekey.Split(':')[0]);
                    yearMonth = ekey.Split(':')[1];
                    year = int.Parse(yearMonth.Substring(0, 4));
                    month = int.Parse(yearMonth.Substring(4, 2));
                    day = int.Parse(yearMonth.Substring(6, 2));
                    data = float.Parse(deviceEnergyMap[ekey].ToString());
                    string d_column = "d_" + day;

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

                    //更新年月发电量数据
                    //统计年月
                    string m_column = "m_" + month;
                    float? m_value = deviceMonthDayData.count();
                    DeviceYearMonthData ymdData = DeviceYearMonthDataService.GetInstance().GetDeviceYearMonthData(deviceID, 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);
                        }
                    }
                    DeviceYearMonthDataService.GetInstance().Cache(ymdData);

                    //统计总体发电量
                    float? y_value = ymdData.count();
                    DeviceYearData yd = DeviceYearDataService.GetInstance().GetDeviceYearData(deviceID, year);
                    if (yd == null) yd = new DeviceYearData() { dataValue = 0, deviceID = deviceID, 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());
                        }
                    }
                    DeviceYearDataService.GetInstance().Cache(yd);
                }
                catch (Exception onee) {//捕获单个异常,保证一个错误不影响其他设备数据处理
                    LogUtil.error("Cache deviceEnergyMap of ekey is " + ekey + " error:" + onee.Message);
                }
            }
        }