| | |
| | | using System.Threading.Tasks; |
| | | using Tiger.Model; |
| | | using Tiger.IBusiness; |
| | | using Org.BouncyCastle.Ocsp; |
| | | using Tiger.Model.Entitys.MES.Position; |
| | | |
| | | namespace Tiger.Business.WMS.Transaction |
| | | { |
| | | /// <summary> |
| | | /// 标准下架事务 |
| | | /// </summary> |
| | | public class Out_Default : WMSTransactionBase, IOut_Default |
| | | public class Out_Default : WmsTask, IOut_Default |
| | | { |
| | | public IOut_Default Init(string id, string userCode, string apiHost, string orgCode) |
| | | { |
| | | TransID = id; |
| | | UserCode = userCode; |
| | | ApiHost = apiHost; |
| | | OrgCode = orgCode; |
| | | |
| | | base.Init(id, userCode, apiHost, orgCode); |
| | | 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 OrgCode { get; set; } |
| | | public Inventory CurInvItem { get; set; } |
| | | public ScanShelfInfo CurScanShelf { get; set; } |
| | | public string Command { get; set; } = "Normal"; |
| | | |
| | | #endregion |
| | | |
| | | #region Functions |
| | |
| | | /// </summary> |
| | | public async Task<ApiAction<ScanOutput>> Scan(BaseInput input) |
| | | { |
| | | var action = new ApiAction<ScanOutput>(); |
| | | var action = new ApiAction<ScanOutput>(new ScanOutput()); |
| | | try |
| | | { |
| | | if (input.SN.IsNullOrEmpty()) |
| | |
| | | catch (Exception ex) |
| | | { |
| | | //取消当前操作 |
| | | ResetInfo(); |
| | | ResetScan(); |
| | | //action.CatchExceptionWithLog(ex, $"扫描[{input.SN}]异常"); |
| | | action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.Scan.ScanException", input.SN)); |
| | | } |
| | |
| | | var action = new ApiAction<ScanOutput>(new ScanOutput() { Command = Command }); |
| | | try |
| | | { |
| | | //解析条码 |
| | | Result<IInventory> result = WMS_ITEM_Biz.WmsItem.Get(input.SN, input.AuthOption, true); |
| | | if (!result.IsSuccessed) |
| | | if (CurInvItem.IsNullOrEmpty()) |
| | | { |
| | | action.IsSuccessed = false; |
| | | action.LocaleMsg = result.LocaleMsg; |
| | | return action; |
| | | } |
| | | CurInvItem = result.Data as Inventory; |
| | | //解析条码 |
| | | Result<IInventory> result = WMS_ITEM_Biz.WmsItem.Get(input.SN, input.AuthOption, true); |
| | | if (!result.IsSuccessed) |
| | | { |
| | | action.IsSuccessed = false; |
| | | action.LocaleMsg = result.LocaleMsg; |
| | | return SetOutPutMqttMsg(action, input.Locale); |
| | | } |
| | | var inv = result.Data as Inventory; |
| | | |
| | | //验证条码是否正确 |
| | | if (!CurInvItem.isNormalStatus || CurInvItem.Status != WMS_ITEM.STATUSs.InStore) |
| | | { |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = Biz.L($"状态[{0}]异常,请重新扫描"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.StatusException", string.Join(',', CurInvItem.StatusList.Select(x => x.GetDesc()))); |
| | | return action; |
| | | //验证条码是否正确 |
| | | if (!inv.isNormalStatus || inv.Status != WMS_ITEM.STATUSs.InStore) |
| | | { |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = Biz.L($"状态[{0}]异常,请重新扫描"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.StatusException", string.Join(',', inv.StatusList.Select(x => x.GetDesc()))); |
| | | return SetOutPutMqttMsg(action, input.Locale); |
| | | } |
| | | //储位验证 |
| | | if (inv.Location.IsNullOrEmpty()) |
| | | { |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = Biz.L($"条码[{0}]库存信息异常: 没有储位信息,请先上架后再扫描(储位Id: {1})"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.LocationIsNull", inv.CurPkg.SN, inv.CurPkg.LOCATION_ID); |
| | | return SetOutPutMqttMsg(action, input.Locale); |
| | | } |
| | | //物料验证 |
| | | if (inv.ItemInfo.IsNullOrEmpty() || inv.ItemInfo.IS_ACTIVE == "N") |
| | | { |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = Biz.L($"物料编码[{0}]不存在或者该物料未启用"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ItemCodeNotExistsOrNotActive", inv.ItemInfo.ITEM_CODE.IsNullOrEmpty(inv.Barcode.ItemCode)); |
| | | return SetOutPutMqttMsg(action, input.Locale); |
| | | } |
| | | CurInvItem = inv; |
| | | |
| | | //把物料数量返回前端确认要下架的数量 |
| | | if (CurInvItem.Items.Any(q => q.QTY > 1)) |
| | | { |
| | | action.Data.Data = CurInvItem.Items.Select(q => new { q.SN, q.QTY }); |
| | | action.Data.Command = Command = "ComfirmQty"; |
| | | //action.LocaleMsg = Biz.L("请确认条码[{0}]要下架的数量"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ComfirmOutQty", input.SN); |
| | | return SetOutPutMqttMsg(action, input.Locale); |
| | | } |
| | | } |
| | | //储位验证 |
| | | if (CurInvItem.Location.IsNullOrEmpty()) |
| | | |
| | | Dictionary<string, double> downDic = null; |
| | | //更新下架后的物料数量 |
| | | if (Command == "ComfirmQty") |
| | | { |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = Biz.L($"条码[{0}]库存信息异常: 没有储位信息,请先上架后再扫描(储位Id: {1})"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.LocationIsNull", CurInvItem.CurPkg.SN, CurInvItem.CurPkg.LOCATION_ID); |
| | | return action; |
| | | } |
| | | //物料验证 |
| | | if (CurInvItem.ItemInfo.IsNullOrEmpty() || CurInvItem.ItemInfo.IS_ACTIVE == "N") |
| | | { |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = Biz.L($"物料编码[{0}]不存在或者该物料未启用"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ItemCodeNotExistsOrNotActive", CurInvItem.ItemInfo.ITEM_CODE.IsNullOrEmpty(CurInvItem.Barcode.ItemCode)); |
| | | return action; |
| | | var qtyList = (input.Data ?? "").JsonToObject<List<WMS_ITEM>>() ?? new List<WMS_ITEM>(); |
| | | if (!qtyList.Any() || qtyList.Sum(q => q.QTY) <= 0) |
| | | { |
| | | action.IsSuccessed = false; |
| | | action.Data.Data = CurInvItem.Items.Select(q => new { q.SN, q.QTY }); |
| | | action.Data.Command = Command = "ComfirmQty"; |
| | | //action.LocaleMsg = Biz.L("下架数量不能小于等于零,请重新确认条码[{0}]的下架数量"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ReComfirmOutQty", input.SN); |
| | | return SetOutPutMqttMsg(action, input.Locale); |
| | | } |
| | | else if (qtyList.Any(q => q.QTY > CurInvItem.Items.First(i => i.SN == q.SN).QTY)) |
| | | { |
| | | action.IsSuccessed = false; |
| | | action.Data.Data = CurInvItem.Items.Select(q => new { q.SN, q.QTY }); |
| | | action.Data.Command = Command = "ComfirmQty"; |
| | | //action.LocaleMsg = Biz.L("下架数量不能超过原条码数量,请重新确认条码[{0}]的下架数量"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ReComfirmExceedOutQty", input.SN); |
| | | return SetOutPutMqttMsg(action, input.Locale); |
| | | } |
| | | else |
| | | { |
| | | downDic = qtyList.ToDictionary(k => k.SN, v => v.QTY); |
| | | Command = "Normal"; |
| | | } |
| | | } |
| | | |
| | | //出库下架 |
| | |
| | | item.TRANS_CODE = "Out_Default"; |
| | | item.TRANS_NO = $"Out_Default_{DateTime.Now:yyyyMMdd}"; |
| | | } |
| | | Result<TakeDownInfo> downResult = WMS_ITEM_Biz.WmsItem.TakeDown(CurInvItem, input.AuthOption, WMS_ITEM.STATUSs.Sended); |
| | | Result downResult = TakeDown(downDic, input.AuthOption, WMS_ITEM.STATUSs.OffShelf); |
| | | if (!downResult.IsSuccessed) |
| | | { |
| | | action.IsSuccessed = false; |
| | | action.LocaleMsg = downResult.LocaleMsg; |
| | | return action; |
| | | ResetScan(); |
| | | return SetOutPutMqttMsg(action, input.Locale); |
| | | } |
| | | TakeDownInfo downInfo = downResult.Data; |
| | | |
| | | //灭灯 |
| | | if (CurInvItem.Shelf.IsLightShelf) |
| | |
| | | await Share.Shelf.DownSingle(TransID, CurInvItem.Location); |
| | | } |
| | | |
| | | //保存数据库 |
| | | var db = Business.Biz.Db; |
| | | var dbTran = db.UseTran(() => |
| | | { |
| | | //下架 |
| | | db.Updateable(downInfo.Items, UserCode).ExecuteCommand(); |
| | | db.Insertable(downInfo.History, UserCode).ExecuteCommand(); |
| | | db.Updateable(downInfo.Packages, UserCode).ExecuteCommand(); |
| | | }); |
| | | if (!dbTran.IsSuccess) |
| | | { |
| | | Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception"); |
| | | throw dbTran.ErrorException; |
| | | } |
| | | |
| | | action.Data.Data = new DefaultScanItemOutput() |
| | | { |
| | | SN = CurInvItem.SN, |
| | | ItemCode = CurInvItem.ItemInfo.ITEM_CODE, |
| | | MaterialName = CurInvItem.ItemInfo.ITEM_NAME, |
| | | Qty = CurInvItem.CurPkg.QTY, |
| | | Unit = CurInvItem.CurPkg.UNIT, |
| | | regionCode = CurInvItem.Region.REGION_CODE, |
| | | locationCode = CurInvItem.Location?.LOCATION_CODE, |
| | | DateCode = CurInvItem.Items[0].PROD_DATE, |
| | | ScanAfCut = CurInvItem.Warehouse.SCAN_AF_CUT |
| | | }; |
| | | //action.LocaleMsg = Biz.L($"扫描条码[{0}]从储位[{1}]下架成功"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.TakeDownSucceeded", CurInvItem.SN, CurInvItem.Location?.LOCATION_CODE); |
| | | //完成所有处理后使用事务保存数据 |
| | | action = DoIfFinish(action, input.Locale); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ResetInfo(); |
| | | ResetScan(); |
| | | //action.CatchExceptionWithLog(ex, $"扫描条码[{input.SN}]复核异常"); |
| | | action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanItem.ScanException", input.SN)); |
| | | } |
| | | return action; |
| | | return SetOutPutMqttMsg(action, input.Locale); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | public async Task<ApiAction<ScanOutput>> ScanShelf(string Code) |
| | | { |
| | | var action = new ApiAction<ScanOutput>(); |
| | | var action = new ApiAction<ScanOutput>(new ScanOutput() { Command = Command }); |
| | | try |
| | | { |
| | | if (Code.IsNullOrEmpty()) |
| | |
| | | CurScanShelf = new ScanShelfInfo(); |
| | | |
| | | // 查询货架信息 |
| | | var whUnit = await Biz.Db.Queryable<V_WH_UNIT>().Where(t => t.SHELF_CODE.ToUpper() == Code.ToUpper() && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync(); |
| | | var whUnit = await MainDB.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()) |
| | |
| | | // 扫描库位代码 |
| | | else |
| | | { |
| | | var nLocation = await Biz.Db.Queryable<V_WH_UNIT>().Where(t => t.LOCATION_CODE.ToUpper() == Code.ToUpper() && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync(); |
| | | var nLocation = await MainDB.Queryable<V_WH_UNIT>().Where(t => t.LOCATION_CODE.ToUpper() == Code.ToUpper() && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync(); |
| | | if (nLocation == null) |
| | | { |
| | | action.IsSuccessed = false; |
| | |
| | | } |
| | | //if (nLocation.Shelf.IsLightShelf || nLocation.Location.IS_SINGLE == "Y") |
| | | //{ |
| | | // var locationData = Biz.Db.Queryable<WMS_ITEM>().Where(q => q.LOCATION_ID == nLocation.LOCATION_ID && q.AUTH_ORG == OrgCode).First(); |
| | | // var locationData = MainDB.Queryable<WMS_ITEM>().Where(q => q.LOCATION_ID == nLocation.LOCATION_ID && q.AUTH_ORG == OrgCode).First(); |
| | | // if (!locationData.IsNullOrEmpty()) |
| | | // { |
| | | // action.IsSuccessed = false; |
| | |
| | | catch (Exception ex) |
| | | { |
| | | //取消当前操作 |
| | | ResetInfo(); |
| | | ResetScan(); |
| | | //action.CatchExceptionWithLog(ex, $"扫描货架/储位[{0}]异常"); |
| | | action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanShelf.ScanException", Code)); |
| | | } |
| | | return action; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 完成所有处理后使用事务保存数据 |
| | | /// </summary> |
| | | /// <param name="action"></param> |
| | | /// <returns></returns> |
| | | public ApiAction<ScanOutput> DoIfFinish(ApiAction<ScanOutput> action, string locale) |
| | | { |
| | | //保存数据库 |
| | | SaveCommitListToDB(); |
| | | |
| | | // 返回数据 |
| | | action.Data.Data = new DefaultScanItemOutput() |
| | | { |
| | | SN = CurInvItem.SN, |
| | | ItemCode = CurInvItem.ItemInfo.ITEM_CODE, |
| | | MaterialName = CurInvItem.ItemInfo.ITEM_NAME, |
| | | Qty = CurInvItem.CurPkg.QTY, |
| | | Unit = CurInvItem.CurPkg.UNIT, |
| | | regionCode = CurInvItem.Region.REGION_CODE, |
| | | locationCode = CurInvItem.Location?.LOCATION_CODE, |
| | | DateCode = CurInvItem.Items[0].PROD_DATE, |
| | | ScanAfCut = CurInvItem.Warehouse.SCAN_AF_CUT |
| | | }; |
| | | |
| | | //action.LocaleMsg = Biz.L($"扫描条码[{0}]从储位[{1}]下架成功"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.TakeDownSucceeded", CurInvItem.SN, CurInvItem.Location?.LOCATION_CODE); |
| | | |
| | | //重置工序 |
| | | ResetScan(); |
| | | return SetOutPutMqttMsg(action, locale); |
| | | } |
| | | |
| | | #endregion |
| | |
| | | /// <summary> |
| | | /// 重置当前操作,有需要则重写此方法 |
| | | /// </summary> |
| | | public override void ResetInfo() |
| | | public override void ResetScan() |
| | | { |
| | | base.ResetInfo(); |
| | | base.ResetScan(); |
| | | Command = null; |
| | | CurInvItem = null; |
| | | CurScanShelf = null; |