Browse Source

修改接口

zs 2 years ago
parent
commit
fcd5c5c650

+ 3 - 0
package.json

@@ -12,11 +12,13 @@
     "@midwayjs/jwt": "^3.11.3",
     "@midwayjs/koa": "^3.0.0",
     "@midwayjs/logger": "^2.14.0",
+    "@midwayjs/rabbitmq": "^3.11.4",
     "@midwayjs/redis": "^3.11.3",
     "@midwayjs/swagger": "^3.11.3",
     "@midwayjs/typegoose": "^3.11.3",
     "@midwayjs/validate": "^3.0.0",
     "@typegoose/typegoose": "^11.0.1",
+    "amqplib": "^0.10.3",
     "exceljs": "^4.3.0",
     "free-midway-component": "^1.0.35",
     "moment": "^2.29.4",
@@ -26,6 +28,7 @@
   "devDependencies": {
     "@midwayjs/cli": "^2.0.0",
     "@midwayjs/mock": "^3.0.0",
+    "@types/amqplib": "^0.10.1",
     "@types/jest": "^29.2.0",
     "@types/jsonwebtoken": "^9.0.1",
     "@types/koa": "^2.13.4",

+ 2 - 0
src/configuration.ts

@@ -1,4 +1,5 @@
 import { Configuration, App } from '@midwayjs/core';
+// import * as rabbitmq from '@midwayjs/rabbitmq';
 import * as koa from '@midwayjs/koa';
 import * as validate from '@midwayjs/validate';
 import * as info from '@midwayjs/info';
@@ -32,6 +33,7 @@ import { CheckTokenMiddleware } from './middleware/checkToken.middleware';
     redis,
     axios,
     swagger,
+    // rabbitmq,
     {
       component: info,
       enabledEnvironment: ['local'],

+ 2 - 1
src/controller/technology/dock.controller.ts

@@ -84,7 +84,8 @@ export class DockController extends BaseController {
   @Validate()
   @ApiResponse({ type: CVO_dock })
   async create(@Body() data: CDTO_dock) {
-    const dbData = await this.service.create(data);
+    const body = await this.service.beforeCreate(data);
+    const dbData = await this.service.create(body);
     const result = new CVO_dock(dbData);
     return result;
   }

+ 7 - 5
src/entity/system/dictData.entity.ts

@@ -4,20 +4,22 @@ import { BaseModel } from 'free-midway-component';
   schemaOptions: { collection: 'dictData' },
 })
 export class DictData extends BaseModel {
-  @prop({ required: false, index: false, zh: '字典类型' })
+  @prop({ required: false, index: true, zh: '字典类型' })
   type: string;
-  @prop({ required: false, index: false, zh: '字典标签' })
+  @prop({ required: false, index: true, zh: '字典标签' })
   label: string;
-  @prop({ required: false, index: false, zh: '字典键值' })
+  @prop({ required: false, index: true, zh: '字典键值' })
   value: string;
-  @prop({ required: false, index: false, zh: '排序', default: '0' })
+  @prop({ required: false, index: true, zh: '排序', default: '0' })
   sort: number;
   @prop({
     required: false,
-    index: false,
+    index: true,
     zh: '是否启用',
     remark: '字典表:common_use',
     default: '0',
   })
   is_use: string;
+  @prop({ required: false, index: false, zh: '子数据' })
+  children: Array<any>;
 }

+ 1 - 1
src/entity/technology/dock.entity.ts

@@ -48,7 +48,7 @@ export class Dock extends BaseModel {
     required: false,
     index: true,
     zh: '状态',
-    remark: '字典:dick_status',
+    remark: '字典:dock_status',
     default: '0',
   })
   status: string;

+ 2 - 0
src/entity/user/company.entity.ts

@@ -77,4 +77,6 @@ export class Company extends BaseModel {
     default: '0',
   })
   status: string;
+  @prop({ required: false, index: true, zh: '角色' })
+  role: Array<any>;
 }

+ 2 - 0
src/entity/user/expert.entity.ts

@@ -85,4 +85,6 @@ export class Expert extends BaseModel {
   status: string;
   @prop({ required: false, index: true, zh: '个人用户id' })
   personal_id: string;
+  @prop({ required: false, index: true, zh: '角色' })
+  role: Array<any>;
 }

+ 2 - 0
src/entity/user/personal.entity.ts

@@ -61,4 +61,6 @@ export class Personal extends BaseModel {
     default: '0',
   })
   status: string;
+  @prop({ required: false, index: true, zh: '角色' })
+  role: Array<any>;
 }

+ 5 - 0
src/interface/system/dictData.interface.ts

@@ -24,6 +24,8 @@ export class FVO_dictData {
   'sort': number = undefined;
   @ApiProperty({ description: '是否启用' })
   'is_use': string = undefined;
+  @ApiProperty({ description: '子数据' })
+  'children': Array<any> = undefined;
 }
 
 export class QDTO_dictData extends SearchBase {
@@ -68,6 +70,9 @@ export class CDTO_dictData {
   @ApiProperty({ description: '是否启用' })
   @Rule(RuleType['string']().empty(''))
   'is_use': string = undefined;
+  @ApiProperty({ description: '子数据' })
+  @Rule(RuleType['array']().empty(''))
+  'children': Array<any> = undefined;
 }
 
 export class CVO_dictData extends FVO_dictData {

+ 8 - 13
src/interface/user/company.interface.ts

@@ -62,6 +62,8 @@ export class FVO_company {
   'qualifications': string = undefined;
   @ApiProperty({ description: '状态' })
   'status': string = undefined;
+  @ApiProperty({ description: '角色' })
+  'role': Array<any> = undefined;
 }
 
 export class QDTO_company extends SearchBase {
@@ -81,6 +83,7 @@ export class QDTO_company extends SearchBase {
       'area',
       'institution_code',
       'status',
+      'role',
     ];
     const mapping = [];
     super({ like_prop, props, mapping });
@@ -111,6 +114,8 @@ export class QDTO_company extends SearchBase {
   'institution_code': string = undefined;
   @ApiProperty({ description: '状态' })
   'status': string = undefined;
+  @ApiProperty({ description: '角色' })
+  'role': Array<any> = undefined;
 }
 
 export class QVO_company extends FVO_company {
@@ -193,20 +198,8 @@ export class CDTO_company {
   @ApiProperty({ description: '状态' })
   @Rule(RuleType['string']().empty(''))
   'status': string = undefined;
-}
-export class FetchVO_company {
-  constructor(data: object) {
-    for (const key of Object.keys(this)) {
-      this[key] = get(data, key);
-    }
-  }
-  @ApiProperty({ description: '数据id' })
-  _id: string = undefined;
-  @ApiProperty({ description: '账号' })
-  'account': string = undefined;
-  @ApiProperty({ description: '名称' })
-  'name': string = undefined;
   @ApiProperty({ description: '角色' })
+  @Rule(RuleType['array']().empty(''))
   'role': Array<any> = undefined;
 }
 
@@ -286,6 +279,8 @@ export class LoginVO {
   'qualifications': string = undefined;
   @ApiProperty({ description: '状态' })
   'status': string = undefined;
+  @ApiProperty({ description: '角色' })
+  'role': Array<any> = undefined;
 }
 
 export class LoginDTO {

+ 10 - 0
src/interface/user/expert.interface.ts

@@ -70,6 +70,8 @@ export class FVO_expert {
   'status': string = undefined;
   @ApiProperty({ description: '个人用户id' })
   'personal_id': string = undefined;
+  @ApiProperty({ description: '角色' })
+  'role': Array<any> = undefined;
 }
 
 export class QDTO_expert extends SearchBase {
@@ -85,6 +87,7 @@ export class QDTO_expert extends SearchBase {
       'card',
       'status',
       'personal_id',
+      'role',
     ];
     const mapping = [];
     super({ like_prop, props, mapping });
@@ -107,6 +110,8 @@ export class QDTO_expert extends SearchBase {
   'status': string = undefined;
   @ApiProperty({ description: '个人用户id' })
   'personal_id': string = undefined;
+  @ApiProperty({ description: '角色' })
+  'role': Array<any> = undefined;
 }
 
 export class QVO_expert extends FVO_expert {
@@ -201,6 +206,9 @@ export class CDTO_expert {
   @ApiProperty({ description: '个人用户id' })
   @Rule(RuleType['string']().empty(''))
   'personal_id': string = undefined;
+  @ApiProperty({ description: '角色' })
+  @Rule(RuleType['array']().empty(''))
+  'role': Array<any> = undefined;
 }
 
 export class CVO_expert extends FVO_expert {
@@ -287,6 +295,8 @@ export class LoginVO {
   'status': string = undefined;
   @ApiProperty({ description: '个人用户id' })
   'personal_id': string = undefined;
+  @ApiProperty({ description: '角色' })
+  'role': Array<any> = undefined;
 }
 
 export class LoginDTO {

+ 10 - 0
src/interface/user/personal.interface.ts

@@ -46,6 +46,8 @@ export class FVO_personal {
   'major': string = undefined;
   @ApiProperty({ description: '状态' })
   'status': string = undefined;
+  @ApiProperty({ description: '角色' })
+  'role': Array<any> = undefined;
 }
 
 export class QDTO_personal extends SearchBase {
@@ -68,6 +70,7 @@ export class QDTO_personal extends SearchBase {
       'school',
       'major',
       'status',
+      'role',
     ];
     const mapping = [];
     super({ like_prop, props, mapping });
@@ -104,6 +107,8 @@ export class QDTO_personal extends SearchBase {
   'major': string = undefined;
   @ApiProperty({ description: '状态' })
   'status': string = undefined;
+  @ApiProperty({ description: '角色' })
+  'role': Array<any> = undefined;
 }
 
 export class QVO_personal extends FVO_personal {
@@ -162,6 +167,9 @@ export class CDTO_personal {
   @ApiProperty({ description: '状态' })
   @Rule(RuleType['string']().empty(''))
   'status': string = undefined;
+  @ApiProperty({ description: '角色' })
+  @Rule(RuleType['array']().empty(''))
+  'role': Array<any> = undefined;
 }
 
 export class CVO_personal extends FVO_personal {
@@ -224,6 +232,8 @@ export class LoginVO {
   'major': string = undefined;
   @ApiProperty({ description: '状态' })
   'status': string = undefined;
+  @ApiProperty({ description: '角色' })
+  'role': Array<any> = undefined;
 }
 
 export class LoginDTO {

+ 8 - 0
src/service/technology/dock.service.ts

@@ -27,4 +27,12 @@ export class DockService extends BaseService<modelType> {
       throw new ServiceError('密码错误', FrameworkErrorEnum.SERVICE_FAULT);
     return user;
   }
+  async beforeCreate(body) {
+    const last = await this.model.findOne().sort({ room_id: -1 });
+    let room_id: any = '1001';
+    if (last) room_id = parseInt(last.room_id) + 1;
+    body.room_id = room_id;
+    body.password = { secret: room_id };
+    return body;
+  }
 }

+ 76 - 0
src/service/util/rabbitMq.ts

@@ -0,0 +1,76 @@
+import {
+  Consumer,
+  MSListenerType,
+  RabbitMQListener,
+  Inject,
+} from '@midwayjs/core';
+import { Context } from '@midwayjs/rabbitmq';
+import { ConsumeMessage } from 'amqplib';
+
+@Consumer(MSListenerType.RABBITMQ)
+export class rabbitMqService {
+  @Inject()
+  ctx: Context;
+
+  @RabbitMQListener('tasks')
+  async gotData(msg: ConsumeMessage) {
+    this.ctx.channel.ack(msg);
+  }
+
+  // // 接收消息
+  // async receiveQueueMsg(ex) {
+  //   this.ctx.logger.info('调用mq的' + ex);
+  //   const { mq } = this.ctx;
+  //   if (mq) {
+  //     const ch = await mq.conn.createChannel();
+  //     await ch.assertExchange(ex, 'topic', { durable: true });
+  //     const q = await ch.assertQueue('', { exclusive: true });
+  //     await ch.bindQueue(q.queue, ex, '*');
+  //     await ch.consume(q.queue, msg => this.logMessage(msg), {
+  //       noAck: true,
+  //     });
+  //   } else {
+  //     this.ctx.logger.error('!!!!!!没有配置MQ插件!!!!!!');
+  //   }
+  // }
+
+  // async logMessage(msg) {
+  //   const result = msg.content.toString();
+  //   const headers = msg.properties.headers;
+  // }
+
+  // // mission队列处理
+  // async mission() {
+  //   const { mq } = this.ctx;
+  //   if (mq) {
+  //     const ch = await mq.conn.createChannel();
+  //     const queue = 'mission/market';
+  //     try {
+  //       // 创建队列:在没有队列的情况,直接获取会导致程序无法启动
+  //       await ch.assertQueue(queue, { durable: false });
+  //       await ch.consume(queue, msg => this.dealMission(msg), { noAck: true });
+  //     } catch (error) {
+  //       this.ctx.logger.error('未找到订阅的队列');
+  //     }
+  //   } else {
+  //     this.ctx.logger.error('!!!!!!没有配置MQ插件!!!!!!');
+  //   }
+  // }
+  // // 执行任务
+  // async dealMission(bdata) {
+  //   if (!bdata) this.ctx.logger.error('mission队列中信息不存在');
+  //   let data = bdata.content.toString();
+  //   try {
+  //     data = JSON.parse(data);
+  //   } catch (error) {
+  //     this.ctx.logger.error('数据不是object');
+  //   }
+  //   const { service, method, project, ...others } = data;
+  //   const arr = service.split('.');
+  //   let s = this.ctx.service;
+  //   for (const key of arr) {
+  //     s = s[key];
+  //   }
+  //   s[method](others);
+  // }
+}