1
wankeda
2026-01-09 58a1b8b7db72225e0c2acca4f76399899f1bda4f
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_Model.Models;
 
namespace WIDESEA_TaskInfoService
{
    public partial class TaskService
    {
        public WebResponseContent WMSGenerateNewOutboundTask(int[] keys)
        {
            try
            {
                List<Dt_Task> tasks = new List<Dt_Task>();
                List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
                List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
 
                List<Dt_NewOutboundOrderDetail> outboundOrderDetails = _outboundService.NewOutboundOrderDetailService.Repository.QueryData(x => keys.Contains(x.Id));
                if (outboundOrderDetails == null || outboundOrderDetails.Count == 0)
                {
                    throw new Exception("未找到出库单明细信息");
                }
                if (outboundOrderDetails.FirstOrDefault(x => x.OrderDetailStatus > OrderDetailStatusEnum.New.ObjToInt() && x.OrderDetailStatus != OrderDetailStatusEnum.AssignOverPartial.ObjToInt()) != null)
                {
                    throw new Exception("所选出库单明细存在出库中或已完成");
                }
                List<Dt_NewOutboundOrder> outboundOrders = _outboundService.NewOutboundOrderService.Repository.QueryData(x => x.Id == outboundOrderDetails.FirstOrDefault().OrderId);
                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.Repository.QueryData(x => outboundOrderDetails.Select(s => s.LPNNo).Contains(x.PalletCode));
                if (outboundOrderDetails == null || outboundOrderDetails.Count == 0)
                {
                    throw new Exception("未找到库存信息");
                }
                if (stockInfos == null || stockInfos.Count == 0)
                {
                    throw new Exception("未找到库存信息");
                }
                var Newtasks = GetTasks(stockInfos, TaskTypeEnum.OutProduct);
                List<Dt_StockInfoDetail> stockInfoDetails = _stockService.StockInfoDetailService.Repository.QueryData(x => stockInfos.Select(x => x.Id).Contains(x.StockId));
                foreach (var item in outboundOrderDetails)
                {
                    Dt_StockInfo? stockInfo = stockInfos.FirstOrDefault(x => x.PalletCode == item.LPNNo);
                    if (stockInfo == null) continue;
                    Dt_StockInfoDetail? stockInfoDetail = stockInfoDetails.FirstOrDefault(x => x.StockId == stockInfo.Id && x.BatchNo == item.BatchNo);
                    if (stockInfoDetail == null) continue;
                    stockInfoDetail.OutboundQuantity += item.OrderQuantity;
                    item.LockQuantity += item.OrderQuantity;
                    var outboundOrder = outboundOrders.FirstOrDefault(x => x.Id == item.OrderId);
                    Dt_OutStockLockInfo outStockLockInfo = _outboundService.OutboundStockLockInfoService.GetOutStockLockInfo(outboundOrder, item, stockInfo, stockInfoDetail, item.OrderQuantity);
                    outStockLockInfo.Status = OutStockStatus.出库中.ObjToInt();
                    item.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
                    outboundOrder.OrderStatus = OutboundStatusEnum.出库中.ObjToInt();
                    stockInfo.StockStatus = StockStatusEmun.出库锁定.ObjToInt();
                    var task = Newtasks.FirstOrDefault(x => x.PalletCode == item.LPNNo);
                    task.OrderNo = outboundOrder.OrderNo;
                    tasks.Add(task);
                    outStockLockInfo.TaskNum = task.TaskNum;
                    outStockLockInfos.Add(outStockLockInfo);
                }
                locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(stockInfos.Select(x => x.LocationCode).ToList()));
 
                _unitOfWorkManage.BeginTran();
 
                BaseDal.AddData(tasks);
                _stockService.StockInfoService.Repository.UpdateData(stockInfos);
                _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetails);
                _outboundService.NewOutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails);
                _outboundService.NewOutboundOrderService.Repository.UpdateData(outboundOrders);
                _outboundService.OutboundStockLockInfoService.Repository.AddData(outStockLockInfos);
                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfos, LocationStatusEnum.Lock.ObjToInt(), StockChangeType.Outbound.ObjToInt(), "", tasks?.Select(x => x.TaskNum).ToList());
                _basicService.LocationInfoService.Repository.UpdateLocationStatus(locationInfos, LocationStatusEnum.Lock);
 
                _unitOfWorkManage.CommitTran();
                //将任务推送到WCS
                return PushTasksWCS(tasks);
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        //合托出库
        public WebResponseContent WMSGenerateSTOutboundTask(int[] keys)
        {
            try
            {
                List<Dt_Task> tasks = new List<Dt_Task>();
                List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
                List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
 
                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.Repository.QueryData(x => keys.Contains(x.Id) && x.StockStatus == StockStatusEmun.入库完成.ObjToInt());
                if (stockInfos == null || stockInfos.Count == 0)
                {
                    throw new Exception("未找到库存信息,或库存状态不为入库完成");
                }
                var Newtasks = GetTasks(stockInfos, TaskTypeEnum.OutSyncretism);
                List<Dt_StockInfoDetail> stockInfoDetails = _stockService.StockInfoDetailService.Repository.QueryData(x => stockInfos.Select(x => x.Id).Contains(x.StockId));
                foreach (var item in stockInfos)
                {
                    Dt_StockInfo? stockInfo = stockInfos.FirstOrDefault(x => x.PalletCode == item.PalletCode);
                    if (stockInfo == null) continue;
 
                    stockInfo.StockStatus = StockStatusEmun.出库锁定.ObjToInt();
                    var task = Newtasks.FirstOrDefault(x => x.PalletCode == item.PalletCode);
                    tasks.Add(task);
                }
                locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(stockInfos.Select(x => x.LocationCode).ToList()));
 
                _unitOfWorkManage.BeginTran();
 
                BaseDal.AddData(tasks);
                _stockService.StockInfoService.Repository.UpdateData(stockInfos);
                _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetails);
                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfos, LocationStatusEnum.Lock.ObjToInt(), StockChangeType.Outbound.ObjToInt(), "", tasks?.Select(x => x.TaskNum).ToList());
                _basicService.LocationInfoService.Repository.UpdateLocationStatus(locationInfos, LocationStatusEnum.Lock);
 
                _unitOfWorkManage.CommitTran();
                //将任务推送到WCS
                return PushTasksWCS(tasks);
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
    }
}