262 lines
9.3 KiB
C#
262 lines
9.3 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 Org.BouncyCastle.Ocsp;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;
|
|
|
|
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)
|
|
{
|
|
|
|
// 返工件入站
|
|
RecordTrace(product, operationCode, 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)
|
|
{
|
|
RecordTrace(product, operationCode, 1);
|
|
return InStationApplyResult.Success;
|
|
}
|
|
|
|
// 检查上一工序状态
|
|
InStationApplyResult result = CheckPreviousOperationStatus(product.ProductSN, product.RoutingCode, processOperation.OperationSeq);
|
|
if (result == InStationApplyResult.Success)
|
|
{
|
|
RecordTrace(product, operationCode, 1);
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
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
|
|
};
|
|
}
|
|
|
|
|
|
private void RecordTrace(ProductLifecycle product, string operationCode, int flag)
|
|
{
|
|
|
|
Context.Updateable<ProductLifecycle>()
|
|
.SetColumns(it => new ProductLifecycle
|
|
{
|
|
ProductStatus = 1,// 设置为生产中状态
|
|
UpdatedTime = DateTime.Now
|
|
}).Where(it => it.ProductSN == product.ProductSN).ExecuteCommand();
|
|
|
|
//插入入站记录
|
|
ProductPassstationRecord passstationRecord = new ProductPassstationRecord
|
|
{
|
|
Workorder = product.Workorder,
|
|
Routingcode = product.RoutingCode,
|
|
ProductSN = product.ProductSN,
|
|
OperationCode = operationCode,
|
|
ProuductStatus = flag, // 入站状态
|
|
InStationTime = DateTime.Now,
|
|
CreatedTime = DateTime.Now
|
|
};
|
|
Context.Insertable(passstationRecord).ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 普通出站流程
|
|
/// </summary>
|
|
/// <param name="operationCode"></param>
|
|
/// <param name="processCode"></param>
|
|
/// <returns></returns>
|
|
[RIZOFlow(FlowType = "common_outbound_flow")]
|
|
public OutStationApplyResult CommonOutboundStationFlow(string operationCode, string processCode)
|
|
{
|
|
// 参数验证
|
|
if (string.IsNullOrWhiteSpace(operationCode) || string.IsNullOrWhiteSpace(processCode))
|
|
{
|
|
return OutStationApplyResult.InvalidParameters;
|
|
}
|
|
// 获取产品是正常件,完成件,返工件
|
|
var product = GetProductBySn(processCode);
|
|
if (product == null)
|
|
{
|
|
// 产品未开工,不得出站
|
|
return OutStationApplyResult.ProductNotStartWork;
|
|
}
|
|
if (product.ProductStatus == 2)
|
|
{
|
|
// 产品已经生产完成,不得出站
|
|
return OutStationApplyResult.ProductCompleted;
|
|
}
|
|
//如果正常件,返工件
|
|
if (product.ProductStatus == 2)
|
|
{
|
|
//插入出站记录
|
|
ProductPassstationRecord passstationRecord = new ProductPassstationRecord
|
|
{
|
|
Workorder = product.Workorder,
|
|
Routingcode = product.RoutingCode,
|
|
ProductSN = product.ProductSN,
|
|
OperationCode = operationCode,
|
|
ProuductStatus = 3, // 出站状态
|
|
OutStationTime = DateTime.Now,
|
|
CreatedTime = DateTime.Now
|
|
};
|
|
Context.Insertable(passstationRecord).ExecuteCommand();
|
|
return OutStationApplyResult.Success;
|
|
}
|
|
//如果,返工件
|
|
if (product.ProductStatus == 3)
|
|
{
|
|
//插入出站记录
|
|
ProductPassstationRecord passstationRecord = new ProductPassstationRecord
|
|
{
|
|
Workorder = product.Workorder,
|
|
Routingcode = product.RoutingCode,
|
|
ProductSN = product.ProductSN,
|
|
OperationCode = operationCode,
|
|
ProuductStatus = 4, // 出站状态
|
|
OutStationTime = DateTime.Now,
|
|
CreatedTime = DateTime.Now
|
|
};
|
|
Context.Insertable(passstationRecord).ExecuteCommand();
|
|
return OutStationApplyResult.Success;
|
|
}
|
|
|
|
|
|
|
|
return OutStationApplyResult.UnknownStatus;
|
|
}
|
|
}
|
|
}
|