提交 e05f4c4e 编写于 作者: W wq1234wq

设备创建

上级 50b24fb4
......@@ -11,13 +11,13 @@
<nz-option nzValue="Gateway" nzLabel="网关"></nz-option>
</nz-select>
</se>
<!--
<se label="所属产品" error="所属产品" >
<nz-select formControlName="produceId" placeholder="所属产品" >
<nz-option *ngFor="let o of deviceproduce" [nzValue]="o.id" [nzLabel]="o.name"></nz-option>
</nz-select>
</se>
-->
<se label="超时" error="超时" required>
<nz-input-number formControlName="timeout" [nzMin]="0" [nzStep]="1"></nz-input-number>
</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 { SharedModule } from '@shared';
import { CreatedeviceformComponent } from './createdeviceform/createdeviceform.component';
import { ProduceRoutingModule } from './produce-routing.module';
import { ProducedatadictionaryformComponent } from './producedatadictionaryform/producedatadictionaryform.component';
import { ProducedataformComponent } from './producedataform/producedataform.component';
const COMPONENTS = [
ProducedataformComponent,ProducedatadictionaryformComponent
ProducedataformComponent,ProducedatadictionaryformComponent,CreatedeviceformComponent
];
@NgModule({
......
......@@ -20,21 +20,17 @@
</nz-select>
</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"
style="width: 100%; height: 500px; padding-top: 1rem" class="editor"
[nzEditorOption]="{ theme: 'vs',language: 'json' }">
</nz-code-editor>
</se>
<se label="默认网关类型" error="默认网关类型" *ngIf="this.form.value.gatewayType!=='Unknow'&&this.form.value.gatewayType!=='Customize'">
<input nz-input formControlName="gatewayConfigurationName" placeholder="名称" />
<se label="默认网关配置名称" error="默认网关配置名称" *ngIf="this.form.value.gatewayType!=='Unknow'&&this.form.value.gatewayType!=='Customize'">
<input nz-input formControlName="gatewayConfigurationName" placeholder="默认网关配置名称" />
</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="Gateway" nzLabel="Gateway"></nz-option>
</nz-select>
......
......@@ -6,6 +6,7 @@ import { Guid } from 'guid-typescript';
import { NzDrawerService } from 'ng-zorro-antd/drawer';
import { NzMessageService } from 'ng-zorro-antd/message';
import { appmessage } from 'src/app/models/appmessage';
import { CreatedeviceformComponent } from '../createdeviceform/createdeviceform.component';
import { ProducedatadictionaryformComponent } from '../producedatadictionaryform/producedatadictionaryform.component';
import { ProducedataformComponent } from '../producedataform/producedataform.component';
import { ProduceformComponent } from '../produceform/produceform.component';
......@@ -92,21 +93,16 @@ export class ProducelistComponent implements OnInit {
Gateway: { text: '网关', color: 'blue' }
};
devicecolumns:STColumn[] = [
{ title: 'id', index: 'id', },
{title: '名称',
index: 'name',
render: 'name',
type: 'link',
},
{ title: '设备类型', index: 'deviceType', type: 'tag', tag: this.DeviceTAG },
{ title: '在线状态', index: 'active', type: 'badge', badge: this.BADGE, sort: true },
{ title: '最后活动时间', index: 'lastActivityDateTime', type: 'date' },
{ title: '认证方式', index: 'identityType', type: 'tag', tag: this.TAG},
]
@ViewChild('st', { static: true })
......@@ -153,6 +149,13 @@ export class ProducelistComponent implements OnInit {
this.editdic(item.id);
}
},
{
text: '创建设备',
acl: 56,
click: (item: any) => {
this.createdevice(item.id);
}
},
{
text: '删除',
pop: {
......@@ -173,6 +176,24 @@ export class ProducelistComponent implements OnInit {
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 {
var { nzMaskClosable, width } = this.settingService.getData('drawerconfig');
var title = id == Guid.EMPTY ? '新增产品' : '修改产品';
......@@ -203,7 +224,7 @@ export class ProducelistComponent implements OnInit {
const drawerRef = this.drawerService.create<ProducedataformComponent, { id: string }, string>({
nzTitle: title,
nzContent: ProducedataformComponent,
nzWidth: width,
nzWidth: '80%',
nzMaskClosable: nzMaskClosable,
nzContentParams: {
id: id
......
......@@ -53,11 +53,12 @@ namespace IoTSharp.Controllers
if (m.limit > 1)
{
{
return new ApiResult<PagedData<ProduceDto>>(ApiCode.Success, "OK", new PagedData<ProduceDto>
{
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
{
Id = c.Id,
......@@ -88,7 +89,7 @@ namespace IoTSharp.Controllers
});
}
}
......@@ -249,19 +250,20 @@ namespace IoTSharp.Controllers
[HttpGet]
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);
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();
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
{ 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.CantFindObject, "Produce is not found", null);
}
......@@ -279,13 +281,18 @@ namespace IoTSharp.Controllers
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)
{
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)
{
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)
{
var pd = pds.FirstOrDefault(c => c.KeyName.ToLower() == item.KeyName.ToLower());
......@@ -297,15 +304,18 @@ namespace IoTSharp.Controllers
}
else
{
item.DeviceId = dto.produceId;
_context.ProduceDatas.Add(item);
}
}
await _context.SaveChangesAsync();
var delete_keynames = pds.Select(c => c.KeyName.ToLower())
.Except(dto.ProduceData.Select(c => c.KeyName.ToLower())).ToArray();
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);
await _context.SaveChangesAsync();
......@@ -313,8 +323,10 @@ namespace IoTSharp.Controllers
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 is not found", false);
}
catch (Exception e)
......@@ -341,6 +353,7 @@ namespace IoTSharp.Controllers
{
return new ApiResult<List<ProduceDictionary>>(ApiCode.Success, "Ok", produce.Dictionaries);
}
return new ApiResult<List<ProduceDictionary>>(ApiCode.CantFindObject, "Produce is not found", null);
}
......@@ -358,7 +371,8 @@ namespace IoTSharp.Controllers
var profile = this.GetUserProfile();
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)
{
......@@ -386,7 +400,8 @@ namespace IoTSharp.Controllers
}
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)
{
produceDictionary.KeyName = item.KeyName;
......@@ -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();
return new ApiResult<bool>(ApiCode.Success, "Ok", true);
}
return new ApiResult<bool>(ApiCode.CantFindObject, "Produce is not found", false);
}
catch (Exception e)
......@@ -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.
先完成此消息的编辑!
想要评论请 注册