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

dev_forum
cxt 5 years ago
commit 321ba22401

@ -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
normal_status(0,"试卷更新成功!")
rescue Exception => e
uid_logger_error(e.message)
tip_exception("页面调用失败!")

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

@ -108,7 +108,7 @@ class HomeworkCommonsController < ApplicationController
@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 +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
@ -216,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{

@ -15,7 +15,6 @@ class MyshixunsController < ApplicationController
# For Admin
# 强制重置实训
# REDO等删除是否可以做成异步
# 前段需要按照操作过程提示
def reset_my_game
unless current_user.admin?

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

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

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

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

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

@ -256,6 +256,7 @@ Rails.application.routes.draw do
get :mine_with_course_and_project
post :import
post :upload
put :bulk_publish
end
member do
get :histories
@ -595,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,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
Loading…
Cancel
Save