248 lines
9.2 KiB
C#
248 lines
9.2 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)
|
|
{
|
|
//校验重复开工
|
|
bool isRepeat = Context.Queryable<ProductLifecycle>().Where(it => it.Workorder == WorkOrder && it.ProductSN == ProcessCode).Any();
|
|
|
|
if (isRepeat)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
//根据工单号查询工艺路线
|
|
ProWorkorder workorder = Context.Queryable<ProWorkorder>()
|
|
.Where(it => it.Workorder == WorkOrder).First();
|
|
ProcessRouting processRouting = Context.Queryable<ProcessRouting>()
|
|
.Where(it => it.FkProductMaterialCode == workorder.ProductionCode)
|
|
.First();
|
|
|
|
ProductLifecycle lifecycle = new ProductLifecycle();
|
|
lifecycle.Workorder = WorkOrder;
|
|
lifecycle.ProductSN = ProcessCode;
|
|
lifecycle.LineCode = workorder.LineCode;
|
|
lifecycle.GroupCode = workorder.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.ProductNotStartWork;
|
|
}
|
|
|
|
ProcessOperationFlow operationFlow = Context.Queryable<ProcessOperationFlow>()
|
|
.Where(it => it.FkRoutingCode == lifecycle.RoutingCode && it.FkOperationCode == OperationCode)
|
|
.Where(it => it.FlowTypeCode.Contains("intbound_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<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;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 出站申请
|
|
/// </summary>
|
|
/// <param name="OperationCode"></param>
|
|
/// <param name="ProcessCode"></param>
|
|
/// <returns></returns>
|
|
public OutStationApplyResult OutStationApply(string OperationCode, string ProcessCode)
|
|
{
|
|
|
|
// 查询本工序的 出站流程
|
|
if (string.IsNullOrEmpty(OperationCode) && string.IsNullOrEmpty(ProcessCode))
|
|
{
|
|
return OutStationApplyResult.InvalidParameters;
|
|
}
|
|
|
|
var lifecycle = Context.Queryable<ProductLifecycle>()
|
|
.Where(it => it.ProductSN == ProcessCode)
|
|
.First();
|
|
|
|
if (lifecycle == null)
|
|
{
|
|
return OutStationApplyResult.ProductNotStartWork;
|
|
}
|
|
|
|
ProcessOperationFlow operationFlow = Context.Queryable<ProcessOperationFlow>()
|
|
.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<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 OutStationApplyResult applyResult)
|
|
{
|
|
return applyResult;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return OutStationApplyResult.UnknownStatus;
|
|
}
|
|
|
|
|
|
public int FinishWorkApply(string ProcessCode, string WorkOrder)
|
|
{
|
|
//校验重复完工
|
|
bool isRepeat = Context.Queryable<ProductLifecycle>()
|
|
.Where(it => it.Workorder == WorkOrder && it.ProductSN == ProcessCode)
|
|
.Where(it => it.ProductStatus == 2)
|
|
.Any();
|
|
|
|
if (isRepeat)
|
|
{
|
|
return -1;
|
|
}
|
|
return Context.Updateable<ProductLifecycle>()
|
|
.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<ProductLifecycle>()
|
|
.Where(it => it.Workorder == WorkOrder && it.ProductSN == ProcessCode)
|
|
.Where(it => it.ProductStatus == 3)
|
|
.Any();
|
|
|
|
if (isRepeat)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
return Context.Updateable<ProductLifecycle>()
|
|
.SetColumns(it => new ProductLifecycle()
|
|
{
|
|
ProductStatus = 3,
|
|
ProductFinishTime = DateTime.Now,
|
|
UpdatedTime = DateTime.Now
|
|
})
|
|
.Where(it => it.ProductSN == ProcessCode && it.Workorder == WorkOrder)
|
|
.ExecuteCommand();
|
|
}
|
|
}
|
|
}
|