wangxinhui
2025-03-15 efaf0b8aeb26aca6536a4b384c912cc3cac4d070
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEAWCS_TaskInfoService
 * 创建者:胡童庆
 * 创建时间:2024/8/2 16:13:36
 * 版本:V1.0.0
 * 描述:
 *
 * ----------------------------------------------------------------
 * 修改人:
 * 修改时间:
 * 版本:V1.0.1
 * 修改说明:
 * 
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEAWCS_TaskInfoService
{
    public class TaskExecuteDetailService : ServiceBase<Dt_TaskExecuteDetail, ITaskExecuteDetailRepository>, ITaskExecuteDetailService
    {
        private readonly ITaskRepository _taskRepository;
 
        public TaskExecuteDetailService(ITaskExecuteDetailRepository BaseDal, ITaskRepository taskRepository) : base(BaseDal)
        {
            _taskRepository = taskRepository;
        }
 
        public void AddTaskExecuteDetail(int taskId, string description = "")
        {
            try
            {
                bool isNormal = true;
                Dt_Task task = _taskRepository.QueryFirst(x => x.TaskId == taskId);
                if (task == null) return;
                int taskNum = task.TaskNum;
                int taskState = task.TaskState;
 
                if(taskState > (int)TaskStatusEnum.Finish)
                {
                    isNormal = false;
                }
                Dt_TaskExecuteDetail taskExecuteDetail = new()
                {
                    IsManual = App.User?.UserId > 0,
                    IsNormal = isNormal,
                    TaskNum = taskNum,
                    TaskId = taskId,
                    TaskState = taskState,
                    Description = description,
                    CurrentAddress = task.CurrentAddress,
                    NextAddress = task.NextAddress,
                };
                BaseDal.AddData(taskExecuteDetail);
            }
            catch (Exception ex)
            {
 
            }
        }
 
        public void AddTaskExecuteDetail(List<int> taskNums, string description = "")
        {
            try
            {
                List<Dt_TaskExecuteDetail> taskExecuteDetails = new List<Dt_TaskExecuteDetail>();
                foreach (var item in taskNums)
                {
                    bool isNormal = true;
                    Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == item);
                    if (task == null) return;
                    int taskNum = task.TaskNum;
                    int taskState = task.TaskState;
 
                    if (taskState > (int)TaskStatusEnum.Finish)
                    {
                        isNormal = false;
                    }
                    Dt_TaskExecuteDetail taskExecuteDetail = new()
                    {
                        IsManual = App.User?.UserId > 0,
                        IsNormal = isNormal,
                        TaskNum = taskNum,
                        TaskId = task.TaskId,
                        TaskState = taskState,
                        Description = description,
                        CurrentAddress = task.CurrentAddress,
                        NextAddress = task.NextAddress,
                    };
                    taskExecuteDetails.Add(taskExecuteDetail);
                }
 
                BaseDal.AddData(taskExecuteDetails);
            }
            catch (Exception ex)
            {
 
            }
        }
 
        public WebResponseContent GetDetailInfo(int taskNum)
        {
            WebResponseContent content = new();
            try
            {
                int active = -1;
                List<object> list = new();
                List<int> steps = new();
                Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == taskNum);
                if (task != null)
                {
 
                    //if (!int.TryParse(Enum.Parse<TaskOutboundTypeEnum>(task.TaskType.ToString()).ToString(), out int result))
                    //{
                    //    steps = Enum.GetValues(typeof(TaskOutStatusEnum)).Cast<int>().Where(x => x <= (int)TaskOutStatusEnum.OutFinish).ToList();
 
                    //    foreach (var item in steps)
                    //    {
                    //        object obj;
                    //        FieldInfo? fieldInfo = typeof(TaskOutStatusEnum).GetField(((TaskOutStatusEnum)item).ToString());
                    //        DescriptionAttribute? descriptionAttribute = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
                    //        if (descriptionAttribute != null)
                    //        {
                    //            obj = new { title = item, description = descriptionAttribute.Description };
                    //        }
                    //        else
                    //        {
                    //            obj = new { title = item, description = ((TaskOutStatusEnum)item).ToString() };
                    //        }
                    //        list.Add(obj);
                    //    }
                    //}
                    //else if (!int.TryParse(Enum.Parse<TaskTypeEnum>(task.TaskType.ToString()).ToString(), out result))
                    //{
                    //    steps = Enum.GetValues(typeof(TaskInStatusEnum)).Cast<int>().Where(x => x <= (int)TaskInStatusEnum.InFinish).ToList();
                    //    foreach (var item in steps)
                    //    {
                    //        object obj;
                    //        FieldInfo? fieldInfo = typeof(TaskInStatusEnum).GetField(((TaskInStatusEnum)item).ToString());
                    //        DescriptionAttribute? descriptionAttribute = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
                    //        if (descriptionAttribute != null)
                    //        {
                    //            obj = new { title = item, description = descriptionAttribute.Description };
                    //        }
                    //        else
                    //        {
                    //            obj = new { title = item, description = ((TaskInStatusEnum)item).ToString() };
                    //        }
                    //        list.Add(obj);
                    //    }
                    //}
                    //else if (!int.TryParse(Enum.Parse<TaskRelocationTypeEnum>(task.TaskType.ToString()).ToString(), out result))
                    //{
                    //    //todo 调用WMS移库完成
                    //}
                    //else if (!int.TryParse(Enum.Parse<TaskOtherTypeEnum>(task.TaskType.ToString()).ToString(), out result))
                    //{
 
                    //}
                    //else
                    //{
                    //    throw new Exception($"任务类型错误,未找到该任务类型,任务号:【{taskNum}】,任务类型:【{task.TaskType}】");
                    //}
                    active = steps.IndexOf(task.TaskState) + 1;
 
                }
 
                content = WebResponseContent.Instance.OK(data: new { active, list });
            }
            catch (Exception ex)
            {
 
            }
            return content;
        }
 
        public WebResponseContent GetDetailDatas(int taskNum)
        {
            WebResponseContent content = new();
            try
            {
                Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == taskNum);
                if (task != null)
                {
                    List<Dt_TaskExecuteDetail> taskExecuteDetails = BaseDal.QueryData(x => x.TaskId == task.TaskId, new Dictionary<string, SqlSugar.OrderByType> { { nameof(Dt_TaskExecuteDetail.TaskDetailId), SqlSugar.OrderByType.Asc } });
 
                    content = WebResponseContent.Instance.OK(data: taskExecuteDetails);
                }
                else
                {
                    content = WebResponseContent.Instance.Error($"未找到该任务信息,任务号:【{taskNum}】");
                }
            }
            catch (Exception ex)
            {
 
            }
            return content;
        }
    }
}