wxw
2025-05-12 c7c2f7aa20427204944ba80a2704232b2f281582
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Model.ModelDto.BllSoDto;
using SqlSugar;
using WMS.BLL.LogServer;
using WMS.DAL;
using WMS.Entity.BllSoEntity;
using WMS.Entity.Context;
using WMS.Entity.DataEntity;
using WMS.Entity.SysEntity;
using WMS.IBLL.IBllSoServer;
namespace WMS.BLL.BllSoServer
{
    public class ExportAllotServer : DbHelper<BllExportAllot>, IExportAllotServer
    {
        private static readonly SqlSugarScope Db = DataContext.Db;
 
        public ExportAllotServer() : base(Db)
        {
        }
 
        //查询出库分配表信息
        public List<ExportAllotDto> GetExportAllotList(string no, string waveNo, string palletNo, string skuNo, string skuName, string lotNo, string status, string boxNo, int page, int limit, out int count)
        {
            try
            {
                var strList = new List<int>();
 
                if (!string.IsNullOrWhiteSpace(boxNo))
                {
                    var detailList = Db.Queryable<BllCompleteDetail>().Where(m => m.IsDel == "0" && m.BoxNo.Contains(boxNo.Trim())).Select(m => m.ExportAllotId).Distinct().ToList();
                    strList = detailList;
                }
                Expression<Func<BllExportAllot, bool>> item = Expressionable.Create<BllExportAllot>()
                    .AndIF(!string.IsNullOrWhiteSpace(no), it => it.SONo.Contains(no.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(waveNo), it => it.WaveNo.Contains(waveNo.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(palletNo), it => it.PalletNo.Contains(palletNo.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(skuNo), it => it.SkuNo.Contains(skuNo.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(skuName), it => it.SkuName.Contains(skuName.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(lotNo), it => it.LotNo.Contains(lotNo.Trim()))
                    .AndIF(!string.IsNullOrWhiteSpace(status), it => it.Status == status)
                    .AndIF(!string.IsNullOrWhiteSpace(boxNo), m => strList.Contains(m.Id))
                    .ToExpression();//注意 这一句 不能少
                var total = 0;
                var data = GetAllWhereAsync(item)
                    .LeftJoin<SysLogisticsInfo>((a, b) => a.LogisticsId == b.Id)
                    .LeftJoin<SysUserInfor>((a, b, c) => a.CreateUser == c.Id)
                    .LeftJoin<SysUserInfor>((a, b, c, d) => a.CreateUser == d.Id)
                    .Select((a, b, c, d) => new ExportAllotDto()
                    {
                        Id = a.Id,
                        SONo = a.SONo,
                        WaveNo = a.WaveNo,
                        SODetailNo = a.SODetailNo,
                        StockId = a.StockId,
                        TaskNo = a.TaskNo,
 
                        LotNo = a.LotNo,
                        LotText = a.LotText,
                        SupplierLot = a.SupplierLot,
                        SkuNo = a.SkuNo,
                        SkuName = a.SkuName,
                        Standard = a.Standard,
                        PalletNo = a.PalletNo,
                        IsBale = a.IsBale,
                        IsBelt = a.IsBelt,
                        Qty = a.Qty,
                        CompleteQty = a.CompleteQty,
                        Status = a.Status,
                        LogisticsId = a.LogisticsId,
                        LogisticsName = b.CarrierName,
                        IsAdvance = a.IsAdvance,
                        OutMode = a.OutMode,
 
                        CreateUserName = c.RealName,
                        UpdateUserName = d.RealName,
                        CreateTime = a.CreateTime,
                        UpdateTime = a.UpdateTime
                    })
                    .OrderByDescending(a => a.CreateTime)
                    .ToOffsetPage(page, limit, ref total);
                count = total;
                return data;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        //撤销分配(删除)
        public void DelExportAllot(int id, int userId)
        {
            try
            {
                var allot = GetOneById(id);
                int a = 0;
                if (allot == null)
                {
                    throw new Exception("未查询到要撤销的分配信息");
                }
                if (allot.Status != "0")
                {
                    throw new Exception("要撤销的分配信息状态不是待下发,不能撤销");
                }
                //出库单
                var notice = new BllExportNotice();
                //出库单明细
                var noticeDe = new BllExportNoticeDetail();
                //库存明细
                var stockDe = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.Id == allot.StockId);
                //获取库存总表
                var stock = Db.Queryable<DataStock>().First(s => s.IsDel == "0" && s.SkuNo == allot.SkuNo && s.LotNo == stockDe.LotNo);
                //获取储位消息
                var locat = Db.Queryable<SysStorageLocat>().First(l => l.IsDel == "0" && l.Status != "0" && l.LocatNo == stockDe.LocatNo);
                if (allot.SkuNo != "100099" && allot.SkuNo != "100098" && allot.SkuNo != "100097")
                {
                    a = 1;
                    notice = Db.Queryable<BllExportNotice>().First(m => m.IsDel == "0" && m.SONo == allot.SONo);
                    noticeDe = Db.Queryable<BllExportNoticeDetail>().First(m => m.IsDel == "0" && m.Id == allot.SODetailNo);
 
                    if (notice == null)
                    {
                        throw new Exception("未查询到出库单信息");
                    }
                    if (noticeDe == null)
                    {
                        throw new Exception("未查询到出库单明细信息");
                    }
                }
                if (stockDe == null)
                {
                    throw new Exception("未查询到要分配的库存明细信息");
                }
                Db.BeginTran();
                var time = DateTime.Now;
                //删除出库分配信息
                allot.IsDel = "1";
                allot.UpdateTime = time;
                allot.UpdateUser = userId;
                if (a == 1)
                {
                    //修改出库单明细
                    noticeDe.AllotQty -= allot.Qty;
                    noticeDe.UpdateTime = time;
                    noticeDe.UpdateUser = userId;
 
                    if (notice.Status == "2")
                    {
                        notice.Status = "1";
                    }
                    if (noticeDe.AllotQty == 0)
                    {
                        noticeDe.Status = "0";
                        var count = Db.Queryable<BllExportNoticeDetail>().Count(m =>
                            m.IsDel == "0" && m.Id != noticeDe.Id && m.SONo == allot.SONo && m.Status != "0");
                        if (count == 0)
                        {
                            notice.Status = "0";
                        }
                    }
                }
                //修改库存明细
                stockDe.LockQty -= allot.Qty;
                if (stockDe.LockQty == 0)
                {
                    stockDe.Status = "0";
                }
                else if (stockDe.Status == "2")
                {
                    stockDe.Status = "1";
                }
 
                if (a == 1)
                {
                    Db.Updateable(notice).ExecuteCommand();
                    Db.Updateable(noticeDe).ExecuteCommand();
                }
 
                //修改储位信息
                locat.Status = "1";
                //修改库存总量
                stock.LockQty -= allot.Qty;
 
                Db.Updateable(allot).ExecuteCommand();
                Db.Updateable(stock).ExecuteCommand();
                Db.Updateable(stockDe).ExecuteCommand();
                Db.Updateable(locat).ExecuteCommand();
 
                //添加操作日志记录
                var k = new OperationSOServer().AddLogOperationSo("出库作业", "拣货明细", notice.SONo, "删除", $"撤销了单据号为{notice.SONo}、托盘码为:{allot.PalletNo}的单据分配信息", userId);
                Db.CommitTran();
 
            }
            catch (Exception e)
            {
                Db.RollbackTran();
                throw new Exception(e.Message);
            }
        }
    }
}