changed device log table

This commit is contained in:
unknown
2024-10-27 09:56:23 +03:00
parent 9e1e0cb2f4
commit ce9555a5f4
5 changed files with 45 additions and 13 deletions

View File

@ -0,0 +1,7 @@
export enum SourceType {
Device = 1,
Client = 2,
ThirdParty = 3,
Cloud = 4,
Unknown = -1,
}

View File

@ -35,4 +35,7 @@ export class AddDeviceStatusDto {
@ValidateNested({ each: true }) @ValidateNested({ each: true })
@Type(() => StatusDto) @Type(() => StatusDto)
status: StatusDto[]; status: StatusDto[];
@IsOptional()
log?: any;
} }

View File

@ -150,6 +150,7 @@ export class DeviceStatusFirebaseService {
async createDeviceStatusFirebase( async createDeviceStatusFirebase(
addDeviceStatusDto: AddDeviceStatusDto, addDeviceStatusDto: AddDeviceStatusDto,
): Promise<any> { ): Promise<any> {
console.log(addDeviceStatusDto);
const dataRef = ref( const dataRef = ref(
this.firebaseDb, this.firebaseDb,
`device-status/${addDeviceStatusDto.deviceUuid}`, `device-status/${addDeviceStatusDto.deviceUuid}`,
@ -188,11 +189,14 @@ export class DeviceStatusFirebaseService {
value, value,
})); }));
const newLog = this.deviceStatusLogRepository.create({ const newLog = this.deviceStatusLogRepository.create({
deviceUuid: addDeviceStatusDto.deviceUuid, deviceId: addDeviceStatusDto.deviceUuid,
deviceTuyaUuid: addDeviceStatusDto.deviceTuyaUuid, deviceTuyaId: addDeviceStatusDto.deviceTuyaUuid,
productUuid: addDeviceStatusDto.productUuid, productId: addDeviceStatusDto.productUuid,
productType: addDeviceStatusDto.productType, log: addDeviceStatusDto.log,
status: existingData.status, code: existingData.status[0].code,
value: existingData.status[0].value,
eventId: addDeviceStatusDto.log.dataId,
eventTime: addDeviceStatusDto.log.properties[0].time,
}); });
await this.deviceStatusLogRepository.save(newLog); await this.deviceStatusLogRepository.save(newLog);

View File

@ -16,7 +16,7 @@ export class TuyaWebSocketService {
accessId: this.configService.get<string>('tuya-config.TUYA_ACCESS_ID'), accessId: this.configService.get<string>('tuya-config.TUYA_ACCESS_ID'),
accessKey: this.configService.get<string>('tuya-config.TUYA_ACCESS_KEY'), accessKey: this.configService.get<string>('tuya-config.TUYA_ACCESS_KEY'),
url: TuyaWebsocket.URL.EU, url: TuyaWebsocket.URL.EU,
env: TuyaWebsocket.env.TEST, env: TuyaWebsocket.env.PROD,
maxRetryTimes: 100, maxRetryTimes: 100,
}); });
@ -40,6 +40,7 @@ export class TuyaWebSocketService {
await this.deviceStatusFirebaseService.addDeviceStatusToFirebase({ await this.deviceStatusFirebaseService.addDeviceStatusToFirebase({
deviceTuyaUuid: message.payload.data.bizData.devId, deviceTuyaUuid: message.payload.data.bizData.devId,
status: message.payload.data.bizData.properties, status: message.payload.data.bizData.properties,
log: message.payload.data.bizData,
}); });
this.client.ackMessage(message.messageId); this.client.ackMessage(message.messageId);

View File

@ -1,26 +1,43 @@
import { SourceType } from '@app/common/constants/source-type.enum';
import { Entity, Column, PrimaryColumn, Index } from 'typeorm'; import { Entity, Column, PrimaryColumn, Index } from 'typeorm';
@Entity('device-status-log') @Entity('device-status-log')
@Index('logTime_idx', ['logTime']) @Index('logTime_idx', ['eventTime'])
export class DeviceStatusLogEntity { export class DeviceStatusLogEntity {
@PrimaryColumn() @PrimaryColumn()
id: number; id: number;
@Column({ type: 'text' })
eventId: string;
@PrimaryColumn({ type: 'timestamptz' }) @PrimaryColumn({ type: 'timestamptz' })
logTime: Date; eventTime: Date;
@Column({
type: 'enum',
enum: SourceType,
default: SourceType.Device,
})
eventFrom: SourceType;
@Column({ type: 'text' }) @Column({ type: 'text' })
deviceUuid: string; deviceId: string;
@Column({ type: 'text' }) @Column({ type: 'text' })
deviceTuyaUuid: string; deviceTuyaId: string;
@Column({ type: 'text' }) @Column({ type: 'text' })
productUuid: string; productId: string;
@Column({ type: 'text' }) @Column({ type: 'text' })
productType: string; code: any;
@Column({ type: 'text' })
value: any;
@Column({ type: 'jsonb' }) @Column({ type: 'jsonb' })
status: any; // JSON array of status codes and values log: any;
@Column({ type: 'timestamptz', default: new Date() })
ingestionTime: Date;
} }