diff --git a/app/controllers/live_links_controller.rb b/app/controllers/live_links_controller.rb index fe2de4afe..f5af80ead 100644 --- a/app/controllers/live_links_controller.rb +++ b/app/controllers/live_links_controller.rb @@ -7,17 +7,17 @@ class LiveLinksController < ApplicationController def index lives = @course.live_links - order_str = "on_status desc,id desc" + order_str = "on_status desc, live_time desc" @total_count = lives.size @my_live_id = @course.live_links.find_by(user_id: current_user.id)&.id - order_str = "live_links.id = #{@my_live_id} desc, #{order_str}" if @my_live_id.present? + # order_str = "live_links.id = #{@my_live_id} desc, #{order_str}" if @my_live_id.present? lives = lives.order("#{order_str}") @lives = paginate lives.includes(user: :user_extension) end def create - tip_exception("一个老师只能设置一个直播间") if @course.live_links.where(user_id: current_user.id).exists? - @course.live_links.create!(create_params.merge(user_id: current_user.id)) + on_status = params[:live_time].present? && params[:live_time].to_time <= Time.now ? 1 : 0 + @course.live_links.create!(create_params.merge(user_id: current_user.id, on_status: on_status)) render_ok end @@ -38,7 +38,8 @@ class LiveLinksController < ApplicationController end end else - current_live.update!(create_params) + on_status = params[:live_time].present? && params[:live_time].to_time <= Time.now ? 1 : 0 + current_live.update!(create_params.merge(on_status: on_status)) end render_ok end @@ -51,7 +52,7 @@ class LiveLinksController < ApplicationController private def create_params - params.permit(:url, :description) + params.permit(:url, :description, :course_name, :platform, :live_time, :duration) end def current_live diff --git a/app/decorators/tiding_decorator.rb b/app/decorators/tiding_decorator.rb index 771df3aa2..8d266b7df 100644 --- a/app/decorators/tiding_decorator.rb +++ b/app/decorators/tiding_decorator.rb @@ -322,7 +322,7 @@ module TidingDecorator end def live_link_content - I18n.t(locale_format) % container&.user.try(:show_real_name) + I18n.t(locale_format) % container&.course_name end def student_graduation_topic_content diff --git a/app/models/live_link.rb b/app/models/live_link.rb index 52c1e3657..27963a0bb 100644 --- a/app/models/live_link.rb +++ b/app/models/live_link.rb @@ -4,8 +4,25 @@ class LiveLink < ApplicationRecord has_many :tidings, as: :container, dependent: :destroy - validates :url, presence: true, format: { with: CustomRegexp::URL, message: "必须为网址超链接" } + validates :url, format: { with: CustomRegexp::URL, message: "必须为网址超链接" } validates :description, length: { maximum: 100, too_long: "不能超过100个字符" } + validates :course_name, presence: true + validates :platform, presence: true, inclusion: {in: %W(tencent douyu bilibili vbt)} + # validates :live_time, presence: true + validates :duration, numericality: { only_integer: true, greater_than: 0}, allow_blank: true + + def platform_name + case platform + when "tencent" + "腾讯课堂" + when "douyu" + "斗鱼直播" + when "vbt" + "威佰通" + else + platform + end + end def op_auth? user == User.current || User.current.admin_or_business? diff --git a/app/services/videos/batch_publish_service.rb b/app/services/videos/batch_publish_service.rb index ce6bdb163..0523097a2 100644 --- a/app/services/videos/batch_publish_service.rb +++ b/app/services/videos/batch_publish_service.rb @@ -25,7 +25,9 @@ class Videos::BatchPublishService < ApplicationService video.title = param[:title].to_s.strip.presence || video.title video.apply_publish - + if param[:course_id].present? + video.status = "published" + end video.save! if param[:course_id].present? diff --git a/app/views/homework_commons/index.json.jbuilder b/app/views/homework_commons/index.json.jbuilder index db3603746..a508659e8 100644 --- a/app/views/homework_commons/index.json.jbuilder +++ b/app/views/homework_commons/index.json.jbuilder @@ -17,7 +17,10 @@ json.homeworks @homework_commons.each do |homework| json.status_time curr_status[:time] json.time_status curr_status[:time_status] json.allow_late homework.allow_late - json.author homework.user.real_name + json.author homework.user&.real_name + json.author_img url_to_avatar(homework.user) + json.author_login homework.user&.login + json.created_at homework.created_at.strftime("%Y-%m-%d") # 只有在主目录才显示 json.upper_category_name homework.course_second_category&.name unless params[:category] diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index f5e6ca01a..cd2f17cf5 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -84,6 +84,7 @@ elsif @user_course_identity == Course::STUDENT json.user_login @work.user.login json.student_id @work.user.student_id json.user_name @work.user.real_name + json.user_img url_to_avatar(@work.user) json.group_name @member.course_group_name end @@ -108,6 +109,7 @@ if @homework.homework_type == "practice" json.view_answer_count work.myshixun.try(:view_answer_count).to_i json.user_login work.user.try(:login) json.user_name work.user.try(:real_name) + json.user_img url_to_avatar(work.user) json.student_id work.user.try(:student_id) json.group_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name) json.work_status work.compelete_status @@ -169,6 +171,7 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal" json.user_login @is_evaluation ? "--" : work.user.try(:login) json.user_name @is_evaluation ? "匿名" : work.user.try(:real_name) + json.user_img url_to_avatar(@is_evaluation ? "0" : work.user) end end diff --git a/app/views/live_links/edit.json.jbuilder b/app/views/live_links/edit.json.jbuilder index 047a226e8..6b0fd385d 100644 --- a/app/views/live_links/edit.json.jbuilder +++ b/app/views/live_links/edit.json.jbuilder @@ -1 +1 @@ -json.(@live, :id, :description, :url) +json.(@live, :id, :description, :url, :platform, :live_time, :duration, :course_name) diff --git a/app/views/live_links/index.json.jbuilder b/app/views/live_links/index.json.jbuilder index e497a068b..419fb49bb 100644 --- a/app/views/live_links/index.json.jbuilder +++ b/app/views/live_links/index.json.jbuilder @@ -1,12 +1,13 @@ json.lives @lives do |live| - json.(live, :id, :description, :on_status) + json.(live, :id, :description, :on_status, :duration, :course_name) json.url live.on_status ? live.url : "" json.author_name live.user.show_real_name json.author_login live.user.login json.author_img url_to_avatar(live.user) json.op_auth live.op_auth? json.delete_auth live.delete_auth? - json.created_at live.created_at.strftime('%Y-%m-%d') + json.live_time live.live_time&.strftime('%Y-%m-%d %H:%M:%S') + json.platform live.platform_name end json.my_live_id @my_live_id json.total_count @total_count \ No newline at end of file diff --git a/config/locales/tidings/zh-CN.yml b/config/locales/tidings/zh-CN.yml index 92c815a05..cda146780 100644 --- a/config/locales/tidings/zh-CN.yml +++ b/config/locales/tidings/zh-CN.yml @@ -238,4 +238,4 @@ 2_end: "你提交的发布视频申请:%s,审核未通过
原因:%{reason}" PublicCourseStart_end: "你报名参与的开放课程:%s,将于%s正式开课" SubjectStartCourse_end: "您创建的开放课程:%s 已达到开课人数要求。您可以在24小时内自主开设新一期课程。如果超过24小时未开课,平台将自动开课并复制您上一期的课程内容。" - LiveLink_end: "%s老师正在直播中" + LiveLink_end: "%s 直播将于30分钟后开始" diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index 6900f6c51..4f41df0c5 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -173,7 +173,10 @@ zh-CN: live_link: description: '说明' url: '链接' - + course_name: '课程名称' + platform: '直播平台' + live_time: '开播时间' + duration: '直播时长' diff --git a/db/migrate/20200212072045_add_columns_to_live_links.rb b/db/migrate/20200212072045_add_columns_to_live_links.rb new file mode 100644 index 000000000..e0c59dcfa --- /dev/null +++ b/db/migrate/20200212072045_add_columns_to_live_links.rb @@ -0,0 +1,8 @@ +class AddColumnsToLiveLinks < ActiveRecord::Migration[5.2] + def change + add_column :live_links, :course_name, :string + add_column :live_links, :platform, :string + add_column :live_links, :live_time, :datetime + add_column :live_links, :duration, :integer + end +end diff --git a/lib/tasks/live_notice.rake b/lib/tasks/live_notice.rake new file mode 100644 index 000000000..da57ebd4b --- /dev/null +++ b/lib/tasks/live_notice.rake @@ -0,0 +1,13 @@ +namespace :live_notice do + desc "send a live message to students before 30 minutes" + task message: :environment do + lives = LiveLink.where(on_status: 0).where("live_time <= '#{Time.now + 30*60}' and live_time > '#{Time.now}'") + lives.each do |live| + LivePublishJob.perform_later(live.id) + end + end + + task on_status: :environment do + LiveLink.where(on_status: 0).where("live_time <= '#{Time.now}'").update_all(on_status: 1) + end +end \ No newline at end of file diff --git a/lib/tasks/statistic_subject_info.rake b/lib/tasks/statistic_subject_info.rake index e7bf4116a..c17823a33 100644 --- a/lib/tasks/statistic_subject_info.rake +++ b/lib/tasks/statistic_subject_info.rake @@ -10,7 +10,7 @@ namespace :subjects do column_value = "subject_id, study_count, course_study_count, initiative_study, passed_count, course_used_count, " + "school_used_count, created_at, updated_at" subjects.find_in_batches(batch_size: 50) do |s| - Parallel.each_with_index(s, in_processes: 4) do |subject, index| + Parallel.each(s, in_processes: 4) do |subject| puts("---------------------data_statistic: #{subject.id}") Rails.logger.info("---------------------data_statistic: #{subject.id}") data = Subjects::DataStatisticService.new(subject) @@ -23,7 +23,8 @@ namespace :subjects do "#{data.passed_count}, #{data.course_used_count}, #{data.school_used_count}, " + "'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')") buffer_size += 1 - if buffer_size == 1000 || subjects.count == (index+1) + puts "buffer_size: #{buffer_size}; subject: #{subject == s.last}; index:#{index+1}" + if buffer_size == 1000 || subject == s.last sql = "REPLACE INTO subject_records(#{column_value}) VALUES #{str}" puts sql ActiveRecord::Base.connection.execute sql diff --git a/public/favicon.ico b/public/favicon.ico index 05b9d163e..9c65fe8c7 100755 Binary files a/public/favicon.ico and b/public/favicon.ico differ diff --git a/public/react/src/common/components/form/City.js b/public/react/src/common/components/form/City.js index b397c8b59..520a2ebbf 100644 --- a/public/react/src/common/components/form/City.js +++ b/public/react/src/common/components/form/City.js @@ -120,7 +120,7 @@ const options = [{ value: '广东', label: '广东', children: [{ - value: "广州", + value: "广州", label: '广州' },{ value: '深圳', @@ -493,6 +493,9 @@ const options = [{ children: [{ value: "兰州", label: '兰州' + },{ + value: "嘉峪关", + label: '嘉峪关' },{ value: '白银', label: '白银' @@ -537,7 +540,7 @@ const options = [{ value: '广西', label: '广西', children: [{ - value: "南宁", + value: "南宁", label: '南宁' },{ value: '百色',