|
|
|
@ -8,7 +8,7 @@ import { Between, DataSource, IsNull, LessThan, Not, Repository } from 'typeorm'
|
|
|
|
import * as bluebird from 'bluebird';
|
|
|
|
import * as bluebird from 'bluebird';
|
|
|
|
import { NodeOtherVisitorEntity } from './node-other-visitor.entity';
|
|
|
|
import { NodeOtherVisitorEntity } from './node-other-visitor.entity';
|
|
|
|
import * as moment from 'moment';
|
|
|
|
import * as moment from 'moment';
|
|
|
|
import { CommonPageArgs, Roles, RolesGuard, User, ValidationPipe } from './common';
|
|
|
|
import { CommonPageArgs, Roles, RolesGuard, User, ValidationPipe, createXlsx } from './common';
|
|
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
|
|
import axios from 'axios';
|
|
|
|
import axios from 'axios';
|
|
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
@ -18,6 +18,7 @@ import { AreaEntity } from './area.entity';
|
|
|
|
import { DeviceEntity } from './device.entity';
|
|
|
|
import { DeviceEntity } from './device.entity';
|
|
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
|
|
import { UserEntity } from './user/user.entity';
|
|
|
|
import { UserEntity } from './user/user.entity';
|
|
|
|
|
|
|
|
import redis from './redis';
|
|
|
|
|
|
|
|
|
|
|
|
export class Electronics {
|
|
|
|
export class Electronics {
|
|
|
|
@ApiProperty({ description: "电子产品名称" })
|
|
|
|
@ApiProperty({ description: "电子产品名称" })
|
|
|
|
@ -338,6 +339,135 @@ export class QueryVisitorByNumberDto {
|
|
|
|
area_code?: string
|
|
|
|
area_code?: string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const people_table_base = [
|
|
|
|
|
|
|
|
"申请人",
|
|
|
|
|
|
|
|
"申请人部门",
|
|
|
|
|
|
|
|
"申请日期",
|
|
|
|
|
|
|
|
"申请单号",
|
|
|
|
|
|
|
|
"来访类型",
|
|
|
|
|
|
|
|
"来访区域",
|
|
|
|
|
|
|
|
"来访单位",
|
|
|
|
|
|
|
|
"访客人数",
|
|
|
|
|
|
|
|
"交通方式",
|
|
|
|
|
|
|
|
"车牌号",
|
|
|
|
|
|
|
|
"起始日期",
|
|
|
|
|
|
|
|
"截至日期",
|
|
|
|
|
|
|
|
"被访人",
|
|
|
|
|
|
|
|
"被访部门",
|
|
|
|
|
|
|
|
"厂区名字",
|
|
|
|
|
|
|
|
"厂区编号",
|
|
|
|
|
|
|
|
"来访事由",
|
|
|
|
|
|
|
|
"携带的电子产品",
|
|
|
|
|
|
|
|
"访客是否有可能接触受控设备",
|
|
|
|
|
|
|
|
"携带电子产品人员",
|
|
|
|
|
|
|
|
"是否上E1楼洽谈",
|
|
|
|
|
|
|
|
"访客姓名",
|
|
|
|
|
|
|
|
"访客身份证号",
|
|
|
|
|
|
|
|
"国籍(中国/其他国籍)",
|
|
|
|
|
|
|
|
"国籍名称",
|
|
|
|
|
|
|
|
"证件类型",
|
|
|
|
|
|
|
|
"访客卡编号",
|
|
|
|
|
|
|
|
"访客姓名(2)",
|
|
|
|
|
|
|
|
"访客身份证号(2)",
|
|
|
|
|
|
|
|
"国籍(中国/其他国籍)(2)",
|
|
|
|
|
|
|
|
"国籍名称(2)",
|
|
|
|
|
|
|
|
"证件类型(2)",
|
|
|
|
|
|
|
|
"访客卡编号(2)",
|
|
|
|
|
|
|
|
"访客姓名(3)",
|
|
|
|
|
|
|
|
"访客身份证号(3)",
|
|
|
|
|
|
|
|
"国籍(中国/其他国籍)(3)",
|
|
|
|
|
|
|
|
"国籍名称(3)",
|
|
|
|
|
|
|
|
"证件类型(3)",
|
|
|
|
|
|
|
|
"访客卡编号(3)",
|
|
|
|
|
|
|
|
"访客姓名(4)",
|
|
|
|
|
|
|
|
"访客身份证号(4)",
|
|
|
|
|
|
|
|
"国籍(中国/其他国籍)(4)",
|
|
|
|
|
|
|
|
"国籍名称(4)",
|
|
|
|
|
|
|
|
"证件类型(4)",
|
|
|
|
|
|
|
|
"访客卡编号(4)",
|
|
|
|
|
|
|
|
"访客姓名(5)",
|
|
|
|
|
|
|
|
"访客身份证号(5)",
|
|
|
|
|
|
|
|
"国籍(中国/其他国籍)(5)",
|
|
|
|
|
|
|
|
"国籍名称(5)",
|
|
|
|
|
|
|
|
"证件类型(5)",
|
|
|
|
|
|
|
|
"访客卡编号(5)",
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function mapTableData(data) {
|
|
|
|
|
|
|
|
const new_data = await bluebird.map(data, async item => {
|
|
|
|
|
|
|
|
let result = [
|
|
|
|
|
|
|
|
item.applicant,
|
|
|
|
|
|
|
|
item.applicant_department,
|
|
|
|
|
|
|
|
item.apply_date,
|
|
|
|
|
|
|
|
item.code,
|
|
|
|
|
|
|
|
item.visitor_type,
|
|
|
|
|
|
|
|
item.area,
|
|
|
|
|
|
|
|
item.visitor_unit,
|
|
|
|
|
|
|
|
item.visitor_number,
|
|
|
|
|
|
|
|
item.transport,
|
|
|
|
|
|
|
|
item.plate_no,
|
|
|
|
|
|
|
|
item.start_date,
|
|
|
|
|
|
|
|
item.end_date,
|
|
|
|
|
|
|
|
item.visited_staff,
|
|
|
|
|
|
|
|
item.visited_department,
|
|
|
|
|
|
|
|
item.to_area,
|
|
|
|
|
|
|
|
item.to_area_code,
|
|
|
|
|
|
|
|
item.purpose,
|
|
|
|
|
|
|
|
item.electronics,
|
|
|
|
|
|
|
|
item.may_access_sensitive_info,
|
|
|
|
|
|
|
|
item.personnel_carrying_electronics,
|
|
|
|
|
|
|
|
item.sfslqt,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
if (item.visitor_list && item.visitor_list.length > 0) {
|
|
|
|
|
|
|
|
item.visitor_list.forEach((d) => {
|
|
|
|
|
|
|
|
// console.log(d)
|
|
|
|
|
|
|
|
// result.push(d.name);
|
|
|
|
|
|
|
|
// result.push(d.identity_card_no);
|
|
|
|
|
|
|
|
// result.push(d.nationality_type);
|
|
|
|
|
|
|
|
// result.push(d.nationality);
|
|
|
|
|
|
|
|
// result.push(d.id_type);
|
|
|
|
|
|
|
|
// result.push(d.card_number);
|
|
|
|
|
|
|
|
result = [...result, d.name,
|
|
|
|
|
|
|
|
d.identity_card_no,
|
|
|
|
|
|
|
|
d.nationality_type,
|
|
|
|
|
|
|
|
d.nationality,
|
|
|
|
|
|
|
|
d.id_type,
|
|
|
|
|
|
|
|
d.card_number]
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// console.log(new_data[0])
|
|
|
|
|
|
|
|
// console.log(new_data[1])
|
|
|
|
|
|
|
|
// console.log(new_data[2])
|
|
|
|
|
|
|
|
// console.log(new_data[3])
|
|
|
|
|
|
|
|
// console.log(new_data[3].length)
|
|
|
|
|
|
|
|
// console.log(people_table_base.length - 24)
|
|
|
|
|
|
|
|
return new_data;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const people_table_base2 = [
|
|
|
|
|
|
|
|
"访客姓名", "访客身份证号", "证件类型", "国籍(中国/其他国籍)", "国籍名称", "厂区名字", "厂区编号", "访客卡编号", "来访时间", "离开时间"
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function mapTableData2(data) {
|
|
|
|
|
|
|
|
const new_data = await bluebird.map(data, async item => {
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
|
|
item.name,
|
|
|
|
|
|
|
|
item.to_area,
|
|
|
|
|
|
|
|
item.to_area_code,
|
|
|
|
|
|
|
|
item.identity_card_no,
|
|
|
|
|
|
|
|
item.id_type,
|
|
|
|
|
|
|
|
item.nationality_type,
|
|
|
|
|
|
|
|
item.nationality,
|
|
|
|
|
|
|
|
item.card_number,
|
|
|
|
|
|
|
|
item.start_time ? moment(item.start_time).utcOffset(8).format("YYYY-MM-DD HH:mm:ss") : "",
|
|
|
|
|
|
|
|
item.end_time ? moment(item.end_time).utcOffset(8).format("YYYY-MM-DD HH:mm:ss") : "",
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return new_data;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Controller()
|
|
|
|
@Controller()
|
|
|
|
export class AppController {
|
|
|
|
export class AppController {
|
|
|
|
constructor(
|
|
|
|
constructor(
|
|
|
|
@ -514,6 +644,93 @@ export class AppController {
|
|
|
|
return { list: new_list, count }
|
|
|
|
return { list: new_list, count }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Get("/visitors/out")
|
|
|
|
|
|
|
|
@ApiOperation({ summary: '导出预约记录' })
|
|
|
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), RolesGuard)
|
|
|
|
|
|
|
|
@UsePipes(new ValidationPipe())
|
|
|
|
|
|
|
|
@Roles('super_admin', '导出预约记录')
|
|
|
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
|
|
|
// @ApiResponse({
|
|
|
|
|
|
|
|
// status: 200,
|
|
|
|
|
|
|
|
// description: '返回参数说明',
|
|
|
|
|
|
|
|
// type: UserEntity,
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
async outVisitors(@Query() query_data: QueryVisitorDto, @User() viewer: any) {
|
|
|
|
|
|
|
|
const where: any = {};
|
|
|
|
|
|
|
|
if (query_data.applicant) {
|
|
|
|
|
|
|
|
where.applicant = query_data.applicant
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const user = await this.userRepository.findOne({ where: { id: viewer.id } })
|
|
|
|
|
|
|
|
if (user && user.area_id) {
|
|
|
|
|
|
|
|
const area = await this.areaRepository.findOne({ where: { id: user.area_id } })
|
|
|
|
|
|
|
|
where.to_area_code = area.code
|
|
|
|
|
|
|
|
} else if (query_data.area_code) {
|
|
|
|
|
|
|
|
where.to_area_code = query_data.area_code
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (query_data.visited_staff) {
|
|
|
|
|
|
|
|
where.visited_staff = query_data.visited_staff
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (query_data.start_date) {
|
|
|
|
|
|
|
|
// where.start_date = query_data.start_date
|
|
|
|
|
|
|
|
where.start_date = Between(query_data.start_date, query_data.end_date)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// if (query_data.end_date) {
|
|
|
|
|
|
|
|
// where.end_date = query_data.end_date
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
const query = this.nodeVisitorRepository.createQueryBuilder('node-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 = ['applicant', 'applicant_department', 'code', 'visitor_unit', 'plate_no', 'visited_staff', 'visited_department'];
|
|
|
|
|
|
|
|
const searchString = fields.join(' like :search OR node-visitor.');
|
|
|
|
|
|
|
|
query.where(`node-visitor.${searchString} like :search`, {
|
|
|
|
|
|
|
|
search: string,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const order_key = 'node-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
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, { concurrency: 5 })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const token = `peoples-${uuid()}`;
|
|
|
|
|
|
|
|
createXlsx(
|
|
|
|
|
|
|
|
people_table_base,
|
|
|
|
|
|
|
|
await mapTableData(new_list),
|
|
|
|
|
|
|
|
token,
|
|
|
|
|
|
|
|
'访客信息',
|
|
|
|
|
|
|
|
people_table_base,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
return { token, success: true };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Get("/visitor-records")
|
|
|
|
@Get("/visitor-records")
|
|
|
|
@ApiOperation({ summary: '查看到访记录' })
|
|
|
|
@ApiOperation({ summary: '查看到访记录' })
|
|
|
|
@UseGuards(AuthGuard('jwt'), RolesGuard)
|
|
|
|
@UseGuards(AuthGuard('jwt'), RolesGuard)
|
|
|
|
@ -581,6 +798,82 @@ export class AppController {
|
|
|
|
return { list, count }
|
|
|
|
return { list, count }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Get("/visitor-records/out")
|
|
|
|
|
|
|
|
@ApiOperation({ summary: '导出到访记录' })
|
|
|
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), RolesGuard)
|
|
|
|
|
|
|
|
@UsePipes(new ValidationPipe())
|
|
|
|
|
|
|
|
@Roles('super_admin', '导出到访记录')
|
|
|
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
|
|
|
async outRecord(@Query() query_data: QueryVisitorDto, @User() viewer: any) {
|
|
|
|
|
|
|
|
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 user = await this.userRepository.findOne({ where: { id: viewer.id } })
|
|
|
|
|
|
|
|
if (user && user.area_id) {
|
|
|
|
|
|
|
|
const area = await this.areaRepository.findOne({ where: { id: user.area_id } })
|
|
|
|
|
|
|
|
where.to_area_code = area.code
|
|
|
|
|
|
|
|
} else if (query_data.area_code) {
|
|
|
|
|
|
|
|
where.to_area_code = query_data.area_code
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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-other-visitor.');
|
|
|
|
|
|
|
|
query.where(`node-other-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
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const token = `peoples-${uuid()}`;
|
|
|
|
|
|
|
|
createXlsx(
|
|
|
|
|
|
|
|
people_table_base2,
|
|
|
|
|
|
|
|
await mapTableData2(list),
|
|
|
|
|
|
|
|
token,
|
|
|
|
|
|
|
|
'访客信息',
|
|
|
|
|
|
|
|
people_table_base2,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
return { token, success: true };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Post("/visitor")
|
|
|
|
@Post("/visitor")
|
|
|
|
async create(@Body() data: CreateVisitor) {
|
|
|
|
async create(@Body() data: CreateVisitor) {
|
|
|
|
if (new Date(data.apply_date).toString() == "Invalid Date") {
|
|
|
|
if (new Date(data.apply_date).toString() == "Invalid Date") {
|
|
|
|
@ -973,4 +1266,21 @@ export class AppController {
|
|
|
|
|
|
|
|
|
|
|
|
res.sendFile(file_path)
|
|
|
|
res.sendFile(file_path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Get('xlsx')
|
|
|
|
|
|
|
|
async seeXlsx(@Query() { token }: any) {
|
|
|
|
|
|
|
|
const result = await redis.get(token);
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
|
|
|
|
// const SERVER_URL = this.configService.get('SERVER_URL');
|
|
|
|
|
|
|
|
return { uri: `/file/download?file_token=${token}` };
|
|
|
|
|
|
|
|
// return { uri: `${SERVER_URL}/api/file/download?file_token=${token}` };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return { uri: null };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Get('/file/download')
|
|
|
|
|
|
|
|
async file_download(@Query() { file_token }: any, @Res() res) {
|
|
|
|
|
|
|
|
const result = await redis.get(file_token);
|
|
|
|
|
|
|
|
return res.sendFile(result);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|