From a5c784c42383e97ad01e9217e29a86fffa3527e1 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 3 Jul 2019 11:13:31 +0800 Subject: [PATCH 01/10] fix account update --- app/forms/users/update_account_form.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/forms/users/update_account_form.rb b/app/forms/users/update_account_form.rb index 68e7fb7bf..d82459fcf 100644 --- a/app/forms/users/update_account_form.rb +++ b/app/forms/users/update_account_form.rb @@ -10,9 +10,9 @@ class Users::UpdateAccountForm validates :gender, presence: true, numericality: { only_integer: true }, inclusion: { in: [0, 1] } validates :location, presence: true validates :location_city, presence: true - validates :identity, presence: true, numericality: { only_integer: true }, inclusion: { in: [0, 1, 2] } - validates :technical_title, presence: true, unless: -> { identity == 1 } - validates :student_id, presence: true, if: -> { identity == 1 } + validates :identity, presence: true, inclusion: { in: %w[teacher student professional ] } + validates :technical_title, presence: true, unless: -> { identity.to_s == 'student' } + validates :student_id, presence: true, if: -> { identity.to_s == 'student' } validates :school_id, presence: true validate :check_school_exist From 7264d1f0f3615884aba975803c7f6d58bfe3b159 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 3 Jul 2019 15:13:57 +0800 Subject: [PATCH 02/10] add apply add school && apply add department --- .../add_department_applies_controller.rb | 15 +++++++ .../add_school_applies_controller.rb | 16 +++++++ app/forms/add_school_apply_form.rb | 10 +++++ app/models/applied_message.rb | 5 +++ app/models/apply_add_department.rb | 15 +++++++ app/models/apply_add_school.rb | 14 ++++++ .../create_add_department_apply_service.rb | 43 +++++++++++++++++++ .../create_add_school_apply_service.rb | 37 ++++++++++++++++ .../forms/add_school_apply_form.zh-CN.yml | 8 ++++ config/routes.rb | 2 + 10 files changed, 165 insertions(+) create mode 100644 app/controllers/add_department_applies_controller.rb create mode 100644 app/controllers/add_school_applies_controller.rb create mode 100644 app/forms/add_school_apply_form.rb create mode 100644 app/models/applied_message.rb create mode 100644 app/models/apply_add_department.rb create mode 100644 app/models/apply_add_school.rb create mode 100644 app/services/create_add_department_apply_service.rb create mode 100644 app/services/create_add_school_apply_service.rb create mode 100644 config/locales/forms/add_school_apply_form.zh-CN.yml diff --git a/app/controllers/add_department_applies_controller.rb b/app/controllers/add_department_applies_controller.rb new file mode 100644 index 000000000..ed8067c84 --- /dev/null +++ b/app/controllers/add_department_applies_controller.rb @@ -0,0 +1,15 @@ +class AddDepartmentAppliesController < ApplicationController + before_action :require_login + + def create + CreateAddDepartmentApplyService.call(current_user, create_params) + render_ok + rescue CreateAddDepartmentApplyService::Error => ex + render_error(ex.message) + end + + private + def create_params + params.permit(:name, :school_id, :remarks) + end +end \ No newline at end of file diff --git a/app/controllers/add_school_applies_controller.rb b/app/controllers/add_school_applies_controller.rb new file mode 100644 index 000000000..9f2376b9e --- /dev/null +++ b/app/controllers/add_school_applies_controller.rb @@ -0,0 +1,16 @@ +class AddSchoolAppliesController < ApplicationController + before_action :require_login + + def create + CreateAddSchoolApplyService.call(current_user, create_params) + render_ok + rescue CreateAddSchoolApplyService::Error => ex + render_error(ex.message) + end + + private + + def create_params + params.permit(:name, :province, :city, :address, :remarks) + end +end \ No newline at end of file diff --git a/app/forms/add_school_apply_form.rb b/app/forms/add_school_apply_form.rb new file mode 100644 index 000000000..c0b767f06 --- /dev/null +++ b/app/forms/add_school_apply_form.rb @@ -0,0 +1,10 @@ +class AddSchoolApplyForm + include ActiveModel::Model + + attr_accessor :name, :province, :city, :address, :remarks + + validates :name, presence: true + validates :province, presence: true + validates :city, presence: true + validates :address, presence: true +end \ No newline at end of file diff --git a/app/models/applied_message.rb b/app/models/applied_message.rb new file mode 100644 index 000000000..ed02a5445 --- /dev/null +++ b/app/models/applied_message.rb @@ -0,0 +1,5 @@ +class AppliedMessage < ApplicationRecord + belongs_to :user + belongs_to :applied, polymorphic: true + +end \ No newline at end of file diff --git a/app/models/apply_add_department.rb b/app/models/apply_add_department.rb new file mode 100644 index 000000000..3deeaa97e --- /dev/null +++ b/app/models/apply_add_department.rb @@ -0,0 +1,15 @@ +class ApplyAddDepartment < ApplicationRecord + belongs_to :user + belongs_to :school + belongs_to :department + + has_many :applied_messages, as: :applied + has_many :tidings, as: :container, dependent: :destroy + + after_create :send_notify + + private + def send_notify + tidings.create!(user_id: 1, trigger_user_id: user_id, belong_container: school, tiding_type: 'Apply', status: 0) + end +end \ No newline at end of file diff --git a/app/models/apply_add_school.rb b/app/models/apply_add_school.rb new file mode 100644 index 000000000..bae65d24f --- /dev/null +++ b/app/models/apply_add_school.rb @@ -0,0 +1,14 @@ +class ApplyAddSchool < ApplicationRecord + belongs_to :school + + has_many :applied_messages, as: :applied + has_many :tidings, as: :container, dependent: :destroy + + after_create :send_notify + + private + + def send_notify + tidings.create!(user_id: 1, status: 0, trigger_user_id: user_id, belong_container: school, tiding_type: 'Apply') + end +end \ No newline at end of file diff --git a/app/services/create_add_department_apply_service.rb b/app/services/create_add_department_apply_service.rb new file mode 100644 index 000000000..f1d6cf852 --- /dev/null +++ b/app/services/create_add_department_apply_service.rb @@ -0,0 +1,43 @@ +class CreateAddDepartmentApplyService < ApplicationService + Error = Class.new(StandardError) + + attr_reader :user, :params + + def initialize(user, params) + @user = user + @params = params + end + + def call + name = params[:name].to_s.strip + raise Error, '名称不能为空' if name.blank? + + school = School.find_by(id: params[:school_id]) + raise Error, '学校/单位不存在' if school.blank? + + department = Department.new + department.name = name + department.school = school + + ActiveRecord::Base.transaction do + department.save! + + attrs = { + user_id: user.id, department: department, school: school, + name: department.name, remarks: params[:remarks], status: 0, + } + apply = ApplyAddDepartment.create!(attrs) + + unless user.professional_certification? + user.user_extension.update!(department_id: department.id) + end + + # 向管理员发送通知 + message = AppliedMessage.new(user_id: 1, status: 0, applied_user_id: user.id, viewed: 0, + applied_id: apply.id, applied_type: 'ApplyAddDepartment', name: department.name) + message.save(validate: false) + end + + school + end +end diff --git a/app/services/create_add_school_apply_service.rb b/app/services/create_add_school_apply_service.rb new file mode 100644 index 000000000..96619c681 --- /dev/null +++ b/app/services/create_add_school_apply_service.rb @@ -0,0 +1,37 @@ +class CreateAddSchoolApplyService < ApplicationService + Error = Class.new(StandardError) + + attr_reader :user, :params + + def initialize(user, params) + @user = user + @params = params + end + + def call + AddSchoolApplyForm.new(params).validate! + + name = params[:name].to_s.strip + raise Error, '学校/单位已经存在' if name.present? && School.exists?(name: name) + + school = School.new + school.name = name + school.province = params[:province].to_s.strip + school.city = params[:city].to_s.strip + school.address = params[:address].to_s.strip + + ActiveRecord::Base.transaction do + school.save! + + school_attrs = school.as_json(only: %i[name province city address]) + ApplyAddSchool.create!(school_attrs.merge(school: school, user_id: user.id, remarks: params[:remarks])) + + # 向管理员发送通知 + message = AppliedMessage.new(user_id: 1, status: 0, applied_user_id: user.id, viewed: 0, + applied_id: school.id, applied_type: 'ApplyAddSchools', name: school.name) + message.save(validate: false) + end + + school + end +end diff --git a/config/locales/forms/add_school_apply_form.zh-CN.yml b/config/locales/forms/add_school_apply_form.zh-CN.yml new file mode 100644 index 000000000..749578164 --- /dev/null +++ b/config/locales/forms/add_school_apply_form.zh-CN.yml @@ -0,0 +1,8 @@ +'zh-CN': + activemodel: + attributes: + add_school_apply_form: + name: 名称 + province: 省份 + city: 城市 + address: 详细地址 diff --git a/config/routes.rb b/config/routes.rb index a27dde1f3..610b7f550 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -592,6 +592,8 @@ Rails.application.routes.draw do resources :ec_major_schools, only: [:index, :create, :destroy] end end + resources :add_school_applies, only: [:create] + resources :add_department_applies, only: [:create] # 为避免url过长以及层级过深,路由定义和controller继承都做了处理 scope module: :ecs do From 0fb454cca58cdbce989441cc7bef237d0623036a Mon Sep 17 00:00:00 2001 From: jasder Date: Wed, 3 Jul 2019 16:18:45 +0800 Subject: [PATCH 03/10] ADD files bulk publish --- app/controllers/files_controller.rb | 8 +++++++- config/routes.rb | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 2af178e47..05a9ab841 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -3,7 +3,7 @@ class FilesController < ApplicationController before_action :require_login, except: %i[index] before_action :find_course, except: %i[public_with_course_and_project mine_with_course_and_project] - before_action :find_ids, only: %i[bulk_delete bulk_send bulk_move bulk_public] + before_action :find_ids, only: %i[bulk_delete bulk_send bulk_move bulk_public bulk_publish] before_action :file_validate_sort_type, only: :index before_action :validate_send_message_to_course_params, only: :bulk_send before_action :set_pagination, only: %i[index public_with_course_and_project mine_with_course_and_project] @@ -40,6 +40,12 @@ class FilesController < ApplicationController @attachments = @attachments.page(@page).per(@page_size) end + def bulk_publish + return normal_status(403, "您没有权限进行操作") if current_user.course_identity(@course) >= 5 + @course.attachments.by_ids(@attachment_ids).unpublish.update_all(is_publish: 1, publish_time: Time.now) + render_ok + end + def bulk_delete ActiveRecord::Base.transaction do begin diff --git a/config/routes.rb b/config/routes.rb index a27dde1f3..f47b704b1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -253,6 +253,7 @@ Rails.application.routes.draw do get :mine_with_course_and_project post :import post :upload + put :bulk_publish end member do get :histories From bed09475eda5361252cd32c0a4acceb2318a024a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 16:35:06 +0800 Subject: [PATCH 04/10] fix bug --- .../exercise_questions_controller.rb | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index deb9b3157..b852e9437 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -347,17 +347,28 @@ class ExerciseQuestionsController < ApplicationController #当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数. - if @exercise.exercise_status == 2 - ex_users_committed = @exercise.exercise_users.exercise_user_committed - if ex_users_committed.size > 0 - ex_users_committed.each do |ex_user| - user = ex_user.user - objective_score = calculate_student_score(@exercise,user)[:total_score] - subjective_score = ex_user.subjective_score - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = objective_score + total_score_subjective_score - ex_user.update_attributes(objective_score:objective_score,score:total_score) - end + # if @exercise.exercise_status == 2 + # ex_users_committed = @exercise.exercise_users.exercise_user_committed + # if ex_users_committed.size > 0 + # ex_users_committed.each do |ex_user| + # user = ex_user.user + # objective_score = calculate_student_score(@exercise,user)[:total_score] + # subjective_score = ex_user.subjective_score + # total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + # total_score = objective_score + total_score_subjective_score + # ex_user.update_attributes(objective_score:objective_score,score:total_score) + # end + # end + # end + ex_users_committed = @exercise.exercise_users.exercise_user_committed + if ex_users_committed.size > 0 + ex_users_committed.each do |ex_user| + user = ex_user.user + objective_score = calculate_student_score(@exercise,user)[:total_score] + subjective_score = ex_user.subjective_score + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = objective_score + total_score_subjective_score + ex_user.update_attributes(objective_score:objective_score,score:total_score) end end From 50ea41ac7ff492eaba5f6d638b37a5f2007b8827 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 16:40:57 +0800 Subject: [PATCH 05/10] git email test --- app/controllers/myshixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 9c3847b3c..89d76c16c 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -275,7 +275,7 @@ class MyshixunsController < ApplicationController message: message, content: content, author_name: author_name, - author_email: author_email) + author_email: "53246666@qq.com") end end From 75aa92026fa3d563134ca3c695039ddcccfb7aaf Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 16:55:08 +0800 Subject: [PATCH 06/10] add author email for git --- app/controllers/myshixuns_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 87823ce21..3dfb739d0 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -15,7 +15,6 @@ class MyshixunsController < ApplicationController # For Admin # 强制重置实训 - # REDO等删除是否可以做成异步 # 前段需要按照操作过程提示 def reset_my_game unless current_user.admin? @@ -275,7 +274,7 @@ class MyshixunsController < ApplicationController message: message, content: content, author_name: author_name, - author_email: "53246666@qq.com") + author_email: author_email) end end From 9ee6fee20ad7640d8721431e6e65c5f77046264c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 16:58:42 +0800 Subject: [PATCH 07/10] fix bug --- .../exercise_questions_controller.rb | 40 ++++++------------- app/helpers/exercises_helper.rb | 9 +++++ 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index b852e9437..e33e5e2dc 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -347,36 +347,20 @@ class ExerciseQuestionsController < ApplicationController #当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数. - # if @exercise.exercise_status == 2 - # ex_users_committed = @exercise.exercise_users.exercise_user_committed - # if ex_users_committed.size > 0 - # ex_users_committed.each do |ex_user| - # user = ex_user.user - # objective_score = calculate_student_score(@exercise,user)[:total_score] - # subjective_score = ex_user.subjective_score - # total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - # total_score = objective_score + total_score_subjective_score - # ex_user.update_attributes(objective_score:objective_score,score:total_score) - # end - # end - # end - ex_users_committed = @exercise.exercise_users.exercise_user_committed - if ex_users_committed.size > 0 - ex_users_committed.each do |ex_user| - user = ex_user.user - objective_score = calculate_student_score(@exercise,user)[:total_score] - subjective_score = ex_user.subjective_score - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = objective_score + total_score_subjective_score - ex_user.update_attributes(objective_score:objective_score,score:total_score) + if @exercise.exercise_status == 2 + ex_users_committed = @exercise.exercise_users.exercise_user_committed + if ex_users_committed.size > 0 + ex_users_committed.each do |ex_user| + user = ex_user.user + objective_score = calculate_student_score(@exercise,user)[:total_score] + subjective_score = ex_user.subjective_score + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = objective_score + total_score_subjective_score + ex_user.update_attributes(objective_score:objective_score,score:total_score) + end end end - - if @exercise_question.save - normal_status(0,"试卷更新成功!") - else - normal_status(-1,"试卷更新失败!") - end + normal_status(0,"试卷更新成功!") rescue Exception => e uid_logger_error(e.message) tip_exception("页面调用失败!") diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 437965ca6..55ade6e7c 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -382,6 +382,9 @@ module ExercisesHelper end answers_content.update_all(:score => q_score_1) score1 = score1 + q.question_score + else + answers_content.update_all(:score => -1.0) + score1 += 0.0 end else score1 += 0.0 @@ -403,6 +406,9 @@ module ExercisesHelper if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 u.update_column('score',q_score_2) score2 = score2 + q_score_2 + else + u.update_column('score',-1.0) + score2 += 0.0 end end else @@ -413,6 +419,9 @@ module ExercisesHelper u.update_column("score",q_score_2) score2 = score2 + q_score_2 st_answer_text.delete(u_answer_text) + else + u.update_column('score',-1.0) + score2 += 0.0 end end end From 2c472f44a9a6e8245fd0d7899a2b70d5f056c7b3 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:10:03 +0800 Subject: [PATCH 08/10] fix bug --- app/controllers/homework_commons_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 4474d47c8..2fcf421f4 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,9 +106,11 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size + logger.info("##########__________@homework.publish_time______________#############{@homework.publish_time}") if @homework.publish_time.blank? || (@homework.publish_time > Time.now) @student_works = [] if params[:format] == "xlsx" || params[:format] == "zip" + logger.info("##########__________params[:format]______________#############{params[:format]}") normal_status(-1,"作业未发布") end else From 41f01f49614a1885ffe373e7eaeb7033fb4a3a58 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 17:21:21 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 1 + db/migrate/20190703090511_add_index_for_shixun_services.rb | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 db/migrate/20190703090511_add_index_for_shixun_services.rb diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 5a1773a10..2c4f2a7d1 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -180,6 +180,7 @@ class ShixunsController < ApplicationController end # 同步配置 + logger.info("########-shixun_service_configs_count: #{@shixun.shixun_service_configs.pluck(:id, :shixun_id)}") @shixun.shixun_service_configs.each do |config| ShixunServiceConfig.create!(:shixun_id => @new_shixun.id, :cpu_limit => config.cpu_limit, diff --git a/db/migrate/20190703090511_add_index_for_shixun_services.rb b/db/migrate/20190703090511_add_index_for_shixun_services.rb new file mode 100644 index 000000000..3e6dd3703 --- /dev/null +++ b/db/migrate/20190703090511_add_index_for_shixun_services.rb @@ -0,0 +1,5 @@ +class AddIndexForShixunServices < ActiveRecord::Migration[5.2] + def change + add_index :shixun_service_configs, [:shixun_id, :mirror_repository_id], unique: true, name: "shixun_id_mirror_id_unique" + end +end From c61cb1190f683a237058ce3babdcfbc26adf3460 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:32:04 +0800 Subject: [PATCH 10/10] fixbug --- app/controllers/homework_commons_controller.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 2fcf421f4..018218799 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,11 +106,9 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size - logger.info("##########__________@homework.publish_time______________#############{@homework.publish_time}") if @homework.publish_time.blank? || (@homework.publish_time > Time.now) @student_works = [] - if params[:format] == "xlsx" || params[:format] == "zip" - logger.info("##########__________params[:format]______________#############{params[:format]}") + if (params[:format] == "xlsx") || (params[:format] == "zip") normal_status(-1,"作业未发布") end else @@ -198,7 +196,7 @@ class HomeworkCommonsController < ApplicationController end if params[:format] == "xlsx" - complete_works = @work_excel.where("work_status > 0").size + complete_works = @work_excel.exist? ? @work_excel.where("work_status > 0").size : 0 if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif complete_works == 0 @@ -218,8 +216,13 @@ class HomeworkCommonsController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") else - zip_works = @work_excel.where("work_status > 0") - status = checkfileSize(zip_works) + if @work_excel.exist? + zip_works = @work_excel&.where("work_status > 0") + status = checkfileSize(zip_works) + else + status = -1 + end + if status == 0 respond_to do |format| format.zip{