提交 49d59915 编写于 作者: W wq1234wq

设备指令发送

上级 9021ff33
......@@ -11,6 +11,13 @@
<nz-option nzValue="Gateway" nzLabel="网关"></nz-option>
</nz-select>
</se>
<se label="设备型号" error="设备型号" >
<nz-select formControlName="deviceModelId" placeholder="设备型号" >
<nz-option *ngFor="let o of devicemodel" [nzValue]="o.deviceModelId" [nzLabel]="o.modelName"></nz-option>
</nz-select>
</se>
<se label="认证方式" error="认证方式" required>
<nz-select formControlName="identityType" placeholder="设备类型">
<nz-option nzValue="AccessToken" nzLabel="AccessToken"></nz-option>
......
......@@ -9,6 +9,7 @@ import { concat } from 'rxjs';
import { map } from 'rxjs/operators';
import { appmessage, AppMessage } from '../../common/AppMessage';
import { MyValidators } from '../../common/validators/MyValidators';
import { devicemodel } from '../../devicemodel/devicemodelcommandparam';
import { deviceitem } from '../devicelist/devicelist.component';
@Component({
......@@ -36,6 +37,9 @@ export class DeviceformComponent implements OnInit {
form!: FormGroup;
submitting = false;
devicemodel:devicemodel[]=[];
data: deviceitem = {
name: '',
deviceType: '',
......@@ -44,15 +48,24 @@ export class DeviceformComponent implements OnInit {
identityType: '',
};
ngOnInit() {
console.log();
const { nullbigintid } = MyValidators;
this.form = this.fb.group({
name: [null, [Validators.required]],
deviceType: [null, [Validators.required]],
customerId: [null, []],
deviceModelId: [null, []],
id: [Guid.EMPTY, []],
identityType: [Guid.EMPTY, []],
});
this._httpClient.post('api/deviceModel/index',{offset:0, limit:100 }).subscribe(next=>{
this.devicemodel=next.data.rows;
},error=>{
},()=>{})
if (this.params.id !== Guid.EMPTY) {
concat(
this._httpClient.get<appmessage<deviceitem>>('api/Devices/' + this.params.id).pipe(
......
......@@ -135,6 +135,28 @@
</tr></tbody>
</nz-table>
</nz-card>
<nz-card nzTitle="操作">
<div nz-row >
<span *ngFor="let _item of cett; let i = index;">
<button
nz-button
nzType="primary"
(nzOnConfirm)="executeCommand(item, _item)"
nz-popconfirm
nzPopconfirmTitle="{{'确认执行'+_item.commandTitle+'?'}}"
nzPopconfirmPlacement="topLeft"
>
{{_item.commandTitle}}
</button></span>
</div>
</nz-card>
</ng-template>
</st>
</page-header>
......@@ -20,6 +20,7 @@ import { ClipboardService } from 'ngx-clipboard';
import { DevicetokendialogComponent } from '../devicetokendialog/devicetokendialog.component';
import { fork } from 'child_process';
import { ProppartComponent } from '../deviceprop/proppart/proppart.component';
import { devicemodelcommand } from '../../devicemodel/devicemodelcommandparam';
@Component({
selector: 'app-devicelist',
templateUrl: './devicelist.component.html',
......@@ -59,6 +60,7 @@ export class DevicelistComponent implements OnInit, OnDestroy {
cetd: telemetryitem[] = [];
cead: attributeitem[] = [];
cerd: ruleitem[] = [];
cett: devicemodelcommand[] = [];
page: STPage = {
front: false,
total: true,
......@@ -368,12 +370,14 @@ export class DevicelistComponent implements OnInit, OnDestroy {
this.cead = [];
this.cetd = [];
this.cerd = [];
this.cett = [];
this.obs = interval(1000).subscribe(async () => {
zip(
this.http.get<appmessage<attributeitem[]>>('api/Devices/' + $events.expand?.id + '/AttributeLatest'),
this.http.get<appmessage<ruleitem[]>>('api/Rules/GetDeviceRules?deviceId=' + $events.expand?.id),
this.http.get<appmessage<telemetryitem[]>>('api/Devices/' + $events.expand?.id + '/TelemetryLatest'),
).subscribe(([attributes, rules, telemetries]) => {
this.http.get<appmessage<devicemodelcommand[]>>('api/deviceModel/getCommandsByDevice?id=' + $events.expand?.id ),
).subscribe(([attributes, rules, telemetries,commands]) => {
// $events.expand.attributes = attributes.data;
// $events.expand.rules = rules.data;
// $events.expand.telemetries = telemetries.data;
......@@ -435,12 +439,18 @@ export class DevicelistComponent implements OnInit, OnDestroy {
}
}
}
if(this.cett.length==0){
this.cett=commands.data;
}
});
});
} else {
this.cead = [];
this.cetd = [];
this.cerd = [];
this.cett = [];
if( this.obs){
this.obs.unsubscribe();
}
......@@ -451,6 +461,23 @@ export class DevicelistComponent implements OnInit, OnDestroy {
}
}
executeCommand(item: deviceitem,command: devicemodelcommand){
console.log(item)
this.http.post('api/Devices/'+item.identityId+'/Rpc/'+command.commandName+'?timeout=300',{}).subscribe(next=>{
},error=>{
},()=>{
})
}
removerule(item: deviceitem, rule: ruleitem) {
this.http.get('api/Rules/DeleteDeviceRules?deviceId=' + item.id + '&ruleId=' + rule.ruleId).subscribe(
() => {
......@@ -470,6 +497,7 @@ export interface deviceitem {
online?: string;
owner?: string;
tenant?: string;
identityId?: string;
timeout?: string;
customerId?: string;
telemetries?: telemetryitem[];
......
export interface devicemodel{
deviceModelId:string;
mdelName:string;
modelName:string;
modelDesc:string;
modelStatus:string;
createDateTime:string;
......
......@@ -10,6 +10,7 @@ using IoTSharp.Dtos;
using IoTSharp.Models;
using LinqKit;
using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;
namespace IoTSharp.Controllers
{
......@@ -108,6 +109,21 @@ namespace IoTSharp.Controllers
return new ApiResult<bool>(ApiCode.CantFindObject, "CantFindObject", false);
}
[HttpGet("[action]")]
public ApiResult<List<DeviceModelCommand>> GetCommandsByDevice(Guid id)
{
var dev = _context.Device.SingleOrDefault(c => c.Id == id);
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", null);
}
[HttpGet("[action]")]
public ApiResult<List<DeviceModelCommand>> GetCommands(Guid id)
{
......
......@@ -405,15 +405,10 @@ namespace IoTSharp.Controllers
public async Task<ApiResult<List<TelemetryDataDto>>> GetTelemetryLatest(Guid deviceId)
{
Device dev = Found(deviceId);
if (dev == null)
{
return new ApiResult<List<TelemetryDataDto>>(ApiCode.NotFoundDeviceIdentity, "Device's Identity not found", null);
}
try
......@@ -428,17 +423,8 @@ namespace IoTSharp.Controllers
null);
}
}
/// <summary>
/// 获取指定设备的指定key 的遥测数据
/// </summary>
......@@ -465,7 +451,6 @@ namespace IoTSharp.Controllers
}
}
/// <summary>
/// 获取指定设备和指定时间, 指定key的数据
/// </summary>
......@@ -494,8 +479,6 @@ namespace IoTSharp.Controllers
? await _storage.LoadTelemetryAsync(deviceId, begin)
: await _storage.LoadTelemetryAsync(deviceId, keys, begin));
}
}
/// <summary>
......@@ -591,6 +574,8 @@ namespace IoTSharp.Controllers
return new ApiResult<bool>(ApiCode.DoNotAllow, "Do not allow access to devices from other customers or tenants", false);
// return BadRequest(new ApiResult(ApiCode.DoNotAllow, $"Do not allow access to devices from other customers or tenants"));
}
dev.DeviceModel = _context.DeviceModels.FirstOrDefault(c => c.DeviceModelId == device.DeviceModelId);
dev.Name = device.Name;
try
{
......@@ -636,11 +621,12 @@ namespace IoTSharp.Controllers
{
var cid = User.Claims.First(c => c.Type == IoTSharpClaimTypes.Customer);
var tid = User.Claims.First(c => c.Type == IoTSharpClaimTypes.Tenant);
var devvalue = new Device() { Name = device.Name, DeviceType = device.DeviceType, Timeout = 300, LastActive = DateTime.Now, Status = 1,
//CreateDate = DateTime.Today,
//CreateMonth =DateTime.Now.ToString("yyyy-MM"),
//CreateDateTime = DateTime.Now
};
var devvalue = new Device() { Name = device.Name, DeviceType = device.DeviceType, Timeout = 300, 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.Customer = _context.Customer.Find(new Guid(cid.Value));
......
......@@ -47,5 +47,10 @@ namespace IoTSharp.Dtos
public string IdentityValue { get; set; }
public string IdentityId { get; set; }
public DeviceModel? Model { get; set; }
}
}
......@@ -10,7 +10,7 @@ namespace IoTSharp.Dtos
{
public string Name { get; set; }
public DeviceType DeviceType { get; set; }
public Guid DeviceModelId { get; set; }
public IdentityType IdentityType { get; set; }
}
}
......@@ -10,6 +10,8 @@ namespace IoTSharp.Dtos
{
public Guid Id { get; set; }
public string Name { get; set; }
public Guid DeviceModelId { get; set; }
public IdentityType IdentityType { get; set; }
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册