From 950fac9fd7b9477fc2bbe3253d217f62ac7608e5 Mon Sep 17 00:00:00 2001 From: wxw <Administrator@DESKTOP-5BIMHQ3> Date: 星期一, 21 七月 2025 17:01:21 +0800 Subject: [PATCH] SAP接口开发 --- Wms/WMS.BLL/BllQualityServer/QualityInspectServer.cs | 202 ++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 171 insertions(+), 31 deletions(-) diff --git a/Wms/WMS.BLL/BllQualityServer/QualityInspectServer.cs b/Wms/WMS.BLL/BllQualityServer/QualityInspectServer.cs index f2de73b..0cc581b 100644 --- a/Wms/WMS.BLL/BllQualityServer/QualityInspectServer.cs +++ b/Wms/WMS.BLL/BllQualityServer/QualityInspectServer.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Data; using System.Text; +using System.Threading.Tasks; +using Model.InterFaceModel; using Model.ModelDto.BllQualityDto; using Model.ModelVm; using SqlSugar; @@ -112,51 +114,59 @@ throw new Exception("鐗╂枡淇℃伅涓虹┖锛岃鏍告煡锛�"); } //楠岃瘉鎵规鍙锋槸鍚︿负绌� - if (string.IsNullOrEmpty(model.LotNo)) + if (string.IsNullOrEmpty(model.LotNo) && string.IsNullOrEmpty(model.ASNNo)) { - throw new Exception("鎵规鍙蜂笉鍙负绌猴紝璇锋牳鏌ワ紒"); + throw new Exception("璇疯緭鍏ユ壒娆″彿鎴栧叆搴撳崟鍙凤紒"); } //楠岃瘉鍏ュ簱鍗曞彿鏄惁涓虹┖ - if (string.IsNullOrEmpty(model.ASNNo)) - { - throw new Exception("鍏ュ簱鍗曞彿涓嶅彲涓虹┖锛�"); + //if (string.IsNullOrEmpty(model.ASNNo)) + //{ + // throw new Exception("鍏ュ簱鍗曞彿涓嶅彲涓虹┖锛�"); - //鏌ヨ鏄惁涓洪��璐у叆搴撳崟鎹� - //var Arrival = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.ASNNo && a.Type == "3"); - //if (Arrival == null) - //{ - // throw new Exception("鍙湁鍏ュ簱鍗曟嵁涓洪��璐у叆搴撳崟鍙緭鍏� 鍏ュ簱鍗曞彿锛岃鏍告煡锛�"); - //} + //鏌ヨ鏄惁涓洪��璐у叆搴撳崟鎹� + //var Arrival = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.ASNNo && a.Type == "3"); + //if (Arrival == null) + //{ + // throw new Exception("鍙湁鍏ュ簱鍗曟嵁涓洪��璐у叆搴撳崟鍙緭鍏� 鍏ュ簱鍗曞彿锛岃鏍告煡锛�"); + //} - ////鑾峰彇鍏ュ簱鍗曟槑缁� - //var ArrivalDetail = Db.Queryable<BllArrivalNoticeDetail>().First(a => a.IsDel == "0" && a.ASNNo == model.ASNNo && a.LotNo.Contains(model.LotNo) && a.SkuNo == model.SkuNo); - //if (ArrivalDetail == null) - //{ - // throw new Exception("杈撳叆鐨勬壒娆℃垨鐗╂枡淇℃伅涓庡叆搴撳崟鎹笉绗︼紝璇锋牳鏌ワ紒"); - //} - //isTui = 1; - } + ////鑾峰彇鍏ュ簱鍗曟槑缁� + //var ArrivalDetail = Db.Queryable<BllArrivalNoticeDetail>().First(a => a.IsDel == "0" && a.ASNNo == model.ASNNo && a.LotNo.Contains(model.LotNo) && a.SkuNo == model.SkuNo); + //if (ArrivalDetail == null) + //{ + // throw new Exception("杈撳叆鐨勬壒娆℃垨鐗╂枡淇℃伅涓庡叆搴撳崟鎹笉绗︼紝璇锋牳鏌ワ紒"); + //} + //isTui = 1; + //} //鏌ユ壘璐ㄦ淇℃伅涓槸鍚﹀瓨鍦ㄥ悓鎵规璐ㄦ褰曞叆璁板綍 //BllQualityInspect quality = Db.Queryable<BllQualityInspect>().First(m => m.IsDel == "0" && m.SkuNo == model.SkuNo && m.LotNo == model.LotNo); //if (quality != null) //{ - ////鍒ゆ柇鏄惁涓洪��璐у叆搴撳崟 - //if (isTui == 1) - //{ - // if (quality.ASNNo == model.ASNNo) - // { - // throw new Exception("褰撳墠閫�璐у叆搴撳崟宸插垱寤鸿川妫�淇℃伅锛岃鍕块噸澶嶅垱寤猴紒"); - // } - //} + ////鍒ゆ柇鏄惁涓洪��璐у叆搴撳崟 + //if (isTui == 1) + //{ + // if (quality.ASNNo == model.ASNNo) + // { + // throw new Exception("褰撳墠閫�璐у叆搴撳崟宸插垱寤鸿川妫�淇℃伅锛岃鍕块噸澶嶅垱寤猴紒"); + // } + //} // throw new Exception("褰撳墠鐗╂枡鍜屾壒娆″凡杩涜璐ㄦ锛岃鏍告煡锛�"); //} ////鏌ユ壘鍚屾壒娆� 鍚屽崟鎹� 鍏ュ簱鍗曚俊鎭�� - BllArrivalNoticeDetail arrivalDetail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" - && m.ASNNo == model.ASNNo && m.LotNo == model.LotNo && m.SkuNo == model.SkuNo); + string sqlStr = $@"select * from BllArrivalNoticeDetail where IsDel='0' and SkuNo='{model.SkuNo}' "; + if (!string.IsNullOrEmpty(model.ASNNo)) + { + sqlStr += $" and ASNNo='{model.ASNNo}' "; + } + if (!string.IsNullOrEmpty(model.LotNo)) + { + sqlStr += $" and LotNo='{model.LotNo}' "; + } + BllArrivalNoticeDetail arrivalDetail = Db.SqlQueryable<BllArrivalNoticeDetail>(sqlStr).First(); if (arrivalDetail == null) { throw new Exception("鏈壘鍒板叆搴撳崟淇℃伅锛�"); @@ -170,10 +180,19 @@ model.PassQty = 0; //鍚堟牸鏁伴噺 model.FailQty = 0; //涓嶅悎鏍兼暟閲� model.Standard = sku.Standard; //瑙勬牸 - //model.SupplierLot = arrivalDetail.SupplierLot; //渚涜揣鎵规 + //model.SupplierLot = arrivalDetail.SupplierLot; //渚涜揣鎵规 //鏌ユ壘搴撳瓨鏄庣粏淇℃伅 - List<DataStockDetail> detail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.SkuNo == model.SkuNo && m.LotNo == model.LotNo).ToList(); + string sqlStr2 = $@"select * from DataStockDetail where IsDel='0' and SkuNo='{model.SkuNo}' "; + if (!string.IsNullOrEmpty(model.ASNNo)) + { + sqlStr2 += $" and ASNNo='{model.ASNNo}' "; + } + if (!string.IsNullOrEmpty(model.LotNo)) + { + sqlStr2 += $" and LotNo='{model.LotNo}' "; + } + List<DataStockDetail> detail = Db.SqlQueryable<DataStockDetail>(sqlStr2).ToList(); foreach (var item in detail) { List<BllBoxInfo> box = Db.Queryable<BllBoxInfo>().Where(a => a.IsDel == "0" && a.SkuNo == model.SkuNo && a.LotNo == model.LotNo).ToList(); @@ -201,7 +220,128 @@ return isquality; } + /// <summary> + /// SAP涓嬪彂搴撳瓨璋冩暣鍗� + /// </summary> + /// <param name="model"></param> + /// <returns></returns> + /// <exception cref="Exception"></exception> + public string InsertQualitySap(SendQualityVm model) + { + try + { + if (string.IsNullOrEmpty(model.orderNo) || model.adjustmentDList.Count <= 0) + { + throw new Exception("鍙傛暟閿欒"); + } + var asnInfo = Db.Queryable<BllArrivalNotice>().First(w => w.IsDel == "0" && w.OrderCode == model.orderNo); + if (asnInfo == null) + { + throw new Exception($"鏈煡璇㈠埌{model.orderNo}瀵瑰簲鐨勫叆搴撳崟淇℃伅"); + } + //寮�鍚簨鍔� + Db.BeginTran(); + foreach (var item in model.adjustmentDList) + { + var asnDetail = Db.Queryable<BllArrivalNoticeDetail>().First(w => w.IsDel == "0" && w.ASNNo == asnInfo.ASNNo && w.OrderDetailCode == item.lineNo && w.SkuNo == item.skuNo && w.LotNo == item.lotNo); + if (asnDetail == null) + { + throw new Exception($"鏈煡璇㈠埌{item.lineNo}瀵瑰簲鐨勫叆搴撳崟鏄庣粏淇℃伅"); + } + asnDetail.InspectStatus = item.IsQualified; + //鏇存柊鍏ュ簱鍗曟槑缁嗚川妫�鐘舵�� + Db.Updateable(asnDetail).ExecuteCommand(); + + //鑾峰彇鐗╂枡淇℃伅 + var sku = Db.Queryable<SysMaterials>().First(a => a.IsDel == "0" && a.SkuNo == item.skuNo); + if (sku == null) + { + throw new Exception($"鐗╂枡缂栫爜涓簕item.skuNo}鐨勭墿鏂欎俊鎭笉瀛樺湪锛岃鏍告煡锛�"); + } + + string toDayTime = DateTime.Now.ToString("yyyyMMdd"); + var maxInspectNo = Db.Queryable<BllQualityInspect>().Where(m => m.IsDel == "0" && m.InspectNo.Contains("SAP")).Max(m => m.InspectNo); + if (string.IsNullOrWhiteSpace(maxInspectNo)) + { + maxInspectNo = "SAP" + toDayTime + "0001"; + } + else + { + var lotStr = maxInspectNo.Substring(3, 8); + if (lotStr == toDayTime) + { + maxInspectNo = "SAP" + toDayTime + (int.Parse(maxInspectNo.Replace("SAP","").Substring(8, 4)) + 1).ToString().PadLeft(4, '0'); + } + else + { + maxInspectNo = "SAP" + toDayTime + "0001"; + } + } + var qualityModel = new BllQualityInspect + { + ASNNo = asnDetail.ASNNo, + InspectNo = maxInspectNo, + SkuNo = item.skuNo, + SkuName = item.skuName, + Standard = sku.Standard, + LotNo = item.lotNo, + IsQualified = item.IsQualified, + Origin = "SAP", + FailQty = 0, + PassQty = 0 + }; + + //鏌ユ壘搴撳瓨淇℃伅 + var stockDetailList = Db.Queryable<DataStockDetail>().Where(w => w.IsDel == "0" && w.SkuNo == item.skuNo && w.LotNo == item.lotNo).ToList(); + foreach(var datailItem in stockDetailList) + { + List<DataBoxInfo> boxList = Db.Queryable<DataBoxInfo>().Where(a => a.IsDel == "0" && a.SkuNo == item.skuNo && a.LotNo == item.lotNo && a.PalletNo == datailItem.PalletNo).ToList(); + foreach (var boxItem in boxList) + { + if (item.IsQualified == "0")//涓嶅悎鏍� + { + boxItem.InspectStatus = "2"; + } + else//鍚堟牸 + { + boxItem.InspectStatus = "1"; + } + } + //鏇存柊绠辩爜鏄庣粏璐ㄦ鐘舵�� + Db.Updateable(boxList).ExecuteCommand(); + + if (item.IsQualified == "0")//涓嶅悎鏍� + { + datailItem.InspectStatus = "2"; + //涓嶅悎鏍兼暟閲� + qualityModel.FailQty += datailItem.Qty; + } + else//鍚堟牸 + { + datailItem.InspectStatus = "1"; + //鍚堟牸鏁伴噺 + qualityModel.PassQty += datailItem.Qty; + } + //鏇存柊搴撳瓨鏄庣粏璐ㄦ鐘舵�� + Db.Updateable(datailItem).ExecuteCommand(); + } + //娣诲姞璐ㄦ鍙樻洿璁板綍 + Db.Insertable(qualityModel).ExecuteCommand(); + } + //鎻愪氦浜嬪姟 + Db.CommitTran(); + + return "0"; + } + catch (Exception ex) + { + //鍥炴粴浜嬪姟 + Db.RollbackTran(); + //鎶涘嚭寮傚父 + throw new Exception("鎺ユ敹SAP涓嬪彂搴撳瓨璋冩暣鍗曞紓甯�:", ex); + } + } #endregion } -- Gitblit v1.8.0