| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993 |
- package postgres
- import (
- "context"
- "fmt"
- )
- type DemoBootstrapSummary struct {
- TenantCode string `json:"tenantCode"`
- ChannelCode string `json:"channelCode"`
- EventID string `json:"eventId"`
- ReleaseID string `json:"releaseId"`
- SourceID string `json:"sourceId"`
- BuildID string `json:"buildId"`
- CardID string `json:"cardId"`
- PlaceID string `json:"placeId"`
- MapAssetID string `json:"mapAssetId"`
- TileReleaseID string `json:"tileReleaseId"`
- CourseSourceID string `json:"courseSourceId"`
- CourseSetID string `json:"courseSetId"`
- CourseVariantID string `json:"courseVariantId"`
- RuntimeBindingID string `json:"runtimeBindingId"`
- ScoreOEventID string `json:"scoreOEventId"`
- ScoreOReleaseID string `json:"scoreOReleaseId"`
- ScoreOCardID string `json:"scoreOCardId"`
- ScoreOSourceID string `json:"scoreOSourceId"`
- ScoreOBuildID string `json:"scoreOBuildId"`
- ScoreOCourseSetID string `json:"scoreOCourseSetId"`
- ScoreOCourseVariantID string `json:"scoreOCourseVariantId"`
- ScoreORuntimeBindingID string `json:"scoreORuntimeBindingId"`
- VariantManualEventID string `json:"variantManualEventId"`
- VariantManualRelease string `json:"variantManualReleaseId"`
- VariantManualCardID string `json:"variantManualCardId"`
- VariantManualSourceID string `json:"variantManualSourceId"`
- VariantManualBuildID string `json:"variantManualBuildId"`
- VariantManualCourseSet string `json:"variantManualCourseSetId"`
- VariantManualVariantID string `json:"variantManualCourseVariantId"`
- VariantManualRuntimeID string `json:"variantManualRuntimeBindingId"`
- CleanedSessionCount int64 `json:"cleanedSessionCount"`
- }
- func (s *Store) EnsureDemoData(ctx context.Context) (*DemoBootstrapSummary, error) {
- tx, err := s.Begin(ctx)
- if err != nil {
- return nil, err
- }
- defer tx.Rollback(ctx)
- var tenantID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO tenants (tenant_code, name, status)
- VALUES ('tenant_demo', '联调租户', 'active')
- ON CONFLICT (tenant_code) DO UPDATE SET
- name = EXCLUDED.name,
- status = EXCLUDED.status
- RETURNING id
- `).Scan(&tenantID); err != nil {
- return nil, fmt.Errorf("ensure demo tenant: %w", err)
- }
- var channelID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO entry_channels (
- tenant_id, channel_code, channel_type, platform_app_id, display_name, status, is_default
- )
- VALUES ($1, 'mini-demo', 'wechat_mini', 'wx-demo-appid', '小程序联调入口', 'active', true)
- ON CONFLICT (tenant_id, channel_code) DO UPDATE SET
- channel_type = EXCLUDED.channel_type,
- platform_app_id = EXCLUDED.platform_app_id,
- display_name = EXCLUDED.display_name,
- status = EXCLUDED.status,
- is_default = EXCLUDED.is_default
- RETURNING id
- `, tenantID).Scan(&channelID); err != nil {
- return nil, fmt.Errorf("ensure demo entry channel: %w", err)
- }
- var eventID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO events (
- tenant_id, event_public_id, slug, display_name, summary, status, is_default_experience, show_in_event_list
- )
- VALUES ($1, 'evt_demo_001', 'city-park-classic', '领秀城公园顺序赛', '顺序赛联调样例活动', 'active', true, true)
- ON CONFLICT (event_public_id) DO UPDATE SET
- tenant_id = EXCLUDED.tenant_id,
- slug = EXCLUDED.slug,
- display_name = EXCLUDED.display_name,
- summary = EXCLUDED.summary,
- status = EXCLUDED.status,
- is_default_experience = EXCLUDED.is_default_experience,
- show_in_event_list = EXCLUDED.show_in_event_list
- RETURNING id
- `, tenantID).Scan(&eventID); err != nil {
- return nil, fmt.Errorf("ensure demo event: %w", err)
- }
- var releaseRow struct {
- ID string
- PublicID string
- }
- if err := tx.QueryRow(ctx, `
- INSERT INTO event_releases (
- release_public_id,
- event_id,
- release_no,
- config_label,
- manifest_url,
- manifest_checksum_sha256,
- route_code,
- status,
- payload_jsonb
- )
- VALUES (
- 'rel_demo_001',
- $1,
- 1,
- '顺序赛联调配置 v1',
- 'https://api.gotomars.xyz/dev/demo-assets/manifests/classic',
- 'demo-checksum-001',
- 'route-demo-001',
- 'published',
- $2::jsonb
- )
- ON CONFLICT (release_public_id) DO UPDATE SET
- event_id = EXCLUDED.event_id,
- config_label = EXCLUDED.config_label,
- manifest_url = EXCLUDED.manifest_url,
- manifest_checksum_sha256 = EXCLUDED.manifest_checksum_sha256,
- route_code = EXCLUDED.route_code,
- status = EXCLUDED.status,
- payload_jsonb = EXCLUDED.payload_jsonb
- RETURNING id, release_public_id
- `, eventID, `{
- "schemaVersion": "1",
- "preview": {
- "mode": "course-preview",
- "baseTiles": {
- "tileBaseUrl": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/",
- "zoom": 16,
- "tileSize": 256
- },
- "viewport": {
- "width": 375,
- "height": 220,
- "minLon": 117.1001,
- "minLat": 36.6501,
- "maxLon": 117.1089,
- "maxLat": 36.6578
- },
- "selectedVariantId": "classic_main",
- "variants": [
- {
- "id": "classic_main",
- "name": "顺序赛主路线",
- "controls": [
- {"id": "31", "code": "31", "lon": 117.1012, "lat": 36.6512},
- {"id": "32", "code": "32", "lon": 117.1034, "lat": 36.6529},
- {"id": "33", "code": "33", "lon": 117.1052, "lat": 36.6541},
- {"id": "34", "code": "34", "lon": 117.1072, "lat": 36.6561}
- ],
- "legs": [
- {"from": "31", "to": "32"},
- {"from": "32", "to": "33"},
- {"from": "33", "to": "34"}
- ]
- }
- ]
- },
- "playfield": {
- "kind": "course"
- },
- "game": {
- "mode": "classic-sequential"
- }
- }`).Scan(&releaseRow.ID, &releaseRow.PublicID); err != nil {
- return nil, fmt.Errorf("ensure demo release: %w", err)
- }
- if _, err := tx.Exec(ctx, `
- UPDATE events
- SET current_release_id = $2
- WHERE id = $1
- `, eventID, releaseRow.ID); err != nil {
- return nil, fmt.Errorf("attach demo release: %w", err)
- }
- sourceNotes := "顺序赛联调 source 配置"
- source, err := s.UpsertEventConfigSource(ctx, tx, UpsertEventConfigSourceParams{
- EventID: eventID,
- SourceVersionNo: 1,
- SourceKind: "event_bundle",
- SchemaID: "event-source",
- SchemaVersion: "1",
- Status: "active",
- Notes: &sourceNotes,
- Source: map[string]any{
- "app": map[string]any{
- "id": "sample-classic-001",
- "title": "领秀城公园顺序赛",
- },
- "branding": map[string]any{
- "tenantCode": "tenant_demo",
- "entryChannel": "mini-demo",
- },
- "map": map[string]any{
- "tiles": "../map/lxcb-001/tiles/",
- "mapmeta": "../map/lxcb-001/tiles/meta.json",
- },
- "preview": demoPreviewManifest("classic"),
- "playfield": map[string]any{
- "kind": "course",
- "source": map[string]any{
- "type": "kml",
- "url": "https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route04.kml",
- },
- },
- "game": map[string]any{
- "mode": "classic-sequential",
- },
- "content": map[string]any{
- "h5Template": "content-h5-test-template.html",
- },
- },
- })
- if err != nil {
- return nil, fmt.Errorf("ensure demo event config source: %w", err)
- }
- buildLog := "顺序赛联调 build 产物"
- build, err := s.UpsertEventConfigBuild(ctx, tx, UpsertEventConfigBuildParams{
- EventID: eventID,
- SourceID: source.ID,
- BuildNo: 1,
- BuildStatus: "success",
- BuildLog: &buildLog,
- Manifest: map[string]any{
- "schemaVersion": "1",
- "releaseId": "rel_demo_001",
- "version": "2026.04.01",
- "app": map[string]any{
- "id": "sample-classic-001",
- "title": "领秀城公园顺序赛",
- },
- "map": map[string]any{
- "tiles": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/",
- "mapmeta": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/meta.json",
- },
- "preview": demoPreviewManifest("classic"),
- "playfield": map[string]any{
- "kind": "course",
- "source": map[string]any{
- "type": "kml",
- "url": "https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/10/c01.kml",
- },
- },
- "game": map[string]any{
- "mode": "classic-sequential",
- },
- "assets": map[string]any{
- "contentHtml": "https://oss-mbh5.colormaprun.com/gotomars/event/content-h5-test-template.html",
- },
- },
- AssetIndex: []map[string]any{
- {
- "assetType": "manifest",
- "assetKey": "manifest",
- },
- {
- "assetType": "mapmeta",
- "assetKey": "mapmeta",
- },
- {
- "assetType": "playfield",
- "assetKey": "playfield-kml",
- },
- {
- "assetType": "content_html",
- "assetKey": "content-html",
- },
- },
- })
- if err != nil {
- return nil, fmt.Errorf("ensure demo event config build: %w", err)
- }
- if err := s.AttachBuildToRelease(ctx, tx, releaseRow.ID, build.ID); err != nil {
- return nil, fmt.Errorf("attach demo build to release: %w", err)
- }
- tilesPath := "map/lxcb-001/tiles/"
- mapmetaPath := "map/lxcb-001/tiles/meta.json"
- playfieldPath := "kml/lxcb-001/10/c01.kml"
- contentPath := "event/content-h5-test-template.html"
- manifestChecksum := "demo-checksum-001"
- if err := s.ReplaceEventReleaseAssets(ctx, tx, releaseRow.ID, []UpsertEventReleaseAssetParams{
- {
- EventReleaseID: releaseRow.ID,
- AssetType: "manifest",
- AssetKey: "manifest",
- AssetURL: "https://api.gotomars.xyz/dev/demo-assets/manifests/classic",
- Checksum: &manifestChecksum,
- Meta: map[string]any{"source": "release-manifest"},
- },
- {
- EventReleaseID: releaseRow.ID,
- AssetType: "tiles",
- AssetKey: "tiles-root",
- AssetPath: &tilesPath,
- AssetURL: "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/",
- Meta: map[string]any{"kind": "directory"},
- },
- {
- EventReleaseID: releaseRow.ID,
- AssetType: "mapmeta",
- AssetKey: "mapmeta",
- AssetPath: &mapmetaPath,
- AssetURL: "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/meta.json",
- Meta: map[string]any{"format": "json"},
- },
- {
- EventReleaseID: releaseRow.ID,
- AssetType: "playfield",
- AssetKey: "course-kml",
- AssetPath: &playfieldPath,
- AssetURL: "https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/10/c01.kml",
- Meta: map[string]any{"format": "kml"},
- },
- {
- EventReleaseID: releaseRow.ID,
- AssetType: "content_html",
- AssetKey: "content-html",
- AssetPath: &contentPath,
- AssetURL: "https://oss-mbh5.colormaprun.com/gotomars/event/content-h5-test-template.html",
- Meta: map[string]any{"kind": "content-page"},
- },
- }); err != nil {
- return nil, fmt.Errorf("ensure demo event release assets: %w", err)
- }
- var cardPublicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO cards (
- card_public_id,
- tenant_id,
- entry_channel_id,
- card_type,
- title,
- subtitle,
- cover_url,
- event_id,
- display_slot,
- display_priority,
- status,
- is_default_experience,
- starts_at,
- ends_at
- )
- VALUES (
- 'card_demo_001',
- $1,
- $2,
- 'event',
- '领秀城公园顺序赛',
- '顺序赛推荐入口',
- 'https://oss-mbh5.colormaprun.com/gotomars/assets/demo-cover.jpg',
- $3,
- 'home_primary',
- 100,
- 'active',
- true,
- NOW() - INTERVAL '1 day',
- NOW() + INTERVAL '30 day'
- )
- ON CONFLICT (card_public_id) DO UPDATE SET
- tenant_id = EXCLUDED.tenant_id,
- entry_channel_id = EXCLUDED.entry_channel_id,
- card_type = EXCLUDED.card_type,
- title = EXCLUDED.title,
- subtitle = EXCLUDED.subtitle,
- cover_url = EXCLUDED.cover_url,
- event_id = EXCLUDED.event_id,
- display_slot = EXCLUDED.display_slot,
- display_priority = EXCLUDED.display_priority,
- status = EXCLUDED.status,
- is_default_experience = EXCLUDED.is_default_experience,
- starts_at = EXCLUDED.starts_at,
- ends_at = EXCLUDED.ends_at
- RETURNING card_public_id
- `, tenantID, channelID, eventID).Scan(&cardPublicID); err != nil {
- return nil, fmt.Errorf("ensure demo card: %w", err)
- }
- var placeID, placePublicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO places (
- place_public_id, code, name, region, status
- )
- VALUES (
- 'place_demo_001', 'place-demo-001', '领秀城公园', 'Shanghai', 'active'
- )
- ON CONFLICT (code) DO UPDATE SET
- name = EXCLUDED.name,
- region = EXCLUDED.region,
- status = EXCLUDED.status
- RETURNING id, place_public_id
- `).Scan(&placeID, &placePublicID); err != nil {
- return nil, fmt.Errorf("ensure demo place: %w", err)
- }
- var mapAssetID, mapAssetPublicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO map_assets (
- map_asset_public_id, place_id, code, name, map_type, status
- )
- VALUES (
- 'mapasset_demo_001', $1, 'mapasset-demo-001', '领秀城公园基础底图', 'standard', 'active'
- )
- ON CONFLICT (code) DO UPDATE SET
- place_id = EXCLUDED.place_id,
- name = EXCLUDED.name,
- map_type = EXCLUDED.map_type,
- status = EXCLUDED.status
- RETURNING id, map_asset_public_id
- `, placeID).Scan(&mapAssetID, &mapAssetPublicID); err != nil {
- return nil, fmt.Errorf("ensure demo map asset: %w", err)
- }
- var tileReleaseID, tileReleasePublicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO tile_releases (
- tile_release_public_id, map_asset_id, version_code, status, tile_base_url, meta_url, published_at
- )
- VALUES (
- 'tile_demo_001', $1, 'v2026-04-03', 'published',
- 'https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/', 'https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/meta.json', NOW()
- )
- ON CONFLICT (map_asset_id, version_code) DO UPDATE SET
- status = EXCLUDED.status,
- tile_base_url = EXCLUDED.tile_base_url,
- meta_url = EXCLUDED.meta_url,
- published_at = EXCLUDED.published_at
- RETURNING id, tile_release_public_id
- `, mapAssetID).Scan(&tileReleaseID, &tileReleasePublicID); err != nil {
- return nil, fmt.Errorf("ensure demo tile release: %w", err)
- }
- if _, err := tx.Exec(ctx, `
- UPDATE map_assets
- SET current_tile_release_id = $2
- WHERE id = $1
- `, mapAssetID, tileReleaseID); err != nil {
- return nil, fmt.Errorf("attach demo tile release: %w", err)
- }
- var courseSourceID, courseSourcePublicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_sources (
- course_source_public_id, source_type, file_url, import_status
- )
- VALUES (
- 'csource_demo_001', 'kml', 'https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/10/c01.kml', 'imported'
- )
- ON CONFLICT (course_source_public_id) DO UPDATE SET
- source_type = EXCLUDED.source_type,
- file_url = EXCLUDED.file_url,
- import_status = EXCLUDED.import_status
- RETURNING id, course_source_public_id
- `).Scan(&courseSourceID, &courseSourcePublicID); err != nil {
- return nil, fmt.Errorf("ensure demo course source: %w", err)
- }
- var courseSourceVariantBID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_sources (
- course_source_public_id, source_type, file_url, import_status
- )
- VALUES (
- 'csource_demo_002', 'kml', 'https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route02.kml', 'imported'
- )
- ON CONFLICT (course_source_public_id) DO UPDATE SET
- source_type = EXCLUDED.source_type,
- file_url = EXCLUDED.file_url,
- import_status = EXCLUDED.import_status
- RETURNING id, course_source_public_id
- `).Scan(&courseSourceVariantBID, new(string)); err != nil {
- return nil, fmt.Errorf("ensure demo course source variant b: %w", err)
- }
- var courseSourceVariantCID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_sources (
- course_source_public_id, source_type, file_url, import_status
- )
- VALUES (
- 'csource_demo_003', 'kml', 'https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route03.kml', 'imported'
- )
- ON CONFLICT (course_source_public_id) DO UPDATE SET
- source_type = EXCLUDED.source_type,
- file_url = EXCLUDED.file_url,
- import_status = EXCLUDED.import_status
- RETURNING id, course_source_public_id
- `).Scan(&courseSourceVariantCID, new(string)); err != nil {
- return nil, fmt.Errorf("ensure demo course source variant c: %w", err)
- }
- var courseSourceVariantDID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_sources (
- course_source_public_id, source_type, file_url, import_status
- )
- VALUES (
- 'csource_demo_004', 'kml', 'https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route04.kml', 'imported'
- )
- ON CONFLICT (course_source_public_id) DO UPDATE SET
- source_type = EXCLUDED.source_type,
- file_url = EXCLUDED.file_url,
- import_status = EXCLUDED.import_status
- RETURNING id, course_source_public_id
- `).Scan(&courseSourceVariantDID, new(string)); err != nil {
- return nil, fmt.Errorf("ensure demo course source variant d: %w", err)
- }
- var courseSetID, courseSetPublicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_sets (
- course_set_public_id, place_id, map_asset_id, code, mode, name, status
- )
- VALUES (
- 'cset_demo_001', $1, $2, 'cset-demo-001', 'classic-sequential', '顺序赛标准赛道', 'active'
- )
- ON CONFLICT (code) DO UPDATE SET
- place_id = EXCLUDED.place_id,
- map_asset_id = EXCLUDED.map_asset_id,
- mode = EXCLUDED.mode,
- name = EXCLUDED.name,
- status = EXCLUDED.status
- RETURNING id, course_set_public_id
- `, placeID, mapAssetID).Scan(&courseSetID, &courseSetPublicID); err != nil {
- return nil, fmt.Errorf("ensure demo course set: %w", err)
- }
- var courseVariantID, courseVariantPublicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_variants (
- course_variant_public_id, course_set_id, source_id, name, route_code, mode, control_count, status, is_default
- )
- VALUES (
- 'cvariant_demo_001', $1, $2, '顺序赛 A 线', 'route-demo-a', 'classic-sequential', 8, 'active', true
- )
- ON CONFLICT (course_variant_public_id) DO UPDATE SET
- course_set_id = EXCLUDED.course_set_id,
- source_id = EXCLUDED.source_id,
- name = EXCLUDED.name,
- route_code = EXCLUDED.route_code,
- mode = EXCLUDED.mode,
- control_count = EXCLUDED.control_count,
- status = EXCLUDED.status,
- is_default = EXCLUDED.is_default
- RETURNING id, course_variant_public_id
- `, courseSetID, courseSourceID).Scan(&courseVariantID, &courseVariantPublicID); err != nil {
- return nil, fmt.Errorf("ensure demo course variant: %w", err)
- }
- var courseVariantBID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_variants (
- course_variant_public_id, course_set_id, source_id, name, route_code, mode, control_count, status, is_default
- )
- VALUES (
- 'cvariant_demo_002', $1, $2, '顺序赛 B 线', 'route-demo-b', 'classic-sequential', 10, 'active', false
- )
- ON CONFLICT (course_variant_public_id) DO UPDATE SET
- course_set_id = EXCLUDED.course_set_id,
- source_id = EXCLUDED.source_id,
- name = EXCLUDED.name,
- route_code = EXCLUDED.route_code,
- mode = EXCLUDED.mode,
- control_count = EXCLUDED.control_count,
- status = EXCLUDED.status,
- is_default = EXCLUDED.is_default
- RETURNING id, course_variant_public_id
- `, courseSetID, courseSourceVariantBID).Scan(&courseVariantBID, new(string)); err != nil {
- return nil, fmt.Errorf("ensure demo course variant b: %w", err)
- }
- if _, err := tx.Exec(ctx, `
- UPDATE course_sets
- SET current_variant_id = $2
- WHERE id = $1
- `, courseSetID, courseVariantID); err != nil {
- return nil, fmt.Errorf("attach demo course variant: %w", err)
- }
- var runtimeBindingID, runtimeBindingPublicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO map_runtime_bindings (
- runtime_binding_public_id, event_id, place_id, map_asset_id, tile_release_id, course_set_id, course_variant_id, status, notes
- )
- VALUES (
- 'runtime_demo_001', $1, $2, $3, $4, $5, $6, 'active', '顺序赛联调运行绑定'
- )
- ON CONFLICT (runtime_binding_public_id) DO UPDATE SET
- event_id = EXCLUDED.event_id,
- place_id = EXCLUDED.place_id,
- map_asset_id = EXCLUDED.map_asset_id,
- tile_release_id = EXCLUDED.tile_release_id,
- course_set_id = EXCLUDED.course_set_id,
- course_variant_id = EXCLUDED.course_variant_id,
- status = EXCLUDED.status,
- notes = EXCLUDED.notes
- RETURNING id, runtime_binding_public_id
- `, eventID, placeID, mapAssetID, tileReleaseID, courseSetID, courseVariantID).Scan(&runtimeBindingID, &runtimeBindingPublicID); err != nil {
- return nil, fmt.Errorf("ensure demo runtime binding: %w", err)
- }
- classicPresentationID, _, err := s.upsertDemoEventPresentation(ctx, tx, eventID, upsertDemoEventPresentationParams{
- PublicID: "pres_demo_001",
- Code: "event-detail-classic",
- Name: "顺序赛详情展示",
- PresentationType: "detail",
- TemplateKey: "event.detail.classic",
- Version: "v2026-04-07-classic",
- Title: "领秀城公园顺序赛展示定义",
- })
- if err != nil {
- return nil, fmt.Errorf("ensure demo presentation: %w", err)
- }
- classicBundleID, _, err := s.upsertDemoContentBundle(ctx, tx, eventID, upsertDemoContentBundleParams{
- PublicID: "bundle_demo_001",
- Code: "result-media-classic",
- Name: "顺序赛结果内容包",
- BundleType: "result_media",
- Version: "v2026-04-07-classic",
- ManifestURL: "https://api.gotomars.xyz/dev/demo-assets/content-manifests/classic",
- AssetRootURL: "https://oss-mbh5.colormaprun.com/gotomars/event/",
- })
- if err != nil {
- return nil, fmt.Errorf("ensure demo content bundle: %w", err)
- }
- if err := s.SetEventDefaultBindings(ctx, tx, SetEventDefaultBindingsParams{
- EventID: eventID,
- PresentationID: &classicPresentationID,
- ContentBundleID: &classicBundleID,
- RuntimeBindingID: &runtimeBindingID,
- UpdatePresentation: true,
- UpdateContent: true,
- UpdateRuntime: true,
- }); err != nil {
- return nil, fmt.Errorf("set demo default bindings: %w", err)
- }
- if err := s.SetEventReleaseBindings(ctx, tx, releaseRow.ID, &runtimeBindingID, &classicPresentationID, &classicBundleID); err != nil {
- return nil, fmt.Errorf("bind demo release defaults: %w", err)
- }
- var manualEventID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO events (
- tenant_id, event_public_id, slug, display_name, summary, status, is_default_experience, show_in_event_list
- )
- VALUES ($1, 'evt_demo_variant_manual_001', 'city-park-manual-variant', '领秀城公园多赛道挑战', '手动多赛道联调样例活动', 'active', false, true)
- ON CONFLICT (event_public_id) DO UPDATE SET
- tenant_id = EXCLUDED.tenant_id,
- slug = EXCLUDED.slug,
- display_name = EXCLUDED.display_name,
- summary = EXCLUDED.summary,
- status = EXCLUDED.status,
- is_default_experience = EXCLUDED.is_default_experience,
- show_in_event_list = EXCLUDED.show_in_event_list
- RETURNING id
- `, tenantID).Scan(&manualEventID); err != nil {
- return nil, fmt.Errorf("ensure variant manual demo event: %w", err)
- }
- var manualReleaseRow struct {
- ID string
- PublicID string
- }
- if err := tx.QueryRow(ctx, `
- INSERT INTO event_releases (
- release_public_id,
- event_id,
- release_no,
- config_label,
- manifest_url,
- manifest_checksum_sha256,
- route_code,
- status,
- payload_jsonb
- )
- VALUES (
- 'rel_demo_variant_manual_001',
- $1,
- 1,
- '多赛道联调配置 v1',
- 'https://api.gotomars.xyz/dev/demo-assets/manifests/manual-variant',
- 'demo-variant-checksum-001',
- 'route-variant-d',
- 'published',
- $2::jsonb
- )
- ON CONFLICT (release_public_id) DO UPDATE SET
- event_id = EXCLUDED.event_id,
- config_label = EXCLUDED.config_label,
- manifest_url = EXCLUDED.manifest_url,
- manifest_checksum_sha256 = EXCLUDED.manifest_checksum_sha256,
- route_code = EXCLUDED.route_code,
- status = EXCLUDED.status,
- payload_jsonb = EXCLUDED.payload_jsonb
- RETURNING id, release_public_id
- `, manualEventID, `{
- "schemaVersion": "1",
- "preview": {
- "mode": "manual-variant-preview",
- "baseTiles": {
- "tileBaseUrl": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/",
- "zoom": 16,
- "tileSize": 256
- },
- "viewport": {
- "width": 375,
- "height": 220,
- "minLon": 117.1001,
- "minLat": 36.6501,
- "maxLon": 117.1112,
- "maxLat": 36.6593
- },
- "selectedVariantId": "variant_d",
- "variants": [
- {
- "id": "variant_a",
- "name": "路线 01",
- "routeCode": "route-variant-a",
- "controls": [
- {"id": "1", "code": "1", "lon": 117.000649296107, "lat": 36.5921631022497},
- {"id": "2", "code": "2", "lon": 116.999689737459, "lat": 36.5922740961347},
- {"id": "3", "code": "3", "lon": 116.999108309973, "lat": 36.5919019395375},
- {"id": "4", "code": "4", "lon": 116.999823913032, "lat": 36.591572220351},
- {"id": "5", "code": "5", "lon": 116.999860506371, "lat": 36.5912131186443},
- {"id": "6", "code": "6", "lon": 117.000340285695, "lat": 36.5909356298175},
- {"id": "7", "code": "7", "lon": 117.000441933857, "lat": 36.5915004001434},
- {"id": "8", "code": "8", "lon": 117.001397426578, "lat": 36.5915983367736},
- {"id": "9", "code": "9", "lon": 117.000665559813, "lat": 36.5919574366878},
- {"id": "10", "code": "10", "lon": 117.000649296107, "lat": 36.5921631022497}
- ],
- "legs": [
- {"from": "1", "to": "2"},
- {"from": "2", "to": "3"},
- {"from": "3", "to": "4"},
- {"from": "4", "to": "5"},
- {"from": "5", "to": "6"},
- {"from": "6", "to": "7"},
- {"from": "7", "to": "8"},
- {"from": "8", "to": "9"},
- {"from": "9", "to": "10"}
- ]
- },
- {
- "id": "variant_b",
- "name": "路线 02",
- "routeCode": "route-variant-b",
- "controls": [
- {"id": "1", "code": "1", "lon": 117.000649296107, "lat": 36.5921631022497},
- {"id": "2", "code": "2", "lon": 116.999766990062, "lat": 36.5921141343085},
- {"id": "3", "code": "3", "lon": 116.999710067091, "lat": 36.5917615642144},
- {"id": "4", "code": "4", "lon": 116.998774904002, "lat": 36.5913306430232},
- {"id": "5", "code": "5", "lon": 116.998941606987, "lat": 36.5908278985923},
- {"id": "6", "code": "6", "lon": 117.00058830721, "lat": 36.5905340853955},
- {"id": "7", "code": "7", "lon": 117.000238637533, "lat": 36.5914742836876},
- {"id": "8", "code": "8", "lon": 117.000937976887, "lat": 36.5916113949816},
- {"id": "9", "code": "9", "lon": 117.000803801313, "lat": 36.5919411140006},
- {"id": "10", "code": "10", "lon": 117.000649296107, "lat": 36.5921631022497}
- ],
- "legs": [
- {"from": "1", "to": "2"},
- {"from": "2", "to": "3"},
- {"from": "3", "to": "4"},
- {"from": "4", "to": "5"},
- {"from": "5", "to": "6"},
- {"from": "6", "to": "7"},
- {"from": "7", "to": "8"},
- {"from": "8", "to": "9"},
- {"from": "9", "to": "10"}
- ]
- },
- {
- "id": "variant_c",
- "name": "路线 03",
- "routeCode": "route-variant-c",
- "controls": [
- {"id": "1", "code": "1", "lon": 117.000649296107, "lat": 36.5921631022497},
- {"id": "2", "code": "2", "lon": 117.000665559813, "lat": 36.5919574366878},
- {"id": "3", "code": "3", "lon": 117.001397426578, "lat": 36.5915983367736},
- {"id": "4", "code": "4", "lon": 117.000441933857, "lat": 36.5915004001434},
- {"id": "5", "code": "5", "lon": 117.000340285695, "lat": 36.5909356298175},
- {"id": "6", "code": "6", "lon": 116.999860506371, "lat": 36.5912131186443},
- {"id": "7", "code": "7", "lon": 116.999823913032, "lat": 36.591572220351},
- {"id": "8", "code": "8", "lon": 116.999108309973, "lat": 36.5919019395375},
- {"id": "9", "code": "9", "lon": 116.999689737459, "lat": 36.5922740961347},
- {"id": "10", "code": "10", "lon": 117.000649296107, "lat": 36.5921631022497}
- ],
- "legs": [
- {"from": "1", "to": "2"},
- {"from": "2", "to": "3"},
- {"from": "3", "to": "4"},
- {"from": "4", "to": "5"},
- {"from": "5", "to": "6"},
- {"from": "6", "to": "7"},
- {"from": "7", "to": "8"},
- {"from": "8", "to": "9"},
- {"from": "9", "to": "10"}
- ]
- },
- {
- "id": "variant_d",
- "name": "路线 04",
- "routeCode": "route-variant-d",
- "controls": [
- {"id": "1", "code": "1", "lon": 117.000649296107, "lat": 36.5921631022497},
- {"id": "2", "code": "2", "lon": 117.000803801313, "lat": 36.5919411140006},
- {"id": "3", "code": "3", "lon": 117.000937976887, "lat": 36.5916113949816},
- {"id": "4", "code": "4", "lon": 117.000238637533, "lat": 36.5914742836876},
- {"id": "5", "code": "5", "lon": 117.00058830721, "lat": 36.5905340853955},
- {"id": "6", "code": "6", "lon": 116.998941606987, "lat": 36.5908278985923},
- {"id": "7", "code": "7", "lon": 116.998774904002, "lat": 36.5913306430232},
- {"id": "8", "code": "8", "lon": 116.999710067091, "lat": 36.5917615642144},
- {"id": "9", "code": "9", "lon": 116.999766990062, "lat": 36.5921141343085},
- {"id": "10", "code": "10", "lon": 117.000649296107, "lat": 36.5921631022497}
- ],
- "legs": [
- {"from": "1", "to": "2"},
- {"from": "2", "to": "3"},
- {"from": "3", "to": "4"},
- {"from": "4", "to": "5"},
- {"from": "5", "to": "6"},
- {"from": "6", "to": "7"},
- {"from": "7", "to": "8"},
- {"from": "8", "to": "9"},
- {"from": "9", "to": "10"}
- ]
- }
- ]
- },
- "playfield": {
- "kind": "course-set"
- },
- "game": {
- "mode": "classic-sequential"
- },
- "play": {
- "assignmentMode": "manual",
- "courseVariants": [
- {
- "id": "variant_a",
- "name": "路线 01",
- "description": "route01.kml",
- "routeCode": "route-variant-a",
- "selectable": true
- },
- {
- "id": "variant_b",
- "name": "路线 02",
- "description": "route02.kml",
- "routeCode": "route-variant-b",
- "selectable": true
- },
- {
- "id": "variant_c",
- "name": "路线 03",
- "description": "route03.kml",
- "routeCode": "route-variant-c",
- "selectable": true
- },
- {
- "id": "variant_d",
- "name": "路线 04",
- "description": "route04.kml",
- "routeCode": "route-variant-d",
- "selectable": true
- }
- ]
- }
- }`).Scan(&manualReleaseRow.ID, &manualReleaseRow.PublicID); err != nil {
- return nil, fmt.Errorf("ensure variant manual demo release: %w", err)
- }
- if _, err := tx.Exec(ctx, `
- UPDATE events
- SET current_release_id = $2
- WHERE id = $1
- `, manualEventID, manualReleaseRow.ID); err != nil {
- return nil, fmt.Errorf("attach variant manual demo release: %w", err)
- }
- var manualCardPublicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO cards (
- card_public_id,
- tenant_id,
- entry_channel_id,
- card_type,
- title,
- subtitle,
- cover_url,
- event_id,
- display_slot,
- display_priority,
- status,
- is_default_experience,
- starts_at,
- ends_at
- )
- VALUES (
- 'card_demo_variant_manual_001',
- $1,
- $2,
- 'event',
- '领秀城公园多赛道挑战',
- '手动选择赛道入口',
- 'https://oss-mbh5.colormaprun.com/gotomars/assets/demo-cover.jpg',
- $3,
- 'home_primary',
- 95,
- 'active',
- false,
- NOW() - INTERVAL '1 day',
- NOW() + INTERVAL '30 day'
- )
- ON CONFLICT (card_public_id) DO UPDATE SET
- tenant_id = EXCLUDED.tenant_id,
- entry_channel_id = EXCLUDED.entry_channel_id,
- card_type = EXCLUDED.card_type,
- title = EXCLUDED.title,
- subtitle = EXCLUDED.subtitle,
- cover_url = EXCLUDED.cover_url,
- event_id = EXCLUDED.event_id,
- display_slot = EXCLUDED.display_slot,
- display_priority = EXCLUDED.display_priority,
- status = EXCLUDED.status,
- is_default_experience = EXCLUDED.is_default_experience,
- starts_at = EXCLUDED.starts_at,
- ends_at = EXCLUDED.ends_at
- RETURNING card_public_id
- `, tenantID, channelID, manualEventID).Scan(&manualCardPublicID); err != nil {
- return nil, fmt.Errorf("ensure variant manual demo card: %w", err)
- }
- manualSourceNotes := "多赛道联调 source 配置"
- manualSource, err := s.UpsertEventConfigSource(ctx, tx, UpsertEventConfigSourceParams{
- EventID: manualEventID,
- SourceVersionNo: 1,
- SourceKind: "event_bundle",
- SchemaID: "event-source",
- SchemaVersion: "1",
- Status: "active",
- Notes: &manualSourceNotes,
- Source: map[string]any{
- "schemaVersion": "1",
- "app": map[string]any{
- "id": "sample-variant-manual-001",
- "title": "领秀城公园多赛道挑战",
- },
- "branding": map[string]any{
- "tenantCode": "tenant_demo",
- "entryChannel": "mini-demo",
- },
- "map": map[string]any{
- "tiles": "../map/lxcb-001/tiles/",
- "mapmeta": "../map/lxcb-001/tiles/meta.json",
- },
- "preview": demoPreviewManifest("manual-variant"),
- "playfield": map[string]any{
- "kind": "course",
- "source": map[string]any{
- "type": "kml",
- "url": "../kml/lxcb-001/10/c01.kml",
- },
- },
- "game": map[string]any{
- "mode": "classic-sequential",
- },
- "play": map[string]any{
- "assignmentMode": "manual",
- "courseVariants": []map[string]any{
- {"id": "variant_a", "name": "路线 01", "description": "route01.kml", "routeCode": "route-variant-a", "selectable": true},
- {"id": "variant_b", "name": "路线 02", "description": "route02.kml", "routeCode": "route-variant-b", "selectable": true},
- {"id": "variant_c", "name": "路线 03", "description": "route03.kml", "routeCode": "route-variant-c", "selectable": true},
- {"id": "variant_d", "name": "路线 04", "description": "route04.kml", "routeCode": "route-variant-d", "selectable": true},
- },
- },
- "content": map[string]any{
- "h5Template": "content-h5-test-template.html",
- },
- },
- })
- if err != nil {
- return nil, fmt.Errorf("ensure variant manual demo event config source: %w", err)
- }
- manualBuildLog := "多赛道联调 build 产物"
- manualBuild, err := s.UpsertEventConfigBuild(ctx, tx, UpsertEventConfigBuildParams{
- EventID: manualEventID,
- SourceID: manualSource.ID,
- BuildNo: 1,
- BuildStatus: "success",
- BuildLog: &manualBuildLog,
- Manifest: map[string]any{
- "schemaVersion": "1",
- "releaseId": "rel_demo_variant_manual_001",
- "version": "2026.04.01",
- "app": map[string]any{
- "id": "sample-variant-manual-001",
- "title": "领秀城公园多赛道挑战",
- },
- "map": map[string]any{
- "tiles": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/",
- "mapmeta": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/meta.json",
- },
- "preview": demoPreviewManifest("manual-variant"),
- "playfield": map[string]any{
- "kind": "course",
- "source": map[string]any{
- "type": "kml",
- "url": "https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route04.kml",
- },
- },
- "game": map[string]any{
- "mode": "classic-sequential",
- },
- "play": map[string]any{
- "assignmentMode": "manual",
- "courseVariants": []map[string]any{
- {"id": "variant_a", "name": "路线 01", "description": "route01.kml", "routeCode": "route-variant-a", "selectable": true},
- {"id": "variant_b", "name": "路线 02", "description": "route02.kml", "routeCode": "route-variant-b", "selectable": true},
- {"id": "variant_c", "name": "路线 03", "description": "route03.kml", "routeCode": "route-variant-c", "selectable": true},
- {"id": "variant_d", "name": "路线 04", "description": "route04.kml", "routeCode": "route-variant-d", "selectable": true},
- },
- },
- "assets": map[string]any{
- "contentHtml": "https://oss-mbh5.colormaprun.com/gotomars/event/content-h5-test-template.html",
- },
- },
- AssetIndex: []map[string]any{
- {"assetType": "manifest", "assetKey": "manifest"},
- {"assetType": "mapmeta", "assetKey": "mapmeta"},
- {"assetType": "playfield", "assetKey": "playfield-kml"},
- {"assetType": "content_html", "assetKey": "content-html"},
- },
- })
- if err != nil {
- return nil, fmt.Errorf("ensure variant manual demo event config build: %w", err)
- }
- if err := s.AttachBuildToRelease(ctx, tx, manualReleaseRow.ID, manualBuild.ID); err != nil {
- return nil, fmt.Errorf("attach variant manual demo build to release: %w", err)
- }
- var manualCourseSetID, manualCourseSetPublicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_sets (
- course_set_public_id, place_id, map_asset_id, code, mode, name, status
- )
- VALUES (
- 'cset_demo_variant_manual_001', $1, $2, 'cset-demo-variant-manual-001', 'classic-sequential', '多赛道挑战赛道集', 'active'
- )
- ON CONFLICT (code) DO UPDATE SET
- place_id = EXCLUDED.place_id,
- map_asset_id = EXCLUDED.map_asset_id,
- mode = EXCLUDED.mode,
- name = EXCLUDED.name,
- status = EXCLUDED.status
- RETURNING id, course_set_public_id
- `, placeID, mapAssetID).Scan(&manualCourseSetID, &manualCourseSetPublicID); err != nil {
- return nil, fmt.Errorf("ensure variant manual demo course set: %w", err)
- }
- var manualCourseSourceAID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_sources (
- course_source_public_id, source_type, file_url, import_status
- )
- VALUES (
- 'csource_demo_variant_manual_a', 'kml', 'https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route01.kml', 'imported'
- )
- ON CONFLICT (course_source_public_id) DO UPDATE SET
- source_type = EXCLUDED.source_type,
- file_url = EXCLUDED.file_url,
- import_status = EXCLUDED.import_status
- RETURNING id
- `).Scan(&manualCourseSourceAID); err != nil {
- return nil, fmt.Errorf("ensure variant manual demo source a: %w", err)
- }
- var manualCourseSourceBID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_sources (
- course_source_public_id, source_type, file_url, import_status
- )
- VALUES (
- 'csource_demo_variant_manual_b', 'kml', 'https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route02.kml', 'imported'
- )
- ON CONFLICT (course_source_public_id) DO UPDATE SET
- source_type = EXCLUDED.source_type,
- file_url = EXCLUDED.file_url,
- import_status = EXCLUDED.import_status
- RETURNING id
- `).Scan(&manualCourseSourceBID); err != nil {
- return nil, fmt.Errorf("ensure variant manual demo source b: %w", err)
- }
- var manualCourseSourceCID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_sources (
- course_source_public_id, source_type, file_url, import_status
- )
- VALUES (
- 'csource_demo_variant_manual_c', 'kml', 'https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route03.kml', 'imported'
- )
- ON CONFLICT (course_source_public_id) DO UPDATE SET
- source_type = EXCLUDED.source_type,
- file_url = EXCLUDED.file_url,
- import_status = EXCLUDED.import_status
- RETURNING id
- `).Scan(&manualCourseSourceCID); err != nil {
- return nil, fmt.Errorf("ensure variant manual demo source c: %w", err)
- }
- var manualCourseSourceDID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_sources (
- course_source_public_id, source_type, file_url, import_status
- )
- VALUES (
- 'csource_demo_variant_manual_d', 'kml', 'https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route04.kml', 'imported'
- )
- ON CONFLICT (course_source_public_id) DO UPDATE SET
- source_type = EXCLUDED.source_type,
- file_url = EXCLUDED.file_url,
- import_status = EXCLUDED.import_status
- RETURNING id
- `).Scan(&manualCourseSourceDID); err != nil {
- return nil, fmt.Errorf("ensure variant manual demo source d: %w", err)
- }
- var manualVariantAID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_variants (
- course_variant_public_id, course_set_id, source_id, name, route_code, mode, control_count, status, is_default
- )
- VALUES (
- 'cvariant_demo_variant_manual_a', $1, $2, '多赛道 路线 01', 'route-variant-a', 'classic-sequential', 10, 'active', false
- )
- ON CONFLICT (course_variant_public_id) DO UPDATE SET
- course_set_id = EXCLUDED.course_set_id,
- source_id = EXCLUDED.source_id,
- name = EXCLUDED.name,
- route_code = EXCLUDED.route_code,
- mode = EXCLUDED.mode,
- control_count = EXCLUDED.control_count,
- status = EXCLUDED.status,
- is_default = EXCLUDED.is_default
- RETURNING id
- `, manualCourseSetID, manualCourseSourceAID).Scan(&manualVariantAID); err != nil {
- return nil, fmt.Errorf("ensure variant manual demo variant a: %w", err)
- }
- var manualVariantBID, manualVariantBPublicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_variants (
- course_variant_public_id, course_set_id, source_id, name, route_code, mode, control_count, status, is_default
- )
- VALUES (
- 'cvariant_demo_variant_manual_b', $1, $2, '多赛道 路线 02', 'route-variant-b', 'classic-sequential', 10, 'active', false
- )
- ON CONFLICT (course_variant_public_id) DO UPDATE SET
- course_set_id = EXCLUDED.course_set_id,
- source_id = EXCLUDED.source_id,
- name = EXCLUDED.name,
- route_code = EXCLUDED.route_code,
- mode = EXCLUDED.mode,
- control_count = EXCLUDED.control_count,
- status = EXCLUDED.status,
- is_default = EXCLUDED.is_default
- RETURNING id, course_variant_public_id
- `, manualCourseSetID, manualCourseSourceBID).Scan(&manualVariantBID, &manualVariantBPublicID); err != nil {
- return nil, fmt.Errorf("ensure variant manual demo variant b: %w", err)
- }
- var manualVariantCID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_variants (
- course_variant_public_id, course_set_id, source_id, name, route_code, mode, control_count, status, is_default
- )
- VALUES (
- 'cvariant_demo_variant_manual_c', $1, $2, '多赛道 路线 03', 'route-variant-c', 'classic-sequential', 10, 'active', false
- )
- ON CONFLICT (course_variant_public_id) DO UPDATE SET
- course_set_id = EXCLUDED.course_set_id,
- source_id = EXCLUDED.source_id,
- name = EXCLUDED.name,
- route_code = EXCLUDED.route_code,
- mode = EXCLUDED.mode,
- control_count = EXCLUDED.control_count,
- status = EXCLUDED.status,
- is_default = EXCLUDED.is_default
- RETURNING id
- `, manualCourseSetID, manualCourseSourceCID).Scan(&manualVariantCID); err != nil {
- return nil, fmt.Errorf("ensure variant manual demo variant c: %w", err)
- }
- var manualVariantDID, manualVariantDPublicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_variants (
- course_variant_public_id, course_set_id, source_id, name, route_code, mode, control_count, status, is_default
- )
- VALUES (
- 'cvariant_demo_variant_manual_d', $1, $2, '多赛道 路线 04', 'route-variant-d', 'classic-sequential', 10, 'active', true
- )
- ON CONFLICT (course_variant_public_id) DO UPDATE SET
- course_set_id = EXCLUDED.course_set_id,
- source_id = EXCLUDED.source_id,
- name = EXCLUDED.name,
- route_code = EXCLUDED.route_code,
- mode = EXCLUDED.mode,
- control_count = EXCLUDED.control_count,
- status = EXCLUDED.status,
- is_default = EXCLUDED.is_default
- RETURNING id, course_variant_public_id
- `, manualCourseSetID, manualCourseSourceDID).Scan(&manualVariantDID, &manualVariantDPublicID); err != nil {
- return nil, fmt.Errorf("ensure variant manual demo variant d: %w", err)
- }
- if _, err := tx.Exec(ctx, `
- UPDATE course_sets
- SET current_variant_id = $2
- WHERE id = $1
- `, manualCourseSetID, manualVariantDID); err != nil {
- return nil, fmt.Errorf("attach variant manual demo course variant: %w", err)
- }
- var manualRuntimeBindingID, manualRuntimeBindingPublicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO map_runtime_bindings (
- runtime_binding_public_id, event_id, place_id, map_asset_id, tile_release_id, course_set_id, course_variant_id, status, notes
- )
- VALUES (
- 'runtime_demo_variant_manual_001', $1, $2, $3, $4, $5, $6, 'active', '多赛道联调运行绑定'
- )
- ON CONFLICT (runtime_binding_public_id) DO UPDATE SET
- event_id = EXCLUDED.event_id,
- place_id = EXCLUDED.place_id,
- map_asset_id = EXCLUDED.map_asset_id,
- tile_release_id = EXCLUDED.tile_release_id,
- course_set_id = EXCLUDED.course_set_id,
- course_variant_id = EXCLUDED.course_variant_id,
- status = EXCLUDED.status,
- notes = EXCLUDED.notes
- RETURNING id, runtime_binding_public_id
- `, manualEventID, placeID, mapAssetID, tileReleaseID, manualCourseSetID, manualVariantDID).Scan(&manualRuntimeBindingID, &manualRuntimeBindingPublicID); err != nil {
- return nil, fmt.Errorf("ensure variant manual demo runtime binding: %w", err)
- }
- manualPresentationID, _, err := s.upsertDemoEventPresentation(ctx, tx, manualEventID, upsertDemoEventPresentationParams{
- PublicID: "pres_demo_variant_manual_001",
- Code: "event-detail-manual-variant",
- Name: "多赛道详情展示",
- PresentationType: "detail",
- TemplateKey: "event.detail.multi-variant",
- Version: "v2026-04-07-manual",
- Title: "领秀城公园多赛道挑战展示定义",
- })
- if err != nil {
- return nil, fmt.Errorf("ensure variant manual presentation: %w", err)
- }
- manualBundleID, _, err := s.upsertDemoContentBundle(ctx, tx, manualEventID, upsertDemoContentBundleParams{
- PublicID: "bundle_demo_variant_manual_001",
- Code: "result-media-manual",
- Name: "多赛道结果内容包",
- BundleType: "result_media",
- Version: "v2026-04-07-manual",
- ManifestURL: "https://api.gotomars.xyz/dev/demo-assets/content-manifests/manual",
- AssetRootURL: "https://oss-mbh5.colormaprun.com/gotomars/event/",
- })
- if err != nil {
- return nil, fmt.Errorf("ensure variant manual content bundle: %w", err)
- }
- if err := s.SetEventDefaultBindings(ctx, tx, SetEventDefaultBindingsParams{
- EventID: manualEventID,
- PresentationID: &manualPresentationID,
- ContentBundleID: &manualBundleID,
- RuntimeBindingID: &manualRuntimeBindingID,
- UpdatePresentation: true,
- UpdateContent: true,
- UpdateRuntime: true,
- }); err != nil {
- return nil, fmt.Errorf("set variant manual default bindings: %w", err)
- }
- if err := s.SetEventReleaseBindings(ctx, tx, manualReleaseRow.ID, &manualRuntimeBindingID, &manualPresentationID, &manualBundleID); err != nil {
- return nil, fmt.Errorf("bind variant manual release defaults: %w", err)
- }
- var scoreOEventID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO events (
- tenant_id, event_public_id, slug, display_name, summary, status, is_default_experience, show_in_event_list
- )
- VALUES ($1, 'evt_demo_score_o_001', 'city-park-score-o', '领秀城公园积分赛', '积分赛联调样例活动', 'active', false, true)
- ON CONFLICT (event_public_id) DO UPDATE SET
- tenant_id = EXCLUDED.tenant_id,
- slug = EXCLUDED.slug,
- display_name = EXCLUDED.display_name,
- summary = EXCLUDED.summary,
- status = EXCLUDED.status,
- is_default_experience = EXCLUDED.is_default_experience,
- show_in_event_list = EXCLUDED.show_in_event_list
- RETURNING id
- `, tenantID).Scan(&scoreOEventID); err != nil {
- return nil, fmt.Errorf("ensure score-o demo event: %w", err)
- }
- var scoreOReleaseRow struct {
- ID string
- PublicID string
- }
- if err := tx.QueryRow(ctx, `
- INSERT INTO event_releases (
- release_public_id,
- event_id,
- release_no,
- config_label,
- manifest_url,
- manifest_checksum_sha256,
- route_code,
- status,
- payload_jsonb
- )
- VALUES (
- 'rel_demo_score_o_001',
- $1,
- 1,
- '积分赛联调配置 v1',
- 'https://api.gotomars.xyz/dev/demo-assets/manifests/score-o',
- 'demo-score-o-checksum-001',
- 'route-score-o-001',
- 'published',
- $2::jsonb
- )
- ON CONFLICT (release_public_id) DO UPDATE SET
- event_id = EXCLUDED.event_id,
- config_label = EXCLUDED.config_label,
- manifest_url = EXCLUDED.manifest_url,
- manifest_checksum_sha256 = EXCLUDED.manifest_checksum_sha256,
- route_code = EXCLUDED.route_code,
- status = EXCLUDED.status,
- payload_jsonb = EXCLUDED.payload_jsonb
- RETURNING id, release_public_id
- `, scoreOEventID, `{
- "schemaVersion": "1",
- "preview": {
- "mode": "control-set-preview",
- "baseTiles": {
- "tileBaseUrl": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/",
- "zoom": 16,
- "tileSize": 256
- },
- "viewport": {
- "width": 375,
- "height": 220,
- "minLon": 117.1001,
- "minLat": 36.6501,
- "maxLon": 117.1098,
- "maxLat": 36.6584
- },
- "selectedVariantId": "score_main",
- "variants": [
- {
- "id": "score_main",
- "name": "积分赛标准赛道",
- "controls": [
- {"id": "41", "code": "41", "lon": 117.1015, "lat": 36.6516},
- {"id": "42", "code": "42", "lon": 117.1042, "lat": 36.6527},
- {"id": "43", "code": "43", "lon": 117.1065, "lat": 36.6548},
- {"id": "44", "code": "44", "lon": 117.1082, "lat": 36.6569}
- ],
- "legs": [
- {"from": "41", "to": "42"},
- {"from": "42", "to": "43"},
- {"from": "43", "to": "44"}
- ]
- }
- ]
- },
- "playfield": {
- "kind": "control-set"
- },
- "game": {
- "mode": "score-o"
- }
- }`).Scan(&scoreOReleaseRow.ID, &scoreOReleaseRow.PublicID); err != nil {
- return nil, fmt.Errorf("ensure score-o demo release: %w", err)
- }
- if _, err := tx.Exec(ctx, `
- UPDATE events
- SET current_release_id = $2
- WHERE id = $1
- `, scoreOEventID, scoreOReleaseRow.ID); err != nil {
- return nil, fmt.Errorf("attach score-o demo release: %w", err)
- }
- scoreOSourceNotes := "积分赛联调 source 配置"
- scoreOSource, err := s.UpsertEventConfigSource(ctx, tx, UpsertEventConfigSourceParams{
- EventID: scoreOEventID,
- SourceVersionNo: 1,
- SourceKind: "event_bundle",
- SchemaID: "event-source",
- SchemaVersion: "1",
- Status: "active",
- Notes: &scoreOSourceNotes,
- Source: map[string]any{
- "schemaVersion": "1",
- "app": map[string]any{
- "id": "sample-score-o-001",
- "title": "领秀城公园积分赛",
- },
- "branding": map[string]any{
- "tenantCode": "tenant_demo",
- "entryChannel": "mini-demo",
- },
- "map": map[string]any{
- "tiles": "../map/lxcb-001/tiles/",
- "mapmeta": "../map/lxcb-001/tiles/meta.json",
- },
- "preview": demoPreviewManifest("score-o"),
- "playfield": map[string]any{
- "kind": "control-set",
- "source": map[string]any{
- "type": "kml",
- "url": "../kml/lxcb-001/10/c01.kml",
- },
- },
- "game": map[string]any{
- "mode": "score-o",
- },
- "content": map[string]any{
- "h5Template": "content-h5-test-template.html",
- },
- },
- })
- if err != nil {
- return nil, fmt.Errorf("ensure score-o demo event config source: %w", err)
- }
- scoreOBuildLog := "积分赛联调 build 产物"
- scoreOBuild, err := s.UpsertEventConfigBuild(ctx, tx, UpsertEventConfigBuildParams{
- EventID: scoreOEventID,
- SourceID: scoreOSource.ID,
- BuildNo: 1,
- BuildStatus: "success",
- BuildLog: &scoreOBuildLog,
- Manifest: map[string]any{
- "schemaVersion": "1",
- "releaseId": "rel_demo_score_o_001",
- "version": "2026.04.01",
- "app": map[string]any{
- "id": "sample-score-o-001",
- "title": "领秀城公园积分赛",
- },
- "map": map[string]any{
- "tiles": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/",
- "mapmeta": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/meta.json",
- },
- "preview": demoPreviewManifest("score-o"),
- "playfield": map[string]any{
- "kind": "control-set",
- "source": map[string]any{
- "type": "kml",
- "url": "https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/10/c01.kml",
- },
- },
- "game": map[string]any{
- "mode": "score-o",
- },
- "assets": map[string]any{
- "contentHtml": "https://oss-mbh5.colormaprun.com/gotomars/event/content-h5-test-template.html",
- },
- },
- AssetIndex: []map[string]any{
- {"assetType": "manifest", "assetKey": "manifest"},
- {"assetType": "mapmeta", "assetKey": "mapmeta"},
- {"assetType": "playfield", "assetKey": "playfield-kml"},
- {"assetType": "content_html", "assetKey": "content-html"},
- },
- })
- if err != nil {
- return nil, fmt.Errorf("ensure score-o demo event config build: %w", err)
- }
- if err := s.AttachBuildToRelease(ctx, tx, scoreOReleaseRow.ID, scoreOBuild.ID); err != nil {
- return nil, fmt.Errorf("attach score-o demo build to release: %w", err)
- }
- var scoreOCardPublicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO cards (
- card_public_id,
- tenant_id,
- entry_channel_id,
- card_type,
- title,
- subtitle,
- cover_url,
- event_id,
- display_slot,
- display_priority,
- status,
- is_default_experience,
- starts_at,
- ends_at
- )
- VALUES (
- 'card_demo_score_o_001',
- $1,
- $2,
- 'event',
- '领秀城公园积分赛',
- '积分赛推荐入口',
- 'https://oss-mbh5.colormaprun.com/gotomars/assets/demo-cover.jpg',
- $3,
- 'home_primary',
- 98,
- 'active',
- false,
- NOW() - INTERVAL '1 day',
- NOW() + INTERVAL '30 day'
- )
- ON CONFLICT (card_public_id) DO UPDATE SET
- tenant_id = EXCLUDED.tenant_id,
- entry_channel_id = EXCLUDED.entry_channel_id,
- card_type = EXCLUDED.card_type,
- title = EXCLUDED.title,
- subtitle = EXCLUDED.subtitle,
- cover_url = EXCLUDED.cover_url,
- event_id = EXCLUDED.event_id,
- display_slot = EXCLUDED.display_slot,
- display_priority = EXCLUDED.display_priority,
- status = EXCLUDED.status,
- is_default_experience = EXCLUDED.is_default_experience,
- starts_at = EXCLUDED.starts_at,
- ends_at = EXCLUDED.ends_at
- RETURNING card_public_id
- `, tenantID, channelID, scoreOEventID).Scan(&scoreOCardPublicID); err != nil {
- return nil, fmt.Errorf("ensure score-o demo card: %w", err)
- }
- var scoreOCourseSetID, scoreOCourseSetPublicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_sets (
- course_set_public_id, place_id, map_asset_id, code, mode, name, status
- )
- VALUES (
- 'cset_demo_score_o_001', $1, $2, 'cset-demo-score-o-001', 'score-o', '积分赛标准赛道', 'active'
- )
- ON CONFLICT (code) DO UPDATE SET
- place_id = EXCLUDED.place_id,
- map_asset_id = EXCLUDED.map_asset_id,
- mode = EXCLUDED.mode,
- name = EXCLUDED.name,
- status = EXCLUDED.status
- RETURNING id, course_set_public_id
- `, placeID, mapAssetID).Scan(&scoreOCourseSetID, &scoreOCourseSetPublicID); err != nil {
- return nil, fmt.Errorf("ensure score-o demo course set: %w", err)
- }
- var scoreOCourseVariantID, scoreOCourseVariantPublicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO course_variants (
- course_variant_public_id, course_set_id, source_id, name, route_code, mode, control_count, status, is_default
- )
- VALUES (
- 'cvariant_demo_score_o_001', $1, $2, '积分赛主赛道', 'route-score-o-001', 'score-o', 10, 'active', true
- )
- ON CONFLICT (course_variant_public_id) DO UPDATE SET
- course_set_id = EXCLUDED.course_set_id,
- source_id = EXCLUDED.source_id,
- name = EXCLUDED.name,
- route_code = EXCLUDED.route_code,
- mode = EXCLUDED.mode,
- control_count = EXCLUDED.control_count,
- status = EXCLUDED.status,
- is_default = EXCLUDED.is_default
- RETURNING id, course_variant_public_id
- `, scoreOCourseSetID, courseSourceID).Scan(&scoreOCourseVariantID, &scoreOCourseVariantPublicID); err != nil {
- return nil, fmt.Errorf("ensure score-o demo course variant: %w", err)
- }
- if _, err := tx.Exec(ctx, `
- UPDATE course_sets
- SET current_variant_id = $2
- WHERE id = $1
- `, scoreOCourseSetID, scoreOCourseVariantID); err != nil {
- return nil, fmt.Errorf("attach score-o demo course variant: %w", err)
- }
- var scoreORuntimeBindingID, scoreORuntimeBindingPublicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO map_runtime_bindings (
- runtime_binding_public_id, event_id, place_id, map_asset_id, tile_release_id, course_set_id, course_variant_id, status, notes
- )
- VALUES (
- 'runtime_demo_score_o_001', $1, $2, $3, $4, $5, $6, 'active', '积分赛联调运行绑定'
- )
- ON CONFLICT (runtime_binding_public_id) DO UPDATE SET
- event_id = EXCLUDED.event_id,
- place_id = EXCLUDED.place_id,
- map_asset_id = EXCLUDED.map_asset_id,
- tile_release_id = EXCLUDED.tile_release_id,
- course_set_id = EXCLUDED.course_set_id,
- course_variant_id = EXCLUDED.course_variant_id,
- status = EXCLUDED.status,
- notes = EXCLUDED.notes
- RETURNING id, runtime_binding_public_id
- `, scoreOEventID, placeID, mapAssetID, tileReleaseID, scoreOCourseSetID, scoreOCourseVariantID).Scan(&scoreORuntimeBindingID, &scoreORuntimeBindingPublicID); err != nil {
- return nil, fmt.Errorf("ensure score-o demo runtime binding: %w", err)
- }
- scoreOPresentationID, _, err := s.upsertDemoEventPresentation(ctx, tx, scoreOEventID, upsertDemoEventPresentationParams{
- PublicID: "pres_demo_score_o_001",
- Code: "event-detail-score-o",
- Name: "积分赛详情展示",
- PresentationType: "detail",
- TemplateKey: "event.detail.score-o",
- Version: "v2026-04-07-score-o",
- Title: "领秀城公园积分赛展示定义",
- })
- if err != nil {
- return nil, fmt.Errorf("ensure score-o presentation: %w", err)
- }
- scoreOBundleID, _, err := s.upsertDemoContentBundle(ctx, tx, scoreOEventID, upsertDemoContentBundleParams{
- PublicID: "bundle_demo_score_o_001",
- Code: "result-media-score-o",
- Name: "积分赛结果内容包",
- BundleType: "result_media",
- Version: "v2026-04-07-score-o",
- ManifestURL: "https://api.gotomars.xyz/dev/demo-assets/content-manifests/score-o",
- AssetRootURL: "https://oss-mbh5.colormaprun.com/gotomars/event/",
- })
- if err != nil {
- return nil, fmt.Errorf("ensure score-o content bundle: %w", err)
- }
- if err := s.SetEventDefaultBindings(ctx, tx, SetEventDefaultBindingsParams{
- EventID: scoreOEventID,
- PresentationID: &scoreOPresentationID,
- ContentBundleID: &scoreOBundleID,
- RuntimeBindingID: &scoreORuntimeBindingID,
- UpdatePresentation: true,
- UpdateContent: true,
- UpdateRuntime: true,
- }); err != nil {
- return nil, fmt.Errorf("set score-o default bindings: %w", err)
- }
- if err := s.SetEventReleaseBindings(ctx, tx, scoreOReleaseRow.ID, &scoreORuntimeBindingID, &scoreOPresentationID, &scoreOBundleID); err != nil {
- return nil, fmt.Errorf("bind score-o release defaults: %w", err)
- }
- var cleanedSessionCount int64
- if err := tx.QueryRow(ctx, `
- WITH cleaned AS (
- UPDATE game_sessions
- SET
- status = 'cancelled',
- ended_at = NOW(),
- updated_at = NOW()
- WHERE event_id = ANY($1::uuid[])
- AND status IN ('launched', 'running')
- RETURNING 1
- )
- SELECT COUNT(*) FROM cleaned
- `, []string{eventID, scoreOEventID, manualEventID}).Scan(&cleanedSessionCount); err != nil {
- return nil, fmt.Errorf("cleanup demo ongoing sessions: %w", err)
- }
- if err := tx.Commit(ctx); err != nil {
- return nil, err
- }
- return &DemoBootstrapSummary{
- TenantCode: "tenant_demo",
- ChannelCode: "mini-demo",
- EventID: "evt_demo_001",
- ReleaseID: releaseRow.PublicID,
- SourceID: source.ID,
- BuildID: build.ID,
- CardID: cardPublicID,
- PlaceID: placePublicID,
- MapAssetID: mapAssetPublicID,
- TileReleaseID: tileReleasePublicID,
- CourseSourceID: courseSourcePublicID,
- CourseSetID: courseSetPublicID,
- CourseVariantID: courseVariantPublicID,
- RuntimeBindingID: runtimeBindingPublicID,
- ScoreOEventID: "evt_demo_score_o_001",
- ScoreOReleaseID: scoreOReleaseRow.PublicID,
- ScoreOCardID: scoreOCardPublicID,
- ScoreOSourceID: scoreOSource.ID,
- ScoreOBuildID: scoreOBuild.ID,
- ScoreOCourseSetID: scoreOCourseSetPublicID,
- ScoreOCourseVariantID: scoreOCourseVariantPublicID,
- ScoreORuntimeBindingID: scoreORuntimeBindingPublicID,
- VariantManualEventID: "evt_demo_variant_manual_001",
- VariantManualRelease: manualReleaseRow.PublicID,
- VariantManualCardID: manualCardPublicID,
- VariantManualSourceID: manualSource.ID,
- VariantManualBuildID: manualBuild.ID,
- VariantManualCourseSet: manualCourseSetPublicID,
- VariantManualVariantID: manualVariantDPublicID,
- VariantManualRuntimeID: manualRuntimeBindingPublicID,
- CleanedSessionCount: cleanedSessionCount,
- }, nil
- }
- type upsertDemoEventPresentationParams struct {
- PublicID string
- Code string
- Name string
- PresentationType string
- TemplateKey string
- Version string
- Title string
- }
- func (s *Store) upsertDemoEventPresentation(ctx context.Context, tx Tx, eventID string, params upsertDemoEventPresentationParams) (string, string, error) {
- var id string
- var publicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO event_presentations (
- presentation_public_id,
- event_id,
- code,
- name,
- presentation_type,
- status,
- is_default,
- schema_jsonb
- )
- VALUES ($1, $2, $3, $4, $5, 'active', true, $6::jsonb)
- ON CONFLICT (event_id, code) DO UPDATE SET
- presentation_public_id = EXCLUDED.presentation_public_id,
- name = EXCLUDED.name,
- presentation_type = EXCLUDED.presentation_type,
- status = EXCLUDED.status,
- is_default = EXCLUDED.is_default,
- schema_jsonb = EXCLUDED.schema_jsonb
- RETURNING id, presentation_public_id
- `, params.PublicID, eventID, params.Code, params.Name, params.PresentationType, fmt.Sprintf(`{"templateKey":"%s","version":"%s","title":"%s"}`, params.TemplateKey, params.Version, params.Title)).Scan(&id, &publicID); err != nil {
- return "", "", err
- }
- return id, publicID, nil
- }
- type upsertDemoContentBundleParams struct {
- PublicID string
- Code string
- Name string
- BundleType string
- Version string
- ManifestURL string
- AssetRootURL string
- }
- func (s *Store) upsertDemoContentBundle(ctx context.Context, tx Tx, eventID string, params upsertDemoContentBundleParams) (string, string, error) {
- var id string
- var publicID string
- if err := tx.QueryRow(ctx, `
- INSERT INTO content_bundles (
- content_bundle_public_id,
- event_id,
- code,
- name,
- status,
- is_default,
- entry_url,
- asset_root_url,
- metadata_jsonb
- )
- VALUES ($1, $2, $3, $4, 'active', true, $5, $6, $7::jsonb)
- ON CONFLICT (event_id, code) DO UPDATE SET
- content_bundle_public_id = EXCLUDED.content_bundle_public_id,
- name = EXCLUDED.name,
- status = EXCLUDED.status,
- is_default = EXCLUDED.is_default,
- entry_url = EXCLUDED.entry_url,
- asset_root_url = EXCLUDED.asset_root_url,
- metadata_jsonb = EXCLUDED.metadata_jsonb
- RETURNING id, content_bundle_public_id
- `, params.PublicID, eventID, params.Code, params.Name, params.ManifestURL, params.AssetRootURL, fmt.Sprintf(`{"bundleType":"%s","version":"%s"}`, params.BundleType, params.Version)).Scan(&id, &publicID); err != nil {
- return "", "", err
- }
- return id, publicID, nil
- }
- func demoPreviewManifest(kind string) map[string]any {
- baseTiles := map[string]any{
- "tileBaseUrl": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/",
- "zoom": 15,
- "tileSize": 256,
- }
- viewport := map[string]any{
- "width": 800,
- "height": 450,
- "minLon": 117.0000,
- "minLat": 36.6000,
- "maxLon": 117.0800,
- "maxLat": 36.6600,
- }
- switch kind {
- case "score-o":
- return map[string]any{
- "mode": "readonly",
- "baseTiles": baseTiles,
- "viewport": viewport,
- "selectedVariantId": "variant_score_main",
- "variants": []map[string]any{
- {
- "variantId": "variant_score_main",
- "name": "积分赛主赛道",
- "routeCode": "route-score-o-001",
- "controls": []map[string]any{
- {"id": "start", "kind": "start", "lon": 117.012, "lat": 36.612, "label": "起点"},
- {"id": "s1", "kind": "control", "lon": 117.021, "lat": 36.618, "label": "10分点"},
- {"id": "s2", "kind": "control", "lon": 117.034, "lat": 36.624, "label": "20分点"},
- {"id": "s3", "kind": "control", "lon": 117.046, "lat": 36.616, "label": "15分点"},
- {"id": "finish", "kind": "finish", "lon": 117.025, "lat": 36.606, "label": "终点"},
- },
- "legs": []map[string]any{
- {"from": "start", "to": "s1"},
- {"from": "s1", "to": "s2"},
- {"from": "s2", "to": "s3"},
- {"from": "s3", "to": "finish"},
- },
- },
- },
- }
- case "manual-variant":
- return map[string]any{
- "mode": "readonly",
- "baseTiles": baseTiles,
- "viewport": viewport,
- "selectedVariantId": "variant_d",
- "variants": []map[string]any{
- {
- "variantId": "variant_a",
- "name": "路线 01",
- "routeCode": "route-variant-a",
- "controls": []map[string]any{
- {"id": "1", "kind": "control", "lon": 117.000649296107, "lat": 36.5921631022497, "label": "1"},
- {"id": "2", "kind": "control", "lon": 116.999689737459, "lat": 36.5922740961347, "label": "2"},
- {"id": "3", "kind": "control", "lon": 116.999108309973, "lat": 36.5919019395375, "label": "3"},
- {"id": "4", "kind": "control", "lon": 116.999823913032, "lat": 36.591572220351, "label": "4"},
- {"id": "5", "kind": "control", "lon": 116.999860506371, "lat": 36.5912131186443, "label": "5"},
- {"id": "6", "kind": "control", "lon": 117.000340285695, "lat": 36.5909356298175, "label": "6"},
- {"id": "7", "kind": "control", "lon": 117.000441933857, "lat": 36.5915004001434, "label": "7"},
- {"id": "8", "kind": "control", "lon": 117.001397426578, "lat": 36.5915983367736, "label": "8"},
- {"id": "9", "kind": "control", "lon": 117.000665559813, "lat": 36.5919574366878, "label": "9"},
- {"id": "10", "kind": "control", "lon": 117.000649296107, "lat": 36.5921631022497, "label": "10"},
- },
- "legs": []map[string]any{
- {"from": "1", "to": "2"},
- {"from": "2", "to": "3"},
- {"from": "3", "to": "4"},
- {"from": "4", "to": "5"},
- {"from": "5", "to": "6"},
- {"from": "6", "to": "7"},
- {"from": "7", "to": "8"},
- {"from": "8", "to": "9"},
- {"from": "9", "to": "10"},
- },
- },
- {
- "variantId": "variant_b",
- "name": "路线 02",
- "routeCode": "route-variant-b",
- "controls": []map[string]any{
- {"id": "1", "kind": "control", "lon": 117.000649296107, "lat": 36.5921631022497, "label": "1"},
- {"id": "2", "kind": "control", "lon": 116.999766990062, "lat": 36.5921141343085, "label": "2"},
- {"id": "3", "kind": "control", "lon": 116.999710067091, "lat": 36.5917615642144, "label": "3"},
- {"id": "4", "kind": "control", "lon": 116.998774904002, "lat": 36.5913306430232, "label": "4"},
- {"id": "5", "kind": "control", "lon": 116.998941606987, "lat": 36.5908278985923, "label": "5"},
- {"id": "6", "kind": "control", "lon": 117.00058830721, "lat": 36.5905340853955, "label": "6"},
- {"id": "7", "kind": "control", "lon": 117.000238637533, "lat": 36.5914742836876, "label": "7"},
- {"id": "8", "kind": "control", "lon": 117.000937976887, "lat": 36.5916113949816, "label": "8"},
- {"id": "9", "kind": "control", "lon": 117.000803801313, "lat": 36.5919411140006, "label": "9"},
- {"id": "10", "kind": "control", "lon": 117.000649296107, "lat": 36.5921631022497, "label": "10"},
- },
- "legs": []map[string]any{
- {"from": "1", "to": "2"},
- {"from": "2", "to": "3"},
- {"from": "3", "to": "4"},
- {"from": "4", "to": "5"},
- {"from": "5", "to": "6"},
- {"from": "6", "to": "7"},
- {"from": "7", "to": "8"},
- {"from": "8", "to": "9"},
- {"from": "9", "to": "10"},
- },
- },
- {
- "variantId": "variant_c",
- "name": "路线 03",
- "routeCode": "route-variant-c",
- "controls": []map[string]any{
- {"id": "1", "kind": "control", "lon": 117.000649296107, "lat": 36.5921631022497, "label": "1"},
- {"id": "2", "kind": "control", "lon": 117.000665559813, "lat": 36.5919574366878, "label": "2"},
- {"id": "3", "kind": "control", "lon": 117.001397426578, "lat": 36.5915983367736, "label": "3"},
- {"id": "4", "kind": "control", "lon": 117.000441933857, "lat": 36.5915004001434, "label": "4"},
- {"id": "5", "kind": "control", "lon": 117.000340285695, "lat": 36.5909356298175, "label": "5"},
- {"id": "6", "kind": "control", "lon": 116.999860506371, "lat": 36.5912131186443, "label": "6"},
- {"id": "7", "kind": "control", "lon": 116.999823913032, "lat": 36.591572220351, "label": "7"},
- {"id": "8", "kind": "control", "lon": 116.999108309973, "lat": 36.5919019395375, "label": "8"},
- {"id": "9", "kind": "control", "lon": 116.999689737459, "lat": 36.5922740961347, "label": "9"},
- {"id": "10", "kind": "control", "lon": 117.000649296107, "lat": 36.5921631022497, "label": "10"},
- },
- "legs": []map[string]any{
- {"from": "1", "to": "2"},
- {"from": "2", "to": "3"},
- {"from": "3", "to": "4"},
- {"from": "4", "to": "5"},
- {"from": "5", "to": "6"},
- {"from": "6", "to": "7"},
- {"from": "7", "to": "8"},
- {"from": "8", "to": "9"},
- {"from": "9", "to": "10"},
- },
- },
- {
- "variantId": "variant_d",
- "name": "路线 04",
- "routeCode": "route-variant-d",
- "controls": []map[string]any{
- {"id": "1", "kind": "control", "lon": 117.000649296107, "lat": 36.5921631022497, "label": "1"},
- {"id": "2", "kind": "control", "lon": 117.000803801313, "lat": 36.5919411140006, "label": "2"},
- {"id": "3", "kind": "control", "lon": 117.000937976887, "lat": 36.5916113949816, "label": "3"},
- {"id": "4", "kind": "control", "lon": 117.000238637533, "lat": 36.5914742836876, "label": "4"},
- {"id": "5", "kind": "control", "lon": 117.00058830721, "lat": 36.5905340853955, "label": "5"},
- {"id": "6", "kind": "control", "lon": 116.998941606987, "lat": 36.5908278985923, "label": "6"},
- {"id": "7", "kind": "control", "lon": 116.998774904002, "lat": 36.5913306430232, "label": "7"},
- {"id": "8", "kind": "control", "lon": 116.999710067091, "lat": 36.5917615642144, "label": "8"},
- {"id": "9", "kind": "control", "lon": 116.999766990062, "lat": 36.5921141343085, "label": "9"},
- {"id": "10", "kind": "control", "lon": 117.000649296107, "lat": 36.5921631022497, "label": "10"},
- },
- "legs": []map[string]any{
- {"from": "1", "to": "2"},
- {"from": "2", "to": "3"},
- {"from": "3", "to": "4"},
- {"from": "4", "to": "5"},
- {"from": "5", "to": "6"},
- {"from": "6", "to": "7"},
- {"from": "7", "to": "8"},
- {"from": "8", "to": "9"},
- {"from": "9", "to": "10"},
- },
- },
- },
- }
- default:
- return map[string]any{
- "mode": "readonly",
- "baseTiles": baseTiles,
- "viewport": viewport,
- "selectedVariantId": "variant_classic_main",
- "variants": []map[string]any{
- {
- "variantId": "variant_classic_main",
- "name": "顺序赛主赛道",
- "routeCode": "route-demo-a",
- "controls": []map[string]any{
- {"id": "start", "kind": "start", "lon": 117.010, "lat": 36.610, "label": "起点"},
- {"id": "c1", "kind": "control", "lon": 117.018, "lat": 36.615, "label": "1"},
- {"id": "c2", "kind": "control", "lon": 117.027, "lat": 36.621, "label": "2"},
- {"id": "c3", "kind": "control", "lon": 117.036, "lat": 36.627, "label": "3"},
- {"id": "finish", "kind": "finish", "lon": 117.044, "lat": 36.632, "label": "终点"},
- },
- "legs": []map[string]any{
- {"from": "start", "to": "c1"},
- {"from": "c1", "to": "c2"},
- {"from": "c2", "to": "c3"},
- {"from": "c3", "to": "finish"},
- },
- },
- },
- }
- }
- }
|