You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Aucma.Scada/Aucma.Scada.Business/OutStoreBusiness.cs

885 lines
33 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Aucma.Core.Scanner;
using Aucma.Scada.Model.domain;
using HighWayIot.Config;
using HighWayIot.Log4net;
using HighWayIot.Repository.service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static Aucma.Scada.Business.OutStoreTaskHandle;
namespace Aucma.Scada.Business
{
/// <summary>
/// 出库业务逻辑
/// </summary>
public sealed class OutStoreBusiness
{
#region 单例实现
private static readonly Lazy<OutStoreBusiness> lazy = new Lazy<OutStoreBusiness>(() => new OutStoreBusiness());
public static OutStoreBusiness Instance
{
get
{
return lazy.Value;
}
}
#endregion
#region 对象引用
private LogHelper logHelper = LogHelper.Instance;
private AppConfig appConfig = AppConfig.Instance;
private RegisterServices registerServices = RegisterServices.Instance;
private AssemblyPlanBusiness assemblyPlanBusiness = AssemblyPlanBusiness.Instance;
private OutStoreTaskHandle taskHandleBusiness = OutStoreTaskHandle.Instance;
private InStoreBusiness inStoreBusiness = InStoreBusiness.Instance;
#endregion
#region 接口引用
/// <summary>
/// 货道信息
/// </summary>
private IBaseSpaceInfoService _spaceInfoService;
/// <summary>
/// 实时任务
/// </summary>
private IRealTaskInfoService _taskInfoService;
/// <summary>
/// BOM信息
/// </summary>
private IBaseBomInfoService _bomInfoService;
/// <summary>
/// 货道明细
/// </summary>
private IBaseSpaceDetailService _spaceDetailService;
private IExecutePlanInfoService _executePlanInfoService;
private IProductPlanInfoService _productPlanInfoService;
private IRecordOutStoreService _recordOutStoreService;
private IRecordProductfinishService _recordProductfinishService;
private IPrintBarCodeServices _printBarCodeServices;
// 过点数据表
private IMaterialCompletionServices _iMaterialCompletionServices;
#endregion
#region 委托事件
/// <summary>
/// 初始化出库任务
/// </summary>
/// <param name="message"></param>
public delegate void RefreshOutStoreTask();
public event RefreshOutStoreTask RefreshOutStoreTaskEvent;
/// <summary>
/// 扫码信息刷新
/// </summary>
/// <param name="materialCode"></param>
/// <param name="materialName"></param>
/// <param name="spaceName"></param>
/// <param name="storeCode"></param>
public delegate void RefreshScanMateriaCode(string materialCode, string materialName, string spaceName, string storeCode);
public event RefreshScanMateriaCode RefreshScanMateriaCodeEvent;
/// <summary>
/// 日志信息刷新
/// </summary>
/// <param name="message"></param>
public delegate void RefreshLogMessage(string message);
public event RefreshLogMessage RefreshLogMessageEvent;
public delegate void RefreshAssemblyPlanInit();
public event RefreshAssemblyPlanInit RefreshAssemblyPlanInitEvent;
public delegate void RefreshStoreStock();
public event RefreshStoreStock RefreshStoreStockEvent;
#endregion
private OutStoreBusiness()
{
_iMaterialCompletionServices = registerServices.GetService<IMaterialCompletionServices>();
_printBarCodeServices = registerServices.GetService<IPrintBarCodeServices>();
_spaceInfoService = registerServices.GetService<IBaseSpaceInfoService>();
_taskInfoService = registerServices.GetService<IRealTaskInfoService>();
_bomInfoService = registerServices.GetService<IBaseBomInfoService>();
_spaceDetailService = registerServices.GetService<IBaseSpaceDetailService>();
_executePlanInfoService = registerServices.GetService<IExecutePlanInfoService>();
_productPlanInfoService = registerServices.GetService<IProductPlanInfoService>();
_recordOutStoreService = registerServices.GetService<IRecordOutStoreService>();
_recordProductfinishService = registerServices.GetService<IRecordProductfinishService>();
assemblyPlanBusiness.NextPassExecutePlanInfoEvent += PlanHandle;
MvCodeHelper.OutMaterialCodeStrEvent += OutStoreFinishHandle;
//assemblyPlanBusiness.PrintLogAndRefreshEvent += PrintLogInfoMessage;
assemblyPlanBusiness.GetSpaceInfoByMaterialTypeEvent += GetSpaceInfoByMaterialType;
taskHandleBusiness.OutStoreAnswerEvent += OutStoreAnswer;
// taskHandleBusiness.OutStoreFinsihEvent += OutStoreFinish;
// test();
StartPassDown();
}
public void test()
{
//var productInfo = _productPlanInfoService.GetProductPlanByPlanCode("2402290019");
//productInfo.beginTime = DateTime.Now;
//productInfo.completeAmount = productInfo.completeAmount + 1;
//_productPlanInfoService.UpdateProductPlanInfo(productInfo);
}
/// <summary>
/// 接收下达的组装计划根据BOM获取需要出库的泡后、内胆物料信息
/// </summary>
/// <param name="planInfo"></param>
private void PlanHandle(ExecutePlanInfo planInfo,BaseSpaceInfo spaceInfo = null)
{
lock (string.Empty)
{
Task.Run(() =>
{
if (planInfo != null)
{
var bomInfo = _bomInfoService.GetBomInfoByMaterialCode(planInfo.materialCode);
if (bomInfo==null)
{
PrintLogInfoMessage($"物料:{planInfo.materialCode}获取Bom信息为空");
return;
}
// 组装计划出库
//if (spaceInfo == null)
//{
// //筛选后的货道
// spaceInfo = GetSpaceInfoByMaterialType(appConfig.foamStoreCode, bomInfo.materialCode);
// if (spaceInfo == null)
// {
// PrintLogInfoMessage($"物料:{planInfo.materialCode};未匹配到货道");
// return;
// }
// for (int i = 0; i < spaceInfo.spaceStock; i++)
// {
// string taskCode = System.Guid.NewGuid().ToString("N").Substring(0, 7);
// OutStore(appConfig.foamStoreCode, bomInfo, planInfo.executePlanCode, taskCode, spaceInfo);
// Thread.Sleep(500);
// }
//}
// else // 指定货道出一个或者整道出
// {
for (int i = 0; i < planInfo.planAmount - planInfo.completeAmount; i++)
{
string taskCode = System.Guid.NewGuid().ToString("N").Substring(0, 7);
OutStore(appConfig.foamStoreCode, bomInfo, planInfo.executePlanCode, taskCode, spaceInfo);
Thread.Sleep(500);
}
// }
}
});
}
}
/// <summary>
/// 解析计划创建出库任务
/// </summary>
/// <param name="storeCode"></param>
/// <param name="bomInfo"></param>
/// <param name="planCode"></param>
private void OutStore(string storeCode, BaseBomInfo bomInfo, string planCode, string taskCode,BaseSpaceInfo spaceInfo = null)
{
try
{
PrintLogInfoMessage($"收到出库计划,物料码:{bomInfo.materialCode}");
if (spaceInfo != null)
{
PrintLogInfoMessage($"匹配货道:{spaceInfo.spaceName}");
// RefreshScanMateriaCodeEvent?.Invoke(materiaclCode, materialType, spaceInfo.spaceName, storeCode); //刷新界面扫码信息
bool result = CreateOutStoreTask(spaceInfo, planCode, taskCode); //创建出库任务
if (result)
{
PrintLogInfoMessage("出库任务创建成功");
// 出过的库标记,禁止再次入库
spaceInfo.inStoreFlag = 2;
_spaceInfoService.UpdateSpaceInfo(spaceInfo);
}
else
{
PrintLogInfoMessage("出库任务创建失败");
}
}
else
{
//报警停线
PrintLogInfoMessage($"{storeCode};仓库内未获取到{bomInfo.materialCode}相匹配的物料及货道");
}
}
catch (Exception ex)
{
PrintLogErrorMessage("出库业务异常", ex);
}
}
/// <summary>
/// 创建出库任务
/// </summary>
/// <param name="spaceInfo"></param>
private bool CreateOutStoreTask(BaseSpaceInfo spaceInfo, string planCode, string taksCode, int taskModel = 0)
{
bool result = false;
try
{
#region 出库任务赋值
RealTaskInfo realTaskInfo = new RealTaskInfo();
// 执行计划编号
realTaskInfo.planCode = planCode;
realTaskInfo.taskType = 2;
realTaskInfo.taskCode = taksCode;
realTaskInfo.taskModel = taskModel;
realTaskInfo.storeCode = spaceInfo.storeCode;
realTaskInfo.spaceCode = spaceInfo.spaceCode;
realTaskInfo.spaceName = spaceInfo.spaceName;
realTaskInfo.materialType = spaceInfo.materialType;
realTaskInfo.planAmount = 1;
realTaskInfo.taskStatus = 1;
realTaskInfo.createTime = DateTime.Now;
#endregion
result = _taskInfoService.AddTaskInfo(realTaskInfo);
if (result)
{
// 禁止入库
spaceInfo.inStoreFlag = 2;
_spaceInfoService.UpdateSpaceInfo(spaceInfo);
PrintLogInfoMessage("出库任务创建成功");
RefreshOutStoreTaskEvent?.Invoke();
// UpdateSpaceAndDetial(spaceInfo, spaceDetail);
}
else
{
PrintLogInfoMessage("出库任务创建失败");
}
}
catch (Exception ex)
{
PrintLogErrorMessage("出库任务创建异常", ex);
}
return result;
}
/// <summary>
/// 根据创建时间获取第一个货道明细
/// </summary>
/// <param name="spaceInfo"></param>
/// <returns></returns>
private BaseSpaceDetail GetSpaceDetailFirstOrderByCreatTime(BaseSpaceInfo spaceInfo)
{
BaseSpaceDetail spaceDetail = null;
try
{
List<BaseSpaceDetail> spaceDetails = _spaceDetailService.GetSpaceDetailsBySpaceCode(spaceInfo.storeCode, spaceInfo.spaceCode);
if (spaceDetails.Count > 0)
{
spaceDetails = spaceDetails.Where(x => x.isFlag != 1).ToList();
if (spaceDetails.Count > 0)
{
spaceDetail = spaceDetails.OrderBy(x => x.createTime).First();
}
}
}
catch (Exception ex)
{
PrintLogErrorMessage("获取货道明细信息异常", ex);
}
return spaceDetail;
}
/// <summary>
/// 任务创建完成后修改货道信息及货道明细
/// </summary>
/// <param name="spaceInfo"></param>
/// <param name="spaceDetail"></param>
private void UpdateSpaceAndDetial(BaseSpaceInfo spaceInfo, BaseSpaceDetail spaceDetail, int detailIsFlag = 1, bool stockFlag = true)
{
//任务创建完成后修改货道库存、货道明细修改物料标识物料不可用
spaceDetail.isFlag = detailIsFlag;
var result = _spaceDetailService.UpdateSpaceDetail(spaceDetail);
//if (stockFlag)
//{
// spaceInfo.spaceStock = spaceInfo.spaceStock > 0 ? spaceInfo.spaceStock - 1 : 0;
//}
//else
//{
// spaceInfo.spaceStock = spaceInfo.spaceStock + 1;
//}
// spaceInfo.outRouteAmount += 1;
// _spaceInfoService.UpdateSpaceInfo(spaceInfo);
}
#region 轮询获取出库任务下发至PLC等待PLC执行反馈完成后再次下发
private SemaphoreSlim semaphore = new SemaphoreSlim(0);
private int completedTasks = 0;
private int taskAmount = 2;
private void StartPassDown()
{
Task.Run(() =>
{
Thread.Sleep(2000);
while (true)
{
PassDownTaskInfo();
Thread.Sleep(1000);
}
});
}
/// <summary>
/// 依次获取任务队列进行下发
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
private void PassDownTaskInfo()
{
try
{
//获取待执行的出库任务下发至PLC,并将任务状态改为执行中
RealTaskInfo taskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.foamStoreCode, appConfig.outstoreTaskType);
if (taskInfo != null)
{
// PrintLogInfoMessage($"下发泡后出库任务:{taskInfo.taskCode};仓库{taskInfo.storeCode};货道:{taskInfo.spaceCode}");
int result = taskHandleBusiness.SendFoamTask_OutStore(taskInfo);
if (result==1)
{
PrintLogInfoMessage($"出库任务:{taskInfo.taskCode}下发成功等待PLC执行反馈");
semaphore.Wait();//一直堵塞直到信号量释放
PrintLogInfoMessage($"出库任务:{taskInfo.taskCode};开始执行");
taskInfo.taskStatus = 2;
_taskInfoService.UpdateTaskInfo(taskInfo);
//刷新出库任务界面
RefreshOutStoreTaskEvent?.Invoke();
// RefreshScanMateriaCodeEvent?.Invoke(taskInfo.materialCode, taskInfo.materialType, taskInfo.spaceName, taskInfo.storeCode);
}
else if (result == 2)
{
// PrintLogInfoMessage("泡后出库任务下发失败PLC接收任务未就绪");
}
else
{
// PrintLogInfoMessage($"泡后出库任务:{taskInfo.taskCode}下发失败请排除PLC连接");
}
}
else
{
// PrintLogInfoMessage("未获取到需要下发的出库任务");
}
}
catch (Exception ex)
{
PrintLogErrorMessage("下传出库任务逻辑处理异常", ex);
}
}
#endregion
/// <summary>
/// 获取所有待执行的出库任务
/// </summary>
/// <returns></returns>
private List<RealTaskInfo> GetAwaitSendTask()
{
List<RealTaskInfo> taskInfos = new List<RealTaskInfo>();
try
{
taskInfos = _taskInfoService.GetAllTaskInfoByStoreCode(appConfig.foamStoreCode, 2);
}
catch (Exception ex)
{
PrintLogErrorMessage("获取待执行的出库任务异常", ex);
}
return taskInfos;
}
#region PLC出库应答反馈
/// <summary>
/// 出库应答
/// </summary>
/// <param name="storeCode"></param>
/// <param name="taskCode"></param>
private void OutStoreAnswer(string storeCode, string taskCode)
{
PrintLogInfoMessage("出库应答成功,自动释放信号量,进行下发新任务");
semaphore.Release();
// 视为出库完成,后续改为监测在库数
// OutStoreFinish(storeCode, taskCode);
}
///// <summary>
///// 出库完成
///// </summary>
///// <param name="storeCode"></param>
///// <param name="taskCode"></param>
//private void OutStoreFinish(string storeCode, string taskCode)
//{
// PrintLogInfoMessage($"出库任务:{taskCode};执行完成");
// OutStoreFinishHandle(taskCode, appConfig.foamStoreCode);
//}
/// <summary>
/// 信号量释放,根据任务完成数量,执行完成后进行释放
/// </summary>
private void CheckCompletedTasks()
{
if (completedTasks == taskAmount)
{
// 释放信号量
semaphore.Release();
}
}
#endregion
/// <summary>
/// 出库完成
/// </summary>
/// <param name="storeCode"></param>
/// <param name="spaceCode"></param>
/// <param name="materialType"></param>
private void OutStoreFinishHandle(string code)
{
try
{
// 插入出库记录
PrintLogInfoMessage($"{code}:出库完成");
RealTaskInfo taskInfo = _taskInfoService.GetTaskInfoByTaskCode(SubStringMaterialCode(code), appConfig.foamStoreCode, 2);
if (taskInfo != null)
{
//更新计划信息
UpdatePlanInfo(taskInfo.planCode);
//刷新界面
RefreshScanMateriaCodeEvent?.Invoke(code, code.Substring(7, 10), taskInfo.spaceName, appConfig.foamStoreCode); //刷新界面扫码信息
}
else
{
//刷新界面
RefreshScanMateriaCodeEvent?.Invoke(code, code.Substring(7, 10), "", appConfig.foamStoreCode); //刷新界面扫码信息
#region 根据创建时间删除没有型号的任务
#endregion
}
// _taskInfoService.DeleteTaskInfoByCode(taskInfo);
// 查询该型号的类型任务按照时间排序删除第一条, 清除任务信息
_taskInfoService.DeleteFirstTaskByStoreCode(appConfig.foamStoreCode, 2);
#region 添加出库记录
RecordOutstore recordOutstore = new RecordOutstore();
recordOutstore.storeCode = appConfig.foamStoreCode;
if (taskInfo != null)
{
recordOutstore.spaceCode = taskInfo.spaceCode;
}
recordOutstore.materialCode = code;
recordOutstore.materialType = code.Substring(7, 10);
recordOutstore.materialName = GetMaterialName(recordOutstore.materialType);
recordOutstore.outStoreAmount = 1;
recordOutstore.outStoreTime = DateTime.Now;
_recordOutStoreService.InsertReocrdOutStoreService(recordOutstore);
#endregion
// 根据条码查询明细并删除
_spaceDetailService.DeleteSpaceDetailByMaterialCode(code);
// 刷新任务页面
RefreshOutStoreTaskEvent?.Invoke();
#region 出库更新过点数据,插入记录到MATERIAL_COMPLETION表
if (!string.IsNullOrEmpty(code))
{
PrintBarCode print = _printBarCodeServices.query(code);
if (print != null)
{
// string planCode = _productPlanInfoServices.GetPlanCode(print.OrderCode, appConfig.stationCode);
MaterialCompletion completion = new MaterialCompletion();
completion.OrderCode = print.OrderCode;
completion.MaterialBarcode = code;
completion.MaterialCode = print.MaterialCode;
completion.MaterialName = print.MaterialName;
completion.StationName = appConfig.outstationCode;
completion.CompleteDate = DateTime.Now;
// completion.planCode = planCode;
_iMaterialCompletionServices.Add(completion);
}
}
#endregion
}
catch (Exception ex)
{
PrintLogErrorMessage("出库完成逻辑处理异常:"+ ex);
}
}
/// <summary>
/// 截条码类型
/// </summary>
/// <param name="materialCode"></param>
/// <returns></returns>
private string SubStringMaterialCode(string materialCode)
{
string result = string.Empty;
if (!string.IsNullOrEmpty(materialCode))
{
result = materialCode.Substring(7, 10);
}
return result;
}
/// <summary>
/// 更新计划信息
/// </summary>
/// <param name="planCode"></param>
private void UpdatePlanInfo(string planCode)
{
try
{
var executeInfo = _executePlanInfoService.GetExecutePlanInfoByPlanCode(planCode);
if (executeInfo != null)
{
executeInfo.completeAmount += 1;
if (executeInfo.completeAmount == executeInfo.planAmount)
{
executeInfo.executeStatus = 3;
}
_executePlanInfoService.UpdateExecutePlanInfo(executeInfo);
var productInfo = _productPlanInfoService.GetProductPlanByPlanCode(executeInfo.productPlanCode);
if (productInfo != null)
{
if(productInfo.completeAmount==0)
{
productInfo.beginTime = DateTime.Now;
}
productInfo.completeAmount += 1;
if (productInfo.completeAmount >= productInfo.planAmount)
{
productInfo.endTime = DateTime.Now;
}
_productPlanInfoService.UpdateProductPlanInfo(productInfo);
}
#region 添加完成记录
RecordProductfinish productfinish = new RecordProductfinish();
productfinish.planCode = executeInfo.executePlanCode;
productfinish.productlineCode = appConfig.stationCode;
productfinish.materialCode = executeInfo.materialCode;
productfinish.completeAmount = 1; //目前一个箱体一个任务下发给plc
productfinish.recordTime = DateTime.Now;
_recordProductfinishService.InsertRecordProductfinish(productfinish);
#endregion
}
RefreshAssemblyPlanInitEvent?.Invoke();
}
catch (Exception ex)
{
PrintLogErrorMessage("计划信息更新异常", ex);
}
}
/// <summary>
/// 获取出库任务
/// </summary>
/// <returns></returns>
public List<RealTaskInfo> GetOutStoreTask()
{
var taskInfos = _taskInfoService.GetTaskInfosByStoreCode(new string[] { appConfig.foamStoreCode }, appConfig.outstoreTaskType);
return taskInfos;
}
/// <summary>
/// 通过任务编号删除任务
///
/// 任务删除后是否需要还原库存,如果出库完成后减少库存则不需要
///
/// </summary>
/// <param name="taskCode"></param>
/// <returns></returns>
public bool DeleteTaskInfoByTaskCode(string taskCode, bool isFlag)
{
bool result = false;
var info = _taskInfoService.GetTaskInfosByTaskCode(taskCode);
if (info != null)
{
foreach (var taskInfo in info)
{
result = _taskInfoService.DeleteTaskInfoById(taskInfo.objId);
if (result)
{
var spaceDetailInfo = _spaceDetailService.GetSpaceDetailByMaterialCode(taskInfo.materialCode);
if (spaceDetailInfo != null)
{
if (!isFlag)
{
spaceDetailInfo.isFlag = 0;
_spaceDetailService.UpdateSpaceDetail(spaceDetailInfo);
}
else
{
_spaceDetailService.DeleteSpaceDetailByMaterialCode(spaceDetailInfo.materialCode);
}
}
}
}
}
return result;
}
/// <summary>
/// 泡后库出库删除所有任务信息
/// </summary>
/// <param name="taskInfo"></param>
/// <summary>
public bool DeleteAllTaskByStoreCode(string storeCode, int taskType)
{
return _taskInfoService.DeleteAllTaskByStoreCode(storeCode, taskType);
}
/// <summary>
/// 根据货道手动出一个
/// </summary>
/// <param name="storeCode"></param>
/// <param name="spaceCode"></param>
/// <returns></returns>
public bool OutOnlyOneBySpaceCode(string storeCode, string spaceCode)
{
bool result = false;
try
{
BaseSpaceInfo spaceInfo = _spaceInfoService.GetSpaceInfoBySpaceCode(storeCode, spaceCode);
if (spaceInfo.spaceStock > 0)
{
#region 创建mes执行任务关联生产计划
var productPlanInfo = _productPlanInfoService.GetProductPlanInfosByMaterialCode(spaceInfo.materialType);
if(productPlanInfo != null)
{
result = assemblyPlanBusiness.PlanTransmitByProductPlan(productPlanInfo.planCode, 1,spaceInfo);
}
#endregion
else
{
// 不关联生产计划
result = this.CreateOutStoreTask(spaceInfo, System.Guid.NewGuid().ToString("N").Substring(0, 7), System.Guid.NewGuid().ToString("N").Substring(0, 10), 1);
}
}
else
{
PrintLogInfoMessage($"仓库:{storeCode};货道:{spaceCode};出一个失败:库存不足");
}
}
catch (Exception ex)
{
logHelper.Error("根据货道出一个异常", ex);
}
return result;
}
/// <summary>
/// 整道出
/// </summary>
/// <param name="storeCode"></param>
/// <param name="spaceCode"></param>
/// <returns></returns>
public bool OutAllBySpaceCode(string storeCode, string spaceCode)
{
bool result = false;
try
{
BaseSpaceInfo spaceInfo = _spaceInfoService.GetSpaceInfoBySpaceCode(storeCode, spaceCode);
if (spaceInfo.spaceStock > 0)
{
#region 创建mes执行任务关联生产计划
var productPlanInfo = _productPlanInfoService.GetProductPlanInfosByMaterialCode(spaceInfo.materialType);
if (productPlanInfo != null)
{
result = assemblyPlanBusiness.PlanTransmitByProductPlan(productPlanInfo.planCode, spaceInfo.spaceStock);
}
#endregion
else
{
for(int i = 1; i <= spaceInfo.spaceStock; i++)
{
result = this.CreateOutStoreTask(spaceInfo, System.Guid.NewGuid().ToString("N").Substring(0, 7), System.Guid.NewGuid().ToString("N").Substring(0, 10), 1);
if (!result)
{
return false;
}
}
}
}
else
{
PrintLogInfoMessage($"仓库:{storeCode};货道:{spaceCode};出库失败:库存不足");
}
}
catch (Exception ex)
{
logHelper.Error("根据货道出一个异常", ex);
}
return result;
}
/// <summary>
/// 日志输出,界面刷新同时记录文件
/// </summary>
/// <param name="message"></param>
public void PrintLogInfoMessage(string message)
{
RefreshLogMessageEvent?.Invoke(message);
logHelper.Info(message);
}
/// <summary>
/// 异常日志输出
/// </summary>
/// <param name="message"></param>
/// <param name="ex"></param>
private void PrintLogErrorMessage(string message, Exception ex = null)
{
RefreshLogMessageEvent?.Invoke(message);
logHelper.Error(message, ex);
}
/// <summary>
/// 手动释放信号量
/// </summary>
/// <param name="sph"></param>
private void GetAllRelese(Semaphore sph)
{
bool res = sph.WaitOne(1, false);
if (res)
{
GetAllRelese(sph);
}
}
/// <summary>
/// 通过BOM获取物料名称
/// </summary>
/// <param name="materialType"></param>
/// <returns></returns>
public string GetMaterialName(string materialType)
{
string materialName = string.Empty;
var info = _bomInfoService.GetBomInfoByMaterialCode(materialType);
if (info != null)
{
materialName = info.materialName;
}
return materialName;
}
/// 出库找货道
/// </summary>
/// <param name="storeCode"></param>
/// <param name="materialType"></param>
/// <returns></returns>
public BaseSpaceInfo GetSpaceInfoByMaterialType(string storeCode, string materialType)
{
BaseSpaceInfo result = null;
try
{
List<BaseSpaceInfo> info = _spaceInfoService.GetBaseSpaceInfosByMaterialType(storeCode, materialType,2);
if (info != null && info.Count>0)
{
foreach (BaseSpaceInfo item in info)
{
var spaceInfo = taskHandleBusiness.ReadSpaceInfoByPlc(item);
item.spaceStock = spaceInfo.spaceStock;
item.onRouteAmount = spaceInfo.onRouteAmount;
}
result = info.OrderByDescending(x => x.spaceStock).First();
}
else
{
PrintLogInfoMessage("未获取到匹配的货道,请排查货道库存及货道状态是否可用");
}
}
catch (Exception ex)
{
PrintLogErrorMessage("货道信息读取异常", ex);
}
return result;
}
} }