warningDetail.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. export function warningValue(source, ...keys) {
  2. for (const key of keys) {
  3. const value = source?.[key]
  4. if (value !== undefined && value !== null && value !== '') return value
  5. }
  6. return ''
  7. }
  8. export function warningIdOf(source) {
  9. return warningValue(source, 'warningId', 'warning_id', 'id')
  10. }
  11. export function normalizeWarningBasic(source = {}, references = {}) {
  12. const warningType = warningValue(source, 'warningType', 'warning_type')
  13. const warningLevel = warningValue(source, 'warningLevel', 'warning_level')
  14. return {
  15. ...source,
  16. warningId: warningIdOf(source),
  17. warningNo: warningValue(source, 'warningNo', 'warning_no'),
  18. warningName: warningValue(source, 'warningName', 'warning_name'),
  19. warningType,
  20. warningTypeText: warningValue(source, 'warningTypeText', 'warningTypeName', 'warning_type_name')
  21. || references.typeLabels?.[warningType]
  22. || warningType,
  23. warningLevel,
  24. warningLevelText: warningValue(source, 'warningLevelText', 'warningLevelName', 'warning_level_name')
  25. || references.levelLabels?.[warningLevel]
  26. || warningLevel,
  27. warningSpecial: warningValue(source, 'warningSpecial', 'warning_special'),
  28. warningContent: warningValue(source, 'warningContent', 'warning_content'),
  29. ownershipUnit: warningValue(source, 'ownershipUnit', 'ownership_unit'),
  30. deviceName: warningValue(source, 'deviceName', 'device_name'),
  31. deviceCode: warningValue(source, 'deviceCode', 'device_code'),
  32. location: warningValue(source, 'location', 'deviceLocation', 'device_location'),
  33. publisher: warningValue(source, 'publisher'),
  34. publisherName: warningValue(source, 'publisherName', 'publisher_name'),
  35. handler: warningValue(source, 'handler'),
  36. handlerName: warningValue(source, 'handlerName', 'handler_name'),
  37. reviewer: warningValue(source, 'reviewer'),
  38. reviewerName: warningValue(source, 'reviewerName', 'reviewer_name'),
  39. publishTime: warningValue(source, 'publishTime', 'publish_time'),
  40. updateTime: warningValue(source, 'updateTime', 'update_time'),
  41. remark: warningValue(source, 'remark'),
  42. status: warningValue(source, 'status'),
  43. itemId: warningValue(source, 'itemId', 'item_id'),
  44. itemSnapshot: warningValue(source, 'itemSnapshot', 'item_snapshot'),
  45. disposalDeadline: warningValue(source, 'disposalDeadline', 'disposal_deadline'),
  46. stageDeadline: warningValue(source, 'stageDeadline', 'stage_deadline')
  47. }
  48. }
  49. export function normalizeWarningAlarm(source = {}) {
  50. return {
  51. ...source,
  52. alarmId: warningValue(source, 'alarmId', 'alarm_id', 'id'),
  53. alarmNo: warningValue(source, 'alarmNo', 'alarm_no', 'warningCode', 'warning_code'),
  54. alarmContent: warningValue(source, 'alarmContent', 'alarm_content'),
  55. alarmType: warningValue(source, 'alarmTypeText', 'alarmType', 'alarm_type', 'warningTypeName', 'warning_type_name', 'warningType', 'warning_type'),
  56. deviceName: warningValue(source, 'deviceName', 'device_name', 'equipmentName', 'equipment_name'),
  57. deviceCode: warningValue(source, 'deviceCode', 'device_code', 'equipmentCode', 'equipment_code'),
  58. thresholdValue: warningValue(source, 'thresholdValue', 'threshold_value', 'warningValue', 'warning_value'),
  59. actualValue: warningValue(source, 'actualValue', 'actual_value'),
  60. createTime: warningValue(source, 'createTime', 'create_time', 'alarmTime', 'alarm_time')
  61. }
  62. }
  63. export function normalizeWarningDetail(source = {}, references = {}) {
  64. const basicSource = source.basicInfo || source.basic_info || source
  65. return {
  66. ...source,
  67. basicInfo: normalizeWarningBasic(basicSource, references),
  68. alarmList: (source.alarmList || source.alarm_list || []).map(normalizeWarningAlarm),
  69. disposalHistory: source.disposalHistory || source.disposal_history || source.disposalList || source.disposal_list || [],
  70. attachmentList: source.attachmentList || source.attachment_list || [],
  71. supervisionList: source.supervisionList || source.supervision_list || [],
  72. electronicArchive: source.electronicArchive || source.electronic_archive || null
  73. }
  74. }