|
|
|
|
@ -4,7 +4,7 @@ import * as fs from 'fs';
|
|
|
|
|
import { ApiBearerAuth, ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
|
|
|
import { IsArray, IsBoolean, IsDateString, IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
|
|
|
|
import { NodeVisitorEntity } from './node-visitor.entity';
|
|
|
|
|
import { DataSource, Repository } from 'typeorm';
|
|
|
|
|
import { DataSource, IsNull, Not, Repository } from 'typeorm';
|
|
|
|
|
import * as bluebird from 'bluebird';
|
|
|
|
|
import { NodeOtherVisitorEntity } from './node-other-visitor.entity';
|
|
|
|
|
import * as moment from 'moment';
|
|
|
|
|
@ -314,6 +314,78 @@ export class AppController {
|
|
|
|
|
return { list: new_list, count }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get("/visitor-records")
|
|
|
|
|
@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())
|
|
|
|
|
};
|
|
|
|
|
if (query_data.start_date) {
|
|
|
|
|
where.start_date = query_data.start_date
|
|
|
|
|
}
|
|
|
|
|
if (query_data.end_date) {
|
|
|
|
|
where.end_date = query_data.end_date
|
|
|
|
|
}
|
|
|
|
|
const query = this.nodeOtherVisitorRepository.createQueryBuilder('node-other-visitor');
|
|
|
|
|
query.where(where);
|
|
|
|
|
// if (organization_name) {
|
|
|
|
|
// query
|
|
|
|
|
// .leftJoin(OrganizationEntity, 'organization', `organization.id = bill.organization_id`)
|
|
|
|
|
// .andWhere(`organization.full_name like "%${organization_name}%"`)
|
|
|
|
|
// }
|
|
|
|
|
if (query_data.search) {
|
|
|
|
|
const string = `%${query_data.search}%`;
|
|
|
|
|
const fields = ['name', 'identity_card_no', 'nationality', 'card_number'];
|
|
|
|
|
const searchString = fields.join(' like :search OR node-visitor.');
|
|
|
|
|
query.where(`node-visitor.${searchString} like :search`, {
|
|
|
|
|
search: string,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
const order_key = 'node-other-visitor.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();
|
|
|
|
|
// const [list, count] = await this.nodeVisitorRepository.findAndCount({
|
|
|
|
|
// skip: query.skip,
|
|
|
|
|
// take: query.take,
|
|
|
|
|
// order: {
|
|
|
|
|
// created_date: "DESC"
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
// const new_list = await bluebird.map(list, async (item) => {
|
|
|
|
|
// const visitor_list = await this.nodeOtherVisitorRepository.find({
|
|
|
|
|
// where: { node_visitor_id: item.id },
|
|
|
|
|
// order: {
|
|
|
|
|
// created_date: "DESC"
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
// return {
|
|
|
|
|
// ...item,
|
|
|
|
|
// visitor_list
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
return { list, count }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post("/visitor")
|
|
|
|
|
async create(@Body() data: CreateVisitor) {
|
|
|
|
|
if (new Date(data.apply_date).toString() == "Invalid Date") {
|
|
|
|
|
|