Merge branch 'dev_aliyun' of http://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_forum
jasder 5 years ago
commit 903b1337fd

@ -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

@ -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

@ -360,12 +360,7 @@ class ExerciseQuestionsController < ApplicationController
end
end
end
if @exercise_question.save
normal_status(0,"试卷更新成功!")
else
normal_status(-1,"试卷更新失败!")
end
rescue Exception => e
uid_logger_error(e.message)
tip_exception("页面调用失败!")

@ -106,9 +106,10 @@ class HomeworkCommonsController < ApplicationController
student_works = @homework.all_works
@all_member_count = student_works.size
if @homework.publish_time.blank? || (@homework.publish_time > Time.now)
@student_works = []
if params[:format] == "xlsx" || params[:format] == "zip"
if (params[:format] == "xlsx") || (params[:format] == "zip")
normal_status(-1,"作业未发布")
end
else
@ -196,7 +197,7 @@ class HomeworkCommonsController < ApplicationController
end
if params[:format] == "xlsx"
complete_works = @work_excel.where("work_status > 0").size
complete_works = @work_excel.present? ? @work_excel.where("work_status > 0").size : 0
if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作")
elsif complete_works == 0
@ -216,8 +217,13 @@ class HomeworkCommonsController < ApplicationController
if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作")
else
zip_works = @work_excel.where("work_status > 0")
if @work_excel.present?
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{

@ -15,7 +15,6 @@ class MyshixunsController < ApplicationController
# For Admin
# 强制重置实训
# REDO等删除是否可以做成异步
# 前段需要按照操作过程提示
def reset_my_game
unless current_user.admin?
@ -267,9 +266,11 @@ class MyshixunsController < ApplicationController
if content != last_content
@content_modified = 1
author_name = current_user.full_name
author_name = current_user.real_name
author_email = current_user.mail
message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted"
uid_logger("112233#{author_name}")
uid_logger("112233#{author_email}")
@content = GitService.update_file(repo_path: @repo_path,
file_path: path,
message: message,

@ -920,7 +920,7 @@ class PollsController < ApplicationController
def commit_result
ActiveRecord::Base.transaction do
begin
@poll_users = @poll.poll_users
@poll_users = @poll.all_poll_users(current_user.id)
@poll_commit_ids = @poll_users.commit_by_status(1).pluck(:user_id) #问卷提交用户的id
@page = params[:page] || 1
@limit = params[:limit] || 10

@ -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,
@ -521,7 +522,18 @@ class ShixunsController < ApplicationController
end
# 如果存在实训,则直接进入实训
@current_task = current_myshixun.current_task(games)
# 如果实训允许跳关传参params[:challenge_id]跳入具体的关卡
@current_task =
if params[:challenge_id]
game = games.where(challenge_id: params[:challenge_id]).take
if game.status == 3 && !@shixun.task_pass
tip_show_exception(-4, "关卡还未开启")
else
game
end
else
current_myshixun.current_task(games)
end
else
# 如果未创建关卡一定不能开启实训否则TPI没法找到当前的关卡
if @shixun.challenges_count == 0

@ -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

@ -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

@ -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

@ -127,4 +127,17 @@ module PollsHelper
"login":user.login
}
end
def poll_commit_result(poll,poll_questions,poll_users,poll_commit_ids)
poll_users_info = %w(序号)
poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?}
poll_un_anony = poll.un_anonymous
if poll_un_anony #是否匿名默认为false
user_info = %w(登陆名 真实姓名 邮箱 学号)
else
user_info = []
end
poll_users_info = poll_users_info + user_info + poll_ques_titles
end
end

@ -6,6 +6,7 @@ class ExercisePublishNotifyJob < ApplicationJob
exercise = Exercise.find_by(id: exercise_id)
return if exercise.blank?
user = exercise.user
course = exercise.course
if group_ids.present?
students = course.students.where(course_group_id: group_ids)
@ -30,7 +31,7 @@ class ExercisePublishNotifyJob < ApplicationJob
Tiding.bulk_insert(*attrs) do |worker|
teacher_ids = teachers.pluck(:user_id)
unless exercise.tidings.exists?(parent_container_type: 'ExercisePublish', user_id: teacher_ids)
teacher_ids.find_each do |user_id|
teacher_ids.each do |user_id|
worker.add same_attrs.merge(user_id: user_id)
end
end

@ -5,6 +5,8 @@ class GraduationTaskPublishNotifyJob < ApplicationJob
def perform(graduation_task_id)
task = GraduationTask.find_by(id: graduation_task_id)
return if task.blank?
course = task.course
return if course.blank?
attrs = %i[
user_id trigger_user_id container_id container_type parent_container_id parent_container_type
@ -18,7 +20,7 @@ class GraduationTaskPublishNotifyJob < ApplicationJob
viewed: 0, tiding_type: 'GraduationTask'
}
Tiding.bulk_insert(*attrs) do |worker|
task.course.course_members.pluck(:user_id).uniq.find_each do |user_id|
course.course_members.pluck(:user_id).uniq.find_each do |user_id|
worker.add same_attrs.merge(user_id: user_id)
end
end

@ -2,7 +2,7 @@ class HomeworkEndUpdateScoreJob < ApplicationJob
# 不允许补交的作业截止后,或者补交截止后需要重新计算一次作业成绩
queue_as :score
def perform(*args)
def perform(homework_id)
homework = HomeworkCommon.find_by(id: homework_id)
return if homework.blank?
course = homework.course
@ -16,7 +16,8 @@ class HomeworkEndUpdateScoreJob < ApplicationJob
student_works = homework.student_works.where(user_id: user_ids)
end
myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids).
shixun_id = homework.homework_commons_shixun.try(:shixun_id)
myshixuns = Myshixun.where(shixun_id: shixun_id, user_id: user_ids).
includes(:games).where(games: {challenge_id: homework.homework_challenge_settings.pluck(:challenge_id)})
challenge_settings = homework.homework_challenge_settings
myshixuns.find_each(batch_size: 100) do |myshixun|

@ -31,7 +31,7 @@ class PollPublishNotifyJob < ApplicationJob
Tiding.bulk_insert(*attrs) do |worker|
teacher_ids = teachers.pluck(:user_id)
unless poll.tidings.exists?(parent_container_type: 'PollPublish', user_id: teacher_ids)
teacher_ids.find_each do |user_id|
teacher_ids.each do |user_id|
worker.add same_attrs.merge(user_id: user_id)
end
end

@ -19,11 +19,12 @@ class SubmitGraduationWorkNotifyJob < ApplicationJob
next unless User.exists?(id: user_id)
work = task.graduation_works.find_by(user_id: user_id)
next if work.blank?
member = course.students.find_by(user_id: user_id)
next if work.blank? || member.blank?
attrs = same_attrs.merge(trigger_user_id: user_id, container_id: work.id)
course.course_member(user_id).member_teachers.find_each do |teacher|
member.member_teachers.find_each do |teacher|
worker.add attrs.merge(user_id: teacher.user_id)
end
end

@ -19,11 +19,12 @@ class SubmitStudentWorkNotifyJob < ApplicationJob
next unless User.exists?(id: user_id)
work = homework.student_works.find_by(user_id: user_id)
next if work.blank?
member = course.students.find_by(user_id: user_id)
next if work.blank? || member.blank?
attrs = same_attrs.merge(trigger_user_id: user_id, container_id: work.id)
course.course_member(user_id).member_teachers.find_each do |teacher|
member.member_teachers.find_each do |teacher|
worker.add attrs.merge(user_id: teacher.user_id)
end
end

@ -0,0 +1,5 @@
class AppliedMessage < ApplicationRecord
belongs_to :user
belongs_to :applied, polymorphic: true
end

@ -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

@ -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

@ -76,8 +76,9 @@ class Challenge < ApplicationRecord
## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成
def user_tpi_status user_id
# todo: 以前没加索引导致相同关卡,同一用户有多个games
game = games.last
# 允许跳关则直接开启
return 1 if shixun.task_pass
game = games.where(user_id: user_id).take
if game.blank?
self.position == 1 ? 1 : 0
elsif game.status == 2

@ -146,11 +146,11 @@ class CourseMember < ApplicationRecord
def member_teachers
teacher_groups = course.teacher_course_groups
if teacher_groups.count > 0
member_ids = teacher_groups.where(course_group_id: self.try(:course_group_id)).pluck(:course_member_id)
member_ids = teacher_groups.where(course_group_id: self.try(:course_group_id)).pluck(:course_member_id).compact
none_group_teachers = teacher_groups.pluck(:course_member_id).size > 0 ? teacher_groups.pluck(:course_member_id).join(',') : -1
teachers = course.teachers.where("members.id not in (#{none_group_teachers}) or
members.id in (#{member_ids.size > 0 ? member_ids.join(',') : -1})")
none_group_teachers = teacher_groups.pluck(:course_member_id).size > 0 ? teacher_groups.pluck(:course_member_id).compact.join(',') : -1
teachers = course.teachers.where("course_members.id not in (#{none_group_teachers}) or
course_members.id in (#{member_ids.size > 0 ? member_ids.join(',') : -1})")
else
teachers = course.teachers
end

@ -404,7 +404,6 @@ class User < ApplicationRecord
# 用户的真实姓名(不考虑用户是否隐藏了真实姓名,课堂模块都用真实姓名)
def real_name
return '游客' unless logged?
name = lastname + firstname
name.blank? ? (nickname.blank? ? login : nickname) : name
name.gsub(/\s+/, '').strip #6.11 -hs

@ -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

@ -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

@ -17,7 +17,7 @@ if @challenges.present?
json.passed_count challenge.user_passed_count
json.playing_count challenge.playing_count
json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
json.open_game challenge.open_game(@user.id, @shixun)
#json.open_game challenge.open_game(@user.id, @shixun)
if @editable
json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)

@ -1,6 +1,8 @@
if identity == Course::STUDENT
if homework.homework_type == "practice"
json.task_operation task_operation_url(work.try(:myshixun), homework.shixuns.take)
shixun = homework.shixuns.take
myshixun = work.try(:myshixun) ? work.myshixun : shixun.myshixuns.find_by(user_id: work.user_id)
json.task_operation task_operation_url(myshixun, shixun)
json.view_report work.work_status > 0
json.commit_des commit_des_status(work, homework)
else

@ -8,7 +8,10 @@ wb.styles do |s|
wb.add_worksheet(:name => "统计结果") do |sheet|
sheet.sheet_view.show_grid_lines = false
poll_users_info = %w(序号)
Rails.logger.info("#############_______________poll_questions.pluck(:question_title)_______####################{poll_questions.pluck(:question_title)}")
poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?}
Rails.logger.info("#############_______________poll_ques_titles_______####################{poll_ques_titles}")
poll_un_anony = poll.un_anonymous
if poll_un_anony #是否匿名默认为false
user_info = %w(登陆名 真实姓名 邮箱 学号)
@ -18,13 +21,13 @@ wb.styles do |s|
poll_users_info = poll_users_info + user_info + poll_ques_titles
poll_questions.each do |q|
if q.question_type != 3 #问题不为主观题
question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).count #该问题的有效填写量
question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).size #该问题的有效填写量
sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组
sheet_answer_row = ["小计"] #选择题回答的答案人数,数组
sheet_answer_percent = ["比例"]
sheet_answer_useful = ["有效填写人次",question_vote_user]
q.poll_answers.each do |a| #问卷的答案选项
answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).count
answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).size
answer_percent = number_to_percentage((answer_users_count.to_f / question_vote_user.to_f)*100,precision:1)
sheet_row.push(a.answer_text)
sheet_answer_row.push(answer_users_count)
@ -41,15 +44,15 @@ wb.styles do |s|
else #主观题答案
main_show_row = ["第#{q.question_number}题",q.question_title]
sheet.add_row main_show_row,:height =>15, :style => blue_cell
q.poll_votes.each do |v| #主观题的答案
sheet.add_row ["",v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all
q.poll_votes.each_with_index do |v,index| #主观题的答案
sheet.add_row [(index+1),v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all
end
sheet.add_row [], :style => sz_all
end
end #each_with_index
sheet.add_row poll_users_info, :height =>15, :style => blue_cell
poll_users.each_with_index do |u,index|
poll_users.includes(user: :user_extension).each_with_index do |u,index|
u_user = u.user
user_answer_array = []
poll_questions.each do |q|

@ -0,0 +1,8 @@
'zh-CN':
activemodel:
attributes:
add_school_apply_form:
name: 名称
province: 省份
city: 城市
address: 详细地址

@ -596,6 +596,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

@ -0,0 +1,9 @@
class AddIndexForShixunServices < ActiveRecord::Migration[5.2]
def change
sql = %Q(delete from shixun_service_configs where (shixun_id, mirror_repository_id) in
(select * from (select shixun_id, mirror_repository_id from shixun_service_configs group by shixun_id, mirror_repository_id having count(*) > 1) a)
and id not in (select * from (select min(id) from shixun_service_configs group by shixun_id, mirror_repository_id having count(*) > 1 order by id) b))
ActiveRecord::Base.connection.execute sql
add_index :shixun_service_configs, [:shixun_id, :mirror_repository_id], unique: true, name: "shixun_id_mirror_id_unique"
end
end
Loading…
Cancel
Save