作业导入
This commit is contained in:
parent
00e250f1b8
commit
a7c57c5b52
|
@ -44,16 +44,22 @@ class CoursesController < ApplicationController
|
|||
name = attachment.disk_filename
|
||||
lists = readData("files/#{path}/#{name}")
|
||||
homework = HomeworkCommon.find params[:homework]
|
||||
users = User.where(:id => @course.members.map(&:user_id))
|
||||
if homework.present?
|
||||
lists.each do |list, index|
|
||||
logger.info("#{list[0]}---#{list[1]}")
|
||||
user = User.find_by_sql("SELECT u.* FROM `users` u, `user_extensions` ue where u.id = ue.user_id and CONCAT(u.lastname,u.firstname) ='#{list[1]}' and ue.student_id='#{list[0]}'").first
|
||||
# 用户存在并且用户是非课程成员
|
||||
if user.present?
|
||||
logger.info("#{index}---------------------------------#{user.id}")
|
||||
work = homework.student_works.where(:user_id => user.id, :work_score => nil).first
|
||||
if work.present?
|
||||
work.update_attributes(:work_status => 1, :work_score => list[2])
|
||||
lists.each_with_index do |list, index|
|
||||
unless list.nil?
|
||||
logger.info("#{list[0]}---#{list[1]}")
|
||||
user = users.joins(:user_extensions).where("users.id = user_extensions.user_id and (CONCAT(users.lastname,users.firstname) ='#{list[1]}' or user_extensions.student_id='#{list[0]}')").first
|
||||
#user = users.find_by_sql("SELECT u.* FROM `users` u, `user_extensions` ue where u.id = ue.user_id and CONCAT(u.lastname,u.firstname) ='#{list[1]}' and ue.student_id='#{list[0]}'").first
|
||||
# 用户存在并且用户是非课程成员
|
||||
if user.present?
|
||||
logger.info("#{index}---------------------------------#{user.id}")
|
||||
work = homework.student_works.where(:user_id => user.id, :work_score => nil).first
|
||||
if work.present?
|
||||
work.update_column('work_status', 1)
|
||||
work.update_column('final_score', list[2].try(:to_f))
|
||||
work.update_column('work_score', list[2].try(:to_f))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue