diff --git a/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs b/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs index b8cd6297..e4035d79 100644 --- a/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs +++ b/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs @@ -30,7 +30,7 @@ public static class DictConst /// /// 注塑工单 /// - public const string PrdMoTypeZS = "25572555259157"; + public const string PrdMoTypeZS = "25019163616533"; /// /// 挤出工单 /// diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoFromOneListOutput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoFromOneListOutput.cs index 5f235c1b..b8de7235 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoFromOneListOutput.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoFromOneListOutput.cs @@ -23,6 +23,11 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage public string? act_start_date { get; set; } public string? act_end_date { get; set; } + + /// + /// 类型 1注塑挤出 2 组装包装 + /// + public int type { get; set; } } @@ -137,7 +142,7 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage } - public class PrdMoReverseFromMaterialOutput + public class PrdMoReverseFromMaterialput { /// /// 物料ID @@ -237,4 +242,80 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage public string process_name { get; set; } } + + public class PrdMoReverseFromOutput + { + /// + /// 物料ID + /// + public string material_id { get; set; } + /// + /// 物料编号 + /// + public string material_code { get; set; } + /// + /// 物料编号 + /// + public string material_name { get; set; } + /// 条码数量 + /// + public decimal barcode_qty { get; set; } + /// + /// 批次 + /// + public string code_batch { get; set;} + /// + /// 单位ID + /// + public string unit_id { get; set; } + /// + /// 入库单号 + /// + public string in_bill_code { get; set; } + /// + /// 入库时间 + /// + public DateTime instock_time { get; set; } + /// + /// 出库单号 + /// + public string out_bill_code { get; set; } + /// + /// 出库时间 + /// + public DateTime? outstock_time { get; set; } + /// + /// 仓库ID + /// + public string warehouse_id { get; set; } + /// + /// 仓库名称 + /// + public string warehouse_name { get; set; } + /// + /// 库位ID + /// + public string location_id { get; set; } + /// + /// 库位编号 + /// + public string location_code { get; set; } + /// + /// 物料状态 + /// + public string material_status { get; set; } + /// + /// 销售出库单号 + /// + public string sale_outstock_code { get; set; } + /// + /// 客户名称 + /// + public string customer_name { get; set; } + /// + /// 发货时间 + /// + public string delivery_time { get; set; } + } + } \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs index 78ba69d1..3b048952 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs @@ -407,6 +407,7 @@ namespace Tnb.ProductionMgr id = a.id, mo_code = a.mo_code, material_id = a.material_id, + type = (a.mo_type==DictConst.PrdMoTypeZS || a.mo_type==DictConst.PrdMoTypeJC ) ? 1 : 2, material_code = b.code, material_name = b.name, material_standard = b.material_standard, @@ -870,7 +871,7 @@ namespace Tnb.ProductionMgr } else { - PageResult output = JsonConvert.DeserializeObject>(authResponse.data.ToString(),new Tnb.Common.Utils.DateTimeJsonConverter()); + PageResult output = JsonConvert.DeserializeObject>(authResponse.data.ToString(),new Tnb.Common.Utils.DateTimeJsonConverter()); if (output.list != null && output.list.Count > 0) { output.list[0].feeding_num = await _db.Queryable() @@ -931,7 +932,7 @@ namespace Tnb.ProductionMgr } /// - /// 物料反向追溯查出信息 + /// 物料反向追溯产出信息 /// /// /// @@ -939,8 +940,123 @@ namespace Tnb.ProductionMgr public async Task PrdMoReverseFromOutInfo(Dictionary dic) { string feeding_detail_id = dic.ContainsKey("feeding_detail_id") ? dic["feeding_detail_id"] : ""; - - return null; + PrdFeedingD prdFeedingD = await _db.Queryable().FirstAsync(x => x.id == feeding_detail_id); + if(prdFeedingD.use_num<=0) return Array.Empty(); + PrdFeedingH prdFeedingH = await _db.Queryable().FirstAsync(x => x.id == prdFeedingD.feeding_id); + PrdMoTask prdMoTask = await _db.Queryable().FirstAsync(x => x.id == prdFeedingH.mo_task_id); + List prdFeedingDs = await _db.Queryable() + .LeftJoin((a, b) => a.feeding_id == b.id) + .Where((a, b) => a.material_id == prdFeedingD.material_id && b.mo_task_id == prdFeedingH.mo_task_id && b.create_time<=prdFeedingH.create_time && a.id!=prdFeedingD.id) + .Select((a, b) => a).ToListAsync(); + decimal beforeIn = prdFeedingDs.Sum(x => x.num); + List reportIds = new List(); + if (prdMoTask.schedule_type == 1) + { + BasEbomH basEbomH = await _db.Queryable().SingleAsync(x => x.id == prdMoTask.ebom_id); + List basEbomDs = await _db.Queryable().Where(x => x.ebom_id == prdMoTask.ebom_id).ToListAsync(); + BasEbomD basEbomD = basEbomDs.Where(x => x.material_id == prdFeedingD.material_id).FirstOrDefault(); + if (basEbomD != null) + { + List prdReports = await _db.Queryable().Where(x => x.mo_task_id == prdMoTask.id).OrderBy(x=>x.create_time).ToListAsync(); + if (prdReports != null && prdReports.Count > 0) + { + bool flag = true; + decimal residueNeed = 0; + foreach (var prdReport in prdReports) + { + var needNum = (prdReport.reported_qty ?? 0) / basEbomH.quantity * basEbomD.quantity; + if (beforeIn - needNum >= 0) + { + beforeIn -= needNum; + } + else + { + if (flag) + { + if (prdFeedingD.num > needNum - beforeIn) + { + residueNeed = prdFeedingD.num - (needNum - beforeIn); + reportIds.Add(prdReport.id); + } + else + { + reportIds.Add(prdReport.id); + break; + } + + flag = false; + continue; + + } + + if (residueNeed - needNum > 0) + { + residueNeed -= needNum; + reportIds.Add(prdReport.id); + }else + { + reportIds.Add(prdReport.id); + break; + } + } + } + } + else + { + return Array.Empty(); + } + } + else + { + return Array.Empty(); + } + + + List barCodes = await _db.Queryable().Where(x=>reportIds.Contains(x.id)).Select(x=>x.barcode).ToListAsync(); + + string domain = (App.HttpContext.Request.IsHttps ? "https://" : "http://") + App.HttpContext.Request.Host; + Dictionary header = new Dictionary() + { + ["Authorization"] = App.HttpContext.Request.Headers["Authorization"] + }; + Dictionary postData = new Dictionary() + { + ["org_id"] = _userManager.GetUserInfo().Result.organizeId, + ["barcode"] = barCodes, + ["currentPage"] = 1, + ["pageSize"] = int.MaxValue, + }; + var sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_FETCH_IN_OUT_STOCK_INFO_BY_BAR_CODE,JsonConvert.SerializeObject(postData),header); + Log.Information(sendResult); + + AuthResponse authResponse = JsonConvert.DeserializeObject(sendResult); + if (authResponse.code != 200) + { + throw Oops.Bah(authResponse.msg); + } + else + { + BasMaterial basMaterial = await _db.Queryable().FirstAsync(x => x.id == prdMoTask.material_id); + PageResult output = JsonConvert.DeserializeObject>(authResponse.data.ToString(),new Tnb.Common.Utils.DateTimeJsonConverter()); + if (output.list != null && output.list.Count > 0) + { + foreach (var item in output.list) + { + item.material_name = basMaterial.name; + } + } + + return output.list; + } + } + else + { + // var queryable = _db.Queryable() + // .LeftJoin((a,b)=>a.mbom_process_id==b.id) + // .LeftJoin((a,b,c)=>a.id==c.mo_task_id) + // .Where((a,b,c)=>a.) + return null; + } } #endregion