diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 2925a8cc7..89a5c84ca 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -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