Exemplo n.º 1
0
        public static void peristentData()
        {
            Console.WriteLine("开始持久化");
            //持久化设备天数据
            try
            {
                DeviceDayDataService.GetInstance().batchSave(BaseMessage.devicedayDataMapList);
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化设备天数据异常:" + ee.Message);
            }

            //持久化采集器天数据
            try
            {
                CollectorDayDataService.GetInstance().batchSave(BaseMessage.collectordayDataMap);
            }
            catch (Exception ee) {
                LogUtil.error("持久化采集器天数据异常:" + ee.Message);
            }

            //持久化设备实时数据
            try{
                DeviceRunDataService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化设备实时数据数据异常:" + ee.Message);
            }
            //持久化采集器实时数据
            try
            {
                LogUtil.writeline("start 持久化采集器实时数据");
                CollectorRunDataService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化采集器实时数据异常:" + ee.Message);
            }

            //持久化最大值统计
            try{
                DeviceDataCountService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化最大值统计异常:" + ee.Message);
            }

            //持久化设备月天数据
            try{
                DeviceMonthDayDataService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化设备月天数据异常:" + ee.Message);
            }
            //持久化采集器月天数据
            try{
                CollectorMonthDayDataService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化采集器月天数据异常:" + ee.Message);
            }
            //持久化设备年月数据
            try{
                DeviceYearMonthDataService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化设备年月数据异常:" + ee.Message);
                //DeviceYearMonthDataService.GetInstance().batchSave();
            }
            //持久化采集器年月数据
            try{
                CollectorYearMonthDataService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化采集器年月数据异常:" + ee.Message);
            }
            //持久化设备总体数据
            try{
                DeviceYearDataService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化采集器年月数据异常:" + ee.Message);
            }
            //持久化采集器总体数据
            try
            {
                CollectorYearDataService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化采集器总体数据异常:" + ee.Message);
            }

            //add by qhb in 20120415 for 2.0协议持久化电站信息,持久化后不删除,
            try
            {
                PlantService.GetInstance().batchSave(BaseMessage.plantInfoMap);
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化电站信息数据异常:" + ee.Message);
            }

            //add by qhb in 20120715 for 2.0协议持久化设备信息,持久化后不删除,
            try
            {
                DeviceService.GetInstance().batchSave(BaseMessage.deviceInfoMap);
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化设备信息数据异常:" + ee.Message);
            }
        }
Exemplo n.º 2
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);
                }
            }
        }
Exemplo n.º 3
0
        public void peristentData()
        {
            Console.WriteLine("开始持久化");
            //持久化设备天数据
            try
            {
                DeviceDayDataService.GetInstance().batchSave(BaseMessage.devicedayDataMapList);
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化设备天数据异常:" + ee.Message);
            }
            //持久化采集器天数据
            try
            {
                CollectorDayDataService.GetInstance().batchSave(BaseMessage.collectordayDataMap);
            }
            catch (Exception ee) {
                LogUtil.error("持久化采集器天数据异常:" + ee.Message);
            }

            //持久化设备实时数据
            try{
                DeviceRunDataService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化设备实时数据数据异常:" + ee.Message);
            }
            //持久化采集器实时数据
            try
            {
                LogUtil.writeline("start 持久化采集器实时数据");
                CollectorRunDataService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化采集器实时数据异常:" + ee.Message);
            }

            //持久化最大值统计
            try{
                DeviceDataCountService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化最大值统计异常:" + ee.Message);
            }

            //持久化设备月天数据
            try{
                DeviceMonthDayDataService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化设备月天数据异常:" + ee.Message);
            }
            //持久化采集器月天数据
            try{
                CollectorMonthDayDataService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化采集器月天数据异常:" + ee.Message);
            }
            //持久化设备年月数据
            try{
                DeviceYearMonthDataService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化设备年月数据异常:" + ee.Message);
                DeviceYearMonthDataService.GetInstance().batchSave();
            }
            //持久化采集器年月数据
            try{
                CollectorYearMonthDataService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化采集器年月数据异常:" + ee.Message);
            }
            //持久化设备总体数据
            try{
                DeviceYearDataService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化采集器年月数据异常:" + ee.Message);
            }
            //持久化采集器总体数据
            try
            {
                CollectorYearDataService.GetInstance().batchSave();
            }
            catch (Exception ee)
            {
                LogUtil.error("持久化采集器总体数据异常:" + ee.Message);
            }
        }