zs 1 年之前
父节点
当前提交
5e82b106bd
共有 3 个文件被更改,包括 49 次插入0 次删除
  1. 9 0
      src/controller/User.controller.ts
  2. 3 0
      src/interface/User.interface.ts
  3. 37 0
      src/service/user.service.ts

+ 9 - 0
src/controller/User.controller.ts

@@ -109,6 +109,15 @@ export class UserController extends BaseController {
     return { data, total };
   }
 
+  @Get('/queryInfo')
+  @ApiQuery({ name: 'queryInfo' })
+  async queryInfo(@Query() filter: any) {
+    const list: any = await this.service.queryInfo(filter);
+    const data = list.list;
+    const total = list.total;
+    return { data, total };
+  }
+
   @Get('/openid')
   @ApiResponse({ type: FVO_User })
   async wxLogin(@Query('openid') openid: string) {

+ 3 - 0
src/interface/User.interface.ts

@@ -47,6 +47,7 @@ export class QDTO_User extends SearchBase {
       'gender',
       'role',
       'street',
+      'community',
       'openid',
       'status',
     ];
@@ -63,6 +64,8 @@ export class QDTO_User extends SearchBase {
   'role': string = undefined;
   @ApiProperty({ description: '所属街道' })
   'street': string = undefined;
+  @ApiProperty({ description: '所属社区' })
+  'community': string = undefined;
   @ApiProperty({ description: '微信id' })
   'openid': string = undefined;
   @ApiProperty({ description: '状态' })

+ 37 - 0
src/service/user.service.ts

@@ -9,12 +9,16 @@ import {
 import { User } from '../entity/User.entity';
 import isEqual = require('lodash/isEqual');
 import { LoginDTO } from '../interface/User.interface';
+import { Office } from '../entity/Office.entity';
 type modelType = ReturnModelType<typeof User>;
 @Provide()
 export class UserService extends BaseService<modelType> {
   @InjectEntityModel(User)
   model: modelType;
 
+  @InjectEntityModel(Office)
+  offModel: ReturnModelType<typeof Office>;
+
   async findUserToLogin(data: LoginDTO): Promise<object> {
     const { tel, password } = data;
     const user = await this.model.findOne({ tel }, '+password').lean();
@@ -56,4 +60,37 @@ export class UserService extends BaseService<modelType> {
       );
     return user;
   }
+
+  async queryInfo(filter): Promise<object> {
+    const { skip = 0, limit, street, ...info } = filter;
+    let list: any = [];
+    let total: any = 0;
+    if (street) {
+      const res = await this.offModel.aggregate([
+        {
+          $match: { belong: street },
+        },
+        {
+          $project: {
+            _id: {
+              $toString: '$_id',
+            },
+          },
+        },
+      ]);
+      const belongList: any = [
+        { street: street },
+        { role: 'jdry' },
+        { role: 'sqry' },
+      ];
+      for (const val of res) {
+        const info = { community: val._id };
+        belongList.push(info);
+      }
+      info.$or = belongList;
+    }
+    list = await this.model.find(info).skip(skip).limit(limit).lean();
+    total = await this.model.count(info);
+    return { list, total };
+  }
 }