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 { 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; @InjectEntityModel(Collection) cModel: Repository; // 多条件查询列表 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 = { 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 }; // } }