/// <summary> /// 获取电站信息 /// </summary> /// <param name="pid">电站id</param> /// <param name="app_key">第三方应用唯一key</param> /// <param name="call_id">请求序号</param> /// <param name="sig">签名</param> /// <param name="v">api版本</param> /// <param name="format">返回结果格式,暂时值支持json</param> /// <param name="lan">语言环境,暂时只支持中英文</param> /// <returns></returns> public ActionResult plantinfo(int pid, string app_key, string call_id, string sig, string v, string format, string lan) { setlan(lan); Plant plant = PlantService.GetInstance().GetPlantInfoById(pid); PlantVO vo = new PlantVO(); if (plant != null) { vo.CQ2reduce = plant.Reductiong.ToString(); vo.CQ2reduceUnit = plant.ReductiongUnit; vo.curPower = plant.TodayTotalPower.ToString(); vo.curPowerUnit = "kW"; vo.dayEnergy = plant.DisplayTotalDayEnergy; vo.dayEnergyUnit = plant.TotalDayEnergyUnit; IList <int> workYears = CollectorYearDataService.GetInstance().GetWorkYears(new List <Plant>() { plant }); vo.logCount = FaultService.GetInstance().getNewLogNums(new List <Plant>() { plant }, workYears); vo.plantId = pid; vo.plantName = plant.name; vo.solarIntensity = plant.Sunstrength.ToString(); vo.solarIntensityUnit = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_LINGT_CODE).unit; //add by qhb in 20120106 for 增加逆变器数量 IList <Device> inverterDevices = plant.typeDevices(DeviceData.INVERTER_CODE); vo.inverterCount = inverterDevices.Count.ToString(); vo.inverterTypeStr = getMainType(inverterDevices, 3); string ts = ""; double t = plant.Temperature; User user = UserService.GetInstance().Get((int)plant.userID); if (t == 0) { CityCodeService codeService = CityCodeService.GetInstance(); t = codeService.GetTemperature(plant.city); if (!double.IsNaN(t)) { ts = t.ToString("0.0"); } } else { ts = t.ToString("0.0"); } if (user != null && !user.TemperatureType.ToLower().Equals("c")) { t = (32 + (t * 1.8)); ts = t.ToString("0.0"); } vo.temprature = ts; vo.tempratureUnit = user.TemperatureType.ToUpper(); vo.totalEnergy = plant.DisplayTotalEnergy; vo.totalEnergyUnit = plant.TotalEnergyUnit; vo.imageArray = "http://" + Request.Url.Authority + "/ufile/" + (string.IsNullOrEmpty(plant.onePic) ? "Nopic/nopico02.gif" : plant.onePic); vo.DesignPower = plant.design_power + " kWp"; vo.Country = plant.country; vo.City = plant.city; vo.organize = user.organize; vo.installDate = plant.installdate.ToString("yyyy-MM-dd"); } string data = JsonUtil.convertToJson(vo, typeof(PlantVO)); return(Content(data)); }
/// <summary> /// 获取电站信息 /// </summary> /// <param name="pid">电站id</param> /// <param name="app_key">第三方应用唯一key</param> /// <param name="call_id">请求序号</param> /// <param name="sig">签名</param> /// <param name="v">api版本</param> /// <param name="format">返回结果格式,暂时值支持json</param> /// <param name="lan">语言环境,暂时只支持中英文</param> /// <returns></returns> public ActionResult plantinfo(int pid, string app_key, string call_id, string sig, string v, string format, string lan) { setlan(lan); Plant plant = PlantService.GetInstance().GetPlantInfoById(pid); PlantVO vo = new PlantVO(); if (plant != null) { vo.CQ2reduce = plant.Reductiong.ToString(); vo.CQ2reduceUnit = plant.ReductiongUnit; vo.curPower = plant.TodayTotalPower.ToString(); vo.curPowerUnit = "kW"; vo.dayEnergy = plant.DisplayTotalDayEnergy; vo.dayEnergyUnit = plant.TotalDayEnergyUnit; IList<int> workYears = CollectorYearDataService.GetInstance().GetWorkYears(new List<Plant>() { plant }); vo.logCount = FaultService.GetInstance().getNewLogNums(new List<Plant>() { plant }, workYears); vo.plantId = pid; vo.plantName = plant.name; vo.solarIntensity = plant.Sunstrength==null?"":plant.Sunstrength.ToString(); vo.solarIntensityUnit = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_LINGT_CODE).unit; //add by qhb in 20120106 for 增加逆变器数量 IList<Device> inverterDevices = plant.typeDevices(DeviceData.INVERTER_CODE); vo.inverterCount = inverterDevices.Count.ToString(); vo.inverterTypeStr = getMainType(inverterDevices, 3); string ts = ""; double t = plant.Temperature; User user = UserService.GetInstance().Get((int)plant.userID); if (t == 0) { CityCodeService codeService = CityCodeService.GetInstance(); t = codeService.GetTemperature(plant.city); if (!double.IsNaN(t)) { ts = t.ToString("0.0"); } } else { ts = t.ToString("0.0"); } if (user != null && !user.TemperatureType.ToLower().Equals("c")) { t = (32 + (t * 1.8)); ts = t.ToString("0.0"); } vo.temprature = ts; vo.tempratureUnit = user.TemperatureType.ToUpper(); vo.totalEnergy = plant.DisplayTotalEnergy; vo.totalEnergyUnit = plant.TotalEnergyUnit; vo.imageArray = "http://" + Request.Url.Authority + "/ufile/" + (string.IsNullOrEmpty(plant.onePic) ? "Nopic/nopico02.gif" : plant.onePic); vo.DesignPower = plant.design_power + " kWp"; vo.Country = plant.country; vo.City = plant.city; vo.organize = user.organize; vo.installDate = plant.installdate.ToString("yyyy-MM-dd"); } string data = JsonUtil.convertToJson(vo, typeof(PlantVO)); return Content(data); }
/// <summary> /// 取得电站信息 /// </summary> /// <param name="plantId"></param> /// <returns></returns> public static PlantVO getPlantInfo(string plantId) { PlantVO pvo = null; DateTime lastDate = dataDateMap.ContainsKey(plantId) ? dataDateMap[plantId] : DateTime.Now; if (lastDate.AddMinutes(30) > DateTime.Now) { pvo = dataItemMap.ContainsKey(plantId) ? dataItemMap[plantId] : null; } if (pvo != null) { return(pvo); } string filename = System.Environment.CurrentDirectory + "/data/info/" + plantId; try { string jsonStr = JsonUtil.loadJsonStr(string.Format("/openapi/plantinfo?pid={0}", plantId), "en-us"); pvo = JsonUtil.Deserialize <PlantVO>(jsonStr); if (pvo == null) { pvo = new PlantVO(); if (File.Exists(filename)) { try { XMLHelper.DeserializerXML <PlantVO>(filename, ref pvo); } catch (Exception eee) { Console.WriteLine(eee.StackTrace); pvo = null; } } else { return(null); } } else { dataDateMap[plantId] = DateTime.Now; dataItemMap[plantId] = pvo; //写入本地缓存 try { if (pvo != null) { XMLHelper.SerializerXML <PlantVO>(filename, pvo); } } catch (Exception eee) { Console.WriteLine(eee.StackTrace); } } } catch (Exception e2) { LogUtil.error("getPlantInfo error:" + e2.StackTrace); return(null); } return(pvo); }