From c6ae00c6bed4e459581cebd854a3e0407d2dd4c4 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 17 Feb 2017 18:54:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E9=87=8D=E5=A4=8D=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_common_controller.rb | 1 + app/models/students_for_course.rb | 4 +- ...70217104309_delete_excess_student_works.rb | 23 ++++++++ db/schema.rb | 53 ++++++++++++++----- 4 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 db/migrate/20170217104309_delete_excess_student_works.rb diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index d5511cb44..7d6539e8d 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -150,6 +150,7 @@ class HomeworkCommonController < ApplicationController end elsif @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0 homework_detail_manual.comment_status = 1 + create_works_list @homework status = true #更新CourseHomeworkStatistics中每个学生的未交作品数 @homework.course.student.each do |student| diff --git a/app/models/students_for_course.rb b/app/models/students_for_course.rb index 5ef2922b0..ec35642cb 100644 --- a/app/models/students_for_course.rb +++ b/app/models/students_for_course.rb @@ -31,7 +31,7 @@ class StudentsForCourse < ActiveRecord::Base #加入班级时创建已发布作业的作品 def create_student_works course = self.course - course.homework_commons.each do |hw| + course.homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status > 0").each do |hw| if hw.homework_type != 3 && hw.student_works.where("user_id = #{self.student_id}").count == 0 hw.student_works << StudentWork.new(:user_id => self.student_id, :name => hw.name.to_s+"的作品提交", :work_status => 0) end @@ -39,7 +39,7 @@ class StudentsForCourse < ActiveRecord::Base end #加入班级时创建一条记录 - def create_course_homework_statistic + def create_course_homework_statisticd if CourseHomeworkStatistics.where(:user_id => self.student_id, :course_id => self.course_id).count == 0 course = self.course user = self.student diff --git a/db/migrate/20170217104309_delete_excess_student_works.rb b/db/migrate/20170217104309_delete_excess_student_works.rb new file mode 100644 index 000000000..d4cee6f7d --- /dev/null +++ b/db/migrate/20170217104309_delete_excess_student_works.rb @@ -0,0 +1,23 @@ +class DeleteExcessStudentWorks < ActiveRecord::Migration + def up + homework = HomeworkCommon.where(:id => 4818) + unless homework.empty? + homework = homework.first + homework.course.student.each do |student| + student_works = homework.student_works.where(:user_id => student.student_id).reorder("created_at asc") + if student_works.count > 1 + if student_works.first.work_status != 0 + student_works.last.destroy + elsif student_works.last.work_status != 0 + student_works.first.destroy + else + student_works.first.destroy + end + end + end + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index ec969b8c3..6b7ab2ef1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20170217004513) do +ActiveRecord::Schema.define(:version => 20170217104309) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -521,6 +521,13 @@ ActiveRecord::Schema.define(:version => 20170217004513) do add_index "contest_messages", ["contest_id"], :name => "index_contest_messages_on_contest_id" add_index "contest_messages", ["user_id"], :name => "index_contest_messages_on_user_id" + create_table "contest_notifications", :force => true do |t| + t.text "title" + t.text "content" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "contestant_for_contests", :force => true do |t| t.integer "student_id" t.integer "contest_id" @@ -588,6 +595,37 @@ ActiveRecord::Schema.define(:version => 20170217004513) do add_index "contestant_works", ["user_id"], :name => "index_contestant_works_on_user_id" add_index "contestant_works", ["work_id"], :name => "index_contestant_works_on_work_id" + create_table "contesting_projects", :force => true do |t| + t.integer "project_id" + t.string "contest_id" + t.integer "user_id" + t.string "description" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "reward" + end + + create_table "contesting_softapplications", :force => true do |t| + t.integer "softapplication_id" + t.integer "contest_id" + t.integer "user_id" + t.string "description" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "reward" + end + + create_table "contestnotifications", :force => true do |t| + t.integer "contest_id" + t.string "title" + t.string "summary" + t.text "description" + t.integer "author_id" + t.integer "notificationcomments_count" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "contests", :force => true do |t| t.integer "user_id" t.string "name" @@ -1154,19 +1192,6 @@ ActiveRecord::Schema.define(:version => 20170217004513) do t.datetime "updated_at", :null => false end - create_table "ii", :force => true do |t| - t.integer "project_id" - t.string "author_login" - t.string "rep_identifier" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.integer "sonar_version", :default => 0 - t.string "path" - t.string "branch" - t.string "language" - t.string "sonar_name" - end - create_table "innodb_monitor", :id => false, :force => true do |t| t.integer "a" end