huangxiaoqiang
12 小时以前 960b33fa24c47a330e51a2c24859d681ae62caeb
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
using HslCommunication;
using HslCommunication.WebSocket;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Information;
using Quartz;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.AGV;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_DTO.WMS;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_TaskInfoRepository;
using WIDESEAWCS_Tasks.ConveyorLineJob;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class CommonAGVJob : JobBase, IJob
    {
        private readonly ITaskRepository _taskRepository;
        private readonly ITaskService _taskService;
        private readonly ISys_ConfigService _sys_ConfigService;
        public CommonAGVJob(ITaskRepository taskRepository, ITaskService taskService, ISys_ConfigService configService)
        {
            _taskRepository = taskRepository;
            _taskService = taskService;
            _sys_ConfigService = configService;
        }
 
        public Task Execute(IJobExecutionContext context)
        {
            var tasks = _taskRepository.QueryData(x => x.TaskState == (int)TaskInStatusEnum.InNew || x.TaskState == (int)TaskOutStatusEnum.OutNew).ToList();
            foreach (var item in tasks)
            {
                TaskModel taskModel = new TaskModel()
                {
                    taskType = item.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup ? "putaway" : "carry",
                    taskGroupCode = "taskGroupCode-001",
                    groupPriority = 0,
                    tasks = new List<TasksType>
                        {
                                new()
                                {
                                    taskCode="KH"+item.TaskNum.ToString(),
                                    taskPriority=0,
                                    taskDescribe = new TaskDescribeType
                                    {
                                        containerCode = item.PalletCode,
                                        containerType = "CT_KUBOT_STANDARD",
                                        fromLocationCode =  item.SourceAddress,
                                        toStationCode = "",
                                        toLocationCode = item.TargetAddress,
                                        deadline = 0,
                                    }
                                }
                        }
                };
                var wmsIpAddress = GetIpAddress(SysConfigKeyConst.ESSIP_BASE, SysConfigKeyConst.SendTask);
                var result = HttpHelper.PostAsync(wmsIpAddress, taskModel.ToJsonString()).Result;
                var response = JsonConvert.DeserializeObject<Response>(result);
                if (response != null && response.Msg == "success")
                {
                    //item.TaskState = item.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup ? (int)TaskInStatusEnum.HasSend : (int)TaskOutStatusEnum.HasSend;
                    //_taskRepository.Db.Updateable(item).ExecuteCommandAsync();
                    _taskService.UpdateTaskStatusToNext(item.TaskNum);
                }
            }
            return Task.CompletedTask;
        }
 
        private string GetIpAddress(string baseIp, string name)
        {
            var configz = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
            var wcsBasez = configz.Where(x => x.ConfigKey == baseIp).FirstOrDefault()?.ConfigValue;
            var address = configz.Where(x => x.ConfigKey == name).FirstOrDefault()?.ConfigValue;
            if (wcsBasez == null || address == null)
            {
                throw new InvalidOperationException("WMS IP 未配置");
            }
            return wcsBasez + address;
        }
    }
}