helongyang
16 小时以前 dc06f58d8ed537555fd529551180f43a0586ec3f
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.APIEnum;
using WIDESEA_Common.CommonEnum;
using WIDESEA_Common.LocationEnum;
using WIDESEA_Common.OtherEnum;
using WIDESEA_Common.StockEnum;
using WIDESEA_Common.TaskEnum;
using WIDESEA_Core;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.Task;
using WIDESEA_Model.Models;
 
namespace WIDESEA_TaskInfoService
{
    public partial class TaskService
    {
        public async Task<WebResponseContent> TaskCompleted(int taskNum)
        {
            try
            {
                Dt_Task task = await Repository.QueryFirstAsync(x => x.TaskNum == taskNum);
                if (task == null)
                {
                    return await Task.FromResult(WebResponseContent.Instance.Error($"未找到任务信息"));
                }
                if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
                {
                    return await Task.FromResult(InboundTaskCompleted(taskNum));
                }
                else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                {
                    return await Task.FromResult(OutboundTaskCompleted(taskNum));
                }
                else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
                {
                    return await Task.FromResult(RelocationTaskCompleted(task));
                }
                else
                {
                    return await Task.FromResult(WebResponseContent.Instance.Error($"未找到该类型任务,任务类型:{task.TaskType}"));
                }
            }
            catch (Exception ex)
            {
                return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message));
            }
        }
 
        /// <summary>
        /// 任务信息推送至WCS
        /// </summary>
        /// <returns></returns>
        public WebResponseContent PushTasksToWCSSingle(int taskNum, string agvDescription = "", string agvtaskNum = "")
        {
            try
            {
                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
                if (task == null)
                {
                    return WebResponseContent.Instance.Error($"错误,未找到该任务信息");
                }
 
                List<WMSTaskDTO> taskDTOs = new List<WMSTaskDTO> { _mapper.Map<WMSTaskDTO>(task) };
                taskDTOs.ForEach(x =>
                {
                    x.AGVArea = agvDescription;
                    x.AGVTaskNum = agvtaskNum;
                });
 
                string url = AppSettings.Get("WCS");
                if (string.IsNullOrEmpty(url))
                {
                    throw new Exception($"未找到WCSAApi地址,请检查配置文件");
                }
                string response = HttpHelper.Post($"{url}/api/Task/ReceiveTask", taskDTOs.Serialize());
 
                return JsonConvert.DeserializeObject<WebResponseContent>(response) ?? WebResponseContent.Instance.Error("返回错误");
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        /// <summary>
        /// 修改任务状态
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public WebResponseContent UpdateTaskInfo(WCSTaskDTO task)
        {
            try
            {
                Dt_Task wmsTask = BaseDal.QueryFirst(x=>x.TaskNum == task.TaskNum);
                if (wmsTask != null)
                {
                    wmsTask.TaskStatus = task.TaskState;
                    wmsTask.CurrentAddress = task.CurrentAddress;
                    wmsTask.NextAddress = task.NextAddress;
                    wmsTask.Dispatchertime = task.Dispatchertime;
                    BaseDal.UpdateData(wmsTask);
                }
                return WebResponseContent.Instance.OK();
            }
            catch(Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        /// <summary>
        /// 回调wcs手动完成任务
        /// </summary>
        /// <param name="taskNum"></param>
        /// <returns></returns>
        public WebResponseContent FeedBackWCSTaskCompleted(int taskNum)
        {
            try
            {
                Dt_ApiInfo? url = _apiInfoRepository.QueryData(x => x.ApiCode == APIEnum.FeedBackWCSTaskCompleted.ToString()).First();
                string? apiAddress = url.ApiAddress;
                if (string.IsNullOrEmpty(apiAddress))
                {
                    return WebResponseContent.Instance.Error($"{taskNum},未找到WCS任务完成接口,请检查接口配置");
                }
                string responseStr = HttpHelper.Get(apiAddress + "?taskNum=" + taskNum);
                WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(responseStr) ?? WebResponseContent.Instance.Error("未找到任务完成返回值");
                return content;
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
    }
}