using MailKit.Search;
|
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.Extensions.Logging;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
|
using System;
|
using System.Collections.Generic;
|
using System.DirectoryServices.Protocols;
|
using System.Linq;
|
using System.Reflection;
|
using System.Reflection.Metadata;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Common.LocationEnum;
|
using WIDESEA_Common.Log;
|
using WIDESEA_Common.StockEnum;
|
using WIDESEA_Common.TaskEnum;
|
using WIDESEA_Common.WareHouseEnum;
|
using WIDESEA_Core;
|
using WIDESEA_Core.Enums;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_DTO.Inbound;
|
using WIDESEA_DTO.Task;
|
using WIDESEA_Model.Models;
|
using static WIDESEA_ITaskInfoService.ITaskService;
|
|
namespace WIDESEA_TaskInfoService
|
{
|
public partial class TaskService
|
{
|
//入库,空盘回库
|
public ApiResponse AddInStoreDoc(MES_InTask mES_In)
|
{
|
WriteLog.GetLog("接收MES入库任务下发").Write($"参数:{mES_In.ToJson()}", $"任务接收参数");
|
ApiResponse apiResponse = new ApiResponse();
|
try
|
{
|
if (mES_In == null) return apiResponse.Error("WMS接收道的数据为空");
|
if (string.IsNullOrWhiteSpace(mES_In.warehouseNo)) return apiResponse.Error("仓库编码不能为空");
|
if (string.IsNullOrWhiteSpace(mES_In.transNo)) return apiResponse.Error("单据编号不能为空");
|
if (mES_In.transDate == default(DateTime)) return apiResponse.Error("单据日期不能为空");
|
if (string.IsNullOrWhiteSpace(mES_In.status)) return apiResponse.Error("状态不能为空");
|
if (string.IsNullOrWhiteSpace(mES_In.containerNo)) return apiResponse.Error("托盘码不能为空");
|
if (string.IsNullOrWhiteSpace(mES_In.startPosition)) return apiResponse.Error("起点位置不能为空");
|
if (string.IsNullOrWhiteSpace(mES_In.endPosition)) return apiResponse.Error("目标位置不能为空");
|
if (string.IsNullOrWhiteSpace(mES_In.containerType)) return apiResponse.Error("载具类型不能为空"); //载具类型,布料-1,松布卷-2,成品-1
|
|
Dt_Warehouse dt_Warehouse = _warehouseService.QueryWarehouse(mES_In.warehouseNo);
|
if (dt_Warehouse == null) return apiResponse.Error($"WMS未能查询道对应仓库,仓库编码:{mES_In.warehouseNo}");
|
int LocationType = 1;
|
if (dt_Warehouse.WarehouseType == (int)WarehouseEnum.YMYL)
|
{
|
if (mES_In.containerType == "2") LocationType = 2;
|
}
|
|
string Roadway = _locationInfoService.AccessingTunnel(dt_Warehouse.WarehouseId, LocationType);
|
if (Roadway == "") return apiResponse.Error($"WMS未能查询道对应巷道编号,仓库编码:{mES_In.warehouseNo}");
|
|
//获取对应PLC站台信息
|
Dt_roadwayinfo _Roadwayinfo = _roadWayinfoService.QbtainPlatform(Roadway);
|
|
|
Dt_Task task = new Dt_Task();
|
task.TaskNum = mES_In.transNo;
|
task.PalletCode = mES_In.containerNo;
|
task.PalletType = mES_In.containerType;
|
task.Roadway = Roadway;
|
task.TaskType = (int)TaskTypeEnum.Inbound;
|
task.TaskStatus = (int)InTaskStatusEnum.InNew;
|
task.SourceAddress = mES_In.startPosition;
|
task.TargetAddress = "";
|
task.CurrentAddress = mES_In.startPosition;
|
task.NextAddress = _Roadwayinfo.InStationCode;
|
task.WarehouseId = dt_Warehouse.WarehouseId;
|
task.OrderNo = mES_In.transDate.ToString();
|
task.Grade = 1;
|
task.Creater = "MES";
|
task.CreateDate = DateTime.Now;
|
|
Dt_StockInfo dt_StockInfo = new Dt_StockInfo();
|
dt_StockInfo.PalletCode = task.PalletCode;
|
dt_StockInfo.PalletType = task.PalletType;
|
dt_StockInfo.WarehouseId = task.WarehouseId;
|
dt_StockInfo.StockStatus = (int)StockStatusEmun.入库中;
|
dt_StockInfo.Creater = "MWS";
|
dt_StockInfo.CreateDate = DateTime.Now;
|
|
_unitOfWorkManage.BeginTran();
|
BaseDal.AddData(task);
|
_stockInfoService.Repository.AddData(dt_StockInfo);
|
_unitOfWorkManage.CommitTran();
|
WriteLog.GetLog("接收MES入库任务下发").Write($"参数:{mES_In.containerNo}", $"入库任务添加成功");
|
return apiResponse.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
WriteLog.GetLog("接收MES入库任务下发").Write($"原因:{ex.Message}", $"入库任务添加");
|
return apiResponse.Error($"WMS任务添加错误,原因:{ex.Message}");
|
}
|
|
|
}
|
|
//出库任务
|
public ApiResponse AddOutStoreDoc(MES_InTask mES_In)
|
{
|
WriteLog.GetLog("接收MES出库任务下发").Write($"参数:{mES_In.ToJson()}", $"任务接收参数");
|
ApiResponse apiResponse = new ApiResponse();
|
try
|
{
|
if (mES_In == null) return apiResponse.Error("WMS接收道的数据为空");
|
if (string.IsNullOrWhiteSpace(mES_In.warehouseNo)) return apiResponse.Error("仓库编码不能为空");
|
if (string.IsNullOrWhiteSpace(mES_In.transNo)) return apiResponse.Error("单据编号不能为空");
|
if (mES_In.transDate == default(DateTime)) return apiResponse.Error("单据日期不能为空");
|
if (string.IsNullOrWhiteSpace(mES_In.status)) return apiResponse.Error("状态不能为空");
|
if (string.IsNullOrWhiteSpace(mES_In.containerNo)) return apiResponse.Error("托盘码不能为空");
|
if (string.IsNullOrWhiteSpace(mES_In.endPosition)) return apiResponse.Error("目标位置不能为空");
|
|
|
Dt_StockInfo dt_Stock=_stockInfoService.Repository.QueryData(x=>x.PalletCode== mES_In.containerNo && x.StockStatus== (int)StockStatusEmun.已入库).FirstOrDefault();
|
if (dt_Stock == null) return apiResponse.Error($"WMS未能查找道该托盘条码的库存货位信息,条码:{mES_In.containerNo}");
|
|
Dt_LocationInfo dt_LocationInfo = _locationInfoService.Repository.QueryData(x => x.LocationCode == dt_Stock.LocationCode && x.LocationStatus== (int)LocationStatusEnum.InStock).FirstOrDefault();
|
if (dt_LocationInfo == null) return apiResponse.Error($"WMS未能查找道该托盘条码的库存货位信息,条码:{mES_In.containerNo},未找到货位号:{dt_Stock.LocationCode}");
|
|
Dt_roadwayinfo _Roadwayinfo = _roadWayinfoService.QbtainPlatform(dt_LocationInfo.RoadwayNo);
|
|
Dt_Task task = new Dt_Task();
|
task.TaskNum = mES_In.transNo;
|
task.PalletCode = dt_Stock.PalletCode;
|
task.PalletType = dt_Stock.PalletType;
|
task.Roadway = dt_LocationInfo.RoadwayNo;
|
task.TaskType = (int)TaskTypeEnum.Outbound;
|
task.TaskStatus = (int)OutTaskStatusEnum.OutNew;
|
task.SourceAddress = dt_LocationInfo.LocationCode;
|
task.TargetAddress = mES_In.endPosition;
|
task.CurrentAddress = dt_LocationInfo.LocationCode;
|
task.NextAddress = _Roadwayinfo.OutSCStationCode;
|
task.WarehouseId = dt_LocationInfo.WarehouseId;
|
task.OrderNo = mES_In.transDate.ToString();
|
task.Grade = 1;
|
task.Creater = "MES";
|
task.CreateDate = DateTime.Now;
|
|
dt_Stock.StockStatus = (int)StockStatusEmun.出库中;
|
dt_LocationInfo.LocationStatus = (int)LocationStatusEnum.Lock;
|
|
_unitOfWorkManage.BeginTran();
|
BaseDal.AddData(task);
|
_stockInfoService.Repository.UpdateData(dt_Stock);
|
_locationInfoService.Repository.UpdateData(dt_LocationInfo);
|
_unitOfWorkManage.CommitTran();
|
|
WriteLog.GetLog("接收MES出库任务下发").Write($"添加成功,托盘条码:{dt_Stock.PalletCode}", $"出库任务添加");
|
return apiResponse.OK();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
WriteLog.GetLog("接收MES出库任务下发").Write($"原因:{ex.Message}", $"出库任务添加");
|
return apiResponse.Error($"WMS任务添加错误,原因:{ex.Message}");
|
}
|
}
|
|
//储位查询接口
|
public ApiResponse GetLocationByContainer(MES_InTask mES_In)
|
{
|
ApiResponse apiResponse = new ApiResponse();
|
try
|
{
|
if (string.IsNullOrWhiteSpace(mES_In.containerNo)) return apiResponse.Error("托盘码不能为空");
|
Dt_StockInfo dt_Stock = _stockInfoService.Repository.QueryData(x => x.PalletCode == mES_In.containerNo).FirstOrDefault();
|
if (dt_Stock == null) return apiResponse.Error($"WMS未能查找道该托盘条码的库存货位信息,条码:{mES_In.containerNo}");
|
Dt_LocationInfo dt_LocationInfo = _locationInfoService.Repository.QueryData(x => x.LocationCode == dt_Stock.LocationCode).FirstOrDefault();
|
if (dt_LocationInfo == null) return apiResponse.Error($"WMS未能查找道该托盘条码的库存货位信息,条码:{mES_In.containerNo},未找到货位号:{dt_Stock.LocationCode}");
|
|
Dt_Warehouse dt_Warehouse = _warehouseService.Repository.QueryFirst(x=>x.WarehouseId== dt_LocationInfo.WarehouseId);
|
|
apiResponse.Code = 200;
|
apiResponse.Msg = "成功";
|
apiResponse.Data = new ResponseData
|
{
|
IsSuccess = true,
|
Message = "操作成功",
|
};
|
apiResponse.Data.result = new locationinfoData
|
{
|
warehouseCode= dt_Warehouse.WarehouseCode,
|
locationCode = dt_LocationInfo.LocationCode,
|
areaNo = dt_LocationInfo.RoadwayNo,
|
};
|
|
return apiResponse;
|
}
|
catch (Exception ex)
|
{
|
WriteLog.GetLog("储位查询接口").Write($"原因:{ex.Message}", $"储位查询查询失败");
|
return apiResponse.Error($"WMS储位查询错误,原因:{ex.Message}");
|
}
|
|
}
|
|
//任务查询接口
|
public ApiResponse GetTaskInfo(MES_InTask mES_In)
|
{
|
ApiResponse apiResponse = new ApiResponse();
|
try
|
{
|
if (string.IsNullOrWhiteSpace(mES_In.transNo)) return apiResponse.Error("单据编号不能为空");
|
Dt_Task dt_Task = BaseDal.QueryData(x => x.TaskNum == mES_In.transNo).FirstOrDefault();
|
if (dt_Task == null) return apiResponse.Error($"WMS未能查找道对应单据任务,条码:{mES_In.transNo}");
|
string status = "N";
|
|
|
apiResponse.Code = 200;
|
apiResponse.Msg = "成功";
|
apiResponse.Data = new ResponseData
|
{
|
IsSuccess = true,
|
Message = "操作成功",
|
};
|
apiResponse.Data.result = new locationinfoData
|
{
|
transNo = dt_Task.TaskNum,
|
containerNo = dt_Task.PalletCode,
|
status = status,
|
};
|
return apiResponse;
|
}
|
catch (Exception ex)
|
{
|
WriteLog.GetLog("任务查询接口").Write($"原因:{ex.Message}", $"任务查询失败");
|
return apiResponse.Error($"WMS任务查询接口错误,原因:{ex.Message}");
|
}
|
}
|
|
//任务取消接口
|
public ApiResponse CancelTask(MES_InTask mES_In)
|
{
|
ApiResponse apiResponse = new ApiResponse();
|
try
|
{
|
if (string.IsNullOrWhiteSpace(mES_In.transNo)) return apiResponse.Error("单据编号不能为空");
|
Dt_Task dt_Task = BaseDal.QueryData(x => x.TaskNum == mES_In.transNo).FirstOrDefault();
|
if (dt_Task == null) return apiResponse.Error($"WMS未能查找道对应单据任务,条码:{mES_In.transNo}");
|
if(dt_Task.TaskStatus== (int)InTaskStatusEnum.InNew || dt_Task.TaskStatus == (int)OutTaskStatusEnum.OutNew)
|
{
|
BaseDal.DeleteData(dt_Task);
|
return apiResponse.OK();
|
}
|
else
|
{
|
return apiResponse.Error("任务已经在执行中,不可取消");
|
}
|
|
}
|
catch (Exception ex)
|
{
|
WriteLog.GetLog("任务取消接口").Write($"原因:{ex.Message}", $"任务取消失败");
|
return apiResponse.Error($"WMS任务取消接口错误,原因:{ex.Message}");
|
}
|
}
|
}
|
}
|