wangxinhui
4 天以前 9ec715d2deb18a269dd49c48da91a36632d08c81
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_Tasks.HoisterJob;
 
namespace WIDESEAWCS_Tasks
{
    /// <summary>
    /// 阻焊仓地面站
    /// </summary>
    [DisallowConcurrentExecution]
    public class GroundStationJob_ZH : JobBase, IJob
    {
        private readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly ITaskRepository _taskRepository;
        private readonly IStationMangerRepository _stationMangerRepository;
 
        public GroundStationJob_ZH(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _taskRepository = taskRepository;
            _stationMangerRepository = stationMangerRepository;
        }
 
        public Task Execute(IJobExecutionContext context)
        {
            OtherDevice device = (OtherDevice)context.JobDetail.JobDataMap.Get("JobParams");
            try
            {
                if (device == null)
                {
                    WriteError(nameof(GroundStationJob_CSJ), "调度错误,设备对象传值为null");
                    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)))
                {
                    try
                    {
                        short isTraytype = device.GetValue<GroundStationDBName, short>(GroundStationDBName.R_TakePalletType, item.StationCode);
                        bool isCanPut = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanPut, item.StationCode);
                        bool isCanTake = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanTake, item.StationCode);
                        short takePalletType = device.GetValue<GroundStationDBName, short>(GroundStationDBName.W_PutPalletType, item.StationCode);
                        bool putRequest = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.W_PutRequest, item.StationCode);
                        bool putFinish = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.W_PutFinish, item.StationCode);
                        bool takeRequest = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.W_TakeRequest, item.StationCode);
                        bool takeFinish = device.GetValue<GroundStationDBName, bool>(GroundStationDBName.W_TakeFinish, item.StationCode);
 
                        if (item.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt())
                        {
 
                            //device.SetValue(GroundStationDBName.W_TakeRequest, true, item.StationCode);
                            //device.SetValue(GroundStationDBName.W_PutPalletType, 1, item.StationCode);//task.PalletType
                            //device.SetValue(GroundStationDBName.W_TakeFinish, true, item.StationCode);
                            ////判断AGV任务完成,后写给地面站取货完成
                            //device.SetValue(GroundStationDBName.W_TakeRequest, false, item.StationCode);
                            //device.SetValue(GroundStationDBName.W_TakeFinish, false, item.StationCode);
                            Dt_Task task = _taskRepository.QueryFirst(x => x.DeviceCode == item.StackerCraneCode && x.TaskState == TaskStatusEnum.New.ObjToInt() && x.NextAddress==item.StationCode);
                            if (task != null && isCanPut && !isCanTake && !putRequest && !putFinish && !takeRequest && !takeFinish)
                            {
                                _taskService.UpdateTask(task, TaskStatusEnum.SC_Execute, nextAddress: item.StackerCraneStationCode);
                            }
                        }
                        if (item.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt())
                        {
                            
                             Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress==item.StationCode && string.IsNullOrEmpty(x.TargetAddress) && string.IsNullOrEmpty(x.NextAddress) && x.TaskState == TaskStatusEnum.AGV_Finish.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;
                                }
                                //string? locationCode = "SC01_ZH-001-027-001-02";//
                                string? locationCode = _taskService.RequestAssignLocation(task.TaskNum, stationManger.StackerCraneCode);
                                if (string.IsNullOrEmpty(locationCode))
                                {
                                    WriteError(item.StationName, $"请求分配货位返回信息错误,设备编号:{item.StationCode},任务号:{task.TaskNum}");
                                    continue;
                                }
                                _taskService.UpdateTask(task, TaskStatusEnum.SC_Execute, currentAddress: stationManger.StackerCraneStationCode, targetAddress: locationCode, nextAddress: locationCode, deviceCode: stationManger.StackerCraneCode);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteError(device.DeviceCode, $"{item}交互错误", ex);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteError(device.DeviceName, "", ex);
            }
            return Task.CompletedTask;
        }
    }
}