DigitalTwinController.cs
2.3 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
using FreeSql;
using HHECS.BllModel;
using HHECS.DAQServer.DataAccess;
using HHECS.DAQServer.Dto.DigitalTwin;
using HHECS.EquipmentModel;
using LinqKit;
using Microsoft.AspNetCore.Mvc;
namespace HHECS.DAQServer.Controllers
{
/// <summary>
/// 数字孪生接口
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
public class DigitalTwinController : ControllerBase
{
private readonly DataContext _context;
public DigitalTwinController(DataContext dataContext)
{
_context = dataContext;
}
/// <summary>
/// 获取设备实时数据
/// </summary>
/// <param name="equipmentInfoRequestDto"></param>
/// <returns></returns>
[HttpGet]
[HttpPost]
public BllResult<List<EquipmentInfoResponseDto>> GetEquipmentInfo(EquipmentInfoRequestDto equipmentInfoRequestDto)
{
try
{
var filter = PredicateBuilder.New<Equipment>(true);
if (!string.IsNullOrWhiteSpace(equipmentInfoRequestDto.EquipmentCode))
{
filter = filter.And(x => x.Code == equipmentInfoRequestDto.EquipmentCode);
}
else if (!string.IsNullOrWhiteSpace(equipmentInfoRequestDto.Requestor))
{
var area = equipmentInfoRequestDto.Requestor;
filter = filter.And(x => x.Code.StartsWith(equipmentInfoRequestDto.Requestor));
}
var equipmentData = _context.Equipment.Where(filter).IncludeMany(x => x.EquipmentProps).ToList(x => new EquipmentInfoResponseDto
{
EquipmentCode = x.Code,
EquipmentName = x.Name,
EquipmentProps = x.EquipmentProps.Select(p => new EquipmentPropDto
{
EquipmentPropCode = p.EquipmentTypePropTemplateCode,
EquipmentPropName = p.Remark,
Value = p.Value,
}),
});
return BllResultFactory.Success(equipmentData);
}
catch (Exception ex)
{
return BllResultFactory.Error<List<EquipmentInfoResponseDto>>(ex.Message);
}
}
}
}