作业导入

This commit is contained in:
huang 2017-11-12 15:42:37 +08:00
parent 00e250f1b8
commit a7c57c5b52
1 changed files with 15 additions and 9 deletions

View File

@ -44,16 +44,22 @@ class CoursesController < ApplicationController
name = attachment.disk_filename name = attachment.disk_filename
lists = readData("files/#{path}/#{name}") lists = readData("files/#{path}/#{name}")
homework = HomeworkCommon.find params[:homework] homework = HomeworkCommon.find params[:homework]
users = User.where(:id => @course.members.map(&:user_id))
if homework.present? if homework.present?
lists.each do |list, index| lists.each_with_index do |list, index|
logger.info("#{list[0]}---#{list[1]}") unless list.nil?
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 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
if user.present? #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
logger.info("#{index}---------------------------------#{user.id}") # 用户存在并且用户是非课程成员
work = homework.student_works.where(:user_id => user.id, :work_score => nil).first if user.present?
if work.present? logger.info("#{index}---------------------------------#{user.id}")
work.update_attributes(:work_status => 1, :work_score => list[2]) 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 end
end end