using Quartz; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using WIDESEA_Common; using WIDESEA_Core.EFDbContext; using WIDESEA_Entity.DomainModels; using WIDESEA_Services.Repositories; using WIDESEA_Services.IRepositories; using WIDESEA_WCS.Jobs; using WIDESEA_WCS.WCSClient; using static System.Collections.Specialized.BitVector32; using System.Threading; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; using WIDESEA_Core.Extensions; using HslCommunication; using WIDESEA_Services; using WIDESEA_Core.Utilities; using WIDESEA_Services.Services; using WIDESEA_Common.TaskEnum; using WIDESEA_WCS.Jobs.ConveyorLine; using WIDESEA_Common.LogEnum; using WIDESEA_Common.Tools; using WIDESEA_WCS.Jobs.ConveyorLine.InboundArea; using WIDESEA_WCS.Jobs.ConveyorLine.OutboundArea; namespace WIDESEA_WCS { [DisallowConcurrentExecution] public class ConveyorLineDispatchJob : JobBase, IJob { /// /// 获取输送线信息 /// /// /// public Task Execute(IJobExecutionContext context) { return Task.Run(() => { var executeLog = ExecuteJob(context, () => Run(context)); }); } public string Run(IJobExecutionContext context) { using (VOLContext dbCcontext = new VOLContext()) { IDt_PLCinfoHeadRepository _PLCinfoHeadRepository = new Dt_PLCinfoHeadRepository(dbCcontext); IDt_StationManagerRepository stationManagerRepository = new Dt_StationManagerRepository(dbCcontext); List _PLCinfoHeads = _PLCinfoHeadRepository.Find(r => r.plcinfo_equiptype == "ConveyorLine" && r.plcinfo_state == "Enable"); IDt_TaskWCSinfoRepository taskWCSinfoRepository = new Dt_TaskWCSinfoRepository(dbCcontext); IDt_TaskRGVinfoRepository taskRGVinfoRepository = new Dt_TaskRGVinfoRepository(dbCcontext); if (null != _PLCinfoHeads) { PLCClient client = WCSService.Clients.Find(r => r.PLCName == "LineDevice"); if (null == client || !client.IsConnected) { string str = "PLC: " + client.PLCName + ", Ip: " + client.PLCIPAddress + ", 与调度系统断开连接"; WriteLog.Info("PLC异常").Write(str, "PLC异常"); return ""; } //说明是入库区的调度,查看入库区线体的运行模式 int modelResult = int.Parse(client.ReadValue(CLineInfoDBName.R_System_Inline_Run_Model.ToString(), "System").ToString()); if (modelResult == 3) { //1=手动 2=单机 3=联机 //入库申请站台调度 20101 bool modelResult1 = bool.Parse(client.ReadValue(CLineInfoDBName.R_System_Normal_Model.ToString(), "System").ToString()); if (modelResult1) { //入库口 InboundAreaDispatch.InboundRequestStationAction(taskWCSinfoRepository, client, "InBound"); //测量站台逻辑 10301 InboundAreaDispatch.MeasureStationAction(taskWCSinfoRepository, client, "Measure_B"); //入库站台确认 InboundAreaDispatch.InboundStationAction(taskWCSinfoRepository, taskRGVinfoRepository, client); //出库站台确认 InboundAreaDispatch.OutboundStationAction(taskWCSinfoRepository, taskRGVinfoRepository, client); } else { //应急模式 modelResult1 = bool.Parse(client.ReadValue(CLineInfoDBName.R_System_Emery_Model.ToString(), "System").ToString()); if (modelResult1) { //左侧可用 modelResult1 = bool.Parse(client.ReadValue(CLineInfoDBName.R_System_LeftState.ToString(), "System").ToString()); if (!modelResult1) { //入库站台确认 InboundAreaDispatch.InboundStationAction_YJ(taskWCSinfoRepository, taskRGVinfoRepository, client, true); //出库站台确认 InboundAreaDispatch.OutboundStationAction_YJ(taskWCSinfoRepository, taskRGVinfoRepository, client, true); InboundAreaDispatch.MeasureStationAction(taskWCSinfoRepository, client, "Measure_B_YJ"); InboundAreaDispatch.InboundRequestStationAction(taskWCSinfoRepository, client, "InBound_YJ"); } else { //右侧可用 modelResult1 = bool.Parse(client.ReadValue(CLineInfoDBName.R_System_RightState.ToString(), "System").ToString()); if (!modelResult1) { InboundAreaDispatch.InboundStationAction_YJ(taskWCSinfoRepository, taskRGVinfoRepository, client, false); //出库站台确认 InboundAreaDispatch.OutboundStationAction_YJ(taskWCSinfoRepository, taskRGVinfoRepository, client, false); InboundAreaDispatch.MeasureStationAction(taskWCSinfoRepository, client, "Measure_B"); InboundAreaDispatch.InboundRequestStationAction(taskWCSinfoRepository, client, "InBound"); } } } } //InboundAreaDispatch.InboundRequestStationAction(taskWCSinfoRepository, client, "InBound"); ////测量站台逻辑 10301 //InboundAreaDispatch.MeasureStationAction(taskWCSinfoRepository, client, "Measure_B"); ////入库站台确认 //InboundAreaDispatch.InboundStationAction(taskWCSinfoRepository, taskRGVinfoRepository, client); ////出库站台确认 //InboundAreaDispatch.OutboundStationAction(taskWCSinfoRepository, taskRGVinfoRepository, client); //称重站台调度 20201 InboundAreaDispatch.InboundWeighAction(taskWCSinfoRepository, client); //出库RFID确认(测量) InboundAreaDispatch.CheckBarcodeAction(taskWCSinfoRepository, client, "30301"); InboundAreaDispatch.CheckBarcodeAction(taskWCSinfoRepository, client, "30302"); } //说明是出库区的调度,查看入库区线体的运行模式 modelResult = int.Parse(client.ReadValue(CLineInfoDBName.R_System_Inline_Run_Model.ToString(), "OutSystem").ToString()); //string rel = client.ReadValue(CLineInfoDBName.W_System_RGVState.ToString()).ToString(); if (modelResult == 3) { //出库区域调度 OutboundAreaDispatch.OutboundAreaDispathAction(taskWCSinfoRepository, taskRGVinfoRepository, client); } else if (modelResult == 2) { client.WriteValue(CLineInfoDBName.W_System_RGVState.ToString(), true); } } } return ""; } } }