huangxiaoqiang
2 天以前 2d9272bdcdbdbca81396a61493e4ef6a822dcf4a
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
using HslCommunication;
using Mapster;
using Newtonsoft.Json;
using SqlSugar;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_Model.BasicInfo;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_Tasks.ConveyorLineJob;
 
namespace WIDESEAWCS_Tasks
{
    public partial class CommonConveyorLineJob
    {
        public async Task HandleNewTaskAsync(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, Dt_Task task = null)
        {
            var stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode && x.stationPLC == conveyorLine.DeviceCode);
 
            switch (stationManager.stationType)
            {
                case 1:
                    await RequestTask(conveyorLine, command, childDeviceCode, stationManager);
                    break;
 
                case 2:
                case 3:
                    RequestNextAddress(command, conveyorLine, stationManager, task);
                    break;
                case 4:
                case 5:
                    task = _taskService.QueryConveyorLineFinishTask(stationManager.stationChildCode, command.TaskNum);
                    if (task != null)
                    {
                        _taskService.UpdateTaskStatusToNext(task);
                    }
                    break;
                default:
                    break;
            }
        }
 
        private async Task RequestTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, Dt_StationManager stationManager)
        {
            var hasTask = await _taskRepository.QueryFirstAsync(x => x.SourceAddress == childDeviceCode);
            if (hasTask != null)
            {
                var log = $"【{conveyorLine._deviceName}】任务号:【{hasTask.TaskNum}】,托盘条码:【{hasTask.PalletCode}】已到达【{childDeviceCode}】输送线存在任务";
                ConsoleHelper.WriteWarningLine(log);
 
               await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
                WriteInfo(conveyorLine.DeviceName, log);
                return;
            }
            var RGVName = string.Empty;
            if (stationManager.stationFloor == "1F")
            {
                var deviceCode = _deviceInfoRepository.Db.Queryable<Dt_DeviceInfo>().Where(x => x.DeviceStatus == "1" && x.DeviceRemark == "1F").Where(x => x.DeviceCode.Contains("RGV")).ToList().Select(x => x.DeviceCode).ToList();
                if (deviceCode != null && deviceCode.Count() > 0)
                {
                    if (deviceCode.Contains("RGV01") && deviceCode.Contains("RGV02"))
                    {
                        var RGVOne = _taskRepository.QueryData(x => x.RGVName == "RGV01").ToList();
                        var RGVTwo = _taskRepository.QueryData(x => x.RGVName == "RGV02").ToList();
                        if (RGVOne.Count > RGVTwo.Count)
                        {
                            RGVName = "RGV01";
                        }
                        else
                        {
                            RGVName = "RGV02";
                        }
                    }
                    else
                    {
                        RGVName = deviceCode[0];
                    }
                }
                else
                {
                    RGVName = "RGV01";
                }
            }
            else
            {
                RGVName = "RGV03";
            }
 
 
                Dt_Task task = new Dt_Task()
                {
                    TaskNum = _taskRepository.GetTaskNo().Result,
                    TaskType = (int)TaskInboundTypeEnum.Inbound,
                    TaskState = (int)TaskInStatusEnum.InNew,
                    SourceAddress = childDeviceCode,
                    Dispatchertime = DateTime.Now,
                    Grade = 1, // 设置默认优先级为1
                    Creater = "System",
                    Floor = stationManager.stationFloor,
                    RGVName = stationManager.RGVName != null ? stationManager.RGVName : RGVName,
                };
            _taskRepository.AddData(task);
        }
    }
}