From c6522831b46b6089f5d08b93acf618d872b40682 Mon Sep 17 00:00:00 2001 From: "DEVICE8\\12494" Date: Sun, 28 May 2023 21:17:49 +0800 Subject: [PATCH] 1 --- .../Consts/DictConst.cs | 5 +- BasicData/Tnb.BasicData/BasMbomService.cs | 24 +- .../Dto/PrdManage/PackReportTreeOutput.cs | 157 +++++++++ .../Dto/PrdManage/PrdPackReportQueryInput.cs | 18 + .../Dto/PrdManage/PrdReportOutput.cs | 2 + .../Entity/PrdMoTask.part.cs | 15 + .../Entity/PrdMoTaskDefectRecord.cs | 4 +- .../Entity/PrdReportRecord.cs | 12 +- .../IPrdPackReportService.cs | 15 + .../PrdMoTaskIssueService.cs | 3 + .../Tnb.ProductionMgr/PrdMoTaskService.cs | 329 ++++++++++-------- .../Tnb.ProductionMgr/PrdPackReportService.cs | 159 +++++++++ .../Tnb.ProductionMgr/PrdTaskManageService.cs | 17 +- .../ProductionReportRecordService.cs | 50 +-- 14 files changed, 621 insertions(+), 189 deletions(-) create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackReportTreeOutput.cs create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdPackReportQueryInput.cs create mode 100644 ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdPackReportService.cs create mode 100644 ProductionMgr/Tnb.ProductionMgr/PrdPackReportService.cs diff --git a/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs b/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs index c2d54a15..f110eb49 100644 --- a/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs +++ b/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs @@ -19,7 +19,10 @@ public static class DictConst /// 生产任务状态TypeId /// public const string PrdTaskStatusTypeId = "25572555259157"; - + /// + /// 生产工单类型TypeId + /// + public const string PrdMoTypeTypeId = "25019155728149"; /// /// 工单状态-已排产 diff --git a/BasicData/Tnb.BasicData/BasMbomService.cs b/BasicData/Tnb.BasicData/BasMbomService.cs index b6bc02b4..f92b105c 100644 --- a/BasicData/Tnb.BasicData/BasMbomService.cs +++ b/BasicData/Tnb.BasicData/BasMbomService.cs @@ -177,29 +177,7 @@ namespace Tnb.BasicData }) .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; } diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackReportTreeOutput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackReportTreeOutput.cs new file mode 100644 index 00000000..0cd3de9f --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackReportTreeOutput.cs @@ -0,0 +1,157 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JNPF.Common.Security; + +namespace Tnb.ProductionMgr.Entities.Dto.PrdManage +{ + /// + /// 组装、包装,生产任务管理树形输出类 + /// + public class PackReportTreeOutput : TreeModel + { + /// + /// 生产任务编号 + /// + public string? mo_task_code { get; set; } + + /// + /// 工单Id + /// + public string? mo_id { get; set; } + + /// + /// 物料Id + /// + public string? material_id { get; set; } + /// + /// 产线id + /// + public string? workline_id { get; set; } + + /// + /// 工位id + /// + public string? workstation_id { get; set; } + + /// + /// 工艺路线id + /// + public string? workroute_id { get; set; } + + /// + /// 生产bom id + /// + public string? bom_id { get; set; } + + /// + /// 任务单状态 + /// + public string? mo_task_status { get; set; } + + /// + /// 计划数量 + /// + public int? plan_qty { get; set; } + + /// + /// 已投入数量 + /// + public int? input_qty { get; set; } + + /// + /// 已完工数量 + /// + public int? complete_qty { get; set; } + + /// + /// 报废数量 + /// + public int? scrap_qty { get; set; } + + /// + /// 已排产数量 + /// + public int? scheduled_qty { get; set; } + + /// + /// 排产类型:1、注塑、挤出2、组装、包装 + /// + public int? schedule_type { get; set; } + + /// + /// 计划开始时间 + /// + public string plan_start_date { get; set; } + + /// + /// 计划结束时间 + /// + public string plan_end_date { get; set; } + + /// + /// 实际开工日期 + /// + public DateTime? act_start_date { get; set; } + + /// + /// 实际完工日期 + /// + public DateTime? act_end_date { get; set; } + + /// + /// 创建人 + /// + public string? create_id { get; set; } + + /// + /// 创建时间 + /// + public DateTime? create_time { get; set; } + + /// + /// 修改人 + /// + public string? modify_id { get; set; } + + /// + /// 修改时间 + /// + public DateTime? modify_time { get; set; } + + /// + /// 扩展字段 + /// + public string? extras { get; set; } + + /// + /// 生产顺序 + /// + public int? prd_order { get; set; } + + /// + /// 预计开始时间 + /// + public DateTime? estimated_start_date { get; set; } + + /// + /// 预计结束时间 + /// + public DateTime? estimated_end_date { get; set; } + /// + /// 父任务Id + /// + public string? parent_id { get; set; } + + /// + /// 工序任务量 + /// + public int? process_task_qty { get; set; } + /// + /// 工序id + /// + public string process_id { get; set; } + } +} diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdPackReportQueryInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdPackReportQueryInput.cs new file mode 100644 index 00000000..5d32519b --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdPackReportQueryInput.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JNPF.Common.Filter; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace Tnb.ProductionMgr.Entities.Dto.PrdManage +{ + public class PrdPackReportQueryInput : PageInputBase + { + /// + /// 生产任务编号 + /// + public string mo_task_code { get; set; } + } +} diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdReportOutput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdReportOutput.cs index 2de1be86..779e1b82 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdReportOutput.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdReportOutput.cs @@ -46,5 +46,7 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage /// 物料属性 /// public string material_property { get; set; } + + } } diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTask.part.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTask.part.cs index 4fef7dff..77b52b81 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTask.part.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTask.part.cs @@ -70,5 +70,20 @@ namespace Tnb.ProductionMgr.Entities /// [SugarColumn(IsIgnore = true)] public string material_property { get; set; } + /// + /// 工序名称 + /// + [SugarColumn(IsIgnore = true)] + public string process_name { get; set; } + /// + /// 工序编码 + /// + [SugarColumn(IsIgnore = true)] + public string process_code { get; set; } + /// + /// 产线编码 + /// + [SugarColumn(IsIgnore = true)] + public string workline_code { get; set; } } } diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTaskDefectRecord.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTaskDefectRecord.cs index eaa4c58c..6d06db85 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTaskDefectRecord.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTaskDefectRecord.cs @@ -52,7 +52,7 @@ public partial class PrdMoTaskDefectRecord : BaseEntity /// /// 报废数量 /// - public int? scrap_qty { get; set; } + public int scrap_qty { get; set; } /// /// 生产任务单状态 @@ -81,6 +81,6 @@ public partial class PrdMoTaskDefectRecord : BaseEntity /// /// 任务类型 /// - public int mo_task_type { get; set; } + public string mo_task_type { get; set; } } diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdReportRecord.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdReportRecord.cs index ba5bdc0b..7ed330d8 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdReportRecord.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdReportRecord.cs @@ -47,7 +47,7 @@ public partial class PrdReportRecord : BaseEntity /// /// 完成数量 /// - public int? completed_qty { get; set; } + public int completed_qty { get; set; } /// /// 任务单号 @@ -60,5 +60,13 @@ public partial class PrdReportRecord : BaseEntity /// /// 任务类型 /// - public int mo_task_type { get; set; } + public string mo_task_type { get; set; } + /// + /// 生产任务id + /// + public string mo_task_id { get; set; } + /// + /// 已报工数量 + /// + public int reported_work_qty { get; set; } } diff --git a/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdPackReportService.cs b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdPackReportService.cs new file mode 100644 index 00000000..c901ed4b --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IPrdPackReportService.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.ProductionMgr.Interfaces +{ + /// + /// 组装、包装 生产提报接口 + /// + public interface IPrdPackReportService + { + } +} diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskIssueService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskIssueService.cs index eb9b1f2e..28190f8d 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskIssueService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskIssueService.cs @@ -19,6 +19,7 @@ using Tnb.ProductionMgr.Entities; using Tnb.ProductionMgr.Interfaces; using Aspose.Cells.Drawing; using Microsoft.AspNetCore.Mvc; +using JNPF.Common.Extension; namespace Tnb.ProductionMgr { @@ -52,6 +53,8 @@ namespace Tnb.ProductionMgr var data = await _runService.GetListResult(templateEntity, input); if (data?.list?.Count > 0) { + var scheduledTypeField = nameof(PrdMoTask.schedule_type); + data.list = data.list.Where(it => it[scheduledTypeField].IsNotEmptyOrNull() && it[scheduledTypeField].ParseToInt() == 1).ToList(); foreach (var row in data.list) { var dic = row.ToDictionary(x => x.Key, x => x.Value); diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs index b552c4bf..34116c7c 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs @@ -589,22 +589,22 @@ namespace Tnb.ProductionMgr await db.Insertable(taskLog).ExecuteCommandAsync(); //将生产任务插入到自检报废记录表 - var sacipRecord = new PrdMoTaskDefectRecord(); - sacipRecord.id = SnowflakeIdHelper.NextId(); - sacipRecord.material_code = material?.code!; - sacipRecord.material_name = material?.name!; - sacipRecord.eqp_code = (await db.Queryable().FirstAsync(it => it.id == moTask.eqp_id))?.code!; - sacipRecord.mold_name = (await db.Queryable().FirstAsync(it => it.id == moTask.mold_id))?.mold_name!; - sacipRecord.estimated_start_date = moTask.plan_start_date; - sacipRecord.estimated_end_date = moTask.plan_end_date; - sacipRecord.plan_qty = moTask.plan_qty; - sacipRecord.scrap_qty = moTask.scrap_qty; - sacipRecord.status = moTask.mo_task_status; - sacipRecord.create_id = _userManager.UserId; - sacipRecord.create_time = DateTime.Now; - sacipRecord.mo_task_id = moTask.id; - sacipRecord.mo_task_code = moTask.mo_task_code; - await db.Insertable(sacipRecord).ExecuteCommandAsync(); + //var sacipRecord = new PrdMoTaskDefectRecord(); + //sacipRecord.id = SnowflakeIdHelper.NextId(); + //sacipRecord.material_code = material?.code!; + //sacipRecord.material_name = material?.name!; + //sacipRecord.eqp_code = (await db.Queryable().FirstAsync(it => it.id == moTask.eqp_id))?.code!; + //sacipRecord.mold_name = (await db.Queryable().FirstAsync(it => it.id == moTask.mold_id))?.mold_name!; + //sacipRecord.estimated_start_date = moTask.plan_start_date; + //sacipRecord.estimated_end_date = moTask.plan_end_date; + //sacipRecord.plan_qty = moTask.plan_qty; + //sacipRecord.scrap_qty = moTask.scrap_qty; + //sacipRecord.status = moTask.mo_task_status; + //sacipRecord.create_id = _userManager.UserId; + //sacipRecord.create_time = DateTime.Now; + //sacipRecord.mo_task_id = moTask.id; + //sacipRecord.mo_task_code = moTask.mo_task_code; + //await db.Insertable(sacipRecord).ExecuteCommandAsync(); await db.Ado.CommitTranAsync(); } @@ -804,102 +804,164 @@ namespace Tnb.ProductionMgr { throw new ArgumentException($"{nameof(input.Behavior)} not be null or empty"); } - string SetTaskStatus(PrdTaskBehavior behavior) => behavior switch + var taskList = await _db.Queryable().Where(it => input.TaskIds.Contains(it.id) && it.mo_task_status == DictConst.ToBeScheduledEncode).ToListAsync(); + if (taskList?.Count > 0) { - PrdTaskBehavior.Release => DictConst.ToBeStartedEnCode, - PrdTaskBehavior.Start => DictConst.InProgressEnCode, - PrdTaskBehavior.Closed => DictConst.ClosedEnCode, - PrdTaskBehavior.Compled => DictConst.ComplatedEnCode, - _ => throw new NotImplementedException(), - }; - PrdTaskBehavior behavior = input.Behavior.ToEnum(); - var status = SetTaskStatus(behavior); - var db = _repository.AsSugarClient(); - var list = await db.Queryable().Where(it => input.TaskIds.Contains(it.id)).Select(it => it).ToListAsync(); - if (behavior == PrdTaskBehavior.Compled) - { - - if (list?.Count > 0) + string SetTaskStatus(PrdTaskBehavior behavior) => behavior switch { - var schedQtySum = list.Sum(x => x.scheduled_qty); - var planQtySum = list.Sum(x => x.plan_qty); - if (schedQtySum < planQtySum) + PrdTaskBehavior.Release => DictConst.ToBeStartedEnCode, + PrdTaskBehavior.Start => DictConst.InProgressEnCode, + PrdTaskBehavior.Closed => DictConst.ClosedEnCode, + PrdTaskBehavior.Compled => DictConst.ComplatedEnCode, + _ => throw new NotImplementedException(), + }; + PrdTaskBehavior behavior = input.Behavior.ToEnum(); + var status = SetTaskStatus(behavior); + var db = _repository.AsSugarClient(); + var list = await db.Queryable().Where(it => input.TaskIds.Contains(it.id)).Select(it => it).ToListAsync(); + if (behavior == PrdTaskBehavior.Compled) + { + if (list?.Count > 0) { - throw new AppFriendlyException("任务数量必须大于等于生产计划数量,才可完成", 500); - } - } - } - row = await db.Updateable() - .SetColumns(it => new PrdMoTask { mo_task_status = status }) - .Where(it => input.TaskIds.Contains(it.id)) - .ExecuteCommandAsync(); - if (row > 0) - { - //更新子任务 - var subMoTaskList = await db.Queryable().Where(it => input.TaskIds.Contains(it.parent_id)).ToListAsync(); - if (subMoTaskList?.Count > 0) - { - var subTaskIds = subMoTaskList.Select(it => it.id).ToList(); - row = await db.Updateable() - .SetColumns(it => new PrdMoTask { mo_task_status = status }) - .Where(it => subTaskIds.Contains(it.id)) - .ExecuteCommandAsync(); - } - } - //插入操作记录日志 - var prdMOTasks = await _db.Queryable().Where(it => input.TaskIds.Contains(it.id) && string.IsNullOrEmpty(it.parent_id)).ToListAsync(); - if (prdMOTasks?.Count > 0) - { - List taskLogEntities = new(); - foreach (var taskId in input.TaskIds) - { - var taskLog = await db.Queryable().FirstAsync(it => it.mo_task_id == taskId); - if (taskLog is null) - { - var taskItem = list?.Find(x => x.id == taskId); - taskLog = new PrdTaskLog(); - taskLog.id = SnowflakeIdHelper.NextId(); - if (taskItem != null) + var schedQtySum = list.Sum(x => x.scheduled_qty); + var planQtySum = list.Sum(x => x.plan_qty); + if (schedQtySum < planQtySum) { - if (taskItem.mo_id!.IsNotEmptyOrNull()) - { - taskLog.mo_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.mo_id))?.mo_code!; - } - if (taskItem.eqp_id!.IsNotEmptyOrNull()) - { - taskLog.eqp_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.eqp_id))?.code!; - } - if (taskItem.mold_id!.IsNotEmptyOrNull()) - { - taskLog.mold_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.mold_id))?.mold_code!; - } - if (taskItem.material_id!.IsNotEmptyOrNull()) - { - var material = await db.Queryable().FirstAsync(it => it.id == taskItem.material_id); - taskLog.item_code = material?.code!; - taskLog.item_standard = material?.material_standard!; - } - taskLog.operator_name = _userManager.RealName; - taskLog.status = status; - taskLog.create_id = _userManager.UserId; - taskLog.create_time = DateTime.Now; - taskLog.mo_task_id = taskItem.id; + throw new AppFriendlyException("任务数量必须大于等于生产计划数量,才可完成", 500); } - taskLogEntities.Add(taskLog); } - else + } + + var taskReportLogs = new List(); + var prdTaskList = await db.Queryable().Where(it => input.TaskIds.Contains(it.id)).ToListAsync(); + if (prdTaskList?.Count > 0) + { + prdTaskList.ForEach(x => x.mo_task_status = status); + row = await db.Updateable(prdTaskList).ExecuteCommandAsync(); + if (row > 0) { - var records = await db.Queryable().Where(it => it.mo_task_id == taskLog.mo_task_id).ToListAsync(); - if (records != null && !records.Select(x => x.status).Contains(status)) + taskReportLogs.AddRange(prdTaskList); + } + } + if (row > 0) + { + //更新子任务 + var subMoTaskList = await db.Queryable().Where(it => input.TaskIds.Contains(it.parent_id)).ToListAsync(); + if (subMoTaskList?.Count > 0) + { + var subTaskIds = subMoTaskList.Select(it => it.id).ToList(); + row = await db.Updateable() + .SetColumns(it => new PrdMoTask { mo_task_status = status }) + .Where(it => subTaskIds.Contains(it.id)) + .ExecuteCommandAsync(); + if (row > 0) { + taskReportLogs.AddRange(subMoTaskList); + } + } + } + //插入操作记录日志 + var prdMOTasks = await _db.Queryable().Where(it => input.TaskIds.Contains(it.id) && string.IsNullOrEmpty(it.parent_id)).ToListAsync(); + if (prdMOTasks?.Count > 0) + { + List taskLogEntities = new(); + foreach (var taskId in input.TaskIds) + { + var taskLog = await db.Queryable().FirstAsync(it => it.mo_task_id == taskId); + if (taskLog is null) + { + var taskItem = list?.Find(x => x.id == taskId); + taskLog = new PrdTaskLog(); taskLog.id = SnowflakeIdHelper.NextId(); - taskLog.status = status; + if (taskItem != null) + { + if (taskItem.mo_id!.IsNotEmptyOrNull()) + { + taskLog.mo_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.mo_id))?.mo_code!; + } + if (taskItem.eqp_id!.IsNotEmptyOrNull()) + { + taskLog.eqp_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.eqp_id))?.code!; + } + if (taskItem.mold_id!.IsNotEmptyOrNull()) + { + taskLog.mold_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.mold_id))?.mold_code!; + } + if (taskItem.material_id!.IsNotEmptyOrNull()) + { + var material = await db.Queryable().FirstAsync(it => it.id == taskItem.material_id); + taskLog.item_code = material?.code!; + taskLog.item_standard = material?.material_standard!; + } + taskLog.operator_name = _userManager.RealName; + taskLog.status = status; + taskLog.create_id = _userManager.UserId; + taskLog.create_time = DateTime.Now; + taskLog.mo_task_id = taskItem.id; + } taskLogEntities.Add(taskLog); } + else + { + var records = await db.Queryable().Where(it => it.mo_task_id == taskLog.mo_task_id).ToListAsync(); + if (records != null && !records.Select(x => x.status).Contains(status)) + { + taskLog.id = SnowflakeIdHelper.NextId(); + taskLog.status = status; + taskLogEntities.Add(taskLog); + } + } } + row = await db.Insertable(taskLogEntities).ExecuteCommandAsync(); + + List prdReportLogs = new(); + List prdTaskDefectLogs = new(); + if (taskReportLogs?.Count > 0) + { + foreach (var taskInfo in taskReportLogs) + { + //组装生产提报对象 + var material = (await db.Queryable().FirstAsync(it => it.id == taskInfo.material_id)); + var mo = await db.Queryable().FirstAsync(it => it.id == taskInfo.mo_id); + var record = taskInfo.Adapt(); + record.masterial_code = material?.code; + record.masterial_name = material?.name; + record.plan_start_date = taskInfo.estimated_start_date; + record.plan_end_date = taskInfo.estimated_end_date; + record.plan_qty = taskInfo.plan_qty; + record.eqp_code = (await db.Queryable().FirstAsync(it => it.id == taskInfo.eqp_id))?.code; + record.mo_task_type = mo?.mo_type; + record.status = taskInfo.mo_task_status; + record.mo_task_id = taskInfo.id; + //record.completed_qty = (await db.Queryable().Where(it => it.mo_task_code == taskInfo.mo_task_code).SumAsync(it => it.reported_work_qty)).Value; + prdReportLogs.Add(record); + + //组装自检报废对象 + var sacipRecord = new PrdMoTaskDefectRecord(); + sacipRecord.material_code = material?.code!; + sacipRecord.material_name = material?.name!; + sacipRecord.eqp_code = (await db.Queryable().FirstAsync(it => it.id == taskInfo.eqp_id))?.code!; + sacipRecord.mold_name = (await db.Queryable().FirstAsync(it => it.id == taskInfo.mold_id))?.mold_name!; + sacipRecord.estimated_start_date = taskInfo.estimated_start_date; + sacipRecord.estimated_end_date = taskInfo.estimated_end_date; + sacipRecord.plan_qty = taskInfo.plan_qty; + sacipRecord.scrap_qty = taskInfo.scrap_qty.HasValue ? taskInfo.scrap_qty.Value : 0; + sacipRecord.status = taskInfo.mo_task_status; + sacipRecord.create_id = _userManager.UserId; + sacipRecord.create_time = DateTime.Now; + sacipRecord.mo_task_id = taskInfo.id; + sacipRecord.mo_task_code = taskInfo.mo_task_code; + sacipRecord.mo_task_type = mo?.mo_type; + sacipRecord.status = taskInfo.mo_task_status; + prdTaskDefectLogs.Add(sacipRecord); + } + } + row = await db.Insertable(prdReportLogs).ExecuteCommandAsync(); + row = await db.Insertable(prdTaskDefectLogs).ExecuteCommandAsync(); } - row = await db.Insertable(taskLogEntities).ExecuteCommandAsync(); } + else + throw new AppFriendlyException("只有待下发状态的任务才可下发", 500); return (row > 0); } @@ -968,38 +1030,31 @@ namespace Tnb.ProductionMgr { var row = -1; var db = _repository.AsSugarClient(); - var report = await db.Queryable().FirstAsync(it => it.mo_task_code == input.mo_task_code); + var report = await db.Queryable().FirstAsync(it => it.mo_task_id == input.mo_task_id); - if (report is not null) - { - report.mo_task_code = input.mo_task_code; - report.mo_task_id = input.mo_task_id; - report.reported_work_qty += input.reported_qty; - report.prd_qty += input.reported_qty; - - } - else + //if (report is not null) + //{ + // report.mo_task_code = input.mo_task_code; + // report.mo_task_id = input.mo_task_id; + // report.reported_work_qty += input.reported_qty; + // report.prd_qty += input.reported_qty; + //} + //else { report = input.Adapt(); report.id = SnowflakeIdHelper.NextId(); - report.reported_work_qty = input.reported_qty; - report.prd_qty = input.reported_qty; + report.reported_qty = input.reported_qty; + report.create_id = _userManager.UserId; + report.create_time = DateTime.Now; + } - row = await db.Storageable(report).ExecuteCommandAsync(); - var prdTask = await db.Queryable().FirstAsync(it => it.mo_task_code == input.mo_task_code); - var record = prdTask.Adapt(); - if (prdTask != null) + row = await db.Insertable(report).ExecuteCommandAsync(); + var master = await db.Queryable().FirstAsync(it => it.mo_task_id == input.mo_task_id); + if (master != null) { - var material = (await db.Queryable().FirstAsync(it => it.id == prdTask.material_id)); - record.id = SnowflakeIdHelper.NextId(); - record.masterial_code = material?.code; - record.masterial_name = material?.name; - record.plan_start_date = prdTask.estimated_start_date; - record.plan_end_date = prdTask.estimated_end_date; - record.plan_qty = prdTask.plan_qty; - record.eqp_code = (await db.Queryable().FirstAsync(it => it.id == prdTask.eqp_id))?.code; - record.completed_qty = input.reported_qty; - row = await db.Insertable(record).ExecuteCommandAsync(); + master.reported_work_qty += input.reported_qty; + master.completed_qty += input.reported_qty; + await db.Updateable(master).ExecuteCommandAsync(); } return row > 0; } @@ -1060,6 +1115,18 @@ namespace Tnb.ProductionMgr { await db.Updateable().SetColumns(it => new PrdMoTask { scrap_qty = scrapQty.Value }).Where(it => it.id == input.mo_task_id).ExecuteCommandAsync(); } + var defectRecord = await db.Queryable().FirstAsync(it => it.mo_task_id == input.mo_task_id); + if (defectRecord != null) + { + defectRecord.scrap_qty += input.scrap_qty; + await db.Updateable(defectRecord).ExecuteCommandAsync(); + } + var reportMaster = await db.Queryable().FirstAsync(it => it.mo_task_id == input.mo_task_id); + if (reportMaster != null) + { + reportMaster.completed_qty += input.scrap_qty; + await db.Updateable(reportMaster).ExecuteCommandAsync(); + } }); return result.IsSuccess; @@ -1110,7 +1177,6 @@ namespace Tnb.ProductionMgr if (outMaterials?.Count > 0) { - //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).ToList(); await _db.Deleteable().Where(it => it.parent_id == input.mo_id).ExecuteCommandAsync(); if (ids?.Count > 0) @@ -1149,19 +1215,6 @@ namespace Tnb.ProductionMgr #endregion - private static dynamic DictionaryToObject(IDictionary dictionary) - { - var expandoObj = new ExpandoObject(); - var expandoObjCollection = (ICollection>)expandoObj; - - foreach (var keyValuePair in dictionary) - { - expandoObjCollection.Add(keyValuePair); - } - dynamic eoDynamic = expandoObj; - return eoDynamic; - } - private static Dictionary dicProperties = new Dictionary(StringComparer.OrdinalIgnoreCase); private static T DictionaryToObject(IDictionary dictionary) where T : class, new() { diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdPackReportService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdPackReportService.cs new file mode 100644 index 00000000..a2e25156 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr/PrdPackReportService.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Aspose.Cells.Drawing; +using JNPF.Common.Extension; +using JNPF.Common.Filter; +using JNPF.Common.Security; +using JNPF.DependencyInjection; +using JNPF.DynamicApiController; +using JNPF.Systems.Entitys.Permission; +using JNPF.Systems.Interfaces.System; +using Mapster; +using Microsoft.AspNetCore.Mvc; +using Microsoft.CodeAnalysis.Operations; +using NPOI.POIFS.Properties; +using Spire.Pdf.Widget; +using SqlSugar; +using Tnb.BasicData; +using Tnb.BasicData.Entities; +using Tnb.ProductionMgr.Entities; +using Tnb.ProductionMgr.Entities.Dto.PrdManage; +using Tnb.ProductionMgr.Interfaces; + +namespace Tnb.ProductionMgr +{ + /// + /// 组装、包装生产提报服务 + /// + [ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)] + [Route("api/[area]/[controller]/[action]")] + + public class PrdPackReportService : IPrdPackReportService, IDynamicApiController, ITransient + { + private readonly ISqlSugarClient _db; + private readonly IDictionaryDataService _dictionaryDataService; + private static Dictionary> _dicWorkLine = new Dictionary>(); + public PrdPackReportService(ISqlSugarRepository repository, IDictionaryDataService dictionaryDataService) + { + _db = repository.AsSugarClient(); + _dictionaryDataService = dictionaryDataService; + } + /// + /// 获取组装包装生产任务记录,树形结构 + /// + /// + [HttpPost] + public async Task GetList(PrdPackReportQueryInput input) + { + if (input == null) throw new ArgumentNullException("input"); + List trees = new(); + var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId); + if (_dicWorkLine.Count < 1) + { + var list = await _db.Queryable().Where(it => it.Category == "workline").ToListAsync(); + _dicWorkLine = list.ToDictionary(x => x.Id, x => Tuple.Create(x.EnCode, x.FullName)); + } + + var items = await _db.Queryable().LeftJoin((a, b) => a.process_id == b.id).LeftJoin((a, b, c) => a.mo_id == c.id) + .WhereIF(!string.IsNullOrEmpty(input.mo_task_code), a => a.mo_task_code == input.mo_task_code) + .Where(a => string.IsNullOrEmpty(a.parent_id) && a.schedule_type == 2 && a.mo_task_status != "ToBeScheduled") + .Select((a, b, c) => new PrdMoTask + { + id = a.id, + mo_task_code = a.mo_task_code, + workline_id = a.workline_id, + process_id = a.process_id, + plan_start_date = a.estimated_start_date, + plan_end_date = a.estimated_end_date, + plan_qty = c.plan_qty, + complete_qty = SqlFunc.Subqueryable().Where(it => it.mo_task_code == a.mo_task_code).Sum(it => it.reported_work_qty), + mo_task_status = a.mo_task_status, + + }) + .ToPagedListAsync(input.currentPage, input.pageSize); + _db.ThenMapper(items.list, it => + { + it.mo_task_status = it.mo_task_status.IsNotEmptyOrNull() && dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : ""; + }); + + if (items != null && items.list != null && items.list.Any()) + { + foreach (var item in items.list) + { + var node = item.Adapt(); + node.parentId = "0"; + if (item.workline_id.IsNotEmptyOrNull()) + { + var workLine = _dicWorkLine.ContainsKey(item.workline_id) ? (Tuple)_dicWorkLine[item.workline_id] : null; + if (workLine != null) + { + node.workline_id = $"{workLine.Item1}/{workLine.Item2}"; + } + } + node.plan_start_date = item.estimated_start_date.HasValue ? item.estimated_start_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""; + node.plan_end_date = item.estimated_end_date.HasValue ? item.estimated_end_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""; + await GetChild(item.id, trees, dic); + trees.Add(node); + } + } + var treeList = trees.ToTree(); + SqlSugarPagedList pagedList = new() + { + list = treeList, + pagination = new Pagination + { + CurrentPage = input.currentPage, + PageSize = input.pageSize, + Total = treeList.Count + } + }; + return PageResult.SqlSugarPageResult(pagedList); + } + + private async Task GetChild(string parentId, List nodes, Dictionary dic) + { + var items = await _db.Queryable().LeftJoin((a, b) => a.process_id == b.id).LeftJoin((a, b, c) => a.mo_id == c.id) + .Where(a => a.parent_id == parentId && a.mo_task_status != "ToBeScheduled") + .Select((a, b, c) => new PrdMoTask + { + id = a.id, + mo_task_code = a.mo_task_code, + workline_id = a.workline_id, + process_id = a.process_id, + process_code =b.process_code, + process_name = b.process_name, + plan_start_date = a.estimated_start_date, + plan_end_date = a.estimated_end_date, + plan_qty = c.plan_qty, + complete_qty = SqlFunc.Subqueryable().Where(it => it.mo_task_code == a.mo_task_code).Sum(it => it.reported_work_qty), + mo_task_status = a.mo_task_status, + + }).ToListAsync(); + _db.ThenMapper(items, it => + { + it.mo_task_status = it.mo_task_status.IsNotEmptyOrNull() && dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : ""; + }); + + if (items?.Count > 0) + { + var nsChild = items.Adapt>(); + for (int i = 0; i < nsChild.Count; i++) + { + nsChild[i].parentId = parentId; + nsChild[i].process_id = $"{items[i].process_code}/{items[i].process_name}"; + nsChild[i].plan_start_date = items[i].estimated_start_date.HasValue ? items[i].estimated_start_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""; + nsChild[i].plan_end_date = items[i].estimated_end_date.HasValue ? items[i].estimated_end_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""; + } + + nodes.AddRange(nsChild); + foreach (var item in items) + { + await GetChild(item.id, nodes, dic); + } + } + } + } +} diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdTaskManageService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdTaskManageService.cs index 62830b07..3571b851 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdTaskManageService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdTaskManageService.cs @@ -23,6 +23,9 @@ using Microsoft.AspNetCore.Mvc; using DbModels; using JNPF.Common.Extension; using Tnb.ProductionMgr.Entities.Dto.PrdManage; +using NPOI.OpenXmlFormats; +using JNPF.Systems.Entitys.Permission; +using Tnb.BasicData; namespace Tnb.ProductionMgr { @@ -131,6 +134,7 @@ namespace Tnb.ProductionMgr var materialProp = ""; if (prdTask != null) { + var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId); var eqp = await db.Queryable().FirstAsync(it => it.id == prdTask.eqp_id); var mold = await db.Queryable().FirstAsync(it => it.id == prdTask.mold_id); var material = await db.Queryable().FirstAsync(it => it.id == prdTask.material_id); @@ -139,6 +143,12 @@ namespace Tnb.ProductionMgr materialCode = material != null ? material.code : ""; materialName = material != null ? material.name : ""; materialProp = material != null ? material.material_property : ""; + prdTask.workline_code = (await db.Queryable().Where(it => it.Id == prdTask.workline_id && it.Category == "workline").FirstAsync())?.EnCode; + prdTask.process_code = (await db.Queryable().Where(it => it.id == prdTask.process_id).FirstAsync())?.process_code; + if (dic.ContainsKey(prdTask.mo_task_status)) + { + prdTask.mo_task_status = dic[prdTask.mo_task_status]?.ToString(); + } } var res = await db.Queryable().Where(it => it.mo_task_code == mo_task_code) @@ -152,7 +162,9 @@ namespace Tnb.ProductionMgr }) .Mapper(it => { - it.icmo_qty = it.icmo_qty ?? (db.Queryable().First(it => it.icmo_code == mo_task_code)?.scheduled_qty < 1 ? 0 : it.icmo_qty ?? db.Queryable().First(it => it.icmo_code == mo_task_code).scheduled_qty); + it.icmo_qty = it.icmo_qty ?? ( + db.Queryable().First(it => it.mo_task_code == mo_task_code)?.scheduled_qty < 1 ? 0 : + (it.icmo_qty ?? db.Queryable().First(it => it.mo_task_code == mo_task_code)?.scheduled_qty ?? 0)); it.reported_work_qty = it.reported_work_qty ?? 0; it.reported_qty = it.reported_qty ?? 0; it.prd_qty = it.prd_qty ?? 0; @@ -167,7 +179,8 @@ namespace Tnb.ProductionMgr prdTask.reported_work_qty = res?.reported_work_qty ?? 0; prdTask.reported_qty = res?.reported_qty ?? 0; prdTask.prd_qty = res?.prd_qty ?? 0; - + prdTask.scrap_qty = res?.scrap_qty ?? 0; + return prdTask; } diff --git a/ProductionMgr/Tnb.ProductionMgr/ProductionReportRecordService.cs b/ProductionMgr/Tnb.ProductionMgr/ProductionReportRecordService.cs index d63b715d..cf2e9c54 100644 --- a/ProductionMgr/Tnb.ProductionMgr/ProductionReportRecordService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/ProductionReportRecordService.cs @@ -16,6 +16,9 @@ using SqlSugar; using Tnb.BasicData.Entities; using Tnb.ProductionMgr.Entities; using Tnb.ProductionMgr.Interfaces; +using JNPF.Systems.Interfaces.System; +using Tnb.BasicData; +using JNPF.Common.Extension; namespace Tnb.ProductionMgr { @@ -32,40 +35,45 @@ namespace Tnb.ProductionMgr private readonly ISqlSugarClient _db; private readonly IRunService _runService; private readonly IVisualDevService _visualDevService; + private readonly IDictionaryDataService _dictionaryDataService; public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); - public ProductionReportRecordService(ISqlSugarRepository repository, IRunService runService, IVisualDevService visualDevService) + public ProductionReportRecordService(ISqlSugarRepository repository, IRunService runService, IVisualDevService visualDevService, IDictionaryDataService dictionaryDataService) { _db = repository.AsSugarClient(); _runService = runService; _visualDevService = visualDevService; OverideFuncs.GetListAsync = GetList; + _dictionaryDataService = dictionaryDataService; } private async Task GetList(VisualDevModelListQueryInput input) { - + VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true); var data = await _runService.GetListResult(templateEntity, input); - if (data?.list?.Count > 0) - { - foreach (var row in data.list) - { - var dic = row.ToDictionary(x => x.Key, x => x.Value); - var pkName = "material_id_id"; - if (dic.ContainsKey(pkName)) - { - var materialId = dic[pkName]?.ToString(); - var material = await _db.Queryable().FirstAsync(it => it.id == materialId); - //if (material != null) - //{ - // row.Add("material_name", material.name); - // row.Add($"material_attribute", material.attribute); - - //} - } - } - } + //if (data?.list?.Count > 0) + //{ + // var dicMoTaskStatus = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId); + // foreach (var row in data.list) + // { + // var dic = row.ToDictionary(x => x.Key, x => x.Value); + // //if (dic.ContainsKey(nameof(PrdReportRecord.status))) + // //{ + // // var statusCode = dic[nameof(PrdReportRecord.status)].ToString(); + // // row[nameof(PrdReportRecord.status)] = dicMoTaskStatus[statusCode]; + // //} + // if (dic.ContainsKey(nameof(PrdReportRecord.mo_task_type))) + // { + // var moTypeId = dic[nameof(PrdReportRecord.mo_task_type)].ToString(); + // if (moTypeId.IsNotEmptyOrNull()) + // { + // row[nameof(PrdReportRecord.mo_task_type)] = (await _dictionaryDataService.GetInfo(moTypeId)).FullName; + // } + + // } + // } + //} return data!; } }