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 })
@Type(() => StatusDto)
status: StatusDto[];
@IsOptional()
log?: any;
}

View File

@ -150,6 +150,7 @@ export class DeviceStatusFirebaseService {
async createDeviceStatusFirebase(
addDeviceStatusDto: AddDeviceStatusDto,
): Promise<any> {
console.log(addDeviceStatusDto);
const dataRef = ref(
this.firebaseDb,
`device-status/${addDeviceStatusDto.deviceUuid}`,
@ -188,11 +189,14 @@ export class DeviceStatusFirebaseService {
value,
}));
const newLog = this.deviceStatusLogRepository.create({
deviceUuid: addDeviceStatusDto.deviceUuid,
deviceTuyaUuid: addDeviceStatusDto.deviceTuyaUuid,
productUuid: addDeviceStatusDto.productUuid,
productType: addDeviceStatusDto.productType,
status: existingData.status,
deviceId: addDeviceStatusDto.deviceUuid,
deviceTuyaId: addDeviceStatusDto.deviceTuyaUuid,
productId: addDeviceStatusDto.productUuid,
log: addDeviceStatusDto.log,
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);

View File

@ -16,7 +16,7 @@ export class TuyaWebSocketService {
accessId: this.configService.get<string>('tuya-config.TUYA_ACCESS_ID'),
accessKey: this.configService.get<string>('tuya-config.TUYA_ACCESS_KEY'),
url: TuyaWebsocket.URL.EU,
env: TuyaWebsocket.env.TEST,
env: TuyaWebsocket.env.PROD,
maxRetryTimes: 100,
});
@ -40,6 +40,7 @@ export class TuyaWebSocketService {
await this.deviceStatusFirebaseService.addDeviceStatusToFirebase({
deviceTuyaUuid: message.payload.data.bizData.devId,
status: message.payload.data.bizData.properties,
log: message.payload.data.bizData,
});
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';
@Entity('device-status-log')
@Index('logTime_idx', ['logTime'])
@Index('logTime_idx', ['eventTime'])
export class DeviceStatusLogEntity {
@PrimaryColumn()
id: number;
@Column({ type: 'text' })
eventId: string;
@PrimaryColumn({ type: 'timestamptz' })
logTime: Date;
eventTime: Date;
@Column({
type: 'enum',
enum: SourceType,
default: SourceType.Device,
})
eventFrom: SourceType;
@Column({ type: 'text' })
deviceUuid: string;
deviceId: string;
@Column({ type: 'text' })
deviceTuyaUuid: string;
deviceTuyaId: string;
@Column({ type: 'text' })
productUuid: string;
productId: string;
@Column({ type: 'text' })
productType: string;
code: any;
@Column({ type: 'text' })
value: any;
@Column({ type: 'jsonb' })
status: any; // JSON array of status codes and values
log: any;
@Column({ type: 'timestamptz', default: new Date() })
ingestionTime: Date;
}