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

PCqiandao
杨树明 5 years ago
commit 1799f4ae42

3
.gitignore vendored

@ -7,6 +7,7 @@
# Ignore bundler config.
/.bundle
/bundle
/node_modules
# Ignore lock config file
*.lock
@ -46,6 +47,8 @@
/public/h5build
/public/npm-debug.log
/dist
# avatars
/public/images/avatars

@ -30,7 +30,7 @@ class CoursesController < ApplicationController
:informs, :update_informs, :online_learning, :update_task_position, :tasks_list,
:join_excellent_course, :export_couser_info, :export_member_act_score, :new_informs,
:delete_informs, :change_member_role, :course_groups, :join_course_group, :statistics,
:work_score, :act_score, :calculate_all_shixun_scores, :move_to_category]
:work_score, :act_score, :calculate_all_shixun_scores, :move_to_category, :watch_video_histories]
before_action :user_course_identity, except: [:join_excellent_course, :index, :create, :new, :apply_to_join_course,
:search_course_list, :get_historical_course_students, :mine, :search_slim, :board_list]
before_action :teacher_allowed, only: [:update, :destroy, :settings, :search_teacher_candidate,
@ -114,7 +114,7 @@ class CoursesController < ApplicationController
#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.includes(video: [user: :user_extension], user: :user_extension)
videos = videos.includes(video: [user: :user_extension],user: :user_extension).select("course_videos.id, course_videos.title, course_videos.link, course_videos.user_id")
videos = videos.where(videos: {transcoded: true})
.or(videos.where(videos: {user_id: current_user.id}))
.or(videos.where(course_videos: {is_link: true}))
@ -1481,6 +1481,23 @@ class CoursesController < ApplicationController
end
end
def watch_video_histories
@videos = CourseVideo.find_by_sql("
SELECT course_videos.id, videos.user_id, videos.title, IFNULL(hisotries.time,0) AS time, IFNULL(hisotries.num,0) AS num
FROM course_videos
JOIN videos ON course_videos.course_id = #{@course.id} AND videos.id = course_videos.video_id
LEFT JOIN (
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
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
")
@count = @videos.count
@videos = paginate @videos
end
private
# Use callbacks to share common setup or constraints between actions.

@ -367,9 +367,9 @@ class FilesController < ApplicationController
@category_name = category.try(:module_name)
else
@category = CourseSecondCategory.find category_id
@category_id = category.try(:id)
@category_name = category.try(:name)
@parent_category_id = category&.parent_id.to_i
@category_id = @category.try(:id)
@category_name = @category.try(:name)
@parent_category_id = @category&.parent_id.to_i
end
end

@ -12,7 +12,14 @@ class MemosController < ApplicationController
def index
@user = current_user
@memos = Memo.all
s_order = (params[:order] == "replies_count" ? "all_replies_count" : params[:order]) || "updated_at"
# replies_count created_at updated_at
s_order =
case params[:order]
when 'replies_count' then 'all_replies_count'
when 'created_at' then 'created_at'
else
'updated_at'
end
# @tidding_count = unviewed_tiddings(current_user) if current_user.present?
page = params[:page] || 1
limit = params[:limit] || 15

@ -70,7 +70,7 @@ class ShixunsController < ApplicationController
end
## 排序参数
bsort = params[:sort] || 'desc'
bsort = (params[:sort] == "desc" ? "desc" : "asc")
case params[:order_by] || 'new'
when 'hot'
@shixuns = @shixuns.order("shixuns.public = 2 desc, shixuns.myshixuns_count #{bsort}")

@ -5,6 +5,6 @@ class WatchVideoHistoriesController < ApplicationController
watch_log = CreateWatchVideoService.new(current_user, request, params).call
render_ok(log_id: watch_log&.id)
rescue CreateWatchVideoService::Error => ex
render_error(ex.message)
render_ok(log_id: watch_log&.id)
end
end

@ -14,6 +14,9 @@ class Weapps::CourseMemberAttendancesController < ApplicationController
@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]})
end

@ -82,7 +82,7 @@ module CoursesHelper
when "video"
"/classrooms/#{course.id}/course_videos"
when "attendance"
"/classrooms/#{course.id}/signin"
"/classrooms/#{course.id}/attendances"
end
end

@ -10,29 +10,36 @@ class CreateWatchVideoService < ApplicationService
def call
ActiveRecord::Base.transaction do
current_time = Time.now
params[:watch_duration] = params[:watch_duration].to_f.round(2)
params[:total_duration] = params[:total_duration].to_f.round(2)
params[:duration] = params[:duration].to_f.round(2)
if params[:log_id].present?
if params[:total_duration].to_f < params[:watch_duration].to_f || params[:watch_duration].to_f < 0
raise Error, '观看时长错误'
watch_video_history = user.watch_video_histories.find(params[:log_id])
if params[:total_duration] < params[:watch_duration]
return watch_video_history
end
# 更新观看时长
watch_video_history = user.watch_video_histories.find(params[:log_id])
if watch_video_history.present? && watch_video_history.watch_duration <= params[:watch_duration].to_f && params[:total_duration].to_f > watch_video_history.total_duration
if watch_video_history.present? && !watch_video_history.is_finished && watch_video_history.watch_duration <= params[:watch_duration] && watch_video_history.total_duration <= params[:total_duration]
# 如果观看总时长没变,说明视频没有播放,无需再去记录
watch_video_history.end_at = current_time
watch_video_history.total_duration = params[:total_duration]
watch_video_history.watch_duration = params[:watch_duration].to_f > watch_video_history.duration ? watch_video_history.duration : params[:watch_duration]
watch_video_history.is_finished = (watch_video_history.duration <= params[:watch_duration].to_f)
watch_video_history.watch_duration = params[:watch_duration] > watch_video_history.duration ? watch_video_history.duration : params[:watch_duration]
watch_video_history.is_finished = params[:ed].present?
watch_video_history.save!
watch_course_video = watch_video_history.watch_course_video
if watch_course_video.present? && !watch_course_video.is_finished && watch_course_video.watch_duration < params[:watch_duration].to_f
# 更新课程视频的时长及是否看完状态
watch_course_video.watch_duration = params[:watch_duration]
watch_course_video.is_finished = (watch_course_video.duration <= params[:watch_duration].to_f)
if watch_course_video.present?
watch_course_video.total_duration = watch_course_video.watch_video_histories.sum(:total_duration)
watch_course_video.end_at = current_time
if !watch_course_video.is_finished && watch_course_video.watch_duration < params[:watch_duration]
# 更新课程视频的时长及是否看完状态
watch_course_video.watch_duration = params[:watch_duration]
if params[:ed].present?
watch_course_video.is_finished = watch_course_video.total_duration >= watch_course_video.duration
end
end
watch_course_video.save!
end
end
@ -45,11 +52,10 @@ class CreateWatchVideoService < ApplicationService
d.start_at = current_time
d.duration = params[:duration]
end
watch_video_history = build_video_log(current_time, course_video.video_id, watch_course_video.id)
watch_video_history.save!
watch_course_video.save! unless watch_course_video.persisted?
watch_video_history = build_video_log(current_time, course_video.video_id, watch_course_video.id)
watch_video_history.save!
else
# 非课堂视频
video = Video.find(params[:video_id])

@ -1,5 +1,5 @@
json.attendances @attendances do |attendance|
json.(attendance, :id, :name, :normal_count, :all_count, :mode)
json.(attendance, :id, :name, :normal_count, :all_count, :mode, :attendance_code)
json.author do
user = attendance.user
json.user_name user.real_name

@ -10,6 +10,8 @@ json.videos @videos do |video|
json.user_login user&.login
else
json.partial! 'users/videos/video', locals: { video: video.video }
json.total_time video.watch_course_videos.sum(:total_duration).round(0)
json.people_num video.watch_course_videos.count(:user_id)
end
end

@ -0,0 +1,10 @@
json.videos do
json.array! @videos do |v|
json.id v.id
json.title v.title
json.user_name v.user&.real_name
json.people_num v.num
json.total_time v.time
end
end
json.count @count

@ -4,8 +4,9 @@
# json.student_id member.user&.student_id
# end
json.member_attendances @members.each do |member|
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"

@ -531,6 +531,7 @@ Rails.application.routes.draw do
post :inform_up
post :inform_down
get :calculate_all_shixun_scores
get :watch_video_histories
end
collection do

@ -0,0 +1,8 @@
class AddTotalDurationToWatchCourseDuration < ActiveRecord::Migration[5.2]
def change
add_column :watch_course_videos, :total_duration, :float, default: 0
WatchVideoHistory.where("created_at < '2020-03-14 00:00:00'").each do |d|
d.watch_course_video.increment!(:total_duration, d.total_duration) if d.watch_course_video.present?
end
end
end

@ -38,6 +38,36 @@ export function getNextHalfHourOfMoment(moment) {
return moment
}
 export function formatSeconds(value) {
        var theTime = parseInt(value);// 秒
        var middle= 0;// 分
        var hour= 0;// 小时
    
        if(theTime > 60) {
            middle= parseInt(theTime/60);
            theTime = parseInt(theTime%60);
            if(middle> 60) {
                hour= parseInt(middle/60);
                middle= parseInt(middle%60);
            }
        }
        var result = ""+parseInt(theTime)+"秒";
        if(middle > 0) {
if(hour>0){
result = ""+parseInt(middle)+"分";
}else{
result = ""+parseInt(middle)+"分"+result;
}
            
        }
        if(hour> 0) {
            result = ""+parseInt(hour)+"小时"+result;
        }
        return result;
    }
export function formatDuring(mss){
var days = parseInt(mss / (1000 * 60 * 60 * 24));
var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));

@ -20,7 +20,7 @@ export { bytesToSize as bytesToSize } from './UnitUtil';
export { markdownToHTML, uploadNameSizeSeperator, appendFileSizeToUploadFile, appendFileSizeToUploadFileAll, isImageExtension,
downloadFile, sortDirections } from './TextUtil'
export { handleDateString, getNextHalfHourOfMoment,formatDuring } from './DateUtil'
export { handleDateString, getNextHalfHourOfMoment,formatDuring,formatSeconds} from './DateUtil'
export { configShareForIndex, configShareForPaths, configShareForShixuns, configShareForCourses, configShareForCustom } from './util/ShareUtil'

@ -240,8 +240,12 @@ class Video extends Component {
{
videos && videos.length > 0 ?
<React.Fragment>
<div style={{display:'flex'}}>
<p className="font-grey-9 mt20 mb20 pl5"> <span className="color-orange">{videoData && videoData.count}</span> </p>
<p className="mt20 mb20 pl5" style={{marginLeft:'auto',color:'#C0C4CC'}}>播放数据从2020-03-13 24:00开始统计</p>
</div>
<div className="videoContent">
{
videos.map((item, key) => {

@ -43,7 +43,7 @@ export default ({ src, videoId, logWatchHistory, courseId = null }) => {
let isSeeking = false
let pos = []//
const log = useCallback((callback) => {
const log = useCallback((callback, isEnd = false) => {
let params = {}
if (logId) {
params['log_id'] = logId
@ -59,6 +59,9 @@ export default ({ src, videoId, logWatchHistory, courseId = null }) => {
params['duration'] = totalDuration
params['device'] = device
}
if (isEnd) {
params['ed'] = "1"
}
async function getLogId() {
isLoging = true
let id = await logWatchHistory(params)
@ -119,7 +122,7 @@ export default ({ src, videoId, logWatchHistory, courseId = null }) => {
isLoging = false
isSeeking = false
pos = []
})
}, true)
}
function onTimeupdate() {

@ -70,6 +70,7 @@
}
.videoItem .time {
height: 15px;
color: #C0C4CC;
}
.videoItem .square-main .buttonRow .dianjilianicon{

@ -1,6 +1,6 @@
import React, { useState, useEffect, useContext, memo } from 'react';
import { Progress, Input, Tooltip , Spin } from 'antd'
import { getUrl2, isDev, CBreadcrumb, ActionBtn, ThemeContext } from 'educoder'
import { getUrl2, isDev, CBreadcrumb, ActionBtn, ThemeContext,formatSeconds} from 'educoder'
import axios from 'axios'
import moment from 'moment'
import playIcon from './images/play.png'
@ -21,7 +21,7 @@ const clipboardMap = {}
function VideoInReviewItem (props) {
const theme = useContext(ThemeContext);
const { history, file_url , play_url , cover_url , transcoded , title, created_at, published_at, isReview, id
, onEditVideo, onMaskClick, getCopyText, showNotification,vv,play_duration,operation , deleteVideo , moveVideo ,link} = props;
, onEditVideo, onMaskClick, getCopyText, showNotification,vv,play_duration,operation , deleteVideo , moveVideo ,link, people_num,total_time} = props;
useEffect(()=> {
if (!isReview) {
_clipboard = new ClipboardJS(`.copybtn_item_${id}`);
@ -37,6 +37,9 @@ function VideoInReviewItem (props) {
}
}
}, [])
const username = props.match.params.username
function toList() {
history.push(`/users/${username}/videos`)
@ -60,7 +63,7 @@ function VideoInReviewItem (props) {
{!isReview && !link && transcoded &&
<div className="playWrap" onClick={() => onMaskClick(props)}>
<img className="play mp23" src={playIcon}></img>
{play_duration===0?"":<div className={"play_duration"}>累计学习时长{play_duration} h</div>}
{/* {play_duration===0?"":<div className={"play_duration"}>累计学习时长:{play_duration} h</div>} */}
</div>
}
</Spin>
@ -69,16 +72,22 @@ function VideoInReviewItem (props) {
title={title && title.length > 20 ? title : ''}
>{title}</div>
<div className="df buttonRow mb10">
<span className="time">{moment(published_at || created_at).format('YYYY-MM-DD HH:mm:ss')}</span>
{/* <div className={"play_duration"}>累计学习时长:{play_duration} h</div> */}
{/* <span className="time">{moment(published_at || created_at).format('YYYY-MM-DD HH:mm:ss')}{people_num}</span> */}
{link ?<span className="time"> </span>:<span className="time">{
formatSeconds(total_time)}
{/* total_time<60?total_time+' s':total_time/60<60?(total_time/60).toFixed(0)+' min':(total_time/3600).toFixed(1)+ ' h' */}
</span>}
</div>
<div className="df buttonRow">
{/* 2019-09-01 10:00:22 */}
<span className={"dianjilianicon"}>
{!vv || (vv && vv)===0 ? "" : <Tooltip title="播放次数" placement="bottom">
<i className={`icon-dianjiliang iconfont dianjilianicon`}></i>
</Tooltip> } {!vv || (vv && vv)===0?"":vv}
{!people_num || (people_num && people_num)===0 ? "" : <Tooltip title="观看人数" placement="bottom">
<i className={`icon-dianjiliang iconfont dianjilianicon font-12`}> {!people_num || (people_num && people_num)===0?"":people_num}</i>
</Tooltip> }
</span>
<div>
{
isReview !== true && moveVideo &&

Loading…
Cancel
Save