Merge branch 'develop' of https://bdgit.educoder.net/Hjqreturn/pgfqe6ch8 into develop
commit
92f778c598
@ -0,0 +1,35 @@
|
||||
#coding=utf-8
|
||||
namespace :competition_notice do
|
||||
require 'simple_xlsx_reader'
|
||||
|
||||
task :send_message => :environment do
|
||||
puts "--------------------------------competition_notice send_message start"
|
||||
attachment = Attachment.where(id: 230670).first
|
||||
if attachment.present?
|
||||
path = attachment.disk_directory
|
||||
name = attachment.disk_filename
|
||||
if name.split(".").last == "xlsx"
|
||||
doc = SimpleXlsxReader.open("files/#{path}/#{name}")
|
||||
sheet = doc.sheets.first
|
||||
lists = sheet.rows
|
||||
|
||||
lists.each_with_index do |list, index|
|
||||
if index > 0
|
||||
puts "--------------------------------user_name:#{list[0]}, user_phone:#{list[1]}"
|
||||
user_name = list[0]
|
||||
user_phone = list[1]
|
||||
if user_name.present? && user_phone.present?
|
||||
begin
|
||||
status = Trustie::Sms.send(mobile: user_phone, send_type:'competition_notice' , name: user_name)
|
||||
rescue => e
|
||||
puts "--------------------------------发送验证码出错: #{user_name}---#{user_phone}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
puts "--------------------------------只支持xlsx文件"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,44 @@
|
||||
namespace :homework do
|
||||
def tran_base64_decode64 str
|
||||
if str.blank?
|
||||
str
|
||||
else
|
||||
s_size = str.size % 4
|
||||
if s_size != 0
|
||||
str += "=" * (4 - s_size)
|
||||
end
|
||||
Base64.decode64(str.tr("-_", "+/")).force_encoding("utf-8")
|
||||
end
|
||||
end
|
||||
|
||||
task :gitfiledown => :environment do
|
||||
# begin
|
||||
puts ENV['args']
|
||||
system("tmp/homework_file") if File.exist?("tmp/homework_file")
|
||||
homework_common = HomeworkCommon.find(ENV['args'])
|
||||
student_works = homework_common.student_works
|
||||
g = Gitlab.client
|
||||
student_works.each do |sw|
|
||||
username = sw.user.try(:show_real_name)
|
||||
myshixun = sw.try(:myshixun)
|
||||
puts myshixun.try(:gpid)
|
||||
if myshixun.try(:gpid)
|
||||
content = g.files(myshixun.gpid, "PL/PL.cpp", "master").try(:content)
|
||||
tran_content = tran_base64_decode64(content)
|
||||
path = "tmp/homework_file/#{username}"
|
||||
FileUtils.mkdir_p(path) unless File.exist?(path)
|
||||
system("cd #{path}; touch PL.cpp")
|
||||
aFile = File.new("#{path}/PL.cpp", "r+")
|
||||
if aFile
|
||||
aFile.syswrite(tran_content)
|
||||
else
|
||||
puts "Unable to open file!"
|
||||
end
|
||||
end
|
||||
end
|
||||
# rescue Exception => e
|
||||
# Rails.logger.error(e.message)
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in new issue