From e05f4c4eef0db94702a120ca13ba90e4ab014c98 Mon Sep 17 00:00:00 2001 From: wq1234wq Date: Fri, 14 Oct 2022 23:59:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../deviceform/deviceform.component.html | 4 +- .../createdeviceform.component.html | 18 +++++++ .../createdeviceform.component.less | 0 .../createdeviceform.component.spec.ts | 25 +++++++++ .../createdeviceform.component.ts | 44 ++++++++++++++++ .../src/app/routes/produce/produce.module.ts | 3 +- .../produceform/produceform.component.html | 14 ++--- .../producelist/producelist.component.ts | 33 +++++++++--- IoTSharp/Controllers/ProducesController.cs | 51 +++++++++++++------ IoTSharp/Dtos/CreateDeviceByProduceDto.cs | 11 ++++ 10 files changed, 170 insertions(+), 33 deletions(-) create mode 100644 IoTSharp/ClientApp/src/app/routes/produce/createdeviceform/createdeviceform.component.html create mode 100644 IoTSharp/ClientApp/src/app/routes/produce/createdeviceform/createdeviceform.component.less create mode 100644 IoTSharp/ClientApp/src/app/routes/produce/createdeviceform/createdeviceform.component.spec.ts create mode 100644 IoTSharp/ClientApp/src/app/routes/produce/createdeviceform/createdeviceform.component.ts create mode 100644 IoTSharp/Dtos/CreateDeviceByProduceDto.cs diff --git a/IoTSharp/ClientApp/src/app/routes/devices/deviceform/deviceform.component.html b/IoTSharp/ClientApp/src/app/routes/devices/deviceform/deviceform.component.html index ea66ea73..3c43ffb4 100644 --- a/IoTSharp/ClientApp/src/app/routes/devices/deviceform/deviceform.component.html +++ b/IoTSharp/ClientApp/src/app/routes/devices/deviceform/deviceform.component.html @@ -11,13 +11,13 @@ - + diff --git a/IoTSharp/ClientApp/src/app/routes/produce/createdeviceform/createdeviceform.component.html b/IoTSharp/ClientApp/src/app/routes/produce/createdeviceform/createdeviceform.component.html new file mode 100644 index 00000000..5543d2bc --- /dev/null +++ b/IoTSharp/ClientApp/src/app/routes/produce/createdeviceform/createdeviceform.component.html @@ -0,0 +1,18 @@ + + +
+ + + + + + + +
+ diff --git a/IoTSharp/ClientApp/src/app/routes/produce/createdeviceform/createdeviceform.component.less b/IoTSharp/ClientApp/src/app/routes/produce/createdeviceform/createdeviceform.component.less new file mode 100644 index 00000000..e69de29b diff --git a/IoTSharp/ClientApp/src/app/routes/produce/createdeviceform/createdeviceform.component.spec.ts b/IoTSharp/ClientApp/src/app/routes/produce/createdeviceform/createdeviceform.component.spec.ts new file mode 100644 index 00000000..9c01aacb --- /dev/null +++ b/IoTSharp/ClientApp/src/app/routes/produce/createdeviceform/createdeviceform.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CreatedeviceformComponent } from './createdeviceform.component'; + +describe('CreatedeviceformComponent', () => { + let component: CreatedeviceformComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ CreatedeviceformComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(CreatedeviceformComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/IoTSharp/ClientApp/src/app/routes/produce/createdeviceform/createdeviceform.component.ts b/IoTSharp/ClientApp/src/app/routes/produce/createdeviceform/createdeviceform.component.ts new file mode 100644 index 00000000..c082890f --- /dev/null +++ b/IoTSharp/ClientApp/src/app/routes/produce/createdeviceform/createdeviceform.component.ts @@ -0,0 +1,44 @@ +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(); + } +} diff --git a/IoTSharp/ClientApp/src/app/routes/produce/produce.module.ts b/IoTSharp/ClientApp/src/app/routes/produce/produce.module.ts index d7b616cb..d92d4bf5 100644 --- a/IoTSharp/ClientApp/src/app/routes/produce/produce.module.ts +++ b/IoTSharp/ClientApp/src/app/routes/produce/produce.module.ts @@ -1,12 +1,13 @@ 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({ diff --git a/IoTSharp/ClientApp/src/app/routes/produce/produceform/produceform.component.html b/IoTSharp/ClientApp/src/app/routes/produce/produceform/produceform.component.html index b902b552..9dcb7f38 100644 --- a/IoTSharp/ClientApp/src/app/routes/produce/produceform/produceform.component.html +++ b/IoTSharp/ClientApp/src/app/routes/produce/produceform/produceform.component.html @@ -20,21 +20,17 @@ - + - - + + - - - - - - + + diff --git a/IoTSharp/ClientApp/src/app/routes/produce/producelist/producelist.component.ts b/IoTSharp/ClientApp/src/app/routes/produce/producelist/producelist.component.ts index 1620da04..381cb781 100644 --- a/IoTSharp/ClientApp/src/app/routes/produce/producelist/producelist.component.ts +++ b/IoTSharp/ClientApp/src/app/routes/produce/producelist/producelist.component.ts @@ -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({ nzTitle: title, nzContent: ProducedataformComponent, - nzWidth: width, + nzWidth: '80%', nzMaskClosable: nzMaskClosable, nzContentParams: { id: id diff --git a/IoTSharp/Controllers/ProducesController.cs b/IoTSharp/Controllers/ProducesController.cs index ef4385ef..6bdc3be0 100644 --- a/IoTSharp/Controllers/ProducesController.cs +++ b/IoTSharp/Controllers/ProducesController.cs @@ -53,11 +53,12 @@ namespace IoTSharp.Controllers if (m.limit > 1) - { + { return new ApiResult>(ApiCode.Success, "OK", new PagedData { 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>> 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>(ApiCode.Success, "Ok", result); } + return new ApiResult>(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(ApiCode.Success, "Ok", true); } + return new ApiResult(ApiCode.CantFindObject, "Produce data is not found", false); } + return new ApiResult(ApiCode.CantFindObject, "Produce is not found", false); } catch (Exception e) @@ -341,6 +353,7 @@ namespace IoTSharp.Controllers { return new ApiResult>(ApiCode.Success, "Ok", produce.Dictionaries); } + return new ApiResult>(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(ApiCode.Success, "Ok", true); } + return new ApiResult(ApiCode.CantFindObject, "Produce is not found", false); } catch (Exception e) @@ -422,6 +441,8 @@ namespace IoTSharp.Controllers } - + + + } } diff --git a/IoTSharp/Dtos/CreateDeviceByProduceDto.cs b/IoTSharp/Dtos/CreateDeviceByProduceDto.cs new file mode 100644 index 00000000..5e4e5836 --- /dev/null +++ b/IoTSharp/Dtos/CreateDeviceByProduceDto.cs @@ -0,0 +1,11 @@ +using System; + +namespace IoTSharp.Dtos +{ + public class CreateDeviceByProduceDto + { + public string DeviceName { get; set; } + + public Guid ProduceId { get; set; } + } +} -- GitLab