You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.7 KiB
C#

using JwKdsV.Core.MessageEvent;
using JwKdsV.Core.Utils;
using JwKdsV.Entity.OrderPackage;
using NLog;
using POSV.Common;
using POSV.Common.JsonObject;
using POSV.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace JwKdsV.Core.SocketMessage
{
/// <summary>
/// 出品显示设备接收服务中心推送的划菜信息处理
/// </summary>
public class KdsHuacaiNotify
{
private static ILogger logger = NLog.LogManager.GetCurrentClassLogger();
public static void OnKdsHuacaiNotify(string huacaiJson)
{
logger.Info("出品厨显收到划菜通知:{0}", huacaiJson);
var response = new BaseDataResponse<KdsHuacaiResponse>();
try
{
var isNew = false;
var hua = JsonUtils.Deserialize<KdsHuacai>(huacaiJson);
ServiceOrderItem item = null;
lock (Global.Instance.SyncLock)
{
using(var db = Global.Instance.OpenDataBase)
{
using (var transaction = db.GetTransaction())
{
foreach(var temp in hua.Data)
{
item = db.FirstOrDefault<ServiceOrderItem>("where id = @0 and huacaiTime is null", temp.ItemId);
if(item != null)
{
isNew = true;
item.HuacaiTime = temp.HuacaiTime;
item.ModifyDate = DateTime.Now;
db.Save(item);
}
}
transaction.Complete();
}
}
System.Threading.Thread.Sleep(50);
}
response.Status = 1;
response.Message = "出品厨显接收成功";
response.Data = new KdsHuacaiResponse();
response.Data.RequestObj = huacaiJson;
if (isNew)
{
//通知界面更改显示
MsgEvent.Send(Constant.NEWHUACAIITEM, null);
}
}
catch(Exception ex)
{
logger.Error(ex, "出品厨显接收划菜异常");
response.Status = 0;
response.Message = "出品厨显接收划菜异常";
}
finally
{
WebSocketEnter.Instance.Send(CommandName.KDSHUACAIRESPONSE, response);
}
}
}
}