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

dev_forum
jasder 5 years ago
commit 9f9f3a85f2

@ -142,7 +142,7 @@ class AccountsController < ApplicationController
# params[:login] 手机号或者邮箱号 # params[:login] 手机号或者邮箱号
# params[:type]为事件通知类型 1用户注册注册 2忘记密码 3: 绑定手机 4: 绑定邮箱 # 如果有新的继续后面加 # params[:type]为事件通知类型 1用户注册注册 2忘记密码 3: 绑定手机 4: 绑定邮箱 # 如果有新的继续后面加
# 发送验证码send_type 1注册手机验证码 2找回密码手机验证码 3找回密码邮箱验证码 4绑定手机 5绑定邮箱 # 发送验证码send_type 1注册手机验证码 2找回密码手机验证码 3找回密码邮箱验证码 4绑定手机 5绑定邮箱
# 6手机验证码登录 7邮箱验证码登录 8邮箱注册验证码 # 6手机验证码登录 7邮箱验证码登录 8邮箱注册验证码 9: 验收手机号有效
def get_verification_code def get_verification_code
code = %W(0 1 2 3 4 5 6 7 8 9) code = %W(0 1 2 3 4 5 6 7 8 9)
value = params[:login] value = params[:login]
@ -151,6 +151,8 @@ class AccountsController < ApplicationController
send_type = verify_type(login_type, type) send_type = verify_type(login_type, type)
verification_code = code.sample(6).join verification_code = code.sample(6).join
logger.info("########get_verification_code: login_type #{login_type} send_type#{send_type}, ")
# 记录验证码 # 记录验证码
check_verification_code(verification_code, send_type, value) check_verification_code(verification_code, send_type, value)
sucess_status sucess_status

@ -72,7 +72,7 @@ class ApplicationController < ActionController::Base
UserMailer.register_email(value, code).deliver_now UserMailer.register_email(value, code).deliver_now
# Mailer.run.email_register(code, value) # Mailer.run.email_register(code, value)
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) logger_error(e)
tip_exception("邮件发送失败,请稍后重试") tip_exception("邮件发送失败,请稍后重试")
end end
end end

@ -12,5 +12,8 @@ module ControllerRescueHandler
rescue_from ActiveModel::ValidationError do |ex| rescue_from ActiveModel::ValidationError do |ex|
render_error(ex.model.errors.full_messages.join(',')) render_error(ex.model.errors.full_messages.join(','))
end end
rescue_from ActiveRecord::RecordInvalid do |ex|
render_error(ex.record.errors.full_messages.join(','))
end
end end
end end

@ -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 :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, 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, :top_banner, :left_banner, :add_teacher_popup, :add_teacher,
:graduation_group_list, :create_graduation_group, :join_graduation_group, :graduation_group_list, :create_graduation_group, :join_graduation_group,
:course_group_list, :set_course_group, :change_course_admin, :change_course_teacher, :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, :transfer_to_course_group, :delete_from_course,
:search_users, :add_students_by_search, :get_historical_courses, :add_teacher_popup, :add_teacher] :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, 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, :set_course_group, :delete_course_teacher, :create_group_by_importing_file]
:create_group_by_importing_file]
before_action :teacher_or_admin_allowed, only: [:graduation_group_list, :create_graduation_group, :join_graduation_group, 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 :validate_course_name, only: [:create, :update]
before_action :find_board, only: :board_list before_action :find_board, only: :board_list
before_action :validate_page_size, only: :mine before_action :validate_page_size, only: :mine
@ -251,46 +251,53 @@ class CoursesController < ApplicationController
if @course.try(:id) != 1309 || current_user.admin? || current_user.try(:id) == 15582 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) @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 else
@teacher_list = @course.course_members.joins(:user).where("(course_members.role in (1, 3) or (course_members.user_id = #{current_user.id} @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)) and course_members.role = 2)) and LOWER(concat(users.lastname, users.firstname))
LIKE '%#{@search_str}%'") LIKE ?", "%#{@search_str}%")
end end
@teacher_list_size = @teacher_list.size @teacher_list_size = @teacher_list.size
@has_graduation_design = @course.course_modules.graduation_module_not_hidden.any? @has_graduation_design = @course.course_modules.graduation_module_not_hidden.any?
sort = params[:sort] || "desc"
@order = params[:order].to_i @order = params[:order].to_i
if @order.present? if @order.present?
case @order case @order
when 1 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 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 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 else
@teacher_list = @teacher_list.order("created_at") @teacher_list = @teacher_list.order("role #{sort}")
end end
else else
if @has_graduation_design @teacher_list = @teacher_list.order("role #{sort}")
@teacher_list = @teacher_list.includes(:course, :graduation_group).order("graduation_groups.name")
else
@teacher_list = @teacher_list.order("created_at")
end
end end
@is_admin = @user_course_identity < Course::PROFESSOR @is_admin = @user_course_identity < Course::PROFESSOR
@applications= CourseMessage.unhandled_join_course_requests_by_course(@course) @applications_size = CourseMessage.unhandled_join_course_requests_by_course(@course).size
page = params[:page] || 1 page = params[:page] || 1
limit = params[:limit] || 20 limit = params[:limit] || 20
@teacher_list = @teacher_list.page(page).per(limit) @teacher_list = @teacher_list.page(page).per(limit)
end end
def apply_teachers
search_str = params[:search].present? ? params[:search].strip : ""
@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
@is_admin = @user_course_identity < Course::PROFESSOR
end
# 打开添加教师或助教弹窗时访问的接口(需要返回该课堂所有答辩组和所有) # 打开添加教师或助教弹窗时访问的接口(需要返回该课堂所有答辩组和所有)
def add_teacher_popup def add_teacher_popup
@graduation_groups = @course.graduation_groups @graduation_groups = @course.graduation_groups
@ -548,6 +555,7 @@ class CoursesController < ApplicationController
course_teacher = CourseMember.find_by(user_id: current_user.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR], course_id: @course.id) course_teacher = CourseMember.find_by(user_id: current_user.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR], course_id: @course.id)
course_student.destroy! course_student.destroy!
course_teacher.update_attributes(is_active: 1) if course_teacher.present? && !course_teacher.is_active course_teacher.update_attributes(is_active: 1) if course_teacher.present? && !course_teacher.is_active
CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id])
normal_status(0, "退出成功") normal_status(0, "退出成功")
end end
@ -576,6 +584,18 @@ class CoursesController < ApplicationController
end end
new_teacher.save! 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 elsif approval == 2
course_message.reject! course_message.reject!
else else
@ -684,11 +704,16 @@ class CoursesController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
students = params[:students] students = params[:students]
student_ids = []
students.each do |student| students.each do |student|
course_member = CourseMember.find_by!(id: student[:course_member_id].to_i, course_id: @course.id) course_member = CourseMember.find_by(id: student[:course_member_id].to_i, course_id: @course.id)
course_member.destroy! if course_member.present?
student_ids << course_member.user_id
course_member.destroy!
end
end end
CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, student_ids) if student_ids.present?
normal_status(0, "操作成功") normal_status(0, "操作成功")
rescue => e rescue => e
uid_logger(e.message) uid_logger(e.message)
@ -711,7 +736,7 @@ class CoursesController < ApplicationController
student_ids = [] student_ids = []
user_ids.each do |user_id| user_ids.each do |user_id|
existing_course_member = CourseMember.find_by(user_id: user_id.to_i, course_id: @course.id) existing_course_member = @course.course_members.find_by(user_id: user_id.to_i)
new_student = CourseMember.new(user_id: user_id.to_i, course_id: @course.id, course_group_id: course_group_id, role: 4) new_student = CourseMember.new(user_id: user_id.to_i, course_id: @course.id, course_group_id: course_group_id, role: 4)
if existing_course_member.present? if existing_course_member.present?
@ -720,6 +745,7 @@ class CoursesController < ApplicationController
else else
new_student.is_active = 0 if existing_course_member.is_active new_student.is_active = 0 if existing_course_member.is_active
new_student.save! new_student.save!
student_ids << user_id
end end
else else
new_student.save! new_student.save!
@ -727,6 +753,7 @@ class CoursesController < ApplicationController
end end
end end
CourseAddStudentCreateWorksJob.perform_later(@course.id, student_ids) if student_ids.present?
TeacherInviteJoinCourseNotifyJob.perform_later(current_user.id, @course.id, 10, student_ids) if student_ids.present? TeacherInviteJoinCourseNotifyJob.perform_later(current_user.id, @course.id, 10, student_ids) if student_ids.present?
normal_status(0, "添加成功") normal_status(0, "添加成功")
rescue => e rescue => e
@ -868,6 +895,7 @@ class CoursesController < ApplicationController
new_student.course_group_id = course_group.id if course_group.present? new_student.course_group_id = course_group.id if course_group.present?
new_student.save! new_student.save!
CourseAddStudentCreateWorksJob.perform_later(course.id, [current_user.id])
StudentJoinCourseNotifyJob.perform_later(current_user.id, course.id) StudentJoinCourseNotifyJob.perform_later(current_user.id, course.id)
end end
end end
@ -984,8 +1012,8 @@ class CoursesController < ApplicationController
normal_status(-1,"课堂暂时没有学生") normal_status(-1,"课堂暂时没有学生")
else else
member_to_xlsx(@course, @all_members, @c_homeworks, @c_exercises, @c_tasks) member_to_xlsx(@course, @all_members, @c_homeworks, @c_exercises, @c_tasks)
filename = current_user.real_name + "_" + @course.name + "_全部成绩" + Time.now.strftime('%Y%m%d_%H%M%S') filename_ = "#{current_user.real_name}_#{@course.name}_全部成绩"
render xlsx: "#{format_sheet_name filename.strip.first(30)}",template: "courses/export_member_scores_excel.xlsx.axlsx", render xlsx: "#{format_sheet_name filename_.strip.first(30)}",template: "courses/export_member_scores_excel.xlsx.axlsx",
locals: {course_info:@course_info, activity_level:@user_activity_level, locals: {course_info:@course_info, activity_level:@user_activity_level,
course_scores:@course_user_scores,shixun_works:@shixun_work_arrays, course_scores:@course_user_scores,shixun_works:@shixun_work_arrays,
common_works:@common_work_arrays,group_works:@group_work_arrays,task_works:@task_work_arrays, common_works:@common_work_arrays,group_works:@group_work_arrays,task_works:@task_work_arrays,

@ -10,13 +10,13 @@ class DiscussesController < ApplicationController
if current_user.admin? if current_user.admin?
@disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count @disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count
@discusses = Discuss.limit(LIMIT).where(:dis_id => @container.id, :dis_type => @container.class.to_s, @discusses = Discuss.limit(LIMIT).where(:dis_id => @container.id, :dis_type => @container.class.to_s,
:root_id => nil).includes(:user, :praise_tread).offset(offset) :root_id => nil).includes(:user, :praise_treads).offset(offset)
else else
disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and
(hidden = :hidden or user_id = :user_id)", (hidden = :hidden or user_id = :user_id)",
{dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_user.id}) {dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_user.id})
@disscuss_count = disscusses.count @disscuss_count = disscusses.count
@discusses = disscusses.limit(LIMIT).includes(:user, :praise_tread).offset(offset) @discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset)
end end
@current_user = current_user @current_user = current_user

@ -1,14 +1,5 @@
class Ecs::BaseController < ApplicationController class Ecs::BaseController < ApplicationController
# model validation error
rescue_from ActiveRecord::RecordInvalid do |ex|
render_error(ex.record.errors.full_messages.join(','))
end
# form validation error
rescue_from ActiveModel::ValidationError do |ex|
render_error(ex.model.errors.full_messages.join(','))
end
before_action :require_login before_action :require_login
before_action :check_user_permission! before_action :check_user_permission!

@ -97,7 +97,7 @@ class ExerciseAnswersController < ApplicationController
@exercise = @exercise_question&.exercise @exercise = @exercise_question&.exercise
@course = @exercise&.course @course = @exercise&.course
@exercise_user = @exercise&.exercise_users.find_by(user_id: current_user.id) #当前用户 @exercise_user = @exercise&.exercise_users.find_by(user_id: current_user.id) #当前用户
@exercise_user_status = @exercise.get_exercise_status(current_user.id) @exercise_user_status = @exercise.get_exercise_status(current_user)
if @exercise_question.blank? if @exercise_question.blank?
normal_status(-1,"试卷问题不存在!") normal_status(-1,"试卷问题不存在!")

@ -23,7 +23,6 @@ class ExercisesController < ApplicationController
before_action :commit_shixun_present,only: [:commit_shixun] before_action :commit_shixun_present,only: [:commit_shixun]
include ExportHelper include ExportHelper
include ExercisesHelper include ExercisesHelper
# require 'pdfkit'
def index def index
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
@ -32,60 +31,49 @@ class ExercisesController < ApplicationController
@exercises_all = @course.exercises @exercises_all = @course.exercises
member_show_exercises = @exercises_all.is_exercise_published #已发布的或已截止的试卷 member_show_exercises = @exercises_all.is_exercise_published #已发布的或已截止的试卷
@current_user_ = current_user @current_user_ = current_user
@exercises_count = @exercises_all.size # 全部页面,需返回
@exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数
@exercises_published_counts = @exercises_all.exercise_by_status([2,3]).size # 已发布的试卷数,包含已截止的
@exercises_ended_counts = @exercises_all.exercise_by_status(3).size #已截止的试卷数
# 课堂的学生人数 # 课堂的学生人数
@course_all_members = @course.students #当前课堂的全部学生 @course_all_members = @course.students #当前课堂的全部学生
@course_all_members_count = @course_all_members.size #当前课堂的学生数
@current_student = @course_all_members.course_find_by_ids("user_id",current_user.id) #当前用户是否为课堂的学生 @current_student = @course_all_members.course_find_by_ids("user_id",current_user.id) #当前用户是否为课堂的学生
# exercises的不同用户群体的显示 # exercises的不同用户群体的显示
if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教 if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教
@is_teacher_or = 1 @is_teacher_or = 1
# @teacher_groups_ids = @course.teacher_course_groups.get_user_groups(current_user.id).pluck(:course_group_id).reject(&:blank?) @exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同)
@exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同)
elsif @user_course_identity == Course::STUDENT # 2为课堂成员能看到统一设置的和自己班级的 elsif @user_course_identity == Course::STUDENT # 2为课堂成员能看到统一设置的和自己班级的
@is_teacher_or = 2 @is_teacher_or = 2
# get_exercise_left_time(@exercise,current_user) @member_group_id = @current_student.first.try(:course_group_id).to_i # 成员的分班id默认为0
member_group_id = @current_student.first.try(:course_group_id).to_i # 成员的分班id默认为0 if @member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的)
if member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的) @exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting : []
@exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : []
else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷 else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷
# 已发布 当前用户班级分组的 试卷id # 已发布 当前用户班级分组的 试卷id
exercise_settings_ids = @course.exercise_group_settings.exercise_group_published not_exercise_ids = @course.exercise_group_settings.exercise_group_not_published.where("course_group_id = #{@member_group_id}").pluck(:exercise_id)
.where(course_group_id: member_group_id).pluck(:exercise_id).uniq @exercises = member_show_exercises.where.not(id: not_exercise_ids)
@exercises = member_show_exercises.present? ?
member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids))
: []
end end
else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁 else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁
@is_teacher_or = 0 @is_teacher_or = 0
@exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : [] @exercises = member_show_exercises.unified_setting
end end
if @exercises.size > 0 if @exercises.size > 0
if params[:type].present? if params[:type].present?
choose_type = params[:type].to_i choose_type = params[:type].to_i
member_group_id = @current_student.first.try(:course_group_id).to_i ex_setting_ids = []
if @is_teacher_or == 2 && member_group_id > 0 if @is_teacher_or != 2
exercise_groups_sets = @course.exercise_group_settings.where(course_group_id: member_group_id) @exercises = @exercises.where("exercise_status = #{choose_type}")
.exercise_group_published
exercise_settings_ids = exercise_groups_sets.pluck(:exercise_id)
exercise_ended_ids = exercise_groups_sets.exercise_group_ended.pluck(:exercise_id).uniq
if choose_type == 2
@exercises = @exercises_all.present? ?
@exercises_all.exercise_by_status(2).unified_setting
.or(@exercises_all.where(id: (exercise_settings_ids - exercise_ended_ids).uniq))
: []
elsif choose_type == 3
@exercises = @exercises_all.present? ?
@exercises_all.exercise_by_status(3).unified_setting
.or(@exercises_all.where(id: exercise_ended_ids))
: []
end
else else
@exercises = @exercises.exercise_by_status(choose_type) case choose_type
when 1
ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}").exercise_group_not_published.pluck(:exercise_id)
when 2
ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}")
.where("publish_time is not null and publish_time <= ? and end_time > ?",Time.now,Time.now).pluck(:exercise_id)
when 3
ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}").exercise_group_ended.pluck(:exercise_id)
end
unified_setting_ids = @exercises.unified_setting.where("exercise_status = #{choose_type}").pluck(:id)
ex_ids = (ex_setting_ids + unified_setting_ids).uniq
@exercises = @exercises.where(id: ex_ids)
end end
end end
@ -101,11 +89,16 @@ class ExercisesController < ApplicationController
@page = params[:page] || 1 @page = params[:page] || 1
@limit = params[:limit] || 15 @limit = params[:limit] || 15
@exercises = @exercises.page(@page).per(@limit) @exercises = @exercises.page(@page).per(@limit)
@exercises = @exercises&.includes(:exercise_users,:exercise_questions,:exercise_group_settings) @exercises = @exercises&.includes(:published_settings)
else else
@exercises = [] @exercises = []
end end
@course_all_members_count = @course_all_members.size #当前课堂的学生数
@exercises_count = @exercises_all.size # 全部页面,需返回
@exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数
@exercises_published_counts = @exercises_count - @exercises_unpublish_counts # 已发布的试卷数,包含已截止的
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception(e.message) tip_exception(e.message)
@ -212,7 +205,7 @@ class ExercisesController < ApplicationController
@user_exercise_answer = 3 #教师页面 @user_exercise_answer = 3 #教师页面
@user_commit_counts = @exercise.exercise_users.where(commit_status:1).count #已提交的用户数 @user_commit_counts = @exercise.exercise_users.where(commit_status:1).count #已提交的用户数
end end
@ex_status = @exercise.get_exercise_status(current_user.id) @ex_status = @exercise.get_exercise_status(current_user)
exercise_id_array = [@exercise.id] exercise_id_array = [@exercise.id]
@exercise_publish_count = get_user_permission_course(exercise_id_array,2).count #是否存在已发布的 @exercise_publish_count = get_user_permission_course(exercise_id_array,2).count #是否存在已发布的
@ -226,7 +219,6 @@ class ExercisesController < ApplicationController
end end
end end
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("没有权限") tip_exception("没有权限")
@ -450,7 +442,7 @@ class ExercisesController < ApplicationController
# course_group_ids = @course.teacher_course_group_ids(current_user.id) #当前老师的班级id数组 # course_group_ids = @course.teacher_course_group_ids(current_user.id) #当前老师的班级id数组
course_group_ids = @course.charge_group_ids(current_user) #当前老师的班级id数组 course_group_ids = @course.charge_group_ids(current_user) #当前老师的班级id数组
exercise_status = @exercise.get_exercise_status(current_user.id) exercise_status = @exercise.get_exercise_status(current_user)
if exercise_status == 1 && course_group_ids.size > 0 # 试卷未发布且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理 if exercise_status == 1 && course_group_ids.size > 0 # 试卷未发布且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理
unified_setting = params[:unified_setting] unified_setting = params[:unified_setting]
@ -477,10 +469,8 @@ class ExercisesController < ApplicationController
params_end_time = params[:end_time].to_time params_end_time = params[:end_time].to_time
end end
if exercise_status == 2 && @exercise.publish_time != params_publish_time if (exercise_status != 1) && (@exercise.publish_time != params_publish_time)
normal_status(-1,"已发布,不允许修改发布时间") normal_status(-1,"已发布/已截止,不允许修改发布时间")
elsif exercise_status == 3 && (@exercise.end_time != params_end_time || @exercise.publish_time != params_publish_time)
normal_status(-1,"已截止,不允许修改时间")
elsif params_publish_time.present? && params_end_time.present? && params_end_time < params_publish_time elsif params_publish_time.present? && params_end_time.present? && params_end_time < params_publish_time
normal_status(-1,"截止时间不能小于发布时间") normal_status(-1,"截止时间不能小于发布时间")
else else
@ -523,12 +513,7 @@ class ExercisesController < ApplicationController
end end
# exercise_end_time = t[:end_time].present? ? t[:end_time].to_time : nil # exercise_end_time = t[:end_time].present? ? t[:end_time].to_time : nil
exercise_group = exercise_groups.find_in_exercise_group("course_group_id",course_id) #判断该分班是否存在 exercise_group = exercise_groups.find_in_exercise_group("course_group_id",course_id) #判断该分班是否存在
if exercise_group.present? && exercise_group.first.end_time <= Time.now && if exercise_group.present? && (exercise_group.first.publish_time < Time.now) && (exercise_publish_time != exercise_group.first.publish_time)
(exercise_end_time != exercise_group.first.end_time || exercise_publish_time != exercise_group.first.publish_time) #已截止且时间改变的,则提示错误
error_count += 1
end
if exercise_group.present? && exercise_group.first.publish_time <
Time.now && exercise_publish_time != exercise_group.first.publish_time
error_count += 1 error_count += 1
end end
if error_count == 0 if error_count == 0
@ -811,7 +796,7 @@ class ExercisesController < ApplicationController
check_ids = Exercise.where(id:params[:check_ids]) check_ids = Exercise.where(id:params[:check_ids])
course_students = @course.students #课堂的全部学生数 course_students = @course.students #课堂的全部学生数
check_ids.each do |exercise| check_ids.each do |exercise|
exercise_status= exercise.get_exercise_status(current_user.id) exercise_status= exercise.get_exercise_status(current_user)
if exercise_status == 2 #跳过已截止的或未发布的 if exercise_status == 2 #跳过已截止的或未发布的
g_course = params[:group_ids] g_course = params[:group_ids]
if g_course.present? if g_course.present?
@ -906,7 +891,7 @@ class ExercisesController < ApplicationController
ex_question_ids = @exercise.exercise_questions.pluck(:id) ex_question_ids = @exercise.exercise_questions.pluck(:id)
exercise_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first exercise_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first
if exercise_user.present? if exercise_user.present?
if exercise_user.commit_status == 1 && @exercise.get_exercise_status(current_user.id) == 2 #用户已提交且试卷提交中 if exercise_user.commit_status == 1 && @exercise.get_exercise_status(current_user) == 2 #用户已提交且试卷提交中
if @exercise.time == -1 || ((Time.now.to_i - exercise_user.start_at.to_i) < @exercise.time.to_i * 60) if @exercise.time == -1 || ((Time.now.to_i - exercise_user.start_at.to_i) < @exercise.time.to_i * 60)
exercise_user.update_attributes(:score => nil, :end_at => nil, :status => nil, :commit_status => 0, exercise_user.update_attributes(:score => nil, :end_at => nil, :status => nil, :commit_status => 0,
:objective_score => 0.0, :subjective_score => -1.0) :objective_score => 0.0, :subjective_score => -1.0)
@ -1033,7 +1018,7 @@ class ExercisesController < ApplicationController
# @user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 # @user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间
# end # end
@t_user_exercise_status = @exercise.get_exercise_status(current_user.id) @t_user_exercise_status = @exercise.get_exercise_status(current_user)
@user_left_time = nil @user_left_time = nil
if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) || if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) ||
@ -1146,7 +1131,7 @@ class ExercisesController < ApplicationController
# @exercise_answerer = User.find_by(id:@exercise_current_user_id) #试卷回答者 # @exercise_answerer = User.find_by(id:@exercise_current_user_id) #试卷回答者
@exercise_questions = @exercise.exercise_questions.order("question_number ASC") @exercise_questions = @exercise.exercise_questions.order("question_number ASC")
@question_status = [] @question_status = []
get_exercise_status = @exercise.get_exercise_status(current_user.id) get_exercise_status = @exercise.get_exercise_status(current_user)
if @ex_user.present? && @is_teacher_or == 0 if @ex_user.present? && @is_teacher_or == 0
if get_exercise_status == 2 #当前用户已提交,且试卷未截止 if get_exercise_status == 2 #当前用户已提交,且试卷未截止
if @ex_user.commit_status == 0 #学生未提交,且当前为学生 if @ex_user.commit_status == 0 #学生未提交,且当前为学生
@ -1174,7 +1159,7 @@ class ExercisesController < ApplicationController
begin begin
@current_user_id = current_user.id @current_user_id = current_user.id
exercise_ids = [@exercise.id] exercise_ids = [@exercise.id]
@exercise_status = @exercise.get_exercise_status(current_user.id) @exercise_status = @exercise.get_exercise_status(current_user)
@course_all_members = @course.students @course_all_members = @course.students
@c_group_counts = @course.course_groups_count @c_group_counts = @course.course_groups_count
question_types = @exercise.exercise_questions.pluck(:question_type).uniq question_types = @exercise.exercise_questions.pluck(:question_type).uniq
@ -1198,12 +1183,12 @@ class ExercisesController < ApplicationController
ex_common_ids = @exercise.common_published_ids(current_user.id) ex_common_ids = @exercise.common_published_ids(current_user.id)
@exercise_course_groups = @course.get_ex_published_course(ex_common_ids) @exercise_course_groups = @course.get_ex_published_course(ex_common_ids)
@exercise_users_list = @exercise.all_exercise_users(current_user.id) #当前老师所在班级的全部学生 @exercise_users_list = @exercise.all_exercise_users(current_user.id) #当前老师所在班级的全部学生
get_exercise_answers(@exercise_users_list) get_exercise_answers(@exercise_users_list, @exercise_status)
end end
elsif @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生或者有过答题的(提交/未提交) elsif @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生或者有过答题的(提交/未提交)
@ex_user_end_time = @exercise.get_exercise_end_time(current_user.id) #当前用户所看到的剩余时间 @ex_user_end_time = @exercise.get_exercise_end_time(current_user.id) #当前用户所看到的剩余时间
@exercise_all_users = @exercise.get_stu_exercise_users @exercise_all_users = @exercise.get_stu_exercise_users
get_exercise_answers(@exercise_all_users) # 未答和已答的 get_exercise_answers(@exercise_users_list, @exercise_status) # 未答和已答的
exercise_current_user = @exercise_all_users.exercise_commit_users(current_user.id) #当前用户是否开始做试卷(提交/未提交/没做) exercise_current_user = @exercise_all_users.exercise_commit_users(current_user.id) #当前用户是否开始做试卷(提交/未提交/没做)
if exercise_current_user.present? if exercise_current_user.present?
@exercise_current_user_status = 1 #当前用户的状态,为学生 @exercise_current_user_status = 1 #当前用户的状态,为学生
@ -1217,11 +1202,9 @@ class ExercisesController < ApplicationController
end end
else else
@exercise_all_users = @exercise.get_stu_exercise_users @exercise_all_users = @exercise.get_stu_exercise_users
get_exercise_answers(@exercise_all_users) # 未答和已答的 get_exercise_answers(@exercise_users_list, @exercise_status) # 未答和已答的
@exercise_current_user_status = 2 #当前用户非课堂成员 @exercise_current_user_status = 2 #当前用户非课堂成员
@exercise_users_list = [] @exercise_users_list = []
# @exercise_unanswers = 0
# @exercise_answers = 0
end end
end end
@ -1300,15 +1283,17 @@ class ExercisesController < ApplicationController
if params[:format] == "xlsx" if params[:format] == "xlsx"
if @user_course_identity > Course::ASSISTANT_PROFESSOR if @user_course_identity > Course::ASSISTANT_PROFESSOR
tip_exception(403,"无权限操作") tip_exception(403,"无权限操作")
elsif (@exercise_status == 1) || (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) elsif @exercise_status == 1
normal_status(-1,"试卷未发布")
elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0)
normal_status(-1,"暂无用户提交") normal_status(-1,"暂无用户提交")
else else
respond_to do |format| respond_to do |format|
format.xlsx{ format.xlsx{
get_export_users(@exercise,@course,@export_ex_users) get_export_users(@exercise,@course,@export_ex_users)
exercise_export_name = exercise_export_name_ =
"#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} render xlsx: "#{exercise_export_name_.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns}
} }
end end
end end
@ -1325,9 +1310,9 @@ class ExercisesController < ApplicationController
def export_exercise def export_exercise
@request_url = request.base_url @request_url = request.base_url
@exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC")
filename = "#{@exercise.user.real_name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d_%H%M')}.pdf" filename_ = "#{@exercise.user.real_name}_#{@course.name}__#{Time.now.strftime('%Y%m%d_%H%M%S')}"
stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css"
render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets render pdf: 'exercise_export/blank_exercise', filename: filename_, stylesheets: stylesheets
end end
#空白试卷预览页面,仅供测试使用,无其他任何用途 #空白试卷预览页面,仅供测试使用,无其他任何用途
@ -1374,7 +1359,7 @@ class ExercisesController < ApplicationController
@exercise_commit_users = @exercise_all_users.commit_exercise_by_status(1) #试卷的已提交用户 @exercise_commit_users = @exercise_all_users.commit_exercise_by_status(1) #试卷的已提交用户
@exercise_commit_user_ids = @exercise_commit_users.pluck(:user_id).uniq #已提交试卷的全部用户id @exercise_commit_user_ids = @exercise_commit_users.pluck(:user_id).uniq #已提交试卷的全部用户id
@exercise_commit_user_counts = @exercise_commit_users.count #试卷的已提交用户人数 @exercise_commit_user_counts = @exercise_commit_users.count #试卷的已提交用户人数
@exercise_status = @exercise.get_exercise_status(current_user.id) @exercise_status = @exercise.get_exercise_status(current_user)
#提交率 #提交率
if @course_all_members_count == 0 if @course_all_members_count == 0
@ -1556,13 +1541,12 @@ class ExercisesController < ApplicationController
exercises_all.each do |exercise| exercises_all.each do |exercise|
if exercise.present? if exercise.present?
if exercise.unified_setting #统一设置只有两种情况,全部发布,全部截止 if exercise.unified_setting #统一设置只有两种情况,全部发布,全部截止
exercise_user_status = exercise.get_exercise_status(current_user.id) #当前用户的能看到的试卷 exercise_user_status = exercise.get_exercise_status(current_user) #当前用户的能看到的试卷
if exercise_user_status == exercise_status || exercise_status == 3 #未发布的情况 if (exercise_user_status == exercise_status) || exercise_status == 3 #未发布的情况
unpublish_group = unpublish_group + user_groups_id unpublish_group = unpublish_group + user_groups_id
else else
unpublish_group = [] unpublish_group = []
end end
# unpublish_group = unpublish_group + user_groups_id
else else
ex_all_group_settings = exercise.exercise_group_settings ex_all_group_settings = exercise.exercise_group_settings
ex_group_settings = ex_all_group_settings.exercise_group_published.pluck(:course_group_id).uniq #问卷设置的班级 ex_group_settings = ex_all_group_settings.exercise_group_published.pluck(:course_group_id).uniq #问卷设置的班级
@ -1590,13 +1574,13 @@ class ExercisesController < ApplicationController
def set_exercise_status(publish_time,end_time) def set_exercise_status(publish_time,end_time)
time_now_i = Time.now time_now_i = Time.now
if publish_time.present? && publish_time <= time_now_i && end_time > time_now_i if publish_time.present? && (publish_time <= time_now_i) && (end_time > time_now_i)
2 2
elsif publish_time.nil? || (publish_time.present? && publish_time > time_now_i) elsif publish_time.nil? || (publish_time.present? && publish_time > time_now_i)
1 1
elsif end_time.present? && end_time <= time_now_i elsif end_time.present? && (end_time <= time_now_i)
3 3
elsif end_time.present? && publish_time.present? && end_time < publish_time elsif end_time.present? && publish_time.present? && (end_time < publish_time)
normal_status(-1,"时间设置错误!") normal_status(-1,"时间设置错误!")
else else
1 1
@ -1626,7 +1610,7 @@ class ExercisesController < ApplicationController
## 判断开始答题页面的用户权限 ## 判断开始答题页面的用户权限
def check_user_on_answer def check_user_on_answer
if @user_course_identity == Course::STUDENT && @exercise.get_exercise_status(current_user.id) == 1 #试卷未发布,且当前用户不为老师/管理员 if @user_course_identity == Course::STUDENT && @exercise.get_exercise_status(current_user) == 1 #试卷未发布,且当前用户不为老师/管理员
normal_status(-1, "未发布试卷!") normal_status(-1, "未发布试卷!")
elsif @user_course_identity > Course::STUDENT && (!@exercise.is_public || (@exercise.is_public && !@exercise.unified_setting)) ##不为课堂成员,且试卷不为公开的,或试卷公开,但不是统一设置的 elsif @user_course_identity > Course::STUDENT && (!@exercise.is_public || (@exercise.is_public && !@exercise.unified_setting)) ##不为课堂成员,且试卷不为公开的,或试卷公开,但不是统一设置的
normal_status(-1, "试卷暂未公开!") normal_status(-1, "试卷暂未公开!")
@ -1637,40 +1621,13 @@ class ExercisesController < ApplicationController
@answer_committed_user = @exercise.exercise_users.exercise_commit_users(current_user.id)&.first @answer_committed_user = @exercise.exercise_users.exercise_commit_users(current_user.id)&.first
if @answer_committed_user.blank? if @answer_committed_user.blank?
normal_status(404,"答题用户不存在") normal_status(404,"答题用户不存在")
# elsif @exercise.get_exercise_status(current_user.id) == 2 && @answer_committed_user.commit_status == 1 #当试卷截止时,会自动提交
# normal_status(-1,"提交错误,试卷用户已提交!")
end end
end end
# def commit_user_exercise
# @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first #查找当前用户是否有过答题
# if @user_course_identity == Course::STUDENT
# if @exercise_user_current.present?
# if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) &&
# ((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now)
# #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制
# objective_score = calculate_student_score(@exercise,current_user)[:total_score]
# subjective_score = @exercise_user_current.subjective_score < 0.0 ? 0.0 : @exercise_user_current.subjective_score
# total_score = objective_score + subjective_score
# commit_option = {
# :status => 1,
# :commit_status => 1,
# :end_at => Time.now,
# :objective_score => objective_score,
# :score => total_score,
# :subjective_score => subjective_score
# }
# @exercise_user_current.update_attributes(commit_option)
# normal_status(0,"已交卷成功!")
# end
# end
# end
# end
#打回重做时的初步判断 #打回重做时的初步判断
def check_exercise_status def check_exercise_status
@exercise_users = @exercise.all_exercise_users(current_user.id).commit_exercise_by_status(1) #当前教师所在分班的全部已提交的学生数 @exercise_users = @exercise.all_exercise_users(current_user.id).commit_exercise_by_status(1) #当前教师所在分班的全部已提交的学生数
if @exercise.get_exercise_status(current_user.id) != 2 if @exercise.get_exercise_status(current_user) != 2
normal_status(-1,"非提交中的试卷不允许打回重做!") normal_status(-1,"非提交中的试卷不允许打回重做!")
elsif @exercise_users.count < 1 elsif @exercise_users.count < 1
normal_status(-1,"暂无人提交试卷!") normal_status(-1,"暂无人提交试卷!")
@ -1680,7 +1637,7 @@ class ExercisesController < ApplicationController
#查看试题页面,当为学生时,除非试卷已截止,或已提交才可以查看 #查看试题页面,当为学生时,除非试卷已截止,或已提交才可以查看
def check_exercise_is_end def check_exercise_is_end
ex_status = @exercise.get_exercise_status(current_user.id) ex_status = @exercise.get_exercise_status(current_user)
@ex_user = @exercise.exercise_users.find_by(user_id:@exercise_current_user_id) #该试卷的回答者 @ex_user = @exercise.exercise_users.find_by(user_id:@exercise_current_user_id) #该试卷的回答者
if @user_course_identity > Course::ASSISTANT_PROFESSOR if @user_course_identity > Course::ASSISTANT_PROFESSOR
if ex_status == 1 if ex_status == 1
@ -1697,7 +1654,7 @@ class ExercisesController < ApplicationController
def check_exercise_public def check_exercise_public
if @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生,试卷公开统计,且已截止,且已提交 if @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生,试卷公开统计,且已截止,且已提交
ex_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first ex_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first
unless @exercise.get_exercise_status(current_user.id) == 3 && ex_user.present? && ex_user.commit_status == 1 && unless @exercise.get_exercise_status(current_user) == 3 && ex_user.present? && ex_user.commit_status == 1 &&
@exercise.show_statistic @exercise.show_statistic
normal_status(-1,"学生暂不能查看") normal_status(-1,"学生暂不能查看")
end end
@ -1790,6 +1747,4 @@ class ExercisesController < ApplicationController
end end
end end
end end

@ -40,10 +40,8 @@ class GamesController < ApplicationController
next_game = @game.next_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position) next_game = @game.next_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position)
# 关卡点赞数, praise_or_tread = 1则表示赞过 # 关卡点赞数, praise_or_tread = 1则表示赞过
praise_count = PraiseTread.where(praise_tread_object_id: game_challenge.id, praise_tread_object_type: "Challenge", praise_count = game_challenge.praises_count
praise_or_tread: 1).count user_praise = game_challenge.praise_treads.exists?(user_id:current_user.id, praise_or_tread: 1)
user_praise = PraiseTread.where(praise_tread_object_id: game_challenge.id, praise_tread_object_type: "Challenge",
user_id: current_user.id, praise_or_tread: 1).present? ? true : false
# 实训的最大评测次数,这个值是为了优化查询,每次只取最新的最新一次评测的结果集 # 实训的最大评测次数,这个值是为了优化查询,每次只取最新的最新一次评测的结果集
max_query_index = @game.query_index.to_i max_query_index = @game.query_index.to_i
@ -79,7 +77,7 @@ class GamesController < ApplicationController
# 区分选择题和编程题st0编程题 # 区分选择题和编程题st0编程题
if @st == 0 if @st == 0
has_answer = game_challenge.challenge_answers.size == 0 ? false : true has_answer = game_challenge.challenge_answers.size != 0
game_challenge.answer = nil game_challenge.answer = nil
mirror_name = @shixun.mirror_name mirror_name = @shixun.mirror_name
@ -89,7 +87,7 @@ class GamesController < ApplicationController
rescue rescue
uid_logger("实训平台繁忙繁忙等级81") uid_logger("实训平台繁忙繁忙等级81")
end end
tpm_cases_modified = (game_challenge.modify_time != @game.modify_time ? true : false) # modify_time 决定TPM测试集是否有更新 tpm_cases_modified = (game_challenge.modify_time != @game.modify_time) # modify_time 决定TPM测试集是否有更新
@task_result = {tpm_modified: tpm_modified, tpm_cases_modified: tpm_cases_modified, mirror_name: mirror_name, has_answer: has_answer} @task_result = {tpm_modified: tpm_modified, tpm_cases_modified: tpm_cases_modified, mirror_name: mirror_name, has_answer: has_answer}
@ -221,12 +219,12 @@ class GamesController < ApplicationController
@result = challenge.st == 0 ? challenge.try(:answer) : challenge.choose_answer @result = challenge.st == 0 ? challenge.try(:answer) : challenge.choose_answer
end end
# 获取答案 # 获取实践题答案
# GET: /tasks/:identifier/get_answer_info # GET: /tasks/:identifier/get_answer_info
# 0 直接查看答案, 1 查看答案弹框, 2 答案详情弹框 # 0 直接查看答案, 1 查看答案弹框, 2 答案详情弹框
def get_answer_info def get_answer_info
challenge = @game.challenge @challenge = @game.challenge
@challenge_answers = challenge.challenge_answers @challenge_answers = @challenge.challenge_answers
# 平台已认证的老师需要控制 # 平台已认证的老师需要控制
@power = (@identity < User::EDU_GAME_MANAGER) @power = (@identity < User::EDU_GAME_MANAGER)
if !@power if !@power
@ -243,16 +241,29 @@ class GamesController < ApplicationController
end end
end end
end end
end
# 获取选择题答案
def get_choose_answer
@challenge = @game.challenge
tip_exception("本接口只能获取选择题答案") if @challenge.st != 1
@power = (@identity < User::EDU_GAME_MANAGER)
# 如果没权限,也没看过答案,则需要解锁
if @game.answer_open == 0 && !@power
tip_exception(1, @challenge.choose_score)
else
@challenge_chooses = @challenge.challenge_chooses
end
end end
# 解锁答案 # 解锁实践题答案
# GET: /tasks/:identifier/get_answer_info?answer_id=? # GET: /tasks/:identifier/get_answer_info?answer_id=?
def unlock_answer def unlock_answer
@challenge = @game.challenge
@answer = ChallengeAnswer.find(params[:answer_id]) @answer = ChallengeAnswer.find(params[:answer_id])
challenge = @answer.challenge challenge = @answer.challenge
# 解锁需要本层级的答案是否需要扣分 # 解锁需要本层级的答案是否需要扣分
points = challenge.challenge_answers.where(level: @game.answer_open+1..@answer.level).sum(:score) points = challenge.challenge_answers.where(level: @game.answer_open + 1..@answer.level).sum(:score)
deduct_score = ((points / 100.0) * challenge.score).to_i deduct_score = ((points / 100.0) * challenge.score).to_i
uid_logger("############金币数目: #{current_user.grade}") uid_logger("############金币数目: #{current_user.grade}")
unless current_user.grade.to_i - deduct_score > 0 unless current_user.grade.to_i - deduct_score > 0
@ -263,15 +274,16 @@ class GamesController < ApplicationController
begin begin
# 积分消耗情况记录 # 积分消耗情况记录
score = challenge.st.zero? ? -deduct_score : -challenge.choose_score.to_i score = challenge.st.zero? ? -deduct_score : -challenge.choose_score.to_i
RewardGradeService.call(current_user, container_id: @answer.id, container_type: 'Answer', score: score) RewardGradeService.call(current_user, container_id: @game.id, container_type: 'Answer', score: score)
# 通关查看答案 不扣 得分 # 通关查看答案 不扣 得分
answer_open = @challenge.st == 1 ? 1 : @answer.level
if @game.status == 2 if @game.status == 2
@game.update_attributes!(:answer_open => @answer.level) @game.update_attributes!(:answer_open =>answer_open)
else else
# 扣除总分计算 # 扣除总分计算
answer_deduction = challenge.challenge_answers.where("level <= #{@answer.level}").sum(:score) answer_deduction = challenge.challenge_answers.where("level <= #{@answer.level}").sum(:score)
@game.update_attributes!(:answer_open => @answer.level, :answer_deduction => answer_deduction) @game.update_attributes!(:answer_open => answer_open, :answer_deduction => answer_deduction)
end end
rescue Exception => e rescue Exception => e
@ -279,7 +291,32 @@ class GamesController < ApplicationController
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
end end
end end
end
# 解锁选择题答案
def unlock_choose_answer
@challenge = @game.challenge
score = @challenge.choose_score
unless current_user.grade.to_i - score > 0
tip_exception("您没有足够的金币")
end
ActiveRecord::Base.transaction do
begin
# 积分消耗情况记录
RewardGradeService.call(current_user, container_id: @game.id, container_type: 'Answer', score: -score)
# 通关查看答案 不扣 得分
if @game.status == 2
@game.update_attributes!(:answer_open => 1)
else
# 扣除总分计算
@game.update_attributes!(:answer_open => 1, :answer_deduction => 100)
end
@challenge_chooses = @challenge.challenge_chooses
rescue Exception => e
uid_logger_error("#######金币扣除异常: #{e.message}")
raise ActiveRecord::Rollback
end
end
end end
# 查看答案需要扣取金币 # 查看答案需要扣取金币
@ -454,7 +491,7 @@ class GamesController < ApplicationController
begin begin
@content = git_fle_content(@myshixun.repo_path, path) || "" @content = git_fle_content(@myshixun.repo_path, path) || ""
rescue rescue
if params[:retry].present? if params[:retry].to_i == 1
begin begin
begin begin
# 检测TPM对应的路径代码是否正常 # 检测TPM对应的路径代码是否正常
@ -501,7 +538,8 @@ class GamesController < ApplicationController
# 编程题评测 # 编程题评测
def game_build def game_build
game_challenge = Challenge.select([:id, :position, :picture_path]).find(@game.challenge_id) sec_key = params[:sec_key]
game_challenge = Challenge.select([:id, :position, :picture_path, :exec_time]).find(@game.challenge_id)
# 更新评测次数 # 更新评测次数
@game.update_column(:evaluate_count, (@game.evaluate_count.to_i + 1)) @game.update_column(:evaluate_count, (@game.evaluate_count.to_i + 1))
@ -548,8 +586,8 @@ class GamesController < ApplicationController
:instanceChallenge => "#{step}", :testCases => "#{testCases}", :resubmit => "#{resubmit}", :instanceChallenge => "#{step}", :testCases => "#{testCases}", :resubmit => "#{resubmit}",
:times => params[:first].to_i, :podType => @shixun.webssh, :content_modified => content_modified, :times => params[:first].to_i, :podType => @shixun.webssh, :content_modified => content_modified,
:containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}", :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}",
:persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}", :persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}", :sec_key => sec_key,
:timeLimit => "#{@shixun.exec_time}", :isPublished => (@shixun.status < 2 ? 0 : 1) } :timeLimit => "#{game_challenge.exec_time}", :isPublished => (@shixun.status < 2 ? 0 : 1) }
# 评测有文件输出的需要特殊传字段 path表示文件存储的位置 # 评测有文件输出的需要特殊传字段 path表示文件存储的位置
br_params['file'] = Base64.urlsafe_encode64({path: "#{game_challenge.picture_path}"}.to_json) if game_challenge.picture_path.present? br_params['file'] = Base64.urlsafe_encode64({path: "#{game_challenge.picture_path}"}.to_json) if game_challenge.picture_path.present?
@ -591,7 +629,7 @@ class GamesController < ApplicationController
# user_answer虽然是传的数组,但是可能存在多选择提的情况. # user_answer虽然是传的数组,但是可能存在多选择提的情况.
user_answer_tran = user_answer[index].size > 1 ? user_answer[index].split("").sort.join("") : user_answer[index] user_answer_tran = user_answer[index].size > 1 ? user_answer[index].split("").sort.join("") : user_answer[index]
standard_answer_tran = choose.standard_answer.size > 1 ? choose.standard_answer.split("").sort.join("") : choose.standard_answer standard_answer_tran = choose.standard_answer.size > 1 ? choose.standard_answer.split("").sort.join("") : choose.standard_answer
correct = (user_answer_tran == standard_answer_tran) ? true : false correct = (user_answer_tran == standard_answer_tran)
if str.present? if str.present?
str += "," str += ","
end end
@ -865,7 +903,7 @@ class GamesController < ApplicationController
end end
# actual_output为空表示暂时没有评测答题不允许查看 # actual_output为空表示暂时没有评测答题不允许查看
actual_output = output.try(:actual_output).try(:strip) actual_output = output.try(:actual_output).try(:strip)
has_answer << choose.answer if choose.answer.present? #has_answer << choose.answer if choose.answer.present?
# 标准答案处理,错误的不让用户查看,用-1替代 # 标准答案处理,错误的不让用户查看,用-1替代
standard_answer = (actual_output.blank? || !output.try(:result)) ? -1 : choose.standard_answer standard_answer = (actual_output.blank? || !output.try(:result)) ? -1 : choose.standard_answer
result = output.try(:result) result = output.try(:result)
@ -876,7 +914,7 @@ class GamesController < ApplicationController
@chooses << sin_choose @chooses << sin_choose
test_sets << sin_test_set test_sets << sin_test_set
end end
@has_answer = has_answer.present? @has_answer = true # 选择题永远都有答案
@choose_test_cases = {:had_submmit => had_submmit, :challenge_chooses_count => challenge_chooses_count, @choose_test_cases = {:had_submmit => had_submmit, :challenge_chooses_count => challenge_chooses_count,
:choose_correct_num => choose_correct_num, :test_sets => test_sets} :choose_correct_num => choose_correct_num, :test_sets => test_sets}
end end

@ -1,10 +1,15 @@
class GitsController < ApplicationController class GitsController < ApplicationController
#供git-workhorse反向调用认证 # 说明:
# 以下Git认证只针对新版gitGitlab的Git认证不走该控制器
# 思路:
# 1、用户通过Git客户端推送代码的时候这个时候Git客户端肯定会强制用户输入邮箱的
# 2、通过web端版本库界面更新代码如果用户邮箱不存在则用系统备用邮箱
# 供 git-workhorse反向调用认证
def auth def auth
# HTTP_AUTHORIZATION: "Basic 这里base64编码的的密码(user:passwd)" # HTTP_AUTHORIZATION: "Basic 这里base64编码的的密码(user:passwd)"
logger.info("11111112222223333 HTTP_AUTHORIZATION: #{request.env["HTTP_AUTHORIZATION"]}") logger.info("11111112222223333 HTTP_AUTHORIZATION: #{request.env["HTTP_AUTHORIZATION"]}")
#logger.info("#########-----request_env: #{request.env}") # logger.info("#########-----request_env: #{request.env}")
# {"service"=>"git-receive-pack", "controller"=>"gits", "action"=>"auth", # {"service"=>"git-receive-pack", "controller"=>"gits", "action"=>"auth",
# "url"=>"forge01/cermyt39.git/info/refs"} # "url"=>"forge01/cermyt39.git/info/refs"}
# #

@ -134,8 +134,8 @@ class GraduationTasksController < ApplicationController
respond_to do |format| respond_to do |format|
format.xlsx{ format.xlsx{
graduation_work_to_xlsx(@work_excel,@task,current_user) graduation_work_to_xlsx(@work_excel,@task,current_user)
exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@task.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" task_export_name_ = "#{current_user.real_name}_#{@course.name}_#{@task.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column} render xlsx: "#{task_export_name_.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column}
} }
end end
end end

@ -270,8 +270,8 @@ class GraduationTopicsController < ApplicationController
course = @course course = @course
students = course.students.joins(user: :user_extension).order("user_extensions.student_id") students = course.students.joins(user: :user_extension).order("user_extensions.student_id")
graduation_topic_to_xlsx(students,course) graduation_topic_to_xlsx(students,course)
exercise_export_name = "#{current_user.real_name}_#{course.name}_毕设选题_#{Time.now.strftime('%Y%m%d_%H%M%S')}" topic_export_name_ = "#{current_user.real_name}_#{course.name}_毕设选题_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_topics/export.xlsx.axlsx",locals: {table_columns:@topic_head_cells,topic_users:@topic_body_cells} render xlsx: "#{topic_export_name_.strip.first(30)}",template: "graduation_topics/export.xlsx.axlsx",locals: {table_columns:@topic_head_cells,topic_users:@topic_body_cells}
rescue Exception => e rescue Exception => e
uid_logger(e.message) uid_logger(e.message)
missing_template missing_template

@ -206,8 +206,7 @@ class HomeworkCommonsController < ApplicationController
respond_to do |format| respond_to do |format|
format.xlsx{ format.xlsx{
student_work_to_xlsx(@work_excel,@homework) student_work_to_xlsx(@work_excel,@homework)
exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@homework.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals:
{table_columns: @work_head_cells,task_users: @work_cells_column} {table_columns: @work_head_cells,task_users: @work_cells_column}
} }
@ -251,12 +250,12 @@ class HomeworkCommonsController < ApplicationController
student_works = @homework.student_works.where(user_id: user_ids) student_works = @homework.student_works.where(user_id: user_ids)
end end
myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids). myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id, user_id: user_ids).
includes(:games).where(games: {challenge_id: @homework.homework_challenge_settings.pluck(:challenge_id)}) includes(:games).where(games: {challenge_id: @homework.homework_challenge_settings.pluck(:challenge_id)})
challenge_settings = @homework.homework_challenge_settings challenge_settings = @homework.homework_challenge_settings
myshixuns.find_each(batch_size: 100) do |myshixun| myshixuns.find_each(batch_size: 100) do |myshixun|
work = student_works.select{|work| work.user_id == myshixun.user_id}.first work = student_works.select{|work| work.user_id == myshixun.user_id}.first
if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.games.pluck(:updated_at).max) if work && myshixun
games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
end end
@ -277,13 +276,13 @@ class HomeworkCommonsController < ApplicationController
myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id) myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id)
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.games.pluck(:updated_at).max) if work && myshixun
challenge_settings = @homework.homework_challenge_settings challenge_settings = @homework.homework_challenge_settings
games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
normal_status("更新成功") normal_status("更新成功")
else else
normal_status("已是最新成绩") normal_status("还开启挑战,暂不能更新成绩")
end end
rescue Exception => e rescue Exception => e
uid_logger(e.message) uid_logger(e.message)
@ -1322,7 +1321,7 @@ class HomeworkCommonsController < ApplicationController
.where(:user_id => user_ids).joins(user: :user_extension) .where(:user_id => user_ids).joins(user: :user_extension)
# 按学号和姓名搜索 # 按学号和姓名搜索
if params[:search] 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 end
# 抄袭作品数 # 抄袭作品数
@copy_reviews_count = @users_reviews.count @copy_reviews_count = @users_reviews.count
@ -1342,7 +1341,7 @@ class HomeworkCommonsController < ApplicationController
end end
# 代码查重详情 # 代码查重代码的详情
def code_review_detail def code_review_detail
@student_work = @homework.student_works.find_by(user_id: params[:user_id]) @student_work = @homework.student_works.find_by(user_id: params[:user_id])
@user = @student_work.user @user = @student_work.user

@ -17,7 +17,7 @@ class MyshixunsController < ApplicationController
# 强制重置实训 # 强制重置实训
# 前段需要按照操作过程提示 # 前段需要按照操作过程提示
def reset_my_game def reset_my_game
unless current_user.admin? unless (current_user.admin? || current_user.id == @myshixun.user_id)
tip_exception("403", "") tip_exception("403", "")
end end
@ -33,7 +33,7 @@ class MyshixunsController < ApplicationController
uid_logger_error("版本库删除异常,详情:#{e.message}") uid_logger_error("版本库删除异常,详情:#{e.message}")
end end
StudentWork.where(:myshixun_id => @myshixun.id).update_all(:myshixun_id => nil, :work_status => 0) StudentWork.where(:myshixun_id => @myshixun.id).update_all(:myshixun_id => 0, :work_status => 0)
rescue Exception => e rescue Exception => e
uid_logger_error("myshixun reset failed #{e}") uid_logger_error("myshixun reset failed #{e}")
@ -85,9 +85,6 @@ class MyshixunsController < ApplicationController
# "createPod":"1.610","evaluateAllTime":2820,"evaluateStart":"2017-11-24 11:04:35","execute":"0.294"}' # "createPod":"1.610","evaluateAllTime":2820,"evaluateStart":"2017-11-24 11:04:35","execute":"0.294"}'
# params[:pics] = "a.png,b.png,c.png" # params[:pics] = "a.png,b.png,c.png"
def training_task_status def training_task_status
logger.info("123################{params[:jsonTestDetails]}")
logger.info("456################{params[:timeCost]}")
logger.info("666###############{params}")
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
@ -98,13 +95,14 @@ class MyshixunsController < ApplicationController
return_back_time = format("%.3f", ( t1.to_f - brige_end_time.to_f)).to_f return_back_time = format("%.3f", ( t1.to_f - brige_end_time.to_f)).to_f
status = jsonTestDetails['status'] status = jsonTestDetails['status']
game_id = jsonTestDetails['buildID'] game_id = jsonTestDetails['buildID']
sec_key = jsonTestDetails['sec_key']
logger.info("training_task_status start#1**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") logger.info("training_task_status start#1**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
resubmit = jsonTestDetails['resubmit'] resubmit = jsonTestDetails['resubmit']
outPut = tran_base64_decode64(jsonTestDetails['outPut']) outPut = tran_base64_decode64(jsonTestDetails['outPut'])
jenkins_testsets = jsonTestDetails['msg'] jenkins_testsets = jsonTestDetails['msg']
compile_success = jsonTestDetails['compileSuccess'] compile_success = jsonTestDetails['compileSuccess']
# message = Base64.decode64(params[:msg]) unless params[:msg].blank? # message = Base64.decode64(params[:msg]) unless params[:msg].blank?
logger.info(outPut)
game = Game.find(game_id) game = Game.find(game_id)
myshixun = game.myshixun myshixun = game.myshixun
challenge = game.challenge challenge = game.challenge
@ -125,7 +123,7 @@ class MyshixunsController < ApplicationController
logger.info "actual_output:################################################# #{actual_output}" logger.info "actual_output:################################################# #{actual_output}"
Output.create!(:code => status, :game_id => game_id, :out_put => outPut, :test_set_position => j_test_set['caseId'], Output.create!(:code => status, :game_id => game_id, :out_put => outPut, :test_set_position => j_test_set['caseId'],
:actual_output => actual_output, :result => j_test_set['passed'].to_i, :query_index => max_query_index, :actual_output => actual_output, :result => j_test_set['passed'].to_i, :query_index => max_query_index,
:compile_success => compile_success.to_i) :compile_success => compile_success.to_i, :sec_key => sec_key)
# 如果设置了按测试集给分,则需要统计测试集的分值 # 如果设置了按测试集给分,则需要统计测试集的分值
if challenge.test_set_score && j_test_set['passed'].to_i == 1 if challenge.test_set_score && j_test_set['passed'].to_i == 1
test_set_score += challenge.test_sets.where(:position => j_test_set['caseId']).pluck(:score).first test_set_score += challenge.test_sets.where(:position => j_test_set['caseId']).pluck(:score).first
@ -280,7 +278,6 @@ class MyshixunsController < ApplicationController
end end
end end
if game.status == 2 if game.status == 2
@resubmit = Time.now.to_i @resubmit = Time.now.to_i
end end

@ -134,7 +134,7 @@ class PollVotesController < ApplicationController
end end
def check_answer_in_question def check_answer_in_question
poll_user_status = @poll.get_poll_status(current_user.id) poll_user_status = @poll.get_poll_status(current_user)
poll_user = @poll.poll_users.find_by(user_id: current_user.id) #当前用户 poll_user = @poll.poll_users.find_by(user_id: current_user.id) #当前用户
question_type = @poll_question&.question_type question_type = @poll_question&.question_type

@ -31,50 +31,48 @@ class PollsController < ApplicationController
@current_user_ = current_user @current_user_ = current_user
@course_status = @course.is_end ? 0 : 1 # 课堂是否结束 @course_status = @course.is_end ? 0 : 1 # 课堂是否结束
@course_is_public = @course.is_public @course_is_public = @course.is_public
@polls_count = @polls_all.count # 全部页面,需返回
@polls_unpublish_counts = @polls_all.poll_by_status(1).count #未发布的问卷数
@polls_published_counts = @polls_all.poll_by_status([2, 3]).count # 已发布的问卷数
# 课堂的学生人数 # 课堂的学生人数
@course_all_members = @course.students #当前课堂的全部学生 @course_all_members = @course.students #当前课堂的全部学生
@course_all_members_count = @course_all_members.count #当前课堂的学生数
@current_student = @course_all_members.find_by(user_id: current_user.id) #当前用户是否为课堂的学生 @current_student = @course_all_members.find_by(user_id: current_user.id) #当前用户是否为课堂的学生
# polls的不同用户群体的显示 # polls的不同用户群体的显示
if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教 if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教
@is_teacher_or = 1 @is_teacher_or = 1
@teacher_groups_ids = @course.charge_group_ids(current_user)
@polls = @polls_all #老师能看到全部的问卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同) @polls = @polls_all #老师能看到全部的问卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同)
elsif @user_course_identity == Course::STUDENT # 2为课堂成员能看到统一设置的和自己班级的 elsif @user_course_identity == Course::STUDENT # 2为课堂成员能看到统一设置的和自己班级的
@is_teacher_or = 2 @is_teacher_or = 2
member_group_id = @current_student.try(:course_group_id).to_i # 成员的分班id默认为0 @member_group_id = @current_student.try(:course_group_id).to_i # 成员的分班id默认为0
if member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的) if @member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的)
@polls = member_show_polls.size > 0 ? member_show_polls.public_or_unset : [] @polls = member_show_polls.size > 0 ? member_show_polls.public_or_unset : []
else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷 else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷
# 已发布 当前用户班级分组的 试卷id # 已发布 当前用户班级分组的 试卷id
poll_settings_ids = @course.poll_group_settings.where(course_group_id: member_group_id).poll_group_published.pluck(:poll_id).uniq # 选择成员的班级id等于课堂问卷设置的班级id not_poll_ids = @course.poll_group_settings.poll_group_not_published.where("course_group_id = #{@member_group_id}").pluck(:poll_id)
@polls = member_show_polls.present? ? member_show_polls.public_or_unset.or(member_show_polls.where(id: poll_settings_ids)) : [] @polls = member_show_polls.where.not(id: not_poll_ids)
end end
else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁 else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁
@is_teacher_or = 0 @is_teacher_or = 0
@polls = member_show_polls.size > 0 ? member_show_polls.public_or_unset : [] @polls = member_show_polls.public_or_unset
end end
if @polls.count > 0 if @polls.count > 0
if params[:type].present? if params[:type].present?
choose_type = params[:type] choose_type = params[:type]
member_group_id = @current_student.try(:course_group_id).to_i # 成员的分班id默认为0 poll_setting_ids = []
if @is_teacher_or == 2 && member_group_id > 0 if @is_teacher_or != 2
poll_groups_sets = @course.poll_group_settings.where(course_group_id: member_group_id).poll_group_published @polls = @polls.where("polls_status = #{choose_type}")
poll_settings_ids = poll_groups_sets.pluck(:poll_id)
poll_ended_ids = poll_groups_sets.poll_group_ended.pluck(:poll_id).uniq
# poll_settings_ids = @course.poll_group_settings.where(course_group_id: member_group_id).poll_group_ended.pluck(:poll_id).uniq
if choose_type.to_i == 2
@polls = @polls_all.present? ? @polls_all.poll_by_status(2).public_or_unset.or(@polls_all.where(id:(poll_settings_ids - poll_ended_ids).uniq)).distinct : []
elsif choose_type.to_i == 3
@polls = @polls_all.present? ? @polls_all.poll_by_status(3).public_or_unset.or(@polls_all.where(id: poll_ended_ids)).distinct : []
end
else else
@polls = @polls.poll_by_status(choose_type) case choose_type
when 1
poll_setting_ids = @course.poll_group_settings.where("course_group_id = #{@member_group_id}").poll_group_not_published.pluck(:poll_id)
when 2
poll_setting_ids = @course.poll_group_settings.where("course_group_id = #{@member_group_id}")
.where("publish_time is not null and publish_time <= ? and end_time > ?",Time.now,Time.now).pluck(:poll_id)
when 3
poll_setting_ids = @course.poll_group_settings.where("course_group_id = #{@member_group_id}").poll_group_ended.pluck(:poll_id)
end
unified_setting_ids = @polls.public_or_unset.where("polls_status = #{choose_type}").pluck(:id)
ex_ids = (poll_setting_ids + unified_setting_ids).uniq
@polls = @polls.where(id: ex_ids)
end end
end end
@ -90,11 +88,16 @@ class PollsController < ApplicationController
@limit = params[:limit] || 15 @limit = params[:limit] || 15
@polls = @polls.page(@page).per(@limit) @polls = @polls.page(@page).per(@limit)
@polls = @polls&.includes(:poll_users,:poll_questions,:poll_group_settings) @polls = @polls&.includes(:published_settings)
else else
@polls = [] @polls = []
end end
@polls_count = @polls_all.size # 全部页面,需返回
@polls_unpublish_counts = @polls_all.poll_by_status(1).size #未发布的问卷数
@polls_published_counts = @polls_count - @polls_unpublish_counts # 已发布的问卷数
@course_all_members_count = @course_all_members.size #当前课堂的学生数
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception(e.message) tip_exception(e.message)
@ -146,7 +149,7 @@ class PollsController < ApplicationController
def edit def edit
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
@poll_questions = @poll.poll_questions.order("question_number ASC")
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("页面请求失败!") tip_exception("页面请求失败!")
@ -183,7 +186,7 @@ class PollsController < ApplicationController
else else
@is_teacher_or = 0 @is_teacher_or = 0
end end
@poll_questions = @poll.poll_questions&.includes(:poll_answers).order("question_number ASC")
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("没有权限") tip_exception("没有权限")
@ -202,7 +205,7 @@ class PollsController < ApplicationController
@is_teacher_or = 1 @is_teacher_or = 1
@user_poll_answer = 3 #教师页面 @user_poll_answer = 3 #教师页面
end end
poll_status = @poll.get_poll_status(current_user.id) poll_status = @poll.get_poll_status(current_user)
poll_id_array = [@poll.id] poll_id_array = [@poll.id]
@poll_publish_count = get_user_permission_course(poll_id_array,2).count #是否存在已发布的 @poll_publish_count = get_user_permission_course(poll_id_array,2).count #是否存在已发布的
@poll_unpublish_count = get_user_permission_course(poll_id_array,1).count #是否存在未发布的 @poll_unpublish_count = get_user_permission_course(poll_id_array,1).count #是否存在未发布的
@ -344,7 +347,7 @@ class PollsController < ApplicationController
begin begin
check_ids = Poll.where(id: params[:check_ids]) check_ids = Poll.where(id: params[:check_ids])
check_ids.each do |poll| check_ids.each do |poll|
poll_status = poll.get_poll_status(current_user.id) poll_status = poll.get_poll_status(current_user)
if poll_status == 2 #跳过已截止的或未发布的 if poll_status == 2 #跳过已截止的或未发布的
g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数那么poll的统一设置需修改poll_group_settings g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数那么poll的统一设置需修改poll_group_settings
if g_course if g_course
@ -687,7 +690,7 @@ class PollsController < ApplicationController
course_group_ids = @course.charge_group_ids(current_user) #当前老师的班级id数组 course_group_ids = @course.charge_group_ids(current_user) #当前老师的班级id数组
poll_status = @poll.get_poll_status(current_user.id) poll_status = @poll.get_poll_status(current_user)
if poll_status == 1 && course_group_ids.size > 0 # 问卷未发布且老师的分班大于1 才可以修改统一设置否则按poll默认的来处理 if poll_status == 1 && course_group_ids.size > 0 # 问卷未发布且老师的分班大于1 才可以修改统一设置否则按poll默认的来处理
unified_setting = params[:unified_setting] unified_setting = params[:unified_setting]
else else
@ -847,7 +850,7 @@ class PollsController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
poll_user_current = @poll.poll_users.find_by_group_ids(@poll_current_user_id).first #查找当前用户是否有过答题 poll_user_current = @poll.poll_users.find_by_group_ids(@poll_current_user_id).first #查找当前用户是否有过答题
@poll_status = @poll.get_poll_status(current_user.id) @poll_status = @poll.get_poll_status(current_user)
if poll_user_current.blank? if poll_user_current.blank?
if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候不创建poll_user表理论上老师是不能进入答题的 if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候不创建poll_user表理论上老师是不能进入答题的
poll_user_params = { poll_user_params = {
@ -868,7 +871,6 @@ class PollsController < ApplicationController
@user_poll_status = 0 #可编辑 @user_poll_status = 0 #可编辑
end end
# @answer_user = User.find_by(id:@poll_current_user_id)
@answer_status = [] @answer_status = []
question_answered = 0 question_answered = 0
@ -924,8 +926,7 @@ class PollsController < ApplicationController
@poll_commit_ids = @poll_users.commit_by_status(1).pluck(:user_id) #问卷提交用户的id @poll_commit_ids = @poll_users.commit_by_status(1).pluck(:user_id) #问卷提交用户的id
@page = params[:page] || 1 @page = params[:page] || 1
@limit = params[:limit] || 10 @limit = params[:limit] || 10
@poll_export_questions = @poll_questions.order("question_number ASC") @poll_export_questions = @poll_questions
@poll_questions = @poll_questions.page(@page).per(@limit) @poll_questions = @poll_questions.page(@page).per(@limit)
if params[:format] == "xlsx" if params[:format] == "xlsx"
if @user_course_identity > Course::ASSISTANT_PROFESSOR if @user_course_identity > Course::ASSISTANT_PROFESSOR
@ -935,12 +936,9 @@ class PollsController < ApplicationController
else else
respond_to do |format| respond_to do |format|
format.xlsx{ format.xlsx{
polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" polls_export_name_ = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: { polls_user_commit = poll_commit_result(@poll,@poll_export_questions,@poll_users,@poll_commit_ids)
poll_questions:@poll_export_questions, render xlsx: "#{polls_export_name_.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: {polls_user_commit:polls_user_commit}
poll:@poll,
poll_users: @poll_users,
poll_commit_ids:@poll_commit_ids}
} }
end end
end end
@ -958,7 +956,7 @@ class PollsController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
poll_ids = [@poll.id] poll_ids = [@poll.id]
@poll_list_status = @poll.get_poll_status(current_user.id) @poll_list_status = @poll.get_poll_status(current_user)
@poll_publish_count = get_user_permission_course(poll_ids,2).count @poll_publish_count = get_user_permission_course(poll_ids,2).count
@poll_unpublish_count = get_user_permission_course(poll_ids,1).count @poll_unpublish_count = get_user_permission_course(poll_ids,1).count
@course_all_members = @course.students @course_all_members = @course.students
@ -967,7 +965,7 @@ class PollsController < ApplicationController
if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的问卷 if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的问卷
@poll_current_user_status = 0 @poll_current_user_status = 0
@poll_users_list = @poll.all_poll_users(current_user.id) #该老师分班的全部学生 @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 if @poll_list_status == 1
@poll_course_groups =[] @poll_course_groups =[]
else else
@ -979,7 +977,7 @@ class PollsController < ApplicationController
end end
elsif @user_course_identity > Course::ASSISTANT_PROFESSOR elsif @user_course_identity > Course::ASSISTANT_PROFESSOR
@poll_all_users = @poll.get_poll_exercise_users @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_course_groups = [] #当为学生的时候,不显示分班情况
@poll_current_user_status = 1 #当前用户的状态,为学生 @poll_current_user_status = 1 #当前用户的状态,为学生
poll_current_user = @poll_all_users.find_by_group_ids(current_user.id) #当前用户是否开始做问卷(提交/未提交/没做) poll_current_user = @poll_all_users.find_by_group_ids(current_user.id) #当前用户是否开始做问卷(提交/未提交/没做)
@ -990,7 +988,7 @@ class PollsController < ApplicationController
end end
else else
@poll_all_users = @poll.get_poll_exercise_users @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_current_user_status = 2 #当前用户非课堂成员
@poll_users_list = [] @poll_users_list = []
end end
@ -1106,7 +1104,7 @@ class PollsController < ApplicationController
## 判断开始答题页面的用户权限 ## 判断开始答题页面的用户权限
def check_user_on_answer def check_user_on_answer
poll_status = @poll.get_poll_status(current_user.id) poll_status = @poll.get_poll_status(current_user)
if @user_course_identity == Course::STUDENT && poll_status == 1 #问卷未发布,且当前用户不为老师/管理员 if @user_course_identity == Course::STUDENT && poll_status == 1 #问卷未发布,且当前用户不为老师/管理员
normal_status(-1, "未发布问卷!") normal_status(-1, "未发布问卷!")
elsif @user_course_identity > Course::STUDENT && (!@poll.is_public || (@poll.is_public && !@poll.unified_setting)) ##不为课堂成员,且问卷不为公开的,或问卷公开,但是不是统一设置的 elsif @user_course_identity > Course::STUDENT && (!@poll.is_public || (@poll.is_public && !@poll.unified_setting)) ##不为课堂成员,且问卷不为公开的,或问卷公开,但是不是统一设置的
@ -1153,16 +1151,17 @@ class PollsController < ApplicationController
end end
def get_questions_count def get_questions_count
@poll_questions = @poll.poll_questions&.includes(:poll_answers,:poll_votes).order("question_number ASC") @poll_questions = @poll.poll_questions.order("question_number ASC")
@poll_questions_count = @poll_questions.size # 全部的题目数 @poll_questions_count = @poll_questions&.size # 全部的题目数
@poll_question_singles = @poll_questions.ques_count(1).all.size # 单选题 @poll_question_singles = @poll_questions.ques_count(1).size # 单选题
@poll_question_doubles = @poll_questions.ques_count(2).all.size # 多选题 @poll_question_doubles = @poll_questions.ques_count(2).size # 多选题
@poll_question_mains = @poll_questions.ques_count(3).all.size #主观题 @poll_question_mains = @poll_questions.ques_count(3).size #主观题
@poll_questions = @poll_questions&.includes(:poll_answers,:poll_votes).distinct
end end
def check_poll_question_complete #commit_poll 的权限 def check_poll_question_complete #commit_poll 的权限
poll_user_current = @poll.poll_users.find_by_group_ids(current_user.id).first poll_user_current = @poll.poll_users.find_by_group_ids(current_user.id).first
poll_status = @poll.get_poll_status(current_user.id) poll_status = @poll.get_poll_status(current_user)
if @user_course_identity < Course::STUDENT || (poll_status == 3) || (poll_user_current.present? && poll_user_current.commit_status == 1) if @user_course_identity < Course::STUDENT || (poll_status == 3) || (poll_user_current.present? && poll_user_current.commit_status == 1)
normal_status(-1,"用户没有权限!") #老师/管理员在提交时没有权限 normal_status(-1,"用户没有权限!") #老师/管理员在提交时没有权限
else else
@ -1184,7 +1183,7 @@ class PollsController < ApplicationController
end end
def check_poll_commit_result def check_poll_commit_result
poll_status = @poll.get_poll_status(current_user.id) poll_status = @poll.get_poll_status(current_user)
commit_poll_user = @poll.poll_users.find_by_group_ids(current_user.id).commit_by_status(1) #当前用户已提交问卷的 commit_poll_user = @poll.poll_users.find_by_group_ids(current_user.id).commit_by_status(1) #当前用户已提交问卷的
unless (@user_course_identity < Course::STUDENT) || ((@poll.show_result == 1) && (poll_status == 3) && commit_poll_user.present?) unless (@user_course_identity < Course::STUDENT) || ((@poll.show_result == 1) && (poll_status == 3) && commit_poll_user.present?)
normal_status(-1,"没有权限!") #当前为老师/问卷公开统计,且问卷已截止,且用户有过回答的 normal_status(-1,"没有权限!") #当前为老师/问卷公开统计,且问卷已截止,且用户有过回答的
@ -1216,18 +1215,12 @@ class PollsController < ApplicationController
def get_user_permission_course(poll_ids,status) #获取用户权限范围内的已发布/未发布 def get_user_permission_course(poll_ids,status) #获取用户权限范围内的已发布/未发布
poll_status = status.to_i poll_status = status.to_i
unpublish_group = [] unpublish_group = []
# g_course_ids = @course.teacher_course_groups.get_user_groups(current_user.id).pluck(:course_group_id).reject(&:blank?).uniq
# if g_course_ids.blank? || g_course_ids.include?(0) #当前用户的分班权限为空,即具体全部的分班权限
# user_groups_id = @course.course_groups.pluck(:id)
# else
# user_groups_id = g_course_ids
# end
user_groups_id = @course.charge_group_ids(current_user) user_groups_id = @course.charge_group_ids(current_user)
all_polls = Poll.where(id:poll_ids) all_polls = Poll.where(id:poll_ids)
all_polls.each do |poll| all_polls.each do |poll|
if poll.present? if poll.present?
if poll.unified_setting if poll.unified_setting
poll_user_status = poll.get_poll_status(current_user.id) #当前用户的能看到的试卷 poll_user_status = poll.get_poll_status(current_user) #当前用户的能看到的试卷
if poll_user_status == poll_status || poll_status == 3 #未发布的情况 if poll_user_status == poll_status || poll_status == 3 #未发布的情况
unpublish_group = unpublish_group + user_groups_id unpublish_group = unpublish_group + user_groups_id
else else
@ -1286,8 +1279,6 @@ class PollsController < ApplicationController
else else
normal_status(-1,"请选择分班!") normal_status(-1,"请选择分班!")
end end
# elsif (@poll.poll_status != 1) && (params[:publish_time].to_time != @poll.publish_time) && (@user_course_identity > Course::CREATOR)
# normal_status(-1,"已发布/已截止的不能修发布时间!") #课堂管理员和超级管理员才有权限
end end
end end
@ -1301,4 +1292,99 @@ class PollsController < ApplicationController
end end
end end
#问卷的统计结果的导出
def poll_commit_result(poll,poll_questions,poll_users,poll_commit_ids)
sub_commit = []
user_commit = []
poll_users_info = %w(序号)
poll_ques_titles = poll_questions.pluck(:question_title).map {|k| ActionController::Base.helpers.strip_tags(k) if k.present?}
poll_un_anony = poll.un_anonymous
if poll_un_anony #是否匿名默认为false
user_info = %w(登陆名 真实姓名 邮箱 学号)
else
user_info = []
end
poll_users_info = poll_users_info + user_info + poll_ques_titles
poll_questions.each do |q|
if q.question_type != 3 #问题不为主观题
question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids)&.size #该问题的有效填写量
sheet_row = ["#{q.question_number}"] #选择题答案选项的数组
sheet_answer_row = ["小计"] #选择题回答的答案人数,数组
sheet_answer_percent = ["比例"]
sheet_answer_useful = ["本题有效填写人次",question_vote_user]
q.poll_answers.each do |a| #问卷的答案选项
answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids)&.size
answer_percent = (question_vote_user == 0) ? "0.0%" : "#{((answer_users_count / question_vote_user.to_f)*100).round(1).to_s}%"
sheet_row.push(a.answer_text)
sheet_answer_row.push(answer_users_count)
sheet_answer_percent.push(answer_percent)
end
sheet_sub_commit = {
sub_title: sheet_row,
sub_user_votes:[sheet_answer_row,sheet_answer_percent,sheet_answer_useful]
}
sub_commit.push(sheet_sub_commit)
else #主观题答案
user_votes= []
main_show_row = ["#{q.question_number}", q.question_title ]
q.poll_votes.each_with_index do |v,index| #主观题的答案
q_poll_vote = [(index+1), v.vote_text.present? ? v.vote_text : "--"]
user_votes.push(q_poll_vote)
end
sheet_sub_commit = {
sub_title: main_show_row,
sub_user_votes:user_votes
}
sub_commit.push(sheet_sub_commit)
end
end #each_with_index
poll_users.includes(user: [:user_extension,:poll_votes]).each_with_index do |u,index|
u_user = u.user
user_answer_array = []
poll_questions.each do |q|
user_poll_votes = u_user.poll_votes.find_current_vote("poll_question_id",q.id)
if user_poll_votes.present?
user_poll_answer_ids = user_poll_votes.pluck(:poll_answer_id).reject(&:blank?)
user_poll_vote_texts = user_poll_votes.pluck(:vote_text).reject(&:blank?)
if user_poll_answer_ids.count > 0
answer_content = q.poll_answers.find_answer_by_custom("id",user_poll_answer_ids)
if user_poll_answer_ids.count >1
u_answer = answer_content.pluck(:answer_text).join(";")
else
u_answer = answer_content.first.answer_text
end
elsif user_poll_vote_texts.count > 0
if user_poll_vote_texts.count > 1
u_answer = user_poll_vote_texts.join(";")
else
u_answer = user_poll_vote_texts.first
end
else
u_answer = "--"
end
else
u_answer = "--"
end
user_answer_array.push(u_answer)
end
user_cell = [index+1]
if poll_un_anony
user_login = u_user.login
user_name = u_user.real_name.present? ? u_user.real_name : "--"
user_student_id = u_user.student_id.present? ? u_user.student_id : "--"
user_cell += [user_login,user_name, u_user.mail, user_student_id]
end
all_user_cell = user_cell + user_answer_array
user_commit.push(all_user_cell)
end
{
poll_users_info:poll_users_info,
sub_commit:sub_commit,
user_commit:user_commit
}
end
end end

@ -0,0 +1,5 @@
class RepertoiresController < ApplicationController
def index
render_ok(repertoires: Repertoire.cache_data)
end
end

@ -526,10 +526,10 @@ class ShixunsController < ApplicationController
@current_task = @current_task =
if params[:challenge_id] if params[:challenge_id]
game = games.where(challenge_id: params[:challenge_id]).take game = games.where(challenge_id: params[:challenge_id]).take
if game.status == 3 && !@shixun.task_pass if @shixun.task_pass || game.status != 3
tip_show_exception(-4, "关卡还未开启")
else
game game
else
current_myshixun.current_task(games)
end end
else else
current_myshixun.current_task(games) current_myshixun.current_task(games)
@ -742,8 +742,8 @@ class ShixunsController < ApplicationController
if apply && apply.status == 0 if apply && apply.status == 0
apply.update_attribute(:status, 3) apply.update_attribute(:status, 3)
apply.tidings.destroy_all apply.tidings.destroy_all
@shixun.update_column('status', 0)
end end
@shixun.update_column(:status, 0)
end end
private private

@ -334,8 +334,9 @@ class StudentWorksController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
# 没传score则取上次评分成绩 # 没传score则取上次评分成绩
score = StudentWorksScore.where(user_id: current_user.id, student_work_id: @work.id).last reviewer_role = @user_course_identity == Course::STUDENT ? 3 : @user_course_identity == Course::ASSISTANT_PROFESSOR ? 2 : 1
new_score = StudentWorksScore.new new_score = StudentWorksScore.new
score = StudentWorksScore.where(user_id: current_user.id, student_work_id: @work.id, reviewer_role: reviewer_role).last
new_score.score = params[:score].blank? ? score.try(:score) : params[:score].to_f new_score.score = params[:score].blank? ? score.try(:score) : params[:score].to_f
new_score.comment = params[:comment] if params[:comment] && params[:comment].strip != "" new_score.comment = params[:comment] if params[:comment] && params[:comment].strip != ""
new_score.user_id = current_user.id new_score.user_id = current_user.id
@ -348,7 +349,7 @@ class StudentWorksController < ApplicationController
@work.update_attributes(group_id: @homework.max_group_id) if @homework.homework_type == "group" @work.update_attributes(group_id: @homework.max_group_id) if @homework.homework_type == "group"
end end
new_score.reviewer_role = @user_course_identity == Course::STUDENT ? 3 : @user_course_identity == Course::ASSISTANT_PROFESSOR ? 2 : 1 new_score.reviewer_role = reviewer_role
if new_score.save! if new_score.save!
Attachment.associate_container(params[:attachment_ids], new_score.id, new_score.class) Attachment.associate_container(params[:attachment_ids], new_score.id, new_score.class)
@ -381,7 +382,7 @@ class StudentWorksController < ApplicationController
when 3 #学生评分 学生评分显示平均分 when 3 #学生评分 学生评分显示平均分
# 匿评分 # 匿评分
@work.student_score = new_score.stu_score(@work.id) @work.student_score = new_score.stu_score(@work.id)
if @homework.homework_type == "group" && params[:same_score] && new_score.score.present? if @homework.homework_type == "group" && new_score.score.present?
add_score_to_member @work, @homework, new_score add_score_to_member @work, @homework, new_score
end end
@ -455,9 +456,9 @@ class StudentWorksController < ApplicationController
@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 }
@myself_consume = @echart_data[:consume_list].find { |item| item.last == @user.id } @myself_consume = @echart_data[:consume_list].find { |item| item.last == @user.id }
# filename = "实训报告_#{@shixun.name}_#{@use.real_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" #下载报错 unknown nil name,下面为修改的-hs-0606
filename = "实训报告_#{@shixun&.name}_#{@use&.real_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" filename_ = "实训报告_#{@shixun&.name}_#{@use&.real_name}"
filename = Base64.urlsafe_encode64(filename_.strip.first(30))
stylesheets = %w(shixun_work/shixun_work.css shared/codemirror.css) stylesheets = %w(shixun_work/shixun_work.css shared/codemirror.css)
render pdf: 'shixun_work/shixun_work', filename: filename, stylesheets: stylesheets render pdf: 'shixun_work/shixun_work', filename: filename, stylesheets: stylesheets
end end
@ -730,19 +731,19 @@ class StudentWorksController < ApplicationController
student_works.each do |st_work| student_works.each do |st_work|
st_score = StudentWorksScore.new(user_id: new_score.user_id, score: new_score.score, st_score = StudentWorksScore.new(user_id: new_score.user_id, score: new_score.score,
reviewer_role: new_score.reviewer_role, comment: new_score.comment) reviewer_role: new_score.reviewer_role, comment: new_score.comment)
st_work.student_works_scores << st_score
score = StudentWorksScore.where(user_id: new_score.user_id, student_work_id: st_work.id).last score = StudentWorksScore.where(user_id: new_score.user_id, student_work_id: st_work.id, reviewer_role: new_score.reviewer_role).last
# 该用户的历史评阅无效 # 该用户的历史评阅无效
score.update_column('is_invalid', true) if score.present? && score.score.present? score.update_column('is_invalid', true) if score.present? && score.score.present?
st_work.student_works_scores << st_score
if new_score.reviewer_role == 1 if new_score.reviewer_role == 1
st_work.teacher_score = new_score.score st_work.teacher_score = new_score.score if new_score.score.present?
elsif new_score.reviewer_role == 2 elsif new_score.reviewer_role == 2
if homework.homework_detail_manual.ta_mode == 1 if homework.homework_detail_manual.ta_mode == 1
st_work.teaching_asistant_score = new_score.ta_score st_work.id st_work.teaching_asistant_score = new_score.ta_score st_work.id
else else
st_work.teaching_asistant_score = new_score.score st_work.teaching_asistant_score = new_score.score if new_score.score.present?
end end
else else
st_work.student_score = student_work.student_score st_work.student_score = student_work.student_score

@ -0,0 +1,39 @@
class Users::AuthAttachmentsController < Users::BaseAccountController
before_action :private_user_resources!
before_action :convert_image!, only: [:update]
def update
image_temp_path = auth_image_path + 'temp' # 上传文件保存至临时文件,提交申请时再移到正常目录
File.delete(image_temp_path) if File.exist?(image_temp_path) # 删除之前的临时文件
Util.write_file(@image, image_temp_path)
render_ok
rescue StandardError => ex
logger_error(ex)
render_error('上传失败')
end
private
def convert_image!
max_size = EduSetting.get('upload_avatar_max_size') || 10 * 1024 * 1024 # 10M
if params[:image].class == ActionDispatch::Http::UploadedFile
@image = params[:image]
render_error('请上传文件') if @image.size.zero?
render_error('文件大小超过限制') if @image.size > max_size
else
image = params[:image].to_s.strip
return render_error('请上传正确的图片') if image.blank?
@image = Util.convert_base64_image(image, max_size: max_size)
end
rescue Base64ImageConverter::Error => ex
render_error(ex.message)
end
def auth_image_path
url_method = params[:type] == 'professional' ? :disk_professional_auth_filename : :disk_real_name_auth_filename
ApplicationController.helpers.send(url_method, observed_user.id)
end
end

@ -0,0 +1,16 @@
class Users::AuthenticationAppliesController < Users::BaseAccountController
before_action :private_user_resources!
def create
Users::ApplyAuthenticationService.call(observed_user, create_params)
render_ok
rescue Users::ApplyAuthenticationService::Error => ex
render_error(ex.message)
end
private
def create_params
params.permit(:name, :id_number, :upload_image)
end
end

@ -0,0 +1,25 @@
class Users::InterestsController < Users::BaseController
skip_before_action :check_observed_user_exists!
before_action :require_login
def create
identity = params[:identity].to_s.strip
extension = current_user.user_extension || current_user.build_user_extension
return render_error('请选择职业') unless %w(teacher student professional).include?(identity)
ActiveRecord::Base.transaction do
extension.update_column(:identity, identity)
# 兴趣
current_user.user_interests.delete_all
UserInterest.bulk_insert(:user_id, :repertoire_id) do |worker|
(Repertoire.pluck(:id) & Array.wrap(params[:interest_ids]).map(&:to_i)).each do |repertoire_id|
worker.add(user_id: current_user.id, repertoire_id: repertoire_id)
end
end
end
render_ok
end
end

@ -0,0 +1,16 @@
class Users::ProfessionalAuthAppliesController < Users::BaseAccountController
before_action :private_user_resources!
def create
Users::ApplyProfessionalAuthService.call(observed_user, create_params)
render_ok
rescue Users::ApplyProfessionalAuthService::Error => ex
render_error(ex.message)
end
private
def create_params
params.permit(:school_id, :department_id, :identity, :extra, :upload_image)
end
end

@ -6,14 +6,9 @@ class ZipsController < ApplicationController
before_action :require_admin_or_teacher before_action :require_admin_or_teacher
def shixun_report def shixun_report
# student_work_ids = Array.wrap(params[:student_work_ids])
# service = BatchExportShixunReportService.new(@homework, @student_work_ids)
service = BatchExportShixunReportService.new(@homework, @all_student_works) service = BatchExportShixunReportService.new(@homework, @all_student_works)
filename_ = filename_for_content_disposition(service.filename)
send_file service.zip, filename: filename_, type: 'application/zip'
filename = filename_for_content_disposition(service.filename)
send_file service.zip, filename: filename, type: 'application/zip'
rescue BatchExportShixunReportService::Error => ex rescue BatchExportShixunReportService::Error => ex
normal_status(-1, ex.message) normal_status(-1, ex.message)
end end
@ -22,9 +17,8 @@ class ZipsController < ApplicationController
@request_url = request.base_url @request_url = request.base_url
exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url) exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url)
file_name = filename_for_content_disposition(exercises.filename) file_name_ = filename_for_content_disposition(exercises.filename)
send_file exercises.ex_zip, filename: file_name, type: 'application/zip' send_file exercises.ex_zip, filename: file_name_, type: 'application/zip'
rescue Exception => e rescue Exception => e
normal_status(-1, e.message) normal_status(-1, e.message)
end end
@ -44,7 +38,7 @@ 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) @exercise_status = @exercise.present? ? @exercise.get_exercise_status(current_user) : 1
group_id = params[:exercise_group_id] group_id = params[:exercise_group_id]
if @exercise.blank? if @exercise.blank?
normal_status(-1,"试卷不存在") normal_status(-1,"试卷不存在")
@ -101,34 +95,40 @@ class ZipsController < ApplicationController
def load_homework def load_homework
@homework = HomeworkCommon.find(params[:homework_common_id]) @homework = HomeworkCommon.find(params[:homework_common_id])
@homework_status = @homework.present? ? @homework.homework_detail_manual.comment_status : 0
if @homework.blank?
normal_status(-1,"该作业不存在")
elsif @homework_status == 0
normal_status(-1,"该作业未发布")
else
@course = @homework.course
##7。2 -hs新增
@member = @course.course_member(current_user.id)
@all_student_works = @homework.teacher_works(@member).where("work_status > 0")
work_status = params[:work_status]
group_id = params[:course_group]
if work_status.present?
@all_student_works = @all_student_works.where(work_status:work_status)
end
if group_id.present?
group_user_ids = @course.students.where(course_group_id: params[:course_group]).pluck(:user_id)
@all_student_works = @all_student_works.where(user_id: group_user_ids)
end
@course = @homework.course unless params[:search].blank?
##7。2 -hs新增 @all_student_works = @all_student_works.joins(user: :user_extension).where("concat(lastname, firstname) like ?
@member = @course.course_member(current_user.id)
@all_student_works = @homework.teacher_works(@member).where("work_status > 0")
work_status = params[:work_status]
group_id = params[:course_group]
if work_status.present?
@all_student_works = @all_student_works.where(work_status:work_status)
end
if group_id.present?
group_user_ids = @course.students.where(course_group_id: params[:course_group]).pluck(:user_id)
@all_student_works = @all_student_works.where(user_id: group_user_ids)
end
unless params[:search].blank?
@all_student_works = @all_student_works.joins(user: :user_extension).where("concat(lastname, firstname) like ?
or student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%") or student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%")
end end
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 end
end end
end end

@ -0,0 +1,8 @@
class Users::ApplyAuthenticationForm
include ActiveModel::Model
attr_accessor :name, :id_number, :upload_image
validates :name, presence: true
validates :id_number, presence: true
end

@ -0,0 +1,10 @@
class Users::ApplyProfessionalAuthForm
include ActiveModel::Model
attr_accessor :school_id, :department_id, :identity, :extra, :upload_image
validates :school_id, presence: true, numericality: { only_integer: true, greater_than: 0 }
validates :department_id, numericality: { only_integer: true, greater_than: 0 }, allow_blank: true
validates :identity, presence: true, inclusion: { in: %w(student teacher professional) }
validates :extra, presence: true
end

@ -145,6 +145,18 @@ module ApplicationHelper
File.join(storage_path, "#{source_type}", "#{source_id}") File.join(storage_path, "#{source_type}", "#{source_id}")
end end
def disk_auth_filename(source_type, source_id, type)
File.join(storage_path, "#{source_type}", "#{source_id}#{type}")
end
def disk_real_name_auth_filename(source_id)
disk_auth_filename('UserAuthentication', source_id, 'ID')
end
def disk_professional_auth_filename(source_id)
disk_auth_filename('UserAuthentication', source_id, 'PRO')
end
def shixun_url_to_avatar(shixun) def shixun_url_to_avatar(shixun)
if File.exist?(disk_filename(shixun.class, shixun.id)) if File.exist?(disk_filename(shixun.class, shixun.id))
File.join("images/#{relative_path}", "#{shixun.class}", "#{shixun.id}") File.join("images/#{relative_path}", "#{shixun.class}", "#{shixun.id}")

@ -89,11 +89,7 @@ module ExercisesHelper
if ex.question_type <= 2 #单选题 if ex.question_type <= 2 #单选题
standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id) #标准答案的位置 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id) #标准答案的位置
ex.exercise_choices.each do |c| ex.exercise_choices.each do |c|
if standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置
right_answer = true
else
right_answer = false
end
answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id)
answer_users_count = answer_this_choice.count answer_users_count = answer_this_choice.count
if effictive_users_count == 0 if effictive_users_count == 0
@ -176,11 +172,7 @@ module ExercisesHelper
# zero_scores = all_zero_scores - un_review_scores #已评阅且答案未0分的人数 # 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 = [full_scores,no_full_scores,zero_scores,un_review_scores]
main_scores_array.each_with_index do |s,index| main_scores_array.each_with_index do |s,index|
if index == 0 right_answer = (index == 0)
right_answer = true
else
right_answer = false
end
if effictive_users_count == 0 || s < 0 if effictive_users_count == 0 || s < 0
s = 0 s = 0
score_percent = 0.0 score_percent = 0.0
@ -207,11 +199,7 @@ module ExercisesHelper
shixun_score_array = [full_scores,no_full_scores,all_zero_scores] shixun_score_array = [full_scores,no_full_scores,all_zero_scores]
shixun_chas = [] shixun_chas = []
shixun_score_array.each_with_index do |s,index| shixun_score_array.each_with_index do |s,index|
if index == 0 right_answer = (index == 0)
right_answer = true
else
right_answer = false
end
if effictive_users_count == 0 if effictive_users_count == 0
score_percent = 0.0 score_percent = 0.0
else else
@ -250,16 +238,19 @@ module ExercisesHelper
end end
#获取试卷的已答/未答人数 #获取试卷的已答/未答人数
def get_exercise_answers(ex_users) def get_exercise_answers(ex_users, status)
@commit_ex_users = ex_users.commit_exercise_by_status(1) #当前老师的全部学生中已提交的 if status == 1
@exercise_answers = 0
@exercise_answers = @commit_ex_users.present? ? @commit_ex_users.size : 0 #表示已经提交了的用户 @exercise_unanswers = 0
course_all_members_count = ex_users.present? ? ex_users.size : 0 else
@exercise_unanswers = (course_all_members_count - @exercise_answers) @exercise_answers = ex_users.commit_exercise_by_status(1).size #表示已经提交了的用户
course_all_members_count = ex_users.size
@exercise_unanswers = (course_all_members_count - @exercise_answers)
end
end end
def exercise_index_show(exercise,course,is_teacher_or,user) def exercise_index_show(exercise,course,is_teacher_or,user)
# exercise_all_users = exercise.exercise_users # lock_icon 0出现锁1不出现锁
ex_show_text = [] ex_show_text = []
if course.is_end #课堂停止后,试卷显示为已结束 if course.is_end #课堂停止后,试卷显示为已结束
@ -267,7 +258,7 @@ module ExercisesHelper
elsif is_teacher_or == 1 #当前为老师的时候,显示的是老师身份的对应试卷的状态,因为该试卷,可能对应老师的多个分班 elsif is_teacher_or == 1 #当前为老师的时候,显示的是老师身份的对应试卷的状态,因为该试卷,可能对应老师的多个分班
exercise_status = exercise.exercise_status exercise_status = exercise.exercise_status
else else
exercise_status = exercise.get_exercise_status(user.id) #当前用户查看的试卷的发布状态 exercise_status = exercise.get_exercise_status(user) #当前用户查看的试卷的发布状态
end end
case exercise_status case exercise_status
@ -280,15 +271,16 @@ module ExercisesHelper
else else
ex_show_text ex_show_text
end end
if is_teacher_or == 1 if is_teacher_or == 1
exercise_users_list = exercise.all_exercise_users(user.id) #当前老师所在班级的全部学生 exercise_users_list = exercise.all_exercise_users(user.id) #当前老师所在班级的全部学生
unreview_count = exercise_users_list.exercise_unreview.size unreview_count = exercise_status == 1 ? 0 : exercise_users_list.exercise_unreview.size
get_exercise_answers(exercise_users_list) get_exercise_answers(exercise_users_list, exercise_status)
ex_pb_time = exercise.get_exercise_times(user.id,true) ex_pb_time = exercise.get_exercise_times(user.id,true)
exercise_publish_time = ex_pb_time[:publish_time] exercise_publish_time = ex_pb_time[:publish_time]
exercise_end_time = ex_pb_time[:end_time] exercise_end_time = ex_pb_time[:end_time]
current_status = 3 current_status = 3
lock_icon = 1 #不显示锁图标 lock_icon = 0
if exercise_status == 1 if exercise_status == 1
ex_show_text.push("未发布") ex_show_text.push("未发布")
elsif exercise_status == 3 elsif exercise_status == 3
@ -296,34 +288,38 @@ module ExercisesHelper
end end
elsif is_teacher_or == 2 elsif is_teacher_or == 2
exercise_users_list = exercise.get_stu_exercise_users exercise_users_list = exercise.get_stu_exercise_users
get_exercise_answers(exercise_users_list) # 未答和已答的 get_exercise_answers(exercise_users_list, exercise_status) # 未答和已答的
unreview_count = exercise_users_list.exercise_unreview.size unreview_count = exercise_status == 1 ? 0 : exercise_users_list.exercise_unreview.size
ex_pb_time = exercise.get_exercise_times(user.id,false) ex_pb_time = exercise.get_exercise_times(user.id,false)
exercise_publish_time = ex_pb_time[:publish_time] exercise_publish_time = ex_pb_time[:publish_time]
exercise_end_time = ex_pb_time[:end_time] exercise_end_time = ex_pb_time[:end_time]
current_status = exercise.check_user_answer_status(user) current_status = exercise.check_user_answer_status(user)
lock_icon = 1 #不显示锁图标 lock_icon = 0
if current_status == 4 if current_status == 4
ex_show_text.push("未提交") ex_show_text.push("未提交")
end end
else else
exercise_users_list = exercise.get_stu_exercise_users exercise_users_list = exercise.get_stu_exercise_users
get_exercise_answers(exercise_users_list) # 未答和已答的 get_exercise_answers(exercise_users_list, exercise_status) # 未答和已答的
exercise_publish_time = exercise.publish_time exercise_publish_time = exercise.publish_time
exercise_end_time = exercise.end_time exercise_end_time = exercise.end_time
unreview_count = nil unreview_count = nil
if exercise.is_public if exercise.is_public
current_status = exercise.check_user_answer_status(user) current_status = exercise.check_user_answer_status(user)
lock_icon = 1 #非课堂成员,但是试卷为公开的,不加 lock_icon = 1 #不出现
if current_status == 4 if current_status == 4
ex_show_text.push("未提交") ex_show_text.push("未提交")
end end
else else
current_status = 4 current_status = 4
lock_icon = 0 #显示锁图标 lock_icon = 0
end end
end end
if (course.is_public == 1) && exercise.is_public
lock_icon = 1
end
if exercise_status > 1 if exercise_status > 1
show_unreview_count = unreview_count show_unreview_count = unreview_count
else else
@ -332,8 +328,6 @@ module ExercisesHelper
if exercise_status == 2 && exercise_end_time.present? if exercise_status == 2 && exercise_end_time.present?
ex_left_time = how_much_time(exercise_end_time) ex_left_time = how_much_time(exercise_end_time)
# elsif exercise_status == 3 && course.end_date.present?
# ex_left_time = how_much_time(course.end_date.to_time)
else #已截止后不显示时间 else #已截止后不显示时间
ex_left_time = nil ex_left_time = nil
end end
@ -507,9 +501,9 @@ module ExercisesHelper
ex_user_user = ex_user.user ex_user_user = ex_user.user
exercise_user_name = ex_user_user.real_name exercise_user_name = ex_user_user.real_name
exercise_user_id = ex_user_user.id exercise_user_id = ex_user_user.id
ex_user_exercise_status = exercise.get_exercise_status(exercise_user_id) ex_user_exercise_status = exercise.get_exercise_status(ex_user_user)
ex_user_student_id = ex_user_user.student_id ex_user_student_id = ex_user_user.student_id
if ex_user.start_at.present? && ex_user.commit_status == 0 #用户已回答,但未提交 if ex_user.start_at.present? && (ex_user.commit_status == 0) #用户已回答,但未提交
commit_status = 2 #继续答题 commit_status = 2 #继续答题
else else
commit_status = ex_user.commit_status commit_status = ex_user.commit_status

@ -40,10 +40,17 @@ module ExportHelper
works.includes(user: :user_extension, student_works_scores: :user).each_with_index do |w, index| works.includes(user: :user_extension, student_works_scores: :user).each_with_index do |w, index|
w_user = w.user w_user = w.user
w_1 = (index + 1) w_1 = (index + 1)
w_2 = w_user.login if w_user.present?
w_3 = w_user.real_name w_2 = w_user&.login
w_3_1 = w_user.mail w_3 = w_user&.real_name
w_4 = w_user.student_id.present? ? w_user.student_id : "--" w_3_1 = w_user&.mail
w_4 = w_user.student_id.present? ? w_user.student_id : "--"
else
w_2 = "--"
w_3 = "--"
w_3_1 = "--"
w_4 = "--"
end
course_name = course.students.find_by(user_id: w.user_id).try(:course_group_name) course_name = course.students.find_by(user_id: w.user_id).try(:course_group_name)
w_5 = course_name.present? ? course_name : "--" w_5 = course_name.present? ? course_name : "--"
#0 未提交, 1 按时提交, 2 延迟提交 #0 未提交, 1 按时提交, 2 延迟提交
@ -487,6 +494,8 @@ module ExportHelper
zipfile_name = "#{output_path}/#{rename_zipfile}" zipfile_name = "#{output_path}/#{rename_zipfile}"
# 同名文件重命名时用
index = 1
Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name)) Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
files_paths.each do |filename| files_paths.each do |filename|
@ -496,7 +505,11 @@ module ExportHelper
begin begin
zipfile.add(rename_file, filename) zipfile.add(rename_file, filename)
rescue Exception => e rescue Exception => e
zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write "该作品中有重复命名文件,请通过文件名学号和姓名信息进入该作业详细界面手动下载"} rename_file = rename_same_file(rename_file, index)
index += 1
zipfile.add(rename_file, filename)
# zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write "该作品中有重复命名文件,请通过文件名学号和姓名信息进入该作业详细界面手动下载"}
next next
end end
end end
@ -516,4 +529,11 @@ module ExportHelper
def format_sheet_name name def format_sheet_name name
name = name.gsub(":", "-") name = name.gsub(":", "-")
end end
def rename_same_file(name, index)
basename = File.basename(name, ".*")
new_basename = basename + "_" + index.to_s
extname = File.extname(name)
new_basename + extname
end
end end

@ -1,11 +1,15 @@
module PollsHelper module PollsHelper
#获取试卷的已答/未答人数 #获取试卷的已答/未答人数
def get_poll_answers(poll_users) def get_poll_answers(poll_users, status)
@commit_poll_users = poll_users.commit_by_status(1) #当前老师的全部学生中已提交的 if status == 1
@poll_answers = @commit_poll_users.present? ? @commit_poll_users.size : 0 #表示已经提交了的用户 @poll_answers = 0
course_all_members_count = poll_users.present? ? poll_users.size : 0 @poll_unanswers = 0
@poll_unanswers = (course_all_members_count - @poll_answers) 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)
end
end end
def poll_votes_count(votes,user_ids) def poll_votes_count(votes,user_ids)
@ -55,29 +59,29 @@ module PollsHelper
#当前为老师(非课堂成员、统一设置)的时候,显示的是老师身份的对应试卷的状态,因为该试卷,可能对应老师的多个分班 #当前为老师(非课堂成员、统一设置)的时候,显示的是老师身份的对应试卷的状态,因为该试卷,可能对应老师的多个分班
poll_status = poll.polls_status poll_status = poll.polls_status
else else
poll_status = poll.get_poll_status(user.id) #当前用户查看的试卷的发布状态 poll_status = poll.get_poll_status(user) #当前用户查看的试卷的发布状态
end end
if is_teacher_or == 1 if is_teacher_or == 1
poll_users_list = poll.all_poll_users(user.id) #当前老师所在班级的全部学生 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) ex_pb_time = poll.get_poll_times(user.id,true)
poll_publish_time = ex_pb_time[:publish_time] poll_publish_time = ex_pb_time[:publish_time]
poll_end_time = ex_pb_time[:end_time] poll_end_time = ex_pb_time[:end_time]
current_status = 3 current_status = 3
lock_icon = 1 #不显示锁图标 lock_icon = 0 #不显示锁图标
elsif is_teacher_or == 2 elsif is_teacher_or == 2
poll_users_list = poll.get_poll_exercise_users 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) # get_poll_answers(poll_all_users)
ex_pb_time = poll.get_poll_times(user.id,false) ex_pb_time = poll.get_poll_times(user.id,false)
poll_publish_time = ex_pb_time[:publish_time] poll_publish_time = ex_pb_time[:publish_time]
poll_end_time = ex_pb_time[:end_time] poll_end_time = ex_pb_time[:end_time]
current_status = poll.check_user_votes_status(user) current_status = poll.check_user_votes_status(user)
lock_icon = 1 #不显示锁图标 lock_icon = 0 #不显示锁图标
else else
poll_users_list = poll.get_poll_exercise_users 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_publish_time = poll.publish_time
poll_end_time = poll.end_time poll_end_time = poll.end_time
current_status = 4 current_status = 4
@ -87,6 +91,9 @@ module PollsHelper
lock_icon = 0 #显示锁图标 lock_icon = 0 #显示锁图标
end end
end end
if (course.is_public == 1) && poll.is_public
lock_icon = 1
end
{ {
"publish_time":poll_publish_time, "publish_time":poll_publish_time,
"end_time":poll_end_time, "end_time":poll_end_time,
@ -128,16 +135,4 @@ module PollsHelper
} }
end end
def poll_commit_result(poll,poll_questions,poll_users,poll_commit_ids)
poll_users_info = %w(序号)
poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?}
poll_un_anony = poll.un_anonymous
if poll_un_anony #是否匿名默认为false
user_info = %w(登陆名 真实姓名 邮箱 学号)
else
user_info = []
end
poll_users_info = poll_users_info + user_info + poll_ques_titles
end
end end

@ -0,0 +1,67 @@
# 学生加入课堂时创建相关任务作品
class CourseAddStudentCreateWorksJob < ApplicationJob
queue_as :default
def perform(course_id, student_ids)
course = Course.find_by(id: course_id)
return if course.blank?
# 如果之前存在相关作品则更新is_delete字段
student_works = StudentWork.joins(:homework_common).where(user_id: student_ids, homework_commons: {course_id: course.id})
student_works.update_all(is_delete: 0)
exercise_users = ExerciseUser.joins(:exercise).where(user_id: student_ids, exercises: {course_id: course.id})
exercise_users.update_all(is_delete: 0)
poll_users = PollUser.joins(:poll).where(user_id: student_ids, polls: {course_id: course.id})
poll_users.update_all(is_delete: 0)
graduation_works = course.graduation_works.where(user_id: student_ids)
graduation_works.update_all(is_delete: 0)
attrs = %i[homework_common_id user_id created_at updated_at]
StudentWork.bulk_insert(*attrs) do |worker|
student_ids.each do |user_id|
same_attrs = {user_id: user_id}
course.homework_commons.where(homework_type: %i[normal group practice]).each do |homework|
next if homework.student_works.where(user_id: user_id).any?
worker.add same_attrs.merge(homework_common_id: homework.id)
end
end
end
attrs = %i[exercise_id user_id created_at updated_at]
ExerciseUser.bulk_insert(*attrs) do |worker|
student_ids.each do |user_id|
same_attrs = {user_id: user_id}
course.exercises.each do |exercise|
next if exercise.exercise_users.where(user_id: user_id).any?
worker.add same_attrs.merge(exercise_id: exercise.id)
end
end
end
attrs = %i[poll_id user_id created_at updated_at]
PollUser.bulk_insert(*attrs) do |worker|
student_ids.each do |user_id|
same_attrs = {user_id: user_id}
course.polls.each do |poll|
next if poll.poll_users.where(user_id: user_id).any?
worker.add same_attrs.merge(poll_id: poll.id)
end
end
end
attrs = %i[graduation_task_id user_id course_id created_at updated_at]
GraduationWork.bulk_insert(*attrs) do |worker|
student_ids.each do |user_id|
same_attrs = {user_id: user_id, course_id: course.id}
course.graduation_tasks.each do |task|
next if task.graduation_works.where(user_id: user_id).any?
worker.add same_attrs.merge(graduation_task_id: task.id)
end
end
end
end
end

@ -0,0 +1,19 @@
class CourseDeleteStudentDeleteWorksJob < ApplicationJob
queue_as :default
def perform(course_id, student_ids)
course = Course.find_by(id: course_id)
return if course.blank?
student_works = StudentWork.joins(:homework_common).where(user_id: student_ids, homework_commons: {course_id: course.id})
student_works.update_all(is_delete: 1)
exercise_users = ExerciseUser.joins(:exercise).where(user_id: student_ids, exercises: {course_id: course.id})
exercise_users.update_all(is_delete: 1)
poll_users = PollUser.joins(:poll).where(user_id: student_ids, polls: {course_id: course.id})
poll_users.update_all(is_delete: 1)
course.graduation_works.where(user_id: student_ids).update_all(is_delete: 1)
end
end

@ -1,6 +1,6 @@
# 毕设任务的交叉评阅分配 # 毕设任务的交叉评阅分配
class GraduationTaskCrossCommentJob < ApplicationJob class GraduationTaskCrossCommentJob < ApplicationJob
queue_as :evaluation_comment queue_as :default
def perform(graduation_task_id) def perform(graduation_task_id)
task = GraduationTask.find_by(id: graduation_task_id) task = GraduationTask.find_by(id: graduation_task_id)

@ -20,7 +20,7 @@ class GraduationTaskPublishNotifyJob < ApplicationJob
viewed: 0, tiding_type: 'GraduationTask' viewed: 0, tiding_type: 'GraduationTask'
} }
Tiding.bulk_insert(*attrs) do |worker| Tiding.bulk_insert(*attrs) do |worker|
course.course_members.pluck(:user_id).uniq.find_each do |user_id| course.course_members.pluck(:user_id).uniq.each do |user_id|
worker.add same_attrs.merge(user_id: user_id) worker.add same_attrs.merge(user_id: user_id)
end end
end end

@ -1,5 +1,5 @@
class HomeworkAbsencePenaltyCalculationJob < ApplicationJob class HomeworkAbsencePenaltyCalculationJob < ApplicationJob
queue_as :score queue_as :default
def perform(homework_common_id) def perform(homework_common_id)
homework_common = HomeworkCommon.find_by(id: homework_common_id) homework_common = HomeworkCommon.find_by(id: homework_common_id)
@ -11,7 +11,7 @@ class HomeworkAbsencePenaltyCalculationJob < ApplicationJob
homework_common.student_works.where("work_status != 0").each do |student_work| homework_common.student_works.where("work_status != 0").each do |student_work|
absence_penalty_count = student_work.user.student_works_evaluation_distributions.where(student_work_id: work_ids).count - absence_penalty_count = student_work.user.student_works_evaluation_distributions.where(student_work_id: work_ids).count -
student_work.user.student_works_scores.where(student_work_id: work_ids, reviewer_role: 3).group_by(:student_work_id).count student_work.user.student_works_scores.where(student_work_id: work_ids, reviewer_role: 3).group_by(&:student_work_id).count
student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0 student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0
student_work.save student_work.save

@ -1,6 +1,6 @@
class HomeworkEndUpdateScoreJob < ApplicationJob class HomeworkEndUpdateScoreJob < ApplicationJob
# 不允许补交的作业截止后,或者补交截止后需要重新计算一次作业成绩 # 不允许补交的作业截止后,或者补交截止后需要重新计算一次作业成绩
queue_as :score queue_as :default
def perform(homework_id) def perform(homework_id)
homework = HomeworkCommon.find_by(id: homework_id) homework = HomeworkCommon.find_by(id: homework_id)

@ -1,5 +1,5 @@
class HomeworkEvaluationCommentAssginJob < ApplicationJob class HomeworkEvaluationCommentAssginJob < ApplicationJob
queue_as :evaluation_comment queue_as :default
def get_assigned_homeworks(student_works, n, index) def get_assigned_homeworks(student_works, n, index)
student_works += student_works student_works += student_works

@ -1,6 +1,6 @@
class HomeworkPublishUpdateWorkStatusJob < ApplicationJob class HomeworkPublishUpdateWorkStatusJob < ApplicationJob
# 作业发布时更新学生(发布前已开启过实训)的作业状态和成绩 # 作业发布时更新学生(发布前已开启过实训)的作业状态和成绩
queue_as :score queue_as :default
def perform(group_ids, homework_id) def perform(group_ids, homework_id)
# Do something later # Do something later

@ -10,7 +10,7 @@ class Challenge < ApplicationRecord
has_many :games, :dependent => :destroy has_many :games, :dependent => :destroy
has_many :challenge_chooses, :dependent => :destroy has_many :challenge_chooses, :dependent => :destroy
has_many :homework_challenge_settings, :dependent => :destroy has_many :homework_challenge_settings, :dependent => :destroy
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
has_one :praise_tread_cache, as: :object, dependent: :destroy has_one :praise_tread_cache, as: :object, dependent: :destroy
has_many :tidings has_many :tidings
# 参考答案 # 参考答案
@ -20,7 +20,7 @@ class Challenge < ApplicationRecord
# acts_as_attachable # acts_as_attachable
scope :base_attrs, -> { select([:id, :subject, :position, :shixun_id, :st, :score, :path, :task_pass, :modify_time, scope :base_attrs, -> { select([:id, :subject, :position, :shixun_id, :st, :score, :path, :task_pass, :modify_time,
:web_route, :answer, :exec_time]) } :web_route, :answer, :exec_time, :praises_count]) }
scope :choose_type, -> { where(st: 1) } scope :choose_type, -> { where(st: 1) }
scope :practice_type, -> { where(st: 0) } scope :practice_type, -> { where(st: 0) }
@ -77,14 +77,17 @@ class Challenge < ApplicationRecord
def user_tpi_status user_id def user_tpi_status user_id
# todo: 以前没加索引导致相同关卡,同一用户有多个games # todo: 以前没加索引导致相同关卡,同一用户有多个games
# 允许跳关则直接开启 # 允许跳关则直接开启
return 1 if shixun.task_pass
game = games.where(user_id: user_id).take game = games.where(user_id: user_id).take
if game.blank? if game.blank?
self.position == 1 ? 1 : 0 position == 1 ? 1 : 0
elsif game.status == 2
2
else else
1 if game.status == 3
shixun.task_pass ? 1 : 0
elsif game.status == 2
2
else
1
end
end end
end end

@ -124,7 +124,7 @@ class Course < ApplicationRecord
#当前老师的班级id #当前老师的班级id
def teacher_course_ids(user_id) def teacher_course_ids(user_id)
course_teacher_member = teacher_course_groups.get_user_groups(user_id) #获取当前老师的分班 course_teacher_member = teacher_course_groups.get_user_groups(user_id).select(:course_group_id) #获取当前老师的分班
if course_teacher_member.blank? if course_teacher_member.blank?
if none_group_count > 0 #有未分班的,则发布到未发布分班 if none_group_count > 0 #有未分班的,则发布到未发布分班
un_group_ids = [0] un_group_ids = [0]
@ -258,7 +258,7 @@ class Course < ApplicationRecord
# 是否具有分班权限,返回分班的id # 是否具有分班权限,返回分班的id
def group_course_power(user_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 end
#课程动态公共表记录 #课程动态公共表记录
@ -308,12 +308,12 @@ class Course < ApplicationRecord
teacher_power_courses = [] teacher_power_courses = []
if course_groups.present? if course_groups.present?
common_ids.each do |i| common_ids.each do |i|
student_count = students.where(course_group_id:i).count
if i == 0 if i == 0
student_count = students.where(course_group_id:i).count
teacher_power_courses << {course_name:"未分班",course_id:0,student_count:student_count} teacher_power_courses << {course_name:"未分班",course_id:0,student_count:student_count}
else else
course_group_name = course_groups.find_by(id:i) course_group_name = course_groups.find_by(id:i)
teacher_power_courses << {course_name:course_group_name&.name,course_id:i,student_count:student_count} teacher_power_courses << {course_name:course_group_name&.name,course_id:i,student_count:course_group_name&.course_members_count}
end end
end end
end end

@ -20,8 +20,8 @@ class CourseMember < ApplicationRecord
# 未分班 # 未分班
scope :ungroup_students, -> { where(course_group_id: 0, role: 4) } scope :ungroup_students, -> { where(course_group_id: 0, role: 4) }
after_destroy :delete_works # after_destroy :delete_works
after_create :work_operation # after_create :work_operation
def delete_works def delete_works
if self.role == "STUDENT" if self.role == "STUDENT"
course = self.course course = self.course
@ -52,13 +52,13 @@ class CourseMember < ApplicationRecord
def recover_works def recover_works
course = self.course course = self.course
student_works = StudentWork.where(user_id: self.user_id, homework_common_id: course.homework_commons) student_works = StudentWork.joins(:homework_common).where(user_id: self.user_id, homework_commons: {course_id: course.id})
student_works.update_all(is_delete: 0) student_works.update_all(is_delete: 0)
exercise_users = ExerciseUser.where(user_id: self.user_id, exercise_id: course.exercises) exercise_users = ExerciseUser.joins(:exercise).where(user_id: self.user_id, exercises: {course_id: course.id})
exercise_users.update_all(is_delete: 0) exercise_users.update_all(is_delete: 0)
poll_users = PollUser.where(user_id: self.user_id, poll_id: course.polls) poll_users = PollUser.joins(:poll).where(user_id: self.user_id, polls: {course_id: course.id})
poll_users.update_all(is_delete: 0) poll_users.update_all(is_delete: 0)
graduation_works = course.graduation_works.where(user_id: self.user_id) graduation_works = course.graduation_works.where(user_id: self.user_id)

@ -5,7 +5,7 @@ class Discuss < ApplicationRecord
belongs_to :parent, class_name: 'Discuss', foreign_key: :parent_id, optional: true belongs_to :parent, class_name: 'Discuss', foreign_key: :parent_id, optional: true
has_many :children, -> { reorder(created_at: :asc) }, class_name: 'Discuss', foreign_key: :parent_id has_many :children, -> { reorder(created_at: :asc) }, class_name: 'Discuss', foreign_key: :parent_id
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
has_many :tidings, as: :container, dependent: :destroy has_many :tidings, as: :container, dependent: :destroy
has_one :praise_tread_cache, as: :object, dependent: :destroy has_one :praise_tread_cache, as: :object, dependent: :destroy

@ -7,6 +7,8 @@ class Exercise < ApplicationRecord
has_many :score_exercise_users, -> { where("is_delete = 0 and commit_status != 0").order("score desc") }, class_name: "ExerciseUser" has_many :score_exercise_users, -> { where("is_delete = 0 and commit_status != 0").order("score desc") }, class_name: "ExerciseUser"
has_many :exercise_questions, :dependent => :delete_all has_many :exercise_questions, :dependent => :delete_all
has_many :exercise_group_settings, :dependent => :delete_all has_many :exercise_group_settings, :dependent => :delete_all
has_many :published_settings, -> { exercise_group_published }, class_name: "ExerciseGroupSetting"
has_many :tidings, as: :container has_many :tidings, as: :container
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, :dependent => :delete_all has_many :course_acts, class_name: 'CourseActivity', as: :course_act, :dependent => :delete_all
@ -40,9 +42,9 @@ class Exercise < ApplicationRecord
if unified_setting #试卷统一设置 if unified_setting #试卷统一设置
exercise_users exercise_users
else 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)
course_user_ids = course.students.where(course_group_id:ex_group_setting_ids).pluck(:user_id) exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id").
exercise_users.where(user_id:course_user_ids) where(course_members: {course_group_id: ex_group_setting_ids})
end end
end end
@ -55,28 +57,47 @@ class Exercise < ApplicationRecord
end end
end end
#统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生 # 根据是否统一发布获取作业的作品列表
def all_exercise_users(user_id) def all_works
ex_users = self.exercise_users ex_users = unified_setting ? exercise_users :
group_ids = common_published_ids(user_id) exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id").
if group_ids.present? where(course_members: {course_group_id: published_settings.pluck(:course_group_id)})
ex_users = ex_users.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id)) end
# 分班权限的老师可见的作品列表
def all_exercise_users user_id
# member = course.course_member(user_id)
teacher_course_groups = course.teacher_course_groups.get_user_groups(user_id)
ex_users = self.all_works
# 有分班权限的统计管理的分班且已发布的学生情况
if teacher_course_groups.exists?
group_ids = teacher_course_groups.pluck(:course_group_id)
ex_users = ex_users.joins("join course_members on exercise_users.user_id=course_members.user_id").
where(course_members: {course_group_id: group_ids})
end end
ex_users ex_users
end end
# #统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生
# def all_exercise_users(user_id)
# ex_users = exercise_users
# group_ids = common_published_ids(user_id)
# if group_ids.present?
# ex_users = ex_users.joins("join course_members on exercise_users.user_id=course_members.user_id").
# where(course_members: {course_group_id: group_ids})
# end
# ex_users
# end
#当前用户已发布的班级id和试卷分组已发布的班级id的交集 #当前用户已发布的班级id和试卷分组已发布的班级id的交集
def common_published_ids(user_id) def common_published_ids(user_id)
current_user_groups = course.teacher_course_ids(user_id) current_user_groups = course.teacher_course_ids(user_id)
if unified_setting if unified_setting
if course.none_group_count > 0 #有未分班的,则发布到未发布分班 # un_group_ids = (course.none_group_count > 0) ? [0] : []
un_group_ids = [0] # published_group_ids = (current_user_groups + un_group_ids).uniq #统一设置时为当前用户的分班id及未分班
else published_group_ids = current_user_groups
un_group_ids = []
end
published_group_ids = (current_user_groups + un_group_ids).uniq #统一设置时为当前用户的分班id及未分班
else else
ex_group_setting = exercise_group_settings.pluck("course_group_id").uniq ex_group_setting = exercise_group_settings.select(:course_group_id).pluck("course_group_id").uniq
common_all_ids = ex_group_setting & current_user_groups #当前用户有权限的已发布的分班id #非统一设置时为当前用户有权限的且已发布分班的id common_all_ids = ex_group_setting & current_user_groups #当前用户有权限的已发布的分班id #非统一设置时为当前用户有权限的且已发布分班的id
published_group_ids = common_all_ids.uniq published_group_ids = common_all_ids.uniq
end end
@ -89,19 +110,13 @@ class Exercise < ApplicationRecord
ex_group_settings = exercise_group_settings.pluck(:course_group_id) ex_group_settings = exercise_group_settings.pluck(:course_group_id)
member = course.course_members.course_find_by_ids("user_id",user_id) member = course.course_members.course_find_by_ids("user_id",user_id)
member_group_id = member.pluck(:course_group_id).uniq member_group_id = member.pluck(:course_group_id).uniq
if (member_group_id & ex_group_settings).size > 0 || user_identity < Course::STUDENT ((member_group_id & ex_group_settings).size > 0 || user_identity < Course::STUDENT) ? true : false
true
else
false
end
end end
#判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间 #判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间
def get_exercise_status(user_id) def get_exercise_status(user)
user_group = course.course_members.find_by(user_id: user_id) if user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态
if user_group.present? && user_group.role == "STUDENT" #当为学生的时候,需根据分班来判断试卷状态
ex_time = get_exercise_times(user_id,false) ex_time = get_exercise_times(user_id,false)
pb_time = ex_time[:publish_time] pb_time = ex_time[:publish_time]
ed_time = ex_time[:end_time] ed_time = ex_time[:end_time]
@ -123,18 +138,17 @@ class Exercise < ApplicationRecord
if unified_setting || teacher #当试卷为统一设置或当前为老师的时候 if unified_setting || teacher #当试卷为统一设置或当前为老师的时候
pb_time = publish_time pb_time = publish_time
en_time = end_time en_time = end_time
if (exercise_status != 3) && en_time.present? && (en_time <= Time.now)
if en_time.present? && (en_time <= Time.now) && (exercise_status != 3)
update_column("exercise_status",3) update_column("exercise_status",3)
end end
else else
ex_group_setting = exercise_group_settings ex_group_setting = exercise_group_settings
user_group = course.students.course_find_by_ids("user_id",user_id) user_group = course.students.where(user_id:user_id).select(:course_group_id)
if user_group.present? if user_group.exists?
user_group_id = user_group.first.course_group_id user_group_id = user_group.first&.course_group_id
user_ex_group_setting = ex_group_setting.find_in_exercise_group("course_group_id",user_group_id) user_ex_group_setting = ex_group_setting.where(course_group_id:user_group_id).select(:publish_time,:end_time)
pb_time = user_ex_group_setting.present? ? user_ex_group_setting.first.publish_time : nil pb_time = user_ex_group_setting.first&.publish_time
en_time = user_ex_group_setting.present? ? user_ex_group_setting.first.end_time : nil en_time = user_ex_group_setting.first&.end_time
else else
pb_time = nil pb_time = nil
en_time = nil en_time = nil
@ -149,13 +163,13 @@ class Exercise < ApplicationRecord
#判断当前用户的答题状态 #判断当前用户的答题状态
def check_user_answer_status(user) def check_user_answer_status(user)
ex_answer_user = exercise_users.find_by(user_id: user.id) ex_answer_user = exercise_users.where(user_id: user.id).select(:start_at,:end_at,:commit_status)
user_ex_status = get_exercise_status(user.id) user_ex_status = get_exercise_status(user)
user_status = 2 user_status = 2
if ex_answer_user.present? && (ex_answer_user.start_at.present? || ex_answer_user.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 if ex_answer_user.exists? && (ex_answer_user.first&.start_at.present? || ex_answer_user.first&.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的
user_status = ex_answer_user.commit_status user_status = ex_answer_user.first.commit_status
end end
if ex_answer_user.present? && ex_answer_user.start_at.blank? && user_ex_status == 3 if ex_answer_user.exists? && ex_answer_user.first&.start_at.blank? && user_ex_status == 3
user_status = 4 user_status = 4
end end

@ -20,9 +20,9 @@ class Game < ApplicationRecord
#全部关卡数 #全部关卡数
scope :ch_games, lambda { |challenge_id| where(challenge_id:challenge_id) } 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) } scope :user_games, lambda { |user_id,challenge_id| where("user_id = ? AND challenge_id = ?",user_id,challenge_id) }

@ -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 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 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 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 else
%Q{ %Q{
SELECT COUNT(distinct graduation_work_id) cnt FROM graduation_works gw 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 JOIN graduation_work_scores gwc ON gw.id = gwc.graduation_work_id
WHERE reviewer_role IN(1,2) AND gwc.graduation_task_id = #{self.id} WHERE reviewer_role IN(1,2) AND gw.graduation_task_id = #{self.id}
} }
end end
GraduationWorkScore.find_by_sql(sql).first.try(:cnt).to_i GraduationWorkScore.find_by_sql(sql).first.try(:cnt).to_i
@ -127,7 +127,7 @@ class GraduationTask < ApplicationRecord
sql = %Q{ sql = %Q{
SELECT count(*) cnt FROM graduation_works gw WHERE work_status = 0 AND gw.graduation_task_id = #{self.id} AND gw.user_id 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 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) GraduationWork.find_by_sql(sql).first.try(:cnt)
@ -144,7 +144,7 @@ class GraduationTask < ApplicationRecord
sql = %Q{ sql = %Q{
SELECT count(*) cnt FROM graduation_works gw WHERE work_status = 1 AND gw.graduation_task_id = #{self.id} AND gw.user_id 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 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) GraduationWork.find_by_sql(sql).first.try(:cnt)
@ -160,7 +160,7 @@ class GraduationTask < ApplicationRecord
sql = %Q{ sql = %Q{
SELECT count(*) cnt FROM graduation_works gw WHERE work_status = 2 AND gw.graduation_task_id = #{self.id} AND gw.user_id 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 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) GraduationWork.find_by_sql(sql).first.try(:cnt)

@ -79,7 +79,8 @@ class HomeworkCommon < ApplicationRecord
# 根据是否统一发布获取作业的作品列表 # 根据是否统一发布获取作业的作品列表
def all_works def all_works
student_works = self.unified_setting ? self.student_works : student_works = self.unified_setting ? self.student_works :
self.student_works.joins("join course_members on student_works.user_id=course_members.user_id").where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)}) self.student_works.joins("join course_members on student_works.user_id=course_members.user_id").
where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)})
end end
# 分班权限的老师可见的作品列表 # 分班权限的老师可见的作品列表
@ -88,7 +89,7 @@ class HomeworkCommon < ApplicationRecord
teacher_course_groups = member.try(:teacher_course_groups) teacher_course_groups = member.try(:teacher_course_groups)
all_student_works = self.all_works all_student_works = self.all_works
# 有分班权限的统计管理的分班且已发布的学生情况 # 有分班权限的统计管理的分班且已发布的学生情况
if member.present? && teacher_course_groups.size > 0 if member.present? && teacher_course_groups.exists?
group_ids = teacher_course_groups.pluck(:course_group_id) group_ids = teacher_course_groups.pluck(:course_group_id)
all_student_works = all_student_works.joins("join course_members on student_works.user_id=course_members.user_id"). all_student_works = all_student_works.joins("join course_members on student_works.user_id=course_members.user_id").
where(course_members: {course_group_id: group_ids}) where(course_members: {course_group_id: group_ids})
@ -196,7 +197,7 @@ class HomeworkCommon < ApplicationRecord
JOIN student_works_scores sws on sws.student_work_id = sw.id WHERE 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} 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 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(",")})
) )
) )
} }

@ -56,7 +56,7 @@ class Myshixun < ApplicationRecord
# status:0 可以测评的; 1 正在测评的; 2评测通过的 3未开启的 # status:0 可以测评的; 1 正在测评的; 2评测通过的 3未开启的
# 如果都完成,则当前任务为最后一个任务 # 如果都完成,则当前任务为最后一个任务
def current_task games def current_task games
current_game = games.select{|game| game.status == 1 || game.status == 0}.first current_game = games.select{|game| game.status == 1 || game.status == 0}.last
if current_game.blank? if current_game.blank?
current_game = games.last current_game = games.last
end end

@ -8,6 +8,7 @@ class Poll < ApplicationRecord
has_many :poll_users, -> { where("is_delete != 1") }, :dependent => :delete_all has_many :poll_users, -> { where("is_delete != 1") }, :dependent => :delete_all
has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 has_many :users, :through => :poll_users #该文件被哪些用户提交答案过
has_many :poll_group_settings, :dependent => :delete_all 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 :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :delete_all
has_many :tidings, as: :container, dependent: :delete_all has_many :tidings, as: :container, dependent: :delete_all
@ -44,22 +45,43 @@ class Poll < ApplicationRecord
if unified_setting #试卷统一设置 if unified_setting #试卷统一设置
poll_users poll_users
else else
ex_group_setting_ids = poll_group_settings.poll_group_published.pluck(:course_group_id) ex_group_setting_ids = published_settings.pluck(:course_group_id)
course_user_ids = course.students.where(course_group_id:ex_group_setting_ids).pluck(:user_id) poll_users.joins("join course_members on poll_users.user_id=course_members.user_id").
poll_users.where(user_id:course_user_ids) where(course_members: {course_group_id: ex_group_setting_ids})
end end
end end
# 统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生 # 根据是否统一发布获取作业的作品列表
def all_poll_users(user_id) def all_works
poll_all_users = poll_users po_users = unified_setting ? poll_users :
group_ids = poll_published_ids(user_id) poll_users.joins("join course_members on poll_users.user_id=course_members.user_id").
if group_ids.present? where(course_members: {course_group_id: published_settings.pluck(:course_group_id)})
poll_all_users = poll_all_users.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id).uniq) end
# 分班权限的老师可见的作品列表
def all_poll_users user_id
# member = course.course_member(user_id)
teacher_course_groups = course.teacher_course_groups.get_user_groups(user_id)
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 end
poll_all_users poll_users
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)
# end
# poll_all_users
# end
#当前用户已发布的班级id和试卷分组已发布的班级id的交集 #当前用户已发布的班级id和试卷分组已发布的班级id的交集
def poll_published_ids(user_id) def poll_published_ids(user_id)
current_user_groups = course.teacher_course_ids(user_id) current_user_groups = course.teacher_course_ids(user_id)
@ -71,20 +93,14 @@ class Poll < ApplicationRecord
end end
(current_user_groups + un_group_ids).uniq #统一设置时为当前用户的分班id (current_user_groups + un_group_ids).uniq #统一设置时为当前用户的分班id
else else
ex_group_setting = poll_group_settings.pluck("course_group_id").uniq ex_group_setting = poll_group_settings.select(:course_group_id).pluck("course_group_id").uniq
ex_group_setting & current_user_groups #当前用户有权限的已发布的分班id #非统一设置时为当前用户有权限的且已发布分班的id ex_group_setting & current_user_groups #当前用户有权限的已发布的分班id #非统一设置时为当前用户有权限的且已发布分班的id
end end
end end
def get_poll_status(user_id) def get_poll_status(user)
user_group = course.course_members.find_by(user_id: user_id, is_active: 1) if user.student_of_course?(course)
if user_group.present? ex_time = get_poll_times(user_id,false)
if user_group.role == "STUDENT" #为学生
is_teacher = false
else
is_teacher = true
end
ex_time = get_poll_times(user_id,is_teacher)
pb_time = ex_time[:publish_time] pb_time = ex_time[:publish_time]
ed_time = ex_time[:end_time] ed_time = ex_time[:end_time]
if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now
@ -102,30 +118,20 @@ class Poll < ApplicationRecord
#获取问卷的发布时间和截止时间。teacher 为boolean,当为true时表示的是当前为老师 #获取问卷的发布时间和截止时间。teacher 为boolean,当为true时表示的是当前为老师
def get_poll_times(user_id,teacher) def get_poll_times(user_id,teacher)
if unified_setting if unified_setting || teacher
pb_time = publish_time pb_time = publish_time
en_time = end_time en_time = end_time
else else
poll_group_setting = poll_group_settings poll_group_setting = poll_group_settings
if teacher #当前为老师,为设置组的最大值和最小值 user_group = course.course_members.where(user_id: user_id).select(:course_group_id)
user_group = course.teacher_course_groups.get_user_groups(user_id) if user_group.exists?
user_group_ids = user_group.present? ? user_group.pluck(:course_group_id) : course.course_groups.pluck(:id) user_group_id = user_group.first&.course_group_id
user_poll_group_settings = poll_group_setting.find_in_poll_group("course_group_id",user_group_ids) user_p_group_setting = poll_group_setting.where(course_group_id: user_group_id).select(:publish_time,:end_time)
pb_time_min = user_poll_group_settings.publish_time_present.map(&:publish_time) pb_time = user_p_group_setting.first&.publish_time
en_time_max = user_poll_group_settings.end_time_present.map(&:end_time) en_time = user_p_group_setting.first&.end_time
pb_time = pb_time_min.size > 0 ? pb_time_min.min : nil
en_time = en_time_max.size > 0 ? en_time_max.max : nil
else else
user_group = course.students.find_by(user_id: user_id) pb_time = nil
if user_group.present? en_time = nil
user_group_id = user_group.course_group_id
user_p_group_setting = poll_group_setting.find_by(course_group_id: user_group_id)
pb_time = user_p_group_setting.present? ? user_p_group_setting.publish_time : nil
en_time = user_p_group_setting.present? ? user_p_group_setting.end_time : nil
else
pb_time = nil
en_time = nil
end
end end
end end
{ {
@ -136,19 +142,11 @@ class Poll < ApplicationRecord
#判断当前用户的答题状态 #判断当前用户的答题状态
def check_user_votes_status(user) def check_user_votes_status(user)
poll_answer_user = poll_users.find_by(user_id: user.id) poll_answer_user = poll_users.where(user_id: user.id).select(:start_at,:end_at,:commit_status)
# user_poll_status = get_poll_status(user.id)
user_status = 2 user_status = 2
if poll_answer_user.exists? && (poll_answer_user.first&.start_at.present? || poll_answer_user.first&.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的
if poll_answer_user.present? && (poll_answer_user.start_at.present? || poll_answer_user.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 user_status = poll_answer_user.first.commit_status
user_status = poll_answer_user.commit_status
end end
#
# if poll_answer_user.present? && poll_answer_user.start_at.blank? && user_poll_status == 3
# # user_status = 4
# user_status = 2 #问卷用户存在,且未开始答题,且问卷已截止时,返回未提交标示
# end
user_status user_status
end end

@ -2,4 +2,24 @@ class Repertoire < ApplicationRecord
has_many :sub_repertoires, ->{order(updated_at: :desc)}, :dependent => :destroy has_many :sub_repertoires, ->{order(updated_at: :desc)}, :dependent => :destroy
has_many :tag_repertoires, through: :sub_repertoires has_many :tag_repertoires, through: :sub_repertoires
has_many :user_interests, dependent: :delete_all
after_create_commit :reset_cache_data
after_update_commit :reset_cache_data
def self.cache_data
Rails.cache.fetch(data_cache_key, expires_in: 1.days) do
Repertoire.select(:id, :name).order(:created_at).as_json
end
end
def self.data_cache_key
'repertoire/cache_data'
end
private
def reset_cache_data
Rails.cache.delete(self.class.data_cache_key)
end
end end

@ -115,6 +115,10 @@ class User < ApplicationRecord
has_many :attendances has_many :attendances
# 兴趣
has_many :user_interests, dependent: :delete_all
has_many :interests, through: :user_interests, source: :repertoire
# Groups and active users # Groups and active users
scope :active, lambda { where(status: STATUS_ACTIVE) } scope :active, lambda { where(status: STATUS_ACTIVE) }

@ -4,7 +4,7 @@ class UserExtension < ApplicationRecord
belongs_to :user belongs_to :user
belongs_to :school belongs_to :school
belongs_to :department belongs_to :department, optional: true
def identity_text def identity_text
I18n.t("user.identity.#{identity}") I18n.t("user.identity.#{identity}")

@ -0,0 +1,4 @@
class UserInterest < ApplicationRecord
belongs_to :user
belongs_to :repertoire
end

@ -3,7 +3,6 @@ class BatchExportShixunReportService
MAX_BATCH_LIMIT = 20 MAX_BATCH_LIMIT = 20
# attr_reader :homework, :student_work_ids
attr_reader :homework, :all_student_works attr_reader :homework, :all_student_works
@ -15,7 +14,7 @@ class BatchExportShixunReportService
end end
def filename def filename
@_filename ||= "#{Time.now.strftime('%Y%m%d%H%M%S')}-#{homework.name}.zip" @_filename ||= "#{homework.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
end end
def zip def zip
@ -37,7 +36,7 @@ class BatchExportShixunReportService
rescue => ex rescue => ex
Rails.logger.error(ex.message) Rails.logger.error(ex.message)
zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write('文件重复') } zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write("文件重复:#{export.filename}") }
next next
end end
end end
@ -45,15 +44,4 @@ class BatchExportShixunReportService
end end
end end
# private
#
# def validate!
# if student_work_ids.size.zero?
# raise Error, '请选择学生实训作业'
# end
#
# if student_work_ids.size > MAX_BATCH_LIMIT
# raise Error, '导出实训报告太多,请分批导出'
# end
# end
end end

@ -10,7 +10,7 @@ class ExportExercisesService
end end
def filename def filename
exercise_export_name = "#{exercise.user.real_name}_#{exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M')}" exercise_export_name = "#{exercise.user.real_name}_#{exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
"#{exercise_export_name.strip}.zip" "#{exercise_export_name.strip}.zip"
end end

@ -10,7 +10,7 @@ class ExportShixunReportService
end end
def filename def filename
@_filename ||= "#{homework.name}-#{work.user.user_extension&.student_id}-#{work.user.real_name}.pdf".gsub(' ', '-').gsub('/', '_') @_filename ||= "#{homework.name}-#{work.user&.student_id}-#{work.user.real_name}.pdf".gsub(' ', '-').gsub('/', '_')
end end
def prepare_binding def prepare_binding

@ -316,7 +316,7 @@ class HomeworksService
if work.work_status == 0 if work.work_status == 0
is_complete = myshixun_endtime && (myshixun_endtime < setting_time.end_time) is_complete = myshixun_endtime && (myshixun_endtime < setting_time.end_time)
if is_complete || (!homework.allow_late && myshixun.created_at < setting_time.end_time) if is_complete || (myshixun.created_at < setting_time.end_time && (!homework.allow_late || setting_time.end_time >= Time.now))
work.work_status = 1 work.work_status = 1
elsif homework.allow_late && myshixun.created_at < homework.late_time elsif homework.allow_late && myshixun.created_at < homework.late_time
work.work_status = 2 work.work_status = 2

@ -47,7 +47,7 @@ class ShixunsService
if current_user.admin? if current_user.admin?
disscuss_count = Discuss.where(dis_id: dis_id, dis_type: dis_type, root_id: nil).count disscuss_count = Discuss.where(dis_id: dis_id, dis_type: dis_type, root_id: nil).count
discusses = Discuss.where(dis_id: dis_id, dis_type: dis_type, root_id: nil) discusses = Discuss.where(dis_id: dis_id, dis_type: dis_type, root_id: nil)
.includes(:user, :praise_tread).limit(LIMIT).offset(offset) .includes(:user, :praise_treads).limit(LIMIT).offset(offset)
else else
disscusses = Discuss.where( disscusses = Discuss.where(
'dis_id = :dis_id and dis_type = :dis_type and root_id is null and (hidden = :hidden or user_id = :user_id)', 'dis_id = :dis_id and dis_type = :dis_type and root_id is null and (hidden = :hidden or user_id = :user_id)',
@ -55,7 +55,7 @@ class ShixunsService
) )
disscuss_count = disscusses.count disscuss_count = disscusses.count
discusses = disscusses.includes(:user, :praise_tread).limit(LIMIT).offset(offset) discusses = disscusses.includes(:user, :praise_treads).limit(LIMIT).offset(offset)
end end
base_data discusses, dis, current_user base_data discusses, dis, current_user
@ -81,7 +81,7 @@ class ShixunsService
offset = page * LIMIT offset = page * LIMIT
find_status = true if position find_status = true if position
end end
discusses = Discuss.limit(LIMIT).where(:dis_id => dis_id, :dis_type => dis_type, :root_id => nil).includes(:user, :praise_tread).offset(offset) discusses = Discuss.limit(LIMIT).where(:dis_id => dis_id, :dis_type => dis_type, :root_id => nil).includes(:user, :praise_treads).offset(offset)
base_data discusses, dis, current_user base_data discusses, dis, current_user
Myshixun.find(params[:myshixun_id]).update_attribute(:onclick_time, Time.now) Myshixun.find(params[:myshixun_id]).update_attribute(:onclick_time, Time.now)
@ -109,8 +109,8 @@ class ShixunsService
if discusses.present? if discusses.present?
discusses.each do |d| discusses.each do |d|
# 总点赞数 # 总点赞数
praise_count = d.praise_tread.where(:praise_or_tread => 1).count praise_count = d.praises_count
user_praise= d.praise_tread.select{|pt| pt.user_id == current_user.id}.length > 0 ? true : false user_praise= d.praise_treads.select{|pt| pt.user_id == current_user.id}.length > 0 ? true : false
manager = current_user.manager_of_shixun?(dis, current_user) manager = current_user.manager_of_shixun?(dis, current_user)
game_url = game_url =
if manager if manager

@ -0,0 +1,52 @@
class Users::ApplyAuthenticationService < ApplicationService
Error = Class.new(StandardError)
attr_reader :user, :params
def initialize(user, params)
@user = user
@params = params
end
def call
Users::ApplyAuthenticationForm.new(params).validate!
raise Error, '您已经申请过实名认证了' if ApplyUserAuthentication.real_name_auth.processing.exists?(user_id: user.id)
user.lastname = params[:name].to_s.strip
user.firstname = ''
user.ID_number = params[:id_number].to_s.strip.presence
ActiveRecord::Base.transaction do
user.authentication = false
user.save!
user.apply_user_authentication.create!(auth_type: 1, status: 0)
move_image_file! unless params[:upload_image].to_s == 'false'
sms_notify_admin
end
user
end
private
def move_image_file!
image_url = ApplicationController.helpers.disk_real_name_auth_filename(user.id)
temp_image_url = image_url + 'temp'
FileUtils.mv(temp_image_url, image_url, force: true) if File.exist?(temp_image_url)
rescue RuntimeError => ex
Util.logger_error(ex)
raise Error, '申请失败'
ensure
File.delete(temp_image_url) if File.exist?(temp_image_url)
end
def sms_notify_admin
Educoder::Sms.notify_admin(send_type: 'apply_auth')
rescue => ex
Util.logger_error(ex)
end
end

@ -0,0 +1,62 @@
class Users::ApplyProfessionalAuthService < ApplicationService
Error = Class.new(StandardError)
attr_reader :user, :params
def initialize(user, params)
@user = user
@params = params
end
def call
Users::ApplyProfessionalAuthForm.new(params).validate!
raise Error, '您已经申请过职业认证了' if ApplyUserAuthentication.professional_auth.processing.exists?(user_id: user.id)
user.professional_certification = false
extension = user.user_extension
extension.school_id = params[:school_id]
extension.department_id = params[:department_id]
extension.identity = params[:identity]
extra = params[:extra].to_s.strip.presence
if extension.identity.to_s == 'student'
extension.technical_title = nil
extension.student_id = extra
else
extension.technical_title = extra
extension.student_id = nil
end
ActiveRecord::Base.transaction do
user.save!
extension.save!
user.apply_user_authentication.create!(auth_type: 2, status: 0)
move_image_file! unless params[:upload_image].to_s == 'false'
sms_notify_admin
end
end
private
def move_image_file!
image_url = ApplicationController.helpers.disk_professional_auth_filename(user.id)
temp_image_url = image_url + 'temp'
FileUtils.mv(temp_image_url, image_url, force: true) if File.exist?(temp_image_url)
rescue RuntimeError => ex
Util.logger_error(ex)
raise Error, '申请失败'
ensure
File.delete(temp_image_url) if File.exist?(temp_image_url)
end
def sms_notify_admin
Educoder::Sms.notify_admin(send_type: 'apply_pro_certification')
rescue => ex
Util.logger_error(ex)
end
end

@ -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

@ -17,14 +17,5 @@ json.teacher_list do
end end
end end
json.teacher_list_size @teacher_list_size json.teacher_list_size @teacher_list_size
json.application_list do json.apply_size @applications_size
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.is_admin @is_admin

@ -14,8 +14,8 @@ json.game_url discuss.game_url(container, current_user)
if discuss.parent_id if discuss.parent_id
json.can_delete discuss.can_deleted?(current_user) json.can_delete discuss.can_deleted?(current_user)
else else
json.praise_count discuss.praise_tread.where(praise_or_tread: 1).count json.praise_count discuss.praises_count
json.user_praise discuss.praise_tread.select{|pt| pt.user_id == current_user.id}.length > 0 ? true : false json.user_praise discuss.praise_treads.select{|pt| pt.user_id == current_user.id}.length > 0
end end

@ -36,7 +36,7 @@ elsif student_status == 1
json.question_status question_status json.question_status question_status
end end
exercise_status = exercise.get_exercise_status(ex_answerer.id) exercise_status = exercise.get_exercise_status(ex_answerer)
#当前为老师,或为学生,但在试卷截止后且答案选择公开的 #当前为老师,或为学生,但在试卷截止后且答案选择公开的
if is_teacher_or == 1 || (exercise_status == 3 && exercise.answer_open) if is_teacher_or == 1 || (exercise_status == 3 && exercise.answer_open)

@ -1,32 +1,13 @@
json.exercises_counts do
json.exercises_total_counts @exercises_count #全部试卷数
json.exercises_all_counts @exercises_select_count #选择后的全部试卷数
json.exercises_unpublish_counts @exercises_unpublish_counts #未发布试卷数
json.exercises_published_counts @exercises_published_counts #已发布试卷数
json.exercises_ended_counts @exercises_ended_counts #已截止试卷数
json.left_banner_id @left_banner_id
json.left_banner_name @left_banner_name
end
json.course_types do
json.course_status @course.is_end ? 1 : 0 #课堂的当前是否结束如结束则为1否则为0
json.course_end_time @course.end_date #课堂的截止时间
json.course_is_public @course.is_public #判断课堂是否为公开,只有公开课才有设为公开的按钮
json.user_permission @is_teacher_or # 当前用户存在且为课堂教师/管理员/超级管理员时为1 课堂成员为2否则为0
end
if @exercises_count > 0 if @exercises_count > 0
json.exercises do json.exercises do
json.array! @exercises do |exercise| json.array! @exercises do |exercise|
ex_index = exercise_index_show(exercise,@course,@is_teacher_or,@current_user_)
json.extract! exercise, :id, :exercise_name,:is_public,:created_at json.extract! exercise, :id, :exercise_name,:is_public,:created_at
if @is_teacher_or == 2 if @is_teacher_or == 2
second_left = get_exercise_left_time(exercise,@current_user_) second_left = get_exercise_left_time(exercise,@current_user_)
json.time second_left.present? ? (second_left / 60) : nil json.time second_left.present? ? (second_left / 60) : nil
end end
ex_index = exercise_index_show(exercise,@course,@is_teacher_or,@current_user_)
json.exercise_status ex_index[:ex_status] json.exercise_status ex_index[:ex_status]
json.lock_status ex_index[:lock_icon] json.lock_status ex_index[:lock_icon]
json.publish_time ex_index[:publish_time] # 试卷的发布时间 json.publish_time ex_index[:publish_time] # 试卷的发布时间
@ -43,3 +24,22 @@ else
json.exercises [] json.exercises []
end end
json.course_types do
json.course_status @course.is_end ? 1 : 0 #课堂的当前是否结束如结束则为1否则为0
json.course_end_time @course.end_date #课堂的截止时间
json.course_is_public @course.is_public #判断课堂是否为公开,只有公开课才有设为公开的按钮
json.user_permission @is_teacher_or # 当前用户存在且为课堂教师/管理员/超级管理员时为1 课堂成员为2否则为0
end
json.exercises_counts do
json.exercises_total_counts @exercises_count #全部试卷数
json.exercises_all_counts @exercises_select_count #选择后的全部试卷数
json.exercises_unpublish_counts @exercises_unpublish_counts #未发布试卷数
json.exercises_published_counts @exercises_published_counts #已发布试卷数
json.exercises_ended_counts @exercises_ended_counts #已截止试卷数
json.left_banner_id @left_banner_id
json.left_banner_name @left_banner_name
end

@ -1,5 +1,6 @@
index = 0 index = 0
json.status 3 json.status 3
# st: 0 实践题 1 选择题
json.message do json.message do
json.array! @challenge_answers do |answer| json.array! @challenge_answers do |answer|
index += 1 index += 1
@ -13,3 +14,5 @@ json.message do
end end
end end

@ -0,0 +1,6 @@
json.choose_answers do
json.array! @challenge_chooses do |choose|
json.position choose.position
json.answer choose.answer.blank? ? choose.standard_answer : choose.answer
end
end

@ -0,0 +1,6 @@
json.choose_answers do
json.array! @challenge_chooses do |choose|
json.position choose.position
json.answer choose.answer.blank? ? choose.standard_answer : choose.answer
end
end

@ -1,5 +1,5 @@
wb = xlsx_package.workbook wb = xlsx_package.workbook
wb.use_autowidth = false # wb.use_autowidth = false
wb.use_shared_strings = true wb.use_shared_strings = true
wb.styles do |s| wb.styles do |s|
@ -9,13 +9,13 @@ wb.styles do |s|
bg_cc = s.add_style :bg_color=> "CCC1DA",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } bg_cc = s.add_style :bg_color=> "CCC1DA",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center }
bg_ff = s.add_style :bg_color=> "FFC000",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } bg_ff = s.add_style :bg_color=> "FFC000",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center }
bg_bb = s.add_style :bg_color=> "9BBB59",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } bg_bb = s.add_style :bg_color=> "9BBB59",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center }
bg_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } bg_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center }
wb.add_worksheet(:name => "毕设选题情况汇总") do |sheet| wb.add_worksheet(:name => "毕设选题情况汇总") do |sheet|
sheet.sheet_view.show_grid_lines = false sheet.sheet_view.show_grid_lines = false
sheet_title = table_columns sheet_title = table_columns
sheet_title_c = sheet_title.count sheet_title_c = sheet_title.count
sheet.add_row sheet_title, :style => bg_cell sheet.add_row sheet_title,:height => 32, :style => bg_cell
sheet["J1:L1"].each { |c| c.style = bg_db } sheet["J1:L1"].each { |c| c.style = bg_db }
sheet["M1:O1"].each { |c| c.style = bg_cc } sheet["M1:O1"].each { |c| c.style = bg_cc }
sheet["P1:Q1"].each { |c| c.style = bg_d2 } sheet["P1:Q1"].each { |c| c.style = bg_d2 }
@ -23,10 +23,10 @@ wb.styles do |s|
sheet["U1:W1"].each { |c| c.style = bg_bb } sheet["U1:W1"].each { |c| c.style = bg_bb }
if topic_users.count > 0 if topic_users.count > 0
topic_users.each do |user| topic_users.each do |user|
sheet.add_row user, :style => sz_all sheet.add_row user,:height => 18, :style => sz_all
end #each_widh_index end #each_widh_index
else else
sheet.add_row ["--"]*sheet_title_c sheet.add_row ["--"]*sheet_title_c,:height => 18
end end
sheet.column_widths *([15]*sheet.column_info.count) sheet.column_widths *([15]*sheet.column_info.count)

@ -7,11 +7,14 @@ json.group_list do
end end
end end
# 未分班展示情况放在最后 # 未分班展示情况放在最后
if @course_groups.count > 0 && @course_groups.count < @limit.to_i if @course_groups.count < @limit.to_i
json.ungroup_list do ungroup_work_count = homework_ungroup_works_count(@homework, @ungroup_user_ids)
json.id 0 if ungroup_work_count > 0
json.name "未分班" json.ungroup_list do
json.work_count homework_ungroup_works_count @homework, @ungroup_user_ids json.id 0
json.last_review_time ungroup_last_review_time @homework json.name "未分班"
json.work_count ungroup_work_count
json.last_review_time ungroup_last_review_time @homework
end
end end
end end

@ -25,14 +25,16 @@ json.homeworks @homework_commons.each do |homework|
if @user_course_identity < Course::STUDENT if @user_course_identity < Course::STUDENT
if homework.homework_type == "practice" if homework.homework_type == "practice"
json.shixun_identifier homework.shixuns.first.try(:identifier) json.shixun_identifier homework.shixuns.take.try(:identifier)
end end
elsif @user_course_identity == Course::STUDENT elsif @user_course_identity == Course::STUDENT
if homework.homework_type == "practice" if homework.homework_type == "practice"
shixun = homework.shixuns.take
# json.challenge_count homework.shixuns.first.try(:challenges_count).to_i # json.challenge_count homework.shixuns.first.try(:challenges_count).to_i
current_myshixun = homework.user_work(@user.id).try(:myshixun) current_myshixun = homework.user_work(@user.id).try(:myshixun)
myshixun = current_myshixun ? current_myshixun : shixun.myshixuns.find_by(user_id: @user.id)
# json.game_count current_myshixun ? current_myshixun.exec_count : 0 # json.game_count current_myshixun ? current_myshixun.exec_count : 0
json.task_operation task_operation_url(current_myshixun, homework.shixuns.first) json.task_operation task_operation_url(myshixun, shixun)
else else
work = homework.user_work(@user.id) work = homework.user_work(@user.id)
json.work_id work.try(:id) json.work_id work.try(:id)

@ -13,6 +13,7 @@ json.ta_mode @homework_detail_manual.ta_mode
json.is_evaluation @is_evaluation ? @is_evaluation : false json.is_evaluation @is_evaluation ? @is_evaluation : false
json.work_public @homework.work_public json.work_public @homework.work_public
json.allow_late @homework.allow_late
if @user_course_identity < Course::STUDENT if @user_course_identity < Course::STUDENT

@ -7,91 +7,33 @@ wb.styles do |s|
wb.add_worksheet(:name => "统计结果") do |sheet| wb.add_worksheet(:name => "统计结果") do |sheet|
sheet.sheet_view.show_grid_lines = false sheet.sheet_view.show_grid_lines = false
poll_users_info = %w(序号) sub_commit = polls_user_commit[:sub_commit]
Rails.logger.info("#############_______________poll_questions.pluck(:question_title)_______####################{poll_questions.pluck(:question_title)}") poll_user_info = polls_user_commit[:poll_users_info]
user_commit = polls_user_commit[:user_commit]
poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} if sub_commit&.size > 0
Rails.logger.info("#############_______________poll_ques_titles_______####################{poll_ques_titles}") sub_commit.each do |sub|
poll_un_anony = poll.un_anonymous main_sub_title = sub[:sub_title]
if poll_un_anony #是否匿名默认为false main_sub_content = sub[:sub_user_votes]
user_info = %w(登陆名 真实姓名 邮箱 学号) sheet.add_row main_sub_title,:height =>15, :style => blue_cell
else if main_sub_content.present?
user_info = [] main_sub_content.each do |con|
end sheet.add_row con,:height =>15, :style => sz_all
poll_users_info = poll_users_info + user_info + poll_ques_titles end
poll_questions.each do |q|
if q.question_type != 3 #问题不为主观题
question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).size #该问题的有效填写量
sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组
sheet_answer_row = ["小计"] #选择题回答的答案人数,数组
sheet_answer_percent = ["比例"]
sheet_answer_useful = ["有效填写人次",question_vote_user]
q.poll_answers.each do |a| #问卷的答案选项
answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).size
answer_percent = number_to_percentage((answer_users_count.to_f / question_vote_user.to_f)*100,precision:1)
sheet_row.push(a.answer_text)
sheet_answer_row.push(answer_users_count)
sheet_answer_percent.push(answer_percent.to_s)
end end
sheet.add_row sheet_row, :height =>15,:style => blue_cell
sheet.add_row sheet_answer_row, :height =>15, :style => sz_all
sheet.add_row sheet_answer_percent, :height =>15, :style => sz_all
sheet.add_row sheet_answer_useful, :height =>15, :style => sz_all
#合并单元格但无法填充style
# sheet.merge_cells (Axlsx::cell_r(1,sheet.rows.last.row_index) + ':' + Axlsx::cell_r(sheet_row.count-1,sheet.rows.last.row_index))
# sheet.rows[sheet.rows.last.row_index].style = sz_all
sheet.add_row [] sheet.add_row []
else #主观题答案
main_show_row = ["第#{q.question_number}题",q.question_title]
sheet.add_row main_show_row,:height =>15, :style => blue_cell
q.poll_votes.each_with_index do |v,index| #主观题的答案
sheet.add_row [(index+1),v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all
end
sheet.add_row [], :style => sz_all
end end
end #each_with_index end
sheet.add_row poll_users_info, :height =>15, :style => blue_cell sheet.add_row poll_user_info, :height =>15, :style => blue_cell
poll_users.includes(user: :user_extension).each_with_index do |u,index|
u_user = u.user if user_commit&.size > 0
user_answer_array = [] user_commit.each do |com|
poll_questions.each do |q| sheet.add_row com, :height =>15,:style => sz_all
user_poll_votes = u_user.poll_votes.find_current_vote("poll_question_id",q.id)
if user_poll_votes.present?
user_poll_answer_ids = user_poll_votes.pluck(:poll_answer_id).reject(&:blank?)
user_poll_vote_texts = user_poll_votes.pluck(:vote_text).reject(&:blank?)
if user_poll_answer_ids.count > 0
answer_content = q.poll_answers.find_answer_by_custom("id",user_poll_answer_ids)
if user_poll_answer_ids.count >1
u_answer = answer_content.pluck(:answer_text).join(";")
else
u_answer = answer_content.first.answer_text
end
elsif user_poll_vote_texts.count > 0
if user_poll_vote_texts.count > 1
u_answer = user_poll_vote_texts.join(";")
else
u_answer = user_poll_vote_texts.first
end
else
u_answer = "--"
end
else
u_answer = "--"
end
user_answer_array.push(u_answer)
end
user_cell = [index+1]
if poll_un_anony
user_login = u_user.login
user_name = u_user.real_name.present? ? u_user.real_name : "--"
user_student_id = u_user.student_id.present? ? u_user.student_id : "--"
user_cell += [user_login,user_name, u_user.mail, user_student_id]
end end
all_user_cell = user_cell + user_answer_array
sheet.add_row all_user_cell, :height =>15,:style => sz_all
end end
sheet.column_widths *([25]*sheet.column_info.count) sheet.column_widths *([25]*sheet.column_info.count)
sheet.column_info.first.width = 10 sheet.column_info.first.width = 15
end #add_worksheet end #add_worksheet
end end

@ -1,18 +1,4 @@
json.polls_counts do
json.polls_total_counts @polls_count #全部问卷数
json.polls_all_counts @polls_select_count #选择后的问卷数
json.polls_unpublish_counts @polls_unpublish_counts #未发布问卷数
json.polls_published_counts @polls_published_counts #已发布问卷数
# json.polls_ended_counts @polls_ended_counts #已截止问卷数
json.left_banner_id @left_banner_id
json.left_banner_name @left_banner_name
end
json.course_types do
json.course_status @course_status # 课堂的当前是否结束如结束则为1否则为0
json.course_is_public @course_is_public #判断课堂是否为公开,只有公开课才有设为公开的按钮
json.user_permission @is_teacher_or # 当前用户存在且为课堂教师/管理员/超级管理员时为1 课堂成员为2否则为0
end
if @polls_count > 0 if @polls_count > 0
json.polls do json.polls do
@ -32,3 +18,17 @@ else
json.polls [] json.polls []
end end
json.polls_counts do
json.polls_total_counts @polls_count #全部问卷数
json.polls_all_counts @polls_select_count #选择后的问卷数
json.polls_unpublish_counts @polls_unpublish_counts #未发布问卷数
json.polls_published_counts @polls_published_counts #已发布问卷数
json.left_banner_id @left_banner_id
json.left_banner_name @left_banner_name
end
json.course_types do
json.course_status @course_status # 课堂的当前是否结束如结束则为1否则为0
json.course_is_public @course_is_public #判断课堂是否为公开,只有公开课才有设为公开的按钮
json.user_permission @is_teacher_or # 当前用户存在且为课堂教师/管理员/超级管理员时为1 课堂成员为2否则为0
end

@ -0,0 +1,7 @@
'zh-CN':
activemodel:
attributes:
users/apply_authentication_form:
name: 姓名
id_number: 身份证号

@ -0,0 +1,9 @@
'zh-CN':
activemodel:
attributes:
users/apply_professional_auth_form:
school_id: 学校/单位
department_id: 学院/部门
identity: 职业
extra: 职称/学号

@ -1,4 +1,11 @@
'zh-CN': 'zh-CN':
activerecord:
models:
user: '用户'
attributes:
user:
phone: '手机号'
mail: '邮箱'
user: user:
identity: identity:
teacher: 教师 teacher: 教师

@ -69,11 +69,16 @@ Rails.application.routes.draw do
resources :tidings, only: [:index] resources :tidings, only: [:index]
scope module: :users do scope module: :users do
resource :interest, only: [:create]
resources :accounts, only: [:show, :update] do resources :accounts, only: [:show, :update] do
resource :phone_bind, only: [:create] resource :phone_bind, only: [:create]
resource :email_bind, only: [:create] resource :email_bind, only: [:create]
resource :password, only: [:update] resource :password, only: [:update]
resource :avatar, only: [:update] resource :avatar, only: [:update]
resource :auth_attachment, only: [:update]
resource :authentication_apply, only: [:create]
resource :professional_auth_apply, only: [:create]
end end
end end
end end
@ -121,6 +126,8 @@ Rails.application.routes.draw do
get :get_answer_info get :get_answer_info
get :unlock_answer get :unlock_answer
get :check_test_sets get :check_test_sets
get :unlock_choose_answer
get :get_choose_answer
end end
collection do collection do
@ -288,6 +295,7 @@ Rails.application.routes.draw do
get 'course_group_list' get 'course_group_list'
get 'add_teacher_popup' get 'add_teacher_popup'
get 'teachers' get 'teachers'
get 'apply_teachers'
get 'graduation_group_list' get 'graduation_group_list'
get 'top_banner' get 'top_banner'
get 'left_banner' get 'left_banner'
@ -655,6 +663,8 @@ Rails.application.routes.draw do
get :export_exercises get :export_exercises
end end
end end
resources :repertoires, only: [:index]
end end
#git 认证回调 #git 认证回调

@ -3,6 +3,4 @@
:logfile: log/sidekiq.log :logfile: log/sidekiq.log
:queues: :queues:
- [default, 3] - [default, 3]
- [score, 4]
- [evaluation_comment, 5]
- [notify, 100] - [notify, 100]

@ -0,0 +1,5 @@
class AddPraisesCountForChallenges < ActiveRecord::Migration[5.2]
def change
add_column :challenges, :praises_count, :integer, :default => 0
end
end

@ -0,0 +1,9 @@
class ModifyPraisesCountForChallenges < ActiveRecord::Migration[5.2]
def change
challenges = Challenge.where(nil).unscoped
challenges.find_each do |c|
praises_count = c.praise_treads.where(praise_or_tread: 1).count
c.update_column(:praises_count, praises_count)
end
end
end

@ -0,0 +1,5 @@
class AddPraisesCountForDiscuess < ActiveRecord::Migration[5.2]
def change
add_column :discusses, :praises_count, :integer, :default => 0
end
end

@ -0,0 +1,9 @@
class ModifyPraisesCountForDiscuess < ActiveRecord::Migration[5.2]
def change
discusses = Discuss.includes(:praise_treads).unscoped
discusses.find_each do |d|
praises_count = d.praise_treads.liker.count
d.update_column(:praises_count, praises_count)
end
end
end

@ -0,0 +1,5 @@
class AddSecKeyToOutputs < ActiveRecord::Migration[5.2]
def change
add_column :outputs, :sec_key, :string
end
end

@ -0,0 +1,8 @@
class CreateUserInterests < ActiveRecord::Migration[5.2]
def change
create_table :user_interests do |t|
t.references :user
t.references :repertoire
end
end
end

@ -0,0 +1,5 @@
class AddIndexForRunCodeMessage < ActiveRecord::Migration[5.2]
def change
add_index :run_code_messages, :game_id
end
end

@ -21,7 +21,7 @@ module Educoder
def self.notify_admin(opt) def self.notify_admin(opt)
opt[:name] = '管理员' opt[:name] = '管理员'
opt[:mobile] = ENV['NOTIDY_ADMIN_PHONE'] || '17680641960' opt[:mobile] = ENV['NOTIFY_ADMIN_PHONE'] || EduSetting.get('notify_admin_phone') || '17680641960'
send(opt) send(opt)
end end

@ -60,9 +60,9 @@ namespace :homework_evaluation do
HomeworkAnonymousAppealStartNotifyJob.perform_later(homework_common.id) HomeworkAnonymousAppealStartNotifyJob.perform_later(homework_common.id)
else else
homework_detail_manual.update_column('comment_status', 5) homework_detail_manual.update_column('comment_status', 5)
# 没有申诉阶段则直接计算缺评扣分 否则申诉结束时才计算
HomeworkAbsencePenaltyCalculationJob.perform_later(homework_common.id)
end end
HomeworkAbsencePenaltyCalculationJob.perform_later(homework_common.id)
end end
end end
end end
@ -71,5 +71,8 @@ namespace :homework_evaluation do
task :end_appeal => :environment do task :end_appeal => :environment do
homework_detail_manuals = HomeworkDetailManual.where("appeal_time <= '#{Time.now}' and homework_detail_manuals.comment_status = 4") homework_detail_manuals = HomeworkDetailManual.where("appeal_time <= '#{Time.now}' and homework_detail_manuals.comment_status = 4")
homework_detail_manuals.update_all(:comment_status => 5) homework_detail_manuals.update_all(:comment_status => 5)
homework_detail_manuals.each do |homework_detail_manual|
HomeworkAbsencePenaltyCalculationJob.perform_later(homework_detail_manual.homework_common_id)
end
end end
end end

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

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