midway-fatcms 0.0.6 → 0.0.7
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/.qoder/skills/midway-fatcms-crud/SKILL.md +375 -0
- package/.qoder/skills/midway-fatcms-crud/examples.md +990 -0
- package/.qoder/skills/midway-fatcms-crud/reference.md +568 -0
- package/dist/libs/crud-pro/models/RequestModel.d.ts +0 -36
- package/dist/libs/crud-pro/models/RequestModel.js +2 -99
- package/dist/libs/crud-pro/utils/OrderByUtils.d.ts +70 -0
- package/dist/libs/crud-pro/utils/OrderByUtils.js +158 -0
- package/dist/libs/crud-sharding/ShardingCrudPro.js +15 -39
- package/dist/libs/crud-sharding/ShardingMerger.d.ts +2 -2
- package/dist/libs/crud-sharding/ShardingMerger.js +11 -9
- package/dist/service/curd/README.md +101 -2
- package/package.json +2 -1
- package/src/libs/crud-pro/models/RequestModel.ts +2 -108
- package/src/libs/crud-pro/utils/OrderByUtils.ts +169 -0
- package/src/libs/crud-sharding/ShardingCrudPro.ts +55 -76
- package/src/libs/crud-sharding/ShardingMerger.ts +14 -12
- package/src/service/curd/README.md +101 -2
|
@@ -824,7 +824,30 @@ await sharding.insert({
|
|
|
824
824
|
|
|
825
825
|
### linkColumnRelationDatas
|
|
826
826
|
|
|
827
|
-
独立于 CRUD
|
|
827
|
+
独立于 CRUD 操作,直接对已有数据行执行关联填充。适用于数据来自缓存、外部接口或其他非 CurdMixService 渠道,但仍需要字典翻译、用户信息等关联数据的场景。
|
|
828
|
+
|
|
829
|
+
> ⚠️ 该方法会**原地修改** `rows` 数组中的对象,不会返回新数组。
|
|
830
|
+
|
|
831
|
+
#### 方法签名
|
|
832
|
+
|
|
833
|
+
```typescript
|
|
834
|
+
linkColumnRelationDatas(rows: any[], param: ILinkColumnRelationParam): Promise<void>
|
|
835
|
+
```
|
|
836
|
+
|
|
837
|
+
#### 参数接口
|
|
838
|
+
|
|
839
|
+
```typescript
|
|
840
|
+
interface ILinkColumnRelationParam {
|
|
841
|
+
columnsRelations: ColumnRelation[]; // 关联配置数组
|
|
842
|
+
}
|
|
843
|
+
```
|
|
844
|
+
|
|
845
|
+
| 参数 | 类型 | 说明 |
|
|
846
|
+
|------|------|------|
|
|
847
|
+
| `rows` | `any[]` | 待填充的数据行数组;为空或非数组时直接返回 |
|
|
848
|
+
| `param.columnsRelations` | `ColumnRelation[]` | 关联规则配置,与 CRUD 配置中的 `columnsRelation` 格式一致 |
|
|
849
|
+
|
|
850
|
+
#### 基础用法
|
|
828
851
|
|
|
829
852
|
```typescript
|
|
830
853
|
// 场景:从缓存或其他来源获取了数据行,仍需要关联填充
|
|
@@ -840,9 +863,85 @@ await curdMixService.linkColumnRelationDatas(rows, {
|
|
|
840
863
|
},
|
|
841
864
|
],
|
|
842
865
|
});
|
|
843
|
-
// rows
|
|
866
|
+
// rows 中的每行会原地追加 sex_text 字段
|
|
844
867
|
```
|
|
845
868
|
|
|
869
|
+
#### 多关联类型组合
|
|
870
|
+
|
|
871
|
+
```typescript
|
|
872
|
+
const rows = await redisCache.get('order_list');
|
|
873
|
+
|
|
874
|
+
await curdMixService.linkColumnRelationDatas(rows, {
|
|
875
|
+
columnsRelations: [
|
|
876
|
+
// 字典翻译
|
|
877
|
+
{
|
|
878
|
+
relatedType: 'dict',
|
|
879
|
+
relatedCode: 'OrderStatus',
|
|
880
|
+
sourceColumn: 'status',
|
|
881
|
+
targetColumns: [
|
|
882
|
+
{ from: 'label', to: 'status_text' },
|
|
883
|
+
{ from: 'color', to: 'status_color' },
|
|
884
|
+
],
|
|
885
|
+
},
|
|
886
|
+
// 系统配置枚举
|
|
887
|
+
{
|
|
888
|
+
relatedType: 'sysCfgEnum',
|
|
889
|
+
relatedCode: 'PayMethod',
|
|
890
|
+
sourceColumn: 'pay_method',
|
|
891
|
+
targetColumns: [
|
|
892
|
+
{ from: 'label', to: 'pay_method_info.label' },
|
|
893
|
+
{ from: 'style', to: 'pay_method_info.style' },
|
|
894
|
+
],
|
|
895
|
+
},
|
|
896
|
+
// 用户信息填充
|
|
897
|
+
{
|
|
898
|
+
relatedType: 'accountBasic',
|
|
899
|
+
sourceColumn: 'created_by',
|
|
900
|
+
targetColumns: [], // 空 = 使用默认映射
|
|
901
|
+
},
|
|
902
|
+
// 工作台信息
|
|
903
|
+
{
|
|
904
|
+
relatedType: 'workbenchBasic',
|
|
905
|
+
sourceColumn: 'workbench_code',
|
|
906
|
+
targetColumns: [
|
|
907
|
+
{ from: 'workbench_domain', to: 'workbench_info.workbench_domain' },
|
|
908
|
+
{ from: 'workbench_name', to: 'workbench_info.workbench_name' },
|
|
909
|
+
],
|
|
910
|
+
},
|
|
911
|
+
],
|
|
912
|
+
});
|
|
913
|
+
```
|
|
914
|
+
|
|
915
|
+
#### 与 CrudProQuick 配合使用
|
|
916
|
+
|
|
917
|
+
```typescript
|
|
918
|
+
const quick = curdProService.getQuickCrud('mydb', SqlDbType.mysql, 't_order');
|
|
919
|
+
|
|
920
|
+
// 先用 CrudProQuick 获取原始数据(不带关联)
|
|
921
|
+
const rows = await quick.getList({
|
|
922
|
+
condition: { status: 'paid' },
|
|
923
|
+
});
|
|
924
|
+
|
|
925
|
+
// 再用 linkColumnRelationDatas 补充关联数据
|
|
926
|
+
await curdMixService.linkColumnRelationDatas(rows, {
|
|
927
|
+
columnsRelations: [
|
|
928
|
+
{
|
|
929
|
+
relatedType: 'dict',
|
|
930
|
+
relatedCode: 'OrderStatus',
|
|
931
|
+
sourceColumn: 'status',
|
|
932
|
+
targetColumns: [{ from: 'label', to: 'status_text' }],
|
|
933
|
+
},
|
|
934
|
+
{
|
|
935
|
+
relatedType: 'accountBasic',
|
|
936
|
+
sourceColumn: 'created_by',
|
|
937
|
+
targetColumns: [],
|
|
938
|
+
},
|
|
939
|
+
],
|
|
940
|
+
});
|
|
941
|
+
```
|
|
942
|
+
|
|
943
|
+
> **提示**:如果 CRUD 操作本身就需要关联填充,建议直接使用 `CurdMixService.executeCrudByCfg()` 配置 `columnsRelation`,一步完成查询和填充。`linkColumnRelationDatas` 适用于数据已存在的二次填充场景。
|
|
944
|
+
|
|
846
945
|
## ColumnRelation 配置
|
|
847
946
|
|
|
848
947
|
```typescript
|