Merge branches 'dev_aliyun' and 'develop' of https://bdgit.educoder.net/Hjqreturn/educoder into develop

courseware
杨树明 5 years ago
commit 87e80fe751

@ -4,30 +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
@member_attendances = attendance.course_member_attendances
if params[:group_ids].present?
@members = @members.where(course_group_id: params[:group_ids])
end
@page = params[:page] || 1
@limit = params[:limit] || 5
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]})
@member_attendances = attendance.course_member_attendances
if params[:group_ids].present?
@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)
@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

@ -50,7 +50,12 @@ class CreateWatchVideoService < ApplicationService
# 更新课程视频的时长及是否看完状态
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)
watch_course_video.is_finished = watch_course_video.total_duration >= watch_course_video.duration
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!

@ -31,16 +31,23 @@ 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?

@ -1,15 +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_with_index.to_a do |member, index|
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

@ -0,0 +1,5 @@
class AddDurationToVideo < ActiveRecord::Migration[5.2]
def change
add_column :videos, :duration, :float, default: 0
end
end

@ -74,4 +74,17 @@ namespace :video do
end
end
end
task :set_duration => :environment do
videos = Video.published.where("duration = 0")
videos.find_each do |v|
result = AliyunVod::Service.get_play_info(v.uuid)
if result.present? && result['PlayInfoList']['PlayInfo'][0]['Duration'].present?
p "-----#{v.id} , #{result['PlayInfoList']['PlayInfo'][0]['Duration']}"
v.update(duration: result['PlayInfoList']['PlayInfo'][0]['Duration'])
end
end
end
end
Loading…
Cancel
Save