diff --git a/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs b/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs index 81f498cb..2716229e 100644 --- a/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs @@ -744,7 +744,14 @@ namespace Tnb.ProductionMgr elapsedMilliseconds = stopwatch.ElapsedMilliseconds; try { - thirdResult = JsonConvert.DeserializeObject(response); + if (response != null && !response.IsEmpty()) + { + thirdResult = JsonConvert.DeserializeObject(response); + } + else + { + thirdResult.Code = 500; + } } catch (Exception e) { diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsSterilizationInstockHService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsSterilizationInstockHService.cs index fb35bc1a..54dc6696 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsSterilizationInstockHService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsSterilizationInstockHService.cs @@ -5,11 +5,13 @@ using JNPF.Common.Extension; using JNPF.Common.Security; using JNPF.EventBus; using JNPF.FriendlyException; +using JNPF.Systems.Entitys.System; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; using JNPF.VisualDev.Entitys; using JNPF.VisualDev.Interfaces; using Microsoft.CodeAnalysis; +using Newtonsoft.Json; using SqlSugar; using Tnb.BasicData.Entities; using Tnb.WarehouseMgr.Entities; @@ -19,6 +21,9 @@ using Tnb.WarehouseMgr.Entities.Dto; using Tnb.WarehouseMgr.Entities.Entity; using Tnb.WarehouseMgr.Entities.Enums; using Tnb.WarehouseMgr.Interfaces; +using Tnb.ProductionMgr.Entities.Entity; +using Tnb.BasicData; + namespace Tnb.WarehouseMgr { @@ -64,14 +69,16 @@ namespace Tnb.WarehouseMgr BasLocation endLocation = await _db.Queryable().Where(r => r.id == input.wmsDistaskH.endlocation_id).FirstAsync(); + string outWhid = ""; // 生产入库(灭菌完成) 仓库传 1001A1100000001MA8KP if (endLocation.wh_id == WmsWareHouseConst.WAREHOUSE_MJC_ID) { - + outWhid = WmsWareHouseConst.bipwarehouseid_bz; } // 生产入库(成品) 仓库传 1001A1100000001MA8ME else if (endLocation.wh_id == WmsWareHouseConst.WAREHOUSE_CP_ID) { + outWhid = WmsWareHouseConst.bipwarehouseid_mj; bool isOk = await _db.Updateable().SetColumns(it => new WmsSterilizationInstockH { status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID }) .Where(it => it.id == input.requireId).ExecuteCommandHasChangeAsync(); if (!isOk) @@ -80,6 +87,93 @@ namespace Tnb.WarehouseMgr } } + WmsSterilizationInstockH wmsRawmatTransferoutstockH = await _db.Queryable().SingleAsync(x=>x.id==input.requireId); + List wmsCarryCodes = await _db.Queryable().Where(r => r.carry_id == input.wmsDistaskH.carry_id).ToListAsync(); + + decimal qty = wmsCarryCodes.Sum(r => r.codeqty); + + List unitCodes = wmsCarryCodes.Select(x => x.unit_id).Distinct().ToList(); + List materialIds = wmsCarryCodes.Select(x => x.material_id).ToList(); + List unitDatas = await _db.Queryable() + .LeftJoin((x, y) => x.Id == y.DictionaryTypeId) + .Where((x, y) => x.EnCode == DictConst.MeasurementUnit && unitCodes.Contains(y.EnCode)) + .Select((x, y) => y) + .ToListAsync(); + + string supplierId = WmsWareHouseConst.TIANYIGONGYINGSHANG_ID; + List tableIds = new List(); + tableIds.Add(WmsWareHouseConst.AdministratorOrgId); + tableIds.AddRange(materialIds); + tableIds.Add(supplierId); + tableIds.AddRange(unitDatas.Select(x => x.Id).ToList()); + + List erpExtendFields = await _db.Queryable().Where(x => tableIds.Contains(x.table_id)).ToListAsync(); + string userId = wmsRawmatTransferoutstockH.create_id; + string erpCreateId = erpExtendFields.Find(x => x.table_id == userId)?.user_id ?? ""; + ErpExtendField erpOrg = erpExtendFields.Find(x => x.table_id == (WmsWareHouseConst.AdministratorOrgId)); + string nowStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + List wmsErpWarehouserelaHs = await _db.Queryable().Where(x=>!SqlFunc.IsNullOrEmpty(x.id)).ToListAsync(); + + List> requestData = new List>(); + Dictionary erpRequestData = new Dictionary(); + erpRequestData.Add("billmaker", erpCreateId); + erpRequestData.Add("corpoid", erpOrg.corpoid); + erpRequestData.Add("corpvid", erpOrg.corpvid); + erpRequestData.Add("cdptid","1001A1100000000JRLI1");//部门先写死 + erpRequestData.Add("cdptvid","0001A11000000007GGO8");//部门先写死 + erpRequestData.Add("cotherdptid","1001A1100000000JRLI1");//部门先写死 + erpRequestData.Add("cotherdptvid","0001A11000000007GGO8");//部门先写死 + erpRequestData.Add("creationtime", nowStr); + erpRequestData.Add("creator", erpCreateId); + erpRequestData.Add("ctrantypeid", "0001H11000000000D32A");//先写死 + erpRequestData.Add("cwarehouseid", "outWhid");//先写死 + erpRequestData.Add("dbilldate", wmsRawmatTransferoutstockH.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss")); + erpRequestData.Add("dmakedate", nowStr); + erpRequestData.Add("dshldarrivedate", nowStr); + erpRequestData.Add("dshlddiliverdate", nowStr); + erpRequestData.Add("fbillflag", 1); + erpRequestData.Add("isbackdeliver", false); + erpRequestData.Add("ntotalnum", qty); + erpRequestData.Add("pk_org", erpOrg.pk_org); + erpRequestData.Add("pk_org_v", erpOrg.pk_org_v); + erpRequestData.Add("pk_group", erpOrg.pk_group); + erpRequestData.Add("vbillcode", wmsRawmatTransferoutstockH.bill_code); + erpRequestData.Add("vtrantypecode", "4Y-01");//先写死 + + List> erpRequestDataDetails = new List>(); + foreach(var item in wmsCarryCodes) + { + // 出库数量wmsMaterialSignD.sign_qty + erpRequestDataDetails.Add(new Dictionary() + { + ["cmaterialoid"] = erpExtendFields.Find(x => x.table_id == item.material_id)?.cmaterialoid ?? "", + ["cmaterialvid"] = erpExtendFields.Find(x => x.table_id == item.material_id)?.cmaterialvid ?? "", + ["corpoid"] = erpOrg.corpoid, + ["corpvid"] = erpOrg.corpvid, + ["crowno"] = (wmsCarryCodes.FindIndex(x => x.id == item.id) + 1) * 10, + ["cunitid"] = erpExtendFields.Find(x => x.table_id == (unitDatas.Find(x => x.EnCode == item.unit_id)?.Id ?? ""))?.cunitid ?? "", + ["nnum"] = item.codeqty, + ["nshouldnum"] = item.codeqty, + ["pk_group"] = erpOrg.pk_group, + ["pk_org"] = erpOrg.pk_org, + ["pk_org_v"] = erpOrg.pk_org_v, + ["vbatchcode"] = item.code_batch, + + }); + } + erpRequestData.Add("dtls", erpRequestDataDetails); + requestData.Add(erpRequestData); + BasFactoryConfig config = await _db.Queryable().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.BIPURL); + ThirdWebapiRecord thirdWebapiRecord = new ThirdWebapiRecord(); + thirdWebapiRecord.id = SnowflakeIdHelper.NextId(); + thirdWebapiRecord.third_name = WmsWareHouseConst.BIP; + thirdWebapiRecord.name = "转库单"; + thirdWebapiRecord.method = "POST"; + thirdWebapiRecord.url = config.value + "uapws/rest/whstrans/save"; + // thirdWebapiRecord.url = WmsWareHouseConst.BIP_DOMAIN + "uapws/rest/transIn/save"; + thirdWebapiRecord.request_data = JsonConvert.SerializeObject(requestData); + thirdWebapiRecord.create_time = DateTime.Now; + await _db.Insertable(thirdWebapiRecord).ExecuteCommandAsync(); } }