dev_store.go 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993
  1. package postgres
  2. import (
  3. "context"
  4. "fmt"
  5. )
  6. type DemoBootstrapSummary struct {
  7. TenantCode string `json:"tenantCode"`
  8. ChannelCode string `json:"channelCode"`
  9. EventID string `json:"eventId"`
  10. ReleaseID string `json:"releaseId"`
  11. SourceID string `json:"sourceId"`
  12. BuildID string `json:"buildId"`
  13. CardID string `json:"cardId"`
  14. PlaceID string `json:"placeId"`
  15. MapAssetID string `json:"mapAssetId"`
  16. TileReleaseID string `json:"tileReleaseId"`
  17. CourseSourceID string `json:"courseSourceId"`
  18. CourseSetID string `json:"courseSetId"`
  19. CourseVariantID string `json:"courseVariantId"`
  20. RuntimeBindingID string `json:"runtimeBindingId"`
  21. ScoreOEventID string `json:"scoreOEventId"`
  22. ScoreOReleaseID string `json:"scoreOReleaseId"`
  23. ScoreOCardID string `json:"scoreOCardId"`
  24. ScoreOSourceID string `json:"scoreOSourceId"`
  25. ScoreOBuildID string `json:"scoreOBuildId"`
  26. ScoreOCourseSetID string `json:"scoreOCourseSetId"`
  27. ScoreOCourseVariantID string `json:"scoreOCourseVariantId"`
  28. ScoreORuntimeBindingID string `json:"scoreORuntimeBindingId"`
  29. VariantManualEventID string `json:"variantManualEventId"`
  30. VariantManualRelease string `json:"variantManualReleaseId"`
  31. VariantManualCardID string `json:"variantManualCardId"`
  32. VariantManualSourceID string `json:"variantManualSourceId"`
  33. VariantManualBuildID string `json:"variantManualBuildId"`
  34. VariantManualCourseSet string `json:"variantManualCourseSetId"`
  35. VariantManualVariantID string `json:"variantManualCourseVariantId"`
  36. VariantManualRuntimeID string `json:"variantManualRuntimeBindingId"`
  37. CleanedSessionCount int64 `json:"cleanedSessionCount"`
  38. }
  39. func (s *Store) EnsureDemoData(ctx context.Context) (*DemoBootstrapSummary, error) {
  40. tx, err := s.Begin(ctx)
  41. if err != nil {
  42. return nil, err
  43. }
  44. defer tx.Rollback(ctx)
  45. var tenantID string
  46. if err := tx.QueryRow(ctx, `
  47. INSERT INTO tenants (tenant_code, name, status)
  48. VALUES ('tenant_demo', '联调租户', 'active')
  49. ON CONFLICT (tenant_code) DO UPDATE SET
  50. name = EXCLUDED.name,
  51. status = EXCLUDED.status
  52. RETURNING id
  53. `).Scan(&tenantID); err != nil {
  54. return nil, fmt.Errorf("ensure demo tenant: %w", err)
  55. }
  56. var channelID string
  57. if err := tx.QueryRow(ctx, `
  58. INSERT INTO entry_channels (
  59. tenant_id, channel_code, channel_type, platform_app_id, display_name, status, is_default
  60. )
  61. VALUES ($1, 'mini-demo', 'wechat_mini', 'wx-demo-appid', '小程序联调入口', 'active', true)
  62. ON CONFLICT (tenant_id, channel_code) DO UPDATE SET
  63. channel_type = EXCLUDED.channel_type,
  64. platform_app_id = EXCLUDED.platform_app_id,
  65. display_name = EXCLUDED.display_name,
  66. status = EXCLUDED.status,
  67. is_default = EXCLUDED.is_default
  68. RETURNING id
  69. `, tenantID).Scan(&channelID); err != nil {
  70. return nil, fmt.Errorf("ensure demo entry channel: %w", err)
  71. }
  72. var eventID string
  73. if err := tx.QueryRow(ctx, `
  74. INSERT INTO events (
  75. tenant_id, event_public_id, slug, display_name, summary, status, is_default_experience, show_in_event_list
  76. )
  77. VALUES ($1, 'evt_demo_001', 'city-park-classic', '领秀城公园顺序赛', '顺序赛联调样例活动', 'active', true, true)
  78. ON CONFLICT (event_public_id) DO UPDATE SET
  79. tenant_id = EXCLUDED.tenant_id,
  80. slug = EXCLUDED.slug,
  81. display_name = EXCLUDED.display_name,
  82. summary = EXCLUDED.summary,
  83. status = EXCLUDED.status,
  84. is_default_experience = EXCLUDED.is_default_experience,
  85. show_in_event_list = EXCLUDED.show_in_event_list
  86. RETURNING id
  87. `, tenantID).Scan(&eventID); err != nil {
  88. return nil, fmt.Errorf("ensure demo event: %w", err)
  89. }
  90. var releaseRow struct {
  91. ID string
  92. PublicID string
  93. }
  94. if err := tx.QueryRow(ctx, `
  95. INSERT INTO event_releases (
  96. release_public_id,
  97. event_id,
  98. release_no,
  99. config_label,
  100. manifest_url,
  101. manifest_checksum_sha256,
  102. route_code,
  103. status,
  104. payload_jsonb
  105. )
  106. VALUES (
  107. 'rel_demo_001',
  108. $1,
  109. 1,
  110. '顺序赛联调配置 v1',
  111. 'https://api.gotomars.xyz/dev/demo-assets/manifests/classic',
  112. 'demo-checksum-001',
  113. 'route-demo-001',
  114. 'published',
  115. $2::jsonb
  116. )
  117. ON CONFLICT (release_public_id) DO UPDATE SET
  118. event_id = EXCLUDED.event_id,
  119. config_label = EXCLUDED.config_label,
  120. manifest_url = EXCLUDED.manifest_url,
  121. manifest_checksum_sha256 = EXCLUDED.manifest_checksum_sha256,
  122. route_code = EXCLUDED.route_code,
  123. status = EXCLUDED.status,
  124. payload_jsonb = EXCLUDED.payload_jsonb
  125. RETURNING id, release_public_id
  126. `, eventID, `{
  127. "schemaVersion": "1",
  128. "preview": {
  129. "mode": "course-preview",
  130. "baseTiles": {
  131. "tileBaseUrl": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/",
  132. "zoom": 16,
  133. "tileSize": 256
  134. },
  135. "viewport": {
  136. "width": 375,
  137. "height": 220,
  138. "minLon": 117.1001,
  139. "minLat": 36.6501,
  140. "maxLon": 117.1089,
  141. "maxLat": 36.6578
  142. },
  143. "selectedVariantId": "classic_main",
  144. "variants": [
  145. {
  146. "id": "classic_main",
  147. "name": "顺序赛主路线",
  148. "controls": [
  149. {"id": "31", "code": "31", "lon": 117.1012, "lat": 36.6512},
  150. {"id": "32", "code": "32", "lon": 117.1034, "lat": 36.6529},
  151. {"id": "33", "code": "33", "lon": 117.1052, "lat": 36.6541},
  152. {"id": "34", "code": "34", "lon": 117.1072, "lat": 36.6561}
  153. ],
  154. "legs": [
  155. {"from": "31", "to": "32"},
  156. {"from": "32", "to": "33"},
  157. {"from": "33", "to": "34"}
  158. ]
  159. }
  160. ]
  161. },
  162. "playfield": {
  163. "kind": "course"
  164. },
  165. "game": {
  166. "mode": "classic-sequential"
  167. }
  168. }`).Scan(&releaseRow.ID, &releaseRow.PublicID); err != nil {
  169. return nil, fmt.Errorf("ensure demo release: %w", err)
  170. }
  171. if _, err := tx.Exec(ctx, `
  172. UPDATE events
  173. SET current_release_id = $2
  174. WHERE id = $1
  175. `, eventID, releaseRow.ID); err != nil {
  176. return nil, fmt.Errorf("attach demo release: %w", err)
  177. }
  178. sourceNotes := "顺序赛联调 source 配置"
  179. source, err := s.UpsertEventConfigSource(ctx, tx, UpsertEventConfigSourceParams{
  180. EventID: eventID,
  181. SourceVersionNo: 1,
  182. SourceKind: "event_bundle",
  183. SchemaID: "event-source",
  184. SchemaVersion: "1",
  185. Status: "active",
  186. Notes: &sourceNotes,
  187. Source: map[string]any{
  188. "app": map[string]any{
  189. "id": "sample-classic-001",
  190. "title": "领秀城公园顺序赛",
  191. },
  192. "branding": map[string]any{
  193. "tenantCode": "tenant_demo",
  194. "entryChannel": "mini-demo",
  195. },
  196. "map": map[string]any{
  197. "tiles": "../map/lxcb-001/tiles/",
  198. "mapmeta": "../map/lxcb-001/tiles/meta.json",
  199. },
  200. "preview": demoPreviewManifest("classic"),
  201. "playfield": map[string]any{
  202. "kind": "course",
  203. "source": map[string]any{
  204. "type": "kml",
  205. "url": "https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route04.kml",
  206. },
  207. },
  208. "game": map[string]any{
  209. "mode": "classic-sequential",
  210. },
  211. "content": map[string]any{
  212. "h5Template": "content-h5-test-template.html",
  213. },
  214. },
  215. })
  216. if err != nil {
  217. return nil, fmt.Errorf("ensure demo event config source: %w", err)
  218. }
  219. buildLog := "顺序赛联调 build 产物"
  220. build, err := s.UpsertEventConfigBuild(ctx, tx, UpsertEventConfigBuildParams{
  221. EventID: eventID,
  222. SourceID: source.ID,
  223. BuildNo: 1,
  224. BuildStatus: "success",
  225. BuildLog: &buildLog,
  226. Manifest: map[string]any{
  227. "schemaVersion": "1",
  228. "releaseId": "rel_demo_001",
  229. "version": "2026.04.01",
  230. "app": map[string]any{
  231. "id": "sample-classic-001",
  232. "title": "领秀城公园顺序赛",
  233. },
  234. "map": map[string]any{
  235. "tiles": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/",
  236. "mapmeta": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/meta.json",
  237. },
  238. "preview": demoPreviewManifest("classic"),
  239. "playfield": map[string]any{
  240. "kind": "course",
  241. "source": map[string]any{
  242. "type": "kml",
  243. "url": "https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/10/c01.kml",
  244. },
  245. },
  246. "game": map[string]any{
  247. "mode": "classic-sequential",
  248. },
  249. "assets": map[string]any{
  250. "contentHtml": "https://oss-mbh5.colormaprun.com/gotomars/event/content-h5-test-template.html",
  251. },
  252. },
  253. AssetIndex: []map[string]any{
  254. {
  255. "assetType": "manifest",
  256. "assetKey": "manifest",
  257. },
  258. {
  259. "assetType": "mapmeta",
  260. "assetKey": "mapmeta",
  261. },
  262. {
  263. "assetType": "playfield",
  264. "assetKey": "playfield-kml",
  265. },
  266. {
  267. "assetType": "content_html",
  268. "assetKey": "content-html",
  269. },
  270. },
  271. })
  272. if err != nil {
  273. return nil, fmt.Errorf("ensure demo event config build: %w", err)
  274. }
  275. if err := s.AttachBuildToRelease(ctx, tx, releaseRow.ID, build.ID); err != nil {
  276. return nil, fmt.Errorf("attach demo build to release: %w", err)
  277. }
  278. tilesPath := "map/lxcb-001/tiles/"
  279. mapmetaPath := "map/lxcb-001/tiles/meta.json"
  280. playfieldPath := "kml/lxcb-001/10/c01.kml"
  281. contentPath := "event/content-h5-test-template.html"
  282. manifestChecksum := "demo-checksum-001"
  283. if err := s.ReplaceEventReleaseAssets(ctx, tx, releaseRow.ID, []UpsertEventReleaseAssetParams{
  284. {
  285. EventReleaseID: releaseRow.ID,
  286. AssetType: "manifest",
  287. AssetKey: "manifest",
  288. AssetURL: "https://api.gotomars.xyz/dev/demo-assets/manifests/classic",
  289. Checksum: &manifestChecksum,
  290. Meta: map[string]any{"source": "release-manifest"},
  291. },
  292. {
  293. EventReleaseID: releaseRow.ID,
  294. AssetType: "tiles",
  295. AssetKey: "tiles-root",
  296. AssetPath: &tilesPath,
  297. AssetURL: "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/",
  298. Meta: map[string]any{"kind": "directory"},
  299. },
  300. {
  301. EventReleaseID: releaseRow.ID,
  302. AssetType: "mapmeta",
  303. AssetKey: "mapmeta",
  304. AssetPath: &mapmetaPath,
  305. AssetURL: "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/meta.json",
  306. Meta: map[string]any{"format": "json"},
  307. },
  308. {
  309. EventReleaseID: releaseRow.ID,
  310. AssetType: "playfield",
  311. AssetKey: "course-kml",
  312. AssetPath: &playfieldPath,
  313. AssetURL: "https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/10/c01.kml",
  314. Meta: map[string]any{"format": "kml"},
  315. },
  316. {
  317. EventReleaseID: releaseRow.ID,
  318. AssetType: "content_html",
  319. AssetKey: "content-html",
  320. AssetPath: &contentPath,
  321. AssetURL: "https://oss-mbh5.colormaprun.com/gotomars/event/content-h5-test-template.html",
  322. Meta: map[string]any{"kind": "content-page"},
  323. },
  324. }); err != nil {
  325. return nil, fmt.Errorf("ensure demo event release assets: %w", err)
  326. }
  327. var cardPublicID string
  328. if err := tx.QueryRow(ctx, `
  329. INSERT INTO cards (
  330. card_public_id,
  331. tenant_id,
  332. entry_channel_id,
  333. card_type,
  334. title,
  335. subtitle,
  336. cover_url,
  337. event_id,
  338. display_slot,
  339. display_priority,
  340. status,
  341. is_default_experience,
  342. starts_at,
  343. ends_at
  344. )
  345. VALUES (
  346. 'card_demo_001',
  347. $1,
  348. $2,
  349. 'event',
  350. '领秀城公园顺序赛',
  351. '顺序赛推荐入口',
  352. 'https://oss-mbh5.colormaprun.com/gotomars/assets/demo-cover.jpg',
  353. $3,
  354. 'home_primary',
  355. 100,
  356. 'active',
  357. true,
  358. NOW() - INTERVAL '1 day',
  359. NOW() + INTERVAL '30 day'
  360. )
  361. ON CONFLICT (card_public_id) DO UPDATE SET
  362. tenant_id = EXCLUDED.tenant_id,
  363. entry_channel_id = EXCLUDED.entry_channel_id,
  364. card_type = EXCLUDED.card_type,
  365. title = EXCLUDED.title,
  366. subtitle = EXCLUDED.subtitle,
  367. cover_url = EXCLUDED.cover_url,
  368. event_id = EXCLUDED.event_id,
  369. display_slot = EXCLUDED.display_slot,
  370. display_priority = EXCLUDED.display_priority,
  371. status = EXCLUDED.status,
  372. is_default_experience = EXCLUDED.is_default_experience,
  373. starts_at = EXCLUDED.starts_at,
  374. ends_at = EXCLUDED.ends_at
  375. RETURNING card_public_id
  376. `, tenantID, channelID, eventID).Scan(&cardPublicID); err != nil {
  377. return nil, fmt.Errorf("ensure demo card: %w", err)
  378. }
  379. var placeID, placePublicID string
  380. if err := tx.QueryRow(ctx, `
  381. INSERT INTO places (
  382. place_public_id, code, name, region, status
  383. )
  384. VALUES (
  385. 'place_demo_001', 'place-demo-001', '领秀城公园', 'Shanghai', 'active'
  386. )
  387. ON CONFLICT (code) DO UPDATE SET
  388. name = EXCLUDED.name,
  389. region = EXCLUDED.region,
  390. status = EXCLUDED.status
  391. RETURNING id, place_public_id
  392. `).Scan(&placeID, &placePublicID); err != nil {
  393. return nil, fmt.Errorf("ensure demo place: %w", err)
  394. }
  395. var mapAssetID, mapAssetPublicID string
  396. if err := tx.QueryRow(ctx, `
  397. INSERT INTO map_assets (
  398. map_asset_public_id, place_id, code, name, map_type, status
  399. )
  400. VALUES (
  401. 'mapasset_demo_001', $1, 'mapasset-demo-001', '领秀城公园基础底图', 'standard', 'active'
  402. )
  403. ON CONFLICT (code) DO UPDATE SET
  404. place_id = EXCLUDED.place_id,
  405. name = EXCLUDED.name,
  406. map_type = EXCLUDED.map_type,
  407. status = EXCLUDED.status
  408. RETURNING id, map_asset_public_id
  409. `, placeID).Scan(&mapAssetID, &mapAssetPublicID); err != nil {
  410. return nil, fmt.Errorf("ensure demo map asset: %w", err)
  411. }
  412. var tileReleaseID, tileReleasePublicID string
  413. if err := tx.QueryRow(ctx, `
  414. INSERT INTO tile_releases (
  415. tile_release_public_id, map_asset_id, version_code, status, tile_base_url, meta_url, published_at
  416. )
  417. VALUES (
  418. 'tile_demo_001', $1, 'v2026-04-03', 'published',
  419. 'https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/', 'https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/meta.json', NOW()
  420. )
  421. ON CONFLICT (map_asset_id, version_code) DO UPDATE SET
  422. status = EXCLUDED.status,
  423. tile_base_url = EXCLUDED.tile_base_url,
  424. meta_url = EXCLUDED.meta_url,
  425. published_at = EXCLUDED.published_at
  426. RETURNING id, tile_release_public_id
  427. `, mapAssetID).Scan(&tileReleaseID, &tileReleasePublicID); err != nil {
  428. return nil, fmt.Errorf("ensure demo tile release: %w", err)
  429. }
  430. if _, err := tx.Exec(ctx, `
  431. UPDATE map_assets
  432. SET current_tile_release_id = $2
  433. WHERE id = $1
  434. `, mapAssetID, tileReleaseID); err != nil {
  435. return nil, fmt.Errorf("attach demo tile release: %w", err)
  436. }
  437. var courseSourceID, courseSourcePublicID string
  438. if err := tx.QueryRow(ctx, `
  439. INSERT INTO course_sources (
  440. course_source_public_id, source_type, file_url, import_status
  441. )
  442. VALUES (
  443. 'csource_demo_001', 'kml', 'https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/10/c01.kml', 'imported'
  444. )
  445. ON CONFLICT (course_source_public_id) DO UPDATE SET
  446. source_type = EXCLUDED.source_type,
  447. file_url = EXCLUDED.file_url,
  448. import_status = EXCLUDED.import_status
  449. RETURNING id, course_source_public_id
  450. `).Scan(&courseSourceID, &courseSourcePublicID); err != nil {
  451. return nil, fmt.Errorf("ensure demo course source: %w", err)
  452. }
  453. var courseSourceVariantBID string
  454. if err := tx.QueryRow(ctx, `
  455. INSERT INTO course_sources (
  456. course_source_public_id, source_type, file_url, import_status
  457. )
  458. VALUES (
  459. 'csource_demo_002', 'kml', 'https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route02.kml', 'imported'
  460. )
  461. ON CONFLICT (course_source_public_id) DO UPDATE SET
  462. source_type = EXCLUDED.source_type,
  463. file_url = EXCLUDED.file_url,
  464. import_status = EXCLUDED.import_status
  465. RETURNING id, course_source_public_id
  466. `).Scan(&courseSourceVariantBID, new(string)); err != nil {
  467. return nil, fmt.Errorf("ensure demo course source variant b: %w", err)
  468. }
  469. var courseSourceVariantCID string
  470. if err := tx.QueryRow(ctx, `
  471. INSERT INTO course_sources (
  472. course_source_public_id, source_type, file_url, import_status
  473. )
  474. VALUES (
  475. 'csource_demo_003', 'kml', 'https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route03.kml', 'imported'
  476. )
  477. ON CONFLICT (course_source_public_id) DO UPDATE SET
  478. source_type = EXCLUDED.source_type,
  479. file_url = EXCLUDED.file_url,
  480. import_status = EXCLUDED.import_status
  481. RETURNING id, course_source_public_id
  482. `).Scan(&courseSourceVariantCID, new(string)); err != nil {
  483. return nil, fmt.Errorf("ensure demo course source variant c: %w", err)
  484. }
  485. var courseSourceVariantDID string
  486. if err := tx.QueryRow(ctx, `
  487. INSERT INTO course_sources (
  488. course_source_public_id, source_type, file_url, import_status
  489. )
  490. VALUES (
  491. 'csource_demo_004', 'kml', 'https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route04.kml', 'imported'
  492. )
  493. ON CONFLICT (course_source_public_id) DO UPDATE SET
  494. source_type = EXCLUDED.source_type,
  495. file_url = EXCLUDED.file_url,
  496. import_status = EXCLUDED.import_status
  497. RETURNING id, course_source_public_id
  498. `).Scan(&courseSourceVariantDID, new(string)); err != nil {
  499. return nil, fmt.Errorf("ensure demo course source variant d: %w", err)
  500. }
  501. var courseSetID, courseSetPublicID string
  502. if err := tx.QueryRow(ctx, `
  503. INSERT INTO course_sets (
  504. course_set_public_id, place_id, map_asset_id, code, mode, name, status
  505. )
  506. VALUES (
  507. 'cset_demo_001', $1, $2, 'cset-demo-001', 'classic-sequential', '顺序赛标准赛道', 'active'
  508. )
  509. ON CONFLICT (code) DO UPDATE SET
  510. place_id = EXCLUDED.place_id,
  511. map_asset_id = EXCLUDED.map_asset_id,
  512. mode = EXCLUDED.mode,
  513. name = EXCLUDED.name,
  514. status = EXCLUDED.status
  515. RETURNING id, course_set_public_id
  516. `, placeID, mapAssetID).Scan(&courseSetID, &courseSetPublicID); err != nil {
  517. return nil, fmt.Errorf("ensure demo course set: %w", err)
  518. }
  519. var courseVariantID, courseVariantPublicID string
  520. if err := tx.QueryRow(ctx, `
  521. INSERT INTO course_variants (
  522. course_variant_public_id, course_set_id, source_id, name, route_code, mode, control_count, status, is_default
  523. )
  524. VALUES (
  525. 'cvariant_demo_001', $1, $2, '顺序赛 A 线', 'route-demo-a', 'classic-sequential', 8, 'active', true
  526. )
  527. ON CONFLICT (course_variant_public_id) DO UPDATE SET
  528. course_set_id = EXCLUDED.course_set_id,
  529. source_id = EXCLUDED.source_id,
  530. name = EXCLUDED.name,
  531. route_code = EXCLUDED.route_code,
  532. mode = EXCLUDED.mode,
  533. control_count = EXCLUDED.control_count,
  534. status = EXCLUDED.status,
  535. is_default = EXCLUDED.is_default
  536. RETURNING id, course_variant_public_id
  537. `, courseSetID, courseSourceID).Scan(&courseVariantID, &courseVariantPublicID); err != nil {
  538. return nil, fmt.Errorf("ensure demo course variant: %w", err)
  539. }
  540. var courseVariantBID string
  541. if err := tx.QueryRow(ctx, `
  542. INSERT INTO course_variants (
  543. course_variant_public_id, course_set_id, source_id, name, route_code, mode, control_count, status, is_default
  544. )
  545. VALUES (
  546. 'cvariant_demo_002', $1, $2, '顺序赛 B 线', 'route-demo-b', 'classic-sequential', 10, 'active', false
  547. )
  548. ON CONFLICT (course_variant_public_id) DO UPDATE SET
  549. course_set_id = EXCLUDED.course_set_id,
  550. source_id = EXCLUDED.source_id,
  551. name = EXCLUDED.name,
  552. route_code = EXCLUDED.route_code,
  553. mode = EXCLUDED.mode,
  554. control_count = EXCLUDED.control_count,
  555. status = EXCLUDED.status,
  556. is_default = EXCLUDED.is_default
  557. RETURNING id, course_variant_public_id
  558. `, courseSetID, courseSourceVariantBID).Scan(&courseVariantBID, new(string)); err != nil {
  559. return nil, fmt.Errorf("ensure demo course variant b: %w", err)
  560. }
  561. if _, err := tx.Exec(ctx, `
  562. UPDATE course_sets
  563. SET current_variant_id = $2
  564. WHERE id = $1
  565. `, courseSetID, courseVariantID); err != nil {
  566. return nil, fmt.Errorf("attach demo course variant: %w", err)
  567. }
  568. var runtimeBindingID, runtimeBindingPublicID string
  569. if err := tx.QueryRow(ctx, `
  570. INSERT INTO map_runtime_bindings (
  571. runtime_binding_public_id, event_id, place_id, map_asset_id, tile_release_id, course_set_id, course_variant_id, status, notes
  572. )
  573. VALUES (
  574. 'runtime_demo_001', $1, $2, $3, $4, $5, $6, 'active', '顺序赛联调运行绑定'
  575. )
  576. ON CONFLICT (runtime_binding_public_id) DO UPDATE SET
  577. event_id = EXCLUDED.event_id,
  578. place_id = EXCLUDED.place_id,
  579. map_asset_id = EXCLUDED.map_asset_id,
  580. tile_release_id = EXCLUDED.tile_release_id,
  581. course_set_id = EXCLUDED.course_set_id,
  582. course_variant_id = EXCLUDED.course_variant_id,
  583. status = EXCLUDED.status,
  584. notes = EXCLUDED.notes
  585. RETURNING id, runtime_binding_public_id
  586. `, eventID, placeID, mapAssetID, tileReleaseID, courseSetID, courseVariantID).Scan(&runtimeBindingID, &runtimeBindingPublicID); err != nil {
  587. return nil, fmt.Errorf("ensure demo runtime binding: %w", err)
  588. }
  589. classicPresentationID, _, err := s.upsertDemoEventPresentation(ctx, tx, eventID, upsertDemoEventPresentationParams{
  590. PublicID: "pres_demo_001",
  591. Code: "event-detail-classic",
  592. Name: "顺序赛详情展示",
  593. PresentationType: "detail",
  594. TemplateKey: "event.detail.classic",
  595. Version: "v2026-04-07-classic",
  596. Title: "领秀城公园顺序赛展示定义",
  597. })
  598. if err != nil {
  599. return nil, fmt.Errorf("ensure demo presentation: %w", err)
  600. }
  601. classicBundleID, _, err := s.upsertDemoContentBundle(ctx, tx, eventID, upsertDemoContentBundleParams{
  602. PublicID: "bundle_demo_001",
  603. Code: "result-media-classic",
  604. Name: "顺序赛结果内容包",
  605. BundleType: "result_media",
  606. Version: "v2026-04-07-classic",
  607. ManifestURL: "https://api.gotomars.xyz/dev/demo-assets/content-manifests/classic",
  608. AssetRootURL: "https://oss-mbh5.colormaprun.com/gotomars/event/",
  609. })
  610. if err != nil {
  611. return nil, fmt.Errorf("ensure demo content bundle: %w", err)
  612. }
  613. if err := s.SetEventDefaultBindings(ctx, tx, SetEventDefaultBindingsParams{
  614. EventID: eventID,
  615. PresentationID: &classicPresentationID,
  616. ContentBundleID: &classicBundleID,
  617. RuntimeBindingID: &runtimeBindingID,
  618. UpdatePresentation: true,
  619. UpdateContent: true,
  620. UpdateRuntime: true,
  621. }); err != nil {
  622. return nil, fmt.Errorf("set demo default bindings: %w", err)
  623. }
  624. if err := s.SetEventReleaseBindings(ctx, tx, releaseRow.ID, &runtimeBindingID, &classicPresentationID, &classicBundleID); err != nil {
  625. return nil, fmt.Errorf("bind demo release defaults: %w", err)
  626. }
  627. var manualEventID string
  628. if err := tx.QueryRow(ctx, `
  629. INSERT INTO events (
  630. tenant_id, event_public_id, slug, display_name, summary, status, is_default_experience, show_in_event_list
  631. )
  632. VALUES ($1, 'evt_demo_variant_manual_001', 'city-park-manual-variant', '领秀城公园多赛道挑战', '手动多赛道联调样例活动', 'active', false, true)
  633. ON CONFLICT (event_public_id) DO UPDATE SET
  634. tenant_id = EXCLUDED.tenant_id,
  635. slug = EXCLUDED.slug,
  636. display_name = EXCLUDED.display_name,
  637. summary = EXCLUDED.summary,
  638. status = EXCLUDED.status,
  639. is_default_experience = EXCLUDED.is_default_experience,
  640. show_in_event_list = EXCLUDED.show_in_event_list
  641. RETURNING id
  642. `, tenantID).Scan(&manualEventID); err != nil {
  643. return nil, fmt.Errorf("ensure variant manual demo event: %w", err)
  644. }
  645. var manualReleaseRow struct {
  646. ID string
  647. PublicID string
  648. }
  649. if err := tx.QueryRow(ctx, `
  650. INSERT INTO event_releases (
  651. release_public_id,
  652. event_id,
  653. release_no,
  654. config_label,
  655. manifest_url,
  656. manifest_checksum_sha256,
  657. route_code,
  658. status,
  659. payload_jsonb
  660. )
  661. VALUES (
  662. 'rel_demo_variant_manual_001',
  663. $1,
  664. 1,
  665. '多赛道联调配置 v1',
  666. 'https://api.gotomars.xyz/dev/demo-assets/manifests/manual-variant',
  667. 'demo-variant-checksum-001',
  668. 'route-variant-d',
  669. 'published',
  670. $2::jsonb
  671. )
  672. ON CONFLICT (release_public_id) DO UPDATE SET
  673. event_id = EXCLUDED.event_id,
  674. config_label = EXCLUDED.config_label,
  675. manifest_url = EXCLUDED.manifest_url,
  676. manifest_checksum_sha256 = EXCLUDED.manifest_checksum_sha256,
  677. route_code = EXCLUDED.route_code,
  678. status = EXCLUDED.status,
  679. payload_jsonb = EXCLUDED.payload_jsonb
  680. RETURNING id, release_public_id
  681. `, manualEventID, `{
  682. "schemaVersion": "1",
  683. "preview": {
  684. "mode": "manual-variant-preview",
  685. "baseTiles": {
  686. "tileBaseUrl": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/",
  687. "zoom": 16,
  688. "tileSize": 256
  689. },
  690. "viewport": {
  691. "width": 375,
  692. "height": 220,
  693. "minLon": 117.1001,
  694. "minLat": 36.6501,
  695. "maxLon": 117.1112,
  696. "maxLat": 36.6593
  697. },
  698. "selectedVariantId": "variant_d",
  699. "variants": [
  700. {
  701. "id": "variant_a",
  702. "name": "路线 01",
  703. "routeCode": "route-variant-a",
  704. "controls": [
  705. {"id": "1", "code": "1", "lon": 117.000649296107, "lat": 36.5921631022497},
  706. {"id": "2", "code": "2", "lon": 116.999689737459, "lat": 36.5922740961347},
  707. {"id": "3", "code": "3", "lon": 116.999108309973, "lat": 36.5919019395375},
  708. {"id": "4", "code": "4", "lon": 116.999823913032, "lat": 36.591572220351},
  709. {"id": "5", "code": "5", "lon": 116.999860506371, "lat": 36.5912131186443},
  710. {"id": "6", "code": "6", "lon": 117.000340285695, "lat": 36.5909356298175},
  711. {"id": "7", "code": "7", "lon": 117.000441933857, "lat": 36.5915004001434},
  712. {"id": "8", "code": "8", "lon": 117.001397426578, "lat": 36.5915983367736},
  713. {"id": "9", "code": "9", "lon": 117.000665559813, "lat": 36.5919574366878},
  714. {"id": "10", "code": "10", "lon": 117.000649296107, "lat": 36.5921631022497}
  715. ],
  716. "legs": [
  717. {"from": "1", "to": "2"},
  718. {"from": "2", "to": "3"},
  719. {"from": "3", "to": "4"},
  720. {"from": "4", "to": "5"},
  721. {"from": "5", "to": "6"},
  722. {"from": "6", "to": "7"},
  723. {"from": "7", "to": "8"},
  724. {"from": "8", "to": "9"},
  725. {"from": "9", "to": "10"}
  726. ]
  727. },
  728. {
  729. "id": "variant_b",
  730. "name": "路线 02",
  731. "routeCode": "route-variant-b",
  732. "controls": [
  733. {"id": "1", "code": "1", "lon": 117.000649296107, "lat": 36.5921631022497},
  734. {"id": "2", "code": "2", "lon": 116.999766990062, "lat": 36.5921141343085},
  735. {"id": "3", "code": "3", "lon": 116.999710067091, "lat": 36.5917615642144},
  736. {"id": "4", "code": "4", "lon": 116.998774904002, "lat": 36.5913306430232},
  737. {"id": "5", "code": "5", "lon": 116.998941606987, "lat": 36.5908278985923},
  738. {"id": "6", "code": "6", "lon": 117.00058830721, "lat": 36.5905340853955},
  739. {"id": "7", "code": "7", "lon": 117.000238637533, "lat": 36.5914742836876},
  740. {"id": "8", "code": "8", "lon": 117.000937976887, "lat": 36.5916113949816},
  741. {"id": "9", "code": "9", "lon": 117.000803801313, "lat": 36.5919411140006},
  742. {"id": "10", "code": "10", "lon": 117.000649296107, "lat": 36.5921631022497}
  743. ],
  744. "legs": [
  745. {"from": "1", "to": "2"},
  746. {"from": "2", "to": "3"},
  747. {"from": "3", "to": "4"},
  748. {"from": "4", "to": "5"},
  749. {"from": "5", "to": "6"},
  750. {"from": "6", "to": "7"},
  751. {"from": "7", "to": "8"},
  752. {"from": "8", "to": "9"},
  753. {"from": "9", "to": "10"}
  754. ]
  755. },
  756. {
  757. "id": "variant_c",
  758. "name": "路线 03",
  759. "routeCode": "route-variant-c",
  760. "controls": [
  761. {"id": "1", "code": "1", "lon": 117.000649296107, "lat": 36.5921631022497},
  762. {"id": "2", "code": "2", "lon": 117.000665559813, "lat": 36.5919574366878},
  763. {"id": "3", "code": "3", "lon": 117.001397426578, "lat": 36.5915983367736},
  764. {"id": "4", "code": "4", "lon": 117.000441933857, "lat": 36.5915004001434},
  765. {"id": "5", "code": "5", "lon": 117.000340285695, "lat": 36.5909356298175},
  766. {"id": "6", "code": "6", "lon": 116.999860506371, "lat": 36.5912131186443},
  767. {"id": "7", "code": "7", "lon": 116.999823913032, "lat": 36.591572220351},
  768. {"id": "8", "code": "8", "lon": 116.999108309973, "lat": 36.5919019395375},
  769. {"id": "9", "code": "9", "lon": 116.999689737459, "lat": 36.5922740961347},
  770. {"id": "10", "code": "10", "lon": 117.000649296107, "lat": 36.5921631022497}
  771. ],
  772. "legs": [
  773. {"from": "1", "to": "2"},
  774. {"from": "2", "to": "3"},
  775. {"from": "3", "to": "4"},
  776. {"from": "4", "to": "5"},
  777. {"from": "5", "to": "6"},
  778. {"from": "6", "to": "7"},
  779. {"from": "7", "to": "8"},
  780. {"from": "8", "to": "9"},
  781. {"from": "9", "to": "10"}
  782. ]
  783. },
  784. {
  785. "id": "variant_d",
  786. "name": "路线 04",
  787. "routeCode": "route-variant-d",
  788. "controls": [
  789. {"id": "1", "code": "1", "lon": 117.000649296107, "lat": 36.5921631022497},
  790. {"id": "2", "code": "2", "lon": 117.000803801313, "lat": 36.5919411140006},
  791. {"id": "3", "code": "3", "lon": 117.000937976887, "lat": 36.5916113949816},
  792. {"id": "4", "code": "4", "lon": 117.000238637533, "lat": 36.5914742836876},
  793. {"id": "5", "code": "5", "lon": 117.00058830721, "lat": 36.5905340853955},
  794. {"id": "6", "code": "6", "lon": 116.998941606987, "lat": 36.5908278985923},
  795. {"id": "7", "code": "7", "lon": 116.998774904002, "lat": 36.5913306430232},
  796. {"id": "8", "code": "8", "lon": 116.999710067091, "lat": 36.5917615642144},
  797. {"id": "9", "code": "9", "lon": 116.999766990062, "lat": 36.5921141343085},
  798. {"id": "10", "code": "10", "lon": 117.000649296107, "lat": 36.5921631022497}
  799. ],
  800. "legs": [
  801. {"from": "1", "to": "2"},
  802. {"from": "2", "to": "3"},
  803. {"from": "3", "to": "4"},
  804. {"from": "4", "to": "5"},
  805. {"from": "5", "to": "6"},
  806. {"from": "6", "to": "7"},
  807. {"from": "7", "to": "8"},
  808. {"from": "8", "to": "9"},
  809. {"from": "9", "to": "10"}
  810. ]
  811. }
  812. ]
  813. },
  814. "playfield": {
  815. "kind": "course-set"
  816. },
  817. "game": {
  818. "mode": "classic-sequential"
  819. },
  820. "play": {
  821. "assignmentMode": "manual",
  822. "courseVariants": [
  823. {
  824. "id": "variant_a",
  825. "name": "路线 01",
  826. "description": "route01.kml",
  827. "routeCode": "route-variant-a",
  828. "selectable": true
  829. },
  830. {
  831. "id": "variant_b",
  832. "name": "路线 02",
  833. "description": "route02.kml",
  834. "routeCode": "route-variant-b",
  835. "selectable": true
  836. },
  837. {
  838. "id": "variant_c",
  839. "name": "路线 03",
  840. "description": "route03.kml",
  841. "routeCode": "route-variant-c",
  842. "selectable": true
  843. },
  844. {
  845. "id": "variant_d",
  846. "name": "路线 04",
  847. "description": "route04.kml",
  848. "routeCode": "route-variant-d",
  849. "selectable": true
  850. }
  851. ]
  852. }
  853. }`).Scan(&manualReleaseRow.ID, &manualReleaseRow.PublicID); err != nil {
  854. return nil, fmt.Errorf("ensure variant manual demo release: %w", err)
  855. }
  856. if _, err := tx.Exec(ctx, `
  857. UPDATE events
  858. SET current_release_id = $2
  859. WHERE id = $1
  860. `, manualEventID, manualReleaseRow.ID); err != nil {
  861. return nil, fmt.Errorf("attach variant manual demo release: %w", err)
  862. }
  863. var manualCardPublicID string
  864. if err := tx.QueryRow(ctx, `
  865. INSERT INTO cards (
  866. card_public_id,
  867. tenant_id,
  868. entry_channel_id,
  869. card_type,
  870. title,
  871. subtitle,
  872. cover_url,
  873. event_id,
  874. display_slot,
  875. display_priority,
  876. status,
  877. is_default_experience,
  878. starts_at,
  879. ends_at
  880. )
  881. VALUES (
  882. 'card_demo_variant_manual_001',
  883. $1,
  884. $2,
  885. 'event',
  886. '领秀城公园多赛道挑战',
  887. '手动选择赛道入口',
  888. 'https://oss-mbh5.colormaprun.com/gotomars/assets/demo-cover.jpg',
  889. $3,
  890. 'home_primary',
  891. 95,
  892. 'active',
  893. false,
  894. NOW() - INTERVAL '1 day',
  895. NOW() + INTERVAL '30 day'
  896. )
  897. ON CONFLICT (card_public_id) DO UPDATE SET
  898. tenant_id = EXCLUDED.tenant_id,
  899. entry_channel_id = EXCLUDED.entry_channel_id,
  900. card_type = EXCLUDED.card_type,
  901. title = EXCLUDED.title,
  902. subtitle = EXCLUDED.subtitle,
  903. cover_url = EXCLUDED.cover_url,
  904. event_id = EXCLUDED.event_id,
  905. display_slot = EXCLUDED.display_slot,
  906. display_priority = EXCLUDED.display_priority,
  907. status = EXCLUDED.status,
  908. is_default_experience = EXCLUDED.is_default_experience,
  909. starts_at = EXCLUDED.starts_at,
  910. ends_at = EXCLUDED.ends_at
  911. RETURNING card_public_id
  912. `, tenantID, channelID, manualEventID).Scan(&manualCardPublicID); err != nil {
  913. return nil, fmt.Errorf("ensure variant manual demo card: %w", err)
  914. }
  915. manualSourceNotes := "多赛道联调 source 配置"
  916. manualSource, err := s.UpsertEventConfigSource(ctx, tx, UpsertEventConfigSourceParams{
  917. EventID: manualEventID,
  918. SourceVersionNo: 1,
  919. SourceKind: "event_bundle",
  920. SchemaID: "event-source",
  921. SchemaVersion: "1",
  922. Status: "active",
  923. Notes: &manualSourceNotes,
  924. Source: map[string]any{
  925. "schemaVersion": "1",
  926. "app": map[string]any{
  927. "id": "sample-variant-manual-001",
  928. "title": "领秀城公园多赛道挑战",
  929. },
  930. "branding": map[string]any{
  931. "tenantCode": "tenant_demo",
  932. "entryChannel": "mini-demo",
  933. },
  934. "map": map[string]any{
  935. "tiles": "../map/lxcb-001/tiles/",
  936. "mapmeta": "../map/lxcb-001/tiles/meta.json",
  937. },
  938. "preview": demoPreviewManifest("manual-variant"),
  939. "playfield": map[string]any{
  940. "kind": "course",
  941. "source": map[string]any{
  942. "type": "kml",
  943. "url": "../kml/lxcb-001/10/c01.kml",
  944. },
  945. },
  946. "game": map[string]any{
  947. "mode": "classic-sequential",
  948. },
  949. "play": map[string]any{
  950. "assignmentMode": "manual",
  951. "courseVariants": []map[string]any{
  952. {"id": "variant_a", "name": "路线 01", "description": "route01.kml", "routeCode": "route-variant-a", "selectable": true},
  953. {"id": "variant_b", "name": "路线 02", "description": "route02.kml", "routeCode": "route-variant-b", "selectable": true},
  954. {"id": "variant_c", "name": "路线 03", "description": "route03.kml", "routeCode": "route-variant-c", "selectable": true},
  955. {"id": "variant_d", "name": "路线 04", "description": "route04.kml", "routeCode": "route-variant-d", "selectable": true},
  956. },
  957. },
  958. "content": map[string]any{
  959. "h5Template": "content-h5-test-template.html",
  960. },
  961. },
  962. })
  963. if err != nil {
  964. return nil, fmt.Errorf("ensure variant manual demo event config source: %w", err)
  965. }
  966. manualBuildLog := "多赛道联调 build 产物"
  967. manualBuild, err := s.UpsertEventConfigBuild(ctx, tx, UpsertEventConfigBuildParams{
  968. EventID: manualEventID,
  969. SourceID: manualSource.ID,
  970. BuildNo: 1,
  971. BuildStatus: "success",
  972. BuildLog: &manualBuildLog,
  973. Manifest: map[string]any{
  974. "schemaVersion": "1",
  975. "releaseId": "rel_demo_variant_manual_001",
  976. "version": "2026.04.01",
  977. "app": map[string]any{
  978. "id": "sample-variant-manual-001",
  979. "title": "领秀城公园多赛道挑战",
  980. },
  981. "map": map[string]any{
  982. "tiles": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/",
  983. "mapmeta": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/meta.json",
  984. },
  985. "preview": demoPreviewManifest("manual-variant"),
  986. "playfield": map[string]any{
  987. "kind": "course",
  988. "source": map[string]any{
  989. "type": "kml",
  990. "url": "https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route04.kml",
  991. },
  992. },
  993. "game": map[string]any{
  994. "mode": "classic-sequential",
  995. },
  996. "play": map[string]any{
  997. "assignmentMode": "manual",
  998. "courseVariants": []map[string]any{
  999. {"id": "variant_a", "name": "路线 01", "description": "route01.kml", "routeCode": "route-variant-a", "selectable": true},
  1000. {"id": "variant_b", "name": "路线 02", "description": "route02.kml", "routeCode": "route-variant-b", "selectable": true},
  1001. {"id": "variant_c", "name": "路线 03", "description": "route03.kml", "routeCode": "route-variant-c", "selectable": true},
  1002. {"id": "variant_d", "name": "路线 04", "description": "route04.kml", "routeCode": "route-variant-d", "selectable": true},
  1003. },
  1004. },
  1005. "assets": map[string]any{
  1006. "contentHtml": "https://oss-mbh5.colormaprun.com/gotomars/event/content-h5-test-template.html",
  1007. },
  1008. },
  1009. AssetIndex: []map[string]any{
  1010. {"assetType": "manifest", "assetKey": "manifest"},
  1011. {"assetType": "mapmeta", "assetKey": "mapmeta"},
  1012. {"assetType": "playfield", "assetKey": "playfield-kml"},
  1013. {"assetType": "content_html", "assetKey": "content-html"},
  1014. },
  1015. })
  1016. if err != nil {
  1017. return nil, fmt.Errorf("ensure variant manual demo event config build: %w", err)
  1018. }
  1019. if err := s.AttachBuildToRelease(ctx, tx, manualReleaseRow.ID, manualBuild.ID); err != nil {
  1020. return nil, fmt.Errorf("attach variant manual demo build to release: %w", err)
  1021. }
  1022. var manualCourseSetID, manualCourseSetPublicID string
  1023. if err := tx.QueryRow(ctx, `
  1024. INSERT INTO course_sets (
  1025. course_set_public_id, place_id, map_asset_id, code, mode, name, status
  1026. )
  1027. VALUES (
  1028. 'cset_demo_variant_manual_001', $1, $2, 'cset-demo-variant-manual-001', 'classic-sequential', '多赛道挑战赛道集', 'active'
  1029. )
  1030. ON CONFLICT (code) DO UPDATE SET
  1031. place_id = EXCLUDED.place_id,
  1032. map_asset_id = EXCLUDED.map_asset_id,
  1033. mode = EXCLUDED.mode,
  1034. name = EXCLUDED.name,
  1035. status = EXCLUDED.status
  1036. RETURNING id, course_set_public_id
  1037. `, placeID, mapAssetID).Scan(&manualCourseSetID, &manualCourseSetPublicID); err != nil {
  1038. return nil, fmt.Errorf("ensure variant manual demo course set: %w", err)
  1039. }
  1040. var manualCourseSourceAID string
  1041. if err := tx.QueryRow(ctx, `
  1042. INSERT INTO course_sources (
  1043. course_source_public_id, source_type, file_url, import_status
  1044. )
  1045. VALUES (
  1046. 'csource_demo_variant_manual_a', 'kml', 'https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route01.kml', 'imported'
  1047. )
  1048. ON CONFLICT (course_source_public_id) DO UPDATE SET
  1049. source_type = EXCLUDED.source_type,
  1050. file_url = EXCLUDED.file_url,
  1051. import_status = EXCLUDED.import_status
  1052. RETURNING id
  1053. `).Scan(&manualCourseSourceAID); err != nil {
  1054. return nil, fmt.Errorf("ensure variant manual demo source a: %w", err)
  1055. }
  1056. var manualCourseSourceBID string
  1057. if err := tx.QueryRow(ctx, `
  1058. INSERT INTO course_sources (
  1059. course_source_public_id, source_type, file_url, import_status
  1060. )
  1061. VALUES (
  1062. 'csource_demo_variant_manual_b', 'kml', 'https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route02.kml', 'imported'
  1063. )
  1064. ON CONFLICT (course_source_public_id) DO UPDATE SET
  1065. source_type = EXCLUDED.source_type,
  1066. file_url = EXCLUDED.file_url,
  1067. import_status = EXCLUDED.import_status
  1068. RETURNING id
  1069. `).Scan(&manualCourseSourceBID); err != nil {
  1070. return nil, fmt.Errorf("ensure variant manual demo source b: %w", err)
  1071. }
  1072. var manualCourseSourceCID string
  1073. if err := tx.QueryRow(ctx, `
  1074. INSERT INTO course_sources (
  1075. course_source_public_id, source_type, file_url, import_status
  1076. )
  1077. VALUES (
  1078. 'csource_demo_variant_manual_c', 'kml', 'https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route03.kml', 'imported'
  1079. )
  1080. ON CONFLICT (course_source_public_id) DO UPDATE SET
  1081. source_type = EXCLUDED.source_type,
  1082. file_url = EXCLUDED.file_url,
  1083. import_status = EXCLUDED.import_status
  1084. RETURNING id
  1085. `).Scan(&manualCourseSourceCID); err != nil {
  1086. return nil, fmt.Errorf("ensure variant manual demo source c: %w", err)
  1087. }
  1088. var manualCourseSourceDID string
  1089. if err := tx.QueryRow(ctx, `
  1090. INSERT INTO course_sources (
  1091. course_source_public_id, source_type, file_url, import_status
  1092. )
  1093. VALUES (
  1094. 'csource_demo_variant_manual_d', 'kml', 'https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/2026-04-07/route04.kml', 'imported'
  1095. )
  1096. ON CONFLICT (course_source_public_id) DO UPDATE SET
  1097. source_type = EXCLUDED.source_type,
  1098. file_url = EXCLUDED.file_url,
  1099. import_status = EXCLUDED.import_status
  1100. RETURNING id
  1101. `).Scan(&manualCourseSourceDID); err != nil {
  1102. return nil, fmt.Errorf("ensure variant manual demo source d: %w", err)
  1103. }
  1104. var manualVariantAID string
  1105. if err := tx.QueryRow(ctx, `
  1106. INSERT INTO course_variants (
  1107. course_variant_public_id, course_set_id, source_id, name, route_code, mode, control_count, status, is_default
  1108. )
  1109. VALUES (
  1110. 'cvariant_demo_variant_manual_a', $1, $2, '多赛道 路线 01', 'route-variant-a', 'classic-sequential', 10, 'active', false
  1111. )
  1112. ON CONFLICT (course_variant_public_id) DO UPDATE SET
  1113. course_set_id = EXCLUDED.course_set_id,
  1114. source_id = EXCLUDED.source_id,
  1115. name = EXCLUDED.name,
  1116. route_code = EXCLUDED.route_code,
  1117. mode = EXCLUDED.mode,
  1118. control_count = EXCLUDED.control_count,
  1119. status = EXCLUDED.status,
  1120. is_default = EXCLUDED.is_default
  1121. RETURNING id
  1122. `, manualCourseSetID, manualCourseSourceAID).Scan(&manualVariantAID); err != nil {
  1123. return nil, fmt.Errorf("ensure variant manual demo variant a: %w", err)
  1124. }
  1125. var manualVariantBID, manualVariantBPublicID string
  1126. if err := tx.QueryRow(ctx, `
  1127. INSERT INTO course_variants (
  1128. course_variant_public_id, course_set_id, source_id, name, route_code, mode, control_count, status, is_default
  1129. )
  1130. VALUES (
  1131. 'cvariant_demo_variant_manual_b', $1, $2, '多赛道 路线 02', 'route-variant-b', 'classic-sequential', 10, 'active', false
  1132. )
  1133. ON CONFLICT (course_variant_public_id) DO UPDATE SET
  1134. course_set_id = EXCLUDED.course_set_id,
  1135. source_id = EXCLUDED.source_id,
  1136. name = EXCLUDED.name,
  1137. route_code = EXCLUDED.route_code,
  1138. mode = EXCLUDED.mode,
  1139. control_count = EXCLUDED.control_count,
  1140. status = EXCLUDED.status,
  1141. is_default = EXCLUDED.is_default
  1142. RETURNING id, course_variant_public_id
  1143. `, manualCourseSetID, manualCourseSourceBID).Scan(&manualVariantBID, &manualVariantBPublicID); err != nil {
  1144. return nil, fmt.Errorf("ensure variant manual demo variant b: %w", err)
  1145. }
  1146. var manualVariantCID string
  1147. if err := tx.QueryRow(ctx, `
  1148. INSERT INTO course_variants (
  1149. course_variant_public_id, course_set_id, source_id, name, route_code, mode, control_count, status, is_default
  1150. )
  1151. VALUES (
  1152. 'cvariant_demo_variant_manual_c', $1, $2, '多赛道 路线 03', 'route-variant-c', 'classic-sequential', 10, 'active', false
  1153. )
  1154. ON CONFLICT (course_variant_public_id) DO UPDATE SET
  1155. course_set_id = EXCLUDED.course_set_id,
  1156. source_id = EXCLUDED.source_id,
  1157. name = EXCLUDED.name,
  1158. route_code = EXCLUDED.route_code,
  1159. mode = EXCLUDED.mode,
  1160. control_count = EXCLUDED.control_count,
  1161. status = EXCLUDED.status,
  1162. is_default = EXCLUDED.is_default
  1163. RETURNING id
  1164. `, manualCourseSetID, manualCourseSourceCID).Scan(&manualVariantCID); err != nil {
  1165. return nil, fmt.Errorf("ensure variant manual demo variant c: %w", err)
  1166. }
  1167. var manualVariantDID, manualVariantDPublicID string
  1168. if err := tx.QueryRow(ctx, `
  1169. INSERT INTO course_variants (
  1170. course_variant_public_id, course_set_id, source_id, name, route_code, mode, control_count, status, is_default
  1171. )
  1172. VALUES (
  1173. 'cvariant_demo_variant_manual_d', $1, $2, '多赛道 路线 04', 'route-variant-d', 'classic-sequential', 10, 'active', true
  1174. )
  1175. ON CONFLICT (course_variant_public_id) DO UPDATE SET
  1176. course_set_id = EXCLUDED.course_set_id,
  1177. source_id = EXCLUDED.source_id,
  1178. name = EXCLUDED.name,
  1179. route_code = EXCLUDED.route_code,
  1180. mode = EXCLUDED.mode,
  1181. control_count = EXCLUDED.control_count,
  1182. status = EXCLUDED.status,
  1183. is_default = EXCLUDED.is_default
  1184. RETURNING id, course_variant_public_id
  1185. `, manualCourseSetID, manualCourseSourceDID).Scan(&manualVariantDID, &manualVariantDPublicID); err != nil {
  1186. return nil, fmt.Errorf("ensure variant manual demo variant d: %w", err)
  1187. }
  1188. if _, err := tx.Exec(ctx, `
  1189. UPDATE course_sets
  1190. SET current_variant_id = $2
  1191. WHERE id = $1
  1192. `, manualCourseSetID, manualVariantDID); err != nil {
  1193. return nil, fmt.Errorf("attach variant manual demo course variant: %w", err)
  1194. }
  1195. var manualRuntimeBindingID, manualRuntimeBindingPublicID string
  1196. if err := tx.QueryRow(ctx, `
  1197. INSERT INTO map_runtime_bindings (
  1198. runtime_binding_public_id, event_id, place_id, map_asset_id, tile_release_id, course_set_id, course_variant_id, status, notes
  1199. )
  1200. VALUES (
  1201. 'runtime_demo_variant_manual_001', $1, $2, $3, $4, $5, $6, 'active', '多赛道联调运行绑定'
  1202. )
  1203. ON CONFLICT (runtime_binding_public_id) DO UPDATE SET
  1204. event_id = EXCLUDED.event_id,
  1205. place_id = EXCLUDED.place_id,
  1206. map_asset_id = EXCLUDED.map_asset_id,
  1207. tile_release_id = EXCLUDED.tile_release_id,
  1208. course_set_id = EXCLUDED.course_set_id,
  1209. course_variant_id = EXCLUDED.course_variant_id,
  1210. status = EXCLUDED.status,
  1211. notes = EXCLUDED.notes
  1212. RETURNING id, runtime_binding_public_id
  1213. `, manualEventID, placeID, mapAssetID, tileReleaseID, manualCourseSetID, manualVariantDID).Scan(&manualRuntimeBindingID, &manualRuntimeBindingPublicID); err != nil {
  1214. return nil, fmt.Errorf("ensure variant manual demo runtime binding: %w", err)
  1215. }
  1216. manualPresentationID, _, err := s.upsertDemoEventPresentation(ctx, tx, manualEventID, upsertDemoEventPresentationParams{
  1217. PublicID: "pres_demo_variant_manual_001",
  1218. Code: "event-detail-manual-variant",
  1219. Name: "多赛道详情展示",
  1220. PresentationType: "detail",
  1221. TemplateKey: "event.detail.multi-variant",
  1222. Version: "v2026-04-07-manual",
  1223. Title: "领秀城公园多赛道挑战展示定义",
  1224. })
  1225. if err != nil {
  1226. return nil, fmt.Errorf("ensure variant manual presentation: %w", err)
  1227. }
  1228. manualBundleID, _, err := s.upsertDemoContentBundle(ctx, tx, manualEventID, upsertDemoContentBundleParams{
  1229. PublicID: "bundle_demo_variant_manual_001",
  1230. Code: "result-media-manual",
  1231. Name: "多赛道结果内容包",
  1232. BundleType: "result_media",
  1233. Version: "v2026-04-07-manual",
  1234. ManifestURL: "https://api.gotomars.xyz/dev/demo-assets/content-manifests/manual",
  1235. AssetRootURL: "https://oss-mbh5.colormaprun.com/gotomars/event/",
  1236. })
  1237. if err != nil {
  1238. return nil, fmt.Errorf("ensure variant manual content bundle: %w", err)
  1239. }
  1240. if err := s.SetEventDefaultBindings(ctx, tx, SetEventDefaultBindingsParams{
  1241. EventID: manualEventID,
  1242. PresentationID: &manualPresentationID,
  1243. ContentBundleID: &manualBundleID,
  1244. RuntimeBindingID: &manualRuntimeBindingID,
  1245. UpdatePresentation: true,
  1246. UpdateContent: true,
  1247. UpdateRuntime: true,
  1248. }); err != nil {
  1249. return nil, fmt.Errorf("set variant manual default bindings: %w", err)
  1250. }
  1251. if err := s.SetEventReleaseBindings(ctx, tx, manualReleaseRow.ID, &manualRuntimeBindingID, &manualPresentationID, &manualBundleID); err != nil {
  1252. return nil, fmt.Errorf("bind variant manual release defaults: %w", err)
  1253. }
  1254. var scoreOEventID string
  1255. if err := tx.QueryRow(ctx, `
  1256. INSERT INTO events (
  1257. tenant_id, event_public_id, slug, display_name, summary, status, is_default_experience, show_in_event_list
  1258. )
  1259. VALUES ($1, 'evt_demo_score_o_001', 'city-park-score-o', '领秀城公园积分赛', '积分赛联调样例活动', 'active', false, true)
  1260. ON CONFLICT (event_public_id) DO UPDATE SET
  1261. tenant_id = EXCLUDED.tenant_id,
  1262. slug = EXCLUDED.slug,
  1263. display_name = EXCLUDED.display_name,
  1264. summary = EXCLUDED.summary,
  1265. status = EXCLUDED.status,
  1266. is_default_experience = EXCLUDED.is_default_experience,
  1267. show_in_event_list = EXCLUDED.show_in_event_list
  1268. RETURNING id
  1269. `, tenantID).Scan(&scoreOEventID); err != nil {
  1270. return nil, fmt.Errorf("ensure score-o demo event: %w", err)
  1271. }
  1272. var scoreOReleaseRow struct {
  1273. ID string
  1274. PublicID string
  1275. }
  1276. if err := tx.QueryRow(ctx, `
  1277. INSERT INTO event_releases (
  1278. release_public_id,
  1279. event_id,
  1280. release_no,
  1281. config_label,
  1282. manifest_url,
  1283. manifest_checksum_sha256,
  1284. route_code,
  1285. status,
  1286. payload_jsonb
  1287. )
  1288. VALUES (
  1289. 'rel_demo_score_o_001',
  1290. $1,
  1291. 1,
  1292. '积分赛联调配置 v1',
  1293. 'https://api.gotomars.xyz/dev/demo-assets/manifests/score-o',
  1294. 'demo-score-o-checksum-001',
  1295. 'route-score-o-001',
  1296. 'published',
  1297. $2::jsonb
  1298. )
  1299. ON CONFLICT (release_public_id) DO UPDATE SET
  1300. event_id = EXCLUDED.event_id,
  1301. config_label = EXCLUDED.config_label,
  1302. manifest_url = EXCLUDED.manifest_url,
  1303. manifest_checksum_sha256 = EXCLUDED.manifest_checksum_sha256,
  1304. route_code = EXCLUDED.route_code,
  1305. status = EXCLUDED.status,
  1306. payload_jsonb = EXCLUDED.payload_jsonb
  1307. RETURNING id, release_public_id
  1308. `, scoreOEventID, `{
  1309. "schemaVersion": "1",
  1310. "preview": {
  1311. "mode": "control-set-preview",
  1312. "baseTiles": {
  1313. "tileBaseUrl": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/",
  1314. "zoom": 16,
  1315. "tileSize": 256
  1316. },
  1317. "viewport": {
  1318. "width": 375,
  1319. "height": 220,
  1320. "minLon": 117.1001,
  1321. "minLat": 36.6501,
  1322. "maxLon": 117.1098,
  1323. "maxLat": 36.6584
  1324. },
  1325. "selectedVariantId": "score_main",
  1326. "variants": [
  1327. {
  1328. "id": "score_main",
  1329. "name": "积分赛标准赛道",
  1330. "controls": [
  1331. {"id": "41", "code": "41", "lon": 117.1015, "lat": 36.6516},
  1332. {"id": "42", "code": "42", "lon": 117.1042, "lat": 36.6527},
  1333. {"id": "43", "code": "43", "lon": 117.1065, "lat": 36.6548},
  1334. {"id": "44", "code": "44", "lon": 117.1082, "lat": 36.6569}
  1335. ],
  1336. "legs": [
  1337. {"from": "41", "to": "42"},
  1338. {"from": "42", "to": "43"},
  1339. {"from": "43", "to": "44"}
  1340. ]
  1341. }
  1342. ]
  1343. },
  1344. "playfield": {
  1345. "kind": "control-set"
  1346. },
  1347. "game": {
  1348. "mode": "score-o"
  1349. }
  1350. }`).Scan(&scoreOReleaseRow.ID, &scoreOReleaseRow.PublicID); err != nil {
  1351. return nil, fmt.Errorf("ensure score-o demo release: %w", err)
  1352. }
  1353. if _, err := tx.Exec(ctx, `
  1354. UPDATE events
  1355. SET current_release_id = $2
  1356. WHERE id = $1
  1357. `, scoreOEventID, scoreOReleaseRow.ID); err != nil {
  1358. return nil, fmt.Errorf("attach score-o demo release: %w", err)
  1359. }
  1360. scoreOSourceNotes := "积分赛联调 source 配置"
  1361. scoreOSource, err := s.UpsertEventConfigSource(ctx, tx, UpsertEventConfigSourceParams{
  1362. EventID: scoreOEventID,
  1363. SourceVersionNo: 1,
  1364. SourceKind: "event_bundle",
  1365. SchemaID: "event-source",
  1366. SchemaVersion: "1",
  1367. Status: "active",
  1368. Notes: &scoreOSourceNotes,
  1369. Source: map[string]any{
  1370. "schemaVersion": "1",
  1371. "app": map[string]any{
  1372. "id": "sample-score-o-001",
  1373. "title": "领秀城公园积分赛",
  1374. },
  1375. "branding": map[string]any{
  1376. "tenantCode": "tenant_demo",
  1377. "entryChannel": "mini-demo",
  1378. },
  1379. "map": map[string]any{
  1380. "tiles": "../map/lxcb-001/tiles/",
  1381. "mapmeta": "../map/lxcb-001/tiles/meta.json",
  1382. },
  1383. "preview": demoPreviewManifest("score-o"),
  1384. "playfield": map[string]any{
  1385. "kind": "control-set",
  1386. "source": map[string]any{
  1387. "type": "kml",
  1388. "url": "../kml/lxcb-001/10/c01.kml",
  1389. },
  1390. },
  1391. "game": map[string]any{
  1392. "mode": "score-o",
  1393. },
  1394. "content": map[string]any{
  1395. "h5Template": "content-h5-test-template.html",
  1396. },
  1397. },
  1398. })
  1399. if err != nil {
  1400. return nil, fmt.Errorf("ensure score-o demo event config source: %w", err)
  1401. }
  1402. scoreOBuildLog := "积分赛联调 build 产物"
  1403. scoreOBuild, err := s.UpsertEventConfigBuild(ctx, tx, UpsertEventConfigBuildParams{
  1404. EventID: scoreOEventID,
  1405. SourceID: scoreOSource.ID,
  1406. BuildNo: 1,
  1407. BuildStatus: "success",
  1408. BuildLog: &scoreOBuildLog,
  1409. Manifest: map[string]any{
  1410. "schemaVersion": "1",
  1411. "releaseId": "rel_demo_score_o_001",
  1412. "version": "2026.04.01",
  1413. "app": map[string]any{
  1414. "id": "sample-score-o-001",
  1415. "title": "领秀城公园积分赛",
  1416. },
  1417. "map": map[string]any{
  1418. "tiles": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/",
  1419. "mapmeta": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/meta.json",
  1420. },
  1421. "preview": demoPreviewManifest("score-o"),
  1422. "playfield": map[string]any{
  1423. "kind": "control-set",
  1424. "source": map[string]any{
  1425. "type": "kml",
  1426. "url": "https://oss-mbh5.colormaprun.com/gotomars/kml/lxcb-001/10/c01.kml",
  1427. },
  1428. },
  1429. "game": map[string]any{
  1430. "mode": "score-o",
  1431. },
  1432. "assets": map[string]any{
  1433. "contentHtml": "https://oss-mbh5.colormaprun.com/gotomars/event/content-h5-test-template.html",
  1434. },
  1435. },
  1436. AssetIndex: []map[string]any{
  1437. {"assetType": "manifest", "assetKey": "manifest"},
  1438. {"assetType": "mapmeta", "assetKey": "mapmeta"},
  1439. {"assetType": "playfield", "assetKey": "playfield-kml"},
  1440. {"assetType": "content_html", "assetKey": "content-html"},
  1441. },
  1442. })
  1443. if err != nil {
  1444. return nil, fmt.Errorf("ensure score-o demo event config build: %w", err)
  1445. }
  1446. if err := s.AttachBuildToRelease(ctx, tx, scoreOReleaseRow.ID, scoreOBuild.ID); err != nil {
  1447. return nil, fmt.Errorf("attach score-o demo build to release: %w", err)
  1448. }
  1449. var scoreOCardPublicID string
  1450. if err := tx.QueryRow(ctx, `
  1451. INSERT INTO cards (
  1452. card_public_id,
  1453. tenant_id,
  1454. entry_channel_id,
  1455. card_type,
  1456. title,
  1457. subtitle,
  1458. cover_url,
  1459. event_id,
  1460. display_slot,
  1461. display_priority,
  1462. status,
  1463. is_default_experience,
  1464. starts_at,
  1465. ends_at
  1466. )
  1467. VALUES (
  1468. 'card_demo_score_o_001',
  1469. $1,
  1470. $2,
  1471. 'event',
  1472. '领秀城公园积分赛',
  1473. '积分赛推荐入口',
  1474. 'https://oss-mbh5.colormaprun.com/gotomars/assets/demo-cover.jpg',
  1475. $3,
  1476. 'home_primary',
  1477. 98,
  1478. 'active',
  1479. false,
  1480. NOW() - INTERVAL '1 day',
  1481. NOW() + INTERVAL '30 day'
  1482. )
  1483. ON CONFLICT (card_public_id) DO UPDATE SET
  1484. tenant_id = EXCLUDED.tenant_id,
  1485. entry_channel_id = EXCLUDED.entry_channel_id,
  1486. card_type = EXCLUDED.card_type,
  1487. title = EXCLUDED.title,
  1488. subtitle = EXCLUDED.subtitle,
  1489. cover_url = EXCLUDED.cover_url,
  1490. event_id = EXCLUDED.event_id,
  1491. display_slot = EXCLUDED.display_slot,
  1492. display_priority = EXCLUDED.display_priority,
  1493. status = EXCLUDED.status,
  1494. is_default_experience = EXCLUDED.is_default_experience,
  1495. starts_at = EXCLUDED.starts_at,
  1496. ends_at = EXCLUDED.ends_at
  1497. RETURNING card_public_id
  1498. `, tenantID, channelID, scoreOEventID).Scan(&scoreOCardPublicID); err != nil {
  1499. return nil, fmt.Errorf("ensure score-o demo card: %w", err)
  1500. }
  1501. var scoreOCourseSetID, scoreOCourseSetPublicID string
  1502. if err := tx.QueryRow(ctx, `
  1503. INSERT INTO course_sets (
  1504. course_set_public_id, place_id, map_asset_id, code, mode, name, status
  1505. )
  1506. VALUES (
  1507. 'cset_demo_score_o_001', $1, $2, 'cset-demo-score-o-001', 'score-o', '积分赛标准赛道', 'active'
  1508. )
  1509. ON CONFLICT (code) DO UPDATE SET
  1510. place_id = EXCLUDED.place_id,
  1511. map_asset_id = EXCLUDED.map_asset_id,
  1512. mode = EXCLUDED.mode,
  1513. name = EXCLUDED.name,
  1514. status = EXCLUDED.status
  1515. RETURNING id, course_set_public_id
  1516. `, placeID, mapAssetID).Scan(&scoreOCourseSetID, &scoreOCourseSetPublicID); err != nil {
  1517. return nil, fmt.Errorf("ensure score-o demo course set: %w", err)
  1518. }
  1519. var scoreOCourseVariantID, scoreOCourseVariantPublicID string
  1520. if err := tx.QueryRow(ctx, `
  1521. INSERT INTO course_variants (
  1522. course_variant_public_id, course_set_id, source_id, name, route_code, mode, control_count, status, is_default
  1523. )
  1524. VALUES (
  1525. 'cvariant_demo_score_o_001', $1, $2, '积分赛主赛道', 'route-score-o-001', 'score-o', 10, 'active', true
  1526. )
  1527. ON CONFLICT (course_variant_public_id) DO UPDATE SET
  1528. course_set_id = EXCLUDED.course_set_id,
  1529. source_id = EXCLUDED.source_id,
  1530. name = EXCLUDED.name,
  1531. route_code = EXCLUDED.route_code,
  1532. mode = EXCLUDED.mode,
  1533. control_count = EXCLUDED.control_count,
  1534. status = EXCLUDED.status,
  1535. is_default = EXCLUDED.is_default
  1536. RETURNING id, course_variant_public_id
  1537. `, scoreOCourseSetID, courseSourceID).Scan(&scoreOCourseVariantID, &scoreOCourseVariantPublicID); err != nil {
  1538. return nil, fmt.Errorf("ensure score-o demo course variant: %w", err)
  1539. }
  1540. if _, err := tx.Exec(ctx, `
  1541. UPDATE course_sets
  1542. SET current_variant_id = $2
  1543. WHERE id = $1
  1544. `, scoreOCourseSetID, scoreOCourseVariantID); err != nil {
  1545. return nil, fmt.Errorf("attach score-o demo course variant: %w", err)
  1546. }
  1547. var scoreORuntimeBindingID, scoreORuntimeBindingPublicID string
  1548. if err := tx.QueryRow(ctx, `
  1549. INSERT INTO map_runtime_bindings (
  1550. runtime_binding_public_id, event_id, place_id, map_asset_id, tile_release_id, course_set_id, course_variant_id, status, notes
  1551. )
  1552. VALUES (
  1553. 'runtime_demo_score_o_001', $1, $2, $3, $4, $5, $6, 'active', '积分赛联调运行绑定'
  1554. )
  1555. ON CONFLICT (runtime_binding_public_id) DO UPDATE SET
  1556. event_id = EXCLUDED.event_id,
  1557. place_id = EXCLUDED.place_id,
  1558. map_asset_id = EXCLUDED.map_asset_id,
  1559. tile_release_id = EXCLUDED.tile_release_id,
  1560. course_set_id = EXCLUDED.course_set_id,
  1561. course_variant_id = EXCLUDED.course_variant_id,
  1562. status = EXCLUDED.status,
  1563. notes = EXCLUDED.notes
  1564. RETURNING id, runtime_binding_public_id
  1565. `, scoreOEventID, placeID, mapAssetID, tileReleaseID, scoreOCourseSetID, scoreOCourseVariantID).Scan(&scoreORuntimeBindingID, &scoreORuntimeBindingPublicID); err != nil {
  1566. return nil, fmt.Errorf("ensure score-o demo runtime binding: %w", err)
  1567. }
  1568. scoreOPresentationID, _, err := s.upsertDemoEventPresentation(ctx, tx, scoreOEventID, upsertDemoEventPresentationParams{
  1569. PublicID: "pres_demo_score_o_001",
  1570. Code: "event-detail-score-o",
  1571. Name: "积分赛详情展示",
  1572. PresentationType: "detail",
  1573. TemplateKey: "event.detail.score-o",
  1574. Version: "v2026-04-07-score-o",
  1575. Title: "领秀城公园积分赛展示定义",
  1576. })
  1577. if err != nil {
  1578. return nil, fmt.Errorf("ensure score-o presentation: %w", err)
  1579. }
  1580. scoreOBundleID, _, err := s.upsertDemoContentBundle(ctx, tx, scoreOEventID, upsertDemoContentBundleParams{
  1581. PublicID: "bundle_demo_score_o_001",
  1582. Code: "result-media-score-o",
  1583. Name: "积分赛结果内容包",
  1584. BundleType: "result_media",
  1585. Version: "v2026-04-07-score-o",
  1586. ManifestURL: "https://api.gotomars.xyz/dev/demo-assets/content-manifests/score-o",
  1587. AssetRootURL: "https://oss-mbh5.colormaprun.com/gotomars/event/",
  1588. })
  1589. if err != nil {
  1590. return nil, fmt.Errorf("ensure score-o content bundle: %w", err)
  1591. }
  1592. if err := s.SetEventDefaultBindings(ctx, tx, SetEventDefaultBindingsParams{
  1593. EventID: scoreOEventID,
  1594. PresentationID: &scoreOPresentationID,
  1595. ContentBundleID: &scoreOBundleID,
  1596. RuntimeBindingID: &scoreORuntimeBindingID,
  1597. UpdatePresentation: true,
  1598. UpdateContent: true,
  1599. UpdateRuntime: true,
  1600. }); err != nil {
  1601. return nil, fmt.Errorf("set score-o default bindings: %w", err)
  1602. }
  1603. if err := s.SetEventReleaseBindings(ctx, tx, scoreOReleaseRow.ID, &scoreORuntimeBindingID, &scoreOPresentationID, &scoreOBundleID); err != nil {
  1604. return nil, fmt.Errorf("bind score-o release defaults: %w", err)
  1605. }
  1606. var cleanedSessionCount int64
  1607. if err := tx.QueryRow(ctx, `
  1608. WITH cleaned AS (
  1609. UPDATE game_sessions
  1610. SET
  1611. status = 'cancelled',
  1612. ended_at = NOW(),
  1613. updated_at = NOW()
  1614. WHERE event_id = ANY($1::uuid[])
  1615. AND status IN ('launched', 'running')
  1616. RETURNING 1
  1617. )
  1618. SELECT COUNT(*) FROM cleaned
  1619. `, []string{eventID, scoreOEventID, manualEventID}).Scan(&cleanedSessionCount); err != nil {
  1620. return nil, fmt.Errorf("cleanup demo ongoing sessions: %w", err)
  1621. }
  1622. if err := tx.Commit(ctx); err != nil {
  1623. return nil, err
  1624. }
  1625. return &DemoBootstrapSummary{
  1626. TenantCode: "tenant_demo",
  1627. ChannelCode: "mini-demo",
  1628. EventID: "evt_demo_001",
  1629. ReleaseID: releaseRow.PublicID,
  1630. SourceID: source.ID,
  1631. BuildID: build.ID,
  1632. CardID: cardPublicID,
  1633. PlaceID: placePublicID,
  1634. MapAssetID: mapAssetPublicID,
  1635. TileReleaseID: tileReleasePublicID,
  1636. CourseSourceID: courseSourcePublicID,
  1637. CourseSetID: courseSetPublicID,
  1638. CourseVariantID: courseVariantPublicID,
  1639. RuntimeBindingID: runtimeBindingPublicID,
  1640. ScoreOEventID: "evt_demo_score_o_001",
  1641. ScoreOReleaseID: scoreOReleaseRow.PublicID,
  1642. ScoreOCardID: scoreOCardPublicID,
  1643. ScoreOSourceID: scoreOSource.ID,
  1644. ScoreOBuildID: scoreOBuild.ID,
  1645. ScoreOCourseSetID: scoreOCourseSetPublicID,
  1646. ScoreOCourseVariantID: scoreOCourseVariantPublicID,
  1647. ScoreORuntimeBindingID: scoreORuntimeBindingPublicID,
  1648. VariantManualEventID: "evt_demo_variant_manual_001",
  1649. VariantManualRelease: manualReleaseRow.PublicID,
  1650. VariantManualCardID: manualCardPublicID,
  1651. VariantManualSourceID: manualSource.ID,
  1652. VariantManualBuildID: manualBuild.ID,
  1653. VariantManualCourseSet: manualCourseSetPublicID,
  1654. VariantManualVariantID: manualVariantDPublicID,
  1655. VariantManualRuntimeID: manualRuntimeBindingPublicID,
  1656. CleanedSessionCount: cleanedSessionCount,
  1657. }, nil
  1658. }
  1659. type upsertDemoEventPresentationParams struct {
  1660. PublicID string
  1661. Code string
  1662. Name string
  1663. PresentationType string
  1664. TemplateKey string
  1665. Version string
  1666. Title string
  1667. }
  1668. func (s *Store) upsertDemoEventPresentation(ctx context.Context, tx Tx, eventID string, params upsertDemoEventPresentationParams) (string, string, error) {
  1669. var id string
  1670. var publicID string
  1671. if err := tx.QueryRow(ctx, `
  1672. INSERT INTO event_presentations (
  1673. presentation_public_id,
  1674. event_id,
  1675. code,
  1676. name,
  1677. presentation_type,
  1678. status,
  1679. is_default,
  1680. schema_jsonb
  1681. )
  1682. VALUES ($1, $2, $3, $4, $5, 'active', true, $6::jsonb)
  1683. ON CONFLICT (event_id, code) DO UPDATE SET
  1684. presentation_public_id = EXCLUDED.presentation_public_id,
  1685. name = EXCLUDED.name,
  1686. presentation_type = EXCLUDED.presentation_type,
  1687. status = EXCLUDED.status,
  1688. is_default = EXCLUDED.is_default,
  1689. schema_jsonb = EXCLUDED.schema_jsonb
  1690. RETURNING id, presentation_public_id
  1691. `, 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 {
  1692. return "", "", err
  1693. }
  1694. return id, publicID, nil
  1695. }
  1696. type upsertDemoContentBundleParams struct {
  1697. PublicID string
  1698. Code string
  1699. Name string
  1700. BundleType string
  1701. Version string
  1702. ManifestURL string
  1703. AssetRootURL string
  1704. }
  1705. func (s *Store) upsertDemoContentBundle(ctx context.Context, tx Tx, eventID string, params upsertDemoContentBundleParams) (string, string, error) {
  1706. var id string
  1707. var publicID string
  1708. if err := tx.QueryRow(ctx, `
  1709. INSERT INTO content_bundles (
  1710. content_bundle_public_id,
  1711. event_id,
  1712. code,
  1713. name,
  1714. status,
  1715. is_default,
  1716. entry_url,
  1717. asset_root_url,
  1718. metadata_jsonb
  1719. )
  1720. VALUES ($1, $2, $3, $4, 'active', true, $5, $6, $7::jsonb)
  1721. ON CONFLICT (event_id, code) DO UPDATE SET
  1722. content_bundle_public_id = EXCLUDED.content_bundle_public_id,
  1723. name = EXCLUDED.name,
  1724. status = EXCLUDED.status,
  1725. is_default = EXCLUDED.is_default,
  1726. entry_url = EXCLUDED.entry_url,
  1727. asset_root_url = EXCLUDED.asset_root_url,
  1728. metadata_jsonb = EXCLUDED.metadata_jsonb
  1729. RETURNING id, content_bundle_public_id
  1730. `, 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 {
  1731. return "", "", err
  1732. }
  1733. return id, publicID, nil
  1734. }
  1735. func demoPreviewManifest(kind string) map[string]any {
  1736. baseTiles := map[string]any{
  1737. "tileBaseUrl": "https://oss-mbh5.colormaprun.com/gotomars/map/lxcb-001/tiles/",
  1738. "zoom": 15,
  1739. "tileSize": 256,
  1740. }
  1741. viewport := map[string]any{
  1742. "width": 800,
  1743. "height": 450,
  1744. "minLon": 117.0000,
  1745. "minLat": 36.6000,
  1746. "maxLon": 117.0800,
  1747. "maxLat": 36.6600,
  1748. }
  1749. switch kind {
  1750. case "score-o":
  1751. return map[string]any{
  1752. "mode": "readonly",
  1753. "baseTiles": baseTiles,
  1754. "viewport": viewport,
  1755. "selectedVariantId": "variant_score_main",
  1756. "variants": []map[string]any{
  1757. {
  1758. "variantId": "variant_score_main",
  1759. "name": "积分赛主赛道",
  1760. "routeCode": "route-score-o-001",
  1761. "controls": []map[string]any{
  1762. {"id": "start", "kind": "start", "lon": 117.012, "lat": 36.612, "label": "起点"},
  1763. {"id": "s1", "kind": "control", "lon": 117.021, "lat": 36.618, "label": "10分点"},
  1764. {"id": "s2", "kind": "control", "lon": 117.034, "lat": 36.624, "label": "20分点"},
  1765. {"id": "s3", "kind": "control", "lon": 117.046, "lat": 36.616, "label": "15分点"},
  1766. {"id": "finish", "kind": "finish", "lon": 117.025, "lat": 36.606, "label": "终点"},
  1767. },
  1768. "legs": []map[string]any{
  1769. {"from": "start", "to": "s1"},
  1770. {"from": "s1", "to": "s2"},
  1771. {"from": "s2", "to": "s3"},
  1772. {"from": "s3", "to": "finish"},
  1773. },
  1774. },
  1775. },
  1776. }
  1777. case "manual-variant":
  1778. return map[string]any{
  1779. "mode": "readonly",
  1780. "baseTiles": baseTiles,
  1781. "viewport": viewport,
  1782. "selectedVariantId": "variant_d",
  1783. "variants": []map[string]any{
  1784. {
  1785. "variantId": "variant_a",
  1786. "name": "路线 01",
  1787. "routeCode": "route-variant-a",
  1788. "controls": []map[string]any{
  1789. {"id": "1", "kind": "control", "lon": 117.000649296107, "lat": 36.5921631022497, "label": "1"},
  1790. {"id": "2", "kind": "control", "lon": 116.999689737459, "lat": 36.5922740961347, "label": "2"},
  1791. {"id": "3", "kind": "control", "lon": 116.999108309973, "lat": 36.5919019395375, "label": "3"},
  1792. {"id": "4", "kind": "control", "lon": 116.999823913032, "lat": 36.591572220351, "label": "4"},
  1793. {"id": "5", "kind": "control", "lon": 116.999860506371, "lat": 36.5912131186443, "label": "5"},
  1794. {"id": "6", "kind": "control", "lon": 117.000340285695, "lat": 36.5909356298175, "label": "6"},
  1795. {"id": "7", "kind": "control", "lon": 117.000441933857, "lat": 36.5915004001434, "label": "7"},
  1796. {"id": "8", "kind": "control", "lon": 117.001397426578, "lat": 36.5915983367736, "label": "8"},
  1797. {"id": "9", "kind": "control", "lon": 117.000665559813, "lat": 36.5919574366878, "label": "9"},
  1798. {"id": "10", "kind": "control", "lon": 117.000649296107, "lat": 36.5921631022497, "label": "10"},
  1799. },
  1800. "legs": []map[string]any{
  1801. {"from": "1", "to": "2"},
  1802. {"from": "2", "to": "3"},
  1803. {"from": "3", "to": "4"},
  1804. {"from": "4", "to": "5"},
  1805. {"from": "5", "to": "6"},
  1806. {"from": "6", "to": "7"},
  1807. {"from": "7", "to": "8"},
  1808. {"from": "8", "to": "9"},
  1809. {"from": "9", "to": "10"},
  1810. },
  1811. },
  1812. {
  1813. "variantId": "variant_b",
  1814. "name": "路线 02",
  1815. "routeCode": "route-variant-b",
  1816. "controls": []map[string]any{
  1817. {"id": "1", "kind": "control", "lon": 117.000649296107, "lat": 36.5921631022497, "label": "1"},
  1818. {"id": "2", "kind": "control", "lon": 116.999766990062, "lat": 36.5921141343085, "label": "2"},
  1819. {"id": "3", "kind": "control", "lon": 116.999710067091, "lat": 36.5917615642144, "label": "3"},
  1820. {"id": "4", "kind": "control", "lon": 116.998774904002, "lat": 36.5913306430232, "label": "4"},
  1821. {"id": "5", "kind": "control", "lon": 116.998941606987, "lat": 36.5908278985923, "label": "5"},
  1822. {"id": "6", "kind": "control", "lon": 117.00058830721, "lat": 36.5905340853955, "label": "6"},
  1823. {"id": "7", "kind": "control", "lon": 117.000238637533, "lat": 36.5914742836876, "label": "7"},
  1824. {"id": "8", "kind": "control", "lon": 117.000937976887, "lat": 36.5916113949816, "label": "8"},
  1825. {"id": "9", "kind": "control", "lon": 117.000803801313, "lat": 36.5919411140006, "label": "9"},
  1826. {"id": "10", "kind": "control", "lon": 117.000649296107, "lat": 36.5921631022497, "label": "10"},
  1827. },
  1828. "legs": []map[string]any{
  1829. {"from": "1", "to": "2"},
  1830. {"from": "2", "to": "3"},
  1831. {"from": "3", "to": "4"},
  1832. {"from": "4", "to": "5"},
  1833. {"from": "5", "to": "6"},
  1834. {"from": "6", "to": "7"},
  1835. {"from": "7", "to": "8"},
  1836. {"from": "8", "to": "9"},
  1837. {"from": "9", "to": "10"},
  1838. },
  1839. },
  1840. {
  1841. "variantId": "variant_c",
  1842. "name": "路线 03",
  1843. "routeCode": "route-variant-c",
  1844. "controls": []map[string]any{
  1845. {"id": "1", "kind": "control", "lon": 117.000649296107, "lat": 36.5921631022497, "label": "1"},
  1846. {"id": "2", "kind": "control", "lon": 117.000665559813, "lat": 36.5919574366878, "label": "2"},
  1847. {"id": "3", "kind": "control", "lon": 117.001397426578, "lat": 36.5915983367736, "label": "3"},
  1848. {"id": "4", "kind": "control", "lon": 117.000441933857, "lat": 36.5915004001434, "label": "4"},
  1849. {"id": "5", "kind": "control", "lon": 117.000340285695, "lat": 36.5909356298175, "label": "5"},
  1850. {"id": "6", "kind": "control", "lon": 116.999860506371, "lat": 36.5912131186443, "label": "6"},
  1851. {"id": "7", "kind": "control", "lon": 116.999823913032, "lat": 36.591572220351, "label": "7"},
  1852. {"id": "8", "kind": "control", "lon": 116.999108309973, "lat": 36.5919019395375, "label": "8"},
  1853. {"id": "9", "kind": "control", "lon": 116.999689737459, "lat": 36.5922740961347, "label": "9"},
  1854. {"id": "10", "kind": "control", "lon": 117.000649296107, "lat": 36.5921631022497, "label": "10"},
  1855. },
  1856. "legs": []map[string]any{
  1857. {"from": "1", "to": "2"},
  1858. {"from": "2", "to": "3"},
  1859. {"from": "3", "to": "4"},
  1860. {"from": "4", "to": "5"},
  1861. {"from": "5", "to": "6"},
  1862. {"from": "6", "to": "7"},
  1863. {"from": "7", "to": "8"},
  1864. {"from": "8", "to": "9"},
  1865. {"from": "9", "to": "10"},
  1866. },
  1867. },
  1868. {
  1869. "variantId": "variant_d",
  1870. "name": "路线 04",
  1871. "routeCode": "route-variant-d",
  1872. "controls": []map[string]any{
  1873. {"id": "1", "kind": "control", "lon": 117.000649296107, "lat": 36.5921631022497, "label": "1"},
  1874. {"id": "2", "kind": "control", "lon": 117.000803801313, "lat": 36.5919411140006, "label": "2"},
  1875. {"id": "3", "kind": "control", "lon": 117.000937976887, "lat": 36.5916113949816, "label": "3"},
  1876. {"id": "4", "kind": "control", "lon": 117.000238637533, "lat": 36.5914742836876, "label": "4"},
  1877. {"id": "5", "kind": "control", "lon": 117.00058830721, "lat": 36.5905340853955, "label": "5"},
  1878. {"id": "6", "kind": "control", "lon": 116.998941606987, "lat": 36.5908278985923, "label": "6"},
  1879. {"id": "7", "kind": "control", "lon": 116.998774904002, "lat": 36.5913306430232, "label": "7"},
  1880. {"id": "8", "kind": "control", "lon": 116.999710067091, "lat": 36.5917615642144, "label": "8"},
  1881. {"id": "9", "kind": "control", "lon": 116.999766990062, "lat": 36.5921141343085, "label": "9"},
  1882. {"id": "10", "kind": "control", "lon": 117.000649296107, "lat": 36.5921631022497, "label": "10"},
  1883. },
  1884. "legs": []map[string]any{
  1885. {"from": "1", "to": "2"},
  1886. {"from": "2", "to": "3"},
  1887. {"from": "3", "to": "4"},
  1888. {"from": "4", "to": "5"},
  1889. {"from": "5", "to": "6"},
  1890. {"from": "6", "to": "7"},
  1891. {"from": "7", "to": "8"},
  1892. {"from": "8", "to": "9"},
  1893. {"from": "9", "to": "10"},
  1894. },
  1895. },
  1896. },
  1897. }
  1898. default:
  1899. return map[string]any{
  1900. "mode": "readonly",
  1901. "baseTiles": baseTiles,
  1902. "viewport": viewport,
  1903. "selectedVariantId": "variant_classic_main",
  1904. "variants": []map[string]any{
  1905. {
  1906. "variantId": "variant_classic_main",
  1907. "name": "顺序赛主赛道",
  1908. "routeCode": "route-demo-a",
  1909. "controls": []map[string]any{
  1910. {"id": "start", "kind": "start", "lon": 117.010, "lat": 36.610, "label": "起点"},
  1911. {"id": "c1", "kind": "control", "lon": 117.018, "lat": 36.615, "label": "1"},
  1912. {"id": "c2", "kind": "control", "lon": 117.027, "lat": 36.621, "label": "2"},
  1913. {"id": "c3", "kind": "control", "lon": 117.036, "lat": 36.627, "label": "3"},
  1914. {"id": "finish", "kind": "finish", "lon": 117.044, "lat": 36.632, "label": "终点"},
  1915. },
  1916. "legs": []map[string]any{
  1917. {"from": "start", "to": "c1"},
  1918. {"from": "c1", "to": "c2"},
  1919. {"from": "c2", "to": "c3"},
  1920. {"from": "c3", "to": "finish"},
  1921. },
  1922. },
  1923. },
  1924. }
  1925. }
  1926. }