162 lines
7.1 KiB
C#
162 lines
7.1 KiB
C#
using Infrastructure.Attribute;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Model;
|
|
using MDM.Model.Plant;
|
|
using MDM.Model.Process;
|
|
using Microsoft.AspNetCore.JsonPatch.Operations;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using NLog;
|
|
using RIZO.Model.Mes;
|
|
using RIZO.Model.MES.product_trace;
|
|
using RIZO.Repository;
|
|
using RIZO.Service.MES.product.IService;
|
|
using RIZO.Service.PLC;
|
|
using S7.Net;
|
|
using SqlSugar.IOC;
|
|
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace RIZO.Service.PLCBackground.Stations.Into
|
|
{
|
|
/// <summary>
|
|
/// OP点散热胶GF1500
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(PlcIntoStationService_OP020_2), ServiceLifetime = LifeTime.Singleton)]
|
|
public class PlcIntoStationService_OP020_2 : PlcIntoStationService_Common
|
|
{
|
|
public PlcIntoStationService_OP020_2(IOptions<OptionsSetting> options) : base(options)
|
|
{
|
|
WorkstationCode = "OP020-2";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 校验是否可以进站
|
|
/// </summary>
|
|
/// <param name="productModel">产品型号</param>
|
|
/// <param name="productSN">产品SN</param>
|
|
/// <returns></returns>
|
|
//protected override async Task<EntryPermissionResult> checkEntryPermission(string productModel, string productSN, string workstationCode, List<ProcessOperation> processOperations)
|
|
//{
|
|
|
|
// EntryPermissionResult result = EntryPermissionResult.UnkownException;
|
|
|
|
|
|
// //2上工位无记录
|
|
|
|
// //ProcessOperation LastOperation = processOperations.Where(operation => operation.OperationSeq < processOperations.Where(it => it.OperationCode == workstationCode).Select(it => it.OperationSeq).First()).OrderByDescending(operation => operation.OperationSeq).First();
|
|
// int LastOperationSeq = processOperations.Where(operation => operation.OperationCode == workstationCode).Select(operation => operation.LastOperationSeq ?? -1).First();
|
|
// ProcessOperation LastOperation = processOperations.Where(it => it.OperationSeq == LastOperationSeq).First();
|
|
// bool isExistLastOperationRecord = await DbScoped.SugarScope.CopyNew().Queryable<ProductPassStationRecord>()
|
|
// .Where(it => it.ProductSN == productSN)
|
|
// .Where(it => it.OperationCode == LastOperation.OperationCode)
|
|
// .AnyAsync();
|
|
// if (!isExistLastOperationRecord)
|
|
// {
|
|
// return EntryPermissionResult.NoRecordAtPreviousStation;
|
|
// }
|
|
|
|
// // 3 上工位NG 入站或者出站结果 NG
|
|
// bool isExistLastOperationNG = await Context.Queryable<ProductPassStationRecord>()
|
|
// .Where(it => it.ProductSN == productSN)
|
|
// .Where(it => it.OperationCode == LastOperation.OperationCode)
|
|
// .Where(it => it.PasstationType == 2 || it.PasstationType == 4)
|
|
// .Where(it => it.ResultCode != 1)
|
|
// .AnyAsync();
|
|
// if (!isExistLastOperationNG)
|
|
// {
|
|
// result = EntryPermissionResult.PreviousStationNG;
|
|
// goto InsertPassrecord;
|
|
// }
|
|
|
|
|
|
// // 4 扫码产品型号错误
|
|
// bool isExistproductSN = await Context.Queryable<ProductLifecycle>()
|
|
// .Where(it => it.ProductSN == productSN).AnyAsync();
|
|
|
|
|
|
// bool isExistproductSNProducting = await Context.Queryable<ProductLifecycle>()
|
|
// .Where(it => it.ProductSN == productSN && (it.ProductCurrentStatus != 1 && it.ProductCurrentStatus != 3)).AnyAsync();
|
|
// if (!isExistproductSN || !isExistproductSNProducting)
|
|
// {
|
|
// result = EntryPermissionResult.ProductModelError;
|
|
// goto InsertPassrecord;
|
|
// }
|
|
// //6时间超出规定无法生产
|
|
|
|
|
|
// //7固化时间未到规定时间
|
|
|
|
// int LastOperationStandardTime = processOperations.Where(operation => operation.OperationCode == LastOperation.OperationCode)
|
|
// .Select(operation => operation.StandardTime ?? 0).First();
|
|
|
|
|
|
|
|
// if (LastOperationStandardTime > 0)
|
|
// {
|
|
// // 上一站的入站时间 和本站的请求时间差值
|
|
// DateTime LastInStationTime = await Context.Queryable<ProductPassStationRecord>()
|
|
// .Where(it => it.ProductSN == productSN)
|
|
// .Where(it => it.OperationCode == LastOperation.OperationCode)
|
|
// .Where(it => it.PasstationType == 1)
|
|
// .MaxAsync(it => it.InStationTime ?? DateTime.MinValue);
|
|
// TimeSpan timeDiff = DateTime.Now - LastInStationTime;
|
|
// double totalSeconds = timeDiff.TotalSeconds;
|
|
// if (totalSeconds < LastOperationStandardTime)
|
|
// {
|
|
// result = EntryPermissionResult.CuringTimeNotReached;
|
|
// goto InsertPassrecord;
|
|
// }
|
|
|
|
// }
|
|
|
|
// //12 最大重复入站次数
|
|
// int MaxRepeatEntries = processOperations.Where(operation => operation.OperationCode == workstationCode).Select(operation => operation.MaxStationCount ?? 1).First();
|
|
// if (MaxRepeatEntries > 1)
|
|
// {
|
|
// int currentStationEntryCount = await Context.Queryable<ProductPassStationRecord>()
|
|
// .Where(it => it.ProductSN == productSN)
|
|
// .Where(it => it.OperationCode == workstationCode)
|
|
// .Where(it => it.PasstationType == 1)
|
|
// .CountAsync();
|
|
// if (currentStationEntryCount >= MaxRepeatEntries)
|
|
// {
|
|
// result = EntryPermissionResult.MaximumRepeatedEntries;
|
|
// goto InsertPassrecord;
|
|
// }
|
|
// }
|
|
|
|
// //OK 准许进站
|
|
// result = EntryPermissionResult.AllowIntoStation;
|
|
// goto InsertPassrecord;
|
|
//InsertPassrecord:
|
|
// //插入入站请求Resp过站记录
|
|
// ProductPassStationRecord RespintoStation = new ProductPassStationRecord
|
|
// {
|
|
// ProductSN = productSN,
|
|
// WorkstationCode = WorkstationCode,
|
|
// Routingcode = processOperations?.First()?.FkRoutingCode ?? "",
|
|
// OperationCode = WorkstationCode,
|
|
// OperationName = plcSetting.WorkStationName,
|
|
// ProductionLifeStage = 1, // 1表示生产中
|
|
// PasstationType = 1, // 入站完毕
|
|
// PasstationDescription = "入站完毕Resp",
|
|
// EffectTime = DateTime.Now,
|
|
// InStationTime = DateTime.Now,
|
|
// ResultCode = (int)result,
|
|
// ResultDescription = result.ToString(),
|
|
// CreatedTime = DateTime.Now,
|
|
|
|
// };
|
|
// await Context.Insertable(RespintoStation).ExecuteCommandAsync();
|
|
|
|
// return result;
|
|
//}
|
|
|
|
}
|
|
|
|
}
|
|
|