服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-12-19 eb0ad83719de660e5c4f7676aea4710625b6bd51
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
using Rhea.Common;
using Microsoft.AspNetCore.Http;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tiger.Model;
using Tiger.IBusiness;
 
namespace Tiger.Business.WMS.Transaction
{
    /// <summary>
    /// 客供料入库清点事务
    /// </summary>
    public class OutNoBillcode : WMSTransactionBase, IOutNoBillcode
    {
        public IOutNoBillcode Init(string id, string userCode, string apiHost, string orgCode)
        {
            TransID = id;
            UserCode = userCode;
            ApiHost = apiHost;
            OrgCode = orgCode;
            Result ruleResult = Cache.CodeRule["NB001"].Generate("NB");  //iWMS.GetBillNoByType("CI");
            if (!ruleResult.IsSuccessed)
            {
                throw new Exception(ruleResult.ExceptionMsg.Message);
            }
            BillCode = ruleResult.Data.ToString();
            NoBillcodeHeader = new()
            {
                CREATE_TIME = DateTime.Now,
                CREATE_USER = userCode,
                UPDATE_USER = userCode,
                BILLCODE = BillCode,
                AUTH_ORG = orgCode,
                STATUS = BIZ_ERP_OTH_OUT.STATUSs.WORKING.GetValue()
            };
            Logger.Console.Info($"Start {this.GetType().Name} Transaction[ID: {TransID}]");
            return this;
        }
 
        #region Propertys & Variables
        public string UserCode { get; set; }
        public long UserId { get; set; }
        public string RackCode { get; set; }
        public string WarehouseCode { get; set; }
        public string WarehouseName { get; set; }
        /// <summary>
        /// 单据代码
        /// </summary>
        public string BillCode { get; set; }
        public Inventory CurInv { get; set; }
        public BIZ_ERP_OTH_OUT NoBillcodeHeader { get; set; }
        public List<BIZ_ERP_OTH_OUT_DTL> NoBillcodeDtl { get; set; }//单据明细
        //public List<BIZ_ERP_OTH_OUT_SN> NoBillcodeSN { get; set; }//单据扫描的条码进行保存
        public string OrgCode { get; set; }
        public WMS_SHELF Shelf { get; set; }
 
        public Model.Minsun.CustomerSupplyPuton CustomerSupplyPuton { get; set; }
        #endregion
 
        #region Functions
        /// <summary>
        /// 扫描物料并复核,如果物料已经完成移库则货架上亮灯提醒储位
        /// </summary>
        public async Task<ApiAction<DefaultScanItemOutput>> ScanItem(BaseInput input)
        {
            var action = new ApiAction<DefaultScanItemOutput>();
            try
            {
                if (input.SN.IsNullOrEmpty())
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L("条码不能为空");
                    return action;
                }
 
                //解析条码
                Result<IInventory> result = WMS_ITEM_Biz.WmsItem.Get(input.SN, input.AuthOption, true);
                if (!result.IsSuccessed)
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = result.LocaleMsg;
                    return action;
                }
                CurInv = result.Data as Inventory;
 
                //验证条码是否正确
                if (!CurInv.isNormalStatus || CurInv.Status != WMS_ITEM.STATUSs.InStore)
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L("WMS.ProdMReq.ScanItem.StatusException", string.Join(',', CurInv.StatusList.Select(x => x.GetDesc())));
                    return action;
                }
                //储位验证
                if (CurInv.Location.IsNullOrEmpty())
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L("WMS.ProdMReq.ScanItem.LocationIsNull", CurInv.CurPkg.SN, CurInv.CurPkg.LOCATION_ID);
                    return action;
                }
                //物料验证
                if (CurInv.ItemInfo.IsNullOrEmpty() || CurInv.ItemInfo.IS_ACTIVE == "N")
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L("WMS.ProdMReq.ScanItem.ItemCodeNotExistsOrNotActive", CurInv.ItemInfo.ITEM_CODE.IsNullOrEmpty(CurInv.Barcode.ItemCode));
                    return action;
                }
                //创建单据
                NoBillcodeHeader.STATUS = BIZ_ERP_OTH_OUT.STATUSs.COMPLETE.GetValue();//扫完单据就为完成
                BIZ_ERP_OTH_OUT_SN NoBillcodeSn = new()
                {
                    CREATE_USER = input.AuthOption.UserId,
                    CREATE_TIME = DateTime.Now,
                    AUTH_ORG = input.AuthOption.OrgCode,
                    ORDER_NO = BillCode,
                    SN = CurInv.SN,
                    META_SN = CurInv.Barcode.MetaSn,
                    ITEM_CODE = CurInv.ItemInfo.ITEM_CODE,
                    STATUS = WMS_ITEM.STATUSs.OffShelf.GetValue(),
                    LOCATION_CODE=CurInv.Location.LOCATION_CODE,
                    ERP_WH=CurInv.Warehouse.WH_CODE,
                    ALLOC_QTY=CurInv.CurPkg.QTY,
                    LOAD_SEQ=0,
                    NEED_CUTTING="N"
                };
                NoBillcodeDtl = new List<BIZ_ERP_OTH_OUT_DTL>();
                //首次直接新增数据
                if (NoBillcodeDtl.Count > 0)
                {
                   //查询这个料号是否存在明细,存在就修改数量,不存在添加一条新数据
                   var noBillcode = NoBillcodeDtl.Where(q => q.ITEM_CODE == CurInv.ItemInfo.ITEM_CODE).FirstOrDefault();
                   if (noBillcode.IsNullOrEmpty()) 
                   {
                        BIZ_ERP_OTH_OUT_DTL dtl = new()
                        {
                            CREATE_USER = input.AuthOption.UserId,
                            CREATE_TIME = DateTime.Now,
                            AUTH_ORG = input.AuthOption.OrgCode,
                            BILLCODE = BillCode,
                            BILLLINE=(int.Parse(NoBillcodeDtl.Max(q => q.BILLLINE))+1).ToString(),
                            LINESTATUS=BIZ_ERP_OTH_OUT.STATUSs.COMPLETE.GetValue(),
                            ITEM_CODE=CurInv.ItemInfo.ITEM_CODE,
                            UNITCODE=CurInv.CurPkg.UNIT,
                            PRQTY=CurInv.CurPkg.QTY,
                            QTY=CurInv.CurPkg.QTY,
                            WAREHOUSECODE=CurInv.Warehouse.WH_CODE
                        };
                        NoBillcodeDtl.Add(dtl);
                   }
                   else
                   {
                        noBillcode.QTY += CurInv.CurPkg.QTY;
                   }
                }
                else
                {
                    BIZ_ERP_OTH_OUT_DTL dtl = new() 
                    {
                        CREATE_USER = input.AuthOption.UserId,
                        CREATE_TIME = DateTime.Now,
                        AUTH_ORG = input.AuthOption.OrgCode,
                        BILLCODE = BillCode,
                        BILLLINE = "1",
                        LINESTATUS = BIZ_ERP_OTH_OUT.STATUSs.COMPLETE.GetValue(),
                        ITEM_CODE = CurInv.ItemInfo.ITEM_CODE,
                        UNITCODE = CurInv.CurPkg.UNIT,
                        PRQTY = CurInv.CurPkg.QTY,
                        QTY = CurInv.CurPkg.QTY,
                        WAREHOUSECODE = CurInv.Warehouse.WH_CODE
                    };
                    NoBillcodeDtl.Add(dtl);
                }
                //处理库存和包装
                CurInv.CurPkg.REGION_ID = "";
                CurInv.CurPkg.SHELF_ID = "";
                CurInv.CurPkg.LOCATION_ID = "";
                CurInv.Items[0].REGION_ID = "";
                CurInv.Items[0].SHELF_ID = "";
                CurInv.Items[0].LOCATION_ID = "";
                CurInv.Items[0].TRANS_CODE = "No Billcode Out";
                CurInv.Items[0].TRANS_NO = BillCode;
                CurInv.Items[0].STATUS = WMS_ITEM.STATUSs.OffShelf.GetValue();
                WMS_ITEM_HIS his = new WMS_ITEM_HIS(CurInv.Items[0], $"无工单出库");
 
                CurInv.History.Add(his);
                //灭灯
                if (CurInv.Shelf.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.Smart.GetValue() || CurInv.Shelf.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.QRCode.GetValue())
                {
                    await Share.Shelf.DownSingle(TransID, CurInv.Location);
                }
                action.Message = "无工单出库成功";
                //保存数据库
                var db = Business.Biz.Db;
                var dbTran = db.UseTran(() =>
                {
                    //出库
                   
                    db.Updateable(CurInv.Items, UserCode).ExecuteCommand();
                    db.Updateable(CurInv.CurPkg, UserCode).ExecuteCommand();
                    db.Insertable(CurInv.History, UserCode).ExecuteCommand();
 
                    db.Insertable(NoBillcodeHeader, UserCode).ExecuteCommand();
                    db.Insertable(NoBillcodeDtl, UserCode).ExecuteCommand();
                    db.Insertable(NoBillcodeSn, UserCode).ExecuteCommand();
 
 
                });
                if (!dbTran.IsSuccess)
                {
                    throw dbTran.ErrorException;
                }
 
                action.Data = new DefaultScanItemOutput()
                {
                    SN = CurInv.SN,
                    ItemCode = CurInv.ItemInfo.ITEM_CODE,
                    MaterialName=CurInv.ItemInfo.ITEM_NAME,
                    Qty = CurInv.CurPkg.QTY,
                    //CutQty = CurInv.CurPkg.QTY - cutQty,
                    //isCutting = _isCutting,
                    //isExceed = _isExceed,
                    ReqNo = BillCode,
                    Unit=CurInv.CurPkg.UNIT,
                    regionCode = CurInv.Region.REGION_CODE,
                    locationCode = CurInv.Location?.LOCATION_CODE,
                    DateCode = CurInv.Items[0].PROD_DATE,
                    ScanAfCut = CurInv.Warehouse.SCAN_AF_CUT
                };
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"扫描物料[{input.SN}]复核异常");
            }
            return action;
        }
 
        /// <summary>
        /// 扫描货架或者储位
        /// </summary>
        public async Task<ApiAction<Model.Minsun.CustomerSupplyPuton>> ScanShelf(string Code)
        {
            var action = new ApiAction<Model.Minsun.CustomerSupplyPuton>();
            try
            {
                if (Code.IsNullOrEmpty())
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.ShelfCanNotEmpty");
                    return action;
                }
 
                CustomerSupplyPuton = new Model.Minsun.CustomerSupplyPuton();
 
                // 查询货架信息
                var whUnit = await Biz.Db.Queryable<V_WH_UNIT>().Where(t => t.SHELF_CODE.ToUpper() == Code.ToUpper() && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync();
 
                // 扫描货架代码,且为智能货架
                if (whUnit != null && whUnit.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.Smart.GetValue())
                {
                    WarehouseName = whUnit.WH_NAME;
                    CustomerSupplyPuton.WarehouseCode = whUnit.WH_CODE;
                    CustomerSupplyPuton.RackCode = whUnit.SHELF_CODE;
                    CustomerSupplyPuton.ShelfType = whUnit.SHELF_TYPE;
                    CustomerSupplyPuton.IsSmartRack = true;
                    Shelf = whUnit.Shelf;
                }
                // 扫描库位代码
                else
                {
                    var nLocation = await Biz.Db.Queryable<V_WH_UNIT>().Where(t => t.LOCATION_CODE.ToUpper() == Code.ToUpper() && t.AUTH_ORG == OrgCode).FirstAsync();
                    WarehouseName = nLocation.WH_NAME;
                    if (nLocation == null)
                    {
                        action.IsSuccessed = false;
                        action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.NotExist", Code);
                        return action;
                    }
 
                    if (nLocation.IS_ACTIVE == "N")
                    {
                        action.IsSuccessed = false;
                        action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.ShelfOrLocationDisabled");
                        return action;
                    }
                    if (nLocation.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.Smart.GetValue() || nLocation.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.QRCode.GetValue())
                    {
                        var locationData = Biz.Db.Queryable<WMS_ITEM>().Where(q => q.LOCATION_ID == nLocation.LOCATION_ID && q.AUTH_ORG == OrgCode).First();
                        if (!locationData.IsNullOrEmpty())
                        {
                            action.IsSuccessed = false;
                            action.LocaleMsg = Biz.L($"系统当前库位存在料盘,请检查系统库存信息");
                            return action;
 
                        }
                    }
 
                    CustomerSupplyPuton.LocationCode = nLocation.LOCATION_CODE;
                    CustomerSupplyPuton.WarehouseCode = nLocation.WH_CODE;
                    //CustomerSupplyPuton.Capacity = nLocation.MAXSIZE - nUsedCapacity;
                    //CustomerSupplyPuton.LotCount = nLocation.LOTCOUNT;
                    //CustomerSupplyPuton.MaxSize = nLocation.MAXSIZE;
                    CustomerSupplyPuton.IsSmartRack = false;
                    CustomerSupplyPuton.RackCode = nLocation.SHELF_CODE;
                }
 
                WarehouseCode = CustomerSupplyPuton.WarehouseCode;
                RackCode = CustomerSupplyPuton.RackCode;
                CustomerSupplyPuton.IsScanShelf = true;
                action.LocaleMsg = Biz.L("扫描货架或储位成功");
                action.Data = CustomerSupplyPuton;
            }
            catch (Exception ex)
            {
                //取消当前操作
 
                action.CatchExceptionWithLog(ex, $"扫描货架或者储位[{Code}]异常");
            }
            return action;
        }
 
        #endregion
 
        public override bool Close(bool needSaveHistoryLog = false)
        {
            this.IsFinished = true;
            return IsFinished ? base.Close(needSaveHistoryLog) : IsFinished;
        }
 
    }//endClass
}