public IActionResult Update([FromBody] error_log log)
        {
            string  myurl    = url + "api/v1/configuration/andon/error_log";
            var     postData = JsonConvert.SerializeObject(log);
            string  result   = PutUrl(myurl, postData);
            JObject jo       = (JObject)JsonConvert.DeserializeObject(result);

            switch (Convert.ToInt32(jo["code"]))
            {
            case 200:
                Json("Success");
                break;

            case 400:
                break;

            case 410:
                break;

            case 411:
                break;

            default:
                break;
            }
            return(Json("Success"));
        }
        /// <summary>
        /// 责任人员现场签到,用于网页端
        /// </summary>
        /// <param name="logItem">异常监控队列</param>
        /// <param name="cfgItem">设备编码</param>
        /// <returns></returns>
        public ErrorObject AckErrorLogPersonForWeb(error_log logItem, error_config cfgItem)
        {
            ErrorTypeService      errorTypeService = new ErrorTypeService();
            person                person           = null;
            material_request_info reInfo           = null;
            ErrorObject           errorObject      = null;

            errorObject = LoadErrorLogObject(logItem, cfgItem);
            if (errorObject.ELog != null && errorObject.eConfig != null)
            {
                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", logItem.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>
        /// 根据异常log记录加载所有信息.初始化加载和web页面确认使用
        /// </summary>
        /// <param name="eLogObject">error_log对象</param>
        /// <param name="unit_no">制程工序</param>
        /// <param name="line_id">线别id</param>
        /// <returns></returns>
        public ErrorObject LoadErrorLogObject(error_log eLogObject, error_config eCfgObject = null)
        {
            ErrorObject errorObject = new ErrorObject();

            errorObject.ELog = eLogObject;
            if (eCfgObject == null)
            {
                errorObject.eConfig = errorConfigManager.GetFirstErrorConfig(eLogObject.system_tag_code, eLogObject.unit_no, eLogObject.line_id);
                if (errorObject.eConfig == null) //未查询到,同时line非0,则以制程查询尝试
                {
                    errorObject.eConfig = errorConfigManager.GetFirstErrorConfig(eLogObject.system_tag_code, eLogObject.unit_no);
                }
            }
            else
            {
                errorObject.eConfig = eCfgObject;
            }

            if (errorObject.eConfig != null)
            {
                errorObject.eCfgPersonList = errorPersonManager.GetCfgPersonList(errorObject.eConfig.id);  //需通知的配置人员加载

                List <error_config_pn> eCfgPns = errorConfigPnManager.GetCfgPns(errorObject.eConfig.id);
                errorObject.eCfgPnList = eCfgPns;          //关联的机种信息加载
                //已通知人员加载
                errorObject.eMsgedPersonList = errorPersonManager.GetErrorLogPersonList(errorObject.ELog.id);
            }

            return(errorObject);
        }
        /// <summary>
        /// 用于网页模式下的解除.时间均在外部维护
        /// </summary>
        /// <param name="logItem">记录对象</param>
        /// <param name="cfgItem">配置对象</param>
        /// <param name="error_code">解除编码</param>
        /// <param name="defectives_count">不良品数量</param>
        /// <returns>正确执行返回ErrorObject,错误执行返回null</returns>
        public ErrorObject AckErrorLogDetails(error_log logItem, error_config cfgItem)
        {
            ErrorObject errorObject         = null;
            Dictionary <string, object> dic = new Dictionary <string, object>();//加入需要更新的字段信息

            errorObject = LoadErrorLogObject(logItem, cfgItem);

            if (errorObject != null && errorObject.ELog != null)
            {
                if (errorObject.eConfig.check_ack == (int)AckModeEnum.CodeAck)
                {
                    dic.Add("maintenance_time", errorObject.ELog.maintenance_time);
                    dic.Add("error_type_id", errorObject.ELog.error_type_id);//未确认原因的再给值。物料呼叫监测typeid会提前赋值
                }
                dic.Add("defectives_count", errorObject.ELog.defectives_count);
                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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 加载指定的异常记录
        /// </summary>
        /// <param name="MachineCode">设备编码</param>
        /// <returns></returns>
        public error_log GetErrorLogById(int id)
        {
            error_log logItem = new error_log();
            string    command = string.Format("Select * from andon.error_log where id='{0}'", id);

            logItem = PostgreHelper.GetSingleEntity <error_log>(command);

            return(logItem);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Web页面处理异常解除
        /// </summary>
        /// <param name="logItem">记录对象</param>
        /// <param name="cfgItem">配置对象</param>
        /// <param name="error_code">确认代码</param>
        /// <param name="defectives_count">不良品数量</param>
        public static void HandleErrorAck(error_log logItem, error_config cfgItem, ErrorObject errorObj = null)
        {
            string      subject = string.Empty, content = string.Empty;
            ErrorObject errorObject = null;

            if (errorObj != null)
            {
                errorObject = errorObj;
            }
            else
            {
                errorObject = andonErrorManager.AckErrorLogDetails(logItem, cfgItem);
            }

            if (errorObject != null && errorObject.eConfig != null)
            {
                if (errorObject.eConfig.trigger_message_type > (int)ErrorMsgType.None)//需要消息通知
                {
                    subject = "安灯系统" + errorObject.ELog.error_name;
                    if (errorObject.eTypeDetails != null)
                    {
                        content = String.Format("{0}已解除{1},原因为{2}" + MessageAdditional, logItem.machine_code, subject, errorObject.eTypeDetails.code_name_cn);
                    }
                    else if (errorObject.RequireMat != null)
                    {
                        content = String.Format("{0}已解除{1},呼叫的物料id为{2}" + MessageAdditional, logItem.machine_code, subject, errorObject.RequireMat.material_id);
                    }
                    else
                    {
                        content = String.Format("{0}已解除{1}" + MessageAdditional, logItem.machine_code, subject);
                    }
                    errorMessageManager.SendErrorMessageAsync(errorObject, (int)MessageLevel.Level1, EventHandleFlowEnum.Event_Ack, subject, content, true);//发送消息通知
                }
                if (errorObject.eConfig.arrival_out_color > (int)LightTowerEnum.None &&
                    errorObject.eConfig.check_arrival > (int)ArrivalModeEnum.NoArrival)     //签到灯颜色复位
                {
                    //写值
                    lightTowerTagManager.WriteLightColorAsync(logItem.station_id, errorObject.eConfig.arrival_out_color, tagAreaAttributeMode, 0);
                    lightTowerTagManager.GreenStatusLightOutAsync(logItem.station_id, tagAreaAttributeMode); //绿灯状态切换
                }
                if (errorObject.eConfig.trigger_out_color > (int)LightTowerEnum.None)                        //警示灯颜色复位
                {
                    //写值
                    lightTowerTagManager.WriteLightColorAsync(logItem.station_id, errorObject.eConfig.trigger_out_color, tagAreaAttributeMode, 0);
                    lightTowerTagManager.GreenStatusLightOutAsync(logItem.station_id, tagAreaAttributeMode);//绿灯状态切换
                }
            }
            else
            {
                Console.WriteLine("安灯解除记录失败,errorObject != null && errorObject.eConfig != null 失败!");
                if (errorObject.eConfig == null)
                {
                    Console.WriteLine("安灯解除记录失败,errorObject.eConfig == null" + logItem.system_tag_code);
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 加载指定的异常记录
        /// </summary>
        /// <param name="StationId">站位id</param>
        /// <returns></returns>
        public error_log GetUnAckLogByDeviceId(int device_id, string system_tag_code)
        {
            error_log obj = new error_log();
            string    command;

            command = "Select * from andon.error_log where station_id='{0}' and system_tag_code='{1}' and (release_time<='{2}' OR release_time is NULL) limit 1";
            command = string.Format(command, device_id, system_tag_code, "2001-01-01 00:00:00");

            obj = PostgreHelper.GetSingleEntity <error_log>(command);

            return(obj);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 人员签到处理
        /// </summary>
        /// <param name="logItem"></param>
        /// <param name="cfgItem"></param>
        /// <param name="errorObj"></param>
        public static void HandlePersonArrival(error_log logItem, error_config cfgItem, ErrorObject errorObj = null)
        {
            string      subject = string.Empty, content = string.Empty;
            ErrorObject errorObject;

            if (errorObj != null)
            {
                errorObject = errorObj;
            }
            else
            {
                errorObject = andonErrorManager.AckErrorLogPersonForWeb(logItem, cfgItem);
            }
            if (errorObject != null && errorObject.eConfig != null)
            {
                if (errorObject.eConfig.arrival_message_type > (int)ErrorMsgType.None)//需要消息通知
                {
                    if (errorObject.eConfig.check_arrival == (int)ArrivalModeEnum.CardArrival)
                    {
                        subject = "安灯系统" + errorObject.ELog.error_name;
                        if (errorObject.eSignedPersons.Count > 0)
                        {
                            content = String.Format("{0}发生{1},签到人员为{2}" + MessageAdditional, errorObject.ELog.machine_code, subject, errorObject.eSignedPersons[0].user_name);
                        }
                        else
                        {
                            content = String.Format("{0}发生{1},人员已签到" + MessageAdditional, errorObject.ELog.machine_code, subject);
                        }
                    }
                    else
                    {
                        subject = "安灯系统" + errorObject.ELog.error_name;
                        content = String.Format("{0}发生{1},人员已签到" + MessageAdditional, errorObject.ELog.machine_code, subject);
                    }
                    errorMessageManager.SendErrorMessageAsync(errorObject, (int)MessageLevel.Level1, EventHandleFlowEnum.Event_SignIn, subject, content); //发送消息通知,人员签到在第一层级??
                }
                if (errorObject.eConfig.arrival_out_color > (int)LightTowerEnum.None)                                                                     //灯颜色输出
                {
                    //写值
                    lightTowerTagManager.WriteLightColorAsync(errorObject.ELog.station_id, errorObject.eConfig.arrival_out_color, tagAreaAttributeMode, 1);
                    lightTowerTagManager.GreenStatusLightOutAsync(errorObject.ELog.station_id, tagAreaAttributeMode);//绿灯状态切换
                }
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// 更新error_log对象
 /// </summary>
 /// <param name="Obj"></param>
 /// <param name="UpdateDic">更新的键值对信息</param>
 /// <returns></returns>
 public int Update(error_log Obj, Dictionary <string, object> UpdateDic)
 {
     return(errorLogService.Update(Obj, UpdateDic));
 }
Exemplo n.º 10
0
 /// <summary>
 /// 更新error_log对象
 /// </summary>
 /// <param name="Obj"></param>
 /// <returns></returns>
 public int Update(error_log Obj)
 {
     return(errorLogService.Update(Obj));
 }
Exemplo n.º 11
0
 /// <summary>
 /// 返回插入的id
 /// </summary>
 /// <param name="Obj"></param>
 /// <returns></returns>
 public int Insert(error_log Obj)
 {
     return(errorLogService.Insert(Obj));
 }
Exemplo n.º 12
0
        /// <summary>
        /// 更新error_log对象
        /// </summary>
        /// <param name="Obj"></param>
        /// <returns></returns>
        public int Update(error_log Obj, Dictionary <string, object> UpdateDic)
        {
            int id = PostgreHelper.UpdateSingleEntity <error_log>("andon.error_log", Obj.id, UpdateDic);

            return(id);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 更新error_log对象
        /// </summary>
        /// <param name="Obj"></param>
        /// <returns></returns>
        public int Update(error_log Obj)
        {
            int id = PostgreHelper.UpdateSingleEntity <error_log>(Obj);

            return(id);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 返回插入的id
        /// </summary>
        /// <param name="Obj"></param>
        /// <returns></returns>
        public int Insert(error_log Obj)
        {
            int id = PostgreHelper.InsertSingleEntity <error_log>(Obj);

            return(id);
        }
        /// <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);
        }
Exemplo n.º 16
0
        /// <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);
            }
        }