|
|
|
@ -9,6 +9,13 @@ using Admin.Core.Model;
|
|
|
|
|
using Admin.Core.Common;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using StackExchange.Profiling.Internal;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Admin.Core.Common.Config;
|
|
|
|
|
using Aucma.Core.PLc;
|
|
|
|
|
using Admin.Core.Model.Model_New;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using Consul;
|
|
|
|
|
using NetTaste;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 泡前库入库任务逻辑处理
|
|
|
|
@ -65,11 +72,16 @@ namespace Admin.Core.Tasks
|
|
|
|
|
private readonly IRecordInStoreServices _recordInstoreServices;
|
|
|
|
|
private readonly IBaseStoreInfoServices _baseStoreInfoServices;
|
|
|
|
|
private readonly IBaseSpaceDetailServices _baseSpaceDetailServices;
|
|
|
|
|
|
|
|
|
|
// 过点数据表,物料完成记录MaterialCompletion
|
|
|
|
|
private readonly IMaterialCompletionServices _iMaterialCompletionServices;
|
|
|
|
|
private readonly IPrintBarCodeServices _printBarCodeServices;
|
|
|
|
|
private PlcSpaceConfig spaceConfig = PlcSpaceConfig.Instance;
|
|
|
|
|
private readonly IBaseBomInfoServices _baseBomInfoServices;
|
|
|
|
|
public Job_BoxFoamInStoreTask_Quartz(ISysTasksQzService SysTasksQzService, ISysJobLogService sysJobLogService,
|
|
|
|
|
IBaseSpaceInfoServices baseSpaceInfoServices, IRealTaskInfoServices realTaskInfoService,
|
|
|
|
|
IProductPlanInfoServices productPlanInfoServices, IRecordInStoreServices recordInstoreServices,
|
|
|
|
|
IBaseStoreInfoServices baseStoreInfoServices, IBaseSpaceDetailServices IBaseSpaceDetailServices)
|
|
|
|
|
IBaseStoreInfoServices baseStoreInfoServices, IBaseSpaceDetailServices IBaseSpaceDetailServices,
|
|
|
|
|
IMaterialCompletionServices IMaterialCompletionServices, IPrintBarCodeServices IPrintBarCodeServices, IBaseBomInfoServices IBaseBomInfoServices)
|
|
|
|
|
{
|
|
|
|
|
_SysTasksQzService = SysTasksQzService;
|
|
|
|
|
_sysJobLogService = sysJobLogService;
|
|
|
|
@ -79,27 +91,80 @@ namespace Admin.Core.Tasks
|
|
|
|
|
_recordInstoreServices = recordInstoreServices;
|
|
|
|
|
_baseStoreInfoServices = baseStoreInfoServices;
|
|
|
|
|
_baseSpaceDetailServices = IBaseSpaceDetailServices;
|
|
|
|
|
_iMaterialCompletionServices = IMaterialCompletionServices;
|
|
|
|
|
_printBarCodeServices = IPrintBarCodeServices;
|
|
|
|
|
_baseBomInfoServices = IBaseBomInfoServices;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Execute(IJobExecutionContext context)
|
|
|
|
|
{
|
|
|
|
|
await ExecuteJob(context, async () => await Run(context));
|
|
|
|
|
await ExecuteJob(context, async () => await PassDown(context));
|
|
|
|
|
await ExecuteJob(context, async () => await PlcRealRun(context));
|
|
|
|
|
}
|
|
|
|
|
public async Task Run(IJobExecutionContext context)
|
|
|
|
|
public async Task PlcRealRun(IJobExecutionContext context)
|
|
|
|
|
{
|
|
|
|
|
string storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//泡前库code
|
|
|
|
|
await InStore(storeCode, "B20231082080029650001");
|
|
|
|
|
await MaterialEnterStore(storeCode);
|
|
|
|
|
}
|
|
|
|
|
public async Task PlcRealRun(IJobExecutionContext context)
|
|
|
|
|
|
|
|
|
|
private SemaphoreSlim semaphore = new SemaphoreSlim(0);
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取入库任务下发plc
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="context"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task PassDown(IJobExecutionContext context)
|
|
|
|
|
{
|
|
|
|
|
string storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//泡前库code
|
|
|
|
|
await MaterialEnterStore(storeCode);
|
|
|
|
|
RealTaskInfo taskInfo = await GetAwaitSendTask(storeCode);
|
|
|
|
|
if (taskInfo != null)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Info($"下发泡后入库任务:{taskInfo.TaskCode};仓库{taskInfo.StoreCode};货道:{taskInfo.SpaceCode}");
|
|
|
|
|
if (SendFoamTask_InStore(taskInfo))
|
|
|
|
|
{
|
|
|
|
|
logHelper.Info($"泡后入库任务:{taskInfo.TaskCode};下发成功,等待PLC执行反馈");
|
|
|
|
|
taskInfo.TaskStatus = 2;
|
|
|
|
|
await _realTaskInfoService.UpdateAsync(taskInfo);
|
|
|
|
|
RefreshInStoreTaskEvent?.Invoke(taskInfo);//刷新datagrid 列表
|
|
|
|
|
semaphore.Wait(); //一直堵塞直到信号量释放
|
|
|
|
|
logHelper.Info($"泡后入库任务:{taskInfo.TaskCode};执行完成");
|
|
|
|
|
// 刷新入库任务列表
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logHelper.Info($"泡后入库任务:{taskInfo.TaskCode};下发失败,请排除PLC连接");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logHelper.Info("未获取到需要下发的泡后入库任务");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取待执行的入库任务
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="storeCode"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private async Task<RealTaskInfo> GetAwaitSendTask(string storeCode)
|
|
|
|
|
{
|
|
|
|
|
RealTaskInfo taskInfo = null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var tasks =await _realTaskInfoService.QueryAsync(x => x.StoreCode == storeCode && x.TaskType == 1 && x.TaskStatus == 1);
|
|
|
|
|
taskInfo = tasks.OrderBy(x => x.CreateTime).FirstOrDefault();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Info("获取待执行的入库任务异常", ex);
|
|
|
|
|
}
|
|
|
|
|
return taskInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 入库
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 入库
|
|
|
|
|
/// 入库,扫码器委托触发
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="storeCode">仓库编号</param>
|
|
|
|
|
/// <param name="materialCode">物料条码</param>
|
|
|
|
@ -118,23 +183,31 @@ namespace Admin.Core.Tasks
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string materialType = SubString(materialBarCode);//截取中间物料条码
|
|
|
|
|
var spaceInfo =await _baseSpaceInfoServices.InStoreGetSpaceInfoByMaterialType(storeCode, materialType);
|
|
|
|
|
|
|
|
|
|
BaseSpaceInfo spaceInfo =await GetSpaceInfoByMaterialType(storeCode, materialType);
|
|
|
|
|
if (spaceInfo != null)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Info($"匹配货道:{spaceInfo.ToJson()}");
|
|
|
|
|
var list= await _productPlanInfoServices.QueryAsync(d => d.MaterialCode == materialType);
|
|
|
|
|
if (list.Count()==0) return;
|
|
|
|
|
var obj = list.FirstOrDefault();
|
|
|
|
|
var repeatList = await _recordInstoreServices.QueryAsync(d => d.BarCodeCode.Equals(materialBarCode));
|
|
|
|
|
if (repeatList.Count() > 0)
|
|
|
|
|
|
|
|
|
|
string message = $"箱体码[{materialBarCode}], 入{spaceInfo.SpaceName},入库中....";
|
|
|
|
|
PrintBarCode print = await _printBarCodeServices.FirstAsync(x => x.MaterialBarcode == materialBarCode);
|
|
|
|
|
RefreshScanMateriaCodeEvent?.Invoke(materialBarCode, materialType, print.MaterialName, spaceInfo.SpaceName, message); //刷新界面扫码信息
|
|
|
|
|
var result =await CreateInStoreTask(spaceInfo, materialBarCode); //创建入库任务
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error($"任务创建记录条码重复异常:{obj.ToJson()}");
|
|
|
|
|
LogDelegateEvent?.Invoke($"物料条码[{materialBarCode}],任务创建失败,该条码任务记录中已存在,请检查!");
|
|
|
|
|
return;
|
|
|
|
|
#region 更新过点数据
|
|
|
|
|
MaterialCompletion completion = new MaterialCompletion();
|
|
|
|
|
completion.OrderCode = print.OrderCode;
|
|
|
|
|
completion.MaterialBarcode = materialBarCode;
|
|
|
|
|
completion.MaterialCode = print.MaterialCode;
|
|
|
|
|
completion.MaterialName = print.MaterialName;
|
|
|
|
|
completion.StationName = "1003";
|
|
|
|
|
completion.CompleteDate = DateTime.Now;
|
|
|
|
|
await _iMaterialCompletionServices.AddAsync(completion);
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
await _baseSpaceInfoServices.UpdateSpaceInfo(spaceInfo);
|
|
|
|
|
}
|
|
|
|
|
string message = $"物料[{obj.MaterialName}], 入{spaceInfo.SpaceName},入库中....";
|
|
|
|
|
RefreshScanMateriaCodeEvent?.Invoke(materialBarCode, obj.MaterialCode, obj.MaterialName, spaceInfo.SpaceName, message); //刷新界面扫码信息
|
|
|
|
|
CreateInStoreTask(spaceInfo, materialBarCode); //创建入库任务
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -146,18 +219,17 @@ namespace Admin.Core.Tasks
|
|
|
|
|
logHelper.Error($"入库业务异常:{ex}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 创建入库任务
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建入库任务
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="spaceInfo"></param>
|
|
|
|
|
private async void CreateInStoreTask(BaseSpaceInfo spaceInfo, string materialCode)
|
|
|
|
|
private async Task<bool> CreateInStoreTask(BaseSpaceInfo spaceInfo, string materialCode)
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string storeCode = Appsettings.app("StoreInfo", "StoreCode");//泡前库code
|
|
|
|
|
//生成入库任务依次下发至PLC
|
|
|
|
|
RealTaskInfo realTaskInfo = new RealTaskInfo();
|
|
|
|
|
realTaskInfo.TaskType = 1;
|
|
|
|
@ -170,44 +242,102 @@ namespace Admin.Core.Tasks
|
|
|
|
|
realTaskInfo.PlanAmount = 1;
|
|
|
|
|
realTaskInfo.TaskStatus = 1; //任务状态:1 - 待执行;2 - 执行中;3 - 完成
|
|
|
|
|
realTaskInfo.CreateTime = DateTime.Now;
|
|
|
|
|
var taskList = await _realTaskInfoService.QueryAsync(d => d.MaterialCode.Equals(materialCode) && d.StoreCode == storeCode);
|
|
|
|
|
if (taskList.Count() > 0) return;
|
|
|
|
|
|
|
|
|
|
int result = await _realTaskInfoService.AddAsync(realTaskInfo);
|
|
|
|
|
if (result > 0)
|
|
|
|
|
int flag = await _realTaskInfoService.AddAsync(realTaskInfo);
|
|
|
|
|
if (flag > 0)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Info("入库任务创建成功");
|
|
|
|
|
RefreshInStoreTaskEvent?.Invoke(realTaskInfo);//刷新datagrid 列表
|
|
|
|
|
result = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logHelper.Info("入库任务创建失败");
|
|
|
|
|
result = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Info($"入库任务创建异常:{ex.Message}");
|
|
|
|
|
result = false;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 截取物料编码
|
|
|
|
|
public string SubString(string barCode)
|
|
|
|
|
|
|
|
|
|
/// 通过PLC读取货道信息(在途数量、在库数量、货道状态)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="storeCode"></param>
|
|
|
|
|
/// <param name="materialType"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private async Task<BaseSpaceInfo> GetSpaceInfoByMaterialType(string storeCode, string materialType)
|
|
|
|
|
{
|
|
|
|
|
BaseSpaceInfo result = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string materialCode = barCode.Substring(7, 10);
|
|
|
|
|
return materialCode;
|
|
|
|
|
// List<BaseSpaceInfo> info = _spaceInfoService.GetBaseSpaceInfosByMaterialType(storeCode, materialType);
|
|
|
|
|
List<BaseSpaceInfo> info = await _baseSpaceInfoServices.InStoreGetSpaceInfoByMaterialType(storeCode, materialType);
|
|
|
|
|
if (info != null)
|
|
|
|
|
{
|
|
|
|
|
if (info.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (BaseSpaceInfo item in info)
|
|
|
|
|
{
|
|
|
|
|
var spaceInfo = ReadSpaceInfoByPlc(item);
|
|
|
|
|
item.SpaceStock = spaceInfo.SpaceStock;
|
|
|
|
|
item.OnRouteAmount = spaceInfo.OnRouteAmount;
|
|
|
|
|
item.SpaceStatus = spaceInfo.SpaceStatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = info.Where(x => x.SpaceStatus == 1 && x.SpaceStock > 0 ? x.SpaceCapacity > (x.SpaceStock + x.OnRouteAmount) : 1 == 1).OrderByDescending(x => x.SpaceStock).OrderBy(x => x.SpaceCode).First();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Info($"截取物料条码失败:{ex.Message}");
|
|
|
|
|
return string.Empty;
|
|
|
|
|
logHelper.Info("货道信息读取异常", ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 通过PLC获取货道信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="spaceInfo"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public BaseSpaceInfo ReadSpaceInfoByPlc(BaseSpaceInfo spaceInfo)
|
|
|
|
|
{
|
|
|
|
|
var spaceAddress = spaceConfig.GetSpaceAddress(spaceInfo.StoreCode, spaceInfo.SpaceCode);
|
|
|
|
|
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("发泡Plc"));
|
|
|
|
|
if (obj != null && obj.plc.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
spaceInfo.SpaceStock = obj.plc.ReadInt32(spaceAddress.onStore);
|
|
|
|
|
spaceInfo.OnRouteAmount = obj.plc.ReadInt32(spaceAddress.onRoute);
|
|
|
|
|
spaceInfo.SpaceStatus = obj.plc.ReadInt32(spaceAddress.spaceStatus);
|
|
|
|
|
}
|
|
|
|
|
return spaceInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 截取物料编码
|
|
|
|
|
public string SubString(string barCode)
|
|
|
|
|
{
|
|
|
|
|
string result = string.Empty;
|
|
|
|
|
if (!string.IsNullOrEmpty(barCode))
|
|
|
|
|
{
|
|
|
|
|
result = barCode.Substring(2, 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region PLC 任务处理表
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// PLC 任务处理表
|
|
|
|
@ -299,5 +429,223 @@ namespace Admin.Core.Tasks
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 泡前入库任务下发处理
|
|
|
|
|
public bool SendFoamTask_InStore(RealTaskInfo taskInfo)
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("发泡Plc"));
|
|
|
|
|
if (obj != null && obj.plc.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
//写入货道号
|
|
|
|
|
obj.plc.WriteString("D110", taskInfo.SpaceCode);
|
|
|
|
|
//写入应答字
|
|
|
|
|
obj.plc.WriteInt16("D112", "1");
|
|
|
|
|
//写入任务号
|
|
|
|
|
obj.plc.WriteInt16("D114", taskInfo.TaskCode);
|
|
|
|
|
//写入完成后读取应答字进行复位
|
|
|
|
|
ReadShellAnswer_InStore(taskInfo.TaskCode);
|
|
|
|
|
result = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logHelper.Info($"仓库{taskInfo.StoreCode};PLC未连接");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error("泡后入库任务下发异常", ex);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取泡后入库应答
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ReadShellAnswer_InStore(string taskCode)
|
|
|
|
|
{
|
|
|
|
|
lock (string.Empty)
|
|
|
|
|
{
|
|
|
|
|
bool isFlag = true;
|
|
|
|
|
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("发泡Plc"));
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
if (obj != null && obj.plc.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
//读取PLC应答字为2时,上位机清空写入的入库内容
|
|
|
|
|
if (obj.plc.ReadInt16("D112") == 2)
|
|
|
|
|
{
|
|
|
|
|
//写入货道号
|
|
|
|
|
obj.plc.WriteString("D110", string.Empty);
|
|
|
|
|
//写入应答字
|
|
|
|
|
obj.plc.WriteInt16("D112", "0");
|
|
|
|
|
//写入任务号
|
|
|
|
|
obj.plc.WriteInt16("D114", string.Empty);
|
|
|
|
|
isFlag = false;
|
|
|
|
|
|
|
|
|
|
ReadShellFinish_InStore(taskCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
} while (isFlag);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logHelper.Info("PLC未连接");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error("读取泡后入库应答字异常", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取泡后入库完成
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ReadShellFinish_InStore(string taskCode)
|
|
|
|
|
{
|
|
|
|
|
lock (string.Empty)
|
|
|
|
|
{
|
|
|
|
|
bool isFlag = true;
|
|
|
|
|
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("发泡Plc"));
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
if (obj != null && obj.plc.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
//读取PLC入库任务完成
|
|
|
|
|
if (obj.plc.ReadInt16("D220") == 1)
|
|
|
|
|
{
|
|
|
|
|
obj.plc.WriteInt16("D220", "0");
|
|
|
|
|
FoamTaskFeedback(taskCode);
|
|
|
|
|
isFlag = false;
|
|
|
|
|
}
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
} while (isFlag);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logHelper.Info("PLC未连接");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error("读取泡后入库完成异常", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 泡前库执行反馈
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void FoamTaskFeedback(string taskCode)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
logHelper.Info("泡后执行完成,自动释放信号量");
|
|
|
|
|
InStoreFinish(taskCode);
|
|
|
|
|
semaphore.Release();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 入库完成
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="storeCode"></param>
|
|
|
|
|
/// <param name="spaceCode"></param>
|
|
|
|
|
/// <param name="materialType"></param>
|
|
|
|
|
private async void InStoreFinish(string taskCode)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//泡前库code
|
|
|
|
|
RealTaskInfo taskInfo = await _realTaskInfoService.FirstAsync(x => x.StoreCode == storeCode && x.TaskCode==taskCode);
|
|
|
|
|
if (taskInfo != null)
|
|
|
|
|
{
|
|
|
|
|
BaseSpaceInfo spaceInfo =await _baseSpaceInfoServices.GetSpaceInfoBySpaceCode(taskInfo.StoreCode, taskInfo.SpaceCode);
|
|
|
|
|
if (spaceInfo != null)
|
|
|
|
|
{
|
|
|
|
|
spaceInfo.MaterialType = taskInfo.MaterialType;
|
|
|
|
|
|
|
|
|
|
//读取PLC获取货道信息:存放数量、在途数量,
|
|
|
|
|
#region Add By wenjy 2023-10-30 13:44:00 通过PLC获取货道信息
|
|
|
|
|
var item = ReadSpaceInfoByPlc(spaceInfo);
|
|
|
|
|
spaceInfo.SpaceStock = item.SpaceStock;
|
|
|
|
|
spaceInfo.OnRouteAmount = item.OnRouteAmount;
|
|
|
|
|
spaceInfo.SpaceStatus = item.SpaceStatus;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
await _baseSpaceInfoServices.UpdateSpaceInfo(spaceInfo);
|
|
|
|
|
|
|
|
|
|
#region 添加货道明细
|
|
|
|
|
BaseSpaceDetail spaceDetail = new BaseSpaceDetail();
|
|
|
|
|
spaceDetail.MaterialType = taskInfo.MaterialType;
|
|
|
|
|
spaceDetail.MaterialCode = taskInfo.MaterialCode;
|
|
|
|
|
spaceDetail.MaterialName = await GetMaterialName(taskInfo.MaterialType);
|
|
|
|
|
spaceDetail.StoreCode = spaceInfo.StoreCode;
|
|
|
|
|
spaceDetail.SpaceCode = spaceInfo.SpaceCode;
|
|
|
|
|
spaceDetail.MaterialAmount = 1;
|
|
|
|
|
await _baseSpaceDetailServices.InsertSpaceDetail(spaceDetail);
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 添加入库记录
|
|
|
|
|
RecordInStore recordInstore = new RecordInStore();
|
|
|
|
|
recordInstore.StoreCode = taskInfo.StoreCode;
|
|
|
|
|
recordInstore.SpaceCode = taskInfo.SpaceCode;
|
|
|
|
|
recordInstore.MaterialCode = taskInfo.MaterialCode;
|
|
|
|
|
recordInstore.MaterialType = taskInfo.MaterialType;
|
|
|
|
|
recordInstore.MaterialName = await GetMaterialName(taskInfo.MaterialType);
|
|
|
|
|
recordInstore.InStoreAmount = 1;
|
|
|
|
|
recordInstore.InStoreTime = DateTime.Now;
|
|
|
|
|
recordInstore.BarCodeCode = taskInfo.MaterialCode;
|
|
|
|
|
bool result = await _recordInstoreServices.SaveRecordToDb(recordInstore, taskInfo, spaceInfo, spaceDetail);
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//清除任务信息
|
|
|
|
|
await _realTaskInfoService.DeleteTaskInfo(taskCode, storeCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Info("入库完成逻辑处理异常", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 通过BOM获取物料名称
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="materialType"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<string> GetMaterialName(string materialType)
|
|
|
|
|
{
|
|
|
|
|
string materialName = string.Empty;
|
|
|
|
|
BaseBomInfo info =await _baseBomInfoServices.GetBomInfoByMaterialCode(materialType);
|
|
|
|
|
if (info != null)
|
|
|
|
|
{
|
|
|
|
|
materialName = info.MaterialName;
|
|
|
|
|
}
|
|
|
|
|
return materialName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|