expert.service.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { Provide } from '@midwayjs/core';
  2. import { InjectEntityModel } from '@midwayjs/typeorm';
  3. import { Equal, In, Like, Repository } from 'typeorm';
  4. import { Collection } from '../../entity/platform/collection.entity';
  5. import { Expert } from '../../entity/users/expert.entity';
  6. import { isArray } from 'lodash';
  7. import { BaseServiceV2 } from '../../frame/BaseServiceV2';
  8. @Provide()
  9. export class ExpertService extends BaseServiceV2 {
  10. getQueryColumnsOpera(): object {
  11. return {};
  12. }
  13. @InjectEntityModel(Expert)
  14. model: Repository<Expert>;
  15. @InjectEntityModel(Collection)
  16. cModel: Repository<Collection>;
  17. // 多条件查询列表
  18. async list(query) {
  19. const { skip = 0, limit = 0, name, is_use, status, area, field, industry, ...condition } = query;
  20. const whereObject: any = condition;
  21. if (name) whereObject.name = { name: Like(`%${name}%`) };
  22. if (industry) {
  23. if (!isArray(industry)) whereObject.industry = Equal(industry);
  24. else whereObject.industry = In(industry);
  25. }
  26. if (field) {
  27. if (!isArray(field)) whereObject.field = Equal(field);
  28. else whereObject.field = In(field);
  29. }
  30. if (area) {
  31. if (!isArray(area)) whereObject.area = Equal(area);
  32. else whereObject.area = In(area);
  33. }
  34. const builder = this.model.createQueryBuilder().setFindOptions({ where: whereObject, skip, take: limit });
  35. const data = await builder.getMany();
  36. const total = await builder.getCount();
  37. return { data, total };
  38. }
  39. // 企业详情
  40. // async detail(id) {
  41. // const user = this.ctx.user;
  42. // const data = { is_collection: false };
  43. // const arr = await this.model.findOne({ where: { id: Equal(id) } });
  44. // if (arr && get(arr, 'id') && user) {
  45. // // TODO: 查询是否收藏该企业
  46. // const collection = await this.cModel.findOne({ where: { user: Equal(user.id), source: Equal(arr.id) } });
  47. // if (collection) data.is_collection = true;
  48. // }
  49. // return { ...arr, ...data };
  50. // }
  51. }