lrf преди 8 месеца
родител
ревизия
6e02bdb281

+ 64 - 0
src/controller/system/message.controller.ts

@@ -0,0 +1,64 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from "@midwayjs/core";
+import { ApiQuery, ApiTags } from "@midwayjs/swagger";
+import { BaseController } from "../../frame/BaseController";
+import { Validate } from "@midwayjs/validate";
+import { omit, pick } from "lodash";
+import { ServiceError, ErrorCode } from "../../error/service.error";
+import { FVO_region, CVO_region } from "../../interface/system/region.interface";
+import { MessageService } from "../../service/system/message.service";
+
+
+const namePrefix = '消息';
+@ApiTags(['消息'])
+@Controller('/message', { tagName: namePrefix })
+export class RegionController implements BaseController {
+  controllerCode = 'system_message';
+  @Inject()
+  service: MessageService;
+
+  @Get('/')
+  @ApiTags('列表查询')
+  @ApiQuery({ name: 'query' })
+  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('单查询')
+  async fetch(@Param('id') id: number) {
+    const data = await this.service.fetch({ id });
+    const result = new FVO_region(data);
+    return result;
+  }
+
+  @Post('/', { routerName: `创建${namePrefix}` })
+  @ApiTags('创建数据')
+  @Validate()
+  async create(@Body() data: object) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_region(dbData);
+    return result;
+  }
+
+  @Post('/:id', { routerName: `修改${namePrefix}` })
+  @ApiTags('修改数据')
+  @Validate()
+  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);
+    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;
+  }
+
+}

+ 19 - 0
src/entity/system/message.entity.ts

@@ -0,0 +1,19 @@
+import { Column, Entity } from 'typeorm';
+import { BaseModel } from '../../frame/BaseModel';
+
+class toModel {
+  user: string; // 用户id
+  user_nick_name: string; //用户名称
+  user_type: string; //用户类型(管理员admin/站内用户user)
+  is_read: string; // 是否阅读: 0否;1是
+}
+
+@Entity('message')
+export class Message extends BaseModel {
+  @Column({ type: 'text', nullable: true, comment: '消息内容' })
+  content: string;
+  @Column({ type: 'jsonb', default: [], comment: '发送对象' })
+  to: Array<toModel>;
+  @Column({ type: 'character varying', nullable: true, comment: '消息类型' })
+  type: string; // 审核消息, 通知消息, 业务消息
+}

+ 5 - 1
src/event/dbSubscriber.ts

@@ -89,6 +89,10 @@ export class DbSubscriber implements EntitySubscriberInterface {
     const url = `${this.esServiceHttpPrefix}/sync`;
     tableName = toLower(tableName);
     const body = { index: tableName, data, method };
-    await Axios.post(url, body, { responseType: 'json' });
+    try {
+      await Axios.post(url, body, { responseType: 'json' });
+    } catch (error) {
+      console.log(error)
+    }
   }
 }

+ 14 - 0
src/service/system/message.service.ts

@@ -0,0 +1,14 @@
+import { Provide } from "@midwayjs/core";
+import { InjectEntityModel } from "@midwayjs/typeorm";
+import { Repository } from "typeorm";
+import { Message } from "../../entity/system/message.entity";
+import { BaseServiceV2 } from "../../frame/BaseServiceV2";
+
+@Provide()
+export class MessageService extends BaseServiceV2 {
+  @InjectEntityModel(Message)
+  model: Repository<Message>;
+  getQueryColumnsOpera() {
+    return { 'to.user': this.Opera.JsonObject };
+  }
+}

+ 3 - 1
src/service/system/user.service.ts

@@ -9,7 +9,9 @@ import { get } from 'lodash';
 export class UserService extends BaseServiceV2 {
   @InjectEntityModel(User)
   model: Repository<User>;
-
+  getQueryColumnsOpera() {
+    return { nick_name: this.Opera.Like };
+  }
   async createBefore(data) {
     const { role } = data;
     if (role && role.length > 1) data.status = '0';