pan
2025-11-05 b2c6ce78c7c95c37f9c3e9ea11e86a7af7b0d3fd
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
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Basic;
using WIDESEA_Model.Models;
 
namespace WIDESEA_TaskInfoService
{
    public partial class TaskService
    {
        /// <summary>
        /// 空托盘出库任务
        /// </summary>
        /// <param name="inTask"></param>
        /// <returns></returns>
        public async Task<WebResponseContent> PalletOutboundTask(string endStation, string palletCode = "")
        {
            try
            {
                Dt_StockInfo stockInfo ;
                if (string.IsNullOrEmpty(palletCode))
                {
                    stockInfo = _stockRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletType == PalletTypeEnum.Empty.ObjToInt()).First();
                }
                else
                {
                    stockInfo = _stockRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode) .First();
                }
 
                if (stockInfo == null)
                {
                    return WebResponseContent.Instance.Error("未找到空托盘库存");
                }
                Dt_LocationInfo locationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
                if (locationInfo == null)
                {
                    return WebResponseContent.Instance.Error("未找到空托盘库存对应的货位信息");
                }
 
                Dt_Task task = new Dt_Task()
                {
                    CurrentAddress = stockInfo.LocationCode,
                    Grade = 0,
                    NextAddress = endStation,
                    PalletCode = stockInfo.PalletCode,
                    Roadway = locationInfo.RoadwayNo,
                    SourceAddress = stockInfo.LocationCode,
                    TargetAddress = endStation,
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    TaskType = TaskTypeEnum.OutEmpty.ObjToInt(),
                    WarehouseId = stockInfo.WarehouseId,
                    PalletType = stockInfo.PalletType
 
                };
                int beforeStatus = locationInfo.LocationStatus;
                _unitOfWorkManage.BeginTran();
                stockInfo.StockStatus = StockStatusEmun.出库锁定.ObjToInt();
                locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
 
                int taskId = BaseDal.AddData(task);
                task.TaskId = taskId;
 
                _stockService.StockInfoService.UpdateData(stockInfo);
 
                _locationInfoService.UpdateData(locationInfo);
 
                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), "", task.TaskNum);
 
                _unitOfWorkManage.CommitTran();
 
                TaskModel esstask = new TaskModel()
                {
                    taskType = "carry",
                    taskGroupCode = "",
                    groupPriority = 0,
                    tasks = new List<TasksType>
                    {
                            new()
                            {
                                taskCode=task.TaskNum.ToString(),
                                taskPriority=0,
                                taskDescribe=new TaskDescribeType{
                                containerCode=stockInfo.PalletCode,
                                containerType= "CT_KUBOT_STANDARD",
                                fromLocationCode=stockInfo.LocationCode??"",
                                toStationCode="",
                                toLocationCode=endStation,
                                deadline=0,storageTag=""
                                }
                            }
                    }
                };
                _logger.LogInformation("创建任务PalletOutboundTask Request:  " + JsonConvert.SerializeObject(esstask));
                var result = await _eSSApiService.CreateTaskAsync(esstask);
 
                _logger.LogInformation("创建任务PalletOutboundTask 返回:  " + result);
                if (result)
                {
                    return WebResponseContent.Instance.OK();
                }
                else
                {
                    return WebResponseContent.Instance.Error("下发机器人任务失败!");
                }
 
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
    }
}