|  |  |  | 
|---|
|  |  |  | using Newtonsoft.Json; | 
|---|
|  |  |  | using Microsoft.AspNetCore.Components.Routing; | 
|---|
|  |  |  | using Newtonsoft.Json; | 
|---|
|  |  |  | using Quartz; | 
|---|
|  |  |  | using SqlSugar.Extensions; | 
|---|
|  |  |  | using System; | 
|---|
|  |  |  | using System.Collections.Generic; | 
|---|
|  |  |  | using System.Linq; | 
|---|
|  |  |  | using System.Text; | 
|---|
|  |  |  | using System.Threading.Tasks; | 
|---|
|  |  |  | using WIDESEAWCS_Common; | 
|---|
|  |  |  | using WIDESEAWCS_Common.TaskEnum; | 
|---|
|  |  |  | using WIDESEAWCS_IBasicInfoRepository; | 
|---|
|  |  |  | using WIDESEAWCS_ITaskInfoRepository; | 
|---|
|  |  |  | using WIDESEAWCS_ITaskInfoService; | 
|---|
|  |  |  | using WIDESEAWCS_Model.Models; | 
|---|
|  |  |  | using WIDESEAWCS_QuartzJob; | 
|---|
|  |  |  | using WIDESEAWCS_QuartzJob.DTO; | 
|---|
|  |  |  | using WIDESEAWCS_QuartzJob.Models; | 
|---|
|  |  |  | using WIDESEAWCS_QuartzJob.Repository; | 
|---|
|  |  |  | using WIDESEAWCS_QuartzJob.Service; | 
|---|
|  |  |  | using WIDESEAWCS_Tasks.ConveyorLineJob; | 
|---|
|  |  |  | using ICacheService = WIDESEAWCS_Core.Caches.ICacheService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | namespace WIDESEAWCS_Tasks.æåä» | 
|---|
|  |  |  | namespace WIDESEAWCS_Tasks | 
|---|
|  |  |  | { | 
|---|
|  |  |  | [DisallowConcurrentExecution] | 
|---|
|  |  |  | public class ConveyorLineJob_CP : JobBase, IJob | 
|---|
|  |  |  | 
|---|
|  |  |  | WriteError(device.DeviceName, $"请é
ç½®ä»åºè®¾å¤ä¿¡æ¯"); | 
|---|
|  |  |  | return Task.CompletedTask; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<string> deviceStations = device.DeviceProDTOs.Select(x => x.DeviceChildCode).ToList(); | 
|---|
|  |  |  | List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode); | 
|---|
|  |  |  | foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode))) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_ConveyorLineCPDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); | 
|---|
|  |  |  | DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(W_ConveyorLineCPDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); | 
|---|
|  |  |  | if (item.StationType==StationTypeEnum.StationType_OnlyInbound.ObjToInt() && deviceProWrite!=null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && (x.TaskState == TaskStatusEnum.New.ObjToInt()) && x.DeviceCode == device.DeviceCode); | 
|---|
|  |  |  | if (task!=null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //è·åç«å° | 
|---|
|  |  |  | Dt_StationManger? stationManger = stationMangers.FirstOrDefault(x => x.StationCode == item.StationCode); | 
|---|
|  |  |  | if (stationManger == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WriteError(item.StationName, $"æªæ¾å°å¯¹åºç«å°ä¿¡æ¯,设å¤ç¼å·:{item.StationCode},ä»»å¡å·:{task.TaskNum}"); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //æ¥è¯¢è·¯ç± | 
|---|
|  |  |  | Dt_Router router = _routerRepository.QueryFirst(x => x.InOutType == task.TaskType && x.StartPosi == task.CurrentAddress); | 
|---|
|  |  |  | if (router == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WriteError(item.StationName, $"æªæ¾å°è·¯ç±é
置信æ¯,设å¤ç¼å·:{item.StationCode},ä»»å¡å·:{task.TaskNum}"); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //string? locationCode = _taskService.RequestAssignLocation(task.TaskNum, "AGV_CP"); | 
|---|
|  |  |  | //if (string.IsNullOrEmpty(locationCode) && task.TaskType != TaskTypeEnum.EmptyProductBack.ObjToInt()) | 
|---|
|  |  |  | //{ | 
|---|
|  |  |  | //    WriteError(item.StationName, $"请æ±åé
è´§ä½è¿åä¿¡æ¯é误,设å¤ç¼å·:{item.StationCode},ä»»å¡å·:{task.TaskNum}"); | 
|---|
|  |  |  | //    continue; | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | device.SetValue(W_ConveyorLineCPDB.StartPos, router.StartPosi, item.StationCode); | 
|---|
|  |  |  | device.SetValue(W_ConveyorLineCPDB.EndPos, router.NextPosi, item.StationCode); | 
|---|
|  |  |  | device.SetValue(W_ConveyorLineCPDB.Barcode, task.PalletCode, item.StationCode); | 
|---|
|  |  |  | device.SetValue(W_ConveyorLineCPDB.TaskNum, task.TaskNum, item.StationCode); | 
|---|
|  |  |  | device.SetValue(W_ConveyorLineCPDB.WorkType, task.PalletType, item.StationCode); | 
|---|
|  |  |  | device.SetValue(W_ConveyorLineCPDB.WorkMode, 1, item.StationCode); | 
|---|
|  |  |  | device.SetValue(W_ConveyorLineCPDB.CheckPos, 1, item.StationCode); | 
|---|
|  |  |  | //å¯å¨æä»¤ | 
|---|
|  |  |  | device.SetValue(W_ConveyorLineCPDB.ConveyArrival, 1, item.StationCode); | 
|---|
|  |  |  | _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing, nextAddress: router.NextPosi, targetAddress: router.NextPosi); | 
|---|
|  |  |  | if (task.TaskType==TaskTypeEnum.EmptyProductBack.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _taskService.TaskCompleted(task.TaskNum); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (item.StationType == StationTypeEnum.StationType_InStartAndOutEnd.ObjToInt() && deviceProRead != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | R_ConveyorLineCPInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineCPInfo>(deviceProRead.DeviceProAddress); | 
|---|
|  |  |  | if (conveyorLineInfoRead != null && conveyorLineInfoRead.EndPos.ToString() == item.StationCode) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | short isCanTake = device.GetValue<GroundStationDBName, short>(GroundStationDBName.R_IsCanTake, item.StationCode); | 
|---|
|  |  |  | if (conveyorLineInfoRead.ConveyArrivaled == 1 && isCanTake == 1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //è·åä»»å¡ | 
|---|
|  |  |  | Dt_Task task = _taskRepository.QueryFirst(x => x.NextAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && (x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt()) && x.DeviceCode == device.DeviceCode && x.TaskNum == conveyorLineInfoRead.TaskNum.ObjToInt()); | 
|---|
|  |  |  | //è·åç«å° | 
|---|
|  |  |  | if (task != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_StationManger? stationManger = stationMangers.FirstOrDefault(x => x.StationCode == item.StationCode); | 
|---|
|  |  |  | if (stationManger == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WriteError(item.StationName, $"æªæ¾å°å¯¹åºç«å°ä¿¡æ¯,设å¤ç¼å·:{item.StationCode},ä»»å¡å·:{task.TaskNum}"); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //æ¥è¯¢è·¯ç± | 
|---|
|  |  |  | Dt_Router router = _routerRepository.QueryFirst(x => x.InOutType == task.TaskType && x.StartPosi == task.NextAddress); | 
|---|
|  |  |  | if (router == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WriteError(item.StationName, $"æªæ¾å°è·¯ç±é
置信æ¯,设å¤ç¼å·:{item.StationCode},ä»»å¡å·:{task.TaskNum}"); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | string? locationCode = _taskService.RequestAssignLocation(task.TaskNum, stationManger.StackerCraneCode); | 
|---|
|  |  |  | if (string.IsNullOrEmpty(locationCode)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WriteError(item.StationName, $"请æ±åé
è´§ä½è¿åä¿¡æ¯é误,设å¤ç¼å·:{item.StationCode},ä»»å¡å·:{task.TaskNum}"); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | _taskService.UpdateTask(task, TaskStatusEnum.AGV_Execute, deviceCode: router.ChildPosiDeviceCode, currentAddress: router.StartPosi, nextAddress: locationCode, targetAddress: locationCode); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //Dt_StationManger? dt_StationManger = stationMangers.FirstOrDefault(x => x.StationType == StationTypeEnum.StationType_ProductBackTake.ObjToInt()); | 
|---|
|  |  |  | //if (dt_StationManger != null) | 
|---|
|  |  |  | //{ | 
|---|
|  |  |  | //    DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == dt_StationManger.StationCode && x.DeviceProParamType == nameof(W_ConveyorLineCPDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); | 
|---|
|  |  |  | //    List<Dt_StationManger> ProductBackStations = stationMangers.Where(x => x.StationType == StationTypeEnum.StationType_ProductBack.ObjToInt()).ToList(); | 
|---|
|  |  |  | //    for (int i = 0; i < ProductBackStations.Count(); i++) | 
|---|
|  |  |  | //    { | 
|---|
|  |  |  | //        short isCanTake = device.GetValue<GroundStationDBName, short>(GroundStationDBName.R_IsCanTake, dt_StationManger.StationCode); | 
|---|
|  |  |  | //        Dt_StationManger stationManger = ProductBackStations[i]; | 
|---|
|  |  |  | //        string startDb = "DB29."; | 
|---|
|  |  |  | //        short stationCurrentStatus = device.Communicator.Read<short>(startDb + stationManger.Remark.ToString()); | 
|---|
|  |  |  | //        short stationEndStatus = device.Communicator.Read<short>(startDb + (stationManger.Remark.ObjToInt() + 2).ToString()); | 
|---|
|  |  |  | //        bool endStatus = true; | 
|---|
|  |  |  | //        if ((i != 2 && i != 5 && i != 8)) | 
|---|
|  |  |  | //        { | 
|---|
|  |  |  | //            endStatus = (stationEndStatus == 1); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        //读åçº¿ä½æ®µç¶æ | 
|---|
|  |  |  | //        if (isCanTake == 1 && stationCurrentStatus == 1 && stationManger.IsOccupied==0 && endStatus) | 
|---|
|  |  |  | //        { | 
|---|
|  |  |  | //            device.SetValue(W_ConveyorLineCPDB.StartPos, dt_StationManger.StationCode, dt_StationManger.StationCode); | 
|---|
|  |  |  | //            device.SetValue(W_ConveyorLineCPDB.EndPos, stationManger.AGVStationCode, dt_StationManger.StationCode); | 
|---|
|  |  |  | //            device.SetValue(W_ConveyorLineCPDB.Barcode, "C00001", dt_StationManger.StationCode); | 
|---|
|  |  |  | //            device.SetValue(W_ConveyorLineCPDB.TaskNum, DateTime.Now.ToString("yyMMddHHmmss"), dt_StationManger.StationCode); | 
|---|
|  |  |  | //            device.SetValue(W_ConveyorLineCPDB.WorkType, 1, dt_StationManger.StationCode); | 
|---|
|  |  |  | //            device.SetValue(W_ConveyorLineCPDB.WorkMode, 1, dt_StationManger.StationCode); | 
|---|
|  |  |  | //            device.SetValue(W_ConveyorLineCPDB.CheckPos, 1, dt_StationManger.StationCode); | 
|---|
|  |  |  | //            //å¯å¨æä»¤ | 
|---|
|  |  |  | //            device.SetValue(W_ConveyorLineCPDB.ConveyArrival, 1, dt_StationManger.StationCode); | 
|---|
|  |  |  | //            stationManger.IsOccupied = 1; | 
|---|
|  |  |  | //            _stationMangerRepository.UpdateData(stationManger); | 
|---|
|  |  |  | //            Thread.Sleep(2000); | 
|---|
|  |  |  | //            return Task.CompletedTask; | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        else if(stationManger.IsOccupied == 1 && (stationCurrentStatus == 3)) | 
|---|
|  |  |  | //        { | 
|---|
|  |  |  | //            stationManger.IsOccupied = 0; | 
|---|
|  |  |  | //            _stationMangerRepository.UpdateData(stationManger); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | //} | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return Task.CompletedTask; | 
|---|
|  |  |  | } | 
|---|