WeldRobotV2Analysis.cs 2.78 KB
using HHECS.BllModel;
using HHECS.DAQHandle.Dto;
using HHECS.DAQShared.Common.Enums;
using HHECS.DAQShared.Common.Utils;
using HHECS.DAQShared.Dto;
using HHECS.DAQShared.Models;
using System.Text.Json;

namespace HHECS.DAQHandle.EquipmentHandle
{
    /// <summary>
    /// 焊接机器人报警解析
    /// </summary>
    /// <remarks>昆山、徐州版本</remarks>
    internal class WeldRobotV2Analysis : AnalysisBase
    {
        public WeldRobotV2Analysis(AnalysisParameter parameter) : base(parameter)
        {
        }

        protected override BllResult<EquipmentStatus> GetEquipmentStatus(EquipmentExtend equipment, EquipmentDataRecord record)
        {
            try
            {
                var tagResult = JsonConvertToTagList(record.Tags);
                if (!tagResult.Success)
                {
                    return BllResultFactory.Error<EquipmentStatus>(tagResult.Msg);
                }
                return EquipmentStatusHelper.GetEquipmentStatus(EquipmentTypeConst.WeldRobotV2, equipment.EquipmentProps, tagResult.Data);
            }
            catch (Exception ex)
            {
                return BllResultFactory.Error<EquipmentStatus>(ex.Message);
            }
        }

        /// <summary>
        /// 焊接机器人同一时间只有一条报警
        /// </summary>
        /// <param name="equipment"></param>
        /// <param name="totalAlarmProp"></param>
        /// <param name="monitorPropTemps"></param>
        /// <param name="tagItems"></param>
        /// <returns></returns>
        protected override (string, Dictionary<string, string>) GenerateAlarmMessage(EquipmentExtend equipment, EquipmentPropExtend totalAlarmProp, IEnumerable<EquipmentPropExtend> monitorPropTemps, IEnumerable<TagItemDto> tagItems)
        {
            //主报警文本
            var mainAlarm = totalAlarmProp.EquipmentTypePropTemplate.MonitorFailure;
            if (string.IsNullOrWhiteSpace(mainAlarm))
            {
                mainAlarm = totalAlarmProp.EquipmentTypePropTemplate.Name;
            }

            var detailAlarms = new Dictionary<string, string>();
            var alarmProp = monitorPropTemps.Where(x => x.EquipmentTypePropTemplateCode == RobotV2Prop.Alarmmsg.ToString()).FirstOrDefault();
            if (alarmProp != null)
            {
                var tag = tagItems.Where(x => x.Tag == alarmProp.EquipmentTypePropTemplateCode || x.Tag == alarmProp.Address).FirstOrDefault();
                if (tag != null && !string.IsNullOrWhiteSpace(tag.Value))
                {
                    var alarmDto = JsonSerializer.Deserialize<RobotAlarmDto>(tag.Value);
                    detailAlarms.Add(RobotV2Prop.Alarmmsg.ToString(), alarmDto.AlarmMessage);
                }
            }

            return (mainAlarm, detailAlarms);
        }
    }
}