diff --git a/BasicData/Tnb.BasicData.Entities/Dto/SubBomListOutput.cs b/BasicData/Tnb.BasicData.Entities/Dto/SubBomListOutput.cs index f85c64e7..7f382d40 100644 --- a/BasicData/Tnb.BasicData.Entities/Dto/SubBomListOutput.cs +++ b/BasicData/Tnb.BasicData.Entities/Dto/SubBomListOutput.cs @@ -26,7 +26,7 @@ namespace Tnb.BasicData.Entities.Dto /// /// 物料型号 /// - public string material_category_code { get; set; } + public string material_standard { get; set; } /// ///输出数量 /// @@ -44,6 +44,10 @@ namespace Tnb.BasicData.Entities.Dto /// public string bom_id { get; set; } /// + /// 工艺路线id + /// + public string route_id { get; set; } + /// /// 工序id /// public string process_id { get; set; } @@ -56,5 +60,9 @@ namespace Tnb.BasicData.Entities.Dto /// 工艺路线名称 /// public string route_name { get; set; } + /// + /// 工序排序序号 + /// + public long? ordinal { get; set; } } } diff --git a/BasicData/Tnb.BasicData/BasMbomService.cs b/BasicData/Tnb.BasicData/BasMbomService.cs index ef2621e8..b6bc02b4 100644 --- a/BasicData/Tnb.BasicData/BasMbomService.cs +++ b/BasicData/Tnb.BasicData/BasMbomService.cs @@ -155,26 +155,51 @@ namespace Tnb.BasicData { if (string.IsNullOrEmpty(bomId)) throw new ArgumentException($"parameter {nameof(bomId)} not be null or empty"); + var result = await _db.Queryable() - .LeftJoin((a, b) => a.route_id == b.id) - .LeftJoin((a, b, c) => b.id == c.route_id) - .LeftJoin((a, b, c, d) => c.process_id == d.process_id) - .LeftJoin((a, b, c, d, e) => e.mbom_id == a.id && e.mbom_process_id == d.id) - .Where((a, b, c, d, e) => a.id == bomId && a.material_id != e.material_id && !string.IsNullOrEmpty(e.material_id)) - .Select((a, b, c, d, e) => new SubBomListOutput - { - version = a.version, - unit_id = a.unit_id, - route_name = b.name, - process_id = c.process_id, - material_id = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.id), - material_code = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.code), - material_name = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.name), - material_category_code = "", - num = e.num, - }) - .Mapper(it => it.output_qty = it.num.ParseToInt()) - .ToListAsync(); + .LeftJoin((a, b) => a.id == b.mbom_id) + .LeftJoin((a, b, c) => a.route_id == c.id) + .LeftJoin((a, b, c, d) => b.process_id == d.process_id && c.id == d.route_id) + .LeftJoin((a, b, c, d, e) => a.id == e.mbom_id && e.mbom_process_id == b.id) + .Where((a, b, c, d, e) => a.id == bomId) + .Select((a, b, c, d, e) => new SubBomListOutput + { + version = a.version, + unit_id = a.unit_id, + route_name = c.name, + process_id = b.process_id, + material_id = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.id), + material_code = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.code), + material_name = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.name), + material_standard = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.material_standard), + num = e.num, + ordinal = d.ordinal, + }) + .Mapper(it => it.output_qty = it.num.ParseToInt()) + .ToListAsync(); + #region 注释代码 + //var result = await _db.Queryable() + // .LeftJoin((a, b) => a.route_id == b.id) + // .LeftJoin((a, b, c) => b.id == c.route_id) + // .LeftJoin((a, b, c, d) => c.process_id == d.process_id) + // .LeftJoin((a, b, c, d, e) => e.mbom_id == a.id && e.mbom_process_id == d.id) + // .Where((a, b, c, d, e) => a.id == bomId && a.material_id != e.material_id && !string.IsNullOrEmpty(e.material_id)) + + // .Select((a, b, c, d, e) => new SubBomListOutput + // { + // version = a.version, + // unit_id = a.unit_id, + // route_name = b.name, + // process_id = c.process_id, + // material_id = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.id), + // material_code = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.code), + // material_name = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.name), + // material_standard = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.material_standard), + // num = e.num, + // }) + // .Mapper(it => it.output_qty = it.num.ParseToInt()) + // .ToListAsync(); + #endregion return result; } @@ -198,7 +223,6 @@ namespace Tnb.BasicData [HttpGet] public async Task GetMBomListByMaterialId([FromRoute] string materialId) { - return await _db.Queryable() .LeftJoin((a, b) => a.material_id == b.id) .LeftJoin((a, b, c) => a.route_id == c.id) diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSchedlingCrInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSchedlingCrInput.cs index ad2901da..fe5d7e06 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSchedlingCrInput.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSchedlingCrInput.cs @@ -31,7 +31,7 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage /// /// 排产数量 /// - public string scheduled_qty { get; set; } + public int scheduled_qty { get; set; } /// /// Desc:预计开始时间 diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSechelToBeIssueListOutput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSechelToBeIssueListOutput.cs index 9eedff4b..08bc9117 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSechelToBeIssueListOutput.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSechelToBeIssueListOutput.cs @@ -21,6 +21,10 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage /// public string mo_task_code { get; set; } /// + /// 物料id + /// + public string material_id { get; set; } + /// /// 物料编号 /// public string material_code { get; set; } diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs index 7be62097..e685cf04 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs @@ -381,7 +381,7 @@ namespace Tnb.ProductionMgr result = await _db.Queryable().LeftJoin((a, b) => a.mo_id == b.id) .LeftJoin((a, b, c) => a.material_id == c.id) .LeftJoin((a, b, c, d) => a.workline_id == d.Id) - .Where((a, b, c, d) => a.mo_id == moId) + .Where((a, b, c, d) => a.mo_id == moId && string.IsNullOrEmpty(a.parent_id)) .Select((a, b, c, d) => new PrdMoTaskOutput { mo_task_code = a.mo_task_code, @@ -414,28 +414,29 @@ namespace Tnb.ProductionMgr public async Task GetPackScheldToBeIssueList([FromQuery] PackScheldToBeIssueListInput input) { var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId); - var result = await _db.Queryable().Where(it => it.schedule_type == 2) - .LeftJoin((a, b) => a.material_id == b.id) - .LeftJoin((a, b, c) => a.workline_id == c.Id) - .LeftJoin((a, b, c, d) => a.mo_id == d.id) - .LeftJoin((a, b, c, d, e) => a.bom_id == e.id) - .WhereIF(!string.IsNullOrEmpty(input.mo_task_code), (a, b, c, d, e) => a.mo_task_code.Contains(input.mo_task_code)) - .Select((a, b, c, d, e) => new PackSechelToBeIssueListOutput + var result = await _db.Queryable() + .LeftJoin((a, b) => a.workline_id == b.Id) + .LeftJoin((a, b, c) => a.mo_id == c.id) + .LeftJoin((a, b, c, d) => a.bom_id == d.id) + .WhereIF(!string.IsNullOrEmpty(input.mo_task_code), (a, b, c, d) => a.mo_task_code.Contains(input.mo_task_code)) + .Where((a, b, c, d) => a.schedule_type == 2 && string.IsNullOrEmpty(a.parent_id)) + .Select((a, b, c, d) => new PackSechelToBeIssueListOutput { mo_task_id = a.id, mo_task_code = a.mo_task_code, - material_code = b.code, - material_name = b.name, + material_id = a.material_id, + material_code = SqlFunc.Subqueryable().Where(it => it.id == a.material_id).Select(it => it.code), + material_name = SqlFunc.Subqueryable().Where(it => it.id == a.material_id).Select(it => it.name), workline_id = a.workline_id, - workline_code = c.EnCode, - workline_name = c.FullName, + workline_code = b.EnCode, + workline_name = b.FullName, mo_task_status = a.mo_task_status, - scheduled_qty = a.scheduled_qty, - plan_qty = d.plan_qty, + scheduled_qty = SqlFunc.Subqueryable().Where(it => it.mo_id == a.mo_id).Sum(it => it.scheduled_qty), + plan_qty = SqlFunc.Subqueryable().Where(it => it.id == a.mo_id).Select(it => it.plan_qty), estimated_start_date = a.estimated_start_date, estimated_end_date = a.estimated_end_date, - bom_id = e.id, - bom_version = e.version + bom_id = d.id, + bom_version = d.version }) .Mapper(it => it.mo_task_status = dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString()! : "") .ToListAsync(); @@ -467,8 +468,10 @@ namespace Tnb.ProductionMgr scheduled_qty = a.scheduled_qty, plan_qty = d.plan_qty, process_task_qty = a.process_task_qty, + bom_version = SqlFunc.Subqueryable().Where(it => it.material_id == a.material_id).Select(it => it.version) }) .Mapper(it => it.mo_task_status = dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString()! : "") + .OrderBy(a => a.mo_task_code, OrderByType.Asc) .ToListAsync(); return result; } @@ -692,18 +695,21 @@ namespace Tnb.ProductionMgr var moTask = input.Adapt(); moTask.id = SnowflakeIdHelper.NextId(); moTask.create_id = _userManager.UserId; + moTask.bom_id = input.bom_id; + moTask.workline_id = input.workline_id; moTask.create_time = DateTime.Now; moTask.schedule_type = 2; moTask.mo_task_status = DictConst.ToBeScheduledEncode; moTask.estimated_start_date = input.estimated_start_date; moTask.estimated_end_date = input.estimated_end_date; + moTask.scheduled_qty = input.scheduled_qty; var mo = await _db.Queryable().FirstAsync(it => it.id == input.mo_id); var moCode = mo?.mo_code; - var taskCode = await _db.Queryable().Where(it => !string.IsNullOrEmpty(it.mo_task_code) && it.mo_task_code.Contains(moCode)) + var taskCode = await _db.Queryable().Where(it => string.IsNullOrEmpty(it.parent_id) && !string.IsNullOrEmpty(it.mo_task_code) && it.mo_task_code.Contains(moCode)) .OrderByDescending(it => it.mo_task_code) .Select(it => it.mo_task_code) .FirstAsync(); - if (taskCode!.IsNullOrEmpty()) + if (taskCode is null || taskCode.IsNullOrEmpty()) { moTask.mo_task_code = $"{moCode}-01"; } @@ -771,51 +777,98 @@ namespace Tnb.ProductionMgr } //根据生产bomId 拆解生产子任务 var outputList = new List(); - var bom = await _db.Queryable().FirstAsync(it => it.id == input.bom_id); - if (bom != null && bom.route_id.IsNotEmptyOrNull()) + var subTaskList = await _db.Queryable() + .LeftJoin((a, b) => a.id == b.mbom_id) + .LeftJoin((a, b, c) => a.route_id == c.id) + .LeftJoin((a, b, c, d) => b.process_id == d.process_id && c.id == d.route_id) + .LeftJoin((a, b, c, d, e) => a.id == e.mbom_id && e.mbom_process_id == b.id) + .Where((a, b, c, d, e) => a.id == input.bom_id && d.ordinal < SqlFunc.Subqueryable().Where(it => it.route_id == a.route_id).OrderByDesc(it => it.ordinal).Select(it => it.ordinal)) + .Select((a, b, c, d, e) => new SubBomListOutput + { + version = a.version, + unit_id = a.unit_id, + route_id = c.id, + route_name = c.name, + process_id = b.process_id, + material_id = SqlFunc.Subqueryable().Where(it => it.id == e.material_id).Select(it => it.id), + num = e.num, + ordinal = d.ordinal, + }) + .Mapper(it => it.output_qty = it.num.ParseToInt()) + .ToListAsync(); + + if (subTaskList?.Count > 0) { - var routes = await _db.Queryable().Where(it => it.route_id == bom.route_id).ToListAsync(); - if (routes?.Count > 0) + List subMoTasks = new(); + foreach (var item in subTaskList) { - var processIds = routes.Select(x => x.process_id).ToList(); - if (processIds?.Count > 0) + PrdMoTask subMoTask = new(); + subMoTask.schedule_type = 2; + subMoTask.mo_task_status = DictConst.ToBeScheduledEncode; + subMoTask.parent_id = moTask.id; + subMoTask.mo_id = input.mo_id; + //subMoTask.bom_id = input.bom_id; + subMoTask.workline_id = input.workline_id; + subMoTask.material_id = item.material_id; + subMoTask.workroute_id = item.route_id; + subMoTask.scheduled_qty = item.output_qty * moTask.scheduled_qty; + subMoTask.process_task_qty = item.output_qty * moTask.scheduled_qty; + subMoTask.estimated_start_date = input.estimated_start_date; + subMoTask.estimated_end_date = input.estimated_end_date; + subMoTask.create_id = _userManager.UserId; + subMoTask.create_time = DateTime.Now; + subMoTasks.Add(subMoTask); + } + //根据生产任务编号生成子任务编号 + if (moTask.mo_task_code!.IsNotEmptyOrNull()) + { + for (int i = 1; i <= subMoTasks.Count; i++) { - var bomOutputs = await _db.Queryable().Where(it => processIds.Contains(it.process_id)).ToListAsync(); - if (bomOutputs?.Count > 0) - { - List subMoTasks = new(); - foreach (var item in bomOutputs) - { - var material = await _db.Queryable().FirstAsync(it => it.id == item.material_id); - PrdMoTask subMoTask = new(); - subMoTask.id = SnowflakeIdHelper.NextId(); - subMoTask.schedule_type = 2; - subMoTask.parent_id = moTask.id; - subMoTask.bom_id = input.bom_id; - subMoTask.mo_task_status = DictConst.ToBeScheduledEncode; - subMoTask.workline_id = input.workline_id; - subMoTask.material_id = item.material_id; - subMoTask.process_task_qty = item.num.ParseToInt() * moTask.scheduled_qty; - subMoTask.estimated_start_date = input.estimated_start_date; - subMoTask.estimated_end_date = input.estimated_end_date; - subMoTask.create_id = _userManager.UserId; - subMoTask.create_time = DateTime.Now; - subMoTasks.Add(subMoTask); - } - //根据生产任务编号生成子任务编号 - if (moTask.mo_task_code!.IsNotEmptyOrNull()) - { - for (int i = 1; i <= subMoTasks.Count; i++) - { - string n = i.ToString(); - subMoTasks[i - 1].mo_task_code = $"{moTask.mo_task_code}-{n.PadLeft(2, '0')}"; - } - } - row = await _db.Insertable(subMoTasks).ExecuteCommandAsync(); - } + string n = i.ToString(); + subMoTasks[i - 1].mo_task_code = $"{moTask.mo_task_code}-{n.PadLeft(2, '0')}"; } } + row = await _db.Insertable(subMoTasks).ExecuteCommandAsync(); } + #region 注释代码 + //var bom = await _db.Queryable().FirstAsync(it => it.id == input.bom_id); + //if (bom != null && bom.route_id.IsNotEmptyOrNull()) + //{ + // var mbomProcesses = await _db.Queryable().Where(it => it.mbom_id == bom.id).ToListAsync(); + // var routes = await _db.Queryable().Where(it => it.route_id == bom.route_id).ToListAsync(); + // if (routes?.Count > 0) + // { + // var processIds = routes.Select(x => x.process_id).ToList(); + // if (processIds?.Count > 0) + // { + // var bomOutputs = await _db.Queryable().Where(it => processIds.Contains(it.process_id)).ToListAsync(); + // if (bomOutputs?.Count > 0) + // { + // List subMoTasks = new(); + // foreach (var item in bomOutputs) + // { + // var material = await _db.Queryable().FirstAsync(it => it.id == item.material_id); + // PrdMoTask subMoTask = new(); + // subMoTask.id = SnowflakeIdHelper.NextId(); + // subMoTask.schedule_type = 2; + // subMoTask.parent_id = moTask.id; + // subMoTask.bom_id = input.bom_id; + // subMoTask.mo_task_status = DictConst.ToBeScheduledEncode; + // subMoTask.workline_id = input.workline_id; + // subMoTask.material_id = item.material_id; + // subMoTask.process_task_qty = item.num.ParseToInt() * moTask.scheduled_qty; + // subMoTask.estimated_start_date = input.estimated_start_date; + // subMoTask.estimated_end_date = input.estimated_end_date; + // subMoTask.create_id = _userManager.UserId; + // subMoTask.create_time = DateTime.Now; + // subMoTasks.Add(subMoTask); + // } + // } + // } + // } + //} + #endregion + await _db.Ado.CommitTranAsync(); } catch (Exception ex) @@ -1142,7 +1195,7 @@ namespace Tnb.ProductionMgr .Where((a, b, c) => a.id == input.bom_id && input.ids.Contains(b.process_id)) .Select((a, b, c) => new { - material_id = a.material_id, + material_id = c.material_id, num = c.num, }) .ToListAsync(); @@ -1151,35 +1204,37 @@ namespace Tnb.ProductionMgr { var mids = await _db.Queryable().Where(it => it.id == input.mo_id).Select(it => it.material_id).ToListAsync(); var ids = outMaterials.Select(x => x.material_id).Except(mids).ToList(); - var dicOutMaterialNum = outMaterials.ToDictionary(x => x.material_id, x => x.num.ParseToInt()); - List subMoList = new(); - var outputMaterials = await _db.Queryable().Where(it => ids.Contains(it.id)).ToListAsync(); - foreach (var om in outputMaterials) + if (ids?.Count > 0) { - PrdMo subMo = new(); - subMo.material_id = om.id; - subMo.material_code = om.code; - subMo.plan_qty = dicOutMaterialNum.ContainsKey(om.id) ? dicOutMaterialNum[om.id] * curMo.plan_qty : 0; - subMo.mo_type = curMo.mo_type; - subMo.parent_id = curMo.id; - subMo.plan_start_date = curMo.plan_start_date; - subMo.plan_end_date = curMo.plan_end_date; - subMo.create_id = _userManager.UserId; - subMo.create_time = DateTime.Now; - subMo.mo_status = DictConst.WaitProductId; - subMoList.Add(subMo); + var dicOutMaterialNum = outMaterials.ToDictionary(x => x.material_id, x => x.num.ParseToInt()); + List subMoList = new(); + var outputMaterials = await _db.Queryable().Where(it => ids.Contains(it.id)).ToListAsync(); + foreach (var om in outputMaterials) + { + PrdMo subMo = new(); + subMo.material_id = om.id; + subMo.material_code = om.code; + subMo.plan_qty = dicOutMaterialNum.ContainsKey(om.id) ? dicOutMaterialNum[om.id] * curMo.plan_qty : 0; + subMo.mo_type = curMo.mo_type; + subMo.parent_id = curMo.id; + subMo.plan_start_date = curMo.plan_start_date; + subMo.plan_end_date = curMo.plan_end_date; + subMo.create_id = _userManager.UserId; + subMo.create_time = DateTime.Now; + subMo.mo_status = DictConst.WaitProductId; + subMoList.Add(subMo); + } + //生成子工单编码 + for (int i = 0; i < subMoList.Count; i++) + { + var num = (i + 1).ToString().PadLeft(2, '0'); + subMoList[i].mo_code = $"{curMo.mo_code}-{num}"; + } + var row = await _db.Insertable(subMoList).ExecuteCommandAsync(); + if (row < 1) throw Oops.Oh(ErrorCode.COM1000); } - //生成子工单编码 - for (int i = 0; i < subMoList.Count; i++) - { - var num = (i + 1).ToString().PadLeft(2, '0'); - subMoList[i].mo_code = $"{curMo.mo_code}-{num}"; - } - var row = await _db.Insertable(subMoList).ExecuteCommandAsync(); - if (row < 1) throw Oops.Oh(ErrorCode.COM1000); + } - - } @@ -1208,7 +1263,6 @@ namespace Tnb.ProductionMgr properies = instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).Select(p => p.Name).ToArray(); dicProperties[name] = properies; } - //var properies = instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).Select(p => p.Name).ToArray(); foreach (var pn in properies) { if (dictionary.ContainsKey(pn)) @@ -1218,10 +1272,6 @@ namespace Tnb.ProductionMgr } return instance; } - - - - private async Task GetList(VisualDevModelListQueryInput input) { var db = _repository.AsSugarClient();