From 396d4d73f0521c7ec4ba483b4b2794ea58e89107 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 30 Dec 2019 17:35:35 +0800 Subject: [PATCH 01/47] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E6=94=BE=E5=BC=80?= =?UTF-8?q?=E6=88=AA=E6=AD=A2=E6=97=B6=E9=97=B4=E7=9A=84=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/polls_controller.rb | 50 ++++++++++++++--------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 0c442a613..2539403af 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -722,19 +722,16 @@ class PollsController < ApplicationController un_anonymous = params[:un_anonymous] ? true : false # 统一设置或者分班为0,则更新问卷,并删除问卷分组 if unified_setting || (course_group_ids.size == 0) - params_publish_time = params[:publish_time].present? ? params[:publish_time].to_time : nil - params_end_time = nil - if params[:end_time].blank? - if params_publish_time.present? - params_end_time = params_publish_time + 30.days - end - else - params_end_time = params[:end_time].to_time - end - # params_end_time = params[:end_time].present? ? params[:end_time].to_time : nil - if poll_status == 2 && @poll.publish_time != params_publish_time - normal_status(-1,"不允许修改发布时间") - elsif poll_status == 3 && (@poll.end_time != params_end_time || @poll.publish_time != params_publish_time) + tip_exception("发布时间不能为空") if params[:publish_time].blank? + tip_exception("截止时间不能为空") if params[:end_time].blank? + 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 + + params_publish_time = params[:publish_time].to_time + params_end_time = params[:end_time].to_time + + if poll_status != 1 && @poll.publish_time != params_publish_time normal_status(-1,"不允许修改发布时间") elsif params_publish_time.present? && params_end_time.present? && params_end_time < params_publish_time normal_status(-1,"截止时间不能小于发布时间") @@ -761,24 +758,25 @@ class PollsController < ApplicationController total_common_group = poll_groups_ids & total_common #传入的分班与问卷已存在的分班的交集 old_poll_groups = poll_groups_ids - total_common_group #后来传入的分班里,没有了的班级,即需要删除 params_times.each do |t| - course_id = t[:course_group_id] #为数组,可能会设置分班为各个班级id的数组 - poll_publish_time = t[:publish_time].present? ? t[:publish_time].to_time : nil - # poll_end_time = t[:end_time].present? ? t[:end_time].to_time : nil - poll_end_time = nil - if t[:end_time].blank? - if poll_publish_time.present? - poll_end_time = poll_publish_time + 30.days - end - else - poll_end_time = t[:end_time].to_time - end + tip_exception("发布时间不能为空") if t[:publish_time].blank? + tip_exception("截止时间不能为空") if t[:end_time].blank? + tip_exception("截止时间不能早于发布时间") if t[:publish_time].to_time > t[:end_time].to_time + tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if + @course.end_date.present? && t[:end_time].to_time > @course.end_date.end_of_day + + course_id = t[:course_group_id] + poll_publish_time = t[:publish_time].to_time + poll_end_time = t[:end_time].to_time + poll_group = poll_groups.find_in_poll_group("course_group_id",course_id) #判断该分班是否存在 - if poll_group.present? && poll_group.first.end_time <= Time.now && (poll_end_time != poll_group.first.end_time || poll_publish_time != poll_group.first.publish_time) #已截止且时间改变的,则提示错误 + + if poll_group.present? && (poll_group.first.publish_time < Time.now) && (poll_publish_time != poll_group.first.publish_time) error_count += 1 end - if poll_group.present? && poll_group.first.publish_time < Time.now && poll_publish_time != poll_group.first.publish_time + if poll_group.present? && (poll_group.first.publish_time < Time.now && poll_group.first.end_time > Time.now) && (poll_end_time < Time.now) error_count += 1 end + if error_count == 0 common_group = poll_groups_ids & course_id #传入的班级与问卷已存在的班级的交集,即表示已有分班的 new_group_ids = course_id - common_group #新传入的班级id From 253b426ba92b7e13cf98ed8b8a7f99862fe3658a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 31 Dec 2019 11:12:53 +0800 Subject: [PATCH 02/47] =?UTF-8?q?=E4=B8=80=E9=94=AE=E8=AF=84=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 197 +----------------- app/jobs/homework_batch_comment_job.rb | 29 +++ config/routes.rb | 1 + spec/jobs/homework_batch_comment_job_spec.rb | 5 + 4 files changed, 44 insertions(+), 188 deletions(-) create mode 100644 app/jobs/homework_batch_comment_job.rb create mode 100644 spec/jobs/homework_batch_comment_job_spec.rb diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 89f65c61d..6efa081f0 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -11,7 +11,7 @@ class HomeworkCommonsController < ApplicationController before_action :find_homework, only: [:edit, :show, :update, :group_list, :homework_code_repeat, :code_review_results, :code_review_detail, :show_comment, :settings, :works_list, :update_settings, :reference_answer, :publish_groups, :end_groups, :alter_name, :update_explanation, - :update_score, :update_student_score] + :update_score, :update_student_score, :batch_comment] before_action :user_course_identity before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer, :update_student_score] @@ -19,7 +19,7 @@ class HomeworkCommonsController < ApplicationController :publish_homework, :end_homework, :set_public, :choose_category, :move_to_category, :choose_category, :create_subject_homework, :multi_destroy, :group_list, :homework_code_repeat, :code_review_results, :code_review_detail, :update_explanation, :update_settings, - :add_to_homework_bank, :publish_groups, :end_groups] + :add_to_homework_bank, :publish_groups, :end_groups, :batch_comment] before_action :require_id_params, only: [:set_public, :multi_destroy, :publish_homework, :end_homework, :move_to_category, :add_to_homework_bank] before_action :course_manager, only: [:alter_name] @@ -453,105 +453,8 @@ class HomeworkCommonsController < ApplicationController # 课堂结束后不能再更新 unless @course.is_end + # 发布设置 UpdateHomeworkPublishSettingService.call(@homework, publish_params) - # 作业未发布时,unified_setting参数不能为空 -=begin - if @homework.publish_time.nil? || @homework.publish_time > Time.now - tip_exception("缺少统一设置的参数") if params[:unified_setting].nil? - if params[:unified_setting] || @course.course_groups_count == 0 - tip_exception("发布时间不能为空") if params[:publish_time].blank? - tip_exception("截止时间不能为空") if params[:end_time].blank? - tip_exception("发布时间不能早于当前时间") if params[:publish_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S") - tip_exception("截止时间不能早于当前时间") if params[:end_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S") - tip_exception("截止时间不能早于发布时间") if params[:publish_time] > params[:end_time] - tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if - @course.end_date.present? && params[:end_time] > @course.end_date.end_of_day - - @homework.unified_setting = 1 - @homework.homework_group_settings.destroy_all - @homework.publish_time = params[:publish_time] - # 截止时间为空时取发布时间后一个月 - @homework.end_time = params[:end_time] - - else - tip_exception("分班发布设置不能为空") if params[:group_settings].blank? - # 创建作业的分班设置 - create_homework_group_settings @homework - - setting_group_ids = [] - - params[:group_settings].each do |setting| - tip_exception("分班id不能为空") if setting[:group_id].length == 0 - tip_exception("发布时间不能为空") if setting[:publish_time].blank? - tip_exception("截止时间不能为空") if setting[:end_time].blank? - tip_exception("发布时间不能早于当前时间") if setting[:publish_time] <= strf_time(Time.now) - tip_exception("截止时间不能早于当前时间") if setting[:end_time] <= strf_time(Time.now) - tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time] - tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if - @course.end_date.present? && setting[:end_time] > @course.end_date.end_of_day - - - publish_time = setting[:publish_time] == "" ? Time.now : setting[:publish_time] - # 截止时间为空时取发布时间后一个月 - end_time = setting[:end_time] - HomeworkGroupSetting.where(homework_common_id: @homework.id, course_group_id: setting[:group_id]). - update_all(publish_time: publish_time, end_time: end_time) - setting_group_ids << setting[:group_id] - end - - # 未设置的分班:发布时间和截止时间都为nil - HomeworkGroupSetting.where.not(course_group_id: setting_group_ids).where(homework_common_id: @homework.id). - update_all(publish_time: nil, end_time: nil) - - # 记录已发布需要发消息的分班 - publish_group_ids = HomeworkGroupSetting.where(homework_common_id: @homework.id).group_published.pluck(:course_group_id) - - @homework.unified_setting = 0 - @homework.publish_time = @homework.min_group_publish_time - @homework.end_time = @homework.max_group_end_time - end - - # 如果作业立即发布则更新状态、发消息 - if @homework.publish_time <= Time.now and @homework_detail_manual.comment_status == 0 - @homework_detail_manual.comment_status = 1 - send_tiding = true - end - - # 作业在"提交中"状态时 - else - if @homework.end_time > Time.now && @homework.unified_setting - 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) - - @homework.end_time = params[:end_time] - - elsif !@homework.unified_setting - create_homework_group_settings @homework - tip_exception("分班发布设置不能为空") if params[:group_settings].blank? - params[:group_settings].each do |setting| - group_settings = HomeworkGroupSetting.where(homework_common_id: @homework.id, course_group_id: setting[:group_id]) - - tip_exception("分班id不能为空") if setting[:group_id].length == 0 - tip_exception("发布时间不能为空") if setting[:publish_time].blank? - tip_exception("截止时间不能为空") if setting[:end_time].blank? - # 如果该发布规则 没有已发布的分班则需判断发布时间 - tip_exception("发布时间不能早于等于当前时间") if setting[:publish_time] <= strf_time(Time.now) && group_settings.group_published.count == 0 - - tip_exception("截止时间不能早于等于当前时间") if setting[:end_time] <= strf_time(Time.now) && group_settings.none_end.count > 0 - tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time] - tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if - @course.end_date.present? && setting[:end_time] > strf_time(@course.end_date.end_of_day) - - group_settings.none_published.update_all(publish_time: setting[:publish_time]) - group_settings.none_end.update_all(end_time: setting[:end_time]) - end - - @homework.end_time = @homework.max_group_end_time - end - end -=end # 补交设置 tip_exception("缺少allow_late参数") if params[:allow_late].nil? @@ -880,69 +783,6 @@ class HomeworkCommonsController < ApplicationController ## 分页参数 page = params[:page] || 1 @shixuns = @shixuns.reorder("shixuns.created_at desc").includes(:challenges, user: [user_extension: :school]).page(page).per(10) - - # 新版用下面的代码 - # ## 我的实训 - # @shixuns = - # if params[:order_by] == 'mine' - # current_user.my_shixuns.unhidden - # else - # if current_user.admin? - # Shixun.unhidden - # else - # none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) - # - # @shixuns = Shixun.where.not(id: none_shixun_ids).unhidden - # end - # end - # - # ## 方向 - # if params[:tag_level].present? && params[:tag_id].present? - # @shixuns = @shixuns.filter_tag(params[:tag_level].to_i, params[:tag_id].to_i) - # case params[:tag_level].to_i - # when 1 #大类 - # @search_tags = Repertoire.find(params[:tag_id].to_i).name - # when 2 #子类 - # @search_tags = SubRepertoire.find(params[:tag_id].to_i).name - # when 3 #tag - # tag = TagRepertoire.find(params[:tag_id].to_i) - # @search_tags = "#{tag.sub_repertoire.name} / #{tag.name}" - # end - # end - # - # ## 搜索关键字创建者、实训名称、院校名称 - # if params[:keyword].present? - # keyword = params[:keyword].strip - # @shixuns = @shixuns.joins(user: [user_extenison: :school]). - # where("schools.name like '%#{keyword}%' - # or concat(lastname, firstname) like '%#{keyword}%' - # or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct - # end - # - # ## 筛选 难度 - # if params[:diff].present? && params[:diff].to_i != 0 - # @shixuns = @shixuns.where(trainee: params[:diff]) - # end - # - # ## 排序参数 - # bsort = params[:sort] || 'desc' - # case params[:order_by] || 'hot' - # when 'hot' - # @shixuns = @shixuns.order("myshixuns_count #{bsort}") - # when 'mine' - # @shixuns = @shixuns.order("shixuns.created_at #{bsort}") - # else - # @shixuns = @shixuns.order("myshixuns_count #{bsort}") - # end - # - # @total_count = @shixuns.count - # - # ## 分页参数 - # page = params[:page] || 1 - # limit = params[:limit] || 15 - # - # @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(limit) - # end def create_shixun_homework @@ -1248,31 +1088,6 @@ class HomeworkCommonsController < ApplicationController # homework_challenge_settings = homework.homework_challenge_settings unless student_works.blank? student_works.joins(:myshixun).where("myshixuns.status != 1").update_all(late_penalty: homework.late_penalty) if homework.allow_late - -=begin - student_works.where("work_status != 0").includes(:myshixun).each do |student_work| - unless student_work.myshixun.is_complete? - student_work.update_attributes(work_status: 2, late_penalty: homework.late_penalty) - student_work.late_penalty = homework.late_penalty - end - HomeworksService.new.set_shixun_final_score student_work, student_work.myshixun, homework_detail_manual.answer_open_evaluation, - homework_challenge_settings - end - - student_works.where("work_status = 0").each do |student_work| - myshixun = Myshixun.where(shixun_id: shixun.id, user_id: student_work.user_id).first - if myshixun.present? - student_work.update_attributes(work_status: (myshixun.is_complete? ? 1 : 2), - late_penalty: myshixun.is_complete? ? 0 : homework.late_penalty, - commit_time: myshixun.created_at, myshixun_id: myshixun.id) - student_work.late_penalty = myshixun.is_complete? ? 0 : homework.late_penalty - HomeworksService.new.set_shixun_final_score student_work, myshixun, homework_detail_manual.answer_open_evaluation, - homework_challenge_settings - end - end -=end - - # 更新所有学生的效率分(重新取homework确保是更新后的) end end homework.save! @@ -1558,6 +1373,12 @@ class HomeworkCommonsController < ApplicationController end + def batch_comment + tip_exception(-1, "作业还未发布,不能评阅") if @homework_detail_manual.comment_status == 0 + tip_exception("请至少输入一个评阅") if params[:comment].blank? && params[:hidden_comment].blank? + + end + private def find_homework diff --git a/app/jobs/homework_batch_comment_job.rb b/app/jobs/homework_batch_comment_job.rb new file mode 100644 index 000000000..d12e29a1b --- /dev/null +++ b/app/jobs/homework_batch_comment_job.rb @@ -0,0 +1,29 @@ +# 作业的一键评阅 +class HomeworkBatchCommentJob < ApplicationJob + queue_as :default + + def perform(comment, hidden_comment, work_ids, homework_id, user_id) + # Do something later + homework = HomeworkCommon.find_by(id: homework_id) + return if homework.blank? + + attrs = %i[student_work_id challenge_id user_id comment hidden_comment] + + same_attrs = { + challenge_id: 0, user_id: user_id, container_type: 'Exercise', + parent_container_id: exercise.id, parent_container_type: 'ExercisePublish', + belong_container_id: exercise.course_id, belong_container_type: 'Course', + viewed: 0, tiding_type: 'Exercise' + } + + StudentWork.bulk_insert(*attrs) do |worker| + student_ids.each do |user_id| + same_attrs = {user_id: user_id} + course.homework_commons.where(homework_type: %i[normal group practice]).each do |homework| + next if StudentWork.where(user_id: user_id, homework_common_id: homework.id).any? + worker.add same_attrs.merge(homework_common_id: homework.id) + end + end + end + end +end diff --git a/config/routes.rb b/config/routes.rb index f9ed12dbe..b27095984 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -512,6 +512,7 @@ Rails.application.routes.draw do post :alter_name get :update_score get :update_student_score + post :batch_comment end collection do diff --git a/spec/jobs/homework_batch_comment_job_spec.rb b/spec/jobs/homework_batch_comment_job_spec.rb new file mode 100644 index 000000000..e2352f104 --- /dev/null +++ b/spec/jobs/homework_batch_comment_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkBatchCommentJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end From 05038761ba7411a73ab4c06ad46ea65ed0014e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Tue, 31 Dec 2019 11:22:57 +0800 Subject: [PATCH 03/47] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/AppConfig.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/public/react/src/AppConfig.js b/public/react/src/AppConfig.js index 24493dd13..b0d0b2f3f 100644 --- a/public/react/src/AppConfig.js +++ b/public/react/src/AppConfig.js @@ -51,7 +51,7 @@ if (isDev) { checkSubmitFlg=true window.setTimeout(function () { checkSubmitFlg=false; - }, 2500); + }, 2000); }else if(checkSubmitFlg===false){ $.ajax({url:proxy,async:false,success:function(data){ if(data.status===0){ @@ -61,7 +61,7 @@ if (isDev) { checkSubmitFlg=true window.setTimeout(function () { checkSubmitFlg=false; - }, 2500); + }, 2000); } } window._debugType = debugType; @@ -224,6 +224,7 @@ export function initAxiosInterceptors(props) { } if (response.data.status === 501) { + window.location.reload() notification.warning({ description:response.data.message || '访问异常,请求不合理', }) From 13f7d8c06f780f923e2af68297a6ef6cfc19e80c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 31 Dec 2019 11:25:01 +0800 Subject: [PATCH 04/47] =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/base_controller.rb | 1 - app/controllers/application_controller.rb | 2 +- app/controllers/schools_controller.rb | 1 - app/views/admins/shared/_sidebar.html.erb | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/admins/base_controller.rb b/app/controllers/admins/base_controller.rb index 9a4a25013..0451b77d1 100644 --- a/app/controllers/admins/base_controller.rb +++ b/app/controllers/admins/base_controller.rb @@ -6,7 +6,6 @@ class Admins::BaseController < ApplicationController layout 'admin' skip_before_action :verify_authenticity_token - before_action :require_login, :require_admin! after_action :rebind_event_if_ajax_render_partial diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4faa42107..ba246829d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -282,7 +282,7 @@ class ApplicationController < ActionController::Base end def user_setup - # reacct静态资源加载不需要走这一步 + # # reacct静态资源加载不需要走这一步 return if params[:controller] == "main" # Find the current user Rails.logger.info("current_laboratory is #{current_laboratory} domain is #{request.subdomain}") diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index dc9f6c091..ae0315cdd 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -15,7 +15,6 @@ class SchoolsController < ApplicationController schools = School.all keyword = params[:keyword].to_s.strip schools = schools.where('name LIKE ?', "%#{keyword}%") if keyword - render_ok(schools: schools.select(:id, :name).as_json) end diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index 4b84068e7..09c115b06 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -2,7 +2,7 @@