344 lines
13 KiB
C#
344 lines
13 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 List<string> MiddleProcessFlowDistribution(string operationCode, string ProcessCode)
|
|
{
|
|
var lifecycle = Context.Queryable<ProductLifecycle>()
|
|
.Where(it => it.ProductSN == ProcessCode)
|
|
.First();
|
|
ProWorkorder proWorkorder = Context.Queryable<ProWorkorder>().Where(it => it.Workorder == lifecycle.Workorder).First();
|
|
ProcessOperationWorkstationMapping processOperationWorkstationMapping = Context.Queryable<ProcessOperationWorkstationMapping>().Where(it => it.FkRoutingCode == lifecycle.RoutingCode && it.FkOperationCode == operationCode && it.FkProductlinebodyCode == proWorkorder.LineCode).First();
|
|
|
|
List<string> resultList = new List<string>();
|
|
//TODO 获取这个工序的中间操作流程
|
|
List<ProcessOperationFlow> operationFlows = Context.Queryable<ProcessOperationFlow>().Where(it => !it.FlowTypeCode.Contains("bound_flow")).ToList();
|
|
|
|
if (operationFlows != null && operationFlows.Count() > 0)
|
|
{
|
|
// 已知程序集和类名
|
|
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>();
|
|
foreach (var operationFlow in operationFlows)
|
|
{
|
|
if (rizoFlow != null && rizoFlow.FlowType == operationFlow.FlowTypeCode)
|
|
{
|
|
// 找到匹配的方法并调用
|
|
var instance = Activator.CreateInstance(targetType);
|
|
// 获取方法的参数信息
|
|
var parameters = method.GetParameters();
|
|
//工序流程
|
|
if (parameters.Length == 3)
|
|
{
|
|
var result = method.Invoke(instance, new object[] { lifecycle.RoutingCode, operationCode, rizoFlow.FlowCode });
|
|
if (result is string list)
|
|
{
|
|
resultList.Add(list);
|
|
}
|
|
}
|
|
// 工位流程
|
|
if (parameters.Length == 5)
|
|
{
|
|
var result = method.Invoke(instance, new object[] { lifecycle.RoutingCode, operationCode, rizoFlow.FlowCode, processOperationWorkstationMapping.FkProductlinebodyCode, processOperationWorkstationMapping.FkWorkstationCode });
|
|
if (result is string list)
|
|
{
|
|
resultList.Add(list);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return resultList;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <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;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 完成工单申请
|
|
/// </summary>
|
|
/// <param name="ProcessCode"></param>
|
|
/// <param name="WorkOrder"></param>
|
|
/// <returns></returns>
|
|
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();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返工申请
|
|
/// </summary>
|
|
/// <param name="ProcessCode"></param>
|
|
/// <param name="WorkOrder"></param>
|
|
/// <returns></returns>
|
|
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();
|
|
}
|
|
}
|
|
}
|