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

dev_course
jingquan huang 6 years ago
commit 28c58434c7

@ -206,7 +206,7 @@ class ChallengesController < ApplicationController
end
# 关卡评测执行文件如果被修改,需要修改脚本内容
script = modify_shixun_script @shixun, @shixun.evaluate_script
@shixun.update_column(:evaluate_script, script)
@shixun.shixun_info.update_column(:evaluate_script, script)
# TODO:
# if path != params[:challenge][:path]
# shixun_modify_status_without_publish(@shixun, 1)

@ -9,11 +9,13 @@ module GitHelper
# 版本库文件内容,带转码
def git_fle_content(repo_path, path)
begin
content = GitService.file_content(repo_path: repo_path, path: path)["content"]
logger.info("@@@@@@@@@@@@@@@@@@#{content}")
content = GitService.file_content(repo_path: repo_path, path: path)
logger.info("@@@@@@@@@@@@@@@@@@#{content}")
decode_content = nil
if content.present?
content = content["content"] #6.24 -hs 这个为新增,因为当实训题里含有选择题时,这里会报错,undefined method `[]' for nil:NilClass
content = Base64.decode64(content)
cd = CharDet.detect(content)
logger.info "encoding: #{cd['encoding']} confidence: #{cd['confidence']}"
@ -27,6 +29,7 @@ module GitHelper
end
decode_content
rescue Exception => e
uid_logger_error(e.message)
raise Educoder::TipException.new("文档内容获取异常")

@ -737,11 +737,11 @@ class CoursesController < ApplicationController
end
end
# 获取历史课堂,即用户管理的所有课堂以及课堂下的分班
# 获取历史课堂,即用户管理的所有课堂以及课堂下的分班(去除当前课堂)
def get_historical_courses
user_id = current_user.id
@courses = Course.includes(:course_groups).where(tea_id: user_id, is_delete: 0)
@courses = Course.where.not(id: @course.id).joins(:course_members).
where(is_delete: 0, course_members: {user_id: current_user.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR]}).includes(:course_groups)
# @courses = Course.includes(:course_groups).where(id: current_user.course_members, is_delete: 0)
end
# 根据历史课堂的课堂id和分班id获取所有学生
@ -754,6 +754,7 @@ class CoursesController < ApplicationController
@students = @students.where(course_group_id: course_group_id)
end
@students = @students.includes(user: [user_extension: :school])
@students_count = @students.size
end

@ -94,28 +94,39 @@ class ExerciseAnswersController < ApplicationController
def get_exercise_question
@exercise_question = ExerciseQuestion.find_by_id(params[:exercise_question_id])
@exercise = @exercise_question.exercise
@course = @exercise.course
@exercise_user = @exercise.exercise_users.find_by(user_id: current_user.id) #当前用户
@exercise = @exercise_question&.exercise
@course = @exercise&.course
@exercise_user = @exercise&.exercise_users.find_by(user_id: current_user.id) #当前用户
@exercise_user_status = @exercise.get_exercise_status(current_user.id)
if @exercise_question.blank?
normal_status(-1,"试卷问题不存在!")
elsif @exercise.blank?
normal_status(-1,"试卷不存在!")
elsif @course.blank?
normal_status(-1,"该课堂不存在!")
elsif (@exercise_user.present? && @exercise_user&.commit_status == 1) || @exercise_user_status == 3 #已提交答案的/时间已结束的试卷不允许再修改
elsif @exercise_user.blank?
normal_status(-1,"试卷用户不存在!")
elsif @exercise_user.commit_status == 1
normal_status(-1,"已提交/已结束的试卷不允许修改!")
elsif @exercise.time > 0
user_start_at = @exercise_user&.start_at
exercise_time = @exercise.time.to_i + 1 #
if (user_start_at + exercise_time.minutes) < Time.now
normal_status(-1,"限时试卷已结束!")
else
if (@exercise_user_status == 3 && @exercise_user.commit_status == 0) || (@exercise.time > 0 && @exercise_user.start_at.present? && ((@exercise_user.start_at + (@exercise.time.to_i + 1).minutes) < Time.now))
objective_score = calculate_student_score(@exercise,current_user)[:total_score]
subjective_score = @exercise_user.subjective_score < 0.0 ? 0.0 : @exercise_user.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.update_attributes(commit_option)
normal_status(-1,"试卷提交时间已截止!")
end
end
end
end

@ -48,6 +48,7 @@ class ExercisesController < ApplicationController
@exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同)
elsif @user_course_identity == Course::STUDENT # 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
if member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的)
@exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : []
@ -200,10 +201,12 @@ class ExercisesController < ApplicationController
def common_header
ActiveRecord::Base.transaction do
begin
@user_left_time = nil
if @user_course_identity > Course::ASSISTANT_PROFESSOR
@is_teacher_or = 0
@user_exercise_answer = @exercise.check_user_answer_status(current_user)
@user_commit_counts = 0
@user_left_time = get_exercise_left_time(@exercise,current_user)
else
@is_teacher_or = 1
@user_exercise_answer = 3 #教师页面
@ -222,6 +225,8 @@ class ExercisesController < ApplicationController
@exercise_publish_count = 1 #试卷未发布,且课堂没有分班的时候
end
end
rescue Exception => e
uid_logger_error(e.message)
tip_exception("没有权限")
@ -1016,19 +1021,27 @@ class ExercisesController < ApplicationController
@exercise_user_current.update_attribute("start_at",Time.now)
end
end
if @exercise.time > 0
exercise_user_start = @exercise_user_current.present? ? @exercise_user_current.start_at.to_i : 0
exercise_user_left_time = Time.now.to_i - exercise_user_start
time_mill = @exercise.time * 60 #转为毫秒
@user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间
end
# ex_time = @exercise.time
# if ex_time > 0
# time_mill = ex_time * 60 #转为秒
# exercise_end_time = @exercise.end_time.present? ? @exercise.end_time.to_i : 0
# exercise_user_start = @exercise_user_current.present? ? @exercise_user_current.start_at.to_i : 0
# if (exercise_user_start + time_mill) > exercise_end_time
# time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时
# end
# exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间
# @user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间
# end
@t_user_exercise_status = @exercise.get_exercise_status(current_user.id)
@user_left_time = nil
if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) ||
(@exercise_user_current.present? && @exercise_user_current.commit_status == 1)
@user_exercise_status = 1 #当前用户为老师/试卷已截止/试卷已提交不可编辑
else
@user_left_time = get_exercise_left_time(@exercise,current_user)
@user_exercise_status = 0 #可编辑
end
@ -1632,12 +1645,6 @@ class ExercisesController < ApplicationController
normal_status(404,"答题用户不存在")
elsif @exercise.get_exercise_status(current_user.id) != 2 || @answer_committed_user.commit_status == 1 #
normal_status(-1,"提交错误,试卷已截止/用户已提交!")
# elsif @exercise.time > 0
# user_start_at = @answer_committed_user.start_at
# exercise_time = @exercise.time.to_i
# if (user_start_at + exercise_time.minutes) < Time.now
# normal_status(-1,"限时试卷已结束,已自动提交!")
# end
end
end
@ -1789,4 +1796,6 @@ class ExercisesController < ApplicationController
end
end
end

@ -530,7 +530,7 @@ class HomeworkCommonsController < ApplicationController
if setting && setting.score != score
score_change = true
setting.update_attributes(score: score)
else
elsif setting.blank?
score_change = true
HomeworkChallengeSetting.create!(homework_common_id: @homework.id, challenge_id: challenge[:challenge_id],
shixun_id: @homework.homework_commons_shixun.try(:shixun_id), score: score)

@ -182,7 +182,13 @@ class MyshixunsController < ApplicationController
test_set_percentage = test_set_score / 100.to_f # 测试集得分比
score = (challenge.score * test_set_percentage * answer_deduction_percentage).to_i
# 如果分数比上次多,则更新成绩
game.update_attributes!(:status => 0, :final_score => score) if game.final_score < score
game_update =
if game.final_score < score
{final_score: score, status: 0}
else
{status: 0}
end
game.update_attributes!(game_update)
end
end
test_cases_time = format("%.3f", (Time.now.to_f - t1.to_f)).to_f

@ -115,8 +115,8 @@ class ShixunsController < ApplicationController
def show_right
owner = @shixun.owner
#@fans_count = owner.followers.count
#@followed_count = owner.followed_users.count
#@fans_count = owner.fan_count
#@followed_count = owner.follow_count
@user_own_shixuns = owner.shixuns.published.count
end
@ -409,12 +409,12 @@ class ShixunsController < ApplicationController
end
def propaedeutics
@content = Shixun.where(identifier: params[:identifier]).pluck(:propaedeutics)
@content = Shixun.find_by_identifier!(params[:identifier]).propaedeutics
end
# 更新背景知识
def update_propaedeutics
@shixun.update_column(:propaedeutics, params[:content])
@shixun.shixun_info.update_column(:propaedeutics, params[:content])
end
# 获取推荐实训接口 2个热门实训 + 2个最新实训

@ -12,50 +12,6 @@ module UserDecorator
logged_user? ? real_name : full_name
end
# 关注数
def follow_count
Watcher.where(user_id: id, watchable_type: %w(Principal User)).count
# User.watched_by(id).count
end
# 粉丝数
def fan_count
Watcher.where(watchable_type: %w(Principal User), watchable_id: id).count
# watchers.count
end
# 是否绑定邮箱
def email_binded?
mail.present?
end
# 学院的url标识
def college_identifier
Department.find_by_id(department_members.pluck(:department_id).first)&.identifier
end
# 是否能申请试用
def can_apply_trial?
return false if certification == 1
apply = ApplyAction.order(created_at: :desc).find_by(user_id: id, container_type: 'TrialAuthorization')
apply.present? && !apply.status.zero?
end
# 是否已经签到
def attendance_signed?
attendance = Attendance.find_by(user_id: id)
attendance.present? && Util.days_between(Time.zone.now, attendance.created_at).zero?
end
# 明日签到金币
def tomorrow_attendance_gold
Attendance.find_by(user_id: id)&.next_gold || 50
end
# ----------- 账号管理 -------------
def authentication_status
if authentication?
@ -76,16 +32,4 @@ module UserDecorator
'uncertified'
end
end
def base_info_completed?
user_columns = %i[nickname lastname]
user_extension_columns = %i[gender location location_city identity school_id department]
user_columns.all? { |column| public_send(column).present? } &&
user_extension_columns.all? { |column| user_extension.send(column).present? }
end
def all_certified?
authentication? && professional_certification?
end
end

@ -32,7 +32,7 @@ module ExerciseQuestionsHelper
def shixun_game_scores(challenge,ex_answerer,shixun_type,question_id)
game_score = challenge.question_score
game_answers = challenge.exercise_shixun_answers.search_shixun_answers("user_id",ex_answerer.id).search_shixun_answers("exercise_question_id",question_id)
game_answers = challenge.exercise_shixun_answers.where(user_id:ex_answerer.id,exercise_question_id:question_id)
if shixun_type == 2 && game_answers.present? #试卷已截止,用户才可以查看答案
s_score = game_answers.first.score
else

@ -56,8 +56,8 @@ module ExercisesHelper
}
@ex_sub_array.push(sub_score)
end
@ex_obj_array.sort_by {|k| k[:q_position]}
@ex_sub_array.sort_by {|k| k[:q_position]}
@ex_obj_array = @ex_obj_array.sort_by {|k| k[:q_position]}
@ex_sub_array = @ex_sub_array.sort_by {|k| k[:q_position]}
end
#试卷的统计结果页面计算各题的
@ -413,43 +413,41 @@ module ExercisesHelper
score2 += 0.0
end
elsif q.question_type == 5 #实训题时,主观题这里不评分
if answers_content.present?
q.exercise_shixun_challenges.each do |exercise_cha|
game = Game.user_games(user.id,exercise_cha.challenge_id).first #当前用户的关卡
if game.present?
exercise_cha_score = 0.0
answer_status = 0
q.exercise_shixun_challenges.each do |exercise_cha|
game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡
if game.present?
exercise_cha_score = 0.0
answer_status = 0
if game.status == 2 && game.final_score >= 0
exercise_cha_score = exercise_cha.question_score #每一关卡的得分
answer_status = 1
end
ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id)
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
cha_path = challenge_path exercise_cha.challenge.path
if game.status == 2 && game.final_score >= 0
exercise_cha_score = exercise_cha.question_score #每一关卡的得分
answer_status = 1
end
ex_shixun_answer_content = answers_content.where(exercise_shixun_challenge_id: exercise_cha.id)
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
game_challenge = game.game_codes.search_challenge_path(cha_path).first
if game_challenge.present?
game_code = game_challenge
code = game_code.try(:new_code)
else
code = git_fle_content(exercise_cha.shixun.repo_path,cha_path)
end
sx_option = {
:exercise_question_id => q.id,
:exercise_shixun_challenge_id => exercise_cha.id,
:user_id => user.id,
:score => exercise_cha_score,
:answer_text => code,
:status => answer_status
}
ExerciseShixunAnswer.create(sx_option)
game_challenge = game.game_codes.search_challenge_path(cha_path).first
if game_challenge.present?
game_code = game_challenge
code = game_code.try(:new_code)
else
ex_shixun_answer_content.first.update_column('score',exercise_cha_score)
code = git_fle_content(exercise_cha.shixun.repo_path,cha_path)
end
score5 += exercise_cha_score
sx_option = {
:exercise_question_id => q.id,
:exercise_shixun_challenge_id => exercise_cha.id,
:user_id => user.id,
:score => exercise_cha_score,
:answer_text => code,
:status => answer_status
}
ExerciseShixunAnswer.create(sx_option)
else
ex_shixun_answer_content.first.update_column('score',exercise_cha_score)
end
score5 += exercise_cha_score
else
score5 += 0.0
end
else
score5 += 0.0
end
end
user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0
@ -681,6 +679,23 @@ module ExercisesHelper
result
end
def get_exercise_left_time(exercise,user)
ex_time = exercise.time
user_left_time = nil
if ex_time > 0
exercise_user = exercise.exercise_users.find_by(user_id:user.id)
time_mill = ex_time * 60 #转为秒
exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0
exercise_user_start = exercise_user.present? ? exercise_user.start_at.to_i : 0
if (exercise_user_start + time_mill) > exercise_end_time
time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时
end
exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间
user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间
end
user_left_time
end
#实训题学生代码的行数
def content_line(content)
content.split(/\r?\n/).length

@ -35,7 +35,7 @@ module ExportHelper
else
head_cells_add = []
end
normal_head_b_cells = %w(最终成绩 提交时间 更新时间)
normal_head_b_cells = %w(最终成绩 提交时间 更新时间 评语)
@work_head_cells = (head_cells_format + group_cells + normal_head_cells + head_cells_add + allow_late_cell + normal_head_b_cells).reject(&:blank?)
works.each_with_index do |w, index|
w_user = w.user
@ -85,8 +85,21 @@ module ExportHelper
w_15 = w.work_score.nil? ? "未评分" : w.work_score.round(1)
w_16 = w.commit_time ? format_time(w.commit_time) : "--"
w_17 = w.update_time ? format_time(w.update_time) : "--"
teacher_comments = w.student_works_scores
if teacher_comments.present?
w_18 = ""
teacher_comments.each do |t|
user_name = t.user.real_name
user_time = format_time(t.updated_at)
user_score = t.score
user_comment = t.comment
w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "" + "\n" + "评语:" + user_comment + "\n\n")
end
else
w_18 = "--"
end
row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17]
row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17,w_18]
row_cells_column = row_cells_column.reject(&:blank?)
@work_cells_column.push(row_cells_column)
end
@ -102,7 +115,7 @@ module ExportHelper
if allow_late_boolean #允许迟交
eff_score_cell.push("迟交扣分")
end
shixun_time_cells = %w(最终成绩 更新时间 提交耗时)
shixun_time_cells = %w(最终成绩 更新时间 提交耗时 评语)
@work_head_cells = (head_cells_format + shixun_head_cells + eff_score_cell + shixun_time_cells).reject(&:blank?)
works.each_with_index do |w, index|
myshixun = w.try(:myshixun)
@ -143,7 +156,20 @@ module ExportHelper
w_15 = w.work_score.nil? ? "--" : w.work_score.round(1)
w_16 = w.update_time ? format_time(w.update_time) : "--" "更新时间"
w_17 = w.cost_time
row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17]
teacher_comments = w.student_works_scores
if teacher_comments.present?
w_18 = ""
teacher_comments.each do |t|
user_name = t.user.real_name
user_time = format_time(t.updated_at)
user_score = t.score
user_comment = t.comment
w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "" + "\n" + "评语:" + user_comment + "\n\n")
end
else
w_18 = "--"
end
row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17,w_18]
row_cells_column = row_cells_column.reject(&:blank?)
@work_cells_column.push(row_cells_column)
end

@ -28,4 +28,9 @@ module Util
end
end
end
def logger_error(exception)
Rails.logger.error(exception.message)
exception.backtrace.each { |message| Rails.logger.error(message) }
end
end

@ -98,59 +98,48 @@ class Exercise < ApplicationRecord
#判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间
def get_exercise_status(user_id)
user_group = course.course_members.find_by(user_id: user_id)
if user_group.present?
if user_group.role == "STUDENT" #为学生
is_teacher = false
else
is_teacher = true
end
ex_time = get_exercise_times(user_id,is_teacher)
if user_group.present? && user_group.role == "STUDENT" #当为学生的时候,需根据分班来判断试卷状态
ex_time = get_exercise_times(user_id,false)
pb_time = ex_time[:publish_time]
ed_time = ex_time[:end_time]
pb_time = ex_time[:publish_time]
ed_time = ex_time[:end_time]
if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now
status = 2
elsif ed_time.present? && ed_time <= Time.now
status = 3
else
status = 1
end
if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now
status = 2
elsif ed_time.present? && ed_time <= Time.now
status = 3
else
status = 1
end
else
status = exercise_status
status = exercise_status #当为老师的时候,则为试卷的总状态
end
Rails.logger.info("#################__________status___________####################{status}")
status
end
#获取试卷的发布时间和截止时间。teacher 为boolean,当为true时表示的是当前为老师
def get_exercise_times(user_id,teacher)
if unified_setting
if unified_setting || teacher #当试卷为统一设置或当前为老师的时候
pb_time = publish_time
en_time = end_time
if en_time.present? && (en_time <= Time.now) && (exercise_status != 3)
update_column("exercise_status",3)
end
else
ex_group_setting = exercise_group_settings
if teacher #当前为老师,为设置组的最大值和最小值
user_group = course.teacher_course_groups.get_user_groups(user_id)
user_group_ids = user_group.present? ? user_group.pluck(:course_group_id) : course.course_groups.pluck(:id)
user_ex_group_settings = ex_group_setting.find_in_exercise_group("course_group_id",user_group_ids)
pb_time_min = user_ex_group_settings.publish_time_no_null.map(&:publish_time)
en_time_max = user_ex_group_settings.end_time_no_null.map(&: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
user_group = course.students.course_find_by_ids("user_id",user_id)
if user_group.present?
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)
pb_time = user_ex_group_setting.present? ? user_ex_group_setting.first.publish_time : nil
en_time = user_ex_group_setting.present? ? user_ex_group_setting.first.end_time : nil
else
user_group = course.students.course_find_by_ids("user_id",user_id)
if user_group.present?
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)
pb_time = user_ex_group_setting.present? ? user_ex_group_setting.first.publish_time : nil
en_time = user_ex_group_setting.present? ? user_ex_group_setting.first.end_time : nil
else
pb_time = nil
en_time = nil
end
pb_time = nil
en_time = nil
end
end
{
"publish_time":pb_time,
"end_time":en_time

@ -1,6 +1,8 @@
# TODO: 已废弃
class Relationship < ApplicationRecord
belongs_to :follower, class_name: "User"
belongs_to :followed, class_name: "User"
validates :follower_id, presence: true
validates :followed_id, presence: true
end

@ -47,14 +47,6 @@ class User < ApplicationRecord
has_many :graduation_works, dependent: :destroy
# 关注
has_many :relationships, foreign_key: "follower_id", dependent: :destroy
has_many :followed_users, through: :relationships, source: :followed
# 粉丝
has_many :reverse_relationships, foreign_key: "followed_id",
class_name: "Relationship",
dependent: :destroy
has_many :followers, through: :reverse_relationships, source: :follower
has_many :students_for_courses, foreign_key: :student_id, dependent: :destroy
has_one :onclick_time, :dependent => :destroy
@ -161,19 +153,16 @@ class User < ApplicationRecord
self.user_extension.try(:student_id)
end
# 关注总数
def following?(other_user)
relationships.find_by(followed_id: other_user)
end
# 关注
def follow!(other_user)
relationships.create!(followed_id: other_user)
# 关注数
def follow_count
Watcher.where(user_id: id, watchable_type: %w(Principal User)).count
# User.watched_by(id).count
end
# 取消关注
def unfollow!(other_user)
relationships.find_by(followed_id: other_user.id).destroy
# 粉丝数
def fan_count
Watcher.where(watchable_type: %w(Principal User), watchable_id: id).count
# watchers.count
end
# 判断当前用户是否为老师
@ -545,6 +534,51 @@ class User < ApplicationRecord
Educoder::Utils.random_hex(16)
end
# 基本资料是否完善
def base_info_completed?
user_columns = %i[nickname lastname]
user_extension_columns = %i[gender location location_city identity school_id department]
user_columns.all? { |column| public_send(column).present? } &&
user_extension_columns.all? { |column| user_extension.send(column).present? }
end
# 全部已认证
def all_certified?
authentication? && professional_certification?
end
# 是否绑定邮箱
def email_binded?
mail.present?
end
# 学院的url标识
def college_identifier
Department.find_by_id(department_members.pluck(:department_id).first)&.identifier
end
# 是否能申请试用
def can_apply_trial?
return false if certification == 1
apply = ApplyAction.order(created_at: :desc).find_by(user_id: id, container_type: 'TrialAuthorization')
apply.present? && !apply.status.zero?
end
# 是否已经签到
def attendance_signed?
attendance = Attendance.find_by(user_id: id)
attendance.present? && Util.days_between(Time.zone.now, attendance.created_at).zero?
end
# 明日签到金币
def tomorrow_attendance_gold
Attendance.find_by(user_id: id)&.next_gold || 60 # 基础50连续签到+10
end
protected
def validate_password_length
# 管理员的初始密码是5位

@ -165,7 +165,7 @@ class HomeworksService
homework = work.homework_common
#logger.info("#############member_course_group_id: #{member.try(:course_group_id)}")
setting_time = homework.homework_group_setting work.user_id
if setting_time.end_time.present? && (setting_time.end_time > Time.now || (homework.allow_late && !homework.course.is_end))
if setting_time.end_time.present? && (setting_time.end_time > Time.now || (homework.allow_late && homework.late_time && homework.late_time > Time.now))
#logger.info("#############setting_time: #{setting_time.end_time}")
user_total_score = 0

@ -1,9 +1,9 @@
json.students do
json.array! @students do |student|
json.course_member_id student.id
json.user_id student.user_id
json.name student.user.real_name
json.student_id student.user.user_extension.try(:student_id)
json.school_name student.user.user_extension.school.try(:name)
json.student_id student.user.student_id
json.school_name student.user.school_name
end
end
json.students_count @students_count

@ -7,7 +7,7 @@ json.stage_list do
json.evaluate_count game.evaluate_count
json.finished_time finished_time game.end_time
json.time_consuming time_consuming game
json.myself_experience game.final_score #经验值
json.myself_experience game.final_score < 0 ? 0 : game.final_score #经验值
json.experience game.challenge.all_score #经验值
json.user_score user_score.round(1).to_s #用户获得的分数
json.game_score game_score.round(1).to_s #该关卡的总分数

@ -1,5 +1,7 @@
json.course_is_end @course.is_end # true表示已结束false表示未结束
json.extract! @exercise, :id,:exercise_name,:exercise_description,:show_statistic,:time
json.extract! @exercise, :id,:exercise_name,:exercise_description,:show_statistic
json.time @user_left_time
json.exercise_status @ex_status
json.user_permission do

@ -21,7 +21,11 @@ if @exercises_count > 0
json.exercises do
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,:time
json.extract! exercise, :id, :exercise_name,:is_public,:created_at
if @is_teacher_or == 2
json.time get_exercise_left_time(exercise,@current_user_)
end
json.exercise_status ex_index[:ex_status]
json.lock_status ex_index[:lock_icon]
json.publish_time ex_index[:publish_time] # 试卷的发布时间

@ -1,5 +1,6 @@
wb = xlsx_package.workbook
# wb.use_autowidth = false
wb.styles do |s|
sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center}
blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center}
@ -8,7 +9,7 @@ wb.styles do |s|
sheet.add_row table_columns, :style => blue_cell
if task_users.count > 0
task_users.each do |user|
sheet.add_row user, :style => sz_all
sheet.add_row user, :height => 20,:style => sz_all
end #each_widh_index
end
sheet.column_widths *([20]*sheet.column_info.count)

@ -10,7 +10,7 @@ json.array! @members do |member|
json.user do
json.partial! 'users/user', locals: { user: member.user }
json.user_shixuns_count member.user.shixuns.published.count
#json.fans_count member.user.followers.count
#json.fans_count member.user.fan_count
json.brief_introduction member.user.user_extension.brief_introduction
json.identity member.user.identity
json.school_name member.user.school_name

@ -1,7 +1,7 @@
'en':
shixun:
status:
0: editing
1: applying
2: published
3: closed
'0': editing
'1': applying
'2': published
'3': closed

@ -1,7 +1,7 @@
'zh-CN':
shixun:
status:
0: 编辑中
1: 审核中
2: 已发布
3: 已关闭
'0': 编辑中
'1': 审核中
'2': 已发布
'3': 已关闭

@ -0,0 +1,10 @@
class AddUniqIndexToHomeworkChallengeSettings < ActiveRecord::Migration[5.2]
def change
remove_index :homework_challenge_settings, [:homework_common_id, :challenge_id] if index_exists?(:homework_challenge_settings, [:homework_common_id, :challenge_id])
sql = %Q(delete from homework_challenge_settings where (homework_common_id, challenge_id) in
(select * from (select homework_common_id, challenge_id from homework_challenge_settings group by homework_common_id, challenge_id having count(*) > 1) a)
and id not in (select * from (select max(id) from homework_challenge_settings group by homework_common_id, challenge_id having count(*) > 1 order by id) b))
ActiveRecord::Base.connection.execute sql
add_index :homework_challenge_settings, [:homework_common_id, :challenge_id], unique: true, name: "index_on_homework_common_id_challenge_id"
end
end
Loading…
Cancel
Save