提交 50b24fb4 编写于 作者: W wq1234wq

产品列表

上级 bc2a9d0c
......@@ -11,7 +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>
......@@ -32,8 +38,6 @@
<button nz-button type="reset" (click)="close()">取消</button>
<button nz-button nzType="primary" [disabled]="form.invalid" type="submit" [nzLoading]="submitting">保存</button>
<button nz-button nzType="primary" type="button" (click)="createcert($event)" *ngIf="data.id!=='00000000-0000-0000-0000-000000000000'&&data.identityType==='X509Certificate'" > <i nz-icon nzType="download"></i>证书生成</button>
</se>
</form>
</nz-card>
......
......@@ -32,7 +32,7 @@ export class DeviceformComponent implements OnInit {
) {}
form!: FormGroup;
submitting = false;
deviceproduce = [];
devicemodel: devicemodel[] = [];
data: deviceitem = {
......@@ -47,20 +47,26 @@ export class DeviceformComponent implements OnInit {
name: [null, [Validators.required, Validators.pattern(/^(\s+\S+\s*)*(?!\s).*$/)]],
deviceType: [null, [Validators.required]],
customerId: [null, []],
// deviceModelId: [null, []],
produceId: [null, []],
timeout: [300, []],
id: [Guid.EMPTY, []],
identityType: [Guid.EMPTY, []]
});
this._httpClient.post('api/deviceModel/index', { offset: 0, limit: 100 }).subscribe({
// this._httpClient.post('api/deviceModel/index', { offset: 0, limit: 100 }).subscribe({
// next: next => {
// this.devicemodel = next.data.rows;
// },
// error: error => {},
// complete: () => {}
// });
this._httpClient.get('api/produces/list', { offset: 0, limit: -1 }).subscribe({
next: next => {
this.devicemodel = next.data.rows;
this.deviceproduce = next.data.rows;
},
error: error => {},
complete: () => {}
});
if (this.params.id !== Guid.EMPTY) {
concat(
this._httpClient.get<appmessage<deviceitem>>('api/Devices/' + this.params.id).pipe(
......
......@@ -12,13 +12,13 @@ import { appmessage } from 'src/app/models/appmessage';
})
export class ProducedatadictionaryformComponent implements OnInit {
@Input() id: string = Guid.EMPTY;
@ViewChild('st') private st!: STComponent;
dictionaryData: STData[] = []
columns: STColumn[] = [
{ title: 'id', index: 'id' },
{ title: '字段名称', index: 'keyName', render: 'keyNameTpl' },
{ title: '字段显示名称', index: 'displayName', render: 'displayNameTpl' },
{ title: '单位', index: 'unit', render: 'unitTpl' },
......@@ -72,11 +72,19 @@ export class ProducedatadictionaryformComponent implements OnInit {
ngOnInit(): void {
this.http.get<appmessage<any>>('api/produces/getProduceDictionary?produceId=' + this.id).subscribe(next => {
this.dictionaryData = next.data;
}, error => {
this.http.get<appmessage<any>>('api/produces/getProduceDictionary?produceId=' + this.id)
.subscribe({
next: next => {
this.dictionaryData = next.data;
},
error: error => {
},
complete: () => { }
}, () => { });
});
}
private submit(i: STData): void {
......@@ -99,7 +107,21 @@ export class ProducedatadictionaryformComponent implements OnInit {
}
saveRow() {
this.http.post('api/produces/editProduceDictionary', { produceId: this.id, dictionProduceDictionaryDataaryData: this.dictionaryData }).subscribe(next => { }, error => { }, () => { });
this.http.post('api/produces/editProduceDictionary', { produceId: this.id, produceDictionaryData: this.dictionaryData }).subscribe(
{
next: next => {
if (next.code === 10000) {
this.msg.success('保存成功')
}else{
this.msg.warning('保存失败:'+next.msg)
}
},
error: error => { },
complete: () => { }
}
);
}
}
......@@ -27,8 +27,8 @@
</ng-template>
<ng-template st-row="ColumnDataTypeTpl" let-item let-index="index">
<nz-select *ngIf="item.edit" [ngModel]="item.dataType"
(ngModelChange)="st.setRow(index, { dataType: $event })">
<nz-select *ngIf="item.edit" [ngModel]="item.type"
(ngModelChange)="st.setRow(index, { type: $event })">
<nz-option nzValue="Boolean" nzLabel="Boolean"></nz-option>
<nz-option nzValue="String" nzLabel="String"></nz-option>
<nz-option nzValue="Long" nzLabel="Long"></nz-option>
......@@ -39,7 +39,7 @@
<nz-option nzValue="DateTime" nzLabel="DateTime"></nz-option>
</nz-select>
<ng-container *ngIf="!item.edit">{{ item.dataType}}</ng-container>
<ng-container *ngIf="!item.edit">{{ item.type}}</ng-container>
</ng-template>
......
......@@ -19,7 +19,7 @@ export class ProducedataformComponent implements OnInit {
columns: STColumn[] = [
{ title: 'KeyName', index: 'keyName', render: 'ColumnTitleTpl' },
{ title: '数据侧', index: 'dataSide', render: 'ColumnTypeTpl' },
{ title: '数据类型', index: 'dataType', render: 'ColumnDataTypeTpl' },
{ title: '数据类型', index: 'type', render: 'ColumnDataTypeTpl' },
{
title: '操作',
buttons: [
......@@ -88,7 +88,12 @@ export class ProducedataformComponent implements OnInit {
}
saveRow() {
this.http.post('api/produces/editProduceData', { produceId: this.id, produceData: this.produceData }).subscribe(next => { }, error => { }, () => { });
this.http.post('api/produces/editProduceData', { produceId: this.id, produceData: this.produceData }).subscribe(next => {
if (next.code === 10000) {
this.msg.success('保存成功')
}else{
this.msg.warning('保存失败:'+next.msg)
}}, error => { }, () => { });
}
......
......@@ -81,29 +81,44 @@ export class ProduceformComponent implements OnInit {
}
if (this.id == Guid.EMPTY) {
this._httpClient.post('api/produces/save', this.form.value).subscribe(
() => {
this.submitting = false;
this.msg.create('success', '产品新增成功');
this.close();
},
() => {
this.msg.create('error', '产品新增失败');
this.close();
},
() => { }
{
next: next => {
this.submitting = false;
if (next.code === 10000) {
this.msg.create('success', '产品新增成功');
this.close();
}
},
error: error => {
this.msg.create('error', '产品新增失败');
this.close();
},
complete: () => { }
}
);
} else {
this._httpClient.put('api/produces/update', this.form.value).subscribe(
() => {
this.submitting = false;
this.msg.create('success', '产品修改成功');
this.close();
},
() => {
this.msg.create('error', '产品修改失败');
this.close();
},
() => { }
{
next: next => {
this.submitting = false;
if (next.code === 10000) {
this.msg.create('success', '产品修改成功');
this.close();
}
},
error: error => {
this.msg.create('error', '产品修改失败');
this.close();
},
complete: () => { }
}
);
}
}
......
......@@ -35,8 +35,14 @@
<span>{{ 'button.new' | translate }}</span>
</button>-->
<st #st [columns]="columns" [data]="url" ps="20" [page]="page" [req]="req" [res]="res">
<st #st [columns]="columns" [data]="url" ps="20" [page]="page" [req]="req" [res]="res" [expand]="expand" expandAccordion (change)="onchange($event)">
<ng-template #expand let-item let-index="index" let-column="column">
<st [data]="item.devices" [columns]="devicecolumns" >
</st>
</ng-template>
</st>
</nz-card>
</page-header>
import { ChangeDetectorRef, Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { STPage, STReq, STRes, STComponent, STColumn, STData } from '@delon/abc/st';
import { STPage, STReq, STRes, STComponent, STColumn, STData, STChange, STColumnTag, STColumnBadge } from '@delon/abc/st';
import { ModalHelper, SettingsService, _HttpClient } from '@delon/theme';
import { Guid } from 'guid-typescript';
import { NzDrawerService } from 'ng-zorro-antd/drawer';
......@@ -78,6 +78,36 @@ export class ProducelistComponent implements OnInit {
list: 'data.rows'
}
};
BADGE: STColumnBadge = {
true: { text: '在线', color: 'success' },
false: { text: '离线', color: 'error' }
};
TAG: STColumnTag = {
AccessToken: { text: 'AccessToken', color: 'green' },
X509Certificate: { text: 'X509Certificate', color: 'blue' }
};
DeviceTAG: STColumnTag = {
Device: { text: '设备', color: 'green' },
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 })
st!: STComponent;
......@@ -110,14 +140,14 @@ export class ProducelistComponent implements OnInit {
},
{
text: '属性',
// i18n: 'common.edit',
// i18n: 'common.edit',
acl: 56,
click: (item: any) => {
this.editattr(item.id);
}
}, {
}, {
text: '字典',
// i18n: 'common.edit',
// i18n: 'common.edit',
acl: 56,
click: (item: any) => {
this.editdic(item.id);
......@@ -141,7 +171,7 @@ export class ProducelistComponent implements OnInit {
selectedRows: STData[] = [];
ngOnInit() {
}
openComponent(id: string): void {
var { nzMaskClosable, width } = this.settingService.getData('drawerconfig');
......@@ -169,7 +199,7 @@ export class ProducelistComponent implements OnInit {
editattr(id: string): void {
var { nzMaskClosable, width } = this.settingService.getData('drawerconfig');
var title = '属性编辑' ;
var title = '属性编辑';
const drawerRef = this.drawerService.create<ProducedataformComponent, { id: string }, string>({
nzTitle: title,
nzContent: ProducedataformComponent,
......@@ -189,14 +219,45 @@ export class ProducelistComponent implements OnInit {
this.getData();
});
}
onchange($events: STChange): void {
switch ($events.type) {
case 'expand':
if ($events.expand.expand) {
}
break;
}
}
getdevices() {
this.http.post('', {}).subscribe({
next: next => {
}, error: error => {
}, complete: () => {
}
})
}
editdic(id: string): void {
var { nzMaskClosable, width } = this.settingService.getData('drawerconfig');
var title ='字典编辑';
var title = '字典编辑';
const drawerRef = this.drawerService.create<ProducedatadictionaryformComponent, { id: string }, string>({
nzTitle: title,
nzContent: ProducedatadictionaryformComponent,
......
......@@ -51,20 +51,44 @@ namespace IoTSharp.Controllers
condition = condition.And(x => x.Name.Contains(m.Name));
}
return new ApiResult<PagedData<ProduceDto>>(ApiCode.Success, "OK", new PagedData<ProduceDto>
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)
.ToList().Select(c => new ProduceDto
{
Id = c.Id,
DefaultIdentityType = c.DefaultIdentityType,
DefaultTimeout = c.DefaultTimeout,
Description = c.Description,
Name = c.Name, Devices = c.Devices
}).ToList()
});
}
else
{
total = await _context.Produces.CountAsync(condition),
rows = _context.Produces.Where(condition).Where(condition).Skip((m.offset) * m.limit).Take(m.limit)
.ToList().Select(c => new ProduceDto
{
Id = c.Id,
DefaultIdentityType = c.DefaultIdentityType,
DefaultTimeout = c.DefaultTimeout,
Description = c.Description,
Name = c.Name
}).ToList()
return new ApiResult<PagedData<ProduceDto>>(ApiCode.Success, "OK", new PagedData<ProduceDto>
{
total = await _context.Produces.CountAsync(),
rows = _context.Produces.Where(condition)
.ToList().Select(c => new ProduceDto
{
Id = c.Id,
DefaultIdentityType = c.DefaultIdentityType,
DefaultTimeout = c.DefaultTimeout,
Description = c.Description,
Name = c.Name
}).ToList()
});
}
});
}
......@@ -95,9 +119,7 @@ namespace IoTSharp.Controllers
{
return new ApiResult<ProduceAddDto>(ApiCode.Success, "OK", new ProduceAddDto
{
Id = result.Id,
Icon = result.Icon,
DefaultDeviceType = result.DefaultDeviceType,
DefaultIdentityType = result.DefaultIdentityType,
......@@ -238,9 +260,6 @@ namespace IoTSharp.Controllers
var result = _context.DataStorage.Where(c => c.DeviceId == Guid.Empty).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);
......@@ -263,14 +282,12 @@ namespace IoTSharp.Controllers
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);
var pds = _context.ProduceDatas.Where(c => c.Owner == produce).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();
foreach (var item in data)
{
var pd = pds.FirstOrDefault(c => c.KeyName.ToLower() == item.KeyName.ToLower());
if (pd != null)
{
......@@ -369,29 +386,31 @@ namespace IoTSharp.Controllers
}
else
{
var produceDictionary=await _context.ProduceDictionaries.SingleOrDefaultAsync(c => c.Id == item.Id);
if (produceDictionary != null)
{
produceDictionary.KeyName = item.KeyName;
produceDictionary.DataType = item.DataType;
produceDictionary.Customer = profile.Customer;
produceDictionary.DefaultValue = item.DefaultValue;
produceDictionary.Display = item.Display;
produceDictionary.DisplayName = item.DisplayName;
produceDictionary.KeyDesc = item.KeyDesc;
produceDictionary.Tag = item.Tag;
produceDictionary.UnitConvert = item.UnitConvert;
produceDictionary.Unit = item.Unit;
produceDictionary.UnitExpression = item.UnitExpression;
_context.ProduceDictionaries.Update(produceDictionary);
var produceDictionary = await _context.ProduceDictionaries.SingleOrDefaultAsync(c => c.Id == item.Id);
if (produceDictionary != null)
{
produceDictionary.KeyName = item.KeyName;
produceDictionary.DataType = item.DataType;
produceDictionary.Customer = profile.Customer;
produceDictionary.DefaultValue = item.DefaultValue;
produceDictionary.Display = item.Display;
produceDictionary.DisplayName = item.DisplayName;
produceDictionary.KeyDesc = item.KeyDesc;
produceDictionary.Tag = item.Tag;
produceDictionary.UnitConvert = item.UnitConvert;
produceDictionary.Unit = item.Unit;
produceDictionary.UnitExpression = item.UnitExpression;
_context.ProduceDictionaries.Update(produceDictionary);
await _context.SaveChangesAsync();
}
}
}
_context.Produces.Update(produce);
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);
}
......@@ -403,6 +422,6 @@ namespace IoTSharp.Controllers
}
}
}
......@@ -21,5 +21,8 @@ namespace IoTSharp.Dtos
public IdentityType DefaultIdentityType { get; set; } = IdentityType.AccessToken;
public string Description { get; set; }
public List<Device> Devices { get; set; }
}
}
......@@ -57,6 +57,7 @@ namespace IoTSharp.Controllers.Models
public bool OnlyActive { get; set; }
public string Name { get; set; }
}
public class RulePageParam : IPageParam
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册