Sfoglia il codice sorgente

修改我的收藏

zs 1 anno fa
parent
commit
bad52f0e67

+ 14 - 0
src/controller/tool.controller.ts

@@ -7,6 +7,20 @@ export class ToolController {
   @Inject()
   service: ToolService;
 
+  @Get('/getTotal')
+  @ApiResponse({})
+  async getTotal(@Query() filter) {
+    const result = await this.service.getTotal(filter);
+    return result;
+  }
+
+  @Get('/query')
+  @ApiResponse({})
+  async query(@Query() filter) {
+    const result = await this.service.query(filter);
+    return result;
+  }
+
   @Get('/CollectionTotal')
   @ApiResponse({})
   async getCollectionTotal() {

+ 1 - 1
src/interface/platform/achievement.interface.ts

@@ -50,7 +50,7 @@ export class FVO_achievement {
 
 export class QDTO_achievement extends SearchBase {
   constructor() {
-    const like_prop = [];
+    const like_prop = ['name'];
     const props = ['user', 'patent', 'name', 'attribute', 'sell', 'mature', 'field', 'technology', 'money', 'status', 'achievement_status', 'is_use'];
     const mapping = [];
     super({ like_prop, props, mapping });

+ 1 - 1
src/interface/platform/demand.interface.ts

@@ -44,7 +44,7 @@ export class FVO_demand {
 
 export class QDTO_demand extends SearchBase {
   constructor() {
-    const like_prop = [];
+    const like_prop = ['name'];
     const props = ['user', 'name', 'type', 'field', 'urgent', 'method', 'demand_status', 'status', 'is_use'];
     const mapping = [];
     super({ like_prop, props, mapping });

+ 1 - 1
src/interface/platform/match.interface.ts

@@ -42,7 +42,7 @@ export class FVO_match {
 
 export class QDTO_match extends SearchBase {
   constructor() {
-    const like_prop = [];
+    const like_prop = ['name'];
     const props = ['user', 'name', 'type', 'status','form', 'match_status', 'is_use'];
     const mapping = [];
     super({ like_prop, props, mapping });

+ 2 - 2
src/interface/platform/news.interface.ts

@@ -36,8 +36,8 @@ export class FVO_news {
 
 export class QDTO_news extends SearchBase {
   constructor() {
-    const like_prop = [];
-    const props = ['title', 'person', 'time', 'type', 'is_use','status'];
+    const like_prop = ['title'];
+    const props = ['title', 'person', 'time', 'type', 'is_use', 'status'];
     const mapping = [];
     super({ like_prop, props, mapping });
   }

+ 1 - 1
src/interface/platform/project.interface.ts

@@ -42,7 +42,7 @@ export class FVO_project {
 
 export class QDTO_project extends SearchBase {
   constructor() {
-    const like_prop = [];
+    const like_prop = ['name'];
     const props = ['user', 'name', 'time', 'type', 'maturity', 'skill', 'field', 'cooperate', 'status', 'is_use'];
     const mapping = [];
     super({ like_prop, props, mapping });

+ 1 - 1
src/interface/users/company.interface.ts

@@ -56,7 +56,7 @@ export class FVO_company {
 
 export class QDTO_company extends SearchBase {
   constructor() {
-    const like_prop = [];
+    const like_prop = ['name'];
     const props = ['user', 'name', 'tags', 'phone', 'type', 'person', 'create_time', 'companyStatus','is_show', 'status'];
     const mapping = [];
     super({ like_prop, props, mapping });

+ 1 - 1
src/interface/users/expert.interface.ts

@@ -50,7 +50,7 @@ export class FVO_expert {
 
 export class QDTO_expert extends SearchBase {
   constructor() {
-    const like_prop = [];
+    const like_prop = ['name'];
     const props = ['user', 'name', 'gender', 'phone', 'field', 'direction', 'education', 'title', 'area', 'is_show', 'status'];
     const mapping = [];
     super({ like_prop, props, mapping });

+ 64 - 0
src/service/tool.service.ts

@@ -9,6 +9,8 @@ import { Match } from '../entity/platform/match.entity';
 import { Expert } from '../entity/users/expert.entity';
 import { Company } from '../entity/users/company.entity';
 import { Project } from '../entity/platform/project.entity';
+import { News } from '../entity/platform/news.entity';
+import { Unit } from '../entity/users/unit.entity';
 @Provide()
 export class ToolService {
   @Inject()
@@ -28,12 +30,74 @@ export class ToolService {
   @InjectEntityModel(Match)
   mModel: ReturnModelType<typeof Match>;
 
+  @InjectEntityModel(News)
+  nModel: ReturnModelType<typeof News>;
+
+  @InjectEntityModel(Unit)
+  uModel: ReturnModelType<typeof Unit>;
+
   @InjectEntityModel(Expert)
   eModel: ReturnModelType<typeof Expert>;
 
   @InjectEntityModel(Company)
   companyModel: ReturnModelType<typeof Company>;
 
+  // 搜索总数
+  async getTotal(filter) {
+    const { searchValue, ...condition } = filter;
+    const actList = [
+      { label: '成果', value: 'achievement' },
+      { label: '需求', value: 'demand' },
+      { label: '项目', value: 'project' },
+      { label: '赛事', value: 'match' },
+      { label: '资讯', value: 'news' },
+      { label: '单位', value: 'unit' },
+      { label: '企业', value: 'company' },
+      { label: '专家', value: 'expert' },
+    ];
+    for (const val of actList) {
+      let model;
+      const query = { ...condition };
+      if (searchValue) {
+        if (val.value === 'news') query.title = { $regex: searchValue };
+        else query.name = { $regex: searchValue };
+      }
+      if (val.value === 'achievement') model = this.aModel;
+      if (val.value === 'demand') model = this.dModel;
+      if (val.value === 'project') model = this.pModel;
+      if (val.value === 'match') model = this.mModel;
+      if (val.value === 'news') model = this.nModel;
+      if (val.value === 'unit') model = this.uModel;
+      if (val.value === 'company') model = this.companyModel;
+      if (val.value === 'expert') model = this.eModel;
+      const total = await model.count(query).lean();
+      val.label = val.label + `(${total})`;
+    }
+    return actList;
+  }
+
+  // 搜索
+  async query(filter) {
+    const { skip = 0, limit = 0, type, searchValue, ...condition } = filter;
+    let model;
+    const query = { ...condition };
+    if (searchValue) {
+      if (type === 'news') query.title = { $regex: searchValue };
+      else query.name = { $regex: searchValue };
+    }
+    if (type === 'achievement') model = this.aModel;
+    if (type === 'demand') model = this.dModel;
+    if (type === 'project') model = this.pModel;
+    if (type === 'match') model = this.mModel;
+    if (type === 'news') model = this.nModel;
+    if (type === 'unit') model = this.uModel;
+    if (type === 'company') model = this.companyModel;
+    if (type === 'expert') model = this.eModel;
+    const data = await model.find(query).skip(skip).limit(limit).lean();
+    const total = await model.count(query).lean();
+    return { data, total };
+  }
+
   // 收藏总数
   async getCollectionTotal() {
     const user = this.ctx.user;