CNCAnalysis.cs 2.61 KB
using HHECS.BllModel;
using HHECS.DAQHandle.Dto;
using HHECS.DAQShared.Common.Enums;
using HHECS.DAQShared.Models;

namespace HHECS.DAQHandle.EquipmentHandle
{
    internal class CNCAnalysis : AnalysisBase
    {
        public CNCAnalysis(AnalysisParameter parameter) : base(parameter)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="equipment"></param>
        /// <param name="record"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        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 redLight = dictionary[CNCProp.RedLight.ToString()];
                var yellowLight = dictionary[CNCProp.YellowLight.ToString()];
                var greenLight = dictionary[CNCProp.GreenLight.ToString()];

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

                var equipmentStatus = EquipmentStatus.None;

                if (greenLight == bool.TrueString)
                {
                    equipmentStatus = EquipmentStatus.Running;
                    return BllResultFactory.Success(equipmentStatus);
                }

                //绿灯不亮,红灯亮,属于故障
                if (greenLight == bool.FalseString && redLight == bool.TrueString)
                {
                    equipmentStatus = EquipmentStatus.Free;
                    return BllResultFactory.Success(equipmentStatus);
                }

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