asia_database/app/models/asia_export_store.rb

31 lines
863 B
Ruby
Raw Normal View History

2023-05-26 14:17:05 +00:00
class AsiaExportStore
require "fileutils"
include Mongoid::Document
include Mongoid::Timestamps
field :tmp_id, :type => String # for syncing
field :filter_str, :type => String
field :status, :type => Integer, :default => 0 # 0 => preparing, 1 => generating, 2 => finish
field :finish_percent, :type => Float, :default => 0
StoreDir = "tmp/asia_db_export"
index({filter_str: 1}, { unique: false, background: true })
index({tmp_id: -1}, { unique: false, background: true })
before_create do
FileUtils.mkdir_p(StoreDir)
FileUtils.rm(self.file_path, :force => true)
end
before_destroy do
FileUtils.rm(self.file_path, :force => true)
end
def file_path
"#{StoreDir}/#{tmp_id}.xlsx"
end
def reinit
FileUtils.mkdir_p(StoreDir)
FileUtils.rm(self.file_path, :force => true)
self.status = 0
self.finish_percent = 0.0
self.save
end
end