midway-fatcms 0.0.1-beta.45 → 0.0.1-beta.47
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.
- package/dist/controller/gateway/CrudStdGatewayController.js +8 -16
- package/dist/libs/utils/functions.js +6 -2
- package/dist/models/bizmodels.d.ts +1 -0
- package/dist/service/asyncTask/handler/ExportExcelByStdCrudHandler.js +10 -2
- package/dist/service/crudstd/CrudStdService.d.ts +9 -4
- package/dist/service/crudstd/CrudStdService.js +44 -16
- package/dist/service/curd/CurdMixByAccountService.js +0 -1
- package/dist/service/curd/CurdMixUtils.js +8 -6
- package/package.json +1 -1
|
@@ -33,52 +33,44 @@ let CrudStdGatewayController = class CrudStdGatewayController extends BaseApiCon
|
|
|
33
33
|
*/
|
|
34
34
|
async getObjectList() {
|
|
35
35
|
const { stdAction, ...otherParams } = this.ctx.request.body;
|
|
36
|
-
|
|
37
|
-
return this.crudStdService.executeStdQuery(
|
|
36
|
+
stdAction.settingKey = CrudStdService_1.SPECIAL_SETTING_KEY.QUERY_LIST;
|
|
37
|
+
return this.crudStdService.executeStdQuery(stdAction, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* 单个查询
|
|
41
41
|
*/
|
|
42
42
|
async getObjectOne() {
|
|
43
43
|
const { stdAction, ...otherParams } = this.ctx.request.body;
|
|
44
|
-
|
|
45
|
-
return this.crudStdService.executeStdQuery(
|
|
44
|
+
stdAction.settingKey = CrudStdService_1.SPECIAL_SETTING_KEY.QUERY_ONE;
|
|
45
|
+
return this.crudStdService.executeStdQuery(stdAction, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_ONE);
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* 单个删除
|
|
49
49
|
*/
|
|
50
50
|
async deleteObject() {
|
|
51
51
|
const { stdAction, ...otherParams } = this.ctx.request.body;
|
|
52
|
-
|
|
53
|
-
const settingKey = stdAction.settingKey;
|
|
54
|
-
return this.crudStdService.executeStdQuery(appCode, settingKey, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_DELETE);
|
|
52
|
+
return this.crudStdService.executeStdQuery(stdAction, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_DELETE);
|
|
55
53
|
}
|
|
56
54
|
/**
|
|
57
55
|
* 单个创建
|
|
58
56
|
*/
|
|
59
57
|
async createObject() {
|
|
60
58
|
const { stdAction, ...otherParams } = this.ctx.request.body;
|
|
61
|
-
|
|
62
|
-
const settingKey = stdAction.settingKey;
|
|
63
|
-
return this.crudStdService.executeStdQuery(appCode, settingKey, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_INSERT);
|
|
59
|
+
return this.crudStdService.executeStdQuery(stdAction, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_INSERT);
|
|
64
60
|
}
|
|
65
61
|
/**
|
|
66
62
|
* 单个更新
|
|
67
63
|
*/
|
|
68
64
|
async updateObject() {
|
|
69
65
|
const { stdAction, ...otherParams } = this.ctx.request.body;
|
|
70
|
-
|
|
71
|
-
const settingKey = stdAction.settingKey;
|
|
72
|
-
return this.crudStdService.executeStdQuery(appCode, settingKey, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE);
|
|
66
|
+
return this.crudStdService.executeStdQuery(stdAction, otherParams, keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE);
|
|
73
67
|
}
|
|
74
68
|
/**
|
|
75
69
|
* 执行操作
|
|
76
70
|
*/
|
|
77
71
|
async executeStdAction() {
|
|
78
72
|
const { stdAction, ...otherParams } = this.ctx.request.body;
|
|
79
|
-
|
|
80
|
-
const settingKey = stdAction.settingKey;
|
|
81
|
-
return await this.crudStdService.executeStdActionByReq(appCode, settingKey, otherParams);
|
|
73
|
+
return await this.crudStdService.executeStdActionByReq(stdAction, otherParams);
|
|
82
74
|
}
|
|
83
75
|
};
|
|
84
76
|
__decorate([
|
|
@@ -12,10 +12,14 @@ function createUniqueId() {
|
|
|
12
12
|
}
|
|
13
13
|
exports.createUniqueId = createUniqueId;
|
|
14
14
|
function parseJsonObject(str) {
|
|
15
|
-
|
|
15
|
+
const typeofStr = typeof str;
|
|
16
|
+
if (str === null || typeofStr === 'undefined') {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
if (typeofStr === 'object') {
|
|
16
20
|
return str;
|
|
17
21
|
}
|
|
18
|
-
if (
|
|
22
|
+
if (typeofStr === 'string') {
|
|
19
23
|
str = str.trim();
|
|
20
24
|
if (str.startsWith('{') || str.startsWith('[')) {
|
|
21
25
|
try {
|
|
@@ -90,7 +90,11 @@ class ExportExcelByStdCrudHandler {
|
|
|
90
90
|
this.ctx.innerHeaders = {};
|
|
91
91
|
}
|
|
92
92
|
Object.assign(this.ctx.innerHeaders, this.inputParams.headers || {});
|
|
93
|
-
const
|
|
93
|
+
const stdAction = {
|
|
94
|
+
appCode: appCode,
|
|
95
|
+
settingKey: CrudStdService_1.SPECIAL_SETTING_KEY.QUERY_LIST,
|
|
96
|
+
};
|
|
97
|
+
const a = await crudStdService.executeStdQuery(stdAction, params, keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
|
|
94
98
|
return pickData(a, 'total_count');
|
|
95
99
|
}
|
|
96
100
|
/**
|
|
@@ -116,7 +120,11 @@ class ExportExcelByStdCrudHandler {
|
|
|
116
120
|
$in: selectedRowKeys,
|
|
117
121
|
};
|
|
118
122
|
}
|
|
119
|
-
const
|
|
123
|
+
const stdAction = {
|
|
124
|
+
appCode: appCode,
|
|
125
|
+
settingKey: CrudStdService_1.SPECIAL_SETTING_KEY.QUERY_LIST,
|
|
126
|
+
};
|
|
127
|
+
const a = await crudStdService.executeStdQuery(stdAction, params, keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
|
|
120
128
|
return pickData(a, 'rows');
|
|
121
129
|
}
|
|
122
130
|
}
|
|
@@ -11,6 +11,11 @@ export declare const SPECIAL_SETTING_KEY: {
|
|
|
11
11
|
QUERY_LIST: string;
|
|
12
12
|
QUERY_ONE: string;
|
|
13
13
|
};
|
|
14
|
+
export interface ICrudStdActionParams {
|
|
15
|
+
appCode: string;
|
|
16
|
+
settingKey?: string;
|
|
17
|
+
buttonSettingKey?: string;
|
|
18
|
+
}
|
|
14
19
|
export declare class CrudStdService extends ApiBaseService {
|
|
15
20
|
protected ctx: Context;
|
|
16
21
|
protected curdMixService: CurdMixService;
|
|
@@ -19,7 +24,7 @@ export declare class CrudStdService extends ApiBaseService {
|
|
|
19
24
|
/**
|
|
20
25
|
* 执行普通CRUD
|
|
21
26
|
*/
|
|
22
|
-
executeStdQuery(
|
|
27
|
+
executeStdQuery(stdAction: ICrudStdActionParams, params: IRequestModel, sqlSimpleName: KeysOfSimpleSQL): Promise<ExecuteContext>;
|
|
23
28
|
/**
|
|
24
29
|
* 获取appInfo 并且拿到当前settingKey相关的信息
|
|
25
30
|
* @param appCode
|
|
@@ -29,11 +34,10 @@ export declare class CrudStdService extends ApiBaseService {
|
|
|
29
34
|
private getParsedCrudStdAppForSettingKey;
|
|
30
35
|
/**
|
|
31
36
|
* 执行动作
|
|
32
|
-
* @param
|
|
33
|
-
* @param settingKey
|
|
37
|
+
* @param stdAction
|
|
34
38
|
* @param params
|
|
35
39
|
*/
|
|
36
|
-
executeStdActionByReq(
|
|
40
|
+
executeStdActionByReq(stdAction: ICrudStdActionParams, params: IRequestModel): Promise<ExecuteContext>;
|
|
37
41
|
/**
|
|
38
42
|
* 查询APP信息
|
|
39
43
|
* @param appCode
|
|
@@ -53,5 +57,6 @@ export declare class CrudStdService extends ApiBaseService {
|
|
|
53
57
|
*/
|
|
54
58
|
private getParsedCrudStdAppInfoPrivate;
|
|
55
59
|
private hasOperationPerm;
|
|
60
|
+
private fixSubmitDataByKeepSubmitData;
|
|
56
61
|
private fixDataFieldTypeBySqlTableField;
|
|
57
62
|
}
|
|
@@ -10,6 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CrudStdService = exports.SPECIAL_SETTING_KEY = void 0;
|
|
13
|
+
/* eslint-disable prettier/prettier */
|
|
13
14
|
const _ = require("lodash");
|
|
14
15
|
const core_1 = require("@midwayjs/core");
|
|
15
16
|
const CurdMixService_1 = require("../curd/CurdMixService");
|
|
@@ -27,7 +28,8 @@ exports.SPECIAL_SETTING_KEY = {
|
|
|
27
28
|
QUERY_LIST: 'QUERY_LIST',
|
|
28
29
|
QUERY_ONE: 'QUERY_ONE',
|
|
29
30
|
};
|
|
30
|
-
function getExecuteTableNameBySettingKey(appInfo,
|
|
31
|
+
function getExecuteTableNameBySettingKey(appInfo, stdAction) {
|
|
32
|
+
const { settingKey } = stdAction || {};
|
|
31
33
|
const stdCrudCfgObj = appInfo.stdCrudCfgObj;
|
|
32
34
|
const actionsMap = appInfo.actionsMap || {};
|
|
33
35
|
const actionCfg = actionsMap[settingKey];
|
|
@@ -43,8 +45,9 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
|
|
|
43
45
|
/**
|
|
44
46
|
* 执行普通CRUD
|
|
45
47
|
*/
|
|
46
|
-
async executeStdQuery(
|
|
47
|
-
const
|
|
48
|
+
async executeStdQuery(stdAction, params, sqlSimpleName) {
|
|
49
|
+
const appCode = stdAction.appCode;
|
|
50
|
+
const appInfo = await this.getParsedCrudStdAppForSettingKey(stdAction);
|
|
48
51
|
const stdCrudCfgObj = appInfo.stdCrudCfgObj;
|
|
49
52
|
if (!appInfo || appInfo.status !== 1) {
|
|
50
53
|
throw new devops_1.BizException('应用不存在或已下线:' + appCode);
|
|
@@ -54,7 +57,7 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
|
|
|
54
57
|
const cfgModel = {
|
|
55
58
|
sqlDatabase: dbName,
|
|
56
59
|
sqlDbType: dbType,
|
|
57
|
-
sqlTable: getExecuteTableNameBySettingKey(appInfo,
|
|
60
|
+
sqlTable: getExecuteTableNameBySettingKey(appInfo, stdAction),
|
|
58
61
|
sqlSimpleName,
|
|
59
62
|
};
|
|
60
63
|
// 接口返回最大值
|
|
@@ -67,6 +70,8 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
|
|
|
67
70
|
}
|
|
68
71
|
// 根据用户配置,设置关联查询的数据信息。
|
|
69
72
|
await this.crudStdRelationService.addCfgModelColumnsRelation(cfgModel, appInfo);
|
|
73
|
+
// 根据用户配置的keepSubmitData字段修改提交的数据
|
|
74
|
+
await this.fixSubmitDataByKeepSubmitData(params, cfgModel, appInfo, { dbType, dbName });
|
|
70
75
|
// 根据表结构的数据类型,修正数据类型
|
|
71
76
|
await this.fixDataFieldTypeBySqlTableField(params, cfgModel, appInfo, { dbType, dbName });
|
|
72
77
|
// 业务系统自定义的修改:查询前的查询条件:cfgModel
|
|
@@ -82,7 +87,8 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
|
|
|
82
87
|
* @param settingKey
|
|
83
88
|
* @private
|
|
84
89
|
*/
|
|
85
|
-
async getParsedCrudStdAppForSettingKey(
|
|
90
|
+
async getParsedCrudStdAppForSettingKey(stdAction) {
|
|
91
|
+
const { appCode, settingKey, buttonSettingKey } = stdAction || {};
|
|
86
92
|
if (!appCode) {
|
|
87
93
|
throw new devops_1.BizException('缺少参数:curdStdAppCode');
|
|
88
94
|
}
|
|
@@ -110,18 +116,20 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
|
|
|
110
116
|
}
|
|
111
117
|
appInfo.settingKeyActionCfg = actionCfg;
|
|
112
118
|
}
|
|
119
|
+
if (buttonSettingKey) {
|
|
120
|
+
appInfo.buttonSettingKeyActionCfg = actionsMap[buttonSettingKey];
|
|
121
|
+
}
|
|
113
122
|
return appInfo;
|
|
114
123
|
}
|
|
115
124
|
/**
|
|
116
125
|
* 执行动作
|
|
117
|
-
* @param
|
|
118
|
-
* @param settingKey
|
|
126
|
+
* @param stdAction
|
|
119
127
|
* @param params
|
|
120
128
|
*/
|
|
121
|
-
async executeStdActionByReq(
|
|
122
|
-
const appInfo = await this.getParsedCrudStdAppForSettingKey(
|
|
129
|
+
async executeStdActionByReq(stdAction, params) {
|
|
130
|
+
const appInfo = await this.getParsedCrudStdAppForSettingKey(stdAction);
|
|
123
131
|
if (!appInfo || appInfo.status !== 1) {
|
|
124
|
-
throw new devops_1.BizException('应用不存在或已下线:' + appCode);
|
|
132
|
+
throw new devops_1.BizException('应用不存在或已下线:' + stdAction.appCode);
|
|
125
133
|
}
|
|
126
134
|
const actionsMap = appInfo.actionsMap;
|
|
127
135
|
const actionCfg = appInfo.settingKeyActionCfg;
|
|
@@ -170,12 +178,7 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
|
|
|
170
178
|
}
|
|
171
179
|
const { app_schema, ...others } = row;
|
|
172
180
|
const stdCrudCfgObj = (0, functions_1.parseJsonObject)(app_schema);
|
|
173
|
-
|
|
174
|
-
const actionsMap = {};
|
|
175
|
-
const keys = Object.keys(stdCrudCfgObj);
|
|
176
|
-
for (let i = 0; i < keys.length; i++) {
|
|
177
|
-
const key = keys[i];
|
|
178
|
-
const arrayCfg = stdCrudCfgObj[key];
|
|
181
|
+
const handleArrayCfg = (arrayCfg) => {
|
|
179
182
|
if (Array.isArray(arrayCfg)) {
|
|
180
183
|
for (let j = 0; j < arrayCfg.length; j++) {
|
|
181
184
|
const actionCfg = arrayCfg[j];
|
|
@@ -183,8 +186,18 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
|
|
|
183
186
|
if (actionCfg.settingKey) {
|
|
184
187
|
actionsMap[actionCfg.settingKey] = actionCfg;
|
|
185
188
|
}
|
|
189
|
+
const submitButtonCfg = _.get(actionCfg, 'component.props.submitButtonCfg');
|
|
190
|
+
handleArrayCfg(submitButtonCfg);
|
|
186
191
|
}
|
|
187
192
|
}
|
|
193
|
+
};
|
|
194
|
+
// 为了方便查找到action对象
|
|
195
|
+
const actionsMap = {};
|
|
196
|
+
const keys = Object.keys(stdCrudCfgObj);
|
|
197
|
+
for (let i = 0; i < keys.length; i++) {
|
|
198
|
+
const key = keys[i];
|
|
199
|
+
const arrayCfg = stdCrudCfgObj[key];
|
|
200
|
+
handleArrayCfg(arrayCfg);
|
|
188
201
|
}
|
|
189
202
|
return { ...others, stdCrudCfgObj, actionsMap };
|
|
190
203
|
}
|
|
@@ -195,6 +208,21 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
|
|
|
195
208
|
}
|
|
196
209
|
return true; // 无需鉴权
|
|
197
210
|
}
|
|
211
|
+
async fixSubmitDataByKeepSubmitData(params, cfgModel, appInfo, arg3) {
|
|
212
|
+
if (cfgModel.sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_INSERT || cfgModel.sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE) {
|
|
213
|
+
const submitData = params.data || {};
|
|
214
|
+
//1. 按钮中配置的keepSubmitData
|
|
215
|
+
const buttonActionCfg = appInfo.buttonSettingKeyActionCfg || {};
|
|
216
|
+
const keepSubmitDataByButtonStr = _.get(buttonActionCfg, 'keepSubmitData');
|
|
217
|
+
const keepSubmitDataByButton = (0, functions_1.parseJsonObject)(keepSubmitDataByButtonStr);
|
|
218
|
+
//2. 全局配置的keepSubmitData
|
|
219
|
+
const keepSubmitDataByGlobalStr = _.get(appInfo, 'stdCrudCfgObj.othersSetting.values.keepSubmitData');
|
|
220
|
+
const keepSubmitDataByGlobal = (0, functions_1.parseJsonObject)(keepSubmitDataByGlobalStr);
|
|
221
|
+
//3. 合并
|
|
222
|
+
Object.assign(submitData, keepSubmitDataByButton);
|
|
223
|
+
Object.assign(submitData, keepSubmitDataByGlobal);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
198
226
|
async fixDataFieldTypeBySqlTableField(params, cfgModel, appInfo, arg3) {
|
|
199
227
|
const tableFields = _.get(appInfo, 'stdCrudCfgObj.tableFields');
|
|
200
228
|
const tableFieldMap = MixinUtils_1.MixinUtils.toMap(tableFields, (e) => {
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RelatedType = exports.CrudMixUtils = void 0;
|
|
4
4
|
const keys_1 = require("../../libs/crud-pro/models/keys");
|
|
5
5
|
const MixinUtils_1 = require("../../libs/crud-pro/utils/MixinUtils");
|
|
6
|
+
const global_config_1 = require("../../libs/global-config/global-config");
|
|
6
7
|
const _ = require("lodash");
|
|
7
8
|
const functions_1 = require("../../libs/utils/functions");
|
|
8
9
|
var RelatedType;
|
|
@@ -248,15 +249,16 @@ class CrudMixUtils {
|
|
|
248
249
|
* @param columnRelation
|
|
249
250
|
*/
|
|
250
251
|
copyUserInfoToRowNoRelatedCode(row, map, columnRelation) {
|
|
251
|
-
const { targetColumns } = columnRelation;
|
|
252
|
+
const { targetColumns, sourceColumn } = columnRelation;
|
|
252
253
|
if (!targetColumns) {
|
|
253
254
|
return;
|
|
254
255
|
}
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
if (!sourceValue) {
|
|
256
|
+
const accountId = _.get(row, sourceColumn);
|
|
257
|
+
if (!accountId) {
|
|
258
258
|
return;
|
|
259
259
|
}
|
|
260
|
+
const { toFatcmsUserAccountId } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
|
|
261
|
+
const fatcmsUserAccountId = toFatcmsUserAccountId(accountId);
|
|
260
262
|
const getValue = (code) => {
|
|
261
263
|
if (!map) {
|
|
262
264
|
return null;
|
|
@@ -266,9 +268,9 @@ class CrudMixUtils {
|
|
|
266
268
|
}
|
|
267
269
|
return map[code];
|
|
268
270
|
};
|
|
269
|
-
const isSetArray = copyByArraySourceValue(row,
|
|
271
|
+
const isSetArray = copyByArraySourceValue(row, fatcmsUserAccountId, targetColumns, getValue);
|
|
270
272
|
if (!isSetArray) {
|
|
271
|
-
copyBySingleSourceValue(row,
|
|
273
|
+
copyBySingleSourceValue(row, fatcmsUserAccountId, targetColumns, getValue);
|
|
272
274
|
}
|
|
273
275
|
}
|
|
274
276
|
}
|