{ "properties" : { }, "id" : "9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4", "script" : null, "groupId" : "f8e3d2c1b0a94e5f8a7b6c5d4e3f2a1", "name" : "地图迁徙数据", "createTime" : 1780882000000, "updateTime" : 1781377000000, "lock" : null, "createBy" : "admin", "updateBy" : "admin", "path" : "/map-trading-network", "method" : "GET", "parameters" : [ ], "options" : [ ], "requestBody" : "", "headers" : [ ], "paths" : [ ], "responseBody" : null, "description" : "中央地图迁徙数据:gov_count_order_total。销售网络=origin_place含红原;源地供应=destination_place含红原;红原出栏=起终点均含红原。头数SUM(yak_number)。", "requestBodyDefinition" : null, "responseBodyDefinition" : null } ================================ // gov_count_order_total:一条记录 = 一笔订单,头数 SUM(yak_number) // outflow 销售网络:origin_place 含「红原」,按 destination_place 聚合 // inflow 源地供应:destination_place 含「红原」,按 origin_place 聚合 // local 红原出栏:destination_place 含「红原」且 origin_place 含「红原」,按 origin_place 乡镇聚合 // hubName 需与系统配置 mapHub.name 保持一致 var hubName = '红原县' var getRowText = (row, camelKey, snakeKey) => { if (row[camelKey]) { return '' + row[camelKey] } if (row[snakeKey]) { return '' + row[snakeKey] } return '' } var getRowNumber = (row, key) => { var v = row[key] if (v == null || v === '') { return 0 } return v } var normalizeCityKey = (name) => { var text = '' + (name == null ? '' : name) if (text.trim() == '') { return '未知' } if (text.indexOf('北京') >= 0) { return '北京' } if (text.indexOf('上海') >= 0) { return '上海' } if (text.indexOf('天津') >= 0) { return '天津' } if (text.indexOf('重庆') >= 0) { return '重庆' } if (text.indexOf('成都') >= 0) { return '成都' } if (text.indexOf('拉萨') >= 0) { return '拉萨' } if (text.indexOf('西宁') >= 0) { return '西宁' } if (text.indexOf('兰州') >= 0) { return '兰州' } if (text.indexOf('西安') >= 0) { return '西安' } if (text.indexOf('昆明') >= 0) { return '昆明' } if (text.indexOf('贵阳') >= 0) { return '贵阳' } if (text.indexOf('广州') >= 0) { return '广州' } if (text.indexOf('深圳') >= 0) { return '深圳' } if (text.indexOf('康定') >= 0) { return '康定' } if (text.indexOf('香格里拉') >= 0) { return '香格里拉' } if (text.indexOf('合作') >= 0) { return '合作' } if (text.indexOf('甘南') >= 0) { return '甘南藏族自治州' } if (text.indexOf('玉树') >= 0) { return '玉树' } if (text.indexOf('甘孜') >= 0) { return '甘孜藏族自治州' } if (text.indexOf('阿坝') >= 0) { return '阿坝县' } if (text.indexOf('马尔康') >= 0) { return '马尔康' } if (text.indexOf('理塘') >= 0) { return '理塘' } if (text.indexOf('那曲') >= 0) { return '那曲' } if (text.indexOf('果洛') >= 0) { return '果洛' } if (text.indexOf('红原') >= 0) { return '红原县' } return text } var buildDirectionalFlows = (rows, direction) => { var flows = [] var valueMap = {} var descMap = {} if (!rows) { return flows } for (row in rows) { var rawName = getRowText(row, 'placeName', 'place_name') var value = getRowNumber(row, 'value') var sample = getRowText(row, 'samplePlace', 'sample_place') if (sample == '') { sample = rawName } if (value > 0) { var cityKey = direction == 'local' ? rawName : normalizeCityKey(rawName) if (cityKey != '未知') { if (valueMap[cityKey] == null) { valueMap[cityKey] = value descMap[cityKey] = sample if (direction == 'outflow') { flows.push({ from: hubName, to: cityKey, value: value, description: sample }) } else { flows.push({ from: cityKey, to: hubName, value: value, description: sample }) } } else { valueMap[cityKey] = valueMap[cityKey] + value var descText = '' + descMap[cityKey] if (descText.indexOf(sample) < 0 && sample != '') { descMap[cityKey] = descText + ';' + sample } for (flow in flows) { var flowCity = direction == 'outflow' ? flow.to : flow.from if (flowCity == cityKey) { flow.value = valueMap[cityKey] flow.description = descMap[cityKey] } } } } } } return flows } var outflowSql = """ SELECT COALESCE(NULLIF(TRIM(destination_place), ''), '未知') AS place_name, COALESCE(SUM(yak_number), 0) AS value, MAX(destination_place) AS sample_place FROM gov_count_order_total WHERE origin_place IS NOT NULL AND position('红原' in origin_place) > 0 AND destination_place IS NOT NULL AND TRIM(destination_place) <> '' GROUP BY COALESCE(NULLIF(TRIM(destination_place), ''), '未知') HAVING COALESCE(SUM(yak_number), 0) > 0 ORDER BY value DESC, place_name """ var inflowSql = """ SELECT COALESCE(NULLIF(TRIM(origin_place), ''), '未知') AS place_name, COALESCE(SUM(yak_number), 0) AS value, MAX(origin_place) AS sample_place FROM gov_count_order_total WHERE destination_place IS NOT NULL AND position('红原' in destination_place) > 0 AND origin_place IS NOT NULL AND TRIM(origin_place) <> '' GROUP BY COALESCE(NULLIF(TRIM(origin_place), ''), '未知') HAVING COALESCE(SUM(yak_number), 0) > 0 ORDER BY value DESC, place_name """ var localSql = """ SELECT COALESCE( NULLIF((regexp_match(origin_place, '([^省市区县]+(?:镇|乡|街道))'))[1], ''), NULLIF(TRIM(origin_place), ''), '未知' ) AS place_name, COALESCE(SUM(yak_number), 0) AS value, MAX(origin_place) AS sample_place FROM gov_count_order_total WHERE destination_place IS NOT NULL AND position('红原' in destination_place) > 0 AND origin_place IS NOT NULL AND position('红原' in origin_place) > 0 AND TRIM(origin_place) <> '' GROUP BY COALESCE( NULLIF((regexp_match(origin_place, '([^省市区县]+(?:镇|乡|街道))'))[1], ''), NULLIF(TRIM(origin_place), ''), '未知' ) HAVING COALESCE(SUM(yak_number), 0) > 0 ORDER BY value DESC, place_name """ var outflowRows = db.select(outflowSql) var inflowRows = db.select(inflowSql) var localRows = db.select(localSql) var outflowFlows = buildDirectionalFlows(outflowRows, 'outflow') var inflowFlows = buildDirectionalFlows(inflowRows, 'inflow') var localFlows = buildDirectionalFlows(localRows, 'local') return { tradingModes: { outflow: { title: '销售网络分布图', description: '从' + hubName + '向全国各地输出牦牛的流向分布', flows: outflowFlows }, inflow: { title: '源地供应分布图', description: '全国各地向' + hubName + '供应牦牛的来源分布', flows: inflowFlows }, local: { title: '红原出栏分布图', description: hubName + '各乡镇牦牛出栏分布情况', flows: localFlows } } }