WeldRobotAnalysis.cs 3.29 KB
using HHECS.BllModel;
using HHECS.DAQHandle.Common.Enums;
using HHECS.DAQHandle.Common.Utils;
using HHECS.DAQHandle.Models;
using HHECS.EquipmentModel;

namespace HHECS.DAQHandle.EquipmentHandle
{
    /// <summary>
    /// 焊接机器人数据解析
    /// </summary>
    internal class WeldRobotAnalysis : BaseAnalysis
    {
        public WeldRobotAnalysis(EquipmentType equipmentType) : base(equipmentType) { }

        //public override BllResult Execute(IEnumerable<EquipmentDataRecord> records)
        //{
        //    try
        //    {
        //        //按设备分组
        //        foreach (var item in records.GroupBy(x => x.EquipmentCode))
        //        {
        //            var equipmentRecords = item.ToList();
        //            var setStatusResult = SetEquipmentStatus(item.Key, equipmentRecords);
        //            if (!setStatusResult.Success)
        //            {
        //                SystemLog.PrintError(setStatusResult.Msg);
        //            }
        //            var setAlarmResult = SetEquipmentAlarm(item.Key, equipmentRecords);
        //            if (!setAlarmResult.Success)
        //            {
        //                SystemLog.PrintError(setStatusResult.Msg);
        //            }
        //            var setValueResult = SetEquipmentPropValues(item.Key, item.LastOrDefault());
        //            if (!setValueResult.Success)
        //            {
        //                SystemLog.PrintError(setStatusResult.Msg);
        //            }
        //        }
        //        //解析完成后清空记录
        //        Context.EquipmentDataRecord.RemoveRange(records);
        //        Context.SaveChanges();
        //        return BllResultFactory.Success();
        //    }
        //    catch (Exception ex)
        //    {
        //        return BllResultFactory.Error($"[{nameof(WeldRobotAnalysis)}]解析出现异常:{ex}");
        //    }
        //}


        public override EquipmentStatusRecordStatus? GetEquipmentStatus(EquipmentDataRecord equipmentInfo)
        {


            EquipmentStatusRecordStatus? equipmentStatus = null;
            var bootFlag = GetPropValue(equipmentInfo, RobotProp.BootFlag);
            //设备未开机不记录状态
            if (bootFlag != "True") return equipmentStatus;

            var totalError = GetPropValue(equipmentInfo, RobotProp.Alarm);
            //故障
            if (string.IsNullOrWhiteSpace(totalError))
            {
                SystemLog.PrintError($"记录{equipmentInfo.Id}的totalError属性无有效数据");
            }
            else if (totalError == "True")
            {
                equipmentStatus = EquipmentStatusRecordStatus.Error;
            }
            else
            {
                //运行
                if (GetPropValue(equipmentInfo, RobotProp.Work_Mode) == "3"
                  && (GetPropValue(equipmentInfo, RobotProp.WorkFlag) == "True" || GetPropValue(equipmentInfo, RobotProp.Work_Time) == "True"))
                {
                    equipmentStatus = EquipmentStatusRecordStatus.Running;
                }
                //待机
                else
                {
                    equipmentStatus = EquipmentStatusRecordStatus.Free;
                }
            }
            return equipmentStatus;

        }

    }
}