wanshenmean
2026-02-09 ae9517420d848e215a9eb807270d5ef6fbe92ae9
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
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEA_TaskInfoService
 * 创建者:胡童庆
 * 创建时间:2024/8/2 16:13:36
 * 版本:V1.0.0
 * 描述:
 *
 * ----------------------------------------------------------------
 * 修改人:
 * 修改时间:
 * 版本:V1.0.1
 * 修改说明:
 * 
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
 
using AutoMapper;
using SqlSugar;
using WIDESEA_Common.TaskEnum;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
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;
 
        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="palletCode">托盘号</param>
        /// <param name="sourceAddress">起始地址</param>
        /// <param name="targetAddress">目标地址</param>
        /// <param name="roadway">巷道号</param>
        /// <param name="warehouseId">仓库主键</param>
        /// <param name="palletType">托盘类型</param>
        /// <param name="taskType">任务类型</param>
        /// <returns>是否成功</returns>
        public async Task<Dt_Task?> CreateTaskInboundAsync(CreateTaskDto taskDto)
        {
            if (string.IsNullOrWhiteSpace(taskDto.PalletCode) || string.IsNullOrWhiteSpace(taskDto.SourceAddress) || string.IsNullOrWhiteSpace(taskDto.TargetAddress) || string.IsNullOrWhiteSpace(taskDto.Roadway))
            {
                return null;
            }
 
            if (taskDto.TaskType != TaskTypeEnum.Inbound || taskDto.TaskType != TaskTypeEnum.InEmpty)
            {
                return null;
            }
 
            var task = new Dt_Task
            {
                TaskNum = 0,
                PalletCode = taskDto.PalletCode,
                PalletType = taskDto.PalletType,
                Roadway = taskDto.Roadway,
                TaskType = taskDto.TaskType.GetHashCode(),
                TaskStatus = TaskStatusEnum.New.GetHashCode(),
                SourceAddress = taskDto.SourceAddress,
                TargetAddress = taskDto.TargetAddress,
                CurrentAddress = taskDto.SourceAddress,
                NextAddress = taskDto.TargetAddress,
                WarehouseId = taskDto.WarehouseId,
                Grade = 1,
                Creater = "system"
            };
 
            return await Repository.AddDataAsync(task) > 0 ? task : null;
        }
 
    }
}