StationMonitorAnalysis.cs 3.31 KB
using HHECS.BllModel;
using HHECS.DAQHandle.Dto;
using HHECS.DAQShared.Common.Enums;
using HHECS.DAQShared.Models;

namespace HHECS.DAQHandle.EquipmentHandle
{
    /// <summary>
    /// 站台监控数据解析
    /// </summary>
    internal class StationMonitorAnalysis : AnalysisBase
    {
        public StationMonitorAnalysis(AnalysisParameter parameter) : base(parameter)
        {
        }

        protected override BllResult UpdateEquipmentAlarm(EquipmentExtend equipment, IEnumerable<EquipmentDataRecord> records)
        {
            //输送线报警暂不记录
            return BllResultFactory.Success();
        }

        protected override BllResult UpdateEquipmentStatus(EquipmentExtend equipment, IEnumerable<EquipmentDataRecord> records)
        {
            //输送线状态暂不记录
            return BllResultFactory.Success();
        }

        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 totalError = dictionary[StationProps.StationError.ToString()];
                var stationCorotation = false;
                var stationReverse = false;
                if (dictionary.ContainsKey(StationProps.StationCorotation.ToString()))
                {
                    _ = bool.TryParse(dictionary[StationProps.StationCorotation.ToString()], out stationCorotation);
                }

                if (dictionary.ContainsKey(StationProps.StationReverse.ToString()))
                {
                    _ = bool.TryParse(dictionary[StationProps.StationReverse.ToString()], out stationReverse);
                }

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

                var equipmentStatus = EquipmentStatus.None;
                //故障
                if (totalError == bool.TrueString)
                {
                    equipmentStatus = EquipmentStatus.Failure;
                    return BllResultFactory.Success(equipmentStatus);
                }

                //运行
                if (stationCorotation || stationReverse)
                {
                    equipmentStatus = EquipmentStatus.Running;
                    return BllResultFactory.Success(equipmentStatus);
                }

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