Index.razor
5.93 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
@page "/Basic/Equipment"
@using System.Text.Json;
@using AntDesign.TableModels
@using System.ComponentModel
@using DataAcquisition.Common.Enums
@using DataAcquisition.Common.Utils
@using DataAcquisition.DataAccess
@using DataAcquisition.Models
@using DataAcquisition.Pages.Basic.EquipmentProptery
@using DataAcquisition.Services
@using DataAcquisition.ViewModels.IOT
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<DataContext> dbContextFactory;
@inject DataCacheService dataCacheService;
@inject IotService iotService;
@inject IMessageService _message
<Flex Justify="space-between" Align="center">
<Flex Justify="flex-start" Align="center" Gap="small">
<AntDesign.Input DefaultValue="@("mysite")">
<AddOnBefore>编号</AddOnBefore>
</AntDesign.Input>
<Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Search">搜索</Button>
<Button Type="@ButtonType.Default" Icon="@IconType.Outline.Redo">重置</Button>
</Flex>
<Flex Justify="flex-end" Align="center" Gap="small">
<Button Type="@ButtonType.Primary" Icon="@IconType.Outline.CloudUpload">新增</Button>
<Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Delete" Danger>批量删除</Button>
<Button Type="@ButtonType.Primary" Icon="@IconType.Outline.CloudUpload" OnClick="IotCloudUpload">上传设备数据至IOT</Button>
</Flex>
</Flex>
<Table @ref="mainTable"
TItem="Equipment"
DataSource="@equipments"
Total="_total"
@bind-PageIndex="_pageIndex"
@bind-PageSize="_pageSize"
Loading="loading"
OnChange="EquipmentOnChange"
Size="TableSize.Small"
RowKey="x=>x.Id">
<Selection Key="@(context.Id.ToString())" />
<PropertyColumn Property="c=>c.Id" Hidden />
<PropertyColumn Title="编号" Property="c=>c.Code" />
<PropertyColumn Title="设备名称" Property="c=>c.Name" />
<PropertyColumn Title="设备类型" Property="c=>c.EquipmentType" />
<PropertyColumn Title="通信配置" Property="c=>c.CommunicationConfig!.Code" />
<PropertyColumn Title="是否启用" Property="c=>c.Enable">
<Switch @bind-Value="@context.Enable" Disabled="true"></Switch>
</PropertyColumn>
<PropertyColumn Title="区域" Property="c=>c.Area" />
<PropertyColumn Title="备注" Property="c=>c.Remark" />
<PropertyColumn Title="创建时间" Property="c=>c.CreateTime" />
<ActionColumn Title="操作">
<Space>
<SpaceItem>
<Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Edit" Size="@ButtonSize.Small">修改</Button>
<Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Delete" Size="@ButtonSize.Small" Danger>删除</Button>
<Button Type="@ButtonType.Primary" Icon="@IconType.Outline.InfoCircle" Size="@ButtonSize.Small" OnClick="()=>OpenDetail(context.Id)">详细</Button>
</SpaceItem>
</Space>
</ActionColumn>
</Table>
<Modal Title="@modalTitle"
@bind-Visible="@_visible"
Maximizable="true"
Centered="true"
Resizable="true"
Draggable="true"
Width="1200"
MaxBodyHeight="80vh"
Footer="null"
DestroyOnClose="true"
DefaultMaximized="true">
<EquipmentPropteryIndex EquipmentId="@equipmentId" />
</Modal>
@code {
bool loading = true;
bool loading_upload = false;
bool _visible = false;
string modalTitle = string.Empty;
List<Equipment> equipments = new List<Equipment>();
SystemLog log = SystemLog.Instance;
ITable mainTable = null!;
int _pageIndex = 1;
int _pageSize = 10;
int _total = 0;
int equipmentId = 0;
public async Task EquipmentOnChange(QueryModel<Equipment> queryModel)
{
loading = true;
using var dbContext = dbContextFactory.CreateDbContext();
var query = dbContext.Equipments;
equipments = await query.OrderBy(x => x.Id).Skip(((queryModel.PageIndex - 1) * queryModel.PageSize)).Take(queryModel.PageSize).Include(x => x.CommunicationConfig).AsSplitQuery().AsNoTracking().ToListAsync();
_total = await query.CountAsync();
loading = false;
}
private void OpenDetail(int id)
{
_visible = true;
equipmentId = id;
modalTitle = equipments.Find(x => x.Id == id)?.Name ?? string.Empty;
}
private async Task IotCloudUpload()
{
try
{
await _message.Loading(new MessageConfig()
{
Content = "Uploading...",
Key = Guid.NewGuid().ToString()
});
await Task.Delay(1500);
var context = dbContextFactory.CreateDbContext();
var robotTypes = new List<EquipmentTypeConst>
{
EquipmentTypeConst.Kuka,
EquipmentTypeConst.Fanuc,
EquipmentTypeConst.Efort,
};
var data = context.Equipments.Where(x => robotTypes.Contains(x.EquipmentType)).Include(x => x.CommunicationConfig).Select(x => new IotEquipment
{
EquipmentCode = x.Code,
EquipmentName = x.Name,
EquipmentTypeCode = x.EquipmentType.ToString(),
EquipmentTypeName = x.EquipmentType.ToString(),
IP = x.CommunicationConfig!.IpAddress,
DestinationArea = $"{x.Area}",
Remark = x.Remark ?? string.Empty,
Type = "I",
IsEnable = 1,
}).AsSplitQuery().AsNoTracking().ToList();
var result = iotService.SendEquipment(data);
if (!result.Status)
{
await _message.Error($"上传失败,{result.Message}");
}
else
{
await _message.Success($"上传成功");
}
}
catch (Exception ex)
{
await _message.Error($"操作失败,{ex.Message}");
}
}
}