AGVForkliftAnalysis.cs 2.31 KB
using HHECS.BllModel;
using HHECS.DAQHandle.Dto;
using HHECS.DAQShared.Common.Enums;
using HHECS.DAQShared.Dto;
using HHECS.DAQShared.Models;
using HHECS.DAQShared.Common.Utils;

namespace HHECS.DAQHandle.EquipmentHandle
{
    /// <summary>
    /// AGV数据解析
    /// </summary>
    /// <remarks>对应ACS系统的设备</remarks>
    internal class AGVForkliftAnalysis : AnalysisBase
    {
        public AGVForkliftAnalysis(AnalysisParameter parameter) : base(parameter) { }

        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 = $"{equipment.Name}总故障";
            }
            var detailAlarms = new Dictionary<string, string>();

            //报警明细
            var tagCodes = new List<string>
            {
                totalAlarmProp.EquipmentTypePropTemplateCode,
                totalAlarmProp.Address
            };

            var alarmTag = tagItems.Where(x => tagCodes.Contains(x.Tag, StringComparer.OrdinalIgnoreCase)).FirstOrDefault();

            if (alarmTag != null && !string.IsNullOrWhiteSpace(alarmTag.Value))
            {
                detailAlarms = alarmTag.Value.Split(',').Distinct().ToDictionary(x => $"Error{x.GetHashCode()}", y => y);
            }

            return (mainAlarm, detailAlarms);
        }

        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.AGVForklift, equipment.EquipmentProps, tagResult.Data);
            }
            catch (Exception ex)
            {
                return BllResultFactory.Error<EquipmentStatus>(ex.Message);
            }
        }
    }
}