midway-fatcms 0.0.12 → 0.0.13

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 (37) hide show
  1. package/dist/controller/gateway/DocGatewayController.js +7 -5
  2. package/dist/controller/gateway/PublicApiController.js +32 -3
  3. package/dist/controller/home.controller.js +2 -1
  4. package/dist/controller/manage/DataDictManageApi.d.ts +2 -0
  5. package/dist/controller/manage/DataDictManageApi.js +41 -9
  6. package/dist/controller/manage/DocManageApi.js +2 -2
  7. package/dist/controller/render/AppRenderController.js +7 -6
  8. package/dist/libs/crud-pro/CrudPro.d.ts +0 -1
  9. package/dist/libs/crud-pro/CrudPro.js +2 -11
  10. package/dist/libs/crud-pro/exceptions.d.ts +6 -0
  11. package/dist/libs/crud-pro/exceptions.js +6 -0
  12. package/dist/libs/crud-pro/utils/SqlErrorParseUtils.d.ts +22 -0
  13. package/dist/libs/crud-pro/utils/SqlErrorParseUtils.js +219 -0
  14. package/dist/libs/utils/functions.js +3 -0
  15. package/dist/service/anyapi/AnyApiService.js +1 -1
  16. package/dist/service/crudstd/CrudStdService.js +2 -2
  17. package/dist/service/curd/CurdMixByDictService.js +1 -1
  18. package/dist/service/curd/CurdMixBySysConfigService.js +1 -1
  19. package/dist/service/curd/CurdMixByWorkbenchService.js +1 -1
  20. package/dist/service/proxyapi/ProxyApiLoadService.js +3 -0
  21. package/package.json +1 -1
  22. package/src/controller/gateway/DocGatewayController.ts +9 -5
  23. package/src/controller/gateway/PublicApiController.ts +39 -4
  24. package/src/controller/home.controller.ts +3 -1
  25. package/src/controller/manage/DataDictManageApi.ts +48 -11
  26. package/src/controller/manage/DocManageApi.ts +2 -2
  27. package/src/controller/render/AppRenderController.ts +9 -7
  28. package/src/libs/crud-pro/CrudPro.ts +2 -12
  29. package/src/libs/crud-pro/exceptions.ts +6 -0
  30. package/src/libs/crud-pro/utils/SqlErrorParseUtils.ts +236 -0
  31. package/src/libs/utils/functions.ts +3 -0
  32. package/src/service/anyapi/AnyApiService.ts +2 -2
  33. package/src/service/crudstd/CrudStdService.ts +3 -3
  34. package/src/service/curd/CurdMixByDictService.ts +1 -1
  35. package/src/service/curd/CurdMixBySysConfigService.ts +1 -1
  36. package/src/service/curd/CurdMixByWorkbenchService.ts +1 -1
  37. package/src/service/proxyapi/ProxyApiLoadService.ts +4 -1
@@ -20,6 +20,7 @@ const global_config_1 = require("../../libs/global-config/global-config");
20
20
  const keys_1 = require("../../libs/crud-pro/models/keys");
21
21
  const WorkbenchService_1 = require("../../service/WorkbenchService");
22
22
  const common_dto_1 = require("../../libs/utils/common-dto");
23
+ const functions_1 = require("../../libs/utils/functions");
23
24
  const fatcms_request_1 = require("../../libs/utils/fatcms-request");
24
25
  function checkIsNumber(value, name) {
25
26
  if (value === null || value === '' || typeof value === 'undefined') {
@@ -82,12 +83,13 @@ let DocGatewayController = class DocGatewayController extends BaseApiController_
82
83
  sqlDatabase: SystemDbName,
83
84
  sqlDbType: SystemDbType,
84
85
  });
85
- // 更新PV数据
86
86
  const docObj = res.getOneObj();
87
- if (docObj) {
88
- const pv = parseInt(docObj.pv) || 0;
89
- await this.updateDocPV(docId, docLibId, pv);
87
+ if (!(0, functions_1.isEntityOK)(docObj)) {
88
+ return common_dto_1.CommonResult.errorRes("文档不存在");
90
89
  }
90
+ // 更新PV数据
91
+ const pv = parseInt(docObj.pv) || 0;
92
+ await this.updateDocPV(docId, docLibId, pv);
91
93
  return res;
92
94
  }
93
95
  /**
@@ -134,7 +136,7 @@ let DocGatewayController = class DocGatewayController extends BaseApiController_
134
136
  sqlDbType: SystemDbType,
135
137
  });
136
138
  const docLibInfo = s.getOneObj();
137
- if (!docLibInfo) {
139
+ if (!(0, functions_1.isEntityOK)(docLibInfo)) {
138
140
  throw '此文档库查询失败';
139
141
  }
140
142
  const workbench_code_array = docLibInfo.workbench_code_array;
@@ -58,8 +58,28 @@ let PublicApiController = class PublicApiController extends BaseApiController_1.
58
58
  const workbenchMenuCodeSet = new Set(workbenchMenuCodeArray);
59
59
  const allMenuList = await this.sysMenuService.getCachedMenusList();
60
60
  const menuList = allMenuList.filter(e => {
61
- return workbenchMenuCodeSet.has(e.menu_code) && e.status === 1;
61
+ return workbenchMenuCodeSet.has(e.menu_code) && (0, functions_1.isEntityOK)(e);
62
62
  });
63
+ const addPermissionInfo = (menu_list, level) => {
64
+ if (!Array.isArray(menu_list)) {
65
+ return [];
66
+ }
67
+ if (level > 10) {
68
+ return menu_list;
69
+ }
70
+ return menu_list.map(e => {
71
+ if (Array.isArray(e.children)) {
72
+ e.children = addPermissionInfo(e.children, level + 1);
73
+ }
74
+ const view_auth_config = e.view_auth_config;
75
+ const view_auth_type = e.view_auth_type || keys_1.KeysOfAuthType.byFuncCode;
76
+ if (!view_auth_config) {
77
+ return { ...e, hasPermission: true };
78
+ }
79
+ const hasPermission = this.ctx.userSession.isAuthPass(view_auth_type, view_auth_config);
80
+ return { ...e, hasPermission };
81
+ });
82
+ };
63
83
  const mapResult = {};
64
84
  for (let i = 0; i < menuList.length; i++) {
65
85
  const rowElement = cloneObject(menuList[i]);
@@ -69,7 +89,8 @@ let PublicApiController = class PublicApiController extends BaseApiController_1.
69
89
  const hasPermission = this.ctx.userSession.isAuthPass(view_auth_type, view_auth_config);
70
90
  const menu_config_content = rowElement.menu_config_content;
71
91
  delete rowElement.menu_config_content;
72
- const menu_list = (0, functions_1.parseJsonObject)(menu_config_content) || [];
92
+ let menu_list = (0, functions_1.parseJsonObject)(menu_config_content) || [];
93
+ menu_list = addPermissionInfo(menu_list, 0);
73
94
  mapResult[menu_code] = { ...rowElement, menu_list, hasPermission };
74
95
  }
75
96
  // 特殊的devops菜单
@@ -97,10 +118,18 @@ let PublicApiController = class PublicApiController extends BaseApiController_1.
97
118
  resultData.appData = await this.sysAppService.deletePrivateField(appInfo);
98
119
  }
99
120
  if (pathname && workbenchCode) {
100
- resultData.pageData = await this.sysAppService.getSysAppPageOne({
121
+ const pageData = await this.sysAppService.getSysAppPageOne({
101
122
  page_path: pathname,
102
123
  workbench_code: workbenchCode
103
124
  });
125
+ if (pageData) {
126
+ const clonePageInfo = { ...pageData };
127
+ const view_auth_config = clonePageInfo.view_auth_config;
128
+ const view_auth_type = clonePageInfo.view_auth_type;
129
+ const hasPermission = this.ctx.userSession.isAuthPass(view_auth_type, view_auth_config);
130
+ clonePageInfo.hasPermission = hasPermission;
131
+ resultData.pageData = clonePageInfo;
132
+ }
104
133
  }
105
134
  return common_dto_1.CommonResult.successRes(resultData);
106
135
  }
@@ -16,12 +16,13 @@ const WorkbenchService_1 = require("../service/WorkbenchService");
16
16
  const render_utils_1 = require("../libs/utils/render-utils");
17
17
  const crypto_utils_1 = require("../libs/utils/crypto-utils");
18
18
  const AuthService_1 = require("../service/AuthService");
19
+ const functions_1 = require("../libs/utils/functions");
19
20
  let HomeController = class HomeController extends BaseApiController_1.BaseApiController {
20
21
  async home() {
21
22
  const host = this.ctx.request.host;
22
23
  const hostname = this.ctx.request.hostname;
23
24
  const workbenchInfo = await this.workbenchService.getCurrentHostWorkbenchInfo();
24
- if (!workbenchInfo || workbenchInfo.status !== 1) {
25
+ if (!(0, functions_1.isEntityOK)(workbenchInfo)) {
25
26
  this.logInfo(`域名不存在:hostname = ${hostname}, host=${host}`);
26
27
  const infos = {
27
28
  host,
@@ -6,6 +6,8 @@ export declare class DataDictManageApi extends BaseApiController {
6
6
  getDataDictList(): Promise<import("../../libs/crud-pro/models/ExecuteContext").ExecuteContext>;
7
7
  getDataDictOne(): Promise<import("../../libs/crud-pro/models/ExecuteContext").ExecuteContext>;
8
8
  createDataDict(): Promise<import("../../libs/crud-pro/models/ExecuteContext").ExecuteContext>;
9
+ /** 查询 dict_code 是否仅被软删除记录占用(不含 deleted_at=0 的活跃记录) */
10
+ private isSoftDeletedDictCode;
9
11
  updateDataDict(): Promise<import("../../libs/crud-pro/models/ExecuteContext").ExecuteContext>;
10
12
  deleteDataDict(): Promise<import("../../libs/crud-pro/models/ExecuteContext").ExecuteContext | CommonResult>;
11
13
  getDataDictItemList(): Promise<import("../../libs/crud-pro/models/ExecuteContext").ExecuteContext>;
@@ -18,6 +18,8 @@ const cacherefresh_middleware_1 = require("../../middleware/cacherefresh.middlew
18
18
  const bizmodels_1 = require("../../models/bizmodels");
19
19
  const SystemPerm_1 = require("../../models/SystemPerm");
20
20
  const common_dto_1 = require("../../libs/utils/common-dto");
21
+ const exceptions_1 = require("../../libs/crud-pro/exceptions");
22
+ const global_config_1 = require("../../libs/global-config/global-config");
21
23
  let DataDictManageApi = class DataDictManageApi extends BaseApiController_1.BaseApiController {
22
24
  async getDataDictList() {
23
25
  return this.executeSysSimpleSQL('sys_data_dict', keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE, {
@@ -30,18 +32,48 @@ let DataDictManageApi = class DataDictManageApi extends BaseApiController_1.Base
30
32
  });
31
33
  }
32
34
  async createDataDict() {
33
- return this.executeSysSimpleSQL('sys_data_dict', keys_1.KeysOfSimpleSQL.SIMPLE_INSERT, {
34
- enableSoftDelete: true,
35
- validateCfg: {
36
- 'data.dict_code': [keys_1.KeysOfValidators.REQUIRED],
37
- },
35
+ var _a;
36
+ const body = this.ctx.request.body;
37
+ const dict_code = (_a = body === null || body === void 0 ? void 0 : body.data) === null || _a === void 0 ? void 0 : _a.dict_code;
38
+ try {
39
+ return await this.executeSysSimpleSQL('sys_data_dict', keys_1.KeysOfSimpleSQL.SIMPLE_INSERT, {
40
+ enableSoftDelete: true,
41
+ validateCfg: {
42
+ 'data.dict_code': [keys_1.KeysOfValidators.REQUIRED],
43
+ },
44
+ });
45
+ }
46
+ catch (e) {
47
+ if ((e === null || e === void 0 ? void 0 : e.code) === exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_DUP_ENTRY && dict_code) {
48
+ const isSoftDeleted = await this.isSoftDeletedDictCode(dict_code);
49
+ if (isSoftDeleted) {
50
+ throw new exceptions_1.CommonException(exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_DUP_ENTRY, '该 dict_code 对应的数据曾被软删除,无法直接创建。请联系 DBA 处理,或更换 dict_code 后重试。');
51
+ }
52
+ }
53
+ throw e;
54
+ }
55
+ }
56
+ /** 查询 dict_code 是否仅被软删除记录占用(不含 deleted_at=0 的活跃记录) */
57
+ async isSoftDeletedDictCode(dict_code) {
58
+ const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
59
+ const result = await this.curdMixService.executeCrudByCfg({ condition: { dict_code } }, {
60
+ sqlTable: 'sys_data_dict',
61
+ sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
62
+ sqlDatabase: SystemDbName,
63
+ sqlDbType: SystemDbType,
64
+ enableSoftDelete: false,
38
65
  });
66
+ const row = result.getOneObj();
67
+ if (!row) {
68
+ return false;
69
+ }
70
+ return Number(row.deleted_at) !== 0;
39
71
  }
40
72
  async updateDataDict() {
41
73
  return this.executeSysSimpleSQL('sys_data_dict', keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE, {
42
74
  enableSoftDelete: true,
43
75
  validateCfg: {
44
- 'condition.id': [keys_1.KeysOfValidators.REQUIRED, keys_1.KeysOfValidators.NUMERIC],
76
+ 'condition.id': [keys_1.KeysOfValidators.REQUIRED],
45
77
  },
46
78
  });
47
79
  }
@@ -55,7 +87,7 @@ let DataDictManageApi = class DataDictManageApi extends BaseApiController_1.Base
55
87
  return this.executeSysSimpleSQL('sys_data_dict', keys_1.KeysOfSimpleSQL.SIMPLE_DELETE, {
56
88
  enableSoftDelete: true,
57
89
  validateCfg: {
58
- 'condition.id': [keys_1.KeysOfValidators.REQUIRED, keys_1.KeysOfValidators.NUMERIC],
90
+ 'condition.id': [keys_1.KeysOfValidators.REQUIRED],
59
91
  'condition.dict_code': [keys_1.KeysOfValidators.REQUIRED],
60
92
  },
61
93
  });
@@ -85,7 +117,7 @@ let DataDictManageApi = class DataDictManageApi extends BaseApiController_1.Base
85
117
  return this.executeSysSimpleSQL('sys_data_dict_item', keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE, {
86
118
  enableSoftDelete: true,
87
119
  validateCfg: {
88
- 'condition.id': [keys_1.KeysOfValidators.REQUIRED, keys_1.KeysOfValidators.NUMERIC],
120
+ 'condition.id': [keys_1.KeysOfValidators.REQUIRED],
89
121
  },
90
122
  });
91
123
  }
@@ -93,7 +125,7 @@ let DataDictManageApi = class DataDictManageApi extends BaseApiController_1.Base
93
125
  return this.executeSysSimpleSQL('sys_data_dict_item', keys_1.KeysOfSimpleSQL.SIMPLE_DELETE, {
94
126
  enableSoftDelete: true,
95
127
  validateCfg: {
96
- 'condition.id': [keys_1.KeysOfValidators.REQUIRED, keys_1.KeysOfValidators.NUMERIC],
128
+ 'condition.id': [keys_1.KeysOfValidators.REQUIRED],
97
129
  'condition.dict_code': [keys_1.KeysOfValidators.REQUIRED],
98
130
  },
99
131
  });
@@ -75,7 +75,7 @@ let DocManageApi = class DocManageApi extends BaseApiController_1.BaseApiControl
75
75
  return this.executeSysSimpleSQL('sys_doc', keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE, {
76
76
  enableSoftDelete: true,
77
77
  validateCfg: {
78
- 'condition.id': [keys_1.KeysOfValidators.REQUIRED, keys_1.KeysOfValidators.NUMERIC],
78
+ 'condition.id': [keys_1.KeysOfValidators.REQUIRED],
79
79
  },
80
80
  updateCfg: {
81
81
  ...updateCfg,
@@ -87,7 +87,7 @@ let DocManageApi = class DocManageApi extends BaseApiController_1.BaseApiControl
87
87
  return this.executeSysSimpleSQL('sys_doc', keys_1.KeysOfSimpleSQL.SIMPLE_DELETE, {
88
88
  enableSoftDelete: true,
89
89
  validateCfg: {
90
- 'condition.id': [keys_1.KeysOfValidators.REQUIRED, keys_1.KeysOfValidators.NUMERIC],
90
+ 'condition.id': [keys_1.KeysOfValidators.REQUIRED],
91
91
  },
92
92
  updateCfg: {
93
93
  'condition.workbench_code': { contextAsString: bizmodels_1.CTX_WORKBENCH_CODE },
@@ -20,6 +20,7 @@ const render_utils_1 = require("../../libs/utils/render-utils");
20
20
  const crypto_utils_1 = require("../../libs/utils/crypto-utils");
21
21
  const SysAppService_1 = require("../../service/SysAppService");
22
22
  const AuthService_1 = require("../../service/AuthService");
23
+ const functions_1 = require("../../libs/utils/functions");
23
24
  /**
24
25
  * 渲染独立外部应用
25
26
  */
@@ -28,13 +29,9 @@ let AppRenderController = class AppRenderController extends BaseApiController_1.
28
29
  const appPathArr = appPath.split('/');
29
30
  const appCode = appPathArr[0];
30
31
  const appInfo = await this.sysAppService.getSysAppOne(appCode);
31
- if (!appInfo) {
32
+ if (!(0, functions_1.isEntityOK)(appInfo)) {
32
33
  this.ctx.status = 404;
33
- return this.ctx.render('404_app', { appCode, errorMsg: ' 应用不存在' });
34
- }
35
- if (appInfo.status !== 1) {
36
- this.ctx.status = 404;
37
- return this.ctx.render('404_app', { appCode, errorMsg: ' 应用已下线' });
34
+ return this.ctx.render('404_app', { appCode, errorMsg: '应用不存在或已下线' });
38
35
  }
39
36
  const isSupportWorkbench = await this.isSupportCurrentWorkbench(appInfo);
40
37
  if (!isSupportWorkbench) {
@@ -42,6 +39,10 @@ let AppRenderController = class AppRenderController extends BaseApiController_1.
42
39
  return this.ctx.render('404_app', { appCode, errorMsg: ' 应用没有绑定此站点' });
43
40
  }
44
41
  const workbenchInfo = await this.workbenchService.getCurrentHostWorkbenchInfo();
42
+ if (!(0, functions_1.isEntityOK)(workbenchInfo)) {
43
+ this.ctx.status = 404;
44
+ return this.ctx.render('404_app', { appCode, errorMsg: '站点不存在或已下线' });
45
+ }
45
46
  const html_content = appInfo.html_content || '<b style="color: red">错误:未配置HTML模版,请检查!!</b>';
46
47
  const userInfo = await this.getUserAndRefreshSessionInfo();
47
48
  // 形如(不带域名):/ns/app/abc-app-path?aa=2332
@@ -119,7 +119,6 @@ declare class CrudPro {
119
119
  */
120
120
  private convertConditionTypeIfNeeded;
121
121
  private executeSQLList;
122
- private parseRunSqlException;
123
122
  private afterExecuteSQLList;
124
123
  private beforeExecuteSQLList;
125
124
  }
@@ -7,6 +7,7 @@ const CurdProServiceHub_1 = require("./services/CurdProServiceHub");
7
7
  const exceptions_1 = require("./exceptions");
8
8
  const RequestCfgModel_1 = require("./models/RequestCfgModel");
9
9
  const MixinUtils_1 = require("./utils/MixinUtils");
10
+ const SqlErrorParseUtils_1 = require("./utils/SqlErrorParseUtils");
10
11
  const keys_1 = require("./models/keys");
11
12
  class CrudPro {
12
13
  constructor() {
@@ -355,19 +356,9 @@ class CrudPro {
355
356
  const message = MixinUtils_1.MixinUtils.getErrorMessage(e);
356
357
  const logger = this.executeContext.getLogger();
357
358
  logger.error('RUN_SQL_EXCEPTION', message);
358
- throw this.parseRunSqlException(e || {});
359
+ throw SqlErrorParseUtils_1.SqlErrorParseUtils.parseRunSqlException(e || {});
359
360
  }
360
361
  }
361
- parseRunSqlException(e) {
362
- const sqlMessage = '' + e.sqlMessage;
363
- if (e.code === 'ER_DUP_ENTRY' && sqlMessage.startsWith('Duplicate entry')) {
364
- return new exceptions_1.CommonException(exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_DUP_ENTRY, '此对象实体已存在,不能创建重复对象');
365
- }
366
- if (e.code === 'ER_NO_SUCH_TABLE') {
367
- return new exceptions_1.CommonException(exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_NO_SUCH_TABLE, '查询的表不存在:' + sqlMessage);
368
- }
369
- return e;
370
- }
371
362
  async afterExecuteSQLList() {
372
363
  return this.executeContext.contextFunc.afterExecuteSQLList();
373
364
  }
@@ -79,6 +79,12 @@ export declare enum Exceptions {
79
79
  RUN_SQL_EXCEPTION = "RUN_SQL_EXCEPTION",
80
80
  RUN_SQL_EXCEPTION_ER_DUP_ENTRY = "RUN_SQL_EXCEPTION_ER_DUP_ENTRY",
81
81
  RUN_SQL_EXCEPTION_ER_NO_SUCH_TABLE = "RUN_SQL_EXCEPTION_ER_NO_SUCH_TABLE",
82
+ RUN_SQL_EXCEPTION_ER_FK_PARENT_REFERENCED = "RUN_SQL_EXCEPTION_ER_FK_PARENT_REFERENCED",
83
+ RUN_SQL_EXCEPTION_ER_FK_PARENT_NOT_FOUND = "RUN_SQL_EXCEPTION_ER_FK_PARENT_NOT_FOUND",
84
+ RUN_SQL_EXCEPTION_ER_NOT_NULL = "RUN_SQL_EXCEPTION_ER_NOT_NULL",
85
+ RUN_SQL_EXCEPTION_ER_DATA_TOO_LONG = "RUN_SQL_EXCEPTION_ER_DATA_TOO_LONG",
86
+ RUN_SQL_EXCEPTION_ER_BAD_FIELD = "RUN_SQL_EXCEPTION_ER_BAD_FIELD",
87
+ RUN_SQL_EXCEPTION_ER_DEADLOCK = "RUN_SQL_EXCEPTION_ER_DEADLOCK",
82
88
  RUN_IS_NEED_EXECUTE_ERR = "RUN_IS_NEED_EXECUTE_ERR",
83
89
  RUN_PICK_ERR_VISITOR_NULL = "RUN_PICK_ERR_VISITOR_NULL",
84
90
  RUN_PICK_ERR_VISITOR_FIELD = "RUN_PICK_ERR_VISITOR_FIELD",
@@ -83,6 +83,12 @@ var Exceptions;
83
83
  Exceptions["RUN_SQL_EXCEPTION"] = "RUN_SQL_EXCEPTION";
84
84
  Exceptions["RUN_SQL_EXCEPTION_ER_DUP_ENTRY"] = "RUN_SQL_EXCEPTION_ER_DUP_ENTRY";
85
85
  Exceptions["RUN_SQL_EXCEPTION_ER_NO_SUCH_TABLE"] = "RUN_SQL_EXCEPTION_ER_NO_SUCH_TABLE";
86
+ Exceptions["RUN_SQL_EXCEPTION_ER_FK_PARENT_REFERENCED"] = "RUN_SQL_EXCEPTION_ER_FK_PARENT_REFERENCED";
87
+ Exceptions["RUN_SQL_EXCEPTION_ER_FK_PARENT_NOT_FOUND"] = "RUN_SQL_EXCEPTION_ER_FK_PARENT_NOT_FOUND";
88
+ Exceptions["RUN_SQL_EXCEPTION_ER_NOT_NULL"] = "RUN_SQL_EXCEPTION_ER_NOT_NULL";
89
+ Exceptions["RUN_SQL_EXCEPTION_ER_DATA_TOO_LONG"] = "RUN_SQL_EXCEPTION_ER_DATA_TOO_LONG";
90
+ Exceptions["RUN_SQL_EXCEPTION_ER_BAD_FIELD"] = "RUN_SQL_EXCEPTION_ER_BAD_FIELD";
91
+ Exceptions["RUN_SQL_EXCEPTION_ER_DEADLOCK"] = "RUN_SQL_EXCEPTION_ER_DEADLOCK";
86
92
  Exceptions["RUN_IS_NEED_EXECUTE_ERR"] = "RUN_IS_NEED_EXECUTE_ERR";
87
93
  Exceptions["RUN_PICK_ERR_VISITOR_NULL"] = "RUN_PICK_ERR_VISITOR_NULL";
88
94
  Exceptions["RUN_PICK_ERR_VISITOR_FIELD"] = "RUN_PICK_ERR_VISITOR_FIELD";
@@ -0,0 +1,22 @@
1
+ import { CommonException } from '../exceptions';
2
+ declare const SqlErrorParseUtils: {
3
+ /**
4
+ * 从驱动原始错误中提取可读 SQL 错误信息(兼容 MySQL / PostgreSQL / SQL Server)
5
+ */
6
+ getSqlErrorMessage(e: any): string;
7
+ isDuplicateEntryError(e: any, sqlMessage?: string): boolean;
8
+ isNoSuchTableError(e: any, sqlMessage?: string): boolean;
9
+ /** 外键约束:父记录被引用,无法删除或修改 */
10
+ isForeignKeyParentReferencedError(e: any, sqlMessage?: string): boolean;
11
+ /** 外键约束:关联的主数据不存在 */
12
+ isForeignKeyParentNotFoundError(e: any, sqlMessage?: string): boolean;
13
+ isNotNullViolationError(e: any, sqlMessage?: string): boolean;
14
+ isDataTooLongError(e: any, sqlMessage?: string): boolean;
15
+ isBadFieldError(e: any, sqlMessage?: string): boolean;
16
+ isDeadlockError(e: any, sqlMessage?: string): boolean;
17
+ /**
18
+ * 将数据库驱动原始错误规范化为 CommonException
19
+ */
20
+ parseRunSqlException(e: any): CommonException;
21
+ };
22
+ export { SqlErrorParseUtils };
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SqlErrorParseUtils = void 0;
4
+ const exceptions_1 = require("../exceptions");
5
+ const SqlErrorParseUtils = {
6
+ /**
7
+ * 从驱动原始错误中提取可读 SQL 错误信息(兼容 MySQL / PostgreSQL / SQL Server)
8
+ */
9
+ getSqlErrorMessage(e) {
10
+ return '' + ((e === null || e === void 0 ? void 0 : e.sqlMessage) || (e === null || e === void 0 ? void 0 : e.message) || '');
11
+ },
12
+ isDuplicateEntryError(e, sqlMessage) {
13
+ const message = sqlMessage !== null && sqlMessage !== void 0 ? sqlMessage : SqlErrorParseUtils.getSqlErrorMessage(e);
14
+ if ((e === null || e === void 0 ? void 0 : e.code) === exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_DUP_ENTRY) {
15
+ return true;
16
+ }
17
+ // MySQL
18
+ if ((e === null || e === void 0 ? void 0 : e.code) === 'ER_DUP_ENTRY' || (e === null || e === void 0 ? void 0 : e.errno) === 1062) {
19
+ return true;
20
+ }
21
+ // PostgreSQL
22
+ if ((e === null || e === void 0 ? void 0 : e.code) === '23505') {
23
+ return true;
24
+ }
25
+ // SQL Server
26
+ if ((e === null || e === void 0 ? void 0 : e.number) === 2627 || (e === null || e === void 0 ? void 0 : e.number) === 2601) {
27
+ return true;
28
+ }
29
+ return /duplicate key/i.test(message)
30
+ || /unique constraint/i.test(message)
31
+ || /unique key constraint/i.test(message)
32
+ || message.startsWith('Duplicate entry');
33
+ },
34
+ isNoSuchTableError(e, sqlMessage) {
35
+ const message = sqlMessage !== null && sqlMessage !== void 0 ? sqlMessage : SqlErrorParseUtils.getSqlErrorMessage(e);
36
+ if ((e === null || e === void 0 ? void 0 : e.code) === exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_NO_SUCH_TABLE) {
37
+ return true;
38
+ }
39
+ // MySQL
40
+ if ((e === null || e === void 0 ? void 0 : e.code) === 'ER_NO_SUCH_TABLE' || (e === null || e === void 0 ? void 0 : e.errno) === 1146) {
41
+ return true;
42
+ }
43
+ // PostgreSQL
44
+ if ((e === null || e === void 0 ? void 0 : e.code) === '42P01') {
45
+ return true;
46
+ }
47
+ // SQL Server
48
+ if ((e === null || e === void 0 ? void 0 : e.number) === 208) {
49
+ return true;
50
+ }
51
+ return /doesn't exist/i.test(message)
52
+ || /does not exist/i.test(message)
53
+ || /invalid object name/i.test(message)
54
+ || /no such table/i.test(message);
55
+ },
56
+ /** 外键约束:父记录被引用,无法删除或修改 */
57
+ isForeignKeyParentReferencedError(e, sqlMessage) {
58
+ const message = sqlMessage !== null && sqlMessage !== void 0 ? sqlMessage : SqlErrorParseUtils.getSqlErrorMessage(e);
59
+ if ((e === null || e === void 0 ? void 0 : e.code) === exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_FK_PARENT_REFERENCED) {
60
+ return true;
61
+ }
62
+ if ((e === null || e === void 0 ? void 0 : e.code) === 'ER_ROW_IS_REFERENCED_2' || (e === null || e === void 0 ? void 0 : e.errno) === 1451) {
63
+ return true;
64
+ }
65
+ return /Cannot delete or update a parent row/i.test(message)
66
+ || /update or delete on table .* violates foreign key constraint/i.test(message)
67
+ || /DELETE statement conflicted with the REFERENCE constraint/i.test(message)
68
+ || /UPDATE statement conflicted with the REFERENCE constraint/i.test(message);
69
+ },
70
+ /** 外键约束:关联的主数据不存在 */
71
+ isForeignKeyParentNotFoundError(e, sqlMessage) {
72
+ const message = sqlMessage !== null && sqlMessage !== void 0 ? sqlMessage : SqlErrorParseUtils.getSqlErrorMessage(e);
73
+ if ((e === null || e === void 0 ? void 0 : e.code) === exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_FK_PARENT_NOT_FOUND) {
74
+ return true;
75
+ }
76
+ if ((e === null || e === void 0 ? void 0 : e.code) === 'ER_NO_REFERENCED_ROW_2' || (e === null || e === void 0 ? void 0 : e.errno) === 1452) {
77
+ return true;
78
+ }
79
+ // PostgreSQL / SQL Server 与父记录被引用共用错误码,需靠消息区分
80
+ if ((e === null || e === void 0 ? void 0 : e.code) === '23503' || (e === null || e === void 0 ? void 0 : e.number) === 547) {
81
+ return /insert or update on table/i.test(message)
82
+ || /INSERT statement conflicted with the FOREIGN KEY constraint/i.test(message)
83
+ || /INSERT statement conflicted with the REFERENCE constraint/i.test(message)
84
+ || /violates foreign key constraint/i.test(message);
85
+ }
86
+ return /Cannot add or update a child row/i.test(message)
87
+ || /insert or update on table .* violates foreign key constraint/i.test(message);
88
+ },
89
+ isNotNullViolationError(e, sqlMessage) {
90
+ const message = sqlMessage !== null && sqlMessage !== void 0 ? sqlMessage : SqlErrorParseUtils.getSqlErrorMessage(e);
91
+ if ((e === null || e === void 0 ? void 0 : e.code) === exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_NOT_NULL) {
92
+ return true;
93
+ }
94
+ if ((e === null || e === void 0 ? void 0 : e.code) === 'ER_BAD_NULL_ERROR' || (e === null || e === void 0 ? void 0 : e.errno) === 1048) {
95
+ return true;
96
+ }
97
+ if ((e === null || e === void 0 ? void 0 : e.code) === '23502') {
98
+ return true;
99
+ }
100
+ if ((e === null || e === void 0 ? void 0 : e.number) === 515) {
101
+ return true;
102
+ }
103
+ return /cannot be null/i.test(message)
104
+ || /null value in column/i.test(message)
105
+ || /violates not-null constraint/i.test(message)
106
+ || /Cannot insert the value NULL into column/i.test(message);
107
+ },
108
+ isDataTooLongError(e, sqlMessage) {
109
+ const message = sqlMessage !== null && sqlMessage !== void 0 ? sqlMessage : SqlErrorParseUtils.getSqlErrorMessage(e);
110
+ if ((e === null || e === void 0 ? void 0 : e.code) === exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_DATA_TOO_LONG) {
111
+ return true;
112
+ }
113
+ if ((e === null || e === void 0 ? void 0 : e.code) === 'ER_DATA_TOO_LONG' || (e === null || e === void 0 ? void 0 : e.errno) === 1406) {
114
+ return true;
115
+ }
116
+ if ((e === null || e === void 0 ? void 0 : e.code) === '22001') {
117
+ return true;
118
+ }
119
+ if ((e === null || e === void 0 ? void 0 : e.number) === 2628 || (e === null || e === void 0 ? void 0 : e.number) === 8152) {
120
+ return true;
121
+ }
122
+ return /data too long/i.test(message)
123
+ || /value too long/i.test(message)
124
+ || /string data, right truncation/i.test(message)
125
+ || /would be truncated/i.test(message);
126
+ },
127
+ isBadFieldError(e, sqlMessage) {
128
+ const message = sqlMessage !== null && sqlMessage !== void 0 ? sqlMessage : SqlErrorParseUtils.getSqlErrorMessage(e);
129
+ if ((e === null || e === void 0 ? void 0 : e.code) === exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_BAD_FIELD) {
130
+ return true;
131
+ }
132
+ if ((e === null || e === void 0 ? void 0 : e.code) === 'ER_BAD_FIELD_ERROR' || (e === null || e === void 0 ? void 0 : e.errno) === 1054) {
133
+ return true;
134
+ }
135
+ if ((e === null || e === void 0 ? void 0 : e.code) === '42703') {
136
+ return true;
137
+ }
138
+ if ((e === null || e === void 0 ? void 0 : e.number) === 207) {
139
+ return true;
140
+ }
141
+ return /unknown column/i.test(message)
142
+ || /Invalid column name/i.test(message);
143
+ },
144
+ isDeadlockError(e, sqlMessage) {
145
+ const message = sqlMessage !== null && sqlMessage !== void 0 ? sqlMessage : SqlErrorParseUtils.getSqlErrorMessage(e);
146
+ if ((e === null || e === void 0 ? void 0 : e.code) === exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_DEADLOCK) {
147
+ return true;
148
+ }
149
+ if ((e === null || e === void 0 ? void 0 : e.code) === 'ER_LOCK_DEADLOCK' || (e === null || e === void 0 ? void 0 : e.errno) === 1213) {
150
+ return true;
151
+ }
152
+ if ((e === null || e === void 0 ? void 0 : e.code) === '40P01') {
153
+ return true;
154
+ }
155
+ if ((e === null || e === void 0 ? void 0 : e.number) === 1205) {
156
+ return true;
157
+ }
158
+ return /deadlock/i.test(message);
159
+ },
160
+ /**
161
+ * 将数据库驱动原始错误规范化为 CommonException
162
+ */
163
+ parseRunSqlException(e) {
164
+ if (e instanceof exceptions_1.CommonException) {
165
+ return e;
166
+ }
167
+ const sqlMessage = SqlErrorParseUtils.getSqlErrorMessage(e);
168
+ const rules = [
169
+ {
170
+ code: exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_DUP_ENTRY,
171
+ match: SqlErrorParseUtils.isDuplicateEntryError,
172
+ message: '此条数据已存在,不能重复创建',
173
+ },
174
+ {
175
+ code: exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_NO_SUCH_TABLE,
176
+ match: SqlErrorParseUtils.isNoSuchTableError,
177
+ message: (message) => '查询的表不存在:' + message,
178
+ },
179
+ {
180
+ code: exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_FK_PARENT_REFERENCED,
181
+ match: SqlErrorParseUtils.isForeignKeyParentReferencedError,
182
+ message: '无法删除或修改:该数据已被其他记录引用,请先解除关联后再试',
183
+ },
184
+ {
185
+ code: exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_FK_PARENT_NOT_FOUND,
186
+ match: SqlErrorParseUtils.isForeignKeyParentNotFoundError,
187
+ message: '无法保存:所关联的数据不存在或已被删除',
188
+ },
189
+ {
190
+ code: exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_NOT_NULL,
191
+ match: SqlErrorParseUtils.isNotNullViolationError,
192
+ message: '操作失败:必填字段不能为空',
193
+ },
194
+ {
195
+ code: exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_DATA_TOO_LONG,
196
+ match: SqlErrorParseUtils.isDataTooLongError,
197
+ message: '操作失败:输入内容超出字段长度限制',
198
+ },
199
+ {
200
+ code: exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_BAD_FIELD,
201
+ match: SqlErrorParseUtils.isBadFieldError,
202
+ message: '操作失败:字段配置有误,请联系管理员检查表结构或接口配置',
203
+ },
204
+ {
205
+ code: exceptions_1.Exceptions.RUN_SQL_EXCEPTION_ER_DEADLOCK,
206
+ match: SqlErrorParseUtils.isDeadlockError,
207
+ message: '操作失败:系统繁忙,请稍后重试',
208
+ },
209
+ ];
210
+ for (const rule of rules) {
211
+ if (rule.match(e, sqlMessage)) {
212
+ const message = typeof rule.message === 'function' ? rule.message(sqlMessage) : rule.message;
213
+ return new exceptions_1.CommonException(rule.code, message);
214
+ }
215
+ }
216
+ return e;
217
+ },
218
+ };
219
+ exports.SqlErrorParseUtils = SqlErrorParseUtils;
@@ -118,6 +118,9 @@ function isEntityDeleted(entity) {
118
118
  }
119
119
  exports.isEntityDeleted = isEntityDeleted;
120
120
  function isEntityOK(entity) {
121
+ if (!entity) {
122
+ return false;
123
+ }
121
124
  const isOK = (entity === null || entity === void 0 ? void 0 : entity.status) === 1 || (entity === null || entity === void 0 ? void 0 : entity.status) === '1';
122
125
  return isOK && !isEntityDeleted(entity);
123
126
  }
@@ -32,7 +32,7 @@ const lruCache = new lru_cache_1.LRUCache({
32
32
  let AnyApiService = class AnyApiService extends ApiBaseService_1.ApiBaseService {
33
33
  async executeAnyApiMethod(methodCode, headers, body, query) {
34
34
  const anyApi = await this.getAnyApiMethod(methodCode);
35
- if (!anyApi || anyApi.status !== 1) {
35
+ if (!(0, functions_1.isEntityOK)(anyApi)) {
36
36
  throw new devops_1.BizException('接口不存在或已下线:' + methodCode);
37
37
  }
38
38
  const isSupport = await this.workbenchService.isSupportCurrentWorkbench(anyApi.workbench_code_array);
@@ -62,7 +62,7 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
62
62
  var _a;
63
63
  const appCode = stdAction.appCode;
64
64
  const appInfo = await this.getParsedCrudStdAppForSettingKey(stdAction);
65
- if (!appInfo || appInfo.status !== 1) {
65
+ if (!(0, functions_1.isEntityOK)(appInfo)) {
66
66
  throw new devops_1.BizException('应用不存在或已下线:' + appCode);
67
67
  }
68
68
  const stdCrudCfgObj = appInfo.stdCrudCfgObj;
@@ -208,7 +208,7 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
208
208
  */
209
209
  async executeStdActionByReq(stdAction, params) {
210
210
  const appInfo = await this.getParsedCrudStdAppForSettingKey(stdAction);
211
- if (!appInfo || appInfo.status !== 1) {
211
+ if (!(0, functions_1.isEntityOK)(appInfo)) {
212
212
  throw new devops_1.BizException('应用不存在或已下线:' + stdAction.appCode);
213
213
  }
214
214
  const actionsMap = appInfo.actionsMap;
@@ -59,7 +59,7 @@ let CurdMixByDictService = class CurdMixByDictService {
59
59
  let selectedRows = [];
60
60
  if (noCacheCodes.length > 0) {
61
61
  const res1 = await this.curdProService.executeCrudByCfg({
62
- condition: { dict_code: { $in: noCacheCodes }, deleted_at: 0 },
62
+ condition: { dict_code: { $in: noCacheCodes }, deleted_at: 0, status: 1 },
63
63
  }, {
64
64
  sqlTable: SystemTables_1.SystemTables.sys_data_dict_item,
65
65
  sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
@@ -47,7 +47,7 @@ let CurdMixBySysConfigService = class CurdMixBySysConfigService {
47
47
  }
48
48
  const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
49
49
  const res1 = await this.curdProService.executeCrudByCfg({
50
- condition: { config_code: { $in: notCachedCodes }, deleted_at: 0 },
50
+ condition: { config_code: { $in: notCachedCodes }, deleted_at: 0, status: 1 },
51
51
  }, {
52
52
  sqlTable: SystemTables_1.SystemTables.sys_configs,
53
53
  sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
@@ -34,7 +34,7 @@ let CurdMixByWorkbenchService = CurdMixByWorkbenchService_1 = class CurdMixByWor
34
34
  const service = await ctx.requestContext.getAsync(CurdMixByWorkbenchService_1);
35
35
  const reqJson = {
36
36
  columns: 'workbench_code,workbench_name,workbench_domain',
37
- condition: { deleted_at: 0 },
37
+ condition: { deleted_at: 0, status: 1 },
38
38
  };
39
39
  const res = await service.curdProService.executeCrudByCfg(reqJson, {
40
40
  sqlTable: SystemTables_1.SystemTables.sys_workbench,