GrooveService.cs 3.07 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="parameter">输入参数</param>
        /// <returns></returns>
        public BllResult<RobotOutputParameter> GetComputedData(RobotInputParameter parameter)
        {
            try
            {
                return GrooveComputerTool.GetComputedData(parameter);
            }
            catch (Exception ex)
            {
                return BllResultFactory.Error<RobotOutputParameter>(ex.Message);
            }
        }

        /// <summary>
        /// 获取输入参数默认值
        /// </summary>
        /// <param name="robotCode">机器人编码</param>
        /// <returns></returns>
        public BllResult<RobotInputParameter> GetInputParameterDefault(string robotCode)
        {
            try
            {
                //测试代码
                //var temp = new RobotInputParameter
                //{
                //    GrooveWidth = 37,
                //    GrooveDepth = 30,
                //    WeldingWire = 1.2,
                //    ReservedGap = 0,
                //    BluntEdgeSize = 2,
                //    WeldLength = 1000,
                //    WeldWidth = 1.5,
                //    WeldHeight = 2
                //};
                //return BllResultFactory.Success(temp);

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

                var result = new RobotInputParameter
                {
                    //WeldingWire = config.WeldingWire,
                    ////ReservedGap = config.ReservedGap,
                    ////BluntEdgeSize = config.BluntEdgeSize,
                    //WeldLength = config.WeldLength,
                    ////WeldWidth = config.WeldWidth,
                    //WeldHeight = config.WeldHeight,
                };
                return BllResultFactory.Success(result);
            }
            catch (Exception ex)
            {
                return BllResultFactory.Error<RobotInputParameter>(ex.Message);
            }
        }

        /// <summary>
        /// 获取输入参数默认值
        /// </summary>
        /// <param name="robotNo">机器人编号</param>
        /// <returns></returns>
        public BllResult<RobotInputParameter> GetInputParameterDefault(int robotNo) => GetInputParameterDefault($"Robot{robotNo}");
    }
}