midway-fatcms 0.0.12 → 0.0.15

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 (55) hide show
  1. package/dist/controller/base/BaseApiController.d.ts +2 -0
  2. package/dist/controller/base/BaseApiController.js +5 -0
  3. package/dist/controller/gateway/DocGatewayController.js +7 -5
  4. package/dist/controller/gateway/PublicApiController.js +32 -3
  5. package/dist/controller/helpers.controller.d.ts +2 -0
  6. package/dist/controller/helpers.controller.js +17 -0
  7. package/dist/controller/home.controller.js +2 -1
  8. package/dist/controller/manage/DataDictManageApi.d.ts +2 -0
  9. package/dist/controller/manage/DataDictManageApi.js +41 -9
  10. package/dist/controller/manage/DocManageApi.js +2 -2
  11. package/dist/controller/myinfo/AuthController.js +17 -1
  12. package/dist/controller/render/AppRenderController.js +7 -6
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.js +1 -1
  15. package/dist/libs/crud-pro/CrudPro.d.ts +0 -1
  16. package/dist/libs/crud-pro/CrudPro.js +2 -11
  17. package/dist/libs/crud-pro/exceptions.d.ts +6 -0
  18. package/dist/libs/crud-pro/exceptions.js +6 -0
  19. package/dist/libs/crud-pro/utils/SqlErrorParseUtils.d.ts +22 -0
  20. package/dist/libs/crud-pro/utils/SqlErrorParseUtils.js +219 -0
  21. package/dist/libs/utils/functions.js +3 -0
  22. package/dist/models/SystemTables.d.ts +1 -0
  23. package/dist/models/SystemTables.js +1 -0
  24. package/dist/service/ActionLogService.d.ts +14 -0
  25. package/dist/service/ActionLogService.js +50 -0
  26. package/dist/service/anyapi/AnyApiService.js +1 -1
  27. package/dist/service/crudstd/CrudStdService.d.ts +1 -2
  28. package/dist/service/crudstd/CrudStdService.js +3 -4
  29. package/dist/service/curd/CurdMixByDictService.js +2 -1
  30. package/dist/service/curd/CurdMixBySysConfigService.js +1 -1
  31. package/dist/service/curd/CurdMixByWorkbenchService.js +1 -1
  32. package/dist/service/proxyapi/ProxyApiLoadService.js +3 -0
  33. package/package.json +1 -1
  34. package/src/controller/base/BaseApiController.ts +3 -1
  35. package/src/controller/gateway/DocGatewayController.ts +9 -5
  36. package/src/controller/gateway/PublicApiController.ts +39 -4
  37. package/src/controller/helpers.controller.ts +24 -2
  38. package/src/controller/home.controller.ts +3 -1
  39. package/src/controller/manage/DataDictManageApi.ts +48 -11
  40. package/src/controller/manage/DocManageApi.ts +2 -2
  41. package/src/controller/myinfo/AuthController.ts +23 -1
  42. package/src/controller/render/AppRenderController.ts +9 -7
  43. package/src/index.ts +1 -1
  44. package/src/libs/crud-pro/CrudPro.ts +2 -12
  45. package/src/libs/crud-pro/exceptions.ts +6 -0
  46. package/src/libs/crud-pro/utils/SqlErrorParseUtils.ts +236 -0
  47. package/src/libs/utils/functions.ts +3 -0
  48. package/src/models/SystemTables.ts +1 -2
  49. package/src/service/ActionLogService.ts +52 -0
  50. package/src/service/anyapi/AnyApiService.ts +2 -2
  51. package/src/service/crudstd/CrudStdService.ts +4 -5
  52. package/src/service/curd/CurdMixByDictService.ts +2 -1
  53. package/src/service/curd/CurdMixBySysConfigService.ts +1 -1
  54. package/src/service/curd/CurdMixByWorkbenchService.ts +1 -1
  55. package/src/service/proxyapi/ProxyApiLoadService.ts +4 -1
@@ -5,6 +5,7 @@ import { KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
5
5
  import { UserAccountService } from '../../service/UserAccountService';
6
6
  import { BaseService } from '../../service/base/BaseService';
7
7
  import { ConfigChangelogService } from '../../service/ConfigChangelogService';
8
+ import { ActionLogService } from '../../service/ActionLogService';
8
9
  export interface IExecuteSimpleSqlParams {
9
10
  updateCfg?: Record<string, IFuncCfgModel>;
10
11
  allowCfg?: Record<string, string[]>;
@@ -28,6 +29,7 @@ export declare class BaseApiController extends BaseService {
28
29
  protected ctx: Context;
29
30
  protected curdMixService: CurdMixService;
30
31
  protected userAccountService: UserAccountService;
32
+ protected actionLogService: ActionLogService;
31
33
  protected configChangelogService: ConfigChangelogService;
32
34
  /**
33
35
  * 检查用户是否在指定时间内重复执行了某个操作
@@ -24,6 +24,7 @@ const aes_128_cbc_1 = require("aes-128-cbc");
24
24
  const md5 = require("md5");
25
25
  const AsymmetricCrypto_1 = require("../../libs/utils/AsymmetricCrypto");
26
26
  const ConfigChangelogService_1 = require("../../service/ConfigChangelogService");
27
+ const ActionLogService_1 = require("../../service/ActionLogService");
27
28
  let BaseApiController = class BaseApiController extends BaseService_1.BaseService {
28
29
  /**
29
30
  * 检查用户是否在指定时间内重复执行了某个操作
@@ -310,6 +311,10 @@ __decorate([
310
311
  (0, core_1.Inject)(),
311
312
  __metadata("design:type", UserAccountService_1.UserAccountService)
312
313
  ], BaseApiController.prototype, "userAccountService", void 0);
314
+ __decorate([
315
+ (0, core_1.Inject)(),
316
+ __metadata("design:type", ActionLogService_1.ActionLogService)
317
+ ], BaseApiController.prototype, "actionLogService", void 0);
313
318
  __decorate([
314
319
  (0, core_1.Inject)(),
315
320
  __metadata("design:type", ConfigChangelogService_1.ConfigChangelogService)
@@ -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
  }
@@ -1,9 +1,11 @@
1
1
  /// <reference types="node" />
2
2
  import { Context } from '@midwayjs/koa';
3
3
  import { CommonResult } from '../libs/utils/common-dto';
4
+ import { ActionLogService } from '../service/ActionLogService';
4
5
  export declare class HelpersApi {
5
6
  protected ctx: Context;
6
7
  private midwayWebRouterService;
8
+ protected actionLogService: ActionLogService;
7
9
  getApiEnv(): Promise<{
8
10
  env: string;
9
11
  href: string;
@@ -24,6 +24,7 @@ const SystemPerm_1 = require("../models/SystemPerm");
24
24
  const permission_middleware_1 = require("../middleware/permission.middleware");
25
25
  const CacheRefreshRedisSubscriber_1 = require("../service/base/cache-refresh/CacheRefreshRedisSubscriber");
26
26
  const CacheServiceFactory_1 = require("../service/base/cache/CacheServiceFactory");
27
+ const ActionLogService_1 = require("../service/ActionLogService");
27
28
  // http://127.0.0.1:7002/ns/api/helpers/getApiScript?prefix=/ns/api/manage
28
29
  // http://127.0.0.1:7002/ns/api/helpers/getApiScript
29
30
  // http://127.0.0.1:7002/ns/api/helpers/getApiEnv
@@ -141,6 +142,12 @@ let HelpersApi = class HelpersApi {
141
142
  const cacheName = cacheNameParam;
142
143
  const cacheServiceFactory = await this.ctx.requestContext.getAsync(CacheServiceFactory_1.CacheServiceFactory);
143
144
  await cacheServiceFactory.refreshByCacheName(cacheName, this.ctx);
145
+ await this.actionLogService.insertActionLogTable({
146
+ actionModule: '系统工具',
147
+ actionName: '刷新缓存',
148
+ actionMessage: '刷新缓存成功',
149
+ actionTarget: cacheNameParam
150
+ });
144
151
  return common_dto_1.CommonResult.successRes({
145
152
  message: `业务缓存 ${cacheName} 已刷新`,
146
153
  cacheName,
@@ -148,6 +155,12 @@ let HelpersApi = class HelpersApi {
148
155
  }
149
156
  const category = categoryParam ? categoryParam : undefined;
150
157
  await (0, CacheRefreshRedisSubscriber_1.refreshCacheWithBroadcast)(this.ctx, category);
158
+ await this.actionLogService.insertActionLogTable({
159
+ actionModule: '系统工具',
160
+ actionName: '刷新缓存',
161
+ actionMessage: '刷新缓存成功',
162
+ actionTarget: cacheNameParam
163
+ });
151
164
  return common_dto_1.CommonResult.successRes({
152
165
  message: `缓存已刷新${category ? '(' + category + ')' : '(全部)'}(已广播集群)`,
153
166
  category: category || 'ALL',
@@ -184,6 +197,10 @@ __decorate([
184
197
  (0, core_1.Inject)(),
185
198
  __metadata("design:type", core_1.MidwayWebRouterService)
186
199
  ], HelpersApi.prototype, "midwayWebRouterService", void 0);
200
+ __decorate([
201
+ (0, core_1.Inject)(),
202
+ __metadata("design:type", ActionLogService_1.ActionLogService)
203
+ ], HelpersApi.prototype, "actionLogService", void 0);
187
204
  __decorate([
188
205
  (0, core_1.Get)('/getApiEnv'),
189
206
  __metadata("design:type", Function),
@@ -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 },
@@ -53,6 +53,12 @@ let AuthController = class AuthController extends BaseApiController_1.BaseApiCon
53
53
  }
54
54
  const userSessionInfo = await this.authService.createUserSession(loginName, workbench.workbench_code);
55
55
  this.ctx.cookies.set(userSession_1.SESSION_ID_KEY, userSessionInfo.sessionId, userSession_1.sessionCookieCfg);
56
+ await this.actionLogService.insertActionLogTable({
57
+ actionModule: '用户账号',
58
+ actionName: '登录',
59
+ actionMessage: '登录成功',
60
+ actionTarget: `${userSessionInfo === null || userSessionInfo === void 0 ? void 0 : userSessionInfo.nickName}(${userSessionInfo === null || userSessionInfo === void 0 ? void 0 : userSessionInfo.accountId})`
61
+ });
56
62
  return common_dto_1.CommonResult.successMsg('登录成功', removePrivateField(userSessionInfo));
57
63
  }
58
64
  /**
@@ -87,12 +93,22 @@ let AuthController = class AuthController extends BaseApiController_1.BaseApiCon
87
93
  * 修改我自己的密码
88
94
  */
89
95
  async changeMyPassword() {
96
+ var _a;
90
97
  const { unsaltedPwd } = this.ctx.request.body;
91
98
  const loginName = this.ctx.userSession.getSessionInfo().loginName;
92
99
  if (loginName === 'devopsviewer') {
93
100
  return common_dto_1.CommonResult.errorRes('开放体验账号不支持修改密码');
94
101
  }
95
- return this.userAccountService.chgUserPassword(loginName, unsaltedPwd);
102
+ const res = await this.userAccountService.chgUserPassword(loginName, unsaltedPwd);
103
+ if (res.success) {
104
+ await this.actionLogService.insertActionLogTable({
105
+ actionModule: '用户账号',
106
+ actionName: '修改密码',
107
+ actionMessage: '修改密码成功',
108
+ actionTarget: (_a = this.ctx.userSession.getSessionInfo()) === null || _a === void 0 ? void 0 : _a.nickName
109
+ });
110
+ }
111
+ return res;
96
112
  }
97
113
  /**
98
114
  * 校验权限接口,给前端用的。用于界面按钮级权限控制
@@ -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
package/dist/index.d.ts CHANGED
@@ -12,7 +12,6 @@ export * from './controller/gateway/AsyncTaskController';
12
12
  export * from './controller/helpers.controller';
13
13
  export * from './controller/home.controller';
14
14
  export * from './controller/manage/AnyApiMangeApi';
15
- export * from './controller/manage/AppLogMangeApi';
16
15
  export * from './controller/manage/AppMangeApi';
17
16
  export * from './controller/manage/AppPageMangeApi';
18
17
  export * from './controller/manage/AppSchemaHistoryApi';
@@ -48,6 +47,7 @@ export * from './middleware/tx.middleware';
48
47
  export * from './middleware/permission.middleware';
49
48
  export * from './middleware/redislock.middleware';
50
49
  export * from './service/AuthService';
50
+ export * from './service/ActionLogService';
51
51
  export * from './service/EnumInfoService';
52
52
  export * from './service/FileCenterService';
53
53
  export * from './service/SysConfigService';
package/dist/index.js CHANGED
@@ -30,7 +30,6 @@ __exportStar(require("./controller/gateway/AsyncTaskController"), exports);
30
30
  __exportStar(require("./controller/helpers.controller"), exports);
31
31
  __exportStar(require("./controller/home.controller"), exports);
32
32
  __exportStar(require("./controller/manage/AnyApiMangeApi"), exports);
33
- __exportStar(require("./controller/manage/AppLogMangeApi"), exports);
34
33
  __exportStar(require("./controller/manage/AppMangeApi"), exports);
35
34
  __exportStar(require("./controller/manage/AppPageMangeApi"), exports);
36
35
  __exportStar(require("./controller/manage/AppSchemaHistoryApi"), exports);
@@ -66,6 +65,7 @@ __exportStar(require("./middleware/tx.middleware"), exports);
66
65
  __exportStar(require("./middleware/permission.middleware"), exports);
67
66
  __exportStar(require("./middleware/redislock.middleware"), exports);
68
67
  __exportStar(require("./service/AuthService"), exports);
68
+ __exportStar(require("./service/ActionLogService"), exports);
69
69
  __exportStar(require("./service/EnumInfoService"), exports);
70
70
  __exportStar(require("./service/FileCenterService"), exports);
71
71
  __exportStar(require("./service/SysConfigService"), exports);
@@ -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 };