GrooveService.cs 3.38 KB
using HHECS.BllModel;
using HHECS.RobotTool.Dto;
using HHECS.RobotTool.Model;
using HHECS.RobotTool.Utils;

namespace HHECS.RobotTool.Service
{
    public class GrooveService
    {
        private readonly IFreeSql _freeSql;

        public GrooveService(IFreeSql freeSql)
        {
            _freeSql = freeSql;
        }

        /// <summary>
        /// 获取坡口自适应计算结果
        /// </summary>
        /// <param name="address">设备IP地址</param>
        /// <param name="grooveWidth">坡口宽度</param>
        /// <param name="grooveDepth">坡口深度</param>
        /// <returns></returns>
        public BllResult<RobotOutputParameter> GetComputedData(string address, float grooveWidth, float grooveDepth)
        {
            try
            {
                var inputParamenterResult = GetInputParameterDefault(address);
                if (!inputParamenterResult.Success)
                {
                    return BllResultFactory.Error<RobotOutputParameter>(inputParamenterResult.Msg);
                }
                var inputParamenter = inputParamenterResult.Data;
                inputParamenter.GrooveDepth = grooveDepth;
                inputParamenter.GrooveWidth = grooveWidth;
                return GrooveComputerTool.GetComputedData(inputParamenter);
            }
            catch (Exception ex)
            {
                return BllResultFactory.Error<RobotOutputParameter>(ex.Message);
            }
        }

        /// <summary>
        /// 获取输入参数默认值
        /// </summary>
        /// <param name="address">设备IP地址</param>
        /// <returns></returns>
        public BllResult<RobotInputParameter> GetInputParameterDefault(string address)
        {
            try
            {
                var equipment = _freeSql.Queryable<EquipmentExtend>().Where(x => x.IP == address).First(x => new EquipmentExtend
                {
                    Code = x.Code,
                    RobotConfigId = x.RobotConfigId,
                });
                if (equipment == null)
                {
                    return BllResultFactory.Error<RobotInputParameter>($"未找到IP地址为“{address}”的设备数据");
                }

                var configId = equipment.RobotConfigId;
                var config = _freeSql.Queryable<RobotConfig>().Where(x => x.Id == configId).First();
                if (config == null)
                {
                    return BllResultFactory.Error<RobotInputParameter>($"设备:{equipment.Code},地址:{address},默认参数ID[{configId}]在配置中不存在,请检查参数配置数据后再试!");
                }

                var result = new RobotInputParameter
                {
                    WeldingWire = (float)config.WeldingWire,
                    OneLayerWireFeedingSpeed = (float)config.OneLayerWireFeedingSpeed,
                    OneWeldHeight = (float)config.OneWeldHeight,
                    WeldWidth = (float)config.WeldWidth,
                    WireFeedingSpeed = (float)config.WireFeedingSpeed,
                    WeldLength = (float)config.WeldLength,
                    WeldHeight = (float)config.WeldHeight,
                };

                return BllResultFactory.Success(result);
            }
            catch (Exception ex)
            {
                return BllResultFactory.Error<RobotInputParameter>(ex.Message);
            }
        }
    }
}