From cf9b1a298dceeae2f0ae1a625aab8d6954a115c2 Mon Sep 17 00:00:00 2001 From: rustdreamer Date: Sun, 7 Apr 2024 15:26:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8E=82=E5=8C=BA=E6=A0=87?= =?UTF-8?q?=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.controller.ts | 41 ++++++++++++++++++++++++++++++++ src/node-other-visitor.entity.ts | 10 +++++++- src/node-visitor.entity.ts | 8 +++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/app.controller.ts b/src/app.controller.ts index 0312e6b..8f130c6 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -67,6 +67,11 @@ export class UpdateVisitorEnd { @IsString() @IsNotEmpty() public id: string; + + @ApiProperty({ description: "area_code" }) + @IsString() + @IsOptional() + public area_code: string; } export class CreateVisitor { @@ -185,6 +190,11 @@ export class QueryVisitorDto extends CommonPageArgs { @IsOptional() search?: string + @ApiPropertyOptional({ description: "厂区标识", required: false }) + @IsString() + @IsOptional() + area_code?: string + @ApiPropertyOptional({ description: "申请人", required: false }) @IsString() @IsOptional() @@ -362,6 +372,9 @@ export class AppController { if (query_data.applicant) { where.applicant = query_data.applicant } + if (query_data.area_code) { + where.area_code = query_data.area_code + } if (query_data.visited_staff) { where.visited_staff = query_data.visited_staff } @@ -499,10 +512,17 @@ export class AppController { if (new Date(data.end_date).toString() == "Invalid Date") { throw new BadRequestException("end_date 格式不正确") } + const new_code = data.code.split("-")[0]; + const area = await this.areaRepository.findOne({ where: { code: new_code } }) + if (!area) { + throw new BadRequestException("区域不存在"); + } return await this.dataSource.transaction(async transactionalEntityManager => { const new_node_visitor = new NodeVisitorEntity(); new_node_visitor.applicant = data.applicant; + new_node_visitor.to_area = area.name; + new_node_visitor.to_area_code = area.code; new_node_visitor.applicant_department = data.applicant_department; new_node_visitor.apply_date = moment(data.apply_date).format("YYYY-MM-DD"); // new_node_visitor.apply_date = new Date(data.apply_date).toLocaleDateString(); @@ -536,6 +556,8 @@ export class AppController { new_node_other_visitor.nationality = item.nationality; new_node_other_visitor.node_visitor_id = result.id; new_node_other_visitor.id_type = item.id_type; + new_node_other_visitor.to_area = area.name; + new_node_other_visitor.to_area_code = area.code; await transactionalEntityManager.save(new_node_other_visitor); }) @@ -682,6 +704,16 @@ export class AppController { if (!node_other_visitor) { throw new BadRequestException("数据不存在") } + + if (data.area_code) { + const area = await this.areaRepository.findOne({ where: { code: data.area_code } }); + if (!area) { + throw new NotFoundException("area not found"); + } + if (node_other_visitor.to_area != area.name) { + throw new NotFoundException("厂区错误"); + } + } if (node_other_visitor.end_time) { // throw new BadRequestException("拜访已结束") return { @@ -700,6 +732,15 @@ export class AppController { if (!node_other_visitor) { throw new BadRequestException("数据不存在") } + if (data.area_code) { + const area = await this.areaRepository.findOne({ where: { code: data.area_code } }); + if (!area) { + throw new NotFoundException("area not found"); + } + if (node_other_visitor.to_area != area.name) { + throw new NotFoundException("厂区错误"); + } + } node_other_visitor.start_time = new Date(); const result = await this.nodeOtherVisitorRepository.save(node_other_visitor); return result; diff --git a/src/node-other-visitor.entity.ts b/src/node-other-visitor.entity.ts index 7254efd..0fd9c82 100644 --- a/src/node-other-visitor.entity.ts +++ b/src/node-other-visitor.entity.ts @@ -9,7 +9,15 @@ export class NodeOtherVisitorEntity extends Base { @ApiProperty({ description: "访客姓名" }) @Column({ length: 150, nullable: true, type: 'char' }) public name: string; - + + @ApiProperty({ description: "" }) + @Column({ length: 150, nullable: true, type: 'char' }) + public to_area?: string; + + @ApiProperty({ description: "" }) + @Column({ length: 150, nullable: true, type: 'char' }) + public to_area_code?: string; + @ApiProperty({ description: "访客身份证号" }) @Column({ length: 150, nullable: true, type: 'char' }) public identity_card_no: string; diff --git a/src/node-visitor.entity.ts b/src/node-visitor.entity.ts index e00cc18..c97c776 100644 --- a/src/node-visitor.entity.ts +++ b/src/node-visitor.entity.ts @@ -31,6 +31,14 @@ export class NodeVisitorEntity extends Base { @Column({ length: 150, nullable: true, type: 'char' }) public area: string; + @ApiProperty({ description: "厂区" }) + @Column({ length: 150, nullable: true, type: 'char' }) + public to_area: string; + + @ApiProperty({ description: "厂区" }) + @Column({ length: 150, nullable: true, type: 'char' }) + public to_area_code: string; + @ApiProperty({ description: "来访单位" }) @Column({ length: 150, nullable: true, type: 'char' }) public visitor_unit: string;