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

dev_course
cxt 5 years ago
commit ba70f02acf

@ -146,7 +146,7 @@ class PollsController < ApplicationController
def edit
ActiveRecord::Base.transaction do
begin
@poll_questions = @poll.poll_questions.order("question_number ASC")
rescue Exception => e
uid_logger_error(e.message)
tip_exception("页面请求失败!")
@ -183,7 +183,7 @@ class PollsController < ApplicationController
else
@is_teacher_or = 0
end
@poll_questions = @poll.poll_questions&.includes(:poll_answers).order("question_number ASC")
rescue Exception => e
uid_logger_error(e.message)
tip_exception("没有权限")
@ -868,7 +868,6 @@ class PollsController < ApplicationController
@user_poll_status = 0 #可编辑
end
# @answer_user = User.find_by(id:@poll_current_user_id)
@answer_status = []
question_answered = 0
@ -925,7 +924,6 @@ class PollsController < ApplicationController
@page = params[:page] || 1
@limit = params[:limit] || 10
@poll_export_questions = @poll_questions
@poll_questions = @poll_questions.page(@page).per(@limit)
if params[:format] == "xlsx"
if @user_course_identity > Course::ASSISTANT_PROFESSOR
@ -1151,7 +1149,7 @@ class PollsController < ApplicationController
def get_questions_count
@poll_questions = @poll.poll_questions.order("question_number ASC")
@poll_questions_count = @poll_questions.size # 全部的题目数
@poll_questions_count = @poll_questions&.size # 全部的题目数
@poll_question_singles = @poll_questions.ques_count(1).size # 单选题
@poll_question_doubles = @poll_questions.ques_count(2).size # 多选题
@poll_question_mains = @poll_questions.ques_count(3).size #主观题
@ -1301,7 +1299,6 @@ class PollsController < ApplicationController
#问卷的统计结果的导出
def poll_commit_result(poll,poll_questions,poll_users,poll_commit_ids)
obj_commit = []
sub_commit = []
user_commit = []
poll_users_info = %w(序号)
@ -1315,25 +1312,23 @@ class PollsController < ApplicationController
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).size #该问题的有效填写量
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]
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).size
answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids)&.size
answer_percent = (question_vote_user == 0) ? "0.0%" : "#{((answer_users_count / question_vote_user.to_f)*100).round(1).to_s}%"
sheet_row.push(a.answer_text)
sheet_answer_row.push(answer_users_count)
sheet_answer_percent.push(answer_percent)
end
sheet_obj_commit = {
sheet_row:sheet_row,
sheet_answer_row:sheet_answer_row,
sheet_answer_percent:sheet_answer_percent,
sheet_answer_useful:sheet_answer_useful
sheet_sub_commit = {
sub_title: sheet_row,
sub_user_votes:[sheet_answer_row,sheet_answer_percent,sheet_answer_useful]
}
obj_commit.push(sheet_obj_commit)
sub_commit.push(sheet_sub_commit)
else #主观题答案
user_votes= []
main_show_row = ["#{q.question_number}", q.question_title ]
@ -1347,9 +1342,10 @@ class PollsController < ApplicationController
}
sub_commit.push(sheet_sub_commit)
end
end #each_with_index
poll_users.includes(user: :user_extension).each_with_index do |u,index|
poll_users.includes(user: [:user_extension,:poll_votes]).each_with_index do |u,index|
u_user = u.user
user_answer_array = []
poll_questions.each do |q|
@ -1390,7 +1386,6 @@ class PollsController < ApplicationController
end
{
obj_commit:obj_commit,
poll_users_info:poll_users_info,
sub_commit:sub_commit,
user_commit:user_commit

@ -0,0 +1,39 @@
class Users::AuthAttachmentsController < Users::BaseAccountController
before_action :private_user_resources!
before_action :convert_image!, only: [:update]
def update
image_temp_path = auth_image_path + 'temp' # 上传文件保存至临时文件,提交申请时再移到正常目录
File.delete(image_temp_path) if File.exist?(image_temp_path) # 删除之前的临时文件
Util.write_file(@image, image_temp_path)
render_ok
rescue StandardError => ex
logger_error(ex)
render_error('上传失败')
end
private
def convert_image!
max_size = EduSetting.get('upload_avatar_max_size') || 10 * 1024 * 1024 # 10M
if params[:image].class == ActionDispatch::Http::UploadedFile
@image = params[:image]
render_error('请上传文件') if @image.size.zero?
render_error('文件大小超过限制') if @image.size > max_size
else
image = params[:image].to_s.strip
return render_error('请上传正确的图片') if image.blank?
@image = Util.convert_base64_image(image, max_size: max_size)
end
rescue Base64ImageConverter::Error => ex
render_error(ex.message)
end
def auth_image_path
url_method = params[:type] == 'professional' ? :disk_professional_auth_filename : :disk_real_name_auth_filename
ApplicationController.helpers.send(url_method, observed_user.id)
end
end

@ -0,0 +1,16 @@
class Users::AuthenticationAppliesController < Users::BaseAccountController
before_action :private_user_resources!
def create
Users::ApplyAuthenticationService.call(observed_user, create_params)
render_ok
rescue Users::ApplyAuthenticationService::Error => ex
render_error(ex.message)
end
private
def create_params
params.permit(:name, :id_number, :upload_image)
end
end

@ -0,0 +1,16 @@
class Users::ProfessionalAuthAppliesController < Users::BaseAccountController
before_action :private_user_resources!
def create
Users::ApplyProfessionalAuthService.call(observed_user, create_params)
render_ok
rescue Users::ApplyProfessionalAuthService::Error => ex
render_error(ex.message)
end
private
def create_params
params.permit(:school_id, :department_id, :identity, :extra, :upload_image)
end
end

@ -0,0 +1,8 @@
class Users::ApplyAuthenticationForm
include ActiveModel::Model
attr_accessor :name, :id_number, :upload_image
validates :name, presence: true
validates :id_number, presence: true
end

@ -0,0 +1,10 @@
class Users::ApplyProfessionalAuthForm
include ActiveModel::Model
attr_accessor :school_id, :department_id, :identity, :extra, :upload_image
validates :school_id, presence: true, numericality: { only_integer: true, greater_than: 0 }
validates :department_id, numericality: { only_integer: true, greater_than: 0 }, allow_blank: true
validates :identity, presence: true, inclusion: { in: %w(student teacher professional) }
validates :extra, presence: true
end

@ -145,6 +145,18 @@ module ApplicationHelper
File.join(storage_path, "#{source_type}", "#{source_id}")
end
def disk_auth_filename(source_type, source_id, type)
File.join(storage_path, "#{source_type}", "#{source_id}#{type}")
end
def disk_real_name_auth_filename(source_id)
disk_auth_filename('UserAuthentication', source_id, 'ID')
end
def disk_professional_auth_filename(source_id)
disk_auth_filename('UserAuthentication', source_id, 'PRO')
end
def shixun_url_to_avatar(shixun)
if File.exist?(disk_filename(shixun.class, shixun.id))
File.join("images/#{relative_path}", "#{shixun.class}", "#{shixun.id}")

@ -78,8 +78,6 @@ class Challenge < ApplicationRecord
# todo: 以前没加索引导致相同关卡,同一用户有多个games
# 允许跳关则直接开启
game = games.where(user_id: user_id).take
logger.info("########---game_status: #{game.status}")
logger.info("########---challenge_id: #{id}")
if game.blank?
position == 1 ? 1 : 0
else

@ -4,7 +4,7 @@ class UserExtension < ApplicationRecord
belongs_to :user
belongs_to :school
belongs_to :department
belongs_to :department, optional: true
def identity_text
I18n.t("user.identity.#{identity}")

@ -0,0 +1,52 @@
class Users::ApplyAuthenticationService < ApplicationService
Error = Class.new(StandardError)
attr_reader :user, :params
def initialize(user, params)
@user = user
@params = params
end
def call
Users::ApplyAuthenticationForm.new(params).validate!
raise Error, '您已经申请过实名认证了' if ApplyUserAuthentication.real_name_auth.processing.exists?(user_id: user.id)
user.lastname = params[:name].to_s.strip
user.firstname = ''
user.ID_number = params[:id_number].to_s.strip.presence
ActiveRecord::Base.transaction do
user.authentication = false
user.save!
user.apply_user_authentication.create!(auth_type: 1, status: 0)
move_image_file! unless params[:upload_image].to_s == 'false'
sms_notify_admin
end
user
end
private
def move_image_file!
image_url = ApplicationController.helpers.disk_real_name_auth_filename(user.id)
temp_image_url = image_url + 'temp'
FileUtils.mv(temp_image_url, image_url, force: true) if File.exist?(temp_image_url)
rescue RuntimeError => ex
Util.logger_error(ex)
raise Error, '申请失败'
ensure
File.delete(temp_image_url) if File.exist?(temp_image_url)
end
def sms_notify_admin
Educoder::Sms.notify_admin(send_type: 'apply_auth')
rescue => ex
Util.logger_error(ex)
end
end

@ -0,0 +1,62 @@
class Users::ApplyProfessionalAuthService < ApplicationService
Error = Class.new(StandardError)
attr_reader :user, :params
def initialize(user, params)
@user = user
@params = params
end
def call
Users::ApplyProfessionalAuthForm.new(params).validate!
raise Error, '您已经申请过职业认证了' if ApplyUserAuthentication.professional_auth.processing.exists?(user_id: user.id)
user.professional_certification = false
extension = user.user_extension
extension.school_id = params[:school_id]
extension.department_id = params[:department_id]
extension.identity = params[:identity]
extra = params[:extra].to_s.strip.presence
if extension.identity.to_s == 'student'
extension.technical_title = nil
extension.student_id = extra
else
extension.technical_title = extra
extension.student_id = nil
end
ActiveRecord::Base.transaction do
user.save!
extension.save!
user.apply_user_authentication.create!(auth_type: 2, status: 0)
move_image_file! unless params[:upload_image].to_s == 'false'
sms_notify_admin
end
end
private
def move_image_file!
image_url = ApplicationController.helpers.disk_professional_auth_filename(user.id)
temp_image_url = image_url + 'temp'
FileUtils.mv(temp_image_url, image_url, force: true) if File.exist?(temp_image_url)
rescue RuntimeError => ex
Util.logger_error(ex)
raise Error, '申请失败'
ensure
File.delete(temp_image_url) if File.exist?(temp_image_url)
end
def sms_notify_admin
Educoder::Sms.notify_admin(send_type: 'apply_pro_certification')
rescue => ex
Util.logger_error(ex)
end
end

@ -15,7 +15,7 @@ wb.styles do |s|
sheet.sheet_view.show_grid_lines = false
sheet_title = table_columns
sheet_title_c = sheet_title.count
sheet.add_row sheet_title, :style => bg_cell
sheet.add_row sheet_title, :style => bg_cell,:height => 15
sheet["J1:L1"].each { |c| c.style = bg_db }
sheet["M1:O1"].each { |c| c.style = bg_cc }
sheet["P1:Q1"].each { |c| c.style = bg_d2 }

@ -8,10 +8,13 @@ json.group_list do
end
# 未分班展示情况放在最后
if @course_groups.count < @limit.to_i
ungroup_work_count = homework_ungroup_works_count(@homework, @ungroup_user_ids)
if ungroup_work_count > 0
json.ungroup_list do
json.id 0
json.name "未分班"
json.work_count homework_ungroup_works_count @homework, @ungroup_user_ids
json.work_count ungroup_work_count
json.last_review_time ungroup_last_review_time @homework
end
end
end

@ -7,31 +7,20 @@ wb.styles do |s|
wb.add_worksheet(:name => "统计结果") do |sheet|
sheet.sheet_view.show_grid_lines = false
obj_commit = polls_user_commit[:obj_commit] || []
sub_commit = polls_user_commit[:sub_commit] || []
poll_user_info = polls_user_commit[:poll_users_info] || []
user_commit = polls_user_commit[:user_commit] || []
sub_commit = polls_user_commit[:sub_commit]
poll_user_info = polls_user_commit[:poll_users_info]
user_commit = polls_user_commit[:user_commit]
#客观题的导出
if obj_commit&.size > 0
obj_commit.each do |obj|
sheet.add_row obj[:sheet_row], :height =>15,:style => blue_cell
sheet.add_row obj[:sheet_answer_row], :height =>15, :style => sz_all
sheet.add_row obj[:sheet_answer_percent], :height =>15, :style => sz_all
sheet.add_row obj[:sheet_answer_useful], :height =>15, :style => sz_all
sheet.add_row []
end
end
#主观题的导出
if sub_commit&.size > 0
sub_commit.each do |sub|
main_sub_title = sub[:sub_tile]
main_sub_title = sub[:sub_title]
main_sub_content = sub[:sub_user_votes]
sheet.add_row main_sub_title,:height =>15, :style => blue_cell
if main_sub_content.present?
main_sub_content.each do |con|
sheet.add_row con,:height =>15, :style => sz_all
end
end
sheet.add_row []
end
end
@ -44,93 +33,7 @@ wb.styles do |s|
end
end
sheet.column_widths *([25]*sheet.column_info.count)
sheet.column_info.first.width = 10
#答题用户的导出
sheet.column_info.first.width = 15
# sheet.sheet_view.show_grid_lines = false
# 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
# poll_questions.each do |q|
# if q.question_type != 3 #问题不为主观题
# 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).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)
# sheet_answer_percent.push(answer_percent.to_s)
# end
# sheet.add_row sheet_row, :height =>15,:style => blue_cell
# sheet.add_row sheet_answer_row, :height =>15, :style => sz_all
# sheet.add_row sheet_answer_percent, :height =>15, :style => sz_all
# sheet.add_row sheet_answer_useful, :height =>15, :style => sz_all
# #合并单元格但无法填充style
# # sheet.merge_cells (Axlsx::cell_r(1,sheet.rows.last.row_index) + ':' + Axlsx::cell_r(sheet_row.count-1,sheet.rows.last.row_index))
# # sheet.rows[sheet.rows.last.row_index].style = sz_all
# sheet.add_row []
# 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_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.includes(user: :user_extension).each_with_index do |u,index|
# u_user = u.user
# user_answer_array = []
# poll_questions.each do |q|
# user_poll_votes = u_user.poll_votes.find_current_vote("poll_question_id",q.id)
# if user_poll_votes.present?
# user_poll_answer_ids = user_poll_votes.pluck(:poll_answer_id).reject(&:blank?)
# user_poll_vote_texts = user_poll_votes.pluck(:vote_text).reject(&:blank?)
# if user_poll_answer_ids.count > 0
# answer_content = q.poll_answers.find_answer_by_custom("id",user_poll_answer_ids)
# if user_poll_answer_ids.count >1
# u_answer = answer_content.pluck(:answer_text).join(";")
# else
# u_answer = answer_content.first.answer_text
# end
# elsif user_poll_vote_texts.count > 0
# if user_poll_vote_texts.count > 1
# u_answer = user_poll_vote_texts.join(";")
# else
# u_answer = user_poll_vote_texts.first
# end
# else
# u_answer = "--"
# end
# else
# u_answer = "--"
# end
# user_answer_array.push(u_answer)
# end
# user_cell = [index+1]
# if poll_un_anony
# user_login = u_user.login
# user_name = u_user.real_name.present? ? u_user.real_name : "--"
# user_student_id = u_user.student_id.present? ? u_user.student_id : "--"
# user_cell += [user_login,user_name, u_user.mail, user_student_id]
# end
# all_user_cell = user_cell + user_answer_array
# sheet.add_row all_user_cell, :height =>15,:style => sz_all
# end
# sheet.column_widths *([25]*sheet.column_info.count)
# sheet.column_info.first.width = 10
end #add_worksheet
end

@ -0,0 +1,7 @@
'zh-CN':
activemodel:
attributes:
users/apply_authentication_form:
name: 姓名
id_number: 身份证号

@ -0,0 +1,9 @@
'zh-CN':
activemodel:
attributes:
users/apply_professional_auth_form:
school_id: 学校/单位
department_id: 学院/部门
identity: 职业
extra: 职称/学号

@ -74,6 +74,9 @@ Rails.application.routes.draw do
resource :email_bind, only: [:create]
resource :password, only: [:update]
resource :avatar, only: [:update]
resource :auth_attachment, only: [:update]
resource :authentication_apply, only: [:create]
resource :professional_auth_apply, only: [:create]
end
end
end

@ -21,7 +21,7 @@ module Educoder
def self.notify_admin(opt)
opt[:name] = '管理员'
opt[:mobile] = ENV['NOTIDY_ADMIN_PHONE'] || '17680641960'
opt[:mobile] = ENV['NOTIFY_ADMIN_PHONE'] || EduSetting.get('notify_admin_phone') || '17680641960'
send(opt)
end

Loading…
Cancel
Save