155 lines
5.4 KiB
C#
155 lines
5.4 KiB
C#
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// 普通流程功能函数
|
|
/// </summary>
|
|
// [AppService(ServiceType = typeof(CommonFlowService), ServiceLifetime = LifeTime.Singleton)]
|
|
public class CommonFlowService : BaseService<Object>
|
|
{
|
|
|
|
/// <summary>
|
|
/// 普通入站站流程
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[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<ProductLifecycle>()
|
|
.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<ProductPassstationRecord>()
|
|
.Where(it => it.ProductSN == productSn && it.OperationCode == operationCode)
|
|
.Any();
|
|
}
|
|
|
|
private ProcessOperation GetProcessOperation(string routingCode, string operationCode)
|
|
{
|
|
return Context.Queryable<ProcessOperation>()
|
|
.Where(it => it.FkRoutingCode == routingCode && it.OperationCode == operationCode)
|
|
.First();
|
|
}
|
|
|
|
private InStationApplyResult CheckPreviousOperationStatus(string productSn, string routingCode, int? currentOperationSeq)
|
|
{
|
|
// 获取上一个工序
|
|
var lastOperation = Context.Queryable<ProcessOperation>()
|
|
.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<ProductPassstationRecord>()
|
|
.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
|
|
};
|
|
}
|
|
}
|
|
}
|