| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using System.Text.Json;
- namespace Admin.NET.Plugin.AiDOP.DataPlatform.Core;
- public sealed record GovernanceTemplate(string Key, string System, string Object, string Name,
- IReadOnlyList<GovernanceField> Fields, string Config, JsonElement Sample, JsonElement Expected,
- SchemaDefinition SourceSchema, SchemaDefinition RawSchema, SchemaDefinition StandardObject);
- public static class GovernanceTemplates
- {
- private static readonly IngestContract Purchase = new PurchaseOrderSchemaRegistry()
- .Find(PurchaseOrderSchemaRegistry.DatasetKey, PurchaseOrderSchemaRegistry.SourceVersion)!;
- public static IReadOnlyList<GovernanceTemplate> All { get; } =
- [
- Create("erp-order", "ERP", "SALES_ORDER", "销售订单", [
- new("OrderNo", "string", true, true), new("OrderLine", "string", true, true),
- new("ItemCode", "string", true), new("CustomerCode", "string", true),
- new("OrderQty", "number", true), new("BusinessDate", "string", true), new("CurrencyCode", "string"), new("Amount", "number")
- ], [new("ItemCode", "sku"), new("CustomerCode", "customer"),
- new("OrderQty", "quantity", "decimal"), new("BusinessDate", "date", "date", DateFormat: "yyyyMMdd"),
- new("Amount", "total", "currency", Factor: 1, Scale: 2),
- new("CurrencyCode", "currency", "enum", Values: new() { ["RMB"] = "CNY" })],
- """{"OrderNo":"SO-1","OrderLine":"1","sku":"SKU-1","customer":"CUST-1","quantity":"15.5","date":"20261201","currency":"RMB","total":"31.255"}""",
- """{"OrderNo":"SO-1","OrderLine":"1","ItemCode":"SKU-1","CustomerCode":"CUST-1","OrderQty":15.5,"BusinessDate":"2026-12-01T00:00:00","CurrencyCode":"CNY","Amount":31.26}"""),
- Create("mes-work-order", "MES", "WO_LINE_PROD", "工单", [
- new("WorkOrderNo", "string", true, true), new("LineNo", "string", true, true),
- new("ItemCode", "string", true), new("OrganizationCode", "string", true),
- new("PlanQty", "number", true), new("BusinessDate", "string", true)
- ], [new("ItemCode", "sku"), new("OrganizationCode", "dept"),
- new("PlanQty", "quantity", "decimal"), new("BusinessDate", "date", "date", DateFormat: "yyyyMMdd")],
- """{"WorkOrderNo":"WO-1","LineNo":"1","sku":"SKU-1","dept":"DEPT-1","quantity":"20","date":"20261201"}""",
- """{"WorkOrderNo":"WO-1","LineNo":"1","ItemCode":"SKU-1","OrganizationCode":"DEPT-1","PlanQty":20,"BusinessDate":"2026-12-01T00:00:00"}"""),
- Create("mes-report", "MES", "S6_REPORT", "生产报工", [
- new("ReportNo", "string", true, true), new("TaskNo", "string", true),
- new("GoodQty", "number", true), new("BusinessDate", "string", true)
- ], [new("GoodQty", "qty", "decimal"), new("BusinessDate", "time", "timestamp", DateFormat: "yyyy-MM-dd HH:mm:ss", TimeZone: "Asia/Shanghai")],
- """{"ReportNo":"RP-1","TaskNo":"TASK-1","qty":"16","time":"2026-12-01 09:00:00"}""",
- """{"ReportNo":"RP-1","TaskNo":"TASK-1","GoodQty":16,"BusinessDate":"2026-12-01T01:00:00.0000000Z"}"""),
- Create("erp-purchase", "ERP", "PURCHASE_ORDER", "采购订单", GovernancePackage.PurchaseFields,
- [new("ItemCode", "sku"), new("SupplierCode", "supplier"),
- new("OrderQty", "qty", "unit", Factor: 10, Scale: 6), new("OrderDate", "orderDate", "date", DateFormat: "yyyyMMdd")],
- """{"PoNo":"PO-1","PoLine":"1","sku":"SKU-1","supplier":"SUP-1","qty":"1.55","orderDate":"20261201","sourceUpdatedAt":"2026-12-01T09:00:00+08:00"}""",
- """{"PoNo":"PO-1","PoLine":"1","ItemCode":"SKU-1","SupplierCode":"SUP-1","OrderQty":15.5,"OrderDate":"2026-12-01T00:00:00","sourceUpdatedAt":"2026-12-01T09:00:00+08:00"}"""),
- Create("wms-inventory", "WMS", "INV_TRANS", "库存流水", [
- new("TransNo", "string", true, true), new("ItemCode", "string", true), new("WarehouseCode", "string", true),
- new("TransType", "string", true), new("Quantity", "number", true), new("BusinessDate", "string", true)
- ], [new("ItemCode", "sku"), new("WarehouseCode", "location"),
- new("TransType", "direction", "enum", Values: new() { ["I"] = "IN", ["O"] = "OUT" }),
- new("Quantity", "qty", "decimal"), new("BusinessDate", "date", "date", DateFormat: "yyyyMMdd")],
- """{"TransNo":"INV-1","sku":"SKU-1","location":"LOC-1","direction":"I","qty":"25","date":"20261201"}""",
- """{"TransNo":"INV-1","ItemCode":"SKU-1","WarehouseCode":"LOC-1","TransType":"IN","Quantity":25,"BusinessDate":"2026-12-01T00:00:00"}""")
- ];
- private static GovernanceTemplate Create(string key, string system, string objectCode, string name, IReadOnlyList<GovernanceField> fields,
- GovernanceRule[] rules, string sample, string expected)
- {
- var config = GovernancePackage.Parse(JsonSerializer.Serialize(new
- {
- format = GovernancePackage.Format, template = key + "@1.0.0", rules
- }, GovernancePackage.JsonOptions), fields);
- return new(key, system, objectCode, name, fields, config.Json,
- JsonSerializer.Deserialize<JsonElement>(sample), JsonSerializer.Deserialize<JsonElement>(expected),
- config.SourceSchema(key + "@1.0.0"), GovernancePackage.RawSchema(Purchase.RawSchema), config.StandardSchema(objectCode + "@1.0.0"));
- }
- }
|