Admin
2026-01-14 81117ff938bfebc06801017d26176a9ffa4d0731
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
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEA_TaskInfoService
 * 创建者:胡童庆
 * 创建时间:2024/8/2 16:13:36
 * 版本:V1.0.0
 * 描述:
 *
 * ----------------------------------------------------------------
 * 修改人:
 * 修改时间:
 * 版本:V1.0.1
 * 修改说明:
 * 
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
 
using AutoMapper;
using SqlSugar;
using System.Reflection;
using WIDESEA_Common.TaskEnum;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.Task;
using WIDESEA_IBasicService;
using WIDESEA_IInboundService;
using WIDESEA_IOutboundService;
using WIDESEA_IRecordService;
using WIDESEA_IStockService;
using WIDESEA_ITaskInfoService;
using WIDESEA_Model.Models;
 
namespace WIDESEA_TaskInfoService
{
    public partial class TaskService : ServiceBase<Dt_Task, IRepository<Dt_Task>>, ITaskService
    {
        private readonly IMapper _mapper;
        private readonly IUnitOfWorkManage _unitOfWorkManage;
        private readonly IStockInfoService _stockInfoService;
        private readonly ILocationInfoService _locationInfoService;
        private readonly IWarehouseService _warehouseService;
        private readonly IRoadWayinfoService _roadWayinfoService;
 
        public IRepository<Dt_Task> Repository => BaseDal;
 
        private Dictionary<string, OrderByType> _taskOrderBy = new()
            {
                {nameof(Dt_Task.Grade),OrderByType.Desc },
                {nameof(Dt_Task.CreateDate),OrderByType.Asc},
            };
 
        public List<int> TaskTypes => typeof(TaskTypeEnum).GetEnumIndexList();
 
        public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList();
 
        public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal)
        {
            _mapper = mapper;
            _unitOfWorkManage = unitOfWorkManage;
        }
 
 
        /// <summary>
        /// 任务完成接口
        /// </summary>
        /// <param name="wCSTask"></param>
        /// <returns></returns>
        public WebResponseContent TaskCompleted(WCSTaskDTO wCSTask)
        {
            try
            {
                Dt_Task task = BaseDal.QueryFirst(x => x.TaskId == wCSTask.TaskNum && x.PalletCode == wCSTask.PalletCode);
                if (task == null)
                    return WebResponseContent.Instance.Error("未找到任务信息");
 
                switch ((TaskTypeEnum)task.TaskType)
                {
                    case TaskTypeEnum.Inbound:
                        return HandleInboundTask(task, wCSTask.TaskType);
                    case TaskTypeEnum.Outbound:
                        return HandleOutboundTask(task, wCSTask.TaskType);
                    case TaskTypeEnum.Relocation:
                        return HandleRelocationTask(task, wCSTask.TaskType);
                    default:
                        return WebResponseContent.Instance.Error($"任务类型错误,任务号:{task.TaskId},托盘编号:{task.PalletCode},类型:{task.TaskType}");
                }
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error($"WMS任务完成错误:{ex.Message}");
            }
        }
 
        private WebResponseContent HandleInboundTask(Dt_Task task, int wcsTaskType)
        {
            switch (wcsTaskType)
            {
                case 1:
                    task.TaskStatus = (int)InTaskStatusEnum.PLC_InFinish;
                    BaseDal.UpdateData(task);
                    return WebResponseContent.Instance.OK($"已接收入库输送线完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                case 2:
                    task.TaskStatus = (int)InTaskStatusEnum.SC_OutFinish;
                    BaseDal.UpdateData(task);
                    return WebResponseContent.Instance.OK($"已接收入库堆垛机完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                default:
                    return WebResponseContent.Instance.Error($"WCS上报类型错误:{wcsTaskType}");
            }
        }
 
        private WebResponseContent HandleOutboundTask(Dt_Task task, int wcsTaskType)
        {
            switch (wcsTaskType)
            {
                case 1:
                    task.TaskStatus = (int)OutTaskStatusEnum.PLC_OutFinish;
                    BaseDal.UpdateData(task);
                    return WebResponseContent.Instance.OK($"已接收出库输送线完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                case 2:
                    task.TaskStatus = (int)OutTaskStatusEnum.SC_OutFinish;
                    BaseDal.UpdateData(task);
                    return WebResponseContent.Instance.OK($"已接收出库堆垛机完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                default:
                    return WebResponseContent.Instance.Error($"WCS上报类型错误:{wcsTaskType}");
            }
        }
 
        private WebResponseContent HandleRelocationTask(Dt_Task task, int wcsTaskType)
        {
            if (wcsTaskType == 2)
            {
                task.TaskStatus = (int)RelocationTaskStatusEnum.RelocationFinish;
                BaseDal.UpdateData(task);
                return WebResponseContent.Instance.OK($"已接收移库堆垛机完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
            }
            return WebResponseContent.Instance.Error($"WCS上报类型错误:{wcsTaskType}");
        }
    }
}