From 60b3deb87fb790a5f46f145173099abaf41beed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Sun, 8 Mar 2020 23:52:55 +0800 Subject: [PATCH 01/27] =?UTF-8?q?=E5=88=A4=E6=96=AD=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/redux/actions/ojForm.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/public/react/src/redux/actions/ojForm.js b/public/react/src/redux/actions/ojForm.js index 62de0fed8..29e2ac13f 100644 --- a/public/react/src/redux/actions/ojForm.js +++ b/public/react/src/redux/actions/ojForm.js @@ -222,38 +222,52 @@ export const validateOjForm = (props, type, cb) => { } - try { + let boolflad=false; + try { if(ojForm.sub_discipline_id.length===0){ hasSuccess = false; notification['error']({ message: '提示', description: '课程必须选择!' }); - + boolflad=true; }else if(ojForm.timeLimit===null){ hasSuccess = false; notification['error']({ message: '提示', description: '时间限制必须输入!' }); - } else if(ojForm.name.length===0){ + boolflad=true; + + } else if(ojForm.name.length===0){ hasSuccess = false; notification['error']({ message: '提示', description: '任务名称必须输入!' }); - + boolflad=true; }else if(ojForm.description.length===0){ hasSuccess = false; notification['error']({ message: '提示', description: '描述必须输入!' }); - } + boolflad=true; + } }catch (e) { } + try { + if( hasSuccess === false){ + if(boolflad===true){ + props.changeSubmitLoadingStatus(false); + } + } + }catch (e) { + + } + From 9698648547b0dbf5153b2d85549f0a07b8fb6627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Mon, 9 Mar 2020 00:09:56 +0800 Subject: [PATCH 02/27] =?UTF-8?q?=E5=88=A4=E6=96=AD=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/modules/developer/newOrEditTask/index.js | 2 +- public/react/src/redux/actions/ojForm.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/public/react/src/modules/developer/newOrEditTask/index.js b/public/react/src/modules/developer/newOrEditTask/index.js index 43cad6106..f80cece44 100644 --- a/public/react/src/modules/developer/newOrEditTask/index.js +++ b/public/react/src/modules/developer/newOrEditTask/index.js @@ -112,7 +112,7 @@ const NewOrEditTask = (props) => { content: (

发布后即可应用到自己管理的课堂
是否确认发布?

), onOk() { changePublishLoadingStatus(true); - handlePublish(props, 'publish'); + props.handlePublish(props, 'publish'); } }); } diff --git a/public/react/src/redux/actions/ojForm.js b/public/react/src/redux/actions/ojForm.js index 29e2ac13f..783c6a793 100644 --- a/public/react/src/redux/actions/ojForm.js +++ b/public/react/src/redux/actions/ojForm.js @@ -267,6 +267,17 @@ export const validateOjForm = (props, type, cb) => { }catch (e) { } + try { + if( hasSuccess === false){ + if(boolflad===true){ + props.changePublishLoadingStatus(false); + } + } + }catch (e) { + + } + + From c4e44e144272e124bbdbd291474fdc8d9aa0250e Mon Sep 17 00:00:00 2001 From: anke1460 Date: Mon, 9 Mar 2020 20:03:10 +0800 Subject: [PATCH 03/27] =?UTF-8?q?=E8=BD=AC=E7=A0=81=E8=BD=AC=E7=A0=81?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/libs/aliyun_vod/service/video_manage.rb | 14 ++++++++++++++ app/libs/aliyun_vod/service/video_process.rb | 16 ++++++++++++++++ app/models/video.rb | 3 +++ app/services/videos/batch_publish_service.rb | 8 ++++++++ app/services/videos/dispatch_callback_service.rb | 5 +++-- .../20200309114326_add_transcoded_to_video.rb | 5 +++++ lib/tasks/video_transcode.rake | 12 ++++++++++++ 7 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20200309114326_add_transcoded_to_video.rb create mode 100644 lib/tasks/video_transcode.rake diff --git a/app/libs/aliyun_vod/service/video_manage.rb b/app/libs/aliyun_vod/service/video_manage.rb index 02a4bac49..b00d86892 100644 --- a/app/libs/aliyun_vod/service/video_manage.rb +++ b/app/libs/aliyun_vod/service/video_manage.rb @@ -26,6 +26,20 @@ module AliyunVod::Service::VideoManage result end + # 读取视频编码格式 + def get_meta_code_info(video_id) + params = { + Action: 'GetMezzanineInfo', + VideoId: video_id, + AdditionType: 'video' + }.merge(base_params) + + result = request(:post, params) + result['Mezzanine']['VideoStreamList'][0]['CodecName'] + rescue => e + Rails.logger.info "读取视频编码信息失败: #{video_id}, #{e.message}" + end + # 删除视频信息 def delete_video(video_ids) params = { diff --git a/app/libs/aliyun_vod/service/video_process.rb b/app/libs/aliyun_vod/service/video_process.rb index eec029c20..61acc4051 100644 --- a/app/libs/aliyun_vod/service/video_process.rb +++ b/app/libs/aliyun_vod/service/video_process.rb @@ -14,4 +14,20 @@ module AliyunVod::Service::VideoProcess result end + + # 提交视频转码任务 + def submit_transcode_job(video_id, group_id, **opts) + params = { + Action: 'SubmitTranscodeJobs', + VideoId: video_id, + TemplateGroupId: group_id + }.merge(base_params) + params = opts.merge(params) + + result = request(:post, params) + + raise AliyunVod::Error, '提交视频转码作业失败' if result['TranscodeJobs'].blank? + + result + end end \ No newline at end of file diff --git a/app/models/video.rb b/app/models/video.rb index 6f5f79ca6..02cccd8f1 100644 --- a/app/models/video.rb +++ b/app/models/video.rb @@ -1,6 +1,9 @@ class Video < ApplicationRecord include AASM + # 标准视频转码组 + NORMAL_TRANSCODE_GROUP_ID = 'a0277c5c0c7458458e171b0cee6ebf5e' + belongs_to :user has_many :video_applies, dependent: :destroy diff --git a/app/services/videos/batch_publish_service.rb b/app/services/videos/batch_publish_service.rb index 0523097a2..c9b1b69c7 100644 --- a/app/services/videos/batch_publish_service.rb +++ b/app/services/videos/batch_publish_service.rb @@ -28,6 +28,14 @@ class Videos::BatchPublishService < ApplicationService if param[:course_id].present? video.status = "published" end + + # 标清转码为h264 + if AliyunVod::Service.get_meta_code_info(video.uuid).start_with?('h264', 'h265', 'flv') + video.transcoded = true + else + AliyunVod::Service.submit_transcode_job(video.uuid, Video::NORMAL_TRANSCODE_GROUP_ID) + end + video.save! if param[:course_id].present? diff --git a/app/services/videos/dispatch_callback_service.rb b/app/services/videos/dispatch_callback_service.rb index 5adebea73..e81a52d3a 100644 --- a/app/services/videos/dispatch_callback_service.rb +++ b/app/services/videos/dispatch_callback_service.rb @@ -15,14 +15,15 @@ class Videos::DispatchCallbackService < ApplicationService video.file_url = convert_https(params['FileUrl']) video.filesize = params['Size'] video.upload_success + video.play_url = video.file_url if video.transcoded #不需要转码时,则统一播放地址 video.save! when 'SnapshotComplete' then # 封面截图完成 return if video.cover_url.present? video.update!(cover_url: params['CoverUrl']) - when 'TranscodeComplete' then # 转码完成 + when 'StreamTranscodeComplete' then # 转码完成 return if video.play_url.present? - video.update!(play_url: params['FileUrl']) + video.update!(play_url: params['FileUrl'], transcoded: true) end rescue => ex diff --git a/db/migrate/20200309114326_add_transcoded_to_video.rb b/db/migrate/20200309114326_add_transcoded_to_video.rb new file mode 100644 index 000000000..31e2764db --- /dev/null +++ b/db/migrate/20200309114326_add_transcoded_to_video.rb @@ -0,0 +1,5 @@ +class AddTranscodedToVideo < ActiveRecord::Migration[5.2] + def change + add_column :videos, :transcoded, :boolean, default: false + end +end diff --git a/lib/tasks/video_transcode.rake b/lib/tasks/video_transcode.rake new file mode 100644 index 000000000..a595b77b0 --- /dev/null +++ b/lib/tasks/video_transcode.rake @@ -0,0 +1,12 @@ +#coding=utf-8 +namespace :video_transcode do + desc "视频转码成h264" + task :submit => :environment do + Video.find_each do |v| + if v.uuid && v.transcoded == false && AliyunVod::Service.get_meta_code_info(v.uuid).start_with?("h264", "h265", "flv") == false + p "--- Start submit video trans code #{v.uuid}" + AliyunVod::Service.submit_transcode_job(v.uuid, 'a0277c5c0c7458458e171b0cee6ebf5e') + end + end + end +end \ No newline at end of file From 958a367f8f0bb4e410f39426b22d2dd9250ac388 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 10 Mar 2020 00:47:59 +0800 Subject: [PATCH 04/27] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course_video.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/course_video.rb b/app/models/course_video.rb index eb2a17595..2cfa151ce 100644 --- a/app/models/course_video.rb +++ b/app/models/course_video.rb @@ -3,6 +3,6 @@ class CourseVideo < ApplicationRecord belongs_to :video, optional: true belongs_to :user, optional: true - validates :title, length: { maximum: 60, too_long: "不能超过60个字符" } - validates :link, format: { with: CustomRegexp::URL, message: "必须为网址超链接" } + validates :title, length: { maximum: 60, too_long: "不能超过60个字符" }, allow_blank: true + validates :link, format: { with: CustomRegexp::URL, message: "必须为网址超链接" }, allow_blank: true end From 1ec306d877b2b6a1cb1c5acb936aa3c3e0753332 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 10 Mar 2020 01:16:57 +0800 Subject: [PATCH 05/27] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 13 ++++--- app/models/challenge.rb | 49 ++++++++++++++++-------- app/views/challenges/index.json.jbuilder | 12 +++--- 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index c69f5bbfb..1d68e3a6e 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -155,15 +155,16 @@ class ChallengesController < ApplicationController def index uid_logger("identifier: #{params}") - base_columns = "challenges.id, challenges.subject, challenges.st, challenges.score, challenges.position, - challenges.shixun_id, games.identifier, games.status" - join_sql = "LEFT JOIN games ON games.challenge_id = challenges.id AND games.user_id = #{current_user.id}" + #base_columns = "challenges.id, challenges.subject, challenges.st, challenges.score, challenges.position, + # challenges.shixun_id, games.identifier, games.status" + #join_sql = "LEFT JOIN games ON games.challenge_id = challenges.id AND games.user_id = #{current_user.id}" # 下面2个参数是为了解决列表获取通关人数与正在游玩人数的问题 - @pass_games_map = @shixun.challenges.joins(:games).where(games: {status:2}).group(:challenge_id).reorder(nil).count - @play_games_map = @shixun.challenges.joins(:games).where(games: {status:[0,1]}).group(:challenge_id).reorder(nil).count + #@pass_games_map = @shixun.challenges.joins(:games).where(games: {status:2}).group(:challenge_id).reorder(nil).count + #@play_games_map = @shixun.challenges.joins(:games).where(games: {status:[0,1]}).group(:challenge_id).reorder(nil).count - @challenges = @shixun.challenges.joins(join_sql).select(base_columns) + #@challenges = @shixun.challenges.joins(join_sql).select(base_columns) + @challenges = @shixun.challenges.fields_for_list @editable = @shixun.status == 0 # before_action:有判断权限,如果没发布,则肯定是管理人员 @user = current_user @shixun.increment!(:visits) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 5646da363..ca88efbb3 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -69,15 +69,16 @@ class Challenge < ApplicationRecord end # 开启挑战 - def open_game shixun - # 这里的identifier,status是关联了games取了games的identifier,status - identifier = self.identifier - if identifier.present? - shixun.task_pass || self.status != 3 ? "/tasks/#{identifier}" : "" - else - self.position == 1 ? "/api/shixuns/#{shixun.identifier}/shixun_exec" : "" - end - end + # def open_game shixun + # # 这里的identifier,status是关联了games取了games的identifier,status + # identifier = self.identifier + # if identifier.present? + # shixun.task_pass || self.status != 3 ? "/tasks/#{identifier}" : "" + # else + # self.position == 1 ? "/api/shixuns/#{shixun.identifier}/shixun_exec" : "" + # end + # end + # # 开启挑战 # def open_game(user_id, shixun) @@ -93,16 +94,16 @@ class Challenge < ApplicationRecord # end ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 - def user_tpi_status shixun + def user_tpi_status shixun, user_id # todo: 以前没加索引导致相同关卡,同一用户有多个games # 允许跳关则直接开启 - identifier = self.identifier - if identifier.blank? - self.position == 1 ? 1 : 0 + game = games.where(user_id: user_id).take + if game.blank? + position == 1 ? 1 : 0 else - if status == 3 + if game.status == 3 shixun.task_pass ? 1 : 0 - elsif status == 2 + elsif game.status == 2 2 else 1 @@ -110,6 +111,24 @@ class Challenge < ApplicationRecord end end + # ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 + # def user_tpi_status shixun + # # todo: 以前没加索引导致相同关卡,同一用户有多个games + # # 允许跳关则直接开启 + # identifier = self.identifier + # if identifier.blank? + # self.position == 1 ? 1 : 0 + # else + # if status == 3 + # shixun.task_pass ? 1 : 0 + # elsif status == 2 + # 2 + # else + # 1 + # end + # end + # end + def tags_show if self.challenge_tags.nil? "--" diff --git a/app/views/challenges/index.json.jbuilder b/app/views/challenges/index.json.jbuilder index d4f2a7f59..409514643 100644 --- a/app/views/challenges/index.json.jbuilder +++ b/app/views/challenges/index.json.jbuilder @@ -16,12 +16,12 @@ if @challenges.present? json.st challenge.st json.name challenge.subject json.score challenge.score - json.passed_count @pass_games_map.fetch(challenge.id, 0) - #json.passed_count challenge.user_passed_count - json.playing_count @play_games_map.fetch(challenge.id, 0) - #json.playing_count challenge.playing_count + #json.passed_count @pass_games_map.fetch(challenge.id, 0) + json.passed_count challenge.user_passed_count + #json.playing_count @play_games_map.fetch(challenge.id, 0) + json.playing_count challenge.playing_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) if @editable json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) @@ -29,6 +29,6 @@ if @challenges.present? json.down_url index_down_shixun_challenge_path(challenge, :shixun_identifier => @shixun.identifier) if @shixun.challenges_count != challenge.position end #json.passed challenge.has_passed?(@user.id) - json.status challenge.user_tpi_status(@shixun) + json.status challenge.user_tpi_status(@shixun, @user.id) end end From 1ee1984ca839f198600bad49dddbd94442b04434 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 10 Mar 2020 01:25:33 +0800 Subject: [PATCH 06/27] =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge.rb | 21 ++++++++------------- app/views/challenges/index.json.jbuilder | 1 + 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index ca88efbb3..68d55a582 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -79,19 +79,14 @@ class Challenge < ApplicationRecord # end # end - - # # 开启挑战 - # def open_game(user_id, shixun) - # - # - # game = self.games.select([:status, :identifier]).where(user_id: user_id).first - # game = self.games.select{|game| game.user_id == user_id} - # if game.present? - # shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" - # else - # "/api/shixuns/#{shixun.identifier}/shixun_exec" - # end - # end + def open_game user_id, shixun + game = self.games.where(user_id: user_id).first + if game.present? + shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" + else + self.position == 1 ? "/api/shixuns/#{shixun.identifier}/shixun_exec" : "" + end + end ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 def user_tpi_status shixun, user_id diff --git a/app/views/challenges/index.json.jbuilder b/app/views/challenges/index.json.jbuilder index 409514643..2eb8093a4 100644 --- a/app/views/challenges/index.json.jbuilder +++ b/app/views/challenges/index.json.jbuilder @@ -22,6 +22,7 @@ if @challenges.present? json.playing_count challenge.playing_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, @user.id) if @editable json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) From 518ee3aa324bc01a07e013c5529cb0a2cc885f0c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 10 Mar 2020 01:27:17 +0800 Subject: [PATCH 07/27] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 68d55a582..19a3bf1bb 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -79,7 +79,7 @@ class Challenge < ApplicationRecord # end # end - def open_game user_id, shixun + def open_game shixun, user_id game = self.games.where(user_id: user_id).first if game.present? shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" From 3cf27da3dc19cb5aecb26847e2e95e3137f9531e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 10 Mar 2020 01:32:25 +0800 Subject: [PATCH 08/27] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 2 +- app/models/challenge.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 1d68e3a6e..9b86bb87d 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -164,7 +164,7 @@ class ChallengesController < ApplicationController #@challenges = @shixun.challenges.joins(join_sql).select(base_columns) - @challenges = @shixun.challenges.fields_for_list + @challenges = @shixun.challenges.includes(:games).fields_for_list @editable = @shixun.status == 0 # before_action:有判断权限,如果没发布,则肯定是管理人员 @user = current_user @shixun.increment!(:visits) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 19a3bf1bb..e948a9bcc 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -142,12 +142,12 @@ class Challenge < ApplicationRecord # 关卡用户通关数 def user_passed_count - games.where(status: 2).count + games.map{|g| g.status == 2}.count end # 关卡用户正在挑战的人数 def playing_count - games.where(status: [0, 1]).count + games.map{|g| g.status == 0 || g.status == 1}.count end def last_challenge From 50d856fa1cde1e3062fefc3eb354e331ccbd3e7b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 10 Mar 2020 01:33:23 +0800 Subject: [PATCH 09/27] =?UTF-8?q?=E4=BC=98=E5=8C=96N+1=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index e948a9bcc..7c3c31ff9 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -80,7 +80,7 @@ class Challenge < ApplicationRecord # end def open_game shixun, user_id - game = self.games.where(user_id: user_id).first + game = self.games.map{|g| g.user_id == user_id}.first if game.present? shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" else From cb6acf22fea9ac3807c3c1974a9ce6ed04e69207 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 10 Mar 2020 01:36:20 +0800 Subject: [PATCH 10/27] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 9b86bb87d..47c8fc68c 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -155,16 +155,16 @@ class ChallengesController < ApplicationController def index uid_logger("identifier: #{params}") - #base_columns = "challenges.id, challenges.subject, challenges.st, challenges.score, challenges.position, - # challenges.shixun_id, games.identifier, games.status" - #join_sql = "LEFT JOIN games ON games.challenge_id = challenges.id AND games.user_id = #{current_user.id}" + base_columns = "challenges.id, challenges.subject, challenges.st, challenges.score, challenges.position, + challenges.shixun_id, games.identifier, games.status" + join_sql = "LEFT JOIN games ON games.challenge_id = challenges.id AND games.user_id = #{current_user.id}" # 下面2个参数是为了解决列表获取通关人数与正在游玩人数的问题 #@pass_games_map = @shixun.challenges.joins(:games).where(games: {status:2}).group(:challenge_id).reorder(nil).count #@play_games_map = @shixun.challenges.joins(:games).where(games: {status:[0,1]}).group(:challenge_id).reorder(nil).count - #@challenges = @shixun.challenges.joins(join_sql).select(base_columns) + @challenges = @shixun.challenges.joins(join_sql).select(base_columns) - @challenges = @shixun.challenges.includes(:games).fields_for_list + #@challenges = @shixun.challenges.fields_for_list @editable = @shixun.status == 0 # before_action:有判断权限,如果没发布,则肯定是管理人员 @user = current_user @shixun.increment!(:visits) From c9157cdf4265ef528f3cc717edfc00a8be7386ae Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 10 Mar 2020 01:40:21 +0800 Subject: [PATCH 11/27] =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge.rb | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 7c3c31ff9..50528b327 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -69,25 +69,25 @@ class Challenge < ApplicationRecord end # 开启挑战 - # def open_game shixun - # # 这里的identifier,status是关联了games取了games的identifier,status - # identifier = self.identifier - # if identifier.present? - # shixun.task_pass || self.status != 3 ? "/tasks/#{identifier}" : "" - # else - # self.position == 1 ? "/api/shixuns/#{shixun.identifier}/shixun_exec" : "" - # end - # end - - def open_game shixun, user_id - game = self.games.map{|g| g.user_id == user_id}.first - if game.present? - shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" + def open_game shixun + # 这里的identifier,status是关联了games取了games的identifier,status + identifier = self.identifier + if identifier.present? + shixun.task_pass || self.status != 3 ? "/tasks/#{identifier}" : "" else self.position == 1 ? "/api/shixuns/#{shixun.identifier}/shixun_exec" : "" end end + # def open_game shixun, user_id + # game = self.games.map{|g| g.user_id == user_id}.first + # if game.present? + # shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" + # else + # self.position == 1 ? "/api/shixuns/#{shixun.identifier}/shixun_exec" : "" + # end + # end + ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 def user_tpi_status shixun, user_id # todo: 以前没加索引导致相同关卡,同一用户有多个games @@ -142,12 +142,14 @@ class Challenge < ApplicationRecord # 关卡用户通关数 def user_passed_count - games.map{|g| g.status == 2}.count + #games.map{|g| g.status == 2}.count + self.games.where(status: 1).count end # 关卡用户正在挑战的人数 def playing_count - games.map{|g| g.status == 0 || g.status == 1}.count + #games.map{|g| g.status == 0 || g.status == 1}.count + self.games.where(status: [0,1]).count end def last_challenge From d79f182daf066dcc78af2624ac00b69bad9e532a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 10 Mar 2020 01:40:43 +0800 Subject: [PATCH 12/27] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/challenges/index.json.jbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/challenges/index.json.jbuilder b/app/views/challenges/index.json.jbuilder index 2eb8093a4..c86acc95b 100644 --- a/app/views/challenges/index.json.jbuilder +++ b/app/views/challenges/index.json.jbuilder @@ -21,8 +21,8 @@ if @challenges.present? #json.playing_count @play_games_map.fetch(challenge.id, 0) json.playing_count challenge.playing_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, @user.id) + json.open_game challenge.open_game(@shixun) + #json.open_game challenge.open_game(@shixun, @user.id) if @editable json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) From 9eb33593222501db22a6d4aeddca172700f1013a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 10 Mar 2020 01:43:58 +0800 Subject: [PATCH 13/27] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge.rb | 48 ++++++++++++------------ app/views/challenges/index.json.jbuilder | 3 +- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 50528b327..31a683760 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -89,34 +89,16 @@ class Challenge < ApplicationRecord # end ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 - def user_tpi_status shixun, user_id - # todo: 以前没加索引导致相同关卡,同一用户有多个games - # 允许跳关则直接开启 - game = games.where(user_id: user_id).take - if game.blank? - position == 1 ? 1 : 0 - else - if game.status == 3 - shixun.task_pass ? 1 : 0 - elsif game.status == 2 - 2 - else - 1 - end - end - end - - # ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 - # def user_tpi_status shixun + # def user_tpi_status shixun, user_id # # todo: 以前没加索引导致相同关卡,同一用户有多个games # # 允许跳关则直接开启 - # identifier = self.identifier - # if identifier.blank? - # self.position == 1 ? 1 : 0 + # game = games.where(user_id: user_id).take + # if game.blank? + # position == 1 ? 1 : 0 # else - # if status == 3 + # if game.status == 3 # shixun.task_pass ? 1 : 0 - # elsif status == 2 + # elsif game.status == 2 # 2 # else # 1 @@ -124,6 +106,24 @@ class Challenge < ApplicationRecord # end # end + # ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 + def user_tpi_status shixun + # todo: 以前没加索引导致相同关卡,同一用户有多个games + # 允许跳关则直接开启 + identifier = self.identifier + if identifier.blank? + self.position == 1 ? 1 : 0 + else + if status == 3 + shixun.task_pass ? 1 : 0 + elsif status == 2 + 2 + else + 1 + end + end + end + def tags_show if self.challenge_tags.nil? "--" diff --git a/app/views/challenges/index.json.jbuilder b/app/views/challenges/index.json.jbuilder index c86acc95b..6613dd888 100644 --- a/app/views/challenges/index.json.jbuilder +++ b/app/views/challenges/index.json.jbuilder @@ -30,6 +30,7 @@ if @challenges.present? json.down_url index_down_shixun_challenge_path(challenge, :shixun_identifier => @shixun.identifier) if @shixun.challenges_count != challenge.position end #json.passed challenge.has_passed?(@user.id) - json.status challenge.user_tpi_status(@shixun, @user.id) + #json.status challenge.user_tpi_status(@shixun, @user.id) + json.status challenge.user_tpi_status(@shixun) end end From 86adedc617ca2b7dead9902307c24b212058c0f6 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 10 Mar 2020 01:56:39 +0800 Subject: [PATCH 14/27] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=85=B3=E5=8D=A1?= =?UTF-8?q?=E4=BA=BA=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/challenges/index.json.jbuilder | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/challenges/index.json.jbuilder b/app/views/challenges/index.json.jbuilder index 6613dd888..eae72dad2 100644 --- a/app/views/challenges/index.json.jbuilder +++ b/app/views/challenges/index.json.jbuilder @@ -17,9 +17,10 @@ if @challenges.present? json.name challenge.subject json.score challenge.score #json.passed_count @pass_games_map.fetch(challenge.id, 0) - json.passed_count challenge.user_passed_count + user_passed_count = challenge.user_passed_count + json.passed_count user_passed_count #json.playing_count @play_games_map.fetch(challenge.id, 0) - json.playing_count challenge.playing_count + 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, @user.id) From b9ad459a9d629f31af15a4e3076106d80f6772b2 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 10 Mar 2020 02:04:13 +0800 Subject: [PATCH 15/27] =?UTF-8?q?=E6=89=93=E6=98=9F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 2 +- app/views/shixuns/_top.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 7e60983d1..b0bd191d2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -339,7 +339,7 @@ class User < ApplicationRecord # 实训管理员:实训合作者、admin def manager_of_shixun?(shixun) logger.info("############id: #{id}") - shixun.shixun_members.exists?(role: [1,2], user_id: id) || admin? || business? + shixun.shixun_members.exists?(user_id: id, role: [1,2]) || admin? || business? end # 实训管理员 diff --git a/app/views/shixuns/_top.json.jbuilder b/app/views/shixuns/_top.json.jbuilder index 362cfd15b..c90de5e5b 100644 --- a/app/views/shixuns/_top.json.jbuilder +++ b/app/views/shixuns/_top.json.jbuilder @@ -14,7 +14,7 @@ json.name shixun.name json.stu_num shixun.myshixuns_count json.experience shixun.all_score json.diffcult level_to_s(shixun.trainee) -json.score_info shixun.shixun_preference_info # todo: 这块可以改成只显示实训的平均分,不用每次都去取每种星的分数了。 +json.score_info shixun.averge_star # todo: 这块可以改成只显示实训的平均分,不用每次都去取每种星的分数了。 json.is_jupyter shixun.is_jupyter # 用于是否显示导航栏中的'背景知识' json.propaedeutics shixun.propaedeutics.present? From a6e05b9451b7b435422f60e580641e2749fe5331 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 10 Mar 2020 02:16:11 +0800 Subject: [PATCH 16/27] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/application_helper.rb | 2 ++ app/models/shixun.rb | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e352d6cec..d1d2499f0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -70,6 +70,8 @@ module ApplicationHelper # shixun开启挑战对应的行为名及url def task_operation_url current_myshixun, shixun + return ["开启挑战", "/shixuns/#{shixun.identifier}/shixun_exec"] unless current_user.logged? + if current_myshixun.blank? name = shixun.status == 0 ? "模拟实战" : "开启挑战" url = "/shixuns/#{shixun.identifier}/shixun_exec" diff --git a/app/models/shixun.rb b/app/models/shixun.rb index c3c5cec78..b9bd372b0 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -210,8 +210,9 @@ class Shixun < ApplicationRecord end # 当前用户开启的实训 - def current_myshixun(user_id) - myshixuns.find_by(user_id: user_id) + def current_myshixun(user) + return nil unless user.logged? + myshixuns.find_by(user_id: user.id) end # 实训技术平台 @@ -264,7 +265,7 @@ class Shixun < ApplicationRecord # 实训关卡的总分(由于大部分是实践题,因此没关联查choose表) # 提前加载问题:由于选择题比较少,所以几乎不会触发选择题的查询,所以没必要提前载入choose_score def all_score - self.challenges.pluck(:score).sum + self.challenges.sum(:score) end ### fork 数量 From 02fbc3bed0380961bce0bb832e1f72a63719d68b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 10 Mar 2020 09:56:17 +0800 Subject: [PATCH 17/27] =?UTF-8?q?=E8=A7=86=E9=A2=91=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/videos/batch_publish_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/videos/batch_publish_service.rb b/app/services/videos/batch_publish_service.rb index 7349799c9..306414dc3 100644 --- a/app/services/videos/batch_publish_service.rb +++ b/app/services/videos/batch_publish_service.rb @@ -49,7 +49,7 @@ class Videos::BatchPublishService < ApplicationService # 如果是课堂上传则创建课堂记录 Rails.logger.info("#####param: #{ param[:course_id]}") if param[:course_id].present? - course_second_category_id = params[:category_id] || 0 + course_second_category_id = param[:category_id] || 0 video.course_videos.create!(course_id: param[:course_id], course_second_category_id: course_second_category_id) end end From 487a9c3a8c68cc78b8ce6f156b78169964b3e2ad Mon Sep 17 00:00:00 2001 From: anke1460 Date: Tue, 10 Mar 2020 10:35:44 +0800 Subject: [PATCH 18/27] =?UTF-8?q?=E5=A4=84=E7=90=86=E9=9D=9E=E8=BD=AC?= =?UTF-8?q?=E7=A0=81=E8=A7=86=E9=A2=91=E6=92=AD=E6=94=BE=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/videos/batch_publish_service.rb | 4 +++- app/services/videos/dispatch_callback_service.rb | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/services/videos/batch_publish_service.rb b/app/services/videos/batch_publish_service.rb index 7349799c9..207fbdf56 100644 --- a/app/services/videos/batch_publish_service.rb +++ b/app/services/videos/batch_publish_service.rb @@ -30,8 +30,10 @@ class Videos::BatchPublishService < ApplicationService end # 标清转码为h264 - if AliyunVod::Service.get_meta_code_info(video.uuid).start_with?('h264', 'h265', 'flv') + if AliyunVod::Service.get_meta_code_info(video.uuid).start_with?('h264', 'h265') video.transcoded = true + result = AliyunVod::Service.get_play_info(video.uuid) + video.play_url = result['PlayInfoList']['PlayInfo'][0]['PlayURL'] else AliyunVod::Service.submit_transcode_job(video.uuid, Video::NORMAL_TRANSCODE_GROUP_ID) end diff --git a/app/services/videos/dispatch_callback_service.rb b/app/services/videos/dispatch_callback_service.rb index e81a52d3a..149009c96 100644 --- a/app/services/videos/dispatch_callback_service.rb +++ b/app/services/videos/dispatch_callback_service.rb @@ -15,7 +15,6 @@ class Videos::DispatchCallbackService < ApplicationService video.file_url = convert_https(params['FileUrl']) video.filesize = params['Size'] video.upload_success - video.play_url = video.file_url if video.transcoded #不需要转码时,则统一播放地址 video.save! when 'SnapshotComplete' then # 封面截图完成 return if video.cover_url.present? From 826f9cab6ac830a62ec840d9296668fe68697c01 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 10 Mar 2020 10:45:46 +0800 Subject: [PATCH 19/27] =?UTF-8?q?=E6=98=AF=E5=90=A6=E8=BD=AC=E7=A0=81?= =?UTF-8?q?=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/videos/_video.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/videos/_video.json.jbuilder b/app/views/users/videos/_video.json.jbuilder index dcf85fb75..1488d120f 100644 --- a/app/views/users/videos/_video.json.jbuilder +++ b/app/views/users/videos/_video.json.jbuilder @@ -1,4 +1,4 @@ -json.extract! video, :id, :title, :cover_url, :file_url, :play_url, :vv, :user_id +json.extract! video, :id, :title, :cover_url, :file_url, :play_url, :vv, :user_id, :transcoded json.play_duration video.video_play_duration json.published_at video.display_published_at From 51007d14e9194d833eeedfc5e6c557bfe54b9a72 Mon Sep 17 00:00:00 2001 From: anke1460 Date: Tue, 10 Mar 2020 10:58:18 +0800 Subject: [PATCH 20/27] =?UTF-8?q?=E8=A7=86=E9=A2=91=E8=BD=AC=E7=A0=81rake?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/video_transcode.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/video_transcode.rake b/lib/tasks/video_transcode.rake index a595b77b0..daababf33 100644 --- a/lib/tasks/video_transcode.rake +++ b/lib/tasks/video_transcode.rake @@ -3,7 +3,7 @@ namespace :video_transcode do desc "视频转码成h264" task :submit => :environment do Video.find_each do |v| - if v.uuid && v.transcoded == false && AliyunVod::Service.get_meta_code_info(v.uuid).start_with?("h264", "h265", "flv") == false + if v.uuid && v.transcoded == false && AliyunVod::Service.get_meta_code_info(v.uuid).start_with?("h264", "h265") == false p "--- Start submit video trans code #{v.uuid}" AliyunVod::Service.submit_transcode_job(v.uuid, 'a0277c5c0c7458458e171b0cee6ebf5e') end From fa43b7809cb192a039aed162a6353784e2d2e629 Mon Sep 17 00:00:00 2001 From: anke1460 Date: Tue, 10 Mar 2020 11:10:42 +0800 Subject: [PATCH 21/27] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E8=BD=AC=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/video_transcode.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/video_transcode.rake b/lib/tasks/video_transcode.rake index daababf33..7e461224e 100644 --- a/lib/tasks/video_transcode.rake +++ b/lib/tasks/video_transcode.rake @@ -3,7 +3,7 @@ namespace :video_transcode do desc "视频转码成h264" task :submit => :environment do Video.find_each do |v| - if v.uuid && v.transcoded == false && AliyunVod::Service.get_meta_code_info(v.uuid).start_with?("h264", "h265") == false + if v.uuid && !v.transcoded && !v.file_url.include?('.mp4') && !AliyunVod::Service.get_meta_code_info(v.uuid).start_with?("h264", "h265") p "--- Start submit video trans code #{v.uuid}" AliyunVod::Service.submit_transcode_job(v.uuid, 'a0277c5c0c7458458e171b0cee6ebf5e') end From 88dcf8e8f705fc09b4b50586594703008772e7a6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 10 Mar 2020 11:47:47 +0800 Subject: [PATCH 22/27] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E6=9D=83=E9=99=90?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 8 ++++++-- app/services/videos/batch_publish_service.rb | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 2e94e435d..de0603868 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -133,13 +133,17 @@ class CoursesController < ApplicationController # 视频移动到目录 def move_to_category + tip_exception("请选择要移动的目录") if params[:new_category_id].blank? category = @course.course_second_categories.find_by(id: params[:new_category_id]) if params[:new_category_id].to_i == 0 || category.present? - videos = @course.course_videos.where(video_id: params[:video_ids]).or(@course.course_videos.where(id: params[:video_ids])) + video = @course.course_videos.where(video_id: params[:video_ids]).or(@course.course_videos.where(id: params[:video_ids])).first + + tip_exception("您不是课堂管理员或者视频发布者,暂不能移动视频。") unless @user_course_identity < Course::PROFESSOR || + video.user_id == current_user.id || current_user.admin_or_business? - videos.update_all(course_second_category_id: params[:new_category_id]) + video.update!(course_second_category_id: params[:new_category_id]) normal_status(0, "操作成功") else normal_status(-1, "目录不存在") diff --git a/app/services/videos/batch_publish_service.rb b/app/services/videos/batch_publish_service.rb index 9ddcae146..5dd511de7 100644 --- a/app/services/videos/batch_publish_service.rb +++ b/app/services/videos/batch_publish_service.rb @@ -41,7 +41,7 @@ class Videos::BatchPublishService < ApplicationService # 如果是课堂上传则创建课堂记录 Rails.logger.info("#####param: #{ param[:course_id]}") if param[:course_id].present? - course_second_category_id = params[:category_id] || 0 + course_second_category_id = param[:category_id] || 0 video.course_videos.create!(course_id: param[:course_id], course_second_category_id: course_second_category_id) end end From 43d124b1992e115025ccb1172a03b511f5342daa Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 10 Mar 2020 11:58:35 +0800 Subject: [PATCH 23/27] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E7=9A=84=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index de0603868..ebdf8dfda 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -140,8 +140,9 @@ class CoursesController < ApplicationController if params[:new_category_id].to_i == 0 || category.present? video = @course.course_videos.where(video_id: params[:video_ids]).or(@course.course_videos.where(id: params[:video_ids])).first + user_id = video.user_id || video.video.user_id tip_exception("您不是课堂管理员或者视频发布者,暂不能移动视频。") unless @user_course_identity < Course::PROFESSOR || - video.user_id == current_user.id || current_user.admin_or_business? + user_id == current_user.id || current_user.admin_or_business? video.update!(course_second_category_id: params[:new_category_id]) normal_status(0, "操作成功") From d70917fbfc1b3055e66f24b74304dc12a226029b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 10 Mar 2020 12:02:43 +0800 Subject: [PATCH 24/27] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E7=9A=84=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index ebdf8dfda..426820701 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -141,8 +141,7 @@ class CoursesController < ApplicationController video = @course.course_videos.where(video_id: params[:video_ids]).or(@course.course_videos.where(id: params[:video_ids])).first user_id = video.user_id || video.video.user_id - tip_exception("您不是课堂管理员或者视频发布者,暂不能移动视频。") unless @user_course_identity < Course::PROFESSOR || - user_id == current_user.id || current_user.admin_or_business? + tip_exception("您不是课堂管理员或者视频发布者,暂不能移动视频。") unless @user_course_identity < Course::PROFESSOR || user_id == current_user.id video.update!(course_second_category_id: params[:new_category_id]) normal_status(0, "操作成功") From 7da4ad0c5b71359885769819914241cf03e27fec Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 10 Mar 2020 12:03:48 +0800 Subject: [PATCH 25/27] =?UTF-8?q?=E8=BD=AC=E7=A0=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 3 ++- app/views/users/videos/_video.json.jbuilder | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 2e94e435d..448a00ff9 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -112,7 +112,8 @@ class CoursesController < ApplicationController videos = custom_sort(videos, params[:sort_by], params[:sort_direction]) @count = videos.count - @videos = paginate videos.includes(video: [user: :user_extension], user: :user_extension) + sql = "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) end def delete_course_video diff --git a/app/views/users/videos/_video.json.jbuilder b/app/views/users/videos/_video.json.jbuilder index 1488d120f..5b0bc7a6e 100644 --- a/app/views/users/videos/_video.json.jbuilder +++ b/app/views/users/videos/_video.json.jbuilder @@ -1,5 +1,4 @@ json.extract! video, :id, :title, :cover_url, :file_url, :play_url, :vv, :user_id, :transcoded - json.play_duration video.video_play_duration json.published_at video.display_published_at json.created_at video.display_created_at From cc9592dd1932ab62515f726de259b8e113dcb1b5 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 10 Mar 2020 12:11:11 +0800 Subject: [PATCH 26/27] 1 --- app/controllers/courses_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 87e2d6a61..ec0a77759 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -112,7 +112,7 @@ class CoursesController < ApplicationController videos = custom_sort(videos, params[:sort_by], params[:sort_direction]) @count = videos.count - sql = "join videos on videos.id=course_videos.video_id AND (videos.transcoded=1 OR videos.user_id = #{current_user.id})" + 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) end From ac9d16bea2698d64296bdc6b268d6495a8fa0f81 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 10 Mar 2020 12:13:24 +0800 Subject: [PATCH 27/27] 1 --- app/controllers/courses_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index ec0a77759..c9fcb38ac 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -113,7 +113,8 @@ class CoursesController < ApplicationController videos = custom_sort(videos, params[:sort_by], params[:sort_direction]) @count = videos.count 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.joins(sql).reload + @videos = paginate videos.includes(video: [user: :user_extension], user: :user_extension) end def delete_course_video