소스 검색

修改BaseService为第二版

lrf 9 달 전
부모
커밋
ece23f7890
76개의 변경된 파일805개의 추가작업 그리고 451개의 파일을 삭제
  1. 1 1
      src/config/config.self.ts
  2. 39 4
      src/controller/home.controller.ts
  3. 3 5
      src/controller/log/opera.controller.ts
  4. 9 7
      src/controller/platform/achievement.controller.ts
  5. 2 4
      src/controller/platform/chat.controller.ts
  6. 2 4
      src/controller/platform/collection.controller.ts
  7. 15 9
      src/controller/platform/demand.controller.ts
  8. 2 4
      src/controller/platform/design.controller.ts
  9. 2 4
      src/controller/platform/footplate.controller.ts
  10. 2 4
      src/controller/platform/journal.controller.ts
  11. 6 5
      src/controller/platform/match.controller.ts
  12. 2 4
      src/controller/platform/news.controller.ts
  13. 2 4
      src/controller/platform/notes.controller.ts
  14. 8 5
      src/controller/platform/project.controller.ts
  15. 2 4
      src/controller/platform/sector.controller.ts
  16. 16 7
      src/controller/platform/sign.controller.ts
  17. 8 5
      src/controller/platform/supply.controller.ts
  18. 2 4
      src/controller/platform/support.controller.ts
  19. 2 4
      src/controller/system/admin.controller.ts
  20. 2 4
      src/controller/system/dept.controller.ts
  21. 2 4
      src/controller/system/dictData.controller.ts
  22. 2 4
      src/controller/system/dictType.controller.ts
  23. 1 2
      src/controller/system/menus.controller.ts
  24. 2 4
      src/controller/system/region.controller.ts
  25. 2 4
      src/controller/system/role.controller.ts
  26. 2 4
      src/controller/system/tags.controller.ts
  27. 2 4
      src/controller/system/user.controller.ts
  28. 2 4
      src/controller/users/association.controller.ts
  29. 9 6
      src/controller/users/company.controller.ts
  30. 2 4
      src/controller/users/competition.controller.ts
  31. 8 6
      src/controller/users/expert.controller.ts
  32. 2 4
      src/controller/users/incubator.controller.ts
  33. 2 4
      src/controller/users/investment.controller.ts
  34. 2 4
      src/controller/users/state.controller.ts
  35. 2 4
      src/controller/users/unit.controller.ts
  36. 9 0
      src/entity/test.entity.ts
  37. 2 3
      src/entityLogs/opera.entity.ts
  38. 370 0
      src/frame/BaseServiceV2.ts
  39. 6 2
      src/frame/dbOpera.ts
  40. 9 156
      src/service/log/opera.service.ts
  41. 1 5
      src/service/login.service.ts
  42. 2 2
      src/service/platform/achievement.service.ts
  43. 2 2
      src/service/platform/chat.service.ts
  44. 5 2
      src/service/platform/collection.service.ts
  45. 8 3
      src/service/platform/demand.service.ts
  46. 2 2
      src/service/platform/design.service.ts
  47. 2 2
      src/service/platform/footplate.service.ts
  48. 2 2
      src/service/platform/journal.service.ts
  49. 2 2
      src/service/platform/match.service.ts
  50. 2 2
      src/service/platform/news.service.ts
  51. 2 2
      src/service/platform/notes.service.ts
  52. 2 2
      src/service/platform/project.service.ts
  53. 2 2
      src/service/platform/sector.service.ts
  54. 25 25
      src/service/platform/sign.service.ts
  55. 2 2
      src/service/platform/supply.service.ts
  56. 2 2
      src/service/platform/support.service.ts
  57. 52 0
      src/service/serviceUtil.service.ts
  58. 5 2
      src/service/system/admin.service.ts
  59. 13 6
      src/service/system/dept.service.ts
  60. 2 2
      src/service/system/dictData.service.ts
  61. 2 2
      src/service/system/dictType.service.ts
  62. 6 5
      src/service/system/menus.service.ts
  63. 2 1
      src/service/system/region.service.ts
  64. 19 16
      src/service/system/role.service.ts
  65. 4 2
      src/service/system/tags.service.ts
  66. 2 2
      src/service/system/user.service.ts
  67. 19 0
      src/service/tests.service.ts
  68. 5 2
      src/service/users/association.service.ts
  69. 16 13
      src/service/users/company.service.ts
  70. 5 2
      src/service/users/competition.service.ts
  71. 16 13
      src/service/users/expert.service.ts
  72. 2 2
      src/service/users/incubator.service.ts
  73. 2 2
      src/service/users/investment.service.ts
  74. 2 2
      src/service/users/state.service.ts
  75. 2 2
      src/service/users/unit.service.ts
  76. 1 1
      src/service/util.service.ts

+ 1 - 1
src/config/config.self.ts

@@ -63,7 +63,7 @@ export default {
         port: 54321,
         entities: ['./entityLogs'],
         type: 'postgres',
-        synchronize: false, // 如果第一次使用,不存在表,有同步的需求可以写 true,注意会丢数据
+        synchronize: true, // 如果第一次使用,不存在表,有同步的需求可以写 true,注意会丢数据
         logging: false,
       },
     },

+ 39 - 4
src/controller/home.controller.ts

@@ -1,10 +1,12 @@
-import { Controller, Get, Inject } from '@midwayjs/core';
+import { Controller, Get, Inject, Query } from '@midwayjs/core';
 import { InitTwoService } from '../service/initData/initTwo.service';
 import { InitRegionService } from '../service/initData/initRegion.service';
 import { InitOneService } from '../service/initData/initOne.service';
 import { QichachaService } from '../service/thirdParty/qichacha.service';
 import { InitThreeService } from '../service/initData/initThree.service';
 import { DataDealService } from '../service/initData/dataDeal.service';
+import { TestsService } from '../service/tests.service';
+import { Opera } from '../frame/dbOpera';
 
 @Controller('/')
 export class HomeController {
@@ -20,8 +22,10 @@ export class HomeController {
   qichachaService: QichachaService;
   @Inject()
   dataDealService: DataDealService;
+  @Inject()
+  testService: TestsService;
   @Get('/')
-  async home(): Promise<any> {
+  async home(@Query() query: object): Promise<any> {
     // await this.oneService.addTags();
     // await this.oneService.addImportDataTags();
     // await this.twoService.addTags();
@@ -33,8 +37,39 @@ export class HomeController {
     // await this.threeService.import2024Company();
     // await this.threeService.importMatching();
     // await this.dataDealService.JsonbAddDefault();
-    return 'ok';
-    // return 'starting...';
+    // const sq = {
+    //   // time: ['2024-01-01', '2025-01-01'],
+    //   // nick_name: '2024',
+    //   // account: '2024',
+    //   // age: [40, 10],
+    //   // data_owner: '',
+    //   // tags: '黑奴'
+    // };
+    // const operas = {
+    //   id: Opera.Not,
+    //   time: Opera.Between,
+    //   nick_name: Opera.ILikeRight,
+    //   account: Opera.LikeRight,
+    //   age: Opera.In,
+    //   data_owner: Opera.IsNotNull,
+    //   tags: Opera.Json,
+    // };
+    // const res = await this.testService.query(sq, null, operas);
+    // const body = {
+    //   nick_name: '测试20240806_1',
+    //   account: '测试20240806_1',
+    //   age: 20,
+    //   hobby: ['上班'],
+    //   time: '2024-09-01',
+    //   tags: ['黑奴'],
+    // };
+    // const res = await this.testService.create(body);
+    // const id = 9;
+    // const res = await this.testService.update({ id }, { age: 21 });
+    // const res = await this.testService.fetch({ id });
+    // const res = await this.testService.delete({ id });
+    // return res;
+    return 'starting...';
   }
   // @Get('/:method')
   // async test(@Param('method') method: string, @Query() query: object) {

+ 3 - 5
src/controller/log/opera.controller.ts

@@ -10,15 +10,13 @@ export class OperaController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
-  @Get('/:id', { routerName: `创建${namePrefix}` })
+  @Get('/:id', { routerName: `${namePrefix}` })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     return data;
   }
 }

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

@@ -4,18 +4,20 @@ 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 { omit, pick } from 'lodash';
+import { get, 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';
 const namePrefix = '成果';
 @ApiTags(['成果'])
 @Controller('/achievement', { tagName: namePrefix })
 export class AchievementController implements BaseController {
   @Inject()
   service: AchievementService;
-
   @Inject()
   ctx: Context;
+  @Inject()
+  serviceUtil: ServiceUtilService;
 
   @Get('/')
   @ApiTags('列表查询')
@@ -24,8 +26,7 @@ export class AchievementController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -33,8 +34,7 @@ export class AchievementController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_achievement })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_achievement(data);
     return result;
   }
@@ -71,7 +71,9 @@ export class AchievementController implements BaseController {
   @Get('/detail/:id')
   @ApiResponse({ type: FVO_achievement })
   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;
   }
 

+ 2 - 4
src/controller/platform/chat.controller.ts

@@ -19,8 +19,7 @@ export class ChatController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -28,8 +27,7 @@ export class ChatController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_chat })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_chat(data);
     return result;
   }

+ 2 - 4
src/controller/platform/collection.controller.ts

@@ -20,8 +20,7 @@ export class CollectionController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -29,8 +28,7 @@ export class CollectionController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_collection })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_collection(data);
     return result;
   }

+ 15 - 9
src/controller/platform/demand.controller.ts

@@ -7,6 +7,7 @@ import { Controller, Inject, Get, Param, Post, Body, Del, Query } from '@midwayj
 import { omit, pick } from 'lodash';
 import { ServiceError, ErrorCode } from '../../error/service.error';
 import { Context } from '@midwayjs/koa';
+import { ServiceUtilService } from '../../service/serviceUtil.service';
 const namePrefix = '需求';
 @ApiTags(['需求'])
 @Controller('/demand', { tagName: namePrefix })
@@ -15,6 +16,8 @@ export class DemandController implements BaseController {
   service: DemandService;
   @Inject()
   ctx: Context;
+  @Inject()
+  serviceUtil: ServiceUtilService;
 
   @Get('/')
   @ApiTags('列表查询')
@@ -23,8 +26,7 @@ export class DemandController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -32,8 +34,7 @@ export class DemandController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_demand })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_demand(data);
     return result;
   }
@@ -67,16 +68,21 @@ export class DemandController 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;
+  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_demand })
   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;
   }
 }

+ 2 - 4
src/controller/platform/design.controller.ts

@@ -20,8 +20,7 @@ export class DesignController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -29,8 +28,7 @@ export class DesignController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_design })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_design(data);
     return result;
   }

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

@@ -20,8 +20,7 @@ export class FootplateController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -29,8 +28,7 @@ export class FootplateController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_footplate })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_footplate(data);
     return result;
   }

+ 2 - 4
src/controller/platform/journal.controller.ts

@@ -20,8 +20,7 @@ export class JournalController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -29,8 +28,7 @@ export class JournalController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_journal })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_journal(data);
     return result;
   }

+ 6 - 5
src/controller/platform/match.controller.ts

@@ -6,13 +6,15 @@ import { Controller, Inject, Get, Param, Post, Body, Del, Query } from '@midwayj
 import { omit, pick } from 'lodash';
 import { ServiceError, ErrorCode } from '../../error/service.error';
 import { BaseController } from '../../frame/BaseController';
+import { ServiceUtilService } from '../../service/serviceUtil.service';
 const namePrefix = '创新大赛';
 @ApiTags(['创新大赛'])
 @Controller('/match', { tagName: namePrefix })
 export class MatchController implements BaseController {
   @Inject()
   service: MatchService;
-
+  @Inject()
+  serviceUtil: ServiceUtilService;
   @Get('/')
   @ApiTags('列表查询')
   @ApiQuery({ name: 'query' })
@@ -20,8 +22,7 @@ export class MatchController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -29,8 +30,7 @@ export class MatchController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_match })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_match(data);
     return result;
   }
@@ -67,6 +67,7 @@ export class MatchController implements BaseController {
   @ApiResponse({ type: FVO_match })
   async detail(@Param('id') id: string) {
     const data = await this.service.detail(id);
+    await this.serviceUtil.fillCollection(data);
     return data;
   }
 }

+ 2 - 4
src/controller/platform/news.controller.ts

@@ -20,8 +20,7 @@ export class NewsController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -29,8 +28,7 @@ export class NewsController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_news })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     await this.service.fetchBrowse(data);
     const result = new FVO_news(data);
     return result;

+ 2 - 4
src/controller/platform/notes.controller.ts

@@ -20,8 +20,7 @@ export class NotesController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -29,8 +28,7 @@ export class NotesController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_notes })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_notes(data);
     return result;
   }

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

@@ -7,6 +7,7 @@ import { ServiceError, ErrorCode } from '../../error/service.error';
 import { BaseController } from '../../frame/BaseController';
 import { QVO_project, FVO_project, CVO_project, UVAO_project } from '../../interface/platform/project.interface';
 import { Context } from '@midwayjs/koa';
+import { ServiceUtilService } from '../../service/serviceUtil.service';
 const namePrefix = '项目';
 @ApiTags(['项目'])
 @Controller('/project', { tagName: namePrefix })
@@ -15,6 +16,8 @@ export class ProjectController implements BaseController {
   service: ProjectService;
   @Inject()
   ctx: Context;
+  @Inject()
+  serviceUtil: ServiceUtilService;
 
   @Get('/')
   @ApiTags('列表查询')
@@ -23,8 +26,7 @@ export class ProjectController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -32,8 +34,7 @@ export class ProjectController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_project })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_project(data);
     return result;
   }
@@ -77,7 +78,9 @@ export class ProjectController implements BaseController {
   @Get('/detail/:id')
   @ApiResponse({ type: FVO_project })
   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;
   }
 }

+ 2 - 4
src/controller/platform/sector.controller.ts

@@ -24,9 +24,8 @@ export class SectorController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others: any = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
     others.order = { sort: 'ASC' };
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -34,8 +33,7 @@ export class SectorController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_sector })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_sector(data);
     return result;
   }

+ 16 - 7
src/controller/platform/sign.controller.ts

@@ -7,6 +7,7 @@ import { omit, pick } from 'lodash';
 import { ServiceError, ErrorCode } from '../../error/service.error';
 import { BaseController } from '../../frame/BaseController';
 import { Context } from '@midwayjs/koa';
+import { ServiceUtilService } from '../../service/serviceUtil.service';
 const namePrefix = '赛事报名表';
 
 @ApiTags(['赛事报名表'])
@@ -18,6 +19,9 @@ export class SignController implements BaseController {
   @Inject()
   ctx: Context;
 
+  @Inject()
+  serviceUtil: ServiceUtilService;
+
   @Get('/')
   @ApiTags('列表查询')
   @ApiQuery({ name: 'query' })
@@ -25,8 +29,7 @@ export class SignController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -34,8 +37,7 @@ export class SignController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_sign })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_sign(data);
     return result;
   }
@@ -70,8 +72,15 @@ export class SignController implements BaseController {
     return result;
   }
   @Get('/sign')
-  async sign() {
-    const list = await this.service.sign(this.ctx.query);
-    return list;
+  async sign(@Query() query: object) {
+    // const list = await this.service.sign(this.ctx.query);
+    // return list;
+    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.fillMatchInfo(i);
+    }
+    return { data, total };
   }
 }

+ 8 - 5
src/controller/platform/supply.controller.ts

@@ -7,6 +7,7 @@ import { ServiceError, ErrorCode } from '../../error/service.error';
 import { BaseController } from '../../frame/BaseController';
 import { QVO_supply, FVO_supply, CVO_supply, UVAO_supply } from '../../interface/platform/supply.interface';
 import { Context } from '@midwayjs/koa';
+import { ServiceUtilService } from '../../service/serviceUtil.service';
 const namePrefix = '供给';
 @ApiTags(['供给'])
 @Controller('/supply', { tagName: namePrefix })
@@ -15,6 +16,8 @@ export class SupplyController implements BaseController {
   service: SupplyService;
   @Inject()
   ctx: Context;
+  @Inject()
+  serviceUtil: ServiceUtilService;
 
   @Get('/')
   @ApiTags('列表查询')
@@ -23,8 +26,7 @@ export class SupplyController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -32,8 +34,7 @@ export class SupplyController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_supply })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_supply(data);
     return result;
   }
@@ -78,7 +79,9 @@ export class SupplyController implements BaseController {
   @Get('/detail/:id')
   @ApiResponse({ type: FVO_supply })
   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;
   }
 }

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

@@ -20,8 +20,7 @@ export class SupportController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -29,8 +28,7 @@ export class SupportController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_support })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_support(data);
     return result;
   }

+ 2 - 4
src/controller/system/admin.controller.ts

@@ -19,8 +19,7 @@ export class HomeController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -28,8 +27,7 @@ export class HomeController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_admin })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_admin(data);
     return result;
   }

+ 2 - 4
src/controller/system/dept.controller.ts

@@ -21,8 +21,7 @@ export class DeptController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
   @Get('/')
@@ -45,8 +44,7 @@ export class DeptController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_dept })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_dept(data);
     return result;
   }

+ 2 - 4
src/controller/system/dictData.controller.ts

@@ -21,8 +21,7 @@ export class DictDataController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -30,8 +29,7 @@ export class DictDataController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_dictData })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_dictData(data);
     return result;
   }

+ 2 - 4
src/controller/system/dictType.controller.ts

@@ -21,8 +21,7 @@ export class DictTypeController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -30,8 +29,7 @@ export class DictTypeController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_dictType })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_dictType(data);
     return result;
   }

+ 1 - 2
src/controller/system/menus.controller.ts

@@ -28,8 +28,7 @@ export class MenusController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_menus })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_menus(data);
     return result;
   }

+ 2 - 4
src/controller/system/region.controller.ts

@@ -25,8 +25,7 @@ export class RegionController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -34,8 +33,7 @@ export class RegionController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_region })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_region(data);
     return result;
   }

+ 2 - 4
src/controller/system/role.controller.ts

@@ -23,8 +23,7 @@ export class RoleController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const { data, total } = await this.service.query(qbr, others);
+    const { data, total } = await this.service.query(qobj, others);
     const list = [];
     for (const i of data) {
       const newData = new QVO_role(i);
@@ -37,8 +36,7 @@ export class RoleController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_role })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_role(data);
     return result;
   }

+ 2 - 4
src/controller/system/tags.controller.ts

@@ -22,8 +22,7 @@ export class TagsController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -31,8 +30,7 @@ export class TagsController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_tags })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_tags(data);
     return result;
   }

+ 2 - 4
src/controller/system/user.controller.ts

@@ -21,8 +21,7 @@ export class UserController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -30,8 +29,7 @@ export class UserController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_user })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_user(data);
     return result;
   }

+ 2 - 4
src/controller/users/association.controller.ts

@@ -24,8 +24,7 @@ export class AssociationController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -33,8 +32,7 @@ export class AssociationController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_association })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_association(data);
     return result;
   }

+ 9 - 6
src/controller/users/company.controller.ts

@@ -3,11 +3,12 @@ import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
 import { UtilService } from '../../service/util.service';
 import { BaseController } from '../../frame/BaseController';
-import { omit, pick } from 'lodash';
+import { get, omit, pick } from 'lodash';
 import { ErrorCode, ServiceError } from '../../error/service.error';
 import { CompanyService } from '../../service/users/company.service';
 import { CVO_company, FVO_company, QVO_company, UVAO_company } from '../../interface/users/company.interface';
 import { Context } from '@midwayjs/koa';
+import { ServiceUtilService } from '../../service/serviceUtil.service';
 const namePrefix = '企业';
 @ApiTags(['企业'])
 @Controller('/company', { tagName: namePrefix })
@@ -21,6 +22,9 @@ export class CompanyController implements BaseController {
   @Inject()
   ctx: Context;
 
+  @Inject()
+  serviceUtil: ServiceUtilService;
+
   @Get('/')
   @ApiTags('列表查询')
   @ApiQuery({ name: 'query' })
@@ -28,8 +32,7 @@ export class CompanyController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -37,8 +40,7 @@ export class CompanyController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_company })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_company(data);
     return result;
   }
@@ -53,7 +55,8 @@ export class CompanyController implements BaseController {
   @Get('/detail/:id')
   @ApiResponse({ type: FVO_company })
   async detail(@Param('id') id: string) {
-    const data = await this.service.detail(id);
+    const data = await this.service.fetch({ id });
+    await this.serviceUtil.fillCollection(data)
     return data;
   }
 

+ 2 - 4
src/controller/users/competition.controller.ts

@@ -24,8 +24,7 @@ export class CompetitionController implements BaseController {
   async index(query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -33,8 +32,7 @@ export class CompetitionController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_competition })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_competition(data);
     return result;
   }

+ 8 - 6
src/controller/users/expert.controller.ts

@@ -3,11 +3,12 @@ import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
 import { UtilService } from '../../service/util.service';
 import { BaseController } from '../../frame/BaseController';
-import { omit, pick } from 'lodash';
+import { get, omit, pick } from 'lodash';
 import { ErrorCode, ServiceError } from '../../error/service.error';
 import { ExpertService } from '../../service/users/expert.service';
 import { Context } from '@midwayjs/koa';
 import { QVO_expert, FVO_expert, CVO_expert, UVAO_expert } from '../../interface/users/expert.interface';
+import { ServiceUtilService } from '../../service/serviceUtil.service';
 const namePrefix = '专家';
 @ApiTags(['专家'])
 @Controller('/expert', { tagName: namePrefix })
@@ -16,6 +17,8 @@ export class ExpertController implements BaseController {
   service: ExpertService;
   @Inject()
   ctx: Context;
+  @Inject()
+  serviceUtil: ServiceUtilService;
 
   @Inject()
   utilService: UtilService;
@@ -27,8 +30,7 @@ export class ExpertController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
   @Get('/list')
@@ -43,15 +45,15 @@ export class ExpertController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_expert })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     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.detail(id);
+    const data = await this.service.fetch({ id });
+    await this.serviceUtil.fillCollection(data)
     return data;
   }
 

+ 2 - 4
src/controller/users/incubator.controller.ts

@@ -27,8 +27,7 @@ export class IncubatorController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -36,8 +35,7 @@ export class IncubatorController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_incubator })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_incubator(data);
     return result;
   }

+ 2 - 4
src/controller/users/investment.controller.ts

@@ -27,8 +27,7 @@ export class InvestmentController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -36,8 +35,7 @@ export class InvestmentController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_investment })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_investment(data);
     return result;
   }

+ 2 - 4
src/controller/users/state.controller.ts

@@ -27,8 +27,7 @@ export class StateController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -36,8 +35,7 @@ export class StateController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_state })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_state(data);
     return result;
   }

+ 2 - 4
src/controller/users/unit.controller.ts

@@ -27,8 +27,7 @@ export class UnitController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.query(qbr, others);
+    const result = await this.service.query(qobj, others);
     return result;
   }
 
@@ -36,8 +35,7 @@ export class UnitController implements BaseController {
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_unit })
   async fetch(@Param('id') id: number) {
-    const qbr = this.service.queryBuilder({ id });
-    const data = await this.service.fetch(qbr);
+    const data = await this.service.fetch({ id });
     const result = new FVO_unit(data);
     return result;
   }

+ 9 - 0
src/entity/test.entity.ts

@@ -1,15 +1,24 @@
 import { Column, Entity } from 'typeorm';
 import { BaseModel } from '../frame/BaseModel';
+import dayjs = require('dayjs');
 @Entity('test')
 export class Test extends BaseModel {
   @Column({ type: 'character varying', nullable: true, comment: '昵称' })
   nick_name: string;
   @Column({ type: 'character varying', nullable: true, comment: '账号' })
   account: string;
+  @Column({ type: 'integer', nullable: true, comment: '数字' })
+  age: number;
   @Column({ type: 'jsonb', nullable: true, comment: '爱好' })
   hobby: Array<any>;
   @Column({ type: 'jsonb', nullable: true, comment: '属性' })
   props: object;
   @Column({ type: 'jsonb', nullable: true, comment: '数组属性' })
   array_props: Array<object>;
+  @Column({ type: 'text', nullable: true, comment: '备注' })
+  remark: string;
+  @Column({ type: 'timestamp without time zone', nullable: true, comment: '时间', transformer: { from: value => dayjs(value).format('YYYY-MM-DD HH:mm:ss'), to: value => value } })
+  time: Date;
+  @Column({ type: 'jsonb', nullable: true, comment: '爱好' })
+  tags: Array<any>;
 }

+ 2 - 3
src/entityLogs/opera.entity.ts

@@ -1,9 +1,8 @@
 import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
 import * as dayjs from 'dayjs';
+import { BaseModel } from '../frame/BaseModel';
 @Entity('opera', { comment: '操作日志' })
-export class Opera {
-  @PrimaryGeneratedColumn({ type: 'integer' })
-  id: number;
+export class Opera extends BaseModel{
   @Column({ type: 'integer', nullable: true, comment: '操作人id' })
   operator_id: number;
   @Column({ type: 'character varying', nullable: true, comment: '操作人名称' })

+ 370 - 0
src/frame/BaseServiceV2.ts

@@ -0,0 +1,370 @@
+import { App, Inject, MidwayWebRouterService } from '@midwayjs/core';
+import { Application, Context } from '@midwayjs/koa';
+import { compact, flattenDeep, get, head, isArray, isNull, isNumber, isObject, isString, isUndefined, last, uniq } from 'lodash';
+import { Opera } from './dbOpera';
+import { Opera as operaModel } from '../entityLogs/opera.entity';
+import dayjs = require('dayjs');
+import { InjectEntityModel } from '@midwayjs/typeorm';
+import { Repository } from 'typeorm';
+import { Tags } from '../entity/system/tags.entity';
+/**
+ * query默认的查询方式(哪个字段 是 = 还是 IN 还是 LIKE)的设置函数为getQueryColumnsOpera,如果有需要重写即可,返回object
+ * {
+ *    column: Opera.xxx
+ * }
+ */
+export abstract class BaseServiceV2 {
+  @App()
+  app: Application;
+
+  @Inject()
+  ctx: Context;
+
+  @InjectEntityModel(operaModel, 'logs')
+  _operaLogsModel: Repository<operaModel>;
+  @InjectEntityModel(Tags)
+  _tagsModel: Repository<Tags>;
+
+  @Inject()
+  private webRouterService: MidwayWebRouterService;
+
+  /**service的model,数据库操作 */
+  abstract model: any;
+  /**返回{column:查询方式}.特殊的查询需要写入,不写入默认采用 =  */
+  getQueryColumnsOpera() {
+    return {};
+  }
+  /** */
+  Opera = Opera;
+  /**
+   * 默认查询列表
+   * @param query @Query直接获取的参数
+   * @param param @Query和调用前可组织的参数
+   * @param {object} operas 指定查询方式
+   * @property {number} param.skip 查询数据起始位置
+   * @property {number} param.limit 查询数据的数量
+   * @property {object} param.order 使用的排序 {${column}:'DESC'/'ASC'}
+   * @property {Array<string>} selects 指定显示的字段
+   */
+  async query(query: object = {}, meta: any = {}, operas?) {
+    let skip = get(meta, 'skip', 0);
+    let limit = get(meta, 'limit', 0);
+    let order = get(meta, 'order', {});
+    let selects = get(meta, 'selects', []);
+    let builder = await this.model.createQueryBuilder();
+    if (selects.length > 0) {
+      // 字段是直接传来的,正常限制,需要加上model的name.否则会导致什么字段都没有
+      const modelName = this.model.metadata.name;
+      builder.select(selects.map(i => `${modelName}.${i}`));
+    }
+    // 组织查询顺序
+    let orderObject: any = {};
+    // 如果有自定义顺序,则按照自定义顺序来, 没有自定义顺序,默认按创建时间的desc查询
+    if (Object.keys(order).length > 0) {
+      for (const column in order) orderObject[column] = order[column];
+    } else orderObject = { created_time: 'DESC' };
+    // 没有传如何查询,就获取query查询设置的默认查询方式
+    if (!operas) operas = this.getQueryColumnsOpera();
+    this.completeBuilderCondition(builder, query, operas);
+    // 分页
+    if (isString(skip)) {
+      skip = parseInt(skip);
+      if (isNumber(skip)) builder.skip(skip);
+    } else if (isNumber(skip)) builder.skip(skip);
+    if (isString(limit)) {
+      limit = parseInt(limit);
+      if (isNumber(limit)) builder.take(limit);
+    } else if (isNumber(limit)) builder.take(limit);
+    // 排序
+    builder.orderBy(orderObject);
+    // 执行
+    if (this.app.getEnv() !== 'prod' && this.app.getEnv() !== 'production') {
+      console.log(builder.getSql());
+    }
+    const data = await builder.getMany();
+    const total = await builder.getCount();
+    return { data, total };
+  }
+
+  /**
+   *
+   * @param builder model的createQueryBuilder,只有到最后要查数据的时候才是异步的
+   * @param {object} query 查询条件
+   * @param {object} operas 指定查询方式
+   */
+  completeBuilderCondition(builder, query = {}, operas = {}) {
+    // 组织查询条件
+    if (!query) return;
+    const searchColumns = Object.keys(query);
+    if (searchColumns.length <= 0) return;
+    for (let i = 0; i < searchColumns.length; i++) {
+      const key = searchColumns[i];
+      const value = query[key];
+      /**该字段的查询方式 */
+      let opera = get(operas, key);
+      /**builder的使用函数名 */
+      let method = 'where';
+      if (i === 0) method = 'where';
+      else method = 'andWhere';
+      let str;
+      let params;
+      // 需要给变量位置重命名,否则多个条件叠加后,都会使用第一个参数
+      const valueStr = `value${i}`;
+      switch (opera) {
+        case this.Opera.Between:
+          str = `"${key}" Between :${valueStr}_1 AND :${valueStr}_2`;
+          params = { [`${valueStr}_1`]: head(value), [`${valueStr}_2`]: last(value) };
+          break;
+        case this.Opera.Not:
+          str = `"${key}" != :${valueStr}`;
+          params = { [`${valueStr}`]: value };
+          break;
+        case this.Opera.Like:
+          str = `"${key}" Like :${valueStr}`;
+          params = { [`${valueStr}`]: `%${value}%` };
+          break;
+        case this.Opera.LikeLeft:
+          str = `"${key}" Like :${valueStr}`;
+          params = { [`${valueStr}`]: `%${value}` };
+          break;
+        case this.Opera.LikeRight:
+          str = `"${key}" Like :${valueStr}`;
+          params = { [`${valueStr}`]: `${value}%` };
+          break;
+        case this.Opera.ILike:
+          str = `"${key}" Not Like :${valueStr}`;
+          params = { [`${valueStr}`]: `%${value}%` };
+          break;
+        case this.Opera.ILikeLeft:
+          str = `"${key}" Not Like :${valueStr}`;
+          params = { [`${valueStr}`]: `%${value}` };
+          break;
+        case this.Opera.ILikeRight:
+          str = `"${key}" Not Like :${valueStr}`;
+          params = { [`${valueStr}`]: `${value}%` };
+          break;
+        case this.Opera.LessThan:
+          str = `"${key}" < :${valueStr}`;
+          params = { [`${valueStr}`]: value };
+          break;
+        case this.Opera.LessThanOrEqual:
+          str = `"${key}" <= :${valueStr}`;
+          params = { [`${valueStr}`]: value };
+          break;
+        case this.Opera.MoreThan:
+          str = `"${key}" > :${valueStr}`;
+          params = { [`${valueStr}`]: value };
+          break;
+        case this.Opera.MoreThanOrEqual:
+          str = `"${key}" >= :${valueStr}`;
+          params = { [`${valueStr}`]: value };
+          break;
+        case this.Opera.In:
+          str = `"${key}" IN (:...${valueStr})`;
+          params = { [`${valueStr}`]: value };
+          break;
+        case this.Opera.IsNull:
+          str = `"${key}" IS NULL`;
+          break;
+        case this.Opera.IsNotNull:
+          str = `"${key}" IS NOT NULL`;
+          params = { [`${valueStr}`]: value };
+          break;
+        case this.Opera.Json:
+          str = `JSONB_EXISTS("${key}", :${valueStr})`;
+          params = { [`${valueStr}`]: value };
+          break;
+        case this.Opera.Equal:
+        default:
+          str = `"${key}" = :${valueStr}`;
+          params = { [`${valueStr}`]: value };
+          break;
+      }
+      if (!str) continue;
+      builder[method](str, params);
+    }
+  }
+
+  /**
+   * 单查询,不止用id还可以根据别的条件,默认全等,可以在调用时,进行查询方式设置
+   * @param {object} query 查询条件
+   * @param {object} operas 指定查询方式
+   */
+  async fetch(query: object, operas = {}) {
+    const builder = this.model.createQueryBuilder();
+    this.completeBuilderCondition(builder, query, operas);
+    const result = await builder.getOne();
+    return result;
+  }
+
+  /**创建 */
+  async create(data: object) {
+    // 设置 创建数据的人
+    const user = get(this.ctx, 'user');
+    if (user) {
+      // 查询本表是否有data_onwer字段,有再添加.
+      const hasColumn = this.checkModelHaveColumn('data_onwer');
+      if (hasColumn) Object.assign(data, { data_owner: get(user, 'id') });
+    }
+    const result = await this.model.insert(data);
+    const id = get(result, 'identifiers.0.id');
+    // 没有id估计是出错了
+    if (!id) return;
+    const createData = await this.fetch({ id });
+    // 没有查出数据,也是有问题
+    if (!createData) return;
+    // 处理标签
+    await this.dealTags(createData);
+    // 添加,没有原数据,只有新数据
+    await this.dealLog(null, createData);
+    return createData;
+  }
+
+  /**修改,单修改/多修改是统一修改为 */
+  async update(query: object = {}, data: object) {
+    // 没有范围的修改不允许执行
+    if (Object.keys(query).length <= 0) return;
+    // 处理数据, 只将是本表的字段拿出来保存
+    const columns = this.model.metadata.columns;
+    /**将array的列设置 转换为object,以便query使用*/
+    const columnsObject = {};
+    // 整理成object
+    for (const c of columns) columnsObject[c.propertyName] = c.type.toString();
+    const updateData = {};
+    const notDealColumn = ['id', 'created_time', 'update_time', 'data_owner', '__v'];
+    for (const column in columnsObject) {
+      if (notDealColumn.includes(column)) continue;
+      const val = data[column];
+      if (isNull(val) || isUndefined(val)) continue;
+      updateData[column] = val;
+    }
+    // 找到原数据
+    const originDataBuilder = this.model.createQueryBuilder();
+    this.completeBuilderCondition(originDataBuilder, query);
+    const origin_data = await originDataBuilder.getMany(query);
+    if (origin_data.length <= 0) return;
+    await this.model.update(query, updateData);
+    const new_data = await originDataBuilder.getMany(query);
+    if (new_data.length <= 0) return;
+    // 处理标签
+    await this.dealTags(new_data);
+    // 处理日志
+    await this.dealLog(origin_data, new_data);
+  }
+
+  /**删除,单删多删都行 */
+  async delete(query: object) {
+    // 没有范围不能删除,清空表需要特殊处理
+    if (query && Object.keys(query).length <= 0) return;
+    // 删除前,先查出来数据, 找到原数据
+    const originDataBuilder = this.model.createQueryBuilder();
+    this.completeBuilderCondition(originDataBuilder, query);
+    const origin_data = await originDataBuilder.getMany(query);
+    if (origin_data.length <= 0) return;
+    const result = await this.model.delete(query);
+    // 处理日志
+    await this.dealLog(origin_data, null);
+    return result;
+  }
+
+  /**
+   * 整理日志
+   * @param origin_data 原数据
+   * @param new_data 新数据
+   */
+  async dealLog(origin_data, new_data) {
+    // 添加,没有原数据,只有新数据
+    const mn = this.model.metadata.tableName;
+    let newObject;
+    if (new_data) newObject = { [mn]: new_data };
+    let originObject;
+    if (origin_data) originObject = { [mn]: origin_data };
+    await this.toMakeLogs(originObject, newObject);
+  }
+  /**
+   * 从操作日志服务迁移过来了.不能初始化service,否则会循环引用
+   * 生成日志
+   * 原数据和新数据格式:
+   * {
+   *    [表名]:[数据,...数据]
+   * }
+   * @param origin_data 原数据
+   * @param new_data 新数据
+   * */
+  async toMakeLogs(origin_data?: object, new_data?: object) {
+    const user = this.ctx.user;
+    if (user && user.id) {
+      const req = this.ctx.request;
+      const logInfo: any = {
+        // 操作人
+        operator_id: user.id,
+        operator_name: get(user, 'nick_name', get(user, 'name')),
+        // ip
+        ip: get(req, 'header.x-forwarded-for', req.ip),
+        // 设备
+        device: get(req, 'header.user-agent'),
+        // 操作时间
+        time: dayjs().format('YYYY-MM-DD HH:mm:ss'),
+        // 操作地址
+        referer: get(req, 'header.referer'),
+        // 请求地址uri
+        path: get(req, 'path'),
+        // 地址参数
+        params: get(req, 'params'),
+        // 请求参数
+        query: get(req, 'query'),
+        // 方法体参数
+        body: get(req, 'body'),
+        // 操作业务:可以通过路由注解的routerName来获取
+        opera: null,
+        // 变动值: 表:[数据] 需要自己组织
+        origin_data: origin_data,
+        new_data: new_data,
+      };
+      const routeInfo = await this.webRouterService.getMatchedRouterInfo(this.ctx.path, this.ctx.method);
+      if (routeInfo) logInfo.opera = get(routeInfo, 'routerName');
+      await this._operaLogsModel.insert(logInfo);
+    }
+  }
+
+  /**
+   * 处理标签
+   * @param {object|Array} data 操作后的数据
+   */
+  async dealTags(data) {
+    // 处理标签,查询本表是否有标签字段.标签都是tags
+    const hasColumn_tags = this.checkModelHaveColumn('tags');
+    if (!hasColumn_tags) return;
+    let tags;
+    // 判断tags数据类型
+    if (isObject(data)) {
+      tags = get(data, 'tags', []);
+      if (!tags) return;
+      // 清除空数据
+      tags = compact(tags);
+    } else if (isArray(data)) {
+      // 提取tags
+      tags = data.map(i => i.tags);
+      // 降至一维
+      tags = flattenDeep(tags);
+      // 去重
+      tags = uniq(tags);
+      // 清除空数据
+      tags = compact(tags);
+    }
+    if (!tags || tags.length <= 0) return;
+    // 处理标签
+    for (const val of tags) {
+      const where = { title: val };
+      const tag = await this._tagsModel.findOne({ where });
+      if (!tag) await this._tagsModel.save(where);
+    }
+  }
+
+  /**检查有没有指定字段,是从model的映射关系中查询下 */
+  private checkModelHaveColumn(columnName: string) {
+    const columns = this.model.metadata.columns;
+    const has = columns.find(f => get(f, 'propertyName') === columnName);
+    return !isUndefined(has);
+  }
+}

+ 6 - 2
src/frame/dbOpera.ts

@@ -13,7 +13,7 @@ export enum Opera {
   ILike = 'ILike',
   ILikeLeft = 'ILikeLeft',
   ILikeRight = 'ILikeRight',
-  /**两者之间(区间), Between(1,10) */
+  /**两者之间(区间), Between(1,10) */
   Between = 'Between',
   /**小于 LessThan(10)*/
   LessThan = 'LessThan',
@@ -25,6 +25,10 @@ export enum Opera {
   MoreThanOrEqual = 'MoreThanOrEqual',
   /**值在数组中 In(['a', 'b']) */
   In = 'In',
-  /**为空 IsNull */
+  /**为空 IsNull */
   IsNull = 'IsNull',
+  IsNotNull = 'IsNotNull',
+  /**JSON */
+  Json = 'Json',
+  /**Json, Object类型需要自定义写法 */
 }

+ 9 - 156
src/service/log/opera.service.ts

@@ -1,173 +1,26 @@
 import { Inject, MidwayWebRouterService, Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
-import * as toqm from 'typeorm';
-import { get, pick } from 'lodash';
+import { get } from 'lodash';
 import dayjs = require('dayjs');
 import { Context } from '@midwayjs/koa';
 import { Opera as operaModel } from '../../entityLogs/opera.entity';
-import { QueryOpera } from '../../frame/BaseService';
-import { Opera } from '../../frame/dbOpera';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 
 @Provide()
-export class OperaService  {
+export class OperaService extends BaseServiceV2 {
   @Inject()
   ctx: Context;
   @InjectEntityModel(operaModel, 'logs')
   model: Repository<operaModel>;
-  @Inject()
-  webRouterService: MidwayWebRouterService;
 
-  /**
-   * 生成日志
-   * 原数据和新数据格式:
-   * {
-   *    [表名]:[数据,...数据]
-   * }
-   * @param origin_data 原数据
-   * @param new_data 新数据
-   */
-  async toMakeLogs(origin_data?: object, new_data?: object) {
-    const user = this.ctx.user;
-    if (user && user.id) {
-      const req = this.ctx.request;
-      const logInfo: any = {
-        // 操作人
-        operator_id: user.id,
-        operator_name: get(user, 'nick_name', get(user, 'name')),
-        // ip
-        ip: get(req, 'header.x-forwarded-for', req.ip),
-        // 设备
-        device: get(req, 'header.user-agent'),
-        // 操作时间
-        time: dayjs().format('YYYY-MM-DD HH:mm:ss'),
-        // 操作地址
-        referer: get(req, 'header.referer'),
-        // 请求地址uri
-        path: get(req, 'path'),
-        // 地址参数
-        params: get(req, 'params'),
-        // 请求参数
-        query: get(req, 'query'),
-        // 方法体参数
-        body: get(req, 'body'),
-        // 操作业务:可以通过路由注解的routerName来获取
-        opera: null,
-        // 变动值: 表:[数据] 需要自己组织
-        origin_data: origin_data,
-        new_data: new_data,
-      };
-      const routeInfo = await this.webRouterService.getMatchedRouterInfo(this.ctx.path, this.ctx.method);
-      if (routeInfo) logInfo.opera = get(routeInfo, 'routerName');
-      await this.model.insert(logInfo);
-    }
+  async create() {
+    return;
   }
-
-
-  /**
-   * 列表查询
-   * @param query 查询条件(经过queryBuilder转换后的)
-   * @param param 有关skip和limit,order_by(数组,多字段排列)
-   */
-  async query(query: QueryOpera[], { skip = 0, limit = 0, order = {} } = {}) {
-    let findOpera: any = {};
-    // 组织查询顺序
-    let orderObject: any = {};
-    // 如果有自定义顺序,则按照自定义顺序来, 没有自定义顺序,默认按创建时间的desc查询
-    if (Object.keys(order).length > 0) {
-      for (const column in order) orderObject[column] = order[column];
-    } else orderObject = { time: 'DESC' };
-    if (query.length > 0) findOpera = this.buildFindWhere(query);
-    const builder = await this.model.createQueryBuilder().setFindOptions({ where: findOpera, skip, take: limit, order: orderObject });
-    const data = await builder.getMany();
-    const total = await builder.getCount();
-    return { data, total };
+  async update() {
+    return;
   }
-
-  /**根据builder设置转换成options */
-  buildFindWhere(query) {
-    const result = {};
-    for (const qo of query) {
-      let val = qo.value;
-      for (const opera of qo.opera) {
-        const methods = pick(toqm, ['IsNull', 'In', 'MoreThanOrEqual', 'MoreThan', 'LessThanOrEqual', 'LessThan', 'Equal', 'Not', 'Like', 'ILike', 'Between']);
-        // const m = get(methods, Opera[opera]);
-        const m = methods[Opera[opera]];
-        // if 和 else if 都是需要特殊处理值的情况
-        // Between这个一般都是最先处理,要放到数组最前面,否则会影响value的值
-        if (Opera[opera] === Opera.Between) val = m(get(val, 0), get(val, 1));
-        else if (Opera[opera] === Opera.Like || Opera[opera] === Opera.ILike) val = m(`%${val}%`);
-        else if (Opera[opera] === Opera.LikeLeft || Opera[opera] === Opera.ILikeLeft) val = m(`%${val}`);
-        else if (Opera[opera] === Opera.LikeRight || Opera[opera] === Opera.ILikeRight) val = m(`${val}%`);
-        else if (Opera[opera] === Opera.IsNull) val = m![Opera[opera]]();
-        else val = m(val);
-      }
-      result[qo.column] = val;
-    }
-    return result;
+  async delete() {
+    return;
   }
-
-
-  /**
-   * 默认查询条件object
-   * integer: 数字 默认 全等
-   * character varying: 字符串 默认 模糊
-   * timestamp without time zone: 时间 默认不处理,手写处理方式
-   * @param {object} query 查询条件object
-   * @return 输出为查询数组
-   * [
-   *  {
-   *    column:字段,
-   *    opera:查询方式
-   *    value:具体值
-   *  }
-   * ]
-   *  e.g.:
-   * [
-   *  {
-   *    column:'nick_name',
-   *    opera:eq,
-   *    value:'admin'
-   *  }
-   * ]
-   * 形成查询数组,再由query函数处理具体查询
-   */
-  queryBuilder(query: any = {}) {
-    /**列设置,所有字段都需要设置type */
-    const columns = this.model.metadata.columns;
-    /**将array的列设置 转换为object,以便query使用*/
-    const columnsObject = {};
-    // 整理成object
-    for (const c of columns) columnsObject[c.propertyName] = c.type.toString();
-    /**返回的查询操作数组 */
-    const queryArray: QueryOpera[] = [];
-    // 根据查询条件(query),对字段进行处理
-    for (const column in query) {
-      const dataType = columnsObject[column];
-      // 没找到字段,那就直接跳过,按理说不应该找不到.但是真的找不到,也不能添加进查询条件里,会出错
-      if (!dataType) continue;
-      if (dataType === 'integer') {
-        const qo: QueryOpera = { column, value: query[column], opera: [Opera.Equal] };
-        queryArray.push(qo);
-      } else if (dataType === 'character varying') {
-        const qo: QueryOpera = { column, value: query[column], opera: [Opera.Like] };
-        queryArray.push(qo);
-      } else if (dataType === 'timestamp without time zone') {
-        //默认不处理
-      }
-    }
-
-    return queryArray;
-  }
-
-
-  /**单查询,不止用id还可以根据别的条件 */
-  async fetch(query: QueryOpera[]) {
-    const whereOptions = this.buildFindWhere(query);
-    const builder = this.model.createQueryBuilder().setFindOptions({ where: whereOptions });
-    const result = await builder.getOne();
-    return result;
-  }
-
-
 }

+ 1 - 5
src/service/login.service.ts

@@ -8,7 +8,6 @@ import { ServiceError, ErrorCode } from '../error/service.error';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Equal, Repository } from 'typeorm';
 import { LoginDTO, LoginType, UPwdDTO } from '../interface/login.interface';
-import { Opera } from '../frame/dbOpera';
 import { Admin } from '../entity/system/admin.entity';
 import * as bcrypt from 'bcryptjs';
 import { User } from '../entity/system/user.entity';
@@ -79,10 +78,7 @@ export class LoginService {
       }
     } else {
       if (get(user, 'status') !== '1') throw new ServiceError(ErrorCode.USER_IS_DISABLED);
-      const qb = [
-        { column: 'code', opera: [Opera.Equal], value: type },
-        { column: 'is_use', opera: [Opera.Equal], value: '0' },
-      ];
+      const qb = { code: type, is_use: '0' };
       const role = await this.roleService.fetch(qb);
       if (!role) throw new ServiceError(ErrorCode.ROLE_IS_DISABLED);
     }

+ 2 - 2
src/service/platform/achievement.service.ts

@@ -2,12 +2,12 @@ import { Achievement } from '../../entity/platform/achievement.entity';
 import { Collection } from '../../entity/platform/collection.entity';
 import { User } from '../../entity/system/user.entity';
 import { get, pick } from 'lodash';
-import { BaseService } from '../../frame/BaseService';
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Between, Equal, In, MoreThanOrEqual, Repository } from 'typeorm';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class AchievementService extends BaseService<Achievement> {
+export class AchievementService extends BaseServiceV2 {
   @InjectEntityModel(Achievement)
   model: Repository<Achievement>;
   @InjectEntityModel(Collection)

+ 2 - 2
src/service/platform/chat.service.ts

@@ -5,10 +5,10 @@ import { Provide, App } from '@midwayjs/core';
 import { Application } from '@midwayjs/koa';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 /**写不下去了。聊天问题让她自己弄吧 */
 @Provide()
-export class ChatService extends BaseService<Chat> {
+export class ChatService extends BaseServiceV2 {
   @InjectEntityModel(Chat)
   model: Repository<Chat>;
 

+ 5 - 2
src/service/platform/collection.service.ts

@@ -2,9 +2,12 @@ import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Equal, Repository } from 'typeorm';
 import { Collection } from '../../entity/platform/collection.entity';
-import { BaseService } from '../../frame/BaseService';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class CollectionService extends BaseService<Collection> {
+export class CollectionService extends BaseServiceV2 {
+  getQueryColumnsOpera(): object {
+    return {};
+  }
   @InjectEntityModel(Collection)
   model: Repository<Collection>;
   // 取消收藏

+ 8 - 3
src/service/platform/demand.service.ts

@@ -5,16 +5,21 @@ import { get } from 'lodash';
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Equal, In, Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class DemandService extends BaseService<Demand> {
+export class DemandService extends BaseServiceV2 {
   @InjectEntityModel(Demand)
   model: Repository<Demand>;
   @InjectEntityModel(Collection)
   cModel: Repository<Collection>;
   @InjectEntityModel(User)
   uModel: Repository<User>;
-
+  getQueryColumnsOpera() {
+    const obj = {
+      industry: this.Opera.In,
+    };
+    return obj;
+  }
   // 需求列表
   async list(query) {
     // const { skip = 0, limit = 0, is_use, status, ...condition } = query;

+ 2 - 2
src/service/platform/design.service.ts

@@ -2,9 +2,9 @@ import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
 import { Design } from '../../entity/platform/design.entity';
-import { BaseService } from '../../frame/BaseService';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class DesignService extends BaseService<Design> {
+export class DesignService extends BaseServiceV2 {
   @InjectEntityModel(Design)
   model: Repository<Design>;
 }

+ 2 - 2
src/service/platform/footplate.service.ts

@@ -2,9 +2,9 @@ import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
 import { Footplate } from '../../entity/platform/footplate.entity';
-import { BaseService } from '../../frame/BaseService';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class FootplateService extends BaseService<Footplate> {
+export class FootplateService extends BaseServiceV2 {
   @InjectEntityModel(Footplate)
   model: Repository<Footplate>;
 }

+ 2 - 2
src/service/platform/journal.service.ts

@@ -2,9 +2,9 @@ import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
 import { Journal } from '../../entity/platform/journal.entity';
-import { BaseService } from '../../frame/BaseService';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class JournalService extends BaseService<Journal> {
+export class JournalService extends BaseServiceV2 {
   @InjectEntityModel(Journal)
   model: Repository<Journal>;
 }

+ 2 - 2
src/service/platform/match.service.ts

@@ -4,9 +4,9 @@ import { Collection } from '../../entity/platform/collection.entity';
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Equal, Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class MatchService extends BaseService<Match> {
+export class MatchService extends BaseServiceV2 {
   @InjectEntityModel(Match)
   model: Repository<Match>;
   @InjectEntityModel(Collection)

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

@@ -2,9 +2,9 @@ import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { News } from '../../entity/platform/news.entity';
 import { Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class NewsService extends BaseService<News> {
+export class NewsService extends BaseServiceV2 {
   @InjectEntityModel(News)
   model: Repository<News>;
   // 加浏览量

+ 2 - 2
src/service/platform/notes.service.ts

@@ -2,9 +2,9 @@ import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
 import { Notes } from '../../entity/platform/notes.entity';
-import { BaseService } from '../../frame/BaseService';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class NotesService extends BaseService<Notes> {
+export class NotesService extends BaseServiceV2 {
   @InjectEntityModel(Notes)
   model: Repository<Notes>;
 }

+ 2 - 2
src/service/platform/project.service.ts

@@ -5,9 +5,9 @@ import { get, pick } from 'lodash';
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Equal, In, Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class ProjectService extends BaseService<Project> {
+export class ProjectService extends BaseServiceV2 {
   @InjectEntityModel(Project)
   model: Repository<Project>;
   @InjectEntityModel(Collection)

+ 2 - 2
src/service/platform/sector.service.ts

@@ -1,10 +1,10 @@
 import { Sector } from '../../entity/platform/sector.entity';
-import { BaseService } from '../../frame/BaseService';
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class SectorService extends BaseService<Sector> {
+export class SectorService extends BaseServiceV2 {
   @InjectEntityModel(Sector)
   model: Repository<Sector>;
 }

+ 25 - 25
src/service/platform/sign.service.ts

@@ -5,9 +5,9 @@ import { ErrorCode, ServiceError } from '../../error/service.error';
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Equal, Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class SignService extends BaseService<Sign> {
+export class SignService extends BaseServiceV2 {
   @InjectEntityModel(Sign)
   model: Repository<Sign>;
 
@@ -21,27 +21,27 @@ export class SignService extends BaseService<Sign> {
     if (result) throw new ServiceError(ErrorCode.SERVICE_REPEAT);
   }
 
-  // 列表
-  async sign(query) {
-    const { skip = 0, limit = 0, ...condition } = query;
-    // const list = await this.model.find(condition).skip(skip).limit(limit).lean();
-    const qb = this.queryBuilder(condition);
-    const whereObject = this.buildFindWhere(qb);
-    const builder = this.model.createQueryBuilder().setFindOptions({ where: whereObject, skip, take: limit });
-    const list = await builder.getMany();
-    const total = await builder.getCount();
-    const data = [];
-    for (const val of list) {
-      if (get(val, 'match')) {
-        // 查询需求发布者
-        // const matchInfo = await this.mModel.findById(val.match).lean();
-        const matchInfo = await this.mModel.findOne({ where: { id: Equal(val.match) } });
-        if (matchInfo) {
-          data.push({ ...val, ...{ matchInfo } });
-        }
-      }
-    }
-    // const total = await this.model.count(condition);
-    return { data, total };
-  }
+  // // 列表
+  // async sign(query) {
+  //   const { skip = 0, limit = 0, ...condition } = query;
+  //   // const list = await this.model.find(condition).skip(skip).limit(limit).lean();
+  //   const qb = this.queryBuilder(condition);
+  //   const whereObject = this.buildFindWhere(qb);
+  //   const builder = this.model.createQueryBuilder().setFindOptions({ where: whereObject, skip, take: limit });
+  //   const list = await builder.getMany();
+  //   const total = await builder.getCount();
+  //   const data = [];
+  //   for (const val of list) {
+  //     if (get(val, 'match')) {
+  //       // 查询需求发布者
+  //       // const matchInfo = await this.mModel.findById(val.match).lean();
+  //       const matchInfo = await this.mModel.findOne({ where: { id: Equal(val.match) } });
+  //       if (matchInfo) {
+  //         data.push({ ...val, ...{ matchInfo } });
+  //       }
+  //     }
+  //   }
+  //   // const total = await this.model.count(condition);
+  //   return { data, total };
+  // }
 }

+ 2 - 2
src/service/platform/supply.service.ts

@@ -5,9 +5,9 @@ import { get, pick } from 'lodash';
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Equal, In, Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class SupplyService extends BaseService<Supply> {
+export class SupplyService extends BaseServiceV2 {
   @InjectEntityModel(Supply)
   model: Repository<Supply>;
   @InjectEntityModel(Collection)

+ 2 - 2
src/service/platform/support.service.ts

@@ -2,9 +2,9 @@ import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
 import { Support } from '../../entity/platform/support.entity';
-import { BaseService } from '../../frame/BaseService';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class SupportService extends BaseService<Support> {
+export class SupportService extends BaseServiceV2 {
   @InjectEntityModel(Support)
   model: Repository<Support>;
 }

+ 52 - 0
src/service/serviceUtil.service.ts

@@ -0,0 +1,52 @@
+import { Inject, Provide } from '@midwayjs/core';
+import { get } from 'lodash';
+import { CollectionService } from './platform/collection.service';
+import { UserService } from './system/user.service';
+import { Context } from '@midwayjs/koa';
+import { MatchService } from './platform/match.service';
+
+/**
+ * 工具类服务,为其他地方提供一些通用的函数
+ */
+@Provide()
+export class ServiceUtilService {
+  @Inject()
+  ctx: Context;
+  @Inject()
+  userService: UserService;
+  @Inject()
+  collectionService: CollectionService;
+  @Inject()
+  matchService: MatchService;
+  /**
+   * 填充创建人数据
+   * @param {object} data 数据
+   */
+  async fillOnwer(data) {
+    if (data && get(data, 'user')) {
+      const dataUser = await this.userService.fetch({ id: get(data, 'user') });
+      if (dataUser) data.userInfo = { name: get(dataUser, 'name', ''), phone: get(dataUser, 'phone', '') };
+    }
+  }
+  /**
+   * 填充是否收藏字段: is_collection boolean类型
+   * @param {object} data 数据
+   */
+  async fillCollection(data) {
+    const user = this.ctx.user;
+    if (user && get(user, 'id')) {
+      const collectionData = await this.collectionService.fetch({ user: get(user, 'id'), source: get(data, 'id') });
+      if (collectionData) data.is_collection = true;
+    }
+  }
+  /**
+   * 填充赛事信息
+   * @param {object} data 数据
+   */
+  async fillMatchInfo(data) {
+    const match = get(data, 'match');
+    if (!match) return;
+    const matchInfo = await this.matchService.fetch({ id: match });
+    if (matchInfo) data = { ...data, matchInfo };
+  }
+}

+ 5 - 2
src/service/system/admin.service.ts

@@ -2,9 +2,12 @@ import { Provide } from '@midwayjs/core';
 import { Admin } from '../../entity/system/admin.entity';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class AdminService extends BaseService<Admin> {
+export class AdminService extends BaseServiceV2 {
+  getQueryColumnsOpera(): object {
+    return {}
+  }
   @InjectEntityModel(Admin)
   model: Repository<Admin>;
 

+ 13 - 6
src/service/system/dept.service.ts

@@ -1,15 +1,19 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Equal, In, Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
 import { Dept } from '../../entity/system/dept.entity';
-import { orderBy } from 'lodash';
+import { get, isNumber, orderBy } from 'lodash';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class DeptService extends BaseService<Dept> {
+export class DeptService extends BaseServiceV2 {
+  getQueryColumnsOpera(): object {
+    return {};
+  }
   @InjectEntityModel(Dept)
   model: Repository<Dept>;
   async queryAll() {
-    const data = await this.model.find({ order: { order_num: 'DESC' } });
+    // const data = await this.model.find({ order: { order_num: 'DESC' } });
+    const { data } = await this.query(null, { order: { order_num: 'DESC' } });
     let treeData = data.filter(f => !f.parent_id);
     treeData = this.treeData(data, treeData);
     return treeData;
@@ -17,11 +21,14 @@ export class DeptService extends BaseService<Dept> {
 
   async getNextLevel(id: number, query = { skip: 0, limit: 10 }) {
     const builder = this.model.createQueryBuilder();
-    builder.setFindOptions({ where: { parent_id: Equal(id) }, skip: query.skip, take: query.limit });
+    builder.where(`parent_id = :value`, { value: id });
+    if (isNumber(get(query, 'skip'))) builder.skip(get(query, 'skip'));
+    if (isNumber(get(query, 'limit'))) builder.take(get(query, 'limit'));
     const result = await builder.getMany();
     const total = await builder.getCount();
     const ids = result.map(i => i.parent_id);
-    const parents = await this.model.find({ where: { id: In(ids) }, select: ['id', 'name'] });
+    // const parents = await this.model.find({ where: { id: In(ids) }, select: ['id', 'name'] });
+    const { data: parents } = await this.query({ id: ids }, { selects: ['id', 'name'] }, { id: this.Opera.In });
     result.map(i => {
       if (!i.parent_id) return i;
       const parent = parents.find(f => f.id === i.parent_id);

+ 2 - 2
src/service/system/dictData.service.ts

@@ -1,10 +1,10 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
 import { DictData } from '../../entity/system/dictData.entity';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class DictDataService extends BaseService<DictData> {
+export class DictDataService extends BaseServiceV2 {
   @InjectEntityModel(DictData)
   model: Repository<DictData>;
 }

+ 2 - 2
src/service/system/dictType.service.ts

@@ -1,10 +1,10 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
 import { DictType } from '../../entity/system/dictType.entity';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class DictTypeService extends BaseService<DictType> {
+export class DictTypeService extends BaseServiceV2 {
   @InjectEntityModel(DictType)
   model: Repository<DictType>;
 }

+ 6 - 5
src/service/system/menus.service.ts

@@ -1,20 +1,21 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
 import { Menus } from '../../entity/system/menus.entity';
 import { get, orderBy } from 'lodash';
 import * as fs from 'fs';
 import path = require('path');
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class MenusService extends BaseService<Menus> {
+export class MenusService extends BaseServiceV2 {
+  getQueryColumnsOpera(): object {
+    return {};
+  }
   @InjectEntityModel(Menus)
   model: Repository<Menus>;
 
   async queryMenu(query = {}): Promise<Array<object>> {
-    const qb = this.queryBuilder(query);
-    const whereObj = this.buildFindWhere(qb);
-    const data = await this.model.find({ where: whereObj, order: { order_num: 'ASC' } });
+    const { data } = await this.query(query, { order: { order_num: 'ASC' } });
     let treeMenu = data.filter(f => !f.parent_id);
     treeMenu = this.treeMenu(data, treeMenu);
     return treeMenu;

+ 2 - 1
src/service/system/region.service.ts

@@ -4,8 +4,9 @@ import { BaseService } from '../../frame/BaseService';
 import { Region } from '../../entity/system/region.entity';
 import { get, pick } from 'lodash';
 import { Equal, Repository } from 'typeorm';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class RegionService extends BaseService<Region> {
+export class RegionService extends BaseServiceV2 {
   @InjectEntityModel(Region)
   model: Repository<Region>;
 

+ 19 - 16
src/service/system/role.service.ts

@@ -1,16 +1,15 @@
 import { Inject, Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { In, Repository } from 'typeorm';
-import { BaseService, QueryOpera } from '../../frame/BaseService';
 import { Role } from '../../entity/system/role.entity';
 import { Context } from '@midwayjs/koa';
 import { AdminService } from './admin.service';
 import { compact, flattenDeep, get, isArray, last, lowerFirst, uniq, upperFirst } from 'lodash';
 import { DeptService } from './dept.service';
-import { Opera } from '../../frame/dbOpera';
 import { MenusService } from './menus.service';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class RoleService extends BaseService<Role> {
+export class RoleService extends BaseServiceV2 {
   @InjectEntityModel(Role)
   model: Repository<Role>;
 
@@ -24,12 +23,15 @@ export class RoleService extends BaseService<Role> {
   menusService: MenusService;
   @Inject()
   ctx: Context;
+  getQueryColumnsOpera(): object {
+    return {};
+  }
   //是否是超级管理员
   async isSuperAdmin() {
     const user = this.ctx.user;
     // if (isArray(user.role) && user.role.includes('Admin')) {
     if (user.is_super) {
-      const qb: QueryOpera[] = [{ column: 'id', value: user.id, opera: [Opera.Equal] }];
+      const qb = { id: user.id };
       const admin = await this.adminService.fetch(qb);
       if (!admin) return false;
       if (admin.is_super === '0') return true;
@@ -55,7 +57,7 @@ export class RoleService extends BaseService<Role> {
       return result;
     };
     if (await this.isSuperAdmin()) {
-      const smqb = [{ column: 'is_use', opera: [Opera.Equal], value: '0' }];
+      const smqb = { is_use: '0' };
       const menus = await this.menusService.queryMenu(smqb);
       // 需要整理出所有 config 中 methodCode = ${controllerCode}.${method} ,query 没有二级code
       let apiCodes = getControllerCode(menus);
@@ -69,8 +71,9 @@ export class RoleService extends BaseService<Role> {
     const roleCodes = await this.getRoleCodes(get(user, 'role'));
     let allCodes = [...deptCodes, ...roleCodes];
     allCodes = uniq(allCodes);
-    const qb = [{ column: 'route_name', opera: [Opera.In], value: allCodes }];
-    const { data: menuList } = await this.menusService.query(qb);
+    const qb = { route_name: allCodes };
+    const operas = { route_name: this.Opera.In };
+    const { data: menuList } = await this.menusService.query(qb, null, operas);
     const apiCodes = getControllerCode(menuList);
     return apiCodes;
   }
@@ -94,8 +97,9 @@ export class RoleService extends BaseService<Role> {
     if (needCode) return allCodes;
     // 根据编码获取目录数据
     const menuCodes = this.setMenuCodes(allCodes);
-    const qb = [{ column: 'route_name', opera: [Opera.In], value: menuCodes }];
-    const { data: menuList } = await this.menusService.query(qb);
+    const qb = { route_name: menuCodes };
+    const operas = { route_name: this.Opera.In };
+    const { data: menuList } = await this.menusService.query(qb, null, operas);
     let treeMenu = menuList.filter(f => !f.parent_id);
     treeMenu = this.menusService.treeMenu(menuList, treeMenu);
     return { menus: treeMenu, role_code: allCodes };
@@ -121,7 +125,7 @@ export class RoleService extends BaseService<Role> {
    */
   async getDeptCodes(deptId: number) {
     if (deptId) {
-      const qb: QueryOpera[] = [{ column: 'id', value: deptId, opera: [Opera.Equal] }];
+      const qb = { id: deptId };
       const dept = await this.deptService.fetch(qb);
       if (!dept) return [];
       // 处理部门有的权限
@@ -146,7 +150,8 @@ export class RoleService extends BaseService<Role> {
       roleCodes.push(lowerFirst(rc));
       roleCodes.push(upperFirst(rc));
     }
-    const role = await this.model.findOne({ where: { code: In(roleCode), is_use: '0' } });
+    // const role = await this.model.findOne({ where: { code: In(roleCode), is_use: '0' } });
+    const role = await this.fetch({ code: roleCode }, { code: this.Opera.In });
     if (!role) return [];
     const roleMenu = get(role, 'menu', []);
     return roleMenu;
@@ -163,11 +168,9 @@ export class RoleService extends BaseService<Role> {
       menus.push(...flattenDeep(r));
     }
     menus = uniq(menus);
-    const qb = [
-      { column: 'id', opera: [Opera.In], value: menus },
-      { column: 'is_use', opera: [Opera.Equal], value: '0' },
-    ];
-    const { data: allMenu } = await this.menusService.query(qb, { order: { order_num: 'ASC' } });
+    const qb = { id: menus, is_use: '0' };
+    const operas = { id: this.Opera.In };
+    const { data: allMenu } = await this.menusService.query(qb, { order: { order_num: 'ASC' } }, operas);
     let treeMenu = allMenu.filter(f => !f.parent_id);
     treeMenu = this.menusService.treeMenu(allMenu, treeMenu);
     return treeMenu;

+ 4 - 2
src/service/system/tags.service.ts

@@ -2,9 +2,11 @@ import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
 import { Tags } from '../../entity/system/tags.entity';
-import { BaseService } from '../../frame/BaseService';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class TagsService extends BaseService<Tags> {
+export class TagsService extends BaseServiceV2 {
   @InjectEntityModel(Tags)
   model: Repository<Tags>;
+
+  
 }

+ 2 - 2
src/service/system/user.service.ts

@@ -1,11 +1,11 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Equal, Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
 import { User } from '../../entity/system/user.entity';
 import { ErrorCode, ServiceError } from '../../error/service.error';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class UserService extends BaseService<User> {
+export class UserService extends BaseServiceV2 {
   @InjectEntityModel(User)
   model: Repository<User>;
 

+ 19 - 0
src/service/tests.service.ts

@@ -0,0 +1,19 @@
+import { InjectEntityModel } from '@midwayjs/typeorm';
+import { Repository } from 'typeorm';
+import { Test } from '../entity/test.entity';
+import { BaseServiceV2 } from '../frame/BaseServiceV2';
+import { Provide } from '@midwayjs/core';
+
+@Provide()
+export class TestsService extends BaseServiceV2 {
+  getQueryColumnsOpera(): object {
+    const obj = {
+      nick_name: this.Opera.ILikeRight,
+      hobby: this.Opera.Json,
+      time: this.Opera.IsNotNull,
+    };
+    return obj;
+  }
+  @InjectEntityModel(Test)
+  model: Repository<Test>;
+}

+ 5 - 2
src/service/users/association.service.ts

@@ -1,10 +1,13 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
 import { Association } from '../../entity/users/association.entity';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class AssociationService extends BaseService<Association> {
+export class AssociationService extends BaseServiceV2 {
+  getQueryColumnsOpera(): object {
+    return {};
+  }
   @InjectEntityModel(Association)
   model: Repository<Association>;
 }

+ 16 - 13
src/service/users/company.service.ts

@@ -5,8 +5,12 @@ import { BaseService } from '../../frame/BaseService';
 import { Company } from '../../entity/users/company.entity';
 import { Collection } from '../../entity/platform/collection.entity';
 import { get, pick } from 'lodash';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class CompanyService extends BaseService<Company> {
+export class CompanyService extends BaseServiceV2 {
+  getQueryColumnsOpera(): object {
+    return {};
+  }
   @InjectEntityModel(Company)
   model: Repository<Company>;
   @InjectEntityModel(Collection)
@@ -39,16 +43,15 @@ export class CompanyService extends BaseService<Company> {
   }
 
   // 企业详情
-  async detail(id) {
-    const user = this.ctx.user;
-    const data = { 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) {
-      // 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 };
-  }
+  // 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 };
+  // }
 }

+ 5 - 2
src/service/users/competition.service.ts

@@ -1,10 +1,13 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
 import { Competition } from '../../entity/users/competition.entity';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class CompetitionService extends BaseService<Competition> {
+export class CompetitionService extends BaseServiceV2 {
+  getQueryColumnsOpera(): object {
+    return {};
+  }
   @InjectEntityModel(Competition)
   model: Repository<Competition>;
 }

+ 16 - 13
src/service/users/expert.service.ts

@@ -1,12 +1,15 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Equal, In, Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
 import { Collection } from '../../entity/platform/collection.entity';
 import { Expert } from '../../entity/users/expert.entity';
 import { get, pick } from 'lodash';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class ExpertService extends BaseService<Expert> {
+export class ExpertService extends BaseServiceV2 {
+  getQueryColumnsOpera(): object {
+    return {}
+  }
   @InjectEntityModel(Expert)
   model: Repository<Expert>;
 
@@ -31,15 +34,15 @@ export class ExpertService extends BaseService<Expert> {
   }
 
   // 企业详情
-  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 };
-  }
+  // 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 };
+  // }
 }

+ 2 - 2
src/service/users/incubator.service.ts

@@ -1,10 +1,10 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
 import { Incubator } from '../../entity/users/incubator.entity';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class IncubatorService extends BaseService<Incubator> {
+export class IncubatorService extends BaseServiceV2 {
   @InjectEntityModel(Incubator)
   model: Repository<Incubator>;
 }

+ 2 - 2
src/service/users/investment.service.ts

@@ -1,10 +1,10 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
 import { Investment } from '../../entity/users/investment.entity';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class InvestmentService extends BaseService<Investment> {
+export class InvestmentService extends BaseServiceV2 {
   @InjectEntityModel(Investment)
   model: Repository<Investment>;
 }

+ 2 - 2
src/service/users/state.service.ts

@@ -1,10 +1,10 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
 import { State } from '../../entity/users/state.entity';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class StateService extends BaseService<State> {
+export class StateService extends BaseServiceV2 {
   @InjectEntityModel(State)
   model: Repository<State>;
 }

+ 2 - 2
src/service/users/unit.service.ts

@@ -1,10 +1,10 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
-import { BaseService } from '../../frame/BaseService';
 import { Unit } from '../../entity/users/unit.entity';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
-export class UnitService extends BaseService<Unit> {
+export class UnitService extends BaseServiceV2 {
   @InjectEntityModel(Unit)
   model: Repository<Unit>;
 }

+ 1 - 1
src/service/util.service.ts

@@ -24,7 +24,7 @@ export class UtilService {
   dataSourceManager: TypeORMDataSourceManager;
   async DBTransaction() {
     const dataSource = this.dataSourceManager.getDataSource('default');
-    const data: Test = {
+    const data: any = {
       nick_name: '测试',
       account: `test-${new Date().getTime()}`, //
       hobby: ['睡觉'],