using Infrastructure.Attribute; using Infrastructure.Extensions; using DOAN.Model.PBL.Dto; using DOAN.Model.PBL; using DOAN.Repository; using DOAN.Service.PBL.IService; using Mapster; using System.Runtime.InteropServices; using SqlSugar; using System.Security.Cryptography.X509Certificates; using DOAN.Infrastructure.PLC; namespace DOAN.Service.PBL { /// /// 料架表Service业务层处理 /// [AppService(ServiceType = typeof(IMESInteractionServcie), ServiceLifetime = LifeTime.Transient)] public class MESInteractionServcie : BaseService, IMESInteractionServcie { public bool MESLightUp(LightUpDto light) { // 1.记录MES交互记录 MES_Interation_Log item = light.Adapt(); item.Id = XUEHUA; item.CreatedTime = DateTime.Now; Context.Insertable(item).ExecuteCommand(); // 2.根据总成零件号 ,版本 查询对应零件号,使得对应料架亮灯 //镜壳 料架 Storagelocation MirrorshellShelf = Context.Queryable().Where(it => it.Partnumber == SqlFunc.Subqueryable().Where(It => It.Productcode == light.AssemblyPartNumber && It.Version == light.Version).Select(it => it.MirrorshellCode)).First(); //镜体 料架 Storagelocation MirrorshellBody = Context.Queryable().Where(it => it.Partnumber == SqlFunc.Subqueryable().Where(It => It.Productcode == light.AssemblyPartNumber && It.Version == light.Version).Select(it => it.MirrorbodyCode)).First(); // 3.对应料架亮灯 //TODO PLC 交互 // 对应料架 亮灯字段 // 通知PLC bool isSucesss = PLCTool.WriteBit(MirrorshellShelf.PlcAddress, true); if (isSucesss) { MirrorshellShelf.IsLight = 1; MirrorshellBody.IsLight = 1; Context.Insertable(MirrorshellShelf).ExecuteCommand(); Context.Insertable(MirrorshellBody).ExecuteCommand(); } //亮灯日志 Light_Log light_Log = new Light_Log(); light_Log.Id = XUEHUA; light_Log.LightOperation = 1; if (MirrorshellShelf != null) { light_Log.ShelfCode = MirrorshellShelf.RackCode; } light_Log.Operationer = "PBL"; light_Log.CreatedTime = DateTime.Now; light_Log.IsSuccess = isSucesss; Light_Log light_Log2 = new Light_Log(); light_Log2.Id = XUEHUA; light_Log2.LightOperation = 1; if (MirrorshellShelf != null) { light_Log2.ShelfCode = MirrorshellShelf.RackCode; } light_Log2.Operationer = "PBL"; light_Log2.CreatedTime = DateTime.Now; light_Log2.IsSuccess = isSucesss; Context.Insertable(light_Log2).ExecuteCommand(); int result = Context.Insertable(light_Log).ExecuteCommand(); return result > 0; } /// /// 灭灯 /// /// /// public bool MESLightDown(string scan_code) { // 1.记录MES交互记录 MES_Interation_Log item = new MES_Interation_Log(); item.Id = XUEHUA; item.ScanCode = scan_code; item.CreatedTime = DateTime.Now; Context.Insertable(item).ExecuteCommand(); //2 找到对应的料架 灭灯 Storagelocation storagelocation = Context.Queryable().Where(it => it.Partnumber == scan_code).First(); //TODO PLC 交互 bool isSuccess= PLCTool.WriteBit(storagelocation.PlcAddress, false); if (isSuccess) { storagelocation.IsLight = 0; storagelocation.PackageNum =storagelocation.PackageNum - 1; //3 扣减对应的库存 Context.Insertable(storagelocation).ExecuteCommand(); } //灭灯日志 Light_Log light_Log = new Light_Log(); light_Log.Id = XUEHUA; light_Log.LightOperation = 2; if (storagelocation != null) { light_Log.ShelfCode = storagelocation.RackCode; } light_Log.IsSuccess = isSuccess; light_Log.Operationer = "PBL"; light_Log.CreatedTime = DateTime.Now; int result = Context.Insertable(light_Log).ExecuteCommand(); return result > 0; } } }