mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 18:56:22 +00:00
changed device log table
This commit is contained in:
7
libs/common/src/constants/source-type.enum.ts
Normal file
7
libs/common/src/constants/source-type.enum.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export enum SourceType {
|
||||
Device = 1,
|
||||
Client = 2,
|
||||
ThirdParty = 3,
|
||||
Cloud = 4,
|
||||
Unknown = -1,
|
||||
}
|
@ -35,4 +35,7 @@ export class AddDeviceStatusDto {
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => StatusDto)
|
||||
status: StatusDto[];
|
||||
|
||||
@IsOptional()
|
||||
log?: any;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user