GrooveService.cs
3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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);
}
}
}
}