1
wankeda
2025-03-22 867aba2636e34a1050b1c4c84bbe78cc9c39b553
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar.Extensions;
using WIDESEA_Core;
using WIDESEA_Core.Enums;
using WIDESEA_Model.Models;
 
 
 
namespace WIDESEA_TaskInfoService
{
    public partial class TaskService
    {
        /// <summary>
        /// 空托入库
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent EmptyInTask(SaveModel saveModel)
        {
            lock (text)
            {
                WebResponseContent content = new WebResponseContent();
                try
                {
                    string stationcode = saveModel.MainData["stationcode"].ToString();
                    //string PalletCode = saveModel.MainData["PalletCode"].ToString();
                    //string toaddress = saveModel.MainData["toaddress"].ToString();
                    if (stationcode == "")//异常返回。。。。。。
                    {
                        return content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:{"扫码数据不能为空"}");
                    }
                    Dt_CachePoint endCachePoint = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode.Contains("空托库HCK") && x.PointStatus == LocationStatusEnum.Free.ObjToInt());
                    if (endCachePoint == null)
                    {
                        return content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:{"未找到空托库出库位可用缓存架"}");
                    }
                    Dt_CachePoint point = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == stationcode);
                    if (point == null)
                    {
                        return content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:{"扫码数据异常,未找到此缓存架或物料类型不匹配"}");
                    }
                    Dt_CachePoint points = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == stationcode && x.PointStatus == LocationStatusEnum.Free.ObjToInt());
                    if (points == null)
                    {
                        return content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:{"扫码数据异常,此缓存点已被锁定"}");
                    }
                    Dt_Task taskcode = BaseDal.QueryFirst(x => x.SourceAddress == stationcode || x.TargetAddress == stationcode);
                    if (taskcode != null)
                    {
                        return content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:该站点已存在任务");
                    }
                    List<Dt_Task> tasks = new List<Dt_Task>();
                    Dt_Task task = new Dt_Task()
                    {
                        CurrentAddress = "",
                        Grade = 1,
                        NextAddress = "",
                        PalletCode = "",
                        Roadway = "",
                        SourceAddress = stationcode,
                        TargetAddress = endCachePoint.PointCode,
                        TaskStatus = AGVTaskStatusEnum.AGV_New.ObjToInt(),
                        TaskType = TaskTypeEnum.AGVCarry.ObjToInt(),
                        Depth = 1,
                        Materialtype = "",
                        TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                        Creater = App.User.UserId > 0 ? App.User.UserName : "System",
                    };
                    tasks.Add(task);
                    Repository.AddData(tasks);
                    //修改已存在任务缓存架状态
                    HCJLock(task);
                    content = WebResponseContent.Instance.OK();
                }
                catch (Exception ex)
                {
                    content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:{ex.Message}");
                }
                return content;
            }
 
        }
        /// <summary>
        /// 空托出库
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent EmptyOutTask(SaveModel saveModel)
        {
            lock (text)
            {
                WebResponseContent content = new WebResponseContent();
                try
                {
                    string stationcode = saveModel.MainData["stationcode"].ToString();
                    //string PalletCode = saveModel.MainData["PalletCode"].ToString();
                    //string toaddress = saveModel.MainData["toaddress"].ToString();
                    if (stationcode == "")//异常返回。。。。。。
                    {
                        return content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:{"扫码数据不能为空"}");
                    }
                    Dt_CachePoint endCachePoint = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode.Contains("空托库HCK") && x.PointStatus == LocationStatusEnum.Free.ObjToInt());
                    if (endCachePoint == null)
                    {
                        return content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:{"未找到空托库入库位可用缓存架"}");
                    }
                    Dt_CachePoint point = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == stationcode);
                    if (point == null)
                    {
                        return content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:{"扫码数据异常,未找到此缓存架或物料类型不匹配"}");
                    }
                    Dt_CachePoint points = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == stationcode && x.PointStatus == LocationStatusEnum.Free.ObjToInt());
                    if (points == null)
                    {
                        return content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:{"扫码数据异常,此缓存点已被锁定"}");
                    }
                    Dt_Task taskcode = BaseDal.QueryFirst(x => x.SourceAddress == stationcode || x.TargetAddress == stationcode);
                    if (taskcode != null)
                    {
                        return content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:该站点已存在任务");
                    }
                    List<Dt_Task> tasks = new List<Dt_Task>();
                    Dt_Task task = new Dt_Task()
                    {
                        CurrentAddress = "",
                        Grade = 1,
                        NextAddress = "",
                        PalletCode = "",
                        Roadway = "",
                        SourceAddress = stationcode,
                        TargetAddress = endCachePoint.PointCode,
                        TaskStatus = AGVTaskStatusEnum.AGV_New.ObjToInt(),
                        TaskType = TaskTypeEnum.AGVCarry.ObjToInt(),
                        Depth = 1,
                        Materialtype = "",
                        TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                        Creater = App.User.UserId > 0 ? App.User.UserName : "System",
                    };
                    tasks.Add(task);
                    Repository.AddData(tasks);
                    //修改已存在任务缓存架状态
                    HCJLock(task);
                    content = WebResponseContent.Instance.OK();
                }
                catch (Exception ex)
                {
                    content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:{ex.Message}");
                }
                return content;
            }
        }
        /// <summary>
        /// 半成品发货
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent PartiallyTask(SaveModel saveModel)
        {
            lock (text)
            {
                WebResponseContent content = new WebResponseContent();
                try
                {
                    string stationcode = saveModel.MainData["stationcode"].ToString();
                    string PalletCode = saveModel.MainData["PalletCode"].ToString();
                    string toaddress = saveModel.MainData["toaddress"].ToString();
                    if (stationcode == "" || PalletCode == "" || toaddress == "")//异常返回。。。。。。
                    {
                        return content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:{"扫码数据不能为空"}");
                    }
                    Dt_CachePoint endCachePoint = _basicService.CachePointService.Repository.QueryFirst(x => x.Materialtype == PalletCode && x.PointName == toaddress && x.PointStatus == LocationStatusEnum.Free.ObjToInt());
                    if (endCachePoint == null)
                    {
                        return content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:{"未找到终点区域可用缓存架"}");
                    }
                    Dt_CachePoint point = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == stationcode);// && x.Materialtype == PalletCode
                    if (point == null)
                    {
                        return content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:{"扫码数据异常,未找到此缓存架或物料类型不匹配"}");
                    }
                    Dt_CachePoint points = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == stationcode && x.PointStatus == LocationStatusEnum.Free.ObjToInt());
                    if (points == null)
                    {
                        return content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:{"扫码数据异常,此缓存点已被锁定"}");
                    }
                    Dt_Task taskcode = BaseDal.QueryFirst(x => x.SourceAddress == stationcode || x.TargetAddress == stationcode);
                    if (taskcode != null)
                    {
                        return content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:该站点已存在任务");
                    }
                    List<Dt_Task> tasks = new List<Dt_Task>();
                    Dt_Task task = new Dt_Task()
                    {
                        CurrentAddress = "",
                        Grade = 1,
                        NextAddress = "",
                        PalletCode = "",
                        Roadway = "",
                        SourceAddress = stationcode,
                        TargetAddress = endCachePoint.PointCode,
                        TaskStatus = AGVTaskStatusEnum.AGV_New.ObjToInt(),
                        TaskType = TaskTypeEnum.AGVCarry.ObjToInt(),
                        Depth = 1,
                        Materialtype = PalletCode,
                        TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                        Creater = App.User.UserId > 0 ? App.User.UserName : "System",
                    };
                    tasks.Add(task);
                    Repository.AddData(tasks);
                    //修改已存在任务缓存架状态
                    HCJLock(task);
                    content = WebResponseContent.Instance.OK();
                }
                catch (Exception ex)
                {
                    content = WebResponseContent.Instance.Error($"添加任务异常,错误信息:{ex.Message}");
                }
                return content;
            }
        }
        /// <summary>
        /// 确认收货
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent ConfirmTask(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                string stationcode = saveModel.MainData["stationcode"].ToString();
                //string PalletCode = saveModel.MainData["PalletCode"].ToString();
                if (stationcode == "")//异常返回。。。。。。|| PalletCode == ""
                {
                    return content = WebResponseContent.Instance.Error($"收货异常,错误信息:{"扫码数据不能为空"}");
                }
                Dt_CachePoint cachePoint = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == stationcode && (x.PointStatus == LocationStatusEnum.Lock.ObjToInt() || x.PointStatus == LocationStatusEnum.InStock.ObjToInt()));//&& x.Materialtype == PalletCode
                if (cachePoint == null)
                {
                    return content = WebResponseContent.Instance.Error($"收货异常,错误信息:{"缓存位不是锁定状态"}");
                }
                Dt_CachePoint point = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == stationcode);// && x.Materialtype == PalletCode
                if (point == null)
                {
                    return content = WebResponseContent.Instance.Error($"收货异常,错误信息:{"扫码数据异常,未找到此缓存架或物料类型不匹配"}");
                }
                Dt_Task taskcode = BaseDal.QueryFirst(x => (x.SourceAddress == stationcode || x.TargetAddress == stationcode));
                if (taskcode != null)
                {
                    return content = WebResponseContent.Instance.Error($"收货异常,错误信息:该站点已存在任务");
                }
                cachePoint.PointStatus = LocationStatusEnum.Free.ObjToInt();
                _basicService.CachePointService.Repository.UpdateData(cachePoint);
                content = WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
 
                content = WebResponseContent.Instance.Error($"收货异常,错误信息:{ex.Message}");
            }
            return content;
        }
    }
}