zs 1 年之前
父节点
当前提交
a370cdd026
共有 2 个文件被更改,包括 22 次插入1 次删除
  1. 10 0
      src/controller/system/brand.controller.ts
  2. 12 1
      src/service/system/brand.service.ts

+ 10 - 0
src/controller/system/brand.controller.ts

@@ -4,6 +4,7 @@ import { BrandService } from '../../service/system/brand.service';
 import { CDTO_brand, CVO_brand, FVO_brand, QDTO_brand, QVO_brand, UDTO_brand, UVAO_brand } from '../../interface/system/brand.interface';
 import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
+import get = require('lodash/get');
 @ApiTags(['品牌'])
 @Controller('/brand')
 export class BrandController extends BaseController {
@@ -32,6 +33,15 @@ export class BrandController extends BaseController {
     return { data, total };
   }
 
+  @Get('/index')
+  @ApiQuery({ name: 'queryIndex' })
+  async queryIndex() {
+    const list = await this.service.queryIndex();
+    const data1 = get(list, 'data1');
+    const data2 = get(list, 'data2');
+    return { data1, data2 };
+  }
+
   @Get('/:id')
   @ApiResponse({ type: FVO_brand })
   async fetch(@Param('id') id: string) {

+ 12 - 1
src/service/system/brand.service.ts

@@ -8,4 +8,15 @@ type modelType = ReturnModelType<typeof Brand>;
 export class BrandService extends BaseService<modelType> {
   @InjectEntityModel(Brand)
   model: modelType;
-}
+
+  async queryIndex() {
+    const list = await this.model.aggregate([{ $match: { is_use: '0' } }, { $sort: { letter: 1 } }, { $group: { _id: '$letter', data: { $addToSet: '$$ROOT' } } }]);
+    const data1 = [];
+    const data2 = [];
+    for (const val of list) {
+      data1.push(val.data);
+      data2.push(val._id);
+    }
+    return { data1, data2 };
+  }
+}