zhuangpei-mesbackend/MDM/Services/Session/SessionManagerService.cs
2026-01-06 17:31:04 +08:00

135 lines
4.8 KiB
C#

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
{
/// <summary>
/// 产品配方关联表Service业务层处理
/// </summary>
[AppService(ServiceType = typeof(ISessionManagerService), ServiceLifetime = LifeTime.Transient)]
public class SessionManagerService : BaseService<Object>, ISessionManagerService
{
/// <summary>
/// 开工申请
/// </summary>
/// <param name="ProcessCode">过程码</param>
/// <returns></returns>
public int StartWorkApply(string ProcessCode, string WorkOrder, string LineCode, string GroupCode)
{
//校验重复开工
bool isRepeat = Context.Queryable<ProductLifecycle>().Where(it => it.Workorder == WorkOrder && it.ProductSN == ProcessCode).Any();
if (isRepeat)
{
return -1;
}
//根据工单号查询工艺路线
ProcessRouting processRouting = Context.Queryable<ProcessRouting>()
.Where(it => it.FkProductMaterialCode == SqlFunc.Subqueryable<ProWorkorder>()
.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();
}
/// <summary>
/// 进站申请
/// </summary>
/// <param name="OperationCode"></param>
/// <param name="ProcessCode"></param>
/// <returns></returns>
public InStationApplyResult InStationApply(string OperationCode, string ProcessCode)
{
// 查询本工序的 入站流程
if (string.IsNullOrEmpty(OperationCode) && string.IsNullOrEmpty(ProcessCode))
{
return InStationApplyResult.InvalidParameters;
}
var lifecycle = Context.Queryable<ProductLifecycle>()
.Where(it => it.ProductSN == ProcessCode)
.First();
if (lifecycle == null)
{
return InStationApplyResult.InvalidParameters;
}
ProcessOperationFlow operationFlow = Context.Queryable<ProcessOperationFlow>()
.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<RIZOFlowAttribute>();
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;
}
}
}