/// <summary> /// 取得设备天数据列表 /// </summary> /// <returns></returns> public void getDeviceDayDataList() { if (this.listTcpbody != null && listTcpbody.Count > 0) { Device device = null; int collectorID = GetCollectorId(); DeviceDayData mdd = null; foreach (DeviceDataBase ddb in ListTcpbody) { try { int deviceID = GetDeviceId(collectorID, ddb.deviceAddress); int deviceT = 1; //根据协议类型取得说属大类型 if (ddb.deviceType == -1) { deviceT = DeviceData.getProtocolTypeByCode(ddb.protocolType).deviceType.code; } else { deviceT = ddb.deviceType; } if (deviceID == 0) { //构造设备 device = new Device(); device.collectorID = collectorID; device.deviceAddress = ddb.deviceAddress.ToString(); device.deviceTypeCode = deviceT; device.deviceModel = new DeviceModel() { code = ddb.deviceXh }; device.status = ddb.deviceState.ToString(); deviceID = DeviceService.GetInstance().Save(device); LogUtil.info("has new device,collectorID is " + collectorID + ",deviceAddress is " + device.deviceAddress); //有新设备要更新bank缓存 HttpClientUtil.requestUrl(bank_url); } else { //这里影响解析性能,出了型号会变,设备类型也会变所以也要更新 device = DeviceService.GetInstance().get(deviceID); if (ddb.deviceXh != device.deviceModelCode || (DeviceData.getProtocolTypeByCode(ddb.protocolType).typecode != device.deviceTypeCode)) { //型号有变化更新设备信息 device.deviceModelCode = ddb.deviceXh; device.deviceModel = new DeviceModel() { code = ddb.deviceXh }; device.deviceTypeCode = deviceT; //device.name = ""; LogUtil.info("has device update,collectorID is " + collectorID + ",deviceAddress is " + device.deviceAddress); DeviceService.GetInstance().Save(device); //设备类型编号也要更新bank缓存 HttpClientUtil.requestUrl(bank_url); } } //设置设备的发电量 if (ddb.todayEnergy > -1) { deviceEnergyMap[deviceID + ":" + messageHeader.year + messageHeader.month + messageHeader.day] = ddb.todayEnergy; } //设置设备的增量日照强度,参照发电量记录,用发电量的记录逻辑,因为发电量的设备id是逆变器,现在时环境监测仪所以不会重复,可以用发电量的结构 //如果增量日照强度大于0则表示有就记录下来,用于后面的累计 add by qianhb in 2012/01/13 if (ddb.todaySunshine > -1) { deviceEnergyMap[deviceID + ":" + messageHeader.year + messageHeader.month + messageHeader.day] = ddb.todaySunshine; } //这里需要改进为依据设备时间,防止设备数据的时间和采集器的时间是不一致的 string mapObjectKey; IDictionary<string, DeviceDayData> tmpdic = null; foreach (int key in ddb.historyMonitorMap.Keys) { tmpdic = devicedayDataMapList[deviceID % 50]; mapObjectKey = CacheKeyUtil.buildDeviceDayDataKey(deviceID, messageHeader.year + messageHeader.month, int.Parse(messageHeader.day), key); if (!tmpdic.ContainsKey(mapObjectKey)) { //先从缓存中取得 mdd = DeviceDayDataService.GetInstance().getDeviceDayData(deviceID, key, int.Parse(messageHeader.day), int.Parse(messageHeader.year), int.Parse(messageHeader.month)); if (mdd == null) mdd = new DeviceDayData() { deviceID = deviceID, sendDay = int.Parse(messageHeader.day), monitorCode = key, deviceType = ddb.tableType }; else { if (mdd.id == 0) LogUtil.warn("mdd id is 0" + deviceID + "-" + key + "-" + ddb.tableType); } tmpdic[mapObjectKey] = mdd; } else { mdd = tmpdic[mapObjectKey]; } //非持久化属性赋值,用于指定所在表 mdd.yearmonth = messageHeader.year + messageHeader.month; float newValue = ddb.historyMonitorMap[key] == null ? 0 : float.Parse(ddb.historyMonitorMap[key].ToString()); string tmpvalue = "#" + messageHeader.hour + messageHeader.minute + messageHeader.second + ":" + newValue; if (mdd.dataContent != null){//避免数据串有重复数据过大 if (!mdd.dataContent.Contains(tmpvalue)) mdd.dataContent += tmpvalue; } else { mdd.dataContent = tmpvalue; } mdd.sendtime = messageHeader.TimeNow; mdd.localAcceptTime = DateTime.Now; mdd.deviceType = ddb.tableType; mdd.changed = true; //add by qhb in 20120924 for 会写到memcahced 以便持久化能取到改数据.设备天数据集中缓存处有点问题, //导致曲线数据有丢失现象 MemcachedClientSatat.getInstance().Set(mapObjectKey, mdd); //将功率和关照的最大发生时间记录下来,稍后在优化下 if (key == MonitorType.MIC_INVERTER_TOTALYGPOWER || key == MonitorType.MIC_DETECTOR_SUNLINGHT || key == MonitorType.MIC_BUSBAR_TOTALCURRENT) { //LogUtil.warn("deviceDataCounts.Add(new DeviceDataCount(): id is " +deviceID+"-"+ messageHeader.year.ToString() + messageHeader + ""); deviceDataCounts.Add(new DeviceDataCount() { deviceId = deviceID, monitorCode = key, year = int.Parse(messageHeader.year), month = int.Parse(messageHeader.month), day = int.Parse(messageHeader.day), deviceTable = TableUtil.DEVICE, maxValue = newValue, maxTime = messageHeader.TimeNow, localAcceptTime = DateTime.Now }); } } } catch (Exception ee) { LogUtil.error(ee.Message); } } } }
/// <summary> /// 删除天数据,按照id /// add by qhb in 20120828 /// </summary> /// <param name="dayData"></param> /// <returns></returns> public bool Delete(DeviceDayData dayData) { return _DevicePowerDaydataDao.Remove(dayData) > 0 ? true : false; }