|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using HBLConsole.Abstract;
- using BPA.Message;
- using HBLConsole.Model;
- using HBLConsole.Service;
- using BPA.Message.Enum;
- using HBLConsole.GVL;
- using Newtonsoft.Json;
- using HBLConsole.Communication;
-
- namespace HBLConsole.Business.AbstractServer
- {
- public class Base : AbstractMessageServer
- {
- public override void AddOrder<T>(T orderInfo)
- {
- if (orderInfo == null) return;
- if (orderInfo is MorkOrderPush morkOrderpush)
- {
- OrderData order = Json<KeepDataBase>.Data.orderLists.FirstOrDefault(par => par.OrderPush?.SuborderId == morkOrderpush.SuborderId);
- if (order == null)//防止重复订单
- {
- ActionManage.GetInstance.Send("AddOrder", morkOrderpush);
- GeneralConfig.morkOrderPushes.Enqueue(morkOrderpush);
- //ActionManage.GetInstance.Send("DataParse", morkOrderpush);
- }
- }
- }
-
- /// <summary>
- /// 接收来自MQTT 推送的物料信息
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="batchingInfo"></param>
- public override void GetBatchingInfo<T>(T batchingInfo)
- {
- if (batchingInfo == null) return;
- if (batchingInfo is OrderMaterialDelivery BatchingInfos)
- {
- Json<BatchingInfoPar>.Data.orderMaterialDelivery = BatchingInfos;
- MessageLog.GetInstance.Show("收到推送的物料信息");
- BatchingInfoDisplay();
- }
- }
-
- private void GetMake()
- {
- //http://localhost:5000/GetDeviceMake
- }
-
- /// <summary>
- /// 通过接口获取物料信息
- /// </summary>
- /// <param name="clientId"></param>
- public override void GetBatchingInfo(int clientId)
- {
- string result = string.Empty;
- for (int i = 0; i < 2; i++)
- {
- try
- {
- int PushType = i;//0:主料 1:辅料
- var jsondata = new { clientId, PushType };
- string header = $"[{InternetInfo.StockServer}/GetItemInfo]_[{DateTime.Now.Ticks}]";
- //string url = $"{InternetInfo.ApiAddress}{InternetInfo.StockServer}/GetItemInfo";
- //string url = $"http://192.168.0.62:7000{InternetInfo.StockServer}/GetItemInfo";
- string url = $"{InternetInfo.StockServer}GetItemInfo";
-
- result = APIHelper.GetInstance.HttpRequest(url, header, jsondata, RequestType.POST);
-
- if (PushType == 1)
- {
- Json<BatchingInfoPar>.Data.recipeBoms = JsonConvert.DeserializeObject<RecipeBoms>(result);
- ActionManage.GetInstance.Send("recipeBom");
- MessageLog.GetInstance.Show("接收到辅料信息");
- }
- else if (PushType == 0)
- {
- Json<BatchingInfoPar>.Data.orderMaterialDelivery = JsonConvert.DeserializeObject<OrderMaterialDelivery>(result);
- }
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.ShowEx(ex.ToString());
- }
- }
- BatchingInfoDisplay();
- //MessageLog.GetInstance.Show("【物料信息】");
- //Json<BatchingInfoPar>.Data.orderMaterialDelivery?.BatchingInfo?.ForEach(x =>
- //{
- // MessageLog.GetInstance.Show($"物料ID:=[{x.BatchingId}],{x.BatchingLoc}号位置:{x.BatchingCount}");
- //});
- }
-
- private void BatchingInfoDisplay()
- {
- MessageLog.GetInstance.Show("【物料信息】");
- Json<BatchingInfoPar>.Data.orderMaterialDelivery?.BatchingInfo?.ForEach(x =>
- {
- MessageLog.GetInstance.Show($"物料ID:=[{x.BatchingId}],{x.BatchingLoc}号位置:{x.BatchingCount}");
- });
- }
-
- /// <summary>
- /// 接收MQTT 推送过来的辅料信息
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="recipeBomInfo"></param>
- public override void GetRecipeBom<T>(T recipeBomInfo)
- {
- if (recipeBomInfo == null) return;
- if (recipeBomInfo is RecipeBoms recipeBom)
- {
- Json<BatchingInfoPar>.Data.recipeBoms = recipeBom;
- MessageLog.GetInstance.Show("接收到辅料信息");
- ActionManage.GetInstance.Send("recipeBom");
-
- Json<BatchingInfoPar>.Data.recipeBoms.RecipeIds.ForEach(x =>
- {
- //MessageLog.GetInstance.Show($"辅料ID:=[{x.RecipeBomId}],{x.RecipeBomLoc}号位置:{x.RecipeBomCount}");
- });
- }
- }
-
- /// <summary>
- /// 订单状态改变
- /// </summary>
- /// <param name="subOrderId"></param>
- /// <param name="status"></param>
- /// <returns></returns>
- public override bool OrderStatusChange(string subOrderId, ORDER_STATUS status)
- {
- return false;
- string result = string.Empty;
- OrderStatusChange orderStatusChange = new OrderStatusChange() { CookingStatus = status, SuborderId = subOrderId };
- try
- {
- string header = $"[{InternetInfo.OrderServer}/order/robotstatuschange]_[{DateTime.Now.Ticks}]";
- //string url = $"{InternetInfo.ApiAddress}{InternetInfo.OrderServer}/order/robotstatuschange";
- string url = $"{InternetInfo.OrderServer}robotstatuschange";
- result = APIHelper.GetInstance.HttpRequest(url, header, orderStatusChange, RequestType.POST);
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.ShowEx(ex.ToString());
- }
- var res = JsonConvert.DeserializeObject<OrderStatusRsp>(result);
- return res == null ? false : res.isSuccess;
- }
-
- /// <summary>
- /// 退单消息
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="chargebackInfo"></param>
- /// <exception cref="NotImplementedException"></exception>
- public override void Chargeback<T>(T chargebackInfo)
- {
- if (chargebackInfo == null) return;
- if (chargebackInfo is Chargeback chargeback)
- {
- ActionManage.GetInstance.Send("chargeback", chargeback.SubOrderId);
- }
- }
-
- public class OrderStatusRsp
- {
- /// <summary>
- /// 子订单ID
- /// </summary>
- public string SuborderId { get; set; }
- /// <summary>
- /// 订单状态
- /// </summary>
- public int Result { get; set; } = 0;
- public bool isSuccess { get; set; }
- public bool data { get; set; }
- public string msg { get; set; }
-
- }
- }
- }
|