midway-fatcms 0.0.1-beta.6 → 0.0.1-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/controller/base/BaseApiController.js +9 -6
  2. package/dist/controller/gateway/DocGatewayController.js +13 -8
  3. package/dist/controller/home.controller.js +2 -2
  4. package/dist/controller/manage/DeployManageApi.js +6 -4
  5. package/dist/controller/manage/SuperAdminManageApi.js +12 -8
  6. package/dist/controller/manage/SysConfigMangeApi.js +3 -1
  7. package/dist/controller/render/AppRenderController.js +4 -2
  8. package/dist/index.d.ts +1 -0
  9. package/dist/index.js +1 -0
  10. package/dist/libs/global-config/global-config.d.ts +19 -0
  11. package/dist/libs/global-config/global-config.js +25 -0
  12. package/dist/models/SystemTables.d.ts +0 -3
  13. package/dist/models/SystemTables.js +1 -4
  14. package/dist/service/AuthService.js +7 -4
  15. package/dist/service/EnumInfoService.js +7 -4
  16. package/dist/service/FileCenterService.js +13 -9
  17. package/dist/service/SysConfigService.js +4 -2
  18. package/dist/service/UserAccountService.js +10 -6
  19. package/dist/service/VisitStatService.js +4 -2
  20. package/dist/service/WorkbenchService.js +4 -2
  21. package/dist/service/anyapi/AnyApiService.js +4 -2
  22. package/dist/service/crudstd/CrudStdService.js +6 -2
  23. package/dist/service/curd/CurdMixByAccountService.js +4 -2
  24. package/dist/service/curd/CurdMixByDictService.js +4 -2
  25. package/dist/service/curd/CurdMixBySysConfigService.js +4 -2
  26. package/dist/service/curd/CurdMixByWorkbenchService.js +4 -2
  27. package/dist/service/proxyapi/ProxyApiLoadService.js +7 -4
  28. package/package.json +1 -1
  29. package/src/controller/base/BaseApiController.ts +13 -13
  30. package/src/controller/gateway/DocGatewayController.ts +9 -1
  31. package/src/controller/home.controller.ts +4 -6
  32. package/src/controller/manage/DeployManageApi.ts +4 -1
  33. package/src/controller/manage/SuperAdminManageApi.ts +11 -2
  34. package/src/controller/manage/SysConfigMangeApi.ts +4 -1
  35. package/src/controller/render/AppRenderController.ts +17 -14
  36. package/src/index.ts +1 -1
  37. package/src/libs/global-config/global-config.ts +47 -0
  38. package/src/models/SystemTables.ts +0 -4
  39. package/src/service/AuthService.ts +10 -5
  40. package/src/service/EnumInfoService.ts +6 -1
  41. package/src/service/FileCenterService.ts +8 -2
  42. package/src/service/SysConfigService.ts +9 -5
  43. package/src/service/UserAccountService.ts +11 -1
  44. package/src/service/VisitStatService.ts +5 -1
  45. package/src/service/WorkbenchService.ts +6 -1
  46. package/src/service/anyapi/AnyApiService.ts +6 -1
  47. package/src/service/crudstd/CrudStdService.ts +11 -1
  48. package/src/service/curd/CurdMixByAccountService.ts +6 -1
  49. package/src/service/curd/CurdMixByDictService.ts +7 -1
  50. package/src/service/curd/CurdMixBySysConfigService.ts +6 -1
  51. package/src/service/curd/CurdMixByWorkbenchService.ts +5 -1
  52. package/src/service/proxyapi/ProxyApiLoadService.ts +9 -1
@@ -17,6 +17,7 @@ const SystemTables_1 = require("../models/SystemTables");
17
17
  const keys_1 = require("../libs/crud-pro/models/keys");
18
18
  const bizmodels_1 = require("../models/bizmodels");
19
19
  const common_dto_1 = require("../libs/utils/common-dto");
20
+ const global_config_1 = require("../libs/global-config/global-config");
20
21
  // 3天 的秒数
21
22
  const EXPIRE_TIME = 3 * 24 * 60 * 60;
22
23
  const STAT_TYPES = {
@@ -31,6 +32,7 @@ let VisitStatService = class VisitStatService extends BaseService_1.BaseService
31
32
  return this.flushVisitStatToDB();
32
33
  }
33
34
  async flushVisitStatToDB() {
35
+ const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
34
36
  // 统计昨天的数据。
35
37
  const stat_date = new Date(Date.now() - 24 * 3600 * 1000).toISOString().split('T')[0];
36
38
  const lockKey = `vs_lock_${stat_date}`;
@@ -74,8 +76,8 @@ let VisitStatService = class VisitStatService extends BaseService_1.BaseService
74
76
  }
75
77
  }, {
76
78
  sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_INSERT,
77
- sqlDatabase: SystemTables_1.SystemDbName,
78
- sqlDdType: SystemTables_1.SystemDbType,
79
+ sqlDatabase: SystemDbName,
80
+ sqlDdType: SystemDbType,
79
81
  sqlTable: SystemTables_1.SystemTables.sys_visit_stats,
80
82
  });
81
83
  await client.del(key);
@@ -20,6 +20,7 @@ const exceptions_1 = require("../libs/crud-pro/exceptions");
20
20
  const functions_1 = require("../libs/utils/functions");
21
21
  const fatcms_request_1 = require("../libs/utils/fatcms-request");
22
22
  const MixinUtils_1 = require("../libs/crud-pro/utils/MixinUtils");
23
+ const global_config_1 = require("../libs/global-config/global-config");
23
24
  //
24
25
  // const lruCache = new LRUCache<string, any>({
25
26
  // max: 500,
@@ -38,14 +39,15 @@ let WorkbenchService = class WorkbenchService extends BaseService_1.BaseService
38
39
  await this.getAllWorkbenchInfoMap(true);
39
40
  }
40
41
  async getAllWorkbenchInfoList(isForceRefresh) {
42
+ const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
41
43
  let listData = lruCache.get(CACHE_KEY_WORKBENCH_LIST);
42
44
  if (!listData || isForceRefresh === true) {
43
45
  const reqJson = { condition: {}, pageSize: 1000, limit: 1000 };
44
46
  const res = await this.curdProService.executeCrudByCfg(reqJson, {
45
47
  sqlTable: SystemTables_1.SystemTables.sys_workbench,
46
48
  sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
47
- sqlDatabase: SystemTables_1.SystemDbName,
48
- sqlDdType: SystemTables_1.SystemDbType,
49
+ sqlDatabase: SystemDbName,
50
+ sqlDdType: SystemDbType,
49
51
  });
50
52
  listData = res.getResRows();
51
53
  lruCache.set(CACHE_KEY_WORKBENCH_LIST, listData);
@@ -23,6 +23,7 @@ const MixinUtils_1 = require("../../libs/crud-pro/utils/MixinUtils");
23
23
  const WorkbenchService_1 = require("../WorkbenchService");
24
24
  const ValidateUtils_1 = require("../../libs/crud-pro/utils/ValidateUtils");
25
25
  const ApiBaseService_1 = require("../base/ApiBaseService");
26
+ const global_config_1 = require("../../libs/global-config/global-config");
26
27
  const lruCache = new lru_cache_1.LRUCache({
27
28
  max: 500,
28
29
  ttl: 1000 * 60,
@@ -65,12 +66,13 @@ let AnyApiService = class AnyApiService extends ApiBaseService_1.ApiBaseService
65
66
  return anyApi;
66
67
  }
67
68
  async _getAnyApiMethod(methodCode) {
69
+ const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
68
70
  const res = await this.curdMixService.executeCrudByCfg({ condition: { method: methodCode } }, {
69
71
  sqlTable: SystemTables_1.SystemTables.sys_anyapi,
70
72
  method: `get_sys_anyapi_${methodCode}`,
71
73
  sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
72
- sqlDatabase: SystemTables_1.SystemDbName,
73
- sqlDdType: SystemTables_1.SystemDbType,
74
+ sqlDatabase: SystemDbName,
75
+ sqlDdType: SystemDbType,
74
76
  updateCfg: {},
75
77
  });
76
78
  const obj = res.getOneObj();
@@ -21,6 +21,7 @@ const CrudStdRelationService_1 = require("./CrudStdRelationService");
21
21
  const _ = require("lodash");
22
22
  const ApiBaseService_1 = require("../base/ApiBaseService");
23
23
  const DatabaseName_1 = require("../../libs/crud-pro/utils/DatabaseName");
24
+ const global_config_1 = require("../../libs/global-config/global-config");
24
25
  exports.SPECIAL_SETTING_KEY = {
25
26
  QUERY_LIST: 'QUERY_LIST',
26
27
  QUERY_ONE: 'QUERY_ONE',
@@ -53,6 +54,8 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
53
54
  }
54
55
  // 根据用户配置,设置关联查询的数据信息。
55
56
  await this.crudStdRelationService.addCfgModelColumnsRelation(cfgModel, appInfo);
57
+ // 业务系统自定义的修改cfgModel
58
+ await global_config_1.GLOBAL_STATIC_CONFIG.getConfig().addCfgModelForCrudStdService(cfgModel, appInfo);
56
59
  return await this.curdMixService.executeCrudByCfg(params, cfgModel);
57
60
  }
58
61
  /**
@@ -112,12 +115,13 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
112
115
  * @private
113
116
  */
114
117
  async getCrudStdAppInfo(appCode) {
118
+ const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
115
119
  this.logInfo('getCrudStdAppInfo', appCode);
116
120
  const ss = {
117
121
  sqlTable: SystemTables_1.SystemTables.sys_app,
118
122
  sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
119
- sqlDatabase: SystemTables_1.SystemDbName,
120
- sqlDdType: SystemTables_1.SystemDbType,
123
+ sqlDatabase: SystemDbName,
124
+ sqlDdType: SystemDbType,
121
125
  };
122
126
  return await this.curdMixService.executeCrudByCfg({ condition: { app_code: appCode } }, ss);
123
127
  }
@@ -17,10 +17,12 @@ const CurdMixUtils_1 = require("./CurdMixUtils");
17
17
  const SystemTables_1 = require("../../models/SystemTables");
18
18
  const keys_1 = require("../../libs/crud-pro/models/keys");
19
19
  const MixinUtils_1 = require("../../libs/crud-pro/utils/MixinUtils");
20
+ const global_config_1 = require("../../libs/global-config/global-config");
20
21
  const dictMixUtils = new CurdMixUtils_1.CrudMixUtils(CurdMixUtils_1.RelatedType.accountBasic);
21
22
  const TMP_CTX_KEY = _.uniqueId('CurdMixByAccountService');
22
23
  let CurdMixByAccountService = class CurdMixByAccountService {
23
24
  async handleExecuteContextPrepare(executeContext) {
25
+ const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
24
26
  const relations = dictMixUtils.pickColumnRelations(executeContext);
25
27
  if (!relations || relations.length === 0) {
26
28
  return;
@@ -40,8 +42,8 @@ let CurdMixByAccountService = class CurdMixByAccountService {
40
42
  method: 'UserAccountService.queryAccountBasicInfoByIds',
41
43
  sqlTable: SystemTables_1.SystemTables.sys_user_account,
42
44
  sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
43
- sqlDatabase: SystemTables_1.SystemDbName,
44
- sqlDdType: SystemTables_1.SystemDbType,
45
+ sqlDatabase: SystemDbName,
46
+ sqlDdType: SystemDbType,
45
47
  };
46
48
  const reqJson = {
47
49
  columns: ['nick_name', 'avatar', 'account_id'],
@@ -18,6 +18,7 @@ const keys_1 = require("../../libs/crud-pro/models/keys");
18
18
  const MultiKeyMap_1 = require("../../libs/crud-pro/utils/MultiKeyMap");
19
19
  const _ = require("lodash");
20
20
  const RedisCacheService_1 = require("../base/RedisCacheService");
21
+ const global_config_1 = require("../../libs/global-config/global-config");
21
22
  const TMP_CTX_KEY = _.uniqueId('CurdMixByDictService');
22
23
  const dictMixUtils = new CurdMixUtils_1.CrudMixUtils(CurdMixUtils_1.RelatedType.dict);
23
24
  let CurdMixByDictService = class CurdMixByDictService {
@@ -38,6 +39,7 @@ let CurdMixByDictService = class CurdMixByDictService {
38
39
  executeContext[TMP_CTX_KEY] = new MultiKeyMap_1.MultiKeyMap(rows, 'dict_code', 'value');
39
40
  }
40
41
  async getDictItemRows(codes) {
42
+ const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
41
43
  const noCacheCodes = [];
42
44
  // 从缓存里面取
43
45
  let cachedRows = [];
@@ -60,8 +62,8 @@ let CurdMixByDictService = class CurdMixByDictService {
60
62
  }, {
61
63
  sqlTable: SystemTables_1.SystemTables.sys_data_dict_item,
62
64
  sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
63
- sqlDatabase: SystemTables_1.SystemDbName,
64
- sqlDdType: SystemTables_1.SystemDbType,
65
+ sqlDatabase: SystemDbName,
66
+ sqlDdType: SystemDbType,
65
67
  });
66
68
  selectedRows = res1.getResRows();
67
69
  //放到缓存里
@@ -18,10 +18,12 @@ const SystemTables_1 = require("../../models/SystemTables");
18
18
  const keys_1 = require("../../libs/crud-pro/models/keys");
19
19
  const MultiKeyMap_1 = require("../../libs/crud-pro/utils/MultiKeyMap");
20
20
  const parseConfig_1 = require("../../libs/utils/parseConfig");
21
+ const global_config_1 = require("../../libs/global-config/global-config");
21
22
  const dictMixUtils = new CurdMixUtils_1.CrudMixUtils(CurdMixUtils_1.RelatedType.sysCfgEnum);
22
23
  const TMP_CTX_KEY = _.uniqueId('CurdMixBySysConfigService');
23
24
  let CurdMixBySysConfigService = class CurdMixBySysConfigService {
24
25
  async handleExecuteContextPrepare(executeContext) {
26
+ const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
25
27
  const codes = dictMixUtils.pickColumnRelationCodes(executeContext);
26
28
  if (!codes || codes.length === 0) {
27
29
  return;
@@ -31,8 +33,8 @@ let CurdMixBySysConfigService = class CurdMixBySysConfigService {
31
33
  }, {
32
34
  sqlTable: SystemTables_1.SystemTables.sys_configs,
33
35
  sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
34
- sqlDatabase: SystemTables_1.SystemDbName,
35
- sqlDdType: SystemTables_1.SystemDbType,
36
+ sqlDatabase: SystemDbName,
37
+ sqlDdType: SystemDbType,
36
38
  });
37
39
  const rows = res1.getResRows();
38
40
  const multiKeyMap = new MultiKeyMap_1.MultiKeyMap();
@@ -18,6 +18,7 @@ const CurdMixUtils_1 = require("./CurdMixUtils");
18
18
  const SystemTables_1 = require("../../models/SystemTables");
19
19
  const keys_1 = require("../../libs/crud-pro/models/keys");
20
20
  const MixinUtils_1 = require("../../libs/crud-pro/utils/MixinUtils");
21
+ const global_config_1 = require("../../libs/global-config/global-config");
21
22
  const lruCache = new lru_cache_1.LRUCache({
22
23
  max: 500,
23
24
  ttl: 1000 * 60 * 5,
@@ -27,6 +28,7 @@ const workbenchMixUtils = new CurdMixUtils_1.CrudMixUtils(CurdMixUtils_1.Related
27
28
  const TMP_CTX_KEY = _.uniqueId('CurdMixByWorkbenchService');
28
29
  let CurdMixByWorkbenchService = class CurdMixByWorkbenchService {
29
30
  async loadWorkbenchListMap() {
31
+ const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
30
32
  let workbenchListMap = lruCache.get('workbenchListMap');
31
33
  if (!workbenchListMap) {
32
34
  const reqJson = {
@@ -36,8 +38,8 @@ let CurdMixByWorkbenchService = class CurdMixByWorkbenchService {
36
38
  const res = await this.curdProService.executeCrudByCfg(reqJson, {
37
39
  sqlTable: SystemTables_1.SystemTables.sys_workbench,
38
40
  sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
39
- sqlDatabase: SystemTables_1.SystemDbName,
40
- sqlDdType: SystemTables_1.SystemDbType,
41
+ sqlDatabase: SystemDbName,
42
+ sqlDdType: SystemDbType,
41
43
  });
42
44
  const workbenchList = res.getResRows();
43
45
  workbenchListMap = MixinUtils_1.MixinUtils.toNewMap(workbenchList, (obj) => obj.workbench_code);
@@ -24,6 +24,7 @@ const WeightedRandom_1 = require("./WeightedRandom");
24
24
  const WeightedRoundRobin_1 = require("./WeightedRoundRobin");
25
25
  const WorkbenchService_1 = require("../WorkbenchService");
26
26
  const exceptions_1 = require("../../libs/crud-pro/exceptions");
27
+ const global_config_1 = require("../../libs/global-config/global-config");
27
28
  function toUpstreamInfo(config_content) {
28
29
  const obj = (0, functions_1.parseJsonObject)(config_content);
29
30
  if (!obj) {
@@ -79,6 +80,7 @@ let ProxyApiLoadService = class ProxyApiLoadService extends BaseService_1.BaseSe
79
80
  return routeTrie;
80
81
  }
81
82
  async buildUpstreamMap() {
83
+ const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
82
84
  // biz_tag={'upstream'}
83
85
  const res = await this.curdProService.executeCrudByCfg({
84
86
  condition: {
@@ -86,8 +88,8 @@ let ProxyApiLoadService = class ProxyApiLoadService extends BaseService_1.BaseSe
86
88
  },
87
89
  }, {
88
90
  sqlTable: SystemTables_1.SystemTables.sys_configs,
89
- sqlDatabase: SystemTables_1.SystemDbName,
90
- sqlDdType: SystemTables_1.SystemDbType,
91
+ sqlDatabase: SystemDbName,
92
+ sqlDdType: SystemDbType,
91
93
  sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
92
94
  });
93
95
  const upstreamMap = {};
@@ -100,12 +102,13 @@ let ProxyApiLoadService = class ProxyApiLoadService extends BaseService_1.BaseSe
100
102
  return upstreamMap;
101
103
  }
102
104
  async loadProxyApiEntity(workbench_code, upstreamMap) {
105
+ const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
103
106
  const res = await this.curdProService.executeCrudByCfg({
104
107
  condition: {},
105
108
  }, {
106
109
  sqlTable: SystemTables_1.SystemTables.sys_proxyapi,
107
- sqlDatabase: SystemTables_1.SystemDbName,
108
- sqlDdType: SystemTables_1.SystemDbType,
110
+ sqlDatabase: SystemDbName,
111
+ sqlDdType: SystemDbType,
109
112
  sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
110
113
  });
111
114
  const rows0 = res.getResRows();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "midway-fatcms",
3
- "version": "0.0.1-beta.6",
3
+ "version": "0.0.1-beta.7",
4
4
  "description": "This is a midway component sample",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -2,8 +2,8 @@ import { Controller, Inject } from '@midwayjs/core';
2
2
  import { Context } from '@midwayjs/koa';
3
3
  import { CurdMixService } from '../../service/curd/CurdMixService';
4
4
  import { IFuncCfgModel, IRequestCfgModel, IValidatorCfgItem } from '../../libs/crud-pro/interfaces';
5
- import {KeyOfCrudTypes, KeysOfSimpleSQL} from '../../libs/crud-pro/models/keys';
6
- import {SystemDbName, SystemDbType} from '../../models/SystemTables';
5
+ import { KeyOfCrudTypes, KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
6
+ import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
7
7
  import { UserAccountService } from '../../service/UserAccountService';
8
8
  import { RelatedType } from '../../service/curd/CurdMixUtils';
9
9
  import { BaseService } from '../../service/base/BaseService';
@@ -27,7 +27,6 @@ export class BaseApiController extends BaseService {
27
27
  @Inject()
28
28
  protected userAccountService: UserAccountService;
29
29
 
30
-
31
30
  protected getUserSessionInfo() {
32
31
  if (!this.ctx.userSession) {
33
32
  return null;
@@ -35,16 +34,15 @@ export class BaseApiController extends BaseService {
35
34
  return this.ctx.userSession.getSessionInfo();
36
35
  }
37
36
 
38
- async executeSysSQL(executeSql:string, executeSqlArgs: any[]){
39
- return await this.curdMixService.executeSQL(
40
- {
41
- executeSql: executeSql,
42
- executeSqlArgs:executeSqlArgs,
43
- sqlDatabase: SystemDbName,
44
- sqlDdType: SystemDbType,
45
- crudType: KeyOfCrudTypes.SYS_QUERY,
46
- }
47
- );
37
+ async executeSysSQL(executeSql: string, executeSqlArgs: any[]) {
38
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
39
+ return await this.curdMixService.executeSQL({
40
+ executeSql: executeSql,
41
+ executeSqlArgs: executeSqlArgs,
42
+ sqlDatabase: SystemDbName,
43
+ sqlDdType: SystemDbType,
44
+ crudType: KeyOfCrudTypes.SYS_QUERY,
45
+ });
48
46
  }
49
47
 
50
48
  /**
@@ -55,6 +53,7 @@ export class BaseApiController extends BaseService {
55
53
  * @protected
56
54
  */
57
55
  protected async executeSysSimpleSQL(sqlTable: string, sqlSimpleName: KeysOfSimpleSQL, params?: IExecuteSimpleSqlParams) {
56
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
58
57
  const body = this.ctx.request.body as any;
59
58
  const req = this.ctx.req;
60
59
  const cfgModel: IRequestCfgModel = {
@@ -80,6 +79,7 @@ export class BaseApiController extends BaseService {
80
79
  }
81
80
 
82
81
  protected get sysDBUtil() {
82
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
83
83
  return this.curdMixService.getBbUtil(SystemDbName, SystemDbType);
84
84
  }
85
85
 
@@ -1,7 +1,8 @@
1
1
  import {Get, Controller, Inject, Query} from '@midwayjs/core';
2
2
  import {Context} from '@midwayjs/koa';
3
3
  import {BaseApiController} from '../base/BaseApiController';
4
- import {SystemDbName, SystemDbType, SystemTables} from '../../models/SystemTables';
4
+ import { SystemTables} from '../../models/SystemTables';
5
+ import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
5
6
  import {KeysOfSimpleSQL} from '../../libs/crud-pro/models/keys';
6
7
  import {WorkbenchService} from '../../service/WorkbenchService';
7
8
  import {CommonResult} from '../../libs/utils/common-dto';
@@ -37,6 +38,8 @@ export class DocGatewayController extends BaseApiController {
37
38
  return;
38
39
  }
39
40
 
41
+ const {SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
42
+
40
43
  await this.curdMixService.executeCrudByCfg({
41
44
  data: {
42
45
  pv: pv + 1
@@ -69,6 +72,7 @@ export class DocGatewayController extends BaseApiController {
69
72
  return docLibInfoRes;
70
73
  }
71
74
 
75
+ const {SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
72
76
 
73
77
  const res = await this.curdMixService.executeCrudByCfg(
74
78
  {
@@ -107,6 +111,8 @@ export class DocGatewayController extends BaseApiController {
107
111
  return docLibInfoRes;
108
112
  }
109
113
 
114
+ const {SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
115
+
110
116
  return this.curdMixService.executeCrudByCfg(
111
117
  {
112
118
  columns: 'id,title,doc_category_code,sort_index',
@@ -135,6 +141,8 @@ export class DocGatewayController extends BaseApiController {
135
141
  async getDocLibInfo(@Query('docLibId') docLibId: string) {
136
142
  checkIsNumber(docLibId, 'docLibId');
137
143
 
144
+ const {SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
145
+
138
146
  const s = await this.curdMixService.executeCrudByCfg(
139
147
  {
140
148
  condition: {
@@ -2,10 +2,8 @@ import { Controller, Get, Inject } from '@midwayjs/core';
2
2
  import { Context } from '@midwayjs/koa';
3
3
  import { BaseApiController } from './base/BaseApiController';
4
4
  import { WorkbenchService } from '../service/WorkbenchService';
5
- import { createRenderUtils } from "../libs/utils/render-utils";
6
- import { privateAES } from "../libs/utils/crypto-utils";
7
-
8
-
5
+ import { createRenderUtils } from '../libs/utils/render-utils';
6
+ import { privateAES } from '../libs/utils/crypto-utils';
9
7
 
10
8
  @Controller('/')
11
9
  export class HomeController extends BaseApiController {
@@ -36,14 +34,14 @@ export class HomeController extends BaseApiController {
36
34
 
37
35
  const userInfo = this.getUserSessionInfo();
38
36
 
39
- const fatcmscsrftoken = await privateAES.time_encrypt_utf8_base64("" + Date.now());
37
+ const fatcmscsrftoken = await privateAES.time_encrypt_utf8_base64('' + Date.now());
40
38
 
41
39
  const utils = createRenderUtils({
42
40
  ctx: this.ctx,
43
41
  userInfo,
44
42
  workbenchInfo,
45
43
  package_assets: workbenchInfo.package_assets,
46
- fatcmscsrftoken
44
+ fatcmscsrftoken,
47
45
  });
48
46
 
49
47
  return this.ctx.renderString(html_content, { workbenchInfo, userInfo, utils }, { viewEngine: 'ejs' });
@@ -7,9 +7,10 @@ import {CommonResult} from "../../libs/utils/common-dto";
7
7
  import {AccessType, UploadCategoryType} from "../../models/bizmodels";
8
8
  import {BizException} from "../../models/devops";
9
9
  import {FileCenterService, toDownloadPaths} from '../../service/FileCenterService';
10
- import {SystemDbName, SystemDbType, SystemTables} from "../../models/SystemTables";
10
+ import {SystemTables} from "../../models/SystemTables";
11
11
  import {KeysOfSimpleSQL} from "../../libs/crud-pro/models/keys";
12
12
  import {WorkbenchService} from "../../service/WorkbenchService";
13
+ import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
13
14
 
14
15
 
15
16
  interface IReleaseAssetsParams {
@@ -128,6 +129,8 @@ export class DeployManageApi extends BaseApiController {
128
129
  throw new BizException('cdnResources参数不存在');
129
130
  }
130
131
 
132
+ const {SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
133
+
131
134
  const workbench = await this.curdMixService.executeCrudByCfg({
132
135
  data: {
133
136
  package_assets: JSON.stringify(toAssetsSchema(cdnResources)),
@@ -5,8 +5,9 @@ import { KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
5
5
  import { BaseApiController } from '../base/BaseApiController';
6
6
  import { checkRole } from '../../middleware/permission.middleware';
7
7
  import { SystemFuncCodeNameMap, SystemRoleCode, SystemRoleCodeNameMap } from '../../models/SystemPerm';
8
- import {SystemDbName, SystemDbType, SystemTables} from '../../models/SystemTables';
9
- import {CommonResult} from "../../libs/utils/common-dto";
8
+ import { SystemTables } from '../../models/SystemTables';
9
+ import { CommonResult } from "../../libs/utils/common-dto";
10
+ import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
10
11
 
11
12
  @Controller('/ns/api/manage/superAdmin', { middleware: [checkRole(SystemRoleCode.SuperAdmin)] })
12
13
  export class SuperAdminManageApi extends BaseApiController {
@@ -22,6 +23,8 @@ export class SuperAdminManageApi extends BaseApiController {
22
23
  */
23
24
  @Post('/presetsFuncCode')
24
25
  async presetsFuncCode() {
26
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
27
+
25
28
  const funcCodeList = Object.keys(SystemFuncCodeNameMap);
26
29
  for (let i = 0; i < funcCodeList.length; i++) {
27
30
  const funcCode = funcCodeList[i];
@@ -52,6 +55,9 @@ export class SuperAdminManageApi extends BaseApiController {
52
55
  */
53
56
  @Post('/presetsRoleCode')
54
57
  async presetsRoleCode() {
58
+
59
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
60
+
55
61
  const roleCodeList = [SystemRoleCode.DevOpsViewer, SystemRoleCode.DevOpsWriter];
56
62
 
57
63
  for (let i = 0; i < roleCodeList.length; i++) {
@@ -82,6 +88,9 @@ export class SuperAdminManageApi extends BaseApiController {
82
88
  */
83
89
  @Post('/presetsRoleFuncList')
84
90
  async presetsRoleFuncList() {
91
+
92
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
93
+
85
94
  const funcCodeList = Object.keys(SystemFuncCodeNameMap);
86
95
  for (let i = 0; i < funcCodeList.length; i++) {
87
96
  const funcCode = funcCodeList[i];
@@ -5,8 +5,9 @@ import { BaseApiController } from '../base/BaseApiController';
5
5
  import { checkPermission } from '../../middleware/permission.middleware';
6
6
  import { SystemFuncCode } from '../../models/SystemPerm';
7
7
  import { CTX_WORKBENCH_CODE } from '../../models/bizmodels';
8
- import {SystemDbName, SystemDbType, SystemTables} from "../../models/SystemTables";
8
+ import {SystemTables} from "../../models/SystemTables";
9
9
  import {CommonResult} from "../../libs/utils/common-dto";
10
+ import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
10
11
 
11
12
  @Controller('/ns/api/manage/sysconfig', { middleware: [checkPermission(SystemFuncCode.SysConfigMangeRead)] })
12
13
  export class SysConfigMangeApi extends BaseApiController {
@@ -48,6 +49,8 @@ export class SysConfigMangeApi extends BaseApiController {
48
49
 
49
50
  @Post('/updateSysConfig', { middleware: [checkPermission(SystemFuncCode.SysConfigMangeWrite)] })
50
51
  async updateSysConfig() {
52
+
53
+ const {SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
51
54
 
52
55
  const body = this.ctx.request.body as any;
53
56
  const id = body.condition.id;
@@ -1,11 +1,12 @@
1
- import {Inject, Controller, Get, Param} from '@midwayjs/core';
2
- import {Context} from '@midwayjs/koa';
3
- import {BaseApiController} from '../base/BaseApiController';
4
- import {KeysOfSimpleSQL} from '../../libs/crud-pro/models/keys';
5
- import {SystemDbName, SystemDbType, SystemTables} from '../../models/SystemTables';
6
- import {WorkbenchService} from '../../service/WorkbenchService';
7
- import {createRenderUtils} from "../../libs/utils/render-utils";
8
- import {privateAES} from "../../libs/utils/crypto-utils";
1
+ import { Inject, Controller, Get, Param } from '@midwayjs/core';
2
+ import { Context } from '@midwayjs/koa';
3
+ import { BaseApiController } from '../base/BaseApiController';
4
+ import { KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
5
+ import { SystemTables } from '../../models/SystemTables';
6
+ import { WorkbenchService } from '../../service/WorkbenchService';
7
+ import { createRenderUtils } from "../../libs/utils/render-utils";
8
+ import { privateAES } from "../../libs/utils/crypto-utils";
9
+ import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
9
10
 
10
11
 
11
12
  /**
@@ -21,11 +22,13 @@ export class AppRenderController extends BaseApiController {
21
22
 
22
23
  @Get('/:appPath+')
23
24
  async home(@Param('appPath') appPath: string): Promise<string> {
25
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
26
+
24
27
  const appPathArr = appPath.split('/');
25
28
  const appCode = appPathArr[0];
26
29
 
27
30
  const res = await this.curdMixService.executeCrudByCfg(
28
- {condition: {app_code: appCode}},
31
+ { condition: { app_code: appCode } },
29
32
  {
30
33
  sqlTable: SystemTables.sys_app,
31
34
  sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
@@ -34,21 +37,21 @@ export class AppRenderController extends BaseApiController {
34
37
  }
35
38
  );
36
39
 
37
- const {row: appInfo} = res.getResModel();
40
+ const { row: appInfo } = res.getResModel();
38
41
  if (!appInfo) {
39
42
  this.ctx.status = 404;
40
- return this.ctx.render('404_app', {appCode, errorMsg: ' 应用不存在'});
43
+ return this.ctx.render('404_app', { appCode, errorMsg: ' 应用不存在' });
41
44
  }
42
45
 
43
46
  if (appInfo.status !== 1) {
44
47
  this.ctx.status = 404;
45
- return this.ctx.render('404_app', {appCode, errorMsg: ' 应用已下线'});
48
+ return this.ctx.render('404_app', { appCode, errorMsg: ' 应用已下线' });
46
49
  }
47
50
 
48
51
  const isSupportWorkbench = await this.isSupportCurrentWorkbench(appInfo);
49
52
  if (!isSupportWorkbench) {
50
53
  this.ctx.status = 404;
51
- return this.ctx.render('404_app', {appCode, errorMsg: ' 应用没有绑定此站点'});
54
+ return this.ctx.render('404_app', { appCode, errorMsg: ' 应用没有绑定此站点' });
52
55
  }
53
56
 
54
57
  const workbenchInfo = await this.workbenchService.getCurrentHostWorkbenchInfo();
@@ -61,7 +64,7 @@ export class AppRenderController extends BaseApiController {
61
64
  ctx: this.ctx,
62
65
  appInfo, workbenchInfo, userInfo, package_assets: appInfo.package_assets, fatcmscsrftoken
63
66
  });
64
- return this.ctx.renderString(html_content, {appInfo, workbenchInfo, userInfo, utils}, {viewEngine: 'ejs'});
67
+ return this.ctx.renderString(html_content, { appInfo, workbenchInfo, userInfo, utils }, { viewEngine: 'ejs' });
65
68
  }
66
69
 
67
70
 
package/src/index.ts CHANGED
@@ -96,4 +96,4 @@ export * from './libs/crud-pro/models/ExecuteContextFunc';
96
96
  export * from './libs/crud-pro/models/RequestCfgModel';
97
97
  export * from './libs/crud-pro/models/SqlSegArg';
98
98
 
99
-
99
+ export * from './libs/global-config/global-config';
@@ -0,0 +1,47 @@
1
+ import { SqlDbType } from "../crud-pro/models/keys";
2
+
3
+ interface IGlobalStaticConfig {
4
+ /**
5
+ * CrudStd: 业务系统自定义的修改cfgModel
6
+ * @param cfgModel
7
+ * @param appInfo
8
+ */
9
+ addCfgModelForCrudStdService(cfgModel: any, appInfo: any): Promise<any>;
10
+
11
+ SystemDbName: string,
12
+ SystemDbType: SqlDbType;
13
+ }
14
+
15
+
16
+ function noop() { }
17
+
18
+
19
+ class GlobalStaticConfig {
20
+ private configObject: any;
21
+ constructor() {
22
+ this.configObject = {
23
+ addCfgModelForCrudStdService: noop,
24
+ SystemDbName: 'fatcms',
25
+ SystemDbType: SqlDbType.mysql
26
+ };
27
+ }
28
+ public getConfig(): IGlobalStaticConfig {
29
+ return this.configObject as IGlobalStaticConfig;
30
+ }
31
+
32
+ public setConfig(configObject: any) {
33
+ if (!configObject || typeof configObject !== 'object') {
34
+ throw new Error("参数configObject不能为空")
35
+ }
36
+ Object.assign(this.configObject, configObject)
37
+ }
38
+ }
39
+
40
+
41
+ const GLOBAL_STATIC_CONFIG = new GlobalStaticConfig();
42
+
43
+
44
+
45
+ export {
46
+ GLOBAL_STATIC_CONFIG
47
+ }
@@ -1,5 +1,3 @@
1
- import {SqlDbType} from "../libs/crud-pro/models/keys";
2
-
3
1
  export const SystemTables = {
4
2
  sys_workbench: 'sys_workbench',
5
3
  sys_user_account: 'sys_user_account',
@@ -24,7 +22,5 @@ export const SystemTables = {
24
22
  sys_visit_stats: 'sys_visit_stats',
25
23
  };
26
24
 
27
- export const SystemDbName = 'fatcms';
28
- export const SystemDbType = SqlDbType.mysql;
29
25
 
30
26
  export const SystemDevOpsWorkbench = 'devops';