diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index e1e8e226b..720f8f593 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1512,7 +1512,7 @@ class ExercisesController < ApplicationController end def get_exercise_question_counts #获取试卷的问题数及总分数 - exercise_questions = @exercise.exercise_questions.all + exercise_questions = @exercise.exercise_questions.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) @exercise_ques_count = exercise_questions.count # 全部的题目数 @exercise_ques_scores = exercise_questions.pluck(:question_score).sum diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 119226c87..6fbba1c3d 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -263,7 +263,6 @@ class PollsController < ApplicationController if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则问卷不用分组,且问卷设定为统一设置,否则则分组设置 poll.poll_group_settings.destroy_all poll_unified = true - notify_student_ids = @course.students.pluck(:user_id) else poll_unified = false g_course.each do |i| @@ -282,13 +281,11 @@ class PollsController < ApplicationController new_poll_group.save end end - - notify_student_ids = @course.students.where(course_group_id: params[:group_ids]).pluck(:user_id) + group_ids = params[:group_ids] end else poll.poll_group_settings.destroy_all poll_unified = true - notify_student_ids = @course.students.pluck(:user_id) end if poll.end_time.blank? e_time = ex_end_time @@ -309,7 +306,7 @@ class PollsController < ApplicationController if poll.course_acts.size == 0 poll.course_acts << CourseActivity.new(:user_id => poll.user_id,:course_id => poll.course_id) end - PollPublishNotifyJob.perform_later(poll.id, notify_student_ids) + PollPublishNotifyJob.perform_later(poll.id, group_ids) end end normal_status(0, "问卷发布成功!") diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 3b14eea84..a319dc58a 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -488,17 +488,19 @@ class ShixunsController < ApplicationController tip_show_exception(-3, "#{@shixun.opening_time.strftime('%Y-%m-%d %H:%M:%S')}") end current_myshixun = @shixun.current_myshixun(current_user.id) + + min_challenges = @shixun.challenges.pluck(:id , :st) + if current_myshixun + games = current_myshixun.games # 如果TPM和TPI的管卡数不相等或者关卡顺序错了,说明实训被极大的改动,需要重置 - if current_myshixun.games.count != @shixun.challenges_count || - current_myshixun.games.reorder(:challenge_id).pluck(:challenge_id) != @shixun.challenges.reorder(:id).pluck(:id) - uid_logger_error("7777777777777777#{current_myshixun.games.count}, #{@shixun.challenges_count}") + if games.size != min_challenges.size || games.map(&:challenge_id) != min_challenges.map{|challenge| challenge.first} # 这里页面弹框要收到 当前用户myshixun的identifier. tip_show_exception("/myshixuns/#{current_myshixun.try(:identifier)}/reset_my_game") end # 如果存在实训,则直接进入实训 - @current_task = current_myshixun.current_task + @current_task = current_myshixun.current_task(games) else # 如果未创建关卡一定不能开启实训,否则TPI没法找到当前的关卡 if @shixun.challenges_count == 0 @@ -506,10 +508,10 @@ class ShixunsController < ApplicationController end # 判断实训是否全为选择题 - is_choice_type = @shixun.is_choice_type? + is_choice_type = (min_challenges.size == min_challenges.select{|challenge| challenge.last == 1}.count) if !is_choice_type commit = GitService.commits(repo_path: @repo_path).try(:first) - Rails.logger.info("First comit########{commit}") + uid_logger("First comit########{commit}") tip_exception("开启实战前请先在版本库中提交代码") if commit.blank? commit_id = commit["id"] end @@ -528,13 +530,13 @@ class ShixunsController < ApplicationController # fork仓库 project_fork(myshixun, @repo_path, current_user.login) - #rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path ) - #uid_logger("start openGameInstance") - #uri = "#{cloud_bridge}/bridge/game/openGameInstance" - #logger.info("end openGameInstance") - #params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: myshixun.repo_name.split("/").last} - #uid_logger("openGameInstance params is #{params}") - # res = interface_post uri, params, 83, "实训云平台繁忙(繁忙等级:83)" + rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path ) + uid_logger("start openGameInstance") + uri = "#{cloud_bridge}/bridge/game/openGameInstance" + logger.info("end openGameInstance") + params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: myshixun.repo_name.split("/").last} + uid_logger("openGameInstance params is #{params}") + interface_post uri, params, 83, "实训云平台繁忙(繁忙等级:83)" end # 其它创建关卡等操作 challenges = @shixun.challenges @@ -565,6 +567,7 @@ class ShixunsController < ApplicationController end end end + # gameID 及实训ID # status: 0 , 1 申请过, 2,实训关卡路径未填, 3 实训标签未填, 4 实训未创建关卡 def publish diff --git a/app/helpers/student_works_helper.rb b/app/helpers/student_works_helper.rb index 17cdd41a7..a7103b4bf 100644 --- a/app/helpers/student_works_helper.rb +++ b/app/helpers/student_works_helper.rb @@ -145,7 +145,7 @@ module StudentWorksHelper else user_name = message_user.real_name user_login = message_user.login - image_url = url_to_avatar(score.user) + image_url = url_to_avatar(message_user) end {user_name: user_name, user_login: user_login, user_image_url: image_url} end diff --git a/app/jobs/poll_publish_notify_job.rb b/app/jobs/poll_publish_notify_job.rb index bc31957e0..d7ed1ae02 100644 --- a/app/jobs/poll_publish_notify_job.rb +++ b/app/jobs/poll_publish_notify_job.rb @@ -2,10 +2,20 @@ class PollPublishNotifyJob < ApplicationJob queue_as :notify - def perform(poll_id, receiver_ids) + def perform(poll_id, group_ids) poll = Poll.find_by(id: poll_id) return if poll.blank? user = poll.user + course = poll.course + + if group_ids.present? + students = course.students.where(course_group_id: group_ids) + subquery = course.teacher_course_groups.where(course_group_id: group_ids).select(:course_member_id) + teachers = course.teachers.where(id: subquery) + else + students = course.students + teachers = course.teachers + end attrs = %i[ user_id trigger_user_id container_id container_type parent_container_id parent_container_type @@ -19,14 +29,14 @@ class PollPublishNotifyJob < ApplicationJob viewed: 0, tiding_type: 'Poll' } Tiding.bulk_insert(*attrs) do |worker| - teacher_ids = poll.course.teachers.pluck(:user_id) + teacher_ids = teachers.pluck(:user_id) unless poll.tidings.exists?(parent_container_type: 'PollPublish', user_id: teacher_ids) poll.course.teachers.find_each do |teacher| worker.add same_attrs.merge(user_id: teacher.user_id) end end - receiver_ids.each do |user_id| + students.pluck(:user_id).each do |user_id| worker.add same_attrs.merge(user_id: user_id) end end diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index a1aca3253..d8f294a39 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -53,14 +53,12 @@ class Myshixun < ApplicationRecord end # 当前任务:一个实训中只可能一个未完成任务(status 0或1只会存在一条记录) - # status:0 可以测评的,正在测评的 + # status:0 可以测评的; 1 正在测评的; 2评测通过的; 3未开启的 # 如果都完成,则当前任务为最后一个任务 - def current_task - games = self.games + def current_task games current_game = games.select{|game| game.status == 1 || game.status == 0}.first if current_game.blank? - current_game = Game.find_by_sql("SELECT g.* FROM games g, challenges c where g.myshixun_id=#{self.id} - and g.challenge_id = c.id and g.status = 2 order by c.position desc").first + current_game = games.last end current_game end diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 28857dff9..8ee1d0cd4 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -47,7 +47,7 @@ class ExerciseUserPdfService end def load_data - @exercise_questions = exercise.exercise_questions + @exercise_questions = exercise.exercise_questions.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) @exercise_ques_count = @exercise_questions.count # 全部的题目数 @exercise_ques_scores = @exercise_questions.pluck(:question_score).sum @@ -81,7 +81,6 @@ class ExerciseUserPdfService @exercise_ques_shixun_count = exercise_ques_shixun.all.count @exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum - @exercise_questions = @exercise_questions.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) get_each_student_exercise(exercise.id,@exercise_questions,@ex_user_user.id) end diff --git a/app/services/git_service.rb b/app/services/git_service.rb index 3298185bf..076f62920 100644 --- a/app/services/git_service.rb +++ b/app/services/git_service.rb @@ -33,7 +33,12 @@ class GitService res = https.request(req) body = res.body logger.info("--uri_exec: .....res is #{body}") + content = JSON.parse(body) + if content["code"] != 0 + raise("版本库异常") + logger.error("repository error: #{content['msg']}") + end #raise content["msg"] if content["code"] != 0 content["data"] diff --git a/lib/tasks/graduation_task.rake b/lib/tasks/graduation_task.rake index 0d4dff237..58f7764d0 100644 --- a/lib/tasks/graduation_task.rake +++ b/lib/tasks/graduation_task.rake @@ -7,7 +7,7 @@ namespace :graduation_task do task.update_attributes(status: 1) GraduationTaskPublishNotifyJob.perform_later(task.id) - task.course_acts << CourseActivity.new(user_id: task.user_id, course_id: task.course_id) if task.course_acts.exists? + task.course_acts << CourseActivity.new(user_id: task.user_id, course_id: task.course_id) if !task.course_acts.exists? end end diff --git a/lib/tasks/homework_publishtime.rake b/lib/tasks/homework_publishtime.rake index 4c27f0317..7ee2a4a07 100644 --- a/lib/tasks/homework_publishtime.rake +++ b/lib/tasks/homework_publishtime.rake @@ -45,7 +45,7 @@ namespace :homework_publishtime do end end - homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id) if homework.course_acts.exists? + homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id) if !homework.course_acts.exists? end # 分组设置发布时间的作业 @@ -54,7 +54,7 @@ namespace :homework_publishtime do homework = homework_group.homework_common if homework.present? HomeworkPublishUpdateWorkStatusJob.perform_now([homework_group.id], homework.id) - HomeworkCommonPushNotifyJob.perform_later(homework.id, [homework_group.id]) + HomeworkCommonPushNotifyJob.perform_later(homework.id, [homework_group.course_group_id]) end end Rails.logger.info("log--------------------------------homework_publish end") diff --git a/lib/tasks/poll_publish.rake b/lib/tasks/poll_publish.rake index 6ced88908..8cec43565 100644 --- a/lib/tasks/poll_publish.rake +++ b/lib/tasks/poll_publish.rake @@ -9,39 +9,22 @@ namespace :poll_publish do polls = Poll.includes(:poll_users).where("publish_time is not null and polls_status = 1 and publish_time <=?",Time.now) polls.each do |poll| poll.update_attributes(:polls_status => 2) - course = poll.course - tid_str = "" - course.teachers.find_each do |member| - tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id}, #{poll.user_id}, #{poll.id}, 'Poll', #{poll.id}, 'PollPublish', #{course.id}, 'Course', 0, 'Poll', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end if poll.unified_setting - course.students.find_each do |student| + PollPublishNotifyJob.perform_later(poll.id, nil) + else + course = poll.course + teachers = course.teachers.where.not(id: course.teacher_course_groups.select(:course_member_id)) + tid_str = "" + teachers.find_each do |member| tid_str += "," if tid_str != "" - tid_str += "(#{student.user_id}, #{poll.user_id}, #{poll.id}, 'Poll', #{poll.id}, 'PollPublish', #{course.id}, 'Course', 0, 'Poll', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - end - if tid_str != "" - tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str - ActiveRecord::Base.connection.execute tid_sql - end - - if poll.poll_users.count == 0 - str = "" - course.students.find_each do |student| - str += "," if str != "" - str += "(#{student.user_id},#{poll.id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" + tid_str += "(#{member.user_id}, #{poll.user_id}, #{poll.id}, 'Poll', #{poll.id}, 'PollPublish', #{course.id}, 'Course', 0, 'Poll', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end - - if str != "" - sql = "insert into poll_users (user_id, poll_id, commit_status, created_at, updated_at) values" + str - ActiveRecord::Base.connection.execute sql + if tid_str != "" + tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str + ActiveRecord::Base.connection.execute tid_sql end end - - if poll.course_acts.size == 0 - poll.course_acts << CourseActivity.new(:user_id => poll.user_id,:course_id => poll.course_id) - end + poll.course_acts << CourseActivity.new(user_id: poll.user_id, course_id: poll.course_id) if !poll.course_acts.exists? end # 分组设置发布时间的问卷 @@ -49,19 +32,8 @@ namespace :poll_publish do poll_group_settings.each do |poll_group| poll = poll_group.poll if poll.present? - course = poll.course poll.update_attributes(:polls_status => 2) if poll.polls_status == 1 - - tid_str = "" - members = course.course_members.where(:course_group_id => poll_group.course_group_id) - members.find_each do |member| - tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id},#{poll.user_id}, #{poll.id}, 'Poll', #{poll.id}, 'PollPublish', #{course.id}, 'Course', 0, 'Poll', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if tid_str != "" - tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str - ActiveRecord::Base.connection.execute tid_sql - end + PollPublishNotifyJob.perform_later(poll.id, [poll_group.course_group_id]) end end