using Admin.Core.Common; using Admin.Core.IService; using Admin.Core.Model; using Aucma.Core.PLc; using log4net; using System; using System.Linq; using System.Threading; using System.Threading.Tasks; /// /// 箱体出库任务 /// namespace Aucma.Core.Tasks { public class Job_BoxFoamOutStoreTask { #region 初始化出库任务 /// /// 初始化出库任务 /// /// public delegate void RefreshOutStoreTask(RealTaskInfo taskInfos); public event RefreshOutStoreTask RefreshOutStoreTaskEvent; #endregion private static readonly log4net.ILog log = LogManager.GetLogger(typeof(Job_BoxFoamOutStoreTask)); protected readonly IBaseOrderInfoServices _baseOrderInfoServices; protected readonly IBaseSpaceInfoServices _baseSpaceInfoServices; protected readonly IBaseBomInfoServices _baseBomInfoServices; protected readonly IRealTaskInfoServices _realTaskInfoServices; protected readonly IExecutePlanInfoServices _executePlanInfoServices; public Job_BoxFoamOutStoreTask(IBaseOrderInfoServices baseOrderInfoServices, IBaseSpaceInfoServices baseSpaceInfoServices, IRealTaskInfoServices realTaskInfoServices,IBaseBomInfoServices baseBomInfoServices, IExecutePlanInfoServices executePlanInfoServices) { _baseOrderInfoServices = baseOrderInfoServices; _baseSpaceInfoServices = baseSpaceInfoServices; _baseBomInfoServices = baseBomInfoServices; _realTaskInfoServices = realTaskInfoServices; _executePlanInfoServices = executePlanInfoServices; } public async Task Run() { var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("泡前库Plc")); if (obj.IsConnect) { var val = obj.plc.ReadBool("M100");//出发出库点位 if (val) { //获取发泡夹类型=》箱体类型 var planInfo = await _executePlanInfoServices.FirstAsync(); await PlanHandle(planInfo); } } } private async Task PlanHandle(ExecutePlanInfo planInfo) { string storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//读取泡前库标识 if (planInfo != null) { var boxBomInfo = await _baseBomInfoServices.GetChildenBomInfoByMaterialCode(planInfo.MaterialCode, storeCode); OutStore(storeCode, boxBomInfo, planInfo.ExecutePlanCode); } } private async void OutStore(string storeCode, BaseBomInfo bomInfo, string planCode) { try { log.Info($"收到出库计划,物料码:{bomInfo.MaterialCode}"); //BaseSpaceInfo spaceInfo = await _baseSpaceInfoServices.OutStoreGetSpaceInfoByMaterialCode(storeCode, bomInfo.MaterialCode); //if (spaceInfo != null) //{ // log.Info($"匹配货道:{spaceInfo.SpaceName}"); // //RefreshScanMateriaCodeEvent?.Invoke(materiaclCode, materialType, spaceInfo.spaceName, storeCode); //刷新界面扫码信息 // CreateOutStoreTask(spaceInfo, bomInfo, planCode); //创建出库任务 //} //else //{ // //报警停线 //} } catch (Exception ex) { log.Info($"出库业务异常:{ex.Message}"); } } #region 创建出库任务 /// /// 创建出库任务 /// /// private async void CreateOutStoreTask(BaseSpaceInfo spaceInfo, BaseBomInfo bomInfo, string planCode) { //生成出库任务依次下发至PLC RealTaskInfo realTaskInfo = new RealTaskInfo(); realTaskInfo.PlanCode = planCode; realTaskInfo.TaskType = 2; realTaskInfo.TaskCode = System.Guid.NewGuid().ToString("N").Substring(0, 6); realTaskInfo.StoreCode = spaceInfo.StoreCode; realTaskInfo.SpaceCode = spaceInfo.SpaceCode; realTaskInfo.SpaceName = spaceInfo.SpaceName; realTaskInfo.MaterialType = bomInfo.MaterialName; realTaskInfo.MaterialCode = bomInfo.MaterialCode; realTaskInfo.PlanAmount = 1; realTaskInfo.TaskStatus = 1; realTaskInfo.CreateTime = DateTime.Now; int result = await _realTaskInfoServices.AddAsync(realTaskInfo); if (result > 0) { log.Info("出库任务创建成功"); RefreshOutStoreTaskEvent?.Invoke(realTaskInfo); } else { log.Error("出库任务创建失败"); } } #endregion } }