From a7c57c5b52c9f5e07cc53ac92bef8c69e2d35a35 Mon Sep 17 00:00:00 2001 From: huang Date: Sun, 12 Nov 2017 15:42:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) 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