StationMonitorAnalysis.cs 2.72 KB
using HHECS.BllModel;
using HHECS.DAQHandle.Common.Enums;
using HHECS.DAQHandle.Dto;
using HHECS.DAQHandle.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 = dictionary[StationProps.StationCorotation.ToString()];
                var stationReverse = dictionary[StationProps.StationReverse.ToString()];

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

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

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