using DataServer.api.EnergyEfficiency; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Net; using System.Net.Http; using System.Text; using System.Web.Http; namespace DongYingAPI.Controllers.api.EnergyEfficiency { public class GetItemizeEnergyController : ApiController { DataServer.BLL.device_info device_bll = new DataServer.BLL.device_info(); DataServer.BLL.electricity_data bll = new DataServer.BLL.electricity_data(); /// /// 获取分项能耗概况接口 /// /// public HttpResponseMessage Get() { var res = new get_itemize_energy_response(); try { //var now = DateTime.Now; //var device_list = device_bll.GetModelList(""); //var list = new List(); ////判断表是否存在,不存在就创建 //var date_base = ConfigurationManager.AppSettings["MySQLDataBase"].ToString(); //var start_date = DateTime.Parse(now.ToString("yyyy-MM-dd") + " 00:00:00"); //var time = now.ToString("yyyyMM"); //if (!bll.IsExistsTable(date_base, "electricity_data_" + time)) //{ // bll.CreateTable(time); //} //list = bll.GetList("(select ElectricityId,DeviceId,EH,P,Kvar,Ia,Ib,Ic,Ua,Ub,Uc,ServiceRating,CreateTime,EntireTime,Reserve1,Reserve2,Reserve3,Reserve4,Reserve5 from electricity_data_" + time + ")", " CreateTime>='" + start_date + "' and CreateTime<='" + now + "' ", ""); //var data = new List(); //foreach (var item in device_list) //{ // var model = new energy_consumption(); // model.DeviceName = item.DeviceName; // model.OperatingPower = list.Where(a => a.DeviceId == item.DeviceId).Sum(a => a.ServiceRating).Value; // data.Add(model); //} //res.code = 200; //res.msg = "成功"; //res.data = data; } catch (Exception ex) { res.code = 500; res.msg = "失败," + ex.Message; } HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(res), Encoding.GetEncoding("UTF-8"), "application/json") }; return result; } } }