using AngleSharp.Common;
using Masuit.Tools;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common;
using WIDESEA_Common.MES;
using WIDESEA_Common.MES.Request;
using WIDESEA_Core;
using WIDESEA_Core.Const;
using WIDESEA_Core.Helper;
using WIDESEAWCS_BasicInfoService;
using WIDESEAWCS_Model.Models;
namespace WIDESEA_StoragIntegrationServices
{
///
/// 锁车上报
///
public partial class MESService
{
public WebResponseContent Lock(object jsondata)
{
WebResponseContent content = new WebResponseContent();
try
{
var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_MESIPAddress);
var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MESIPAddress)?.ConfigValue;
var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.bindWorkOrder)?.ConfigValue;
if (wmsBase == null || ipAddress == null)
{
throw new InvalidOperationException("WMS IP 未配置");
}
var wmsIpAddress = wmsBase + ipAddress;
var carBodyInfo = _carBodyRepository.QueryFirst(x => x.RFID == "");
if (carBodyInfo == null) throw new Exception($"未找到PVI的车身数据");
BindWorkOrder bindOrder = new BindWorkOrder()
{
unionKey = Guid.NewGuid().ToString(),
stationCode = "",
messageTime = DateTime.Now.ToString(),
plantCode = "1052",
pvi = carBodyInfo.PVI,
};
var MESrespon = HttpHelper.PostAsync(wmsIpAddress, bindOrder.ToJson(), contentType, headers).Result;
Console.WriteLine(MESrespon);
WebResponseContent webResponse = JsonConvert.DeserializeObject(MESrespon.ToString());
if (webResponse.Code != 200)
{
throw new Exception($"{webResponse.msg}");
}
BindWorkOrderRespon characterRespon = JsonConvert.DeserializeObject(webResponse.Data.ToJson());
_unitOfWorkManage.BeginTran();
LogFactory.GetLog("锁车上报").Info(true, $"\r\r--------------------------------------");
LogFactory.GetLog("锁车上报").Info(true, jsondata.ToJsonString());
_unitOfWorkManage.CommitTran();
return content.OK();
}
catch (Exception ex)
{
return content.Error(ex.Message);
}
}
}
}