WeldRobotAnalysis.cs 2.57 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 WeldRobotAnalysis : AnalysisBase
    {
        public WeldRobotAnalysis(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.WeldRobot, equipment.EquipmentProps, tagResult.Data);
            }
            catch (Exception ex)
            {
                return BllResultFactory.Error<EquipmentStatus>(ex.Message);
            }
        }

        protected override BllResult UpdateEquipmentAlarm(EquipmentExtend equipment, IEnumerable<EquipmentDataRecord> records)
        {
            try
            {
                var result = base.UpdateEquipmentAlarm(equipment, records);
                //焊接机器人小于1分钟的报警不记录
                freeSql.Delete<EquipmentAlarmRecord>().Where(x => x.EquipmentCode == equipment.Code && x.IsEnd && x.ErrorDuration < 60).ExecuteAffrows();
                return result;
            }
            catch (Exception ex)
            {
                return BllResultFactory.Error(ex.Message);
            }
        }


        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>
            {
                { RobotProp.Alarm.ToString(), "自动焊接中报警,请检查焊接耗材、焊接参数、焊接姿态"}
            };

            return (mainAlarm, detailAlarms);
        }
    }
}