zs 1 year ago
parent
commit
50f859759f

+ 2 - 2
src/configuration.ts

@@ -58,7 +58,7 @@ export class MainConfiguration {
   async onServerReady?(container: IMidwayContainer, app: IMidwayApplication) {
     // 初始化es
     const esService = await container.getAsync(ElasticsearchService);
-    await esService.preparMapping();
-    await container.getAsync(DBService);
+    // await esService.preparMapping();
+    // await container.getAsync(DBService);
   }
 }

+ 1 - 1
src/controller/login.controller.ts

@@ -29,7 +29,7 @@ export class LoginController {
    * @param data 用户名和密码
    * @param type 用户类型
    */
-  @Post('/:type', { description: 'ignore' })
+  @Post('/:type')
   async toLogin(@Body() data: LoginDTO, @Param('type') type: string) {
     const user = await this.loginService.loginByAccount(data, LoginType[type]);
     if (type === 'Admin') user.role = [type];

+ 16 - 0
src/controller/platform/supply.controller.ts

@@ -32,6 +32,22 @@ export class SupplyController extends BaseController {
     return { data, total };
   }
 
+  @Get('/list')
+  async list() {
+    const list = await this.service.list(this.ctx.filter);
+    const data = list.data;
+    const total = list.total;
+    return { data, total };
+  }
+
+
+  @Get('/detail/:id')
+  @ApiResponse({ type: FVO_supply })
+  async detail(@Param('id') id: string) {
+    const data = await this.service.detail(id);
+    return data;
+  }
+
   @Get('/:id')
   @ApiResponse({ type: FVO_supply })
   async fetch(@Param('id') id: string) {

+ 1 - 1
src/controller/platform/tags.controller.ts

@@ -18,7 +18,7 @@ export class TagsController extends BaseController {
     const result = new CVO_tags(dbData);
     return result;
   }
-  @Get('/', { description: 'ignore' })
+  @Get('/')
   @ApiQuery({ name: 'query' })
   @ApiResponse({ type: QVO_tags })
   async query(@Query() filter: QDTO_tags, @Query('skip') skip: number, @Query('limit') limit: number) {

+ 1 - 1
src/middleware/checkOnePointLogin.middleware.ts

@@ -15,7 +15,7 @@ export class CheckOnePointLoginMiddleware implements IMiddleware<Context, NextFu
         return
       }
       const desc = routeInfo.description;
-      if (desc !== 'ignore') {
+      if (desc === 'ignore') {
         const loginService = await ctx.requestContext.getAsync(LoginService);
         await loginService.onePointCheck();
       }

+ 4 - 3
src/queue/esSync.queue.ts

@@ -5,9 +5,9 @@ import { difference, differenceBy, get, intersection, isObject } from 'lodash';
 import { ElasticsearchService } from '../service/elasticsearch';
 import { FORMAT } from '@midwayjs/core';
 @Processor('esSync', {
-  repeat: {
-    cron: FORMAT.CRONTAB.EVERY_MINUTE,
-  },
+  // repeat: {
+  //   cron: FORMAT.CRONTAB.EVERY_MINUTE,
+  // },
 })
 export class EsSyncProcessor implements IProcessor {
   @Inject()
@@ -15,6 +15,7 @@ export class EsSyncProcessor implements IProcessor {
   @Inject()
   es: ElasticsearchService;
   async execute() {
+    return false;
     // ...
     console.log('in es sync processor');
     const result = await this.dataRecord.noDealQuery({ es_sync: false });

+ 44 - 0
src/service/platform/supply.service.ts

@@ -3,9 +3,53 @@ import { InjectEntityModel } from '@midwayjs/typegoose';
 import { ReturnModelType } from '@typegoose/typegoose';
 import { BaseService } from 'free-midway-component';
 import { Supply } from '../../entity/platform/supply.entity';
+import { Collection } from '../../entity/platform/collection.entity';
+import { User } from '../../entity/system/user.entity';
+import { get } from 'lodash';
 type modelType = ReturnModelType<typeof Supply>;
 @Provide()
 export class SupplyService extends BaseService<modelType> {
   @InjectEntityModel(Supply)
   model: modelType;
+  @InjectEntityModel(Collection)
+  cModel: ReturnModelType<typeof Collection>;
+  @InjectEntityModel(User)
+  uModel: ReturnModelType<typeof User>;
+  // 需求列表
+  async list(query) {
+    const { skip = 0, limit = 0, is_use, status, ...condition } = query;
+    const { one, two, thr, four } = condition;
+    const info: any = { is_use, status };
+    if (one) info.field = { $in: one };
+    if (two) info.method = { $in: two };
+    if (thr) info.area = { $in: thr };
+    if (four) info.demand_status = { $in: four };
+    const data = await this.model.find(info).skip(skip).limit(limit).lean();
+    for (const val of data) {
+      if (get(val, 'user')) {
+        // 查询需求发布者
+        const userData = await this.uModel.findById(val.user).lean();
+        if (userData) Object.assign(val, { userName: userData.nick_name });
+      }
+    }
+    const total = await this.model.count(info);
+    return { data, total };
+  }
+  // 需求详情
+  async detail(id) {
+    const user = this.ctx.user;
+    const data = { userInfo: {}, is_collection: false };
+    const arr = await this.model.findById(id).lean();
+    if (arr && get(arr, 'user')) {
+      // 查询需求发布者
+      const userData = await this.uModel.findById(arr.user).lean();
+      if (userData) data.userInfo = { name: userData.nick_name || '', phone: userData.phone || '' };
+    }
+    if (arr && get(arr, '_id')) {
+      // 查询是否收藏该需求
+      const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
+      if (collection) data.is_collection = true;
+    }
+    return { ...arr, ...data };
+  }
 }