From 5bcc9fbb41bca7b2d3b0d246b9c1f4a67ea7476e Mon Sep 17 00:00:00 2001 From: anke1460 Date: Tue, 17 Mar 2020 10:13:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E9=99=90=E5=AE=9A=E7=BB=9F=E8=AE=A1=E5=AD=A6=E7=94=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/course_videos_controller.rb | 5 ++--- app/controllers/courses_controller.rb | 11 ++++++++--- app/views/course_videos/watch_histories.json.jbuilder | 2 +- app/views/courses/own_watch_histories.json.jbuilder | 2 +- app/views/courses/watch_video_histories.json.jbuilder | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/controllers/course_videos_controller.rb b/app/controllers/course_videos_controller.rb index c5e0358cd..fe01c6226 100644 --- a/app/controllers/course_videos_controller.rb +++ b/app/controllers/course_videos_controller.rb @@ -26,14 +26,13 @@ class CourseVideosController < ApplicationController @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 + 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.joins(" - JOIN course_members ON course_members.user_id = watch_course_videos.user_id AND course_members.course_id = #{@course.id} - ").where("course_members.course_group_id = ?", params[:group_id]) + @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_video_histories.id) AS freq, watch_course_videos.*") diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index bdb5daae1..909f1c11d 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1494,6 +1494,7 @@ class CoursesController < ApplicationController 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") @@ -1523,6 +1524,7 @@ class CoursesController < ApplicationController SELECT watch_course_videos.course_video_id, 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 + 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} AND watch_course_videos.user_id = #{current_user.id} AND watch_course_videos.end_at IS NOT NULL GROUP BY watch_course_videos.course_video_id ) AS hisotries ON hisotries.course_video_id = course_videos.id").select("course_videos.id") @@ -1543,9 +1545,12 @@ class CoursesController < ApplicationController # 课堂视频的统计总览 def watch_statics - @total_duration = @course.course_videos.joins(:watch_course_videos).sum(:total_duration).round(2) - @frequencies = @course.course_videos.joins([watch_course_videos: :watch_video_histories]).count(:id) - @people_num = @course.course_videos.joins(:watch_course_videos).count(:id) + 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 + ") + @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").count(:id) + @people_num = course_videos.count(:id) render json: { total_duration: @total_duration, freq: @frequencies, diff --git a/app/views/course_videos/watch_histories.json.jbuilder b/app/views/course_videos/watch_histories.json.jbuilder index 705e2d6b7..2babab5d0 100644 --- a/app/views/course_videos/watch_histories.json.jbuilder +++ b/app/views/course_videos/watch_histories.json.jbuilder @@ -2,7 +2,7 @@ json.data do json.array! @watch_course_videos do |d| json.user_name d.user&.real_name json.is_finished d.is_finished ? true : false - json.total_duration d.total_duration.round(2) + 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 diff --git a/app/views/courses/own_watch_histories.json.jbuilder b/app/views/courses/own_watch_histories.json.jbuilder index 982939d9c..cc3b31eae 100644 --- a/app/views/courses/own_watch_histories.json.jbuilder +++ b/app/views/courses/own_watch_histories.json.jbuilder @@ -3,7 +3,7 @@ json.data do json.title d.title json.user_name @current_user&.real_name json.is_finished d.is_finished ? true : false - json.total_duration d.total_duration.round(2) + 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 diff --git a/app/views/courses/watch_video_histories.json.jbuilder b/app/views/courses/watch_video_histories.json.jbuilder index 207b9029b..8efab4a20 100644 --- a/app/views/courses/watch_video_histories.json.jbuilder +++ b/app/views/courses/watch_video_histories.json.jbuilder @@ -4,7 +4,7 @@ json.videos do json.title v.title json.user_name v.user&.real_name json.people_num v['people_num'] - json.total_time v['total_time'] + json.total_time v['total_time'].round(0) end end json.count @count \ No newline at end of file From 6e7bce87f4f408dfa302b849d75bc07b9f753fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=9E=97?= <904079904@qq.com> Date: Tue, 17 Mar 2020 10:45:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/modules/courses/Video/VideoIndex.js | 2 +- .../courses/videostatistics/Videostatistics.js | 10 ++++++---- .../component/Videostatisticscomtwo.js | 18 ++++++++++++++---- .../component/Videostatisticslist.js | 4 ++-- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/public/react/src/modules/courses/Video/VideoIndex.js b/public/react/src/modules/courses/Video/VideoIndex.js index d808ee787..787263cb0 100644 --- a/public/react/src/modules/courses/Video/VideoIndex.js +++ b/public/react/src/modules/courses/Video/VideoIndex.js @@ -382,7 +382,7 @@ class VideoIndex extends Component { isAdmin? this.statisticsy(b)}> : - + ) } { diff --git a/public/react/src/modules/courses/videostatistics/Videostatistics.js b/public/react/src/modules/courses/videostatistics/Videostatistics.js index ddd8c8deb..f497b3ca6 100644 --- a/public/react/src/modules/courses/videostatistics/Videostatistics.js +++ b/public/react/src/modules/courses/videostatistics/Videostatistics.js @@ -14,6 +14,7 @@ class Videostatistics extends Component{ watch_staticsdata:[], tisticsbool:false, tisid:null, + mytitle:"" } @@ -43,16 +44,17 @@ class Videostatistics extends Component{ }); } - tisticsbools=(bool,id)=>{ + tisticsbools=(bool,id,mytitle)=>{ this.setState({ tisticsbool:bool, tisid:id, + mytitle:mytitle }) } render(){ - let {watch_staticsdata,tisticsbool,tisid}= this.state; + let {watch_staticsdata,tisticsbool,tisid,mytitle}= this.state; return( @@ -79,13 +81,13 @@ class Videostatistics extends Component{
- this.tisticsbools(b,id)}> + this.tisticsbools(b,id,t)}>
: - this.tisticsbools(b,id)}> + this.tisticsbools(b,id,t)}> } diff --git a/public/react/src/modules/courses/videostatistics/component/Videostatisticscomtwo.js b/public/react/src/modules/courses/videostatistics/component/Videostatisticscomtwo.js index 51673aa38..b64cd06ac 100644 --- a/public/react/src/modules/courses/videostatistics/component/Videostatisticscomtwo.js +++ b/public/react/src/modules/courses/videostatistics/component/Videostatisticscomtwo.js @@ -207,6 +207,7 @@ class Videostatisticscomtwo extends Component { feq: response.data.data[i].feq, start_at: response.data.data[i].start_at, end_at: response.data.data[i].end_at, + title: response.data.data[i].title, }) } @@ -436,12 +437,21 @@ class Videostatisticscomtwo extends Component { } ); + + let mytitle=""; + if(isAdmin){ + mytitle=this.props&&this.props.mytitle; + + }else{ + mytitle=this.state.data[0].title; + } + return (
-
视频名称视频名称…
+
{mytitle}
分班 { fbbool === true ? - + : - + } @@ -488,7 +498,7 @@ class Videostatisticscomtwo extends Component { } -
+
{ data.length === 0 ?
( - this.props.tisticsbools(true,record.id)}>详情 + this.props.tisticsbools(true,record.id,record.title)}>详情 ), } ], @@ -266,7 +266,7 @@ class Videostatisticslist extends Component { } -
+
{ data.length===0?