diff --git a/app/controllers/attendances_controller.rb b/app/controllers/attendances_controller.rb
index 256e651e8..412b3bee6 100644
--- a/app/controllers/attendances_controller.rb
+++ b/app/controllers/attendances_controller.rb
@@ -79,8 +79,26 @@ class AttendancesController < ApplicationController
new_end_time = "#{params[:attendance_date]} #{params[:end_time]}".to_time
@attendance.update!(update_params)
- # 如果历史签到变为了正在签到,将未创建的学生签到数据补上
- if a_end_time < Time.current && new_end_time > Time.current
+ old_group_ids = @attendance.course_attendance_groups.pluck(:course_group_id)
+ unless old_group_ids.include?(0)
+ all_groups_ids = old_group_ids + params[:group_ids]
+ # 如果新增的的分班加上之前的分班是课堂的全部分班,则只需创建一条记录
+ if all_groups_ids.uniq.count == @course.course_groups_count
+ @attendance.course_attendance_groups.destroy_all
+ @attendance.course_attendance_groups.create!(course_group_id: 0, course_id: @attendance.course_id)
+ new_group = true
+ else
+ new_group_ids = params[:group_ids] - old_group_ids
+ new_group_ids.each do |group_id|
+ @attendance.course_attendance_groups.create!(course_group_id: group_id, course_id: @attendance.course_id)
+ new_group = true
+ end
+ end
+
+ end
+
+ # 如果新增了分班或者历史签到变为了正在签到,将未创建的学生签到数据补上
+ if new_group || (a_end_time < Time.current && new_end_time > Time.current)
create_absence_student_data
end
render_ok
diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb
new file mode 100644
index 000000000..1d1c03742
--- /dev/null
+++ b/app/controllers/collections_controller.rb
@@ -0,0 +1,21 @@
+class CollectionsController < ApplicationController
+
+ before_action :require_login
+
+ def create
+ tip_exception("勿重复收藏") if current_user.collections.find_by(create_params).present?
+ current_user.collections.create!(create_params)
+ normal_status("收藏成功,您可以在个人主页对应的栏目中查看")
+ end
+
+ def cancel
+ collection = current_user.collections.find_by!(create_params)
+ collection.destroy!
+ normal_status("操作成功")
+ end
+
+ private
+ def create_params
+ params.permit(:container_id, :container_type)
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/tidings_controller.rb b/app/controllers/tidings_controller.rb
index 91d6c095d..91836a12a 100644
--- a/app/controllers/tidings_controller.rb
+++ b/app/controllers/tidings_controller.rb
@@ -12,7 +12,7 @@ class TidingsController < ApplicationController
case params[:type]
when 'notice' then 'System'
when 'apply' then 'Apply'
- when 'course' then %w(HomeworkCommon Exercise Poll GraduationTask GraduationTopic)
+ when 'course' then %w(HomeworkCommon Exercise Poll GraduationTask GraduationTopic PublishCourseVideo)
when 'project' then 'Project'
when 'interaction' then %w(Comment Mentioned Praise Fan)
when 'project_package' then %w(Created Destroyed Bidding BiddingEnd BiddingWon BiddingLost)
@@ -25,6 +25,8 @@ class TidingsController < ApplicationController
tidings = tidings.where(container_type: 'ProjectPackage') if params[:type] == 'project_package'
+
+
@count = tidings.count
@tidings = paginate(tidings.order(created_at: :desc), per_page: 10)
end
diff --git a/app/decorators/tiding_decorator.rb b/app/decorators/tiding_decorator.rb
index 8d266b7df..4e640a28b 100644
--- a/app/decorators/tiding_decorator.rb
+++ b/app/decorators/tiding_decorator.rb
@@ -403,6 +403,8 @@ module TidingDecorator
def video_content
if tiding_type == 'System'
I18n.t(locale_format(tiding_type, status), reason: extra) % container.try(:title)
+ elsif tiding_type == 'PublishCourseVideo'
+ I18n.t(locale_format(tiding_type)) % [belong_container&.name]
else
I18n.t(locale_format(tiding_type)) % [container.try(:title) || extra]
end
@@ -419,4 +421,5 @@ module TidingDecorator
def hack_content
I18n.t(locale_format(parent_container_type)) % (container&.name || extra)
end
+
end
diff --git a/app/jobs/course_video_uploaded_job.rb b/app/jobs/course_video_uploaded_job.rb
new file mode 100644
index 000000000..71dfaa600
--- /dev/null
+++ b/app/jobs/course_video_uploaded_job.rb
@@ -0,0 +1,25 @@
+class CourseVideoUploadedJob < ApplicationJob
+ queue_as :notify
+
+ def perform(video_id)
+ video = Video.select("id, user_id").find_by(id: video_id)
+ course_ids = video&.course_videos&.pluck(:course_id)
+
+ return unless course_ids.present?
+
+ course_members = CourseMember.where(course_id: course_ids, role: 'STUDENT').select("user_id, course_id")
+ Tiding.bulk_insert do |worker|
+ course_members.find_each do |m|
+ worker.add(
+ user_id: m.user_id,
+ tiding_type: 'PublishCourseVideo',
+ trigger_user_id: video.user_id,
+ container_id: video.id,
+ container_type: 'Video',
+ belong_container_type: 'Course',
+ belong_container_id: m.course_id)
+ end
+ end
+ end
+
+end
diff --git a/app/models/collection.rb b/app/models/collection.rb
index 3baf96931..4ed77db60 100644
--- a/app/models/collection.rb
+++ b/app/models/collection.rb
@@ -1,3 +1,7 @@
class Collection < ApplicationRecord
belongs_to :user
+ belongs_to :container, polymorphic: true, optional: true
+
+ scope :shixuns, -> {where(container_type: 'Shixun')}
+ scope :subjects, -> {where(container_type: 'Subject')}
end
diff --git a/app/models/shixun.rb b/app/models/shixun.rb
index 5caacebce..f9adf237c 100644
--- a/app/models/shixun.rb
+++ b/app/models/shixun.rb
@@ -53,6 +53,9 @@ class Shixun < ApplicationRecord
has_many :shixun_service_configs, :dependent => :destroy
has_many :tidings, as: :container, dependent: :destroy
+ # 收藏
+ has_many :collections, as: :container, dependent: :destroy
+
# 实训审核记录
has_many :shixun_reviews, -> {order("shixun_reviews.created_at desc")}, :dependent => :destroy
diff --git a/app/models/subject.rb b/app/models/subject.rb
index 387e5adb1..a7ad74d61 100644
--- a/app/models/subject.rb
+++ b/app/models/subject.rb
@@ -16,6 +16,9 @@ class Subject < ApplicationRecord
has_many :subject_appointments, dependent: :destroy
+ # 收藏
+ has_many :collections, as: :container, dependent: :destroy
+
has_many :subject_members, ->{ order("subject_members.position asc")}, dependent: :destroy
has_many :users, through: :subject_members
has_many :tidings, as: :container, dependent: :destroy
diff --git a/app/models/user.rb b/app/models/user.rb
index fb4cc50da..531782ac0 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -117,6 +117,11 @@ class User < ApplicationRecord
has_many :manage_course_members, -> { teachers_and_admin }, class_name: 'CourseMember'
has_many :manage_courses, through: :manage_course_members, source: :course
+ has_many :collections, dependent: :destroy
+ has_many :shixun_collections, -> { shixuns }, class_name: 'Collection'
+ has_many :subject_collections, -> { subjects }, class_name: 'Collection'
+
+
# 关注
# has_many :be_watchers, foreign_key: :user_id, dependent: :destroy # 我的关注
# has_many :be_watcher_users, through: :be_watchers, dependent: :destroy # 我关注的用户
@@ -419,6 +424,10 @@ class User < ApplicationRecord
end
end
+ def is_collect? container
+ collections.where(container: container).exists?
+ end
+
# 实训用户身份
def shixun_identity(shixun)
@identity =
diff --git a/app/services/shixuns/create_shixun_service.rb b/app/services/shixuns/create_shixun_service.rb
index 2a66cf2fb..c3a46285e 100644
--- a/app/services/shixuns/create_shixun_service.rb
+++ b/app/services/shixuns/create_shixun_service.rb
@@ -12,6 +12,7 @@ class CreateShixunService < ApplicationService
identifier = Util::UUID.generate_identifier(Shixun, 8)
shixun.identifier= identifier
shixun.user_id = user.id
+ shixun.can_copy = 1
main_mirror = MirrorRepository.find params[:main_type]
sub_mirrors = MirrorRepository.where(id: params[:sub_type])
begin
diff --git a/app/services/users/shixun_service.rb b/app/services/users/shixun_service.rb
index b13b0ab1f..7e95cda84 100644
--- a/app/services/users/shixun_service.rb
+++ b/app/services/users/shixun_service.rb
@@ -24,15 +24,17 @@ class Users::ShixunService
user.study_shixuns.where(shixuns: {id: laboratory.shixuns})
when 'manage' then
laboratory.shixuns.where(id: user.shixuns)
+ when 'collect' then
+ laboratory.shixuns.where(id: user.shixun_collections.pluck(:container_id))
else
- ids = user.study_shixuns.pluck(:id) + user.shixuns.pluck(:id)
+ ids = user.study_shixuns.pluck(:id) + user.shixuns.pluck(:id) + user.shixun_collections.pluck(:container_id)
laboratory.shixuns.where(id: ids)
end
end
def status_filter(relations)
case params[:category]
- when 'study' then
+ when 'study', 'collect' then
study_shixun_status_filter(relations)
when 'manage' then
manage_shixun_status_filter(relations)
@@ -97,7 +99,7 @@ class Users::ShixunService
end
case params[:category]
- when 'study' then
+ when 'study', 'collect' then
relations.order("myshixuns.#{sort_by} #{sort_direction}")
when 'manage' then
relations.order("shixuns.#{sort_by} #{sort_direction}")
diff --git a/app/services/users/subject_service.rb b/app/services/users/subject_service.rb
index d0b995c8e..a8b9b32fb 100644
--- a/app/services/users/subject_service.rb
+++ b/app/services/users/subject_service.rb
@@ -25,10 +25,13 @@ class Users::SubjectService
Subject.joins(stage_shixuns: { shixun: :myshixuns }).where(myshixuns: { user_id: user.id })
when 'manage' then
Subject.joins(:subject_members).where(subject_members: { user_id: user.id })
+ when 'collect' then
+ Subject.where(id: user.subject_collections.pluck(:container_id))
else
study_subject_ids = StageShixun.where(shixun_id: user.myshixuns.pluck(:shixun_id)).pluck(:subject_id)
manage_subject_ids = user.subject_members.pluck(:subject_id)
- Subject.where(id: study_subject_ids + manage_subject_ids)
+ collect_subject_ids = user.subject_collections.pluck(:container_id)
+ Subject.where(id: study_subject_ids + manage_subject_ids + collect_subject_ids)
end
end
@@ -45,7 +48,7 @@ class Users::SubjectService
return relations unless self_or_admin?
case params[:category]
- when 'study' then
+ when 'study', 'collect' then
study_subject_status_filter(relations)
when 'manage' then
manage_subject_status_filter(relations)
diff --git a/app/services/videos/batch_publish_service.rb b/app/services/videos/batch_publish_service.rb
index 3ddc54967..543497e9e 100644
--- a/app/services/videos/batch_publish_service.rb
+++ b/app/services/videos/batch_publish_service.rb
@@ -52,6 +52,7 @@ class Videos::BatchPublishService < ApplicationService
if param[:course_id].present?
video.video_applies.create!(status: "agreed")
+ CourseVideoUploadedJob.perform_later(video.id) if video.transcoded
else
video.video_applies.create!
end
diff --git a/app/services/videos/dispatch_callback_service.rb b/app/services/videos/dispatch_callback_service.rb
index 4ff94a1c4..49b1d5935 100644
--- a/app/services/videos/dispatch_callback_service.rb
+++ b/app/services/videos/dispatch_callback_service.rb
@@ -22,6 +22,7 @@ class Videos::DispatchCallbackService < ApplicationService
when 'StreamTranscodeComplete' then # 转码完成
#return if video.play_url.present?
video.update!(play_url: params['FileUrl'], transcoded: true)
+ CourseVideoUploadedJob.perform_later(video.id) if video.video_applies.exists?(status: 'agreed') #通过的情况基本上是课堂视频
when 'DeleteMediaComplete' #完成云端视频删除
video.update_column(:delete_state, Video::FINISH_DELETE)
end
diff --git a/app/views/shixuns/show.json.jbuilder b/app/views/shixuns/show.json.jbuilder
index 4a0c3ebd6..404acb4fa 100644
--- a/app/views/shixuns/show.json.jbuilder
+++ b/app/views/shixuns/show.json.jbuilder
@@ -1,5 +1,7 @@
json.fork_from @fork_from
json.identity User.current.shixun_identity(@shixun)
+json.is_collect User.current&.is_collect?(@shixun)
+
json.power @power
json.partial! 'shixuns/top', locals: { shixun: @shixun, current_myshixun: @current_myshixun }
json.secret_repository @shixun.shixun_secret_repository.present?
diff --git a/app/views/subjects/show.json.jbuilder b/app/views/subjects/show.json.jbuilder
index d25437f0a..577424fb4 100644
--- a/app/views/subjects/show.json.jbuilder
+++ b/app/views/subjects/show.json.jbuilder
@@ -5,6 +5,8 @@ json.challenges_count @subject.subject_challenge_count
json.subject_score @subject.all_score
json.member_count @subject.member_count
+json.is_collect @user&.is_collect?(@subject)
+
json.allow_delete (@subject.status != 2 && @is_creator) || @user.admin?
json.publish_status publish_status(@subject, @is_manager)
json.public_status public_status(@subject, @is_manager, @user)
diff --git a/config/locales/tidings/zh-CN.yml b/config/locales/tidings/zh-CN.yml
index cda146780..5eb6ee759 100644
--- a/config/locales/tidings/zh-CN.yml
+++ b/config/locales/tidings/zh-CN.yml
@@ -236,6 +236,7 @@
System:
1_end: "你提交的发布视频申请:%s,审核已通过"
2_end: "你提交的发布视频申请:%s,审核未通过
原因:%{reason}"
+ PublishCourseVideo_end: "在课堂 %s 发布了视频,观看视频可以增加平时分哦~"
PublicCourseStart_end: "你报名参与的开放课程:%s,将于%s正式开课"
SubjectStartCourse_end: "您创建的开放课程:%s 已达到开课人数要求。您可以在24小时内自主开设新一期课程。如果超过24小时未开课,平台将自动开课并复制您上一期的课程内容。"
LiveLink_end: "%s 直播将于30分钟后开始"
diff --git a/config/routes.rb b/config/routes.rb
index da07c8d89..f858056a7 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -306,6 +306,10 @@ Rails.application.routes.draw do
resources :subject_lists
resources :shixun_lists
+ resources :collections do
+ delete :cancel, on: :collection
+ end
+
resources :shixuns, param: :identifier do
collection do
diff --git a/db/migrate/20200320082708_uniq_index_on_collections.rb b/db/migrate/20200320082708_uniq_index_on_collections.rb
new file mode 100644
index 000000000..30b55def4
--- /dev/null
+++ b/db/migrate/20200320082708_uniq_index_on_collections.rb
@@ -0,0 +1,6 @@
+class UniqIndexOnCollections < ActiveRecord::Migration[5.2]
+ def change
+ remove_index :collections, [:container_type, :container_id]
+ add_index :collections, [:container_type, :container_id], unique: true
+ end
+end