midway-fatcms 0.0.1-beta.13 → 0.0.1-beta.16

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 (86) hide show
  1. package/README.md +7 -0
  2. package/dist/configuration.d.ts +1 -0
  3. package/dist/configuration.js +21 -8
  4. package/dist/controller/base/BaseApiController.d.ts +1 -1
  5. package/dist/controller/gateway/AsyncTaskController.js +17 -6
  6. package/dist/controller/gateway/CrudMtdGatewayController.d.ts +3 -3
  7. package/dist/controller/gateway/CrudMtdGatewayController.js +5 -5
  8. package/dist/index.d.ts +7 -0
  9. package/dist/index.js +7 -0
  10. package/dist/libs/crud-pro/CrudPro.d.ts +1 -0
  11. package/dist/libs/crud-pro/CrudPro.js +5 -0
  12. package/dist/libs/crud-pro/defaultConfigs.js +2 -0
  13. package/dist/libs/crud-pro/interfaces.d.ts +6 -0
  14. package/dist/libs/crud-pro/models/ExecuteContext.d.ts +2 -1
  15. package/dist/libs/crud-pro/models/ExecuteContextFunc.d.ts +8 -1
  16. package/dist/libs/crud-pro/models/ExecuteContextFunc.js +8 -0
  17. package/dist/libs/crud-pro/models/ResModel.d.ts +16 -0
  18. package/dist/libs/crud-pro/models/ResModel.js +2 -0
  19. package/dist/libs/crud-pro/services/CrudProCachedCfgService.d.ts +1 -0
  20. package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +22 -11
  21. package/dist/libs/crud-pro/services/CrudProServiceBase.d.ts +2 -6
  22. package/dist/libs/crud-pro/services/CrudProServiceBase.js +3 -2
  23. package/dist/libs/crud-pro/services/CrudProTableMetaService.d.ts +1 -0
  24. package/dist/libs/crud-pro/services/CrudProTableMetaService.js +31 -7
  25. package/dist/libs/crud-pro/utils/DatabaseName.js +24 -3
  26. package/dist/libs/global-config/global-config.d.ts +6 -0
  27. package/dist/libs/global-config/global-config.js +1 -0
  28. package/dist/models/AsyncTaskModel.d.ts +13 -11
  29. package/dist/models/AsyncTaskModel.js +23 -23
  30. package/dist/schedule/anonymousContext.d.ts +13 -0
  31. package/dist/schedule/anonymousContext.js +59 -0
  32. package/dist/schedule/index.d.ts +4 -4
  33. package/dist/schedule/index.js +9 -68
  34. package/dist/schedule/runSchedule.d.ts +6 -0
  35. package/dist/schedule/runSchedule.js +34 -0
  36. package/dist/schedule/scheduleNames.d.ts +8 -0
  37. package/dist/schedule/scheduleNames.js +17 -0
  38. package/dist/service/asyncTask/AsyncTaskRunnerService.d.ts +14 -0
  39. package/dist/service/asyncTask/AsyncTaskRunnerService.js +66 -16
  40. package/dist/service/asyncTask/AsyncTaskService.js +2 -1
  41. package/dist/service/crudstd/CrudStdService.d.ts +1 -0
  42. package/dist/service/crudstd/CrudStdService.js +27 -0
  43. package/dist/service/curd/CrudProQuick.d.ts +24 -0
  44. package/dist/service/curd/CrudProQuick.js +105 -0
  45. package/dist/service/curd/CurdMixByLinkToCustomService.d.ts +10 -1
  46. package/dist/service/curd/CurdMixByLinkToCustomService.js +71 -23
  47. package/dist/service/curd/CurdMixService.d.ts +1 -1
  48. package/dist/service/curd/CurdMixService.js +2 -2
  49. package/dist/service/curd/CurdMixUtils.js +35 -28
  50. package/dist/service/curd/CurdProService.d.ts +2 -10
  51. package/dist/service/curd/CurdProService.js +28 -143
  52. package/dist/service/curd/fixCfgModel.d.ts +3 -0
  53. package/dist/service/curd/fixCfgModel.js +107 -0
  54. package/package.json +1 -1
  55. package/src/configuration.ts +30 -10
  56. package/src/controller/gateway/AnyApiGatewayController.ts +1 -1
  57. package/src/controller/gateway/AsyncTaskController.ts +21 -8
  58. package/src/controller/gateway/CrudMtdGatewayController.ts +5 -5
  59. package/src/controller/manage/DocManageApi.ts +5 -5
  60. package/src/index.ts +7 -0
  61. package/src/libs/crud-pro/CrudPro.ts +8 -0
  62. package/src/libs/crud-pro/defaultConfigs.ts +2 -0
  63. package/src/libs/crud-pro/interfaces.ts +10 -1
  64. package/src/libs/crud-pro/models/ExecuteContext.ts +5 -2
  65. package/src/libs/crud-pro/models/ExecuteContextFunc.ts +12 -1
  66. package/src/libs/crud-pro/models/ResModel.ts +24 -0
  67. package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +26 -17
  68. package/src/libs/crud-pro/services/CrudProServiceBase.ts +5 -8
  69. package/src/libs/crud-pro/services/CrudProTableMetaService.ts +43 -9
  70. package/src/libs/crud-pro/utils/DatabaseName.ts +35 -15
  71. package/src/libs/global-config/global-config.ts +12 -1
  72. package/src/models/AsyncTaskModel.ts +14 -11
  73. package/src/schedule/anonymousContext.ts +79 -0
  74. package/src/schedule/index.ts +13 -72
  75. package/src/schedule/runSchedule.ts +35 -0
  76. package/src/schedule/scheduleNames.ts +20 -0
  77. package/src/service/asyncTask/AsyncTaskRunnerService.ts +91 -24
  78. package/src/service/asyncTask/AsyncTaskService.ts +3 -2
  79. package/src/service/base/BaseService.ts +2 -2
  80. package/src/service/crudstd/CrudStdService.ts +34 -6
  81. package/src/service/curd/CrudProQuick.ts +137 -0
  82. package/src/service/curd/CurdMixByLinkToCustomService.ts +100 -49
  83. package/src/service/curd/CurdMixService.ts +3 -3
  84. package/src/service/curd/CurdMixUtils.ts +51 -38
  85. package/src/service/curd/CurdProService.ts +42 -186
  86. package/src/service/curd/fixCfgModel.ts +139 -0
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CrudProQuick = void 0;
4
+ const keys_1 = require("../../libs/crud-pro/models/keys");
5
+ class CrudProQuick {
6
+ constructor(curdPro, sqlDatabase, sqlDbType, sqlTable) {
7
+ this.baseCfgModel = {};
8
+ this.sqlDatabase = sqlDatabase;
9
+ this.sqlDbType = sqlDbType;
10
+ this.curdPro = curdPro;
11
+ this.sqlTable = sqlTable; // 全局sqlTable为空时,单独调用时就必须传sqlTable参数。
12
+ }
13
+ setBaseCfgModel(baseCfgModel) {
14
+ Object.assign(this.baseCfgModel, baseCfgModel);
15
+ }
16
+ async executeCrudByCfg(reqJson, cfgModel2) {
17
+ const cfgModel = { ...this.baseCfgModel };
18
+ Object.assign(cfgModel, cfgModel2);
19
+ cfgModel.method = 'CrudProQuickAnonymous';
20
+ cfgModel.updateCfg = {};
21
+ cfgModel.sqlDatabase = this.sqlDatabase;
22
+ cfgModel.sqlDbType = this.sqlDbType;
23
+ if (!cfgModel.sqlTable) {
24
+ cfgModel.sqlTable = this.sqlTable;
25
+ }
26
+ if (!cfgModel.sqlTable) {
27
+ throw new Error('[CrudProQuick] sqlTable not found');
28
+ }
29
+ return await this.curdPro.executeCrudByCfg(reqJson, cfgModel);
30
+ }
31
+ async getOne(reqJson, sqlTable) {
32
+ const cfgModel = {
33
+ sqlTable,
34
+ sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
35
+ };
36
+ const res = await this.executeCrudByCfg(reqJson, cfgModel);
37
+ return res.getOneObj();
38
+ }
39
+ async getList(reqJson, sqlTable) {
40
+ const cfgModel = {
41
+ sqlTable,
42
+ sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
43
+ };
44
+ const res = await this.executeCrudByCfg(reqJson, cfgModel);
45
+ return res.getResRows();
46
+ }
47
+ async getListPage(reqJson, sqlTable) {
48
+ const cfgModel = {
49
+ sqlTable,
50
+ sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE,
51
+ };
52
+ const res = await this.executeCrudByCfg(reqJson, cfgModel);
53
+ return res.getResModel(); // 因为它有2个返回值
54
+ }
55
+ async getTotalCount(reqJson, sqlTable) {
56
+ const cfgModel = {
57
+ sqlTable,
58
+ sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_COUNT,
59
+ };
60
+ const res = await this.executeCrudByCfg(reqJson, cfgModel);
61
+ return res.getResModel().total_count;
62
+ }
63
+ async insertObject(reqJson, sqlTable) {
64
+ const cfgModel = {
65
+ sqlTable,
66
+ sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_INSERT,
67
+ };
68
+ const res = await this.executeCrudByCfg(reqJson, cfgModel);
69
+ return res.getResModel().affected;
70
+ }
71
+ async updateObject(reqJson, sqlTable) {
72
+ const cfgModel = {
73
+ sqlTable,
74
+ sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE,
75
+ };
76
+ const res = await this.executeCrudByCfg(reqJson, cfgModel);
77
+ return res.getResModel().affected;
78
+ }
79
+ async insertOrUpdate(reqJson, sqlTable) {
80
+ const cfgModel = {
81
+ sqlTable,
82
+ sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_INSERT_OR_UPDATE,
83
+ };
84
+ const res = await this.executeCrudByCfg(reqJson, cfgModel);
85
+ return res.getResModel(); // 因为它有三个返回值
86
+ }
87
+ async deleteObject(reqJson, sqlTable) {
88
+ const cfgModel = {
89
+ sqlTable,
90
+ sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_DELETE,
91
+ };
92
+ const res = await this.executeCrudByCfg(reqJson, cfgModel);
93
+ return res.getResModel().affected;
94
+ }
95
+ async executeSQL(executeSql, args) {
96
+ const sqlCfgModel = {
97
+ executeSql: executeSql,
98
+ executeSqlArgs: args,
99
+ sqlDatabase: this.sqlDatabase,
100
+ sqlDbType: this.sqlDbType,
101
+ };
102
+ return await this.curdPro.executeSQL(sqlCfgModel);
103
+ }
104
+ }
105
+ exports.CrudProQuick = CrudProQuick;
@@ -1,7 +1,7 @@
1
1
  import { Context } from '@midwayjs/koa';
2
2
  import { CurdProService } from './CurdProService';
3
3
  import { ExecuteContext, IExecuteContextHandler } from '../../libs/crud-pro/models/ExecuteContext';
4
- import { RedisCacheService } from "../base/RedisCacheService";
4
+ import { RedisCacheService } from '../base/RedisCacheService';
5
5
  export declare class CurdMixByLinkToCustomService implements IExecuteContextHandler {
6
6
  protected ctx: Context;
7
7
  protected curdProService: CurdProService;
@@ -13,10 +13,19 @@ export declare class CurdMixByLinkToCustomService implements IExecuteContextHand
13
13
  * code形如:mysql_________fatcms~~~sys_perm_role~~~role_code,role_name,xxx_name
14
14
  * code形如:fatcms~~~sys_perm_role~~~role_code,role_name,xxx_name
15
15
  * code形如:fatcms~~~sys_perm_role~~~id,*
16
+ * code形如:GET_BY_CRUD_METHOD~~~GetActiveLineEnum~~~id,*
17
+ * code形如:GET_BY_CRUD_METHOD~~~GetActiveLineEnum~~~id,name
16
18
  * 【数据库】~~~【表名】~~~【value】,【label】,【style】
17
19
  * @param code
18
20
  * @private
19
21
  */
20
22
  private queryInfoByLinkToCustomImpl;
23
+ /**
24
+ *
25
+ * @param code
26
+ * code形如:GET_BY_CRUD_METHOD~~~GetActiveLineEnum~~~id,*
27
+ * code形如:GET_BY_CRUD_METHOD~~~GetActiveLineEnum~~~id,name
28
+ */
29
+ private queryInfoByLinkToCustomByCrudMethod;
21
30
  private loadInfoByLinkToCustomMap;
22
31
  }
@@ -19,8 +19,32 @@ const devops_1 = require("../../models/devops");
19
19
  const exceptions_1 = require("../../libs/crud-pro/exceptions");
20
20
  const RedisCacheService_1 = require("../base/RedisCacheService");
21
21
  const DatabaseName_1 = require("../../libs/crud-pro/utils/DatabaseName");
22
+ const global_config_1 = require("../../libs/global-config/global-config");
22
23
  const linkToCustomMixUtils = new CurdMixUtils_1.CrudMixUtils(CurdMixUtils_1.RelatedType.linkToCustom);
23
24
  const TMP_CTX_KEY = _.uniqueId('CurdMixByLinkToCustomService');
25
+ function toMapObject(rows, fieldsArr) {
26
+ const valueKey = fieldsArr[0];
27
+ const labelKey = fieldsArr[1];
28
+ const isObjectMode = fieldsArr.length > 2 || labelKey === '*';
29
+ const map = new Map();
30
+ for (let i = 0; i < rows.length; i++) {
31
+ const rowObj = rows[i];
32
+ const value = rowObj[valueKey];
33
+ if (typeof value !== 'undefined') {
34
+ const valueStr = '' + value;
35
+ if (isObjectMode) {
36
+ map.set(valueStr, rowObj);
37
+ }
38
+ else {
39
+ const label = rowObj[labelKey];
40
+ if (label) {
41
+ map.set(valueStr, label);
42
+ }
43
+ }
44
+ }
45
+ }
46
+ return map;
47
+ }
24
48
  let CurdMixByLinkToCustomService = class CurdMixByLinkToCustomService {
25
49
  async handleExecuteContextPrepare(executeContext) {
26
50
  const relations = linkToCustomMixUtils.pickColumnRelations(executeContext);
@@ -43,8 +67,8 @@ let CurdMixByLinkToCustomService = class CurdMixByLinkToCustomService {
43
67
  if (!Array.isArray(targetColumns) || targetColumns.length === 0) {
44
68
  columnRelation.targetColumns = [
45
69
  {
46
- "from": "*",
47
- "to": `${sourceColumn}_info[$ARRAY_INDEX]`
70
+ from: '*',
71
+ to: `${sourceColumn}_info[$ARRAY_INDEX]`,
48
72
  },
49
73
  ];
50
74
  }
@@ -54,7 +78,7 @@ let CurdMixByLinkToCustomService = class CurdMixByLinkToCustomService {
54
78
  });
55
79
  }
56
80
  async queryInfoByLinkToCustom(code) {
57
- const cacheKey = "linkToCustom@@" + code;
81
+ const cacheKey = 'linkToCustom@@' + code;
58
82
  let values;
59
83
  const expireSecond = 2 * 60; // 2分钟
60
84
  const enumMap = await this.redisCacheService.getJsonObject(cacheKey);
@@ -68,11 +92,16 @@ let CurdMixByLinkToCustomService = class CurdMixByLinkToCustomService {
68
92
  * code形如:mysql_________fatcms~~~sys_perm_role~~~role_code,role_name,xxx_name
69
93
  * code形如:fatcms~~~sys_perm_role~~~role_code,role_name,xxx_name
70
94
  * code形如:fatcms~~~sys_perm_role~~~id,*
95
+ * code形如:GET_BY_CRUD_METHOD~~~GetActiveLineEnum~~~id,*
96
+ * code形如:GET_BY_CRUD_METHOD~~~GetActiveLineEnum~~~id,name
71
97
  * 【数据库】~~~【表名】~~~【value】,【label】,【style】
72
98
  * @param code
73
99
  * @private
74
100
  */
75
101
  async queryInfoByLinkToCustomImpl(code) {
102
+ if (code.startsWith('GET_BY_CRUD_METHOD')) {
103
+ return this.queryInfoByLinkToCustomByCrudMethod(code);
104
+ }
76
105
  const arr = code
77
106
  .split('~~~')
78
107
  .map(s => s.trim())
@@ -89,12 +118,10 @@ let CurdMixByLinkToCustomService = class CurdMixByLinkToCustomService {
89
118
  if (fieldsArr.length < 2) {
90
119
  throw new devops_1.BizException('linkToCustom枚举值查询字符串,fields字段必须符合固定格式', exceptions_1.Exceptions.CFG_ERROR);
91
120
  }
92
- const valueKey = fieldsArr[0];
93
121
  const labelKey = fieldsArr[1];
94
- const isObjectMode = fieldsArr.length > 2 || labelKey === "*";
95
122
  const res1 = await this.curdProService.executeCrudByCfg({
96
123
  condition: {},
97
- columns: labelKey === "*" ? null : fields,
124
+ columns: labelKey === '*' ? null : fields,
98
125
  limit: 4000,
99
126
  offset: 0,
100
127
  }, {
@@ -105,30 +132,51 @@ let CurdMixByLinkToCustomService = class CurdMixByLinkToCustomService {
105
132
  maxLimit: 4000,
106
133
  });
107
134
  const rows = res1.getResRows();
108
- const map = new Map();
109
- for (let i = 0; i < rows.length; i++) {
110
- const rowObj = rows[i];
111
- const value = rowObj[valueKey];
112
- if (typeof value !== 'undefined') {
113
- const valueStr = "" + value;
114
- if (isObjectMode) {
115
- map.set(valueStr, rowObj);
116
- }
117
- else {
118
- const label = rowObj[labelKey];
119
- if (label) {
120
- map.set(valueStr, label);
121
- }
122
- }
123
- }
135
+ const map = toMapObject(rows, fieldsArr);
136
+ return map;
137
+ }
138
+ /**
139
+ *
140
+ * @param code
141
+ * code形如:GET_BY_CRUD_METHOD~~~GetActiveLineEnum~~~id,*
142
+ * code形如:GET_BY_CRUD_METHOD~~~GetActiveLineEnum~~~id,name
143
+ */
144
+ async queryInfoByLinkToCustomByCrudMethod(code) {
145
+ const arr = code
146
+ .split('~~~')
147
+ .map(s => s.trim())
148
+ .filter(Boolean);
149
+ if (arr.length !== 3) {
150
+ throw new devops_1.BizException('linkToCustom枚举值查询字符串,必须符合固定格式。', exceptions_1.Exceptions.CFG_ERROR);
151
+ }
152
+ const [prefix, methodCode, fields] = arr;
153
+ const fieldsArr = fields
154
+ .split(',')
155
+ .map(s => s.trim())
156
+ .filter(Boolean);
157
+ if (fieldsArr.length < 2) {
158
+ throw new devops_1.BizException(`linkToCustom枚举值查询字符串,fields字段必须符合固定格式。${prefix}`, exceptions_1.Exceptions.CFG_ERROR);
159
+ }
160
+ const methodInfo = (await this.curdProService.getCachedCfgByMethod(methodCode));
161
+ if (!methodInfo || methodInfo.status !== 1) {
162
+ throw new Error('接口不存在或已下线: ' + methodCode);
124
163
  }
164
+ const cfgModel = methodInfo;
165
+ const { dbType, dbName } = (0, DatabaseName_1.parseDatabaseName)(cfgModel.sqlDatabase);
166
+ cfgModel.sqlDatabase = dbName;
167
+ cfgModel.sqlDbType = dbType;
168
+ const reqJson = {};
169
+ await global_config_1.GLOBAL_STATIC_CONFIG.getConfig().bizUpdateCfgModelForCrudMtd(reqJson, cfgModel, methodInfo, this.ctx);
170
+ const exeCtx = await this.curdProService.executeCrudByCfg(reqJson, cfgModel);
171
+ const rows = exeCtx.getResRows();
172
+ const map = toMapObject(rows, fieldsArr);
125
173
  return map;
126
174
  }
127
175
  async loadInfoByLinkToCustomMap(relations) {
128
176
  const bigMap = new Map();
129
177
  for (let i = 0; i < relations.length; i++) {
130
178
  const relation = relations[i];
131
- const code = relation.relatedCode || "";
179
+ const code = relation.relatedCode || '';
132
180
  const codeTrim = code.trim();
133
181
  const map = await this.queryInfoByLinkToCustom(codeTrim);
134
182
  bigMap.set(codeTrim, map);
@@ -10,7 +10,7 @@ export declare class CurdMixService {
10
10
  private curdMixByLinkToCustomService;
11
11
  private prepare;
12
12
  executeCrudByCfg(reqJson: IRequestModel, cfgModel: IRequestCfgModel2): Promise<import("../../libs/crud-pro/models/ExecuteContext").ExecuteContext>;
13
- getBbUtil(database: string, sqlDbType: SqlDbType): import("./CurdProService").DBUtils;
13
+ getBbUtil(sqlDatabase: string, sqlDbType: SqlDbType, sqlTable?: string): import("./CrudProQuick").CrudProQuick;
14
14
  executeSQL(sqlCfgModel: ISqlCfgModel): Promise<any>;
15
15
  executeCrud(reqJson: IRequestModel): Promise<import("../../libs/crud-pro/models/ExecuteContext").ExecuteContext>;
16
16
  getCachedCfgByMethod(method: string): Promise<IRequestCfgModel>;
@@ -30,9 +30,9 @@ let CurdMixService = class CurdMixService {
30
30
  this.prepare();
31
31
  return this.curdProService.executeCrudByCfg(reqJson, cfgModel);
32
32
  }
33
- getBbUtil(database, sqlDbType) {
33
+ getBbUtil(sqlDatabase, sqlDbType, sqlTable) {
34
34
  this.prepare();
35
- return this.curdProService.getBbUtil(database, sqlDbType);
35
+ return this.curdProService.getBbUtil(sqlDatabase, sqlDbType, sqlTable);
36
36
  }
37
37
  async executeSQL(sqlCfgModel) {
38
38
  this.prepare();
@@ -46,40 +46,47 @@ function copyBySingleSourceValue(row, sourceValue, targetColumns, getValue) {
46
46
  }
47
47
  }
48
48
  }
49
- function copyByArraySourceValue(row, sourceValue, targetColumns, getValue) {
50
- let isSetArray = false;
51
- // 支持关联JSON数组
52
- if (typeof sourceValue === 'string' && sourceValue.startsWith('[') && sourceValue.endsWith(']')) {
53
- const codes = (0, functions_1.parseJsonObject)(sourceValue);
54
- if (Array.isArray(codes)) {
55
- for (let codeIndex = 0; codeIndex < codes.length; codeIndex++) {
56
- const code = codes[codeIndex];
57
- // const codeObject = map.get(code);
58
- const codeObject = getValue(code);
59
- if (codeObject) {
60
- if (Array.isArray(targetColumns)) {
61
- for (let i = 0; i < targetColumns.length; i++) {
62
- const targetColumn = targetColumns[i];
63
- if (targetColumn.from === '*') {
64
- const toStr = targetColumn.to.replace('$ARRAY_INDEX', `${codeIndex}`);
65
- _.set(row, toStr, codeObject);
66
- isSetArray = true;
67
- }
68
- else {
69
- const dictAttrValue = _.get(codeObject, targetColumn.from);
70
- if (typeof dictAttrValue !== 'undefined' && dictAttrValue !== null) {
71
- const toStr = targetColumn.to.replace('$ARRAY_INDEX', `${codeIndex}`);
72
- _.set(row, toStr, dictAttrValue);
73
- isSetArray = true;
74
- }
75
- }
49
+ function copyByArraySourceValueInner(row, codes, targetColumns, getValue, resultObj) {
50
+ for (let codeIndex = 0; codeIndex < codes.length; codeIndex++) {
51
+ const code = codes[codeIndex];
52
+ // const codeObject = map.get(code);
53
+ const codeObject = getValue(code);
54
+ if (codeObject) {
55
+ if (Array.isArray(targetColumns)) {
56
+ for (let i = 0; i < targetColumns.length; i++) {
57
+ const targetColumn = targetColumns[i];
58
+ if (targetColumn.from === '*') {
59
+ const toStr = targetColumn.to.replace('$ARRAY_INDEX', `${codeIndex}`);
60
+ _.set(row, toStr, codeObject);
61
+ resultObj.isSetArray = true;
62
+ }
63
+ else {
64
+ const dictAttrValue = _.get(codeObject, targetColumn.from);
65
+ if (typeof dictAttrValue !== 'undefined' && dictAttrValue !== null) {
66
+ const toStr = targetColumn.to.replace('$ARRAY_INDEX', `${codeIndex}`);
67
+ _.set(row, toStr, dictAttrValue);
68
+ resultObj.isSetArray = true;
76
69
  }
77
70
  }
78
71
  }
79
72
  }
80
73
  }
81
74
  }
82
- return isSetArray;
75
+ }
76
+ function copyByArraySourceValue(row, sourceValue, targetColumns, getValue) {
77
+ const resultObj = { isSetArray: false };
78
+ // 支持关联JSON数组。使用 字符串存储的类型
79
+ if (typeof sourceValue === 'string' && sourceValue.startsWith('[') && sourceValue.endsWith(']')) {
80
+ const codes = (0, functions_1.parseJsonObject)(sourceValue);
81
+ if (Array.isArray(codes)) {
82
+ copyByArraySourceValueInner(row, codes, targetColumns, getValue, resultObj);
83
+ }
84
+ }
85
+ else if (Array.isArray(sourceValue)) {
86
+ // 直接使用JSON或者postgres的数组存储的类型
87
+ copyByArraySourceValueInner(row, sourceValue, targetColumns, getValue, resultObj);
88
+ }
89
+ return resultObj.isSetArray;
83
90
  }
84
91
  class CrudMixUtils {
85
92
  constructor(relatedType) {
@@ -5,14 +5,7 @@ import { ExecuteContext, IExecuteContextHandler } from '../../libs/crud-pro/mode
5
5
  import { RelatedType } from './CurdMixUtils';
6
6
  import { BaseService } from '../base/BaseService';
7
7
  import { IRequestCfgModel2 } from '../../models/bizmodels';
8
- export declare class DBUtils {
9
- private readonly sqlDatabase;
10
- private readonly sqlDbType;
11
- private readonly curdProService;
12
- constructor(sqlDatabase: string, sqlDbType: SqlDbType, curdProService: CurdProService);
13
- getOne(reqJson: IRequestModel, sqlTable: string): Promise<any>;
14
- getList(reqJson: IRequestModel, sqlTable: string): Promise<any[]>;
15
- }
8
+ import { CrudProQuick } from "../../service/curd/CrudProQuick";
16
9
  export declare class CurdProService extends BaseService {
17
10
  protected ctx: Context;
18
11
  private mysql2Config;
@@ -33,7 +26,6 @@ export declare class CurdProService extends BaseService {
33
26
  executeCrud(reqJson: IRequestModel): Promise<ExecuteContext>;
34
27
  executeSQL(sqlCfgModel: ISqlCfgModel): Promise<any>;
35
28
  executeCrudByCfg(reqJson: IRequestModel, cfgModel: IRequestCfgModel2): Promise<ExecuteContext>;
36
- private applyStandardUpdateCfg;
37
- getBbUtil(database: string, sqlDbType: SqlDbType): DBUtils;
29
+ getBbUtil(sqlDatabase: string, sqlDbType: SqlDbType, sqlTable?: string): CrudProQuick;
38
30
  getCachedCfgByMethod(method: string): Promise<IRequestCfgModel>;
39
31
  }
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.CurdProService = exports.DBUtils = void 0;
12
+ exports.CurdProService = void 0;
13
13
  const _ = require("lodash");
14
14
  const core_1 = require("@midwayjs/core");
15
15
  const CrudPro_1 = require("../../libs/crud-pro/CrudPro");
@@ -20,7 +20,9 @@ const keys_1 = require("../../libs/crud-pro/models/keys");
20
20
  const exceptions_1 = require("../../libs/crud-pro/exceptions");
21
21
  const ExecuteContextFunc_1 = require("../../libs/crud-pro/models/ExecuteContextFunc");
22
22
  const BaseService_1 = require("../base/BaseService");
23
- const bizmodels_1 = require("../../models/bizmodels");
23
+ const CrudProQuick_1 = require("../../service/curd/CrudProQuick");
24
+ const fixCfgModel_1 = require("./fixCfgModel");
25
+ const global_config_1 = require("../../libs/global-config/global-config");
24
26
  function toVisitor(ctx) {
25
27
  const workbenchInfo = ctx.workbenchInfo;
26
28
  const userSession = ctx.userSession;
@@ -69,6 +71,7 @@ class MyContextFunc extends ExecuteContextFunc_1.BaseExecuteContextFunc {
69
71
  if (sqlDbType === keys_1.SqlDbType.postgres) {
70
72
  const dbConfig = _.get(this.postgres2Config, dataBaseName);
71
73
  if (!dbConfig) {
74
+ console.error('postgres配置中不存在此数据库', JSON.stringify(sqlCfgModel));
72
75
  throw new exceptions_1.CommonException(exceptions_1.Exceptions.DB_NOT_FOUND, 'postgres配置中不存在此数据库:' + dataBaseName);
73
76
  }
74
77
  return (0, PostgresUtils_1.getConnectionPool)(dataBaseName, dbConfig);
@@ -76,12 +79,14 @@ class MyContextFunc extends ExecuteContextFunc_1.BaseExecuteContextFunc {
76
79
  if (sqlDbType === keys_1.SqlDbType.sqlserver) {
77
80
  const dbConfig = _.get(this.sqlserver2Config, dataBaseName);
78
81
  if (!dbConfig) {
82
+ console.error('sqlserver配置中不存在此数据库', JSON.stringify(sqlCfgModel));
79
83
  throw new exceptions_1.CommonException(exceptions_1.Exceptions.DB_NOT_FOUND, 'sqlserver配置中不存在此数据库:' + dataBaseName);
80
84
  }
81
85
  return (0, SqlServerUtils_1.getConnectionPool)(dataBaseName, dbConfig);
82
86
  }
83
87
  const dbConfig = _.get(this.mysql2Config, dataBaseName);
84
88
  if (!dbConfig) {
89
+ console.error('MySQL配置中不存在此数据库', JSON.stringify(sqlCfgModel));
85
90
  throw new exceptions_1.CommonException(exceptions_1.Exceptions.DB_NOT_FOUND, 'MySQL配置中不存在此数据库:' + dataBaseName);
86
91
  }
87
92
  return (0, MySQLUtils_1.getConnectionPool)(dataBaseName, dbConfig);
@@ -96,43 +101,19 @@ class MyContextFunc extends ExecuteContextFunc_1.BaseExecuteContextFunc {
96
101
  }
97
102
  return null;
98
103
  }
99
- }
100
- class DBUtils {
101
- constructor(sqlDatabase, sqlDbType, curdProService) {
102
- this.sqlDatabase = sqlDatabase;
103
- this.sqlDbType = sqlDbType;
104
- this.curdProService = curdProService;
105
- }
106
- async getOne(reqJson, sqlTable) {
107
- const cfgModel = {
108
- sqlTable,
109
- sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
110
- sqlDatabase: this.sqlDatabase,
111
- sqlDbType: this.sqlDbType,
112
- updateCfg: {},
113
- };
114
- const res = await this.curdProService.executeCrudByCfg(reqJson, cfgModel);
115
- return res.getOneObj();
116
- }
117
- async getList(reqJson, sqlTable) {
118
- const cfgModel = {
119
- sqlTable,
120
- sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
121
- sqlDatabase: this.sqlDatabase,
122
- sqlDbType: this.sqlDbType,
123
- updateCfg: {},
124
- };
125
- const res = await this.curdProService.executeCrudByCfg(reqJson, cfgModel);
126
- return res.getResRows();
104
+ /**
105
+ * 在执行之前可以根据业务需要修改需要执行的内容
106
+ * @param reqJson
107
+ * @param cfgJson
108
+ */
109
+ async beforeExecuteSQLList(reqJson, cfgJson) {
110
+ const { bizUpdateCfgModelForCrudPro } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
111
+ if (typeof bizUpdateCfgModelForCrudPro === "function") {
112
+ await bizUpdateCfgModelForCrudPro(reqJson, cfgJson);
113
+ }
114
+ return Promise.resolve();
127
115
  }
128
116
  }
129
- exports.DBUtils = DBUtils;
130
- function isSimpleQuery(sqlSimpleName) {
131
- return sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_QUERY ||
132
- sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_COUNT ||
133
- sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE ||
134
- sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_ONE;
135
- }
136
117
  let CurdProService = class CurdProService extends BaseService_1.BaseService {
137
118
  constructor() {
138
119
  super(...arguments);
@@ -152,7 +133,11 @@ let CurdProService = class CurdProService extends BaseService_1.BaseService {
152
133
  crudPro.transaction = this.ctx.transaction;
153
134
  crudPro.logger = this.getContextLogger();
154
135
  crudPro.visitor = visitor;
155
- crudPro.contextCfg = this.crudProCfg;
136
+ const crudProCfg = this.crudProCfg || {};
137
+ const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
138
+ crudProCfg.sysDatabaseName = SystemDbName;
139
+ crudProCfg.sysDatabaseDbType = SystemDbType;
140
+ crudPro.contextCfg = crudProCfg;
156
141
  crudPro.contextFunc = new MyContextFunc({
157
142
  mysql2Config: this.mysql2Config,
158
143
  postgres2Config: this.postgres2Config,
@@ -181,114 +166,14 @@ let CurdProService = class CurdProService extends BaseService_1.BaseService {
181
166
  // 直接执行一个请求
182
167
  async executeCrudByCfg(reqJson, cfgModel) {
183
168
  this.logInfo('executeCrudByCfg', cfgModel);
184
- if (!cfgModel.method) {
185
- const req = this.ctx.req;
186
- if (req) {
187
- cfgModel.method = `${req.method}:${req.url}`;
188
- }
189
- else {
190
- cfgModel.method = 'anonymous';
191
- }
192
- }
193
- if (!cfgModel.updateCfg) {
194
- cfgModel.updateCfg = {};
195
- }
196
- // 应用标准的updateCfg
197
- this.applyStandardUpdateCfg(cfgModel);
198
169
  const curdPro = this.getCrudPro();
170
+ // 应用标准的updateCfg。
171
+ (0, fixCfgModel_1.fixCfgModel)(cfgModel);
199
172
  return await curdPro.executeCrudByCfg(reqJson, cfgModel);
200
173
  }
201
- applyStandardUpdateCfg(cfgModel) {
202
- const sqlSimpleName = cfgModel.sqlSimpleName;
203
- const enableStandardUpdateCfg = cfgModel.enableStandardUpdateCfg; // 用于设置data字段
204
- const enableStandardUpdateCfgCondition = cfgModel.enableStandardUpdateCfgCondition; // 用于设置condition字段
205
- // 彻底关闭
206
- if (enableStandardUpdateCfg === false) {
207
- return;
208
- }
209
- const getDataCfgArray = () => {
210
- // 明确有配置
211
- if (Array.isArray(enableStandardUpdateCfg)) {
212
- if (enableStandardUpdateCfg.includes('null')) {
213
- return [];
214
- }
215
- return enableStandardUpdateCfg;
216
- }
217
- // update 、insert 添加 by
218
- return ['by']; // 创建/修改语句默认添加by
219
- };
220
- const getConditionCfgArray = () => {
221
- // 明确有配置
222
- if (Array.isArray(enableStandardUpdateCfgCondition)) {
223
- if (enableStandardUpdateCfgCondition.includes('null')) {
224
- return [];
225
- }
226
- return enableStandardUpdateCfgCondition;
227
- }
228
- return [];
229
- };
230
- const dataCfgArray = getDataCfgArray();
231
- const conditionCfgArray = getConditionCfgArray();
232
- const mapping = {
233
- 'condition.created_by': { contextAsString: bizmodels_1.CTX_VISITOR_ID },
234
- 'condition.created_account_type': { contextAsString: bizmodels_1.CTX_VISITOR_ACCOUNT_TYPE },
235
- 'data.created_by': { contextAsString: bizmodels_1.CTX_VISITOR_ID },
236
- 'data.created_avatar': { contextAsString: bizmodels_1.CTX_VISITOR_AVATAR },
237
- 'data.created_nickname': { contextAsString: bizmodels_1.CTX_VISITOR_NICKNAME },
238
- 'data.created_account_type': { contextAsString: bizmodels_1.CTX_VISITOR_ACCOUNT_TYPE },
239
- 'data.modified_by': { contextAsString: bizmodels_1.CTX_VISITOR_ID },
240
- 'data.modified_avatar': { contextAsString: bizmodels_1.CTX_VISITOR_AVATAR },
241
- 'data.modified_nickname': { contextAsString: bizmodels_1.CTX_VISITOR_NICKNAME },
242
- 'data.modified_account_type': { contextAsString: bizmodels_1.CTX_VISITOR_ACCOUNT_TYPE },
243
- };
244
- const buildUpdateCfgBy = (cfgArray, prefix) => {
245
- const obj = {};
246
- if (Array.isArray(cfgArray)) {
247
- for (let i = 0; i < cfgArray.length; i++) {
248
- const suffix = cfgArray[i];
249
- if (suffix) {
250
- const key = `${prefix}_${suffix}`;
251
- obj[key] = mapping[key];
252
- }
253
- }
254
- }
255
- return obj;
256
- };
257
- // 查询语句
258
- if (isSimpleQuery(sqlSimpleName)) {
259
- const updateCfgObj = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 查询用户本人创建的
260
- Object.assign(cfgModel.updateCfg, updateCfgObj);
261
- }
262
- // 删除语句
263
- if (sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_DELETE) {
264
- const updateCfgObj = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 删除用户本人创建的
265
- Object.assign(cfgModel.updateCfg, updateCfgObj);
266
- }
267
- // 插入语句
268
- if (sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_INSERT) {
269
- const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray, 'data.created');
270
- Object.assign(cfgModel.updateCfg, updateCfgObj1);
271
- }
272
- // 更新语句
273
- if (sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE) {
274
- const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray, 'data.modified');
275
- const updateCfgObj2 = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 更新用户本人创建的
276
- Object.assign(cfgModel.updateCfg, updateCfgObj1);
277
- Object.assign(cfgModel.updateCfg, updateCfgObj2);
278
- }
279
- // 插入或更新
280
- if (sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_INSERT_OR_UPDATE ||
281
- sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_INSERT_ON_DUPLICATE_UPDATE) {
282
- const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray, 'data.created');
283
- const updateCfgObj2 = buildUpdateCfgBy(dataCfgArray, 'data.modified');
284
- const updateCfgObj3 = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 更新用户本人创建的
285
- Object.assign(cfgModel.updateCfg, updateCfgObj1);
286
- Object.assign(cfgModel.updateCfg, updateCfgObj2);
287
- Object.assign(cfgModel.updateCfg, updateCfgObj3);
288
- }
289
- }
290
- getBbUtil(database, sqlDbType) {
291
- return new DBUtils(database, sqlDbType, this);
174
+ getBbUtil(sqlDatabase, sqlDbType, sqlTable) {
175
+ const curdPro = this.getCrudPro();
176
+ return new CrudProQuick_1.CrudProQuick(curdPro, sqlDatabase, sqlDbType, sqlTable);
292
177
  }
293
178
  async getCachedCfgByMethod(method) {
294
179
  const curdPro = this.getCrudPro();
@@ -0,0 +1,3 @@
1
+ import { IRequestCfgModel2 } from "../../models/bizmodels";
2
+ declare function fixCfgModel(cfgModel: IRequestCfgModel2): void;
3
+ export { fixCfgModel };