Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_forum
daiao 5 years ago
commit f55e1568ed

@ -84,6 +84,7 @@ gem 'rails-i18n', '~> 5.1'
# job # job
gem 'sidekiq' gem 'sidekiq'
gem 'sinatra'
# batch insert # batch insert
gem 'bulk_insert' gem 'bulk_insert'

@ -142,6 +142,7 @@ GEM
multi_json (1.13.1) multi_json (1.13.1)
multi_xml (0.6.0) multi_xml (0.6.0)
multipart-post (2.0.0) multipart-post (2.0.0)
mustermann (1.0.3)
mysql2 (0.5.2) mysql2 (0.5.2)
nio4r (2.3.1) nio4r (2.3.1)
nokogiri (1.8.4) nokogiri (1.8.4)
@ -265,6 +266,11 @@ GEM
simple_xlsx_reader (1.0.4) simple_xlsx_reader (1.0.4)
nokogiri nokogiri
rubyzip rubyzip
sinatra (2.0.5)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.5)
tilt (~> 2.0)
spreadsheet (1.2.3) spreadsheet (1.2.3)
ruby-ole (>= 1.0) ruby-ole (>= 1.0)
spring (2.0.2) spring (2.0.2)
@ -341,6 +347,7 @@ DEPENDENCIES
selenium-webdriver selenium-webdriver
sidekiq sidekiq
simple_xlsx_reader simple_xlsx_reader
sinatra
spreadsheet spreadsheet
spring spring
spring-watcher-listen (~> 2.0.0) spring-watcher-listen (~> 2.0.0)

@ -1064,14 +1064,22 @@ class CoursesController < ApplicationController
AND student_works.user_id = cm.user_id AND student_works.user_id = cm.user_id
) AS score, ) AS score,
(SELECT max(student_id) FROM user_extensions WHERE user_extensions.user_id = cm.user_id) AS student_id, (SELECT max(student_id) FROM user_extensions WHERE user_extensions.user_id = cm.user_id) AS student_id,
(SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{@course.id} AND messages.author_id = cm.user_id and messages.parent_id is null) AS message_num, (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{@course.id}
(SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{@course.id} AND messages.author_id = cm.user_id and messages.parent_id is not null) AS message_reply_num, AND messages.author_id = cm.user_id and messages.parent_id is null) AS message_num,
(SELECT count(attachments.id) FROM attachments WHERE container_id = #{@course.id} and container_type = "Course" AND attachments.author_id = cm.user_id) AS resource_num, (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{@course.id}
(SELECT count(jfm.id) FROM journals_for_messages AS jfm, homework_commons hs WHERE jfm.jour_id = hs.id AND jfm.user_id = cm.user_id and jfm.jour_type = "HomeworkCommon" and hs.course_id = #{@course.id}) AS homework_journal_num, AND messages.author_id = cm.user_id and messages.parent_id is not null) AS message_reply_num,
(SELECT COUNT(gw.id) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND gt.course_id = #{@course.id} AND gw.work_status != 0 AND gw.user_id = cm.user_id) AS graduation_num, (SELECT count(attachments.id) FROM attachments WHERE container_id = #{@course.id} and container_type = "Course"
(SELECT COUNT(ss.id) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND hc.course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id) AS homework_num, AND attachments.author_id = cm.user_id) AS resource_num,
(SELECT COUNT(eu.id) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{@course.id} AND eu.commit_status = 1 AND eu.user_id = cm.user_id) AS exercise_num, (SELECT count(jfm.id) FROM journals_for_messages AS jfm, homework_commons hs WHERE jfm.jour_id = hs.id AND
(SELECT COUNT(pu.id) FROM poll_users AS pu, polls WHERE pu.poll_id = polls.id AND polls.course_id = #{@course.id} AND pu.commit_status = 1 AND pu.user_id = cm.user_id) AS poll_num jfm.user_id = cm.user_id and jfm.jour_type = "HomeworkCommon" and hs.course_id = #{@course.id}) AS homework_journal_num,
(SELECT COUNT(gw.id) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND
gt.course_id = #{@course.id} AND gw.work_status != 0 AND gw.user_id = cm.user_id) AS graduation_num,
(SELECT COUNT(ss.id) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND
hc.course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id) AS homework_num,
(SELECT COUNT(eu.id) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{@course.id}
AND eu.commit_status = 1 AND eu.user_id = cm.user_id) AS exercise_num,
(SELECT COUNT(pu.id) FROM poll_users AS pu, polls WHERE pu.poll_id = polls.id AND polls.course_id = #{@course.id}
AND pu.commit_status = 1 AND pu.user_id = cm.user_id) AS poll_num
FROM course_members cm} FROM course_members cm}
if search.present? && group_id.present? if search.present? && group_id.present?
sql_select += %Q{ join users on cm.user_id = users.id sql_select += %Q{ join users on cm.user_id = users.id
@ -1080,7 +1088,7 @@ class CoursesController < ApplicationController
(concat(users.lastname, users.firstname) like '%#{search}%' or ue.student_id like '%#{search}%') ORDER BY score desc} (concat(users.lastname, users.firstname) like '%#{search}%' or ue.student_id like '%#{search}%') ORDER BY score desc}
elsif search.present? elsif search.present?
ql_select += %Q{ join users on cm.user_id = users.id sql_select += %Q{ join users on cm.user_id = users.id
joins user_extensions ue on ue.user_id = users.id joins user_extensions ue on ue.user_id = users.id
WHERE cm.role = 4 and WHERE cm.role = 4 and
(concat(users.lastname, users.firstname) like '%#{search}%' or ue.student_id like '%#{search}%') ORDER BY score desc} (concat(users.lastname, users.firstname) like '%#{search}%' or ue.student_id like '%#{search}%') ORDER BY score desc}
@ -1103,7 +1111,7 @@ class CoursesController < ApplicationController
common_titles = common_homeworks.pluck(:name)+ ["总得分"] common_titles = common_homeworks.pluck(:name)+ ["总得分"]
common_homeworks = common_homeworks.includes(:score_student_works) common_homeworks = common_homeworks.includes(:score_student_works)
group_homeworks = homeworks.search_homework_type(3).includes(:score_student_works) #全部分组作业 group_homeworks = homeworks.search_homework_type(3) #全部分组作业
group_titles = group_homeworks.pluck(:name)+ ["总得分"] group_titles = group_homeworks.pluck(:name)+ ["总得分"]
group_homeworks = group_homeworks.includes(:score_student_works) group_homeworks = group_homeworks.includes(:score_student_works)
@ -1181,7 +1189,7 @@ class CoursesController < ApplicationController
c_poll_num = user_poll_num*7 c_poll_num = user_poll_num*7
c_file_num = user_file_num*5 c_file_num = user_file_num*5
c_message_num = user_messages_num*2 c_message_num = user_messages_num*2
c_reply_num = user_reply_num*2 c_reply_num = user_reply_num
user_activity_levels = c_works_num + c_exercise_num + c_poll_num + c_file_num + c_message_num + c_reply_num + user_work_reply_num user_activity_levels = c_works_num + c_exercise_num + c_poll_num + c_file_num + c_message_num + c_reply_num + user_work_reply_num
user_ac_level = { user_ac_level = {
u_1: user_name, u_1: user_name,

@ -200,7 +200,7 @@ class FilesController < ApplicationController
# 资源设置 # 资源设置
def update def update
return normal_status(403, "您没有权限进行该操作") unless current_user.teacher_or_admin?(@course) || @file.author == current_user return normal_status(403, "您没有权限进行该操作") if current_user.course_identity(@course) >= 5 && @file.author != current_user
is_unified_setting = params[:is_unified_setting] is_unified_setting = params[:is_unified_setting]
publish_time = params[:publish_time] publish_time = params[:publish_time]

@ -129,7 +129,7 @@ class GraduationTasksController < ApplicationController
if @user_course_identity >= Course::STUDENT if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作") tip_exception(403, "无权限操作")
elsif complete_works == 0 elsif complete_works == 0
normal_status(-1,"暂无提交的学生") normal_status(-1,"暂无用户提交!")
else else
respond_to do |format| respond_to do |format|
format.xlsx{ format.xlsx{

@ -200,7 +200,7 @@ class HomeworkCommonsController < ApplicationController
if @user_course_identity >= Course::STUDENT if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作") tip_exception(403, "无权限操作")
elsif complete_works == 0 elsif complete_works == 0
normal_status(-1,"暂无提交的学生") normal_status(-1,"暂无用户提交!")
else else
respond_to do |format| respond_to do |format|
format.xlsx{ format.xlsx{
@ -1117,7 +1117,7 @@ class HomeworkCommonsController < ApplicationController
=end =end
# 更新所有学生的效率分(重新取homework确保是更新后的) # 更新所有学生的效率分(重新取homework确保是更新后的)
HomeworksService.new.update_student_eff_score HomeworkCommon.find_by(id: homework.id) if !homework.allow_late && homework.end_time <= time HomeworkEndUpdateScoreJob.perform_later(homework.id) if !homework.allow_late && homework.end_time <= time
end end
end end
homework.save! homework.save!

@ -44,9 +44,12 @@ class ZipsController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
@exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id])
@exercise_status = @exercise.get_exercise_status(current_user.id)
group_id = params[:exercise_group_id] group_id = params[:exercise_group_id]
if @exercise.blank? if @exercise.blank?
normal_status(-1,"试卷不存在") normal_status(-1,"试卷不存在")
elsif @exercise_status == 1
normal_status(-1,"试卷未发布")
else else
@course = @exercise.course @course = @exercise.course
default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed
@ -66,7 +69,7 @@ class ZipsController < ApplicationController
if params[:commit_status].present? && (params[:commit_status].to_i == 1) if params[:commit_status].present? && (params[:commit_status].to_i == 1)
@exercise_users_list = @exercise_users_list.where(commit_status:params[:commit_status]) @exercise_users_list = @exercise_users_list.where(commit_status:params[:commit_status])
elsif params[:commit_status].present? && (params[:commit_status].to_i == 0) elsif params[:commit_status].present? && (params[:commit_status].to_i == 0)
normal_status(-1,"仅支持导出已提交的学生") normal_status(-1,"暂无用户提交")
end end
#可以分班选择 #可以分班选择
@ -84,7 +87,7 @@ class ZipsController < ApplicationController
default_ex_users_size = @ex_users&.size default_ex_users_size = @ex_users&.size
if default_ex_users_size.blank? || default_ex_users_size == 0 if default_ex_users_size.blank? || default_ex_users_size == 0
normal_status(-1,"导出失败,暂时没有已提交的学生") normal_status(-1,"暂无用户提交")
elsif default_ex_users_size > 100 elsif default_ex_users_size > 100
normal_status(-2,"100") normal_status(-2,"100")
end end
@ -98,6 +101,8 @@ class ZipsController < ApplicationController
def load_homework def load_homework
@homework = HomeworkCommon.find(params[:homework_common_id]) @homework = HomeworkCommon.find(params[:homework_common_id])
@course = @homework.course @course = @homework.course
##7。2 -hs新增 ##7。2 -hs新增
@member = @course.course_member(current_user.id) @member = @course.course_member(current_user.id)
@ -121,7 +126,7 @@ class ZipsController < ApplicationController
student_work_sizes = @all_student_works&.size student_work_sizes = @all_student_works&.size
if student_work_sizes.blank? || student_work_sizes == 0 if student_work_sizes.blank? || student_work_sizes == 0
normal_status(-1,"导出失败,暂时没有已提交的学生") normal_status(-1,"暂无用户提交")
elsif student_work_sizes > 100 elsif student_work_sizes > 100
normal_status(-2,"100") normal_status(-2,"100")
end end

@ -0,0 +1,32 @@
class HomeworkEndUpdateScoreJob < ApplicationJob
# 不允许补交的作业截止后,或者补交截止后需要重新计算一次作业成绩
queue_as :score
def perform(*args)
homework = HomeworkCommon.find_by(id: homework_id)
return if homework.blank?
course = homework.course
return if course.blank?
if homework.unified_setting
student_works = homework.student_works
user_ids = course.students.pluck(:user_id)
else
user_ids = course.students.where(course_group_id: homework.published_settings.pluck(:course_group_id)).pluck(:user_id)
student_works = homework.student_works.where(user_id: user_ids)
end
myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids).
includes(:games).where(games: {challenge_id: homework.homework_challenge_settings.pluck(:challenge_id)})
challenge_settings = homework.homework_challenge_settings
myshixuns.find_each(batch_size: 100) do |myshixun|
work = student_works.select{|work| work.user_id == myshixun.user_id}.first
if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at)
games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
HomeworksService.new.update_myshixun_work_score work, myshixun, games, homework, challenge_settings
end
end
HomeworksService.new.update_student_eff_score homework
homework.update_attribute('calculation_time', Time.now)
end
end

@ -45,7 +45,8 @@ class ExportShixunReportService
@games = @work.myshixun.games.includes(:challenge, :game_codes,:outputs) if @work.myshixun @games = @work.myshixun.games.includes(:challenge, :game_codes,:outputs) if @work.myshixun
# 用户最大评测次数 # 用户最大评测次数
@user_evaluate_count = @games.inject(0){|sum, g| sum + g.outputs.pluck(:query_index).first } if @games @user_evaluate_count = @games.pluck(:evaluate_count).sum if @games
# @user_evaluate_count = @games.inject(0){|sum, g| sum + g.outputs.pluck(:query_index)&.first } if @games
# 图形效率图的数据 # 图形效率图的数据
@echart_data = student_efficiency(homework, @work) @echart_data = student_efficiency(homework, @work)
@myself_eff = @echart_data[:efficiency_list].find { |item| item.last == @user.id } @myself_eff = @echart_data[:efficiency_list].find { |item| item.last == @user.id }

@ -1,5 +1,8 @@
Rails.application.routes.draw do Rails.application.routes.draw do
require 'sidekiq/web'
mount Sidekiq::Web => '/sidekiq'
resources :edu_settings resources :edu_settings
scope '/api' do scope '/api' do
get 'home/index' get 'home/index'

@ -84,7 +84,8 @@ namespace :homework_publishtime do
student_works.joins(:myshixun).where("myshixuns.status != 1").update_all(late_penalty: homework.late_penalty) if student_works.present? student_works.joins(:myshixun).where("myshixuns.status != 1").update_all(late_penalty: homework.late_penalty) if student_works.present?
else else
HomeworksService.new.update_student_eff_score homework HomeworkEndUpdateScoreJob.perform_later(homework.id)
# HomeworksService.new.update_student_eff_score homework
end end
=begin =begin
@ -206,7 +207,8 @@ namespace :homework_publishtime do
homework_commons = HomeworkCommon.joins(:homework_detail_manual).where("homework_type = 4 and allow_late = 1 and homework_commons = HomeworkCommon.joins(:homework_detail_manual).where("homework_type = 4 and allow_late = 1 and
late_time <= ? and late_time > ? and homework_detail_manuals.comment_status != 6", Time.now, Time.now - 900) late_time <= ? and late_time > ? and homework_detail_manuals.comment_status != 6", Time.now, Time.now - 900)
homework_commons.each do |homework| homework_commons.each do |homework|
HomeworksService.new.update_student_eff_score homework # HomeworksService.new.update_student_eff_score homework
HomeworkEndUpdateScoreJob.perform_later(homework.id)
=begin =begin
homework_detail_manual = homework.homework_detail_manual homework_detail_manual = homework.homework_detail_manual

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe HomeworkEndUpdateScoreJob, type: :job do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save