diff --git a/DLL/LightContrl.dll b/DLL/LightContrl.dll new file mode 100644 index 0000000..c8ffee3 Binary files /dev/null and b/DLL/LightContrl.dll differ diff --git a/DLL/LightContrl.pdb b/DLL/LightContrl.pdb new file mode 100644 index 0000000..253b438 Binary files /dev/null and b/DLL/LightContrl.pdb differ diff --git a/Epost.BLL/AddressstorageBLL.cs b/Epost.BLL/AddressstorageBLL.cs index 324dde2..7daf910 100644 --- a/Epost.BLL/AddressstorageBLL.cs +++ b/Epost.BLL/AddressstorageBLL.cs @@ -374,5 +374,26 @@ namespace Epost.BLL return dal.GetAddressListByByPage(strWhere, orderby, startIndex, endIndex, out recordCount); } #endregion + + + #region 灯带 + + #region 查询设备信息 + public DataTable QueryAddrList(string strwhere) + { + return dal.QueryAddrList(strwhere); + } + + #endregion + + + #region 查询设备信息 + public DataTable QueryControlList(string strwhere) + { + return dal.QueryControlList(strwhere); + } + + #endregion + #endregion } } diff --git a/Epost.BLL/OrderControlBLL.cs b/Epost.BLL/OrderControlBLL.cs index 12d547d..a13d5f6 100644 --- a/Epost.BLL/OrderControlBLL.cs +++ b/Epost.BLL/OrderControlBLL.cs @@ -41,7 +41,6 @@ namespace Epost.BLL public ResultModel ClearALL() { - try { bool t = addrBLL.UpdateState(); diff --git a/Epost.DAL/AddressstorageDAL.cs b/Epost.DAL/AddressstorageDAL.cs index 95af696..1a4c8a2 100644 --- a/Epost.DAL/AddressstorageDAL.cs +++ b/Epost.DAL/AddressstorageDAL.cs @@ -809,5 +809,26 @@ namespace Epost.DAL } #endregion + + #region 灯带 + #region 查询设备信息 + public DataTable QueryAddrList(string strwhere) + { + string sql = string.Format("select * from v_address where 1=1 " + strwhere); + return db.GetsqlForDT(sql); + } + + #endregion + #region 查询设备信息 + public DataTable QueryControlList(string strwhere) + { + string sql = string.Format(" select distinct controlip ,port,waveno,address from v_address where 1=1 " + strwhere); + return db.GetsqlForDT(sql); + } + + #endregion + + #endregion + } } diff --git a/Epost.DAL/Cache/LightControlCacheDAL.cs b/Epost.DAL/Cache/LightControlCacheDAL.cs new file mode 100644 index 0000000..d0e596b --- /dev/null +++ b/Epost.DAL/Cache/LightControlCacheDAL.cs @@ -0,0 +1,94 @@ +using LightContrl; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Epost.DAL.Cache +{ + public class LightControlCacheDAL + { + + private static object lockconobj = new object(); + public static List MainControlList = new List();// + + #region 获取计划任务列表 + public List GetControlList() + { + return MainControlList; + } + #endregion + + + + #region 初始化任务列表 + public void ClearControlList() + { + foreach (var planitem in MainControlList.ToArray()) + { + MainControlList.Remove(planitem); + } + } + #endregion + + #region Job缓存处理方法 + /// + /// Job缓存处理方法 + /// + /// + /// + /// + public bool UpdateControlList(List JobParam, EcontrolCommend CommendType) + { + + lock (lockconobj) + { + + if (CommendType.Equals(EcontrolCommend.Create)) + { + + MainControlList.AddRange(JobParam); + } + + else if (CommendType.Equals(EcontrolCommend.Execute)) + { + JobParam.ForEach(m => MainControlList.Remove(m)); + + } + + + return true; + } + } + #endregion + + + + + + } + public enum EcontrolCommend + { + /// + /// 创建 + /// + [Description("创建")] + Create, + /// + /// 删除 + /// + [Description("删除")] + Execute + } + + public class LightcontrolModel + { + private string _controlip = string.Empty; + MainControl _maincontrol = new MainControl(); + + public MainControl maincontrol { get => _maincontrol; set => _maincontrol = value; } + public string controlip { get => _controlip; set => _controlip = value; } + } +} diff --git a/Epost.DAL/Epost.DAL.csproj b/Epost.DAL/Epost.DAL.csproj index ecc522b..4a3252a 100644 --- a/Epost.DAL/Epost.DAL.csproj +++ b/Epost.DAL/Epost.DAL.csproj @@ -82,6 +82,9 @@ ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll True + + ..\DLL\LightContrl.dll + @@ -106,6 +109,7 @@ + diff --git a/Epost.Model/OrderModel.cs b/Epost.Model/OrderModel.cs index b256ccf..0241510 100644 --- a/Epost.Model/OrderModel.cs +++ b/Epost.Model/OrderModel.cs @@ -9,10 +9,18 @@ namespace Epost.Model public class OrderModel { - private string _OrderNO = string.Empty; - private string _State = string.Empty;// 1亮灯 0灭灯 + private string _wallNo = string.Empty; + private string _location = string.Empty; + private string _lightColor = string.Empty; + private string _lightType = string.Empty; + private string _brightness = string.Empty; + private string _status = string.Empty; - public string OrderNO { get => _OrderNO; set => _OrderNO = value; } - public string State { get => _State; set => _State = value; } + public string wallNo { get => _wallNo; set => _wallNo = value; } + public string lcation { get => _location; set => _location = value; } + public string lightColor { get => _lightColor; set => _lightColor = value; } + public string lightType { get => _lightType; set => _lightType = value; } + public string brightness { get => _brightness; set => _brightness = value; } + public string status { get => _status; set => _status = value; } } } diff --git a/Epost.Model/ResultModel.cs b/Epost.Model/ResultModel.cs index 58bb6b0..f69cb12 100644 --- a/Epost.Model/ResultModel.cs +++ b/Epost.Model/ResultModel.cs @@ -37,4 +37,89 @@ namespace Epost.Model } } } + + public class SerResultModel + { + private string _resultCode = string.Empty; + private string _resultMsg = string.Empty; + + public string resultCode { get => _resultCode; set => _resultCode = value; } + public string resultMsg { get => _resultMsg; set => _resultMsg = value; } + } + + public class TaskReqModel + { + private string matchid = string.Empty; + private string orderid = string.Empty; + private string sku = string.Empty; + private string tolocation = string.Empty; + private string originalBatch = string.Empty; + private string block = string.Empty; + private string area = string.Empty; + private string _id = string.Empty; + public string Matchid { get => matchid; set => matchid = value; } + public string Orderid { get => orderid; set => orderid = value; } + public string Sku { get => sku; set => sku = value; } + public string Tolocation { get => tolocation; set => tolocation = value; } + public string OriginalBatch { get => originalBatch; set => originalBatch = value; } + public string Block { get => block; set => block = value; } + public string Area { get => area; set => area = value; } + public string id { get => _id; set => _id = value; } + } + + + + public class ResultLightModel + { + private string _resultCode = string.Empty; + private string _resultMsg = string.Empty; + + public string resultCode + { + get + { + return _resultCode; + } + + set + { + _resultCode = value; + } + } + + public string resultMsg + { + get + { + return _resultMsg; + } + + set + { + _resultMsg = value; + } + } + } + + + + + + public class reqmodel + { + public string wallNo { get; set; } + public string lightType { get; set; } + } + + + + public class DisplayjobModelReq + { + public string wallNo { get; set; } + public string location { get; set; } + public string lightColor { get; set; } + public string lightType { get; set; } + public string brightness { get; set; } + } + } diff --git a/Epost.TestToolsWeb/Controllers/HomeController.cs b/Epost.TestToolsWeb/Controllers/HomeController.cs index 4e8149f..d19102c 100644 --- a/Epost.TestToolsWeb/Controllers/HomeController.cs +++ b/Epost.TestToolsWeb/Controllers/HomeController.cs @@ -41,6 +41,7 @@ namespace Epost.TestToolsWeb.Controllers public ActionResult Index() { + ViewBag.isClear = isClear; ViewBag.isWork = isWork; diff --git a/Epost.TestToolsWeb/Controllers/ServerController.cs b/Epost.TestToolsWeb/Controllers/ServerController.cs index 1fe2008..4c9cc21 100644 --- a/Epost.TestToolsWeb/Controllers/ServerController.cs +++ b/Epost.TestToolsWeb/Controllers/ServerController.cs @@ -5,167 +5,267 @@ using System; using System.Collections.Generic; using System.Data; using System.Linq; -using System.Net; -using System.Net.Http; + using System.Web.Http; +using LightContrl; + +using Epost.DAL.Cache; namespace Epost.DPS.Controllers { - [RoutePrefix("api/WebAPI")] + [RoutePrefix("api/TaskAPI")] public class ServerController : ApiController { - private static object lockinit = new object(); + AddressstorageBLL addrbll = new AddressstorageBLL(); + LightControlCacheDAL cachedal = new LightControlCacheDAL(); + MainControl lig = new MainControl(); + #region 连接 + [Route("CONNECT")] + [HttpPost] + public ResultLightModel CONNECT([FromBody] List data) + { + ResultLightModel res = new ResultLightModel(); + try + { + if (data.Any() && data.Count > 0) + { + foreach (var item in data) + { + DataTable dt = addrbll.QueryControlList(" and waveno ='" + item.wallNo + "'"); + if (dt != null && dt.Rows.Count > 0) + { + foreach (DataRow rowitem in dt.Rows) + { - OrderControlBLL contrbll = new OrderControlBLL(); + string ipaddress = rowitem["controlip"].ToString().Trim(); + List conlist = cachedal.GetControlList().FindAll(o => o.controlip == ipaddress); + if (conlist != null && conlist.Count > 0) + { + LogHelper.WriteLogInfo(ipaddress + "已连接!"); + } + else + { + 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; + cachedal.UpdateControlList(new List { model }, EcontrolCommend.Create); + res.resultCode = "0"; + res.resultMsg = "成功!"; + } + else + { + res.resultCode = "-1"; + res.resultMsg = "连接失败" + ipaddress; + return res; + } + } + } - //初始化 + + + + + + + } + } + } + return res; + } + catch (Exception ex) + { + LogHelper.WriteLogInfo(ex.ToString(), LogHelper.Log_Type.ERROR); + res.resultMsg = "请求接口异常!"; + res.resultCode = "-1"; + + } + return res; + } + + #endregion + + #region 全亮全灭 + [Route("LEDON")] + [HttpPost] + public ResultLightModel LEDON([FromBody] List data) + { + ResultLightModel res = new ResultLightModel(); + try + { + if (data.Any() && data.Count > 0) + { + foreach (var item in data) + { + + //根据播种墙号查询灯带IP + DataTable dt = addrbll.QueryControlList(" and waveno ='" + item.wallNo + "'"); + if (dt != null && dt.Rows.Count > 0) + { + foreach (DataRow rowitem in dt.Rows) + { + string ipaddress = rowitem["controlip"].ToString().Trim(); + List 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(); + if (item.lightType == "0") + { + + bo = control.LED_OFF(ipaddress, Address); + } + else + { + bo = control.LED_ON(ipaddress, Address, "3", "0", "1"); + } + + + + if (bo) + { + res.resultCode = "0"; + res.resultMsg = "成功!"; + } + else + { + res.resultCode = "-1"; + res.resultMsg = "失败"; + } + + } + else + { + res.resultCode = "-1"; + res.resultMsg = "请先连接设备"; + } + + + } + } + else + { + res.resultCode = "-1"; + res.resultMsg = "播种墙号错误!"; + LogHelper.WriteLogInfo("播种墙号错误", LogHelper.Log_Type.ERROR); + } + } + } + else + { + + res.resultCode = "-1"; + res.resultMsg = "请求参数错误!"; + } + + + return res; + } + catch (Exception ex) + { + LogHelper.WriteLogInfo(ex.ToString(), LogHelper.Log_Type.ERROR); + res.resultMsg = "请求接口异常!"; + res.resultCode = "-1"; + + } + return res; + } + + #endregion + + #region 根据货位点亮/熄灭格口 [Route("DISPLAYJOB")] [HttpPost] - public ResultModel DISPLAYJOB(OrderModel model) + public ResultLightModel DISPLAYJOB([FromBody] List data) { - lock (lockinit) + ResultLightModel res = new ResultLightModel(); + try { - ResultModel res = new ResultModel(); - try + if (data.Any() && data.Count > 0) { - LogHelper.WriteLogInfo(JsonHelper.SerializeObject(model)); - res.result = "0"; - res.msg = "成功!"; - return res; + foreach (DisplayjobModelReq item in data) + { + //根据播种墙号查询灯带IP + DataTable dt = addrbll.QueryControlList(" and waveno ='" + item.wallNo + "'"); + if (dt != null && dt.Rows.Count > 0) + { + foreach (DataRow rowitem in dt.Rows) + { + string ipaddress = rowitem["controlip"].ToString().Trim(); + List conlist = cachedal.GetControlList().FindAll(o => o.controlip == ipaddress); + if (conlist != null && conlist.Count > 0) + { + MainControl control = conlist.FirstOrDefault().maincontrol; + DataTable locdt = addrbll.QueryAddrList(" and waveno ='" + item.wallNo + "' and location ='" + item.location + "' and controlip='" + ipaddress + "'"); + if (locdt != null && locdt.Rows.Count > 0) + { + List list = new List(); + 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); + + } + bool bo = control.LED_By_Paragraph(ipaddress, address, list); + if (bo) + { + res.resultCode = "0"; + res.resultMsg = "成功!"; + } + else + { + res.resultCode = "-1"; + res.resultMsg = "失败"; + return res; + } + + } + } + else + { + res.resultCode = "-1"; + res.resultMsg = "请先连接设备!"; + } + } + + } + else + { + res.resultCode = "-1"; + res.resultMsg = "连接失败"; + } + } } - catch (Exception ex) - { - LogHelper.WriteLogInfo("GetDataList异常:" + ex.Message); - res.msg = "请求异常!"; - res.result = "-1"; - return res; - } - } - - } - //初始化 - [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"; - } return res; } - } - - - - - - #region 设备检测 - [Route("TestStart")] - [HttpPost] - public ResultModel TestStart() - { - lock (lockinit) + catch (Exception ex) { - ResultModel res = new ResultModel(); - try - { - ResultModel result = contrbll.TestStart(); - - return result; - - } - catch (Exception ex) - { - LogHelper.WriteLogInfo("GetDataList异常:" + ex.Message); - res.msg = "请求异常!"; - res.result = "-1"; - return res; - - } + LogHelper.WriteLogInfo(ex.ToString(), LogHelper.Log_Type.ERROR); + res.resultMsg = "请求接口异常!"; + res.resultCode = "-1"; } + return res; } #endregion - #region 停止检测 - [Route("TestEnd")] - [HttpPost] - public ResultModel TestEnd() - { - lock (lockinit) - { - ResultModel res = new ResultModel(); - contrbll.TestEnd(); - res.msg = "成功!"; - res.result = "0"; - return res; - } - } - #endregion - - - - #region 停止作业 - [Route("EndWork")] - [HttpPost] - public ResultModel EndWork() - { - lock (lockinit) - { - ResultModel res = new ResultModel(); - contrbll.EndWork(); - res.msg = "成功!"; - res.result = "0"; - return res; - } - } - #endregion - - - } diff --git a/Epost.TestToolsWeb/Epost.DPS.csproj b/Epost.TestToolsWeb/Epost.DPS.csproj index 0337f12..96821d4 100644 --- a/Epost.TestToolsWeb/Epost.DPS.csproj +++ b/Epost.TestToolsWeb/Epost.DPS.csproj @@ -61,6 +61,10 @@ False ..\DLL\ExcelIntOut.dll + + False + ..\DLL\LightContrl.dll + ..\packages\Microsoft.ApplicationInsights.Agent.Intercept.1.2.1\lib\net45\Microsoft.AI.Agent.Intercept.dll True diff --git a/Epost.TestToolsWeb/Web.config b/Epost.TestToolsWeb/Web.config index d59abdf..7a688d8 100644 --- a/Epost.TestToolsWeb/Web.config +++ b/Epost.TestToolsWeb/Web.config @@ -32,7 +32,9 @@ - + + +