diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs index 4f1bfa0c..1d8c1d95 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs @@ -2559,7 +2559,7 @@ namespace Tnb.ProductionMgr // thirdWebapiRecord.url = WmsWareHouseConst.BIP_DOMAIN+"uapws/rest/pwrnew/save"; thirdWebapiRecord.request_data = JsonConvert.SerializeObject(erpRequestData); thirdWebapiRecord.create_time = DateTime.Now; - + thirdWebapiRecord.remark = $"载具编号:{report?.material_box_code ?? ""}"; await _db.Insertable(thirdWebapiRecord).ExecuteCommandAsync(); } diff --git a/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs b/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs index 8ec20959..b077939b 100644 --- a/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs @@ -914,7 +914,7 @@ namespace Tnb.ProductionMgr try { - string response2 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-material"); + string response2 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-material",null,10*60*1000); AuthResponse authResponse2 = JsonConvert.DeserializeObject(response2); result += ","+authResponse2.data.ToString(); } @@ -1014,10 +1014,10 @@ namespace Tnb.ProductionMgr if (erpBdMaterial.CODE.StartsWith("0401")) { string str = ""; - if (erpBdMaterial.MATERIALSPEC.Contains("*")) + if (erpBdMaterial.MATERIALSPEC!=null && erpBdMaterial.MATERIALSPEC.Contains("*")) { str = erpBdMaterial.MATERIALSPEC; - }else if (erpBdMaterial.NAME.Contains("*")) + }else if (erpBdMaterial.NAME!=null && erpBdMaterial.NAME.Contains("*")) { str = erpBdMaterial.NAME; } @@ -1030,7 +1030,7 @@ namespace Tnb.ProductionMgr if (strArr.Length <= 2) { categoryId = "[\"CGJCJ\"]"; - }else if (decimal.Parse(strArr[2]) > 600) + }else if (decimal.Parse(strArr[2]) > 500) { categoryId = "[\"CGJCJ\"]"; } @@ -1042,7 +1042,7 @@ namespace Tnb.ProductionMgr } else { - categoryId = materialcategoryDic.ContainsKey(erpBdMaterial.DEFNAME) ? $"[\"{materialcategoryDic["erpBdMaterial.DEFNAME"]}\"]" : "[\"CGJCJ\"]"; + categoryId = !string.IsNullOrEmpty(erpBdMaterial.DEFNAME) && materialcategoryDic.ContainsKey(erpBdMaterial.DEFNAME) ? $"[\"{materialcategoryDic[erpBdMaterial.DEFNAME]}\"]" : ""; } if (erpExtendFields.All(x => x.cmaterialoid != erpBdMaterial.ID)) @@ -1103,6 +1103,7 @@ namespace Tnb.ProductionMgr ErpExtendField extendField = erpExtendFields.Find(x => x.cmaterialoid == erpBdMaterial.ID); string materialId = extendField?.table_id ?? ""; BasMaterial basMaterial = await _db.Queryable().SingleAsync(x => x.id == materialId); + // if (extendField.erp_modify_time==null || erpBdMaterial.MODIFIEDTIME != extendField.erp_modify_time) if (erpBdMaterial.MODIFIEDTIME != extendField.erp_modify_time) { string unitId = erpExtendFields.Find(x => x.cunitid == erpBdMaterial.PK_MEASDOC)?.table_id ?? ""; @@ -1114,7 +1115,7 @@ namespace Tnb.ProductionMgr int updateRow = await _db.Updateable() .SetColumns(x => x.name == erpBdMaterial.NAME) .SetColumns(x => x.code == erpBdMaterial.CODE) - .SetColumns(x=>x.category_id == categoryId) + .SetColumnsIF(!string.IsNullOrEmpty(categoryId),x=>x.category_id == categoryId) .SetColumns(x => x.material_specification == erpBdMaterial.MATERIALSPEC) .SetColumns(x => x.material_standard == erpBdMaterial.MATERIALTYPE) .SetColumns(x => x.unit_id == unitId) @@ -1183,7 +1184,7 @@ namespace Tnb.ProductionMgr BasMaterial material = materials.Find(x => x.code==firstItemInList.MPRODID); if (material == null) continue; string unitId = unitDic2.ContainsKey(firstItemInList.UNIT) ? unitDic2[firstItemInList.UNIT].ToString() : ""; - if (basEbomHs.All(x => x.material_id != material.id && x.version != firstItemInList.HVERSION)) + if (basEbomHs.FindIndex(x => x.material_id == material.id && x.version == firstItemInList.HVERSION)==-1) { BasEbomH basEbomH = new BasEbomH() { diff --git a/QcMgr/Tnb.QcMgr.Entities/Dto/CheckTask.cs b/QcMgr/Tnb.QcMgr.Entities/Dto/CheckTask.cs index f9a380e7..33829f62 100644 --- a/QcMgr/Tnb.QcMgr.Entities/Dto/CheckTask.cs +++ b/QcMgr/Tnb.QcMgr.Entities/Dto/CheckTask.cs @@ -18,6 +18,8 @@ public string mo_task_code { get; set; } public string batch { get; set; } public int? qty { get; set; } + public int? rqty { get; set; } + public string bill_code { get; set; } public string equip_name { get; set; } /// diff --git a/QcMgr/Tnb.QcMgr.Entities/Entity/QcCheckExecH.cs b/QcMgr/Tnb.QcMgr.Entities/Entity/QcCheckExecH.cs index ff0f6b8d..711a5deb 100644 --- a/QcMgr/Tnb.QcMgr.Entities/Entity/QcCheckExecH.cs +++ b/QcMgr/Tnb.QcMgr.Entities/Entity/QcCheckExecH.cs @@ -48,6 +48,11 @@ namespace Tnb.QcMgr.Entities /// 合格数 /// public int? qty { get; set; } + + /// + /// 不合格数 + /// + public int? rqty { get; set; } /// /// 状态 diff --git a/QcMgr/Tnb.QcMgr/QcCheckTaskService.cs b/QcMgr/Tnb.QcMgr/QcCheckTaskService.cs index 9008ee4e..b1a5610e 100644 --- a/QcMgr/Tnb.QcMgr/QcCheckTaskService.cs +++ b/QcMgr/Tnb.QcMgr/QcCheckTaskService.cs @@ -108,6 +108,7 @@ namespace Tnb.QcMgr mo_task_code = a.mo_task_code, batch = a.batch, qty = a.qty, + rqty = a.rqty, material_standard = b.material_standard, material_specification = b.material_specification, equip_name = h.name, @@ -344,6 +345,7 @@ namespace Tnb.QcMgr } await db.Ado.BeginTranAsync(); QcCheckExecH.qty = int.Parse(CheckTaskInput.checknum) - rqty; + QcCheckExecH.rqty = rqty; _ = await db.Updateable(QcCheckExecH).ExecuteCommandAsync(); _ = await db.Deleteable(QcCheckExecDdel).ExecuteCommandAsync(); _ = await db.Insertable(QcCheckExecDinsert).ExecuteCommandAsync(); diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPrdInstockHService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPrdInstockHService.cs index 270979a1..31e6037d 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPrdInstockHService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPrdInstockHService.cs @@ -386,8 +386,8 @@ namespace Tnb.WarehouseMgr erpRequestData.Add("billmaker", erpCreateId); erpRequestData.Add("corpoid", erpOrg.corpoid); erpRequestData.Add("corpvid", erpOrg.corpvid); - erpRequestData.Add("cprocalbodyoid", erpOrg.pk_org_v); - erpRequestData.Add("cprocalbodyvid", erpOrg.pk_group); + erpRequestData.Add("cprocalbodyoid", erpOrg.pk_org); + erpRequestData.Add("cprocalbodyvid", erpOrg.pk_org_v); erpRequestData.Add("creationtime", nowStr); erpRequestData.Add("creator", erpCreateId); erpRequestData.Add("ctrantypeid", "0001H11000000000D30X");//先写死 @@ -448,6 +448,7 @@ namespace Tnb.WarehouseMgr // thirdWebapiRecord.url = WmsWareHouseConst.BIP_DOMAIN + "uapws/rest/transIn/save"; thirdWebapiRecord.request_data = JsonConvert.SerializeObject(requestData); thirdWebapiRecord.create_time = DateTime.Now; + thirdWebapiRecord.remark = $"载具编号:{prdReport?.material_box_code ?? ""}"; await _db.Insertable(thirdWebapiRecord).ExecuteCommandAsync(); } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsRawmatOutstockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsRawmatOutstockService.cs index 4e5e8e94..a4f53c98 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsRawmatOutstockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsRawmatOutstockService.cs @@ -1,340 +1,341 @@ -// using System; -// using System.Collections.Generic; -// using System.Linq; -// using System.Text; -// using System.Threading.Tasks; -// using Aop.Api.Domain; -// using JNPF.Common.Core.Manager; -// using JNPF.Common.Dtos.VisualDev; -// using JNPF.Common.Enums; -// using JNPF.Common.Security; -// using JNPF.FriendlyException; -// using JNPF.Systems.Entitys.System; -// using JNPF.Systems.Interfaces.System; -// using JNPF.VisualDev; -// using JNPF.VisualDev.Interfaces; -// using Mapster; -// using Microsoft.AspNetCore.Authorization; -// using Microsoft.AspNetCore.Mvc; -// using Microsoft.Extensions.Logging; -// using Newtonsoft.Json; -// using Newtonsoft.Json.Linq; -// using NPOI.HPSF; -// using Senparc.Weixin.Work.AdvancedAPIs.OaDataOpen; -// using SqlSugar; -// using Tnb.BasicData.Entities; -// using Tnb.WarehouseMgr.Entities; -// using Tnb.WarehouseMgr.Entities.Attributes; -// using Tnb.WarehouseMgr.Entities.Consts; -// using Tnb.WarehouseMgr.Entities.Dto; -// using Tnb.WarehouseMgr.Entities.Dto.Inputs; -// using Tnb.WarehouseMgr.Entities.Entity; -// using Tnb.WarehouseMgr.Interfaces; -// using Tnb.ProductionMgr.Entities.Entity; -// using Tnb.BasicData; -// -// namespace Tnb.WarehouseMgr -// { -// /// -// /// 材料出库单 -// /// -// [OverideVisualDev(ModuleConsts.MODULE_WmsRawmatOutstock_ID)] -// [ServiceModule(BizTypeId)] -// public class WmsRawmatOutstockService : BaseWareHouseService -// { -// private const string BizTypeId = WmsWareHouseConst.BIZTYPE_WmsRawmatOutstock_ID; -// private readonly ISqlSugarClient _db; -// private readonly IUserManager _userManager; -// private readonly IBillRullService _billRullService; -// private readonly IRunService _runService; -// private readonly IVisualDevService _visualDevService; -// private readonly IWmsPDAScanInStockService _wmsPDAScanInStock; -// private readonly IWareHouseService _wareHouseService; -// public WmsRawmatOutstockService( -// ISqlSugarRepository repository, -// IUserManager userManager, -// IBillRullService billRullService, -// IRunService runService, -// IVisualDevService visualDevService, -// IWmsPDAScanInStockService wmsPDAScanInStock, -// IWareHouseService wareHouseService) -// { -// _db = repository.AsSugarClient(); -// _userManager = userManager; -// _billRullService = billRullService; -// _runService = runService; -// _visualDevService = visualDevService; -// _wmsPDAScanInStock = wmsPDAScanInStock; -// _wareHouseService = wareHouseService; -// -// OverideFuncs.GetDetailsAsync = GetDetailsAsync; -// } -// -// -// public override async Task ModifyAsync(WareHouseUpInput input) -// { -// if (input == null) -// { -// throw new ArgumentNullException(nameof(input)); -// } -// -// WmsRawmatOutstockD wmsRawmatOutstockD = await _db.Queryable().SingleAsync(x=>x.id==input.requireId); -// WmsRawmatOutstockH wmsRawmatOutstockH = await _db.Queryable().SingleAsync(x=>x.id==wmsRawmatOutstockD.bill_id); -// List wmsCarryCodes = await _db.Queryable() -// .Where(r => r.carry_id == input.wmsDistaskH.carry_id) -// .Where(r => r.material_id == wmsRawmatOutstockD.material_id && r.code_batch == wmsRawmatOutstockD.batchno) -// .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("ccostdomainoid", null); -// erpRequestData.Add("cdrawcalbodyoid", erpOrg.pk_org); -// erpRequestData.Add("cdrawcalbodyvid", erpOrg.pk_org_v); -// -// erpRequestData.Add("corpoid", erpOrg.corpoid); -// erpRequestData.Add("corpvid", erpOrg.corpvid); -// erpRequestData.Add("cdptid","1001A1100000001JFOPQ");//部门先写死 -// erpRequestData.Add("cdptvid","0001A1100000000AOMIQ");//部门先写死 -// erpRequestData.Add("cotherdptid","1001A1100000001JFOPQ");//部门先写死 -// erpRequestData.Add("cotherdptvid","0001A1100000000AOMIQ");//部门先写死 -// 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/materialOut/self/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(); -// -// } -// -// [NonAction] -// private async Task GetDetailsAsync(string id) -// { -// try -// { -// return await Task.FromResult(_db.Queryable().Where(r => r.bill_id == id).ToList()); -// } -// catch (Exception ex) -// { -// return Task.FromResult(ex); -// } -// } -// -// /// -// /// 下发 -// /// -// /// -// /// -// /// -// [HttpPost, NonUnify, AllowAnonymous] -// public async Task Distribute(RawmatOutstockInput input) -// { -// try -// { -// await _s_taskExecuteSemaphore_YCLOutstock.WaitAsync(); -// if (string.IsNullOrEmpty(input.source_id)) -// { -// throw new AppFriendlyException("来源单据id不可为空", 500); -// } -// if (input.carrys.Count == 0) -// { -// throw new AppFriendlyException("至少选择一个载具", 500); -// } -// -// WmsRawmatOutstockD wmsRawmatOutstockD = await _db.Queryable().FirstAsync(it => it.id == input.source_id); -// WmsRawmatOutstockH wmsRawmatOutstockH = await _db.Queryable().FirstAsync(it => it.id == wmsRawmatOutstockD.bill_id); -// -// List _items = await _db.Queryable().Where(r => input.carrys.Select(c => c.carry_code).Contains(r.carry_code)).ToListAsync(); -// -// List wmsCarryCodes = await _db.Queryable().Where(r => _items.Select(c => c.id).Contains(r.carry_id) -// && r.material_id == wmsRawmatOutstockD.material_id && r.code_batch == wmsRawmatOutstockD.batchno).ToListAsync(); -// -// List items = new List(); -// -// foreach (var carry in input.carrys.Select(c => c.carry_code)) -// { -// items.Add(_items.Where(r => r.carry_code == carry).First()); -// } -// -// foreach (var item in items) -// { -// if (item.is_lock == 1) -// { -// throw new AppFriendlyException($"载具{item.carry_code}已锁定", 500); -// } -// BasLocation carrryLoc = await _db.Queryable().Where(r => r.id == item.location_id).FirstAsync(); -// if (carrryLoc == null || carrryLoc.is_type != "0") -// { -// throw new Exception($"托盘{item.carry_code}已经不在存储库位中,不能出库!"); -// } -// } -// -// decimal? sign_qty = 0; -// -// decimal qty = wmsCarryCodes.Sum(c => c.codeqty); -// if (wmsRawmatOutstockD.actual_outstock_qty + qty > wmsRawmatOutstockD.qty) -// { -// // 最后一个托盘的数量 -// decimal lastCarryQty = wmsCarryCodes.Where(r => r.carry_id == items[items.Count - 1].id).Sum(r => r.codeqty); -// // 如果最后一个托盘数量小于超出的出库数量 -// if (lastCarryQty < wmsRawmatOutstockD.actual_outstock_qty + qty - wmsRawmatOutstockD.qty) -// { -// throw new AppFriendlyException($"本次出库数量{qty}已超过可出库数量{wmsRawmatOutstockD.qty - wmsRawmatOutstockD.actual_outstock_qty} 且无需选择{items[items.Count - 1].carry_code}", 500); -// } -// // 签收数量 -// sign_qty = lastCarryQty - (wmsRawmatOutstockD.actual_outstock_qty + qty - wmsRawmatOutstockD.qty); -// } -// -// await _db.Ado.BeginTranAsync(); -// -// List endLocations = new List(); -// -// endLocations = _db.Queryable().Where(r => _wareHouseService.GetFloor1YCLDBOutstockLocation().Contains(r.id) && r.is_lock == 0 && r.is_use == "0") -// .OrderBy("is_lock, task_nums, location_code").ToList(); -// -// if (endLocations.Count() < items.Count) -// { -// throw new AppFriendlyException($@"可用的终点库位数量为{endLocations.Count()}个 下发数量为{items.Count}个 请检查终点库位的锁定和占用状态", 500); -// } -// -// foreach (var wmsCarryH in items) -// { -// BasLocation startLocation = await _db.Queryable().Where(r => r.id == wmsCarryH.location_id).FirstAsync(); -// -// BasLocation endLocation = null; -// -// endLocation = await _db.Queryable().Where(r => _wareHouseService.GetFloor1YCLDBOutstockLocation().Contains(r.id) && r.is_lock == 0 && r.is_use == "0").OrderBy("is_lock, task_nums, location_code").FirstAsync(); -// -// if (endLocation == null) -// { -// throw new AppFriendlyException($@"没有可用的终点库位!请检查终点库位的锁定和占用状态", 500); -// } -// -// WmsRawmatOutstockC wmsRawmatOutstockC = new WmsRawmatOutstockC(); -// wmsRawmatOutstockC.bill_id = wmsRawmatOutstockH.id; -// wmsRawmatOutstockC.mat_bill_id = wmsRawmatOutstockD.id; -// wmsRawmatOutstockC.carry_id = wmsCarryH.id; -// wmsRawmatOutstockC.carry_code = wmsCarryH.carry_code; -// wmsRawmatOutstockC.create_id = input.create_id; -// wmsRawmatOutstockC.create_time = DateTime.Now; -// wmsRawmatOutstockC.startlocation_id = startLocation.id; -// wmsRawmatOutstockC.startlocation_code = startLocation.location_code; -// wmsRawmatOutstockC.endlocation_id = endLocation.id; -// wmsRawmatOutstockC.endlocation_code = endLocation.location_code; -// decimal carryQty = wmsCarryCodes.Where(r => r.carry_id == wmsCarryH.id).Sum(r => r.codeqty); -// wmsRawmatOutstockC.qty = carryQty; -// wmsRawmatOutstockC.sign_qty = wmsCarryH.id == items[items.Count - 1].id && sign_qty > 0 ? sign_qty : carryQty; -// -// await _db.Insertable(wmsRawmatOutstockC).ExecuteCommandAsync(); -// -// CommonCreatePretaskInput commonCreatePretaskInput = new CommonCreatePretaskInput(); -// commonCreatePretaskInput.startlocation_id = startLocation.id; -// commonCreatePretaskInput.endlocation_id = endLocation.id; -// commonCreatePretaskInput.task_type = WmsWareHouseConst.WMS_PRETASK_OUTSTOCK_TYPE_ID; -// commonCreatePretaskInput.biz_type = WmsWareHouseConst.BIZTYPE_WmsRawmatOutstock_ID; -// commonCreatePretaskInput.source_id = input.source_id; -// commonCreatePretaskInput.carry_id = wmsCarryH.id; -// commonCreatePretaskInput.carry_code = wmsCarryH.carry_code; -// commonCreatePretaskInput.isExcuteMission = false; -// -// Entities.Dto.Outputs.Result res = await _wareHouseService.CommonCreatePretask(commonCreatePretaskInput, _db); -// -// if (res.code != HttpStatusCode.OK) -// { -// Logger.LogInformation($@"生成预任务失败"); -// throw new AppFriendlyException($@"生成预任务失败", 500); -// } -// } -// -// // 更新子表已下发数量 -// await _db.Updateable().SetColumns(r => r.actual_outstock_qty == r.actual_outstock_qty + qty).Where(r => r.id == input.source_id).ExecuteCommandAsync(); -// -// await _db.Ado.CommitTranAsync(); -// } -// catch (Exception ex) -// { -// await _db.Ado.RollbackTranAsync(); -// Logger.LogError("【Distribute】" + ex.Message); -// Logger.LogError("【Distribute】" + ex.StackTrace); -// return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message); -// } -// finally -// { -// _ = _s_taskExecuteSemaphore_YCLOutstock.Release(); -// InvokeGenPretaskExcute(); -// } -// -// return await ToApiResult(HttpStatusCode.OK, "成功"); -// } -// -// } -// } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Aop.Api.Domain; +using JNPF.Common.Core.Manager; +using JNPF.Common.Dtos.VisualDev; +using JNPF.Common.Enums; +using JNPF.Common.Security; +using JNPF.FriendlyException; +using JNPF.Systems.Entitys.System; +using JNPF.Systems.Interfaces.System; +using JNPF.VisualDev; +using JNPF.VisualDev.Interfaces; +using Mapster; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using NPOI.HPSF; +using Senparc.Weixin.Work.AdvancedAPIs.OaDataOpen; +using SqlSugar; +using Tnb.BasicData.Entities; +using Tnb.WarehouseMgr.Entities; +using Tnb.WarehouseMgr.Entities.Attributes; +using Tnb.WarehouseMgr.Entities.Consts; +using Tnb.WarehouseMgr.Entities.Dto; +using Tnb.WarehouseMgr.Entities.Dto.Inputs; +using Tnb.WarehouseMgr.Entities.Entity; +using Tnb.WarehouseMgr.Interfaces; +using Tnb.ProductionMgr.Entities.Entity; +using Tnb.BasicData; + +namespace Tnb.WarehouseMgr +{ + /// + /// 材料出库单 + /// + [OverideVisualDev(ModuleConsts.MODULE_WmsRawmatOutstock_ID)] + [ServiceModule(BizTypeId)] + public class WmsRawmatOutstockService : BaseWareHouseService + { + private const string BizTypeId = WmsWareHouseConst.BIZTYPE_WmsRawmatOutstock_ID; + private readonly ISqlSugarClient _db; + private readonly IUserManager _userManager; + private readonly IBillRullService _billRullService; + private readonly IRunService _runService; + private readonly IVisualDevService _visualDevService; + private readonly IWmsPDAScanInStockService _wmsPDAScanInStock; + private readonly IWareHouseService _wareHouseService; + public WmsRawmatOutstockService( + ISqlSugarRepository repository, + IUserManager userManager, + IBillRullService billRullService, + IRunService runService, + IVisualDevService visualDevService, + IWmsPDAScanInStockService wmsPDAScanInStock, + IWareHouseService wareHouseService) + { + _db = repository.AsSugarClient(); + _userManager = userManager; + _billRullService = billRullService; + _runService = runService; + _visualDevService = visualDevService; + _wmsPDAScanInStock = wmsPDAScanInStock; + _wareHouseService = wareHouseService; + + OverideFuncs.GetDetailsAsync = GetDetailsAsync; + } + + + public override async Task ModifyAsync(WareHouseUpInput input) + { + if (input == null) + { + throw new ArgumentNullException(nameof(input)); + } + + // WmsRawmatOutstockD wmsRawmatOutstockD = await _db.Queryable().SingleAsync(x=>x.id==input.requireId); + // WmsRawmatOutstockH wmsRawmatOutstockH = await _db.Queryable().SingleAsync(x=>x.id==wmsRawmatOutstockD.bill_id); + // List wmsCarryCodes = await _db.Queryable() + // .Where(r => r.carry_id == input.wmsDistaskH.carry_id) + // .Where(r => r.material_id == wmsRawmatOutstockD.material_id && r.code_batch == wmsRawmatOutstockD.batchno) + // .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 = wmsRawmatOutstockH.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("ccostdomainoid", null); + // erpRequestData.Add("cdrawcalbodyoid", erpOrg.pk_org); + // erpRequestData.Add("cdrawcalbodyvid", erpOrg.pk_org_v); + // erpRequestData.Add("cdrawwarehouseid", erpOrg.pk_org_v); + // + // erpRequestData.Add("corpoid", erpOrg.corpoid); + // erpRequestData.Add("corpvid", erpOrg.corpvid); + // erpRequestData.Add("cdptid","1001A1100000001JFOPQ");//部门先写死 + // erpRequestData.Add("cdptvid","0001A1100000000AOMIQ");//部门先写死 + // erpRequestData.Add("cotherdptid","1001A1100000001JFOPQ");//部门先写死 + // erpRequestData.Add("cotherdptvid","0001A1100000000AOMIQ");//部门先写死 + // 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/materialOut/self/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(); + + } + + [NonAction] + private async Task GetDetailsAsync(string id) + { + try + { + return await Task.FromResult(_db.Queryable().Where(r => r.bill_id == id).ToList()); + } + catch (Exception ex) + { + return Task.FromResult(ex); + } + } + + /// + /// 下发 + /// + /// + /// + /// + [HttpPost, NonUnify, AllowAnonymous] + public async Task Distribute(RawmatOutstockInput input) + { + try + { + await _s_taskExecuteSemaphore_YCLOutstock.WaitAsync(); + if (string.IsNullOrEmpty(input.source_id)) + { + throw new AppFriendlyException("来源单据id不可为空", 500); + } + if (input.carrys.Count == 0) + { + throw new AppFriendlyException("至少选择一个载具", 500); + } + + WmsRawmatOutstockD wmsRawmatOutstockD = await _db.Queryable().FirstAsync(it => it.id == input.source_id); + WmsRawmatOutstockH wmsRawmatOutstockH = await _db.Queryable().FirstAsync(it => it.id == wmsRawmatOutstockD.bill_id); + + List _items = await _db.Queryable().Where(r => input.carrys.Select(c => c.carry_code).Contains(r.carry_code)).ToListAsync(); + + List wmsCarryCodes = await _db.Queryable().Where(r => _items.Select(c => c.id).Contains(r.carry_id) + && r.material_id == wmsRawmatOutstockD.material_id && r.code_batch == wmsRawmatOutstockD.batchno).ToListAsync(); + + List items = new List(); + + foreach (var carry in input.carrys.Select(c => c.carry_code)) + { + items.Add(_items.Where(r => r.carry_code == carry).First()); + } + + foreach (var item in items) + { + if (item.is_lock == 1) + { + throw new AppFriendlyException($"载具{item.carry_code}已锁定", 500); + } + BasLocation carrryLoc = await _db.Queryable().Where(r => r.id == item.location_id).FirstAsync(); + if (carrryLoc == null || carrryLoc.is_type != "0") + { + throw new Exception($"托盘{item.carry_code}已经不在存储库位中,不能出库!"); + } + } + + decimal? sign_qty = 0; + + decimal qty = wmsCarryCodes.Sum(c => c.codeqty); + if (wmsRawmatOutstockD.actual_outstock_qty + qty > wmsRawmatOutstockD.qty) + { + // 最后一个托盘的数量 + decimal lastCarryQty = wmsCarryCodes.Where(r => r.carry_id == items[items.Count - 1].id).Sum(r => r.codeqty); + // 如果最后一个托盘数量小于超出的出库数量 + if (lastCarryQty < wmsRawmatOutstockD.actual_outstock_qty + qty - wmsRawmatOutstockD.qty) + { + throw new AppFriendlyException($"本次出库数量{qty}已超过可出库数量{wmsRawmatOutstockD.qty - wmsRawmatOutstockD.actual_outstock_qty} 且无需选择{items[items.Count - 1].carry_code}", 500); + } + // 签收数量 + sign_qty = lastCarryQty - (wmsRawmatOutstockD.actual_outstock_qty + qty - wmsRawmatOutstockD.qty); + } + + await _db.Ado.BeginTranAsync(); + + List endLocations = new List(); + + endLocations = _db.Queryable().Where(r => _wareHouseService.GetFloor1YCLDBOutstockLocation().Contains(r.id) && r.is_lock == 0 && r.is_use == "0") + .OrderBy("is_lock, task_nums, location_code").ToList(); + + if (endLocations.Count() < items.Count) + { + throw new AppFriendlyException($@"可用的终点库位数量为{endLocations.Count()}个 下发数量为{items.Count}个 请检查终点库位的锁定和占用状态", 500); + } + + foreach (var wmsCarryH in items) + { + BasLocation startLocation = await _db.Queryable().Where(r => r.id == wmsCarryH.location_id).FirstAsync(); + + BasLocation endLocation = null; + + endLocation = await _db.Queryable().Where(r => _wareHouseService.GetFloor1YCLDBOutstockLocation().Contains(r.id) && r.is_lock == 0 && r.is_use == "0").OrderBy("is_lock, task_nums, location_code").FirstAsync(); + + if (endLocation == null) + { + throw new AppFriendlyException($@"没有可用的终点库位!请检查终点库位的锁定和占用状态", 500); + } + + WmsRawmatOutstockC wmsRawmatOutstockC = new WmsRawmatOutstockC(); + wmsRawmatOutstockC.bill_id = wmsRawmatOutstockH.id; + wmsRawmatOutstockC.mat_bill_id = wmsRawmatOutstockD.id; + wmsRawmatOutstockC.carry_id = wmsCarryH.id; + wmsRawmatOutstockC.carry_code = wmsCarryH.carry_code; + wmsRawmatOutstockC.create_id = input.create_id; + wmsRawmatOutstockC.create_time = DateTime.Now; + wmsRawmatOutstockC.startlocation_id = startLocation.id; + wmsRawmatOutstockC.startlocation_code = startLocation.location_code; + wmsRawmatOutstockC.endlocation_id = endLocation.id; + wmsRawmatOutstockC.endlocation_code = endLocation.location_code; + decimal carryQty = wmsCarryCodes.Where(r => r.carry_id == wmsCarryH.id).Sum(r => r.codeqty); + wmsRawmatOutstockC.qty = carryQty; + wmsRawmatOutstockC.sign_qty = wmsCarryH.id == items[items.Count - 1].id && sign_qty > 0 ? sign_qty : carryQty; + + await _db.Insertable(wmsRawmatOutstockC).ExecuteCommandAsync(); + + CommonCreatePretaskInput commonCreatePretaskInput = new CommonCreatePretaskInput(); + commonCreatePretaskInput.startlocation_id = startLocation.id; + commonCreatePretaskInput.endlocation_id = endLocation.id; + commonCreatePretaskInput.task_type = WmsWareHouseConst.WMS_PRETASK_OUTSTOCK_TYPE_ID; + commonCreatePretaskInput.biz_type = WmsWareHouseConst.BIZTYPE_WmsRawmatOutstock_ID; + commonCreatePretaskInput.source_id = input.source_id; + commonCreatePretaskInput.carry_id = wmsCarryH.id; + commonCreatePretaskInput.carry_code = wmsCarryH.carry_code; + commonCreatePretaskInput.isExcuteMission = false; + + Entities.Dto.Outputs.Result res = await _wareHouseService.CommonCreatePretask(commonCreatePretaskInput, _db); + + if (res.code != HttpStatusCode.OK) + { + Logger.LogInformation($@"生成预任务失败"); + throw new AppFriendlyException($@"生成预任务失败", 500); + } + } + + // 更新子表已下发数量 + await _db.Updateable().SetColumns(r => r.actual_outstock_qty == r.actual_outstock_qty + qty).Where(r => r.id == input.source_id).ExecuteCommandAsync(); + + await _db.Ado.CommitTranAsync(); + } + catch (Exception ex) + { + await _db.Ado.RollbackTranAsync(); + Logger.LogError("【Distribute】" + ex.Message); + Logger.LogError("【Distribute】" + ex.StackTrace); + return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message); + } + finally + { + _ = _s_taskExecuteSemaphore_YCLOutstock.Release(); + InvokeGenPretaskExcute(); + } + + return await ToApiResult(HttpStatusCode.OK, "成功"); + } + + } +} diff --git a/common/Tnb.CollectiveOAuth/Utils/HttpUtils.cs b/common/Tnb.CollectiveOAuth/Utils/HttpUtils.cs index a908e1df..5d7e4d6b 100644 --- a/common/Tnb.CollectiveOAuth/Utils/HttpUtils.cs +++ b/common/Tnb.CollectiveOAuth/Utils/HttpUtils.cs @@ -155,11 +155,15 @@ public class HttpUtils /// /// 地址. /// 请求参数定义. - public static string RequestGet(string url, Dictionary header = null) + public static string RequestGet(string url, Dictionary header = null, int? timeout = null) { StringBuilder builder = new StringBuilder(); builder.Append(url); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(builder.ToString()); + if (timeout != null) + { + request.Timeout = timeout.Value; + } request.ContentType = "application/json;charset=utf-8;"; ComeSetRequestHeader(request, header); return ComeRequestGet(request);