zs 8 месяцев назад
Родитель
Сommit
443acceabf

+ 2 - 1
src/controller/system/tags.controller.ts

@@ -21,8 +21,9 @@ export class TagsController implements BaseController {
   @ApiResponse({ type: QVO_tags })
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
-    const others = pick(query, ['skip', 'limit']);
+    const others: any = pick(query, ['skip', 'limit']);
     const qbr = this.service.queryBuilder(qobj);
+    others.order = { num: 'ASC' };
     const result = await this.service.query(qbr, others);
     return result;
   }

+ 2 - 0
src/entity/system/tags.entity.ts

@@ -9,6 +9,8 @@ export class Tags extends BaseModel {
   sort: number;
   @Column({ type: 'character varying', nullable: true, comment: '备注' })
   remark: string;
+  @Column({ type: 'integer', nullable: true, comment: '搜索次数' })
+  num: number;
   @Column({ type: 'character varying', nullable: true, comment: '是否使用', default: '0' })
   is_use: string;
 }

+ 4 - 1
src/frame/BaseService.ts

@@ -1,5 +1,5 @@
 import { Application, Context } from '@midwayjs/koa';
-import { Repository } from 'typeorm';
+import { Like, Repository } from 'typeorm';
 import * as toqm from 'typeorm';
 import { get, isNull, isObject, isUndefined, pick } from 'lodash';
 import { App, Inject } from '@midwayjs/core';
@@ -48,6 +48,9 @@ export abstract class BaseService<T> {
     let builder;
     if ('tags' in findOpera) {
       const column = get(findOpera, 'tags');
+      // 修改搜索量
+      const tag: any = await this.tModel.findOne({ where: { title: Like(`%${column}%`) } });
+      if (tag) await this.tModel.update({ id: get(tag, 'id') }, { num: tag.num || 0 + 1 });
       delete findOpera.tags;
       builder = await this.model.createQueryBuilder().setFindOptions({ where: findOpera, skip, take: limit, order: orderObject }).where('JSONB_EXISTS(tags, :column)', { column });
     } else {

+ 7 - 0
src/interface/system/tags.interface.ts

@@ -12,6 +12,8 @@ export class FVO_tags {
   'title': string = undefined;
   @ApiProperty({ description: '排序' })
   'sort': number = undefined;
+  @ApiProperty({ description: '搜索次数' })
+  'number': number = undefined;
   @ApiProperty({ description: '备注' })
   'remark': string = undefined;
   @ApiProperty({ description: '是否使用' })
@@ -21,6 +23,8 @@ export class FVO_tags {
 export class QDTO_tags extends SearchBase {
   @ApiProperty({ description: '标题' })
   'title': string = undefined;
+  @ApiProperty({ description: '搜索次数' })
+  'number': number = undefined;
   @ApiProperty({ description: '是否使用' })
   'is_use': string = undefined;
 }
@@ -39,6 +43,9 @@ export class CDTO_tags {
   @ApiProperty({ description: '排序' })
   @Rule(RuleType['number']().empty(''))
   'sort': number = undefined;
+  @ApiProperty({ description: '搜索次数' })
+  @Rule(RuleType['number']().empty(''))
+  'num': number = undefined;
   @ApiProperty({ description: '备注' })
   @Rule(RuleType['string']().empty(''))
   'remark': string = undefined;