diff --git a/Gemfile b/Gemfile index 7909cb17..6cf60e0e 100644 --- a/Gemfile +++ b/Gemfile @@ -55,6 +55,7 @@ gem 'chinese_pinyin' # gem 'sunspot' # gem 'progress_bar' gem 'ansi' +gem 'diff-lcs', '~> 1.3' gem 'kaminari' gem 'elasticsearch-model' diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 289c122b..304fcb7d 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -2017,10 +2017,10 @@ class StudentWorkController < ApplicationController if @homework.homework_type == 1 #普通作业 if @homework.anonymous_comment ==0 sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_course_group),l(:excel_homework_des), - l(:excel_t_score),l(:excel_ta_score), l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_update_time)]) + l(:excel_t_score),l(:excel_ta_score), l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_update_time), "评语"]) else sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_course_group),l(:excel_homework_des), - l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_update_time)]) + l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_update_time), "评语"]) end count_row = 1 items.each do |homework| @@ -2039,10 +2039,12 @@ class StudentWorkController < ApplicationController sheet1[count_row,11] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.late_penalty sheet1[count_row,12] = homework.respond_to?("work_score") ? homework.work_score.nil? ? l(:label_without_score) : homework.work_score.round(1) : l(:label_without_score) sheet1[count_row,13] = format_time(homework.update_time) + sheet1[count_row,14] = work_comment(homework) else sheet1[count_row,9] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.late_penalty sheet1[count_row,10] = homework.respond_to?("work_score") ? homework.work_score.nil? ? l(:label_without_score) : homework.work_score.round(1) : l(:label_without_score) sheet1[count_row,11] = format_time(homework.update_time) + sheet1[count_row,12] = work_comment(homework) end count_row += 1 end @@ -2082,10 +2084,10 @@ class StudentWorkController < ApplicationController elsif @homework.homework_type == 3 #分组作业 if @homework.anonymous_comment ==0 sheet1.row(0).concat([l(:excel_group),l(:excel_group_member),l(:excel_course_group),l(:excel_homework_des), - l(:excel_t_score),l(:excel_ta_score),l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_update_time)]) + l(:excel_t_score),l(:excel_ta_score),l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_update_time), "评语"]) else sheet1.row(0).concat([l(:excel_group),l(:excel_group_member),l(:excel_course_group),l(:excel_homework_des), - l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_update_time)]) + l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_update_time), "评语"]) end count_row = 1 items.each do |homework| @@ -2101,16 +2103,18 @@ class StudentWorkController < ApplicationController sheet1[count_row,8] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.late_penalty sheet1[count_row,9] = homework.respond_to?("work_score") ? homework.work_score.nil? ? l(:label_without_score) : homework.work_score.round(1) : l(:label_without_score) sheet1[count_row,10] = format_time(homework.update_time) + sheet1[count_row,11] = work_comment(homework) else sheet1[count_row,6] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.late_penalty sheet1[count_row,7] = homework.respond_to?("work_score") ? homework.work_score.nil? ? l(:label_without_score) : homework.work_score.round(1) : l(:label_without_score) sheet1[count_row,8] = format_time(homework.update_time) + sheet1[count_row,9] = work_comment(homework) end count_row += 1 end elsif @homework.homework_type == 4 #实训作业 sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_course_group),l(:excel_homework_complete_time), - l(:excel_homework_complete_status), l(:excel_homework_evaluate_times), l(:excel_homework_spend_time),l(:excel_homework_total_exp),l(:excel_l_penalty),l(:excel_f_score),l(:excel_update_time)]) + l(:excel_homework_complete_status), l(:excel_homework_evaluate_times), l(:excel_homework_spend_time),l(:excel_homework_total_exp),l(:excel_l_penalty),l(:excel_f_score),l(:excel_update_time), "评语"]) count_row = 1 shixun = @homework.homework_commons_shixuns.shixun items.each do |homework| @@ -2129,6 +2133,7 @@ class StudentWorkController < ApplicationController sheet1[count_row,11] = homework.late_penalty sheet1[count_row,12] = homework.respond_to?("work_score") ? homework.work_score.nil? ? "--" : homework.work_score.round(1) : "--" sheet1[count_row,13] = homework.update_time ? format_time(homework.update_time) : "--" + sheet1[count_row,14] = work_comment(homework) count_row += 1 end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 64e7aa86..4fae7ff7 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4178,7 +4178,8 @@ class UsersController < ApplicationController ###add by huang def user_watchlist - watch_query = User.watched_by(@user.id) + watch_query = User.joins('left join watchers on watchers.watchable_id = users.id and watchers.watchable_type in ("Principal", "User")') + .where('watchers.user_id = ?', @user.id) @user_watchlist_count = watch_query.size @user_watchlist = watch_query.order("#{Watcher.table_name}.id desc") @limit = 10 @@ -4191,7 +4192,8 @@ class UsersController < ApplicationController ###add by huang def user_fanslist - fan_query = @user.watcher_users + fan_query = User.joins('left join watchers on watchers.user_id = users.id and watchers.watchable_type in ("Principal", "User")') + .where('watchers.watchable_id = ?', @user.id) @user_fanlist_count = fan_query.size @user_fanlist = fan_query.order("#{Watcher.table_name}.id desc") @@ -4204,10 +4206,12 @@ class UsersController < ApplicationController end def user_wathlist_and_fanslist - watch_query = User.watched_by(@user.id) + watch_query = User.joins('left join watchers on watchers.watchable_id = users.id and watchers.watchable_type in ("Principal", "User")') + .where('watchers.user_id = ?', @user.id) @user_watchlist_count = watch_query.count @user_watchlist = watch_query.order("#{Watcher.table_name}.id desc") - fan_query = @user.watcher_users + fan_query = User.joins('left join watchers on watchers.user_id = users.id and watchers.watchable_type in ("Principal", "User")') + .where('watchers.watchable_id = ?', @user.id) @user_fanlist_count = fan_query.count @user_fanlist = fan_query.order("#{Watcher.table_name}.id desc") respond_to do |format| diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index 94b8348d..cda73147 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -3,6 +3,17 @@ include UserScoreHelper module StudentWorkHelper + # 作品的评语(拼接,导出excel成绩) + def work_comment work + comment = "" + work_scores = work.student_works_scores.order("created_at desc") + work_scores.each do |score| + comment += "#{score.user.show_real_name}: #{format_time(score.created_at)} #{score.score} 分\n" + comment += "#{score.comment}\n\n" + end + comment + end + #获取当前用户的项目列表 def user_projects_option projects = User.current.projects.visible diff --git a/app/views/users/_user_fans_or_watch.html.erb b/app/views/users/_user_fans_or_watch.html.erb index 898b3d2e..0044cb65 100644 --- a/app/views/users/_user_fans_or_watch.html.erb +++ b/app/views/users/_user_fans_or_watch.html.erb @@ -13,7 +13,7 @@ <% if user != User.current %>