2023-01-13 15:30:20 +08:00
|
|
|
|
using Epost.BLL;
|
|
|
|
|
using Epost.Common;
|
|
|
|
|
using Epost.Model;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq;
|
2023-04-17 14:10:34 +08:00
|
|
|
|
|
2023-01-13 15:30:20 +08:00
|
|
|
|
using System.Web.Http;
|
2023-04-17 14:10:34 +08:00
|
|
|
|
using LightContrl;
|
|
|
|
|
|
|
|
|
|
using Epost.DAL.Cache;
|
2023-04-20 16:36:30 +08:00
|
|
|
|
using System.Net;
|
2023-04-21 11:44:47 +08:00
|
|
|
|
using Microsoft.Owin.BuilderProperties;
|
2023-01-13 15:30:20 +08:00
|
|
|
|
|
|
|
|
|
namespace Epost.DPS.Controllers
|
|
|
|
|
{
|
2023-12-05 14:35:20 +08:00
|
|
|
|
[RoutePrefix("api/WebAPI")]
|
2023-01-13 15:30:20 +08:00
|
|
|
|
public class ServerController : ApiController
|
|
|
|
|
{
|
2023-04-17 14:10:34 +08:00
|
|
|
|
AddressstorageBLL addrbll = new AddressstorageBLL();
|
|
|
|
|
LightControlCacheDAL cachedal = new LightControlCacheDAL();
|
2023-12-05 14:35:20 +08:00
|
|
|
|
private static object lockinit = new object();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OrderControlBLL contrbll = new OrderControlBLL();
|
|
|
|
|
|
2023-04-17 14:10:34 +08:00
|
|
|
|
MainControl lig = new MainControl();
|
|
|
|
|
#region 连接
|
|
|
|
|
[Route("CONNECT")]
|
2023-01-13 15:30:20 +08:00
|
|
|
|
[HttpPost]
|
2023-04-17 14:10:34 +08:00
|
|
|
|
public ResultLightModel CONNECT([FromBody] List<reqmodel> data)
|
2023-01-13 15:30:20 +08:00
|
|
|
|
{
|
2023-04-17 14:10:34 +08:00
|
|
|
|
ResultLightModel res = new ResultLightModel();
|
|
|
|
|
try
|
2023-01-13 15:30:20 +08:00
|
|
|
|
{
|
2023-04-23 17:12:13 +08:00
|
|
|
|
LogHelper.WriteLogInfo("CONNECT请求" + JsonHelper.SerializeObject(data));
|
2023-04-17 14:10:34 +08:00
|
|
|
|
if (data.Any() && data.Count > 0)
|
2023-01-13 15:30:20 +08:00
|
|
|
|
{
|
2023-04-17 14:10:34 +08:00
|
|
|
|
foreach (var item in data)
|
|
|
|
|
{
|
2023-04-21 11:44:47 +08:00
|
|
|
|
if (item.status == "1")//连接
|
2023-04-17 14:10:34 +08:00
|
|
|
|
{
|
2023-12-05 14:35:20 +08:00
|
|
|
|
DataTable dt = addrbll.QueryControlList(" ");
|
2023-04-21 11:44:47 +08:00
|
|
|
|
if (dt != null && dt.Rows.Count > 0)
|
2023-04-17 14:10:34 +08:00
|
|
|
|
{
|
2023-04-21 11:44:47 +08:00
|
|
|
|
foreach (DataRow rowitem in dt.Rows)
|
2023-04-17 14:10:34 +08:00
|
|
|
|
{
|
2023-04-21 11:44:47 +08:00
|
|
|
|
|
|
|
|
|
string ipaddress = rowitem["controlip"].ToString().Trim();
|
|
|
|
|
List<LightcontrolModel> conlist = cachedal.GetControlList().FindAll(o => o.controlip == ipaddress);
|
|
|
|
|
if (conlist != null && conlist.Count > 0)
|
2023-04-17 14:10:34 +08:00
|
|
|
|
{
|
2023-04-21 11:44:47 +08:00
|
|
|
|
LogHelper.WriteLogInfo(ipaddress + "已连接!");
|
2023-04-23 17:12:13 +08:00
|
|
|
|
res.resultCode = "0";
|
|
|
|
|
res.resultMsg = "成功!";
|
|
|
|
|
return res;
|
2023-04-17 14:10:34 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-04-21 11:44:47 +08:00
|
|
|
|
int port = Convert.ToInt32(rowitem["port"].ToString().Trim());
|
|
|
|
|
int timeout = 2000;
|
|
|
|
|
bool bo = lig.Connect(ipaddress, port, timeout);//timeout 毫秒
|
|
|
|
|
if (bo)
|
|
|
|
|
{
|
|
|
|
|
LightcontrolModel model = new LightcontrolModel();
|
|
|
|
|
model.controlip = ipaddress;
|
|
|
|
|
model.maincontrol = lig;
|
|
|
|
|
model.port = port;
|
|
|
|
|
cachedal.UpdateControlList(new List<LightcontrolModel> { model }, EcontrolCommend.Create);
|
|
|
|
|
res.resultCode = "0";
|
|
|
|
|
res.resultMsg = "成功!";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
res.resultCode = "-1";
|
|
|
|
|
res.resultMsg = "连接失败" + ipaddress;
|
2023-04-23 17:12:13 +08:00
|
|
|
|
LogHelper.WriteLogInfo("连接失败" + ipaddress);
|
2023-04-21 11:44:47 +08:00
|
|
|
|
return res;
|
|
|
|
|
}
|
2023-04-17 14:10:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-23 17:12:13 +08:00
|
|
|
|
|
2023-04-21 11:44:47 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
res.resultCode = "-1";
|
|
|
|
|
res.resultMsg = "播种墙号错误";
|
2023-04-23 17:12:13 +08:00
|
|
|
|
LogHelper.WriteLogInfo("播种墙号错误");
|
2023-04-21 11:44:47 +08:00
|
|
|
|
return res;
|
|
|
|
|
}
|
2023-04-20 16:36:30 +08:00
|
|
|
|
}
|
|
|
|
|
else {
|
2023-04-21 11:44:47 +08:00
|
|
|
|
LogHelper.WriteLogInfo("断开连接");
|
|
|
|
|
List<LightcontrolModel> conlist = cachedal.GetControlList();
|
|
|
|
|
if (conlist.Any() && conlist.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (LightcontrolModel con in conlist)
|
|
|
|
|
{
|
|
|
|
|
bool b= con.maincontrol.DisConnect(con.controlip,con.port);
|
|
|
|
|
LogHelper.WriteLogInfo(b+"断开连接"+ con.controlip+"=="+con.port);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cachedal.ClearControlList();
|
|
|
|
|
res.resultCode = "0";
|
|
|
|
|
res.resultMsg = "断开连接成功!";
|
2023-04-17 14:10:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-13 15:30:20 +08:00
|
|
|
|
}
|
2023-04-17 14:10:34 +08:00
|
|
|
|
return res;
|
2023-01-13 15:30:20 +08:00
|
|
|
|
}
|
2023-04-17 14:10:34 +08:00
|
|
|
|
catch (Exception ex)
|
2023-01-13 15:30:20 +08:00
|
|
|
|
{
|
2023-04-17 14:10:34 +08:00
|
|
|
|
LogHelper.WriteLogInfo(ex.ToString(), LogHelper.Log_Type.ERROR);
|
|
|
|
|
res.resultMsg = "请求接口异常!";
|
|
|
|
|
res.resultCode = "-1";
|
2023-01-13 15:30:20 +08:00
|
|
|
|
|
|
|
|
|
}
|
2023-04-17 14:10:34 +08:00
|
|
|
|
return res;
|
2023-01-13 15:30:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-17 14:10:34 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 全亮全灭
|
|
|
|
|
[Route("LEDON")]
|
2023-01-13 15:30:20 +08:00
|
|
|
|
[HttpPost]
|
2023-04-17 14:10:34 +08:00
|
|
|
|
public ResultLightModel LEDON([FromBody] List<reqmodel> data)
|
2023-01-13 15:30:20 +08:00
|
|
|
|
{
|
2023-04-17 14:10:34 +08:00
|
|
|
|
ResultLightModel res = new ResultLightModel();
|
|
|
|
|
try
|
2023-01-13 15:30:20 +08:00
|
|
|
|
{
|
2023-04-23 17:12:13 +08:00
|
|
|
|
LogHelper.WriteLogInfo("LEDON请求" + JsonHelper.SerializeObject(data));
|
2023-04-17 14:10:34 +08:00
|
|
|
|
if (data.Any() && data.Count > 0)
|
2023-01-13 15:30:20 +08:00
|
|
|
|
{
|
2023-04-17 14:10:34 +08:00
|
|
|
|
foreach (var item in data)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//根据播种墙号查询灯带IP
|
2023-12-05 14:35:20 +08:00
|
|
|
|
DataTable dt = addrbll.QueryControlList(" ");
|
2023-04-17 14:10:34 +08:00
|
|
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (DataRow rowitem in dt.Rows)
|
|
|
|
|
{
|
|
|
|
|
string ipaddress = rowitem["controlip"].ToString().Trim();
|
|
|
|
|
List<LightcontrolModel> conlist = cachedal.GetControlList().FindAll(o => o.controlip == ipaddress);
|
|
|
|
|
if (conlist != null && conlist.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
MainControl control = conlist.FirstOrDefault().maincontrol;
|
|
|
|
|
bool bo = false;
|
|
|
|
|
string Address = dt.Rows[0]["address"].ToString().Trim();
|
2023-04-21 15:47:55 +08:00
|
|
|
|
string resstr = string.Empty;
|
2023-04-17 14:10:34 +08:00
|
|
|
|
if (item.lightType == "0")
|
|
|
|
|
{
|
|
|
|
|
|
2023-04-21 15:47:55 +08:00
|
|
|
|
bo = control.LED_OFF(ipaddress, Address,ref resstr);
|
2023-04-17 14:10:34 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-04-21 15:47:55 +08:00
|
|
|
|
bo = control.LED_ON(ipaddress, Address, ref resstr, "3", "0" , item.lightColor.Trim());
|
2023-04-17 14:10:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bo)
|
|
|
|
|
{
|
|
|
|
|
res.resultCode = "0";
|
|
|
|
|
res.resultMsg = "成功!";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
res.resultCode = "-1";
|
|
|
|
|
res.resultMsg = "失败";
|
2023-04-23 17:12:13 +08:00
|
|
|
|
LogHelper.WriteLogInfo(ipaddress+"失败!" +resstr);
|
2023-04-17 14:10:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
res.resultCode = "-1";
|
|
|
|
|
res.resultMsg = "请先连接设备";
|
2023-04-23 17:12:13 +08:00
|
|
|
|
LogHelper.WriteLogInfo("请先连接设备!");
|
2023-04-17 14:10:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
res.resultCode = "-1";
|
|
|
|
|
res.resultMsg = "播种墙号错误!";
|
|
|
|
|
LogHelper.WriteLogInfo("播种墙号错误", LogHelper.Log_Type.ERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-13 15:30:20 +08:00
|
|
|
|
}
|
2023-04-17 14:10:34 +08:00
|
|
|
|
else
|
2023-01-13 15:30:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
2023-04-17 14:10:34 +08:00
|
|
|
|
res.resultCode = "-1";
|
|
|
|
|
res.resultMsg = "请求参数错误!";
|
2023-04-23 17:12:13 +08:00
|
|
|
|
LogHelper.WriteLogInfo("请求参数错误!");
|
2023-01-13 15:30:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-17 14:10:34 +08:00
|
|
|
|
|
2023-01-13 15:30:20 +08:00
|
|
|
|
return res;
|
|
|
|
|
}
|
2023-04-17 14:10:34 +08:00
|
|
|
|
catch (Exception ex)
|
2023-01-13 15:30:20 +08:00
|
|
|
|
{
|
2023-04-17 14:10:34 +08:00
|
|
|
|
LogHelper.WriteLogInfo(ex.ToString(), LogHelper.Log_Type.ERROR);
|
|
|
|
|
res.resultMsg = "请求接口异常!";
|
|
|
|
|
res.resultCode = "-1";
|
2023-01-13 15:30:20 +08:00
|
|
|
|
|
|
|
|
|
}
|
2023-04-17 14:10:34 +08:00
|
|
|
|
return res;
|
2023-01-13 15:30:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2023-04-17 14:10:34 +08:00
|
|
|
|
#region 根据货位点亮/熄灭格口
|
|
|
|
|
[Route("DISPLAYJOB")]
|
2023-01-13 15:30:20 +08:00
|
|
|
|
[HttpPost]
|
2023-04-17 14:10:34 +08:00
|
|
|
|
public ResultLightModel DISPLAYJOB([FromBody] List<DisplayjobModelReq> data)
|
2023-01-13 15:30:20 +08:00
|
|
|
|
{
|
2023-04-17 14:10:34 +08:00
|
|
|
|
ResultLightModel res = new ResultLightModel();
|
|
|
|
|
try
|
2023-01-13 15:30:20 +08:00
|
|
|
|
{
|
2023-04-23 17:12:13 +08:00
|
|
|
|
LogHelper.WriteLogInfo("DISPLAYJOB请求" + JsonHelper.SerializeObject(data));
|
2023-04-17 14:10:34 +08:00
|
|
|
|
if (data.Any() && data.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (DisplayjobModelReq item in data)
|
|
|
|
|
{
|
|
|
|
|
//根据播种墙号查询灯带IP
|
2023-12-05 14:35:20 +08:00
|
|
|
|
DataTable dt = addrbll.QueryControlList("");
|
2023-04-17 14:10:34 +08:00
|
|
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (DataRow rowitem in dt.Rows)
|
|
|
|
|
{
|
|
|
|
|
string ipaddress = rowitem["controlip"].ToString().Trim();
|
|
|
|
|
List<LightcontrolModel> conlist = cachedal.GetControlList().FindAll(o => o.controlip == ipaddress);
|
|
|
|
|
if (conlist != null && conlist.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
MainControl control = conlist.FirstOrDefault().maincontrol;
|
2023-12-05 14:35:20 +08:00
|
|
|
|
DataTable locdt = addrbll.QueryAddrList(" and location ='" + item.location + "' and controlip='" + ipaddress + "'");
|
2023-04-17 14:10:34 +08:00
|
|
|
|
if (locdt != null && locdt.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
List<LightParagraph> list = new List<LightParagraph>();
|
|
|
|
|
string address = locdt.Rows[0]["address"].ToString().Trim();
|
|
|
|
|
foreach (DataRow locitem in locdt.Rows)
|
|
|
|
|
{
|
|
|
|
|
//根据播种墙号、格口号查询播种墙ip及灯带地址
|
|
|
|
|
|
|
|
|
|
LightParagraph show = new LightParagraph();
|
|
|
|
|
show.WayNu = Convert.ToInt32(locitem["wayno"].ToString().Trim());
|
|
|
|
|
show.LightBeganNu = locitem["beginno"].ToString().Trim();
|
|
|
|
|
show.LightEndNu = locitem["endno"].ToString().Trim();
|
|
|
|
|
show.LightColor = item.lightColor.Trim(); //1:蓝色 2:绿色 3:青色 4:红色 5:紫色 6黄色 7白色
|
|
|
|
|
show.Brightness = item.brightness.Trim();//亮度 1-9
|
|
|
|
|
list.Add(show);
|
|
|
|
|
|
|
|
|
|
}
|
2023-04-21 15:47:55 +08:00
|
|
|
|
string resstr = string.Empty;
|
|
|
|
|
bool bo = control.LED_By_Paragraph(ipaddress, address, list,ref resstr);
|
2023-04-17 14:10:34 +08:00
|
|
|
|
if (bo)
|
|
|
|
|
{
|
2023-04-23 17:12:13 +08:00
|
|
|
|
LogHelper.WriteLogInfo("成功" + ipaddress+"list:"+JsonHelper.SerializeObject(list));
|
2023-04-17 14:10:34 +08:00
|
|
|
|
res.resultCode = "0";
|
|
|
|
|
res.resultMsg = "成功!";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-04-23 17:12:13 +08:00
|
|
|
|
LogHelper.WriteLogInfo("失败"+ ipaddress + "list:" + JsonHelper.SerializeObject(list),LogHelper.Log_Type.ERROR);
|
2023-04-17 14:10:34 +08:00
|
|
|
|
res.resultCode = "-1";
|
2023-04-21 15:47:55 +08:00
|
|
|
|
res.resultMsg = resstr;
|
2023-04-17 14:10:34 +08:00
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
res.resultCode = "-1";
|
|
|
|
|
res.resultMsg = "请先连接设备!";
|
2023-04-23 17:12:13 +08:00
|
|
|
|
LogHelper.WriteLogInfo("请先连接设备!");
|
2023-04-17 14:10:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
res.resultCode = "-1";
|
2023-04-23 17:12:13 +08:00
|
|
|
|
res.resultMsg = "播种墙号错误!";
|
|
|
|
|
LogHelper.WriteLogInfo("播种墙号错误!");
|
2023-04-17 14:10:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-13 15:30:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2023-04-17 14:10:34 +08:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogHelper.WriteLogInfo(ex.ToString(), LogHelper.Log_Type.ERROR);
|
|
|
|
|
res.resultMsg = "请求接口异常!";
|
|
|
|
|
res.resultCode = "-1";
|
2023-01-13 15:30:20 +08:00
|
|
|
|
|
2023-04-17 14:10:34 +08:00
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2023-01-13 15:30:20 +08:00
|
|
|
|
|
2023-04-17 14:10:34 +08:00
|
|
|
|
#endregion
|
2023-01-13 15:30:20 +08:00
|
|
|
|
|
|
|
|
|
|
2023-12-05 14:35:20 +08:00
|
|
|
|
//初始化
|
|
|
|
|
[Route("ClearALL")]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ResultModel ClearALL()
|
|
|
|
|
{
|
|
|
|
|
lock (lockinit)
|
|
|
|
|
{
|
|
|
|
|
ResultModel res = new ResultModel();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
res = contrbll.ClearALL();
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogHelper.WriteLogInfo("GetDataList异常:" + ex.Message);
|
|
|
|
|
res.msg = "请求异常!";
|
|
|
|
|
res.result = "-1";
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("StartWork")]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ResultModel StartWork()
|
|
|
|
|
{
|
|
|
|
|
lock (lockinit)
|
|
|
|
|
{
|
|
|
|
|
ResultModel res = new ResultModel();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
contrbll.StartWork();
|
|
|
|
|
res.msg = "成功!";
|
|
|
|
|
res.result = "0";
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
LogHelper.WriteLogInfo("启动作业异常" + ex.ToString(), LogHelper.Log_Type.ERROR);
|
|
|
|
|
res.msg = "启动作业异常!";
|
|
|
|
|
res.result = "-1";
|
|
|
|
|
}
|
2023-01-13 15:30:20 +08:00
|
|
|
|
|
2023-12-05 14:35:20 +08:00
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#region 停止作业
|
|
|
|
|
[Route("EndWork")]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ResultModel EndWork()
|
|
|
|
|
{
|
|
|
|
|
lock (lockinit)
|
|
|
|
|
{
|
|
|
|
|
ResultModel res = new ResultModel();
|
|
|
|
|
contrbll.EndWork();
|
|
|
|
|
res.msg = "成功!";
|
|
|
|
|
res.result = "0";
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2023-01-13 15:30:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|