|
|
|
|
@ -1,14 +1,14 @@
|
|
|
|
|
import { BadRequestException, Body, Controller, Delete, Get, NotFoundException, Param, Post, Put, Query, Req, Res } from '@nestjs/common';
|
|
|
|
|
import { BadRequestException, Body, Controller, Delete, Get, NotFoundException, Param, Post, Put, Query, Req, Res, UseGuards, UsePipes } from '@nestjs/common';
|
|
|
|
|
import { AppService } from './app.service';
|
|
|
|
|
import * as fs from 'fs';
|
|
|
|
|
import { ApiBearerAuth, ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
|
|
|
import { ApiBearerAuth, ApiOperation, ApiProperty, ApiPropertyOptional, ApiResponse } from '@nestjs/swagger';
|
|
|
|
|
import { IsArray, IsBoolean, IsDateString, IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
|
|
|
|
import { NodeVisitorEntity } from './node-visitor.entity';
|
|
|
|
|
import { Between, DataSource, IsNull, LessThan, Not, Repository } from 'typeorm';
|
|
|
|
|
import * as bluebird from 'bluebird';
|
|
|
|
|
import { NodeOtherVisitorEntity } from './node-other-visitor.entity';
|
|
|
|
|
import * as moment from 'moment';
|
|
|
|
|
import { CommonPageArgs } from './common';
|
|
|
|
|
import { CommonPageArgs, Roles, RolesGuard, ValidationPipe } from './common';
|
|
|
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
|
@ -16,6 +16,7 @@ import { verificationService } from './lib/face';
|
|
|
|
|
import { join } from 'path';
|
|
|
|
|
import { AreaEntity } from './area.entity';
|
|
|
|
|
import { DeviceEntity } from './device.entity';
|
|
|
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
|
|
|
|
|
|
|
|
export class Electronics {
|
|
|
|
|
@ApiProperty({ description: "电子产品名称" })
|
|
|
|
|
@ -433,24 +434,17 @@ export class AppController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get("/visitors")
|
|
|
|
|
@ApiOperation({ summary: '查看预约记录' })
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), RolesGuard)
|
|
|
|
|
@UsePipes(new ValidationPipe())
|
|
|
|
|
@Roles('super_admin', '查看预约记录')
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
// @ApiResponse({
|
|
|
|
|
// status: 200,
|
|
|
|
|
// description: '返回参数说明',
|
|
|
|
|
// type: UserEntity,
|
|
|
|
|
// })
|
|
|
|
|
async get(@Query() query_data: QueryVisitorDto, @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 = {};
|
|
|
|
|
if (query_data.applicant) {
|
|
|
|
|
where.applicant = query_data.applicant
|
|
|
|
|
@ -513,24 +507,12 @@ export class AppController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get("/visitor-records")
|
|
|
|
|
@ApiOperation({ summary: '查看到访记录' })
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), RolesGuard)
|
|
|
|
|
@UsePipes(new ValidationPipe())
|
|
|
|
|
@Roles('super_admin', '查看到访记录')
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
async getRecord(@Query() query_data: QueryVisitorDto, @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 = {
|
|
|
|
|
start_time: Not(IsNull())
|
|
|
|
|
};
|
|
|
|
|
@ -653,22 +635,12 @@ export class AppController {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Post("/area")
|
|
|
|
|
@ApiOperation({ summary: '创建厂区' })
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), RolesGuard)
|
|
|
|
|
@UsePipes(new ValidationPipe())
|
|
|
|
|
@Roles('super_admin', '创建厂区')
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
async createArea(@Body() data: CreateArea, @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 area = new AreaEntity();
|
|
|
|
|
@ -682,22 +654,12 @@ export class AppController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put("/area/:id")
|
|
|
|
|
@ApiOperation({ summary: '更新厂区' })
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), RolesGuard)
|
|
|
|
|
@UsePipes(new ValidationPipe())
|
|
|
|
|
@Roles('super_admin', '更新厂区')
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
async updateArea(@Param() { id }: any, @Body() data: UpdateArea, @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 area = await this.areaRepository.findOne({ where: { id } });
|
|
|
|
|
if (!area) {
|
|
|
|
|
throw new NotFoundException("area not found");
|
|
|
|
|
@ -709,22 +671,12 @@ export class AppController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete("/area/:id")
|
|
|
|
|
@ApiOperation({ summary: '删除厂区' })
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), RolesGuard)
|
|
|
|
|
@UsePipes(new ValidationPipe())
|
|
|
|
|
@Roles('super_admin', '删除厂区')
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
async deleteArea(@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.areaRepository.findOne({ where: { id } });
|
|
|
|
|
if (!result) {
|
|
|
|
|
throw new NotFoundException("area not found");
|
|
|
|
|
@ -736,22 +688,6 @@ export class AppController {
|
|
|
|
|
@Get("/areas")
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
async areas(@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);
|
|
|
|
|
@ -774,22 +710,12 @@ export class AppController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post("/device")
|
|
|
|
|
@ApiOperation({ summary: '创建设备' })
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), RolesGuard)
|
|
|
|
|
@UsePipes(new ValidationPipe())
|
|
|
|
|
@Roles('super_admin', '创建设备')
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
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();
|
|
|
|
|
@ -805,22 +731,12 @@ export class AppController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put("/device/:id")
|
|
|
|
|
@ApiOperation({ summary: '更新设备' })
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), RolesGuard)
|
|
|
|
|
@UsePipes(new ValidationPipe())
|
|
|
|
|
@Roles('super_admin', '更新设备')
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
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");
|
|
|
|
|
@ -835,22 +751,12 @@ export class AppController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete("/device/:id")
|
|
|
|
|
@ApiOperation({ summary: '删除设备' })
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), RolesGuard)
|
|
|
|
|
@UsePipes(new ValidationPipe())
|
|
|
|
|
@Roles('super_admin', '删除设备')
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
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");
|
|
|
|
|
@ -860,24 +766,12 @@ export class AppController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get("/devices")
|
|
|
|
|
@ApiOperation({ summary: '查看设备' })
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), RolesGuard)
|
|
|
|
|
@UsePipes(new ValidationPipe())
|
|
|
|
|
@Roles('super_admin', '查看设备')
|
|
|
|
|
@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.deviceRepository.createQueryBuilder('device');
|
|
|
|
|
query.where(where);
|
|
|
|
|
|