mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 09:24:54 +00:00
Merge pull request #367 from SyncrowIOT/add-space-presence-sensor-detection-entity
refactor: rename presence sensor entities and update related references
This commit is contained in:
@ -51,7 +51,10 @@ import {
|
|||||||
PowerClampHourlyEntity,
|
PowerClampHourlyEntity,
|
||||||
PowerClampMonthlyEntity,
|
PowerClampMonthlyEntity,
|
||||||
} from '../modules/power-clamp/entities/power-clamp.entity';
|
} from '../modules/power-clamp/entities/power-clamp.entity';
|
||||||
import { PresenceSensorDailyEntity } from '../modules/presence-sensor/entities';
|
import {
|
||||||
|
PresenceSensorDailyDeviceEntity,
|
||||||
|
PresenceSensorDailySpaceEntity,
|
||||||
|
} from '../modules/presence-sensor/entities';
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forRootAsync({
|
TypeOrmModule.forRootAsync({
|
||||||
@ -110,7 +113,8 @@ import { PresenceSensorDailyEntity } from '../modules/presence-sensor/entities';
|
|||||||
PowerClampHourlyEntity,
|
PowerClampHourlyEntity,
|
||||||
PowerClampDailyEntity,
|
PowerClampDailyEntity,
|
||||||
PowerClampMonthlyEntity,
|
PowerClampMonthlyEntity,
|
||||||
PresenceSensorDailyEntity,
|
PresenceSensorDailyDeviceEntity,
|
||||||
|
PresenceSensorDailySpaceEntity,
|
||||||
],
|
],
|
||||||
namingStrategy: new SnakeNamingStrategy(),
|
namingStrategy: new SnakeNamingStrategy(),
|
||||||
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import { SpaceEntity } from '../../space/entities/space.entity';
|
|||||||
import { SubspaceEntity } from '../../space/entities/subspace/subspace.entity';
|
import { SubspaceEntity } from '../../space/entities/subspace/subspace.entity';
|
||||||
import { NewTagEntity } from '../../tag';
|
import { NewTagEntity } from '../../tag';
|
||||||
import { PowerClampHourlyEntity } from '../../power-clamp/entities/power-clamp.entity';
|
import { PowerClampHourlyEntity } from '../../power-clamp/entities/power-clamp.entity';
|
||||||
import { PresenceSensorDailyEntity } from '../../presence-sensor/entities';
|
import { PresenceSensorDailyDeviceEntity } from '../../presence-sensor/entities';
|
||||||
|
|
||||||
@Entity({ name: 'device' })
|
@Entity({ name: 'device' })
|
||||||
@Unique(['deviceTuyaUuid'])
|
@Unique(['deviceTuyaUuid'])
|
||||||
@ -83,8 +83,8 @@ export class DeviceEntity extends AbstractEntity<DeviceDto> {
|
|||||||
public tag: NewTagEntity;
|
public tag: NewTagEntity;
|
||||||
@OneToMany(() => PowerClampHourlyEntity, (powerClamp) => powerClamp.device)
|
@OneToMany(() => PowerClampHourlyEntity, (powerClamp) => powerClamp.device)
|
||||||
powerClampHourly: PowerClampHourlyEntity[];
|
powerClampHourly: PowerClampHourlyEntity[];
|
||||||
@OneToMany(() => PresenceSensorDailyEntity, (sensor) => sensor.device)
|
@OneToMany(() => PresenceSensorDailyDeviceEntity, (sensor) => sensor.device)
|
||||||
presenceSensorDaily: PresenceSensorDailyEntity[];
|
presenceSensorDaily: PresenceSensorDailyDeviceEntity[];
|
||||||
constructor(partial: Partial<DeviceEntity>) {
|
constructor(partial: Partial<DeviceEntity>) {
|
||||||
super();
|
super();
|
||||||
Object.assign(this, partial);
|
Object.assign(this, partial);
|
||||||
|
|||||||
@ -2,10 +2,11 @@ import { Column, Entity, ManyToOne, Unique } from 'typeorm';
|
|||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
import { PresenceSensorDto } from '../dtos';
|
import { PresenceSensorDto } from '../dtos';
|
||||||
import { DeviceEntity } from '../../device/entities/device.entity';
|
import { DeviceEntity } from '../../device/entities/device.entity';
|
||||||
|
import { SpaceEntity } from '../../space/entities/space.entity';
|
||||||
|
|
||||||
@Entity({ name: 'presence-sensor-daily-detection' })
|
@Entity({ name: 'presence-sensor-daily-device-detection' })
|
||||||
@Unique(['deviceUuid', 'eventDate'])
|
@Unique(['deviceUuid', 'eventDate'])
|
||||||
export class PresenceSensorDailyEntity extends AbstractEntity<PresenceSensorDto> {
|
export class PresenceSensorDailyDeviceEntity extends AbstractEntity<PresenceSensorDto> {
|
||||||
@Column({ nullable: false })
|
@Column({ nullable: false })
|
||||||
public deviceUuid: string;
|
public deviceUuid: string;
|
||||||
|
|
||||||
@ -24,7 +25,33 @@ export class PresenceSensorDailyEntity extends AbstractEntity<PresenceSensorDto>
|
|||||||
@ManyToOne(() => DeviceEntity, (device) => device.presenceSensorDaily)
|
@ManyToOne(() => DeviceEntity, (device) => device.presenceSensorDaily)
|
||||||
device: DeviceEntity;
|
device: DeviceEntity;
|
||||||
|
|
||||||
constructor(partial: Partial<PresenceSensorDailyEntity>) {
|
constructor(partial: Partial<PresenceSensorDailyDeviceEntity>) {
|
||||||
|
super();
|
||||||
|
Object.assign(this, partial);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Entity({ name: 'presence-sensor-daily-space-detection' })
|
||||||
|
@Unique(['spaceUuid', 'eventDate'])
|
||||||
|
export class PresenceSensorDailySpaceEntity extends AbstractEntity<PresenceSensorDto> {
|
||||||
|
@Column({ nullable: false })
|
||||||
|
public spaceUuid: string;
|
||||||
|
|
||||||
|
@Column({ nullable: false, type: 'date' })
|
||||||
|
public eventDate: string;
|
||||||
|
|
||||||
|
@Column({ nullable: false })
|
||||||
|
public CountMotionDetected: number;
|
||||||
|
|
||||||
|
@Column({ nullable: false })
|
||||||
|
public CountPresenceDetected: number;
|
||||||
|
|
||||||
|
@Column({ nullable: false })
|
||||||
|
public CountTotalPresenceDetected: number;
|
||||||
|
|
||||||
|
@ManyToOne(() => SpaceEntity, (space) => space.presenceSensorDaily)
|
||||||
|
space: SpaceEntity;
|
||||||
|
|
||||||
|
constructor(partial: Partial<PresenceSensorDailySpaceEntity>) {
|
||||||
super();
|
super();
|
||||||
Object.assign(this, partial);
|
Object.assign(this, partial);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,19 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { PresenceSensorDailyEntity } from './entities/presence-sensor.entity';
|
import {
|
||||||
|
PresenceSensorDailyDeviceEntity,
|
||||||
|
PresenceSensorDailySpaceEntity,
|
||||||
|
} from './entities/presence-sensor.entity';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [],
|
providers: [],
|
||||||
exports: [],
|
exports: [],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
imports: [TypeOrmModule.forFeature([PresenceSensorDailyEntity])],
|
imports: [
|
||||||
|
TypeOrmModule.forFeature([
|
||||||
|
PresenceSensorDailyDeviceEntity,
|
||||||
|
PresenceSensorDailySpaceEntity,
|
||||||
|
]),
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class PresenceSensorRepositoryModule {}
|
export class PresenceSensorRepositoryModule {}
|
||||||
|
|||||||
@ -1,10 +1,19 @@
|
|||||||
import { DataSource, Repository } from 'typeorm';
|
import { DataSource, Repository } from 'typeorm';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { PresenceSensorDailyEntity } from '../entities';
|
import {
|
||||||
|
PresenceSensorDailyDeviceEntity,
|
||||||
|
PresenceSensorDailySpaceEntity,
|
||||||
|
} from '../entities';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PresenceSensorDailyRepository extends Repository<PresenceSensorDailyEntity> {
|
export class PresenceSensorDailyDeviceRepository extends Repository<PresenceSensorDailyDeviceEntity> {
|
||||||
constructor(private dataSource: DataSource) {
|
constructor(private dataSource: DataSource) {
|
||||||
super(PresenceSensorDailyEntity, dataSource.createEntityManager());
|
super(PresenceSensorDailyDeviceEntity, dataSource.createEntityManager());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Injectable()
|
||||||
|
export class PresenceSensorDailySpaceRepository extends Repository<PresenceSensorDailySpaceEntity> {
|
||||||
|
constructor(private dataSource: DataSource) {
|
||||||
|
super(PresenceSensorDailySpaceEntity, dataSource.createEntityManager());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import { SpaceModelEntity } from '../../space-model';
|
|||||||
import { InviteUserSpaceEntity } from '../../Invite-user/entities';
|
import { InviteUserSpaceEntity } from '../../Invite-user/entities';
|
||||||
import { SpaceProductAllocationEntity } from './space-product-allocation.entity';
|
import { SpaceProductAllocationEntity } from './space-product-allocation.entity';
|
||||||
import { SubspaceEntity } from './subspace/subspace.entity';
|
import { SubspaceEntity } from './subspace/subspace.entity';
|
||||||
|
import { PresenceSensorDailySpaceEntity } from '../../presence-sensor/entities';
|
||||||
|
|
||||||
@Entity({ name: 'space' })
|
@Entity({ name: 'space' })
|
||||||
export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||||
@ -111,6 +112,9 @@ export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
|||||||
)
|
)
|
||||||
public productAllocations: SpaceProductAllocationEntity[];
|
public productAllocations: SpaceProductAllocationEntity[];
|
||||||
|
|
||||||
|
@OneToMany(() => PresenceSensorDailySpaceEntity, (sensor) => sensor.space)
|
||||||
|
presenceSensorDaily: PresenceSensorDailySpaceEntity[];
|
||||||
|
|
||||||
constructor(partial: Partial<SpaceEntity>) {
|
constructor(partial: Partial<SpaceEntity>) {
|
||||||
super();
|
super();
|
||||||
Object.assign(this, partial);
|
Object.assign(this, partial);
|
||||||
|
|||||||
@ -94,7 +94,7 @@ daily_aggregates AS (
|
|||||||
GROUP BY device_id, event_date
|
GROUP BY device_id, event_date
|
||||||
)
|
)
|
||||||
|
|
||||||
INSERT INTO public."presence-sensor-daily-detection" (
|
INSERT INTO public."presence-sensor-daily-device-detection" (
|
||||||
device_uuid,
|
device_uuid,
|
||||||
event_date,
|
event_date,
|
||||||
count_motion_detected,
|
count_motion_detected,
|
||||||
|
|||||||
@ -11,7 +11,7 @@ WITH params AS (
|
|||||||
A.count_motion_detected,
|
A.count_motion_detected,
|
||||||
A.count_presence_detected,
|
A.count_presence_detected,
|
||||||
A.count_total_presence_detected
|
A.count_total_presence_detected
|
||||||
FROM public."presence-sensor-daily-detection" AS A
|
FROM public."presence-sensor-daily-device-detection" AS A
|
||||||
JOIN params P ON TRUE
|
JOIN params P ON TRUE
|
||||||
WHERE A.device_uuid::text = ANY(P.device_ids)
|
WHERE A.device_uuid::text = ANY(P.device_ids)
|
||||||
AND (P.month IS NULL
|
AND (P.month IS NULL
|
||||||
|
|||||||
@ -85,7 +85,7 @@ daily_aggregate AS (
|
|||||||
GROUP BY device_id, event_date
|
GROUP BY device_id, event_date
|
||||||
)
|
)
|
||||||
|
|
||||||
INSERT INTO public."presence-sensor-daily-detection" (
|
INSERT INTO public."presence-sensor-daily-device-detection" (
|
||||||
device_uuid,
|
device_uuid,
|
||||||
event_date,
|
event_date,
|
||||||
count_motion_detected,
|
count_motion_detected,
|
||||||
|
|||||||
Reference in New Issue
Block a user