82 lines
3.8 KiB
C#
82 lines
3.8 KiB
C#
using DataServer.api;
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// 照明-设备详情
|
|
/// </summary>
|
|
public class GetDeviceDetailsController : ApiController
|
|
{
|
|
DataServer.BLL.electricity_data bll = new DataServer.BLL.electricity_data();
|
|
DataServer.BLL.device_info bll_info = new DataServer.BLL.device_info();
|
|
DataServer.BLL.lighting_control bll_control=new DataServer.BLL.lighting_control();
|
|
public HttpResponseMessage Get()
|
|
{
|
|
var res = new get_device_details();
|
|
try
|
|
{
|
|
var data = new List<device_detailsData>();
|
|
var time = DateTime.Now.ToString("yyyyMM");
|
|
#region 表是否存在
|
|
//表名
|
|
var date_base = ConfigurationManager.AppSettings["MySQLDataBase"].ToString();
|
|
//今月的表是否存在
|
|
var jtime = DateTime.Now.ToString("yyyyMM");
|
|
var a1 = bll.IsExistsTable(date_base, "electricity_data_" + time);
|
|
if (a1 == false)
|
|
{
|
|
bll.CreateTable(jtime);
|
|
}
|
|
|
|
#endregion
|
|
var blist = bll_control.GetModelList("");
|
|
foreach (var item in blist)
|
|
{
|
|
var model = new device_detailsData();
|
|
model.DeviceName = item.LightingName;
|
|
model.DeviceState =Convert.ToInt32(item.LightingState);
|
|
if(model.DeviceName== "照明回路1"|| model.DeviceName == "照明回路2"|| model.DeviceName == "照明回路3"|| model.DeviceName == "照明回路4"|| model.DeviceName == "照明回路5"|| model.DeviceName == "照明回路1"|| model.DeviceName == "照明回路6"
|
|
|| model.DeviceName == "照明回路7"|| model.DeviceName == "照明回路8"|| model.DeviceName == "照明回路9"|| model.DeviceName == "照明回路10"|| model.DeviceName == "照明回路11")
|
|
{
|
|
var sdate = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
|
|
var edate = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
|
|
var alist = bll.GetModelListDate(" DeviceId='370510043003' and EntireTime>='" + sdate + "' and EntireTime<'" + edate + "'", time);
|
|
decimal? num = alist.Sum(x => Convert.ToDecimal(x.P));
|
|
model.P = num;
|
|
}
|
|
else
|
|
{
|
|
var sdate = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
|
|
var edate = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
|
|
var alist = bll.GetModelListDate(" DeviceId='370510043004' and EntireTime>='" + sdate + "' and EntireTime<'" + edate + "'", time);
|
|
decimal? num = alist.Sum(x => Convert.ToDecimal(x.P));
|
|
model.P = num;
|
|
}
|
|
model.Illuminance = item.LightingBrightness+"%";
|
|
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;
|
|
}
|
|
}
|
|
} |