using MaterialTraceability.Common; using MaterialTraceability.Entity.DAO; using MaterialTraceability.Entity.DTO; using MaterialTraceability.SqlSugar; using MaterialTraceability.SqlSugar.ServiceImpl; using MaterialTraceability.WebService; using System; using System.Linq.Expressions; using System.Threading.Tasks; namespace MaterialTraceability.Business { /// /// 业务辅助类 /// public class BusinessHelper { private static IBaseServices upRecordServices = new BaseServices(); private static IBaseServices downRecordServices = new BaseServices(); private static IBaseServices bindInfoServices = new BaseServices(); /// /// Mes WebService接口 /// private IMesWebServices MesWebServices = new MesWebServicesImpl(); /// /// 放卷位RFID标签是否重复 /// /// /// public static async Task UpRfidIsRecur(string rfid,int position) { try { AppConfigDto appConfig = AppConfigDto.Instance; LogHelper.Info("判断放卷位RFID:" + rfid + "是否和上一次读取相同"); Expression> exp = s1 => true; exp = exp.And(x => x.PositionId == position && x.MachineId == appConfig.machineId); Expression> order = (x) => x.RecordTime; ProUpRecord upRecord = await upRecordServices.QueryFirst(exp, order, false); if (upRecord != null) { if (upRecord.Rfid == rfid) { return true; } } return false; }catch(Exception ex) { LogHelper.Error("放卷位卷筒是否和上一次读取相同过滤异常", ex); return false; } } /// /// 收卷位RFID标签是否重复 /// /// public static async Task DownRfidIsRecur(string rfid,int position) { try { AppConfigDto appConfig = AppConfigDto.Instance; LogHelper.Info("判断收卷位RFID:"+ rfid + "是否和上一次读取相同过滤异常"); Expression> exp = s1 => true; exp = exp.And(x => x.PositionId == position && x.MachineId == appConfig.machineId); Expression> order = (x) => x.RecordTime; ProDownRecord downRecord = await downRecordServices.QueryFirst(exp, order, false); if (downRecord != null) { if (downRecord.Rfid == rfid) { return true; } } return false; }catch(Exception ex) { LogHelper.Error("收卷位卷筒是否和上一次读取相同过滤异常",ex); return false; } } /// /// 绑定RFID与SFC信息 /// /// /// /// public static async Task BindRfidAndSfc(string rfidStr, string sfcStr) { Expression> exp = s1 => true; exp = exp.And(x => x.rfid == rfidStr); Expression> order = (x) => x.bindTime; ProBindInfo bindInfo = await bindInfoServices.QueryFirst(exp, order, true); //如果有RFID更新绑定信息 if (bindInfo != null) { bindInfo.sfc = sfcStr; bindInfo.bindTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); bool bindResult = await bindInfoServices.Update(bindInfo); if (bindResult) { return true; } else { return false; } } else //如果没有新加绑定信息 { bindInfo = new ProBindInfo(); bindInfo.id = System.Guid.NewGuid().ToString("N"); bindInfo.rfid = rfidStr; bindInfo.sfc = sfcStr; bindInfo.bindTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); int addResult = await bindInfoServices.Add(bindInfo); if (addResult > 0) { return true; } else { return false; } } } } }