heshaofeng
2026-01-30 fe410d91f907e15797e82726b8449958494de0cf
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
using SqlSugar.Extensions;
using WIDESEA_Common.StockEnum;
using WIDESEA_Core;
using WIDESEA_DTO.CalcOut;
using WIDESEA_Model.Models;
 
namespace WIDESEA_OutboundService
{
    public partial class OutboundService
    {
        public WebResponseContent GetOrderInfo(string orderNo)
        {
            try
            {
                Dt_OutboundOrder outboundOrder = _outboundRepository.Db.Queryable<Dt_OutboundOrder>().First(x => x.OrderNo == orderNo);
                return WebResponseContent.Instance.OK(data: outboundOrder);
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        //public WebResponseContent QueryPickingTasks(string palletCode, string orderNo)
        //{
        //    try
        //    {
        //        Dt_StockInfo stockInfo = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First();
 
        //        var outboundOrder = _outboundRepository.QueryFirst(x => x.OrderNo == orderNo);
 
        //        bool isMatMixed = false;
        //        if (stockInfo != null)
        //        {
        //            isMatMixed = stockInfo.Details.GroupBy(x => new
        //            {
        //                x.MaterielCode,
        //                x.MaterielName,
        //                x.BatchNo,
        //                x.SupplyCode,
        //                x.WarehouseCode
        //            }).Count() > 1;
        //        }
 
 
        //        List<Dt_OutStockLockInfo> outStockLockInfos = _outboundLockInfoRepository.QueryData(x => x.PalletCode == palletCode && x.OrderNo == orderNo);
        //        return WebResponseContent.Instance.OK(data: new { outStockLockInfos, stockInfo, isMatMixed });
        //    }
        //    catch (Exception ex)
        //    {
        //        return WebResponseContent.Instance.Error(ex.Message);
        //    }
        //}
 
        public WebResponseContent QueryPickingTasks(string palletCode, string orderNo)
        {
            try
            {
                Dt_StockInfo stockInfo = _stockInfoRepository.Db.Queryable<Dt_StockInfo>()
                    .Where(x => x.PalletCode == palletCode)
                    .Includes(x => x.Details)
                    .First();
 
                List<Dt_OutStockLockInfo> outStockLockInfos = _outboundLockInfoRepository
                    .QueryData(x => x.PalletCode == palletCode && x.OrderNo == orderNo);
 
                bool isMatMixed = false;
                bool orderOver = false;
                decimal sumQty = 0;
                if (stockInfo != null && stockInfo.Details != null && stockInfo.Details.Any())
                {
                    if (outStockLockInfos.FirstOrDefault() != null)
                    {
                        bool includeBatchNo = !string.IsNullOrEmpty(outStockLockInfos.FirstOrDefault().BatchNo);
                        bool includeSupplyCode = !string.IsNullOrEmpty(outStockLockInfos.FirstOrDefault().SupplyCode);
                        var orderId = outStockLockInfos.FirstOrDefault().OrderDetailIds.Split(",");
                        foreach (var item in orderId)
                        {
                            Dt_OutboundOrderDetail outboundOrderDetail = _outboundRepository.Db.Queryable<Dt_OutboundOrderDetail>().Where(x=>x.Id == item.ObjToInt()).First();
                            if(outboundOrderDetail == null)
                            {
                                return WebResponseContent.Instance.Error("该托盘的出库明细未找到");
                            }
                            sumQty += (outboundOrderDetail.OrderQuantity - outboundOrderDetail.OverOutQuantity - outboundOrderDetail.MoveQty);
                        }
                        if(sumQty < outStockLockInfos.FirstOrDefault().AssignQuantity)
                        {
                            orderOver = true;
                        }
                        if (includeBatchNo && includeSupplyCode)
                        {
                            isMatMixed = stockInfo.Details.GroupBy(x => new
                            {
                                x.MaterielCode,
                                x.MaterielName,
                                x.BatchNo,
                                x.SupplyCode,
                                x.WarehouseCode
                            }).Count() > 1;
                        }
                        else if (includeBatchNo && !includeSupplyCode)
                        {
                            isMatMixed = stockInfo.Details.GroupBy(x => new
                            {
                                x.MaterielCode,
                                x.MaterielName,
                                x.BatchNo,
                                x.WarehouseCode
                            }).Count() > 1;
                        }
                        else if (!includeBatchNo && includeSupplyCode)
                        {
                            isMatMixed = stockInfo.Details.GroupBy(x => new
                            {
                                x.MaterielCode,
                                x.MaterielName,
                                x.SupplyCode,
                                x.WarehouseCode
                            }).Count() > 1;
                        }
                        else
                        {
                            isMatMixed = stockInfo.Details.GroupBy(x => new
                            {
                                x.MaterielCode,
                                x.MaterielName,
                                x.WarehouseCode
                            }).Count() > 1;
                        }
                    }
                    else
                    {
                        isMatMixed = stockInfo.Details.GroupBy(x => new
                        {
                            x.MaterielCode,
                            x.MaterielName,
                            x.WarehouseCode
                        }).Count() > 1;
 
                        Dt_OutStockLockInfo outStockLockInfo = _outboundLockInfoRepository.QueryFirst(x=>x.PalletCode == palletCode);
 
                        if (outStockLockInfo != null)
                        {
                            return WebResponseContent.Instance.Error($"该托盘在该单据中无拣选记录,请前往{outStockLockInfo.OrderNo}单据中进行拣货操作");
                        }
                    }
                }
 
                return WebResponseContent.Instance.OK(data: new { outStockLockInfos, stockInfo, isMatMixed, orderOver });
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        /// <summary>
        /// 查询已拣选列表(通过库存变动记录)
        /// </summary>
        /// <param name="request">查询请求</param>
        /// <returns>已拣选列表</returns>
        public WebResponseContent QueryPickedList(string orderNo, string palletCode)
        {
            WebResponseContent content = WebResponseContent.Instance;
 
            try
            {
                // 构建查询条件
                var query = _stockChangeRepository.Db
                    .Queryable<Dt_StockQuantityChangeRecord>()
                    .LeftJoin<Dt_OutboundOrder>((r, o) => r.OrderNo == o.OrderNo)
                    .Where((r, o) => r.ChangeType == (int)StockChangeTypeEnum.Outbound)
                    .Where((r, o) => r.OrderNo == orderNo)
                    .Where((r, o) => r.PalleCode == palletCode)
                    .OrderBy((r, o) => r.CreateDate, OrderByType.Desc)
                    .Select((r, o) => new PickedListItemDTO
                    {
                        Id = r.Id,
                        OrderNo = r.OrderNo,
                        TaskNum = r.TaskNum,
                        PalletCode = r.PalleCode,
                        MaterielCode = r.MaterielCode,
                        MaterielName = r.MaterielName,
                        BatchNo = r.BatchNo,
                        OriginalBarcode = r.OriginalSerilNumber,
                        NewBarcode = r.NewSerilNumber,
                        ChangeQuantity = r.ChangeQuantity,
                        BeforeQuantity = r.BeforeQuantity,
                        AfterQuantity = r.AfterQuantity,
                        SupplyCode = r.SupplyCode,
                        WarehouseCode = r.WarehouseCode,
                        Remark = r.Remark,
                        CreateDate = r.CreateDate,
                        OrderStatus = o.OrderStatus,
                        FactoryArea = o.FactoryArea
                    });
 
                var result = query.ToList();
 
                return WebResponseContent.Instance.OK(data: result);
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error($"查询已拣选列表失败:{ex.Message}");
            }
        }
    }
}