/// <summary> /// 获取输出的标签 /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="ObjectId">ID</param> /// <param name="OutTypevalue"></param> /// <returns></returns> public T GetLightTowerOutTag <T>(int ObjectId, int OutTypevalue, TagAreaAttributeEnum tagAreaAttributeEnum) where T : new() { List <T> list = null; T TagInfo = default(T); switch (OutTypevalue) { case (int)LightTowerEnum.red_light_on: list = tagService.GetWaTagAndTypeInfo <T>(tagAreaAttributeEnum, ObjectId, SystemTagCodeEnum.red_light_on.ToString()); break; case (int)LightTowerEnum.yellow_light_on: list = tagService.GetWaTagAndTypeInfo <T>(tagAreaAttributeEnum, ObjectId, SystemTagCodeEnum.yellow_light_on.ToString()); break; case (int)LightTowerEnum.green_light_on: list = tagService.GetWaTagAndTypeInfo <T>(tagAreaAttributeEnum, ObjectId, SystemTagCodeEnum.green_light_on.ToString()); break; case (int)LightTowerEnum.blue_light_on: list = tagService.GetWaTagAndTypeInfo <T>(tagAreaAttributeEnum, ObjectId, SystemTagCodeEnum.blue_light_on.ToString()); break; case (int)LightTowerEnum.white_light_on: list = tagService.GetWaTagAndTypeInfo <T>(tagAreaAttributeEnum, ObjectId, SystemTagCodeEnum.white_light_on.ToString()); break; } if (list != null && list.Count > 0) { TagInfo = list[0]; return(TagInfo); } return(TagInfo); }
/// <summary> /// 初始化:灯状态输出 /// </summary> public static void TaskInitial(TagAreaAttributeEnum tagAreaAttributeEnum) { string times = srpInnerLogManager.GetLastTimeByCode(SrpCode); lastDatetime = Convert.ToDateTime(times); //获取上一次的时间记录 if (tagAreaAttributeEnum == TagAreaAttributeEnum.machine_info) { List <MachineInfo> machines = machineInfoManager.SelectAll(null); foreach (MachineInfo machine in machines) { lightTowerTagManager.GreenStatusLightOutAsync(machine.machine_id, tagAreaAttributeEnum); } } else if (tagAreaAttributeEnum == TagAreaAttributeEnum.station_info) { List <station_info> stations = stationManager.SelectAll(-1); foreach (station_info station in stations) { lightTowerTagManager.GreenStatusLightOutAsync(station.station_id, tagAreaAttributeEnum); } } //公式需要优化 // ////读取所有的设备工时异常配置 //deviceTimeErrCfgList = errorConfigManager.GetErrorConfig(SystemTagCodeEnum.machine_time_error.ToString()); //if(deviceTimeErrCfgList != null && deviceTimeErrCfgList.Count>0)//存在工时的异常配置 //{ // CTManager.CtValueChangedEvent += CTManager_CtValueChangedEvent; //} }
/// <summary> /// 人员签到处理.以Tag点形式上抛的。方案待优化!!!!!!!!!!!!!!!!!!! /// </summary> /// <param name="machineCode"></param> /// <param name="stationId"></param> /// <param name="deviceTagValueInfo"></param> /// <param name="tagAreaAttributeEnum"></param> public static void HandlePersonArrivalForTag(string machineCode, int stationId, DeviceTagValueInfo deviceTagValueInfo, TagAreaAttributeEnum tagAreaAttributeEnum = TagAreaAttributeEnum.station_info) { string subject = string.Empty, content = string.Empty; ErrorObject errorObject = andonErrorManager.AckErrorLogPerson(machineCode, stationId, deviceTagValueInfo, tagAreaAttributeEnum); if (errorObject != null) { HandlePersonArrival(null, null, errorObject); } }
/// <summary> /// 灯颜色输出写值 /// </summary> /// <param name="device_id"></param> /// <param name="ColorValue"></param> /// <param name="tagAreaAttributeEnum"></param> public bool WriteLightColorAsync(int device_id, int ColorValue, TagAreaAttributeEnum tagAreaAttributeEnum, int Value) { bool bit = false; if (tagAreaAttributeEnum == TagAreaAttributeEnum.machine_info) { MachineTagInfo tagInfo = GetLightTowerOutTag <MachineTagInfo>(device_id, ColorValue, tagAreaAttributeEnum); if (tagInfo != null) { if (ScadaAPIConfig.EnableScadaApi) { bit = ScadaAPIHelper.WriteValueAsync(tagInfo.tag_code, Value); if (bit == false) { bit = ScadaAPIHelper.WriteValueAsync(tagInfo.tag_code, Value);//失败再次写入 } } else { //MqttManager.MqttHelper.WriteValueToWA(tagInfo.tag_code, Value);//写值 } } } else if (tagAreaAttributeEnum == TagAreaAttributeEnum.station_info) { try { StationTagInfo tagInfo = GetLightTowerOutTag <StationTagInfo>(device_id, ColorValue, tagAreaAttributeEnum); if (tagInfo != null) { if (ScadaAPIConfig.EnableScadaApi) { bit = ScadaAPIHelper.WriteValueAsync(tagInfo.tag_code, Value); if (bit == false) { bit = ScadaAPIHelper.WriteValueAsync(tagInfo.tag_code, Value);//失败再次写入 } } else { //MqttManager.MqttHelper.WriteValueToWA(tagInfo.tag_code, Value);//写值 } } } catch (Exception ex) { Console.WriteLine(ex.Message); bit = false; } } return(bit); }
/// <summary> /// 现场正常状态下绿灯输出 /// </summary> /// <param name="tagAreaAttributeEnum"></param> public bool GreenStatusLightOutAsync(int device_id, TagAreaAttributeEnum tagAreaAttributeEnum) { List <error_log> list; bool bit = false; list = errorLogManager.GetAllUnfinishedByDeviceId(device_id); if (list != null && list.Count > 0)//有异常,绿灯熄灭 { bit = WriteLightColorAsync(device_id, (int)LightTowerEnum.green_light_on, tagAreaAttributeEnum, 0); } else { bit = WriteLightColorAsync(device_id, (int)LightTowerEnum.green_light_on, tagAreaAttributeEnum, 1); } return(bit); }
/// <summary> /// 处理异常解除,以tag点方式,待实际场合进一步优化代码!!!!!!!!!!!!!!!!!!!!!!!!!!1 /// </summary> /// <param name="machineCode"></param> /// <param name="stationId"></param> /// <param name="deviceTagValueInfo"></param> /// <param name="tagAreaAttributeEnum"></param> public static void HandleErrorAckForTag(string machineCode, int stationId, DeviceTagValueInfo deviceTagValueInfo, TagAreaAttributeEnum tagAreaAttributeEnum = TagAreaAttributeEnum.station_info) { string subject = string.Empty, content = string.Empty; ErrorObject errorObject = null; if (deviceTagValueInfo.system_tag_code == SystemTagCodeEnum.material_require.ToString()) { errorObject = andonErrorManager.AckErrorLogDetailsForMat(machineCode, stationId, deviceTagValueInfo, tagAreaAttributeEnum); } else { errorObject = andonErrorManager.AckErrorLogDetails(machineCode, stationId, deviceTagValueInfo, tagAreaAttributeEnum); } HandleErrorAck(null, null, errorObject); }
/// <summary> /// 责任人员现场签到 /// 现场提交有3格式:card或者id&card,id&card&M /// 格式1:只有card内容时,为HMI触控屏发送的格式,此方式只能确认第一条记录,HMI触控屏无物料呼叫列表; /// 格式2:id&card格式:为Web网页异常呼叫时传递内容。Id为error_log表id,card为人员卡号; /// 格式3:id&card&M:为web网页物料呼叫传递内容,id为material_require_info表id,card为人员卡号,M为特殊标识符 /// </summary> /// <param name="ErrorWatchList">异常监控队列</param> /// <param name="MachineCode">设备编码</param> /// <param name="StationId">站位id</param> /// <param name="TagValueInItem">标签值对象</param> /// <returns></returns> public ErrorObject AckErrorLogPerson(string MachineCode, int StationId, DeviceTagValueInfo TagValueInItem, TagAreaAttributeEnum tagAreaAttributeEnum = TagAreaAttributeEnum.station_info) { ErrorTypeService errorTypeService = new ErrorTypeService(); person person = null; ErrorObject errorObject = null; string PersonCardId = String.Empty; int errorLogId = -1; material_request_info reInfo = null; TagIdAndValue valueObject = tagService.GetTagValue(TagValueInItem.tag_value); if (tagAreaAttributeEnum == TagAreaAttributeEnum.machine_info) { MachineInfo machine = AndonGlobalCfg.MachinesList.FirstOrDefault(x => x.machine_code == MachineCode); errorObject = LoadErrorLogObject(TagValueInItem.device_id, TagValueInItem.system_tag_code, machine.unit_no, machine.line_id); } else if (tagAreaAttributeEnum == TagAreaAttributeEnum.station_info) { station_info station = AndonGlobalCfg.StationsList.FirstOrDefault(x => x.station_id == StationId); errorObject = LoadErrorLogObject(TagValueInItem.device_id, TagValueInItem.system_tag_code, station.unit_no, station.line_id); } if (valueObject.value == null || valueObject.value.Trim().Length == 0) { return(null); //值无效 } else { if (valueObject.id >= 0 && valueObject.value.Length > 0 && valueObject.value2.Length == 0) { errorLogId = valueObject.id; PersonCardId = valueObject.value; Console.WriteLine("AckErrorLogPerson,errorLogId=" + errorLogId + ",PersonCardId=" + PersonCardId); } else if (valueObject.id >= 0 && valueObject.value.Length > 0 && valueObject.value2.Length > 0)//物料呼叫传递内容 { reInfo = materialRequestInfoManager.SelectById(valueObject.id); PersonCardId = valueObject.value; Console.WriteLine("AckErrorLogPerson,物料呼叫传递,PersonCardId=" + PersonCardId); } else if (valueObject.id < 0 && valueObject.value.Length > 0) { PersonCardId = valueObject.value; Console.WriteLine("AckErrorLogPerson,PersonCardId=" + PersonCardId); } } if (errorObject.eConfig.check_arrival == (int)ArrivalModeEnum.CardArrival) //以卡信息签到 { if (PersonCardId.Length > 0) //获取具体的描述对象 { person = personManager.GetPersonByCardId(PersonCardId); if (person == null) { return(null); } } else { return(null); } } if (errorObject != null && errorObject.ELog != null) { errorObject.ELog.arrival_time = TagValueInItem.insert_time.AddHours(GlobalDefine.SysTimeZone); //时间加8小时,更新结束时间 Dictionary <string, object> dic = new Dictionary <string, object>(); if (errorObject.eConfig.check_arrival == (int)ArrivalModeEnum.CardArrival) { errorObject.eSignedPersons.Add(person); //记录签到的人员 errorObject.ELog.arrival_person_id = person.id; //更新具体的id信息 dic.Add("arrival_person_id", errorObject.ELog.arrival_person_id); errorObject.eSignedPersons.Add(person); //签到人员记录 } dic.Add("arrival_time", errorObject.ELog.arrival_time); errorLogManager.Update(errorObject.ELog, dic); //提交数据库 Console.WriteLine("AckErrorLogPerson,执行结束,id=" + errorObject.ELog.id); return(errorObject); } return(null); }
/// <summary> /// 确认并解除异常记录,用于现场提交解除. /// 格式1:id&M&M:为web网页物料呼叫传递内容,id为material_require_info表id,M为特殊标识符 /// 格式2:id:为web网页物料呼叫传递内容,id为error_log表id /// </summary> /// <param name="ErrorWatchList">当前监控队列</param> /// <param name="MachineCode">设备编码</param> /// <param name="StationId">站位id</param> /// <param name="TagValueInItem">标签值对象</param> /// <returns>正确执行返回ErrorObject,错误执行返回null</returns> public ErrorObject AckErrorLogDetailsForMat(string MachineCode, int StationId, DeviceTagValueInfo TagValueInItem, TagAreaAttributeEnum tagAreaAttributeEnum) { ErrorTypeService errorTypeService = new ErrorTypeService(); ErrorObject errorObject = null; int errorLogId = -1; material_request_info reInfo = null; //支持两种格式,sn或者id&sn,id为异常记录的唯一标识号 TagIdAndValue valueObject = tagService.GetTagValue(TagValueInItem.tag_value); if (tagAreaAttributeEnum == TagAreaAttributeEnum.machine_info) { MachineInfo machine = AndonGlobalCfg.MachinesList.FirstOrDefault(x => x.machine_code == MachineCode); errorObject = LoadErrorLogObject(TagValueInItem.device_id, TagValueInItem.system_tag_code, machine.unit_no, machine.line_id); } else if (tagAreaAttributeEnum == TagAreaAttributeEnum.station_info) { station_info station = AndonGlobalCfg.StationsList.FirstOrDefault(x => x.station_id == StationId); errorObject = LoadErrorLogObject(TagValueInItem.device_id, TagValueInItem.system_tag_code, station.unit_no, station.line_id); } if (valueObject.value != null && valueObject.value.Trim().Length >= 0) { if (AndonGlobalCfg.MaterialType == 0) { errorLogId = valueObject.id; } else { if (valueObject.id >= 0 && valueObject.value.Length > 0 && valueObject.value2.Length > 0)//物料呼叫确认 { reInfo = materialRequestInfoManager.SelectById(valueObject.id); Console.WriteLine("AckErrorLogDetails,errorLogId=" + errorLogId); Console.WriteLine("AckErrorLogDetails,物料呼叫=" + valueObject.id); } } } if (errorObject != null && errorObject.ELog != null) { if (reInfo != null) //物料呼叫确认的对象 { errorObject.ELog.error_type_id = reInfo.material_id; //更新为物料id信息 errorObject.ELog.maintenance_time = TagValueInItem.insert_time.AddHours(GlobalDefine.SysTimeZone); errorObject.RequireMat = reInfo; } else { errorObject.ELog.error_type_id = -1; //只有呼叫,无具体信息 errorObject.eTypeDetails = null; } errorObject.ELog.release_time = TagValueInItem.insert_time.AddHours(GlobalDefine.SysTimeZone); //以变量值的时间更新结束时间 Dictionary <string, object> dic = new Dictionary <string, object>(); //加入需要更新的字段信息 if (errorObject.ELog.error_type_id > 0) { dic.Add("error_type_id", errorObject.ELog.error_type_id);//未确认原因的再给值。物料呼叫监测typeid会提前赋值 dic.Add("maintenance_time", errorObject.ELog.maintenance_time); } dic.Add("release_time", errorObject.ELog.release_time); errorLogManager.Update(errorObject.ELog, dic); //提交数据库 Console.WriteLine("AckErrorLogDetails,确认成功,id=" + errorObject.ELog.id); return(errorObject); } return(null); }
/// <summary> /// 确认并解除异常记录,用于现场提交解除. /// 支持三种格式:sn或者id&sn,id&M&M /// 格式1:只有card内容时,为HMI触控屏发送的格式,此方式只能确认第一条记录,HMI触控屏无物料呼叫列表; /// </summary> /// <param name="ErrorWatchList">当前监控队列</param> /// <param name="MachineCode">设备编码</param> /// <param name="StationId">站位id</param> /// <param name="TagValueInItem">标签值对象</param> /// <returns>正确执行返回ErrorObject,错误执行返回null</returns> public ErrorObject AckErrorLogDetails(string MachineCode, int StationId, DeviceTagValueInfo TagValueInItem, TagAreaAttributeEnum tagAreaAttributeEnum) { ErrorTypeService errorTypeService = new ErrorTypeService(); error_type_details eDetails = null; ErrorObject errorObject = null; string TypeSn = string.Empty; int errorLogId = -1; Dictionary <string, object> dic = new Dictionary <string, object>();//加入需要更新的字段信息 //支持两种格式,sn或者id&sn,id为异常记录的唯一标识号 TagIdAndValue valueObject = tagService.GetTagValue(TagValueInItem.tag_value); if (tagAreaAttributeEnum == TagAreaAttributeEnum.machine_info) { MachineInfo machine = AndonGlobalCfg.MachinesList.FirstOrDefault(x => x.machine_code == MachineCode); errorObject = LoadErrorLogObject(TagValueInItem.device_id, TagValueInItem.system_tag_code, machine.unit_no, machine.line_id); } else if (tagAreaAttributeEnum == TagAreaAttributeEnum.station_info) { station_info station = AndonGlobalCfg.StationsList.FirstOrDefault(x => x.station_id == StationId); errorObject = LoadErrorLogObject(TagValueInItem.device_id, TagValueInItem.system_tag_code, station.unit_no, station.line_id); } if (errorObject != null && errorObject.eConfig != null && errorObject.eConfig.check_ack == (int)AckModeEnum.CodeAck) { if (valueObject.value != null && valueObject.value.Trim().Length >= 0) { if (valueObject.id >= 0 && valueObject.value.Length > 0 && valueObject.value2.Length == 0) { errorLogId = valueObject.id; TypeSn = valueObject.value; Console.WriteLine("AckErrorLogDetails,errorLogId=" + errorLogId + ",TypeSn=" + TypeSn); } else if (valueObject.id < 0 && valueObject.value.Length > 0) { TypeSn = valueObject.value; Console.WriteLine("AckErrorLogDetails,TypeSn=" + TypeSn); } } if (TypeSn.Length > 0)//获取具体的描述对象 { eDetails = errorTypeService.GetTypeDetails(-1, TypeSn); if (eDetails == null) { return(null); } } else { return(null); } } else if (errorObject != null && errorObject.eConfig != null && errorObject.eConfig.check_ack == (int)AckModeEnum.WithoutCodeAck)//不需要代码解除的 { int.TryParse(valueObject.value, out errorLogId); if (errorLogId != errorObject.ELog.id)//传递的id不匹配 { Console.WriteLine("安灯解除出错,id不匹配退出:errorLogId=" + errorLogId + "errorObject.ELog.id=" + errorObject.ELog.id); return(null); } } if (errorObject != null && errorObject.ELog != null) { if (errorObject.eConfig.check_ack == (int)AckModeEnum.CodeAck) { errorObject.ELog.error_type_id = eDetails.id; //更新具体的id信息 errorObject.eTypeDetails = eDetails; //记录详细原因 errorObject.ELog.maintenance_time = TagValueInItem.insert_time.AddHours(GlobalDefine.SysTimeZone); dic.Add("maintenance_time", errorObject.ELog.maintenance_time); dic.Add("error_type_id", errorObject.ELog.error_type_id);//未确认原因的再给值。物料呼叫监测typeid会提前赋值 } errorObject.ELog.release_time = TagValueInItem.insert_time.AddHours(GlobalDefine.SysTimeZone); //以变量值的时间更新结束时间 dic.Add("release_time", errorObject.ELog.release_time); int count = errorLogManager.Update(errorObject.ELog, dic); //提交数据库 if (count > 0) { Console.WriteLine("AckErrorLogDetails,确认成功,id=" + errorObject.ELog.id); } else { Console.WriteLine("安灯解除更新数据失败!"); } return(errorObject); } else { Console.WriteLine("安灯解除出错,errorObject != null && errorObject.ELog !=null 失败!"); } return(null); }
/// <summary> /// 增加设备新的异常记录。会将该异常的所有配置,记录,人员,类型对象一次性加载并返回 /// </summary> /// <param name="TagValueObject"></param> /// <param name="eCodeDeatials"></param> /// <returns>ErrorObject:包含该异常的配置,记录,需要通知的人员,以及类型</returns> public ErrorObject AddNewErrorLog(DeviceTagValueInfo TagValueObject, ErrorObject errorObject, TagAreaAttributeEnum tagAreaAttributeEnum, string AppendDetailsInfo = "") { int id = -1; error_log eLog = new error_log(); MachineInfo machine = null; station_info station = null; Pro_schedule_machine deviceSchedule = null; if (tagAreaAttributeEnum == TagAreaAttributeEnum.machine_info)//设备形式 { machine = AndonGlobalCfg.MachinesList.FirstOrDefault(x => x.machine_code == TagValueObject.device_code); deviceSchedule = proScheduleMachineManager.SelectOnLineWorkorder(TagValueObject.device_code); } else if (tagAreaAttributeEnum == TagAreaAttributeEnum.station_info)//站位形式 { station = AndonGlobalCfg.StationsList.FirstOrDefault(x => x.station_id == TagValueObject.device_id); deviceSchedule = proScheduleMachineManager.SelectOnLineWorkorder(TagValueObject.device_code); } if (machine != null || station != null) { if (deviceSchedule != null)//从在制进度中获取工单机种 { eLog.pn = deviceSchedule.part_num; eLog.work_order = deviceSchedule.work_order; } if (TagValueObject.system_tag_code == SystemTagCodeEnum.machine_time_error.ToString()) //工时异常类型 { eLog.start_time = TagValueObject.insert_time; //CT从CT模块过来,无时差 } else if (TagValueObject.system_tag_code == SystemTagCodeEnum.material_require.ToString()) //物料呼叫类型 { eLog.start_time = TagValueObject.insert_time.AddHours(GlobalDefine.SysTimeZone); //加上时区 int requireCount = 0, materialId = 0; //支持两种格式:数量,数量&物料id TagIdAndValue valueObject = tagService.GetTagValue(TagValueObject.tag_value); if (valueObject.id > 0 && valueObject.value.Length > 0) { requireCount = valueObject.id; int.TryParse(valueObject.value, out materialId); //id为物料呼叫的id eLog.error_type_id = materialId; //物料呼叫的id直接给到error_type_id字段 } } else { eLog.start_time = TagValueObject.insert_time.AddHours(GlobalDefine.SysTimeZone); //加上时区 } eLog.arrival_time = default(DateTime); //分配默认时间 eLog.release_time = default(DateTime); //分配默认时间 eLog.maintenance_time = default(DateTime); //分配默认时间 if (machine != null) { eLog.machine_code = TagValueObject.device_code; eLog.station_id = machine.station_id; eLog.line_id = machine.line_id; eLog.unit_no = machine.unit_no; } else { eLog.station_id = station.station_id; eLog.machine_code = station.station_name_en; eLog.line_id = station.line_id; eLog.unit_no = station.unit_no; } eLog.system_tag_code = TagValueObject.system_tag_code; eLog.error_name = errorObject.eConfig.error_name + AppendDetailsInfo; if (errorObject.eConfig.check_ack == (int)AckModeEnum.NoAck)//只是记录,不需要确认 { eLog.release_time = eLog.start_time; } eLog.ack_person_id = -1;//确认人员为空 if (eLog.error_type_id == 0) { eLog.error_type_id = -1;//确认编码为空 } id = errorLogManager.Insert(eLog); //插入数据库 if (id > 0) { eLog.id = id; //id记录 errorObject.ELog = eLog; } } return(errorObject); }
/// <summary> /// 根据Tag值信息加载所有信息.外部处理进入,需要确认和优化?????????? /// </summary> /// <param name="TagValueObject"></param> /// <param name="tagAreaAttributeEnum"></param> /// <returns></returns> public ErrorObject LoadErrorObject(DeviceTagValueInfo TagValueObject, TagAreaAttributeEnum tagAreaAttributeEnum) { ErrorObject errorObject = new ErrorObject(); List <error_config_pn> eCfgPns; string partNo = string.Empty;//当前机种 Pro_schedule_machine deviceSchedule = null; if (tagAreaAttributeEnum == TagAreaAttributeEnum.machine_info)//设备形式 { MachineInfo machine = AndonGlobalCfg.MachinesList.FirstOrDefault(x => x.machine_id == TagValueObject.device_id); if (machine != null) { errorObject.eConfig = errorConfigManager.GetFirstErrorConfig(TagValueObject.system_tag_code, machine.unit_no, machine.line_id); if (errorObject.eConfig == null) { errorObject.eConfig = errorConfigManager.GetFirstErrorConfig(TagValueObject.system_tag_code, machine.unit_no); } } } else if (tagAreaAttributeEnum == TagAreaAttributeEnum.station_info)//站位形式 { station_info station = AndonGlobalCfg.StationsList.FirstOrDefault(x => x.station_id == TagValueObject.device_id); if (station != null) { errorObject.eConfig = errorConfigManager.GetFirstErrorConfig(TagValueObject.system_tag_code, station.unit_no, station.line_id); if (errorObject.eConfig == null) { errorObject.eConfig = errorConfigManager.GetFirstErrorConfig(TagValueObject.system_tag_code, station.unit_no); } } } if (errorObject.eConfig == null) { return(errorObject); } errorObject.DeviceCode = TagValueObject.device_code; if (TagValueObject.system_type_code == SystemTagCodeEnum.quality_error.ToString()) { eCfgPns = errorConfigPnManager.GetCfgPns(errorObject.eConfig.id);//获取该异常配置的机种信息 deviceSchedule = proScheduleMachineManager.SelectOnLineWorkorder(TagValueObject.device_code); if (deviceSchedule != null) { partNo = deviceSchedule.part_num;//获取当前机种 } if (eCfgPns != null && eCfgPns.Count > 0) { if (eCfgPns.Any(x => x.part_num.Equals(partNo))) //当前机种在此配置里面 { errorObject.eCfgPnList = eCfgPns; } } } if (errorObject.eConfig != null) { errorObject.eCfgPersonList = errorPersonManager.GetCfgPersonList(errorObject.eConfig.id); //需通知的配置人员加载 eCfgPns = errorConfigPnManager.GetCfgPns(errorObject.eConfig.id); errorObject.eCfgPnList = eCfgPns; //关联的机种信息加载 } return(errorObject); }
/// <summary> /// 队列超时监测 /// </summary> private static void TimeoutWatch(TagAreaAttributeEnum tagAreaAttributeEnum) { DateTime dateTime = DateTime.Now.AddHours(GlobalDefine.SysTimeZone);//此处需要加上时区 int timeDiffMin = 0, ratio = 0; string subject = string.Empty, content = string.Empty; AndonGlobalCfg.ErrorWatchList.Clear(); var list = errorLogManager.GetAllUnfinishedByDeviceCode(null); if (list != null && list.Count > 0) { foreach (var item in list) { var errObject = andonErrorManager.LoadErrorLogObject(item); AndonGlobalCfg.ErrorWatchList.Add(errObject); } } try { for (int i = 0; i < AndonGlobalCfg.ErrorWatchList.Count; i++) { ErrorObject errItem = AndonGlobalCfg.ErrorWatchList[i]; if (errItem.eConfig == null) { continue; } TimeSpan interval = dateTime - errItem.ELog.start_time; timeDiffMin = interval.Days * 24 + interval.Hours * 60 + interval.Minutes; subject = "安灯系统" + errItem.ELog.error_name; content = String.Format("{0}发生{1},已持续{2}分钟,已经超时!" + MessageAdditional, errItem.DeviceCode, subject, timeDiffMin); if (errItem.eMsgedPersonList.Any(x => x.eLogPerson.message_level == (int)MessageLevel.Level1 && x.eLogPerson.message_flow == EventHandleFlowEnum.Event_Trigger.ToString()) == false) { errorMessageManager.SendErrorMessageAsync(errItem, (int)MessageLevel.Level1, EventHandleFlowEnum.Event_Trigger, subject, content);//一级人员通知,此处是补充通知,如果系统down机情况 } if (timeDiffMin >= errItem.eConfig.timeout_setting)//大于超时时间 { ratio = (timeDiffMin / errItem.eConfig.timeout_setting) + 1; if (ratio > (int)MessageLevel.Level3)//最大级别限制 { ratio = (int)MessageLevel.Level3; } if (ratio > (int)MessageLevel.Level1 && ratio <= (int)MessageLevel.Level3) //限定在2-3级 { if (errItem.eCfgPersonList.Any(x => x.eCfgPerson.person_level == ratio)) //存在该级别的人员 { if (errItem.eMsgedPersonList.Any(x => x.eLogPerson.message_level == ratio && x.eLogPerson.message_flow == EventHandleFlowEnum.Event_Timeout.ToString()) == false) { error_log logItem = errorLogManager.GetErrorLogById(errItem.ELog.id); if (logItem != null)//检查数据库是否还存在 { Console.WriteLine("error timeout level2,time= " + DateTime.Now.ToLongTimeString() + " " + errItem.DeviceCode + " " + errItem.eConfig.error_name); errorMessageManager.SendErrorMessageAsync(errItem, ratio, EventHandleFlowEnum.Event_Timeout, subject, content); } else { AndonGlobalCfg.ErrorWatchList.RemoveAll(x => x.ELog.id == errItem.ELog.id); } } } } } } } catch (Exception ex) { srpLogManager.Insert("TimeoutWatch error:" + ex.Message); } }
/// <summary> /// 异常判断与处理 /// </summary> /// <param name="deviceTagValueItem">设备Tag值</param> /// <param name="stationTagValueItem">站位Tag值</param> private static void ErrorHandle(DeviceTagValueInfo deviceTagValueItem, TagAreaAttributeEnum tagAreaAttributeEnum, string DetailsInfo = "", int MaterialId = -1) { bool dbExist = false; //根据类型检索是否已经存在 if (deviceTagValueItem.system_tag_code != SystemTagCodeEnum.machine_time_error.ToString()) //工时异常不查询数据库 { if (MaterialId > 0) //物料呼叫有传入id则特殊处理 { if (tagAreaAttributeEnum == TagAreaAttributeEnum.machine_info) { dbExist = errorLogManager.CheckMaterialRequireExist(deviceTagValueItem.system_tag_code, MaterialId, deviceTagValueItem.device_code); } else if (tagAreaAttributeEnum == TagAreaAttributeEnum.station_info) { dbExist = errorLogManager.CheckMaterialRequireExist(deviceTagValueItem.system_tag_code, MaterialId, "", deviceTagValueItem.device_id); } } else { if (tagAreaAttributeEnum == TagAreaAttributeEnum.machine_info) { dbExist = errorLogManager.CheckExist(deviceTagValueItem.system_tag_code, deviceTagValueItem.device_code); } else if (tagAreaAttributeEnum == TagAreaAttributeEnum.station_info) { dbExist = errorLogManager.CheckExist(deviceTagValueItem.system_tag_code, "", deviceTagValueItem.device_id); //list = ErrorWatchList.Where(x => x.ELog.station_id == deviceTagValueItem.device_id && // x.ELog.system_tag_code == deviceTagValueItem.system_tag_code).ToList(); } } } //查找当前是否配置有关联的机种信息 ErrorObject errorObject = andonErrorManager.LoadErrorObject(deviceTagValueItem, tagAreaAttributeEnum); //获取到配置,并不存在 if (errorObject != null && errorObject.eConfig != null && errorObject.eConfig.error_active == 1 && dbExist == false) //不存在,且激活,则新增 { errorObject = andonErrorManager.AddNewErrorLog(deviceTagValueItem, errorObject, tagAreaAttributeEnum); //记录增加至数据库 if (errorObject != null && errorObject.eConfig != null) { if (errorObject.eConfig.check_ack > (int)AckModeEnum.NoAck) //只是记录,不需要确认,返回空对象 { if (errorObject.eConfig.trigger_message_type > (int)ErrorMsgType.None) //异常发生时需要消息通知 { string subject = "安灯系统" + deviceTagValueItem.system_code_name_cn + DetailsInfo; string content = String.Format("{0}发生{1},请相关人员尽快前往解决!" + MessageAdditional, deviceTagValueItem.device_code, subject); errorMessageManager.SendErrorMessageAsync(errorObject, (int)MessageLevel.Level1, EventHandleFlowEnum.Event_Trigger, subject, content); //发送消息通知 } if (errorObject.eConfig.trigger_out_color > (int)LightTowerEnum.None) //灯颜色输出.需要确认解除的才亮灯 { //写值 lightTowerTagManager.WriteLightColorAsync(deviceTagValueItem.device_id, errorObject.eConfig.trigger_out_color, tagAreaAttributeEnum, 1); lightTowerTagManager.GreenStatusLightOutAsync(deviceTagValueItem.device_id, tagAreaAttributeEnum);//绿灯状态切换 Console.WriteLine("error handle finish,time= " + DateTime.Now.ToLongTimeString() + " " + errorObject.DeviceCode + " " + errorObject.DeviceId + " " + errorObject.eConfig.system_tag_code); } } } } }
/// <summary> /// Tag标签值变化监测 /// </summary> private static void TagValueWatch(TagAreaAttributeEnum tagAreaAttributeEnum) { DateTime dateTimeNow = DateTime.Now; //Console.WriteLine("---------------start to scan MongoDb,time span =" + lastDatetime.ToString() + " --" + dateTimeNow.ToString()+",Dt now="+ DateTime.Now.ToLongTimeString()); List <DeviceTagValueInfo> vList = new List <DeviceTagValueInfo>(); List <error_config_person> eCfgPersons = new List <error_config_person>(); string subject = string.Empty, content = string.Empty; int value = 0; string machineCode; int stationId; string mErrCode = string.Empty; List <MongoDbTag> Tags = new List <MongoDbTag>(); if (ScadaAPIConfig.EnableScadaApi == false)//本地版本 { var filterBuilder1 = Builders <LocalMongoDbTag> .Filter; var filter1 = filterBuilder1.And(filterBuilder1.Gt(x => x.ts, lastDatetime), filterBuilder1.Lte(x => x.ts, dateTimeNow), filterBuilder1.Ne(x => x.v, "*"), filterBuilder1.Ne(x => x.v, "")); var localTags = mongoDBHelper.GetList <LocalMongoDbTag>("HistoryRawDatas", filter1).OrderBy(x => x.ts).ToList(); if (localTags == null || localTags.Count == 0) { return; } //Console.WriteLine("success find MongoDb list=" + localTags.Count.ToString() +",time="+ DateTime.Now.ToLongTimeString()); foreach (var item in localTags)//分项合并 { MongoDbTag tag = new MongoDbTag(); tag.ID = item.ID; tag.t = string.Format("{0}:{1}:{2}", item.s, item.d, item.t); tag.v = item.v; tag.ts = item.ts; Tags.Add(tag); } if (localTags.Count > 0) { lastDatetime = localTags[localTags.Count - 1].ts; //缓存上一次的时间,以最后一笔记录的时间为准 } } else { var filterBuilder = Builders <MongoDbTag> .Filter; var filter = filterBuilder.And(filterBuilder.Gt(x => x.ts, lastDatetime), filterBuilder.Lte(x => x.ts, dateTimeNow), filterBuilder.Ne(x => x.v, "*"), filterBuilder.Ne(x => x.v, "")); Tags = mongoDBHelper.GetList <MongoDbTag>("scada_HistRawData", filter).OrderBy(x => x.ts).ToList(); //Console.WriteLine("---------------start to scan MongoDb,time span ="+ lastDatetime.ToString()+" --"+dateTimeNow.ToString()); if (Tags == null || Tags.Count == 0) { return; } //Console.WriteLine("AndonMainTask success find MongoDb list=" + Tags.Count.ToString() + ",time=" + DateTime.Now.ToLongTimeString()); if (Tags.Count > 0) { lastDatetime = Tags[Tags.Count - 1].ts; //缓存上一次的时间,以最后一笔记录的时间为准 } } Console.WriteLine("Mongodb combine finished,begin to find with postgre,time is " + DateTime.Now.ToLongTimeString() + " Tags count=" + Tags.Count.ToString()); try { vList = tagService.GetDeviceTagValueInfo(Tags, tagAreaAttributeEnum); vList = vList.OrderBy(x => x.insert_time).ToList(); foreach (var valueItem in vList) { if (valueItem.tag_value == "" || valueItem.tag_value == "*") { continue; } if (tagAreaAttributeMode == TagAreaAttributeEnum.machine_info) { machineCode = valueItem.device_code; stationId = -1; } else { machineCode = ""; stationId = valueItem.device_id; } if (valueItem.system_type_code == TagTypeEnum.Error.ToString()) //属于异常类型 { if (valueItem.system_tag_code == SystemTagCodeEnum.material_require.ToString()) //物料呼叫信息标签 { int requireCount = 0, materialId = 0; //支持两种格式:数量,数量&物料id TagIdAndValue valueObject = tagService.GetTagValue(valueItem.tag_value); if (valueObject.id > 0 && valueObject.value.Length > 0) { requireCount = valueObject.id; int.TryParse(valueObject.value, out materialId); //id为物料的id //andonMaterialRequestManager.AddMaterialRequest(materialId, requireCount, valueItem, tagAreaAttributeMode);//增加 //传递的有物料数量和id,在异常里记录,监测时间 // ErrorHandle(valueItem, tagAreaAttributeEnum, "", materialId); } else if (valueObject.id < 0 && valueObject.value.Length > 0) { int.TryParse(valueObject.value, out requireCount); if (requireCount > 0) { ErrorHandle(valueItem, tagAreaAttributeEnum);//只传递的有数量,则记录,此方式为触摸屏HMI方式 } } } else if (valueItem.system_tag_code == SystemTagCodeEnum.machine_error_code.ToString()) //采集到的异常编码 { mErrCode = MachineErrorCodeHelper.MachineErrorCodeHandle(valueItem); //异常编码处理 if (mErrCode != string.Empty) { ErrorHandle(valueItem, tagAreaAttributeMode, mErrCode); } } else//其他品质、设备、环膜等扩展异常 { int.TryParse(valueItem.tag_value, out value);//值比较 if (value == 1) { ErrorHandle(valueItem, tagAreaAttributeEnum); string msg = "error handle:" + DateTime.Now.AddHours(GlobalDefine.SysTimeZone).ToLongTimeString() + valueItem.device_code + " " + valueItem.device_id + " " + valueItem.tag_code + valueItem.system_type_code + " " + valueItem.system_tag_code + " " + valueItem.tag_value; //srpLogManager.Insert(new srp_log(msg, DateTime.Now.AddHours(GlobalDefine.SysTimeZone))); Console.WriteLine(msg); } } } else if (valueItem.system_type_code == TagTypeEnum.Other.ToString()) //其他类别 { if (valueItem.system_tag_code == SystemTagCodeEnum.andon_ack_code.ToString()) //现场确认并提交错误编码sn { //支持两种格式,sn或者id&sn,id为异常记录的唯一标识号 HandleErrorAckForTag(machineCode, stationId, valueItem, tagAreaAttributeEnum); } else if (valueItem.system_tag_code == SystemTagCodeEnum.andon_ack_person.ToString())//签到人员的卡号 { HandlePersonArrivalForTag(machineCode, stationId, valueItem, tagAreaAttributeEnum); } } } } catch (Exception ex) { srpLogManager.Insert("Andon tagvalue错误:" + ex.Message); } try { //------------------------------------------------------------------------------------------------ //对设备层的编码特殊处理 //Console.WriteLine("start to find machine error code!"); if (tagAreaAttributeEnum != TagAreaAttributeEnum.machine_info) { //异常代码特殊处理,因为绑定在设备上面 vList = tagService.GetDeviceTagValueInfo(Tags, TagAreaAttributeEnum.machine_info);//异常代码特殊处理 vList = vList.Where(x => x.system_type_code == TagTypeEnum.Error.ToString() && x.system_tag_code == SystemTagCodeEnum.machine_error_code.ToString()).ToList(); foreach (var valueItem in vList) { mErrCode = MachineErrorCodeHelper.MachineErrorCodeHandle(valueItem);//异常编码处理 if (mErrCode != string.Empty) { ErrorHandle(valueItem, tagAreaAttributeMode, mErrCode); } } } //Console.WriteLine("machine error code handle finished!"); } catch (Exception ex) { srpLogManager.Insert("抓取设备异常信息失败:" + ex.Message); } srpInnerLogManager.UpdateSrpTimeByCode(SrpCode, lastDatetime);//更新时间 Tags.Clear(); vList.Clear(); }
//private MaterialInfoManager materialInfoManager = new MaterialInfoManager(); /// <summary> /// 物料呼叫增加 /// </summary> /// <param name="materialID">物料id</param> /// <param name="count">数量</param> /// <param name="deviceTagValueInfo"></param> /// <param name="tagAreaAttributeEnum"></param> public void AddMaterialRequest(int materialID, int count, DeviceTagValueInfo deviceTagValueInfo, TagAreaAttributeEnum tagAreaAttributeEnum) { material_request_info request_Info = new material_request_info(); MachineInfo machine = null; station_info station = null; bool CheckOk = false; CT ct = null; //material_info material= materialInfoManager.SelectSingle(materialID); if (tagAreaAttributeEnum == TagAreaAttributeEnum.machine_info) { machine = machineInfoManager.SelectSingle(deviceTagValueInfo.device_id); if (machine != null) { var list = materialRequestInfoManager.SelectUnfinishedRequestInfo(materialID, machine.station_id); if (list == null || list.Count == 0) { CheckOk = true; request_Info.station_id = machine.station_id; ct = ctManager.SelectSingle(machine.machine_code); } } } else if (tagAreaAttributeEnum == TagAreaAttributeEnum.station_info) { station = stationManager.SelectSingle(deviceTagValueInfo.device_id); if (station != null) { var list = materialRequestInfoManager.SelectUnfinishedRequestInfo(materialID, station.station_id); if (list == null || list.Count == 0) { CheckOk = true; request_Info.station_id = station.station_id; ct = ctManager.SelectSingle(station.station_id); } } } if (CheckOk)//队列不存在 { request_Info.createtime = DateTime.Now.AddHours(GlobalDefine.SysTimeZone); request_Info.request_count = count; request_Info.material_id = materialID; if (ct != null) { request_Info.part_num = ct.wo; //机种 request_Info.work_order = ct.pn; //工单 } materialRequestInfoManager.Insert(request_Info); } }