Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IoTSharp
IoTSharp
提交
abcf73c2
IoTSharp
项目概览
IoTSharp
/
IoTSharp
大约 1 年 前同步成功
通知
15
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
IoTSharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
abcf73c2
编写于
12月 21, 2021
作者:
W
wq1234wq
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新Mysql迁移,增加异常捕获
上级
495ffad9
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
2441 addition
and
68 deletion
+2441
-68
IoTSharp.Data.MySQL/Migrations/20211221075652_addmodelcommand.Designer.cs
...SQL/Migrations/20211221075652_addmodelcommand.Designer.cs
+1957
-0
IoTSharp.Data.MySQL/Migrations/20211221075652_addmodelcommand.cs
...p.Data.MySQL/Migrations/20211221075652_addmodelcommand.cs
+285
-0
IoTSharp.Data.MySQL/Migrations/ApplicationDbContextModelSnapshot.cs
...ata.MySQL/Migrations/ApplicationDbContextModelSnapshot.cs
+110
-8
IoTSharp/ClientApp/src/app/core/i18n/i18n.service.ts
IoTSharp/ClientApp/src/app/core/i18n/i18n.service.ts
+2
-1
IoTSharp/Controllers/DeviceModelController.cs
IoTSharp/Controllers/DeviceModelController.cs
+20
-11
IoTSharp/Controllers/DevicesController.cs
IoTSharp/Controllers/DevicesController.cs
+67
-48
未找到文件。
IoTSharp.Data.MySQL/Migrations/20211221075652_addmodelcommand.Designer.cs
0 → 100644
浏览文件 @
abcf73c2
此差异已折叠。
点击以展开。
IoTSharp.Data.MySQL/Migrations/20211221075652_addmodelcommand.cs
0 → 100644
浏览文件 @
abcf73c2
using
System
;
using
Microsoft.EntityFrameworkCore.Migrations
;
namespace
IoTSharp.Data.MySql.Migrations
{
public
partial
class
addmodelcommand
:
Migration
{
protected
override
void
Up
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropForeignKey
(
name
:
"FK_FlowOperations_BaseEvents_BaseEventEventId"
,
table
:
"FlowOperations"
);
migrationBuilder
.
DropForeignKey
(
name
:
"FK_FlowOperations_FlowRules_FlowRuleRuleId"
,
table
:
"FlowOperations"
);
migrationBuilder
.
DropForeignKey
(
name
:
"FK_FlowOperations_Flows_FlowId"
,
table
:
"FlowOperations"
);
migrationBuilder
.
DropIndex
(
name
:
"IX_FlowOperations_BaseEventEventId"
,
table
:
"FlowOperations"
);
migrationBuilder
.
DropIndex
(
name
:
"IX_FlowOperations_FlowRuleRuleId"
,
table
:
"FlowOperations"
);
migrationBuilder
.
DropColumn
(
name
:
"BaseEventEventId"
,
table
:
"FlowOperations"
);
migrationBuilder
.
DropColumn
(
name
:
"FlowRuleRuleId"
,
table
:
"FlowOperations"
);
migrationBuilder
.
AlterColumn
<
Guid
>(
name
:
"FlowId"
,
table
:
"FlowOperations"
,
type
:
"char(36)"
,
nullable
:
false
,
defaultValue
:
new
Guid
(
"00000000-0000-0000-0000-000000000000"
),
collation
:
"ascii_general_ci"
,
oldClrType
:
typeof
(
Guid
),
oldType
:
"char(36)"
,
oldNullable
:
true
)
.
OldAnnotation
(
"Relational:Collation"
,
"ascii_general_ci"
);
migrationBuilder
.
AddColumn
<
Guid
>(
name
:
"BaseEventId"
,
table
:
"FlowOperations"
,
type
:
"char(36)"
,
nullable
:
false
,
defaultValue
:
new
Guid
(
"00000000-0000-0000-0000-000000000000"
),
collation
:
"ascii_general_ci"
);
migrationBuilder
.
AddColumn
<
Guid
>(
name
:
"FlowRuleId"
,
table
:
"FlowOperations"
,
type
:
"char(36)"
,
nullable
:
false
,
defaultValue
:
new
Guid
(
"00000000-0000-0000-0000-000000000000"
),
collation
:
"ascii_general_ci"
);
migrationBuilder
.
AddColumn
<
Guid
>(
name
:
"DeviceModelId"
,
table
:
"Device"
,
type
:
"char(36)"
,
nullable
:
true
,
collation
:
"ascii_general_ci"
);
migrationBuilder
.
CreateTable
(
name
:
"DeviceModels"
,
columns
:
table
=>
new
{
DeviceModelId
=
table
.
Column
<
Guid
>(
type
:
"char(36)"
,
nullable
:
false
,
collation
:
"ascii_general_ci"
),
ModelName
=
table
.
Column
<
string
>(
type
:
"longtext"
,
nullable
:
true
)
.
Annotation
(
"MySql:CharSet"
,
"utf8mb4"
),
ModelDesc
=
table
.
Column
<
string
>(
type
:
"longtext"
,
nullable
:
true
)
.
Annotation
(
"MySql:CharSet"
,
"utf8mb4"
),
ModelStatus
=
table
.
Column
<
int
>(
type
:
"int"
,
nullable
:
false
),
CreateDateTime
=
table
.
Column
<
DateTime
>(
type
:
"datetime(6)"
,
nullable
:
false
),
Creator
=
table
.
Column
<
Guid
>(
type
:
"char(36)"
,
nullable
:
false
,
collation
:
"ascii_general_ci"
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_DeviceModels"
,
x
=>
x
.
DeviceModelId
);
})
.
Annotation
(
"MySql:CharSet"
,
"utf8mb4"
);
migrationBuilder
.
CreateTable
(
name
:
"DeviceModelCommands"
,
columns
:
table
=>
new
{
CommandId
=
table
.
Column
<
Guid
>(
type
:
"char(36)"
,
nullable
:
false
,
collation
:
"ascii_general_ci"
),
CommandTitle
=
table
.
Column
<
string
>(
type
:
"longtext"
,
nullable
:
true
)
.
Annotation
(
"MySql:CharSet"
,
"utf8mb4"
),
CommandI18N
=
table
.
Column
<
string
>(
type
:
"longtext"
,
nullable
:
true
)
.
Annotation
(
"MySql:CharSet"
,
"utf8mb4"
),
CommandType
=
table
.
Column
<
int
>(
type
:
"int"
,
nullable
:
false
),
CommandParams
=
table
.
Column
<
string
>(
type
:
"longtext"
,
nullable
:
true
)
.
Annotation
(
"MySql:CharSet"
,
"utf8mb4"
),
CommandName
=
table
.
Column
<
string
>(
type
:
"longtext"
,
nullable
:
true
)
.
Annotation
(
"MySql:CharSet"
,
"utf8mb4"
),
CommandTemplate
=
table
.
Column
<
string
>(
type
:
"longtext"
,
nullable
:
true
)
.
Annotation
(
"MySql:CharSet"
,
"utf8mb4"
),
DeviceModelId
=
table
.
Column
<
Guid
>(
type
:
"char(36)"
,
nullable
:
false
,
collation
:
"ascii_general_ci"
),
CreateDateTime
=
table
.
Column
<
DateTime
>(
type
:
"datetime(6)"
,
nullable
:
false
),
Creator
=
table
.
Column
<
Guid
>(
type
:
"char(36)"
,
nullable
:
false
,
collation
:
"ascii_general_ci"
),
CommandStatus
=
table
.
Column
<
int
>(
type
:
"int"
,
nullable
:
false
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_DeviceModelCommands"
,
x
=>
x
.
CommandId
);
table
.
ForeignKey
(
name
:
"FK_DeviceModelCommands_DeviceModels_DeviceModelId"
,
column
:
x
=>
x
.
DeviceModelId
,
principalTable
:
"DeviceModels"
,
principalColumn
:
"DeviceModelId"
,
onDelete
:
ReferentialAction
.
Cascade
);
})
.
Annotation
(
"MySql:CharSet"
,
"utf8mb4"
);
migrationBuilder
.
CreateIndex
(
name
:
"IX_FlowOperations_BaseEventId"
,
table
:
"FlowOperations"
,
column
:
"BaseEventId"
);
migrationBuilder
.
CreateIndex
(
name
:
"IX_FlowOperations_FlowRuleId"
,
table
:
"FlowOperations"
,
column
:
"FlowRuleId"
);
migrationBuilder
.
CreateIndex
(
name
:
"IX_Device_DeviceModelId"
,
table
:
"Device"
,
column
:
"DeviceModelId"
);
migrationBuilder
.
CreateIndex
(
name
:
"IX_DeviceModelCommands_DeviceModelId"
,
table
:
"DeviceModelCommands"
,
column
:
"DeviceModelId"
);
migrationBuilder
.
AddForeignKey
(
name
:
"FK_Device_DeviceModels_DeviceModelId"
,
table
:
"Device"
,
column
:
"DeviceModelId"
,
principalTable
:
"DeviceModels"
,
principalColumn
:
"DeviceModelId"
,
onDelete
:
ReferentialAction
.
Restrict
);
migrationBuilder
.
AddForeignKey
(
name
:
"FK_FlowOperations_BaseEvents_BaseEventId"
,
table
:
"FlowOperations"
,
column
:
"BaseEventId"
,
principalTable
:
"BaseEvents"
,
principalColumn
:
"EventId"
,
onDelete
:
ReferentialAction
.
Cascade
);
migrationBuilder
.
AddForeignKey
(
name
:
"FK_FlowOperations_FlowRules_FlowRuleId"
,
table
:
"FlowOperations"
,
column
:
"FlowRuleId"
,
principalTable
:
"FlowRules"
,
principalColumn
:
"RuleId"
,
onDelete
:
ReferentialAction
.
Cascade
);
migrationBuilder
.
AddForeignKey
(
name
:
"FK_FlowOperations_Flows_FlowId"
,
table
:
"FlowOperations"
,
column
:
"FlowId"
,
principalTable
:
"Flows"
,
principalColumn
:
"FlowId"
,
onDelete
:
ReferentialAction
.
Cascade
);
}
protected
override
void
Down
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropForeignKey
(
name
:
"FK_Device_DeviceModels_DeviceModelId"
,
table
:
"Device"
);
migrationBuilder
.
DropForeignKey
(
name
:
"FK_FlowOperations_BaseEvents_BaseEventId"
,
table
:
"FlowOperations"
);
migrationBuilder
.
DropForeignKey
(
name
:
"FK_FlowOperations_FlowRules_FlowRuleId"
,
table
:
"FlowOperations"
);
migrationBuilder
.
DropForeignKey
(
name
:
"FK_FlowOperations_Flows_FlowId"
,
table
:
"FlowOperations"
);
migrationBuilder
.
DropTable
(
name
:
"DeviceModelCommands"
);
migrationBuilder
.
DropTable
(
name
:
"DeviceModels"
);
migrationBuilder
.
DropIndex
(
name
:
"IX_FlowOperations_BaseEventId"
,
table
:
"FlowOperations"
);
migrationBuilder
.
DropIndex
(
name
:
"IX_FlowOperations_FlowRuleId"
,
table
:
"FlowOperations"
);
migrationBuilder
.
DropIndex
(
name
:
"IX_Device_DeviceModelId"
,
table
:
"Device"
);
migrationBuilder
.
DropColumn
(
name
:
"BaseEventId"
,
table
:
"FlowOperations"
);
migrationBuilder
.
DropColumn
(
name
:
"FlowRuleId"
,
table
:
"FlowOperations"
);
migrationBuilder
.
DropColumn
(
name
:
"DeviceModelId"
,
table
:
"Device"
);
migrationBuilder
.
AlterColumn
<
Guid
>(
name
:
"FlowId"
,
table
:
"FlowOperations"
,
type
:
"char(36)"
,
nullable
:
true
,
collation
:
"ascii_general_ci"
,
oldClrType
:
typeof
(
Guid
),
oldType
:
"char(36)"
)
.
OldAnnotation
(
"Relational:Collation"
,
"ascii_general_ci"
);
migrationBuilder
.
AddColumn
<
Guid
>(
name
:
"BaseEventEventId"
,
table
:
"FlowOperations"
,
type
:
"char(36)"
,
nullable
:
true
,
collation
:
"ascii_general_ci"
);
migrationBuilder
.
AddColumn
<
Guid
>(
name
:
"FlowRuleRuleId"
,
table
:
"FlowOperations"
,
type
:
"char(36)"
,
nullable
:
true
,
collation
:
"ascii_general_ci"
);
migrationBuilder
.
CreateIndex
(
name
:
"IX_FlowOperations_BaseEventEventId"
,
table
:
"FlowOperations"
,
column
:
"BaseEventEventId"
);
migrationBuilder
.
CreateIndex
(
name
:
"IX_FlowOperations_FlowRuleRuleId"
,
table
:
"FlowOperations"
,
column
:
"FlowRuleRuleId"
);
migrationBuilder
.
AddForeignKey
(
name
:
"FK_FlowOperations_BaseEvents_BaseEventEventId"
,
table
:
"FlowOperations"
,
column
:
"BaseEventEventId"
,
principalTable
:
"BaseEvents"
,
principalColumn
:
"EventId"
,
onDelete
:
ReferentialAction
.
Restrict
);
migrationBuilder
.
AddForeignKey
(
name
:
"FK_FlowOperations_FlowRules_FlowRuleRuleId"
,
table
:
"FlowOperations"
,
column
:
"FlowRuleRuleId"
,
principalTable
:
"FlowRules"
,
principalColumn
:
"RuleId"
,
onDelete
:
ReferentialAction
.
Restrict
);
migrationBuilder
.
AddForeignKey
(
name
:
"FK_FlowOperations_Flows_FlowId"
,
table
:
"FlowOperations"
,
column
:
"FlowId"
,
principalTable
:
"Flows"
,
principalColumn
:
"FlowId"
,
onDelete
:
ReferentialAction
.
Restrict
);
}
}
}
IoTSharp.Data.MySQL/Migrations/ApplicationDbContextModelSnapshot.cs
浏览文件 @
abcf73c2
...
@@ -446,6 +446,9 @@ namespace IoTSharp.Data.MySql.Migrations
...
@@ -446,6 +446,9 @@ namespace IoTSharp.Data.MySql.Migrations
b
.
Property
<
Guid
?>(
"CustomerId"
)
b
.
Property
<
Guid
?>(
"CustomerId"
)
.
HasColumnType
(
"char(36)"
);
.
HasColumnType
(
"char(36)"
);
b
.
Property
<
Guid
?>(
"DeviceModelId"
)
.
HasColumnType
(
"char(36)"
);
b
.
Property
<
int
>(
"DeviceType"
)
b
.
Property
<
int
>(
"DeviceType"
)
.
HasColumnType
(
"int"
);
.
HasColumnType
(
"int"
);
...
@@ -476,6 +479,8 @@ namespace IoTSharp.Data.MySql.Migrations
...
@@ -476,6 +479,8 @@ namespace IoTSharp.Data.MySql.Migrations
b
.
HasIndex
(
"CustomerId"
);
b
.
HasIndex
(
"CustomerId"
);
b
.
HasIndex
(
"DeviceModelId"
);
b
.
HasIndex
(
"OwnerId"
);
b
.
HasIndex
(
"OwnerId"
);
b
.
HasIndex
(
"TenantId"
);
b
.
HasIndex
(
"TenantId"
);
...
@@ -669,6 +674,75 @@ namespace IoTSharp.Data.MySql.Migrations
...
@@ -669,6 +674,75 @@ namespace IoTSharp.Data.MySql.Migrations
b
.
ToTable
(
"DeviceIdentities"
);
b
.
ToTable
(
"DeviceIdentities"
);
});
});
modelBuilder
.
Entity
(
"IoTSharp.Data.DeviceModel"
,
b
=>
{
b
.
Property
<
Guid
>(
"DeviceModelId"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"char(36)"
);
b
.
Property
<
DateTime
>(
"CreateDateTime"
)
.
HasColumnType
(
"datetime(6)"
);
b
.
Property
<
Guid
>(
"Creator"
)
.
HasColumnType
(
"char(36)"
);
b
.
Property
<
string
>(
"ModelDesc"
)
.
HasColumnType
(
"longtext"
);
b
.
Property
<
string
>(
"ModelName"
)
.
HasColumnType
(
"longtext"
);
b
.
Property
<
int
>(
"ModelStatus"
)
.
HasColumnType
(
"int"
);
b
.
HasKey
(
"DeviceModelId"
);
b
.
ToTable
(
"DeviceModels"
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.DeviceModelCommand"
,
b
=>
{
b
.
Property
<
Guid
>(
"CommandId"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"char(36)"
);
b
.
Property
<
string
>(
"CommandI18N"
)
.
HasColumnType
(
"longtext"
);
b
.
Property
<
string
>(
"CommandName"
)
.
HasColumnType
(
"longtext"
);
b
.
Property
<
string
>(
"CommandParams"
)
.
HasColumnType
(
"longtext"
);
b
.
Property
<
int
>(
"CommandStatus"
)
.
HasColumnType
(
"int"
);
b
.
Property
<
string
>(
"CommandTemplate"
)
.
HasColumnType
(
"longtext"
);
b
.
Property
<
string
>(
"CommandTitle"
)
.
HasColumnType
(
"longtext"
);
b
.
Property
<
int
>(
"CommandType"
)
.
HasColumnType
(
"int"
);
b
.
Property
<
DateTime
>(
"CreateDateTime"
)
.
HasColumnType
(
"datetime(6)"
);
b
.
Property
<
Guid
>(
"Creator"
)
.
HasColumnType
(
"char(36)"
);
b
.
Property
<
Guid
>(
"DeviceModelId"
)
.
HasColumnType
(
"char(36)"
);
b
.
HasKey
(
"CommandId"
);
b
.
HasIndex
(
"DeviceModelId"
);
b
.
ToTable
(
"DeviceModelCommands"
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.DevicePort"
,
b
=>
modelBuilder
.
Entity
(
"IoTSharp.Data.DevicePort"
,
b
=>
{
{
b
.
Property
<
Guid
>(
"PortId"
)
b
.
Property
<
Guid
>(
"PortId"
)
...
@@ -1042,7 +1116,7 @@ namespace IoTSharp.Data.MySql.Migrations
...
@@ -1042,7 +1116,7 @@ namespace IoTSharp.Data.MySql.Migrations
b
.
Property
<
DateTime
?>(
"AddDate"
)
b
.
Property
<
DateTime
?>(
"AddDate"
)
.
HasColumnType
(
"datetime(6)"
);
.
HasColumnType
(
"datetime(6)"
);
b
.
Property
<
Guid
?>(
"BaseEvent
EventId"
)
b
.
Property
<
Guid
>(
"Base
EventId"
)
.
HasColumnType
(
"char(36)"
);
.
HasColumnType
(
"char(36)"
);
b
.
Property
<
string
>(
"BizId"
)
b
.
Property
<
string
>(
"BizId"
)
...
@@ -1051,10 +1125,10 @@ namespace IoTSharp.Data.MySql.Migrations
...
@@ -1051,10 +1125,10 @@ namespace IoTSharp.Data.MySql.Migrations
b
.
Property
<
string
>(
"Data"
)
b
.
Property
<
string
>(
"Data"
)
.
HasColumnType
(
"longtext"
);
.
HasColumnType
(
"longtext"
);
b
.
Property
<
Guid
?
>(
"FlowId"
)
b
.
Property
<
Guid
>(
"FlowId"
)
.
HasColumnType
(
"char(36)"
);
.
HasColumnType
(
"char(36)"
);
b
.
Property
<
Guid
?>(
"FlowRule
RuleId"
)
b
.
Property
<
Guid
>(
"Flow
RuleId"
)
.
HasColumnType
(
"char(36)"
);
.
HasColumnType
(
"char(36)"
);
b
.
Property
<
int
?>(
"NodeStatus"
)
b
.
Property
<
int
?>(
"NodeStatus"
)
...
@@ -1074,11 +1148,11 @@ namespace IoTSharp.Data.MySql.Migrations
...
@@ -1074,11 +1148,11 @@ namespace IoTSharp.Data.MySql.Migrations
b
.
HasKey
(
"OperationId"
);
b
.
HasKey
(
"OperationId"
);
b
.
HasIndex
(
"BaseEvent
Event
Id"
);
b
.
HasIndex
(
"BaseEventId"
);
b
.
HasIndex
(
"FlowId"
);
b
.
HasIndex
(
"FlowId"
);
b
.
HasIndex
(
"FlowRule
Rule
Id"
);
b
.
HasIndex
(
"FlowRuleId"
);
b
.
ToTable
(
"FlowOperations"
);
b
.
ToTable
(
"FlowOperations"
);
});
});
...
@@ -1647,6 +1721,10 @@ namespace IoTSharp.Data.MySql.Migrations
...
@@ -1647,6 +1721,10 @@ namespace IoTSharp.Data.MySql.Migrations
.
WithMany
(
"Devices"
)
.
WithMany
(
"Devices"
)
.
HasForeignKey
(
"CustomerId"
);
.
HasForeignKey
(
"CustomerId"
);
b
.
HasOne
(
"IoTSharp.Data.DeviceModel"
,
"DeviceModel"
)
.
WithMany
()
.
HasForeignKey
(
"DeviceModelId"
);
b
.
HasOne
(
"IoTSharp.Data.Gateway"
,
"Owner"
)
b
.
HasOne
(
"IoTSharp.Data.Gateway"
,
"Owner"
)
.
WithMany
(
"Children"
)
.
WithMany
(
"Children"
)
.
HasForeignKey
(
"OwnerId"
);
.
HasForeignKey
(
"OwnerId"
);
...
@@ -1657,6 +1735,8 @@ namespace IoTSharp.Data.MySql.Migrations
...
@@ -1657,6 +1735,8 @@ namespace IoTSharp.Data.MySql.Migrations
b
.
Navigation
(
"Customer"
);
b
.
Navigation
(
"Customer"
);
b
.
Navigation
(
"DeviceModel"
);
b
.
Navigation
(
"Owner"
);
b
.
Navigation
(
"Owner"
);
b
.
Navigation
(
"Tenant"
);
b
.
Navigation
(
"Tenant"
);
...
@@ -1680,6 +1760,17 @@ namespace IoTSharp.Data.MySql.Migrations
...
@@ -1680,6 +1760,17 @@ namespace IoTSharp.Data.MySql.Migrations
b
.
Navigation
(
"Device"
);
b
.
Navigation
(
"Device"
);
});
});
modelBuilder
.
Entity
(
"IoTSharp.Data.DeviceModelCommand"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Data.DeviceModel"
,
"DeviceModel"
)
.
WithMany
(
"DeviceModelCommands"
)
.
HasForeignKey
(
"DeviceModelId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
b
.
Navigation
(
"DeviceModel"
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.DeviceRule"
,
b
=>
modelBuilder
.
Entity
(
"IoTSharp.Data.DeviceRule"
,
b
=>
{
{
b
.
HasOne
(
"IoTSharp.Data.Device"
,
"Device"
)
b
.
HasOne
(
"IoTSharp.Data.Device"
,
"Device"
)
...
@@ -1714,15 +1805,21 @@ namespace IoTSharp.Data.MySql.Migrations
...
@@ -1714,15 +1805,21 @@ namespace IoTSharp.Data.MySql.Migrations
{
{
b
.
HasOne
(
"IoTSharp.Data.BaseEvent"
,
"BaseEvent"
)
b
.
HasOne
(
"IoTSharp.Data.BaseEvent"
,
"BaseEvent"
)
.
WithMany
()
.
WithMany
()
.
HasForeignKey
(
"BaseEventEventId"
);
.
HasForeignKey
(
"BaseEventId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
b
.
HasOne
(
"IoTSharp.Data.Flow"
,
"Flow"
)
b
.
HasOne
(
"IoTSharp.Data.Flow"
,
"Flow"
)
.
WithMany
()
.
WithMany
()
.
HasForeignKey
(
"FlowId"
);
.
HasForeignKey
(
"FlowId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
b
.
HasOne
(
"IoTSharp.Data.FlowRule"
,
"FlowRule"
)
b
.
HasOne
(
"IoTSharp.Data.FlowRule"
,
"FlowRule"
)
.
WithMany
()
.
WithMany
()
.
HasForeignKey
(
"FlowRuleRuleId"
);
.
HasForeignKey
(
"FlowRuleId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
b
.
Navigation
(
"BaseEvent"
);
b
.
Navigation
(
"BaseEvent"
);
...
@@ -1836,6 +1933,11 @@ namespace IoTSharp.Data.MySql.Migrations
...
@@ -1836,6 +1933,11 @@ namespace IoTSharp.Data.MySql.Migrations
b
.
Navigation
(
"Devices"
);
b
.
Navigation
(
"Devices"
);
});
});
modelBuilder
.
Entity
(
"IoTSharp.Data.DeviceModel"
,
b
=>
{
b
.
Navigation
(
"DeviceModelCommands"
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.Tenant"
,
b
=>
modelBuilder
.
Entity
(
"IoTSharp.Data.Tenant"
,
b
=>
{
{
b
.
Navigation
(
"Customers"
);
b
.
Navigation
(
"Customers"
);
...
...
IoTSharp/ClientApp/src/app/core/i18n/i18n.service.ts
浏览文件 @
abcf73c2
...
@@ -98,7 +98,8 @@ export class I18NService extends AlainI18nBaseService {
...
@@ -98,7 +98,8 @@ export class I18NService extends AlainI18nBaseService {
}
}
loadLangData
(
lang
:
string
):
Observable
<
NzSafeAny
>
{
loadLangData
(
lang
:
string
):
Observable
<
NzSafeAny
>
{
return
this
.
http
.
get
(
`assets/tmp/i18n/
${
lang
}
.json`
);
return
this
.
http
.
get
(
`api/i18n/current?_allow_anonymous=true&lang=
${
lang
}
`
);
}
}
use
(
lang
:
string
,
data
:
Record
<
string
,
unknown
>
):
void
{
use
(
lang
:
string
,
data
:
Record
<
string
,
unknown
>
):
void
{
...
...
IoTSharp/Controllers/DeviceModelController.cs
浏览文件 @
abcf73c2
...
@@ -29,12 +29,23 @@ namespace IoTSharp.Controllers
...
@@ -29,12 +29,23 @@ namespace IoTSharp.Controllers
[
HttpPost
(
"[action]"
)]
[
HttpPost
(
"[action]"
)]
public
ApiResult
<
PagedData
<
DeviceModel
>>
Index
([
FromQuery
]
DeviceModelParam
m
)
public
ApiResult
<
PagedData
<
DeviceModel
>>
Index
([
FromQuery
]
DeviceModelParam
m
)
{
{
Expression
<
Func
<
DeviceModel
,
bool
>>
condition
=
x
=>
x
.
ModelStatus
>
-
1
;
try
if
(!
string
.
IsNullOrEmpty
(
m
.
Name
))
{
Expression
<
Func
<
DeviceModel
,
bool
>>
condition
=
x
=>
x
.
ModelStatus
>
-
1
;
if
(!
string
.
IsNullOrEmpty
(
m
.
Name
))
{
condition
.
And
(
x
=>
x
.
ModelName
==
m
.
Name
);
}
return
new
ApiResult
<
PagedData
<
DeviceModel
>>(
ApiCode
.
Success
,
"OK"
,
new
PagedData
<
DeviceModel
>()
{
rows
=
_context
.
DeviceModels
.
Where
(
condition
).
Skip
((
m
.
offset
)
*
m
.
limit
).
Take
(
m
.
limit
).
ToList
(),
total
=
_context
.
DeviceModels
.
Count
(
condition
)
});
}
catch
(
Exception
e
)
{
{
condition
.
And
(
x
=>
x
.
ModelName
==
m
.
Name
);
return
new
ApiResult
<
PagedData
<
DeviceModel
>>(
ApiCode
.
Exception
,
e
.
Message
,
null
);
}
}
return
new
ApiResult
<
PagedData
<
DeviceModel
>>(
ApiCode
.
Success
,
"OK"
,
new
PagedData
<
DeviceModel
>()
{
rows
=
_context
.
DeviceModels
.
Where
(
condition
).
Skip
((
m
.
offset
)
*
m
.
limit
).
Take
(
m
.
limit
).
ToList
(),
total
=
_context
.
DeviceModels
.
Count
(
condition
)
});
}
}
[
HttpGet
(
"[action]"
)]
[
HttpGet
(
"[action]"
)]
public
ApiResult
<
DeviceModel
>
Get
(
Guid
id
)
public
ApiResult
<
DeviceModel
>
Get
(
Guid
id
)
...
@@ -81,8 +92,6 @@ namespace IoTSharp.Controllers
...
@@ -81,8 +92,6 @@ namespace IoTSharp.Controllers
_context
.
DeviceModels
.
Update
(
dm
);
_context
.
DeviceModels
.
Update
(
dm
);
_context
.
SaveChanges
();
_context
.
SaveChanges
();
return
new
ApiResult
<
bool
>(
ApiCode
.
CantFindObject
,
"Ok"
,
true
);
return
new
ApiResult
<
bool
>(
ApiCode
.
CantFindObject
,
"Ok"
,
true
);
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
...
@@ -115,9 +124,9 @@ namespace IoTSharp.Controllers
...
@@ -115,9 +124,9 @@ namespace IoTSharp.Controllers
{
{
var
dev
=
_context
.
Device
.
SingleOrDefault
(
c
=>
c
.
Id
==
id
);
var
dev
=
_context
.
Device
.
SingleOrDefault
(
c
=>
c
.
Id
==
id
);
if
(
dev
!=
null
&&
dev
.
DeviceModelId
!=
null
&&
dev
.
DeviceModelId
!=
Guid
.
Empty
)
if
(
dev
!=
null
&&
dev
.
DeviceModelId
!=
null
&&
dev
.
DeviceModelId
!=
Guid
.
Empty
)
{
{
return
new
ApiResult
<
List
<
DeviceModelCommand
>>(
ApiCode
.
Success
,
"Ok"
,
_context
.
DeviceModelCommands
.
Where
(
c
=>
c
.
DeviceModelId
==
dev
.
DeviceModelId
&&
c
.
CommandStatus
>
-
1
).
ToList
());
return
new
ApiResult
<
List
<
DeviceModelCommand
>>(
ApiCode
.
Success
,
"Ok"
,
_context
.
DeviceModelCommands
.
Where
(
c
=>
c
.
DeviceModelId
==
dev
.
DeviceModelId
&&
c
.
CommandStatus
>
-
1
).
ToList
());
}
}
...
@@ -127,7 +136,7 @@ namespace IoTSharp.Controllers
...
@@ -127,7 +136,7 @@ namespace IoTSharp.Controllers
[
HttpGet
(
"[action]"
)]
[
HttpGet
(
"[action]"
)]
public
ApiResult
<
List
<
DeviceModelCommand
>>
GetCommands
(
Guid
id
)
public
ApiResult
<
List
<
DeviceModelCommand
>>
GetCommands
(
Guid
id
)
{
{
return
new
ApiResult
<
List
<
DeviceModelCommand
>>(
ApiCode
.
Success
,
"Ok"
,
_context
.
DeviceModelCommands
.
Where
(
c
=>
c
.
DeviceModelId
==
id
&&
c
.
CommandStatus
>
-
1
).
ToList
());
return
new
ApiResult
<
List
<
DeviceModelCommand
>>(
ApiCode
.
Success
,
"Ok"
,
_context
.
DeviceModelCommands
.
Where
(
c
=>
c
.
DeviceModelId
==
id
&&
c
.
CommandStatus
>
-
1
).
ToList
());
}
}
[
HttpGet
(
"[action]"
)]
[
HttpGet
(
"[action]"
)]
...
@@ -157,8 +166,8 @@ namespace IoTSharp.Controllers
...
@@ -157,8 +166,8 @@ namespace IoTSharp.Controllers
CommandParams
=
m
.
CommandParams
,
CommandParams
=
m
.
CommandParams
,
CommandName
=
m
.
CommandName
,
CommandName
=
m
.
CommandName
,
DeviceModelId
=
m
.
DeviceModelId
,
DeviceModelId
=
m
.
DeviceModelId
,
CommandTemplate
=
m
.
CommandTemplate
,
CommandTemplate
=
m
.
CommandTemplate
,
CreateDateTime
=
DateTime
.
Now
CreateDateTime
=
DateTime
.
Now
};
};
_context
.
DeviceModelCommands
.
Add
(
dmc
);
_context
.
DeviceModelCommands
.
Add
(
dmc
);
...
...
IoTSharp/Controllers/DevicesController.cs
浏览文件 @
abcf73c2
...
@@ -104,53 +104,66 @@ namespace IoTSharp.Controllers
...
@@ -104,53 +104,66 @@ namespace IoTSharp.Controllers
public
async
Task
<
ApiResult
<
PagedData
<
DeviceDetailDto
>>>
GetDevices
([
FromQuery
]
DeviceParam
m
)
public
async
Task
<
ApiResult
<
PagedData
<
DeviceDetailDto
>>>
GetDevices
([
FromQuery
]
DeviceParam
m
)
{
{
if
(
m
.
limit
>
0
)
if
(
m
.
limit
>
0
)
{
{
Expression
<
Func
<
Device
,
bool
>>
condition
=
x
=>
x
.
Customer
.
Id
==
m
.
customerId
&&
x
.
Status
>
-
1
;
return
new
ApiResult
<
PagedData
<
DeviceDetailDto
>>(
ApiCode
.
Success
,
"OK"
,
new
PagedData
<
DeviceDetailDto
>
try
{
{
total
=
await
_context
.
Device
.
CountAsync
(
condition
),
Expression
<
Func
<
Device
,
bool
>>
condition
=
x
=>
x
.
Customer
.
Id
==
m
.
customerId
&&
x
.
Status
>
-
1
;
r
ows
=
await
_context
.
Device
.
OrderByDescending
(
c
=>
c
.
LastActive
).
Where
(
condition
).
Skip
((
m
.
offset
)
*
m
.
limit
).
Take
(
m
.
limit
).
Join
(
_context
.
DeviceIdentities
,
x
=>
x
.
Id
,
y
=>
y
.
Device
.
Id
,
(
x
,
y
)
=>
new
DeviceDetailDto
()
r
eturn
new
ApiResult
<
PagedData
<
DeviceDetailDto
>>(
ApiCode
.
Success
,
"OK"
,
new
PagedData
<
DeviceDetailDto
>
{
{
Id
=
x
.
Id
,
total
=
await
_context
.
Device
.
CountAsync
(
condition
),
Name
=
x
.
Name
,
rows
=
await
_context
.
Device
.
OrderByDescending
(
c
=>
c
.
LastActive
).
Where
(
condition
).
Skip
((
m
.
offset
)
*
m
.
limit
).
Take
(
m
.
limit
).
Join
(
_context
.
DeviceIdentities
,
x
=>
x
.
Id
,
y
=>
y
.
Device
.
Id
,
(
x
,
y
)
=>
new
DeviceDetailDto
()
LastActive
=
x
.
LastActive
,
{
IdentityId
=
y
.
IdentityId
,
Id
=
x
.
Id
,
IdentityValue
=
y
.
IdentityType
==
IdentityType
.
X509Certificate
?
""
:
y
.
IdentityValue
,
Name
=
x
.
Name
,
Tenant
=
x
.
Tenant
,
LastActive
=
x
.
LastActive
,
Customer
=
x
.
Customer
,
IdentityId
=
y
.
IdentityId
,
DeviceType
=
x
.
DeviceType
,
IdentityValue
=
y
.
IdentityType
==
IdentityType
.
X509Certificate
?
""
:
y
.
IdentityValue
,
Online
=
x
.
Online
,
Tenant
=
x
.
Tenant
,
Owner
=
x
.
Owner
,
Customer
=
x
.
Customer
,
Timeout
=
x
.
Timeout
,
DeviceType
=
x
.
DeviceType
,
IdentityType
=
y
.
IdentityType
Online
=
x
.
Online
,
Owner
=
x
.
Owner
,
Timeout
=
x
.
Timeout
,
}).
ToListAsync
()
IdentityType
=
y
.
IdentityType
});
}).
ToListAsync
()
});
}
catch
(
Exception
e
)
{
return
new
ApiResult
<
PagedData
<
DeviceDetailDto
>>(
ApiCode
.
Exception
,
e
.
Message
,
null
);
}
}
}
else
else
{
{
try
Expression
<
Func
<
Device
,
bool
>>
condition
=
x
=>
x
.
Customer
.
Id
==
m
.
customerId
&&
x
.
Status
>
-
1
;
return
new
ApiResult
<
PagedData
<
DeviceDetailDto
>>(
ApiCode
.
Success
,
"OK"
,
new
PagedData
<
DeviceDetailDto
>
{
{
total
=
await
_context
.
Device
.
CountAsync
(
condition
),
Expression
<
Func
<
Device
,
bool
>>
condition
=
x
=>
x
.
Customer
.
Id
==
m
.
customerId
&&
x
.
Status
>
-
1
;
r
ows
=
await
_context
.
Device
.
OrderByDescending
(
c
=>
c
.
LastActive
).
Where
(
condition
).
Select
(
x
=>
new
DeviceDetailDto
()
r
eturn
new
ApiResult
<
PagedData
<
DeviceDetailDto
>>(
ApiCode
.
Success
,
"OK"
,
new
PagedData
<
DeviceDetailDto
>
{
{
Id
=
x
.
Id
,
total
=
await
_context
.
Device
.
CountAsync
(
condition
),
Name
=
x
.
Name
,
rows
=
await
_context
.
Device
.
OrderByDescending
(
c
=>
c
.
LastActive
).
Where
(
condition
).
Select
(
x
=>
new
DeviceDetailDto
()
LastActive
=
x
.
LastActive
,
{
Tenant
=
x
.
Tenant
,
Id
=
x
.
Id
,
Customer
=
x
.
Customer
,
Name
=
x
.
Name
,
DeviceType
=
x
.
DeviceType
,
LastActive
=
x
.
LastActive
,
Online
=
x
.
Online
,
Tenant
=
x
.
Tenant
,
Owner
=
x
.
Owner
,
Customer
=
x
.
Customer
,
Timeout
=
x
.
Timeout
,
DeviceType
=
x
.
DeviceType
,
}).
ToListAsync
()
Online
=
x
.
Online
,
});
Owner
=
x
.
Owner
,
Timeout
=
x
.
Timeout
,
}).
ToListAsync
()
});
}
catch
(
Exception
e
)
{
return
new
ApiResult
<
PagedData
<
DeviceDetailDto
>>(
ApiCode
.
Exception
,
e
.
Message
,
null
);
}
}
}
...
@@ -622,15 +635,21 @@ namespace IoTSharp.Controllers
...
@@ -622,15 +635,21 @@ namespace IoTSharp.Controllers
{
{
var
cid
=
User
.
Claims
.
First
(
c
=>
c
.
Type
==
IoTSharpClaimTypes
.
Customer
);
var
cid
=
User
.
Claims
.
First
(
c
=>
c
.
Type
==
IoTSharpClaimTypes
.
Customer
);
var
tid
=
User
.
Claims
.
First
(
c
=>
c
.
Type
==
IoTSharpClaimTypes
.
Tenant
);
var
tid
=
User
.
Claims
.
First
(
c
=>
c
.
Type
==
IoTSharpClaimTypes
.
Tenant
);
var
devvalue
=
new
Device
()
{
Name
=
device
.
Name
,
DeviceType
=
device
.
DeviceType
,
Timeout
=
device
.
Timeout
,
LastActive
=
DateTime
.
Now
,
Status
=
1
,
var
devvalue
=
new
Device
()
DeviceModel
=
_context
.
DeviceModels
.
FirstOrDefault
(
c
=>
c
.
DeviceModelId
==
device
.
DeviceModelId
),
{
//CreateDate = DateTime.Today,
Name
=
device
.
Name
,
//CreateMonth =DateTime.Now.ToString("yyyy-MM"),
DeviceType
=
device
.
DeviceType
,
//CreateDateTime = DateTime.Now
Timeout
=
device
.
Timeout
,
};
LastActive
=
DateTime
.
Now
,
Status
=
1
,
DeviceModel
=
_context
.
DeviceModels
.
FirstOrDefault
(
c
=>
c
.
DeviceModelId
==
device
.
DeviceModelId
),
//CreateDate = DateTime.Today,
//CreateMonth =DateTime.Now.ToString("yyyy-MM"),
//CreateDateTime = DateTime.Now
};
devvalue
.
Tenant
=
_context
.
Tenant
.
Find
(
new
Guid
(
tid
.
Value
));
devvalue
.
Tenant
=
_context
.
Tenant
.
Find
(
new
Guid
(
tid
.
Value
));
devvalue
.
Customer
=
_context
.
Customer
.
Find
(
new
Guid
(
cid
.
Value
));
devvalue
.
Customer
=
_context
.
Customer
.
Find
(
new
Guid
(
cid
.
Value
));
if
(
devvalue
.
Tenant
==
null
||
devvalue
.
Customer
==
null
)
if
(
devvalue
.
Tenant
==
null
||
devvalue
.
Customer
==
null
)
...
@@ -646,7 +665,7 @@ namespace IoTSharp.Controllers
...
@@ -646,7 +665,7 @@ namespace IoTSharp.Controllers
{
{
identity
.
IdentityType
=
device
.
IdentityType
;
identity
.
IdentityType
=
device
.
IdentityType
;
_context
.
DeviceIdentities
.
Update
(
identity
);
_context
.
DeviceIdentities
.
Update
(
identity
);
await
_context
.
SaveChangesAsync
();
await
_context
.
SaveChangesAsync
();
}
}
...
@@ -711,7 +730,7 @@ namespace IoTSharp.Controllers
...
@@ -711,7 +730,7 @@ namespace IoTSharp.Controllers
try
try
{
{
_logger
.
LogInformation
(
$"RPC 通过 access_token:
{
access_token
}
找到设备
{
dev
.
Name
}
"
);
_logger
.
LogInformation
(
$"RPC 通过 access_token:
{
access_token
}
找到设备
{
dev
.
Name
}
"
);
var
rpcClient
=
new
RpcClient
(
_mqtt
,
_logger
);
var
rpcClient
=
new
RpcClient
(
_mqtt
,
_logger
);
var
_timeout
=
TimeSpan
.
FromSeconds
(
timeout
);
var
_timeout
=
TimeSpan
.
FromSeconds
(
timeout
);
var
qos
=
MqttQualityOfServiceLevel
.
AtMostOnce
;
var
qos
=
MqttQualityOfServiceLevel
.
AtMostOnce
;
var
payload
=
Newtonsoft
.
Json
.
JsonConvert
.
SerializeObject
(
args
);
var
payload
=
Newtonsoft
.
Json
.
JsonConvert
.
SerializeObject
(
args
);
...
@@ -865,7 +884,7 @@ namespace IoTSharp.Controllers
...
@@ -865,7 +884,7 @@ namespace IoTSharp.Controllers
});
});
await
_context
.
SaveChangesAsync
();
await
_context
.
SaveChangesAsync
();
return
new
ApiResult
<
bool
>(
ApiCode
.
Success
,
"Ok"
,
true
);
return
new
ApiResult
<
bool
>(
ApiCode
.
Success
,
"Ok"
,
true
);
}
}
...
@@ -939,7 +958,7 @@ namespace IoTSharp.Controllers
...
@@ -939,7 +958,7 @@ namespace IoTSharp.Controllers
[
ProducesDefaultResponseType
]
[
ProducesDefaultResponseType
]
public
async
Task
<
ApiResult
<
int
>>
GetSessionsCount
()
public
async
Task
<
ApiResult
<
int
>>
GetSessionsCount
()
{
{
return
new
ApiResult
<
int
>(
ApiCode
.
Success
,
"OK"
,
(
await
_serverEx
.
GetClientStatusAsync
()).
Count
);
return
new
ApiResult
<
int
>(
ApiCode
.
Success
,
"OK"
,
(
await
_serverEx
.
GetClientStatusAsync
()).
Count
);
}
}
}
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录