From f2e29cd33de00a0bfa763b4f2450ed6ec4f6e921 Mon Sep 17 00:00:00 2001
From: cxt <853663049@qq.com>
Date: Thu, 31 Oct 2019 16:28:40 +0800
Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E8=AE=BE=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/controllers/files_controller.rb           | 22 +++++++++++++++++--
 .../homework_commons_controller.rb            |  3 ++-
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb
index bb81269da..683d35da2 100644
--- a/app/controllers/files_controller.rb
+++ b/app/controllers/files_controller.rb
@@ -181,8 +181,8 @@ class FilesController < ApplicationController
           attachment.delay_publish = @atta_delay_publish
           attachment.publish_time = @atta_publish_time
           attachment.unified_setting = @unified_setting
-          unless @unified_setting
-
+          if @unified_setting == 0
+            attachment_group_setting attachment, params[:group_settings]
           end
           # attachment.set_publish_time(publish_time) if is_unified_setting
           # attachment.set_course_group_publish_time(@course, course_group_publish_times) if @course.course_groups.size > 0 && !is_unified_setting && publish_time.blank?
@@ -226,6 +226,10 @@ class FilesController < ApplicationController
         attach_copied_obj.is_publish = @atta_is_publish
         attach_copied_obj.delay_publish = @atta_delay_publish
         attach_copied_obj.publish_time = @atta_publish_time
+        attach_copied_obj.unified_setting = @unified_setting
+        if @unified_setting == 0
+          attachment_group_setting attach_copied_obj, params[:group_settings]
+        end
         attach_copied_obj.course_second_category_id = course_second_category_id
         attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from
         if attach_copied_obj.attachtype == nil
@@ -265,6 +269,10 @@ class FilesController < ApplicationController
       @old_attachment.is_publish = @atta_is_publish
       @old_attachment.delay_publish = @atta_delay_publish
       @old_attachment.publish_time = @atta_publish_time
+      @old_attachment.unified_setting = @unified_setting
+      if @unified_setting == 0
+        attachment_group_setting @old_attachment, params[:group_settings]
+      end
 
       if params[:description] && !params[:description].strip.blank? && params[:description] != @old_attachment.description
         @old_attachment.description = params[:description]
@@ -376,4 +384,14 @@ class FilesController < ApplicationController
       end
     end
   end
+
+  def attachment_group_setting attachment, group_setting
+    create_atta_group_settings attachment
+    group_setting.each do |setting|
+      tip_exception("分班id不能为空") if setting[:group_id].length == 0
+      tip_exception("发布时间不能为空") if setting[:publish_time].blank?
+      AttachmentGroupSetting.where(attachment_id: attachment.id, course_group_id: setting[:group_id]).
+        update_all(publish_time: setting[:publish_time])
+    end
+  end
 end
diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb
index 5d27de7b8..b7a76951e 100644
--- a/app/controllers/homework_commons_controller.rb
+++ b/app/controllers/homework_commons_controller.rb
@@ -13,7 +13,8 @@ class HomeworkCommonsController < ApplicationController
                                        :reference_answer, :publish_groups, :end_groups, :alter_name, :update_explanation,
                                        :update_score, :update_student_score]
   before_action :user_course_identity
-  before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer, :update_student_score]
+  before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer,
+                                          :update_student_score]
   before_action :teacher_allowed, only: [:new, :edit, :create, :update, :shixuns, :subjects, :create_shixun_homework,
                                          :publish_homework, :end_homework, :set_public, :choose_category, :move_to_category,
                                          :choose_category, :create_subject_homework, :multi_destroy, :group_list, :homework_code_repeat,