waterFacilityGisModel.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. function finiteCoordinate(value) {
  2. if (value === null || value === undefined || value === '') return null
  3. const coordinate = Number(value)
  4. return Number.isFinite(coordinate) ? coordinate : null
  5. }
  6. function featureIdentity(feature, properties) {
  7. return {
  8. id: properties.id ?? feature.id,
  9. featureId: feature.id,
  10. type: properties.facilityType || properties.type || '',
  11. name: properties.facilityName || properties.name || properties.pipeName || properties.facilityTypeName || '供水设施',
  12. code: properties.facilityCode || properties.code || properties.pipeCode || '-',
  13. status: properties.status,
  14. road: properties.road || properties.address || properties.location || '',
  15. raw: feature
  16. }
  17. }
  18. export function buildFacilityMapModel(collection = {}) {
  19. const points = []
  20. const lines = []
  21. for (const feature of Array.isArray(collection.features) ? collection.features : []) {
  22. const properties = feature.properties || {}
  23. const identity = featureIdentity(feature, properties)
  24. const coordinates = feature.geometry?.coordinates
  25. if (feature.geometry?.type === 'Point' && Array.isArray(coordinates)) {
  26. const lng = finiteCoordinate(coordinates[0])
  27. const lat = finiteCoordinate(coordinates[1])
  28. if (lng === null || lat === null) continue
  29. points.push({
  30. ...identity,
  31. address: properties.address || properties.location || '',
  32. lng,
  33. lat
  34. })
  35. }
  36. if (feature.geometry?.type === 'LineString' && Array.isArray(coordinates) && coordinates.length >= 2) {
  37. const linePoints = coordinates.map(pair => ({
  38. lng: finiteCoordinate(pair?.[0]),
  39. lat: finiteCoordinate(pair?.[1])
  40. }))
  41. if (linePoints.some(point => point.lng === null || point.lat === null)) continue
  42. lines.push({
  43. ...identity,
  44. type: identity.type || 'pipe',
  45. material: properties.pipeMaterial,
  46. diameter: properties.pipeDiameter,
  47. startPoint: properties.startPoint,
  48. endPoint: properties.endPoint,
  49. layingYear: properties.layingYear,
  50. length: properties.pipeLength,
  51. points: linePoints
  52. })
  53. }
  54. }
  55. return { points, lines }
  56. }
  57. export function filterFacilityMapModel(model = {}, enabledTypes = {}) {
  58. const points = (model.points || []).filter(item => enabledTypes[item.type] !== false)
  59. const lines = (model.lines || []).filter(item => enabledTypes[item.type] !== false)
  60. return { points, lines, isEmpty: points.length === 0 && lines.length === 0 }
  61. }
  62. export function findFacilityFeature(model = {}, keyword = '') {
  63. const normalized = String(keyword).trim().toLocaleLowerCase()
  64. if (!normalized) return null
  65. const items = [
  66. ...(model.points || []).map(item => ({ ...item, kind: 'point' })),
  67. ...(model.lines || []).map(item => {
  68. const first = item.points[0]
  69. const last = item.points[item.points.length - 1]
  70. const midpoint = {
  71. lng: Number(((first.lng + last.lng) / 2).toFixed(8)),
  72. lat: Number(((first.lat + last.lat) / 2).toFixed(8))
  73. }
  74. return { ...item, kind: 'pipeline', lng: midpoint.lng, lat: midpoint.lat }
  75. })
  76. ]
  77. return items.find(item => [item.name, item.code, item.road]
  78. .some(value => String(value || '').toLocaleLowerCase().includes(normalized))) || null
  79. }
  80. const facilityDetailLabels = {
  81. id: '系统编号',
  82. sourceId: '水源地编号',
  83. sourceName: '水源地名称',
  84. sourceType: '水源地类型',
  85. unit: '所属单位',
  86. address: '详细地址',
  87. location: '位置描述',
  88. longitude: '经度',
  89. latitude: '纬度',
  90. waterType: '水源类型',
  91. protectionLevel: '保护等级',
  92. waterQualityLevel: '水质等级',
  93. protectionScope: '保护范围',
  94. reportTime: '上报时间',
  95. status: '运行状态',
  96. plantCode: '水厂编号',
  97. plantName: '水厂名称',
  98. waterSourceType: '水源类型',
  99. designCapacity: '设计供水能力',
  100. currentCapacity: '实际供水能力',
  101. treatmentProcess: '处理工艺',
  102. commissionDate: '投运日期',
  103. waterQualityStandard: '水质执行标准',
  104. stationCode: '泵站编号',
  105. stationName: '泵站名称',
  106. stationType: '设施类型',
  107. pumpCount: '水泵数量',
  108. designFlow: '设计流量',
  109. designHead: '设计扬程',
  110. powerCapacity: '装机容量',
  111. userCode: '用水户编号',
  112. userName: '用水户名称',
  113. userType: '用水户类型',
  114. contactPerson: '联系人',
  115. contactPhone: '联系电话',
  116. meterNumber: '水表编号',
  117. initialReading: '初始读数',
  118. currentReading: '当前读数',
  119. annualWaterConsumption: '年用水量',
  120. networkId: '管网系统编号',
  121. networkCode: '管网编号',
  122. networkName: '管网名称',
  123. networkLevel: '管网等级',
  124. networkType: '业务归属',
  125. managementUnit: '管养单位',
  126. material: '管道材质',
  127. diameter: '管径',
  128. length: '管道长度',
  129. buildDate: '建设日期',
  130. buildYear: '建设年份',
  131. principal: '负责人',
  132. remark: '备注',
  133. delFlag: '删除标志',
  134. createBy: '创建人',
  135. createTime: '创建时间',
  136. updateBy: '更新人',
  137. updateTime: '更新时间'
  138. }
  139. const facilityStatusLabels = {
  140. source: { 0: '正常', 1: '异常' },
  141. plant: { 0: '正常', 1: '停产' },
  142. pumpStation: { 0: '正常', 1: '故障停运', 2: '检修中' },
  143. pipe: { 0: '正常', 1: '停用' },
  144. user: { 0: '正常', 1: '欠费', 2: '停用' }
  145. }
  146. function formatFacilityDetailValue(key, value, facilityType) {
  147. if (key === 'status') {
  148. return facilityStatusLabels[facilityType]?.[String(value)] ?? value
  149. }
  150. if (key === 'stationType') {
  151. return { water_supply: '供水泵站', drainage: '排水泵站' }[value] ?? value
  152. }
  153. if (key === 'networkType') {
  154. return { 0: '燃气', 1: '排水', 2: '供水' }[String(value)] ?? value
  155. }
  156. if (key === 'delFlag') {
  157. return { 0: '正常', 2: '已删除' }[String(value)] ?? value
  158. }
  159. return value
  160. }
  161. export function formatFacilityDetail(detail = {}, facilityType = '') {
  162. if (!detail || typeof detail !== 'object') return []
  163. return Object.entries(detail)
  164. .filter(([key, value]) => key in facilityDetailLabels && value !== null && value !== undefined && value !== '')
  165. .map(([key, value]) => ({
  166. label: facilityDetailLabels[key],
  167. value: formatFacilityDetailValue(key, value, facilityType)
  168. }))
  169. }