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 ea66ea73be3681537ec48ac7401db6521ddfcfd0..3c43ffb4b5330a97167e59e7e591cfba81a512b8 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 0000000000000000000000000000000000000000..5543d2bca82dcf7871939a9c0003bcaed29d7a24 --- /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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 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 0000000000000000000000000000000000000000..9c01aacb93e0b3c4f506342c6e8a5067de64155c --- /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 0000000000000000000000000000000000000000..c082890fc365eafff58e396dd3063c854a5b643e --- /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 d7b616cb89584b173e9606b6b7a24f7904c73013..d92d4bf516d01d1b52e86e1a6de71974f712f7ef 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 b902b552dc6ce37803797eac5fc543355adcf604..9dcb7f38dd4ad3ea362b95780e1d2a94f6108438 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 1620da045fa452cba64610b29873c07c5835a9df..381cb7818526ef90353fccd6eaeaf62f0d4de6cd 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 ef4385ef9b41884583eda3d9a07ea00b23bb41cd..6bdc3be00d3c9eb92f9e922fd3535210898741ae 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 0000000000000000000000000000000000000000..5e4e58366fde1fb741df0a419b6768b4cc8c2649 --- /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; } + } +}