|
|
|
|
@ -8,7 +8,7 @@ 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, Roles, RolesGuard, ValidationPipe } from './common';
|
|
|
|
|
import { CommonPageArgs, Roles, RolesGuard, User, ValidationPipe } from './common';
|
|
|
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
|
@ -17,6 +17,7 @@ import { join } from 'path';
|
|
|
|
|
import { AreaEntity } from './area.entity';
|
|
|
|
|
import { DeviceEntity } from './device.entity';
|
|
|
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
|
|
|
import { UserEntity } from './user/user.entity';
|
|
|
|
|
|
|
|
|
|
export class Electronics {
|
|
|
|
|
@ApiProperty({ description: "电子产品名称" })
|
|
|
|
|
@ -346,6 +347,8 @@ export class AppController {
|
|
|
|
|
private readonly nodeVisitorRepository: Repository<NodeVisitorEntity>,
|
|
|
|
|
@InjectRepository(AreaEntity)
|
|
|
|
|
private readonly areaRepository: Repository<AreaEntity>,
|
|
|
|
|
@InjectRepository(UserEntity)
|
|
|
|
|
private readonly userRepository: Repository<UserEntity>,
|
|
|
|
|
@InjectRepository(DeviceEntity)
|
|
|
|
|
private readonly deviceRepository: Repository<DeviceEntity>,
|
|
|
|
|
@InjectRepository(NodeOtherVisitorEntity)
|
|
|
|
|
@ -444,12 +447,17 @@ export class AppController {
|
|
|
|
|
// description: '返回参数说明',
|
|
|
|
|
// type: UserEntity,
|
|
|
|
|
// })
|
|
|
|
|
async get(@Query() query_data: QueryVisitorDto, @Req() req: any) {
|
|
|
|
|
async get(@Query() query_data: QueryVisitorDto, @User() viewer: any) {
|
|
|
|
|
const where: any = {};
|
|
|
|
|
if (query_data.applicant) {
|
|
|
|
|
where.applicant = query_data.applicant
|
|
|
|
|
}
|
|
|
|
|
if (query_data.area_code) {
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
@ -512,7 +520,7 @@ export class AppController {
|
|
|
|
|
@UsePipes(new ValidationPipe())
|
|
|
|
|
@Roles('super_admin', '查看到访记录')
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
async getRecord(@Query() query_data: QueryVisitorDto, @Req() req: any) {
|
|
|
|
|
async getRecord(@Query() query_data: QueryVisitorDto, @User() viewer: any) {
|
|
|
|
|
const where: any = {
|
|
|
|
|
start_time: Not(IsNull())
|
|
|
|
|
};
|
|
|
|
|
@ -522,7 +530,11 @@ export class AppController {
|
|
|
|
|
if (query_data.end_date) {
|
|
|
|
|
where.end_date = query_data.end_date
|
|
|
|
|
}
|
|
|
|
|
if (query_data.area_code) {
|
|
|
|
|
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');
|
|
|
|
|
@ -709,6 +721,38 @@ export class AppController {
|
|
|
|
|
return { list, count }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get("/areas/list")
|
|
|
|
|
@ApiOperation({ summary: '查看厂区' })
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), RolesGuard)
|
|
|
|
|
@UsePipes(new ValidationPipe())
|
|
|
|
|
@Roles('super_admin', '查看厂区')
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
async areaList(@Query() query_data: AreaDto, @User() viewer: any) {
|
|
|
|
|
const where: any = {};
|
|
|
|
|
const user = await this.userRepository.findOne({ where: { id: viewer.id } })
|
|
|
|
|
if (user && user.area_id) {
|
|
|
|
|
where.id = user.area_id;
|
|
|
|
|
}
|
|
|
|
|
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 }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post("/device")
|
|
|
|
|
@ApiOperation({ summary: '创建设备' })
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), RolesGuard)
|
|
|
|
|
|