diff --git a/MDM/Attribute/RIZOFlowAttribute.cs b/MDM/Attribute/RIZOFlowAttribute.cs new file mode 100644 index 0000000..16832ba --- /dev/null +++ b/MDM/Attribute/RIZOFlowAttribute.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MDM.Attribute +{ + [AttributeUsage(AttributeTargets.Method, Inherited = false)] + public class RIZOFlowAttribute : System.Attribute + { + /// + /// 流程类型 + /// + public string FlowType { get; set; } + + /// + /// 流程码 + /// + public string FlowCode { get; set; } + + } +} diff --git a/MDM/Controllers/Session/SessionManagerController.cs b/MDM/Controllers/Session/SessionManagerController.cs new file mode 100644 index 0000000..57fc9ca --- /dev/null +++ b/MDM/Controllers/Session/SessionManagerController.cs @@ -0,0 +1,90 @@ +using DOAN.Model.MES.recipe; +using DOAN.Model.MES.recipe.Dto; +using DOAN.Service.MES.recipe.IService; +using DOAN.ServiceCore.Middleware; +using Infrastructure; +using Infrastructure.Attribute; +using Infrastructure.Controllers; +using Infrastructure.Enums; +using Mapster; +using MDM.Models.Flow; +using MDM.Models.Session; +using MDM.Services.Session.IService; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace MDM.Controllers.Session +{ + + /// + /// 回会管理 + /// + [Route("mes/session_managemer")] + [AllowAnonymous] + public class SessionManagerController : BaseController + { + + /// + /// 会话管理接口 + /// + private readonly ISessionManagerService _ISessionManagerService; + public SessionManagerController(ISessionManagerService ISessionManagerService) + { + _ISessionManagerService = ISessionManagerService; + } + + + //TODO 开工申请 + /// + /// 开工申请 + /// + /// 过程码 + /// 当前工单号 + /// 当前产线码 + /// 当前组码 + /// 1:开工成功 0:异常 -1:重复开工 -2 参数异常 + [HttpGet("start_work_apply")] + public IActionResult StartWorkApply(string ProcessCode,string WorkOrder,string LineCode,string GroupCode) + { + if(string.IsNullOrEmpty(ProcessCode)||string.IsNullOrEmpty(WorkOrder)||string.IsNullOrEmpty(GroupCode)) + { + return SUCCESS(-2); + } + + int result= _ISessionManagerService.StartWorkApply(ProcessCode, WorkOrder, LineCode, GroupCode); + + return SUCCESS(result); + } + + //TODO 入站申请 + + /// + /// 入站申请 + /// + /// + [HttpGet("in_station_apply")] + public IActionResult InStationApply(string OperationCode, string ProcessCode) + { + + InStationApplyResult result = _ISessionManagerService.InStationApply(OperationCode, ProcessCode); + return SUCCESS(result); + } + + + + //TODO 出站申请 + [HttpGet("out_station_apply")] + public IActionResult OutStationApply(string OperationCode, string ProcessCode) + { + + InStationApplyResult result = _ISessionManagerService.OutStationApply(OperationCode, ProcessCode); + return SUCCESS(result); + } + + + + + + } + +} diff --git a/MDM/Flows/CommonFlowfunction.cs b/MDM/Flows/CommonFlowfunction.cs deleted file mode 100644 index 479cfe9..0000000 --- a/MDM/Flows/CommonFlowfunction.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Infrastructure.Attribute; -using NPOI.SS.Formula.Functions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MDM.Flows -{ - /// - /// 普通流程功能函数 - /// - [AppService(ServiceType = typeof(CommonFlowfunction), ServiceLifetime = LifeTime.Singleton)] - public class CommonFlowfunction - { - /// - /// 开工 - /// - /// 工单号 - /// 过程码 - /// - public static int CommenceWork(string workorder,string processcode) - { - return 1; - - } - /// - /// 普通入站站流程 - /// - /// - public static int CommonInboundStationFlow() - { - return 42; - } - } -} diff --git a/MDM/Flows/FlowEnums.cs b/MDM/Models/Flow/FlowEnums.cs similarity index 57% rename from MDM/Flows/FlowEnums.cs rename to MDM/Models/Flow/FlowEnums.cs index 88539e5..7933c63 100644 --- a/MDM/Flows/FlowEnums.cs +++ b/MDM/Models/Flow/FlowEnums.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace MDM.Flows +namespace MDM.Models.Flow { /// /// 普通入站站流程结果枚举 @@ -68,4 +68,69 @@ namespace MDM.Flows Reset = 0, } + + /// + /// 进站申请结果状态 + /// + public enum InStationApplyResult + { + /// + /// 成功 准许进站 + /// + Success = 1, + + /// + /// 传入 参数无效,禁止入站 + /// + InvalidParameters = -7, + + /// + /// 产品未开工,禁止入站 + /// + ProductNotStartWork = -2, + + /// + /// 产品已完工,,禁止入站 + /// + ProductCompleted = -3, + + + + /// + /// 重复进站,,禁止入站 + /// + RepeatInStation = -5, + + + + /// + /// 本工序不存在,禁止入站 + /// + OperationNotFound = -8, + + /// + /// 找不到上一工序,禁止入站 + /// + PreviousOperationNotFound = -9, + + /// + /// 未知状态,,禁止入站 + /// + UnknownStatus = -10, + + /// + /// 上一工序未进站,,禁止入站 + /// + PreviousOperationNotStarted = -1, + + /// + /// 上一工序进站但未出站,,禁止入站 + /// + PreviousOperationInProgress = -2, + + /// + /// 上一工序有异常,,禁止入站 + /// + PreviousOperationHasException = -3 + } } diff --git a/MDM/Models/Process/ProcessOperation.cs b/MDM/Models/Process/ProcessOperation.cs index 608f89a..75f379f 100644 --- a/MDM/Models/Process/ProcessOperation.cs +++ b/MDM/Models/Process/ProcessOperation.cs @@ -64,19 +64,19 @@ namespace MDM.Model.Process /// 是否允许跳过该工序(跳站) /// [SugarColumn(ColumnName = "is_skippable")] - public string IsSkippable { get; set; } + public int IsSkippable { get; set; } /// /// 是否允许返工 /// [SugarColumn(ColumnName = "is_reworkable")] - public string IsReworkable { get; set; } + public int IsReworkable { get; set; } /// /// 是否准许并行 /// [SugarColumn(ColumnName = "is_parallel")] - public string IsParallel { get; set; } + public int IsParallel { get; set; } /// /// 并行组编号(如有) diff --git a/MDM/Models/Session/ProductLifecycle.cs b/MDM/Models/Session/ProductLifecycle.cs new file mode 100644 index 0000000..226facd --- /dev/null +++ b/MDM/Models/Session/ProductLifecycle.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MDM.Models.Session +{ + /// + /// 产品生命周期表 + /// + [SugarTable("product_lifecycle")] + public class ProductLifecycle + { + /// + /// 主键ID + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + + /// + /// 工单 + /// + [SugarColumn(ColumnName = "workorder")] + public string Workorder { get; set; } + + + + /// + /// 当前生产状态 + /// + [SugarColumn(ColumnName = "product_status")] + public int ProductStatus { get; set; } + + + + + /// + /// 过程码 + /// + [SugarColumn(ColumnName = "product_SN")] + public string ProductSN { get; set; } + + + /// + /// 产线码 + /// + [SugarColumn(ColumnName = "line_code")] + public string LineCode { get; set; } + + + /// + /// 组码 + /// + [SugarColumn(ColumnName = "group_code")] + public string GroupCode { get; set; } + + /// + /// 工艺路线 + /// + [SugarColumn(ColumnName = "routing_code")] + public string RoutingCode { get; set; } + + + /// + /// 产品开工时间 + /// + [SugarColumn(ColumnName = "product_start_time")] + public DateTime? ProductStartTime { get; set; } + + /// + /// 产品返工时间 + /// + [SugarColumn(ColumnName = "product_rework_time")] + public DateTime? ProductReworkTime { get; set; } + + /// + /// 产品结束时间 + /// + [SugarColumn(ColumnName = "product_finish_time")] + public DateTime? ProductFinishTime { get; set; } + + /// + /// 产品报废时间 + /// + [SugarColumn(ColumnName = "product_scrap_time")] + public DateTime? ProductScrapTime { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "created_time")] + public DateTime? CreatedTime { get; set; } + + /// + /// 更新时间 + /// + [SugarColumn(ColumnName = "updated_time")] + public DateTime? UpdatedTime { get; set; } + + + + } +} diff --git a/MDM/Models/Session/ProductPassstationRecord.cs b/MDM/Models/Session/ProductPassstationRecord.cs new file mode 100644 index 0000000..afa7541 --- /dev/null +++ b/MDM/Models/Session/ProductPassstationRecord.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MDM.Models.Session +{ + + /// + /// 过站记录表 + /// + [SugarTable("product_passstation_record")] + public class ProductPassstationRecord + { + /// + /// 主键ID + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = false)] // 注意:这里没有自增标识 + public long Id { get; set; } + + /// + /// 工单号 + /// + [SugarColumn(ColumnName = "workorder", Length = 50)] + public string Workorder { get; set; } + + /// + /// 过程码 + /// + [SugarColumn(ColumnName = "product_SN", Length = 100)] + public string ProductSN { get; set; } + + /// + /// 工位号 + /// + [SugarColumn(ColumnName = "workstationCode", Length = 50)] + public string WorkstationCode { get; set; } + + /// + /// 工艺路线code + /// + [SugarColumn(ColumnName = "routingcode", Length = 50)] + public string Routingcode { get; set; } + + /// + /// 工序号 + /// + [SugarColumn(ColumnName = "operationCode", Length = 50)] + public string OperationCode { get; set; } + + /// + /// 进站时间 + /// + [SugarColumn(ColumnName = "InStationTime")] + public DateTime? InStationTime { get; set; } + + /// + /// 出站时间 + /// + [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; } + + /// + /// 操作人员 + /// + [SugarColumn(ColumnName = "operator", Length = 50)] + public string Operator { get; set; } + + /// + /// 不良代码 + /// + [SugarColumn(ColumnName = "NgCode", Length = 50)] + public string NgCode { get; set; } + + /// + /// 不良描述 + /// + [SugarColumn(ColumnName = "NgDescription", Length = 255)] + public string NgDescription { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "created_time")] + public DateTime? CreatedTime { get; set; } + + /// + /// 更新时间 + /// + [SugarColumn(ColumnName = "updated_time")] + public DateTime? UpdatedTime { get; set; } + } +} diff --git a/MDM/Models/Session/ProductProcessData.cs b/MDM/Models/Session/ProductProcessData.cs new file mode 100644 index 0000000..18eb3c0 --- /dev/null +++ b/MDM/Models/Session/ProductProcessData.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MDM.Models.Session +{ + /// + /// 工艺数据采集 + /// + [SugarTable("product_process_data")] + public class ProductProcessData + { + /// + /// 主键 + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + + /// + /// 工单号 + /// + [SugarColumn(ColumnName = "fk_workorder", Length = 50)] + public string FkWorkorder { get; set; } + + /// + /// 产线编码(U01) + /// + [SugarColumn(ColumnName = "lineCode", Length = 50)] + public string LineCode { get; set; } + + /// + /// 工位编码 + /// + [SugarColumn(ColumnName = "workstationCode", Length = 50)] + public string WorkstationCode { get; set; } + + /// + /// 工艺路线编码 + /// + [SugarColumn(ColumnName = "routingCode", Length = 50)] + public string RoutingCode { get; set; } + + /// + /// 工序编码 + /// + [SugarColumn(ColumnName = "operationCode", Length = 50)] + public string OperationCode { get; set; } + + /// + /// 产品编码 + /// + [SugarColumn(ColumnName = "productCode", Length = 50)] + public string ProductCode { get; set; } + + /// + /// 产品名称 + /// + [SugarColumn(ColumnName = "productname", Length = 50)] + public string Productname { get; set; } + + /// + /// SN码 + /// + [SugarColumn(ColumnName = "SNnumber", Length = 50)] + public string SNnumber { get; set; } + + /// + /// 参数名 + /// + [SugarColumn(ColumnName = "paramter_name", Length = 50)] + public string ParamterName { get; set; } + + /// + /// 标准值 + /// + [SugarColumn(ColumnName = "standard_paramter_value", DecimalDigits = 2)] + public decimal? StandardParamterValue { get; set; } + + /// + /// 参数值 + /// + [SugarColumn(ColumnName = "real_paramter_value", DecimalDigits = 2)] + public decimal? RealParamterValue { get; set; } + + /// + /// 上限 + /// + [SugarColumn(ColumnName = "up_range_limit", DecimalDigits = 2)] + public decimal? UpRangeLimit { get; set; } + + /// + /// 下限 + /// + [SugarColumn(ColumnName = "low_range_limit", DecimalDigits = 2)] + public decimal? LowRangeLimit { get; set; } + + /// + /// 单位 + /// + [SugarColumn(ColumnName = "unit", Length = 50)] + public string Unit { get; set; } + + /// + /// 检测结果 + /// + [SugarColumn(ColumnName = "checkResult")] + public int? CheckResult { get; set; } + + /// + /// 参数时间 + /// + [SugarColumn(ColumnName = "paramTime")] + public DateTime? ParamTime { get; set; } + + /// + /// 创建人 + /// + [SugarColumn(ColumnName = "createdby", Length = 50)] + public string Createdby { get; set; } + + /// + /// 更新人 + /// + [SugarColumn(ColumnName = "updatedby", Length = 50)] + public string Updatedby { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "created_time")] + public DateTime? CreatedTime { get; set; } + + /// + /// 更新时间 + /// + [SugarColumn(ColumnName = "updated_time")] + public DateTime? UpdatedTime { get; set; } + } +} diff --git a/MDM/Models/Session/ProductRunning.cs b/MDM/Models/Session/ProductRunning.cs new file mode 100644 index 0000000..5daad0b --- /dev/null +++ b/MDM/Models/Session/ProductRunning.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MDM.Models.Session +{ + +} diff --git a/MDM/Models/Session/ProductScanRecord.cs b/MDM/Models/Session/ProductScanRecord.cs new file mode 100644 index 0000000..39e3b8c --- /dev/null +++ b/MDM/Models/Session/ProductScanRecord.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MDM.Models.Session +{ + [SugarTable("product_scan_record")] + public class ProductScanRecord + { + /// + /// 主键ID + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = false)] // bigint类型,非自增 + public long Id { get; set; } + + /// + /// 实际扫到码 + /// + [SugarColumn(ColumnName = "actual_scan_code", Length = 100)] + public string ActualScanCode { get; set; } + + /// + /// 期望扫到的码 + /// + [SugarColumn(ColumnName = "expected_code", Length = 100)] + public string ExpectedCode { get; set; } + + /// + /// 扫码结果 (建议:0-失败,1-成功) + /// + [SugarColumn(ColumnName = "scan_result")] + public int? ScanResult { get; set; } + + /// + /// 错误码代号 + /// + [SugarColumn(ColumnName = "error_code", Length = 50)] + public string ErrorCode { get; set; } + + /// + /// 错误信息 + /// + [SugarColumn(ColumnName = "error_message", Length = 255)] + public string ErrorMessage { get; set; } + + /// + /// 扫码时间 + /// + [SugarColumn(ColumnName = "scan_time")] + public DateTime? ScanTime { get; set; } + } +} diff --git a/MDM/Services/Flows/CommonFlowService.cs b/MDM/Services/Flows/CommonFlowService.cs new file mode 100644 index 0000000..68e52bf --- /dev/null +++ b/MDM/Services/Flows/CommonFlowService.cs @@ -0,0 +1,154 @@ + +using Infrastructure.Attribute; +using JinianNet.JNTemplate; +using MDM.Attribute; +using MDM.Model.Material; +using MDM.Model.Process; +using MDM.Models.Flow; +using MDM.Models.Session; +using MDM.Service; +using NPOI.SS.Formula.Functions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MDM.Services.Flows +{ + /// + /// 普通流程功能函数 + /// + // [AppService(ServiceType = typeof(CommonFlowService), ServiceLifetime = LifeTime.Singleton)] + public class CommonFlowService : BaseService + { + + /// + /// 普通入站站流程 + /// + /// + [RIZOFlow(FlowType = "common_inbound_flow")] + public InStationApplyResult CommonInboundStationFlow(string operationCode, string processCode) + { + // 参数验证 + if (string.IsNullOrWhiteSpace(operationCode) || string.IsNullOrWhiteSpace(processCode)) + { + return InStationApplyResult.InvalidParameters; + } + + // 获取产品是否开工 + var product = GetProductBySn(processCode); + if (product == null) + { + // 产品未开工,不得入站 + return InStationApplyResult.ProductNotStartWork; + } + + // 判断正常件还是返工件,完工件 + + if (product.ProductStatus == 2) + { + // 完工件不得入站 + return InStationApplyResult.ProductCompleted; + } + + // 返工件进行 进站处理 + if (product.ProductStatus == 3) + { + // 返工件入站 + return InStationApplyResult.Success; + } + + // 正常件进行 进站处理 + if (product.ProductStatus == 1) + { + return HandleInProductionProduct(product, operationCode); + } + + 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) + { + // 允许跳站,直接入站成功 + return InStationApplyResult.Success; + } + + // 检查上一工序状态 + return CheckPreviousOperationStatus(product.ProductSN, product.RoutingCode, processOperation.OperationSeq); + } + + 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 + }; + } + } +} diff --git a/MDM/Services/Session/IService/ISessionManagerService.cs b/MDM/Services/Session/IService/ISessionManagerService.cs new file mode 100644 index 0000000..697f2c7 --- /dev/null +++ b/MDM/Services/Session/IService/ISessionManagerService.cs @@ -0,0 +1,20 @@ +using MDM.Models.Flow; +using MDM.Models.Session; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MDM.Services.Session.IService +{ + public interface ISessionManagerService + { + + int StartWorkApply(string ProcessCode, string WorkOrder, string LineCode, string GroupCode); + + InStationApplyResult InStationApply(string OperationCode, string ProcessCode); + + + } +} diff --git a/MDM/Services/Session/SessionManagerService.cs b/MDM/Services/Session/SessionManagerService.cs new file mode 100644 index 0000000..74fcb8c --- /dev/null +++ b/MDM/Services/Session/SessionManagerService.cs @@ -0,0 +1,134 @@ +using DOAN.Model.MES.product; +using DOAN.Model.MES.recipe; +using DOAN.Service.MES.recipe.IService; +using Infrastructure.Attribute; +using MDM.Attribute; +using MDM.Model.Process; +using MDM.Models.Flow; +using MDM.Models.Process; +using MDM.Models.Session; +using MDM.Service; +using MDM.Services.Session.IService; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace MDM.Services.Session +{ + /// + /// 产品配方关联表Service业务层处理 + /// + [AppService(ServiceType = typeof(ISessionManagerService), ServiceLifetime = LifeTime.Transient)] + public class SessionManagerService : BaseService, ISessionManagerService + { + + + + + /// + /// 开工申请 + /// + /// 过程码 + /// + public int StartWorkApply(string ProcessCode, string WorkOrder, string LineCode, string GroupCode) + { + //校验重复开工 + bool isRepeat = Context.Queryable().Where(it => it.Workorder == WorkOrder && it.ProductSN == ProcessCode).Any(); + + if (isRepeat) + { + return -1; + } + + //根据工单号查询工艺路线 + + ProcessRouting processRouting = Context.Queryable() + .Where(it => it.FkProductMaterialCode == SqlFunc.Subqueryable() + .Where(it => it.Workorder == WorkOrder).Select(s => s.ProductionCode)) + .First(); + + ProductLifecycle lifecycle = new ProductLifecycle(); + lifecycle.Workorder = WorkOrder; + lifecycle.ProductSN = ProcessCode; + lifecycle.LineCode = LineCode; + lifecycle.GroupCode = GroupCode; + lifecycle.ProductStatus = 1; + lifecycle.RoutingCode = processRouting.RoutingCode ?? ""; + lifecycle.ProductStartTime = DateTime.Now; + lifecycle.CreatedTime = DateTime.Now; + + + return Context.Insertable(lifecycle).ExecuteCommand(); + + } + + + /// + /// 进站申请 + /// + /// + /// + /// + public InStationApplyResult InStationApply(string OperationCode, string ProcessCode) + { + // 查询本工序的 入站流程 + if (string.IsNullOrEmpty(OperationCode) && string.IsNullOrEmpty(ProcessCode)) + { + return InStationApplyResult.InvalidParameters; + } + + var lifecycle = Context.Queryable() + .Where(it => it.ProductSN == ProcessCode) + .First(); + + if (lifecycle == null) + { + return InStationApplyResult.InvalidParameters; + } + + ProcessOperationFlow operationFlow = Context.Queryable() + .Where(it => it.FkRoutingCode == lifecycle.RoutingCode && it.FkOperationCode == OperationCode) + .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 InStationApplyResult applyResult) + { + return applyResult; + } + } + } + } + } + + return InStationApplyResult.UnknownStatus; + } + } +}