88 lines
3.4 KiB
C#
88 lines
3.4 KiB
C#
using DataServer.api;
|
|
using Microsoft.Ajax.Utilities;
|
|
using Newtonsoft.Json;
|
|
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;
|
|
|
|
namespace DongYingAPI.Controllers.api
|
|
{
|
|
/// <summary>
|
|
/// 空调-末端风机启停
|
|
/// </summary>
|
|
public class SetDraughtFanController : ApiController
|
|
{
|
|
DataServer.BLL.draught_fan bll = new DataServer.BLL.draught_fan();
|
|
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 model = new DataServer.Model.draught_fan();
|
|
model.DraughtId = item.DraughtId;
|
|
model.DeviceNumber = item.DeviceNumber;
|
|
model.DraughtName = item.DraughtName;
|
|
model.DraughtNumberOne = item.DraughtNumberOne;
|
|
model.DraughtNumberTwo= item.DraughtNumberTwo;
|
|
if (item.DraughtStateOne == "0")
|
|
{
|
|
model.DraughtStateOne = "1";
|
|
}
|
|
else
|
|
{
|
|
model.DraughtStateTwo = "0";
|
|
}
|
|
if (item.DraughtStateOne == "1")
|
|
{
|
|
model.DraughtStateOne = "0";
|
|
}
|
|
else
|
|
{
|
|
model.DraughtStateTwo = "1";
|
|
}
|
|
model.ClientId = item.ClientId;
|
|
bll.Update(model);
|
|
}
|
|
var alist = bll.GetModelList("");
|
|
foreach (var aitem 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 = aitem.DeviceNumber;
|
|
|
|
// 如果需要同时设置多个数据项,可以使用字典
|
|
controlData.b = new BodyData();
|
|
controlData.b.dl = new Dictionary<string, string>();
|
|
controlData.b.dl["" + aitem.DraughtNumberOne + ""] = "" + aitem.DraughtStateOne + "";
|
|
controlData.b.dl["" + aitem.DraughtNumberTwo + ""] = "" + aitem.DraughtStateTwo + "";
|
|
data.Add(controlData);
|
|
mqqt.MqttClientStart();
|
|
mqqt.Publish("/gc/data/"+aitem.ClientId, "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;
|
|
}
|
|
}
|
|
} |