diff --git a/DosingSystem/App.config b/DosingSystem/App.config
index ae6300c6..32eca971 100644
--- a/DosingSystem/App.config
+++ b/DosingSystem/App.config
@@ -12,6 +12,7 @@
+
@@ -59,5 +60,11 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/DosingSystem/App.xaml.cs b/DosingSystem/App.xaml.cs
index a70640df..649ffe85 100644
--- a/DosingSystem/App.xaml.cs
+++ b/DosingSystem/App.xaml.cs
@@ -4,6 +4,8 @@ using BPASmartClient.CustomResource.Pages.Model;
using BPASmartClient.CustomResource.Pages.View;
using BPASmartClient.CustomResource.Pages.ViewModel;
using BPASmartClient.DosingSystem.Model;
+using BPASmartClient.DosingSystem.Model.MQTT;
+using BPASmartClient.DosingSystem.Service;
using System;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
@@ -58,6 +60,7 @@ namespace BPASmartClient.DosingSystem
await Task.Run(() => { excute = ExcuteControl.GetInstance; });
MenuInit();
+
//SiemensTest.GetInstance.Init();
DeviceInquire.GetInstance.Init();//配料机设备上线监听,设备列表初始化
MainView mv = new MainView();
@@ -92,6 +95,8 @@ namespace BPASmartClient.DosingSystem
}
else
mv.Close();
+ ServerFactory.GetInstance.Set(new APIServer());
+ MqttServer.GetInstance.Init();
MainWindow = mv;
}
@@ -280,7 +285,7 @@ namespace BPASmartClient.DosingSystem
ToggleWindowPath = "View.DeviceListView"
});
//2023/6/29修改
- if ((ConveryType)Enum.Parse(typeof(ConveryType), Json.Data.BaseParModel.ConveryType) == ConveryType.U型)
+ if (!String.IsNullOrWhiteSpace(Json.Data.BaseParModel.ConveryType) && (ConveryType)Enum.Parse(typeof(ConveryType), Json.Data.BaseParModel.ConveryType) == ConveryType.U型)
{
DeviceMonitor.Add(new SubMenumodel()
{
diff --git a/DosingSystem/ExcuteControl.cs b/DosingSystem/ExcuteControl.cs
index b1ebe2f8..ae18e0bb 100644
--- a/DosingSystem/ExcuteControl.cs
+++ b/DosingSystem/ExcuteControl.cs
@@ -29,6 +29,8 @@ using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
using System.Windows.Navigation;
using System.Text.RegularExpressions;
using static System.Resources.ResXFileRef;
+using BPASmartClient.DosingSystem.Model.Dto;
+using BPASmartClient.DosingSystem.Model.MQTT;
namespace BPASmartClient.DosingSystem
{
@@ -102,8 +104,8 @@ namespace BPASmartClient.DosingSystem
RecipeRun();
BusinessExcute();
ConveyerPropertyReport();
-
-#if Debug
+ ThreadTaskInit();
+#if Debug
Task.Run(() => {
while (true)
{
@@ -749,8 +751,58 @@ namespace BPASmartClient.DosingSystem
+ ///
+ /// 多线程接收工单配方数据。
+ ///
+ private void ThreadTaskInit()
+ {
+ TaskManage.GetInstance.StartLong(new Action(() =>
+ {
+ while (MqttServer.GetInstance.WorkOrders.Count > 0)
+ {
+ if (MqttServer.GetInstance.WorkOrders.TryDequeue(out WorkOrderPusht wod))
+ {
+ App.Current?.Dispatcher?.Invoke(new Action(() =>
+ {
+ //TODO:工单数据处理,直接新建配方。
+ foreach (var recipe in wod.ProductList)
+ {
+ var tempRecipe = new RecipeModel();
+ var tempMaterials = new ObservableCollection();
+
+ if (Json.Data.Recipes.Any(p => p.RecipCode == recipe.Id))
+ {
+ continue;
+ }
+ else
+ {
+ tempRecipe.RecipCode = recipe.Id;
+ }
+ tempRecipe.RecipeName = recipe.Name;
+
+ foreach (var material in recipe.BOMEntryList)
+ {
+ tempMaterials.Add(new RawMaterialModel()
+ {
+ RawMaterialName = material.MaterialName,
+ DeviceIp="",
+ Loc=1,
+ RawMaterialWeight=(uint)material.BomQty,
+ RawMaterialSource=0,
+ RawMaterialId=material.MaterialId,
+ });
+ }
+ tempRecipe.RawMaterials = tempMaterials;
+ Json.Data.Recipes.Add(tempRecipe);
+ }
+ }));
+ }
+ }
+ Thread.Sleep(500);
+ }), "工单信息监听");
+ }
diff --git a/DosingSystem/Model/Dto/BOMEntryOutput.cs b/DosingSystem/Model/Dto/BOMEntryOutput.cs
new file mode 100644
index 00000000..362b39bd
--- /dev/null
+++ b/DosingSystem/Model/Dto/BOMEntryOutput.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.DosingSystem.Model.Dto
+{
+ ///
+ ///
+ ///
+ public class BOMEntryOutput
+ {
+ ///
+ /// 主键
+ ///
+ public string Id { get; set; }
+ ///
+ /// 工单id
+ ///
+ public string WorkOrderId { get; set; }
+ ///
+ /// 工单id
+ ///
+ public string WorkOrderName { get; set; }
+ ///
+ /// 配方单位
+ ///
+ public string UnitId { get; set; }
+ ///
+ /// 配方单位名称
+ ///
+ public string UnitName { get; set; }
+ ///
+ /// 上误差值
+ ///
+ public string UpErrorValue { get; set; }
+ ///
+ /// 下误差值
+ ///
+ public string DownErrorValue { get; set; }
+ ///
+ /// 物料id
+ ///
+ public string MaterialId { get; set; }
+ ///
+ /// 物料名称
+ ///
+ public string MaterialName { get; set; }
+ ///
+ /// 产品Id
+ ///
+ public string ProductId { get; set; }
+ ///
+ /// 产品名称
+ ///
+ public string ProductName { get; set; }
+ ///
+ /// 配方用量
+ ///
+ public decimal BomQty { get; set; }
+ ///
+ /// 产量
+ ///
+ public string Yield { get; set; }
+ ///
+ /// 配方id
+ ///
+ public string BomId { get; set; }
+ ///
+ /// 1主料配方0 辅料配方
+ ///
+ public bool IsMain { get; set; }
+ ///
+ /// 计划完成时间
+ ///
+ public string PlantEndTime { get; set; }
+ ///
+ /// 计划开始时间
+ ///
+ public string PlantStartTime { get; set; }
+ }
+}
diff --git a/DosingSystem/Model/Dto/BOMOutput.cs b/DosingSystem/Model/Dto/BOMOutput.cs
new file mode 100644
index 00000000..9558437b
--- /dev/null
+++ b/DosingSystem/Model/Dto/BOMOutput.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.DosingSystem.Model.Dto
+{
+ public class BOMOutput
+ {
+ ///
+ /// 主键
+ ///
+ public string Id { get; set; }
+ ///
+ /// 配方名称
+ ///
+ public string Name { get; set; }
+ ///
+ /// 1主料配方0 辅料配方
+ ///
+ public bool IsMain { get; set; }
+
+ ///
+ /// 配方明细
+ ///
+ public List BOMEntryList { get; set; } = new();
+
+ }
+}
diff --git a/DosingSystem/Model/Dto/WorkOrderPusht.cs b/DosingSystem/Model/Dto/WorkOrderPusht.cs
new file mode 100644
index 00000000..481d1a5e
--- /dev/null
+++ b/DosingSystem/Model/Dto/WorkOrderPusht.cs
@@ -0,0 +1,37 @@
+using BPASmartClient.DosingSystem.Model.MQTT.Messages;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.DosingSystem.Model.Dto
+{
+ public class WorkOrderPusht : IMessage
+ {
+ ///
+ /// 主键
+ ///
+ public string Id { get; set; }
+ ///
+ /// 工单名称
+ ///
+ public string Name { get; set; }
+ ///
+ /// 计划完成时间
+ ///
+ public string PlantEndTime { get; set; }
+ ///
+ /// 产量
+ ///
+ public string Yield { get; set; }
+ ///
+ /// 计划开始时间
+ ///
+ public string PlantStartTime { get; set; }
+ ///
+ /// 配方信息
+ ///
+ public List ProductList { get; set; } = new();
+ }
+}
diff --git a/DosingSystem/Model/MQTT/IServer.cs b/DosingSystem/Model/MQTT/IServer.cs
new file mode 100644
index 00000000..61b2bf75
--- /dev/null
+++ b/DosingSystem/Model/MQTT/IServer.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.DosingSystem.Model.MQTT
+{
+ public interface IServer
+ {
+
+ Task Init(params object[] pars);
+
+ void Dispose();
+ }
+}
diff --git a/DosingSystem/Model/MQTT/Messages/IMessage.cs b/DosingSystem/Model/MQTT/Messages/IMessage.cs
new file mode 100644
index 00000000..d911d758
--- /dev/null
+++ b/DosingSystem/Model/MQTT/Messages/IMessage.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.DosingSystem.Model.MQTT.Messages
+{
+ public interface IMessage
+ {
+ }
+}
diff --git a/DosingSystem/Model/MQTT/Messages/MessageDefine.cs b/DosingSystem/Model/MQTT/Messages/MessageDefine.cs
new file mode 100644
index 00000000..55303690
--- /dev/null
+++ b/DosingSystem/Model/MQTT/Messages/MessageDefine.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+
+namespace BPASmartClient.DosingSystem.Model.MQTT.Messages
+{
+ public class MessageDefine
+ {
+ public static readonly Dictionary MSG = new Dictionary()
+ {
+ { MessageID.WorkOrderIssued,typeof(WorkOrderPublishOutput)},
+ };
+ }
+}
\ No newline at end of file
diff --git a/DosingSystem/Model/MQTT/Messages/MessageID.cs b/DosingSystem/Model/MQTT/Messages/MessageID.cs
new file mode 100644
index 00000000..5f19610d
--- /dev/null
+++ b/DosingSystem/Model/MQTT/Messages/MessageID.cs
@@ -0,0 +1,16 @@
+namespace BPASmartClient.DosingSystem.Model.MQTT.Messages
+{
+ public class MessageID
+ {
+ public const int DevcieControl = 1;//出入库命令控制ID
+ public const int WorkOrderIssued = 2;//工单下发ID
+ public const int StatusChange = 3;//配料流程修改ID
+ public const int MakeDown = 4;//工单配方下发ID
+ public const int DeviceDataUpdate = 5;//设备数据更新ID
+ public const int HandControlComm = 6;//手动控制命令
+ public const int DataActualTimeUpdate = 7;//设备数据实时更新
+ public const int UiChangeNotify = 8;//UI操作更新
+ public const int StoreStockTaking = 9;//库存盘点
+ public const int LogInfoNotify = 10;//业务服务日志消息通知
+ }
+}
\ No newline at end of file
diff --git a/DosingSystem/Model/MQTT/Messages/MqttBaseModel.cs b/DosingSystem/Model/MQTT/Messages/MqttBaseModel.cs
new file mode 100644
index 00000000..d5c210ac
--- /dev/null
+++ b/DosingSystem/Model/MQTT/Messages/MqttBaseModel.cs
@@ -0,0 +1,8 @@
+namespace BPASmartClient.DosingSystem.Model.MQTT.Messages
+{
+ public class MqttBaseModel : IMessage
+ {
+ /// 客户端唯一ID,客户端区分
+ public short ClientId { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/DosingSystem/Model/MQTT/Messages/MsgPackExtensionMethod.cs b/DosingSystem/Model/MQTT/Messages/MsgPackExtensionMethod.cs
new file mode 100644
index 00000000..973dff85
--- /dev/null
+++ b/DosingSystem/Model/MQTT/Messages/MsgPackExtensionMethod.cs
@@ -0,0 +1,86 @@
+using BPA.Helper;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using System;
+using System.Linq;
+
+namespace BPASmartClient.DosingSystem.Model.MQTT.Messages
+{
+ public static class MsgPackExtensionMethod
+ {
+ public static MsgPackage Deserialize(this string msg)
+ {
+ if (msg != null)
+ {
+ if (msg.Iskey("MessageId") && msg.Iskey("Message") && msg.Iskey("MessageLen"))
+ {
+ var obj = msg.FromJSON();
+ if (obj != null)
+ return obj;
+ }
+ else
+ {
+ var id = msg.ToLower().GetJsonObjValue("messageid");
+ if (int.TryParse(id, out int tempId))
+ {
+ if (MessageDefine.MSG.ContainsKey(tempId))
+ {
+ MsgPackage package = new MsgPackage();
+ package.MessageId = tempId;
+ if (int.TryParse(msg.ToLower().GetJsonObjValue("messagelen"), out int tempLen))
+ package.MessageLen = tempLen;
+ var res = msg.ToLower().GetJsonObjValue("message");
+ if (res != null)
+ {
+ package.Message = (IMessage)JsonConvert.DeserializeObject(res, MessageDefine.MSG[tempId]);
+ }
+ return package;
+ }
+ }
+ }
+ }
+ return new MsgPackage();
+ }
+
+ public static string Serialize(this IMessage mes)
+ {
+ MsgPackage msg = new MsgPackage();
+ var res = MessageDefine.MSG.FirstOrDefault(p => p.Value == mes.GetType());
+ msg.MessageId = res.Key;
+ msg.MessageLen = JsonConvert.SerializeObject(mes).Length;
+ msg.Message = mes;
+ return JsonConvert.SerializeObject(msg);
+ }
+
+ public static string GetJsonObjValue(this string input, string key)
+ {
+ try
+ {
+ JObject jo = (JObject)JsonConvert.DeserializeObject(input);
+ if (jo != null && jo.ContainsKey(key))
+ return jo[key].ToString();
+ else
+ return string.Empty;
+ }
+ catch (Exception EX)
+ {
+ MessageLog.GetInstance.ShowEx(EX.ToString());
+ return string.Empty;
+ }
+ }
+
+ public static bool Iskey(this string input, string key)
+ {
+ try
+ {
+ JObject jo = (JObject)JsonConvert.DeserializeObject(input);
+ return jo != null && jo.ContainsKey(key);
+ }
+ catch (Exception EX)
+ {
+ MessageLog.GetInstance.ShowEx(EX.ToString());
+ return false;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DosingSystem/Model/MQTT/Messages/MsgPackage.cs b/DosingSystem/Model/MQTT/Messages/MsgPackage.cs
new file mode 100644
index 00000000..31a4961c
--- /dev/null
+++ b/DosingSystem/Model/MQTT/Messages/MsgPackage.cs
@@ -0,0 +1,17 @@
+using Newtonsoft.Json;
+
+namespace BPASmartClient.DosingSystem.Model.MQTT.Messages
+{
+ public class MsgPackage
+ {
+ /// 消息ID
+ public int MessageId { get; set; }
+
+ /// 消息内容
+ [JsonProperty(TypeNameHandling = TypeNameHandling.Auto)]
+ public IMessage Message { get; set; }
+
+ /// 消息长度
+ public int MessageLen { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/DosingSystem/Model/MQTT/Messages/WorkOrderPublishOutput.cs b/DosingSystem/Model/MQTT/Messages/WorkOrderPublishOutput.cs
new file mode 100644
index 00000000..9824b536
--- /dev/null
+++ b/DosingSystem/Model/MQTT/Messages/WorkOrderPublishOutput.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.DosingSystem.Model.MQTT.Messages
+{
+ ///
+ /// 下发数据
+ ///
+ public class WorkOrderPublishOutput : IMessage
+ {
+ ///
+ /// 工单Id
+ ///
+ public string WorkOrderId { get; set; }
+ }
+}
diff --git a/DosingSystem/Model/MQTT/MqttServer.cs b/DosingSystem/Model/MQTT/MqttServer.cs
new file mode 100644
index 00000000..b7d977d1
--- /dev/null
+++ b/DosingSystem/Model/MQTT/MqttServer.cs
@@ -0,0 +1,120 @@
+using Aop.Api.Domain;
+using BPA.Communication;
+using BPA.Communication.Base;
+using BPA.Helper;
+using BPASmartClient.DosingSystem.Model.Dto;
+using BPASmartClient.DosingSystem.Model.MQTT.Messages;
+using BPASmartClient.DosingSystem.Service;
+using BPASmartClient.Model;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.DosingSystem.Model.MQTT
+{
+ public class MqttServer : IServer
+ {
+ private volatile static MqttServer _Instance;
+ public static MqttServer GetInstance => _Instance ?? (_Instance = new MqttServer());
+ private MqttServer() { }
+
+ ///
+ /// MQTT 消息
+ ///
+ ConcurrentQueue msg= new ConcurrentQueue();
+ MqttHelper mqttHelper = new MqttHelper();
+
+ NameValueCollection mqttParam;
+
+ ///
+ /// 工单信息
+ ///
+ public ConcurrentQueue WorkOrders { get; set; } = new ConcurrentQueue();
+
+ public Task Init(params object[] pars)
+ {
+ return Task.Factory.StartNew(() =>
+ {
+ mqttParam = (NameValueCollection)System.Configuration.ConfigurationManager.GetSection("FlexBatchSystem/MQTTParam");
+
+ //mqttHelper.IsVerifyNetwork = false;
+ mqttHelper.MessageRecive = new Action(
+ s => {
+ msg.Enqueue(s); });
+ mqttHelper.Connected = new Action(() =>
+ {
+ if (pars.Length > 0)
+ {
+ pars.ToList().ForEach(item => { mqttHelper.Subscrib(item?.ToString()); });
+ }
+ else
+ {
+ //mqttHelper.Subscrib(Topics.MakeDown);
+
+ //mqttHelper.Subscrib(Topics.StatusChange);
+
+ mqttHelper.Subscrib(Topics.WorkOrderDown);
+
+ //mqttHelper.Subscrib(Topics.DataActualTimeUpdate);
+ }
+ TaskManage.GetInstance.StartLong(new Action(() =>
+ {
+ while (msg.Count > 0)
+ {
+ try
+ {
+ if (msg.TryDequeue(out string str))
+ {
+ var res = str.Deserialize();
+ if (res?.Message is WorkOrderPublishOutput wod)
+ WorkOrderPublish(wod);
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageLog.GetInstance.ShowEx(ex.ToString());
+ }
+
+ }
+ Thread.Sleep(10);
+ }), "MCS工单信息接收", true);
+ });
+ //mqttHelper.Connect(Json.Data.MqttUser, Json.Data.MqttPas, Json.Data.MqttIp, Json.Data.MqttPort, $"WCS系统,{Guid.NewGuid()}");
+ mqttHelper.Connect(new ConfigurationOptions()
+ {
+ UserName = mqttParam?.Get("UserName")?? "admin",
+ Password = mqttParam?.Get("Password")?? "admin8765490789",
+ IpAddress =mqttParam?.Get("IpAddress")?? "111.9.47.105",
+ Port =int.TryParse( mqttParam?.Get("Port"),out int port)?port:18883,
+ ClientId = $"WCS系统业务消息,{Guid.NewGuid()}"
+ });
+ });
+ }
+ private void WorkOrderPublish(WorkOrderPublishOutput wod)
+ {
+ Task.Factory.StartNew(new Action(() =>
+ {
+ var x = ServerFactory.GetInstance.Get().GetWorkOrder(wod.WorkOrderId);
+ if (x.IsSuccess && x.Content.Count > 0)
+ {
+ var wop = x.Content.ElementAt(0);
+ wop.ProductList = wop.ProductList.OrderBy(p => p.Name).ToList();
+ WorkOrders.Enqueue(wop);
+ }
+ }));
+ }
+
+ public void Dispose()
+ {
+ mqttHelper.Dispose();
+ }
+
+ public static void Dis() => _Instance = null;
+ }
+}
diff --git a/DosingSystem/Model/MQTT/Topics.cs b/DosingSystem/Model/MQTT/Topics.cs
new file mode 100644
index 00000000..076a1dbc
--- /dev/null
+++ b/DosingSystem/Model/MQTT/Topics.cs
@@ -0,0 +1,61 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.DosingSystem.Model.MQTT
+{
+ public class Topics
+ {
+ ///
+ /// 工单下发
+ ///
+ public const string WorkOrderDown = "WMS/WCS/WorkOrderDown";
+
+ ///
+ /// 工单配方下发
+ ///
+ public const string MakeDown = "WCSClient/WCSServer/MakeDown";
+
+ ///
+ /// 控制命令,出入库操作
+ ///
+ public const string ControlComm = "WCSClient/WCSServer/ControlComm";
+
+ ///
+ /// 配料状态更改
+ ///
+ public const string StatusChange = "WCSServer/WCSClient/StatusChange";
+
+ ///
+ /// 称重设备数据更新
+ ///
+ public const string DeviceDataUpdate = "WCSServer/WCSClient/DataUpdate";
+
+ ///
+ /// 手动控制命令下发
+ ///
+ public const string HandControlComm = "WCSClient/WCSServer/HandControlComm";
+
+ ///
+ /// 设备数据实时更新
+ ///
+ public const string DataActualTimeUpdate = "WCSServer/WCSClient/DataActualTimeUpdate";
+
+ ///
+ /// UI操作修改数据时触发更新其它UI
+ ///
+ public const string UIDataChange = "WCSClient/WCSClient/UIDataChange";
+
+ ///
+ /// 盘库消息+库房ID
+ ///
+ public static string StoreStockTaking = "WMS/WCSClient/StoreStockTaking";
+
+ ///
+ /// 日志消息通知
+ ///
+ public static string LogInfoNotify = "WCSBusines/WCS/LoginfoNotify";
+ }
+}
diff --git a/DosingSystem/Service/APIResult.cs b/DosingSystem/Service/APIResult.cs
new file mode 100644
index 00000000..7073a9de
--- /dev/null
+++ b/DosingSystem/Service/APIResult.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.DosingSystem.Service
+{
+ public class APIResult
+ {
+ public T Content { get; set; }
+
+ public string ErrorMesg { get; set; } = string.Empty;
+
+ public bool IsSuccess { get; set; }
+ }
+
+ public class APIResult
+ {
+ public string ErrorMesg { get; set; } = string.Empty;
+
+ public bool IsSuccess { get; set; }
+ }
+}
diff --git a/DosingSystem/Service/APIServer.cs b/DosingSystem/Service/APIServer.cs
new file mode 100644
index 00000000..a9160895
--- /dev/null
+++ b/DosingSystem/Service/APIServer.cs
@@ -0,0 +1,35 @@
+using BPA.Helper;
+using BPA.Message;
+using BPASmartClient.DosingSystem.Model.Dto;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.DosingSystem.Service
+{
+ public class APIServer : IAPIServer
+ {
+
+
+ ///
+ /// 设置业务插件状态
+ ///
+ ///
+ ///
+ public APIResult PlugInstatusSet(bool state)
+ {
+ var data = new { state = state };
+ var res = APIHelper.GetInstance.PostRequest($"{ApiRoute.SetStatus}{state}", data.ToJson());
+ return new FromT(res).Result;
+ }
+
+ public APIResult> GetWorkOrder(string workOrderId)
+ {
+ var data = new { workOrderId = workOrderId, startTime = "", endTime = "" };
+ var res = APIHelper.GetInstance.PostRequest(ApiRoute.WorkOrderData, data.ToJson());
+ return new FromT>(res).Result;
+ }
+ }
+}
diff --git a/DosingSystem/Service/ApiRoute.cs b/DosingSystem/Service/ApiRoute.cs
new file mode 100644
index 00000000..c676cd29
--- /dev/null
+++ b/DosingSystem/Service/ApiRoute.cs
@@ -0,0 +1,87 @@
+using BPA.Helper;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.DosingSystem.Service
+{
+ public class ApiRoute
+ {
+
+ private static string APIAddress => "http://111.9.47.105:18090";
+ //private static string APIAddress => "https://localhost:44342";
+
+ ///
+ /// 货架路由
+ ///
+ public static string StoreShelves => $"{APIAddress}/StoreShelves/List";
+
+ ///
+ /// 库位路由
+ ///
+ public static string StorePlace => $"{APIAddress}/StorePlace/MaterialStorePlaceList";
+
+ ///
+ /// 库位数据更新(库位坐标更新)
+ ///
+ public static string StorePlaceUpdate => $"{APIAddress}/StorePlace/Update";
+
+ ///
+ /// 获取物料信息
+ ///
+ public static string GetMaterialInfo => $"{APIAddress}/Material/GetMaterialList";
+
+ ///
+ /// 获取电子标签
+ ///
+ public static string GetCaseTagList => $"{APIAddress}/CaseTag/List";
+
+ ///
+ /// 出入库管理
+ ///
+ public static string StockFlowManager => $"{APIAddress}/StockFlow/Add";
+
+ ///
+ /// 库位解绑
+ ///
+ public static string StockUnBind => $"{APIAddress}/MaterialStock/UnBind";
+
+ ///
+ /// 绑定标签
+ ///
+ public static string BindTag => $"{APIAddress}/StorePlace/BindCaseTag";
+
+ ///
+ /// 库位坐标批量更新
+ ///
+ public static string BatchUpdate => $"{APIAddress}/StorePlace/BatchUpdate";
+
+ ///
+ /// 出入库流水记录添加(更新库位余量数据)
+ ///
+ public static string MaterialStockUpdate => $"{APIAddress}/StockFlow/Add";
+
+ ///
+ /// 库存盘点数据
+ ///
+ public static string StoreStockTakingInfo => $"{APIAddress}/StoreStockTakingInfo/Add";
+
+ ///
+ /// 工单下发数据
+ ///
+ public static string WorkOrderData => $"{APIAddress}/WorkOrder/WorkOrderData";
+
+ ///
+ /// 业务插件唯一性状态设置
+ ///
+ public static string SetStatus => $"{APIAddress}/Basic/PlugInstatusSet?state=";
+
+ ///
+ /// 获取库房信息
+ ///
+ public static string GetStoreHouseInfo => $"{APIAddress}/StoreHouse/List";
+
+ }
+}
diff --git a/DosingSystem/Service/FormT.cs b/DosingSystem/Service/FormT.cs
new file mode 100644
index 00000000..ed2ebc72
--- /dev/null
+++ b/DosingSystem/Service/FormT.cs
@@ -0,0 +1,41 @@
+using BPA.Helper;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.DosingSystem.Service
+{
+ public class FromT
+ {
+ public APIResult Result { get; set; } = new APIResult();
+ public FromT(string msg)
+ {
+ if (string.IsNullOrEmpty(msg))
+ return;
+ //Result.Content = msg.ToJson("content").FromJSON();
+ if (msg.ToJson("content").TryFromJSON(out T temp))
+ Result.Content = temp;
+ else
+ {
+ Result.Content = (T)Convert.ChangeType(msg.ToJson("content"), typeof(T));
+ }
+ Result.ErrorMesg = msg.ToJson("message");
+ Result.IsSuccess = msg.ToJson("isSuccess").ToLower().FromJSON();
+ }
+ }
+
+
+ public class FromT
+ {
+ public APIResult Result { get; set; } = new APIResult();
+ public FromT(string msg)
+ {
+ if (string.IsNullOrEmpty(msg))
+ return;
+ Result.ErrorMesg = msg.ToJson("message");
+ Result.IsSuccess = msg.ToJson("isSuccess").ToLower().FromJSON();
+ }
+ }
+}
diff --git a/DosingSystem/Service/IAPIServer.cs b/DosingSystem/Service/IAPIServer.cs
new file mode 100644
index 00000000..821df153
--- /dev/null
+++ b/DosingSystem/Service/IAPIServer.cs
@@ -0,0 +1,116 @@
+using BPA.Message;
+using BPA.Models;
+using BPASmartClient.DosingSystem.Model.Dto;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.DosingSystem.Service
+{
+ public interface IAPIServer
+ {
+ ///
+ /// 获取货架信息
+ ///
+ ///
+ /// 创库ID
+ ///
+ //APIResult> GetStoreShelvesInfo(string id, string houseId);
+
+ ///
+ /// 获取库位信息
+ ///
+ ///
+ /// 仓库ID
+ /// 货架ID
+ ///
+ //APIResult> GetStorePlace(string id, string houseId, string shelvesId);
+
+ ///
+ /// 批量更新库位坐标
+ ///
+ ///
+ ///
+ //APIResult BatchUpdate(List stores);
+
+ ///
+ /// 更新库位坐标
+ ///
+ ///
+ ///
+ // APIResult StorePlaceUpdate(StorePlaceParModel store);
+
+ ///
+ /// 获取物料信息
+ ///
+ ///
+ // APIResult> GetMaterialInfo();
+
+ ///
+ /// 获取电子标签
+ ///
+ //APIResult> GetCaseTagList();
+
+ ///
+ /// 出入库流水管理
+ ///
+ ///
+ ///
+ // APIResult StockFlowManager(StockFlowManagerModel sfm);
+
+ ///
+ /// 库位解绑
+ ///
+ /// 物料ID
+ /// 库位ID
+ ///
+ //APIResult StockUnBind(string MaterialId, string PlaceId);
+
+ ///
+ /// 库位绑定标签
+ ///
+ /// 库位ID
+ /// 标签ID
+ ///
+ // APIResult BindTag(string PlaceId, string TagId);
+
+ ///
+ /// 库位数据更新
+ ///
+ /// 物料ID
+ /// 库位ID
+ /// 数量
+ /// 主键ID
+ ///
+ //APIResult MaterialStockUpdate(string materialId, string placeId, double qty, string id);
+
+ ///
+ /// 盘库操作
+ ///
+ /// 库位信息
+ ///
+ //APIResult StoreStockTakingInfoService(List sstie);
+
+ ///
+ /// 设置业务插件状态
+ ///
+ ///
+ ///
+ APIResult PlugInstatusSet(bool state);
+
+ ///
+ /// 获取工单信息
+ ///
+ ///
+ ///
+ APIResult> GetWorkOrder(string workOrderId);
+
+ ///
+ /// 获取库房信息
+ ///
+ ///
+ //APIResult> GetStoreHouseInfo();
+ }
+}
diff --git a/DosingSystem/Service/ServerFactory.cs b/DosingSystem/Service/ServerFactory.cs
new file mode 100644
index 00000000..fc98aa83
--- /dev/null
+++ b/DosingSystem/Service/ServerFactory.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPASmartClient.DosingSystem.Service
+{
+ public class ServerFactory
+ {
+ private volatile static ServerFactory _Instance;
+ public static ServerFactory GetInstance => _Instance ?? (_Instance = new ServerFactory());
+ private ServerFactory() { }
+
+ ConcurrentDictionary servers = new ConcurrentDictionary();
+
+ public void Set(T server) where T : IAPIServer
+ {
+ string name = server.GetType().Name;
+ if (!servers.ContainsKey(name))
+ {
+ servers.TryAdd(name, server);
+ }
+ }
+
+ public IAPIServer Get()
+ {
+ if (servers.Count > 0)
+ return servers.ElementAt(0).Value;
+ return default;
+ }
+
+ public IAPIServer Get(TServer server) where TServer : IAPIServer
+ {
+ var name = server.GetType().Name;
+ if (servers.ContainsKey(name))
+ return servers[name];
+ return default;
+ }
+
+ }
+}