using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.WMSInfo;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_Tasks.ProductionLineJob;
namespace WIDESEAWCS_Tasks
{
public partial class CommonProductionLineJob
{
///
/// 入库产线
///
///
///
public void ProductionLineIn(OtherDevice ProductionLine)
{
foreach (var item in ProductionLine.DeviceProDTOs.GroupBy(x => x.DeviceChildCode))
{
var request = ProductionLine.GetValue(ProductionLineDBName.request, item.Key);
if (request == 1)
{
var traytype = ProductionLine.GetValue(ProductionLineDBName.trayType, item.Key);
var content = Request(ProductionLine, traytype, item.Key);
if (content.Status) ProductionLine.SetValue(ProductionLineDBName.Wrequest, 1, item.Key);
}
}
}
///
/// 出库产线
///
///
public void ProductionLineOut(OtherDevice ProductionLine)
{
foreach (var item in ProductionLine.DeviceProDTOs.GroupBy(x => x.DeviceChildCode))
{
var request = ProductionLine.GetValue(ProductionLineDBName.request, item.Key);
if (request == 1)
{
bool ok = false;
var traytype = ProductionLine.GetValue(ProductionLineDBName.trayType, item.Key);
if (traytype == 2 || traytype == 4 || traytype == 6)
ok = Request(ProductionLine, traytype, item.Key).Status;
else
{
var task = _taskService.QuertOutProductionLineTask(true);
if (task != null)
{
//if (task.Remark.ObjToInt() == traytype)
if (!string.IsNullOrEmpty(task.Remark) && traytype == 5)
{
task.TargetAddress = item.Key;
task.NextAddress = item.Key;
ok = _taskService.UpdateData(task).Status;
}
}
}
if (ok) ProductionLine.SetValue(ProductionLineDBName.Wrequest, 1, item.Key);
}
}
}
///
/// 申请
///
/// 产线
/// 托盘类型
/// 站台号
///
public WebResponseContent Request(OtherDevice ProductionLine, short traytype, string station)
{
WebResponseContent response = new WebResponseContent();
ProductionLineDTO MaterielGroupDTO = new ProductionLineDTO();
try
{
switch (traytype)
{
case 1://放空托
case 3://放空盒
//case 5://放满盒
{
MaterielGroupDTO.stationCode = station;
MaterielGroupDTO.traytype = traytype;
}
break;
case 2://取空托
case 4://取满盒
case 6://取空盒
{
MaterielGroupDTO.Barcode = ProductionLine.GetValue(ProductionLineDBName.trayBarcode, station);
MaterielGroupDTO.stationCode = station;
MaterielGroupDTO.traytype = traytype;
if (traytype == 4)
{
#region 读取数量
//var productQtyadd = ProductionLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ProductionLineDBName.productQty.ToString() && x.DeviceChildCode == station);
//var productQty = ProductionLine.Communicator.Read(productQtyadd.DeviceProAddress, (ushort)productQtyadd.DeviceProDataLength);
//#endregion
//#region 写入数量
//var WproductQtyadd = ProductionLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ProductionLineDBName.WproductQty.ToString() && x.DeviceChildCode == station);
//ProductionLine.Communicator.Write(WproductQtyadd.DeviceProAddress, productQty);
#endregion
MaterielGroupDTO.batchNo = ProductionLine.GetValue(ProductionLineDBName.batchNo, station);
//MaterielGroupDTO.productQty = string.Join(",", productQty);
}
}
break;
#region MyRegion
//case 3://放空盒
// {
// MaterielGroupDTO.stationCode = station;
// MaterielGroupDTO.traytype = traytype;
// }
// break;
//case 4://取满盒
// {
// //var productQty = ProductionLine.GetValue(ProductionLineDBName.productQty, station);
// #region 读取数量
// var productQtyadd = ProductionLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ProductionLineDBName.productQty.ToString() && x.DeviceChildCode == station);
// var productQty = ProductionLine.Communicator.Read(productQtyadd.DeviceProAddress, (ushort)productQtyadd.DeviceProDataLength);
// #endregion
// #region 写入数量
// var WproductQtyadd = ProductionLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ProductionLineDBName.WproductQty.ToString() && x.DeviceChildCode == station);
// ProductionLine.Communicator.Write(WproductQtyadd.DeviceProAddress, productQty);
// #endregion
// var batchNo = ProductionLine.GetValue(ProductionLineDBName.batchNo, station);
// var trayBarcode = ProductionLine.GetValue(ProductionLineDBName.trayBarcode, station);
// MaterielGroupDTO.batchNo = batchNo;
// MaterielGroupDTO.Barcode = trayBarcode;
// MaterielGroupDTO.stationCode = station;
// MaterielGroupDTO.traytype = traytype;
// MaterielGroupDTO.productQty = string.Join(",", productQty);
// }
// break;
//case 5://放满盒
// {
// MaterielGroupDTO.stationCode = station;
// MaterielGroupDTO.traytype = traytype;
// }
// break;
//case 6://取空盒
// {
// }
// break;
#endregion
default:
throw new Exception("未定义托盘类型");
}
response = ProductionLineToWMSRequest(MaterielGroupDTO);
}
catch (Exception ex)
{
response.Error(ex.Message);
}
return response;
}
public WebResponseContent ProductionLineToWMSRequest(ProductionLineDTO MaterielGroupDTO)
{
WebResponseContent content = new WebResponseContent();
try
{
var ResultData = HttpHelper.PostAsync(WMSInterfaceAddress.ProductionlineRequest, MaterielGroupDTO.ToJson(), headers: new Dictionary());
if (ResultData.Result == null) throw new Exception($"产线向WMS请求超时");
content = JsonConvert.DeserializeObject(ResultData.Result);
#region 产线申请入库任务
if (content != null && content.Status)//任务转换
{
var task = JsonConvert.DeserializeObject(content.Data.ToJson());
if (task != null)
{
List TaskNums = new List();
List routers = _routerService.QueryNextRoutes(task.CurrentAddress, task.TargetAddress);
if (routers.Count > 0)
{
task.NextAddress = routers.FirstOrDefault().ChildPosi;
}
task.WMSId = task.TaskId;
task.Creater = "WMS";
task.Dispatchertime = null;
task.CreateDate = DateTime.Now;
content = _taskService.AddData(task);
TaskNums.Add(task.TaskNum);
_taskExecuteDetailService.AddTaskExecuteDetail(TaskNums, "接收WMS任务");
}
}
#endregion
}
catch (Exception ex)
{
content.Error(ex.Message);
}
return content;
}
}
}