85 lines
3.4 KiB
C#
85 lines
3.4 KiB
C#
using DataServer.api;
|
|
using Microsoft.Ajax.Utilities;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using QingHaiVisualizationAPI.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Web.Http;
|
|
using System.Xml.Linq;
|
|
|
|
namespace DongYingAPI.Controllers.api
|
|
{
|
|
/// <summary>
|
|
/// 空调-主机控制(启停)
|
|
/// </summary>
|
|
public class SetHostControlController : ApiController
|
|
{
|
|
DataServer.BLL.host_control bll = new DataServer.BLL.host_control();
|
|
static log4net.ILog log;
|
|
public HttpResponseMessage Get()
|
|
{
|
|
var res = new get_information();
|
|
try
|
|
{
|
|
var data = new List<data>();
|
|
var list = bll.GetModelList("");
|
|
foreach (var item in list)
|
|
{
|
|
var clist = list.Where(x => x.HostNumber == item.HostNumber).ToList();
|
|
foreach (var aitem in clist)
|
|
{
|
|
var model = new DataServer.Model.host_control();
|
|
model.HostId= aitem.HostId;
|
|
model.HostName = aitem.HostName;
|
|
model.HostLocation= aitem.HostLocation;
|
|
model.HostNumber = aitem.HostNumber;
|
|
if (aitem.HostState == "0")
|
|
{
|
|
model.HostState= "1";
|
|
}
|
|
if (aitem.HostState == "1")
|
|
{
|
|
model.HostState= "0";
|
|
}
|
|
model.HostTemperature= aitem.HostTemperature;
|
|
bll.Update(model);
|
|
}
|
|
}
|
|
var alist = bll.GetModelList("");
|
|
foreach (var item in alist)
|
|
{
|
|
log4net.Config.XmlConfigurator.Configure();
|
|
log = log4net.LogManager.GetLogger("loginfo");
|
|
var mqqt = new MqttClientService();
|
|
data controlData = new data();
|
|
controlData.h = new HeaderData();
|
|
controlData.h.rt = item.HostNumber;
|
|
|
|
// 如果需要同时设置多个数据项,可以使用字典
|
|
controlData.b = new BodyData();
|
|
controlData.b.dl = new Dictionary<string, string>();
|
|
controlData.b.dl["冷冻水出水温度设定"] = "" + item.HostTemperature + "";
|
|
controlData.b.dl["主机远程启停控制"] = "" + item.HostState + "";
|
|
data.Add(controlData);
|
|
mqqt.MqttClientStart();
|
|
mqqt.Publish("gc/data/ce5a0665-b5eb-4e75-a6a5-799449c3f092", "J" + JsonConvert.SerializeObject(controlData));
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
} |