/// <summary> /// 根據PLC返回數據,分析判斷幾臺狀態 /// </summary> /// <param name="data"></param> /// <returns></returns> private CustEnum.MachineStatus AnalysisStatus(ScheduleProjList_swl_Info schProj, PLCData_pda_Info data) { if (data.pda_lRunning) { schProj.PROD_STOP_Datetime = null; return CustEnum.MachineStatus.MACHINE_PRODUCTION; } else { if (!schProj.PROD_STOP_Datetime.HasValue) { schProj.PROD_STOP_Datetime = DateTime.Now; } return CustEnum.MachineStatus.MACHINE_SHUTDOWN; } }
/// <summary> /// 獲取信號控制主檔 /// </summary> /// <returns></returns> //public List<SignalLightsStatus_sls_Info> GetSignalControls() //{ // List<SignalLightsStatus_sls_Info> result = null; // try // { // CRUD baseDal = new CRUD(); // result = baseDal.ExcuteHQL<SignalLightsStatus_sls_Info>("from SignalLightsStatus_sls_Info") as List<SignalLightsStatus_sls_Info>; // } // catch (Exception ex) // { // result = new List<SignalLightsStatus_sls_Info>(); // mLog.Error("PLCBL.GetSignalControls", ex); // // throw; // } // return result; //} /// <summary> /// 工程開始生產,狀態改變規則:準備中-->生產中 /// </summary> /// <param name="schProj"></param> /// <param name="printProj"></param> /// <param name="shiftProject"></param> /// <param name="data"></param> /// <returns></returns> public bool ProduceBegin(DBContext uow, ScheduleProjList_swl_Info schProj, PrintProject_ppj_Info printProj, ShiftProjList_spl_Info shiftProject, PLCData_pda_Info data) { try { //using (DBContext uow = DBContext.Begin()) //{ DateTime dealTime = DateTime.Now; #region 更新印刷工程信息 schProj.swl_iIsByModify = true; schProj.swl_cProjStatus = CustEnum.ProjectStatus.PROD_IN.ToString(); schProj.swl_dStatusChange = dealTime; schProj.swl_dLastDate = dealTime; uow.CurrentSession.Update(uow.CurrentSession.Merge(schProj)); #endregion #region 更新生產工程信息 if (printProj != null) { printProj.ppj_dProdBeginTime = dealTime; printProj.ppj_fMachineSpeed = data.pda_iMachineSpeed; printProj.ppj_iActualProdNum = data.pad_iQty; printProj.ppj_iCountProdNum = data.pad_iQty; printProj.ppj_dLastDate = dealTime; var projectDinnerQuery = uow.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_swlID == schProj.swl_RecordID); projectDinnerQuery.And(d => d.dsm_ppjID == printProj.ppj_RecordID); projectDinnerQuery.And(d => d.dsm_cProjectStatus == CustEnum.ProjectStatus.PREPARE.ToString()); int projectDinnerTime = (int)projectDinnerQuery.And(d => d.dnr_DSMID != Guid.Empty).List().Sum(d => (d.dnr_dEndTime.Value - d.dnr_dBeginTime.Value).TotalSeconds); printProj.ppj_iActualPrepairTime = (int)(printProj.ppj_dProdBeginTime.Value - printProj.ppj_dProjBeginTime).TotalSeconds - projectDinnerTime; uow.CurrentSession.Update(printProj); } #endregion #region 更新班次內工程信息 #region 準備時間計算 shiftProject.spl_dProdBegin = printProj.ppj_dProdBeginTime; int prepairTime = (int)(shiftProject.spl_dProdBegin.Value - shiftProject.spl_dBeginTime).TotalSeconds; var dinnerQuery = uow.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_swlID == schProj.swl_RecordID); dinnerQuery.And(d => d.dsm_ppjID == printProj.ppj_RecordID); dinnerQuery.And(d => d.dsm_splID == shiftProject.spl_RecordID); dinnerQuery.And(d => d.dsm_cProjectStatus == CustEnum.ProjectStatus.PREPARE.ToString()); int dinnerTime = (int)dinnerQuery.And(d => d.dnr_DSMID != Guid.Empty).List().Sum(d => (d.dnr_dEndTime.Value - d.dnr_dBeginTime.Value).TotalSeconds); shiftProject.spl_iPrepairTime = prepairTime - dinnerTime; #endregion shiftProject.spl_dLastDate = dealTime; shiftProject.spl_iBeginQTY = 0; shiftProject.spl_iQTY = data.pad_iQty; shiftProject.spl_iEndQTY = data.pad_iQty; shiftProject.spl_iCalQTY = shiftProject.spl_iEndQTY - shiftProject.spl_iBeginQTY; uow.CurrentSession.Update(shiftProject); #endregion #region 更新生產中停機的結束時間 ProjectStopRecord_psrd_Info psrd_prepare; var query_pre = uow.CurrentSession.QueryOver<ProjectStopRecord_psrd_Info>(); query_pre.And(d => d.psrd_SPLID == shiftProject.spl_RecordID); query_pre.And(d => d.psrd_dEndTime == null); query_pre.And(d => d.psrd_cTypeID == CustEnum.RecordType.NORMAL.ToString()); IList<ProjectStopRecord_psrd_Info> list_pre = query_pre.List<ProjectStopRecord_psrd_Info>(); if (list_pre.Count > 0) { psrd_prepare = list_pre[0]; psrd_prepare.psrd_dEndTime = dealTime; psrd_prepare.psrd_dLastDate = dealTime; psrd_prepare.psrd_iActualStopTime = TimeCalculater.ProjectStopRecordActualTime(uow, psrd_prepare); uow.CurrentSession.Update(uow.CurrentSession.Merge(psrd_prepare)); printProj.ppj_iStopTime += psrd_prepare.psrd_iActualStopTime; uow.CurrentSession.Update(uow.CurrentSession.Merge(printProj)); shiftProject.spl_iStopTime += psrd_prepare.psrd_iActualStopTime; uow.CurrentSession.Update(uow.CurrentSession.Merge(shiftProject)); } #endregion // } return true; } catch (Exception ex) { uow.CanCommit = false; mLog.Error("PLCBL.ProduceBegin" + ex); return false; } }
public CustEnum.ProductionStatus SaveData(CustEnum.ProductionStatus prodStatus, ScheduleProjList_swl_Info schProj, PrintProject_ppj_Info printProj, ShiftProjList_spl_Info shiftProject, PLCData_pda_Info data, int savetoDBInterval) { DateTime start = DateTime.Now; ///工程生產狀態 CustEnum.ProductionStatus status; try { //暫時關閉這項功能,由於可能存在性能問題 //IPLCDataDA plcda = SQLiteDAFacotry.GetDAL<IPLCDataDA>(SQLiteDAFacotry.PLCDataDAL); //if (data != null && data.SaveToDB) //{ // //選擇工程後開始記錄機台PLC數據 // plcda.Insert(data); //} ///根據PLC返回數據,分析判斷機台狀態 CustEnum.MachineStatus mstatus = AnalysisStatus(schProj, data); using (DBContext uow = DBContext.Begin()) { // 根據印刷工程狀態 與 機台狀態,得出印刷工程生產狀態 status = AnalysisProdStatus(uow, mstatus, prodStatus, schProj, printProj, shiftProject); //Common.General.BLLoger.Debug("工程生產狀態--->" + status.ToString()); #region //生產開始 switch (status) { case CustEnum.ProductionStatus.PRO_PREPARE: //#region 更新印刷工程信息 //if (printProj.ppj_iPredictPrepairTime > 0) //{ // if (printProj.ppj_iActualPrepairTime > printProj.ppj_iPredictPrepairTime) // { // schProj.swl_cProjStatus = CustEnum.ProjectStatus.PREPARE_OT.ToString(); // schProj.swl_dStatusChange = DateTime.Now; // schProj.swl_dLastDate = DateTime.Now; // uow.CurrentSession.Update(uow.CurrentSession.Merge(schProj)); // } //} //#endregion break; case CustEnum.ProductionStatus.PROD_BEGIN: if (status != prodStatus) //狀態改變 { ProduceBegin(uow, schProj, printProj, shiftProject, data); } break; //生產中 case CustEnum.ProductionStatus.PROD_IN: Producing(uow, schProj, printProj, shiftProject, data, savetoDBInterval); break; //生產中停機 case CustEnum.ProductionStatus.PROD_STOP: #region 記錄生產中停機信息 if (prodStatus != status) //狀態改變 { ProduceStop(uow, schProj, printProj, shiftProject, data); } else { //判斷是否停機超時 IList<ProjectStopRecord_psrd_Info> psrd = uow.CurrentSession.QueryOver<ProjectStopRecord_psrd_Info>().And(d => d.psrd_PPJID == printProj.ppj_RecordID).And(d => d.psrd_dEndTime == null).OrderBy(d => d.psrd_dBeginTime).Desc.List(); if (psrd.Count > 0 && psrd[0].psrd_iPredictStopTime > 0) { ProduceStop2Long(uow, schProj, printProj, shiftProject, psrd[0]); for (int index = 1; index < psrd.Count; index++) { psrd[index].psrd_dEndTime = DateTime.Now; uow.CurrentSession.Update(psrd[index]); } } } #endregion break; //生產繼續 case CustEnum.ProductionStatus.PROD_RESART: ProduceRestart(uow, schProj, printProj, shiftProject, data); break; default: break; } #endregion } } catch (Exception ex) { Common.General.BLLoger.Debug(ex); throw new Exception(Resource.B0022); } DateTime end = DateTime.Now; if (savetoDBInterval == 0) { mLog.Debug("保存工程數據到數據庫,耗時" + (end - start).Milliseconds.ToString()); } else { //mLog.Debug("不保存工程數據到數據庫,耗時" + (end - start).Milliseconds.ToString()); } return status; }
public bool RemoveData(PLCData_pda_Info data) { try { return plcDataDAL.Delete(data.pda_iRecordID); } catch { return false; } }
/// <summary> /// 1,savetoDBInterval等於0時,才將數據寫入數據庫,部分時間才重新計算 /// </summary> /// <param name="uow"></param> /// <param name="schProj"></param> /// <param name="printProj"></param> /// <param name="shiftProject"></param> /// <param name="data"></param> /// <param name="savetoDBInterval"></param> /// <returns></returns> public bool Producing(DBContext uow, ScheduleProjList_swl_Info schProj, PrintProject_ppj_Info printProj, ShiftProjList_spl_Info shiftProject, PLCData_pda_Info data, int savetoDBInterval) { try { if (printProj.ppj_iSpeed > data.pda_iProductionSpeed * 60 && data.pda_iMachineSpeed != 0) { schProj.swl_cProjStatus = CustEnum.ProjectStatus.PROD_SLOW.ToString(); } else { schProj.swl_cProjStatus = CustEnum.ProjectStatus.PROD_IN.ToString(); } #region 更新生產工程信息 if (printProj != null) { DateTime dealtime = DateTime.Now; if (savetoDBInterval == 0) { var dinnerQuery = uow.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_swlID == schProj.swl_RecordID); dinnerQuery.And(d => d.dsm_ppjID == printProj.ppj_RecordID); int dinnerTime = (int)dinnerQuery.And(d => d.dnr_DSMID != Guid.Empty).List().Sum(d => (d.dnr_dEndTime.Value - d.dnr_dBeginTime.Value).TotalSeconds); printProj.ppj_iProdSumTime = printProj.ppj_iProjRunTime - printProj.ppj_iActualPrepairTime - printProj.ppj_iStopTime - printProj.ppj_iQCSumTime - dinnerTime; } printProj.ppj_iActualProdNum += data.pad_iQty - printProj.ppj_iCountProdNum; printProj.ppj_iCountProdNum = data.pad_iQty; printProj.ppj_fProdSpeed = data.pda_iProductionSpeed; printProj.ppj_fMachineSpeed = data.pda_iMachineSpeed; printProj.ppj_dLastDate = dealtime; if (printProj.ppj_dProdBeginTime == null) { printProj.ppj_dProdBeginTime = dealtime; } if (savetoDBInterval == 0) { uow.CurrentSession.Update(printProj); } #region 更新班次內工程信息 ///增加數量 int diffQTY = shiftProject.spl_iCalQTY - shiftProject.spl_iQTY; if (shiftProject.spl_iBeginQTY == 0 && shiftProject.spl_iCalQTY == 0) { shiftProject.spl_iBeginQTY = 0; shiftProject.spl_iQTY = 0; } shiftProject.spl_iEndQTY = data.pad_iQty; shiftProject.spl_iCalQTY = shiftProject.spl_iEndQTY - shiftProject.spl_iBeginQTY; shiftProject.spl_iQTY = shiftProject.spl_iCalQTY - diffQTY; shiftProject.spl_dLastDate = dealtime; if (shiftProject.spl_dProdBegin == null) { shiftProject.spl_dProdBegin = dealtime; } if (savetoDBInterval == 0) { var splDinnerQuery = uow.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_swlID == schProj.swl_RecordID); splDinnerQuery.And(d => d.dsm_splID == shiftProject.spl_RecordID); int splDinnerTime = (int)splDinnerQuery.And(d => d.dnr_DSMID != Guid.Empty).List().Sum(d => (d.dnr_dEndTime.Value - d.dnr_dBeginTime.Value).TotalSeconds); shiftProject.spl_iProdSumTime = shiftProject.spl_iRunTime - shiftProject.spl_iPrepairTime - shiftProject.spl_iStopTime - shiftProject.spl_iQCTime - splDinnerTime; uow.CurrentSession.Update(shiftProject); } #endregion } #endregion return true; } catch (Exception ex) { uow.CanCommit = false; mLog.Error("PLCBL.Producing" + ex); return false; } }
/// <summary> /// 生產中停機 /// </summary> /// <param name="uow"></param> /// <param name="schProj"></param> /// <param name="printProj"></param> /// <param name="shiftProject"></param> /// <param name="data"></param> /// <returns></returns> public bool ProduceStop(DBContext uow, ScheduleProjList_swl_Info schProj, PrintProject_ppj_Info printProj, ShiftProjList_spl_Info shiftProject, PLCData_pda_Info data) { try { #region 停機記錄 ProjectStopRecord_psrd_Info psrd = new ProjectStopRecord_psrd_Info(); psrd.psrd_RecordID = Guid.NewGuid(); psrd.psrd_PPJID = shiftProject.spl_PPJID; psrd.psrd_SPLID = shiftProject.spl_RecordID; psrd.psrd_dBeginTime = schProj.PROD_STOP_Datetime; psrd.psrd_dAddDate = DateTime.Now; psrd.psrd_dLastDate = DateTime.Now; psrd.psrd_cTypeID = CustEnum.RecordType.NORMAL.ToString(); psrd.psrd_iPredictStopTime = 0; psrd.psrd_lSync = false; uow.CurrentSession.Save(psrd); #endregion #region 更新印刷工程信息 schProj.swl_cProjStatus = CustEnum.ProjectStatus.PROD_STOP.ToString(); schProj.swl_dStatusChange = DateTime.Now; schProj.swl_dLastDate = DateTime.Now; schProj.swl_iIsByModify = true; uow.CurrentSession.Update(schProj); #endregion #region 生产工程 printProj.ppj_fMachineSpeed = data.pda_iMachineSpeed; printProj.ppj_iStopTimes += 1; uow.CurrentSession.Update(printProj); #endregion #region 班次內工程 shiftProject.spl_iStopTimes += 1; uow.CurrentSession.Update(shiftProject); #endregion #region 用餐記錄 //工程在生產中進入就餐,但由於工程進入生產中停機狀態有一定時間的約定延遲,如果超過這個時間,進入停機狀態,需要更新就餐時工程的狀態 var dinnerQuery = uow.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_swlID == schProj.swl_RecordID); dinnerQuery.And(d => d.dsm_ppjID == printProj.ppj_RecordID); dinnerQuery.And(d => d.dsm_splID == shiftProject.spl_RecordID); dinnerQuery.And(d => d.dsm_cProjectStatus == CustEnum.ProjectStatus.PROD_IN.ToString()); dinnerQuery = dinnerQuery.OrderBy(d => d.dnr_dBeginTime).Desc; var listDinner = dinnerQuery.And(d => d.dnr_DSMID != null).List(); if (listDinner.Count > 0) { DinnerRecord_dnr_Info dnr = listDinner[0]; if (dnr.dnr_dBeginTime >= psrd.psrd_dBeginTime)//用餐開始時間在停機開始時間之後,因此需要將用餐記錄的工程狀態更新為“PROD_STOP”,並更新停機記錄ID { dnr.dsm_cProjectStatus = CustEnum.ProjectStatus.PROD_STOP.ToString(); dnr.dsm_psrdID = psrd.psrd_RecordID; dnr.dnr_dLastDate = DateTime.Now; uow.CurrentSession.Update(dnr); } } #endregion return true; } catch (Exception ex) { uow.CanCommit = false; mLog.Error("PLCBL.ProduceStop" + ex); return false; } }
/// <summary> /// 重新開始生產,狀態改變規則:生產中停機-->生產中 /// </summary> /// <param name="uow"></param> /// <param name="schProj"></param> /// <param name="printProj"></param> /// <param name="shiftProject"></param> /// <param name="data"></param> /// <returns></returns> public bool ProduceRestart(DBContext uow, ScheduleProjList_swl_Info schProj, PrintProject_ppj_Info printProj, ShiftProjList_spl_Info shiftProject, PLCData_pda_Info data) { try { #region 更新印刷工程信息 schProj.swl_cProjStatus = CustEnum.ProjectStatus.PROD_IN.ToString(); schProj.swl_dStatusChange = DateTime.Now; schProj.swl_dLastDate = DateTime.Now; schProj.swl_iIsByModify = true; uow.CurrentSession.Update(schProj); #endregion #region 更新生產中停機的結束時間 ProjectStopRecord_psrd_Info psrd_old; var query = uow.CurrentSession.QueryOver<ProjectStopRecord_psrd_Info>(); query.And(d => d.psrd_SPLID == shiftProject.spl_RecordID); query.And(d => d.psrd_dEndTime == null); query.And(d => d.psrd_cTypeID == CustEnum.RecordType.NORMAL.ToString()); IList<ProjectStopRecord_psrd_Info> list = query.List<ProjectStopRecord_psrd_Info>(); if (list.Count > 0) { psrd_old = list[0]; psrd_old.psrd_dEndTime = DateTime.Now; psrd_old.psrd_dLastDate = DateTime.Now; //停機就餐時間 var stopDinnerQuery = uow.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_ppjID == printProj.ppj_RecordID); stopDinnerQuery.And(d => d.dsm_splID == shiftProject.spl_RecordID); stopDinnerQuery.And(d => d.dsm_psrdID == psrd_old.psrd_RecordID); stopDinnerQuery.And(d => d.dsm_cProjectStatus == CustEnum.ProjectStatus.PROD_STOP.ToString() || d.dsm_cProjectStatus == CustEnum.ProjectStatus.PROD_STOP_OT.ToString()); int stopDinnerTime = (int)stopDinnerQuery.And(d => d.dnr_DSMID != Guid.Empty).List().Sum(d => (d.dnr_dEndTime.Value - d.dnr_dBeginTime.Value).TotalSeconds); psrd_old.psrd_iActualStopTime = (int)(psrd_old.psrd_dEndTime.Value - psrd_old.psrd_dBeginTime.Value).TotalSeconds - stopDinnerTime; uow.CurrentSession.Update(psrd_old); printProj.ppj_fMachineSpeed = data.pda_iMachineSpeed; printProj.ppj_iStopTime += psrd_old.psrd_iActualStopTime; //實際準備時間=生產結束時間-工程開始時間-就餐時間 // printProj.ppj_iActualPrepairTime = (int)(printProj.ppj_dProdBeginTime.Value - printProj.ppj_dProjBeginTime).TotalSeconds - stopDinnerTime; printProj.ppj_iProdSumTime = printProj.ppj_iProjRunTime - printProj.ppj_iStopTime - printProj.ppj_iActualPrepairTime - printProj.ppj_iQCSumTime - stopDinnerTime; uow.CurrentSession.Update(printProj); shiftProject.spl_iStopTime += psrd_old.psrd_iActualStopTime; //int totalPrepare; //if (shiftProject.spl_dProdBegin.HasValue) //{ // totalPrepare = (int)(shiftProject.spl_dProdBegin.Value - shiftProject.spl_dBeginTime).TotalSeconds; //} //else //{ // totalPrepare = (int)(shiftProject.spl_dEndTime.Value - shiftProject.spl_dBeginTime).TotalSeconds; //} //shiftProject.spl_iPrepairTime = totalPrepare - stopDinnerTime; shiftProject.spl_iProdSumTime = shiftProject.spl_iRunTime - shiftProject.spl_iPrepairTime - shiftProject.spl_iQCTime - shiftProject.spl_iStopTime - stopDinnerTime; uow.CurrentSession.Update(shiftProject); } #endregion return true; } catch (Exception ex) { uow.CanCommit = false; mLog.Error("PLCBL.ProduceRestart" + ex); return false; } }