2020-11-23 15:35:03 +08:00
|
|
|
# == Schema Information
|
|
|
|
|
#
|
|
|
|
|
# Table name: issue_priorities
|
|
|
|
|
#
|
|
|
|
|
# id :integer not null, primary key
|
|
|
|
|
# name :string(255)
|
|
|
|
|
# position :integer
|
|
|
|
|
# created_at :datetime not null
|
|
|
|
|
# updated_at :datetime not null
|
|
|
|
|
#
|
|
|
|
|
# Indexes
|
|
|
|
|
#
|
|
|
|
|
# index_issue_priorities_on_name (name)
|
|
|
|
|
#
|
|
|
|
|
|
2020-03-09 00:40:16 +08:00
|
|
|
class IssuePriority < ApplicationRecord
|
|
|
|
|
has_many :issues
|
2023-02-22 13:56:02 +08:00
|
|
|
|
|
|
|
|
def self.init_data
|
|
|
|
|
map = {
|
|
|
|
|
"1" => "低",
|
|
|
|
|
"2" => "正常",
|
|
|
|
|
"3" => "高",
|
|
|
|
|
"4" => "紧急"
|
|
|
|
|
}
|
|
|
|
|
IssuePriority.order(id: :asc).each do |prty|
|
|
|
|
|
if map["#{prty.id}"] == prty.name
|
|
|
|
|
IssuePriority.find_or_create_by(id: prty.id, name: prty.name)
|
|
|
|
|
else
|
|
|
|
|
Issue.where(priority_id: prty.id).each{|i| i.update_column(:priority_id, 2)}
|
|
|
|
|
prty.destroy!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-03-29 18:49:20 +08:00
|
|
|
|
|
|
|
|
def to_builder
|
|
|
|
|
Jbuilder.new do |priority|
|
|
|
|
|
priority.(self, :id, :name)
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-11-23 15:35:03 +08:00
|
|
|
end
|