From c226764c38e56da9f7fecf76781dc5916ae9b374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E8=89=B3?= <2836604403@qq.com> Date: Tue, 9 Jan 2024 13:31:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E8=8E=B7=E5=8F=96=E8=8A=82?= =?UTF-8?q?=E8=83=BD=E9=87=8F=EF=BC=88=E8=8A=82=E7=94=B5=E7=8E=87=EF=BC=89?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E3=80=81=E8=8E=B7=E5=8F=96=E7=94=B5=E8=B4=B9?= =?UTF-8?q?=E7=94=B5=E4=BB=B7=E6=8E=A5=E5=8F=A3=E3=80=81=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E8=BF=90=E8=A1=8C=E6=83=85=E5=86=B5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataServer/BLL/device_operation.cs | 24 ++++----- DataServer/BLL/electricity_price.cs | 26 +++++----- DataServer/DAL/device_operation.cs | 14 ++--- DataServer/DAL/electricity_price.cs | 38 +++++++------- DataServer/Model/device_operation.cs | 2 +- DataServer/Model/electricity_price.cs | 12 ++--- .../get_amount_energy_response.cs | 27 ++++++++++ .../get_device_operation_response.cs | 14 +++++ .../get_electricity_price_response.cs | 32 ++++++++++++ .../GetAmountEnergyController.cs | 26 +++++++++- .../GetDeviceOperationController.cs | 28 +++++++++- .../GetElectricityPriceController.cs | 48 +++++++++++++++++- ...DongYingAPI.csproj.AssemblyReference.cache | Bin 82644 -> 102311 bytes 13 files changed, 230 insertions(+), 61 deletions(-) diff --git a/DataServer/BLL/device_operation.cs b/DataServer/BLL/device_operation.cs index 1899c8b..e8233c5 100644 --- a/DataServer/BLL/device_operation.cs +++ b/DataServer/BLL/device_operation.cs @@ -18,15 +18,15 @@ using System; using System.Data; using System.Collections.Generic; using Maticsoft.Common; -using DataService.Model; -namespace DataService.BLL +using DataServer.Model; +namespace DataServer.BLL { /// /// device_operation /// public partial class device_operation { - private readonly DataService.DAL.device_operation dal=new DataService.DAL.device_operation(); + private readonly DataServer.DAL.device_operation dal=new DataServer.DAL.device_operation(); public device_operation() {} #region BasicMethod @@ -41,7 +41,7 @@ namespace DataService.BLL /// /// 增加一条数据 /// - public bool Add(DataService.Model.device_operation model) + public bool Add(DataServer.Model.device_operation model) { return dal.Add(model); } @@ -49,7 +49,7 @@ namespace DataService.BLL /// /// 更新一条数据 /// - public bool Update(DataService.Model.device_operation model) + public bool Update(DataServer.Model.device_operation model) { return dal.Update(model); } @@ -73,7 +73,7 @@ namespace DataService.BLL /// /// 得到一个对象实体 /// - public DataService.Model.device_operation GetModel(string OperationId) + public DataServer.Model.device_operation GetModel(string OperationId) { return dal.GetModel(OperationId); @@ -82,7 +82,7 @@ namespace DataService.BLL /// /// 得到一个对象实体,从缓存中 /// - public DataService.Model.device_operation GetModelByCache(string OperationId) + public DataServer.Model.device_operation GetModelByCache(string OperationId) { string CacheKey = "device_operationModel-" + OperationId; @@ -100,7 +100,7 @@ namespace DataService.BLL } catch{} } - return (DataService.Model.device_operation)objModel; + return (DataServer.Model.device_operation)objModel; } /// @@ -113,7 +113,7 @@ namespace DataService.BLL /// /// 获得数据列表 /// - public List GetModelList(string strWhere) + public List GetModelList(string strWhere) { DataSet ds = dal.GetList(strWhere); return DataTableToList(ds.Tables[0]); @@ -121,13 +121,13 @@ namespace DataService.BLL /// /// 获得数据列表 /// - public List DataTableToList(DataTable dt) + public List DataTableToList(DataTable dt) { - List modelList = new List(); + List modelList = new List(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { - DataService.Model.device_operation model; + DataServer.Model.device_operation model; for (int n = 0; n < rowsCount; n++) { model = dal.DataRowToModel(dt.Rows[n]); diff --git a/DataServer/BLL/electricity_price.cs b/DataServer/BLL/electricity_price.cs index f242666..14425fb 100644 --- a/DataServer/BLL/electricity_price.cs +++ b/DataServer/BLL/electricity_price.cs @@ -6,7 +6,7 @@ * * Ver 变更日期 负责人 变更内容 * ─────────────────────────────────── -* V0.01 2024/1/9 10:06:20 N/A 初版 +* V0.01 2024/1/9 11:09:28 N/A 初版 * * Copyright (c) 2012 Maticsoft Corporation. All rights reserved. *┌──────────────────────────────────┐ @@ -18,15 +18,15 @@ using System; using System.Data; using System.Collections.Generic; using Maticsoft.Common; -using DataService.Model; -namespace DataService.BLL +using DataServer.Model; +namespace DataServer.BLL { /// /// electricity_price /// public partial class electricity_price { - private readonly DataService.DAL.electricity_price dal=new DataService.DAL.electricity_price(); + private readonly DataServer.DAL.electricity_price dal=new DataServer.DAL.electricity_price(); public electricity_price() {} #region BasicMethod @@ -41,7 +41,7 @@ namespace DataService.BLL /// /// 增加一条数据 /// - public bool Add(DataService.Model.electricity_price model) + public bool Add(DataServer.Model.electricity_price model) { return dal.Add(model); } @@ -49,7 +49,7 @@ namespace DataService.BLL /// /// 更新一条数据 /// - public bool Update(DataService.Model.electricity_price model) + public bool Update(DataServer.Model.electricity_price model) { return dal.Update(model); } @@ -73,7 +73,7 @@ namespace DataService.BLL /// /// 得到一个对象实体 /// - public DataService.Model.electricity_price GetModel(string PriceId) + public DataServer.Model.electricity_price GetModel(string PriceId) { return dal.GetModel(PriceId); @@ -82,7 +82,7 @@ namespace DataService.BLL /// /// 得到一个对象实体,从缓存中 /// - public DataService.Model.electricity_price GetModelByCache(string PriceId) + public DataServer.Model.electricity_price GetModelByCache(string PriceId) { string CacheKey = "electricity_priceModel-" + PriceId; @@ -100,7 +100,7 @@ namespace DataService.BLL } catch{} } - return (DataService.Model.electricity_price)objModel; + return (DataServer.Model.electricity_price)objModel; } /// @@ -113,7 +113,7 @@ namespace DataService.BLL /// /// 获得数据列表 /// - public List GetModelList(string strWhere) + public List GetModelList(string strWhere) { DataSet ds = dal.GetList(strWhere); return DataTableToList(ds.Tables[0]); @@ -121,13 +121,13 @@ namespace DataService.BLL /// /// 获得数据列表 /// - public List DataTableToList(DataTable dt) + public List DataTableToList(DataTable dt) { - List modelList = new List(); + List modelList = new List(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { - DataService.Model.electricity_price model; + DataServer.Model.electricity_price model; for (int n = 0; n < rowsCount; n++) { model = dal.DataRowToModel(dt.Rows[n]); diff --git a/DataServer/DAL/device_operation.cs b/DataServer/DAL/device_operation.cs index 20911fd..61f3b9e 100644 --- a/DataServer/DAL/device_operation.cs +++ b/DataServer/DAL/device_operation.cs @@ -19,7 +19,7 @@ using System.Data; using System.Text; using MySql.Data.MySqlClient; using Maticsoft.DBUtility;//Please add references -namespace DataService.DAL +namespace DataServer.DAL { /// /// 数据访问类:device_operation @@ -49,7 +49,7 @@ namespace DataService.DAL /// /// 增加一条数据 /// - public bool Add(DataService.Model.device_operation model) + public bool Add(DataServer.Model.device_operation model) { StringBuilder strSql=new StringBuilder(); strSql.Append("insert into device_operation("); @@ -91,7 +91,7 @@ namespace DataService.DAL /// /// 更新一条数据 /// - public bool Update(DataService.Model.device_operation model) + public bool Update(DataServer.Model.device_operation model) { StringBuilder strSql=new StringBuilder(); strSql.Append("update device_operation set "); @@ -184,7 +184,7 @@ namespace DataService.DAL /// /// 得到一个对象实体 /// - public DataService.Model.device_operation GetModel(string OperationId) + public DataServer.Model.device_operation GetModel(string OperationId) { StringBuilder strSql=new StringBuilder(); @@ -194,7 +194,7 @@ namespace DataService.DAL new MySqlParameter("@OperationId", MySqlDbType.VarChar,50) }; parameters[0].Value = OperationId; - DataService.Model.device_operation model=new DataService.Model.device_operation(); + DataServer.Model.device_operation model=new DataServer.Model.device_operation(); DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { @@ -210,9 +210,9 @@ namespace DataService.DAL /// /// 得到一个对象实体 /// - public DataService.Model.device_operation DataRowToModel(DataRow row) + public DataServer.Model.device_operation DataRowToModel(DataRow row) { - DataService.Model.device_operation model=new DataService.Model.device_operation(); + DataServer.Model.device_operation model=new DataServer.Model.device_operation(); if (row != null) { if(row["OperationId"]!=null) diff --git a/DataServer/DAL/electricity_price.cs b/DataServer/DAL/electricity_price.cs index 5db2491..e403b98 100644 --- a/DataServer/DAL/electricity_price.cs +++ b/DataServer/DAL/electricity_price.cs @@ -6,7 +6,7 @@ * * Ver 变更日期 负责人 变更内容 * ─────────────────────────────────── -* V0.01 2024/1/9 10:06:20 N/A 初版 +* V0.01 2024/1/9 11:09:28 N/A 初版 * * Copyright (c) 2012 Maticsoft Corporation. All rights reserved. *┌──────────────────────────────────┐ @@ -19,7 +19,7 @@ using System.Data; using System.Text; using MySql.Data.MySqlClient; using Maticsoft.DBUtility;//Please add references -namespace DataService.DAL +namespace DataServer.DAL { /// /// 数据访问类:electricity_price @@ -49,18 +49,18 @@ namespace DataService.DAL /// /// 增加一条数据 /// - public bool Add(DataService.Model.electricity_price model) + public bool Add(DataServer.Model.electricity_price model) { StringBuilder strSql=new StringBuilder(); strSql.Append("insert into electricity_price("); - strSql.Append("PriceId,Cost,UnitPrice,AcquisitionTime,Remark1,Remark2,Remark3,Remark4,Remark5)"); + strSql.Append("PriceId,Cost,UnitPrice,Month,Remark1,Remark2,Remark3,Remark4,Remark5)"); strSql.Append(" values ("); - strSql.Append("@PriceId,@Cost,@UnitPrice,@AcquisitionTime,@Remark1,@Remark2,@Remark3,@Remark4,@Remark5)"); + strSql.Append("@PriceId,@Cost,@UnitPrice,@Month,@Remark1,@Remark2,@Remark3,@Remark4,@Remark5)"); MySqlParameter[] parameters = { new MySqlParameter("@PriceId", MySqlDbType.VarChar,50), new MySqlParameter("@Cost", MySqlDbType.Decimal,10), new MySqlParameter("@UnitPrice", MySqlDbType.Decimal,10), - new MySqlParameter("@AcquisitionTime", MySqlDbType.DateTime), + new MySqlParameter("@Month", MySqlDbType.Int32), new MySqlParameter("@Remark1", MySqlDbType.VarChar,255), new MySqlParameter("@Remark2", MySqlDbType.VarChar,255), new MySqlParameter("@Remark3", MySqlDbType.VarChar,255), @@ -69,7 +69,7 @@ namespace DataService.DAL parameters[0].Value = model.PriceId; parameters[1].Value = model.Cost; parameters[2].Value = model.UnitPrice; - parameters[3].Value = model.AcquisitionTime; + parameters[3].Value = model.Month; parameters[4].Value = model.Remark1; parameters[5].Value = model.Remark2; parameters[6].Value = model.Remark3; @@ -89,13 +89,13 @@ namespace DataService.DAL /// /// 更新一条数据 /// - public bool Update(DataService.Model.electricity_price model) + public bool Update(DataServer.Model.electricity_price model) { StringBuilder strSql=new StringBuilder(); strSql.Append("update electricity_price set "); strSql.Append("Cost=@Cost,"); strSql.Append("UnitPrice=@UnitPrice,"); - strSql.Append("AcquisitionTime=@AcquisitionTime,"); + strSql.Append("Month=@Month,"); strSql.Append("Remark1=@Remark1,"); strSql.Append("Remark2=@Remark2,"); strSql.Append("Remark3=@Remark3,"); @@ -105,7 +105,7 @@ namespace DataService.DAL MySqlParameter[] parameters = { new MySqlParameter("@Cost", MySqlDbType.Decimal,10), new MySqlParameter("@UnitPrice", MySqlDbType.Decimal,10), - new MySqlParameter("@AcquisitionTime", MySqlDbType.DateTime), + new MySqlParameter("@Month", MySqlDbType.Int32), new MySqlParameter("@Remark1", MySqlDbType.VarChar,255), new MySqlParameter("@Remark2", MySqlDbType.VarChar,255), new MySqlParameter("@Remark3", MySqlDbType.VarChar,255), @@ -114,7 +114,7 @@ namespace DataService.DAL new MySqlParameter("@PriceId", MySqlDbType.VarChar,50)}; parameters[0].Value = model.Cost; parameters[1].Value = model.UnitPrice; - parameters[2].Value = model.AcquisitionTime; + parameters[2].Value = model.Month; parameters[3].Value = model.Remark1; parameters[4].Value = model.Remark2; parameters[5].Value = model.Remark3; @@ -179,17 +179,17 @@ namespace DataService.DAL /// /// 得到一个对象实体 /// - public DataService.Model.electricity_price GetModel(string PriceId) + public DataServer.Model.electricity_price GetModel(string PriceId) { StringBuilder strSql=new StringBuilder(); - strSql.Append("select PriceId,Cost,UnitPrice,AcquisitionTime,Remark1,Remark2,Remark3,Remark4,Remark5 from electricity_price "); + strSql.Append("select PriceId,Cost,UnitPrice,Month,Remark1,Remark2,Remark3,Remark4,Remark5 from electricity_price "); strSql.Append(" where PriceId=@PriceId "); MySqlParameter[] parameters = { new MySqlParameter("@PriceId", MySqlDbType.VarChar,50) }; parameters[0].Value = PriceId; - DataService.Model.electricity_price model=new DataService.Model.electricity_price(); + DataServer.Model.electricity_price model=new DataServer.Model.electricity_price(); DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { @@ -205,9 +205,9 @@ namespace DataService.DAL /// /// 得到一个对象实体 /// - public DataService.Model.electricity_price DataRowToModel(DataRow row) + public DataServer.Model.electricity_price DataRowToModel(DataRow row) { - DataService.Model.electricity_price model=new DataService.Model.electricity_price(); + DataServer.Model.electricity_price model=new DataServer.Model.electricity_price(); if (row != null) { if(row["PriceId"]!=null) @@ -222,9 +222,9 @@ namespace DataService.DAL { model.UnitPrice=decimal.Parse(row["UnitPrice"].ToString()); } - if(row["AcquisitionTime"]!=null && row["AcquisitionTime"].ToString()!="") + if(row["Month"]!=null && row["Month"].ToString()!="") { - model.AcquisitionTime=DateTime.Parse(row["AcquisitionTime"].ToString()); + model.Month=int.Parse(row["Month"].ToString()); } if(row["Remark1"]!=null) { @@ -256,7 +256,7 @@ namespace DataService.DAL public DataSet GetList(string strWhere) { StringBuilder strSql=new StringBuilder(); - strSql.Append("select PriceId,Cost,UnitPrice,AcquisitionTime,Remark1,Remark2,Remark3,Remark4,Remark5 "); + strSql.Append("select PriceId,Cost,UnitPrice,Month,Remark1,Remark2,Remark3,Remark4,Remark5 "); strSql.Append(" FROM electricity_price "); if(strWhere.Trim()!="") { diff --git a/DataServer/Model/device_operation.cs b/DataServer/Model/device_operation.cs index ea9e3a2..2498adc 100644 --- a/DataServer/Model/device_operation.cs +++ b/DataServer/Model/device_operation.cs @@ -15,7 +15,7 @@ *└──────────────────────────────────┘ */ using System; -namespace DataService.Model +namespace DataServer.Model { /// /// device_operation:实体类(属性说明自动提取数据库字段的描述信息) diff --git a/DataServer/Model/electricity_price.cs b/DataServer/Model/electricity_price.cs index bd81331..eee7271 100644 --- a/DataServer/Model/electricity_price.cs +++ b/DataServer/Model/electricity_price.cs @@ -6,7 +6,7 @@ * * Ver 变更日期 负责人 变更内容 * ─────────────────────────────────── -* V0.01 2024/1/9 10:06:20 N/A 初版 +* V0.01 2024/1/9 11:09:28 N/A 初版 * * Copyright (c) 2012 Maticsoft Corporation. All rights reserved. *┌──────────────────────────────────┐ @@ -15,7 +15,7 @@ *└──────────────────────────────────┘ */ using System; -namespace DataService.Model +namespace DataServer.Model { /// /// electricity_price:实体类(属性说明自动提取数据库字段的描述信息) @@ -29,7 +29,7 @@ namespace DataService.Model private string _priceid; private decimal? _cost; private decimal? _unitprice; - private DateTime? _acquisitiontime; + private int _month; private string _remark1; private string _remark2; private string _remark3; @@ -62,10 +62,10 @@ namespace DataService.Model /// /// /// - public DateTime? AcquisitionTime + public int Month { - set{ _acquisitiontime=value;} - get{return _acquisitiontime;} + set{ _month=value;} + get{return _month;} } /// /// diff --git a/DataServer/api/EnergyEfficiency/get_amount_energy_response.cs b/DataServer/api/EnergyEfficiency/get_amount_energy_response.cs index 67060df..5dc3674 100644 --- a/DataServer/api/EnergyEfficiency/get_amount_energy_response.cs +++ b/DataServer/api/EnergyEfficiency/get_amount_energy_response.cs @@ -11,5 +11,32 @@ namespace DataServer.api.EnergyEfficiency /// public class get_amount_energy_response { + /// + /// 返回码 + /// + public int code { get; set; } + + /// + /// 返回说明 + /// + public string msg { get; set; } + + /// + /// 数据 + /// + public amount_energy data { get; set; } + } + + public class amount_energy + { + /// + /// 节能量 + /// + public decimal Energy { get; set; } + + /// + /// 节电率 + /// + public decimal PowerSavingRate { get; set; } } } diff --git a/DataServer/api/EnergyEfficiency/get_device_operation_response.cs b/DataServer/api/EnergyEfficiency/get_device_operation_response.cs index 3f12ab6..6a93304 100644 --- a/DataServer/api/EnergyEfficiency/get_device_operation_response.cs +++ b/DataServer/api/EnergyEfficiency/get_device_operation_response.cs @@ -11,5 +11,19 @@ namespace DataServer.api.EnergyEfficiency /// public class get_device_operation_response { + /// + /// 返回码 + /// + public int code { get; set; } + + /// + /// 返回说明 + /// + public string msg { get; set; } + + /// + /// 数据 + /// + public List data { get; set; } } } diff --git a/DataServer/api/EnergyEfficiency/get_electricity_price_response.cs b/DataServer/api/EnergyEfficiency/get_electricity_price_response.cs index b2dd36e..9a6c5c8 100644 --- a/DataServer/api/EnergyEfficiency/get_electricity_price_response.cs +++ b/DataServer/api/EnergyEfficiency/get_electricity_price_response.cs @@ -11,5 +11,37 @@ namespace DataServer.api.EnergyEfficiency /// public class get_electricity_price_response { + /// + /// 返回码 + /// + public int code { get; set; } + + /// + /// 返回说明 + /// + public string msg { get; set; } + + /// + /// 数据 + /// + public List data { get; set; } + } + + public class electricity_price + { + /// + /// 电费 + /// + public decimal Cost { get; set; } + + /// + /// 销售单价 + /// + public decimal UnitPrice { get; set; } + + /// + /// 月份 + /// + public int Month { get; set; } } } diff --git a/DongYingAPI/Controllers/api/EnergyEfficiency/GetAmountEnergyController.cs b/DongYingAPI/Controllers/api/EnergyEfficiency/GetAmountEnergyController.cs index 62700f0..aabd813 100644 --- a/DongYingAPI/Controllers/api/EnergyEfficiency/GetAmountEnergyController.cs +++ b/DongYingAPI/Controllers/api/EnergyEfficiency/GetAmountEnergyController.cs @@ -1,8 +1,11 @@ -using System; +using DataServer.api.EnergyEfficiency; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; +using System.Text; using System.Web.Http; namespace DongYingAPI.Controllers.api.EnergyEfficiency @@ -12,5 +15,26 @@ namespace DongYingAPI.Controllers.api.EnergyEfficiency /// public class GetAmountEnergyController : ApiController { + /// + /// 获取节能量(节电率)接口 + /// + /// + public HttpResponseMessage Get() + { + var res = new get_amount_energy_response(); + try + { + res.code = 200; + res.msg = "成功"; + res.data = new amount_energy() { Energy = 24.21m, PowerSavingRate = 19m }; + } + 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; + } } } diff --git a/DongYingAPI/Controllers/api/EnergyEfficiency/GetDeviceOperationController.cs b/DongYingAPI/Controllers/api/EnergyEfficiency/GetDeviceOperationController.cs index 54eed3b..beea23c 100644 --- a/DongYingAPI/Controllers/api/EnergyEfficiency/GetDeviceOperationController.cs +++ b/DongYingAPI/Controllers/api/EnergyEfficiency/GetDeviceOperationController.cs @@ -1,8 +1,11 @@ -using System; +using DataServer.api.EnergyEfficiency; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; +using System.Text; using System.Web.Http; namespace DongYingAPI.Controllers.api.EnergyEfficiency @@ -12,5 +15,28 @@ namespace DongYingAPI.Controllers.api.EnergyEfficiency /// public class GetDeviceOperationController : ApiController { + DataServer.BLL.device_operation bll = new DataServer.BLL.device_operation(); + + /// + /// 获取设备运行情况接口 + /// + /// + public HttpResponseMessage Get() + { + var res = new get_device_operation_response(); + try + { + res.code = 200; + res.msg = "成功"; + res.data = bll.GetModelList(""); + } + 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; + } } } diff --git a/DongYingAPI/Controllers/api/EnergyEfficiency/GetElectricityPriceController.cs b/DongYingAPI/Controllers/api/EnergyEfficiency/GetElectricityPriceController.cs index edb8154..9ed3a3c 100644 --- a/DongYingAPI/Controllers/api/EnergyEfficiency/GetElectricityPriceController.cs +++ b/DongYingAPI/Controllers/api/EnergyEfficiency/GetElectricityPriceController.cs @@ -1,8 +1,11 @@ -using System; +using DataServer.api.EnergyEfficiency; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; +using System.Text; using System.Web.Http; namespace DongYingAPI.Controllers.api.EnergyEfficiency @@ -12,5 +15,48 @@ namespace DongYingAPI.Controllers.api.EnergyEfficiency /// public class GetElectricityPriceController : ApiController { + DataServer.BLL.electricity_price bll = new DataServer.BLL.electricity_price(); + + /// + /// 获取电费电价接口 + /// + /// + public HttpResponseMessage Get() + { + var res = new get_electricity_price_response(); + try + { + res.code = 200; + res.msg = "成功"; + + var now = DateTime.Now; + var month = now.Month;//当前月份 + var start_month = now.AddMonths(-5); + var list = bll.GetModelList(""); + + var data = new List(); + for (int i = 0; i < 5; i++) + { + var model = new electricity_price(); + var new_month = start_month.AddMonths(i); + model.Month = new_month.Month; + var price_model = list.Where(a => a.Month == model.Month).FirstOrDefault(); + if (price_model != null) + { + model.UnitPrice = price_model.UnitPrice.Value; + model.Cost = price_model.Cost.Value; + } + data.Add(model); + } + 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; + } } } diff --git a/DongYingAPI/obj/Debug/DongYingAPI.csproj.AssemblyReference.cache b/DongYingAPI/obj/Debug/DongYingAPI.csproj.AssemblyReference.cache index 9c228b5c0df96eb258b35d099b7c7f426ac89630..50f0e0f7542b90d750a1b7842f8589c620d015bf 100644 GIT binary patch delta 1328 zcmaKsT}V@57{`6w*^X=9NE5MX!EC0%W@hMSI!$fZ$|ft`R&x_$f zb5v9m)T84=MYrX-1v(12P+F|5!LqCIyw%akl{+3vmj_AMyBy1{?o80nqkB0^Sk+{; zHEPvrb+J~BgAe~7Md`{6YGhn`{c{;`T@VZ!@+(k(*+7n!FL~6`1(a48aKyiZ6U?BN z2vE?Pt_Of_!i3UA0`&zsn9V6ii@1t%?gS-a4F==eZ$|R5Zk46V)^tKgcs&LkOH*ro zFqB?K-#fS-&QXPn-*d@YhmEC8r=*~`H!*@|8a?~tW&kF_satyV)fjMEHcDI0$bmQ) ztT^O9MY=@&Ec3KKS9mG1VL-sNhfe(205|{yJ(92Egwj+f#q^kRem6smLCIYux;Nz8 zVbf?&Q!l}FhLoa0r%i^u;WT0A>@^k#0C6ZAj>D6~Dm0C6ZO9uK<4Z=)Kv%bHK%l>% zb%U!L^ASm@E=q z*$zi9nyzz*%3u^F-v`;`$g$`r%yS-X%M{i|Hj1TH?Y{}a{0|}7{9I}ZTU(mV)|O_> zo5>*ODs$ManYU|&_1mDlztqsdbR)!xFIhOt38ZNga6KW@Q&33