/// <summary> /// 初始化历史记录列表 /// </summary> private void InitDeviceData() { this.listView1.Items.Clear(); List <DeviceData> list = DeviceData.FindAll(); foreach (var log in list) { var strings = new string[] { log.Code1, log.Code2, log.Code3, log.SensorDeviceUnitName, log.CreateTime.ToString() }; var listViewItem = new ListViewItem(strings); listViewItem.Tag = log; this.listView1.Items.Add(listViewItem); } }
/// <summary> /// The upload data 2. /// </summary> /// <param name="totalDatainfoList"> /// The total datainfo list. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> private static bool UploadData(out EntityList<DeviceData> totalDatainfoList) { var exp = new WhereExpression(DeviceData<DeviceData>._.Upload == false); // 所有上传的DataInfo前20条数据记录集合 List<DeviceData> tempList = totalDatainfoList = DeviceData.FindAll(exp, DeviceData<DeviceData>._.CreateTime.Asc(), null, 0, 20); var syncResult = false; string farmCode = null; var collectData = new CollectDataBlock(); ////采集数据 //var deviceUnits = // FacilitySensorDeviceUnit.FindAllWithCache() // .ToList() // .Where(c => c.Code1.Substring(13, 1).EqualIgnoreCase("C")); //分批上传设备数据 const int size = 10; //var facilitySensorDeviceUnits = deviceUnits as FacilitySensorDeviceUnit[] ?? deviceUnits.ToArray(); var count = tempList.Count()/size; if (tempList.Count()%size > 0) count++; for (var i = 0; i < count; i++) { var list = tempList.Skip(i*size).Take(size); var sendDatas = list.Select(fsd => { farmCode = fsd.SensorDeviceUnit.FacilitySensorDeviceUnits[0].Facility.Farm.Code1; var code1 = fsd.Code1; var sd = new SensorData { DeviceCode = code1, Value = fsd.SensorDeviceUnit.ProcessedValue, ShowValue = fsd.SensorDeviceUnit.ShowValue }; //var mediaDatas = list.Select(); //sd.DeviceType = fsd.SensorDeviceUnit.Sensor.DeviceTypeSerialnum; //sd.FacilityCode = fsd.Facility.Code1; //sd.Unit = fsd.SensorDeviceUnit.Sensor.Unit; //#if DEBUG if ( DateTime.Now.Subtract(fsd.SensorDeviceUnit.UpdateTime) .TotalMinutes > 10) { var ran = new Random(DateTime.Now.Minute); var c = ran.Next(10, 100); sd.Value = fsd.SensorDeviceUnit.ProcessedValue + c*0.01M; sd.ShowValue = sd.Value + ""; } sd.Time = fsd.CreateTime; //设施编码+更新时间//批次号 sd.BatchNum = fsd.SensorDeviceUnit.FacilitySensorDeviceUnits[0].Facility.Code1.Substring(0, 13) + "-" + sd.Time; //#else // sd.Time = fsd.SensorDeviceUnit.UpdateTime; //#endif return sd; }).ToList(); collectData.SensorDatas = sendDatas; var entity = AwEntityHelper.GetEntity(farmCode, "上传设备数据"); #if DEBUG var sw = new Stopwatch(); sw.Start(); #endif var trans = ApiTransportHelper.GetTransport(); var result = _deviceApi.UploadDeviceData(entity, trans, collectData); trans.Dispose(); syncResult = result; LogHelper.Debug("上传设备数据:{0}", result ? "成功" : "失败"); #if DEBUG sw.Stop(); var apiAccesslog = new ApiAccessLog { ApiName = "上传设备数据", Result = result, CreateTime = DateTime.Now, CostTime = Convert.ToInt32(sw.ElapsedMilliseconds) }; apiAccesslog.Save(); LogHelper.Debug("上传设备数据耗时" + sw.ElapsedMilliseconds.ToString() + "ms"); } #endif //return syncResult; return true; }