|
|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
import { BadRequestException, Body, Controller, Get, Post, Put, Query, Req, Res } from '@nestjs/common';
|
|
|
|
|
import { BadRequestException, Body, Controller, Delete, Get, NotFoundException, Param, Post, Put, Query, Req, Res } from '@nestjs/common';
|
|
|
|
|
import { AppService } from './app.service';
|
|
|
|
|
import * as fs from 'fs';
|
|
|
|
|
import { ApiBearerAuth, ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
|
|
|
@ -14,6 +14,7 @@ import axios from 'axios';
|
|
|
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
|
import { verificationService } from './lib/face';
|
|
|
|
|
import { join } from 'path';
|
|
|
|
|
import { AreaEntity } from './area.entity';
|
|
|
|
|
|
|
|
|
|
export class Electronics {
|
|
|
|
|
@ApiProperty({ description: "电子产品名称" })
|
|
|
|
|
@ -205,6 +206,45 @@ export class QueryVisitorDto extends CommonPageArgs {
|
|
|
|
|
end_date?: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class AreaDto extends CommonPageArgs {
|
|
|
|
|
@ApiPropertyOptional({ description: "根据名称模糊搜索", required: false })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsOptional()
|
|
|
|
|
search?: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class CreateArea {
|
|
|
|
|
@ApiProperty({ description: "" })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
public name: string;
|
|
|
|
|
|
|
|
|
|
@ApiProperty({ description: "" })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
public code: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class UpdateArea {
|
|
|
|
|
@ApiProperty({ description: "" })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
public name: string;
|
|
|
|
|
|
|
|
|
|
@ApiProperty({ description: "" })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
public code: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class DeleteArea {
|
|
|
|
|
@ApiProperty({ description: "" })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
public id: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class QueryVisitorByNumberDto {
|
|
|
|
|
@ApiPropertyOptional({ description: "身份证号", required: true })
|
|
|
|
|
@IsString()
|
|
|
|
|
@ -219,6 +259,8 @@ export class AppController {
|
|
|
|
|
private readonly dataSource: DataSource,
|
|
|
|
|
@InjectRepository(NodeVisitorEntity)
|
|
|
|
|
private readonly nodeVisitorRepository: Repository<NodeVisitorEntity>,
|
|
|
|
|
@InjectRepository(AreaEntity)
|
|
|
|
|
private readonly areaRepository: Repository<AreaEntity>,
|
|
|
|
|
@InjectRepository(NodeOtherVisitorEntity)
|
|
|
|
|
private readonly nodeOtherVisitorRepository: Repository<NodeOtherVisitorEntity>,
|
|
|
|
|
) { }
|
|
|
|
|
@ -501,6 +543,128 @@ export class AppController {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Post("/area")
|
|
|
|
|
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();
|
|
|
|
|
area.name = data.name;
|
|
|
|
|
area.code = data.code;
|
|
|
|
|
|
|
|
|
|
const result = await transactionalEntityManager.save(area);
|
|
|
|
|
|
|
|
|
|
return { statusCode: 201, data: result };
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put("/area/:id")
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
area.name = data.name;
|
|
|
|
|
area.code = data.code;
|
|
|
|
|
const result = await this.areaRepository.save(area);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete("/area/:id")
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
await this.areaRepository.delete(id);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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);
|
|
|
|
|
if (query_data.search) {
|
|
|
|
|
const string = `%${query_data.search}%`;
|
|
|
|
|
const fields = ['applicant', 'applicant_department', 'code', 'visitor_unit', 'plate_no', 'visited_staff', 'visited_department'];
|
|
|
|
|
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 } })
|
|
|
|
|
@ -598,13 +762,13 @@ export class AppController {
|
|
|
|
|
@Req() req: any,
|
|
|
|
|
): Promise<any> {
|
|
|
|
|
return {
|
|
|
|
|
"versionName":"1.2.0",
|
|
|
|
|
"apkUrl":`http://${process.env.LOCAL_IP}/app.apk`,
|
|
|
|
|
"versionName": "1.2.0",
|
|
|
|
|
"apkUrl": `http://${process.env.LOCAL_IP}/app.apk`,
|
|
|
|
|
"forceUpdate": false,
|
|
|
|
|
"whatsNew": "新版本更新"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Get('app.apk')
|
|
|
|
|
async file(
|
|
|
|
|
@Res() res: any,
|
|
|
|
|
|