1
hutongqing
2024-09-13 ea9bdf217e8202a5fa475262dba1792decb05bcb
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
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEA_TaskInfoService
 * 创建者:胡童庆
 * 创建时间:2024/8/2 16:13:36
 * 版本:V1.0.0
 * 描述:
 *
 * ----------------------------------------------------------------
 * 修改人:
 * 修改时间:
 * 版本:V1.0.1
 * 修改说明:
 * 
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
 
using AutoMapper;
using MailKit.Search;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Stock;
using WIDESEA_IBasicRepository;
using WIDESEA_IBasicService;
using WIDESEA_IOutboundRepository;
using WIDESEA_IOutboundService;
using WIDESEA_IRecordService;
using WIDESEA_IStockRepository;
using WIDESEA_IStockService;
using WIDESEA_ITaskInfoRepository;
using WIDESEA_ITaskInfoService;
using WIDESEA_Model.Models;
using WIDESEA_TaskInfoRepository;
 
namespace WIDESEA_TaskInfoService
{
    public partial class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService
    {
        private readonly IMapper _mapper;
        private readonly IUnitOfWorkManage _unitOfWorkManage;
        private readonly ILocationInfoService _locationInfoService;
        private readonly IStockInfoService _stockInfoService;
        private readonly ILocationStatusChangeRecordSetvice _locationStatusChangeRecordSetvice;
        private readonly IOutboundOrderDetailService _outboundOrderDetailService;
        private readonly IRoadwayInfoRepository _roadwayInfoRepository;
        private readonly IOutStockLockInfoService _outStockLockInfoService;
 
        public ITaskRepository Repository => BaseDal;
 
        public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, ILocationInfoService locationInfoService, IStockInfoRepository stockInfoRepository, ILocationStatusChangeRecordSetvice locationStatusChangeRecordSetvice, IOutboundOrderDetailService outboundOrderDetailService, IRoadwayInfoRepository roadwayInfoRepository, IOutStockLockInfoService outStockLockInfoService, IStockInfoService stockInfoService) : base(BaseDal)
        {
            _mapper = mapper;
            _locationInfoService = locationInfoService;
            _stockInfoService = stockInfoService;
            _locationStatusChangeRecordSetvice = locationStatusChangeRecordSetvice;
            _outboundOrderDetailService = outboundOrderDetailService;
            _roadwayInfoRepository = roadwayInfoRepository;
            _unitOfWorkManage = unitOfWorkManage;
            _outStockLockInfoService = outStockLockInfoService;
        }
 
        public WebResponseContent InboundTaskCompleted(Dt_Task task)
        {
            Dt_StockInfo stockInfo = _stockInfoService.Repository.GetStockInfo(task.PalletCode);
 
            Dt_LocationInfo locationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
 
            CheckInboundCompleted(stockInfo, locationInfo);
 
            stockInfo.LocationCode = locationInfo.LocationCode;
            stockInfo.StockStatus = StockStatusEmun.已入库.ObjToInt();
            _stockInfoService.Repository.UpdateData(stockInfo);
 
            int beforeStatus = locationInfo.LocationStatus;
            locationInfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt();
            _locationInfoService.Repository.UpdateData(locationInfo);
 
            BaseDal.DeleteData(task);
 
            _locationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
 
            return WebResponseContent.Instance.OK();
        }
 
        /// <summary>
        /// 验证数据
        /// </summary>
        /// <param name="stockInfo"></param>
        /// <param name="locationInfo"></param>
        /// <returns></returns>
        private (bool, string) CheckInboundCompleted(Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo, bool isCheckStockDetail = true)
        {
            if (stockInfo == null)
            {
                return (false, "未找到组盘信息");
            }
 
            if (locationInfo == null)
            {
                return (false, "未找到货位信息");
            }
 
            if (isCheckStockDetail && (stockInfo.Details == null || stockInfo.Details.Count == 0))
            {
                return (false, "未找到组盘明细信息");
            }
 
            return (true, "成功");
        }
 
        /// <summary>
        /// 任务完成
        /// </summary>
        /// <param name="taskNum">任务号</param>
        /// <returns>返回处理结果</returns>
        public WebResponseContent TaskCompleted(int taskNum)
        {
            Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
            if (task == null)
            {
                return WebResponseContent.Instance.Error("未找到任务信息");
            }
            MethodInfo? methodInfo = GetType().GetMethod(((TaskTypeEnum)task.TaskType) + "TaskCompleted");
            if (methodInfo != null)
            {
                WebResponseContent? responseContent = (WebResponseContent?)methodInfo.Invoke(this, new object[] { task });
                if (responseContent != null)
                {
                    return responseContent;
                }
            }
            return WebResponseContent.Instance.Error();
        }
 
    }
}