request.txt 44.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326

1、根据下面模型文件,完整代码实现案例(含前端React端到端测试页Demo),特别是M4的flowSteps,M2的bizSteps,MetaRule,架构引擎负责解释与执行,各层釆用什么具体技术,M 8前端模板定义及如何与具体业务绑定,并用案例方式推演解释整体架构的运行原理

2、以上方案实现使用 Claude Code 全流程开发,包含工程目录结构、Claude专用配置、全套建模YAML、后端Java引擎源码、React前端Demo、场景推演文档、代码生成模板、部署脚本、测试用例等等。

模型文件如下:
本体驱动 DDD+EDA 全量11份YAML架构文档 v2.0
架构总述
版本:v2.0 | 状态:生产级完备,支持代码生成
架构分层全集:M0-meta-schema、M1-domain、M2-command、ME-event、M3-deploy、M4-scene、M5-security、M6-monitor、M7-sla、MetaRule-business、M8-front-schema
核心扩展:新增M8-front-schema React可视化拖拽建模层,M0补充前端模板完整JSON Schema校验;全量兼容原有DDD+EDA本体模型,无破坏性变更、仅增量扩展;实现业务专家无代码拖拽生成React页面,页面数据源强制绑定M1领域模型,页面自动关联M4场景、M2命令API、M5脱敏权限、MetaRule动态规则,实现后期仅维护模板、不修改前端业务源码。

一、M0-meta-schema.yaml(全域元数据校验根规范,新增M8前端Schema定义)
meta_model:
  version: "2.0"
  $schema: https://json-schema.org/draft/2020-12/schema
  definitions:
    # 基础通用标识类型
    Identifier:
      type: string
      pattern: "^[a-z][a-zA-Z0-9]*$"
      description: 小写驼峰字段/组件标识
    UpperIdentifier:
      type: string
      pattern: "^[A-Z][a-zA-Z0-9]*$"
      description: 大写驼峰聚合/命令/事件ID
    NonEmptyString:
      type: string
      minLength: 1
    SceneId:
      type: string
      pattern: "^SCENE_[A-Z0-9_]+$"
    RuleId:
      type: string
      pattern: "^R_[A-Z0-9_]+$"
    TopicName:
      type: string
      pattern: "^topic_[a-z0-9_]+$"
    ConsistencyTypeEnum:
      type: string
      enum: [strong, eventual]
    DbEngineEnum:
      type: string
      enum: [mysql8]
    AuthModeEnum:
      type: string
      enum: [oauth2_jwt]

    # ========== M8前端专用枚举(新增) ==========
    FrontTemplateTypeEnum:
      type: string
      enum: [single_table_form, master_detail_form, custom_drag_form]
      description: single_table_form单实体表单;master_detail_form主从表单;custom_drag_form自定义空白拖拽模板
    FrontComponentEnum:
      type: string
      enum: [input, number_input, date_picker, switch, table, card, text_area, select]
      description: React底层原子拖拽组件
    BindSourceTypeEnum:
      type: string
      enum: [aggregate_root, aggregate_entity]
      description: 组件绑定数据源类型:聚合根/聚合内部子实体
    ReactRenderModeEnum:
      type: string
      enum: [form_modal, page_container, drawer]
      description: 页面渲染载体:弹窗/整页/侧边抽屉

    # M1 领域模型单元定义
    M1_Attribute:
      type: object
      required: [name, type]
      properties:
        name: { $ref: "#/definitions/Identifier" }
        type:
          type: string
          enum: [string, int, decimal, datetime, boolean]
        refAggregate: { type: string }
        refRoot: { type: string }
        refIdentifier: { type: string }
        description: { type: string }
    M1_Relation:
      type: object
      required: [ref, relationType]
      properties:
        ref: { $ref: "#/definitions/NonEmptyString" }
        relationType:
          type: string
          enum: [composition]
    M1_Entity:
      type: object
      required: [name, localIdentifier, attributes]
      properties:
        name: { $ref: "#/definitions/NonEmptyString" }
        localIdentifier: { $ref: "#/definitions/Identifier" }
        attributes:
          type: array
          items: { $ref: "#/definitions/M1_Attribute" }
    M1_AggregateRoot:
      type: object
      required: [name, identifier, attributes]
      properties:
        name: { $ref: "#/definitions/NonEmptyString" }
        identifier: { $ref: "#/definitions/Identifier" }
        attributes:
          type: array
          items: { $ref: "#/definitions/M1_Attribute" }
        relations:
          type: array
          items: { $ref: "#/definitions/M1_Relation" }
    M1_Aggregate:
      type: object
      required: [aggregateId, description, aggregateRoot]
      properties:
        aggregateId:
          type: string
          pattern: "^[A-Z][a-zA-Z]+Aggregate$"
        description: { $ref: "#/definitions/NonEmptyString" }
        aggregateRoot: { $ref: "#/definitions/M1_AggregateRoot" }
        entities:
          type: array
          items: { $ref: "#/definitions/M1_Entity" }
        valueObjects:
          type: array
          maxItems: 0

    # M2 命令行为单元定义
    M2_InputParam:
      type: object
      required: [name, type]
      properties:
        name: { $ref: "#/definitions/Identifier" }
        type: { type: string }
        optional: { type: boolean }
    M2_Command:
      type: object
      required: [cmdId, desc, inputParams, validations, emitEvents]
      properties:
        cmdId: { $ref: "#/definitions/UpperIdentifier" }
        desc: { $ref: "#/definitions/NonEmptyString" }
        inputParams:
          type: array
          items: { $ref: "#/definitions/M2_InputParam" }
        validations:
          type: array
          items: { type: string }
        bizSteps: { type: string }
        emitEvents:
          type: array
          items: { $ref: "#/definitions/UpperIdentifier" }
        sideEffect: { type: string }
    M2_AggregateBehavior:
      type: object
      required: [aggregateId, aggregateRoot, commands]
      properties:
        aggregateId:
          type: string
          pattern: "^[A-Z][a-zA-Z]+Aggregate$"
        aggregateRoot: { $ref: "#/definitions/NonEmptyString" }
        commands:
          type: array
          items: { $ref: "#/definitions/M2_Command" }

    # ME 事件模型单元定义
    ME_Event:
      type: object
      required: [topic, payload]
      properties:
        topic: { $ref: "#/definitions/TopicName" }
        payload:
          type: array
          items: { $ref: "#/definitions/Identifier" }
        consumers:
          type: array
          items: { type: string }
    ME_OutboxConfig:
      type: object
      required: [enabled, table]
      properties:
        enabled: { type: boolean }
        table: { $ref: "#/definitions/NonEmptyString" }
        pollInterval: { type: string }
        batchSize: { type: integer, minimum:1 }
        cleanupDays: { type: integer, minimum:1 }
    ME_CrossConsistencyRule:
      type: object
      required: [triggerEvent, targetAggregate, targetCommand, consistencyType]
      properties:
        triggerEvent: { $ref: "#/definitions/UpperIdentifier" }
        targetAggregate:
          type: string
          pattern: "^[A-Z][a-zA-Z]+Aggregate$"
        targetCommand: { $ref: "#/definitions/UpperIdentifier" }
        consistencyType: { $ref: "#/definitions/ConsistencyTypeEnum" }

    # M3 存储部署映射单元定义
    M3_TableMapping:
      type: object
      required: [domainEntity, table, pk, fieldMap]
      properties:
        domainEntity: { $ref: "#/definitions/NonEmptyString" }
        table: { $ref: "#/definitions/NonEmptyString" }
        pk: { $ref: "#/definitions/Identifier" }
        shardRule: { type: string }
        fieldMap:
          type: object
          additionalProperties: { type: string }
    M3_AggregateDeploy:
      type: object
      required: [aggregateId, serviceName, commandApi, tableMappings]
      properties:
        aggregateId:
          type: string
          pattern: "^[A-Z][a-zA-Z]+Aggregate$"
        serviceName:
          type: string
          pattern: "^[a-z-]+-service$"
        commandApi:
          type: object
          additionalProperties:
            type: string
            pattern: "^/api/v1/.+"
        tableMappings:
          type: array
          items: { $ref: "#/definitions/M3_TableMapping" }

    # M4 业务场景编排单元定义
    M4_SceneStep:
      type: object
      required: [stepType]
      properties:
        stepType:
          type: string
          enum: [bindCommand, readOnlyCheck, loopItems, return]
        bindAggregate: { type: string }
        bindCommand: { $ref: "#/definitions/UpperIdentifier" }
    M4_Scene:
      type: object
      required: [sceneId, sceneName, aggregateScope, permissionBind, flowSteps]
      properties:
        sceneId: { $ref: "#/definitions/SceneId" }
        sceneName: { $ref: "#/definitions/NonEmptyString" }
        aggregateScope:
          type: array
          items:
            type: string
            pattern: "^[A-Z][a-zA-Z]+Aggregate$"
        permissionBind:
          type: array
          items: { $ref: "#/definitions/Identifier" }
        flowSteps:
          type: array
          items: { $ref: "#/definitions/M4_SceneStep" }

    # M5 安全权限单元定义
    M5_SecurityRoot:
      type: object
      required: [globalConfig, principals, functionPermissions, maskRules, encryptRules]
    # M6 监控告警单元定义
    M6_Alert:
      type: object
      required: [desc, level, trigger]
      properties:
        desc: { type: string }
        level:
          type: string
          enum: [严重告警, 警告告警]
        trigger: { type: string }
    M6_MonitorRoot:
      type: object
      required: [globalConfig, serviceMetricBind, alertRules]
    # M7 流量SLA单元定义
    M7_QualityRoot:
      type: object
      required: [aggregateSla, commandSla, sceneSla, flowControl]
    # MetaRule 动态业务规则单元定义
    MetaRule_Param:
      type: object
      required: [paramId, name, dataType, defaultValue]
    MetaRule_Item:
      type: object
      required: [ruleId, ruleVersion, ruleName, matchCondition, effect, message]
      properties:
        ruleId: { $ref: "#/definitions/RuleId" }
        effect:
          type: string
          enum: [REJECT, ALERT, SKIP_CHECK, CALC_FILL, COMPENSATE]
    MetaRule_Group:
      type: object
      required: [groupId, groupType, bindScene, rules]

    # ===================== M8 前端拖拽模板完整定义(新增核心) =====================
    M8_FrontFieldBind:
      type: object
      required: [bindAggregateId, bindSourceType, domainFieldName]
      properties:
        bindAggregateId:
          type: string
          pattern: "^[A-Z][a-zA-Z]+Aggregate$"
        bindSourceType: { $ref: "#/definitions/BindSourceTypeEnum" }
        domainEntityName: { type: string }
        domainFieldName: { $ref: "#/definitions/Identifier" }
        formLabel: { type: string }
        placeholder: { type: string }
        required: { type: boolean }
        maskField: { type: boolean }
    M8_FrontDragComponent:
      type: object
      required: [compId, compType, fieldBind]
      properties:
        compId: { $ref: "#/definitions/Identifier" }
        compType: { $ref: "#/definitions/FrontComponentEnum" }
        width: { type: string }
        span: { type: integer }
        fieldBind: { $ref: "#/definitions/M8_FrontFieldBind" }
        childComponents:
          type: array
          items: { $ref: "#/definitions/M8_FrontDragComponent" }
    M8_FrontPageTemplate:
      type: object
      required: [templateId, templateName, templateType, renderMode, bindSceneId, rootComponents]
      properties:
        templateId: { $ref: "#/definitions/Identifier" }
        templateName: { $ref: "#/definitions/NonEmptyString" }
        templateType: { $ref: "#/definitions/FrontTemplateTypeEnum" }
        renderMode: { $ref: "#/definitions/ReactRenderModeEnum" }
        bindSceneId: { $ref: "#/definitions/SceneId" }
        masterAggregate: { type: string }
        detailAggregates:
          type: array
          items: { type: string }
        rootComponents:
          type: array
          items: { $ref: "#/definitions/M8_FrontDragComponent" }
    M8_FrontSchema:
      type: object
      required: [reactGlobalConfig, pageTemplates]
      properties:
        reactGlobalConfig:
          type: object
          required: [uiLib, dragEngineStorage]
          properties:
            uiLib:
              type: string
              const: antd
            dragEngineStorage:
              type: string
              const: mysql8
        pageTemplates:
          type: array
          items: { $ref: "#/definitions/M8_FrontPageTemplate" }

    # 各分层根Schema定义(新增M8根校验)
    M1_Schema:
      type: object
      required: [aggregates, globalConstraints]
    M2_Schema:
      type: object
      required: [behaviors, globalBehaviorConstraints]
    ME_Schema:
      type: object
      required: [eventModel]
    M3_Schema:
      type: object
      required: [deploymentMappings]
    M4_Schema:
      type: object
      required: [sceneModel]
    M5_Schema:
      type: object
      required: [securityModel]
    M6_Schema:
      type: object
      required: [monitorModel]
    M7_Schema:
      type: object
      required: [qualityModel]
    MetaRule_Schema:
      type: object
      required: [metaRuleModel]
    M8_Schema:
      type: object
      required: [frontModel]

  rootAllOntologySchema:
    type: object
    oneOf:
      - {$ref: "#/definitions/M1_Schema"}
      - {$ref: "#/definitions/M2_Schema"}
      - {$ref: "#/definitions/ME_Schema"}
      - {$ref: "#/definitions/M3_Schema"}
      - {$ref: "#/definitions/M4_Schema"}
      - {$ref: "#/definitions/M5_Schema"}
      - {$ref: "#/definitions/M6_Schema"}
      - {$ref: "#/definitions/M7_Schema"}
      - {$ref: "#/definitions/MetaRule_Schema"}
      - {$ref: "#/definitions/M8_Schema"}
二、M1-domain.yaml(DDD领域聚合静态模型,无修改)
# M1 DDD聚合领域静态模型
aggregates:
  # 聚合1:客户聚合 CustomerAggregate
  - aggregateId: CustomerAggregate
    description: 客户主数据聚合,独立事务边界
    aggregateRoot:
      name: Customer
      identifier: customerId
      attributes:
        - name: customerName
          type: string
        - name: contactPhone
          type: string
        - name: registerTime
          type: datetime
        - name: customerLevel
          type: string
    entities: []
    valueObjects: []

  # 聚合2:产品聚合 ProductAggregate
  - aggregateId: ProductAggregate
    description: 商品主数据聚合,独立事务边界
    aggregateRoot:
      name: Product
      identifier: productId
      attributes:
        - name: productName
          type: string
        - name: skuCode
          type: string
        - name: category
          type: string
        - name: saleCurrency
          type: string
        - name: salePrice
          type: decimal
        - name: stockNum
          type: int
        - name: isOnSale
          type: boolean
    entities: []
    valueObjects: []

  # 聚合3:订单聚合 OrderAggregate
  - aggregateId: OrderAggregate
    description: 订单业务聚合,独立事务边界
    aggregateRoot:
      name: Order
      identifier: orderId
      attributes:
        - name: createTime
          type: datetime
        - name: totalCurrency
          type: string
        - name: totalAmount
          type: decimal
        - name: customerId
          type: string
          refAggregate: CustomerAggregate
          refRoot: Customer
          refIdentifier: customerId
          description: 客户ID,引用客户聚合根主键
      relations:
        - ref: OrderItem
          relationType: composition
        - ref: PaymentTerm
          relationType: composition
        - ref: DeliveryAddressEntity
          relationType: composition
    entities:
      - name: OrderItem
        localIdentifier: itemId
        attributes:
          - name: productId
            type: string
            refAggregate: ProductAggregate
            refRoot: Product
            refIdentifier: productId
            description: 商品ID,引用产品聚合根主键
          - name: quantity
            type: int
          - name: itemCurrency
            type: string
          - name: itemPrice
            type: decimal
      - name: PaymentTerm
        localIdentifier: termId
        attributes:
          - name: paymentType
            type: string
          - name: dueDays
            type: int
          - name: depositRatio
            type: decimal
          - name: settleCurrency
            type: string
          - name: settleAmount
            type: decimal
      - name: DeliveryAddressEntity
        localIdentifier: addrId
        attributes:
          - name: province
            type: string
          - name: city
            type: string
          - name: district
            type: string
          - name: streetDetail
            type: string
          - name: receiverName
            type: string
          - name: receiverPhone
            type: string
    valueObjects: []

globalConstraints:
  - crossAggRefRule: 跨聚合仅允许引用对方【聚合根唯一标识】,禁止引用对方内部实体、值对象
  - transactionBoundary: 一次事务只能修改同一个聚合内对象,跨聚合拆分为多个事务
  - cascadeDelete: 聚合根删除时,级联删除自身内部所有组合子实体
  - foreignKeyStrategy: 业务层做引用校验,默认不创建数据库物理外键;如需物理外键增加 dbForeignKey: true
三、M2-command.yaml(聚合命令行为模型,无修改)
# M2 聚合行为命令模型
behaviors:
  # 1.客户聚合行为
  - aggregateId: CustomerAggregate
    aggregateRoot: Customer
    commands:
      - cmdId: CreateCustomer
        desc: 新增客户主数据
        inputParams:
          - name: customerName
            type: string
          - name: contactPhone
            type: string
          - name: customerLevel
            type: string
        validations:
          - contactPhone非空、手机号格式校验
          - customerLevel取值范围[普通,VIP,高级VIP]
        emitEvents:
          - CustomerCreated
        sideEffect: 仅写入本聚合,不可修改其他聚合

      - cmdId: ModifyCustomerInfo
        desc: 修改客户名称、联系方式、等级
        inputParams:
          - name: customerId
            type: string
          - name: customerName
            type: string
            optional: true
          - name: contactPhone
            type: string
            optional: true
          - name: customerLevel
            type: string
            optional: true
        validations:
          - customerId必须存在
        emitEvents:
          - CustomerInfoModified

  # 2.产品聚合行为
  - aggregateId: ProductAggregate
    aggregateRoot: Product
    commands:
      - cmdId: CreateProduct
        desc: 新增商品档案
        inputParams:
          - name: productName
            type: string
          - name: skuCode
            type: string
          - name: category
            type: string
          - name: saleCurrency
            type: string
          - name: salePrice
            type: decimal
          - name: stockNum
            type: int
          - name: isOnSale
            type: boolean
        validations:
          - skuCode全局唯一
          - salePrice > 0
          - stockNum >= 0
        emitEvents:
          - ProductCreated

      - cmdId: ModifyProductPrice
        desc: 修改售价与币种
        inputParams:
          - name: productId
            type: string
          - name: saleCurrency
            type: string
            optional: true
          - name: salePrice
            type: decimal
            optional: true
        validations:
          - productId存在
          - 修改后售价>0
        emitEvents:
          - ProductPriceChanged

      - cmdId: StockDeduct
        desc: 下单扣减库存(订单聚合远程调用)
        inputParams:
          - name: productId
            type: string
          - name: deductQty
            type: int
        validations:
          - 可用库存 >= deductQty
        emitEvents:
          - ProductStockDeducted

  # 3.订单聚合行为
  - aggregateId: OrderAggregate
    aggregateRoot: Order
    commands:
      - cmdId: CreateOrder
        desc: 创建订单主单+明细+付款条件+送货地址
        inputParams:
          - name: customerId
            type: string
          - name: totalCurrency
            type: string
          - name: totalAmount
            type: decimal
          - name: items
            type: array
          - name: paymentTerm
            type: object
          - name: deliveryAddress
            type: object
        validations:
          - customerId 存在于CustomerAggregate
          - 所有productId存在于ProductAggregate
          - 订单明细金额累加 ≈ 订单总金额
          - dueDays >= 0, depositRatio ∈ [0,1]
          - 收货手机号格式合法
        bizSteps: "1.构建Order聚合根主记录 2.批量构建OrderItem子实体 3.构建PaymentTerm、DeliveryAddressEntity子实体 4.远程调用Product聚合StockDeduct扣减各商品库存"
        emitEvents:
          - OrderCreated
          - OrderItemAdded
          - OrderPaymentTermSet
          - OrderDeliveryAddressSet

      - cmdId: ModifyOrderDeliveryAddress
        desc: 修改订单送货地址子实体
        inputParams:
          - name: orderId
            type: string
          - name: province
            type: string
            optional: true
          - name: city
            type: string
            optional: true
          - name: district
            type: string
            optional: true
          - name: streetDetail
            type: string
            optional: true
          - name: receiverName
            type: string
            optional: true
          - name: receiverPhone
            type: string
            optional: true
        validations:
          - orderId存在
        emitEvents:
          - OrderDeliveryAddressModified

      - cmdId: CancelOrder
        desc: 取消订单,归还库存
        inputParams:
          - name: orderId
            type: string
        validations:
          - 订单状态允许取消
        bizSteps: "1.校验订单可取消状态 2.查询订单全部明细商品与数量 3.远程调用Product聚合增加对应库存 4.标记订单作废"
        emitEvents:
          - OrderCancelled

globalBehaviorConstraints:
  - 命令只能操作所属聚合内部对象,跨聚合仅允许调用对方聚合根暴露Command,禁止直接操作对方内部实体
  - 单个命令事务边界仅限当前聚合;跨聚合操作拆为分布式事件最终一致性
  - 子实体只能被所属聚合根命令修改,外部无法直接操作
  - 所有跨聚合依赖仅基于对方聚合根ID做校验,不依赖内部字段
四、ME-event.yaml(EDA事件驱动模型,无修改)
eventModel:
  globalConfig:
    idGenerator: snowflake
    bus: rocketmq
    retry: 3
    dlq: topic_msg_dlq
    outbox:
      enabled: true
      table: t_domain_outbox
      pollInterval: 1000ms
      batchSize: 50
      cleanupDays: 7

  aggregateEventDefinitions:
    - aggregateId: CustomerAggregate
      events:
        CustomerCreated:
          topic: topic_customer_create
          payload: [customerId,customerName,customerLevel]
          consumers: [customer-service]
        CustomerInfoModified:
          topic: topic_customer_modify
          payload: [customerId,contactPhone,customerLevel]
          consumers: [customer-service]

    - aggregateId: ProductAggregate
      events:
        ProductCreated:
          topic: topic_product_create
          payload: [productId,skuCode,salePrice,stockNum]
          consumers: [product-service]
        ProductPriceChanged:
          topic: topic_product_price
          payload: [productId,salePrice,saleCurrency]
          consumers: [order-service]
        ProductStockDeducted:
          topic: topic_stock_deduct
          payload: [productId,stockNum]
          consumers: [order-service]

    - aggregateId: OrderAggregate
      events:
        OrderCreated:
          topic: topic_order_create
          payload: [orderId,customerId,totalAmount]
          consumers: [product-service,customer-service]
        OrderDeliveryAddressModified:
          topic: topic_order_addr_modify
          payload: [orderId,receiverPhone]
          consumers: [order-service]
        OrderCancelled:
          topic: topic_order_cancel
          payload: [orderId,productIdList]
          consumers: [product-service]

  crossAggConsistencyRules:
    - triggerEvent: OrderCreated
      targetAggregate: ProductAggregate
      targetCommand: StockDeduct
      consistencyType: eventual
    - triggerEvent: OrderCancelled
      targetAggregate: ProductAggregate
      targetCommand: StockDeduct
      consistencyType: eventual
五、M3-deploy.yaml(服务存储部署映射,无修改)
deploymentMappings:
  globalConfig:
    dbEngine: mysql8
    defaultSchema: trade_db
    idGen: snowflake

  aggregateMappingList:
    - aggregateId: CustomerAggregate
      serviceName: customer-service
      commandApi:
        CreateCustomer: /api/v1/customer/create
        ModifyCustomerInfo: /api/v1/customer/modify
      tableMappings:
        - domainEntity: Customer
          table: t_customer_main
          pk: customer_id
          fieldMap:
            customerId: customer_id
            customerName: cust_name
            contactPhone: phone
            registerTime: register_time
            customerLevel: cust_level

    - aggregateId: ProductAggregate
      serviceName: product-service
      commandApi:
        CreateProduct: /api/v1/product/create
        ModifyProductPrice: /api/v1/product/price
        StockDeduct: /api/v1/product/stock/deduct
      tableMappings:
        - domainEntity: Product
          table: t_product_main
          pk: product_id
          fieldMap:
            productId: product_id
            productName: prod_name
            skuCode: sku_code
            category: category
            saleCurrency: currency
            salePrice: sale_price
            stockNum: stock_num
            isOnSale: is_on_sale

    - aggregateId: OrderAggregate
      serviceName: order-service
      commandApi:
        CreateOrder: /api/v1/order/create
        ModifyOrderDeliveryAddress: /api/v1/order/addr
        CancelOrder: /api/v1/order/cancel
      tableMappings:
        - domainEntity: Order
          table: t_order_main
          pk: order_id
          fieldMap:
            orderId: order_id
            createTime: create_time
            totalCurrency: total_currency
            totalAmount: total_amt
            customerId: cust_id
        - domainEntity: OrderItem
          table: t_order_item
          pk: item_id
          fieldMap:
            itemId: item_id
            productId: product_id
            quantity: buy_qty
            itemCurrency: item_currency
            itemPrice: item_price
        - domainEntity: PaymentTerm
          table: t_order_payment_term
          pk: term_id
          fieldMap:
            termId: term_id
            paymentType: pay_type
            dueDays: due_days
            depositRatio: deposit_ratio
            settleCurrency: settle_currency
            settleAmount: settle_amt
        - domainEntity: DeliveryAddressEntity
          table: t_order_address
          pk: addr_id
          fieldMap:
            addrId: addr_id
            province: province
            city: city
            district: district
            streetDetail: street
            receiverName: receiver_name
            receiverPhone: receiver_phone
六、M4-scene.yaml(业务Saga场景编排,无修改)
sceneModel:
  globalConfig:
    engine: saga
    consistency: eventual
    maxRetry: 2

  sceneDefinitions:
    - sceneId: SCENE_CREATE_ORDER
      sceneName: 用户创建订单完整流程
      aggregateScope: [CustomerAggregate,ProductAggregate,OrderAggregate]
      permissionBind: [order_create]
      flowSteps:
        - stepType: readOnlyCheck
          bindAggregate: CustomerAggregate
        - stepType: bindCommand
          bindAggregate: OrderAggregate
          bindCommand: CreateOrder
        - stepType: return

    - sceneId: SCENE_MODIFY_ORDER_ADDR
      sceneName: 修改订单收货地址
      aggregateScope: [OrderAggregate]
      permissionBind: [order_modify_addr]
      flowSteps:
        - stepType: bindCommand
          bindAggregate: OrderAggregate
          bindCommand: ModifyOrderDeliveryAddress
        - stepType: return

    - sceneId: SCENE_CANCEL_ORDER
      sceneName: 取消订单、归还库存
      aggregateScope: [OrderAggregate,ProductAggregate]
      permissionBind: [order_cancel]
      flowSteps:
        - stepType: bindCommand
          bindAggregate: OrderAggregate
          bindCommand: CancelOrder
        - stepType: return
七、M5-security.yaml(权限脱敏安全模型,无修改)
securityModel:
  globalConfig:
    authMode: oauth2_jwt
    auditEnable: true

  principals:
    - principalId: normal_user
      desc: C端普通消费者
    - principalId: backend_admin
      desc: 后台运营管理员

  functionPermissions:
    - permId: order_create
      bindScene: SCENE_CREATE_ORDER
      allowPrincipals: [normal_user,backend_admin]
    - permId: order_modify_addr
      bindScene: SCENE_MODIFY_ORDER_ADDR
      allowPrincipals: [normal_user,backend_admin]
    - permId: order_cancel
      bindScene: SCENE_CANCEL_ORDER
      allowPrincipals: [normal_user,backend_admin]

  maskRules:
    contactPhone: "{first3}****{last4}"
    receiverPhone: "{first3}****{last4}"

  encryptRules:
    storageEncrypt: [contactPhone,receiverPhone]
八、M6-monitor.yaml(全链路监控告警,无修改)
monitorModel:
  globalConfig:
    traceEngine: skywalking
    metricExport: prometheus

  serviceMetricBind:
    - serviceName: customer-service
      metricItems: [qps,rt,error_count]
    - serviceName: product-service
      metricItems: [qps,rt,stock_deduct_fail]
    - serviceName: order-service
      metricItems: [qps,rt,create_fail,cancel_fail]

  alertRules:
    - desc: 订单创建失败率大于5%
      level: 严重告警
      trigger: order-service.create_fail / order-service.qps > 0.05
    - desc: 库存扣减失败突增
      level: 警告告警
      trigger: product-service.stock_deduct_fail > 10
九、M7-sla.yaml(流量管控SLA规范,无修改)
qualityModel:
  aggregateSla:
    CustomerAggregate:
      availability: 99.95
    ProductAggregate:
      availability: 99.95
    OrderAggregate:
      availability: 99.99
  commandSla:
    CreateOrder:
      RT: 300ms
    StockDeduct:
      RT: 100ms
  sceneSla:
    SCENE_CREATE_ORDER:
      endToEndRT: 600ms
      successRate: 99.9
  flowControl:
    globalLimitQps: 20000
    circuitBreaker:
      enable: true
      failureThreshold: 20
      waitDuration: 3000ms
十、MetaRule-business.yaml(前端后端统一动态规则引擎,无修改)
metaRuleModel:
  globalConfig:
    ruleEngine: aviator
    hotUpdate: true

  ruleGlobalParams:
    - paramId: single_order_max_amount
      name: 单笔订单最大限额
      dataType: decimal
      defaultValue: 50000
    - paramId: stock_warn_min
      name: 库存预警最低值
      dataType: int
      defaultValue: 20
    - paramId: vip_discount_limit
      name: VIP免风控金额阈值
      dataType: decimal
      defaultValue: 10000

  ruleGroups:
    - groupId: ORDER_RISK_RULE
      groupType: 下单风控校验
      bindScene: SCENE_CREATE_ORDER
      rules:
        - ruleId: R_ORDER_AMOUNT_LIMIT
          ruleVersion: 1.0
          ruleName: 大额订单拦截
          matchCondition: totalAmount > #{single_order_max_amount} && customerLevel != "VIP"
          effect: REJECT
          message: 普通用户单笔订单不可超过50000元,请拆分下单
        - ruleId: R_STOCK_LOW_WARN
          ruleVersion: 1.0
          ruleName: 低库存预警
          matchCondition: stockNum < #{stock_warn_min}
          effect: ALERT
          message: 商品库存低于预警值,请及时补货

    - groupId: ORDER_COMPENSATE_RULE
      groupType: 订单取消补偿逻辑
      bindScene: SCENE_CANCEL_ORDER
      rules:
        - ruleId: R_CANCEL_STOCK_RETURN
          ruleVersion: 1.0
          ruleName: 取消订单归还库存
          matchCondition: true
          effect: COMPENSATE
          message: 订单取消自动返还锁定商品库存
十一、M8-front-schema.yaml(新增核心:React可视化拖拽前端模板建模层)
# M8 React前端可视化拖拽页面模板建模层 v2.0
# 约束:所有组件字段强制绑定M1领域模型,不允许自定义字段;自动关联M4场景、M2命令、M5脱敏、MetaRule规则
frontModel:
  reactGlobalConfig:
    uiLib: antd
    dragEngineStorage: mysql8
    renderFramework: react18
    autoGenFormSubmit: true
    autoBindApiFromScene: true
    dragRolePermission: [backend_admin]
    desc: 拖拽编辑器仅管理员可见;普通用户仅渲染页面,不可编辑模板

  pageTemplates:
    # 模板1:单实体表单模板 - 客户录入
    - templateId: template_customer_single
      templateName: 客户单表单录入模板
      templateType: single_table_form
      renderMode: page_container
      bindSceneId: SCENE_CREATE_CUSTOMER
      masterAggregate: CustomerAggregate
      detailAggregates: []
      rootComponents:
        - compId: card_customer_base
          compType: card
          width: 100%
          span: 24
          fieldBind:
            bindAggregateId: CustomerAggregate
            bindSourceType: aggregate_root
            domainFieldName: customerId
            formLabel: 客户基础信息卡片
          childComponents:
            - compId: input_cust_name
              compType: input
              span: 12
              fieldBind:
                bindAggregateId: CustomerAggregate
                bindSourceType: aggregate_root
                domainFieldName: customerName
                formLabel: 客户名称
                required: true
            - compId: input_cust_phone
              compType: input
              span: 12
              fieldBind:
                bindAggregateId: CustomerAggregate
                bindSourceType: aggregate_root
                domainFieldName: contactPhone
                formLabel: 联系手机号
                required: true
                maskField: true
            - compId: select_cust_level
              compType: select
              span: 12
              fieldBind:
                bindAggregateId: CustomerAggregate
                bindSourceType: aggregate_root
                domainFieldName: customerLevel
                formLabel: 客户等级
                required: true
            - compId: date_register
              compType: date_picker
              span: 12
              fieldBind:
                bindAggregateId: CustomerAggregate
                bindSourceType: aggregate_root
                domainFieldName: registerTime
                formLabel: 注册时间

    # 模板2:主从表单模板 - 订单录入(聚合根+多子实体)
    - templateId: template_order_master_detail
      templateName: 订单主从录入模板
      templateType: master_detail_form
      renderMode: page_container
      bindSceneId: SCENE_CREATE_ORDER
      masterAggregate: OrderAggregate
      detailAggregates: [OrderItem,PaymentTerm,DeliveryAddressEntity]
      rootComponents:
        # 订单主信息卡片
        - compId: card_order_master
          compType: card
          width: 100%
          span: 24
          fieldBind:
            bindAggregateId: OrderAggregate
            bindSourceType: aggregate_root
            domainFieldName: orderId
            formLabel: 订单主信息
          childComponents:
            - compId: select_customer
              compType: select
              span: 12
              fieldBind:
                bindAggregateId: CustomerAggregate
                bindSourceType: aggregate_root
                domainFieldName: customerId
                formLabel: 客户
                required: true
            - compId: input_currency
              compType: input
              span: 12
              fieldBind:
                bindAggregateId: OrderAggregate
                bindSourceType: aggregate_root
                domainFieldName: totalCurrency
                formLabel: 结算币种
                required: true
            - compId: number_total_amt
              compType: number_input
              span: 12
              fieldBind:
                bindAggregateId: OrderAggregate
                bindSourceType: aggregate_root
                domainFieldName: totalAmount
                formLabel: 订单总金额
                required: true
            - compId: date_create
              compType: date_picker
              span: 12
              fieldBind:
                bindAggregateId: OrderAggregate
                bindSourceType: aggregate_root
                domainFieldName: createTime
                formLabel: 下单时间
        # 订单明细表格子实体
        - compId: table_order_item
          compType: table
          width: 100%
          span: 24
          fieldBind:
            bindAggregateId: OrderAggregate
            bindSourceType: aggregate_entity
            domainEntityName: OrderItem
            domainFieldName: itemId
            formLabel: 订单商品明细
          childComponents:
            - compId: select_product
              compType: select
              span: 6
              fieldBind:
                bindAggregateId: ProductAggregate
                bindSourceType: aggregate_root
                domainFieldName: productId
                formLabel: 商品
                required: true
            - compId: number_qty
              compType: number_input
              span: 6
              fieldBind:
                bindAggregateId: OrderAggregate
                bindSourceType: aggregate_entity
                domainEntityName: OrderItem
                domainFieldName: quantity
                formLabel: 购买数量
                required: true
            - compId: number_price
              compType: number_input
              span: 6
              fieldBind:
                bindAggregateId: OrderAggregate
                bindSourceType: aggregate_entity
                domainEntityName: OrderItem
                domainFieldName: itemPrice
                formLabel: 单品单价
            - compId: input_item_currency
              compType: input
              span: 6
              fieldBind:
                bindAggregateId: OrderAggregate
                bindSourceType: aggregate_entity
                domainEntityName: OrderItem
                domainFieldName: itemCurrency
                formLabel: 单品币种
        # 付款条件子实体卡片
        - compId: card_payment_term
          compType: card
          width: 100%
          span: 24
          fieldBind:
            bindAggregateId: OrderAggregate
            bindSourceType: aggregate_entity
            domainEntityName: PaymentTerm
            domainFieldName: termId
            formLabel: 付款条款
          childComponents:
            - compId: select_pay_type
              compType: select
              span: 12
              fieldBind:
                bindAggregateId: OrderAggregate
                bindSourceType: aggregate_entity
                domainEntityName: PaymentTerm
                domainFieldName: paymentType
                formLabel: 付款方式
            - compId: number_duedays
              compType: number_input
              span: 12
              fieldBind:
                bindAggregateId: OrderAggregate
                bindSourceType: aggregate_entity
                domainEntityName: PaymentTerm
                domainFieldName: dueDays
                formLabel: 账期天数
        # 收货地址子实体卡片
        - compId: card_delivery_addr
          compType: card
          width: 100%
          span: 24
          fieldBind:
            bindAggregateId: OrderAggregate
            bindSourceType: aggregate_entity
            domainEntityName: DeliveryAddressEntity
            domainFieldName: addrId
            formLabel: 收货地址
          childComponents:
            - compId: input_province
              compType: input
              span: 6
              fieldBind:
                bindAggregateId: OrderAggregate
                bindSourceType: aggregate_entity
                domainEntityName: DeliveryAddressEntity
                domainFieldName: province
                formLabel: 省份
            - compId: input_city
              compType: input
              span: 6
              fieldBind:
                bindAggregateId: OrderAggregate
                bindSourceType: aggregate_entity
                domainEntityName: DeliveryAddressEntity
                domainFieldName: city
                formLabel: 城市
            - compId: input_district
              compType: input
              span: 6
              fieldBind:
                bindAggregateId: OrderAggregate
                bindSourceType: aggregate_entity
                domainEntityName: DeliveryAddressEntity
                domainFieldName: district
                formLabel: 区县
            - compId: input_street
              compType: input
              span: 6
              fieldBind:
                bindAggregateId: OrderAggregate
                bindSourceType: aggregate_entity
                domainEntityName: DeliveryAddressEntity
                domainFieldName: streetDetail
                formLabel: 详细街道
            - compId: input_receiver
              compType: input
              span: 12
              fieldBind:
                bindAggregateId: OrderAggregate
                bindSourceType: aggregate_entity
                domainEntityName: DeliveryAddressEntity
                domainFieldName: receiverName
                formLabel: 收货人
            - compId: input_receiver_phone
              compType: input
              span: 12
              fieldBind:
                bindAggregateId: OrderAggregate
                bindSourceType: aggregate_entity
                domainEntityName: DeliveryAddressEntity
                domainFieldName: receiverPhone
                formLabel: 收货电话
                maskField: true

    # 模板3:空白自定义拖拽模板(全新业务场景使用)
    - templateId: template_custom_blank
      templateName: 空白自定义拖拽模板
      templateType: custom_drag_form
      renderMode: drawer
      bindSceneId: ""
      masterAggregate: null
      detailAggregates: []
      rootComponents: []
完整架构分层定位总总结

全套11层分层职责

1. M0-meta-schema:全域本体校验根规范,新增React前端模板JSON Schema约束,CI流水线校验所有YAML语法合法;统一前后端数据、组件、页面描述标准。

2. M1-domain:DDD领域聚合唯一数据源,前端所有拖拽组件强制绑定本层字段,禁止自定义字段,保证前后端数据口径完全统一。

3. M2-command:聚合操作命令入参定义,React页面提交时自动映射表单组件值至命令参数,无硬编码接口参数。

4. ME-event:EDA事件总线定义,页面提交完成后监听领域事件,自动刷新页面、弹窗反馈、触发异步补偿逻辑。

5. M3-deploy:服务与数据库映射,自动关联页面场景对应的后端HTTP接口地址,前端无硬编码URL。

6. M4-scene:Saga业务流程编排,M8页面模板绑定SceneId,一套模板对应完整端到端业务流程。

7. M5-security:权限、脱敏、数据加密规范;区分模板编辑管理员权限、页面访问权限、敏感字段掩码渲染规则,前端渲染引擎自动读取执行。

8. M6-monitor:全链路监控指标,前端页面加载、表单提交、接口异常自动埋点,匹配后端告警规则。

9. M7-sla:接口流量、熔断、超时规范,前端请求层统一复用SLA限流配置。

10. MetaRule-business:Aviator统一动态规则,前端渲染引擎实时执行,控制组件显隐、禁用、输入拦截、预警弹窗;后端执行持久化校验,规则仅维护一份。

11. M8-front-schema(新增):React18+Ant Design可视化拖拽建模层,业务专家无代码操作;内置单表单/主从表单/空白模板三类模板;模板持久化MySQL;自动联动上游全部M层元数据;业务迭代仅修改模板yaml,无需修改React底层业务代码,满足后期专业人员独立维护模板的核心需求。

业务落地闭环流程

1. 架构工程师维护M0-M7、MetaRule底层元模型(一次性开发,极少变更);

2. 业务建模/专业维护人员仅操作M8-front-schema模板:可视化拖拽绑定M1字段生成页面;

3. 模板绑定M4场景后,系统自动关联M2命令API、M5脱敏权限、MetaRule动态规则;

4. 前端React通用渲染引擎读取M8模板动态生成页面,无业务硬编码;

5. 业务需求变更:仅调整M8模板组件配置,无需发布前端JS/TS源码,支持配置中心热更新。