public static List <TimeVoltage> dataTransfer(IQueryable <object> records) { List <TimeVoltage> tvoltages = new List <TimeVoltage>(); foreach (Object o in records) { var time = (DateTime)o.GetType().GetProperty("datatime").GetValue(o); var stationid = (string)o.GetType().GetProperty("stationid").GetValue(o); var voltage = (decimal?)o.GetType().GetProperty("data").GetValue(o); var transtyp = (string)o.GetType().GetProperty("transtype").GetValue(o); TimeVoltage timeVoltage = new TimeVoltage(time, voltage.HasValue ? (decimal)voltage : -1) { }; timeVoltage.transtype = transtyp; tvoltages.Add(timeVoltage); //twaters.Add(new TimeRiver(time, waterstage.HasValue ? (decimal)waterstage : -1, waterflow.HasValue ? (decimal)waterflow : -1) { waterStage = waterstage.HasValue ? (decimal)waterstage : -1, waterFlow = waterflow.HasValue ? (decimal)waterflow : -1 }); } return(tvoltages); }
/// <summary> /// 原始库单站电压数据查询 /// </summary> /// <param name="fromTime"></param> /// <param name="toTime"></param> /// <param name="stationIds"></param> /// <returns></returns> public static QueryResult ListHourVoltage(DateTime fromTime, DateTime toTime, string id) { //查询为空 if (id == null) { return(new QueryResult()); } //传递得参数 Dictionary <string, object> param = new Dictionary <string, object>(); //TODO添加datatime转string timeStart timeEnd //查询条件 Dictionary <string, string> paramInner = new Dictionary <string, string>(); paramInner["stationid"] = id; paramInner["strttime"] = fromTime.ToString(); paramInner["endtime"] = toTime.ToString(); //返回结果 QueryResult result = new QueryResult(); List <VoltageDbData> voltageList = new List <VoltageDbData>(); //string suffix = "/subcenter/getSubcenter"; string url = suffix + "/voltage/getVoltageBS"; //string url = "http://127.0.0.1:8088/voltage/getVoltageBS"; string jsonStr = HttpHelper.SerializeDictionaryToJsonString(paramInner); param["voltage"] = jsonStr; try { string resultJson = HttpHelper.Post(url, param); voltageList = (List <VoltageDbData>)HttpHelper.JsonDeserialize <List <VoltageDbData> >(resultJson, new List <VoltageDbData>()); } catch (Exception e) { Debug.WriteLine("查询电压信息失败"); throw e; } //处理数据 Station station = StationService.GetStationByRawId(id); TimeRecord record = new TimeRecord { stationId = station.id, stationName = station.stationName, stationType = station.stationType }; List <TimeVoltage> tvoltages = new List <TimeVoltage>(); foreach (VoltageDbData voltage in voltageList) { TimeVoltage timeVoltage = new TimeVoltage(voltage.datatime, voltage.data); timeVoltage.time = voltage.datatime; timeVoltage.voltage = voltage.data.HasValue ? voltage.data.Value : 0; tvoltages.Add(timeVoltage); } record.tvoltages = tvoltages; record.tvoltages = record.tvoltages.OrderByDescending(r => r.time).ToList(); result.records.Add(record); return(result); ////获取数据 ////List<VoltageDbData> voltageRecord = ListRawHourVoltage(fromTime, toTime, id); //QueryResult result = new QueryResult(); //Station station = StationService.GetStationByRawId(id); //TimeRecord record = new TimeRecord { stationId = station.id, stationName = station.stationName, stationType = station.stationType }; //List<TimeVoltage> tvoltages = new List<TimeVoltage>(); //LNRRDB ln = new LNRRDB(); //List<string> tableNameList = TableNameHelper.getTableName("voltage", fromTime, toTime); //#region 循环获取所有数据 辣鸡代码,不是gm写的 //foreach (string tableName in tableNameList) //{ // switch (tableName) // { // case "voltage20188A": // var voltagerecords20188A = from voltage in ln.voltage20188A where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages20188A = dataTransfer(voltagerecords20188A); // tvoltages.AddRange(voltages20188A); // break; // case "voltage20188B": // var voltagerecords20188B = from voltage in ln.voltage20188B where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages20188B = dataTransfer(voltagerecords20188B); // tvoltages.AddRange(voltages20188B); // break; // case "voltage20189A": // var voltagerecords20189A = from voltage in ln.voltage20189A where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages20189A = dataTransfer(voltagerecords20189A); // tvoltages.AddRange(voltages20189A); // break; // case "voltage20189B": // var voltagerecords20189B = from voltage in ln.voltage20189B where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages20189B = dataTransfer(voltagerecords20189B); // tvoltages.AddRange(voltages20189B); // break; // case "voltage201810A": // var voltagerecords201810A = from voltage in ln.voltage201810A where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages201810A = dataTransfer(voltagerecords201810A); // tvoltages.AddRange(voltages201810A); // break; // case "voltage201810B": // var voltagerecords201810B = from voltage in ln.voltage201810B where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages201810B = dataTransfer(voltagerecords201810B); // tvoltages.AddRange(voltages201810B); // break; // case "voltage201811A": // var voltagerecords201811A = from voltage in ln.voltage201811A where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages201811A = dataTransfer(voltagerecords201811A); // tvoltages.AddRange(voltages201811A); // break; // case "voltage201811B": // var voltagerecords201811B = from voltage in ln.voltage201811B where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages201811B = dataTransfer(voltagerecords201811B); // tvoltages.AddRange(voltages201811B); // break; // case "voltage201812A": // var voltagerecords201812A = from voltage in ln.voltage201812A where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages201812A = dataTransfer(voltagerecords201812A); // tvoltages.AddRange(voltages201812A); // break; // case "voltage201812B": // var voltagerecords201812B = from voltage in ln.voltage201812B where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages201812B = dataTransfer(voltagerecords201812B); // tvoltages.AddRange(voltages201812B); // break; // case "voltage20191A": // var voltagerecords20191A = from voltage in ln.voltage20191A where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages20191A = dataTransfer(voltagerecords20191A); // tvoltages.AddRange(voltages20191A); // break; // case "voltage20191B": // var voltagerecords20191B = from voltage in ln.voltage20191B where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages20191B = dataTransfer(voltagerecords20191B); // tvoltages.AddRange(voltages20191B); // break; // case "voltage20192A": // var voltagerecords20192A = from voltage in ln.voltage20192A where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages20192A = dataTransfer(voltagerecords20192A); // tvoltages.AddRange(voltages20192A); // break; // case "voltage20192B": // var voltagerecords20192B = from voltage in ln.voltage20192B where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages20192B = dataTransfer(voltagerecords20192B); // tvoltages.AddRange(voltages20192B); // break; // case "voltage20193A": // var voltagerecords20193A = from voltage in ln.voltage20193A where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages20193A = dataTransfer(voltagerecords20193A); // tvoltages.AddRange(voltages20193A); // break; // case "voltage20193B": // var voltagerecords20193B = from voltage in ln.voltage20193B where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages20193B = dataTransfer(voltagerecords20193B); // tvoltages.AddRange(voltages20193B); // break; // case "voltage20194A": // var voltagerecords20194A = from voltage in ln.voltage20194A where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages20194A = dataTransfer(voltagerecords20194A); // tvoltages.AddRange(voltages20194A); // break; // case "voltage20194B": // var voltagerecords20194B = from voltage in ln.voltage20194B where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages20194B = dataTransfer(voltagerecords20194B); // tvoltages.AddRange(voltages20194B); // break; // case "voltage20195A": // var voltagerecords20195A = from voltage in ln.voltage20195A where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages20195A = dataTransfer(voltagerecords20195A); // tvoltages.AddRange(voltages20195A); // break; // case "voltage20195B": // var voltagerecords20195B = from voltage in ln.voltage20195B where id == voltage.stationid && voltage.datatime <= toTime && voltage.datatime >= fromTime select voltage; // List<TimeVoltage> voltages20195B = dataTransfer(voltagerecords20195B); // tvoltages.AddRange(voltages20195B); // break; // default: // break; // } //} //record.tvoltages = tvoltages; //#endregion ////List<Models.VoltageDbData> singleStationRecord = new List<VoltageDbData>(); ////singleStationRecord = voltageRecord.Where(r => r.stationid.Equals(id)).OrderByDescending(r => r.datatime).ToList(); //////数据处理 ////Station station = StationService.GetStationByRawId(id); ////TimeRecord record = new TimeRecord { stationId = station.id, stationName = station.stationName, stationType = station.stationType }; ////foreach (var r in singleStationRecord) ////{ //// TimeVoltage tv = new TimeVoltage(r.datatime, r.data); //// record.tvoltages.Add(tv); ////} //record.tvoltages = record.tvoltages.OrderByDescending(r => r.time).ToList(); //result.records.Add(record); //return result; }