using Mapster;
using StackExchange.Profiling.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.MES;
using WIDESEA_Core;
using WIDESEA_Core.Enums;
using WIDESEA_DTO;
using WIDESEA_Model.Models;
using WIDESEA_StorageBasicRepository;
namespace WIDESEA_StoragIntegrationServices
{
public partial class WCSService
{
///
/// 涂总精排点
///
///
///
public WebResponseContent Queue(RequestTaskDto json)
{
WebResponseContent content = new WebResponseContent();
try
{
//查找对应的PVI码车身信息
var carinfo = _carBodyInfoRepository.QueryFirst(x => x.RFID == json.PVI);
if (carinfo == null) throw new Exception($"{json.PVI}车身信息未找到");
Dt_CarBodyInfo_hty carInfo_Hty = carinfo.Adapt();
carInfo_Hty.FinishTime = DateTime.Now;
carInfo_Hty.FinishType = (int)OperateTypeEnum.自动完成;
carInfo_Hty.sourceID = carinfo.Id;
VINRespon respon = new VINRespon();
if (!string.IsNullOrEmpty(carinfo.VIN))
{
respon = new VINRespon
{
VIN = carinfo.VIN,
Color = carinfo.carBodyCharacteristic,
SkyLight = carinfo.skylightCharacteristic,
VechicleModel = carinfo.vehicleCharacteristic,
};
_carBodyInfo_HtyRepository.AddData(carInfo_Hty);
_carBodyInfoRepository.DeleteData(carinfo);
return content.OK(data: respon);
}
var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == json.Position);
if (station == null) throw new Exception("站台未找到");
//涂总工单绑定
WebResponseContent webResponse = _mesService.bindWorkOrder("EL01RB01", json.PVI);
if (!webResponse.Status) throw new Exception($"绑定失败:{webResponse.msg},请求信息:{json.ToJson()}");
//过点信息
WebResponseContent content1 = _mesService.PassPoint(json);
if (!content1.Status) throw new Exception($"过点失败:{content1.msg},请求信息:{json.ToJson()}");
//获取VIN号
WebResponseContent responseContent = _mesService.getCharacteristic(json);
if (!responseContent.Status) throw new Exception($"BDC请求车辆特征信息:{responseContent.msg},请求信息:{json.ToJson()}");
respon = new VINRespon
{
VIN = responseContent.Data.ToString().Substring(35, 17),
Color = carinfo.carBodyCharacteristic,
SkyLight = carinfo.skylightCharacteristic,
VechicleModel = carinfo.vehicleCharacteristic,
};
var mesLock = _mesLockInfoRepository.QueryFirst(x => x.carBodyID == carinfo.Id);
_unitOfWorkManage.BeginTran();
//删除车身信息
carInfo_Hty.VIN = respon.VIN;
_carBodyInfo_HtyRepository.AddData(carInfo_Hty);
_carBodyInfoRepository.DeleteData(carinfo);
if (mesLock != null)
{
mesLock.LockStatue = 2;
_mesLockInfoRepository.UpdateData(mesLock);
}
_unitOfWorkManage.CommitTran();
content.OK(data: respon);
}
catch (Exception ex)
{
_unitOfWorkManage.RollbackTran();
content.Error(ex.Message);
}
return content;
}
}
}