AGVAnalysis.cs 3.57 KB
using HHECS.BllModel;
using HHECS.DAQHandle.Dto;
using HHECS.DAQShared.Common.Enums;
using HHECS.DAQShared.Dto;
using HHECS.DAQShared.Models;
using HHECS.EquipmentModel;

namespace HHECS.DAQHandle.EquipmentHandle
{
    /// <summary>
    /// AGV数据解析
    /// </summary>
    internal class AGVAnalysis : AnalysisBase
    {
        public AGVAnalysis(AnalysisParameter parameter) : base(parameter) { }

        protected override (string, List<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 List<string>();

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

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

            if (alarmTagValue != null)
            {
                detailAlarms = alarmTagValue?.Value.Split(',').ToList();
            }

            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);
                }
                var dictionaryResult = TagListConvertToDictionary(equipment.EquipmentProps, tagResult.Data);
                if (!dictionaryResult.Success)
                {
                    return BllResultFactory.Error<EquipmentStatus>(dictionaryResult.Msg);
                }

                var dictionary = dictionaryResult.Data;

                var travelStatus = dictionary[AGVProp.Status.ToString()];
                var isOnline = dictionary[AGVProp.IsOnline.ToString()];

                var validationResult = ValidationIsNullOrWhiteSpace(travelStatus, isOnline);
                if (!validationResult.Success)
                {
                    return BllResultFactory.Error<EquipmentStatus>(validationResult.Msg);
                }

                var equipmentStatus = EquipmentStatus.None;
                if (isOnline == "0")
                {
                    equipmentStatus = EquipmentStatus.Offline;
                    return BllResultFactory.Success(equipmentStatus);
                }

                //故障
                if (travelStatus == "30")
                {
                    equipmentStatus = EquipmentStatus.Failure;
                    return BllResultFactory.Success(equipmentStatus);
                }

                //运行
                if (travelStatus == "13")
                {
                    equipmentStatus = EquipmentStatus.Running;
                    return BllResultFactory.Success(equipmentStatus);
                }

                equipmentStatus = EquipmentStatus.Free;
                return BllResultFactory.Success(equipmentStatus);
            }
            catch (Exception ex)
            {
                return BllResultFactory.Error<EquipmentStatus>(ex.Message);
            }
        }
    }
}