|
|
|
|
@ -15,6 +15,7 @@ import { v4 as uuid } from 'uuid';
|
|
|
|
|
import { verificationService } from './lib/face';
|
|
|
|
|
import { join } from 'path';
|
|
|
|
|
import { AreaEntity } from './area.entity';
|
|
|
|
|
import { DeviceEntity } from './device.entity';
|
|
|
|
|
|
|
|
|
|
export class Electronics {
|
|
|
|
|
@ApiProperty({ description: "电子产品名称" })
|
|
|
|
|
@ -254,6 +255,74 @@ export class DeleteArea {
|
|
|
|
|
public id: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class DeviceDto extends CommonPageArgs {
|
|
|
|
|
@ApiPropertyOptional({ description: "根据名称模糊搜索", required: false })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsOptional()
|
|
|
|
|
search?: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class CreateDevice {
|
|
|
|
|
@ApiProperty({ description: "" })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
public name: string;
|
|
|
|
|
|
|
|
|
|
@ApiProperty({ description: "" })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsOptional()
|
|
|
|
|
public cn: string;
|
|
|
|
|
|
|
|
|
|
@ApiProperty({ description: "" })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsOptional()
|
|
|
|
|
public ip: string;
|
|
|
|
|
|
|
|
|
|
@ApiProperty({ description: "" })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsOptional()
|
|
|
|
|
public area_id: string;
|
|
|
|
|
|
|
|
|
|
@ApiProperty({ description: "" })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsOptional()
|
|
|
|
|
public address: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class UpdateDevice {
|
|
|
|
|
@ApiProperty({ description: "" })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
public name: string;
|
|
|
|
|
|
|
|
|
|
@ApiProperty({ description: "" })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsOptional()
|
|
|
|
|
public cn: string;
|
|
|
|
|
|
|
|
|
|
@ApiProperty({ description: "" })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsOptional()
|
|
|
|
|
public ip: string;
|
|
|
|
|
|
|
|
|
|
@ApiProperty({ description: "" })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsOptional()
|
|
|
|
|
public area_id: string;
|
|
|
|
|
|
|
|
|
|
@ApiProperty({ description: "" })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsOptional()
|
|
|
|
|
public address: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class DeleteDevice {
|
|
|
|
|
@ApiProperty({ description: "" })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
public id: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class QueryVisitorByNumberDto {
|
|
|
|
|
@ApiPropertyOptional({ description: "身份证号", required: true })
|
|
|
|
|
@ -276,6 +345,8 @@ export class AppController {
|
|
|
|
|
private readonly nodeVisitorRepository: Repository<NodeVisitorEntity>,
|
|
|
|
|
@InjectRepository(AreaEntity)
|
|
|
|
|
private readonly areaRepository: Repository<AreaEntity>,
|
|
|
|
|
@InjectRepository(DeviceEntity)
|
|
|
|
|
private readonly deviceRepository: Repository<DeviceEntity>,
|
|
|
|
|
@InjectRepository(NodeOtherVisitorEntity)
|
|
|
|
|
private readonly nodeOtherVisitorRepository: Repository<NodeOtherVisitorEntity>,
|
|
|
|
|
) { }
|
|
|
|
|
@ -702,6 +773,132 @@ export class AppController {
|
|
|
|
|
return { list, count }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post("/device")
|
|
|
|
|
async createDevice(@Body() data: CreateDevice, @Req() req: any) {
|
|
|
|
|
if (!req.headers.authorization) {
|
|
|
|
|
throw new BadRequestException("无权限")
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
// console.log(`${process.env.RUST_URI}/api/viewer`)
|
|
|
|
|
const result = await axios.get(`${process.env.RUST_URI}/api/viewer`, {
|
|
|
|
|
headers: {
|
|
|
|
|
authorization: req.headers.authorization
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// console.log("result", result)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// console.log(e)
|
|
|
|
|
throw new BadRequestException("无权限, 请联系管理员")
|
|
|
|
|
}
|
|
|
|
|
return await this.dataSource.transaction(async transactionalEntityManager => {
|
|
|
|
|
|
|
|
|
|
const device = new DeviceEntity();
|
|
|
|
|
device.name = data.name;
|
|
|
|
|
device.cn = data.cn;
|
|
|
|
|
device.ip = data.ip;
|
|
|
|
|
device.area_id = data.area_id;
|
|
|
|
|
device.address = data.address;
|
|
|
|
|
const result = await transactionalEntityManager.save(device);
|
|
|
|
|
|
|
|
|
|
return { statusCode: 201, data: result };
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put("/device/:id")
|
|
|
|
|
async updateDevice(@Param() { id }: any, @Body() data: UpdateDevice, @Req() req: any) {
|
|
|
|
|
if (!req.headers.authorization) {
|
|
|
|
|
throw new BadRequestException("无权限")
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
// console.log(`${process.env.RUST_URI}/api/viewer`)
|
|
|
|
|
const result = await axios.get(`${process.env.RUST_URI}/api/viewer`, {
|
|
|
|
|
headers: {
|
|
|
|
|
authorization: req.headers.authorization
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// console.log("result", result)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// console.log(e)
|
|
|
|
|
throw new BadRequestException("无权限, 请联系管理员")
|
|
|
|
|
}
|
|
|
|
|
const device = await this.deviceRepository.findOne({ where: { id } });
|
|
|
|
|
if (!device) {
|
|
|
|
|
throw new NotFoundException("device not found");
|
|
|
|
|
}
|
|
|
|
|
device.name = data.name;
|
|
|
|
|
device.cn = data.cn;
|
|
|
|
|
device.ip = data.ip;
|
|
|
|
|
device.area_id = data.area_id;
|
|
|
|
|
device.address = data.address;
|
|
|
|
|
const result = await this.deviceRepository.save(device);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete("/device/:id")
|
|
|
|
|
async deleteDevice(@Param() { id }: any, @Req() req: any) {
|
|
|
|
|
if (!req.headers.authorization) {
|
|
|
|
|
throw new BadRequestException("无权限")
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
// console.log(`${process.env.RUST_URI}/api/viewer`)
|
|
|
|
|
const result = await axios.get(`${process.env.RUST_URI}/api/viewer`, {
|
|
|
|
|
headers: {
|
|
|
|
|
authorization: req.headers.authorization
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// console.log("result", result)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// console.log(e)
|
|
|
|
|
throw new BadRequestException("无权限, 请联系管理员")
|
|
|
|
|
}
|
|
|
|
|
const result = await this.deviceRepository.findOne({ where: { id } });
|
|
|
|
|
if (!result) {
|
|
|
|
|
throw new NotFoundException("device not found");
|
|
|
|
|
}
|
|
|
|
|
await this.deviceRepository.delete(id);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get("/devices")
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
async devices(@Query() query_data: AreaDto, @Req() req: any) {
|
|
|
|
|
// console.log("req", req.headers)
|
|
|
|
|
if (!req.headers.authorization) {
|
|
|
|
|
throw new BadRequestException("无权限")
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
// console.log(`${process.env.RUST_URI}/api/viewer`)
|
|
|
|
|
const result = await axios.get(`${process.env.RUST_URI}/api/viewer`, {
|
|
|
|
|
headers: {
|
|
|
|
|
authorization: req.headers.authorization
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// console.log("result", result)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// console.log(e)
|
|
|
|
|
throw new BadRequestException("无权限, 请联系管理员")
|
|
|
|
|
}
|
|
|
|
|
const where: any = {};
|
|
|
|
|
const query = this.areaRepository.createQueryBuilder('area');
|
|
|
|
|
query.where(where);
|
|
|
|
|
if (query_data.search) {
|
|
|
|
|
const string = `%${query_data.search}%`;
|
|
|
|
|
const fields = ['name'];
|
|
|
|
|
const searchString = fields.join(' like :search OR area.');
|
|
|
|
|
query.where(`area.${searchString} like :search`, {
|
|
|
|
|
search: string,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
const order_key = 'area.created_date';
|
|
|
|
|
let order_value: any = 'DESC';
|
|
|
|
|
const [list, count] = await query
|
|
|
|
|
.skip(query_data.skip)
|
|
|
|
|
.take(query_data.take)
|
|
|
|
|
.orderBy(order_key, order_value)
|
|
|
|
|
.getManyAndCount();
|
|
|
|
|
return { list, count }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put("/visitor/number")
|
|
|
|
|
async updateVisitor(@Body() data: UpdateVisitorNumber) {
|
|
|
|
|
const node_other_visitor = await this.nodeOtherVisitorRepository.findOne({ where: { id: data.id } })
|
|
|
|
|
|