priority.rb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. module Import
  2. module OTRS
  3. class Priority
  4. include Import::Helper
  5. include Import::OTRS::Helper
  6. MAPPING = {
  7. ChangeTime: :updated_at,
  8. CreateTime: :created_at,
  9. CreateBy: :created_by_id,
  10. ChangeBy: :updated_by_id,
  11. Name: :name,
  12. ID: :id,
  13. Comment: :note,
  14. }.freeze
  15. def initialize(priority)
  16. import(priority)
  17. end
  18. private
  19. def import(priority)
  20. create_or_update(map(priority))
  21. end
  22. def create_or_update(priority)
  23. return if updated?(priority)
  24. create(priority)
  25. end
  26. def updated?(priority)
  27. @local_priority = ::Ticket::Priority.find_by(id: priority[:id])
  28. return false if !@local_priority
  29. log "update Ticket::Priority.find_by(id: #{priority[:id]})"
  30. @local_priority.update!(priority)
  31. true
  32. end
  33. def create(priority)
  34. log "add Ticket::Priority.find_by(id: #{priority[:id]})"
  35. @local_priority = ::Ticket::Priority.new(priority)
  36. @local_priority.id = priority[:id]
  37. @local_priority.save
  38. reset_primary_key_sequence('ticket_priorities')
  39. end
  40. def ui_color(priority)
  41. return 'high-priority' if ['4 high', '5 very high'].include?(priority['Name'])
  42. return 'low-priority' if ['2 low', '1 very low'].include?(priority['Name'])
  43. nil
  44. end
  45. def ui_icon(priority)
  46. return 'important' if ['4 high', '5 very high'].include?(priority['Name'])
  47. return 'low-priority' if ['2 low', '1 very low'].include?(priority['Name'])
  48. nil
  49. end
  50. def map(priority)
  51. {
  52. created_by_id: 1,
  53. updated_by_id: 1,
  54. ui_color: ui_color(priority),
  55. ui_icon: ui_icon(priority),
  56. active: active?(priority),
  57. }
  58. .merge(from_mapping(priority))
  59. end
  60. end
  61. end
  62. end