diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index bba33bd8e..6ef43c694 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -205,8 +205,12 @@ class AttachmentsController < ApplicationController end def send_file_with_range(path, options = {}) + logger.info("########request.headers: #{request.headers}") + logger.info("########request.headers: #{File.exist?(path)}") + if File.exist?(path) size = File.size(path) + logger.info("########request.headers: #{request.headers}") if !request.headers["Range"] status_code = 200 # 200 OK offset = 0 diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index e820c383d..1f66555f9 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -242,7 +242,7 @@ class SubjectsController < ApplicationController ## 云上实验室过滤 @courses = @courses.where(id: current_laboratory.all_courses) - @none_shixun_ids = ShixunSchool.where("school_id != #{current_user.user_extension.try(:school_id).to_i}").pluck(:shixun_id) + @none_shixun_ids = @subject.shixuns.joins(:shixun_schools).where("school_id != #{current_user.user_extension.try(:school_id).to_i}").where(use_scope: 1).pluck(:id) end def send_to_course diff --git a/app/controllers/weapps/shixun_lists_controller.rb b/app/controllers/weapps/shixun_lists_controller.rb new file mode 100644 index 000000000..4db1e171f --- /dev/null +++ b/app/controllers/weapps/shixun_lists_controller.rb @@ -0,0 +1,15 @@ +class Weapps::ShixunListsController < ApplicationController + before_action :require_login + + def index + results = Weapps::ShixunSearchService.call(search_params, current_laboratory) + @total_count = results.size + @results = paginate results + end + + private + + def search_params + params.permit(:keyword, :type, :page, :limit, :order, :status, :diff, :sort, :no_jupyter) + end +end \ No newline at end of file diff --git a/app/models/course.rb b/app/models/course.rb index 1d5175ed3..eb7ffd91f 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -206,7 +206,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] + %w[activity announcement online_learning shixun_homework common_homework group_homework exercise attachment course_group graduation poll board statistics video] end def get_course_module_by_type(type) @@ -406,6 +406,7 @@ class Course < ApplicationRecord when 'exercise' then '试卷' when 'poll' then '问卷' when 'attachment' then '资源' + when 'video' then '视频' when 'board' then '讨论' when 'course_group' then '分班' when 'statistics' then '统计' @@ -425,9 +426,10 @@ class Course < ApplicationRecord when 'exercise' then 8 when 'poll' then 9 when 'attachment' then 10 - when 'board' then 11 - when 'course_group' then 12 - when 'statistics' then 13 + when 'video' then 11 + when 'board' then 12 + when 'course_group' then 13 + when 'statistics' then 14 else 100 end end diff --git a/app/services/videos/dispatch_callback_service.rb b/app/services/videos/dispatch_callback_service.rb index e4ad1628a..b32c87c4e 100644 --- a/app/services/videos/dispatch_callback_service.rb +++ b/app/services/videos/dispatch_callback_service.rb @@ -20,6 +20,9 @@ class Videos::DispatchCallbackService < ApplicationService return if video.cover_url.present? video.update!(cover_url: params['CoverUrl']) + when 'TranscodeComplete' then # 转码完成 + return if video.play_url.present? + video.update!(play_url: params['FileUrl']) end rescue => ex diff --git a/app/services/weapps/shixun_search_service.rb b/app/services/weapps/shixun_search_service.rb new file mode 100644 index 000000000..448bb1992 --- /dev/null +++ b/app/services/weapps/shixun_search_service.rb @@ -0,0 +1,53 @@ +class Weapps::ShixunSearchService < ApplicationService + + attr_reader :params, :laboratory + + def initialize(params, laboratory) + @params = params + @laboratory = laboratory + end + + def call + # 全部实训/我的实训 + type = params[:type] || "all" + shixuns = laboratory.shixuns.published.no_jupyter + + if type == "mine" + shixuns = shixuns.where(id: User.current.shixuns) + else + # 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭) + if User.current.admin? || User.current.business? || !User.current.school_id + shixuns = shixuns.where(hidden: 0) + else + shixun_ids = ShixunSchool.where(school_id: User.current.school_id).pluck(:shixun_id) + shixun_ids = shixun_ids.reject(&:blank?).length == 0 ? -1 : shixun_ids.join(",") + + shixuns = shixuns.where("use_scope = 0 or shixuns.id in (#{shixun_ids})").unhidden.publiced.or(shixuns.where(id: User.current.shixuns)) + end + end + + ## 筛选 难度 + if params[:diff].present? && params[:diff].to_i != 0 + shixuns = shixuns.where(trainee: params[:diff]) + end + + 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 + end + + shixuns.order("#{sort_str} #{order_str}") + end + + private + + def order_str + params[:order] || "desc" + end + + def sort_str + params[:sort] || "myshixuns_count" + end +end \ No newline at end of file diff --git a/app/views/subjects/choose_course.json.jbuilder b/app/views/subjects/choose_course.json.jbuilder index f5e33d4ee..2e03c5287 100644 --- a/app/views/subjects/choose_course.json.jbuilder +++ b/app/views/subjects/choose_course.json.jbuilder @@ -4,12 +4,19 @@ json.courses @courses do |course| json.created_at course.created_at end -json.stages @subject.stages do |stage| +json.stages @subject.stages.includes(shixuns: [user: :user_extension]) do |stage| index = 1 json.shixuns stage.shixuns do |shixun| - if shixun.status == 2 && !@none_shixun_ids.include?(shixun.id) + if shixun.status == 2 && !shixun.is_jupyter && !@none_shixun_ids.include?(shixun.id) json.shixun_id shixun.id + json.id shixun.id + json.identifier shixun.identifier json.shixun_name "#{stage.position}-#{index} #{shixun.name}" + json.title shixun.name + json.level level_to_s(shixun.trainee) + json.study_count shixun.myshixuns_count + json.author_name shixun.user.real_name + json.author_img url_to_avatar(shixun.user) end index += 1 end diff --git a/app/views/weapps/shixun_lists/index.json.jbuilder b/app/views/weapps/shixun_lists/index.json.jbuilder new file mode 100644 index 000000000..fac238f45 --- /dev/null +++ b/app/views/weapps/shixun_lists/index.json.jbuilder @@ -0,0 +1,9 @@ +json.shixun_list @results do |obj| + json.(obj, :id, :identifier) + json.title obj.name + json.level level_to_s(obj.trainee) + json.study_count obj.myshixuns_count + json.author_name obj.user.real_name + json.author_img url_to_avatar(obj.user) +end +json.shixuns_count @total_count \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 3eb02c95d..a4f8b80f6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1021,6 +1021,7 @@ Rails.application.routes.draw do post :cancel_sticky, on: :collection end + resources :shixun_lists, only: [:index] resources :subjects, path: :paths, only: [:index, :create, :update, :edit, :show] resources :courses, only: [:create, :update, :edit, :show] do diff --git a/db/migrate/20200207090252_add_video_to_course_module.rb b/db/migrate/20200207090252_add_video_to_course_module.rb new file mode 100644 index 000000000..1d0364524 --- /dev/null +++ b/db/migrate/20200207090252_add_video_to_course_module.rb @@ -0,0 +1,12 @@ +class AddVideoToCourseModule < ActiveRecord::Migration[5.2] + def change + Course.all.each do |course| + unless course.course_modules.exists?(module_type: "video") + atta_position = course.course_modules.find_by(module_type: 'attachment')&.position.to_i + video_position = atta_position != 0 ? (atta_position + 1) : 11 + course.course_modules.where("position >= #{video_position}").update_all("position = position + 1") + course.course_modules << CourseModule.new(module_type: "video", hidden: 1, module_name: "视频", position: video_position) + end + end + end +end diff --git a/lib/tasks/get_video_data.rake b/lib/tasks/get_video_data.rake index 05c33fb27..d38164923 100644 --- a/lib/tasks/get_video_data.rake +++ b/lib/tasks/get_video_data.rake @@ -45,9 +45,6 @@ namespace :video do task :get_play_url => :environment do Video.all.each do |video| - if video.uuid.present? - - end result = AliyunVod::Service.get_play_info(video.uuid) rescue nil if result.present? && result["PlayInfoList"]["PlayInfo"].present? puts result