merge aliyun

dev_aliyun2
harry 5 years ago
commit 188bf989cc

@ -112,4 +112,4 @@ gem 'request_store'
# 敏感词汇
gem 'harmonious_dictionary', '~> 0.0.1'
gem 'parallel', '~> 1.19', '>= 1.19.1'
gem 'parallel', '~> 1.19', '>= 1.19.1'

@ -1,5 +1,6 @@
class AdminConstraint
def matches?(request)
return true
laboratory = Laboratory.first
return false unless request.session[:"#{laboratory.try(:identifier).split('.').first}_user_id"]
user = User.find request.session[:"#{laboratory.try(:identifier).split('.').first}_user_id"]

@ -21,7 +21,7 @@ class Admins::BaseController < ApplicationController
def require_admin!
return if current_user.blank? || !current_user.logged?
return if current_user.admin_or_business?
return if current_user.admin_or_business? || current_user.admin_visitable?
render_forbidden
end

@ -7,13 +7,15 @@ class Admins::CoursesController < Admins::BaseController
courses = Admins::CourseQuery.call(params)
@ended_courses = courses.where(is_end: 1).size
@processed_courses = courses.where(is_end: 0).size
@courses = paginate courses.includes(:school, :students, :attachments, :homework_commons, teacher: :user_extension)
@courses = paginate courses.includes(:school, :students, :teacher_course_members, :informs, :course_videos, :attachments, :homework_commons, teacher: :user_extension)
respond_to do |format|
format.js
format.html
format.xlsx do
@courses = courses.includes(:school, :students, :attachments, :homework_commons, :course_acts, teacher: :user_extension)
@courses = courses.not_deleted.includes(:school, :students, :teacher_course_members, :informs, :course_videos,
:live_links, :attachments, :homework_commons,
teacher: [user_extension: :department])
filename = "课堂列表_#{Time.current.strftime('%Y%m%d%H%M%S')}.xlsx"
render xlsx: 'index', filename: filename
end

@ -63,6 +63,6 @@ class Admins::UsersController < Admins::BaseController
def update_params
params.require(:user).permit(%i[lastname nickname gender identity technical_title student_id is_shixun_marker
mail phone location location_city school_id department_id admin business is_test
password professional_certification authentication])
password professional_certification authentication admin_visitable])
end
end

@ -330,7 +330,7 @@ class ApplicationController < ActionController::Base
end
if !User.current.logged? && Rails.env.development?
User.current = User.find 1
User.current = User.find 3117
end

@ -2,29 +2,45 @@ class AttendancesController < ApplicationController
before_action :require_login
before_action :find_course, only: [:index, :statistics]
before_action :find_attendance, except: [:index, :statistics]
before_action :user_course_identity
def index
current_date = Date.current
current_end_time = Time.current.strftime("%H:%M:%S")
member = @course.students.find_by(user_id: current_user.id)
if params[:history]
@attendances = @course.course_attendances.where("attendance_date < '#{current_date}' or
(attendance_date = '#{current_date}' and end_time < '#{current_end_time}')")
if @user_course_identity == Course::STUDENT
member = @course.students.find_by(user_id: current_user.id)
group_ids = [member&.course_group_id.to_i, 0]
@attendances = @attendances.joins(:course_attendance_groups).where(course_attendance_groups: {course_group_id: group_ids})
history_attendance_ids = member.course_member_attendances.where(course_id: @course.id).pluck(:course_attendance_id)
@attendances = @course.course_attendances.where(id: history_attendance_ids.uniq).
where("attendance_date < '#{current_date}' or (attendance_date = '#{current_date}' and end_time < '#{current_end_time}')")
else
@attendances = @course.course_attendances.where("attendance_date < '#{current_date}' or
(attendance_date = '#{current_date}' and end_time < '#{current_end_time}')")
end
else
@attendances = @course.course_attendances.where("attendance_date > '#{current_date}' or
(attendance_date = '#{current_date}' and end_time > '#{current_end_time}')")
end
if @user_course_identity == Course::STUDENT
group_ids = [member&.course_group_id.to_i, 0]
@attendances = @attendances.joins(:course_attendance_groups).where(course_attendance_groups: {course_group_id: group_ids})
if params[:history]
attendance_ids = @attendances.pluck(:id)
@normal_count = @course.course_member_attendances.where(course_member_id: member&.id, course_attendance_id: attendance_ids, attendance_status: "NORMAL").size
@leave_count = @course.course_member_attendances.where(course_member_id: member&.id, course_attendance_id: attendance_ids, attendance_status: "LEAVE").size
@absence_count = @course.course_member_attendances.where(course_member_id: member&.id, course_attendance_id: attendance_ids, attendance_status: "ABSENCE").size
else
@attendances = @attendances.where("attendance_date = '#{current_date}' and start_time <= '#{current_end_time}' and end_time > '#{current_end_time}'")
end
else
@attendances = @course.course_attendances.where("attendance_date > '#{current_date}' or
(attendance_date = '#{current_date}' and end_time > '#{current_end_time}')")
end
@attendances_count = @attendances.size
@attendances = @attendances.order("attendance_date desc, start_time desc")
@ -36,10 +52,12 @@ class AttendancesController < ApplicationController
current_end_time = Time.current.strftime("%H:%M:%S")
history_attendances = @course.course_attendances.where("attendance_date < '#{current_date}' or
(attendance_date = '#{current_date}' and end_time < '#{current_end_time}')")
all_member_attendances = CourseMemberAttendance.where(course_attendance_id: history_attendances)
if params[:group_id].present?
history_attendances = history_attendances.joins(:course_attendance_groups).where(course_attendance_groups: {course_group_id: [params[:group_id], 0]})
all_member_attendances = all_member_attendances.joins(:course_member).where(course_members: {course_group_id: params[:group_id]})
all_member_attendances = CourseMemberAttendance.where(course_attendance_id: history_attendances)
.joins(:course_member).where(course_members: {course_group_id: params[:group_id]})
else
all_member_attendances = CourseMemberAttendance.where(course_attendance_id: history_attendances)
end
history_attendances = history_attendances.order("attendance_date desc, start_time desc")
@ -51,9 +69,72 @@ class AttendancesController < ApplicationController
@avg_leave_rate = data[:avg_leave_rate]
end
def edit
@groups = @course.course_groups.where(id: @attendance.course_attendance_groups.pluck(:course_group_id))
end
def update
tip_exception(403, "") unless @user_course_identity < Course::PROFESSOR || @attendance.user_id == current_user.id
a_end_time = "#{@attendance.attendance_date} #{@attendance.end_time}".to_time
new_end_time = "#{params[:attendance_date]} #{params[:end_time]}".to_time
@attendance.update!(update_params)
old_group_ids = @attendance.course_attendance_groups.pluck(:course_group_id)
unless old_group_ids.include?(0)
# all_groups_ids = old_group_ids + params[:group_ids].map(&:to_i)
# 如果新增的的分班加上之前的分班是课堂的全部分班,则只需创建一条记录(未分班需要区分考虑,不需要这步)
# if all_groups_ids.uniq.count == @course.course_groups_count
# @attendance.course_attendance_groups.destroy_all
# @attendance.course_attendance_groups.create!(course_group_id: 0, course_id: @attendance.course_id)
# new_group = true
# else
new_group = false
new_group_ids = params[:group_ids].map(&:to_i) - old_group_ids
new_group_ids.each do |group_id|
@attendance.course_attendance_groups.create!(course_group_id: group_id, course_id: @attendance.course_id)
new_group = true
end
# end
end
# 如果新增了分班或者历史签到变为了正在签到,将未创建的学生签到数据补上
if new_group || (a_end_time < Time.current && new_end_time > Time.current)
create_absence_student_data
end
render_ok
end
private
def find_attendance
@attendance = CourseAttendance.find params[:id]
@course = @attendance.course
end
def update_params
params.permit(:name, :mode, :attendance_date, :start_time, :end_time)
end
def create_absence_student_data
group_ids = @attendance.course_attendance_groups.pluck(:course_group_id)
if group_ids.include?(0)
students = @course.students
else
students = @course.students.where(course_group_id: group_ids)
end
none_users = students.where.not(user_id: @attendance.course_member_attendances.pluck(:user_id))
attrs = %i[course_attendance_id user_id course_member_id course_id course_group_id created_at updated_at]
same_attrs = {course_attendance_id: @attendance.id, course_id: @course.id}
CourseMemberAttendance.bulk_insert(*attrs) do |worker|
none_users.each do |student|
next if @attendance.course_member_attendances.exists?(user_id: student.user_id)
worker.add same_attrs.merge(user_id: student.user_id, course_member_id: student.id, course_group_id: student.course_group_id)
end
end
end
end

@ -164,6 +164,12 @@ class ChallengesController < ApplicationController
@challenges = @shixun.challenges.joins(join_sql).select(base_columns).uniq
@shixun_modify = (@challenges.select{|c| !c.status.nil? }.size != @challenges.size)
logger.info("########shixun_modify#{@shixun_modify}")
logger.info("########challenges.size#{@challenges.size}")
logger.info("########challenge_inspect#{@challenges.inspect}")
#@challenges = @shixun.challenges.fields_for_list
@editable = @shixun.status == 0 # before_action有判断权限如果没发布则肯定是管理人员
@user = current_user
@ -313,19 +319,27 @@ class ChallengesController < ApplicationController
end
rescue => e
tip_exception("上移失败: #{e.message}")
raise ActiveRecord::Rollback
end
end
def destroy
next_challenges = @shixun.challenges.where("position > #{@challenge.position}")
next_challenges.update_all("position = position - 1")
# Todo: 实训修改后,关卡需要重置
# shixun_modify_status_without_publish(@shixun, 1)
@challenge.destroy
# 关卡位置被删除,需要修改脚本
script = modify_shixun_script @shixun, @shixun.evaluate_script
@shixun.shixun_info.update_column(:evaluate_script, script)
begin
ActiveRecord::Base.transaction do
next_challenges.update_all("position = position - 1")
# Todo: 实训修改后,关卡需要重置
# shixun_modify_status_without_publish(@shixun, 1)
@challenge.destroy
# 关卡位置被删除,需要修改脚本
script = modify_shixun_script @shixun, @shixun.evaluate_script
@shixun.shixun_info.update_column(:evaluate_script, script)
end
rescue => e
tip_exception("删除关卡失败: #{e.message}")
raise ActiveRecord::Rollback
end
end

@ -0,0 +1,21 @@
class CollectionsController < ApplicationController
before_action :require_login
def create
tip_exception("勿重复收藏") if current_user.collections.find_by(create_params).present?
current_user.collections.create!(create_params)
normal_status("收藏成功,您可以在个人主页对应的栏目中查看")
end
def cancel
collection = current_user.collections.find_by!(create_params)
collection.destroy!
normal_status("操作成功")
end
private
def create_params
params.permit(:container_id, :container_type)
end
end

@ -27,7 +27,7 @@ class CollegesController < ApplicationController
def shixun_time
time_sum = Game.joins('left join user_extensions on user_extensions.user_id = games.user_id')
.where(user_extensions: { school_id: current_school.id }).sum(:cost_time)
shixun_time_sum = (time_sum / (24 * 60 * 60.0)).ceil
shixun_time_sum = (time_sum / 60.0).ceil
render json: { shixun_time: shixun_time_sum }
end

@ -38,7 +38,7 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController
student_count_subquery = CourseMember.where('course_id = courses.id AND role = 4').select('count(*)').to_sql
subquery = StudentWork.where('homework_common_id = hcs.id')
.select('sum(compelete_status !=0 ) as finish, count(*) as total')
.select('sum(compelete_status >0 ) as finish, count(*) as total')
.having('total != 0 and finish >= (total / 2)').to_sql
course_ids = Course.where('courses.created_at > ?', start_time)
.where('courses.created_at <= ?', end_time)
@ -149,7 +149,7 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController
def get_valid_course_count(ids)
percentage_sql = StudentWork.where('homework_common_id = homework_commons.id and homework_commons.publish_time is not null and homework_commons.publish_time < NOW()')
.select('sum(compelete_status !=0 ) as finish, count(*) as total')
.select('sum(compelete_status >0 ) as finish, count(*) as total')
.having('total != 0 and finish >= (total / 2)').to_sql
Course.joins(practice_homeworks: :homework_commons_shixun)
@ -160,7 +160,7 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController
def get_valid_shixun_count(ids)
percentage_sql = StudentWork.where('homework_common_id = homework_commons.id and homework_commons.publish_time is not null and homework_commons.publish_time < NOW()')
.select('sum(compelete_status !=0 ) as finish, count(*) as total')
.select('sum(compelete_status >0 ) as finish, count(*) as total')
.having('total != 0 and finish >= (total / 2)').to_sql
Shixun.joins(homework_commons_shixuns: :homework_common)
.where(homework_commons: { homework_type: 4 })

@ -6,10 +6,21 @@ module ControllerRescueHandler
Util.logger_error e
render json: {status: -1, message: e.message}
end
rescue_from ActiveRecord::StatementInvalid do |e|
Util.logger_error e
render json: {status: -1, message: "接口数据异常"}
end
rescue_from NoMethodError do |e|
Util.logger_error e
render json: {status: -1, message: "接口方法异常"}
end
rescue_from ActionController::UnknownFormat do |e|
render json: {status: -1, message: "接口调用非JSON格式"}
end
# rescue_from ActionView::MissingTemplate, with: :object_not_found
# rescue_from ActiveRecord::RecordNotFound, with: :object_not_found
rescue_from Educoder::TipException, with: :tip_show
@ -25,10 +36,6 @@ module ControllerRescueHandler
render_error(ex.record.errors.full_messages.join(','))
end
rescue_from ActionController::UnknownFormat do |e|
render json: {status: -1, message: "接口调用非JSON格式"}
end
# rescue_from RuntimeError do |ex|
# Util.logger_error "#######ex:#{ex}"
# render_error(ex.message)

@ -1,9 +1,9 @@
class CourseVideosController < ApplicationController
before_action :require_login
before_action :validate_params
before_action :validate_params, except: [:watch_histories]
before_action :find_course, only: [:create]
before_action :find_video, only: [:update]
before_action :teacher_allowed
before_action :find_video, only: [:update, :watch_histories]
before_action :teacher_allowed, except: [:watch_histories]
def create
title = params[:name].strip
@ -20,6 +20,32 @@ class CourseVideosController < ApplicationController
render_ok
end
def watch_histories
return normal_status(403, "你没有权限操作") if !current_user.teacher_of_course?(@course)
course_video = CourseVideo.find(@video.id)
@watch_course_videos = course_video.watch_course_videos.joins("
JOIN watch_video_histories ON watch_video_histories.watch_course_video_id = watch_course_videos.id AND watch_video_histories.end_at IS NOT NULL
JOIN course_members ON course_members.user_id = watch_course_videos.user_id AND course_members.course_id = #{@course.id} AND role = 4
").group("watch_video_histories.watch_course_video_id").where("watch_course_videos.end_at IS NOT NULL").select("watch_course_videos.id")
@count = @watch_course_videos.count.count
if params[:group_id].present?
@watch_course_videos = @watch_course_videos.where("course_members.course_group_id = ?", params[:group_id])
end
@watch_course_videos = @watch_course_videos.select("count(watch_course_videos.course_video_id) AS freq, watch_course_videos.id, watch_course_videos.user_id, watch_course_videos.start_at, watch_course_videos.end_at, watch_course_videos.is_finished, watch_course_videos.total_duration")
if params[:order].present?
key = params[:order].split("-")
if ["freq", 'total_duration'].include?(key.first) && ["desc", "asc"].include?(key.last)
@watch_course_videos = @watch_course_videos.order("#{key.first} #{key.last}")
end
end
@watch_course_videos = paginate @watch_course_videos
end
private
def validate_params

@ -30,7 +30,8 @@ class CoursesController < ApplicationController
:informs, :update_informs, :online_learning, :update_task_position, :tasks_list,
:join_excellent_course, :export_couser_info, :export_member_act_score, :new_informs,
:delete_informs, :change_member_role, :course_groups, :join_course_group, :statistics,
:work_score, :act_score, :calculate_all_shixun_scores, :move_to_category, :watch_video_histories]
:work_score, :act_score, :calculate_all_shixun_scores, :move_to_category, :watch_video_histories, :watch_statics,
:own_watch_histories]
before_action :user_course_identity, except: [:join_excellent_course, :index, :create, :new, :apply_to_join_course,
:search_course_list, :get_historical_course_students, :mine, :search_slim, :board_list]
before_action :teacher_allowed, only: [:update, :destroy, :settings, :search_teacher_candidate,
@ -98,28 +99,42 @@ class CoursesController < ApplicationController
limit = params[:limit] || 16
@courses = @courses.page(page).per(limit)
@courses = @courses.preload(:school, :none_hidden_course_modules, teacher: :user_extension)
@courses = @courses.preload(:school, :teacher_users, :none_hidden_course_modules, teacher: :user_extension)
end
def course_videos
videos = @course.course_videos
course_videos = @course.course_videos
course_videos = course_videos.joins("
LEFT JOIN videos ON course_videos.video_id = videos.id AND
((videos.transcoded = TRUE OR videos.user_id = #{current_user.id}) OR course_videos.is_link = TRUE)
LEFT JOIN (
SELECT watch_course_videos.course_video_id,
SUM(watch_course_videos.total_duration) AS total_duration,
count(watch_course_videos.course_video_id) AS count
FROM watch_course_videos
JOIN course_videos ON watch_course_videos.course_video_id = course_videos.id AND watch_course_videos.end_at IS NOT NULL
JOIN course_members ON course_members.user_id = watch_course_videos.user_id AND course_members.course_id = #{@course.id} AND role = 4
WHERE course_videos.course_id = #{@course.id}
GROUP BY watch_course_videos.course_video_id
) AS watch_courses ON watch_courses.course_video_id = course_videos.id
")
@video_module = @course.course_modules.find_by(module_type: "video")
if params[:category_id].present? && params[:category_id].to_i != 0
@category = @video_module&.course_second_categories.find_by(id: params[:category_id])
tip_exception("子目录id有误") if !@category.present?
videos = videos.where(course_second_category_id: params[:category_id].to_i)
course_videos = course_videos.where(course_second_category_id: params[:category_id].to_i)
end
videos = custom_sort(videos, params[:sort_by], params[:sort_direction])
course_videos = custom_sort(course_videos, params[:sort_by], params[:sort_direction])
course_videos = course_videos.includes(video: [user: :user_extension], user: :user_extension)
#sql = "left join videos on videos.id=course_videos.video_id AND (videos.transcoded=1 OR videos.user_id = #{current_user.id})"
#@videos = paginate videos.joins(sql).includes(video: [user: :user_extension], user: :user_extension)
videos = videos.includes(:watch_course_videos, video: [user: :user_extension],user: :user_extension)
videos = videos.where(videos: {transcoded: true})
.or(videos.where(videos: {user_id: current_user.id}))
.or(videos.where(course_videos: {is_link: true}))
@count = videos.count
@videos = paginate videos
@count = course_videos.count("course_videos.id")
logger.info("#######count:#{@count}")
course_videos = course_videos.select("course_videos.id, IFNULL(watch_courses.total_duration, 0) AS total_duration, IFNULL(watch_courses.count,0) AS count, course_videos.video_id, course_videos.title, course_videos.link, course_videos.is_link, course_videos.user_id")
@videos = paginate course_videos
end
def delete_course_video
@ -1291,6 +1306,7 @@ class CoursesController < ApplicationController
@user = current_user
@switch_student = Course::BUSINESS < @user_course_identity && @user_course_identity < Course::STUDENT
@is_student = @user_course_identity == Course::STUDENT
@teacher_users = @course.teacher_users.where.not(id: @course.tea_id).map(&:real_name)[0..3]
@course.increment!(:visits)
end
@ -1318,6 +1334,7 @@ class CoursesController < ApplicationController
def attahcment_category_list
@has_course_groups = @course.course_groups.exists?
@course_modules = @course.attachment_course_modules
@no_child = params[:no_child]
end
def mine
@ -1481,23 +1498,92 @@ class CoursesController < ApplicationController
end
end
# 课堂视频观看记录总览
def watch_video_histories
@videos = CourseVideo.find_by_sql("
SELECT course_videos.id, videos.user_id, videos.title, IFNULL(hisotries.time,0) AS time, IFNULL(hisotries.num,0) AS num
FROM course_videos
return normal_status(403, "你没有权限操作") unless current_user.teacher_of_course?(@course)
@videos = CourseVideo.joins("
JOIN videos ON course_videos.course_id = #{@course.id} AND videos.id = course_videos.video_id
LEFT JOIN (
SELECT watch_course_videos.course_video_id, SUM(watch_course_videos.total_duration) AS time, COUNT(watch_course_videos.course_video_id) AS num
FROM watch_course_videos
JOIN course_videos ON course_videos.id = watch_course_videos.course_video_id AND watch_course_videos.end_at IS NOT NULL
JOIN course_members ON course_members.user_id = watch_course_videos.user_id AND course_members.course_id = #{@course.id} AND role = 4
WHERE course_videos.course_id = #{@course.id}
GROUP BY watch_course_videos.course_video_id
) AS hisotries ON hisotries.course_video_id = course_videos.id").select("course_videos.id")
@count = @videos.count
if params[:order].present?
key = params[:order].split("-")
if ["people_num", 'total_time'].include?(key.first) && ["desc", "asc"].include?(key.last)
@videos = @videos.order("#{key.first} #{key.last}")
end
end
@videos = @videos.select("course_videos.id, videos.user_id, videos.title AS video_title, IFNULL(hisotries.time,0) AS total_time, IFNULL(hisotries.num,0) AS people_num")
@videos = paginate @videos
end
# 学生角度观看课堂视频的记录
def own_watch_histories
@current_user = current_user
@videos = CourseVideo.joins("
JOIN videos ON course_videos.course_id = #{@course.id} AND videos.id = course_videos.video_id
LEFT JOIN (
SELECT watch_course_videos.course_video_id, sum(watch_course_videos.total_duration) AS time, count(watch_course_videos.course_video_id) AS num
FROM watch_course_videos
JOIN watch_course_videos ON course_videos.id = watch_course_videos.course_video_id AND watch_course_videos.user_id = #{current_user.id}
JOIN (
SELECT watch_course_videos.id, COUNT(watch_video_histories.watch_course_video_id) AS num
FROM watch_course_videos
JOIN course_videos ON course_videos.id = watch_course_videos.course_video_id
WHERE course_videos.course_id = #{@course.id}
GROUP BY watch_course_videos.course_video_id
) AS hisotries ON hisotries.course_video_id = course_videos.id
")
JOIN course_members ON course_members.user_id = watch_course_videos.user_id AND course_members.course_id = #{@course.id} AND role = 4
JOIN watch_video_histories ON watch_course_videos.id = watch_video_histories.watch_course_video_id AND watch_video_histories.end_at IS NOT NULL
WHERE course_videos.course_id = #{@course.id} AND watch_course_videos.user_id = #{current_user.id} AND watch_course_videos.end_at IS NOT NULL
GROUP BY watch_course_videos.id
) AS hisotries ON hisotries.id = watch_course_videos.id ").select("course_videos.id")
@count = @videos.count
@videos = @videos.includes(video: :user)
if params[:order].present?
key = params[:order].split("-")
if ["freq", 'total_duration'].include?(key.first) && ["desc", "asc"].include?(key.last)
@videos = @videos.order("#{key.first} #{key.last}")
end
end
@videos = @videos.select("course_videos.id, watch_course_videos.id AS watch_course_video_id, course_videos.video_id, watch_course_videos.start_at, watch_course_videos.total_duration, watch_course_videos.end_at, watch_course_videos.is_finished, videos.title, IFNULL(hisotries.num,0) AS freq")
@videos = paginate @videos
end
# 课堂视频的统计总览
def watch_statics
course_videos = @course.course_videos.joins(:watch_course_videos).joins("JOIN course_members ON course_members.user_id = watch_course_videos.user_id AND course_members.course_id = #{@course.id} AND role = 4").where("watch_course_videos.end_at IS NOT NULL")
if params[:all].present?
return normal_status(403, "你没有权限操作") unless current_user.teacher_of_course?(@course)
@total_duration = course_videos.sum(:total_duration).round(0)
@frequencies = course_videos.joins("JOIN watch_video_histories ON watch_course_videos.id = watch_video_histories.watch_course_video_id AND watch_video_histories.end_at IS NOT NULL").count(:id)
@num = course_videos.count(:id)
else
course_videos = course_videos.where("course_members.user_id = #{current_user.id}")
@total_duration = course_videos.sum(:total_duration).round(0)
@frequencies = course_videos.joins("JOIN watch_video_histories ON watch_course_videos.id = watch_video_histories.watch_course_video_id AND watch_video_histories.end_at IS NOT NULL").count(:id)
@num = course_videos.count(:id)
end
render json: {
total_duration: @total_duration,
freq: @frequencies,
num: @num,
begin_at: '2020-03-13 24:00'
}
end
private
# Use callbacks to share common setup or constraints between actions.

@ -3,7 +3,7 @@ class ExaminationBanksController < ApplicationController
before_action :require_login
before_action :certi_identity_auth, only: [:create, :edit, :update, :destroy, :set_public, :revoke_item, :cancel_items]
before_action :find_exam, except: [:index, :create, :cancel_items]
before_action :edit_auth, only: [:update, :destroy, :set_public, :revoke_item, :cancel_items]
before_action :edit_auth, only: [:update, :set_public, :revoke_item, :cancel_items]
before_action :identity_auth, only: [:index]
def index
@ -52,6 +52,7 @@ class ExaminationBanksController < ApplicationController
end
def destroy
tip_exception(403, "无权限") unless current_user.admin? || @item.user == current_user
ActiveRecord::Base.transaction do
ApplyAction.where(container_type: "ExaminationBank", container_id: @exam.id).destroy_all
@exam.destroy!
@ -92,6 +93,6 @@ class ExaminationBanksController < ApplicationController
end
def edit_auth
current_user.admin_or_business? || @exam.user == current_user
tip_exception(403, "无权限") unless current_user.admin_or_business? || @exam.user == current_user
end
end

@ -102,18 +102,7 @@ class ExerciseAnswersController < ApplicationController
normal_status(-1,"已提交/已结束的试卷不允许修改!")
else
if (@exercise_user_status == Exercise::DEADLINE && @exercise_user.commit_status == 0) || (@exercise.time > 0 && @exercise_user.start_at.present? && ((@exercise_user.start_at + @exercise.time.to_i.minutes) < Time.now))
objective_score = calculate_student_score(@exercise,current_user,Time.now)[: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!(commit_option)
commit_exercise_user @exercise, @exercise_user
normal_status(-1,"试卷提交时间已截止!")
end
end

@ -614,31 +614,21 @@ class ExerciseQuestionsController < ApplicationController
@exercise_current_user.update!(ex_scores)
end
comments = params[:comment]
question_comment = @exercise_question.exercise_answer_comments&.first
if question_comment.present?
comment_option = {
:comment => comments,
:score => @c_score,
:exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil,
:user_id => current_user.id
}
question_comment.update!(comment_option)
@exercise_comments = question_comment
if @exercise_question.question_type == Exercise::PRACTICAL
shixun_answer = ExerciseShixunAnswer.find_by(exercise_question_id: @exercise_question.id, user_id: @user_id, exercise_shixun_challenge_id: @shixun_a_id)
answer_comment = shixun_answer&.exercise_answer_comments.take
else
ex_answer_comment_id = @exercise_question.exercise_answers.find_by(user_id: @user_id).try(:id)
comment_option = {
:user_id => current_user.id,
:comment => comments,
:score => @c_score,
:exercise_question_id => @exercise_question.id,
:exercise_shixun_answer_id => @shixun_a_id.present? ? @shixun_a_id : nil,
:exercise_answer_id => ex_answer_comment_id
}
@exercise_comments = ExerciseAnswerComment.new(comment_option)
@exercise_comments.save!
question_answer = ExerciseAnswer.find_by(exercise_question_id: @exercise_question.id, user_id: @user_id)
answer_comment = question_answer&.exercise_answer_comments.take
end
# 给被评阅人发送消息,同一个教师评阅无需重复发消息
if answer_comment.present?
answer_comment.update!(:comment => comments, :score => @c_score)
else
ExerciseAnswerComment.create!(:comment => comments, :score => @c_score, :user_id => current_user.id,
:exercise_question_id => @exercise_question.id, :exercise_shixun_answer_id => shixun_answer&.id,
:exercise_answer_id => question_answer&.id)
unless Tiding.where(user_id: @user_id, trigger_user_id: current_user.id, parent_container_id: @exercise.id, parent_container_type: "ExerciseScore").exists?
Tiding.create!(user_id: @user_id, trigger_user_id: current_user.id, container_id: @exercise.id,
@ -646,8 +636,42 @@ class ExerciseQuestionsController < ApplicationController
parent_container_type: "ExerciseScore", belong_container_id: @course.id,
belong_container_type: 'Course', tiding_type: "Exercise")
end
end
# question_comment = @exercise_question.exercise_answer_comments&.first
#
# if question_comment.present?
# comment_option = {
# :comment => comments,
# :score => @c_score,
# :exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil,
# :user_id => current_user.id
# }
# question_comment.update!(comment_option)
# @exercise_comments = question_comment
# else
# ex_answer_comment_id = @exercise_question.exercise_answers.find_by(user_id: @user_id).try(:id)
# comment_option = {
# :user_id => current_user.id,
# :comment => comments,
# :score => @c_score,
# :exercise_question_id => @exercise_question.id,
# :exercise_shixun_answer_id => @shixun_a_id.present? ? @shixun_a_id : nil,
# :exercise_answer_id => ex_answer_comment_id
# }
# @exercise_comments = ExerciseAnswerComment.new(comment_option)
# @exercise_comments.save!
#
# # 给被评阅人发送消息,同一个教师评阅无需重复发消息
#
# unless Tiding.where(user_id: @user_id, trigger_user_id: current_user.id, parent_container_id: @exercise.id, parent_container_type: "ExerciseScore").exists?
# Tiding.create!(user_id: @user_id, trigger_user_id: current_user.id, container_id: @exercise.id,
# container_type: "Exercise", parent_container_id: @exercise.id,
# parent_container_type: "ExerciseScore", belong_container_id: @course.id,
# belong_container_type: 'Course', tiding_type: "Exercise")
# end
#
# end
end
end

@ -774,10 +774,11 @@ class ExercisesController < ApplicationController
ex_group_setting = exercise.exercise_group_settings
old_exercise_groups = ex_group_setting.find_in_exercise_group("course_group_id", g_course) #试卷的分组设置
left_course_groups = teacher_course_group_ids - g_course
all_left_groups = all_course_group_ids - g_course
left_exercise_groups = ex_group_setting.find_in_exercise_group("course_group_id", left_course_groups)
if left_exercise_groups.blank? && exercise.unified_setting
if left_course_groups.size > 0 #开始为统一设置但是立即截止为分班。则创建没有立即截止的班级的exercise_group_setting
left_course_groups.each do |g|
if all_left_groups.size > 0 #开始为统一设置但是立即截止为分班。则创建没有立即截止的班级的exercise_group_setting
all_left_groups.each do |g|
ex_group_options = {
:exercise_id => exercise.id,
:course_group_id => g,
@ -815,7 +816,7 @@ class ExercisesController < ApplicationController
ex_user_ids = exercise_users.pluck(:id)
EndExerciseCalculateJob.perform_later(ex_user_ids, exercise, Time.now.to_s)
EndExerciseCalculateJob.perform_later(ex_user_ids, exercise.id, Time.now.to_s, true, 4)
# exercise_users.each do |user|
# if user.commit_status == 0 && user.start_at.present?
# objective_score = calculate_student_score(exercise,user.user)[:total_score]
@ -981,11 +982,17 @@ class ExercisesController < ApplicationController
@shixun_undo = 0
@ques_undo = 0
ex_answer_time = @exercise.time.to_i
exercise_user = @exercise.exercise_users.find_by(user_id: current_user.id)
if ex_answer_time > 0 #有剩余时间的时候
user_left_time = get_exercise_left_time(@exercise, current_user)
@ex_end_time = Time.now + user_left_time.to_i.seconds
# 提交用户试卷
commit_exercise_user @exercise, exercise_user if user_left_time.nil?
else
@ex_end_time = @exercise.get_exercise_end_time(current_user.id)
commit_exercise_user @exercise, exercise_user if @ex_end_time.present? && @ex_end_time < Time.now
end
# @ex_end_time = @exercise.get_exercise_end_time(current_user.id)
# if ex_answer_time > 0
@ -1032,20 +1039,7 @@ class ExercisesController < ApplicationController
can_commit_exercise = true
end
if can_commit_exercise
objective_score = calculate_student_score(@exercise, current_user, Time.now)[:total_score]
subjective_score = @answer_committed_user.subjective_score
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
total_score = objective_score + total_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,
:commit_method => @answer_committed_user&.commit_method.to_i > 0 ? @answer_committed_user&.commit_method.to_i : params[:commit_method].to_i
}
@answer_committed_user.update!(commit_option)
commit_exercise_user @exercise, @answer_committed_user, Time.now
CommitExercsieNotifyJobJob.perform_later(@exercise.id, current_user.id)
normal_status(0, "试卷提交成功!")
else
@ -1196,10 +1190,19 @@ class ExercisesController < ApplicationController
@exercise_users_size = @exercise_users_list.size
if @exercise.time > 0
start_time = Time.current - @exercise.time * 60
ex_user_ids = @exercise_users_list.where("start_at <= '#{Time.at(start_time)}' and commit_status = 0").pluck(:id)
if ex_user_ids.size > 0
EndExerciseCalculateJob.perform_later(ex_user_ids, @exercise.id, Time.now.to_s, false, 2)
end
end
# 分页
@page = params[:page] || 1
@limit = params[:limit] || 20
@exercise_users_list = @exercise_users_list.page(@page).per(@limit)
else
@exercise_users_list = []
@export_ex_users = @exercise_users_list

@ -32,8 +32,7 @@ class FilesController < ApplicationController
end
end
@attachments = @attachments.includes(author: [:user_extension, :course_members])
.ordered(sort: sort.to_i, sort_type: sort_type.strip)
@attachments = @attachments.ordered(sort: sort.to_i, sort_type: sort_type.strip)
@total_count = @attachments.size
@unlink_count = @attachments.no_link.size
@ -59,7 +58,8 @@ class FilesController < ApplicationController
@attachments = @attachments.no_link
end
@attachments = @attachments.page(@page).per(@page_size)
@attachments = @attachments.includes(:course_second_category, author: [:user_extension, :course_members])
.page(@page).per(@page_size)
end
def bulk_publish
@ -367,9 +367,9 @@ class FilesController < ApplicationController
@category_name = category.try(:module_name)
else
@category = CourseSecondCategory.find category_id
@category_id = category.try(:id)
@category_name = category.try(:name)
@parent_category_id = category&.parent_id.to_i
@category_id = @category.try(:id)
@category_name = @category.try(:name)
@parent_category_id = @category&.parent_id.to_i
end
end

@ -973,15 +973,15 @@ class GamesController < ApplicationController
if res && res['code'].to_i != 0
raise("实训云平台繁忙繁忙等级99")
end
# @vnc_url = res['showServer']
@vnc_url =
if request.subdomain == "pre-newweb" || request.subdomain == "test-newweb"
# 无域名版本
"http://#{service_host}:#{res['port']}/vnc_lite.html?password=headless"
else
# 有域名版本
"https://#{res['port']}.#{service_host}/vnc_lite.html?password=headless"
end
@vnc_url = res['showServer']
# @vnc_url =
# if request.subdomain == "pre-newweb" || request.subdomain == "test-newweb"
# # 无域名版本
# "http://#{service_host}:#{res['port']}/vnc_lite.html?password=headless"
# else
# # 有域名版本
# "https://#{res['port']}.#{service_host}/vnc_lite.html?password=headless"
# end
@vnc_evaluate = shixun.vnc_evaluate
rescue Exception => e
Rails.logger.error(e.message)

@ -11,7 +11,7 @@ class HomeworkCommonsController < ApplicationController
before_action :find_homework, only: [:edit, :show, :update, :group_list, :homework_code_repeat, :code_review_results,
:code_review_detail, :show_comment, :settings, :works_list, :update_settings,
:reference_answer, :publish_groups, :end_groups, :alter_name, :update_explanation,
:update_score, :update_student_score, :batch_comment]
:update_score, :update_student_score, :batch_comment, :get_next_work]
before_action :user_course_identity
before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer,
:update_student_score]
@ -230,7 +230,7 @@ class HomeworkCommonsController < ApplicationController
limit = params[:limit] || 20
@student_works = @student_works.page(page).per(limit)
if @homework.homework_type == "practice"
@student_works = @student_works.includes(:student_works_scores, :shixun_work_comments, user: :user_extension, myshixun: :games)
@student_works = @student_works.includes(:student_works_scores, :shixun_work_comments, :challenge_work_scores, user: :user_extension, myshixun: :games)
else
@student_works = @student_works.includes(:student_works_scores, :project, user: :user_extension)
end
@ -287,6 +287,15 @@ class HomeworkCommonsController < ApplicationController
end
end
def get_next_work
member = @course.course_member(current_user.id)
student_works = @homework.teacher_works(member).where.not(id: @homework.student_works_scores.where(reviewer_role: [1, 2]).pluck(:student_work_id))
if params[:work_id]
student_works = student_works.where.not(id: params[:work_id])
end
@work = student_works.where("work_status > 0").sample(1).first
end
def update_score
tip_exception("作业还未发布,暂不能计算成绩") if @homework.publish_time.nil? || @homework.publish_time > Time.now
@homework.update_homework_work_score
@ -937,8 +946,14 @@ class HomeworkCommonsController < ApplicationController
publish_groups = charge_group_ids & group_ids if group_ids
# ActiveRecord::Base.transaction do
messages = []
homeworks.each do |homework|
# 作业未发布时
max_end_time = params[:detail] ? group_end_times.max : params[:end_time]
if homework.allow_late && max_end_time.to_time >= homework.late_time
messages << "#{homework.name}"
next
end
if homework.homework_detail_manual.try(:comment_status) == 0
if !params[:group_ids].blank?
@ -1018,7 +1033,14 @@ class HomeworkCommonsController < ApplicationController
# 更新学生状态及成绩(手动点击计算)
# HomeworkPublishUpdateWorkStatusJob.perform_later(tiding_group_ids, homework.id)
end
normal_status(0, "发布成功")
unless messages.blank?
return_message = messages.join("")
return_message += messages.size == 1 ? "" : ""
return_message += "作业发布失败,原因:截止时间必须早于补交结束时间"
else
return_message = "发布成功"
end
normal_status(0, return_message)
# end
end

@ -3,7 +3,7 @@ class ItemBanksController < ApplicationController
before_action :require_login
before_action :certi_identity_auth, only: [:create, :edit, :update, :destroy, :set_public]
before_action :find_item, except: [:index, :create]
before_action :edit_auth, only: [:update, :destroy, :set_public]
before_action :edit_auth, only: [:update, :set_public]
before_action :identity_auth, only: [:index]
def index
@ -41,6 +41,7 @@ class ItemBanksController < ApplicationController
end
def destroy
tip_exception(403, "无权限") unless current_user.admin? || @item.user == current_user
ActiveRecord::Base.transaction do
ApplyAction.where(container_type: "ItemBank", container_id: @item.id).destroy_all
if @item.item_type == "PROGRAM"
@ -67,7 +68,7 @@ class ItemBanksController < ApplicationController
end
def edit_auth
current_user.admin_or_business? || @item.user == current_user
tip_exception(403, "无权限") unless current_user.admin_or_business? || @item.user == current_user
end
def form_params

@ -18,7 +18,8 @@ class MyshixunsController < ApplicationController
# 强制重置实训
# 前段需要按照操作过程提示
def reset_my_game
unless (current_user.admin? || current_user.id == @myshixun.user_id)
course = Course.find_by(id: params[:course_id])
unless (current_user.admin_or_business? || current_user.id == @myshixun.user_id) || (course.present? && current_user.course_identity(course) < Course::STUDENT)
tip_exception("403", "")
end
begin
@ -26,9 +27,15 @@ class MyshixunsController < ApplicationController
ActiveRecord::Base.transaction do
@myshixun.destroy!
StudentWork.where(:myshixun_id => @myshixun.id).includes(:shixun_work_comments, :student_works_scores, :challenge_work_scores).each do |work|
work.shixun_work_comments.destroy_all
work.student_works_scores.destroy_all
work.challenge_work_scores.destroy_all
end
StudentWork.where(:myshixun_id => @myshixun.id)
.update_all(myshixun_id: 0, work_status: 0, work_score: nil,
final_score: nil, efficiency: 0, eff_score: 0, calculation_time: nil, cost_time: 0, compelete_status: 0)
final_score: nil, efficiency: 0, eff_score: 0, calculation_time: nil, ultimate_score: 0, cost_time: 0, compelete_status: -1)
end
# 删除版本库
GitService.delete_repository(repo_path: @repo_path) unless @shixun.is_choice_type?

@ -18,19 +18,17 @@ class QuestionBanksController < ApplicationController
# 已认证才能获取题库
if @certification_teacher
sql = %Q{
#{@objects.table_name}.is_public = 1 and concat(#{@objects.table_name}.name, course_lists.name) like
'%#{params[:search]}%'
}
@objects.joins(:course_list).where(sql)
#{@objects.table_name}.is_public = 1 and concat(#{@objects.table_name}.name, course_lists.name) like :keyword
}
@objects.joins(:course_list).where(sql, keyword: "%#{params[:search]}%")
else
@objects.none
end
else
sql = %Q{
#{@objects.table_name}.user_id = #{current_user.id} and concat(#{@objects.table_name}.name, course_lists.name) like
'%#{params[:search]}%'
}
@objects.joins(:course_list).where(sql)
#{@objects.table_name}.user_id = #{current_user.id} and concat(#{@objects.table_name}.name, course_lists.name) like :keyword
}
@objects.joins(:course_list).where(sql, keyword: "%#{params[:search]}%")
end
else
if params[:filter] == 'public'

@ -477,6 +477,8 @@ class StudentWorksController < ApplicationController
@user_evaluate_count = 0
end
@view_tpi = ((@user_course_identity < Course::STUDENT && current_user.is_certification_teacher) || current_user.admin_or_business?) && @work.myshixun.present?
# 图形效率图的数据
@echart_data = student_efficiency(@homework, @work) if @work.myshixun
end
@ -555,7 +557,7 @@ class StudentWorksController < ApplicationController
@work.student_works_scores.where.not(score: nil).update_all(is_invalid: 1)
reviewer_role = @user_course_identity == Course::ASSISTANT_PROFESSOR ? 2 : 1
new_score = StudentWorksScore.new(student_work_id: @work.id, score: params[:score].to_f,
comment: "使用调分功能调整了作业最终成绩:#{params[:comment]}",
comment: params[:comment],
homework_common_id: @work.homework_common_id, user_id: current_user.id,
reviewer_role: reviewer_role, is_ultimate: 1)
new_score.save!

@ -17,7 +17,7 @@ class SubjectsController < ApplicationController
include CustomSortable
def index
subjects = Weapps::SubjectQuery.call(current_laboratory, params)
subjects = Weapps::SubjectQuery.call(current_laboratory, params, "web")
@subject_count = subjects.map(&:id).size
@subjects = paginate subjects.includes(:shixuns, :repertoire)
end
@ -244,7 +244,7 @@ class SubjectsController < ApplicationController
@subject.update_attributes(public: 1)
ApplyAction.create(container_type: "ApplySubject", container_id: @subject.id, user_id: current_user.id, status: 0)
begin
Educoder::Sms.send(mobile: '18711011226', send_type:'publish_subject' , name: '管理员')
Educoder::Sms.send(mobile: '17347001317', send_type:'publish_subject' , name: '管理员')
rescue => e
uid_logger_error("发送验证码出错: #{e}")
end

@ -12,7 +12,7 @@ class TidingsController < ApplicationController
case params[:type]
when 'notice' then 'System'
when 'apply' then 'Apply'
when 'course' then %w(HomeworkCommon Exercise Poll GraduationTask GraduationTopic)
when 'course' then %w(HomeworkCommon Exercise Poll GraduationTask GraduationTopic PublishCourseVideo)
when 'project' then 'Project'
when 'interaction' then %w(Comment Mentioned Praise Fan)
when 'project_package' then %w(Created Destroyed Bidding BiddingEnd BiddingWon BiddingLost)
@ -25,6 +25,8 @@ class TidingsController < ApplicationController
tidings = tidings.where(container_type: 'ProjectPackage') if params[:type] == 'project_package'
@count = tidings.count
@tidings = paginate(tidings.order(created_at: :desc), per_page: 10)
end

@ -5,7 +5,7 @@ class Users::CoursesController < Users::BaseController
courses = courses.where(id: current_laboratory.all_courses)
@count = courses.count
@courses = paginate(courses.includes(teacher: { user_extension: :school }), special: observed_user.is_teacher?)
@courses = paginate(courses.includes(:teacher_users, teacher: { user_extension: :school }), special: observed_user.is_teacher?)
end
private

@ -5,6 +5,6 @@ class WatchVideoHistoriesController < ApplicationController
watch_log = CreateWatchVideoService.new(current_user, request, params).call
render_ok(log_id: watch_log&.id)
rescue CreateWatchVideoService::Error => ex
render_error(ex.message)
render_ok(log_id: watch_log&.id)
end
end

@ -9,15 +9,17 @@ class Weapps::AttendancesController < ApplicationController
def create
ActiveRecord::Base.transaction do
attendance = @course.course_attendances.create!(create_params.merge(user_id: current_user.id))
unless params[:group_ids].blank? || @course.course_groups.where(id: params[:group_ids]).count == @course.course_groups.count
group_ids = @course.charge_group_ids(current_user) & params[:group_ids].map(&:to_i)
group_ids = params[:group_ids] || []
group_ids = group_ids.blank? ? @course.charge_group_ids(current_user) : @course.charge_group_ids(current_user) & params[:group_ids].map(&:to_i)
if group_ids.blank? || (params[:group_ids].blank? && @course.course_groups.where(id: group_ids).count == @course.course_groups.count)
@course.course_attendance_groups.create!(course_group_id: 0, course_attendance: attendance)
CreateStudentAttendanceRecordJob.perform_now(attendance.id, [0])
else
# group_ids = @course.charge_group_ids(current_user) & params[:group_ids].map(&:to_i)
group_ids.each do |group_id|
@course.course_attendance_groups.create!(course_group_id: group_id, course_attendance: attendance)
end
CreateStudentAttendanceRecordJob.perform_now(attendance.id, group_ids)
else
@course.course_attendance_groups.create!(course_group_id: 0, course_attendance: attendance)
CreateStudentAttendanceRecordJob.perform_now(attendance.id, [0])
end
render_ok({attendance_id: attendance.id})
end
@ -114,6 +116,8 @@ class Weapps::AttendancesController < ApplicationController
@course_members = @course.students if @_is_current_attendance
@all_attendances = @attendance.course_member_attendances
@user = @attendance.user
end
def update

@ -4,27 +4,36 @@ class Weapps::CourseMemberAttendancesController < ApplicationController
def index
attendance = CourseAttendance.find params[:attendance_id]
if attendance.course_attendance_groups.first&.course_group_id.to_i == 0
@members = attendance.course.students
else
@members = attendance.course.students.where(course_group_id: attendance.course_attendance_groups.pluck(:course_group_id))
end
@page = params[:page] || 1
@limit = params[:limit] || 5
@member_attendances = attendance.course_member_attendances
if params[:group_ids].present?
@members = @members.where(course_group_id: params[:group_ids])
@member_attendances = @member_attendances.joins(:course_member).where(course_members: {course_group_id: params[:group_ids]})
end
@member_attendances = @member_attendances.where(attendance_status: params[:attendance_status]) if params[:attendance_status].present?
@member_attendances = @member_attendances.order("attendance_status=1 desc, course_member_attendances.updated_at desc")
@members_count = @member_attendances.uniq.count
@member_attendances = paginate @member_attendances.preload(user: :user_extension)
if params[:attendance_status].present?
@members = @members.joins(:course_member_attendances).where(course_member_attendances: {course_attendance_id: attendance.id, attendance_status: params[:attendance_status]})
end
@members = @members.joins(:course_member_attendances).order("attendance_status=1 desc, course_member_attendances.updated_at desc")
@members_count = @members.uniq.count
@members = paginate @members.preload(user: :user_extension).uniq
# @member_attendances = @member_attendances.where(attendance_status: params[:attendance_status]) if params[:attendance_status].present?
# @member_attendances = @member_attendances.joins(user: :user_extension).order("attendance_status=1 desc, course_member_attendances.updated_at desc, user_extensions.student_id asc")
# @member_attendances = paginate @member_attendances.preload(user: :user_extension)
# if attendance.course_attendance_groups.first&.course_group_id.to_i == 0
# @members = attendance.course.students
# else
# @members = attendance.course.students.where(course_group_id: attendance.course_attendance_groups.pluck(:course_group_id))
# end
# @member_attendances = attendance.course_member_attendances
# if params[:group_ids].present?
# @members = @members.where(course_group_id: params[:group_ids])
# end
#
# if params[:attendance_status].present?
# @members = @members.joins(:course_member_attendances).where(course_member_attendances: {course_attendance_id: attendance.id, attendance_status: params[:attendance_status]})
# end
#
# @members = @members.joins(:course_member_attendances).order("attendance_status=1 desc, course_member_attendances.updated_at desc")
# @members_count = @members.uniq.count
# @members = paginate @members.preload(user: :user_extension).uniq
end
def create
@ -34,7 +43,7 @@ class Weapps::CourseMemberAttendancesController < ApplicationController
if params[:attendance_mode] == "QUICK"
attendance = CourseAttendance.find_by(id: params[:attendance_id])
else
attendance = CourseAttendance.find_by(attendance_code: params[:code])
attendance = CourseAttendance.find_by(id: params[:attendance_id], attendance_code: params[:code])
end
tip_exception("该签到不存在") if attendance.blank? || attendance.course.blank?

@ -76,6 +76,7 @@ class Weapps::CoursesController < Weapps::BaseController
def show
@course = current_course
@current_user = current_user
@teacher_users = @course.teacher_users.where.not(id: @course.tea_id).map(&:real_name)[0..3]
end
def shixun_homework_category

@ -19,7 +19,7 @@ class Weapps::HomesController < Weapps::BaseController
@courses = @courses.where(id: current_laboratory.all_courses)
@course_count = @courses.count
order_str = "course_members.sticky=1 desc, course_members.sticky_time desc, courses.created_at desc"
@courses = paginate(@courses.order(order_str).includes(:teacher, :school))
@courses = paginate(@courses.order(order_str).includes(:teacher_users, :teacher, :school))
@user = current_user
end
end

@ -4,7 +4,7 @@ class Weapps::SubjectsController < Weapps::BaseController
# 首页
def index
subjects = Weapps::SubjectQuery.call(current_laboratory, params)
subjects = Weapps::SubjectQuery.call(current_laboratory, params, "wechat")
@subject_count = subjects.map(&:id).size
@subjects = paginate subjects
end

@ -403,6 +403,8 @@ module TidingDecorator
def video_content
if tiding_type == 'System'
I18n.t(locale_format(tiding_type, status), reason: extra) % container.try(:title)
elsif tiding_type == 'PublishCourseVideo'
I18n.t(locale_format(tiding_type)) % [belong_container&.name]
else
I18n.t(locale_format(tiding_type)) % [container.try(:title) || extra]
end
@ -419,4 +421,5 @@ module TidingDecorator
def hack_content
I18n.t(locale_format(parent_container_type)) % (container&.name || extra)
end
end

@ -140,11 +140,11 @@ module ApplicationHelper
# 用户图像url如果不存在的话source为匿名用户即默认使用匿名用户图像
def url_to_avatar(source)
if File.exist?(disk_filename(source&.class, source&.id))
ctime = File.ctime(disk_filename(source.class, source.id)).to_i
ctime = File.ctime(disk_filename(source&.class, source&.id)).to_i
if source.class.to_s == 'User'
File.join(relative_path, ["#{source.class}", "#{source.id}"]) + "?t=#{ctime}"
File.join(relative_path, ["#{source&.class}", "#{source&.id}"]) + "?t=#{ctime}"
else
File.join("images/avatars", ["#{source.class}", "#{source.id}"]) + "?t=#{ctime}"
File.join("images/avatars", ["#{source&.class}", "#{source&.id}"]) + "?t=#{ctime}"
end
elsif source.class.to_s == 'User'
str = source.user_extension.try(:gender).to_i == 0 ? "b" : "g"

@ -81,6 +81,8 @@ module CoursesHelper
"/classrooms/#{course.id}/statistics"
when "video"
"/classrooms/#{course.id}/course_videos"
when "attendance"
"/classrooms/#{course.id}/attendances"
end
end
@ -131,31 +133,33 @@ module CoursesHelper
# 课堂模块的任务数
def course_task_count(course, module_type)
case module_type
when "shixun_homework"
get_homework_commons_count(course, 4, 0)
when "common_homework"
get_homework_commons_count(course, 1, 0)
when "group_homework"
get_homework_commons_count(course, 3, 0)
when "graduation"
0
when "exercise"
course.exercises_count
when "poll"
course.polls_count
when "attachment"
get_attachment_count(course, 0)
when "board"
course_board = course.course_board
course_board.present? ? course_board.messages.size : 0
when "course_group"
course.course_groups_count
when "announcement"
course.informs.count
when "online_learning"
course.shixuns.count
when "video"
course.videos_count + course.live_links.count
when "shixun_homework"
get_homework_commons_count(course, 4, 0)
when "common_homework"
get_homework_commons_count(course, 1, 0)
when "group_homework"
get_homework_commons_count(course, 3, 0)
when "graduation"
0
when "exercise"
course.exercises_count
when "poll"
course.polls_count
when "attachment"
get_attachment_count(course, 0)
when "board"
course_board = course.course_board
course_board.present? ? course_board.messages.size : 0
when "course_group"
course.course_groups_count
when "announcement"
course.informs.count
when "online_learning"
course.shixuns.count
when "video"
course.videos_count + course.live_links.count
when "attendance"
course.course_attendances.count
end
end
@ -247,7 +251,13 @@ module CoursesHelper
# 获取课堂的资源数
def get_attachment_count(course, category_id)
identity = current_user.course_identity(course)
attachments = category_id.to_i == 0 ? course.attachments : course.attachments.where(course_second_category_id: category_id)
if category_id.to_i == 0
attachments = course.attachments
else
# children_ids = CourseSecondCategory.where(parent_id: category_id).pluck(:id)
# category_ids = [category_id] + children_ids
attachments = course.attachments.joins(:course_second_category).where(course_second_categories: {id: category_id}).or(course.attachments.joins(:course_second_category).where(course_second_categories: {parent_id: category_id}))
end
identity > Course::ASSISTANT_PROFESSOR ? attachments.published.size : attachments.size
end

@ -961,4 +961,44 @@ module ExercisesHelper
def content_line(content)
content.split(/\r?\n/).length + 1
end
def commit_exercise_user exercise, exercise_user, commit_time = nil
exercise_end_time = exercise.get_exercise_end_time(exercise_user.user_id) #没有考虑分班的情况
objective_score = calculate_student_score(exercise, exercise_user.user, exercise_end_time)[:total_score]
subjective_score = exercise_user.subjective_score < 0.0 ? 0.0 : exercise_user.subjective_score
total_score = objective_score + subjective_score
if exercise.time > 0
start_time = Time.at(exercise_user.start_at + exercise.time * 60)
end_time = start_time > exercise_end_time ? exercise_end_time : start_time
commit_method = start_time > exercise_end_time ? 3 : 2
else
commit_method = 3
end_time = exercise_end_time
end
unless commit_time.nil?
commit_method = 1
end
commit_time = commit_time.present? && end_time > commit_time ? commit_time : end_time
commit_option = {
:status => 1,
:commit_status => 1,
:end_at => commit_time,
:objective_score => objective_score,
:score => total_score,
:subjective_score => subjective_score,
:commit_method => commit_method
}
exercise_user.update!(commit_option)
end
def has_comment? exercise_user, question_ids
exercise_answer_ids = exercise_user.user.exercise_answers.where(exercise_question_id: question_ids).pluck(:id)
exercise_shixun_answer_ids = exercise_user.user.exercise_shixun_answers.where(exercise_question_id: question_ids).pluck(:id)
exercise_user.commit_status == 1 && (exercise_user.exercise_user_scores.size > 0 ||
ExerciseAnswerComment.where(exercise_answer_id: exercise_answer_ids).or(ExerciseAnswerComment.where(exercise_shixun_answer_id: exercise_shixun_answer_ids)).exists?)
end
end

@ -457,7 +457,9 @@ module ExportHelper
course_name = course.students.find_by(user_id: w.user_id).try(:course_group_name)
w_5 = course_name.present? ? course_name : "--"
#0 未提交, 1 按时提交, 2 延迟提交
if w.compelete_status == 0
if w.compelete_status == -1
w_6 = "重做中"
elsif w.compelete_status == 0
w_6 = "未开启"
elsif w.compelete_status == 1
w_6 = "未通关"

@ -240,10 +240,16 @@ module HomeworkCommonsHelper
# 作品状态
def practice_homework_status homework, member
[{id: 0, name: "未开启", count: homework.compelete_status_count(member, 0)},
status_arr = [{id: 0, name: "未开启", count: homework.compelete_status_count(member, 0)},
{id: 1, name: "未通关", count: homework.compelete_status_count(member, 1)},
{id: 2, name: "按时通关", count: homework.compelete_status_count(member, 2)},
{id: 3, name: "迟交通关", count: homework.compelete_status_count(member, 3)}]
redo_count = homework.compelete_status_count(member, -1)
if redo_count > 0
status_arr.insert(1, {id: -1, name: "重做中", count: homework.compelete_status_count(member, -1)})
end
status_arr
end
# 作品状态

@ -2,7 +2,9 @@ module Weapps::AttendancesHelper
def student_attendance_status attendance, user
st_attendance = attendance.course_member_attendances.find_by(user_id: user.id)
st_attendance.present? ? st_attendance.attendance_status : "ABSENCE"
attendance_status = st_attendance.present? ? st_attendance.attendance_status : "ABSENCE"
attendance_mode = st_attendance.present? ? st_attendance.attendance_mode : "DEFAULT"
{attendance_status: attendance_status, attendance_mode: attendance_mode}
end
def group_attendance_count attendances, member_ids

@ -0,0 +1,25 @@
class CourseVideoUploadedJob < ApplicationJob
queue_as :notify
def perform(video_id)
video = Video.select("id, user_id").find_by(id: video_id)
course_ids = video&.course_videos&.pluck(:course_id)
return unless course_ids.present?
course_members = CourseMember.where(course_id: course_ids, role: 'STUDENT').select("id, user_id, course_id")
Tiding.bulk_insert do |worker|
course_members.find_each do |m|
worker.add(
user_id: m.user_id,
tiding_type: 'PublishCourseVideo',
trigger_user_id: video.user_id,
container_id: video.id,
container_type: 'Video',
belong_container_type: 'Course',
belong_container_id: m.course_id)
end
end
end
end

@ -0,0 +1,11 @@
class DeleteUnpublishVideoJob < ApplicationJob
queue_as :default
def perform(*args)
# "清理过时视频,一周之前用户还未确定上传的视频"
videos = Video.where(transcoded: false, delete_state: nil, status: 'pending').where("updated_at < '#{Time.now.days_ago(7)}'")
videos.find_each do |d|
d.destroy
end
end
end

@ -5,10 +5,14 @@ class EndExerciseCalculateJob < ApplicationJob
queue_as :default
def perform(ex_user_ids,exercise,end_time)
def perform(ex_user_ids,exercise_id,end_time,work_time,commit_method)
exercise = Exercise.find_by(id: exercise_id)
return if exercise.blank?
exercise_users = ExerciseUser.where(id: ex_user_ids)
exercise_users.each do |user|
if user.commit_status == 0 && user.start_at.present?
end_at = work_time ? end_time : Time.at(user.start_at + exercise.time * 60)
objective_score = calculate_student_score(exercise,user.user,end_time.to_time)[:total_score]
user_sub_score = user.subjective_score
subjective_score = user_sub_score < 0.0 ? 0.0 : user_sub_score
@ -16,11 +20,11 @@ class EndExerciseCalculateJob < ApplicationJob
commit_option = {
:status => 1,
:commit_status => 1,
:end_at => Time.now,
:end_at => end_at,
:objective_score => objective_score,
:score => total_score,
:subjective_score => user_sub_score,
:commit_method => user&.commit_method.to_i > 0 ? user&.commit_method.to_i : 4
:commit_method => user&.commit_method.to_i > 0 ? user&.commit_method.to_i : commit_method
}
user.update_attributes(commit_option)
end

@ -4,14 +4,14 @@ class StudentJoinAttendanceRecordJob < ApplicationJob
def perform(member_id)
member = CourseMember.find_by(id: member_id)
course = member&.course
return if member.blank? || course.blank?
return if member.blank? || member.role != "STUDENT" || course.blank?
current_date = Date.current
current_end_time = Time.current.strftime("%H:%M:%S")
group_ids = member.course_group_id == 0 ? [0] : [member.course_group_id, 0]
current_attendance_ids = course.course_attendances.joins(:course_attendance_groups).where(course_attendance_groups: {course_group_id: group_ids}).
where("(attendance_date = '#{current_date}' and start_time <= '#{current_end_time}' and end_time > '#{current_end_time}') or (attendance_date > '#{current_date}')").pluck(:id)
where("(attendance_date = '#{current_date}' and end_time > '#{current_end_time}') or (attendance_date > '#{current_date}')").pluck(:id)
all_group_attendance_ids = course.course_attendances.joins(:course_attendance_groups).where(course_attendance_groups: {course_group_id: 0}).pluck(:id)
member.course_member_attendances.where.not(course_attendance_id: all_group_attendance_ids+current_attendance_ids).delete_all

@ -11,7 +11,7 @@ module UserOnline
def set_bit(user_id, flag)
if !Rails.cache.data.exists(cache_key)
Rails.cache.data.setbit(cache_key, user_id, flag)
Rails.cache.data.expire(cache_key, 20 * 60 + 10)
Rails.cache.data.expire(cache_key, 2 * 60 + 10)
else
Rails.cache.data.setbit(cache_key, user_id, flag)
end
@ -27,11 +27,11 @@ module UserOnline
def cache_key
if Rails.cache.is_a?(ActiveSupport::Cache::RedisStore)
# 10分钟为一段记录用户在线, 统计范围为20分钟内的线用户
# 如设置2分钟内即120秒有请求的用户视为在线, 则最大会统计到4分钟内有活动用户
# TODO 更精确时长
begin_hour = Time.now.beginning_of_hour
minutes_piece = (Time.now - begin_hour) / 600
time = begin_hour.since((minutes_piece.to_i - 1) * 600).strftime("%H-%M")
minutes_piece = (Time.now - begin_hour) / 120
time = begin_hour.since((minutes_piece.to_i - 1) * 120).strftime("%H-%M")
"online_user_#{time}"
else
raise '请配置config.cache_store = redis_store'

@ -28,6 +28,7 @@ class Attachment < ApplicationRecord
scope :no_link, -> {where(link: nil)}
validates_length_of :description, maximum: 100, message: "不能超过100个字符"
validates :link, format: { with: CustomRegexp::URL, message: "必须为网址超链接" }, allow_blank: true
DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
@ -114,7 +115,7 @@ class Attachment < ApplicationRecord
def become_history
history = self.attachment_histories.first
new_attachment_history = AttachmentHistory.new(self.attributes.except("id", "resource_bank_id", "unified_setting", "course_second_category_id", "delay_publish").merge(
new_attachment_history = AttachmentHistory.new(self.attributes.except("id", "resource_bank_id", "unified_setting", "course_second_category_id", "delay_publish", "link").merge(
attachment_id: self.id,
version: history.nil? ? 1 : history.version + 1,
))
@ -122,7 +123,7 @@ class Attachment < ApplicationRecord
end
def copy_attributes_from_new_attachment(new_attachment)
self.attributes = new_attachment.attributes.dup.except("id","container_id","container_type","is_public","downloads", "quotes",'is_publish','publish_time', "delay_publish")
self.attributes = new_attachment.attributes.dup.except("id","container_id","container_type","is_public","downloads", "quotes",'is_publish','publish_time', "delay_publish", "link")
end
def set_public(is_public)

@ -69,13 +69,17 @@ class Challenge < ApplicationRecord
end
# 开启挑战
def open_game shixun
def open_game shixun, shixun_modify
# 这里的identifier,status是关联了games取了games的identifier,status
identifier = self.identifier
if identifier.present?
shixun.task_pass || self.status != 3 ? "/tasks/#{identifier}" : ""
if shixun_modify
"/shixuns/#{shixun.identifier}/shixun_exec.json"
else
(shixun.task_pass || self.status != 3) ? "/tasks/#{identifier}" : ""
end
else
self.position == 1 ? "/shixuns/#{shixun.identifier}/shixun_exec.json" : ""
(shixun.task_pass || position == 1) ? "/shixuns/#{shixun.identifier}/shixun_exec.json" : ""
end
end

@ -0,0 +1,7 @@
class Collection < ApplicationRecord
belongs_to :user
belongs_to :container, polymorphic: true, optional: true
scope :shixuns, -> {where(container_type: 'Shixun')}
scope :subjects, -> {where(container_type: 'Subject')}
end

@ -161,7 +161,7 @@ class Course < ApplicationRecord
end
def videos_count
course_videos.where(video_id: videos.where("transcoded = 1 or videos.user_id = #{User.current.id}").pluck(:id))
course_videos.where(video_id: videos.where("transcoded = 1"))
.or(course_videos.where(course_videos: {is_link: true})).size
end
@ -226,7 +226,7 @@ class Course < ApplicationRecord
end
def all_course_module_types
%w[activity announcement online_learning shixun_homework common_homework group_homework exercise attachment course_group graduation poll board statistics video]
%w[activity announcement online_learning shixun_homework common_homework group_homework exercise attachment course_group graduation poll board statistics video attendance]
end
def get_course_module_by_type(type)
@ -392,7 +392,7 @@ class Course < ApplicationRecord
# 课堂实训作业的评测次数
def evaluate_count
course_user_ids = students.pluck(:user_id)
shixun_ids = homework_commons.joins(:homework_commons_shixun).where(homework_type: 4).pluck(:shixun_id)
shixun_ids = homework_commons.joins(:homework_commons_shixun).where(homework_type: "practice").pluck(:shixun_id)
return 0 if shixun_ids.blank?
Game.joins(:challenge).where(challenges: {shixun_id: shixun_ids}, games: {user_id: course_user_ids}).sum(:evaluate_count)
end
@ -406,6 +406,15 @@ class Course < ApplicationRecord
homework_commons.select{|homework| homework.homework_type == type}.size
end
# 课堂作业数
def published_course_homework_count type
homework_commons.select{|homework| homework.homework_type == type && homework.publish_time.present? && homework.publish_time <= Time.now}.size
end
def student_works_count
StudentWork.joins(:homework_common).where(homework_commons: {course_id: id}).where("work_status > 0").size
end
private
#创建课程后,给该用户发送消息
@ -429,6 +438,7 @@ class Course < ApplicationRecord
when 'video' then '视频直播'
when 'board' then '讨论'
when 'course_group' then '分班'
when 'attendance' then '签到'
when 'statistics' then '统计'
else ''
end
@ -449,7 +459,8 @@ class Course < ApplicationRecord
when 'video' then 11
when 'board' then 12
when 'course_group' then 13
when 'statistics' then 14
when 'attendance' then 14
when 'statistics' then 15
else 100
end
end

@ -23,7 +23,7 @@ class CourseMember < ApplicationRecord
# after_destroy :delete_works
# after_create :work_operation
after_create :create_attendance_record
# after_create :create_attendance_record
after_commit :create_attendance_record
@ -165,7 +165,9 @@ class CourseMember < ApplicationRecord
private
def create_attendance_record
StudentJoinAttendanceRecordJob.perform_later(id)
if role == "STUDENT"
StudentJoinAttendanceRecordJob.perform_later(id)
end
end
end

@ -53,6 +53,9 @@ class Shixun < ApplicationRecord
has_many :shixun_service_configs, :dependent => :destroy
has_many :tidings, as: :container, dependent: :destroy
# 收藏
has_many :collections, as: :container, dependent: :destroy
# 实训审核记录
has_many :shixun_reviews, -> {order("shixun_reviews.created_at desc")}, :dependent => :destroy

@ -223,6 +223,16 @@ class StudentWork < ApplicationRecord
end
end
# 实训作品是否已被评阅过
def shixun_has_comment?
shixun_work_comments.size > 0 || student_works_scores.size > 0 || challenge_work_scores.size > 0
end
# 普通/分组作品是否已被评阅过
def work_has_comment?
student_works_scores.select{|score| score.reviewer_role < 3}.size > 0
end
def scored?
student_works_scores.where.not(reviewer_role: 3, score: nil).exists?
end

@ -16,6 +16,9 @@ class Subject < ApplicationRecord
has_many :subject_appointments, dependent: :destroy
# 收藏
has_many :collections, as: :container, dependent: :destroy
has_many :subject_members, ->{ order("subject_members.position asc")}, dependent: :destroy
has_many :users, through: :subject_members
has_many :tidings, as: :container, dependent: :destroy

@ -117,6 +117,11 @@ class User < ApplicationRecord
has_many :manage_course_members, -> { teachers_and_admin }, class_name: 'CourseMember'
has_many :manage_courses, through: :manage_course_members, source: :course
has_many :collections, dependent: :destroy
has_many :shixun_collections, -> { shixuns }, class_name: 'Collection'
has_many :subject_collections, -> { subjects }, class_name: 'Collection'
# 关注
# has_many :be_watchers, foreign_key: :user_id, dependent: :destroy # 我的关注
# has_many :be_watcher_users, through: :be_watchers, dependent: :destroy # 我关注的用户
@ -419,6 +424,10 @@ class User < ApplicationRecord
end
end
def is_collect? container
collections.where(container: container).exists?
end
# 实训用户身份
def shixun_identity(shixun)
@identity =

@ -3,7 +3,7 @@ class WatchCourseVideo < ApplicationRecord
belongs_to :user
has_many :watch_video_histories
has_one :watch_course_video_detail
validates :course_video_id, uniqueness: {scope: :user_id}
end

@ -0,0 +1,6 @@
class WatchCourseVideoDetail < ApplicationRecord
belongs_to :user
belongs_to :watch_course_video
serialize :times, Array
end

@ -2,13 +2,20 @@ class Weapps::SubjectQuery < ApplicationQuery
include CustomSortable
attr_reader :params
def initialize(current_laboratory, params)
def initialize(current_laboratory, params, device)
@current_laboratory = current_laboratory
@params = params
@device = device
end
def call
subjects = @current_laboratory.subjects.unhidden.publiced
Rails.logger.info("##### @device: #{@device}")
subjects =
if @device == "wechat"
@current_laboratory.subjects.unhidden.publiced.show_moblied
else
@current_laboratory.subjects.unhidden.publiced
end
# 课程体系的过滤
if params[:sub_discipline_id].present?
@ -21,7 +28,7 @@ class Weapps::SubjectQuery < ApplicationQuery
# 搜索
if params[:keyword].present?
subjects = subjects.where("subjects.name like '%#{params[:keyword]}%'")
subjects = subjects.where("subjects.name like :keyword", keyword: "%#{params[:keyword]}%")
end
subjects = subjects.left_joins(:shixuns, :repertoire).select('subjects.id, subjects.name, subjects.excellent, subjects.stages_count, subjects.status, subjects.homepage_show,
@ -33,10 +40,10 @@ class Weapps::SubjectQuery < ApplicationQuery
private
def order_type
params[:order] || "updated_at"
params[:order] == "updated_at" ? "updated_at" : "myshixuns_count"
end
def sort_type
params[:sort] || "desc"
params[:sort] == "desc" ? "desc" : "asc"
end
end

@ -9,6 +9,7 @@ class Admins::UpdateUserService < ApplicationService
end
def call
user.assign_attributes(user_attributes)
user.mail = params[:mail].to_s.presence
user.phone = params[:phone].to_s.presence
@ -36,8 +37,11 @@ class Admins::UpdateUserService < ApplicationService
private
def user_attributes
params.slice(*%i[lastname nickname mail phone admin business is_test
professional_certification authentication is_shixun_marker])
allow_attributes = %i[lastname nickname mail phone business is_test
professional_certification authentication is_shixun_marker admin_visitable]
allow_attributes.push(:admin) if user.admin?
params.slice(*allow_attributes)
end
def user_extension_attributes

@ -20,7 +20,7 @@ class AttendanceStatisticsService < ApplicationService
leave_count = history_member_count(member_attendances, "LEAVE", attendance.id)
all_count = member_attendances.select{|member_attendance| member_attendance.course_attendance_id == attendance.id}.size
normal_rate = cal_rate(normal_count, all_count)
normal_rate = all_count == 0 ? 1 : cal_rate(normal_count, all_count)
all_normal_rate << normal_rate
absence_rate = cal_rate(absence_count, all_count)
all_absence_rate << absence_rate
@ -34,7 +34,7 @@ class AttendanceStatisticsService < ApplicationService
all_history_count = history_attendances.size
history_attendances = history_attendances[0..9].reverse
avg_normal_rate = cal_rate(all_normal_rate.sum, all_history_count)
avg_normal_rate = all_history_count == 0 ? 1 : cal_rate(all_normal_rate.sum, all_history_count)
avg_absence_rate = cal_rate(all_absence_rate.sum, all_history_count)
avg_leave_rate = cal_rate(all_leave_rate.sum, all_history_count)

@ -10,33 +10,53 @@ class CreateWatchVideoService < ApplicationService
def call
ActiveRecord::Base.transaction do
current_time = Time.now
params[:watch_duration] = params[:watch_duration].to_f.round(2)
params[:total_duration] = params[:total_duration].to_f.round(2)
params[:duration] = params[:duration].to_f.round(2)
if params[:log_id].present?
if params[:total_duration].to_f < params[:watch_duration].to_f || params[:watch_duration].to_f < 0
raise Error, '观看时长错误'
end
# 更新观看时长
watch_video_history = user.watch_video_histories.find(params[:log_id])
if watch_video_history.present? && watch_video_history.watch_duration <= params[:watch_duration].to_f && params[:total_duration].to_f > watch_video_history.total_duration
# if params[:total_duration] < params[:watch_duration]
# return watch_video_history
# end
# 更新观看时长
if watch_video_history.present? && !watch_video_history.is_finished && watch_video_history.total_duration <= params[:total_duration]
# 如果观看总时长没变,说明视频没有播放,无需再去记录
watch_video_history.end_at = current_time
watch_video_history.total_duration = params[:total_duration]
watch_video_history.watch_duration = params[:watch_duration].to_f > watch_video_history.duration ? watch_video_history.duration : params[:watch_duration]
watch_video_history.watch_duration = params[:watch_duration] > watch_video_history.duration ? watch_video_history.duration : params[:watch_duration]
watch_video_history.is_finished = params[:ed].present?
watch_video_history.last_point = params[:point].to_i
watch_video_history.save!
watch_course_video = watch_video_history.watch_course_video
watch_course_video.total_duration = watch_course_video.watch_video_histories.sum(:total_duration)
watch_course_video.end_at = current_time
watch_course_video.save!
if watch_course_video.present?
watch_course_video.total_duration = watch_course_video.watch_video_histories.sum(:total_duration)
watch_course_video.end_at = current_time
if params[:point].to_i > watch_course_video.last_point
detail = WatchCourseVideoDetail.find_or_initialize_by(watch_course_video_id: watch_course_video.id, user_id: user.id) do |d|
d.times = [[ watch_course_video.last_point, params[:point].to_i]]
end
if detail.persisted?
detail.times << [watch_course_video.last_point, params[:point].to_i]
end
detail.save
end
watch_course_video.last_point = params[:point].to_i
if watch_course_video.present? && !watch_course_video.is_finished && watch_course_video.watch_duration < params[:watch_duration].to_f
# 更新课程视频的时长及是否看完状态
watch_course_video.watch_duration = params[:watch_duration]
if params[:ed].present?
watch_course_video.is_finished = watch_course_video.watch_video_histories.sum(:total_duration) >= watch_course_video.duration
if !watch_course_video.is_finished
# 更新课程视频的时长及是否看完状态
watch_course_video.watch_duration = params[:watch_duration] if watch_course_video.watch_duration < params[:watch_duration]
if params[:ed].present? || (watch_course_video.duration >= 300 && (watch_course_video.duration - params[:point].to_i) <= 20)
video_duration = watch_video_history.video.duration.to_i
if video_duration > 0
watch_course_video.is_finished = watch_course_video.total_duration.to_i >= video_duration
else
watch_course_video.is_finished = watch_course_video.total_duration.to_i >= watch_course_video.duration.to_i
end
end
end
watch_course_video.save!
end
@ -50,11 +70,10 @@ class CreateWatchVideoService < ApplicationService
d.start_at = current_time
d.duration = params[:duration]
end
watch_course_video.last_point = params[:point].to_i
watch_course_video.save!
watch_video_history = build_video_log(current_time, course_video.video_id, watch_course_video.id)
watch_video_history.save!
watch_course_video.save! unless watch_course_video.persisted?
else
# 非课堂视频
video = Video.find(params[:video_id])

@ -133,9 +133,9 @@ class HomeworksService
# 计算实训作品学生的效率分
def update_student_eff_score homework
if homework.work_efficiency && homework.max_efficiency != 0
max_efficiency = homework.student_works.where("compelete_status != 0").pluck(:efficiency).max
max_efficiency = homework.student_works.where("compelete_status > 0").pluck(:efficiency).max
homework.update_column("max_efficiency", max_efficiency)
homework.student_works.where("compelete_status != 0").each do |student_work|
homework.student_works.where("compelete_status > 0").each do |student_work|
eff_score = student_work.efficiency / max_efficiency * homework.eff_score
student_work.eff_score = format("%.2f", eff_score)
student_work.late_penalty = student_work.work_status == 1 ? 0 : homework.late_penalty
@ -146,7 +146,7 @@ class HomeworksService
student_work.save!
end
else
homework.student_works.where("compelete_status != 0").each do |student_work|
homework.student_works.where("compelete_status > 0").each do |student_work|
student_work.eff_score = 0
student_work.late_penalty = student_work.work_status == 1 ? 0 : homework.late_penalty
unless student_work.ultimate_score

@ -12,6 +12,7 @@ class CreateShixunService < ApplicationService
identifier = Util::UUID.generate_identifier(Shixun, 8)
shixun.identifier= identifier
shixun.user_id = user.id
shixun.can_copy = 1
main_mirror = MirrorRepository.find params[:main_type]
sub_mirrors = MirrorRepository.where(id: params[:sub_type])
begin

@ -24,8 +24,10 @@ class Users::ShixunService
user.study_shixuns.where(shixuns: {id: laboratory.shixuns})
when 'manage' then
laboratory.shixuns.where(id: user.shixuns)
when 'collect' then
laboratory.shixuns.where(id: user.shixun_collections.pluck(:container_id))
else
ids = user.study_shixuns.pluck(:id) + user.shixuns.pluck(:id)
ids = user.study_shixuns.pluck(:id) + user.shixuns.pluck(:id) + user.shixun_collections.pluck(:container_id)
laboratory.shixuns.where(id: ids)
end
end
@ -34,6 +36,8 @@ class Users::ShixunService
case params[:category]
when 'study' then
study_shixun_status_filter(relations)
when 'collect' then
collect_shixun_status_filter(relations)
when 'manage' then
manage_shixun_status_filter(relations)
else
@ -64,6 +68,16 @@ class Users::ShixunService
relations
end
def collect_shixun_status_filter relations
passed_shixun_ids = user.myshixuns.where(shixun_id: relations, status: 1).pluck(:shixun_id)
if params[:status] == 'passed'
relations = relations.where(id: passed_shixun_ids)
elsif params[:status] == 'processing'
relations = relations.where.not(id: passed_shixun_ids)
end
relations
end
def manage_shixun_status_filter(relations)
if params[:status] == "publiced"
relations = relations.where(public: 2)
@ -99,7 +113,7 @@ class Users::ShixunService
case params[:category]
when 'study' then
relations.order("myshixuns.#{sort_by} #{sort_direction}")
when 'manage' then
when 'manage', 'collect' then
relations.order("shixuns.#{sort_by} #{sort_direction}")
else
relations.order("shixuns.#{sort_by} #{sort_direction}")

@ -25,10 +25,13 @@ class Users::SubjectService
Subject.joins(stage_shixuns: { shixun: :myshixuns }).where(myshixuns: { user_id: user.id })
when 'manage' then
Subject.joins(:subject_members).where(subject_members: { user_id: user.id })
when 'collect' then
Subject.where(id: user.subject_collections.pluck(:container_id))
else
study_subject_ids = StageShixun.where(shixun_id: user.myshixuns.pluck(:shixun_id)).pluck(:subject_id)
manage_subject_ids = user.subject_members.pluck(:subject_id)
Subject.where(id: study_subject_ids + manage_subject_ids)
collect_subject_ids = user.subject_collections.pluck(:container_id)
Subject.where(id: study_subject_ids + manage_subject_ids + collect_subject_ids)
end
end
@ -45,7 +48,7 @@ class Users::SubjectService
return relations unless self_or_admin?
case params[:category]
when 'study' then
when 'study', 'collect' then
study_subject_status_filter(relations)
when 'manage' then
manage_subject_status_filter(relations)

@ -31,20 +31,28 @@ class Videos::BatchPublishService < ApplicationService
# 非MP4 H264编码的都转码
code_info = AliyunVod::Service.get_meta_code_info(video.uuid)
result = AliyunVod::Service.get_play_info(video.uuid) rescue nil
Rails.logger.info("code_info: #{code_info[:format]}, #{code_info[:codecnamne]}")
if code_info[:format] == "mp4" && code_info[:codecnamne].present? && code_info[:codecnamne].start_with?('h264')
video.transcoded = true
result = AliyunVod::Service.get_play_info(video.uuid) rescue nil
play_url = result['PlayInfoList']['PlayInfo'].first['PlayURL'] if result.present?
video.play_url = play_url
if result.present? && result['PlayInfoList']['PlayInfo'].first['PlayURL']
play_url = result['PlayInfoList']['PlayInfo'].first['PlayURL']
video.play_url = play_url
end
else
AliyunVod::Service.submit_transcode_job(video.uuid, Video::NORMAL_TRANSCODE_GROUP_ID)
end
if result.present?
video.duration = result['PlayInfoList']['PlayInfo'][0]['Duration'] if result['PlayInfoList']['PlayInfo'][0]['Duration'].present?
end
video.save!
if param[:course_id].present?
video.video_applies.create!(status: "agreed")
CourseVideoUploadedJob.perform_later(video.id) if video.transcoded
else
video.video_applies.create!
end

@ -22,6 +22,7 @@ class Videos::DispatchCallbackService < ApplicationService
when 'StreamTranscodeComplete' then # 转码完成
#return if video.play_url.present?
video.update!(play_url: params['FileUrl'], transcoded: true)
CourseVideoUploadedJob.perform_later(video.id) if video.video_applies.exists?(status: 'agreed') #通过的情况基本上是课堂视频
when 'DeleteMediaComplete' #完成云端视频删除
video.update_column(:delete_state, Video::FINISH_DELETE)
end

@ -34,11 +34,18 @@ class Weapps::ShixunSearchService < ApplicationService
unless params[:keyword].blank?
keyword = params[:keyword].strip
shixuns = shixuns.joins(:user).
where("concat(lastname, firstname) like :keyword or shixuns.name like :keyword",
keyword: "%#{keyword}%", name: "%#{keyword.split(" ").join("%")}%").distinct
where("concat(lastname, firstname) like :keyword or shixuns.name like :keyword",
keyword: "%#{keyword}%", name: "%#{keyword.split(" ").join("%")}%").distinct
end
shixuns.order("#{sort_str} #{order_str}")
order =
if sort_str == "wechat_myshixuns_count"
"is_wechat_support desc, myshixuns_count #{order_str}"
else
"#{sort_str} #{order_str}"
end
shixuns.order(order)
end
private

@ -3,25 +3,36 @@ wb = xlsx_package.workbook
wb.styles do |s|
blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 25,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center}
wb.add_worksheet(name: "课堂列表") do |sheet|
sheet.add_row %w(ID 课堂名称 成员 资源 普通作业 分组作业 实训作业 试卷 评测次数 私有 状态 单位 创建者 创建时间 动态时间), :height => 25,:style => blue_cell
sheet.add_row %w(ID 课堂名称 老师 学生 分班数 资源 公告 视频 视频学习时长 直播 普通作业 分组作业 实训作业 实训作业已发布数 作品数 试卷 评测次数 讨论数 私有 状态 单位 部门 创建者 创建时间), :height => 25,:style => blue_cell
@courses.each do |course|
course_board = course.course_board
topic_count = course_board.present? ? course_board.messages.size : 0
data = [
course.id,
course.name,
course.course_members_count,
course.teacher_course_members.size,
course.students.size,
course.course_groups_count,
get_attachment_count(course, 0),
course.course_homework_count(1),
course.course_homework_count(3),
course.course_homework_count(4),
course.informs.size,
course.course_videos.size,
course.course_videos.map{|cv| cv.watch_course_videos.map(&:total_duration).sum }.sum.round,
course.live_links.size,
course.course_homework_count("normal"),
course.course_homework_count("group"),
course.course_homework_count("practice"),
course.published_course_homework_count("practice"),
course.student_works_count,
course.exercises_count,
course.evaluate_count,
topic_count,
course.is_public == 1 ? "--" : "√",
course.is_end ? "已结束" : "正在进行",
course.school&.name,
course.teacher&.department_name,
course.teacher&.real_name,
course.created_at&.strftime('%Y-%m-%d %H:%M'),
course.max_activity_time ? course.max_activity_time&.strftime('%Y-%m-%d %H:%M') : "--"
]
sheet.add_row(data)
end

@ -3,18 +3,22 @@
<tr>
<th width="4%">序号</th>
<th width="4%">ID</th>
<th width="10%" class="text-left">课堂名称</th>
<th width="5%">成员</th>
<th width="8%" class="text-left">课堂名称</th>
<th width="4%">老师</th>
<th width="4%">学生</th>
<th width="4%">资源</th>
<th width="4%">公告</th>
<th width="4%">视频</th>
<th width="4%">普通作业</th>
<th width="4%">分组作业</th>
<th width="4%">实训作业</th>
<th width="4%">作品数</th>
<th width="4%">试卷</th>
<th width="6%">评测次数</th>
<th width="4%">私有</th>
<th width="6%">状态</th>
<th width="10%">单位</th>
<th width="7%">创建者</th>
<th width="4%">状态</th>
<th width="8%">单位</th>
<th width="6%">创建者</th>
<th width="10%"><%= sort_tag('创建时间', name: 'created_at', path: admins_courses_path) %></th>
<th width="4%">首页</th>
<th width="5%">邮件通知</th>

@ -3,11 +3,15 @@
<td class="text-left">
<%= link_to(course.name, "/classrooms/#{course.id}", target: '_blank') %>
</td>
<td><%= course.course_members_count %></td>
<td><%= course.teacher_course_members.size %></td>
<td><%= course.students.size %></td>
<td><%= get_attachment_count(course, 0) %></td>
<td><%= course.course_homework_count(1) %></td>
<td><%= course.course_homework_count(3) %></td>
<td><%= course.course_homework_count(4) %></td>
<td><%= course.informs.size %></td>
<td><%= course.course_videos.size %></td>
<td><%= course.course_homework_count("normal") %></td>
<td><%= course.course_homework_count("group") %></td>
<td><%= course.course_homework_count("practice") %></td>
<td><%= course.student_works_count %></td>
<td><%= course.exercises_count %></td>
<td><%= course.evaluate_count %></td>
<td><%= course.is_public == 1 ? "--" : "√" %></td>

@ -111,6 +111,7 @@
<%= f.input :admin, as: :boolean, label: '管理员', checked_value: 1, unchecked_value: 0 %>
<%= f.input :business, as: :boolean, label: '运营人员', wrapper_html: { class: 'ml-3' }, checked_value: 1, unchecked_value: 0 %>
<%= f.input :is_test, as: :boolean, label: '测试账号', wrapper_html: { class: 'ml-3' }, checked_value: 1, unchecked_value: 0 %>
<%= f.input :admin_visitable, as: :boolean, label: '允许查看后台', wrapper_html: { class: 'ml-3' }, checked_value: 1, unchecked_value: 0 %>
</div>
</div>
<% end %>

@ -0,0 +1,4 @@
json.(@attendance, :name, :mode, :attendance_date, :start_time, :end_time)
json.groups @groups do |group|
json.(group, :id, :name)
end

@ -1,5 +1,5 @@
json.attendances @attendances do |attendance|
json.(attendance, :id, :name, :normal_count, :all_count, :mode)
json.(attendance, :id, :name, :normal_count, :all_count, :mode, :attendance_code)
json.author do
user = attendance.user
json.user_name user.real_name
@ -11,7 +11,9 @@ json.attendances @attendances do |attendance|
json.edit_auth @user_course_identity < Course::PROFESSOR || attendance.user_id == User.current.id
if @user_course_identity == Course::STUDENT
json.attendance_status student_attendance_status(attendance, User.current)
student_attendance_status = student_attendance_status(attendance, User.current)
json.attendance_status student_attendance_status[:attendance_status]
json.attendance_mode student_attendance_status[:attendance_mode]
end
end

@ -22,7 +22,7 @@ if @challenges.present?
#json.playing_count @play_games_map.fetch(challenge.id, 0)
json.playing_count (challenge.games.count - user_passed_count)
json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
json.open_game challenge.open_game(@shixun)
json.open_game challenge.open_game(@shixun, @shixun_modify)
#json.open_game challenge.open_game(@shixun, @user.id)
if @editable
json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)

@ -0,0 +1,13 @@
json.data do
json.array! @watch_course_videos do |d|
json.id d.id
json.user_name d.user&.real_name
json.is_finished d.is_finished ? true : false
json.total_duration d.total_duration.round(0)
json.feq d['freq']
json.start_at d.start_at.to_s
json.end_at d.end_at.to_s
end
end
json.count @count

@ -1,12 +1,16 @@
json.has_course_groups @has_course_groups
json.course_modules do
json.array! @course_modules do |course_module|
json.id course_module.id
json.module_name course_module.module_name
json.course_second_categories course_module.first_categories do |category|
json.(category, :id, :name)
json.course_third_categories category.children do |child|
json.(child, :id, :name)
json.value course_module.id
json.title course_module.module_name.to_s + "(根目录)"
json.children course_module.first_categories do |category|
json.title category.name
json.value category.id
unless @no_child
json.children category.children do |child|
json.title child.name
json.value child.id
end
end
end
end

@ -9,9 +9,10 @@ json.videos @videos do |video|
json.user_img url_to_avatar(user)
json.user_login user&.login
else
json.course_video_id video.id
json.partial! 'users/videos/video', locals: { video: video.video }
json.total_time video.watch_course_videos.sum(:total_duration)
json.people_num video.watch_course_videos.count(:user_id)
json.total_time video['total_duration'].round(0)
json.people_num video['count']
end
end

@ -2,7 +2,7 @@ json.courses @courses do |course|
json.id course.id
json.name course.name
json.avatar_url url_to_avatar(course.teacher)
json.creator course.teacher.real_name
json.creator course.teacher&.real_name
json.school course.school&.name
json.technical_title "" # course.teacher.identity
json.course_members_count course.course_members_count
@ -13,5 +13,7 @@ json.courses @courses do |course|
json.is_end course.is_end
json.first_category_url module_url(course.none_hidden_course_modules.first, course)
json.excellent course.excellent
json.teacher_users course.teacher_users.select{|u| u.id != course.tea_id }.map(&:real_name)[0..3] # 取前4名老师
end
json.courses_count @courses_count

@ -30,6 +30,7 @@ json.course_modules @course_modules.each do |mod|
json.third_category category.children do |child|
json.partial! "category_info", category: child
json.parent_id child.parent_id
end
end
end

@ -0,0 +1,14 @@
json.data do
json.array! @videos.each do |d|
json.watch_course_video_id d['watch_course_video_id']
json.title d.title
json.user_name d.video.user&.real_name
json.is_finished d.is_finished == 1 ? true : false
json.total_duration d.total_duration.round(0)
json.freq d['freq']
json.start_at d.start_at.to_s
json.end_at d.end_at.to_s
end
end
json.count @count

@ -22,6 +22,8 @@ json.switch_to_assistant switch_assistant_role(@is_student, @course, @user)
#json.copy_course !@user.member_of_course?(@course) && @user.is_teacher?
json.course_identity @user_course_identity
json.excellent @course.excellent
# 协作老师
json.teacher_users @teacher_users
if @course.is_end == 0
json.days_remaining (@course.end_date.to_date - Time.now.to_date).to_i
end

@ -1,10 +1,10 @@
json.videos do
json.array! @videos do |v|
json.id v.id
json.title v.title
json.title v['video_title']
json.user_name v.user&.real_name
json.people_num v.num
json.total_time v.time
json.people_num v['people_num']
json.total_time v['total_time'].round(0)
end
end
json.count @count

@ -14,4 +14,5 @@ if subjective_type == 1
json.subjective_score ex_user_info[:ex_subject_score]
end
json.score ex_user_info[:score]
json.review_status ex_user_info[:teacher_review] #教师是否评阅评阅则为true否则为false
json.review_status ex_user_info[:teacher_review] #教师是否评阅评阅则为true否则为false
json.has_comment has_comment?(exercise_user, question_ids)

@ -37,7 +37,8 @@ end
if @current_user_ex_answers.present?
json.current_answer_user do
json.partial! "exercises/exercise_user",locals: {exercise_user:@current_user_ex_answers.first, subjective_type:@subjective_type,
user_status:@exercise_current_user_status, exercise:@exercise}
user_status:@exercise_current_user_status, exercise:@exercise,
question_ids: @exercise.exercise_questions.pluck(:id)}
end
end
@ -45,7 +46,8 @@ if @exercise_users_list.present?
json.exercise_users do
json.array! @exercise_users_list.each do |exercise_user|
json.partial! "exercises/exercise_user",locals: {exercise_user:exercise_user, subjective_type:@subjective_type,
user_status:@exercise_current_user_status, exercise:@exercise}
user_status:@exercise_current_user_status, exercise:@exercise,
question_ids: @exercise.exercise_questions.pluck(:id)}
end
end
else

@ -17,8 +17,14 @@ json.data do
end
# json.partial! "files/course_groups", attachment_group_settings: attachment.attachment_group_settings
json.category_id attachment.course_second_category_id
unless @parent_category_id.present? && @parent_category_id != 0
if @course_second_category_id.to_i == 0 && attachment.course_second_category.present?
json.category_name attachment.course_second_category&.name
json.parent_category_name attachment.course_second_category&.parent&.name
end
if @parent_category_id == 0 && attachment.course_second_category&.parent_id.to_i != 0
json.category_name attachment.course_second_category&.name
json.parent_category_name nil
end
end
end

@ -0,0 +1,2 @@
json.work_id @work&.id
json.user_name @work&.user&.real_name

@ -3,4 +3,5 @@ json.course_groups @course_groups do |group|
json.name group.name
json.end_time @group_settings.select{|group_setting| group_setting.course_group_id == group.id}.first&.end_time
end
json.end_time @homework.end_time
json.end_time @homework.end_time
json.late_time @homework.late_time

@ -103,6 +103,7 @@ if @homework.homework_type == "practice"
json.efficiency work_score_format(work.efficiency, @current_user == work.user, @score_open)
json.eff_score work_score_format(work.eff_score, @current_user == work.user, @score_open)
json.myshixun_identifier work.myshixun&.identifier
json.cost_time work.myshixun.try(:total_spend_time)
json.current_complete_count myshixun.try(:passed_count) if @homework.end_or_late
end_time = @homework.allow_late ? @homework.late_time : @homework.homework_group_setting(work.user_id)&.end_time
@ -114,7 +115,7 @@ if @homework.homework_type == "practice"
json.student_id work.user.try(:student_id)
json.group_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name)
json.work_status work.compelete_status
json.has_comment work.shixun_work_comments.size > 0
json.has_comment work.shixun_has_comment?
end
elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
json.anonymous_comment @homework.anonymous_comment
@ -175,7 +176,7 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
json.user_login @is_evaluation ? "--" : work.user.try(:login)
json.user_name @is_evaluation ? "匿名" : work.user.try(:real_name)
json.user_img @is_evaluation ? "--" : url_to_avatar(work.user)
json.has_comment work.work_has_comment?
end
end

@ -1,5 +1,7 @@
json.fork_from @fork_from
json.identity User.current.shixun_identity(@shixun)
json.is_collect User.current&.is_collect?(@shixun)
json.power @power
json.partial! 'shixuns/top', locals: { shixun: @shixun, current_myshixun: @current_myshixun }
json.secret_repository @shixun.shixun_secret_repository.present?

@ -1,4 +1,5 @@
json.homework_common_id @homework.id
json.course_id @homework.course_id
json.category @homework.category_info
json.course_name @course.name
json.work_id @work.id
@ -87,4 +88,9 @@ if @shixun
end
end
json.view_tpi @view_tpi
json.myshixun_id @work.myshixun_id
json.myshixun_identifier @work.myshixun&.identifier
json.homework_end @homework.end_or_late

@ -5,6 +5,8 @@ json.challenges_count @subject.subject_challenge_count
json.subject_score @subject.all_score
json.member_count @subject.member_count
json.is_collect @user&.is_collect?(@subject)
json.allow_delete (@subject.status != 2 && @is_creator) || @user.admin?
json.publish_status publish_status(@subject, @is_manager, @user)
json.allow_statistics @is_manager

@ -7,6 +7,8 @@ json.homework_commons_count get_tasks_count course
json.attachments_count course.attachments.count
json.visits course.visits
json.school course.school&.name
json.teacher_users course.teacher_users.select{|u| u.id != course.tea_id }.map(&:real_name)[0..3] # 取前4名老师
json.first_category_url module_url(course.course_modules.where(hidden: 0).order(position: :desc).first, course)

@ -2,4 +2,7 @@ json.(attendance, :id, :name, :mode)
json.attendance_date attendance.attendance_date.strftime("%Y/%m/%d")
json.start_time attendance.start_time.strftime("%H:%M")
json.end_time attendance.end_time.strftime("%H:%M")
json.attendance_status student_attendance_status(attendance, User.current)
student_attendance_status = student_attendance_status(attendance, User.current)
json.attendance_status student_attendance_status[:attendance_status]
json.attendance_mode student_attendance_status[:attendance_mode]

@ -9,6 +9,10 @@ json.name @attendance.name
json.attendance_date @attendance.attendance_date.strftime("%Y-%m-%d")
json.start_time @attendance.start_time.strftime("%H:%M")
json.end_time @attendance.end_time.strftime("%H:%M")
json.author do
json.user_name @user.real_name
json.user_login @user.login
end
# json.course_groups @group_ids do |group|
# json.(group, :id, :name, :course_members_count)

@ -1,14 +1,16 @@
# json.member_attendances @member_attendances.each do |member|
# json.(member, :user_id, :attendance_status)
# json.user_name member.user&.real_name
# json.student_id member.user&.student_id
# end
json.member_attendances @members.each do |member|
json.(member, :user_id)
json.member_attendances @member_attendances.each_with_index.to_a do |member, index|
json.(member, :user_id, :attendance_status)
json.index (@page.to_i - 1) * @limit.to_i + index + 1
json.user_name member.user&.real_name
json.student_id member.user&.student_id
json.attendance_status @member_attendances.select{|attendance| attendance.course_member_id == member.id}.first&.attendance_status || "ABSENCE"
end
# json.member_attendances @members.each_with_index.to_a do |member, index|
# json.(member, :user_id)
# json.index (@page.to_i - 1) * @limit.to_i + index + 1
# json.user_name member.user&.real_name
# json.student_id member.user&.student_id
# json.attendance_status @member_attendances.select{|attendance| attendance.course_member_id == member.id}.first&.attendance_status || "ABSENCE"
# end
json.members_count @members_count

@ -1,4 +1,5 @@
json.(@course, :id, :name, :course_members_count, :credit, :invite_code_halt)
json.teachers_count @course.teachers.count
json.students_count @course.students.count
json.course_identity @current_user.course_identity(@course)
json.course_identity @current_user.course_identity(@course)
json.teacher_users @teacher_users

@ -26,5 +26,6 @@ json.courses @courses.each do |course|
course_member = @category == "study" ? course.students.where(user_id: @user.id).first : course.teachers.where(user_id: @user.id).first
json.sticky course_member.sticky
json.course_identity current_user.course_identity(course)
json.teacher_users course.teacher_users.select{|u| u.id != course.tea_id }.map(&:real_name)[0..3] # 取前4名老师
end

@ -5,5 +5,6 @@ json.shixun_list @results do |obj|
json.study_count obj.myshixuns_count
json.author_name obj.user.real_name
json.author_img url_to_avatar(obj.user)
json.pic url_to_avatar(obj)
end
json.shixuns_count @total_count

@ -518,7 +518,6 @@ H漫画
胡启立
芮杏文
杨白冰
邹家华
谭绍文
王汉斌
任建新
@ -1378,5 +1377,3 @@ B样
傻 逼
真蠢
蠢猪

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save