From 705363130d913e9c56ef7b411e9b4d3202931356 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 8 Jul 2019 17:26:24 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=BA=E9=99=B7'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/game.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/game.rb b/app/models/game.rb index ba6664d5c..eed425ea6 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -20,9 +20,9 @@ class Game < ApplicationRecord #全部关卡数 scope :ch_games, lambda { |challenge_id| where(challenge_id:challenge_id) } # 已通关的数量 - scope :finished_num, -> (challenge_id) { where(:challenge_id => challenge_id, :status => 1)} + scope :finished_num, -> (challenge_id) { where(:challenge_id => challenge_id, :status => 2)} # 正在通关的数量 - scope :doing_num, -> (challenge_id) { where(:challenge_id => challenge_id, :status => 0)} + scope :doing_num, -> (challenge_id) { where(:challenge_id => challenge_id, :status => [0,1])} #用户的全部关卡 scope :user_games, lambda { |user_id,challenge_id| where("user_id = ? AND challenge_id = ?",user_id,challenge_id) } From d9e274b2988caa26d39534595f0a0f1a4154a1e2 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 17:48:23 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/polls_controller.rb | 8 +++--- app/helpers/polls_helper.rb | 19 ++++++++----- app/models/exercise.rb | 10 +++---- app/models/poll.rb | 41 ++++++++++++++++++++++------- 4 files changed, 53 insertions(+), 25 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 47ad365f5..e2d0ce3cd 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -88,7 +88,7 @@ class PollsController < ApplicationController @limit = params[:limit] || 15 @polls = @polls.page(@page).per(@limit) - @polls = @polls&.includes(:poll_users,:poll_questions,:poll_group_settings) + @polls = @polls&.includes(:published_settings) else @polls = [] end @@ -965,7 +965,7 @@ class PollsController < ApplicationController if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的问卷 @poll_current_user_status = 0 @poll_users_list = @poll.all_poll_users(current_user.id) #该老师分班的全部学生 - get_poll_answers(@poll_users_list) + get_poll_answers(@poll_users_list, @poll_list_status) if @poll_list_status == 1 @poll_course_groups =[] else @@ -977,7 +977,7 @@ class PollsController < ApplicationController end elsif @user_course_identity > Course::ASSISTANT_PROFESSOR @poll_all_users = @poll.get_poll_exercise_users - get_poll_answers(@poll_all_users) # 未答和已答的 + get_poll_answers(@poll_all_users, @poll_list_status) # 未答和已答的 @poll_course_groups = [] #当为学生的时候,不显示分班情况 @poll_current_user_status = 1 #当前用户的状态,为学生 poll_current_user = @poll_all_users.find_by_group_ids(current_user.id) #当前用户是否开始做问卷(提交/未提交/没做) @@ -988,7 +988,7 @@ class PollsController < ApplicationController end else @poll_all_users = @poll.get_poll_exercise_users - get_poll_answers(@poll_all_users) # 未答和已答的 + get_poll_answers(@poll_all_users, @poll_list_status) # 未答和已答的 @poll_current_user_status = 2 #当前用户非课堂成员 @poll_users_list = [] end diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 54a9fe1f0..f6dc3fc89 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -1,10 +1,15 @@ module PollsHelper #获取试卷的已答/未答人数 - def get_poll_answers(poll_users) - @poll_answers = poll_users.commit_by_status(1).size #表示已经提交了的用户 - course_all_members_count = poll_users.size - @poll_unanswers = (course_all_members_count - @poll_answers) + def get_poll_answers(poll_users, status) + if status == 1 + @poll_answers = poll_users.commit_by_status(1).size #表示已经提交了的用户 + course_all_members_count = poll_users.size + @poll_unanswers = (course_all_members_count - @poll_answers) + else + @poll_answers = 0 + @poll_unanswers = 0 + end end def poll_votes_count(votes,user_ids) @@ -59,7 +64,7 @@ module PollsHelper if is_teacher_or == 1 poll_users_list = poll.all_poll_users(user.id) #当前老师所在班级的全部学生 - get_poll_answers(poll_users_list) + get_poll_answers(poll_users_list, poll_status) ex_pb_time = poll.get_poll_times(user.id,true) poll_publish_time = ex_pb_time[:publish_time] poll_end_time = ex_pb_time[:end_time] @@ -67,7 +72,7 @@ module PollsHelper lock_icon = 0 #不显示锁图标 elsif is_teacher_or == 2 poll_users_list = poll.get_poll_exercise_users - get_poll_answers(poll_users_list) # 未答和已答的 + get_poll_answers(poll_users_list, poll_status) # 未答和已答的 # get_poll_answers(poll_all_users) ex_pb_time = poll.get_poll_times(user.id,false) poll_publish_time = ex_pb_time[:publish_time] @@ -76,7 +81,7 @@ module PollsHelper lock_icon = 0 #不显示锁图标 else poll_users_list = poll.get_poll_exercise_users - get_poll_answers(poll_users_list) # 未答和已答的 + get_poll_answers(poll_users_list, poll_status) # 未答和已答的 poll_publish_time = poll.publish_time poll_end_time = poll.end_time current_status = 4 diff --git a/app/models/exercise.rb b/app/models/exercise.rb index e3a89a19a..cc7c99f1b 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -42,7 +42,7 @@ class Exercise < ApplicationRecord if unified_setting #试卷统一设置 exercise_users else - ex_group_setting_ids = exercise_group_settings.exercise_group_published.pluck(:course_group_id) + ex_group_setting_ids = published_settings.pluck(:course_group_id) exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). where(course_members: {course_group_id: ex_group_setting_ids}) end @@ -59,15 +59,15 @@ class Exercise < ApplicationRecord # 根据是否统一发布获取作业的作品列表 def all_works - exercise_users = self.unified_setting ? self.exercise_users : - self.exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). - where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)}) + exercise_users = unified_setting ? exercise_users : + exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: published_settings.pluck(:course_group_id)}) end # 分班权限的老师可见的作品列表 def all_exercise_users user_id # member = course.course_member(user_id) - teacher_course_groups = course.teacher_course_groups.where(user_id: user_id) + teacher_course_groups = course.teacher_course_groups.get_user_groups ex_users = self.all_works # 有分班权限的统计管理的分班且已发布的学生情况 if teacher_course_groups.exists? diff --git a/app/models/poll.rb b/app/models/poll.rb index a055fd656..3edc3c661 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -8,6 +8,7 @@ class Poll < ApplicationRecord has_many :poll_users, -> { where("is_delete != 1") }, :dependent => :delete_all has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 has_many :poll_group_settings, :dependent => :delete_all + has_many :published_settings, -> { poll_group_published }, class_name: "PollGroupSetting" has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :delete_all has_many :tidings, as: :container, dependent: :delete_all @@ -44,21 +45,43 @@ class Poll < ApplicationRecord if unified_setting #试卷统一设置 poll_users else - ex_group_setting_ids = poll_group_settings.poll_group_published.pluck(:course_group_id) - poll_users.where(user_id: course.students.where(course_group_id:ex_group_setting_ids).pluck(:user_id).uniq) + ex_group_setting_ids = published_settings.pluck(:course_group_id) + poll_users.joins("join course_members on poll_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: ex_group_setting_ids}) end end - # 统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生 - def all_poll_users(user_id) - poll_all_users = poll_users - group_ids = poll_published_ids(user_id) - if group_ids.present? - poll_all_users = poll_all_users.where(user_id: course.students.where(course_group_id: group_ids).select(:user_id).pluck(:user_id).uniq) + # 根据是否统一发布获取作业的作品列表 + def all_works + poll_users = unified_setting ? poll_users : + poll_users.joins("join course_members on poll_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: published_settings.pluck(:course_group_id)}) + end + + # 分班权限的老师可见的作品列表 + def all_poll_users user_id + # member = course.course_member(user_id) + teacher_course_groups = course.teacher_course_groups.get_user_groups + poll_users = self.all_works + # 有分班权限的统计管理的分班且已发布的学生情况 + if teacher_course_groups.exists? + group_ids = teacher_course_groups.pluck(:course_group_id) + poll_users = poll_users.joins("join course_members on poll_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: group_ids}) end - poll_all_users + poll_users end + # # 统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生 + # def all_poll_users(user_id) + # poll_all_users = poll_users + # group_ids = poll_published_ids(user_id) + # if group_ids.present? + # poll_all_users = poll_all_users.where(user_id: course.students.where(course_group_id: group_ids).select(:user_id).pluck(:user_id).uniq) + # end + # poll_all_users + # end + #当前用户已发布的班级id和试卷分组已发布的班级id的交集 def poll_published_ids(user_id) current_user_groups = course.teacher_course_ids(user_id) From fc37a72d11d70e87be4ae7d7eec97fd61b883bdb Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 17:49:43 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise.rb | 2 +- app/models/poll.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index cc7c99f1b..0b4aca8eb 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -67,7 +67,7 @@ class Exercise < ApplicationRecord # 分班权限的老师可见的作品列表 def all_exercise_users user_id # member = course.course_member(user_id) - teacher_course_groups = course.teacher_course_groups.get_user_groups + teacher_course_groups = course.teacher_course_groups.get_user_groups(user_id) ex_users = self.all_works # 有分班权限的统计管理的分班且已发布的学生情况 if teacher_course_groups.exists? diff --git a/app/models/poll.rb b/app/models/poll.rb index 3edc3c661..d37ea8458 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -61,7 +61,7 @@ class Poll < ApplicationRecord # 分班权限的老师可见的作品列表 def all_poll_users user_id # member = course.course_member(user_id) - teacher_course_groups = course.teacher_course_groups.get_user_groups + teacher_course_groups = course.teacher_course_groups.get_user_groups(user_id) poll_users = self.all_works # 有分班权限的统计管理的分班且已发布的学生情况 if teacher_course_groups.exists? From a025e17daa685599f3f5982101bbdd0cb564753b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 17:57:44 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise.rb | 2 +- app/models/poll.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 0b4aca8eb..f9efabbd8 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -59,7 +59,7 @@ class Exercise < ApplicationRecord # 根据是否统一发布获取作业的作品列表 def all_works - exercise_users = unified_setting ? exercise_users : + ex_users = unified_setting ? exercise_users : exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). where(course_members: {course_group_id: published_settings.pluck(:course_group_id)}) end diff --git a/app/models/poll.rb b/app/models/poll.rb index d37ea8458..381a7f359 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -53,7 +53,7 @@ class Poll < ApplicationRecord # 根据是否统一发布获取作业的作品列表 def all_works - poll_users = unified_setting ? poll_users : + po_users = unified_setting ? poll_users : poll_users.joins("join course_members on poll_users.user_id=course_members.user_id"). where(course_members: {course_group_id: published_settings.pluck(:course_group_id)}) end From 74a5c849b0e4aeea3754c1df1585794d647c1deb Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 18:00:16 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/polls_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index f6dc3fc89..52e90f559 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -3,12 +3,12 @@ module PollsHelper #获取试卷的已答/未答人数 def get_poll_answers(poll_users, status) if status == 1 + @poll_answers = 0 + @poll_unanswers = 0 + else @poll_answers = poll_users.commit_by_status(1).size #表示已经提交了的用户 course_all_members_count = poll_users.size @poll_unanswers = (course_all_members_count - @poll_answers) - else - @poll_answers = 0 - @poll_unanswers = 0 end end From f6eadf1279fa963d2513fb343ffbcd7d3d14cda8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 10:29:05 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E6=95=99=E5=B8=88=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 50 +++++++++++++------ .../courses/apply_teachers.json.jbuilder | 13 +++++ app/views/courses/teachers.json.jbuilder | 13 +---- 3 files changed, 49 insertions(+), 27 deletions(-) create mode 100644 app/views/courses/apply_teachers.json.jbuilder diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index fa1d06d77..159650c38 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -13,7 +13,7 @@ class CoursesController < ApplicationController before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups, :left_banner, :top_banner] before_action :set_course, :user_course_identity, only: [:show, :update, :destroy, :settings, :set_invite_code_halt, - :set_public_or_private, :search_teacher_candidate, :teachers, + :set_public_or_private, :search_teacher_candidate, :teachers, :apply_teachers, :top_banner, :left_banner, :add_teacher_popup, :add_teacher, :graduation_group_list, :create_graduation_group, :join_graduation_group, :course_group_list, :set_course_group, :change_course_admin, :change_course_teacher, @@ -26,10 +26,10 @@ class CoursesController < ApplicationController :transfer_to_course_group, :delete_from_course, :search_users, :add_students_by_search, :get_historical_courses, :add_teacher_popup, :add_teacher] before_action :admin_allowed, only: [:set_invite_code_halt, :set_public_or_private, :change_course_admin, - :set_course_group, :delete_course_teacher, :teacher_application_review, - :create_group_by_importing_file] + :set_course_group, :delete_course_teacher, :create_group_by_importing_file] before_action :teacher_or_admin_allowed, only: [:graduation_group_list, :create_graduation_group, :join_graduation_group, - :change_course_teacher, :export_member_scores_excel, :course_group_list] + :change_course_teacher, :export_member_scores_excel, :course_group_list, + :teacher_application_review, :apply_teachers] before_action :validate_course_name, only: [:create, :update] before_action :find_board, only: :board_list before_action :validate_page_size, only: :mine @@ -251,46 +251,52 @@ class CoursesController < ApplicationController if @course.try(:id) != 1309 || current_user.admin? || current_user.try(:id) == 15582 @teacher_list = @course.course_members.joins(:user).where("course_members.role in (1, 2, 3) - and LOWER(concat(users.lastname, users.firstname)) LIKE '%#{@search_str}%'") + and LOWER(concat(users.lastname, users.firstname)) LIKE ?", "%#{@search_str}%") else @teacher_list = @course.course_members.joins(:user).where("(course_members.role in (1, 3) or (course_members.user_id = #{current_user.id} and course_members.role = 2)) and LOWER(concat(users.lastname, users.firstname)) - LIKE '%#{@search_str}%'") + LIKE ?", "%#{@search_str}%") end @teacher_list_size = @teacher_list.size @has_graduation_design = @course.course_modules.graduation_module_not_hidden.any? + sort = params[:sort] || "desc" @order = params[:order].to_i if @order.present? case @order when 1 - @teacher_list = @teacher_list.includes(:user).order("CONVERT(CONCAT(users.lastname, users.firstname) USING gbk) COLLATE gbk_chinese_ci asc") + @teacher_list = @teacher_list.order("role #{sort}") when 2 - @teacher_list = @teacher_list.order("created_at") + @teacher_list = @teacher_list.includes(:user).order("CONVERT(CONCAT(users.lastname, users.firstname) USING gbk) COLLATE gbk_chinese_ci #{sort}") when 3 - @teacher_list = @teacher_list.includes(:course, :graduation_group).order("graduation_groups.name") + @teacher_list = @teacher_list.includes(:course, :graduation_group).order("graduation_groups.name #{sort}") else - @teacher_list = @teacher_list.order("created_at") + @teacher_list = @teacher_list.order("role #{sort}") end else - if @has_graduation_design - @teacher_list = @teacher_list.includes(:course, :graduation_group).order("graduation_groups.name") - else - @teacher_list = @teacher_list.order("created_at") - end + @teacher_list = @teacher_list.order("role #{sort}") end @is_admin = @user_course_identity < Course::PROFESSOR - @applications = @is_admin ? CourseMessage.unhandled_join_course_requests_by_course(@course) : CourseMessage.none + @applications_size = CourseMessage.unhandled_join_course_requests_by_course(@course).size page = params[:page] || 1 limit = params[:limit] || 20 @teacher_list = @teacher_list.page(page).per(limit) end + def apply_teachers + search_str = params[:search].present? ? params[:search].strip : "" + @applications = CourseMessage.unhandled_join_course_requests_by_course(@course).joins(:user). + where("LOWER(concat(users.lastname, users.firstname)) LIKE ?", "%#{search_str}%") + @teacher_list_size = @course.teachers.size + @applications_size = CourseMessage.unhandled_join_course_requests_by_course(@course).size + @is_admin = @user_course_identity < Course::PROFESSOR + end + # 打开添加教师或助教弹窗时访问的接口(需要返回该课堂所有答辩组和所有) def add_teacher_popup @graduation_groups = @course.graduation_groups @@ -577,6 +583,18 @@ class CoursesController < ApplicationController end new_teacher.save! + + # 课堂管理员才有分配权限,且课堂分班数大于0 + if @user_course_identity < Course::PROFESSOR && @course.course_groups_count > 0 && params[:group_id] && params[:group_id].size > 0 + # 分班全选则是不限,不需要做处理 + unless @course.course_groups.where(id: params[:group_id]).size == @course.course_groups_count + @course.course_groups.where(id: params[:group_id]).each do |group| + unless TeacherCourseGroup.where(course_id: @course.id, user_id: applier_user.id, course_group_id: group.id, course_member_id: new_teacher.id).exists? + TeacherCourseGroup.create(course_id: @course.id, user_id: applier_user.id, course_member_id: new_teacher.id, course_group_id: group.id) + end + end + end + end elsif approval == 2 course_message.reject! else diff --git a/app/views/courses/apply_teachers.json.jbuilder b/app/views/courses/apply_teachers.json.jbuilder new file mode 100644 index 000000000..aee0803b4 --- /dev/null +++ b/app/views/courses/apply_teachers.json.jbuilder @@ -0,0 +1,13 @@ +json.teacher_list_size @teacher_list_size +json.apply_size @applications_size +json.is_admin @is_admin +json.application_list do + json.array! @applications do |application| + json.application_id application.id + json.user_id application.course_message_id + json.name application.application_user.real_name + json.name_link user_path(application.application_user) + json.login application.application_user.login + json.role application.content.to_i == 3 || application.content.to_i == 7 ? "助教" : application.content.to_i == 2 || application.content.to_i == 9 ? "教师" : "" + end +end \ No newline at end of file diff --git a/app/views/courses/teachers.json.jbuilder b/app/views/courses/teachers.json.jbuilder index 1be1ce16c..6a8505964 100644 --- a/app/views/courses/teachers.json.jbuilder +++ b/app/views/courses/teachers.json.jbuilder @@ -17,14 +17,5 @@ json.teacher_list do end end json.teacher_list_size @teacher_list_size -json.application_list do - json.array! @applications do |application| - json.application_id application.id - json.user_id application.course_message_id - json.name application.application_user.real_name - json.name_link user_path(application.application_user) - json.login application.application_user.login - json.role application.content.to_i == 3 || application.content.to_i == 7 ? "助教" : application.content.to_i == 2 || application.content.to_i == 9 ? "教师" : "" - end -end -json.is_admin @is_admin +json.apply_size @applications_size +json.is_admin @is_admin \ No newline at end of file From e173cae3903bee6e537ab7d2d86e3dd7eb6aad38 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 9 Jul 2019 11:02:57 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9F=A5=E9=87=8D?= =?UTF-8?q?=E6=A3=80=E7=B4=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- app/helpers/exercises_helper.rb | 18 +++--------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 9048b0046..232250e4c 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1321,7 +1321,7 @@ class HomeworkCommonsController < ApplicationController .where(:user_id => user_ids).joins(user: :user_extension) # 按学号和姓名搜索 if params[:search] - @users_reviews = @users_reviews.where("concat(lastname, firstname) like ? or student_id like ?", params[:search], params[:search]) + @users_reviews = @users_reviews.where("concat(lastname, firstname) like :keyword or student_id like :keyword", keyword: "%#{params[:search]}%") end # 抄袭作品数 @copy_reviews_count = @users_reviews.count diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 655620db7..0b64cb916 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -89,11 +89,7 @@ module ExercisesHelper if ex.question_type <= 2 #单选题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id) #标准答案的位置 ex.exercise_choices.each do |c| - if standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 - right_answer = true - else - right_answer = false - end + right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) answer_users_count = answer_this_choice.count if effictive_users_count == 0 @@ -176,11 +172,7 @@ module ExercisesHelper # zero_scores = all_zero_scores - un_review_scores #已评阅,且答案未0分的人数 main_scores_array = [full_scores,no_full_scores,zero_scores,un_review_scores] main_scores_array.each_with_index do |s,index| - if index == 0 - right_answer = true - else - right_answer = false - end + right_answer = (index == 0) if effictive_users_count == 0 || s < 0 s = 0 score_percent = 0.0 @@ -207,11 +199,7 @@ module ExercisesHelper shixun_score_array = [full_scores,no_full_scores,all_zero_scores] shixun_chas = [] shixun_score_array.each_with_index do |s,index| - if index == 0 - right_answer = true - else - right_answer = false - end + right_answer = (index == 0) if effictive_users_count == 0 score_percent = 0.0 else From 952221970b9663edddf1c65542fe945ca362587a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 11:38:19 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/routes.rb b/config/routes.rb index ee8b6a187..7e34363d1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -295,6 +295,7 @@ Rails.application.routes.draw do get 'course_group_list' get 'add_teacher_popup' get 'teachers' + get 'apply_teachers' get 'graduation_group_list' get 'top_banner' get 'left_banner' From ddc67bc14f08e21e53ac51310cb7cbcb0662179c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 14:03:38 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84=E5=B7=B2=E8=AF=84=E6=95=B0=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course.rb | 2 +- app/models/graduation_task.rb | 12 ++++++------ app/models/homework_common.rb | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/course.rb b/app/models/course.rb index d36d5d2c5..06090f236 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -258,7 +258,7 @@ class Course < ApplicationRecord # 是否具有分班权限,返回分班的id def group_course_power(user_id) - teacher_course_groups.where(user_id: user_id).pluck(:id) + teacher_course_groups.where(user_id: user_id).pluck(:course_group_id) end #课程动态公共表记录 diff --git a/app/models/graduation_task.rb b/app/models/graduation_task.rb index 030978817..e247f2b6e 100644 --- a/app/models/graduation_task.rb +++ b/app/models/graduation_task.rb @@ -100,15 +100,15 @@ class GraduationTask < ApplicationRecord SELECT count(distinct graduation_work_id) cnt FROM graduation_work_scores WHERE reviewer_role IN(1,2) AND graduation_work_id IN(SELECT id FROM graduation_works WHERE graduation_task_id = #{self.id} AND user_id IN(SELECT user_id FROM course_members WHERE role = 4 AND course_group_id - IN(SELECT course_group_id FROM teacher_course_groups WHERE id IN(#{course_group_ids.join(",")})) + IN(#{course_group_ids.join(",")}) ) ) } else %Q{ SELECT COUNT(distinct graduation_work_id) cnt FROM graduation_works gw - JOIN graduation_work_scores gwc ON gw.graduation_task_id = gwc.graduation_task_id - WHERE reviewer_role IN(1,2) AND gwc.graduation_task_id = #{self.id} + JOIN graduation_work_scores gwc ON gw.id = gwc.graduation_work_id + WHERE reviewer_role IN(1,2) AND gw.graduation_task_id = #{self.id} } end GraduationWorkScore.find_by_sql(sql).first.try(:cnt).to_i @@ -127,7 +127,7 @@ class GraduationTask < ApplicationRecord sql = %Q{ SELECT count(*) cnt FROM graduation_works gw WHERE work_status = 0 AND gw.graduation_task_id = #{self.id} AND gw.user_id IN( SELECT user_id FROM course_members WHERE role = 4 AND course_group_id - IN( SELECT course_group_id FROM teacher_course_groups WHERE id not IN(#{course_group_ids.join(",")}) ) + IN(#{course_group_ids.join(",")}) ) } GraduationWork.find_by_sql(sql).first.try(:cnt) @@ -144,7 +144,7 @@ class GraduationTask < ApplicationRecord sql = %Q{ SELECT count(*) cnt FROM graduation_works gw WHERE work_status = 1 AND gw.graduation_task_id = #{self.id} AND gw.user_id IN( SELECT user_id FROM course_members WHERE role = 4 AND course_group_id - IN( SELECT course_group_id FROM teacher_course_groups WHERE id IN(#{course_group_ids.join(",")}) ) + IN(#{course_group_ids.join(",")}) ) } GraduationWork.find_by_sql(sql).first.try(:cnt) @@ -160,7 +160,7 @@ class GraduationTask < ApplicationRecord sql = %Q{ SELECT count(*) cnt FROM graduation_works gw WHERE work_status = 2 AND gw.graduation_task_id = #{self.id} AND gw.user_id IN( SELECT user_id FROM course_members WHERE role = 4 AND course_group_id - IN( SELECT course_group_id FROM teacher_course_groups WHERE id IN(#{course_group_ids.join(",")}) ) + IN(#{course_group_ids.join(",")}) ) } GraduationWork.find_by_sql(sql).first.try(:cnt) diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 80b92d175..335b898fb 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -197,7 +197,7 @@ class HomeworkCommon < ApplicationRecord JOIN student_works_scores sws on sws.student_work_id = sw.id WHERE reviewer_role IN(1,2) AND sw.id IN (SELECT id FROM student_works WHERE homework_common_id = #{self.id} AND user_id IN (SELECT user_id FROM course_members WHERE role = 4 AND course_group_id - IN (SELECT course_group_id FROM teacher_course_groups WHERE id IN(#{course_group_ids.join(",")})) + IN (#{course_group_ids.join(",")}) ) ) } From 75ea0bd5cbabaa7c4e715ff008fadae4be306e82 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 9 Jul 2019 14:37:19 +0800 Subject: [PATCH 10/14] add sms type --- app/controllers/accounts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index e5d9ba5c4..d3808a06b 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -142,7 +142,7 @@ class AccountsController < ApplicationController # params[:login] 手机号或者邮箱号 # params[:type]为事件通知类型 1:用户注册注册 2:忘记密码 3: 绑定手机 4: 绑定邮箱 # 如果有新的继续后面加 # 发送验证码:send_type 1:注册手机验证码 2:找回密码手机验证码 3:找回密码邮箱验证码 4:绑定手机 5:绑定邮箱 - # 6:手机验证码登录 7:邮箱验证码登录 8:邮箱注册验证码 + # 6:手机验证码登录 7:邮箱验证码登录 8:邮箱注册验证码 9: 验收手机号有效 def get_verification_code code = %W(0 1 2 3 4 5 6 7 8 9) value = params[:login] From 0366af3a88f0176f2eafb8e460ad5999a912fa66 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 15:07:57 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 159650c38..e6c4ae330 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -290,7 +290,8 @@ class CoursesController < ApplicationController def apply_teachers search_str = params[:search].present? ? params[:search].strip : "" - @applications = CourseMessage.unhandled_join_course_requests_by_course(@course).joins(:user). + @applications = CourseMessage.unhandled_join_course_requests_by_course(@course). + joins("join users on course_messages.course_message_id=users.id"). where("LOWER(concat(users.lastname, users.firstname)) LIKE ?", "%#{search_str}%") @teacher_list_size = @course.teachers.size @applications_size = CourseMessage.unhandled_join_course_requests_by_course(@course).size From 008690be20d7db7d74a146e38e88eba384c74d1e Mon Sep 17 00:00:00 2001 From: jasder Date: Tue, 9 Jul 2019 15:31:43 +0800 Subject: [PATCH 12/14] FIX bug --- app/views/boards/destroy.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/boards/destroy.json.jbuilder b/app/views/boards/destroy.json.jbuilder index a9d8fbdaf..0fd68dc8c 100644 --- a/app/views/boards/destroy.json.jbuilder +++ b/app/views/boards/destroy.json.jbuilder @@ -1,2 +1,2 @@ json.status 0 -json.right_url course_board_messages_path(@course, @course_board) \ No newline at end of file +json.right_url board_messages_path(@course_board) From 3f6049df398585e94fbf7dd64dc52bff3a56affd Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 15:58:15 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E4=BD=9C=E5=93=81=E7=9A=84=E5=85=B3=E5=8D=A1=E5=88=86=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 35 ++++++++++++++----- app/models/challenge_work_score.rb | 8 +++++ .../adjust_review_score.json.jbuilder | 3 ++ .../shixun_work_report.json.jbuilder | 1 + 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 92d146c82..62d96c424 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -631,16 +631,35 @@ class StudentWorksController < ApplicationController # 查重作品调分 def adjust_review_score - if params[:score].nil? || params[:challenge_id].nil? || params[:code_rate].nil? || params[:copy_user_id].nil? + tip_exception("缺少type参数") if params[:type].blank? || ["review", "report"].include?(params[:type]) + if params[:type] == "review" && (params[:score].nil? || params[:challenge_id].nil? || params[:code_rate].nil? || params[:copy_user_id].nil?) tip_exception("参数错误,score和challenge_id和code_rate和copy_user_id不能为空") + elsif params[:type] == "report" && (params[:score].nil? || params[:challenge_id].nil?) + tip_exception("参数错误,score和challenge_id") + end + challenge_setting = @homework.homework_challenge_settings.find_by(challenge_id: params[:challenge_id]) + challenge = challenge_setting&.challenge + tip_exception("不能小于零") if params[:score] < 0 + tip_exception("不能大于关卡分值:#{challenge_setting.score}分") if challenge_setting.score < params[:score] + + ActiveRecord::Base.transaction do + begin + if params[:type] == "review" + copy_user = User.find params[:copy_user_id] + comment = "代码查重结果显示与#{copy_user.try(:show_real_name)}的代码相似度#{params[:code_rate]}%" + else + comment = "根据实训报告中最终提交的代码调整第#{challenge.position}关分数" + end + challenge_score = @work.challenge_work_scores.create(challenge_id: params[:challenge_id], user_id: current_user.id, score: params[:score], + comment: comment) + challenge_score.create_tiding current_user.id + HomeworksService.new.update_myshixun_work_score @work, @work&.myshixun, @work&.myshixun&.games, @homework, @homework.homework_challenge_settings + rescue Exception => e + uid_logger(e.message) + tip_exception(e.message) + raise ActiveRecord::Rollback + end end - copy_user = User.find params[:copy_user_id] - comment = "代码查重结果显示与#{copy_user.try(:show_real_name)}的代码相似度#{params[:code_rate]}%" - @work.challenge_work_scores.create(challenge_id: params[:challenge_id], user_id: current_user.id, score: params[:score], - comment: comment) - HomeworksService.new.set_shixun_final_score(@work) - @work_score = @homework.student_works.find_by(id: @work.id).try(:work_score) - end diff --git a/app/models/challenge_work_score.rb b/app/models/challenge_work_score.rb index 8316e228b..1e7c9f7fe 100644 --- a/app/models/challenge_work_score.rb +++ b/app/models/challenge_work_score.rb @@ -2,4 +2,12 @@ class ChallengeWorkScore < ApplicationRecord belongs_to :user belongs_to :student_work belongs_to :challenge + has_many :tidings, as: :container, dependent: :destroy + + def create_tiding trigger_user_id + tidings << Tiding.new(user_id: student_work.user_id, trigger_user_id: trigger_user_id, container_id: id, + container_type: "ChallengeWorkScore", parent_container_id: student_work_id, + parent_container_type: "StudentWork", belong_container_id: student_work&.homework_common&.course_id, + belong_container_type: "Course", viewed: 0, tiding_type: "HomeworkCommon") + end end diff --git a/app/views/student_works/adjust_review_score.json.jbuilder b/app/views/student_works/adjust_review_score.json.jbuilder index e69de29bb..399b52c13 100644 --- a/app/views/student_works/adjust_review_score.json.jbuilder +++ b/app/views/student_works/adjust_review_score.json.jbuilder @@ -0,0 +1,3 @@ +json.status 0 +json.message "调分成功" +json.work_score @work.work_score \ No newline at end of file diff --git a/app/views/student_works/shixun_work_report.json.jbuilder b/app/views/student_works/shixun_work_report.json.jbuilder index 1c6ed5899..f0aa8119e 100644 --- a/app/views/student_works/shixun_work_report.json.jbuilder +++ b/app/views/student_works/shixun_work_report.json.jbuilder @@ -24,6 +24,7 @@ if @shixun json.myself_experience game.final_score json.experience game.challenge.all_score json.complete_status game_status(game, @homework) + json.challenge_id game.challenge_id end end From 8bee375b67a224e583b9cfe56507ee1fea7684f8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 17:20:11 +0800 Subject: [PATCH 14/14] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E4=BD=9C=E5=93=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/graduation_works/edit.json.jbuilder | 2 ++ app/views/graduation_works/new.json.jbuilder | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/views/graduation_works/edit.json.jbuilder b/app/views/graduation_works/edit.json.jbuilder index 7fc3a9621..254579473 100644 --- a/app/views/graduation_works/edit.json.jbuilder +++ b/app/views/graduation_works/edit.json.jbuilder @@ -3,6 +3,8 @@ json.task_type @task.task_type json.work_id @work.id json.description @work.description json.user_name @task_user.real_name +json.max_num @task.max_num +json.min_num @task.min_num json.attachments @work.attachments do |atta| json.partial! "attachments/attachment_simple", locals: {attachment: atta, delete: @work.delete_atta(atta)} diff --git a/app/views/graduation_works/new.json.jbuilder b/app/views/graduation_works/new.json.jbuilder index 601ba02d3..26c046ab6 100644 --- a/app/views/graduation_works/new.json.jbuilder +++ b/app/views/graduation_works/new.json.jbuilder @@ -6,4 +6,6 @@ if @task.task_type == 2 json.user_id @user.id json.user_student_id @user.student_id json.group_name @course.course_member(@user.id).try(:course_group_name) + json.max_num @task.max_num + json.min_num @task.min_num end