midway-fatcms 0.0.17 → 0.0.18

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 (47) hide show
  1. package/dist/libs/crud-pro/services/CrudProDataTypeConvertService.d.ts +2 -37
  2. package/dist/libs/crud-pro/services/CrudProDataTypeConvertService.js +137 -213
  3. package/dist/libs/crud-pro/utils/MixinUtils.d.ts +2 -17
  4. package/dist/libs/crud-pro/utils/MixinUtils.js +4 -84
  5. package/dist/libs/crud-pro/utils/idgene/generateSnowflakeId.d.ts +12 -0
  6. package/dist/libs/crud-pro/utils/idgene/generateSnowflakeId.js +61 -0
  7. package/dist/libs/crud-pro/utils/idgene/generateSnowflakeIdExt.d.ts +19 -0
  8. package/dist/libs/crud-pro/utils/idgene/generateSnowflakeIdExt.js +89 -0
  9. package/dist/libs/crud-pro/utils/idgene/index.d.ts +3 -0
  10. package/dist/libs/crud-pro/utils/idgene/index.js +10 -0
  11. package/dist/libs/crud-pro/utils/idgene/uuid.d.ts +7 -0
  12. package/dist/libs/crud-pro/utils/idgene/uuid.js +28 -0
  13. package/dist/libs/crud-pro-quick/fixSoftDelete.d.ts +0 -17
  14. package/dist/libs/crud-pro-quick/fixSoftDelete.js +55 -5
  15. package/dist/libs/crud-pro-quick/models.d.ts +11 -1
  16. package/dist/service/SysAppService.d.ts +0 -3
  17. package/dist/service/SysAppService.js +0 -15
  18. package/dist/service/SysConfigService.d.ts +0 -1
  19. package/dist/service/SysConfigService.js +0 -6
  20. package/dist/service/SysDictDataService.d.ts +0 -2
  21. package/dist/service/SysDictDataService.js +0 -12
  22. package/dist/service/SysMenuService.d.ts +0 -1
  23. package/dist/service/SysMenuService.js +0 -3
  24. package/dist/service/WorkbenchService.d.ts +0 -1
  25. package/dist/service/WorkbenchService.js +0 -3
  26. package/dist/service/base/bizmemcache/BizMemCacheService.js +4 -2
  27. package/dist/service/base/bizmemcache/BizMemCacheStore.js +10 -9
  28. package/dist/service/crudstd/CrudStdService.js +1 -1
  29. package/dist/service/curd/fixCfgModel.js +21 -1
  30. package/package.json +1 -1
  31. package/src/libs/crud-pro/services/CrudProDataTypeConvertService.ts +149 -219
  32. package/src/libs/crud-pro/utils/MixinUtils.ts +309 -400
  33. package/src/libs/crud-pro/utils/idgene/generateSnowflakeId.ts +65 -0
  34. package/src/libs/crud-pro/utils/idgene/generateSnowflakeIdExt.ts +99 -0
  35. package/src/libs/crud-pro/utils/idgene/index.ts +3 -0
  36. package/src/libs/crud-pro/utils/idgene/uuid.ts +26 -0
  37. package/src/libs/crud-pro-quick/fixSoftDelete.ts +84 -18
  38. package/src/libs/crud-pro-quick/models.ts +15 -3
  39. package/src/service/SysAppService.ts +0 -18
  40. package/src/service/SysConfigService.ts +0 -8
  41. package/src/service/SysDictDataService.ts +0 -14
  42. package/src/service/SysMenuService.ts +0 -4
  43. package/src/service/WorkbenchService.ts +0 -5
  44. package/src/service/base/bizmemcache/BizMemCacheService.ts +4 -2
  45. package/src/service/base/bizmemcache/BizMemCacheStore.ts +10 -9
  46. package/src/service/crudstd/CrudStdService.ts +3 -2
  47. package/src/service/curd/fixCfgModel.ts +145 -125
@@ -1,125 +1,145 @@
1
- import * as _ from 'lodash';
2
- import { CTX_VISITOR_ACCOUNT_TYPE, CTX_VISITOR_AVATAR, CTX_VISITOR_ID, CTX_VISITOR_NICKNAME, IRequestCfgModel2 } from '@/models/bizmodels';
3
- import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
4
-
5
- function isSimpleQuery(sqlSimpleName: KeysOfSimpleSQL): boolean {
6
- return sqlSimpleName === KeysOfSimpleSQL.SIMPLE_QUERY || sqlSimpleName === KeysOfSimpleSQL.SIMPLE_QUERY_COUNT || sqlSimpleName === KeysOfSimpleSQL.SIMPLE_QUERY_PAGE || sqlSimpleName === KeysOfSimpleSQL.SIMPLE_QUERY_ONE;
7
- }
8
-
9
- function fixCfgModel(cfgModel: IRequestCfgModel2) {
10
- if (!cfgModel.method) {
11
- cfgModel.method = 'anonymous';
12
- }
13
-
14
- if (!cfgModel.updateCfg) {
15
- cfgModel.updateCfg = {};
16
- }
17
-
18
- const sqlSimpleName = cfgModel.sqlSimpleName;
19
-
20
- const enableStandardUpdateCfg = cfgModel.enableStandardUpdateCfg; // 用于设置data字段
21
- const enableStandardUpdateCfgCondition = cfgModel.enableStandardUpdateCfgCondition; // 用于设置condition字段
22
-
23
- // 彻底关闭
24
- if (enableStandardUpdateCfg === false) {
25
- return;
26
- }
27
-
28
- const getDataCfgArray = () => {
29
- // 明确有配置
30
- if (Array.isArray(enableStandardUpdateCfg)) {
31
- if (enableStandardUpdateCfg.includes('null')) {
32
- return [];
33
- }
34
- return enableStandardUpdateCfg;
35
- }
36
- // update 、insert 添加 by
37
- return ['by', 'at']; // 创建/修改语句默认添加by
38
- };
39
-
40
- const getConditionCfgArray = () => {
41
- // 明确有配置
42
- if (Array.isArray(enableStandardUpdateCfgCondition)) {
43
- if (enableStandardUpdateCfgCondition.includes('null')) {
44
- return [];
45
- }
46
- return enableStandardUpdateCfgCondition;
47
- }
48
- return [];
49
- };
50
-
51
- const dataCfgArray = getDataCfgArray();
52
- const conditionCfgArray = getConditionCfgArray();
53
-
54
- const mapping: Record<string, any> = {
55
- 'condition.created_by': { contextAsString: CTX_VISITOR_ID },
56
- 'condition.created_account_type': { contextAsString: CTX_VISITOR_ACCOUNT_TYPE },
57
-
58
- 'data.created_at': { functionName: 'getCurrentTimeString' },
59
- 'data.created_by': { contextAsString: CTX_VISITOR_ID },
60
- 'data.created_avatar': { contextAsString: CTX_VISITOR_AVATAR },
61
- 'data.created_nickname': { contextAsString: CTX_VISITOR_NICKNAME },
62
- 'data.created_account_type': { contextAsString: CTX_VISITOR_ACCOUNT_TYPE },
63
-
64
- 'data.modified_at': { functionName: 'getCurrentTimeString' },
65
- 'data.modified_by': { contextAsString: CTX_VISITOR_ID },
66
- 'data.modified_avatar': { contextAsString: CTX_VISITOR_AVATAR },
67
- 'data.modified_nickname': { contextAsString: CTX_VISITOR_NICKNAME },
68
- 'data.modified_account_type': { contextAsString: CTX_VISITOR_ACCOUNT_TYPE },
69
- };
70
-
71
- const buildUpdateCfgBy = (cfgArray: string[], prefix: string): any => {
72
- const obj: any = {};
73
- if (Array.isArray(cfgArray)) {
74
- for (let i = 0; i < cfgArray.length; i++) {
75
- const suffix = cfgArray[i];
76
- if (suffix) {
77
- const key = `${prefix}_${suffix}`;
78
- obj[key] = mapping[key];
79
- }
80
- }
81
- }
82
- return obj;
83
- };
84
-
85
- // 查询语句
86
- if (isSimpleQuery(sqlSimpleName)) {
87
- const updateCfgObj = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 查询用户本人创建的
88
- _.merge(cfgModel.updateCfg, updateCfgObj);
89
- }
90
-
91
- // 删除语句
92
- if (sqlSimpleName === KeysOfSimpleSQL.SIMPLE_DELETE) {
93
- const updateCfgObj = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 删除用户本人创建的
94
- _.merge(cfgModel.updateCfg, updateCfgObj);
95
- }
96
-
97
- // 插入语句
98
- if (sqlSimpleName === KeysOfSimpleSQL.SIMPLE_INSERT) {
99
- const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray, 'data.created');
100
- _.merge(cfgModel.updateCfg, updateCfgObj1);
101
- }
102
-
103
- // 更新语句
104
- if (sqlSimpleName === KeysOfSimpleSQL.SIMPLE_UPDATE) {
105
- const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray, 'data.modified');
106
- const updateCfgObj2 = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 更新用户本人创建的
107
- _.merge(cfgModel.updateCfg, updateCfgObj1);
108
- _.merge(cfgModel.updateCfg, updateCfgObj2);
109
- }
110
-
111
- // 插入或更新
112
- if (sqlSimpleName === KeysOfSimpleSQL.SIMPLE_INSERT_OR_UPDATE || sqlSimpleName === KeysOfSimpleSQL.SIMPLE_INSERT_ON_DUPLICATE_UPDATE) {
113
- const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray, 'data.created');
114
- const updateCfgObj2 = buildUpdateCfgBy(dataCfgArray, 'data.modified');
115
- const updateCfgObj3 = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 更新用户本人创建的
116
- _.merge(cfgModel.updateCfg, updateCfgObj1);
117
- _.merge(cfgModel.updateCfg, updateCfgObj2);
118
- _.merge(cfgModel.updateCfg, updateCfgObj3);
119
- }
120
- }
121
-
122
-
123
-
124
-
125
- export { fixCfgModel };
1
+ import * as _ from 'lodash';
2
+ import { CTX_VISITOR_ACCOUNT_TYPE, CTX_VISITOR_AVATAR, CTX_VISITOR_ID, CTX_VISITOR_NICKNAME, IRequestCfgModel2 } from '@/models/bizmodels';
3
+ import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
4
+
5
+ function isSimpleQuery(sqlSimpleName: KeysOfSimpleSQL): boolean {
6
+ return sqlSimpleName === KeysOfSimpleSQL.SIMPLE_QUERY || sqlSimpleName === KeysOfSimpleSQL.SIMPLE_QUERY_COUNT || sqlSimpleName === KeysOfSimpleSQL.SIMPLE_QUERY_PAGE || sqlSimpleName === KeysOfSimpleSQL.SIMPLE_QUERY_ONE;
7
+ }
8
+
9
+ function fixCfgModel(cfgModel: IRequestCfgModel2) {
10
+ if (!cfgModel.method) {
11
+ cfgModel.method = 'anonymous';
12
+ }
13
+
14
+ if (!cfgModel.updateCfg) {
15
+ cfgModel.updateCfg = {};
16
+ }
17
+
18
+ const sqlSimpleName = cfgModel.sqlSimpleName;
19
+
20
+ const enableStandardUpdateCfg = cfgModel.enableStandardUpdateCfg; // 用于设置data字段
21
+ const enableStandardUpdateCfgCondition = cfgModel.enableStandardUpdateCfgCondition; // 用于设置condition字段
22
+
23
+ // 彻底关闭
24
+ if (enableStandardUpdateCfg === false) {
25
+ return;
26
+ }
27
+
28
+ const getDataCfgArray = () => {
29
+ // 明确有配置
30
+ if (Array.isArray(enableStandardUpdateCfg)) {
31
+ if (enableStandardUpdateCfg.includes('null')) {
32
+ return [];
33
+ }
34
+ return enableStandardUpdateCfg;
35
+ }
36
+ // update 、insert 添加 by
37
+ return ['by', 'at']; // 创建/修改语句默认添加by
38
+ };
39
+
40
+ const getConditionCfgArray = () => {
41
+ // 明确有配置
42
+ if (Array.isArray(enableStandardUpdateCfgCondition)) {
43
+ if (enableStandardUpdateCfgCondition.includes('null')) {
44
+ return [];
45
+ }
46
+ return enableStandardUpdateCfgCondition;
47
+ }
48
+ return [];
49
+ };
50
+
51
+ const dataCfgArray = getDataCfgArray();
52
+ const conditionCfgArray = getConditionCfgArray();
53
+
54
+ const mapping: Record<string, any> = {
55
+ 'condition.created_by': { contextAsString: CTX_VISITOR_ID },
56
+ 'condition.created_account_type': { contextAsString: CTX_VISITOR_ACCOUNT_TYPE },
57
+
58
+ 'data.created_at': { functionName: 'getCurrentTimeString' },
59
+ 'data.created_by': { contextAsString: CTX_VISITOR_ID },
60
+ 'data.created_avatar': { contextAsString: CTX_VISITOR_AVATAR },
61
+ 'data.created_nickname': { contextAsString: CTX_VISITOR_NICKNAME },
62
+ 'data.created_account_type': { contextAsString: CTX_VISITOR_ACCOUNT_TYPE },
63
+
64
+ 'data.modified_at': { functionName: 'getCurrentTimeString' },
65
+ 'data.modified_by': { contextAsString: CTX_VISITOR_ID },
66
+ 'data.modified_avatar': { contextAsString: CTX_VISITOR_AVATAR },
67
+ 'data.modified_nickname': { contextAsString: CTX_VISITOR_NICKNAME },
68
+ 'data.modified_account_type': { contextAsString: CTX_VISITOR_ACCOUNT_TYPE },
69
+ };
70
+
71
+ const buildUpdateCfgBy = (cfgArray: string[], prefix: string): any => {
72
+ const obj: any = {};
73
+ if (Array.isArray(cfgArray)) {
74
+ for (let i = 0; i < cfgArray.length; i++) {
75
+ const suffix = cfgArray[i];
76
+ if (suffix) {
77
+ const key = `${prefix}_${suffix}`;
78
+ if (mapping[key]) {
79
+ obj[key] = mapping[key];
80
+ }
81
+ }
82
+ }
83
+ }
84
+ return obj;
85
+ };
86
+
87
+ // 查询语句
88
+ if (isSimpleQuery(sqlSimpleName)) {
89
+ const updateCfgObj = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 查询用户本人创建的
90
+ _.merge(cfgModel.updateCfg, updateCfgObj);
91
+ }
92
+
93
+ // 删除语句
94
+ if (sqlSimpleName === KeysOfSimpleSQL.SIMPLE_DELETE) {
95
+ const updateCfgObj = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 删除用户本人创建的
96
+ _.merge(cfgModel.updateCfg, updateCfgObj);
97
+ }
98
+
99
+ // 插入语句
100
+ if (sqlSimpleName === KeysOfSimpleSQL.SIMPLE_INSERT) {
101
+ const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray, 'data.created');
102
+ _.merge(cfgModel.updateCfg, updateCfgObj1);
103
+
104
+ // 启用: 雪花ID
105
+ if (dataCfgArray.includes('idBySnowflakeId')) {
106
+ _.merge(cfgModel.updateCfg, {
107
+ 'data.id': { functionName: 'generateSnowflakeId' },
108
+ });
109
+ }
110
+
111
+ // 启用: 扩展的雪花ID: -128bit,base58(建议数据库varchar(24))
112
+ if (dataCfgArray.includes('idBySnowflakeIdExt')) {
113
+ _.merge(cfgModel.updateCfg, {
114
+ 'data.id': { functionName: 'generateSnowflakeIdExt' },
115
+ });
116
+ }
117
+
118
+ // 启用: UUID
119
+ if (dataCfgArray.includes('idByUUID')) {
120
+ _.merge(cfgModel.updateCfg, {
121
+ 'data.id': { functionName: 'uuid' },
122
+ });
123
+ }
124
+ }
125
+
126
+ // 更新语句
127
+ if (sqlSimpleName === KeysOfSimpleSQL.SIMPLE_UPDATE) {
128
+ const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray, 'data.modified');
129
+ const updateCfgObj2 = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 更新用户本人创建的
130
+ _.merge(cfgModel.updateCfg, updateCfgObj1);
131
+ _.merge(cfgModel.updateCfg, updateCfgObj2);
132
+ }
133
+
134
+ // 插入或更新
135
+ if (sqlSimpleName === KeysOfSimpleSQL.SIMPLE_INSERT_OR_UPDATE || sqlSimpleName === KeysOfSimpleSQL.SIMPLE_INSERT_ON_DUPLICATE_UPDATE) {
136
+ const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray, 'data.created');
137
+ const updateCfgObj2 = buildUpdateCfgBy(dataCfgArray, 'data.modified');
138
+ const updateCfgObj3 = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 更新用户本人创建的
139
+ _.merge(cfgModel.updateCfg, updateCfgObj1);
140
+ _.merge(cfgModel.updateCfg, updateCfgObj2);
141
+ _.merge(cfgModel.updateCfg, updateCfgObj3);
142
+ }
143
+ }
144
+
145
+ export { fixCfgModel };