Browse Source

修改问题

zs 9 tháng trước cách đây
mục cha
commit
929f99030c

+ 70 - 0
src/controller/users/school.controller.ts

@@ -0,0 +1,70 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/core';
+import { SchoolService } from '../../service/users/school.service';
+import { CVO_school, FVO_school, QVO_school, UVAO_school } from '../../interface/users/school.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+import { BaseController } from '../../frame/BaseController';
+import { omit, pick } from 'lodash';
+import { ErrorCode, ServiceError } from '../../error/service.error';
+import { ServiceUtilService } from '../../service/serviceUtil.service';
+const namePrefix = '院校';
+@ApiTags(['院校'])
+@Controller('/school', { tagName: namePrefix })
+export class schoolController implements BaseController {
+  @Inject()
+  service: SchoolService;
+
+  @Inject()
+  serviceUtil: ServiceUtilService;
+
+  @Get('/')
+  @ApiTags('列表查询')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_school })
+  async index(@Query() query: object) {
+    const qobj = omit(query, ['skip', 'limit']);
+    const others = pick(query, ['skip', 'limit']);
+    const result = await this.service.query(qobj, others);
+    return result;
+  }
+
+  @Get('/:id')
+  @ApiTags('单查询')
+  @ApiResponse({ type: FVO_school })
+  async fetch(@Param('id') id: number) {
+    const data = await this.service.fetch({ id });
+    const result = new FVO_school(data);
+    return result;
+  }
+
+  @Post('/', { routerName: `创建${namePrefix}` })
+  @ApiTags('创建数据')
+  @Validate()
+  @ApiResponse({ type: CVO_school })
+  async create(@Body() data: object) {
+    const dbData = await this.service.create(data);
+    this.serviceUtil.fillIdentity(data, 'School');
+    const result = new CVO_school(dbData);
+    return result;
+  }
+
+  @Post('/:id', { routerName: `修改${namePrefix}` })
+  @ApiTags('修改数据')
+  @Validate()
+  @ApiResponse({ type: UVAO_school })
+  async update(@Param('id') id: number, @Body() data: object) {
+    if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
+    const result = await this.service.update({ id }, data);
+    this.serviceUtil.fillIdentity(data, 'School');
+    return result;
+  }
+
+  @Del('/:id', { routerName: `删除${namePrefix}` })
+  @ApiTags('删除数据')
+  @Validate()
+  async delete(@Param('id') id: number) {
+    if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
+    const result = await this.service.delete({ id });
+    return result;
+  }
+}

+ 24 - 0
src/entity/users/school.entity.ts

@@ -0,0 +1,24 @@
+import { Column, Entity } from 'typeorm';
+import { BaseModel } from '../../frame/BaseModel';
+// 院校
+@Entity('school')
+export class School extends BaseModel {
+  @Column({ type: 'integer', nullable: true, comment: '平台用户id' })
+  user: number;
+  @Column({ type: 'character varying', nullable: true, comment: '名称' })
+  name: string;
+  @Column({ type: 'character varying', nullable: true, comment: '负责人' })
+  person: string;
+
+  @Column({ type: 'character varying', nullable: true, comment: '负责人电话' })
+  person_phone: string;
+  @Column({ type: 'text', nullable: true, comment: '简介' })
+  brief: string;
+  @Column({ type: 'character varying', nullable: true, comment: '地址' })
+  address: string;
+
+  @Column({ type: 'character varying', nullable: true, comment: '是否公开' })
+  is_show: string;
+  @Column({ type: 'character varying', nullable: true, default: '0', comment: '状态' })
+  status: string;
+}

+ 93 - 0
src/interface/users/school.interface.ts

@@ -0,0 +1,93 @@
+import { ApiProperty } from '@midwayjs/swagger';
+import { Rule, RuleType } from '@midwayjs/validate';
+import { dealVO } from '../../frame/VOBase';
+export class FVO_school {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  id: string = undefined;
+  @ApiProperty({ description: '平台用户id' })
+  'user': number = undefined;
+  @ApiProperty({ description: '名称' })
+  'name': string = undefined;
+  @ApiProperty({ description: '负责人' })
+  'person': string = undefined;
+  @ApiProperty({ description: '负责人电话' })
+  'person_phone': string = undefined;
+  @ApiProperty({ description: '简介' })
+  'brief': string = undefined;
+  @ApiProperty({ description: '地址' })
+  'address': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  'is_show': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class QDTO_school {
+  @ApiProperty({ description: '平台用户id' })
+  'user': number = undefined;
+  @ApiProperty({ description: '名称' })
+  'name': string = undefined;
+  @ApiProperty({ description: '负责人电话' })
+  'person_phone': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  'is_show': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class QVO_school extends FVO_school {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_school {
+  @ApiProperty({ description: '平台用户id' })
+  @Rule(RuleType['number']().empty(''))
+  'user': number = undefined;
+  @ApiProperty({ description: '名称' })
+  @Rule(RuleType['string']().empty(''))
+  'name': string = undefined;
+  @ApiProperty({ description: '负责人' })
+  @Rule(RuleType['string']().empty(''))
+  'person': string = undefined;
+  @ApiProperty({ description: '负责人电话' })
+  @Rule(RuleType['string']().empty(''))
+  'person_phone': string = undefined;
+  @ApiProperty({ description: '简介' })
+  @Rule(RuleType['string']().empty(''))
+  'brief': string = undefined;
+  @ApiProperty({ description: '地址' })
+  @Rule(RuleType['string']().empty(''))
+  'address': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  @Rule(RuleType['string']().empty(''))
+  'is_show': string = undefined;
+  @ApiProperty({ description: '状态' })
+  @Rule(RuleType['string']().empty(''))
+  'status': string = undefined;
+}
+
+export class CVO_school extends FVO_school {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_school extends CDTO_school {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['number']().empty(''))
+  id: number = undefined;
+}
+
+export class UVAO_school extends FVO_school {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 1 - 1
src/service/serviceUtil.service.ts

@@ -61,7 +61,7 @@ export class ServiceUtilService {
       const dataUser = await this.userService.fetch({ id: get(data, 'user') });
       if (dataUser) {
         const role = union(get(dataUser, 'role'), [type]);
-        await this.userService.update({ id: get(dataUser, 'id') }, { id: get(dataUser, 'id'), role, status: '0' });
+        await this.userService.update({ id: get(dataUser, 'id') }, { id: get(dataUser, 'id'), role, status: '1' });
       }
     }
   }

+ 3 - 0
src/service/system/role.service.ts

@@ -17,6 +17,7 @@ import { Incubator } from '../../entity/users/incubator.entity';
 import { Company } from '../../entity/users/company.entity';
 import { Unit } from '../../entity/users/unit.entity';
 import { Expert } from '../../entity/users/expert.entity';
+import { School } from '../../entity/users/school.entity';
 @Provide()
 export class RoleService extends BaseServiceV2 {
   @InjectEntityModel(Role)
@@ -50,6 +51,8 @@ export class RoleService extends BaseServiceV2 {
   Expert: Repository<Expert>;
   @InjectEntityModel(Unit)
   Unit: Repository<Unit>;
+  @InjectEntityModel(School)
+  School: Repository<School>;
 
   @Inject()
   ctx: Context;

+ 13 - 0
src/service/users/school.service.ts

@@ -0,0 +1,13 @@
+import { Provide } from '@midwayjs/core';
+import { InjectEntityModel } from '@midwayjs/typeorm';
+import { Repository } from 'typeorm';
+import { School } from '../../entity/users/school.entity';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
+@Provide()
+export class SchoolService extends BaseServiceV2 {
+  getQueryColumnsOpera(): object {
+    return {};
+  }
+  @InjectEntityModel(School)
+  model: Repository<School>;
+}