From b107d5bae1ab4e1815dae66b2e31bdc302e55859 Mon Sep 17 00:00:00 2001 From: gcw_MV9p2JJN Date: Wed, 7 Jan 2026 19:31:58 +0800 Subject: [PATCH] 1 --- .../Session/SessionManagerController.cs | 55 +- .../Session/ProductPassstationRecord.cs | 65 ++- MDM/Services/Flows/CommonFlowService.cs | 521 +++++++++++------- .../IService/ISessionManagerService.cs | 10 +- MDM/Services/Session/SessionManagerService.cs | 131 ++++- 5 files changed, 546 insertions(+), 236 deletions(-) diff --git a/MDM/Controllers/Session/SessionManagerController.cs b/MDM/Controllers/Session/SessionManagerController.cs index 57fc9ca..104670c 100644 --- a/MDM/Controllers/Session/SessionManagerController.cs +++ b/MDM/Controllers/Session/SessionManagerController.cs @@ -40,22 +40,21 @@ namespace MDM.Controllers.Session /// /// 过程码 /// 当前工单号 - /// 当前产线码 - /// 当前组码 /// 1:开工成功 0:异常 -1:重复开工 -2 参数异常 [HttpGet("start_work_apply")] - public IActionResult StartWorkApply(string ProcessCode,string WorkOrder,string LineCode,string GroupCode) + public IActionResult StartWorkApply(string ProcessCode, string WorkOrder) { - if(string.IsNullOrEmpty(ProcessCode)||string.IsNullOrEmpty(WorkOrder)||string.IsNullOrEmpty(GroupCode)) + if (string.IsNullOrEmpty(ProcessCode) || string.IsNullOrEmpty(WorkOrder)) { return SUCCESS(-2); } - int result= _ISessionManagerService.StartWorkApply(ProcessCode, WorkOrder, LineCode, GroupCode); + int result = _ISessionManagerService.StartWorkApply(ProcessCode, WorkOrder); return SUCCESS(result); } + //TODO 入站申请 /// @@ -63,13 +62,16 @@ namespace MDM.Controllers.Session /// /// [HttpGet("in_station_apply")] - public IActionResult InStationApply(string OperationCode, string ProcessCode) + public IActionResult InStationApply(string OperationCode, string ProcessCode) { InStationApplyResult result = _ISessionManagerService.InStationApply(OperationCode, ProcessCode); return SUCCESS(result); } + //TODO 中间流程/工步下发 + + //TODO 出站申请 @@ -77,11 +79,50 @@ namespace MDM.Controllers.Session public IActionResult OutStationApply(string OperationCode, string ProcessCode) { - InStationApplyResult result = _ISessionManagerService.OutStationApply(OperationCode, ProcessCode); + OutStationApplyResult result = _ISessionManagerService.OutStationApply(OperationCode, ProcessCode); return SUCCESS(result); } + //TODO 完工申请 + /// + /// 完工申请 + /// + /// 过程码 + /// 当前工单号 + /// 1:开工成功 0:异常 -1:重复开工 -2 参数异常 + [HttpGet("finish_work_apply")] + public IActionResult FinishWorkApply(string ProcessCode, string WorkOrder) + { + if (string.IsNullOrEmpty(ProcessCode) || string.IsNullOrEmpty(WorkOrder)) + { + return SUCCESS(-2); + } + + int result = _ISessionManagerService.FinishWorkApply(ProcessCode, WorkOrder); + + return SUCCESS(result); + } + + //TODO 返工申请 + /// + /// 返工申请 + /// + /// 过程码 + /// 当前工单号 + /// 1:返工成功 0:异常 -1:重复开工 -2 参数异常 + [HttpGet("rework_apply")] + public IActionResult ReWorkApply(string ProcessCode, string WorkOrder) + { + if (string.IsNullOrEmpty(ProcessCode) || string.IsNullOrEmpty(WorkOrder)) + { + return SUCCESS(-2); + } + + int result = _ISessionManagerService.ReWorkApply(ProcessCode, WorkOrder); + + return SUCCESS(result); + } diff --git a/MDM/Models/Session/ProductPassstationRecord.cs b/MDM/Models/Session/ProductPassstationRecord.cs index afa7541..2b0b063 100644 --- a/MDM/Models/Session/ProductPassstationRecord.cs +++ b/MDM/Models/Session/ProductPassstationRecord.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; namespace MDM.Models.Session { - /// /// 过站记录表 /// @@ -16,7 +15,7 @@ namespace MDM.Models.Session /// /// 主键ID /// - [SugarColumn(IsPrimaryKey = true, IsIdentity = false)] // 注意:这里没有自增标识 + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] // 修正:启用自增 public long Id { get; set; } /// @@ -49,6 +48,24 @@ namespace MDM.Models.Session [SugarColumn(ColumnName = "operationCode", Length = 50)] public string OperationCode { get; set; } + /// + /// 产品生命周期阶段(1,是生产中,2是完工,3是返工) + /// + [SugarColumn(ColumnName = "production_life_stage")] + public int? ProductionLifeStage { get; set; } + + /// + /// 过站类型(IN 进站,OUT 出站) + /// + [SugarColumn(ColumnName = "apply_type")] + public ApplyTypeEnum? ApplyType { get; set; } + + /// + /// 过站状态(SUCCESS 准许过站放行,REJECTED 禁止过站) + /// + [SugarColumn(ColumnName = "apply_status")] + public ApplyStatusEnum? ApplyStatus { get; set; } + /// /// 进站时间 /// @@ -61,26 +78,12 @@ namespace MDM.Models.Session [SugarColumn(ColumnName = "OutStationTime")] public DateTime? OutStationTime { get; set; } - - /// - /// 产品状态 - /// - [SugarColumn(ColumnName = "prouduct_status", Length = 50)] - public int? ProuductStatus { get; set; } - - /// /// 停留时间,秒 /// [SugarColumn(ColumnName = "DurationSeconds")] public int? DurationSeconds { get; set; } - /// - /// 处理结果 - /// - [SugarColumn(ColumnName = "ProcessResult")] - public int? ProcessResult { get; set; } - /// /// 操作人员 /// @@ -88,16 +91,16 @@ namespace MDM.Models.Session public string Operator { get; set; } /// - /// 不良代码 + /// 禁止过站代码 /// - [SugarColumn(ColumnName = "NgCode", Length = 50)] - public string NgCode { get; set; } + [SugarColumn(ColumnName = "reject_reason_code")] + public string RejectReasonCode { get; set; } /// - /// 不良描述 + /// 禁止过站描述 /// - [SugarColumn(ColumnName = "NgDescription", Length = 255)] - public string NgDescription { get; set; } + [SugarColumn(ColumnName = "reject_reason_desc", Length = 255)] + public string RejectReasonDesc { get; set; } /// /// 创建时间 @@ -111,4 +114,22 @@ namespace MDM.Models.Session [SugarColumn(ColumnName = "updated_time")] public DateTime? UpdatedTime { get; set; } } + + /// + /// 过站类型枚举 + /// + public enum ApplyTypeEnum + { + IN = 0, + OUT = 1 + } + + /// + /// 过站状态枚举 + /// + public enum ApplyStatusEnum + { + SUCCESS = 0, + REJECTED = 1 + } } diff --git a/MDM/Services/Flows/CommonFlowService.cs b/MDM/Services/Flows/CommonFlowService.cs index c0e0b09..a7a322e 100644 --- a/MDM/Services/Flows/CommonFlowService.cs +++ b/MDM/Services/Flows/CommonFlowService.cs @@ -1,21 +1,16 @@  +using DOAN.Model.MES.recipe; +using DOAN.Model.MES.recipe.Dto; using Infrastructure.Attribute; -using JinianNet.JNTemplate; using MDM.Attribute; using MDM.Model.Material; using MDM.Model.Process; using MDM.Models.Flow; +using MDM.Models.Process; using MDM.Models.Session; using MDM.Service; using NPOI.SS.Formula.Functions; -using Org.BouncyCastle.Ocsp; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData; + namespace MDM.Services.Flows { @@ -27,169 +22,306 @@ namespace MDM.Services.Flows { /// - /// 普通入站站流程 + /// 普通入站流程 /// - /// + /// 工序代码 + /// 产品序列号 + /// 入站结果 [RIZOFlow(FlowType = "common_inbound_flow")] public InStationApplyResult CommonInboundStationFlow(string operationCode, string processCode) { // 参数验证 - if (string.IsNullOrWhiteSpace(operationCode) || string.IsNullOrWhiteSpace(processCode)) + if (string.IsNullOrWhiteSpace(operationCode)) { return InStationApplyResult.InvalidParameters; } - // 获取产品是否开工 - var product = GetProductBySn(processCode); - if (product == null) + if (string.IsNullOrWhiteSpace(processCode)) + { + return InStationApplyResult.InvalidParameters; + } + + //1.获取产品是正常件,完成件,返工件 + ProductLifecycle productInfo = Context.Queryable() + .Where(p => p.ProductSN == processCode) + .First(); + if (productInfo == null) { // 产品未开工,不得入站 + RecordTrace(productInfo, operationCode, 0, ApplyStatusEnum.REJECTED, InStationApplyResult.ProductNotStartWork.ToString(), "产品未开工,不得入站"); return InStationApplyResult.ProductNotStartWork; } - - // 判断正常件还是返工件,完工件 - - if (product.ProductStatus == 2) + if (productInfo.ProductStatus == 2) { - // 完工件不得入站 + // 产品已经生产完成,不得入站 + RecordTrace(productInfo, operationCode, 2, ApplyStatusEnum.REJECTED, InStationApplyResult.ProductCompleted.ToString(), "产品已经生产完成,不得入站"); return InStationApplyResult.ProductCompleted; } - - // 返工件进行 进站处理 - if (product.ProductStatus == 3) + if (productInfo.ProductStatus == 3) { - - // 返工件入站 - RecordTrace(product, operationCode, 3); + // 返工件允许入站 + RecordTrace(productInfo, operationCode, 3, ApplyStatusEnum.SUCCESS, string.Empty, string.Empty); return InStationApplyResult.Success; } - - // 正常件进行 进站处理 - if (product.ProductStatus == 1) + if (productInfo.ProductStatus == 1) { - return HandleInProductionProduct(product, operationCode); + //正常件处理 + // 1.检查是否重复进站 + bool IsRepeatInStation = Context.Queryable() + .Where(it => it.ProductSN == processCode && it.OperationCode == operationCode) + .Any(); + if (IsRepeatInStation) + { + // 重复进站禁止入站 + RecordTrace(productInfo, operationCode, 3, ApplyStatusEnum.REJECTED, InStationApplyResult.RepeatInStation.ToString(), "重复进站禁止入站"); + return InStationApplyResult.RepeatInStation; + } + + // 获取工序信息 + ProcessOperation processOperation = Context.Queryable() + .Where(it => it.FkRoutingCode == productInfo.RoutingCode && it.OperationCode == operationCode).First(); + if (processOperation == null) + { + return InStationApplyResult.OperationNotFound; + } + + // 可跳过的工序直接允许入站 + if (processOperation.IsSkippable == 1) + { + RecordTrace(productInfo, operationCode, 1, ApplyStatusEnum.SUCCESS, null, null); + return InStationApplyResult.Success; + } + + // 检查上一工序状态 + if (processOperation.OperationSeq <= 10) + { + // 当前是第一个工序,无需检查上一工序 + RecordTrace(productInfo, operationCode, 1, ApplyStatusEnum.SUCCESS, null, null); + return InStationApplyResult.Success; + } + + // 获取上一个工序 + var lastOperation = Context.Queryable() + .Where(it => it.FkRoutingCode == productInfo.RoutingCode) + .Where(it => it.OperationSeq < processOperation.OperationSeq) + .OrderByDescending(it => it.OperationSeq) + .First(); + + if (lastOperation == null) + { + return InStationApplyResult.PreviousOperationNotFound; + } + + // 获取上一工序的通过记录状态 判断上一站是否已经出站 + bool lastOperationStatus = Context.Queryable() + .Where(it => it.ProductSN == processCode && it.OperationCode == lastOperation.OperationCode) + .Where(it => it.ApplyType == ApplyTypeEnum.OUT) + .Where(it => it.ApplyStatus == ApplyStatusEnum.SUCCESS) + .Any(); + + if (lastOperationStatus) + { + // 上一工序已完成,允许入站 + RecordTrace(productInfo, operationCode, 1, ApplyStatusEnum.SUCCESS, InStationApplyResult.Success.ToString(), "上一工序已完成,允许入站"); + return InStationApplyResult.Success; + } + else + { + // 上一工序未完成,禁止入站 + RecordTrace(productInfo, operationCode, 1, ApplyStatusEnum.REJECTED, InStationApplyResult.PreviousOperationNotStarted.ToString(), "上一工序未完成,禁止入站"); + return InStationApplyResult.PreviousOperationNotStarted; + } } - return InStationApplyResult.Success; - } - - private ProductLifecycle GetProductBySn(string productSn) - { - return Context.Queryable() - .Where(it => it.ProductSN == productSn) - .First(); - } - - private InStationApplyResult HandleInProductionProduct(ProductLifecycle product, string operationCode) - { - // 检查是否重复进站 - if (IsRepeatInStation(product.ProductSN, operationCode)) - { - //重复入站,禁止入站 - return InStationApplyResult.RepeatInStation; - } - - // 获取工序信息 - var processOperation = GetProcessOperation(product.RoutingCode, operationCode); - if (processOperation == null) - { - // 工序不存在 异常 - return InStationApplyResult.OperationNotFound; - } - - // 检查是否可以跳站 - if (processOperation.IsSkippable == 1) - { - RecordTrace(product, operationCode, 1); - return InStationApplyResult.Success; - } - - // 检查上一工序状态 - InStationApplyResult result = CheckPreviousOperationStatus(product.ProductSN, product.RoutingCode, processOperation.OperationSeq); - if (result == InStationApplyResult.Success) - { - RecordTrace(product, operationCode, 1); - } - - return result; - - } - - private bool IsRepeatInStation(string productSn, string operationCode) - { - return Context.Queryable() - .Where(it => it.ProductSN == productSn && it.OperationCode == operationCode) - .Any(); - } - - private ProcessOperation GetProcessOperation(string routingCode, string operationCode) - { - return Context.Queryable() - .Where(it => it.FkRoutingCode == routingCode && it.OperationCode == operationCode) - .First(); - } - - private InStationApplyResult CheckPreviousOperationStatus(string productSn, string routingCode, int? currentOperationSeq) - { - // 获取上一个工序 - var lastOperation = Context.Queryable() - .Where(it => it.FkRoutingCode == routingCode) - .Where(it => it.OperationSeq < currentOperationSeq) - .OrderByDescending(it => it.OperationSeq) - .First(); - - if (lastOperation == null) - { - return InStationApplyResult.PreviousOperationNotFound; - } - - // 获取上一工序的通过记录状态 - var lastOperationStatus = Context.Queryable() - .Where(it => it.ProductSN == productSn && it.OperationCode == lastOperation.OperationCode) - .Select(it => it.ProuductStatus) - .First(); - - - - return lastOperationStatus switch - { - // 上一个工序未入站,禁止入站 - null => InStationApplyResult.PreviousOperationNotStarted, - // 上一个工序进站但未出站,禁止入站 - 1 => InStationApplyResult.PreviousOperationInProgress, - // 上一个工序已完成,允许入站 - 2 => InStationApplyResult.Success, - // 上一个工序有异常,禁止入站 - 3 => InStationApplyResult.PreviousOperationHasException, - _ => InStationApplyResult.UnknownStatus - }; + return InStationApplyResult.UnknownStatus; } - private void RecordTrace(ProductLifecycle product, string operationCode, int flag) + + + + + /// + /// 记录入站操作轨迹 + /// + /// 产品信息 + /// 工序代码 + /// 入站结果 + /// 拒绝原因代码 + /// 拒绝原因描述 + private void RecordTrace(ProductLifecycle product, string operationCode, int ProductionLifeStage, ApplyStatusEnum isPass, string rejectReasonCode, string rejectReasonDesc) { - - Context.Updateable() - .SetColumns(it => new ProductLifecycle + // 更新产品状态 + if (product != null) { - ProductStatus = 1,// 设置为生产中状态 - UpdatedTime = DateTime.Now - }).Where(it => it.ProductSN == product.ProductSN).ExecuteCommand(); + Context.Updateable() + .SetColumns(it => new ProductLifecycle + { + ProductStatus = 1, // 设置为生产中状态 + UpdatedTime = DateTime.Now + }) + .Where(it => it.ProductSN == product.ProductSN) + .ExecuteCommand(); + } - //插入入站记录 - ProductPassstationRecord passstationRecord = new ProductPassstationRecord + // 构建入站记录 + var passstationRecord = new ProductPassstationRecord { - Workorder = product.Workorder, - Routingcode = product.RoutingCode, - ProductSN = product.ProductSN, + Workorder = product?.Workorder, + Routingcode = product?.RoutingCode, + ProductSN = product?.ProductSN ?? string.Empty, OperationCode = operationCode, - ProuductStatus = flag, // 入站状态 + ProductionLifeStage = ProductionLifeStage, // 生产中 + ApplyType = ApplyTypeEnum.IN, + ApplyStatus = isPass, + RejectReasonCode = rejectReasonCode, + RejectReasonDesc = rejectReasonDesc, InStationTime = DateTime.Now, CreatedTime = DateTime.Now }; + Context.Insertable(passstationRecord).ExecuteCommand(); + + + } + + //TODO: 下发中间操作流程规则 + + + //public Object MiddleProcessFlowDistribution(string operationCode, string processCode) + //{ + + // //TODO 获取这个工序的中间操作规则 + + // //1. 获取不同的流程规则 + // List MiddleProcessFlowLists = Context.Queryable().Where(it => !it.FlowTypeCode.Contains("bound_flow")).ToList(); + + // //2.分配处理不同的中间操作规则 + // foreach (var flow in MiddleProcessFlowLists) + // { + // //根据不同的流程类型,调用不同的处理函数 + // switch (flow.FlowTypeCode) + // { + // //扫码流程 + // case "Scanningcode_flow": + // //调用质量检验流程处理函数 + // //QualityInspectionFlow(operationCode, processCode); + // break; + // //数据采集流程 + // case "data_collect_flow": + // //调用返工流程处理函数 + // //ReworkProcessFlow(operationCode, processCode); + // break; + // //配方下发流程 + // case "recipe_distribute_flow": + // //调用返工流程处理函数 + // //ReworkProcessFlow(operationCode, processCode); + // break; + // // 添加更多的流程类型处理 + // default: + // break; + // } + // } + + + + + //} + + + //TODO: 扫码流程 + [RIZOFlow(FlowType = "Scanningcode_flow")] + public List ScanningcodeFlow(string operationCode, string RoutingCode) + { + + + //获取这个工序d的扫码规则 + List ScanningFlowList = Context.Queryable().LeftJoin((f, m) => f.FkRoutingCode == m.FkRoutingCode && f.FkOperationCode == m.FkOperationCode && f.FlowCode == m.FkFlowCode) + + .Where((f, m) => f.FkRoutingCode == RoutingCode && f.FkOperationCode == operationCode && f.FlowTypeCode == "Scanningcode_flow") + .Select((f, m) => new ProcessOperationFlowMaterialParamter() + { + id = f.id, + FkRoutingCode = f.FkRoutingCode, + FkOperationCode = f.FkOperationCode, + FkFlowCode = m.FkFlowCode, + MaterialCode = m.MaterialCode, + MaterialName = m.MaterialName, + UseErrorProofRuleCode = m.UseErrorProofRuleCode, + + }) + .ToList(); + return ScanningFlowList; + + } + + //TODO: 数采流程 + [RIZOFlow(FlowType = "data_collect_flow")] + public List DataCollectFlow( string RoutingCode, string operationCode, string ProductlinebodyCode, string WorkstationCode) + { + + + //获取这个工序d的扫码规则 + List DataCollectFlowList = Context.Queryable().LeftJoin + ((f, m) => f.FkRoutingCode == m.FkRoutingCode && f.FkOperationCode == m.FkOperationCode && f.FlowCode == m.FkFlowCode) + .Where((f, m) => f.FkRoutingCode == RoutingCode && f.FkOperationCode == operationCode && f.FlowTypeCode == "Scanningcode_flow") + .Where((f,m)=>m.FkProductlinebodyCode== ProductlinebodyCode&&m.FkWorkstationCode== WorkstationCode) + .Select((f, m) => new ProcessOperationWorkstationFlowCollectParameter() + { + + FkRoutingCode = f.FkRoutingCode, + FkOperationCode = f.FkOperationCode, + FkProductlinebodyCode = m.FkProductlinebodyCode, + FkWorkstationCode = m.FkWorkstationCode, + FkFlowCode = m.FkFlowCode, + ParameterCode = m.ParameterCode, + PlcPoint = m.PlcPoint, + ParameterName = m.ParameterName, + Description = m.Description, + DataType = m.DataType, + Unit = m.Unit, + StandardValue = m.StandardValue, + MinValue = m.MinValue, + MaxValue = m.MaxValue, + IsControlled = m.IsControlled, + IsMonitored = m.IsMonitored, + ControlType = m.ControlType, + DefaultValue = m.DefaultValue, + IsRequired = m.IsRequired, + Sequence = m.Sequence, + + + + }) + .ToList(); + return DataCollectFlowList; + + } + + //TODO: 配方流程 + [RIZOFlow(FlowType = "recipe_distribute_flow")] + public List RecipeDistributeFlow(string operationCode, string RoutingCode) + { + return Context.Queryable() + .LeftJoin((refpr, ver) => refpr.RecipeCode == ver.RecipeCode) + .LeftJoin((refpr, ver, param) => ver.RecipeCode == param.RecipeCode && ver.Version == param.Version) + .Where((refpr, ver, param) => refpr.FkRoutingCode == RoutingCode && refpr.FkOperationCode == operationCode) + .Select((refpr, ver, param) => new PfRecipeParametersDto + { + Id = param.Id, + RecipeCode = param.RecipeCode, + Version = param.Version, + ParamName = param.ParamName, + Unit = param.Unit, + UpperLimit = param.UpperLimit, + LowerLimit = param.LowerLimit, + StandardValue = param.StandardValue, + Remark = param.Remark + }).ToList(); + + } /// @@ -198,64 +330,69 @@ namespace MDM.Services.Flows /// /// /// - [RIZOFlow(FlowType = "common_outbound_flow")] - public OutStationApplyResult CommonOutboundStationFlow(string operationCode, string processCode) - { - // 参数验证 - if (string.IsNullOrWhiteSpace(operationCode) || string.IsNullOrWhiteSpace(processCode)) - { - return OutStationApplyResult.InvalidParameters; - } - // 获取产品是正常件,完成件,返工件 - var product = GetProductBySn(processCode); - if (product == null) - { - // 产品未开工,不得出站 - return OutStationApplyResult.ProductNotStartWork; - } - if (product.ProductStatus == 2) - { - // 产品已经生产完成,不得出站 - return OutStationApplyResult.ProductCompleted; - } - //如果正常件,返工件 - if (product.ProductStatus == 2) - { - //插入出站记录 - ProductPassstationRecord passstationRecord = new ProductPassstationRecord - { - Workorder = product.Workorder, - Routingcode = product.RoutingCode, - ProductSN = product.ProductSN, - OperationCode = operationCode, - ProuductStatus = 3, // 出站状态 - OutStationTime = DateTime.Now, - CreatedTime = DateTime.Now - }; - Context.Insertable(passstationRecord).ExecuteCommand(); - return OutStationApplyResult.Success; - } - //如果,返工件 - if (product.ProductStatus == 3) - { - //插入出站记录 - ProductPassstationRecord passstationRecord = new ProductPassstationRecord - { - Workorder = product.Workorder, - Routingcode = product.RoutingCode, - ProductSN = product.ProductSN, - OperationCode = operationCode, - ProuductStatus = 4, // 出站状态 - OutStationTime = DateTime.Now, - CreatedTime = DateTime.Now - }; - Context.Insertable(passstationRecord).ExecuteCommand(); - return OutStationApplyResult.Success; - } + //[RIZOFlow(FlowType = "common_outbound_flow")] + //public OutStationApplyResult CommonOutboundStationFlow(string operationCode, string processCode) + //{ + // // 参数验证 + // if (string.IsNullOrWhiteSpace(operationCode) || string.IsNullOrWhiteSpace(processCode)) + // { + // return OutStationApplyResult.InvalidParameters; + // } + // // 获取产品是正常件,完成件,返工件 + // var product = GetProductBySn(processCode); + // if (product == null) + // { + // // 产品未开工,不得出站 + // return OutStationApplyResult.ProductNotStartWork; + // } + // if (product.ProductStatus == 2) + // { + // // 产品已经生产完成,不得出站 + // return OutStationApplyResult.ProductCompleted; + // } + // //如果正常件 + // if (product.ProductStatus == 2) + // { + // // 此工序未入站,禁止出站 + + // // 此工序未完成中间流程,禁止出站 + + + // //插入出站记录 + // ProductPassstationRecord passstationRecord = new ProductPassstationRecord + // { + // Workorder = product.Workorder, + // Routingcode = product.RoutingCode, + // ProductSN = product.ProductSN, + // OperationCode = operationCode, + // ProuductStatus = 3, // 出站状态 + // OutStationTime = DateTime.Now, + // CreatedTime = DateTime.Now + // }; + // Context.Insertable(passstationRecord).ExecuteCommand(); + // return OutStationApplyResult.Success; + // } + // //如果,返工件 + // if (product.ProductStatus == 3) + // { + // //插入出站记录 + // ProductPassstationRecord passstationRecord = new ProductPassstationRecord + // { + // Workorder = product.Workorder, + // Routingcode = product.RoutingCode, + // ProductSN = product.ProductSN, + // OperationCode = operationCode, + // ProuductStatus = 4, // 出站状态 + // OutStationTime = DateTime.Now, + // CreatedTime = DateTime.Now + // }; + // Context.Insertable(passstationRecord).ExecuteCommand(); + // return OutStationApplyResult.Success; + // } - return OutStationApplyResult.UnknownStatus; - } + // return OutStationApplyResult.UnknownStatus; + //} } } diff --git a/MDM/Services/Session/IService/ISessionManagerService.cs b/MDM/Services/Session/IService/ISessionManagerService.cs index eb1dd6b..7f0ff44 100644 --- a/MDM/Services/Session/IService/ISessionManagerService.cs +++ b/MDM/Services/Session/IService/ISessionManagerService.cs @@ -8,13 +8,17 @@ using System.Threading.Tasks; namespace MDM.Services.Session.IService { - public interface ISessionManagerService + public interface ISessionManagerService { - int StartWorkApply(string ProcessCode, string WorkOrder, string LineCode, string GroupCode); + public int StartWorkApply(string ProcessCode, string WorkOrder); InStationApplyResult InStationApply(string OperationCode, string ProcessCode); - InStationApplyResult OntStationApply(string OperationCode, string ProcessCode); + OutStationApplyResult OutStationApply(string OperationCode, string ProcessCode); + + + int FinishWorkApply(string ProcessCode, string WorkOrder); + int ReWorkApply(string ProcessCode, string WorkOrder); } diff --git a/MDM/Services/Session/SessionManagerService.cs b/MDM/Services/Session/SessionManagerService.cs index 8344b15..fa6c1f9 100644 --- a/MDM/Services/Session/SessionManagerService.cs +++ b/MDM/Services/Session/SessionManagerService.cs @@ -25,16 +25,12 @@ namespace MDM.Services.Session [AppService(ServiceType = typeof(ISessionManagerService), ServiceLifetime = LifeTime.Transient)] public class SessionManagerService : BaseService, ISessionManagerService { - - - - /// /// 开工申请 /// /// 过程码 /// - public int StartWorkApply(string ProcessCode, string WorkOrder, string LineCode, string GroupCode) + public int StartWorkApply(string ProcessCode, string WorkOrder) { //校验重复开工 bool isRepeat = Context.Queryable().Where(it => it.Workorder == WorkOrder && it.ProductSN == ProcessCode).Any(); @@ -45,17 +41,17 @@ namespace MDM.Services.Session } //根据工单号查询工艺路线 - + ProWorkorder workorder = Context.Queryable() + .Where(it => it.Workorder == WorkOrder).First(); ProcessRouting processRouting = Context.Queryable() - .Where(it => it.FkProductMaterialCode == SqlFunc.Subqueryable() - .Where(it => it.Workorder == WorkOrder).Select(s => s.ProductionCode)) + .Where(it => it.FkProductMaterialCode == workorder.ProductionCode) .First(); ProductLifecycle lifecycle = new ProductLifecycle(); lifecycle.Workorder = WorkOrder; lifecycle.ProductSN = ProcessCode; - lifecycle.LineCode = LineCode; - lifecycle.GroupCode = GroupCode; + lifecycle.LineCode = workorder.LineCode; + lifecycle.GroupCode = workorder.GroupCode; lifecycle.ProductStatus = 1; lifecycle.RoutingCode = processRouting.RoutingCode ?? ""; lifecycle.ProductStartTime = DateTime.Now; @@ -87,11 +83,12 @@ namespace MDM.Services.Session if (lifecycle == null) { - return InStationApplyResult.InvalidParameters; + return InStationApplyResult.ProductNotStartWork; } ProcessOperationFlow operationFlow = Context.Queryable() .Where(it => it.FkRoutingCode == lifecycle.RoutingCode && it.FkOperationCode == OperationCode) + .Where(it => it.FlowTypeCode.Contains("intbound_flow")) .First(); if (operationFlow != null) @@ -132,9 +129,119 @@ namespace MDM.Services.Session } - public InStationApplyResult OntStationApply(string OperationCode, string ProcessCode) + /// + /// 出站申请 + /// + /// + /// + /// + public OutStationApplyResult OutStationApply(string OperationCode, string ProcessCode) { + // 查询本工序的 出站流程 + if (string.IsNullOrEmpty(OperationCode) && string.IsNullOrEmpty(ProcessCode)) + { + return OutStationApplyResult.InvalidParameters; + } + + var lifecycle = Context.Queryable() + .Where(it => it.ProductSN == ProcessCode) + .First(); + + if (lifecycle == null) + { + return OutStationApplyResult.ProductNotStartWork; + } + + ProcessOperationFlow operationFlow = Context.Queryable() + .Where(it => it.FkRoutingCode == lifecycle.RoutingCode && it.FkOperationCode == OperationCode) + .Where(it => it.FlowTypeCode.Contains("outbound_flow")) + .First(); + + if (operationFlow != null) + { + // 已知程序集和类名 + string assemblyName = "MDM.Services.Flows"; + string className = "CommonFlowService"; // 具体的类名 + + // 加载程序集并获取指定类型 + Assembly assembly = Assembly.Load(assemblyName); + Type targetType = assembly.GetType($"{assemblyName}.{className}"); + + if (targetType != null) + { + // 获取类型中带有RIZOFlow特性的方法 + var methods = targetType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); + + foreach (var method in methods) + { + var rizoFlow = method.GetCustomAttribute(); + if (rizoFlow != null && rizoFlow.FlowType == operationFlow.FlowTypeCode) + { + // 找到匹配的方法并调用 + var instance = Activator.CreateInstance(targetType); + var result = method.Invoke(instance, new object[] { OperationCode, ProcessCode }); + + // 处理返回结果 + if (result is OutStationApplyResult applyResult) + { + return applyResult; + } + } + } + } + } + + return OutStationApplyResult.UnknownStatus; + } + + + public int FinishWorkApply(string ProcessCode, string WorkOrder) + { + //校验重复完工 + bool isRepeat = Context.Queryable() + .Where(it => it.Workorder == WorkOrder && it.ProductSN == ProcessCode) + .Where(it => it.ProductStatus == 2) + .Any(); + + if (isRepeat) + { + return -1; + } + return Context.Updateable() + .SetColumns(it => new ProductLifecycle() + { + ProductStatus = 2, + ProductFinishTime = DateTime.Now, + UpdatedTime = DateTime.Now + }) + .Where(it => it.ProductSN == ProcessCode && it.Workorder == WorkOrder) + .ExecuteCommand(); + + } + public int ReWorkApply(string ProcessCode, string WorkOrder) + { + + //校验重复返工 + bool isRepeat = Context.Queryable() + .Where(it => it.Workorder == WorkOrder && it.ProductSN == ProcessCode) + .Where(it => it.ProductStatus == 3) + .Any(); + + if (isRepeat) + { + return -1; + } + + return Context.Updateable() + .SetColumns(it => new ProductLifecycle() + { + ProductStatus = 3, + ProductFinishTime = DateTime.Now, + UpdatedTime = DateTime.Now + }) + .Where(it => it.ProductSN == ProcessCode && it.Workorder == WorkOrder) + .ExecuteCommand(); } } }