浏览代码

Merge branch 'main' of http://git.cc-lotus.info/Information/cxyy-service

lrf 8 月之前
父节点
当前提交
9f47d5a113

+ 14 - 0
src/controller/users/applyCompany.controller.ts

@@ -22,6 +22,7 @@ export class ApplyCompanyController implements BaseController {
   @ApiQuery({ name: 'examine' })
   async examine(@Body('id') id: number, @Body('status') status: string) {
     if (!id || !status) throw new ServiceError(ErrorCode.BODY_ERROR);
+    if (status === '1') await this.service.apply(id);
     const result = await this.service.update({ id }, { status });
     return result;
   }
@@ -37,6 +38,18 @@ export class ApplyCompanyController implements BaseController {
     return result;
   }
 
+  @Get('/list')
+  async list(@Query() query: object) {
+    const qobj = omit(query, ['skip', 'limit']);
+    const others = pick(query, ['skip', 'limit']);
+    const { data, total } = await this.service.query(qobj, others);
+    const list = [];
+    for (const i of data) {
+      list.push(await this.service.fillName(i));
+    }
+    return { data: list, total };
+  }
+
   @Get('/:id')
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_applyCompany })
@@ -51,6 +64,7 @@ export class ApplyCompanyController implements BaseController {
   @Validate()
   @ApiResponse({ type: CVO_applyCompany })
   async create(@Body() data: object) {
+    await this.service.createExamine(data);
     const dbData = await this.service.create(data);
     const result = new CVO_applyCompany(dbData);
     return result;

+ 2 - 2
src/entity/users/expert.entity.ts

@@ -43,8 +43,8 @@ export class Expert extends BaseModel {
   status: string;
   @Column({ type: 'character varying', nullable: true, comment: '产业类型' })
   industry_type: string;
-  @Column({ type: 'character varying', nullable: true, comment: '所属产业' })
-  industry: string;
+  @Column({ type: 'jsonb', nullable: true, comment: '所属产业' })
+  industry: Array<any>;
   @Column({ type: 'character varying', nullable: true, comment: '工作单位类型' })
   work_type: string;
 }

+ 1 - 0
src/error/service.error.ts

@@ -31,6 +31,7 @@ export enum ErrorCode {
   // contactApply
   CONTACTAPPLY_TARGET_USER_NOT_FOUND = 'TARGET_USER_NOT_FOUND',
   CONTACTAPPLY_HAS_APPLY_NOT_STATUS = 'CONTACTAPPLY_HAS_APPLY_NOT_STATUS',
+  SERVICE_APPLY = 'SERVICE_APPLY',
 }
 export class ServiceError extends Error {
   constructor(errcode: string) {

+ 4 - 3
src/interface/system/user.interface.ts

@@ -14,7 +14,7 @@ export class FVO_user {
   @ApiProperty({ description: '密码' })
   'password': string = undefined;
   @ApiProperty({ description: '所属产业' })
-  'industry': string = undefined;
+  'industry': Array<any> = undefined;
   @ApiProperty({ description: '昵称' })
   'nick_name': string = undefined;
   @ApiProperty({ description: '性别' })
@@ -39,7 +39,7 @@ export class QDTO_user {
   @ApiProperty({ description: '昵称' })
   'nick_name': string = undefined;
   @ApiProperty({ description: '所属产业' })
-  'industry': string = undefined;
+  'industry': Array<any> = undefined;
   @ApiProperty({ description: '手机号' })
   'phone': string = undefined;
   @ApiProperty({ description: '电子邮箱' })
@@ -66,7 +66,8 @@ export class CDTO_user {
   @Rule(RuleType['string']().empty(''))
   'password': string = undefined;
   @ApiProperty({ description: '所属产业' })
-  'industry': string = undefined;
+  @Rule(RuleType['array']().empty(''))
+  'industry': Array<any> = undefined;
   @ApiProperty({ description: '昵称' })
   @Rule(RuleType['string']().empty(''))
   'nick_name': string = undefined;

+ 4 - 4
src/interface/users/expert.interface.ts

@@ -36,7 +36,7 @@ export class FVO_expert {
   @ApiProperty({ description: '工作类型' })
   'work_type': string = undefined;
   @ApiProperty({ description: '所属产业' })
-  'industry': string = undefined;
+  'industry': Array<any> = undefined;
   @ApiProperty({ description: '产业类型' })
   'industry_type': string = undefined;
   @ApiProperty({ description: '职称' })
@@ -75,7 +75,7 @@ export class QDTO_expert {
   @ApiProperty({ description: '工作类型' })
   'work_type': string = undefined;
   @ApiProperty({ description: '所属产业' })
-  'industry': string = undefined;
+  'industry': Array<any> = undefined;
   @ApiProperty({ description: '产业类型' })
   'industry_type': string = undefined;
   @ApiProperty({ description: '是否公开' })
@@ -135,8 +135,8 @@ export class CDTO_expert {
   @Rule(RuleType['string']().empty(''))
   'industry_type': string = undefined;
   @ApiProperty({ description: '所属产业' })
-  @Rule(RuleType['string']().empty(''))
-  'industry': string = undefined;
+  @Rule(RuleType['array']().empty(''))
+  'industry': Array<any> = undefined;
   @ApiProperty({ description: '工作类型' })
   @Rule(RuleType['string']().empty(''))
   'work_type': string = undefined;

+ 55 - 2
src/service/users/applyCompany.service.ts

@@ -1,10 +1,63 @@
-import { Provide } from '@midwayjs/core';
+import { Inject, Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
-import { Repository } from 'typeorm';
+import { Repository, Equal } from 'typeorm';
 import { ApplyCompany } from '../../entity/users/applyCompany.entity';
 import { BaseServiceV2 } from '../../frame/BaseServiceV2';
+import { get } from 'lodash';
+import { CompanyService } from './company.service';
+import { UserService } from '../system/user.service';
+import { ErrorCode, ServiceError } from '../../error/service.error';
 @Provide()
 export class ApplyCompanyService extends BaseServiceV2 {
   @InjectEntityModel(ApplyCompany)
   model: Repository<ApplyCompany>;
+
+  @Inject()
+  companyService: CompanyService;
+
+  @Inject()
+  userService: UserService;
+  // 认领检查
+  async createExamine(data) {
+    const { user } = data;
+    const company = await this.companyService.fetch({ user: user });
+    if (company) throw new ServiceError(ErrorCode.SERVICE_APPLY);
+  }
+  /**
+   * 如果审核通过修改该企业的用户id,修改用户角色
+   * @param {object} data 数据
+   */
+  async apply(id) {
+    const result = await this.model.findOne({ where: { id: Equal(id) } });
+    // 查询该用户是否有企业信息
+    const company = await this.companyService.fetch({ user: get(result, 'user') });
+    if (company) throw new ServiceError(ErrorCode.SERVICE_APPLY);
+    else {
+      // 查询用户角色
+      const userInfo = await this.userService.fetch({ id: get(result, 'user') });
+      if (userInfo) {
+        const is_update = userInfo.role.find(i => i === 'Company');
+        // 如果没有企业角色 增加一个企业角色
+        if (!is_update) await this.userService.update({ id: get(result, 'user') }, { id: get(result, 'user'), role: [...userInfo.role, 'Company'] });
+        // 修改企业用户id
+        await this.companyService.update({ id: get(result, 'company') }, { id: get(result, 'company'), user: get(result, 'user') });
+      } else throw new ServiceError(ErrorCode.USER_NOT_FOUND);
+    }
+  }
+
+  /**
+   * 填充
+   * @param {object} data 数据
+   */
+  async fillName(data) {
+    const { company, user } = data;
+    // 公司名称
+    const companyInfo = await this.companyService.fetch({ id: company });
+    if (companyInfo) data = { ...data, company_name: get(companyInfo, 'name') };
+    // 用户名称
+    const userInfo = await this.userService.fetch({ id: user });
+    if (userInfo) data = { ...data, user_name: get(userInfo, 'nick_name') };
+
+    return data;
+  }
 }