PLC数据采集
This commit is contained in:
parent
d06908a1b9
commit
e648d92e75
@ -187,12 +187,8 @@ namespace RIZO.Service.PLCBackground.Stations.Into
|
||||
|
||||
//2上工位无记录
|
||||
|
||||
//ProcessOperation LastOperation1 = processOperations.Where(operation => operation.OperationSeq < processOperations.Where(it => it.OperationCode == workstationCode).Select(it => it.OperationSeq).First()).OrderByDescending(operation => operation.OperationSeq).First();
|
||||
//var LastOperationSeqObject = processOperations
|
||||
// .Where(operation => operation.OperationCode == workstationCode)
|
||||
// .FirstOrDefault();
|
||||
var LastOperationSeqObject = processOperations?.Where(operation =>
|
||||
string.Equals(operation.OperationCode, workstationCode, StringComparison.OrdinalIgnoreCase))
|
||||
string.Equals(CleanString(operation.OperationCode), CleanString(workstationCode), StringComparison.OrdinalIgnoreCase))
|
||||
.FirstOrDefault();
|
||||
if (LastOperationSeqObject.LastOperationSeq != 0)
|
||||
{
|
||||
@ -207,8 +203,8 @@ namespace RIZO.Service.PLCBackground.Stations.Into
|
||||
// 3. 构建并执行真正的异步查询(补充执行方法,使 await 生效)
|
||||
var ExistLastOperationRecord = await DbScoped.SugarScope.CopyNew()
|
||||
.Queryable<ProductPassStationRecord>()
|
||||
.Where(it => it.ProductSN == productSN)
|
||||
.Where(it => it.OperationCode == cleanOperationCode) // 使用清理后的字符串匹配
|
||||
.Where(it => CleanString(it.ProductSN) == productSN)
|
||||
.Where(it => CleanString(it.OperationCode) == cleanOperationCode) // 使用清理后的字符串匹配
|
||||
// 补充:根据需求选择合适的执行方法(二选一或其他)
|
||||
.ToListAsync(); // 推荐:返回符合条件的所有数据(列表)
|
||||
// .FirstOrDefaultAsync(); // 若只需返回第一条数据,用这个(无匹配返回 null)
|
||||
@ -218,18 +214,10 @@ namespace RIZO.Service.PLCBackground.Stations.Into
|
||||
return EntryPermissionResult.NoRecordAtPreviousStation;
|
||||
}
|
||||
|
||||
//// 3 上工位NG 入站或者出站结果 NG
|
||||
//bool isExistLastOperationNG = Context.Queryable<ProductPassStationRecord>()
|
||||
// .Where(it => it.ProductSN == productSN)
|
||||
// .Where(it => it.OperationCode == cleanOperationCode)
|
||||
// .Where(it => it.PasstationType == 3)
|
||||
// .Where(it => it.ResultCode == 1)
|
||||
// .Any();
|
||||
|
||||
// 3 上工位NG 入站或者出站结果 NG
|
||||
var ExistLastOperationNG = Context.Queryable<ProductPassStationRecord>()
|
||||
.Where(it => it.ProductSN == productSN)
|
||||
.Where(it => it.OperationCode == cleanOperationCode)
|
||||
.Where(it => CleanString(it.ProductSN) == productSN)
|
||||
.Where(it => CleanString(it.OperationCode) == cleanOperationCode)
|
||||
.Where(it => it.PasstationType == 3)
|
||||
.Where(it => it.ResultCode == 1).ToList();
|
||||
|
||||
@ -267,7 +255,7 @@ namespace RIZO.Service.PLCBackground.Stations.Into
|
||||
// 上一站的出站时间 和本站的请求时间差值
|
||||
DateTime LastInStationTime = await Context.Queryable<ProductPassStationRecord>()
|
||||
.Where(it => it.ProductSN == productSN)
|
||||
.Where(it => it.OperationCode == cleanOperationCode)
|
||||
.Where(it => CleanString(it.OperationCode) == cleanOperationCode)
|
||||
.Where(it => it.PasstationType == 3)
|
||||
.MaxAsync(it => it.OutStationTime ?? DateTime.MinValue);
|
||||
TimeSpan timeDiff = DateTime.Now - LastInStationTime;
|
||||
@ -325,6 +313,21 @@ namespace RIZO.Service.PLCBackground.Stations.Into
|
||||
return result;
|
||||
}
|
||||
|
||||
private string CleanString(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
// 清洗逻辑:
|
||||
// 1. Trim():去除前后普通半角空格
|
||||
// 2. 替换全角空格、制表符、换行符、回车符(常见隐藏空白字符)
|
||||
return input.Trim()
|
||||
.Replace(" ", "") // 替换全角空格(中文输入法空格)
|
||||
.Replace("\t", "") // 替换制表符
|
||||
.Replace("\n", "") // 替换换行符
|
||||
.Replace("\r", ""); // 替换回车符
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user