增加厂区接口
continuous-integration/drone/push Build is failing Details

main
rustdreamer 2 years ago
parent 4ba66c1b25
commit 9f75083201

@ -0,0 +1,4 @@
{
"DevChat.PythonForChat": "/usr/bin/python3",
"DevChat.PythonForCommands": "/Users/tianshuai/.chat/mamba/envs/devchat-commands/bin/python"
}

@ -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 { AppService } from './app.service';
import * as fs from 'fs'; import * as fs from 'fs';
import { ApiBearerAuth, ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { ApiBearerAuth, ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
@ -14,6 +14,7 @@ import axios from 'axios';
import { v4 as uuid } from 'uuid'; import { v4 as uuid } from 'uuid';
import { verificationService } from './lib/face'; import { verificationService } from './lib/face';
import { join } from 'path'; import { join } from 'path';
import { AreaEntity } from './area.entity';
export class Electronics { export class Electronics {
@ApiProperty({ description: "电子产品名称" }) @ApiProperty({ description: "电子产品名称" })
@ -205,6 +206,45 @@ export class QueryVisitorDto extends CommonPageArgs {
end_date?: string 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 { export class QueryVisitorByNumberDto {
@ApiPropertyOptional({ description: "身份证号", required: true }) @ApiPropertyOptional({ description: "身份证号", required: true })
@IsString() @IsString()
@ -219,6 +259,8 @@ export class AppController {
private readonly dataSource: DataSource, private readonly dataSource: DataSource,
@InjectRepository(NodeVisitorEntity) @InjectRepository(NodeVisitorEntity)
private readonly nodeVisitorRepository: Repository<NodeVisitorEntity>, private readonly nodeVisitorRepository: Repository<NodeVisitorEntity>,
@InjectRepository(AreaEntity)
private readonly areaRepository: Repository<AreaEntity>,
@InjectRepository(NodeOtherVisitorEntity) @InjectRepository(NodeOtherVisitorEntity)
private readonly nodeOtherVisitorRepository: Repository<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") @Put("/visitor/number")
async updateVisitor(@Body() data: UpdateVisitorNumber) { async updateVisitor(@Body() data: UpdateVisitorNumber) {
const node_other_visitor = await this.nodeOtherVisitorRepository.findOne({ where: { id: data.id } }) const node_other_visitor = await this.nodeOtherVisitorRepository.findOne({ where: { id: data.id } })

@ -0,0 +1,16 @@
import { BaseEntity, Column, Entity, Index, JoinColumn, OneToMany, OneToOne } from 'typeorm';
import { createHmac } from 'crypto';
import { Base } from './common';
import { ApiProperty } from '@nestjs/swagger';
// 厂区
@Entity({ name: 'area' })
export class AreaEntity extends Base {
@ApiProperty({ description: "name" })
@Column({ length: 150, nullable: false, type: 'char' })
public name: string;
@ApiProperty({ description: "code" })
@Column({ length: 150, nullable: false, type: 'char' })
public code: string;
}

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save