From 2de80c4a641e1c0976a07fc04aeaa1c626b2b9e6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 15:43:31 +0800 Subject: [PATCH 1/3] =?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/controllers/student_works_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 4d98ea02b..15b59e863 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -44,8 +44,8 @@ class StudentWorksController < ApplicationController # 统一设置的作业取所有学生,否则取已发布的分班学生 students = @homework.unified_setting? ? @course.students : @course.students.where(course_group_id: @homework.published_settings.pluck(:course_group_id)) unless params[:search].blank? - @members = students.joins(:user).where("user_id != #{current_user.id} and - concat(users.lastname, users.firstname) like ?", "%#{params[:search]}%") + @members = students.joins(user: :user_extensions).where("user_id != #{current_user.id} and (concat(users.lastname, users.firstname) + like ? or user_extensions.student_id like ?)", "%#{params[:search]}%", "%#{params[:search]}%") else # 没有搜索条件时搜索课堂所有未提交的学生 From eb7655d0517a03ea55554b5ee552512feaad2bef Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 21 Jun 2019 15:46:28 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/tasks/exercise_publish_task.rb | 68 ++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index d0a52646b..7f3ee63ee 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -67,41 +67,75 @@ class ExercisePublishTask end def end - exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now) + exercises = Exercise.where("end_time <= ? and exercise_status = ?",Time.now,2) exercises.each do |exercise| course = exercise.course - exercise.update_column('exercise_status', 3) - + ex_type = exercise.exercise_questions.pluck(:question_type).uniq + exercise.update_attribute('exercise_status', 3) exercise.exercise_users.each do |exercise_user| if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? - exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) - + # exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] - exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) - if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? - exercise_user.update_attributes(:subjective_score => 0) + if ex_type.include?(4) #是否包含主观题 + subjective_score = exercise_user.subjective_score + else + subjective_score = -1.0 end + # subjective_score = exercise_user.subjective_score + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = s_score + total_score_subjective_score + commit_option = { + :status => 1, + :commit_status => 1, + :end_at => Time.now, + :objective_score => s_score, + :score => total_score, + :subjective_score => subjective_score + } + exercise_user.update_attributes(commit_option) + # if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? + # exercise_user.update_attributes(:subjective_score => 0) + # end end end end - all_exercises = Exercise.where("end_time > ? and exercise_status = 2",Time.now) + all_exercises = Exercise.where("end_time > ? and exercise_status = ?",Time.now,2) exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" - ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}").each do |exercise_setting| + ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}") + ex_group_settings.each do |exercise_setting| exercise = exercise_setting.exercise - + ex_types = exercise.exercise_questions.pluck(:question_type).uniq users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id) exercise_users = exercise.exercise_users.where(:user_id => users.map(&:user_id)) exercise_users.each do |exercise_user| if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? - exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) - - s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] - exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) - if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? - exercise_user.update_attributes(:subjective_score => 0) + if ex_types.include?(4) #是否包含主观题 + subjective_score = exercise_user.subjective_score + else + subjective_score = -1.0 end + s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] + # subjective_score = exercise_user.subjective_score + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = s_score + total_score_subjective_score + commit_option = { + :status => 1, + :commit_status => 1, + :end_at => Time.now, + :objective_score => s_score, + :score => total_score, + :subjective_score => subjective_score + } + exercise_user.update_attributes(commit_option) + # exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) + + # s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] + # exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) + # if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? + # exercise_user.update_attributes(:subjective_score => 0.0) + # end end end end From 32e2872bbd73431f7bf1805e195367329b316784 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 21 Jun 2019 15:48:55 +0800 Subject: [PATCH 3/3] modify users controller code --- app/controllers/users_controller.rb | 27 ++++++++++----------- app/views/users/reply_message.json.jbuilder | 1 - 2 files changed, 13 insertions(+), 15 deletions(-) delete mode 100644 app/views/users/reply_message.json.jbuilder diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 17281087b..d01973175 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -9,10 +9,6 @@ class UsersController < ApplicationController @user = User.find params[:id] @user.update!(user_params) render_ok - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback end # 贴吧获取用户信接口 @@ -69,21 +65,24 @@ class UsersController < ApplicationController # 用户回复功能 def reply_message - @message = JournalsForMessage.new(reply_message_params) - @message.user_id = current_user.id - @message.save! - #normal_status("回复成功") + message = JournalsForMessage.new(reply_message_params) + message.user_id = current_user.id + message.save! + + render_ok(id: message.id) end # 搜索用户具有管理员角色的项目 def search_user_projects - condition = '%%' - condition = "%#{params[:search].strip}%".gsub(" ","") if !params[:search].blank? + projects = Project.where.not(status: 9) + + projects = projects.joins(members: :member_roles).where(member_roles: { role_id: 3 }) + projects = projects.where(members: { user_id: current_user.id }) + + search = params[:search].to_s.strip + projects = projects.where('projects.name LIKE ?', "%#{search}%") if search.present? - project_ids = Project.find_by_sql("SELECT p.id FROM projects p, members m, member_roles mr WHERE m.project_id = p.id - AND m.id=mr.member_id AND mr.role_id = 3 AND m.user_id=#{current_user.id} AND p.status != 9 and - p.name like '#{condition}'") - @projects = Project.where(id: project_ids.pluck(:id)) + @projects = projects.select(:id, :name) end # 个人主页信息 diff --git a/app/views/users/reply_message.json.jbuilder b/app/views/users/reply_message.json.jbuilder deleted file mode 100644 index 26052baa8..000000000 --- a/app/views/users/reply_message.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.id @message.id \ No newline at end of file