/// <summary> /// 同步卸样命令 /// </summary> /// <param name="output"></param> /// <returns></returns> public void SyncJXCYControlUnloadCMD(Action <string, eOutputType> output) { int res = 0; // 集中管控 > 第三方 foreach (InfQCJXCYUnLoadCMD entity in CarSamplerDAO.GetInstance().GetWaitForSyncJXCYSampleUnloadCmd(MachineCode)) { bool isSuccess = false; //同步卸样命令 KY_CYJ_OutRun outrun = this.EquDber.Entity <KY_CYJ_OutRun>(" where CYJ_Machine=@CYJ_Machine", new { CYJ_Machine = DataToKYMachine(this.MachineCode) }); if (outrun == null) { outrun = new KY_CYJ_OutRun(); outrun.CYJ_Machine = DataToKYMachine(this.MachineCode); outrun.CY_Code = entity.SampleCode; outrun.CY_Type = "机械采样"; outrun.CY_Control = (int)eSamplingControl.卸料指令; outrun.Send_Time = DateTime.Now; isSuccess = this.EquDber.Insert(outrun) > 0; } else { outrun.CY_Code = entity.SampleCode; outrun.CY_Type = "机械采样"; outrun.CY_Control = (int)eSamplingControl.卸料指令; outrun.Send_Time = DateTime.Now; isSuccess = this.EquDber.Update(outrun) > 0; } string SqlWhere = "where CY_Code=@CY_Code"; if (entity.UnLoadType != "到制样机") { SqlWhere += " and Barrel_Code=@Barrel_Code"; } IList <KY_CYJ_BarrelStatus> barrel_codes = this.EquDber.Entities <KY_CYJ_BarrelStatus>(SqlWhere, new { CY_Code = entity.SampleCode, Barrel_Code = entity.BarrelNumber }); foreach (var item in barrel_codes) { KY_CYJ_Down down = this.EquDber.Entity <KY_CYJ_Down>("where Barrel_Code=@Barrel_Code", new { Barrel_Code = item.Barrel_Code }); if (down != null) { down.XL_Start = 1; down.XL_Finish = 0; down.Down_Type = entity.UnLoadType == "到制样机" ? "0" : "1"; this.EquDber.Update(down); } } if (isSuccess) { entity.SyncFlag = 1; Dbers.GetInstance().SelfDber.Update(entity); res++; } } output(string.Format("同步卸样命令 {0} 条(集中管控 > 第三方)-{1}", res, this.MachineCode), eOutputType.Normal); }
/// <summary> /// 同步采样命令 /// </summary> /// <param name="output"></param> public void SyncSampleCmd(Action <string, eOutputType> output) { string CarNumber = string.Empty; int res = 0; // 集中管控 > 第三方 foreach (InfQCJXCYSampleCMD entity in CarSamplerDAO.GetInstance().GetWaitForSyncSampleCMD(this.MachineCode)) { bool isSuccess = false; CmcsAutotruck AutoTruck = commonDAO.SelfDber.Entity <CmcsAutotruck>(" where CarNumber=:CarNumber", new { CarNumber = entity.CarNumber }); if (AutoTruck != null) { CarNumber = AutoTruck.CarNumber; //先同步车辆信息 KY_CarInfo car = this.EquDber.Get <KY_CarInfo>(entity.CarNumber); if (car == null) { car = new KY_CarInfo(); car.Car_Number = AutoTruck.CarNumber; car.Car_Long = AutoTruck.CarriageLength; car.Car_Width = AutoTruck.CarriageWidth; car.Car_Height = AutoTruck.CarriageBottomToFloor; car.LJ_Sum = SumObstacle(AutoTruck); car.LJ_0 = 0; car.LJ_1 = AutoTruck.LeftObstacle1; car.LJ_2 = AutoTruck.LeftObstacle2; car.LJ_3 = AutoTruck.LeftObstacle3; car.LJ_4 = AutoTruck.LeftObstacle4; car.LJ_5 = AutoTruck.LeftObstacle5; car.LJ_6 = AutoTruck.LeftObstacle6; car.UserName = AutoTruck.Driver; car.EditDate = DateTime.Now; this.EquDber.Insert(car); } else { car.Car_Number = AutoTruck.CarNumber; car.Car_Long = AutoTruck.CarriageLength; car.Car_Width = AutoTruck.CarriageWidth; car.Car_Height = AutoTruck.CarriageBottomToFloor; car.LJ_Sum = SumObstacle(AutoTruck); car.LJ_0 = 0; car.LJ_1 = AutoTruck.LeftObstacle1; car.LJ_2 = AutoTruck.LeftObstacle2; car.LJ_3 = AutoTruck.LeftObstacle3; car.LJ_4 = AutoTruck.LeftObstacle4; car.LJ_5 = AutoTruck.LeftObstacle5; car.LJ_6 = AutoTruck.LeftObstacle6; car.UserName = AutoTruck.Driver; car.EditDate = DateTime.Now; this.EquDber.Update(car); } //同步采样命令 KY_CYJ_OutRun outrun = this.EquDber.Entity <KY_CYJ_OutRun>(" where CYJ_Machine=@CYJ_Machine", new { CYJ_Machine = DataToKYMachine(this.MachineCode) }); if (outrun == null) { outrun = new KY_CYJ_OutRun(); outrun.CYJ_Machine = DataToKYMachine(this.MachineCode); outrun.Car_Number = AutoTruck.CarNumber; //outrun.Rcd_Code = commonDAO.SelfDber.Entity<CmcsBuyFuelTransport>(" where CarNumber=:CarNumber", new { CarNumber = AutoTruck.CarNumber }).SerialNumber; outrun.CY_Code = entity.SampleCode; outrun.CY_Type = "机械采样"; outrun.CY_Point = entity.PointCount; outrun.Batch_Number = entity.InFactoryBatchId; outrun.CY_Control = (int)eSamplingControl.采样指令; outrun.CY_State = (int)eSamplingState.等待采样; outrun.Send_Time = DateTime.Now; //outrun.Clean_Flag = 0; isSuccess = this.EquDber.Insert(outrun) > 0; } else { //outrun.CYJ_Machine = DataToKYMachine(this.MachineCode); outrun.Car_Number = AutoTruck.CarNumber; //outrun.Rcd_Code = commonDAO.SelfDber.Entity<CmcsBuyFuelTransport>(" where CarNumber=:CarNumber", new { CarNumber = AutoTruck.CarNumber }).SerialNumber; outrun.CY_Code = entity.SampleCode; outrun.CY_Type = "机械采样"; outrun.CY_Point = entity.PointCount; outrun.Batch_Number = entity.InFactoryBatchId; outrun.CY_Control = (int)eSamplingControl.采样指令; outrun.CY_State = (int)eSamplingState.等待采样; outrun.Send_Time = DateTime.Now; //outrun.Clean_Flag = 0; isSuccess = this.EquDber.Update(outrun) > 0; } } if (isSuccess) { entity.SyncFlag = 1; Dbers.GetInstance().SelfDber.Update(entity); res++; } } output(string.Format("同步采样计划 {0} 条(集中管控 > 第三方)-{1}", res, this.MachineCode), eOutputType.Normal); res = 0; // 第三方 > 集中管控 同步采样结果 foreach (KY_CYJ_Record entity in this.EquDber.Entities <KY_CYJ_Record>("where CYJ_Machine=@CYJ_Machine and datediff(dd,Begin_Date,getdate())=0", new { CYJ_Machine = DataToKYMachine(this.MachineCode) })) { InfQCJXCYSampleCMD samplecmdInf = Dbers.GetInstance().SelfDber.Entity <InfQCJXCYSampleCMD>("where MachineCode=:MachineCode and SampleCode=:SampleCode and CarNumber=:CarNumber and DataFlag=0 order by createdate desc", new { MachineCode = this.MachineCode, SampleCode = entity.CY_Code, CarNumber = entity.Car_Number }); if (samplecmdInf == null) { continue; } samplecmdInf.StartTime = entity.Begin_Date; samplecmdInf.EndTime = entity.End_Date; samplecmdInf.SampleUser = entity.CY_User; if (Dbers.GetInstance().SelfDber.Update(samplecmdInf) > 0) { res++; } } //采样结果 采样完成后采样指令为0 采样状态为采样完成 开元接收到采样命令后会把采样状态改为0 等待采样 foreach (KY_CYJ_OutRun entity in this.EquDber.Entities <KY_CYJ_OutRun>(" where CYJ_Machine=@CYJ_Machine and CY_Control=0 and CY_State!=0 and Convert(varchar(10),SEND_TIME,120)>=convert(varchar(10),GETDATE(),120)", new { CYJ_Machine = DataToKYMachine(this.MachineCode) })) { InfQCJXCYSampleCMD samplecmdInf = Dbers.GetInstance().SelfDber.Entity <InfQCJXCYSampleCMD>("where MachineCode=:MachineCode and SampleCode=:SampleCode and CarNumber=:CarNumber and DataFlag=0 order by createdate desc", new { MachineCode = this.MachineCode, SampleCode = entity.CY_Code, CarNumber = entity.Car_Number }); if (samplecmdInf == null) { continue; } if (entity.CY_State == 2)//采样完成 { samplecmdInf.ResultCode = eEquInfCmdResultCode.成功.ToString(); } else if (entity.CY_State == 3) { samplecmdInf.ResultCode = eEquInfCmdResultCode.失败.ToString(); } samplecmdInf.DataFlag = 1; if (Dbers.GetInstance().SelfDber.Update(samplecmdInf) > 0) { res++; } } output(string.Format("同步采样计划 {0} 条(第三方 > 集中管控)-{1}", res, this.MachineCode), eOutputType.Normal); }