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.
- package/dist/controller/base/BaseApiController.d.ts +2 -0
- package/dist/controller/base/BaseApiController.js +5 -0
- package/dist/controller/gateway/DocGatewayController.js +7 -5
- package/dist/controller/gateway/PublicApiController.js +32 -3
- package/dist/controller/helpers.controller.d.ts +2 -0
- package/dist/controller/helpers.controller.js +17 -0
- package/dist/controller/home.controller.js +2 -1
- package/dist/controller/manage/DataDictManageApi.d.ts +2 -0
- package/dist/controller/manage/DataDictManageApi.js +41 -9
- package/dist/controller/manage/DocManageApi.js +2 -2
- package/dist/controller/myinfo/AuthController.js +17 -1
- package/dist/controller/render/AppRenderController.js +7 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/libs/crud-pro/CrudPro.d.ts +0 -1
- package/dist/libs/crud-pro/CrudPro.js +2 -11
- package/dist/libs/crud-pro/exceptions.d.ts +6 -0
- package/dist/libs/crud-pro/exceptions.js +6 -0
- package/dist/libs/crud-pro/utils/SqlErrorParseUtils.d.ts +22 -0
- package/dist/libs/crud-pro/utils/SqlErrorParseUtils.js +219 -0
- package/dist/libs/utils/functions.js +3 -0
- package/dist/models/SystemTables.d.ts +1 -0
- package/dist/models/SystemTables.js +1 -0
- package/dist/service/ActionLogService.d.ts +14 -0
- package/dist/service/ActionLogService.js +50 -0
- package/dist/service/anyapi/AnyApiService.js +1 -1
- package/dist/service/crudstd/CrudStdService.d.ts +1 -2
- package/dist/service/crudstd/CrudStdService.js +3 -4
- package/dist/service/curd/CurdMixByDictService.js +2 -1
- package/dist/service/curd/CurdMixBySysConfigService.js +1 -1
- package/dist/service/curd/CurdMixByWorkbenchService.js +1 -1
- package/dist/service/proxyapi/ProxyApiLoadService.js +3 -0
- package/package.json +1 -1
- package/src/controller/base/BaseApiController.ts +3 -1
- package/src/controller/gateway/DocGatewayController.ts +9 -5
- package/src/controller/gateway/PublicApiController.ts +39 -4
- package/src/controller/helpers.controller.ts +24 -2
- package/src/controller/home.controller.ts +3 -1
- package/src/controller/manage/DataDictManageApi.ts +48 -11
- package/src/controller/manage/DocManageApi.ts +2 -2
- package/src/controller/myinfo/AuthController.ts +23 -1
- package/src/controller/render/AppRenderController.ts +9 -7
- package/src/index.ts +1 -1
- package/src/libs/crud-pro/CrudPro.ts +2 -12
- package/src/libs/crud-pro/exceptions.ts +6 -0
- package/src/libs/crud-pro/utils/SqlErrorParseUtils.ts +236 -0
- package/src/libs/utils/functions.ts +3 -0
- package/src/models/SystemTables.ts +1 -2
- package/src/service/ActionLogService.ts +52 -0
- package/src/service/anyapi/AnyApiService.ts +2 -2
- package/src/service/crudstd/CrudStdService.ts +4 -5
- package/src/service/curd/CurdMixByDictService.ts +2 -1
- package/src/service/curd/CurdMixBySysConfigService.ts +1 -1
- package/src/service/curd/CurdMixByWorkbenchService.ts +1 -1
- package/src/service/proxyapi/ProxyApiLoadService.ts +4 -1
|
@@ -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
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseService } from "../service/base/BaseService";
|
|
2
|
+
import { CrudWriteResult } from '../libs/crud-pro/models/CrudResult';
|
|
3
|
+
export interface IActionLoginInfo {
|
|
4
|
+
actionModule: string;
|
|
5
|
+
actionName: string;
|
|
6
|
+
actionMessage: string;
|
|
7
|
+
actionTarget: string;
|
|
8
|
+
createdBy?: string;
|
|
9
|
+
modifiedBy?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class ActionLogService extends BaseService {
|
|
12
|
+
private curdMixService;
|
|
13
|
+
insertActionLogTable(logInfo: IActionLoginInfo): Promise<CrudWriteResult>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ActionLogService = void 0;
|
|
13
|
+
const core_1 = require("@midwayjs/core");
|
|
14
|
+
const CurdMixService_1 = require("./curd/CurdMixService");
|
|
15
|
+
const SystemTables_1 = require("../models/SystemTables");
|
|
16
|
+
const global_config_1 = require("../libs/global-config/global-config");
|
|
17
|
+
const BaseService_1 = require("../service/base/BaseService");
|
|
18
|
+
const DateTimeUtils_1 = require("../libs/crud-pro/utils/DateTimeUtils");
|
|
19
|
+
let ActionLogService = class ActionLogService extends BaseService_1.BaseService {
|
|
20
|
+
async insertActionLogTable(logInfo) {
|
|
21
|
+
const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
|
|
22
|
+
const actionTable = this.curdMixService.getQuickCrud({
|
|
23
|
+
sqlDatabase: SystemDbName,
|
|
24
|
+
sqlDbType: SystemDbType,
|
|
25
|
+
sqlTable: SystemTables_1.SystemTables.sys_action_log,
|
|
26
|
+
});
|
|
27
|
+
const sessionInfo = this.ctx.userSession.getSessionInfo();
|
|
28
|
+
return actionTable.insert({
|
|
29
|
+
data: {
|
|
30
|
+
action_module: logInfo.actionModule,
|
|
31
|
+
action_name: logInfo.actionName,
|
|
32
|
+
action_message: logInfo.actionMessage,
|
|
33
|
+
created_by: logInfo.createdBy || (sessionInfo === null || sessionInfo === void 0 ? void 0 : sessionInfo.accountId) || '',
|
|
34
|
+
created_at: DateTimeUtils_1.DateTimeUtils.getCurrentTimeString(),
|
|
35
|
+
modified_at: DateTimeUtils_1.DateTimeUtils.getCurrentTimeString(),
|
|
36
|
+
modified_by: logInfo.modifiedBy || (sessionInfo === null || sessionInfo === void 0 ? void 0 : sessionInfo.accountId) || '',
|
|
37
|
+
status: 1,
|
|
38
|
+
action_target: logInfo.actionTarget
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, core_1.Inject)(),
|
|
45
|
+
__metadata("design:type", CurdMixService_1.CurdMixService)
|
|
46
|
+
], ActionLogService.prototype, "curdMixService", void 0);
|
|
47
|
+
ActionLogService = __decorate([
|
|
48
|
+
(0, core_1.Provide)()
|
|
49
|
+
], ActionLogService);
|
|
50
|
+
exports.ActionLogService = ActionLogService;
|
|
@@ -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 (!
|
|
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);
|
|
@@ -35,8 +35,7 @@ export declare class CrudStdService extends ApiBaseService {
|
|
|
35
35
|
private handleResultDataPermissionBySettingKey;
|
|
36
36
|
/**
|
|
37
37
|
* 获取appInfo 并且拿到当前settingKey相关的信息
|
|
38
|
-
* @param
|
|
39
|
-
* @param settingKey
|
|
38
|
+
* @param stdAction
|
|
40
39
|
*/
|
|
41
40
|
getParsedCrudStdAppForSettingKey(stdAction: ICrudStdActionParams): Promise<ICrudStdAppInfoForSettingKey>;
|
|
42
41
|
/**
|
|
@@ -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 (!
|
|
65
|
+
if (!(0, functions_1.isEntityOK)(appInfo)) {
|
|
66
66
|
throw new devops_1.BizException('应用不存在或已下线:' + appCode);
|
|
67
67
|
}
|
|
68
68
|
const stdCrudCfgObj = appInfo.stdCrudCfgObj;
|
|
@@ -155,8 +155,7 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
|
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
157
|
* 获取appInfo 并且拿到当前settingKey相关的信息
|
|
158
|
-
* @param
|
|
159
|
-
* @param settingKey
|
|
158
|
+
* @param stdAction
|
|
160
159
|
*/
|
|
161
160
|
async getParsedCrudStdAppForSettingKey(stdAction) {
|
|
162
161
|
const { appCode, settingKey, buttonSettingKey } = stdAction || {};
|
|
@@ -208,7 +207,7 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
|
|
|
208
207
|
*/
|
|
209
208
|
async executeStdActionByReq(stdAction, params) {
|
|
210
209
|
const appInfo = await this.getParsedCrudStdAppForSettingKey(stdAction);
|
|
211
|
-
if (!
|
|
210
|
+
if (!(0, functions_1.isEntityOK)(appInfo)) {
|
|
212
211
|
throw new devops_1.BizException('应用不存在或已下线:' + stdAction.appCode);
|
|
213
212
|
}
|
|
214
213
|
const actionsMap = appInfo.actionsMap;
|
|
@@ -59,7 +59,8 @@ let CurdMixByDictService = class CurdMixByDictService {
|
|
|
59
59
|
let selectedRows = [];
|
|
60
60
|
if (noCacheCodes.length > 0) {
|
|
61
61
|
const res1 = await this.curdProService.executeCrudByCfg({
|
|
62
|
-
|
|
62
|
+
columns: ['dict_code', 'label', 'value', 'style', 'code'],
|
|
63
|
+
condition: { dict_code: { $in: noCacheCodes }, deleted_at: 0, status: 1 },
|
|
63
64
|
}, {
|
|
64
65
|
sqlTable: SystemTables_1.SystemTables.sys_data_dict_item,
|
|
65
66
|
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,
|
|
@@ -115,6 +115,9 @@ let ProxyApiLoadService = class ProxyApiLoadService extends BaseService_1.BaseSe
|
|
|
115
115
|
});
|
|
116
116
|
const rows0 = res.getResRows();
|
|
117
117
|
const rows = rows0.filter(s => {
|
|
118
|
+
if (!(0, functions_1.isEntityOK)(s)) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
118
121
|
if (!s.workbench_code_array) {
|
|
119
122
|
throw new exceptions_1.CommonException('IS_SUPPORT_CURRENT_WORKBENCH', '未配置支持的站点字段');
|
|
120
123
|
}
|
package/package.json
CHANGED
|
@@ -15,6 +15,7 @@ import * as md5 from 'md5';
|
|
|
15
15
|
import { AsymmetricCrypto } from '@/libs/utils/AsymmetricCrypto';
|
|
16
16
|
import { IRequestCfgModel2 } from "@/models/bizmodels";
|
|
17
17
|
import { ConfigChangelogService, isChangelogTable, ChangelogAction } from '@/service/ConfigChangelogService';
|
|
18
|
+
import { ActionLogService } from '@/service/ActionLogService'
|
|
18
19
|
|
|
19
20
|
export interface IExecuteSimpleSqlParams {
|
|
20
21
|
updateCfg?: Record<string, IFuncCfgModel>;
|
|
@@ -49,7 +50,8 @@ export class BaseApiController extends BaseService {
|
|
|
49
50
|
@Inject()
|
|
50
51
|
protected userAccountService: UserAccountService;
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
@Inject()
|
|
54
|
+
protected actionLogService: ActionLogService;
|
|
53
55
|
|
|
54
56
|
@Inject()
|
|
55
57
|
protected configChangelogService: ConfigChangelogService;
|
|
@@ -6,6 +6,7 @@ import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
|
|
|
6
6
|
import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
|
|
7
7
|
import { WorkbenchService } from '@/service/WorkbenchService';
|
|
8
8
|
import { CommonResult } from '@/libs/utils/common-dto';
|
|
9
|
+
import { isEntityOK } from '@/libs/utils/functions';
|
|
9
10
|
import { getRealIpSafe } from '@/libs/utils/fatcms-request';
|
|
10
11
|
|
|
11
12
|
function checkIsNumber(value: string, name: string) {
|
|
@@ -91,13 +92,16 @@ export class DocGatewayController extends BaseApiController {
|
|
|
91
92
|
}
|
|
92
93
|
);
|
|
93
94
|
|
|
94
|
-
|
|
95
|
+
|
|
95
96
|
const docObj = res.getOneObj();
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
|
|
98
|
+
if (!isEntityOK(docObj)) {
|
|
99
|
+
return CommonResult.errorRes("文档不存在");
|
|
99
100
|
}
|
|
100
101
|
|
|
102
|
+
// 更新PV数据
|
|
103
|
+
const pv: number = parseInt(docObj.pv) || 0;
|
|
104
|
+
await this.updateDocPV(docId, docLibId, pv);
|
|
101
105
|
return res;
|
|
102
106
|
}
|
|
103
107
|
|
|
@@ -160,7 +164,7 @@ export class DocGatewayController extends BaseApiController {
|
|
|
160
164
|
);
|
|
161
165
|
const docLibInfo = s.getOneObj();
|
|
162
166
|
|
|
163
|
-
if (!docLibInfo) {
|
|
167
|
+
if (!isEntityOK(docLibInfo)) {
|
|
164
168
|
throw '此文档库查询失败';
|
|
165
169
|
}
|
|
166
170
|
|
|
@@ -4,7 +4,7 @@ import * as _ from 'lodash';
|
|
|
4
4
|
import { BaseApiController } from '../base/BaseApiController';
|
|
5
5
|
import { EnumInfoService } from '@/service/EnumInfoService';
|
|
6
6
|
import { CommonResult } from '@/libs/utils/common-dto';
|
|
7
|
-
import { parseJsonObject } from '@/libs/utils/functions';
|
|
7
|
+
import { isEntityOK, parseJsonObject } from '@/libs/utils/functions';
|
|
8
8
|
import { WorkbenchService } from '@/service/WorkbenchService';
|
|
9
9
|
import { SystemRoleCode } from '@/models/SystemPerm';
|
|
10
10
|
import { KeysOfAuthType } from '@/libs/crud-pro/models/keys';
|
|
@@ -71,10 +71,33 @@ export class PublicApiController extends BaseApiController {
|
|
|
71
71
|
const allMenuList = await this.sysMenuService.getCachedMenusList();
|
|
72
72
|
|
|
73
73
|
const menuList = allMenuList.filter(e => {
|
|
74
|
-
return workbenchMenuCodeSet.has(e.menu_code) && e
|
|
74
|
+
return workbenchMenuCodeSet.has(e.menu_code) && isEntityOK(e);
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
|
|
78
|
+
const addPermissionInfo = (menu_list: any[], level: number) => {
|
|
79
|
+
if (!Array.isArray(menu_list)) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
if (level > 10) {
|
|
83
|
+
return menu_list;
|
|
84
|
+
}
|
|
85
|
+
return menu_list.map(e => {
|
|
86
|
+
if (Array.isArray(e.children)) {
|
|
87
|
+
e.children = addPermissionInfo(e.children, level + 1);
|
|
88
|
+
}
|
|
89
|
+
const view_auth_config = e.view_auth_config;
|
|
90
|
+
const view_auth_type: KeysOfAuthType = e.view_auth_type || KeysOfAuthType.byFuncCode;
|
|
91
|
+
if (!view_auth_config) {
|
|
92
|
+
return { ...e, hasPermission: true };
|
|
93
|
+
}
|
|
94
|
+
const hasPermission = this.ctx.userSession.isAuthPass(view_auth_type, view_auth_config);
|
|
95
|
+
return { ...e, hasPermission };
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
78
101
|
const mapResult: any = {};
|
|
79
102
|
for (let i = 0; i < menuList.length; i++) {
|
|
80
103
|
const rowElement = cloneObject(menuList[i]);
|
|
@@ -86,7 +109,8 @@ export class PublicApiController extends BaseApiController {
|
|
|
86
109
|
|
|
87
110
|
const menu_config_content = rowElement.menu_config_content;
|
|
88
111
|
delete rowElement.menu_config_content;
|
|
89
|
-
|
|
112
|
+
let menu_list = parseJsonObject(menu_config_content) || [];
|
|
113
|
+
menu_list = addPermissionInfo(menu_list, 0);
|
|
90
114
|
mapResult[menu_code] = { ...rowElement, menu_list, hasPermission };
|
|
91
115
|
}
|
|
92
116
|
|
|
@@ -121,10 +145,21 @@ export class PublicApiController extends BaseApiController {
|
|
|
121
145
|
}
|
|
122
146
|
|
|
123
147
|
if (pathname && workbenchCode) {
|
|
124
|
-
|
|
148
|
+
|
|
149
|
+
const pageData = await this.sysAppService.getSysAppPageOne({
|
|
125
150
|
page_path: pathname,
|
|
126
151
|
workbench_code: workbenchCode
|
|
127
152
|
});
|
|
153
|
+
|
|
154
|
+
if (pageData) {
|
|
155
|
+
const clonePageInfo = { ...pageData };
|
|
156
|
+
const view_auth_config = clonePageInfo.view_auth_config;
|
|
157
|
+
const view_auth_type: KeysOfAuthType = clonePageInfo.view_auth_type;
|
|
158
|
+
const hasPermission = this.ctx.userSession.isAuthPass(view_auth_type, view_auth_config);
|
|
159
|
+
clonePageInfo.hasPermission = hasPermission;
|
|
160
|
+
resultData.pageData = clonePageInfo;
|
|
161
|
+
}
|
|
162
|
+
|
|
128
163
|
}
|
|
129
164
|
|
|
130
165
|
return CommonResult.successRes(resultData);
|
|
@@ -6,12 +6,13 @@ import { CommonException, Exceptions } from '@/libs/crud-pro/exceptions';
|
|
|
6
6
|
import { createUniqueId } from '@/libs/utils/functions';
|
|
7
7
|
import { privateAES } from '@/libs/utils/crypto-utils';
|
|
8
8
|
import { CommonResult } from '@/libs/utils/common-dto';
|
|
9
|
-
import {SystemFuncCode, SystemRoleCode} from "@/models/SystemPerm";
|
|
9
|
+
import { SystemFuncCode, SystemRoleCode } from "@/models/SystemPerm";
|
|
10
10
|
import { checkPermission } from '@/middleware/permission.middleware';
|
|
11
11
|
import { refreshCacheWithBroadcast } from '@/service/base/cache-refresh/CacheRefreshRedisSubscriber';
|
|
12
12
|
import { CacheRefreshCategory } from '@/models/CacheRefreshCategory';
|
|
13
13
|
import { CacheNameEnum } from '@/models/bizmodels';
|
|
14
14
|
import { CacheServiceFactory } from '@/service/base/cache/CacheServiceFactory';
|
|
15
|
+
import { ActionLogService } from '@/service/ActionLogService';
|
|
15
16
|
|
|
16
17
|
// http://127.0.0.1:7002/ns/api/helpers/getApiScript?prefix=/ns/api/manage
|
|
17
18
|
// http://127.0.0.1:7002/ns/api/helpers/getApiScript
|
|
@@ -26,6 +27,9 @@ export class HelpersApi {
|
|
|
26
27
|
@Inject()
|
|
27
28
|
private midwayWebRouterService: MidwayWebRouterService;
|
|
28
29
|
|
|
30
|
+
@Inject()
|
|
31
|
+
protected actionLogService: ActionLogService;
|
|
32
|
+
|
|
29
33
|
|
|
30
34
|
@Get('/getApiEnv')
|
|
31
35
|
async getApiEnv() {
|
|
@@ -166,6 +170,15 @@ export class HelpersApi {
|
|
|
166
170
|
const cacheName = cacheNameParam as CacheNameEnum;
|
|
167
171
|
const cacheServiceFactory = await this.ctx.requestContext.getAsync(CacheServiceFactory);
|
|
168
172
|
await cacheServiceFactory.refreshByCacheName(cacheName, this.ctx as any);
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
await this.actionLogService.insertActionLogTable({
|
|
176
|
+
actionModule: '系统工具',
|
|
177
|
+
actionName: '刷新缓存',
|
|
178
|
+
actionMessage: '刷新缓存成功',
|
|
179
|
+
actionTarget: cacheNameParam
|
|
180
|
+
});
|
|
181
|
+
|
|
169
182
|
return CommonResult.successRes({
|
|
170
183
|
message: `业务缓存 ${cacheName} 已刷新`,
|
|
171
184
|
cacheName,
|
|
@@ -174,6 +187,15 @@ export class HelpersApi {
|
|
|
174
187
|
|
|
175
188
|
const category = categoryParam ? categoryParam as CacheRefreshCategory : undefined;
|
|
176
189
|
await refreshCacheWithBroadcast(this.ctx, category);
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
await this.actionLogService.insertActionLogTable({
|
|
193
|
+
actionModule: '系统工具',
|
|
194
|
+
actionName: '刷新缓存',
|
|
195
|
+
actionMessage: '刷新缓存成功',
|
|
196
|
+
actionTarget: cacheNameParam
|
|
197
|
+
});
|
|
198
|
+
|
|
177
199
|
return CommonResult.successRes({
|
|
178
200
|
message: `缓存已刷新${category ? '(' + category + ')' : '(全部)'}(已广播集群)`,
|
|
179
201
|
category: category || 'ALL',
|
|
@@ -183,7 +205,7 @@ export class HelpersApi {
|
|
|
183
205
|
private checkLocalPermissionEnv() {
|
|
184
206
|
|
|
185
207
|
//是否是开发者
|
|
186
|
-
|
|
208
|
+
const isDevelopUser = (): boolean => {
|
|
187
209
|
const isDevOpsWriter = this.ctx.userSession?.hasRole(SystemRoleCode.DevOpsWriter);
|
|
188
210
|
const isSuperAdmin = this.ctx.userSession?.hasRole(SystemRoleCode.SuperAdmin);
|
|
189
211
|
const isHelpersTools = this.ctx.userSession?.hasPermission(SystemFuncCode.HelpersTools);
|
|
@@ -6,6 +6,7 @@ import { createRenderUtils } from '@/libs/utils/render-utils';
|
|
|
6
6
|
import { privateAES } from '@/libs/utils/crypto-utils';
|
|
7
7
|
import { AuthService } from '@/service/AuthService';
|
|
8
8
|
import { ISessionInfo } from '@/models/userSession';
|
|
9
|
+
import { isEntityOK } from '@/libs/utils/functions';
|
|
9
10
|
|
|
10
11
|
@Controller('/')
|
|
11
12
|
export class HomeController extends BaseApiController {
|
|
@@ -25,7 +26,7 @@ export class HomeController extends BaseApiController {
|
|
|
25
26
|
|
|
26
27
|
const workbenchInfo = await this.workbenchService.getCurrentHostWorkbenchInfo();
|
|
27
28
|
|
|
28
|
-
if (!workbenchInfo
|
|
29
|
+
if (!isEntityOK(workbenchInfo)) {
|
|
29
30
|
this.logInfo(`域名不存在:hostname = ${hostname}, host=${host}`);
|
|
30
31
|
const infos = {
|
|
31
32
|
host,
|
|
@@ -35,6 +36,7 @@ export class HomeController extends BaseApiController {
|
|
|
35
36
|
return this.ctx.render('404_workbench', infos);
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
|
|
38
40
|
const html_content = workbenchInfo.html_content || '未配置HTML模版';
|
|
39
41
|
|
|
40
42
|
const userInfo = await this.getUserAndRefreshSessionInfo();
|