Blame view

Service/GrooveService.cs 3.38 KB
唐召明 authored
1
2
using HHECS.BllModel;
using HHECS.RobotTool.Dto;
唐召明 authored
3
using HHECS.RobotTool.Model;
唐召明 authored
4
using HHECS.RobotTool.Utils;
唐召明 authored
5
唐召明 authored
6
namespace HHECS.RobotTool.Service
唐召明 authored
7
8
9
{
    public class GrooveService
    {
唐召明 authored
10
        private readonly IFreeSql _freeSql;
唐召明 authored
11
唐召明 authored
12
        public GrooveService(IFreeSql freeSql)
唐召明 authored
13
        {
唐召明 authored
14
            _freeSql = freeSql;
唐召明 authored
15
16
17
        }

        /// <summary>
18
        /// 获取坡口自适应计算结果
唐召明 authored
19
        /// </summary>
20
21
22
        /// <param name="address">设备IP地址</param>
        /// <param name="grooveWidth">坡口宽度</param>
        /// <param name="grooveDepth">坡口深度</param>
唐召明 authored
23
        /// <returns></returns>
24
        public BllResult<RobotOutputParameter> GetComputedData(string address, float grooveWidth, float grooveDepth)
唐召明 authored
25
        {
唐召明 authored
26
            try
唐召明 authored
27
            {
28
29
30
31
32
33
34
35
36
                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);
唐召明 authored
37
38
39
            }
            catch (Exception ex)
            {
唐召明 authored
40
                return BllResultFactory.Error<RobotOutputParameter>(ex.Message);
唐召明 authored
41
            }
唐召明 authored
42
        }
唐召明 authored
43
44

        /// <summary>
唐召明 authored
45
        /// 获取输入参数默认值
唐召明 authored
46
        /// </summary>
47
        /// <param name="address">设备IP地址</param>
唐召明 authored
48
        /// <returns></returns>
49
        public BllResult<RobotInputParameter> GetInputParameterDefault(string address)
唐召明 authored
50
51
52
        {
            try
            {
53
54
55
56
57
58
59
60
61
                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}”的设备数据");
                }
唐召明 authored
62
63
                var configId = equipment.RobotConfigId;
唐召明 authored
64
65
                var config = _freeSql.Queryable<RobotConfig>().Where(x => x.Id == configId).First();
                if (config == null)
唐召明 authored
66
                {
67
                    return BllResultFactory.Error<RobotInputParameter>($"设备:{equipment.Code},地址:{address},默认参数ID[{configId}]在配置中不存在,请检查参数配置数据后再试!");
唐召明 authored
68
69
                }
唐召明 authored
70
                var result = new RobotInputParameter
唐召明 authored
71
                {
72
73
74
75
76
77
78
                    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,
唐召明 authored
79
                };
80
唐召明 authored
81
                return BllResultFactory.Success(result);
唐召明 authored
82
            }
唐召明 authored
83
            catch (Exception ex)
唐召明 authored
84
            {
唐召明 authored
85
                return BllResultFactory.Error<RobotInputParameter>(ex.Message);
唐召明 authored
86
87
            }
        }
唐召明 authored
88
89
    }
}