Jelajahi Sumber

修改多条件查询

zs 8 bulan lalu
induk
melakukan
c6cce90722

+ 13 - 9
src/controller/platform/achievement.controller.ts

@@ -4,7 +4,7 @@ import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
 import { BaseController } from '../../frame/BaseController';
 import { ErrorCode, ServiceError } from '../../error/service.error';
-import { get, omit, pick } from 'lodash';
+import { omit, pick } from 'lodash';
 import { Controller, Inject, Get, Param, Post, Body, Del, Query } from '@midwayjs/core';
 import { Context } from '@midwayjs/koa';
 import { ServiceUtilService } from '../../service/serviceUtil.service';
@@ -70,6 +70,18 @@ export class AchievementController implements BaseController {
     return result;
   }
 
+  @Get('/list')
+  async list(@Query() query: object) {
+    const qobj = omit(query, ['skip', 'limit']);
+    const others = pick(query, ['skip', 'limit']);
+    const filter = await this.service.money(qobj);
+    const { data, total } = await this.service.query(filter, others);
+    for (const i of data) {
+      await this.serviceUtil.fillOnwer(i);
+    }
+    return { data, total };
+  }
+
   @Get('/detail/:id')
   @ApiResponse({ type: FVO_achievement })
   async detail(@Param('id') id: string) {
@@ -78,12 +90,4 @@ export class AchievementController implements BaseController {
     await this.serviceUtil.fillCollection(data);
     return data;
   }
-
-  @Get('/list')
-  async list() {
-    const list = await this.service.list(this.ctx.query);
-    const data = list.data;
-    const total = list.total;
-    return { data, total };
-  }
 }

+ 4 - 4
src/controller/platform/footplate.controller.ts

@@ -29,10 +29,10 @@ export class FootplateController implements BaseController {
   }
 
   @Get('/list')
-  async list() {
-    const list = await this.service.list(this.ctx.query);
-    const data = list.data;
-    const total = list.total;
+  async list(@Query() query: object) {
+    const qobj = omit(query, ['skip', 'limit']);
+    const others = pick(query, ['skip', 'limit']);
+    const { data, total } = await this.service.query(qobj, others);
     return { data, total };
   }
 

+ 3 - 1
src/controller/platform/match.controller.ts

@@ -63,10 +63,12 @@ export class MatchController implements BaseController {
     const result = await this.service.delete({ id });
     return result;
   }
+
   @Get('/detail/:id')
   @ApiResponse({ type: FVO_match })
   async detail(@Param('id') id: string) {
-    const data = await this.service.detail(id);
+    const data = await this.service.fetch({ id });
+    await this.serviceUtil.fillOnwer(data);
     await this.serviceUtil.fillCollection(data);
     return data;
   }

+ 8 - 4
src/controller/platform/project.controller.ts

@@ -69,12 +69,16 @@ export class ProjectController implements BaseController {
   }
 
   @Get('/list')
-  async list() {
-    const list = await this.service.list(this.ctx.query);
-    const data = list.data;
-    const total = list.total;
+  async list(@Query() query: object) {
+    const qobj = omit(query, ['skip', 'limit']);
+    const others = pick(query, ['skip', 'limit']);
+    const { data, total } = await this.service.query(qobj, others);
+    for (const i of data) {
+      await this.serviceUtil.fillOnwer(i);
+    }
     return { data, total };
   }
+
   @Get('/detail/:id')
   @ApiResponse({ type: FVO_project })
   async detail(@Param('id') id: string) {

+ 7 - 4
src/controller/platform/supply.controller.ts

@@ -69,10 +69,13 @@ export class SupplyController implements BaseController {
   }
 
   @Get('/list')
-  async list() {
-    const list = await this.service.list(this.ctx.query);
-    const data = list.data;
-    const total = list.total;
+  async list(@Query() query: object) {
+    const qobj = omit(query, ['skip', 'limit']);
+    const others = pick(query, ['skip', 'limit']);
+    const { data, total } = await this.service.query(qobj, others);
+    for (const i of data) {
+      await this.serviceUtil.fillOnwer(i);
+    }
     return { data, total };
   }
 

+ 4 - 4
src/controller/platform/support.controller.ts

@@ -29,10 +29,10 @@ export class SupportController implements BaseController {
   }
 
   @Get('/list')
-  async list() {
-    const list = await this.service.list(this.ctx.query);
-    const data = list.data;
-    const total = list.total;
+  async list(@Query() query: object) {
+    const qobj = omit(query, ['skip', 'limit']);
+    const others = pick(query, ['skip', 'limit']);
+    const { data, total } = await this.service.query(qobj, others);
     return { data, total };
   }
 

+ 20 - 15
src/controller/users/company.controller.ts

@@ -45,21 +45,6 @@ export class CompanyController implements BaseController {
     return result;
   }
 
-  @Get('/list')
-  async list() {
-    const list = await this.service.list(this.ctx.query);
-    const data = list.data;
-    const total = list.total;
-    return { data, total };
-  }
-  @Get('/detail/:id')
-  @ApiResponse({ type: FVO_company })
-  async detail(@Param('id') id: string) {
-    const data = await this.service.fetch({ id });
-    await this.serviceUtil.fillCollection(data)
-    return data;
-  }
-
   @Post('/', { routerName: `创建${namePrefix}` })
   @ApiTags('创建数据')
   @Validate()
@@ -89,4 +74,24 @@ export class CompanyController implements BaseController {
     const result = await this.service.delete({ id });
     return result;
   }
+
+  @Get('/list')
+  async list(@Query() query: object) {
+    const qobj = omit(query, ['skip', 'limit']);
+    const others = pick(query, ['skip', 'limit']);
+    const { data, total } = await this.service.query(qobj, others);
+    for (const i of data) {
+      await this.serviceUtil.fillOnwer(i);
+    }
+    return { data, total };
+  }
+
+  @Get('/detail/:id')
+  @ApiResponse({ type: FVO_company })
+  async detail(@Param('id') id: string) {
+    const data = await this.service.fetch({ id });
+    await this.serviceUtil.fillOnwer(data);
+    await this.serviceUtil.fillCollection(data);
+    return data;
+  }
 }

+ 20 - 14
src/controller/users/expert.controller.ts

@@ -33,13 +33,6 @@ export class ExpertController implements BaseController {
     const result = await this.service.query(qobj, others);
     return result;
   }
-  @Get('/list')
-  async list() {
-    const list = await this.service.list(this.ctx.query);
-    const data = list.data;
-    const total = list.total;
-    return { data, total };
-  }
 
   @Get('/:id')
   @ApiTags('单查询')
@@ -49,13 +42,6 @@ export class ExpertController implements BaseController {
     const result = new FVO_expert(data);
     return result;
   }
-  @Get('/detail/:id')
-  @ApiResponse({ type: FVO_expert })
-  async detail(@Param('id') id: string) {
-    const data = await this.service.fetch({ id });
-    await this.serviceUtil.fillCollection(data)
-    return data;
-  }
 
   @Post('/', { routerName: `创建${namePrefix}` })
   @ApiTags('创建数据')
@@ -86,4 +72,24 @@ export class ExpertController implements BaseController {
     const result = await this.service.delete({ id });
     return result;
   }
+
+  @Get('/list')
+  async list(@Query() query: object) {
+    const qobj = omit(query, ['skip', 'limit']);
+    const others = pick(query, ['skip', 'limit']);
+    const { data, total } = await this.service.query(qobj, others);
+    for (const i of data) {
+      await this.serviceUtil.fillOnwer(i);
+    }
+    return { data, total };
+  }
+
+  @Get('/detail/:id')
+  @ApiResponse({ type: FVO_expert })
+  async detail(@Param('id') id: string) {
+    const data = await this.service.fetch({ id });
+    await this.serviceUtil.fillOnwer(data);
+    await this.serviceUtil.fillCollection(data);
+    return data;
+  }
 }

+ 2 - 2
src/frame/BaseServiceV2.ts

@@ -111,6 +111,8 @@ export abstract class BaseServiceV2 {
       let params;
       // 需要给变量位置重命名,否则多个条件叠加后,都会使用第一个参数
       const valueStr = `value${i}`;
+      let valueArr = [];
+      const strArr = [];
       switch (opera) {
         case this.Opera.Between:
           str = `"${key}" Between :${valueStr}_1 AND :${valueStr}_2`;
@@ -173,8 +175,6 @@ export abstract class BaseServiceV2 {
           params = { [`${valueStr}`]: value };
           break;
         case this.Opera.Json:
-          let valueArr = [];
-          let strArr = [];
           params = {};
           if (isArray(value)) valueArr = value;
           else valueArr = [value];

+ 20 - 60
src/service/platform/achievement.service.ts

@@ -1,19 +1,25 @@
 import { Achievement } from '../../entity/platform/achievement.entity';
-import { Collection } from '../../entity/platform/collection.entity';
-import { User } from '../../entity/system/user.entity';
-import { get, isArray } from 'lodash';
+import { isArray } from 'lodash';
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
-import { Between, Equal, In, Like, MoreThanOrEqual, Repository } from 'typeorm';
+import { Between, Equal, In, MoreThanOrEqual, Repository } from 'typeorm';
 import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
 export class AchievementService extends BaseServiceV2 {
   @InjectEntityModel(Achievement)
   model: Repository<Achievement>;
-  @InjectEntityModel(Collection)
-  cModel: Repository<Collection>;
-  @InjectEntityModel(User)
-  uModel: Repository<User>;
+
+  getQueryColumnsOpera() {
+    const obj = {
+      name: this.Opera.Like,
+      industry: this.Opera.In,
+      field: this.Opera.In,
+      sell: this.Opera.In,
+      mature: this.Opera.In,
+      area: this.Opera.Json,
+    };
+    return obj;
+  }
 
   // 加浏览量
   async fetchBrowse(data) {
@@ -21,31 +27,9 @@ export class AchievementService extends BaseServiceV2 {
     await this.model.update({ id }, { num: num + 1 });
   }
 
-  // 多条件查询列表
-  async list(query) {
-    const { skip = 0, limit = 0, is_use, status, name, area, field, industry, mature, money, sell, ...condition } = query;
-    const whereObject: any = condition;
-    if (name) whereObject.name = { name: Like(`%${name}%`) };
-    if (industry) {
-      if (!isArray(industry)) whereObject.industry = Equal(industry);
-      else whereObject.industry = In(industry);
-    }
-    if (field) {
-      if (!isArray(field)) whereObject.field = Equal(field);
-      else whereObject.field = In(field);
-    }
-    if (sell) {
-      if (!isArray(sell)) whereObject.sell = Equal(sell);
-      else whereObject.sell = In(sell);
-    }
-    if (mature) {
-      if (!isArray(mature)) whereObject.mature = Equal(mature);
-      else whereObject.mature = In(mature);
-    }
-    if (area) {
-      if (!isArray(area)) whereObject.area = Equal(area);
-      else whereObject.area = In(area);
-    }
+  // 处理金钱
+  async money(filter) {
+    const { money, ...info } = filter;
     if (money) {
       if (!isArray(money)) {
         let money_title;
@@ -56,7 +40,7 @@ export class AchievementService extends BaseServiceV2 {
         if (money === '5') money_title = Between('100', '500');
         if (money === '6') money_title = Between('500', '1000');
         if (money === '7') money_title = MoreThanOrEqual('1000');
-        whereObject.money = money_title;
+        info.money = money_title;
       } else {
         const moneylist = [];
         for (const val of money) {
@@ -68,33 +52,9 @@ export class AchievementService extends BaseServiceV2 {
           if (val === '6') moneylist.push(Between('500', '1000'));
           if (val === '7') moneylist.push(MoreThanOrEqual('1000'));
         }
-        whereObject.money = In(moneylist);
+        info.money = In(moneylist);
       }
     }
-    const builder = this.model.createQueryBuilder().setFindOptions({ where: whereObject, skip, take: limit });
-    const data = await builder.getMany();
-    const total = await builder.getCount();
-    return { data, total };
-  }
-
-  // 成果详情
-  async detail(id) {
-    const user = this.ctx.user;
-    const data = { userInfo: {}, is_collection: false };
-    const arr = await this.model.findOne({ where: { id: Equal(id) } });
-    if (arr && get(arr, 'user')) {
-      // 查询成果发布者
-      // const userData = await this.uModel.findById(arr.user).lean();
-      const userData = await this.uModel.findOne({ where: { id: Equal(arr.user) } });
-      if (userData) data.userInfo = { name: userData.nick_name || '', phone: userData.phone || '' };
-    }
-    if (user && get(user, 'id')) {
-      // 查询是否收藏该成果
-      // const collection = await this.cModel.findOne({ user: user._id, source: arr.id }).lean();
-      const collection = await this.cModel.findOne({ where: { user: Equal(user.id), source: Equal(arr.id) } });
-      if (collection) data.is_collection = true;
-    }
-    await this.fetchBrowse(arr);
-    return { ...arr, ...data };
+    return info;
   }
 }

+ 4 - 50
src/service/platform/demand.service.ts

@@ -1,66 +1,20 @@
 import { Demand } from '../../entity/platform/demand.entity';
-import { Collection } from '../../entity/platform/collection.entity';
-import { User } from '../../entity/system/user.entity';
-import { get, isArray } from 'lodash';
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
-import { Equal, In, Like, Repository } from 'typeorm';
+import { Repository } from 'typeorm';
 import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
 export class DemandService extends BaseServiceV2 {
   @InjectEntityModel(Demand)
   model: Repository<Demand>;
-  @InjectEntityModel(Collection)
-  cModel: Repository<Collection>;
-  @InjectEntityModel(User)
-  uModel: Repository<User>;
+
   getQueryColumnsOpera() {
     const obj = {
+      name: this.Opera.Like,
       industry: this.Opera.In,
+      field: this.Opera.In,
       area: this.Opera.Json,
     };
     return obj;
   }
-  // 需求列表
-  async list(query) {
-    const { skip = 0, limit = 0, name, is_use, status, area, field, industry, ...condition } = query;
-    const whereObject: any = condition;
-    if (name) whereObject.name = { name: Like(`%${name}%`) };
-    if (industry) {
-      if (!isArray(industry)) whereObject.industry = Equal(industry);
-      else whereObject.industry = In(industry);
-    }
-    if (field) {
-      if (!isArray(field)) whereObject.field = Equal(field);
-      else whereObject.field = In(field);
-    }
-    if (area) {
-      if (!isArray(area)) whereObject.area = Equal(area);
-      else whereObject.area = In(area);
-    }
-    const builder = this.model.createQueryBuilder().setFindOptions({ where: whereObject, skip, take: limit });
-    const data = await builder.getMany();
-    const total = await builder.getCount();
-    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();
-    const arr = await this.model.findOne({ where: { id: Equal(id) } });
-    if (arr && get(arr, 'user')) {
-      // 查询需求发布者
-      // const userData = await this.uModel.findById(arr.user).lean();
-      const userData = await this.uModel.findOne({ where: { id: arr.user } });
-      if (userData) data.userInfo = { name: userData.nick_name || '', phone: userData.phone || '' };
-    }
-    if (user && get(user, 'id')) {
-      // 查询是否收藏该需求
-      // const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
-      const collection = await this.cModel.findOne({ where: { user: Equal(user.id), source: Equal(arr.id) } });
-      if (collection) data.is_collection = true;
-    }
-    return { ...arr, ...data };
-  }
 }

+ 8 - 19
src/service/platform/footplate.service.ts

@@ -1,30 +1,19 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
-import { In, Equal, Like, Repository } from 'typeorm';
+import { Repository } from 'typeorm';
 import { Footplate } from '../../entity/platform/footplate.entity';
 import { BaseServiceV2 } from '../../frame/BaseServiceV2';
-import { isArray } from 'lodash';
 @Provide()
 export class FootplateService extends BaseServiceV2 {
   @InjectEntityModel(Footplate)
   model: Repository<Footplate>;
 
-  // 多条件查询列表
-  async list(query) {
-    const { skip = 0, limit = 0, name, area, industry, ...condition } = query;
-    const whereObject: any = condition;
-    if (name) whereObject.name = { name: Like(`%${name}%`) };
-    if (industry) {
-      if (!isArray(industry)) whereObject.industry = Equal(industry);
-      else whereObject.industry = In(industry);
-    }
-    if (area) {
-      if (!isArray(area)) whereObject.area = Equal(area);
-      else whereObject.area = In(area);
-    }
-    const builder = this.model.createQueryBuilder().setFindOptions({ where: whereObject, skip, take: limit });
-    const data = await builder.getMany();
-    const total = await builder.getCount();
-    return { data, total };
+  getQueryColumnsOpera() {
+    const obj = {
+      name: this.Opera.Like,
+      industry: this.Opera.In,
+      area: this.Opera.Json,
+    };
+    return obj;
   }
 }

+ 1 - 20
src/service/platform/match.service.ts

@@ -1,29 +1,10 @@
 import { Match } from '../../entity/platform/match.entity';
-import { get } from 'lodash';
-import { Collection } from '../../entity/platform/collection.entity';
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
-import { Equal, Repository } from 'typeorm';
+import { Repository } from 'typeorm';
 import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
 export class MatchService extends BaseServiceV2 {
   @InjectEntityModel(Match)
   model: Repository<Match>;
-  @InjectEntityModel(Collection)
-  cModel: Repository<Collection>;
-
-  // 比赛详情
-  async detail(id) {
-    const user = this.ctx.user;
-    const data = { userInfo: {}, is_collection: false };
-    // const arr = await this.model.findById(id).lean();
-    const arr = await this.model.findOne({ where: { id: Equal(id) } });
-    if (arr && get(arr, 'id') && user) {
-      // 查询是否收藏该比赛
-      // const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
-      const collection = await this.cModel.findOne({ where: { user: Equal(user.id), source: Equal(arr.id) } });
-      if (collection) data.is_collection = true;
-    }
-    return { ...arr, ...data };
-  }
 }

+ 10 - 53
src/service/platform/project.service.ts

@@ -1,64 +1,21 @@
 import { Project } from '../../entity/platform/project.entity';
-import { Collection } from '../../entity/platform/collection.entity';
-import { User } from '../../entity/system/user.entity';
-import { get, isArray } from 'lodash';
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
-import { Equal, In, Like, Repository } from 'typeorm';
+import { Repository } from 'typeorm';
 import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
 export class ProjectService extends BaseServiceV2 {
   @InjectEntityModel(Project)
   model: Repository<Project>;
-  @InjectEntityModel(Collection)
-  cModel: Repository<Collection>;
-  @InjectEntityModel(User)
-  uModel: Repository<User>;
 
-  // 多条件查询列表
-  async list(query) {
-    const { skip = 0, limit = 0, name, is_use, status, area, field, maturity, industry, ...condition } = query;
-    const whereObject: any = condition;
-    if (name) whereObject.name = { name: Like(`%${name}%`) };
-    if (industry) {
-      if (!isArray(industry)) whereObject.industry = Equal(industry);
-      else whereObject.industry = In(industry);
-    }
-    if (field) {
-      if (!isArray(field)) whereObject.field = Equal(field);
-      else whereObject.field = In(field);
-    }
-    if (area) {
-      if (!isArray(area)) whereObject.area = Equal(area);
-      else whereObject.area = In(area);
-    }
-    if (maturity) {
-      if (!isArray(maturity)) whereObject.maturity = Equal(maturity);
-      else whereObject.maturity = In(maturity);
-    }
-    const builder = this.model.createQueryBuilder().setFindOptions({ where: whereObject, skip, take: limit });
-    const data = await builder.getMany();
-    const total = await builder.getCount();
-    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();
-    const arr = await this.model.findOne({ where: { id: Equal(id) } });
-    if (arr && get(arr, 'user')) {
-      // 查询项目发布者
-      // const userData = await this.uModel.findById(arr.user).lean();
-      const userData = await this.uModel.findOne({ where: { id: Equal(arr.user) } });
-      if (userData) data.userInfo = { name: userData.nick_name || '', phone: userData.phone || '' };
-    }
-    if (user && get(user, 'id')) {
-      // 查询是否收藏该项目
-      const collection = await this.cModel.findOne({ where: { user: user.id, source: arr.id } });
-      if (collection) data.is_collection = true;
-    }
-    return { ...arr, ...data };
+  getQueryColumnsOpera() {
+    const obj = {
+      name: this.Opera.Like,
+      industry: this.Opera.In,
+      field: this.Opera.In,
+      maturity: this.Opera.In,
+      area: this.Opera.Json,
+    };
+    return obj;
   }
 }

+ 9 - 50
src/service/platform/supply.service.ts

@@ -1,61 +1,20 @@
 import { Supply } from '../../entity/platform/supply.entity';
-import { Collection } from '../../entity/platform/collection.entity';
-import { User } from '../../entity/system/user.entity';
-import { get, isArray } from 'lodash';
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
-import { Equal, In, Like, Repository } from 'typeorm';
+import { Repository } from 'typeorm';
 import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
 export class SupplyService extends BaseServiceV2 {
   @InjectEntityModel(Supply)
   model: Repository<Supply>;
-  @InjectEntityModel(Collection)
-  cModel: Repository<Collection>;
-  @InjectEntityModel(User)
-  uModel: Repository<User>;
 
-  // 多条件查询列表
-  async list(query) {
-    const { skip = 0, limit = 0, name, is_use, status, area, field, industry, ...condition } = query;
-    const whereObject: any = condition;
-    if (name) whereObject.name = { name: Like(`%${name}%`) };
-    if (industry) {
-      if (!isArray(industry)) whereObject.industry = Equal(industry);
-      else whereObject.industry = In(industry);
-    }
-    if (field) {
-      if (!isArray(field)) whereObject.field = Equal(field);
-      else whereObject.field = In(field);
-    }
-    if (area) {
-      if (!isArray(area)) whereObject.area = Equal(area);
-      else whereObject.area = In(area);
-    }
-    const builder = this.model.createQueryBuilder().setFindOptions({ where: whereObject, skip, take: limit });
-    const data = await builder.getMany();
-    const total = await builder.getCount();
-    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();
-    const arr = await this.model.findOne({ where: { id: Equal(id) } });
-    if (arr && get(arr, 'user')) {
-      // 查询需求发布者
-      // const userData = await this.uModel.findById(arr.user).lean();
-      const userData = await this.uModel.findOne({ where: { id: Equal(arr.user) } });
-      if (userData) data.userInfo = { name: userData.nick_name || '', phone: userData.phone || '' };
-    }
-    if (user && get(user, 'id')) {
-      // 查询是否收藏该需求
-      // const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
-      const collection = await this.cModel.findOne({ where: { user: Equal(user.id), source: Equal(arr.id) } });
-      if (collection) data.is_collection = true;
-    }
-    return { ...arr, ...data };
+  getQueryColumnsOpera() {
+    const obj = {
+      name: this.Opera.Like,
+      industry: this.Opera.In,
+      field: this.Opera.In,
+      area: this.Opera.Json,
+    };
+    return obj;
   }
 }

+ 9 - 23
src/service/platform/support.service.ts

@@ -1,34 +1,20 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
-import { Equal, In, Like, Repository } from 'typeorm';
+import { Repository } from 'typeorm';
 import { Support } from '../../entity/platform/support.entity';
 import { BaseServiceV2 } from '../../frame/BaseServiceV2';
-import { isArray } from 'lodash';
 @Provide()
 export class SupportService extends BaseServiceV2 {
   @InjectEntityModel(Support)
   model: Repository<Support>;
 
-  // 多条件查询列表
-  async list(query) {
-    const { skip = 0, limit = 0, name, area, field, industry, ...condition } = query;
-    const whereObject: any = condition;
-    if (name) whereObject.name = { name: Like(`%${name}%`) };
-    if (industry) {
-      if (!isArray(industry)) whereObject.industry = Equal(industry);
-      else whereObject.industry = In(industry);
-    }
-    if (field) {
-      if (!isArray(field)) whereObject.field = Equal(field);
-      else whereObject.field = In(field);
-    }
-    if (area) {
-      if (!isArray(area)) whereObject.area = Equal(area);
-      else whereObject.area = In(area);
-    }
-    const builder = this.model.createQueryBuilder().setFindOptions({ where: whereObject, skip, take: limit });
-    const data = await builder.getMany();
-    const total = await builder.getCount();
-    return { data, total };
+  getQueryColumnsOpera() {
+    const obj = {
+      name: this.Opera.Like,
+      industry: this.Opera.In,
+      field: this.Opera.In,
+      area: this.Opera.Json,
+    };
+    return obj;
   }
 }

+ 9 - 42
src/service/users/company.service.ts

@@ -1,53 +1,20 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
-import { Equal, Like, In, Repository } from 'typeorm';
+import { Repository } from 'typeorm';
 import { Company } from '../../entity/users/company.entity';
-import { Collection } from '../../entity/platform/collection.entity';
-import { isArray } from 'lodash';
 import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
 export class CompanyService extends BaseServiceV2 {
-  getQueryColumnsOpera(): object {
-    return {};
-  }
   @InjectEntityModel(Company)
   model: Repository<Company>;
-  @InjectEntityModel(Collection)
-  cModel: Repository<Collection>;
 
-  // 多条件查询列表
-  async list(query) {
-    const { skip = 0, limit = 0, name, is_use, status, area, pattern, industry, ...condition } = query;
-    const whereObject: any = condition;
-    if (name) whereObject.name = { name: Like(`%${name}%`) };
-    if (industry) {
-      if (!isArray(industry)) whereObject.industry = Equal(industry);
-      else whereObject.industry = In(industry);
-    }
-    if (pattern) {
-      if (!isArray(pattern)) whereObject.pattern = Equal(pattern);
-      else whereObject.pattern = In(pattern);
-    }
-    if (area) {
-      if (!isArray(area)) whereObject.area = Equal(area);
-      else whereObject.area = In(area);
-    }
-    const builder = this.model.createQueryBuilder().setFindOptions({ where: whereObject, skip, take: limit });
-    const data = await builder.getMany();
-    const total = await builder.getCount();
-    return { data, total };
+  getQueryColumnsOpera() {
+    const obj = {
+      name: this.Opera.Like,
+      industry: this.Opera.In,
+      pattern: this.Opera.In,
+      area: this.Opera.Json,
+    };
+    return obj;
   }
-
-  // 企业详情
-  // async detail(id) {
-  //   const user = this.ctx.user;
-  //   const cd = { is_collection: false };
-  //   const data = await this.fetch({ id });
-  //   if (data && get(data, 'id') && user) {
-  //     // TODO: 查询是否收藏该企业
-  //     const collection = await this.cModel.findOne({ where: { user: Equal(user.id), source: Equal(data.id) } });
-  //     if (collection) data.is_collection = true;
-  //   }
-  //   return { ...data, ...cd };
-  // }
 }

+ 9 - 43
src/service/users/expert.service.ts

@@ -1,54 +1,20 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
-import { Equal, In, Like, Repository } from 'typeorm';
-import { Collection } from '../../entity/platform/collection.entity';
+import { Repository } from 'typeorm';
 import { Expert } from '../../entity/users/expert.entity';
-import { isArray } from 'lodash';
 import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
 export class ExpertService extends BaseServiceV2 {
-  getQueryColumnsOpera(): object {
-    return {};
-  }
   @InjectEntityModel(Expert)
   model: Repository<Expert>;
 
-  @InjectEntityModel(Collection)
-  cModel: Repository<Collection>;
-
-  // 多条件查询列表
-  async list(query) {
-    const { skip = 0, limit = 0, name, is_use, status, area, field, industry, ...condition } = query;
-    const whereObject: any = condition;
-    if (name) whereObject.name = { name: Like(`%${name}%`) };
-    if (industry) {
-      if (!isArray(industry)) whereObject.industry = Equal(industry);
-      else whereObject.industry = In(industry);
-    }
-    if (field) {
-      if (!isArray(field)) whereObject.field = Equal(field);
-      else whereObject.field = In(field);
-    }
-    if (area) {
-      if (!isArray(area)) whereObject.area = Equal(area);
-      else whereObject.area = In(area);
-    }
-    const builder = this.model.createQueryBuilder().setFindOptions({ where: whereObject, skip, take: limit });
-    const data = await builder.getMany();
-    const total = await builder.getCount();
-    return { data, total };
+  getQueryColumnsOpera() {
+    const obj = {
+      name: this.Opera.Like,
+      industry: this.Opera.In,
+      field: this.Opera.In,
+      area: this.Opera.Json,
+    };
+    return obj;
   }
-
-  // 企业详情
-  // async detail(id) {
-  //   const user = this.ctx.user;
-  //   const data = { is_collection: false };
-  //   const arr = await this.model.findOne({ where: { id: Equal(id) } });
-  //   if (arr && get(arr, 'id') && user) {
-  //     // TODO: 查询是否收藏该企业
-  //     const collection = await this.cModel.findOne({ where: { user: Equal(user.id), source: Equal(arr.id) } });
-  //     if (collection) data.is_collection = true;
-  //   }
-  //   return { ...arr, ...data };
-  // }
 }