From c6132d9955269689111945e9ee894a1280a26718 Mon Sep 17 00:00:00 2001
From: Jasder <2053003901@@qq.com>
Date: Mon, 9 Mar 2020 14:07:22 +0800
Subject: [PATCH 1/4] FIX bug
---
app/controllers/challenges_controller.rb | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb
index c7fcb44..695f264 100644
--- a/app/controllers/challenges_controller.rb
+++ b/app/controllers/challenges_controller.rb
@@ -10,11 +10,10 @@ class ChallengesController < ApplicationController
# 关卡访问的权限控制
before_action :shixun_access_allowed, only: [:index]
- include ShixunsHelper
include ChallengesHelper
-
+
# 新建实践题
def new
@@ -163,7 +162,7 @@ class ChallengesController < ApplicationController
@shixun.increment!(:visits)
end
-
+
def show
@tab = params[:tab].nil? ? 1 : params[:tab].to_i
From 6d12a0f5324d52ffd69116571e7b19912e0b9067 Mon Sep 17 00:00:00 2001
From: Jasder <2053003901@@qq.com>
Date: Mon, 9 Mar 2020 14:46:40 +0800
Subject: [PATCH 2/4] FIX .
---
app/controllers/courses_controller.rb | 1 -
1 file changed, 1 deletion(-)
diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index d0a2e5e..75cb22b 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -1,6 +1,5 @@
class CoursesController < ApplicationController
include MessagesHelper
- include ExportHelper
include CustomSortable
# model validation error
From a9cdf966f8c57c141128bba275c41cd0de3079d3 Mon Sep 17 00:00:00 2001
From: Jasder <2053003901@@qq.com>
Date: Mon, 9 Mar 2020 15:06:15 +0800
Subject: [PATCH 3/4] =?UTF-8?q?FIX=20=E5=88=A0=E9=99=A4=E4=B8=8E=E8=AF=BE?=
=?UTF-8?q?=E7=A8=8B=E7=9B=B8=E5=85=B3=E7=9A=84=E6=97=A0=E7=94=A8=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81=E6=96=87=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../graduation_tasks_controller.rb | 755 ---------------
app/controllers/student_works_controller.rb | 896 ------------------
app/jobs/end_exercise_calculate_job.rb | 30 -
app/models/course_message.rb | 45 -
app/models/message.rb | 102 --
5 files changed, 1828 deletions(-)
delete mode 100644 app/controllers/graduation_tasks_controller.rb
delete mode 100644 app/controllers/student_works_controller.rb
delete mode 100644 app/jobs/end_exercise_calculate_job.rb
delete mode 100644 app/models/course_message.rb
delete mode 100644 app/models/message.rb
diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb
deleted file mode 100644
index 6196aa5..0000000
--- a/app/controllers/graduation_tasks_controller.rb
+++ /dev/null
@@ -1,755 +0,0 @@
-class GraduationTasksController < ApplicationController
- before_action :require_login, :check_auth, except: [:index]
- before_action :find_course, except: [:edit, :update, :settings, :update_settings, :tasks_list, :show, :show_comment,
- :cross_comment_setting, :assign_works, :commit_comment_setting, :sonar]
- before_action :find_task, only: [:edit, :update, :settings, :update_settings, :tasks_list, :show, :show_comment,
- :cross_comment_setting, :assign_works, :commit_comment_setting, :sonar]
- before_action :user_course_identity
- before_action :task_publish, only: [:show, :show_comment, :tasks_list, :settings]
- before_action :teacher_allowed, only: [:new, :create, :edit, :update, :set_public,:multi_destroy, :publish_task, :end_task,
- :update_settings, :add_to_bank, :cross_comment_setting, :assign_works, :commit_comment_setting]
- before_action :require_id_params, only: [:set_public ,:multi_destroy, :publish_task, :end_task, :add_to_bank]
- before_action :valid_params, only: [:update_settings]
- before_action :allow_cross_comment, only: [:cross_comment_setting, :assign_works, :commit_comment_setting]
- include ExportHelper
-
- def index
- search = "#{params[:search].to_s.strip.downcase}"
- order = params[:order]
- page = params[:page] ? params[:page].to_i : 1
-
- default_order = "IF(ISNULL(graduation_tasks.publish_time),0,1), graduation_tasks.publish_time DESC, graduation_tasks.created_at DESC"
- @identity = current_user.course_identity(@course)
- if @identity < Course::STUDENT
- @tasks = @course.graduation_tasks.where("graduation_tasks.name like ?", "%#{search}%")
- else
- @tasks = @course.graduation_tasks.where("graduation_tasks.name like ? and publish_time <= '#{Time.now}'", "%#{search}%")
- end
-
- if order.present? && order != "all"
- if @course.is_end
- @tasks = @tasks.none
- elsif order.to_i == 4 # 补交
- @tasks = @tasks.where("status > 1 and allow_late = 1 and (late_time is null or late_time > '#{Time.now}')")
- else
- @tasks = @tasks.where(status: order)
- end
- end
-
- @member = @course.course_members.find_by(user_id: current_user.id, is_active: 1)
- @all_count = @course.graduation_tasks.size
- @published_count = @course.graduation_tasks.where("publish_time <= '#{Time.now}'").size
- @task_count = @tasks.size
- @tasks = @tasks.reorder("#{default_order}").page(page).per(15).includes(:graduation_works)
- end
-
- # 任务问答
- def show
- @attachments = @task.attachments
- @current_user = current_user
- end
-
- # 毕设任务列表
- def tasks_list
- # 搜索栏数据
- @current_user = current_user
-
- # 分页参数
- page = params[:page] || 1
- limit = params[:limit] || 20
- @work = @task.graduation_works.where(user_id: current_user.id)
- @students = @course.students
- @assign_power = @user_course_identity < Course::STUDENT && @task.cross_comment && @task.comment_status == 2
- #end_time @task.allow_late ? @task.late_time : @task.end_time
- # 任务发布的情况下: 是老师身份或者任务已截止的情况下公开任务了作品设置的学生也能查看其他人的作品
- if @task.published? && (@user_course_identity < Course::STUDENT ||
- (@user_course_identity == Course::STUDENT && @work.present? && @work.take.work_status > 0 &&
- ((!@task.allow_late && @task.status > 1) || (@task.allow_late && @task.late_time && @task.late_time < Time.now)) &&
- (@task.open_work || @task.open_score)))
-
- _tasks_list
-
- # 排序
- rorder = params[:order].blank? ? "update_time" : params[:order]
- b_order = params[:b_order].blank? ? "desc" : params[:b_order]
- if rorder == "update_time" || rorder == "work_score"
- @work_list = @work_list.order("graduation_works.#{rorder} #{b_order}")
- elsif rorder == "student_id"
- @work_list = @work_list.joins(user: :user_extension).order("user_extensions.#{rorder} #{b_order}")
- end
-
- @view_work = @task.open_work || @user_course_identity < Course::STUDENT
-
- @work_count = @work_list.count
- @work_excel = @work_list
- @work_list = @work_list.page(page).per(limit)
-
- if params[:format] == "xlsx"
- complete_works = @work_excel.where("work_status > 0").size
- if @user_course_identity >= Course::STUDENT
- tip_exception(403, "无权限操作")
- elsif complete_works == 0
- normal_status(-1,"暂无用户提交")
- elsif params[:export].present? && params[:export]
- normal_status(0,"正在下载中")
- else
- respond_to do |format|
- format.xlsx{
- set_export_cookies
- graduation_work_to_xlsx(@work_excel,@task,current_user)
- task_export_name_ = "#{current_user.real_name}_#{@course.name}_#{@task.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
- render xlsx: "#{task_export_name_.strip}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column}
- }
- end
- end
- elsif params[:format] == "zip"
- if @user_course_identity >= Course::STUDENT
- tip_exception(403, "无权限操作")
- else
- zip_works = @work_excel.where("work_status > 0")
- status = checkfileSize(zip_works)
- if status == 0
- if params[:export].present? && params[:export]
- normal_status(0,"正在下载中")
- else
- respond_to do |format|
- format.zip{
- set_export_cookies
- zipfile = zip_homework_common @task, zip_works
- file = decode64(zipfile[0][:base64file])
- send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip'
- }
- end
- end
- else
- normal_status(status,status == -2 ? "500M" : "无附件可下载")
- end
- end
- end
- else
- @work_list = !@task.published? ? [] : @work
- @view_work = false
- @work_count = @work_list.count
- @all_work_count = @work_list.count
- if params[:format] == "xlsx" || params[:format] == "zip"
- normal_status(-1,"毕设任务未发布")
- end
- end
- end
-
-
- # 评论列表接口、 包含一级和二级评论的获取
- def show_comment
- @page = params[:page] || 1
- @limit = params[:limit] || 10
- @parent = params[:parent_id]
- @current_user = current_user
-
- @messages = @task.journals_for_messages
- @messages_count = @messages.count
- if @parent
- @messages = @messages.where(m_parent_id: @parent).order("created_on asc")
- else
- @messages = @messages.parent_comment.order("created_on desc")
- end
-
- @messages = @messages.page(@page).per(@limit)
- end
-
- def create
- ActiveRecord::Base.transaction do
- begin
- @graduation_task = GraduationTask.new(graduation_task_params)
- @graduation_task.course_id = @course.id
- @graduation_task.user_id = current_user.id
- @graduation_task.base_on_project = @graduation_task.task_type == 2 ? 1 : 0
- if @graduation_task.save!
- # 为学生创建作品
- @graduation_task.create_work_list
-
- Attachment.associate_container(params[:attachment_ids], @graduation_task.id, @graduation_task.class) if params[:attachment_ids]
- end
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
- end
-
- def new
- left_banner_content = @course.course_modules.search_by_module_type("graduation")
- if left_banner_content.present?
- banner = left_banner_content.first.course_second_categories.last
- @left_banner_id = banner.id
- @left_banner_name = banner.name
- else
- normal_status(-1,"左侧导航不存在!")
- end
- end
-
- def edit
- left_banner_content = @course.course_modules.search_by_module_type("graduation")
- if left_banner_content.present?
- banner = left_banner_content.first.course_second_categories.last
- @left_banner_id = banner.id
- @left_banner_name = banner.name
- end
- end
-
- def update
- ActiveRecord::Base.transaction do
- begin
- @task.update_attributes(graduation_task_params)
- Attachment.associate_container(params[:attachment_ids], @task.id, @task.class) if params[:attachment_ids]
- normal_status(0, "更新成功")
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
- end
-
- # 代码检测
- def sonar
- tip_exception(403, "无权限访问") unless current_user.admin_or_business?
-
- _tasks_list
- @work_list = @work_list.where("work_status > 0")
-
- person_list = @work_list.map do |work|
- o = {
- name: "#{work.user&.real_name}",
- uid: "#{work.user&.student_id}",
- downloadUrl: ''
- }
- attachment = work.attachments.last
- if attachment
- o[:downloadUrl] = "#{edu_setting('host_name')}"+download_url(attachment)
- end
-
- o
- end
- filename = "#{@task.name}_#{Time.now.strftime('%Y%m%d%H%M%S')}.json"
- json = File.open("/tmp/#{filename}", "w+")
- json.puts(person_list.to_json)
- json.close
-
- send_file json.path, filename: filename
- end
-
- # 设为公开
- def set_public
- tip_exception("仅公开课堂才能公开毕设任务") if @course.is_public == 0
- tasks = @course.graduation_tasks.where(id: params[:task_ids])
- tasks.update_all(is_public: 1)
- normal_status(0, "更新成功")
- end
-
- # 删除多个任务
- def multi_destroy
- ActiveRecord::Base.transaction do
- begin
- tasks = @course.graduation_tasks.where(id: params[:task_ids])
-
- tasks.destroy_all
-
- # 这些写是因为model中的关联删除无法删除is_delete=0的作品
- GraduationWork.where(graduation_work_id: tasks.pluck(:id)).destroy_all
- normal_status(0, "删除成功")
-
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
- end
-
- # 加入题库
- def add_to_bank
- ActiveRecord::Base.transaction do
- begin
- tasks = @course.graduation_tasks.where(id: params[:task_ids])
-
- tasks.each do |task|
- task_bank = current_user.gtask_banks.find_by(graduation_task_id: task.id)
-
- # 已加入的更新,未加入的新建
- if task_bank.present?
- task_bank.update_attributes(name: task.name, description: task.description, course_list_id: @course.course_list_id,
- min_num: task.min_num, max_num: task.max_num, base_on_project: task.base_on_project)
- task_bank.attachments.destroy_all
- else
- task_bank = GtaskBank.new(name: task.name, description: task.description, user_id: current_user.id,
- task_type: task.task_type, quotes: 1, graduation_task_id: task.id,
- min_num: task.min_num, max_num: task.max_num, base_on_project: task.base_on_project,
- course_list_id: @course.course_list_id)
-
- task_bank.save!
- task.update_attributes!(gtask_bank_id: task_bank.id)
- end
- task.attachments.each do |attachment|
- att = attachment.copy
- att.author_id = task_bank.user_id
- att.copy_from = attachment.id
- task_bank.attachments << att
- end
- end
-
- normal_status(0,"加入题库成功")
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
- end
-
- def publish_task
- tip_exception("缺少截止时间参数") if params[:end_time].blank?
- tip_exception("截止时间必须晚于当前时间") if params[:end_time] <= strf_time(Time.now)
- tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
- @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day)
-
- # ActiveRecord::Base.transaction do
- begin
- tasks = @course.graduation_tasks.where(id: params[:task_ids], status: 0).
- where("publish_time is null or publish_time > '#{Time.now}'")
-
- tasks.each do |task|
- task.publish_time = Time.now
- task.status = 1
-
- task.end_time = params[:end_time]
-
- # 补交结束时间
- task.late_time = Time.at(task.end_time.to_i + 30*24*3600) if task.allow_late && task.late_time.nil?
-
- task.save!
- GraduationTaskPublishNotifyJob.perform_later(task.id)
- task.act_as_course_activity
- end
- normal_status(0, "发布成功")
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- # end
- end
-
- def end_task
- ActiveRecord::Base.transaction do
- begin
- tasks = @course.graduation_tasks.where(id: params[:task_ids], status: 1)
-
- tasks.each do |task|
- task.end_time = Time.now
- task.status = 2
- task.save!
- end
- normal_status(0, "更新成功")
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
- end
-
- def settings
- @current_user = current_user
- end
-
- def update_settings
- ActiveRecord::Base.transaction do
- begin
- unless @course.is_end
-
- # 分组设置 已有提交作品或关联项目的,则“基于项目实施”不能修改, 已有提交作品的人数限制的范围只能扩大,不能缩小
- if @task.task_type == 2
- @task.min_num = @task.student_commit_works ? (params[:min_num].to_i > @task.min_num ? @task.min_num : params[:min_num])
- : params[:min_num]
- @task.max_num = @task.student_commit_works ? (params[:max_num].to_i < @task.max_num ? @task.max_num : params[:max_num])
- : params[:max_num]
- unless @task.student_relate_projects
- tip_exception("base_on_project参数不能为空") if params[:base_on_project].blank?
- @task.base_on_project = params[:base_on_project].to_i
- end
- end
-
- # 发布设置
- if @task.status == 0
- tip_exception("发布时间不能为空") if params[:publish_time].blank?
- tip_exception("截止时间不能为空") if params[:end_time].blank?
- tip_exception("发布时间不能早于当前时间") if params[:publish_time].to_time <= Time.now
- tip_exception("截止时间不能早于当前时间") if params[:end_time].to_time <= Time.now
- tip_exception("截止时间必须晚于发布时间") if params[:publish_time].to_time >= params[:end_time].to_time
- tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
- @course.end_date.present? && params[:end_time].to_time > @course.end_date.end_of_day
-
- @task.publish_time = params[:publish_time]
- @task.end_time = params[:end_time]
- if @task.publish_time <= Time.now
- @task.status = 1
- send_tiding = true
- end
-
- elsif @task.status < 2
- tip_exception("截止时间不能为空") if params[:end_time].blank?
- tip_exception("截止时间不能早于当前时间") if params[:end_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S")
- tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
- @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day)
- @task.end_time = params[:end_time]
- end
-
- # 补交设置
- # @task.allow_late = params[:allow_late]
- # @task.late_penalty = params[:allow_late].to_i == 1 ? params[:late_penalty] : 0
- current_late_penalty = @task.late_penalty
- if params[:allow_late].to_i == 1
- tip_exception("补交结束时间不能为空") if params[:late_time].blank?
- tip_exception("补交结束时间不能早于截止时间") if params[:late_time] <= @task.end_time
- tip_exception("补交结束时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
- @course.end_date.present? && params[:late_time] > strf_time(@course.end_date.end_of_day)
- tip_exception("迟交扣分应为正整数") if params[:late_penalty] && params[:late_penalty].to_i < 0
-
- @task.allow_late = true
- @task.late_time = params[:late_time]
- @task.late_penalty = params[:late_penalty].to_i
- else
- @task.allow_late = false
- @task.late_penalty = 0
- end
-
- # 迟交扣分有变动则更新迟交学生的成绩
- if @task.late_penalty != current_late_penalty
- @task.graduation_works.where(work_status: 2).each do |work|
- work.late_penalty = @task.late_penalty
- work.save!
- end
- end
-
- # 评分设置
- unless @task.cross_comment && @task.comment_time && @task.comment_time < Time.now
- @task.cross_comment = params[:cross_comment].to_i
-
- tip_exception("评阅时间不能为空") if @task.cross_comment && params[:comment_time].blank?
- tip_exception("评阅时间应当大于截止时间") if @task.cross_comment && params[:comment_time] <= @task.end_time
-
- @task.comment_time = @task.cross_comment ? params[:comment_time] : nil
-
- @task.comment_status = 2 if @task.cross_comment && @task.comment_status == 0
-
- @task.graduation_work_comment_assignations.destroy_all if !@task.cross_comment
- # 去掉评阅设置
- # @task.comment_num = @task.cross_comment ? params[:comment_num].to_i : 3
- # @task.comment_status = @task.cross_comment ? params[:comment_status] : 0
- # if @task.cross_comment && params[:comment_status].to_i == 4
- # tip_exception("评阅数不能为空") if params[:comment_num].blank?
- # tip_exception("评阅数应大于0") if params[:comment_num].to_i < 1
- #
- # @course.graduation_groups.each_with_index do |group, index|
- # ass_group = @task.graduation_task_group_assignations.find_by(graduation_group_id: group.id)
- # if ass_group.present? && params[:comment_group][index].present? && params[:comment_group][index] != "0"
- # ass_group.update_attributes(assign_graduation_group_id: params[:comment_group][index])
- # else
- # @task.graduation_task_group_assignations << GraduationTaskGroupAssignation.new(graduation_group_id: group.id,
- # assign_graduation_group_id: params[:comment_group][index])
- # end
- # end
- # end
- end
-
- # 公开设置
- @task.open_work = params[:open_work] ? params[:open_work].to_i : 0
- @task.open_score = params[:open_score] ? params[:open_score].to_i : 0
- @task.save!
-
- if send_tiding
- GraduationTaskPublishNotifyJob.perform_later(@task.id)
- @task.act_as_course_activity
- end
-
- normal_status(0, "更新成功")
- else
- tip_exception("课堂已结束不能再更新")
- end
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
- end
-
- def cross_comment_setting
- @comment_status = params[:comment_status] || (@task.cross_comment ? @task.comment_status : 2)
- group_ids = @course.charge_group_ids(current_user)
- @course_groups = @course.course_groups.where(id: group_ids)
-
- # 如果传了分班id则取合集
- group_ids = group_ids & params[:group_ids].map(&:to_i) unless params[:group_ids].blank?
- page = params[:page] ? params[:page].to_i : 1
- limit = params[:limit] ? params[:limit].to_i : 10
-
- # 取所有课堂的作品
- if group_ids.sort == @course.course_groups.pluck(:id).sort
- @work_list = @task.graduation_works
- else
- @work_list = @task.graduation_works.joins("join course_members on graduation_works.user_id=course_members.user_id").
- where(course_members: {course_group_id: group_ids})
- end
- @user_count = @work_list.size
- @work_list = @work_list.page(page).per(limit).includes(user: [:user_extension])
- @students = @course.students.where(user_id: @work_list.pluck(:user_id))
- end
-
- def assign_works
- tip_exception("请先选择作品") if params[:work_ids].blank?
- tip_exception("请指定要分配的老师或答辩组") if params[:user_ids].blank? && params[:graduation_group_ids].blank?
-
- ActiveRecord::Base.transaction do
- begin
- works = @task.graduation_works.where(id: params[:work_ids])
- # 手动分配:分配给老师
- if !params[:user_ids].blank?
- @task.update_attributes(comment_status: 2)
- works.each do |work|
- # 之前分配的老师但现在未分配时需要删除
- work.graduation_work_comment_assignations.where.not(user_id: params[:user_ids]).destroy_all
- @course.teachers.where(user_id: params[:user_ids]).pluck(:user_id).uniq.each do |user_id|
- unless work.graduation_work_comment_assignations.exists?(user_id: user_id)
- GraduationWorkCommentAssignation.create!(graduation_task_id: @task.id, graduation_work_id: work.id,
- user_id: user_id)
- end
- end
- end
-
- # 答辩组分配:分配答辩组
- elsif !params[:graduation_group_ids].blank?
- @task.update_attributes(comment_status: 4)
- works.each do |work|
- work.graduation_task_group_assignations.where.not(graduation_group_id: params[:graduation_group_ids]).destroy_all
- @course.graduation_groups.where(id: params[:graduation_group_ids]).pluck(:id).uniq.each do |graduation_group_id|
- unless work.graduation_task_group_assignations.exists?(graduation_group_id: graduation_group_id)
- GraduationTaskGroupAssignation.create!(graduation_task_id: @task.id, graduation_work_id: work.id,
- graduation_group_id: graduation_group_id)
- end
- end
- end
- end
- normal_status("分配成功")
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
- end
-
- def commit_comment_setting
- tip_exception("type参数有误") if params[:type].blank? || !["commit", "cancel"].include?(params[:type])
- ActiveRecord::Base.transaction do
- begin
- # 提交弹框
- # if params[:type] == "commit"
- # tip_exception("comment_status参数有误") if params[:comment_status].blank? || ![2, 4].include?(params[:comment_status].to_i)
- # @task.update_attributes(comment_status: params[:comment_status])
- # if params[:comment_status].to_i == 2
- # @task.temporary_graduation_work_comment_assignations.update_all(temporary: 0) # 临时数据转正
- # @task.delete_graduation_work_comment_assignations.destroy_all # 删除置了删除位的数据
- # @task.graduation_task_group_assignations.destroy_all # 删除答辩组分配数据
- # else
- # @task.temporary_graduation_task_group_assignations.update_all(temporary: 0)
- # @task.delete_graduation_task_group_assignations.destroy_all
- # @task.graduation_work_comment_assignations.destroy_all
- #
- # GraduationTaskCrossCommentJob.perform_later(@task.id)
- # end
- # else
- # # 取消时删除临时数据,恢复删除位数据
- # @task.temporary_graduation_work_comment_assignations.destroy_all # 删除临时数据
- # @task.delete_graduation_work_comment_assignations.update_all(temporary: 0) # 恢复置了删除位的数据
- #
- # @task.temporary_graduation_task_group_assignations.destroy_all # 删除临时数据
- # @task.delete_graduation_task_group_assignations.update_all(temporary: 0) # 恢复置了删除位的数据
- # end
- normal_status("操作成功")
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
- end
-
- private
- def find_task
- begin
- @task = GraduationTask.find(params[:id])
- @course = @task.course
- rescue Exception => e
- uid_logger(e.message)
- tip_exception("id不存在")
- end
- end
-
- # 未发布时非老师角色不能访问,发布后非课堂成员不能访问未公开的任务
- def task_publish
- if (@user_course_identity >= Course::STUDENT && @task.status < 1) ||
- (@user_course_identity > Course::STUDENT && (@course.is_public == 0 || !@task.is_public))
- tip_exception(-1,"任务还未发布,无法查看")
- end
- end
-
- def graduation_task_params
- tip_exception("类型参数不能为空") if params[:task_type].blank?
- tip_exception("名称不能为空") if params[:name].blank?
- tip_exception("名称不能超过60个字符") if params[:name].length > 60 #6.11 -hs
- tip_exception("描述不能为空") if params[:description].blank?
- params.require(:graduation_task).permit(:task_type, :name, :description)
- end
-
- def require_id_params
- tip_exception("请至少选择一个毕设任务") if params[:task_ids].blank?
- tip_exception("批量设置不能超过15个") if params[:task_ids].length > 15
- end
-
- def valid_params
- if @task.task_type == 2
- tip_exception("最小人数不能为空") if params[:min_num].blank?
- tip_exception("最大人数不能为空") if params[:max_num].blank?
- tip_exception("最小人数不能少于1") if params[:min_num].to_i <= 0
- tip_exception("最大人数不能小于最小人数要求") if params[:min_num].to_i > params[:max_num].to_i
- end
- end
-
- def allow_cross_comment
- tip_exception("请先开启交叉评阅再设置") unless @task.cross_comment
- end
-
- def _tasks_list
- # 如有有分班则看分班内的学生,否则看所有学生的作品
- user_ids =
- if @user_course_identity < Course::STUDENT
- @course.teacher_group_user_ids(current_user.id)
- else
- course_group_id = @course.course_member(current_user.id).course_group_id
- @course.students.where(course_group_id: course_group_id).pluck(:user_id)
- end
-
- @work_list = @task.graduation_works.where(user_id: user_ids).includes(user: [:user_extension])
- @all_work_count = @work_list.count
- @teachers = @course.teachers.where.not(user_id: current_user.id).includes(:user)
- # 教师评阅搜索 0: 未评, 1 已评
- unless params[:teacher_comment].blank?
- graduation_work_ids = GraduationWorkScore.where(graduation_work_id: @work_list.map(&:id)).pluck(:graduation_work_id)
- if params[:teacher_comment].to_i == 0
- @work_list = @work_list.where("work_status != 0")
- elsif params[:teacher_comment].to_i == 1
- @work_list = @work_list.where("work_status != 0").where(id: graduation_work_ids)
- end
- end
-
- # 作品状态 0: 未提交, 1 按时提交, 2 延迟提交
- unless params[:task_status].blank?
- @work_list = @work_list.where(work_status: params[:task_status])
- end
-
- # 分班情况
- unless params[:course_group].blank?
- group_user_ids = @course.students.where(course_group_id: params[:course_group]).pluck(:user_id)
- # 有分组只可能是老师身份查看列表
- @work_list = @work_list.where(user_id: group_user_ids)
- end
-
- # 只看我的交叉评阅
- unless params[:cross_comment].blank?
- graduation_work_id = @task.graduation_work_comment_assignations.where(:user_id =>current_user.id)
- .pluck(:graduation_work_id).uniq if @task.graduation_work_comment_assignations
- @work_list = @task.graduation_works.where(id: graduation_work_id)
- end
-
- # 组员、组长作品的筛选
- if @task.task_type == 2 && !params[:member_work].blank?
- if params[:member_work].to_i == 1
- @work_list = @work_list.where("user_id = commit_user_id")
- elsif params[:member_work].to_i == 0
- @work_list = @work_list.where("user_id != commit_user_id")
- end
- end
-
- # 输入姓名和学号搜索
- # TODO user_extension 如果修改 请调整
- unless params[:search].blank?
- @work_list = @work_list.joins(user: :user_extension).where("concat(lastname, firstname) like ?
- or student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%")
- end
- end
-
- #
- # def graduation_work_to_xls items
- # xls_report = StringIO.new
- # book = Spreadsheet::Workbook.new
- # sheet1 = book.create_worksheet :name => "学生成绩"
- # blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
- # sheet1.row(0).default_format = blue
- # course = @task.course
- # count_row = 1
- # list = 0
- # if @task.task_type == 1
- # if @task.cross_comment
- # sheet1.row(0).concat(["学生id","真实姓名", "登录名", "学号", "电子邮箱", "分班", "作品描述", "教师评分","交叉评分", "迟交扣分",
- # "成绩", "更新时间"])
- # else
- # sheet1.row(0).concat(["学生id", "真实姓名", "登录名", "学号", "电子邮箱", "分班", "作品描述", "教师评分", "迟交扣分",
- # "成绩", "更新时间"])
- # end
- # items.each do |work|
- # sheet1[count_row,list] = work.user.id
- # sheet1[count_row,list+=1] = work.user.full_name
- # sheet1[count_row,list+=1] = work.user.login
- # sheet1[count_row,list+=1] = work.user.student_id
- # sheet1[count_row,list+=1] = work.user.mail
- # sheet1[count_row,list+=1] = work.class_grouping_name
- # sheet1[count_row,list+=1] = strip_html work.description if work.description
- # sheet1[count_row,list+=1] = work.teacher_score.nil? ? "未评分" : work.teacher_score.round(1)
- # if @task.cross_comment
- # sheet1[count_row,list+=1] = work.cross_score.nil? ? "未评分" : work.cross_score.round(1)
- # end
- # sheet1[count_row,list+=1] = work.late_penalty
- # sheet1[count_row,list+=1] = work.respond_to?("work_score") ? work.work_score.nil? ? "未评分" : work.work_score.round(1) : "未评分"
- # sheet1[count_row,list+=1] = format_time(work.update_time)
- # count_row += 1
- # list = 0
- # end
- # elsif @task.task_type == 2
- # if @task.cross_comment
- # sheet1.row(0).concat(["分组", "组员","分班", "作品描述", "教师评分","交叉评分","迟交扣分", "成绩", "更新时间"])
- # else
- # sheet1.row(0).concat(["分组", "组员","分班", "作品描述", "教师评分", "迟交扣分", "成绩", "更新时间"])
- # end
- # items.each do |work|
- # sheet1[count_row,list] = work.group_id
- # sheet1[count_row,list+=1] = work.user.full_name
- # sheet1[count_row,list+=1] = work.class_grouping_name
- # sheet1[count_row,list+=1] = strip_html work.description if work.description
- # sheet1[count_row,list+=1] = work.teacher_score.nil? ? "未评分" : work.teacher_score.round(1)
- # if @task.cross_comment
- # sheet1[count_row,list+=1] = work.cross_score.nil? ? "未评分" : work.cross_score.round(1)
- # end
- # sheet1[count_row,list+=1] = work.late_penalty
- # sheet1[count_row,list+=1] = work.respond_to?("work_score") ? work.work_score.nil? ? "未评分" : work.work_score.round(1) : "未评分"
- # sheet1[count_row,list+=1] = format_time(work.update_time)
- # count_row += 1
- # list = 0
- # end
- # end
- # book.write xls_report
- # xls_report.string
- # end
-
-end
diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb
deleted file mode 100644
index 59da737..0000000
--- a/app/controllers/student_works_controller.rb
+++ /dev/null
@@ -1,896 +0,0 @@
-class StudentWorksController < ApplicationController
- include HomeworkCommonsHelper
- include StudentWorksHelper
-
- before_action :require_login, :check_auth
- before_action :find_homework, only: [:new, :create, :search_member_list, :check_project, :relate_project,
- :cancel_relate_project, :delete_work]
- before_action :find_work, only: [:shixun_work_report, :adjust_review_score, :shixun_work, :commit_des, :update_des,
- :adjust_score, :show, :adjust_score, :supply_attachments, :revise_attachment,
- :comment_list, :add_score, :add_score_reply, :destroy_score, :appeal_anonymous_score,
- :deal_appeal_score, :cancel_appeal, :edit, :update, :export_shixun_work_report,
- :shixun_work_comment, :destroy_work_comment]
- before_action :user_course_identity
- before_action :allow_add_score, only: [:add_score]
- before_action :homework_publish
-
- before_action :teacher_allowed, only: [:adjust_score, :adjust_review_score, :deal_appeal_score, :shixun_work_comment,
- :destroy_work_comment]
-
- before_action :course_student, only: [:new, :commit_des, :update_des, :create, :edit, :update, :search_member_list, :relate_project,
- :cancel_relate_project, :relate_project, :delete_work]
-
- before_action :my_work, only: [:commit_des, :update_des, :edit, :update, :revise_attachment, :appeal_anonymous_score,
- :cancel_appeal]
-
- before_action :edit_duration, only: [:edit, :update, :delete_work]
- before_action :end_or_late, only: [:new, :create, :search_member_list, :commit_des, :update_des]
-
- before_action :require_score_id, only: [:destroy_score, :add_score_reply, :appeal_anonymous_score, :deal_appeal_score, :cancel_appeal]
-
- before_action :is_evaluation, :open_work, only: [:show, :supply_attachments]
-
- def new
- uid_logger("#######new current_user : 1111")
- @current_user = current_user
- uid_logger("#######new current_user : #{@current_user.id}")
- if @homework.homework_type == "group" && @homework.homework_detail_group.try(:base_on_project)
- work = @homework.student_works.find_by(user_id: @current_user.id)
- if work.present? && (work.work_status != 0 || work.project_id == 0)
- normal_status(403, "")
- end
- end
- end
-
- # 搜索课堂学生
- def search_member_list
- # 统一设置的作业取所有学生,否则取已发布的分班学生
- students = @homework.unified_setting? ? @course.students : @course.students.where(course_group_id: @homework.published_settings.pluck(:course_group_id))
- if !params[:search].blank?
- @members = students.joins(user: :user_extension).where("course_members.user_id != #{current_user.id} and (concat(users.lastname, users.firstname)
- like ? or user_extensions.student_id like ?)", "%#{params[:search]}%", "%#{params[:search]}%")
- else
-
- # 没有搜索条件时搜索课堂所有未提交的学生
- user_ids = @homework.student_works.where("work_status = 0").pluck(:user_id) - [current_user.id]
- @members = students.where(user_id: user_ids)
- end
-
- page = params[:page] ? params[:page].to_i : 1
- limit = params[:limit] ? params[:limit].to_i : 10
-
- # todo user_extension
- @members = @members.page(page).per(limit).includes(:course_group, user: :user_extension)
- end
-
- def delete_work
- ActiveRecord::Base.transaction do
- begin
- work = @homework.student_works.find_by!(user_id: params[:user_id])
- tip_exception("只有组长才能删除组员") if work.commit_user_id != current_user.id
- work.update_attributes!(description: nil, project_id: 0,
- late_penalty: 0, work_status: 0,
- commit_time: nil, update_time: nil, group_id: 0,
- commit_user_id: nil, final_score: nil, work_score: nil, teacher_score: nil, teaching_asistant_score: nil)
- work.attachments.destroy_all
- work.tidings.destroy_all
- normal_status("删除成功")
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- end
- end
- end
-
- def create
- student_work = @homework.student_works.find_or_create_by(user_id: current_user.id)
-
- tip_exception("作业不可重复提交") if student_work.work_status != 0
- update_check student_work
-
- student_ids = [current_user.id]
- ActiveRecord::Base.transaction do
- begin
- student_work.description = params[:description]
- student_work.commit_time = Time.now
- student_work.update_time = Time.now
- student_work.commit_user_id = current_user.id
- student_work.update_user_id = current_user.id
- student_work.group_id = @homework.homework_type == "group" ? @homework.max_group_id : 0
-
- #提交作品时,计算是否迟交
- homework_setting = @homework.homework_group_setting(current_user.id)
- student_work.late_penalty = homework_setting.end_time < Time.now ? @homework.late_penalty : 0
- student_work.work_status = homework_setting.end_time < Time.now ? 2 : 1
-
- if student_work.save!
- Attachment.associate_container(params[:attachment_ids], student_work.id, student_work.class)
-
- if @homework.homework_type == "group"
- members = (params[:user_ids] || []).collect(&:to_i) - [current_user.id]
- members = @course.students.pluck(:user_id) & members
- student_ids += members
- for i in 0 .. members.count-1
- stu_work = @homework.student_works.find_or_initialize_by(user_id: members[i].to_i)
- stu_work.update_attributes!(user_id: members[i].to_i, description: student_work.description,
- homework_common_id: @homework.id, project_id: student_work.project_id,
- late_penalty: student_work.late_penalty, work_status: student_work.work_status,
- commit_time: Time.now, update_time: Time.now, group_id: student_work.group_id,
- commit_user_id: current_user.id, update_user_id: current_user.id)
- stu_work.save!
- student_work.attachments.each do |attachment|
- att = attachment.copy
- att.author_id = attachment.author_id
- stu_work.attachments << att
- end
- end
- end
- @homework.update_column(:updated_at, Time.now)
- # todo 更新对应的作业课堂动态
- # update_course_activity(@taskhomework.class,@task.id)
-
- @work_id = student_work.id
- end
-
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
-
- SubmitStudentWorkNotifyJob.perform_later(@homework.id, student_ids)
- end
-
- def edit
- @current_user = current_user
- if @homework.homework_type == "group"
- # todo user_extension
- @commit_user_id = @work.commit_user_id
- @work_members = @course.students.where(user_id: @homework.student_works.where(group_id: @work.group_id).pluck(:user_id)).
- order("course_members.user_id=#{@work.commit_user_id} desc").includes(:course_group, user: :user_extension)
- end
- end
-
- def update
- update_check @work
-
- student_ids = []
- ActiveRecord::Base.transaction do
- begin
- @work.description = params[:description]
- @work.update_time = Time.now
- @work.update_user_id = current_user.id
- # @work.commit_user_id = current_user.id
- if @work.save!
- Attachment.associate_container(params[:attachment_ids], @work.id, @work.class)
-
- #如果学生作品被打分后修改,应该给老师提示
- student_ids << @work.user_id if @work.scored?
-
- if @homework.homework_type == "group"
- student_works = @homework.student_works.where("group_id = #{@work.group_id} and user_id != #{@work.user_id}")
- work_user_ids = student_works.pluck(:user_id)
- params_user_ids = (params[:user_ids] || []).collect(&:to_i) - [@work.user_id]
- params_user_ids = @course.students.pluck(:user_id) & params_user_ids
-
- # 原成员更新描述、更新时间以及附件
- @homework.student_works.where(group_id: @work.group_id, user_id: (work_user_ids & params_user_ids)).each do |work|
- # work.update_attributes(update_time: Time.now, description: @work.description, commit_user_id: current_user.id)
- work.update_attributes!(update_time: Time.now, description: @work.description, update_user_id: current_user.id)
- work.attachments.destroy_all
- @work.attachments.each do |attachment|
- att = attachment.copy
- att.author_id = attachment.author_id
- work.attachments << att
- end
- student_ids << work.user_id if work.scored?
- end
-
- # 删除的成员
- delete_user_ids = work_user_ids - params_user_ids
- @homework.student_works.where(group_id: @work.group_id, user_id: delete_user_ids).each do |work|
- work.attachments.destroy_all
- # work.student_works_scores.destroy_all
- work.tidings.destroy_all
- end
- @homework.student_works.where(group_id: @work.group_id, user_id: delete_user_ids).
- update_all(work_status: 0, description: nil, late_penalty: 0, commit_time: nil, update_time: nil,
- final_score: nil, teacher_score: nil, student_score: nil, teaching_asistant_score: nil,
- work_score: nil, project_id: 0, group_id: 0, commit_user_id: nil, update_user_id: nil)
-
- # 新增加的成员
- (params_user_ids - work_user_ids).each do |user_id|
- stu_work = @homework.student_works.find_or_initialize_by(user_id: user_id)
- stu_work.update_attributes!(user_id: user_id, description: @work.description, homework_common_id: @homework.id,
- project_id: @work.project_id, late_penalty: @work.late_penalty,
- work_status: @work.work_status, commit_time: Time.now, update_time: Time.now,
- group_id: @work.group_id, commit_user_id: @work.commit_user_id, update_user_id: current_user.id)
- @work.attachments.each do |attachment|
- att = attachment.copy
- att.author_id = attachment.author_id
- stu_work.attachments << att
- end
-
- student_ids << user_id
- end
- end
-
- normal_status(0,"更新成功")
- end
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
-
- ResubmitStudentWorkNotifyJob.perform_later(@homework.id, student_ids) if student_ids.present?
- end
- end
-
- def show
- @current_user = current_user
- @work_members = @homework.homework_type != "group" ? [] : @homework.student_works.where.not(user_id: @work.user_id).
- where(group_id: @work.group_id).includes(:user)
- @attachments = @work.attachments.where("attachtype != 7 or attachtype is null")
- end
-
- # 判断项目是否已有其他作品关联上了
- def check_project
- tip_exception("项目id不能为空") if params[:project_id].blank?
- work = @homework.student_works.find_by_project_id(params[:project_id])
- @is_relate = work.present?
- @relate_user = work.present? ? work.user.real_name : ""
- end
-
- def relate_project
- tip_exception("项目id不能为空") if params[:project_id].blank?
-
- ActiveRecord::Base.transaction do
- begin
- # 判断项目是否存在且当前用户是项目管理员
- project = Project.find_by_id(params[:project_id])
- member = Member.find_by_project_id_and_user_id(project.try(:id), current_user.id)
-
- if project.present? && member.present? && member.member_roles.take.try(:role_id) == 3
-
- work = @homework.student_works.find_or_create_by(user_id: current_user.id)
-
- if work.work_status == 0 && work.project_id == 0
- work.update_attributes!(project_id: project.id, update_time: Time.now)
-
- # 将老师加入项目
- project_member = project.members.find_by_user_id(@homework.user_id)
- if project_member.present?
- project_member.member_roles.take.update_attributes!(role_id: 3) if project_member.member_roles.take.present?
- else
- member = Member.create!(user_id: @homework.user_id, project_id: project.id)
- member.member_roles << MemberRole.new(role_id: 3)
- Tiding.create(user_id: @homework.user_id, trigger_user_id: current_user.id, container_id: project.id,
- container_type: 'ManagerJoinProject', belong_container_id: project.id,
- belong_container_type: "Project", tiding_type: "System", extra: 3)
- end
- normal_status(0,"关联成功")
- else
- tip_exception("不能重复关联项目")
- end
- else
- tip_exception("该项目不存在")
- end
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
- end
-
- def cancel_relate_project
- work = @homework.student_works.find_by_user_id_and_work_status(current_user.id, 0)
- if work.present? && work.project.present?
- ActiveRecord::Base.transaction do
- begin
- member = work.project.members.find_by_user_id(@homework.user_id)
- member.destroy if member.present?
- Tiding.where(user_id: @homework.user_id, trigger_user_id: current_user.id, container_id: work.project.id,
- container_type: 'ManagerJoinProject').destroy_all
-
- work.update_attributes!(project_id: 0)
- normal_status(0,"取消关联成功")
-
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
- else
- tip_exception("无法取消关联")
- end
- end
-
- def supply_attachments
- @revise_attachments = @work.attachments.where(attachtype: 7)
- @last_atta = @revise_attachments.last
- end
-
- def revise_attachment
- tip_exception("不在补交阶段内") unless @homework.late_duration
- tip_exception("附件参数有误") if params[:attachment_ids].blank? || !params[:attachment_ids].is_a?(Array)
- tip_exception("补交附件原因不能为空") if params[:description].blank?
-
- ActiveRecord::Base.transaction do
- begin
- # 补交作业附件不覆盖之前上传的附件
- # revise_attachment = @work.attachments.where(attachtype: 7).reorder("created_on desc").last
- # if revise_attachment.present? && @work.student_works_scores.where("created_at > '#{revise_attachment.created_on}'
- # and score is not null").count == 0
- # revise_attachment.destroy
- # end
- Attachment.associate_container(params[:attachment_ids], @work.id, @work.class, 7)
- revise_attachment = Attachment.where(attachtype: 7, container_id: @work.id, container_type: "StudentWork").last
- revise_attachment.update_attributes!(description: params[:description]) if revise_attachment.present?
-
- @work.update_attributes!(update_time: Time.now)
-
- # 补交附件时给评阅过作品的教师、助教发消息
- unless @work.student_works_scores.where.not(score: nil).where(reviewer_role: [1, 2]).pluck(:user_id).uniq.blank?
- ResubmitStudentWorkNotifyJob.perform_later(@homework.id, [current_user.id])
- end
-
- normal_status(0, "提交成功")
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
- end
-
- def comment_list
- @current_user = current_user
- @last_comment = @work.student_works_scores.where(user_id: @current_user.id).last
- # todo user_extension
- @comment_scores = (@user_course_identity < Course::STUDENT || current_user == @work.user) ?
- @work.student_works_scores.reorder("created_at desc") :
- @work.student_works_scores.where(user_id: current_user.id).reorder("created_at desc")
- @comment_scores = @comment_scores.includes(:student_works_scores_appeal, :attachments, journals_for_messages: :user, user: :user_extension)
- end
-
- # 给作品评分
- def add_score
- tip_exception("该学生的分数已经过调整,不能再评阅") if @work.ultimate_score
- tip_exception("分数和评语不能都为空") if params[:score].blank? && params[:comment].blank?
- tip_exception("分数不能超过0-100") if params[:score] && (params[:score].to_f < 0 || params[:score].to_f > 100)
-
- ActiveRecord::Base.transaction do
- begin
- # 没传score则取上次评分成绩
- reviewer_role = @user_course_identity == Course::STUDENT ? 3 : @user_course_identity == Course::ASSISTANT_PROFESSOR ? 2 : 1
- new_score = StudentWorksScore.new
- score = StudentWorksScore.where(user_id: current_user.id, student_work_id: @work.id, reviewer_role: reviewer_role).last
- new_score.score = params[:score].blank? ? score.try(:score) : params[:score].to_f
- new_score.comment = params[:comment] if params[:comment] && params[:comment].strip != ""
- new_score.user_id = current_user.id
- new_score.student_work_id = @work.id
-
- # 如果作品是未提交的状态则更新为已提交
- if @user_course_identity < Course::STUDENT && !new_score.score.nil? && @work.work_status == 0
- @work.update_attributes!(work_status: 1, commit_time: Time.now)
- # 分组作业更新分组id
- @work.update_attributes!(group_id: @homework.max_group_id) if @homework.homework_type == "group"
- end
-
- new_score.reviewer_role = reviewer_role
-
- if new_score.save!
- Attachment.associate_container(params[:attachment_ids], new_score.id, new_score.class)
-
- # 该用户的历史评阅无效
- score.update_column('is_invalid', true) if score.present? && score.score.present?
-
- Tiding.create(user_id: @work.user_id, trigger_user_id: User.current.id, container_id: new_score.id,
- container_type: "StudentWorksScore", parent_container_id: @work.id,
- parent_container_type: "HomeworkCommon", belong_container_id: @homework.course_id,
- belong_container_type: "Course", viewed: 0, tiding_type: new_score.reviewer_role == 3 ? "System" : "HomeworkCommon", extra: new_score.reviewer_role)
-
- case new_score.reviewer_role
- when 1 #教师评分:最后一个教师评分为最终评分
- @work.teacher_score = new_score.score
- if @homework.homework_type == "group" && params[:same_score]
- add_score_to_member @work, @homework, new_score
- end
- when 2 #教辅评分 教辅评分显示平均分
- # 助教评分:普通模式则是平均分,复审模式则是最新评分
- if @homework.homework_detail_manual.ta_mode == 1
- @work.teaching_asistant_score = new_score.ta_score @work.id
- else
- @work.teaching_asistant_score = new_score.score
- end
-
- if @homework.homework_type == "group" && params[:same_score]
- add_score_to_member @work, @homework, new_score
- end
- when 3 #学生评分 学生评分显示平均分
- # 匿评分
- @work.student_score = new_score.stu_score(@work.id)
- if @homework.homework_type == "group" && new_score.score.present?
- add_score_to_member @work, @homework, new_score
- end
-
- current_user.student_works_scores.where(student_work_id: @work.id, reviewer_role: 3, appeal_status: 1).update_all(appeal_status: 5)
- end
-
- @homework.update_column('updated_at', Time.now)
- # update_course_activity(@homework.class,@homework.id)
- @work.save!
-
- normal_status(0,"提交成功")
- end
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
- end
-
- # 实训作品的提交总结
- def commit_des
- @current_user = current_user
- end
-
- # 实训作品的总结
- def update_des
- @work.update_attributes!(des_params)
- tip_exception(0, "提交成功")
- end
-
- # 实训作品弹框
- def shixun_work
- @myshixun = @work.myshixun
- if @myshixun.present?
- @current_user = current_user
- @work_user = @work.user
- @shixun = @homework.shixuns.take
- else
- tip_exception("作品还未提交")
- end
- end
-
- # 实训报告
- def shixun_work_report
- @user = @work.user
- @shixun = @homework.shixuns.take
- # 提示: 这里如果includes outputs表的话: sum(:evaluate_count)会出现错误
- @games = @work.myshixun.games.joins(:challenge).reorder("challenges.position asc") if @work.myshixun
- @challenges = @shixun.challenges if @shixun
- @comment = @work.shixun_work_comments.find_by(challenge_id: 0)
-
- # 用户最大评测次数
- if @games
- @user_evaluate_count = @games.pluck(:evaluate_count).sum
- @games = @games.includes(:challenge, :game_codes, :outputs)
- else
- @user_evaluate_count = 0
- end
-
- # 图形效率图的数据
- @echart_data = student_efficiency(@homework, @work) if @work.myshixun
- end
-
- # 实训作品的评阅
- def shixun_work_comment
- tip_exception("请至少输入一个评阅") if params[:comment].blank? && params[:hidden_comment].blank?
- ActiveRecord::Base.transaction do
- challenge = @homework.shixuns.first&.challenges.find_by(id: params[:challenge_id]) unless params[:challenge_id].blank?
- if challenge.present?
- @comment = @work.shixun_work_comments.find_by(challenge_id: challenge.id) ||
- ShixunWorkComment.new(student_work_id: @work.id, user_id: current_user.id, challenge_id: challenge.id)
- else
- @comment = @work.shixun_work_comments.find_by(challenge_id: 0) ||
- ShixunWorkComment.new(student_work_id: @work.id, user_id: current_user.id, challenge_id: 0)
- end
- @comment.comment = params[:comment]
- @comment.hidden_comment = params[:hidden_comment]
- @comment.save!
- if @work.work_status == 0
- @work.update_attributes!(work_status: 1, commit_time: @homework.end_time, update_time: Time.now, work_score: 0, final_score: 0)
- end
- end
- end
-
- # 删除实训作品评阅
- def destroy_work_comment
- ActiveRecord::Base.transaction do
- # tip_exception("visible_comment参数有误") if params[:visible_comment].nil?
-
- comment = @work.shixun_work_comments.find_by!(id: params[:comment_id])
- comment.destroy!
- # params[:visible_comment] ? comment.comment = nil : comment.hidden_comment = nil
- # if comment.comment.nil? && comment.hidden_comment.nil?
- # comment.destroy!
- # else
- # comment.save!
- # end
- normal_status("删除成功")
- end
- end
-
- def export_shixun_work_report
- @user = @work.user
- @shixun = @homework.shixuns.take
- @games = @work.myshixun.games.includes(:challenge, :game_codes, :outputs) if @work.myshixun
- @challenges = @shixun.challenges if @shixun
-
- # 用户最大评测次数
- @user_evaluate_count = @games.pluck(:evaluate_count).sum if @games
- # 图形效率图的数据
- @echart_data = student_efficiency(@homework, @work)
- @myself_eff = @echart_data[:efficiency_list].find { |item| item.last == @user.id }
- @myself_consume = @echart_data[:consume_list].find { |item| item.last == @user.id }
- filename_ = "#{@homework.course&.user_group_name(@work.user_id)}_#{@user&.student_id}_#{@user&.real_name}_#{@shixun&.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}.pdf"
- filename = filename_.strip.tr("+/", "-_")
- stylesheets = %w(shixun_work/shixun_work.css shared/codemirror.css)
- if params[:export].present? && params[:export]
- normal_status(0,"正在下载中")
- else
- set_export_cookies
- render pdf: 'shixun_work/shixun_work', filename: filename, stylesheets: stylesheets, disposition: 'inline', type:"pdf_attachment.content_type",stream:false
- end
- # render pdf: 'shixun_work/shixun_work', filename: filename, stylesheets: stylesheets, disposition: 'inline', type:"pdf_attachment.content_type",stream:false
- end
-
- # 作品调分
- def adjust_score
- tip_exception("成绩不能为空") if params[:score].blank?
- tip_exception("成绩不能小于零") if params[:score].to_f < 0
- tip_exception("成绩不能大于100") if params[:score].to_f.round(1) > 100
- tip_exception("调分原因不能超过100个字符") if params[:comment].present? && params[:comment].length > 100
- ActiveRecord::Base.transaction do
- begin
- # 分数不为空的历史评阅都置为失效
- @work.student_works_scores.where.not(score: nil).update_all(is_invalid: 1)
- reviewer_role = @user_course_identity == Course::ASSISTANT_PROFESSOR ? 2 : 1
- new_score = StudentWorksScore.new(student_work_id: @work.id, score: params[:score].to_f, comment: "使用调分功能调整了作业最终成绩:#{params[:comment]}",
- user_id: current_user.id, reviewer_role: reviewer_role, is_ultimate: 1)
- new_score.save!
-
- # 如果作品是未提交的状态则更新为已提交
- if @work.work_status == 0
- @work.work_status = 1
- @work.commit_time = Time.now
- @work.compelete_status = 1 if @homework.homework_type == "practice"
- # 分组作业更新分组id
- @work.group_id = @homework.max_group_id if @homework.homework_type == "group"
- end
-
- @work.ultimate_score = true
- @work.work_score = params[:score].to_f
- @work.save!
-
- Tiding.create!(user_id: @work.user_id, trigger_user_id: current_user.id, container_id: new_score.id,
- container_type: "AdjustScore", parent_container_id: @homework.id,
- parent_container_type: "HomeworkCommon", belong_container_id: @course.id,
- belong_container_type: 'Course', tiding_type: "HomeworkCommon")
-
- normal_status(0,"调分成功")
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
- end
-
- #添加评分的回复
- def add_score_reply
- tip_exception("回复内容不能为空") if params[:comment].blank?
- ActiveRecord::Base.transaction do
- begin
- score = @work.student_works_scores.find_by!(id: params[:score_id])
- jour = score.journals_for_messages.new(user_id: current_user.id, notes: params[:comment], reply_id: score.user_id)
- jour.save!
- normal_status(0,"回复成功")
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
- end
-
- # 删除教师/教辅的评分记录
- def destroy_score
- score = @work.student_works_scores.find_by(id: params[:score_id])
- tip_exception("该评阅记录不存在") unless score.present?
- tip_exception("该评阅记录不能删除") unless score.allow_delete(current_user)
- begin
- score.destroy
- normal_status(0,"删除成功")
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
-
- # 对学生匿评进行申诉
- def appeal_anonymous_score
- tip_exception("申诉原因不能为空") if params[:comment].blank?
- score = @work.student_works_scores.find_by(id: params[:score_id].to_i)
- tip_exception("无法申诉") unless score.present? && @homework.appeal_duration &&
- score.reviewer_role == 3 && score.appeal_status == 0
- score_appeal = nil
- ActiveRecord::Base.transaction do
- begin
- score.update_attributes!(appeal_status: 1)
- score_appeal = StudentWorksScoresAppeal.create!(user_id: current_user.id, student_works_score_id: score.id,
- comment: params[:comment], appeal_status: 1)
-
- normal_status(0,"提交成功")
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
- # 提交后给老师和助教、匿评人发消息
- StudentWorkScoreAppealNotifyJob.perform_later(@course.id, score_appeal.id, current_user.id)
- end
-
- # 撤销申诉
- def cancel_appeal
- score = @work.student_works_scores.find_by(id: params[:score_id].to_i)
- if score.present? && score.appeal_status == 1
- ActiveRecord::Base.transaction do
- begin
- score.update_attributes!(appeal_status: 2)
- score_appeal = score.student_works_scores_appeal
- score_appeal.update_attributes!(appeal_status: 2)
- score_appeal.tidings.destroy_all
- normal_status(0,"撤销成功")
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
- else
- tip_exception("无法撤销")
- end
- end
-
- # status 3 接受 4 拒绝
- def deal_appeal_score
- tip_exception("缺少status参数") if params[:status].blank?
- tip_exception("status值不合要求") unless params[:status].to_i == 3 || params[:status].to_i == 4
- score = @work.student_works_scores.find_by(id: params[:score_id].to_i)
- if score.present? && score.appeal_status == 1
- ActiveRecord::Base.transaction do
- begin
- # 更新appeal_status的值
- score.update_attributes!(appeal_status: params[:status].to_i)
- score_appeal = score.student_works_scores_appeal
- score_appeal.update_attributes!(appeal_status: params[:status].to_i)
- score_appeal.tidings.update_all(status: 1)
-
- if params[:status].to_i == 3
- # 申诉成功后该评分失效
- score.update_attributes!(is_invalid: 1)
-
- # 申诉成功后 扣匿评学生的违规匿评扣分
- sw = @homework.student_works.find_by(user_id: score.user_id)
- sw.update_attributes!(appeal_penalty: @homework.homework_detail_manual.appeal_penalty + sw.appeal_penalty) if sw.present?
-
- # 申诉成功 重新计算申诉者的匿评分
- if @work.student_works_scores.where("reviewer_role = 3 AND appeal_status != 3").count > 0
- @work.student_score = score.stu_score(@work.id)
- else
- @work.student_score = nil
- end
- @work.save!
- end
-
- # todo tiding
- Tiding.create(user_id: score_appeal.user_id, trigger_user_id: current_user.id, container_id: score_appeal.id,
- container_type: "StudentWorksScoresAppeal", parent_container_id: @work.id,
- parent_container_type: 'UserAppealResult', belong_container_id: @course.id,
- belong_container_type: "Course", viewed: 0, status: params[:status].to_i == 3 ? 1 : 2,
- tiding_type: "HomeworkCommon")
- Tiding.create(user_id: score.user_id, trigger_user_id: current_user.id, container_id: score_appeal.id,
- container_type: "StudentWorksScoresAppeal", parent_container_id: @work.id,
- parent_container_type: 'AppealResult', belong_container_id: @course.id, belong_container_type: "Course",
- viewed: 0, status: params[:status].to_i == 3 ? 1 : 2, tiding_type: "HomeworkCommon")
-
- normal_status(0,"提交成功")
- rescue Exception => e
- uid_logger(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
- end
- end
- else
- tip_exception("该申诉不存在")
- end
- end
-
- # 查重作品调分
- def adjust_review_score
- tip_exception("缺少type参数") if params[:type].blank? || !["review", "report"].include?(params[:type])
- if params[:type] == "review" && (params[:score].blank? || params[:challenge_id].blank? || params[:code_rate].blank? || params[:copy_user_id].blank?)
- tip_exception("参数错误,score和challenge_id和code_rate和copy_user_id不能为空")
- elsif params[:type] == "report" && (params[:score].blank? || params[:challenge_id].blank?)
- tip_exception("参数错误,score和challenge_id不能为空")
- end
- challenge_setting = @homework.homework_challenge_settings.find_by(challenge_id: params[:challenge_id])
- if challenge_setting
- challenge = challenge_setting&.challenge
- tip_exception("不能小于零") if params[:score].to_i < 0
- tip_exception("不能大于关卡分值:#{challenge_setting.score}分") if challenge_setting && challenge_setting.score < params[:score].to_i
-
- ActiveRecord::Base.transaction do
- begin
- if params[:type] == "review"
- copy_user = User.find params[:copy_user_id]
- comment = "代码查重结果显示与#{copy_user.try(:show_real_name)}的代码相似度#{params[:code_rate]}%"
- else
- comment = "根据实训报告中最终提交的代码调整第#{challenge.position}关分数"
- end
- challenge_score = @work.challenge_work_scores.create!(challenge_id: params[:challenge_id], user_id: current_user.id, score: params[:score],
- comment: comment)
- challenge_score.create_tiding current_user.id
- if @work.work_status != 0 && @work.myshixun
- games = @work.myshixun.games.where(challenge_id: @homework.homework_challenge_settings.pluck(:challenge_id))
- HomeworksService.new.update_myshixun_work_score @work, @work.myshixun, games, @homework, @homework.homework_challenge_settings
- else
- update_none_commit_work @work, @homework
- end
- rescue Exception => e
- uid_logger(e.message)
- tip_exception("调分失败")
- raise ActiveRecord::Rollback
- end
- end
- else
- tip_exception("该关卡不记分")
- end
- end
-
-
- private
-
- def find_homework
- begin
- @homework = HomeworkCommon.find params[:homework_common_id]
- @course = @homework.course
- rescue Exception => e
- uid_logger_error("##########{e.message}")
- missing_template
- end
- end
-
- def find_work
- begin
- @work = StudentWork.find params[:id]
- @homework = @work.homework_common
- @course = @homework.course
- rescue Exception => e
- uid_logger_error("##########{e.message}")
- missing_template
- end
- end
-
- def homework_public
- tip_exception(403,"没有操作权限") unless @user_course_identity <= Course::STUDENT ||
- (@course.is_public == 1 && @homework.is_public)
- end
-
- def course_student
- uid_logger("#########course-student")
- tip_exception(403,"没有操作权限") if @user_course_identity != Course::STUDENT
- end
-
- def my_work
- tip_exception(403,"没有操作权限") if @work.user_id != current_user.id || @work.work_status == 0
- end
-
- def edit_duration
- tip_exception("已过了修改时间") if @homework.end_time && @homework.end_time < Time.now
- end
-
- def end_or_late
- tip_exception("不在提交/更新阶段") if @homework.end_or_late
- end
-
- def des_params
- tip_exception("description参数不能为空") if params[:description].blank?
- params.require(:student_work).permit(:description)
- end
-
- def require_score_id
- tip_exception("score_id参数不能为空") if params[:score_id].blank?
- end
-
- # 是否匿评阶段
- def is_evaluation
- @is_author = @work.user_id == current_user.id
- @is_evaluation = @user_course_identity == Course::STUDENT && !@is_author && @homework.anonymous_comment &&
- [3, 4].include?(@homework.homework_detail_manual.comment_status)
- end
-
- # 作品是否公开
- def open_work
- tip_exception(403,"没有操作权限") unless (@user_course_identity < Course::STUDENT || current_user == @work.user || @homework.work_public || @is_evaluation)
- end
-
- def allow_add_score
- # 老师始终有评阅权限,匿评阶段内,学生对分配给该学生的作品有评阅权限
- tip_exception(403, "没有权限") unless allow_score(@homework, @user_course_identity, current_user.id, @work)
- end
-
- def update_check work
- tip_exception("作品描述不能为空") if params[:description].blank?
- if @homework.homework_type == "group"
- tip_exception("小组成员不能为空") if params[:user_ids].blank?
- tip_exception("小组成员人数不合要求") if params[:user_ids].length > @homework.homework_detail_group.max_num ||
- params[:user_ids].length < @homework.homework_detail_group.min_num
- tip_exception("请先关联项目") if @homework.homework_detail_group.base_on_project && work.project_id == 0
- end
- end
-
-
- def add_score_to_member student_work, homework, new_score
- student_works = homework.student_works.where("group_id = #{student_work.group_id} and id != #{student_work.id} and ultimate_score = 0")
- student_works.each do |st_work|
- st_score = StudentWorksScore.new(user_id: new_score.user_id, score: new_score.score,
- reviewer_role: new_score.reviewer_role, comment: new_score.comment)
-
- score = StudentWorksScore.where(user_id: new_score.user_id, student_work_id: st_work.id, reviewer_role: new_score.reviewer_role).last
- # 该用户的历史评阅无效
- score.update_column('is_invalid', true) if score.present? && score.score.present?
- st_work.student_works_scores << st_score
-
- if new_score.reviewer_role == 1
- st_work.teacher_score = new_score.score if new_score.score.present?
- elsif new_score.reviewer_role == 2
- if homework.homework_detail_manual.ta_mode == 1
- st_work.teaching_asistant_score = new_score.ta_score st_work.id
- else
- st_work.teaching_asistant_score = new_score.score if new_score.score.present?
- end
- else
- st_work.student_score = student_work.student_score
- end
- st_work.save!
-
- Tiding.create(user_id: st_work.user_id, trigger_user_id: current_user.id, container_id: st_score.id,
- container_type: "StudentWorksScore", parent_container_id: st_work.id, parent_container_type: "StudentWork",
- belong_container_id: homework.course_id, belong_container_type: "Course", viewed: 0,
- tiding_type: "HomeworkCommon", extra: new_score.reviewer_role)
-
- new_score.attachments.each do |attachment|
- att = attachment.copy
- att.author_id = st_score.user_id
- st_score.attachments << att
- end
- end
- end
-
- def update_none_commit_work work, homework
- if work.work_status == 0
- work.work_status = 1
- work.compelete_status = 1
- work.commit_time = homework.end_time
- work.update_time = Time.now
- end
- final_score = 0
- homework.homework_challenge_settings.each do |cha_setting|
- adjust_score = work.challenge_work_scores.select{|work_score| work_score.challenge_id == cha_setting.challenge_id}.last
- final_score += adjust_score.score if adjust_score.present?
- end
- work.final_score = final_score
- work.work_score = final_score
- work.save!
- end
-end
diff --git a/app/jobs/end_exercise_calculate_job.rb b/app/jobs/end_exercise_calculate_job.rb
deleted file mode 100644
index 251496c..0000000
--- a/app/jobs/end_exercise_calculate_job.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-class EndExerciseCalculateJob < ApplicationJob
-
- include ExercisesHelper
- include GitHelper
-
- queue_as :default
-
- def perform(ex_user_ids,exercise,end_time)
- exercise_users = ExerciseUser.where(id: ex_user_ids)
- exercise_users.each do |user|
- if user.commit_status == 0 && user.start_at.present?
- objective_score = calculate_student_score(exercise,user.user,end_time.to_time)[:total_score]
- user_sub_score = user.subjective_score
- subjective_score = user_sub_score < 0.0 ? 0.0 : user_sub_score
- total_score = objective_score + subjective_score
- commit_option = {
- :status => 1,
- :commit_status => 1,
- :end_at => Time.now,
- :objective_score => objective_score,
- :score => total_score,
- :subjective_score => user_sub_score,
- :commit_method => user&.commit_method.to_i > 0 ? user&.commit_method.to_i : 4
- }
- user.update_attributes(commit_option)
- end
- end
- end
-
-end
diff --git a/app/models/course_message.rb b/app/models/course_message.rb
deleted file mode 100644
index b09613e..0000000
--- a/app/models/course_message.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-class CourseMessage < ApplicationRecord
- enum status: { UNHANDLED: 0, PASSED: 1, REJECTED: 2 }
- belongs_to :course
- belongs_to :user
- has_one :course_act, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
-
- scope :find_by_course, ->(course) { where(course_id: course.id) }
- scope :join_course_requests, -> { where(course_message_type: "JoinCourseRequest") }
- scope :unhandled, -> { where(status: :UNHANDLED) }
-
- scope :unhandled_join_course_requests_by_course, ->(course) { find_by_course(course).join_course_requests.unhandled }
-
- after_create :act_as_course_activity
-
- def pass!
- update!(status: :PASSED)
- send_deal_tiding(1)
- end
-
- def application_user
- User.find_by(id: course_message_id)
- end
-
- def reject!
- update!(status: :REJECTED)
- send_deal_tiding(2)
- end
-
- private
-
- #课程动态公共表记录
- def act_as_course_activity
- self.course_act << CourseActivity.new(user_id: course_message_id, course_id: course_id)
- end
-
- def send_deal_tiding deal_status
- # 发送申请处理结果消息
- Tiding.create!(
- user_id: course_message_id, trigger_user_id: 0, container_id: course_id, container_type: 'DealCourse',
- belong_container: course, extra: content.to_i == 2 ? '9' : '7', tiding_type: 'System', status: deal_status
- )
- # 将申请消息置为已处理
- Tiding.where(trigger_user_id: course_message_id, container_id: course_id, container_type: 'JoinCourse', status: 0).update_all(status: 1)
- end
-end
\ No newline at end of file
diff --git a/app/models/message.rb b/app/models/message.rb
deleted file mode 100644
index 59dd84b..0000000
--- a/app/models/message.rb
+++ /dev/null
@@ -1,102 +0,0 @@
-class Message < ApplicationRecord
- attr_accessor :total_replies_count
-
- belongs_to :board, counter_cache: true
- belongs_to :author, class_name: "User", foreign_key: 'author_id'
- belongs_to :parent, class_name: "Message", foreign_key: "parent_id", counter_cache: :replies_count, optional: true
- belongs_to :root, class_name: 'Message', foreign_key: :root_id, counter_cache: :descendants_count, optional: true
-
- has_one :message_detail, dependent: :destroy
- accepts_nested_attributes_for :message_detail, update_only: true
-
- has_many :children, -> { order(updated_on: :desc ) }, class_name: "Message", foreign_key: "parent_id", dependent: :destroy
- has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
- has_many :tidings, as: :container, dependent: :destroy
- has_many :attachments, as: :container, dependent: :destroy
- has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy # 课程动态
- has_many :descendants, class_name: 'Message', foreign_key: :root_id, dependent: :destroy
-
- scope :root_nodes, -> { where("parent_id IS NULL") } #判断该信息是帖子还是回复。null为发布的帖子
- scope :reply_nodes, -> { where("parent_id IS NOT NULL") }
- scope :visible, -> { where(is_hidden: false) }
- scope :by_user, ->(user) { visible if user.nil? || !user.admin? }
- scope :preload_messages, -> { includes(:author, :message_detail) }
- scope :short, -> { select(:id, :subject, :created_on, :replies_count, :visits, :sticky, :praises_count) }
- scope :ordered, -> (opts={}) { reorder("created_on #{opts[:sort] == 1 ? 'asc': 'desc'}") }
- scope :by_ids, lambda { |ids| where(id: ids) unless ids.blank? }
- scope :find_by_boards, ->(ids) {where(board_id: ids)}
- scope :by_keywords, lambda { |keywords|
- where("subject LIKE ?", "%#{keywords.split(" ").join('|')}%") unless keywords.blank?
- }
-
-
- #转发表
- # has_many :forwards, as: :from, dependent: :destroy
-
- validates :subject, length: { maximum: 255, too_long: "不能超过255个字符" }
-
- def update_content(content)
- message_detail.update_attributes(content: content)
- end
-
- # 主贴的名称
- def main_subject
- Rails.logger.info("##########parent: #{parent&.subject}")
- parent.present? ? parent.subject : subject
- end
-
- def copy_attachments_to_new_message(new_message, user)
- attachments.each do |attach|
- new_message.attachments << Attachment.new(attach.attributes.except("id").merge(
- quotes: 0,
- downloads: 0,
- author_id: user.id,
- created_on: Time.now
- ))
- end
- end
-
- def self.bulk_move_to_other_board(message_ids, to_board_id)
- to_board = Board.find(to_board_id)
-
- messages = Message.where(id: message_ids, parent_id: nil).select(:id, :board_id).to_a
- return if messages.blank?
-
- from_board = Board.find(messages.first.board_id)
-
- root_ids = messages.map(&:id)
- children_ids = Message.where(parent_id: root_ids).pluck(:id)
- second_children_ids = Message.where(parent_id: children_ids).pluck(:id)
-
- ids = root_ids.concat(children_ids).concat(second_children_ids).uniq
-
- ActiveRecord::Base.transaction do
- Message.where(id: ids, board_id: from_board.id).update_all(board_id: to_board.id)
- to_board.increment!(:messages_count, ids.size)
- from_board.increment!(:messages_count, - ids.size)
- end
- end
-
- # 包含二级回复的总点赞数
- def total_praises_count
- praises_count + descendants.sum(:praises_count)
- end
-
- # 包含二级回复数的总回复数
- def total_replies_count
- descendants_count
- end
-
- def has_replies
- children.exists?
- end
-
- #
- def by_user_with_visible(user)
- user.nil? || !user.admin? ? children.visible.limit(5) : children.limit(5)
- end
-
- def update_visits
- update_attributes(:visits => visits + 1)
- end
-end
From 7341be065c163f93b786a3de504e30415a2ac310 Mon Sep 17 00:00:00 2001
From: Jasder <2053003901@@qq.com>
Date: Mon, 9 Mar 2020 15:06:42 +0800
Subject: [PATCH 4/4] FIX react build for production
---
public/react/build/asset-manifest.json | 2 +-
public/react/build/index.html | 2 +-
public/react/build/service-worker.js | 2 +-
.../build/static/js/{main.19b9fc67.js => main.62f0e757.js} | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
rename public/react/build/static/js/{main.19b9fc67.js => main.62f0e757.js} (99%)
diff --git a/public/react/build/asset-manifest.json b/public/react/build/asset-manifest.json
index 0fa441e..55553b4 100644
--- a/public/react/build/asset-manifest.json
+++ b/public/react/build/asset-manifest.json
@@ -282,7 +282,7 @@
"./static/js/98.4c2c8b49.chunk.js": "./static/js/98.4c2c8b49.chunk.js",
"./static/js/99.4ecedbde.chunk.js": "./static/js/99.4ecedbde.chunk.js",
"main.css": "./static/css/main.fd229636.css",
- "main.js": "./static/js/main.19b9fc67.js",
+ "main.js": "./static/js/main.62f0e757.js",
"static/media/KaTeX_AMS-Regular.ttf": "static/media/KaTeX_AMS-Regular.aaf4eee9.ttf",
"static/media/KaTeX_AMS-Regular.woff": "static/media/KaTeX_AMS-Regular.7f06b4e3.woff",
"static/media/KaTeX_AMS-Regular.woff2": "static/media/KaTeX_AMS-Regular.e78e28b4.woff2",
diff --git a/public/react/build/index.html b/public/react/build/index.html
index 26f4775..903fbd1 100644
--- a/public/react/build/index.html
+++ b/public/react/build/index.html
@@ -24,7 +24,7 @@
_host = 'https://ali-cdn.educoder.net/react/build/'
}
document.write('