You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
183 lines
6.7 KiB
C#
183 lines
6.7 KiB
C#
using SLH.SSDMS.Common;
|
|
using SLH.SSDMS.Model.DO;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SLH.SSDMS.Services.serviceImpl
|
|
{
|
|
public class RfidJudge : IRfidJudge
|
|
{
|
|
private static string lastRfidCode = "";
|
|
|
|
private static Base_ReadRecord lastReadRecord = new Base_ReadRecord();
|
|
|
|
private static IBaseServices<Base_RFIDInfo> baseServices = new BaseServices<Base_RFIDInfo>();
|
|
|
|
private static IBaseServices<Day_RunInfo> runInfoServices = new BaseServices<Day_RunInfo>();
|
|
|
|
private static IBaseServices<Base_ReadRecord> readRecordServices = new BaseServices<Base_ReadRecord>();
|
|
|
|
private static IBaseServices<Base_BeltInfo> beltInfoServices = new BaseServices<Base_BeltInfo>();
|
|
|
|
public async Task<int> JudgeDirection(string rfidCode)
|
|
{
|
|
Expression<Func<Base_RFIDInfo, bool>> exp = s1 => true;
|
|
exp = exp.And(x => x.updateFlag == 0);
|
|
Expression<Func<Base_RFIDInfo, object>> order = (x) => x.rfidCode;
|
|
List<Base_RFIDInfo> rfidInfos = await baseServices.Query(exp, order,true);
|
|
|
|
List<string> rfidList = new List<string>();
|
|
rfidInfos.ForEach(x => rfidList.Add(x.rfidCode));
|
|
|
|
if (StringExtension.IsNotBlank(lastRfidCode))
|
|
{
|
|
int presentIndex = rfidList.IndexOf(rfidCode);
|
|
int lastIndex = rfidList.IndexOf(lastRfidCode);
|
|
|
|
if (lastIndex == 0 && presentIndex > lastIndex && presentIndex == 1)
|
|
{
|
|
lastRfidCode = rfidCode;
|
|
return 1;
|
|
}
|
|
|
|
if (lastIndex == 0 && presentIndex > lastIndex && presentIndex == rfidList.Count - 1)
|
|
{
|
|
lastRfidCode = rfidCode;
|
|
return 0;
|
|
}
|
|
|
|
if (lastIndex > 0 && presentIndex > 0 && lastIndex < presentIndex)
|
|
{
|
|
lastRfidCode = rfidCode;
|
|
return 1;
|
|
}
|
|
|
|
if (lastIndex > 0 && presentIndex > 0 && lastIndex > presentIndex)
|
|
{
|
|
lastRfidCode = rfidCode;
|
|
return 0;
|
|
}
|
|
|
|
if (presentIndex == 0 && lastIndex > presentIndex && lastIndex == rfidList.Count - 1)
|
|
{
|
|
lastRfidCode = rfidCode;
|
|
return 1;
|
|
}
|
|
|
|
if (presentIndex == 0 && lastIndex > presentIndex && lastIndex == 1)
|
|
{
|
|
lastRfidCode = rfidCode;
|
|
return 0;
|
|
}
|
|
}
|
|
lastRfidCode = rfidCode;
|
|
return 3;
|
|
}
|
|
|
|
public async Task<decimal> JudgeRunSpeed(Base_ReadRecord readRecord)
|
|
{
|
|
//计算时间差
|
|
try
|
|
{
|
|
TimeSpan readTime = new TimeSpan(readRecord.readTime.Ticks);
|
|
if (lastReadRecord == null)
|
|
{
|
|
Console.WriteLine("lastReadRecord为空");
|
|
return new decimal();
|
|
}
|
|
TimeSpan lastTime = new TimeSpan(lastReadRecord.readTime.Ticks);
|
|
decimal interval = (decimal)readTime.Subtract(lastTime).Duration().TotalSeconds;
|
|
Console.WriteLine("时差:" + interval);
|
|
|
|
//计算速度m/s
|
|
decimal result = readRecord.preDistance / interval;
|
|
var speed = Math.Round(result, 3);
|
|
lastReadRecord = readRecord;
|
|
return speed;
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
LogHelper.Error("速度计算异常", ex);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public async Task<decimal> JudgeRunDistance(Base_ReadRecord readRecord)
|
|
{
|
|
try
|
|
{
|
|
//查询已经生成好的里程数据
|
|
Expression<Func<Day_RunInfo, bool>> exp = s1 => true;
|
|
exp = exp.And(x => x.lotNum == readRecord.lotNum);
|
|
List<Day_RunInfo> runInfos = await runInfoServices.Query(exp);
|
|
|
|
var distance = runInfos.Sum(x=>x.runDistance);
|
|
|
|
//查询当天的里程数据
|
|
Expression<Func<Base_ReadRecord, bool>> readExp = s1 => true;
|
|
readExp = readExp.And(x => x.readTime.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"));
|
|
List<Base_ReadRecord> readRecords = await readRecordServices.Query(readExp);
|
|
|
|
var info = readRecords.Sum(x => x.preDistance);
|
|
|
|
return Math.Round((info + distance) / 1000,3);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error("里程计算异常", ex);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public async Task<decimal> JudgeRunTime(Base_ReadRecord readRecord)
|
|
{
|
|
try
|
|
{
|
|
//查询已经生成好的里程数据
|
|
Expression<Func<Day_RunInfo, bool>> exp = s1 => true;
|
|
exp = exp.And(x => x.lotNum == readRecord.lotNum);
|
|
List<Day_RunInfo> runInfos = await runInfoServices.Query(exp);
|
|
|
|
var runTime = runInfos.Sum(x=>x.runTime);
|
|
|
|
//查询当天的里程数据
|
|
Expression<Func<Base_ReadRecord, bool>> readExp = s1 => true;
|
|
readExp = readExp.And(x => x.readTime.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"));
|
|
List<Base_ReadRecord> readRecords = await readRecordServices.Query(readExp);
|
|
|
|
Base_ReadRecord todayReadRecord = readRecords.OrderBy(x => x.readTime).First();
|
|
|
|
TimeSpan readTime = new TimeSpan(DateTime.Now.Ticks);
|
|
TimeSpan lastTime = new TimeSpan(todayReadRecord.readTime.Ticks);
|
|
decimal interval = (decimal)readTime.Subtract(lastTime).Duration().TotalSeconds;
|
|
|
|
return Math.Round((interval + runTime) / 60 / 60,2);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error("时长计算异常", ex);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public async Task<string> JudgeFirstTime(string lotCode)
|
|
{
|
|
try
|
|
{
|
|
Expression<Func<Base_BeltInfo, bool>> exp = s1 => true;
|
|
exp = exp.And(x => x.lotNum == lotCode);
|
|
var info = await beltInfoServices.Query(exp);
|
|
return info.FirstOrDefault().firstTime;
|
|
}catch(Exception ex)
|
|
{
|
|
LogHelper.Error("首次上机时间查询异常"+ lotCode, ex);
|
|
return DateTime.Now.ToString("yyyy-MM-dd");
|
|
}
|
|
}
|
|
}
|
|
}
|