提交 e05f4c4e 编写于 作者: W wq1234wq

设备创建

上级 50b24fb4
...@@ -11,13 +11,13 @@ ...@@ -11,13 +11,13 @@
<nz-option nzValue="Gateway" nzLabel="网关"></nz-option> <nz-option nzValue="Gateway" nzLabel="网关"></nz-option>
</nz-select> </nz-select>
</se> </se>
<!--
<se label="所属产品" error="所属产品" > <se label="所属产品" error="所属产品" >
<nz-select formControlName="produceId" placeholder="所属产品" > <nz-select formControlName="produceId" placeholder="所属产品" >
<nz-option *ngFor="let o of deviceproduce" [nzValue]="o.id" [nzLabel]="o.name"></nz-option> <nz-option *ngFor="let o of deviceproduce" [nzValue]="o.id" [nzLabel]="o.name"></nz-option>
</nz-select> </nz-select>
</se> </se>
-->
<se label="超时" error="超时" required> <se label="超时" error="超时" required>
<nz-input-number formControlName="timeout" [nzMin]="0" [nzStep]="1"></nz-input-number> <nz-input-number formControlName="timeout" [nzMin]="0" [nzStep]="1"></nz-input-number>
</se> </se>
......
<div class="modal-header">
<div class="modal-title">Title</div>
</div>
<form nz-form [formGroup]="form" (ngSubmit)="submit()" se-container="1" labelWidth="200">
<se label="名称" error="名称不能为空或者空白字符" required>
<input nz-input formControlName="name" placeholder="名称" required />
</se>
<se>
<button nz-button [nzType]="'default'" (click)="cancel()">
取消
</button>
<button nz-button [nzType]="'primary'" [disabled]="form.invalid" type="submit">
创建
</button>
</se>
</form>
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CreatedeviceformComponent } from './createdeviceform.component';
describe('CreatedeviceformComponent', () => {
let component: CreatedeviceformComponent;
let fixture: ComponentFixture<CreatedeviceformComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ CreatedeviceformComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(CreatedeviceformComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { _HttpClient } from '@delon/theme';
import { Guid } from 'guid-typescript';
import { NzModalRef } from 'ng-zorro-antd/modal';
@Component({
selector: 'app-createdeviceform',
templateUrl: './createdeviceform.component.html',
styleUrls: ['./createdeviceform.component.less']
})
export class CreatedeviceformComponent implements OnInit {
constructor(private nzModalRef:NzModalRef , private fb: FormBuilder,private _httpClient: _HttpClient,) { }
id:string
form!: FormGroup;
ngOnInit(): void {
this.form = this.fb.group({
name: ['', [Validators.required]],
// produceId: [this.id, []],
});
}
submit(){
this._httpClient.post('api/Devices/produce/'+this.id,this.form.value).subscribe({
next:next=>{
if(next.code==10000){
this.nzModalRef.close(next);
}else{
this.nzModalRef.close(next);
}
},
error:error=>{},
complete:()=>{},
})
}
cancel(){
this.nzModalRef.close();
}
}
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { SharedModule } from '@shared'; import { SharedModule } from '@shared';
import { CreatedeviceformComponent } from './createdeviceform/createdeviceform.component';
import { ProduceRoutingModule } from './produce-routing.module'; import { ProduceRoutingModule } from './produce-routing.module';
import { ProducedatadictionaryformComponent } from './producedatadictionaryform/producedatadictionaryform.component'; import { ProducedatadictionaryformComponent } from './producedatadictionaryform/producedatadictionaryform.component';
import { ProducedataformComponent } from './producedataform/producedataform.component'; import { ProducedataformComponent } from './producedataform/producedataform.component';
const COMPONENTS = [ const COMPONENTS = [
ProducedataformComponent,ProducedatadictionaryformComponent ProducedataformComponent,ProducedatadictionaryformComponent,CreatedeviceformComponent
]; ];
@NgModule({ @NgModule({
......
...@@ -20,21 +20,17 @@ ...@@ -20,21 +20,17 @@
</nz-select> </nz-select>
</se> </se>
<se label="默认网关类型" error="默认网关类型" *ngIf="this.form.value.gatewayType==='Customize'"> <se label="默认网关配置" error="默认网关配置" *ngIf="this.form.value.gatewayType==='Customize'">
<nz-code-editor formControlName="gatewayConfigurationJson" [class.full-screen]="fullScreen" <nz-code-editor formControlName="gatewayConfigurationJson" [class.full-screen]="fullScreen"
style="width: 100%; height: 500px; padding-top: 1rem" class="editor" style="width: 100%; height: 500px; padding-top: 1rem" class="editor"
[nzEditorOption]="{ theme: 'vs',language: 'json' }"> [nzEditorOption]="{ theme: 'vs',language: 'json' }">
</nz-code-editor> </nz-code-editor>
</se> </se>
<se label="默认网关类型" error="默认网关类型" *ngIf="this.form.value.gatewayType!=='Unknow'&&this.form.value.gatewayType!=='Customize'"> <se label="默认网关配置名称" error="默认网关配置名称" *ngIf="this.form.value.gatewayType!=='Unknow'&&this.form.value.gatewayType!=='Customize'">
<input nz-input formControlName="gatewayConfigurationName" placeholder="名称" /> <input nz-input formControlName="gatewayConfigurationName" placeholder="默认网关配置名称" />
</se> </se>
<se label="默认设备类型" error="默认设备类型" required>
<nz-select formControlName="defaultDeviceType" placeholder="默认设备类型">
<se label="默认超时" error="默认超时" required>
<nz-select formControlName="defaultDeviceType" placeholder="默认网关类型">
<nz-option nzValue="Device" nzLabel="Device"></nz-option> <nz-option nzValue="Device" nzLabel="Device"></nz-option>
<nz-option nzValue="Gateway" nzLabel="Gateway"></nz-option> <nz-option nzValue="Gateway" nzLabel="Gateway"></nz-option>
</nz-select> </nz-select>
......
...@@ -6,6 +6,7 @@ import { Guid } from 'guid-typescript'; ...@@ -6,6 +6,7 @@ import { Guid } from 'guid-typescript';
import { NzDrawerService } from 'ng-zorro-antd/drawer'; import { NzDrawerService } from 'ng-zorro-antd/drawer';
import { NzMessageService } from 'ng-zorro-antd/message'; import { NzMessageService } from 'ng-zorro-antd/message';
import { appmessage } from 'src/app/models/appmessage'; import { appmessage } from 'src/app/models/appmessage';
import { CreatedeviceformComponent } from '../createdeviceform/createdeviceform.component';
import { ProducedatadictionaryformComponent } from '../producedatadictionaryform/producedatadictionaryform.component'; import { ProducedatadictionaryformComponent } from '../producedatadictionaryform/producedatadictionaryform.component';
import { ProducedataformComponent } from '../producedataform/producedataform.component'; import { ProducedataformComponent } from '../producedataform/producedataform.component';
import { ProduceformComponent } from '../produceform/produceform.component'; import { ProduceformComponent } from '../produceform/produceform.component';
...@@ -92,21 +93,16 @@ export class ProducelistComponent implements OnInit { ...@@ -92,21 +93,16 @@ export class ProducelistComponent implements OnInit {
Gateway: { text: '网关', color: 'blue' } Gateway: { text: '网关', color: 'blue' }
}; };
devicecolumns:STColumn[] = [ devicecolumns:STColumn[] = [
{ title: 'id', index: 'id', }, { title: 'id', index: 'id', },
{title: '名称', {title: '名称',
index: 'name', index: 'name',
render: 'name', render: 'name',
type: 'link', type: 'link',
}, },
{ title: '设备类型', index: 'deviceType', type: 'tag', tag: this.DeviceTAG }, { title: '设备类型', index: 'deviceType', type: 'tag', tag: this.DeviceTAG },
{ title: '在线状态', index: 'active', type: 'badge', badge: this.BADGE, sort: true }, { title: '在线状态', index: 'active', type: 'badge', badge: this.BADGE, sort: true },
{ title: '最后活动时间', index: 'lastActivityDateTime', type: 'date' }, { title: '最后活动时间', index: 'lastActivityDateTime', type: 'date' },
{ title: '认证方式', index: 'identityType', type: 'tag', tag: this.TAG}, { title: '认证方式', index: 'identityType', type: 'tag', tag: this.TAG},
] ]
@ViewChild('st', { static: true }) @ViewChild('st', { static: true })
...@@ -153,6 +149,13 @@ export class ProducelistComponent implements OnInit { ...@@ -153,6 +149,13 @@ export class ProducelistComponent implements OnInit {
this.editdic(item.id); this.editdic(item.id);
} }
}, },
{
text: '创建设备',
acl: 56,
click: (item: any) => {
this.createdevice(item.id);
}
},
{ {
text: '删除', text: '删除',
pop: { pop: {
...@@ -173,6 +176,24 @@ export class ProducelistComponent implements OnInit { ...@@ -173,6 +176,24 @@ export class ProducelistComponent implements OnInit {
ngOnInit() { ngOnInit() {
} }
createdevice( id:string){
this.modal.create(CreatedeviceformComponent, { id }).subscribe(res => {
if(res&&res.code===10000){
this.msg.success('保存成功')
}else{
this.msg.warning('保存失败:'+res.msg)
}
});
}
openComponent(id: string): void { openComponent(id: string): void {
var { nzMaskClosable, width } = this.settingService.getData('drawerconfig'); var { nzMaskClosable, width } = this.settingService.getData('drawerconfig');
var title = id == Guid.EMPTY ? '新增产品' : '修改产品'; var title = id == Guid.EMPTY ? '新增产品' : '修改产品';
...@@ -203,7 +224,7 @@ export class ProducelistComponent implements OnInit { ...@@ -203,7 +224,7 @@ export class ProducelistComponent implements OnInit {
const drawerRef = this.drawerService.create<ProducedataformComponent, { id: string }, string>({ const drawerRef = this.drawerService.create<ProducedataformComponent, { id: string }, string>({
nzTitle: title, nzTitle: title,
nzContent: ProducedataformComponent, nzContent: ProducedataformComponent,
nzWidth: width, nzWidth: '80%',
nzMaskClosable: nzMaskClosable, nzMaskClosable: nzMaskClosable,
nzContentParams: { nzContentParams: {
id: id id: id
......
...@@ -53,11 +53,12 @@ namespace IoTSharp.Controllers ...@@ -53,11 +53,12 @@ namespace IoTSharp.Controllers
if (m.limit > 1) if (m.limit > 1)
{ {
return new ApiResult<PagedData<ProduceDto>>(ApiCode.Success, "OK", new PagedData<ProduceDto> return new ApiResult<PagedData<ProduceDto>>(ApiCode.Success, "OK", new PagedData<ProduceDto>
{ {
total = await _context.Produces.CountAsync(condition), total = await _context.Produces.CountAsync(condition),
rows = _context.Produces.Include(c=>c.Devices).Where(condition).Skip((m.offset) * m.limit).Take(m.limit) rows = _context.Produces.Include(c => c.Devices).Where(condition).Skip((m.offset) * m.limit)
.Take(m.limit)
.ToList().Select(c => new ProduceDto .ToList().Select(c => new ProduceDto
{ {
Id = c.Id, Id = c.Id,
...@@ -88,7 +89,7 @@ namespace IoTSharp.Controllers ...@@ -88,7 +89,7 @@ namespace IoTSharp.Controllers
}); });
} }
} }
...@@ -249,19 +250,20 @@ namespace IoTSharp.Controllers ...@@ -249,19 +250,20 @@ namespace IoTSharp.Controllers
[HttpGet] [HttpGet]
public async Task<ApiResult<List<ProduceDataItemDto>>> GetProduceData(Guid produceId) public async Task<ApiResult<List<ProduceDataItemDto>>> GetProduceData(Guid produceId)
{ {
var produce = await _context.Produces var produce = await _context.Produces.Include(c=>c.DefaultAttributes)
.SingleOrDefaultAsync(c => c.Id == produceId); .SingleOrDefaultAsync(c => c.Id == produceId);
if (produce != null) if (produce != null)
{ {
//var result = _context.ProduceDatas.Where(c => c.Owner.Id == produceId).Select(c => new ProduceDataItemDto //var result = _context.ProduceDatas.Include(c=>c.Owner).Where(c => c.Owner.Id == produceId).Select(c => new ProduceDataItemDto
//{ KeyName = c.KeyName, DataSide = c.DataSide, Type = c.Type }).ToList(); //{ KeyName = c.KeyName, DataSide = c.DataSide, Type = c.Type }).ToList();
var result = _context.DataStorage.Where(c => c.DeviceId == Guid.Empty).Select(c => var result = _context.DataStorage.Where(c => c.DeviceId == produceId).Select(c =>
new ProduceDataItemDto new ProduceDataItemDto
{ KeyName = c.KeyName, DataSide = c.DataSide, Type = c.Type }).ToList(); { KeyName = c.KeyName, DataSide = c.DataSide, Type = c.Type }).ToList();
return new ApiResult<List<ProduceDataItemDto>>(ApiCode.Success, "Ok", result); return new ApiResult<List<ProduceDataItemDto>>(ApiCode.Success, "Ok", result);
} }
return new ApiResult<List<ProduceDataItemDto>>(ApiCode.CantFindObject, "Produce is not found", null); return new ApiResult<List<ProduceDataItemDto>>(ApiCode.CantFindObject, "Produce is not found", null);
} }
...@@ -279,13 +281,18 @@ namespace IoTSharp.Controllers ...@@ -279,13 +281,18 @@ namespace IoTSharp.Controllers
try try
{ {
var produce = await _context.Produces.Include(c => c.DefaultAttributes).SingleOrDefaultAsync(c => c.Id == dto.produceId); var produce = await _context.Produces.Include(c => c.DefaultAttributes)
.SingleOrDefaultAsync(c => c.Id == dto.produceId);
if (produce != null) if (produce != null)
{ {
var pds = _context.ProduceDatas.Where(c => c.Owner == produce).ToList(); var pds = _context.ProduceDatas.Include(c=>c.Owner).Where(c => c.Owner.Id==dto.produceId).ToList();
if (dto.ProduceData != null && dto.ProduceData.Length > 0) if (dto.ProduceData != null && dto.ProduceData.Length > 0)
{ {
var data = dto.ProduceData.Select(c => new ProduceData { KeyName = c.KeyName, DataSide = c.DataSide, Type = c.Type, Owner = produce, DateTime = DateTime.Now }).ToList(); var data = dto.ProduceData.Select(c => new ProduceData
{
KeyName = c.KeyName, DataSide = c.DataSide, Type = c.Type, Owner = produce,
DateTime = DateTime.Now
}).ToList();
foreach (var item in data) foreach (var item in data)
{ {
var pd = pds.FirstOrDefault(c => c.KeyName.ToLower() == item.KeyName.ToLower()); var pd = pds.FirstOrDefault(c => c.KeyName.ToLower() == item.KeyName.ToLower());
...@@ -297,15 +304,18 @@ namespace IoTSharp.Controllers ...@@ -297,15 +304,18 @@ namespace IoTSharp.Controllers
} }
else else
{ {
item.DeviceId = dto.produceId;
_context.ProduceDatas.Add(item); _context.ProduceDatas.Add(item);
} }
} }
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
var delete_keynames = pds.Select(c => c.KeyName.ToLower()) var delete_keynames = pds.Select(c => c.KeyName.ToLower())
.Except(dto.ProduceData.Select(c => c.KeyName.ToLower())).ToArray(); .Except(dto.ProduceData.Select(c => c.KeyName.ToLower())).ToArray();
if (delete_keynames.Length > 0) if (delete_keynames.Length > 0)
{ {
var deleteattr = pds.Join(delete_keynames, x => x.KeyName.ToLower(), y => y, (x, y) => x).ToArray(); var deleteattr = pds.Join(delete_keynames, x => x.KeyName.ToLower(), y => y, (x, y) => x)
.ToArray();
_context.ProduceDatas.RemoveRange(deleteattr); _context.ProduceDatas.RemoveRange(deleteattr);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
...@@ -313,8 +323,10 @@ namespace IoTSharp.Controllers ...@@ -313,8 +323,10 @@ namespace IoTSharp.Controllers
return new ApiResult<bool>(ApiCode.Success, "Ok", true); return new ApiResult<bool>(ApiCode.Success, "Ok", true);
} }
return new ApiResult<bool>(ApiCode.CantFindObject, "Produce data is not found", false); return new ApiResult<bool>(ApiCode.CantFindObject, "Produce data is not found", false);
} }
return new ApiResult<bool>(ApiCode.CantFindObject, "Produce is not found", false); return new ApiResult<bool>(ApiCode.CantFindObject, "Produce is not found", false);
} }
catch (Exception e) catch (Exception e)
...@@ -341,6 +353,7 @@ namespace IoTSharp.Controllers ...@@ -341,6 +353,7 @@ namespace IoTSharp.Controllers
{ {
return new ApiResult<List<ProduceDictionary>>(ApiCode.Success, "Ok", produce.Dictionaries); return new ApiResult<List<ProduceDictionary>>(ApiCode.Success, "Ok", produce.Dictionaries);
} }
return new ApiResult<List<ProduceDictionary>>(ApiCode.CantFindObject, "Produce is not found", null); return new ApiResult<List<ProduceDictionary>>(ApiCode.CantFindObject, "Produce is not found", null);
} }
...@@ -358,7 +371,8 @@ namespace IoTSharp.Controllers ...@@ -358,7 +371,8 @@ namespace IoTSharp.Controllers
var profile = this.GetUserProfile(); var profile = this.GetUserProfile();
try try
{ {
var produce = await _context.Produces.Include(c => c.Dictionaries).SingleOrDefaultAsync(c => c.Id == dto.produceId); var produce = await _context.Produces.Include(c => c.Dictionaries)
.SingleOrDefaultAsync(c => c.Id == dto.produceId);
if (produce != null) if (produce != null)
{ {
...@@ -386,7 +400,8 @@ namespace IoTSharp.Controllers ...@@ -386,7 +400,8 @@ namespace IoTSharp.Controllers
} }
else else
{ {
var produceDictionary = await _context.ProduceDictionaries.SingleOrDefaultAsync(c => c.Id == item.Id); var produceDictionary =
await _context.ProduceDictionaries.SingleOrDefaultAsync(c => c.Id == item.Id);
if (produceDictionary != null) if (produceDictionary != null)
{ {
produceDictionary.KeyName = item.KeyName; produceDictionary.KeyName = item.KeyName;
...@@ -406,12 +421,16 @@ namespace IoTSharp.Controllers ...@@ -406,12 +421,16 @@ namespace IoTSharp.Controllers
} }
} }
var deletedic = produce.Dictionaries.Select(c => c.Id).Except(dto.ProduceDictionaryData.Select(c => c.Id)).ToList();
_context.ProduceDictionaries.RemoveRange(produce.Dictionaries.Where(c => deletedic.Any(p => p == c.Id)).ToList()); var deletedic = produce.Dictionaries.Select(c => c.Id)
.Except(dto.ProduceDictionaryData.Select(c => c.Id)).ToList();
_context.ProduceDictionaries.RemoveRange(produce.Dictionaries
.Where(c => deletedic.Any(p => p == c.Id)).ToList());
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return new ApiResult<bool>(ApiCode.Success, "Ok", true); return new ApiResult<bool>(ApiCode.Success, "Ok", true);
} }
return new ApiResult<bool>(ApiCode.CantFindObject, "Produce is not found", false); return new ApiResult<bool>(ApiCode.CantFindObject, "Produce is not found", false);
} }
catch (Exception e) catch (Exception e)
...@@ -422,6 +441,8 @@ namespace IoTSharp.Controllers ...@@ -422,6 +441,8 @@ namespace IoTSharp.Controllers
} }
} }
} }
using System;
namespace IoTSharp.Dtos
{
public class CreateDeviceByProduceDto
{
public string DeviceName { get; set; }
public Guid ProduceId { get; set; }
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册