From 495cebdd257dc9f767a916fd466ab9a952e3c0d9 Mon Sep 17 00:00:00 2001 From: anke1460 Date: Thu, 19 Mar 2020 02:36:23 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=97=B6=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/create_watch_video_service.rb | 7 ++++++- app/services/videos/batch_publish_service.rb | 13 ++++++++++--- db/migrate/20200318181442_add_duration_to_video.rb | 5 +++++ lib/tasks/get_video_data.rake | 13 +++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20200318181442_add_duration_to_video.rb diff --git a/app/services/create_watch_video_service.rb b/app/services/create_watch_video_service.rb index 4629d9c8e..4920374dc 100644 --- a/app/services/create_watch_video_service.rb +++ b/app/services/create_watch_video_service.rb @@ -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 >= video_duration + else + watch_course_video.is_finished = watch_course_video.total_duration >= watch_course_video.duration + end end end watch_course_video.save! diff --git a/app/services/videos/batch_publish_service.rb b/app/services/videos/batch_publish_service.rb index 553ffe4f2..1c3795102 100644 --- a/app/services/videos/batch_publish_service.rb +++ b/app/services/videos/batch_publish_service.rb @@ -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["VideoBase"]["Duration"] if result["VideoBase"]["Duration"] + end + video.save! if param[:course_id].present? diff --git a/db/migrate/20200318181442_add_duration_to_video.rb b/db/migrate/20200318181442_add_duration_to_video.rb new file mode 100644 index 000000000..caf3a70e9 --- /dev/null +++ b/db/migrate/20200318181442_add_duration_to_video.rb @@ -0,0 +1,5 @@ +class AddDurationToVideo < ActiveRecord::Migration[5.2] + def change + add_column :videos, :duration, :float, default: 0 + end +end diff --git a/lib/tasks/get_video_data.rake b/lib/tasks/get_video_data.rake index f6f85c7d5..3a86273ec 100644 --- a/lib/tasks/get_video_data.rake +++ b/lib/tasks/get_video_data.rake @@ -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["VideoBase"]["Duration"].present? + p '-----#{v.id} , #{result["VideoBase"]["Duration"]]}' + video.update(duration: result["VideoBase"]["Duration"]) + end + end + + end end \ No newline at end of file From 1e84cf48af09860f3e76dfae2adcd7aa9f3660d4 Mon Sep 17 00:00:00 2001 From: anke1460 Date: Thu, 19 Mar 2020 02:39:06 +0800 Subject: [PATCH 2/5] fix --- lib/tasks/get_video_data.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/get_video_data.rake b/lib/tasks/get_video_data.rake index 3a86273ec..3de199502 100644 --- a/lib/tasks/get_video_data.rake +++ b/lib/tasks/get_video_data.rake @@ -82,7 +82,7 @@ namespace :video do result = AliyunVod::Service.get_play_info(v.uuid) if result.present? && result["VideoBase"]["Duration"].present? p '-----#{v.id} , #{result["VideoBase"]["Duration"]]}' - video.update(duration: result["VideoBase"]["Duration"]) + v.update(duration: result["VideoBase"]["Duration"]) end end From 81de79240842e393a3c085d9d7813ae53e942c35 Mon Sep 17 00:00:00 2001 From: anke1460 Date: Thu, 19 Mar 2020 02:46:36 +0800 Subject: [PATCH 3/5] fix --- app/services/videos/batch_publish_service.rb | 4 ++-- lib/tasks/get_video_data.rake | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/services/videos/batch_publish_service.rb b/app/services/videos/batch_publish_service.rb index 1c3795102..3ddc54967 100644 --- a/app/services/videos/batch_publish_service.rb +++ b/app/services/videos/batch_publish_service.rb @@ -31,7 +31,7 @@ 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') @@ -45,7 +45,7 @@ class Videos::BatchPublishService < ApplicationService end if result.present? - video.duration = result["VideoBase"]["Duration"] if result["VideoBase"]["Duration"] + video.duration = result['PlayInfoList']['PlayInfo'][0]['Duration'] if result['PlayInfoList']['PlayInfo'][0]['Duration'].present? end video.save! diff --git a/lib/tasks/get_video_data.rake b/lib/tasks/get_video_data.rake index 3de199502..efb89e99e 100644 --- a/lib/tasks/get_video_data.rake +++ b/lib/tasks/get_video_data.rake @@ -80,9 +80,9 @@ namespace :video do videos = Video.published.where("duration = 0") videos.find_each do |v| result = AliyunVod::Service.get_play_info(v.uuid) - if result.present? && result["VideoBase"]["Duration"].present? - p '-----#{v.id} , #{result["VideoBase"]["Duration"]]}' - v.update(duration: result["VideoBase"]["Duration"]) + 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 From 208716a5bd260071de6575652678b3efa0e85194 Mon Sep 17 00:00:00 2001 From: anke1460 Date: Thu, 19 Mar 2020 03:20:39 +0800 Subject: [PATCH 4/5] fix --- app/services/create_watch_video_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/create_watch_video_service.rb b/app/services/create_watch_video_service.rb index 4920374dc..f637a2126 100644 --- a/app/services/create_watch_video_service.rb +++ b/app/services/create_watch_video_service.rb @@ -52,9 +52,9 @@ class CreateWatchVideoService < ApplicationService 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 >= video_duration + 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 >= watch_course_video.duration + watch_course_video.is_finished = watch_course_video.total_duration.to_i >= watch_course_video.duration.to_i end end end From 32d475c4c910cf362f6856003cce19f66a376b27 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 19 Mar 2020 12:23:22 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=8E=86=E5=8F=B2=E7=AD=BE=E5=88=B0?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E4=B8=AD=EF=BC=8C=E5=90=8E=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E7=9A=84=E5=AD=A6=E7=94=9F=E4=B8=8D=E9=9C=80=E8=A6=81=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E5=86=8D=E5=88=97=E8=A1=A8=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../course_member_attendances_controller.rb | 42 +++++++++++-------- .../index.json.jbuilder | 19 +++++---- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/app/controllers/weapps/course_member_attendances_controller.rb b/app/controllers/weapps/course_member_attendances_controller.rb index 254a89b1d..3dde09dbe 100644 --- a/app/controllers/weapps/course_member_attendances_controller.rb +++ b/app/controllers/weapps/course_member_attendances_controller.rb @@ -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 diff --git a/app/views/weapps/course_member_attendances/index.json.jbuilder b/app/views/weapps/course_member_attendances/index.json.jbuilder index 765de5833..43ce6ed44 100644 --- a/app/views/weapps/course_member_attendances/index.json.jbuilder +++ b/app/views/weapps/course_member_attendances/index.json.jbuilder @@ -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 \ No newline at end of file