@ -2,11 +2,10 @@
class ManagementsController < ApplicationController
before_filter :require_business
before_filter :require_admin , :only = > [ :shixun_setting_list , :mirror_repository , :mirror_picture_shixuns , :editmd_template ,
:editmd_template , :subject_level_system , :subject_setting_list , :auto_users_trial ,
:evaluate_records , :identity_authentication , :identity_authentication , :professional_authentication ,
:shixun_authorization , :graduation_standard , :ec_template , :codemirror_template ,
:editmd_template , :subject_level_system , :subject_setting_list ,
:shixun_authorization , :ec_template , :codemirror_template ,
:course_guide_template , :shixun_quality_score , :tech_system , :update_notice , :setting_banner ,
:training_2018 ]
:training_2018 , :create_standard ]
layout 'base_management'
include ManagementsHelper
include SortHelper
@ -32,6 +31,15 @@ class ManagementsController < ApplicationController
# 实训课程等级体系
def subject_level_system
@levels = SubjectLevelSystem . all
respond_to do | format |
format . js
format . html
format . xls {
time = Time . now . strftime ( " %Y%m%d " )
filename = " 实训课程体系 #{ time } .xls "
send_data ( export_subject_level_system ( ) , :type = > 'application/octet-stream' , :filename = > filename_for_content_disposition ( filename ) )
}
end
end
# 创建课程等级体系
@ -2023,7 +2031,7 @@ end
# @schools = School.where(:id =>user_exs.map(&:school_id))
# end
@search = params [ :search ] # 搜索字
@keyword = params [ :keyword ] . blank? ? " u _name" : params [ :keyword ] # 根据姓名/课程名搜索
@keyword = params [ :keyword ] . blank? ? " c _name" : params [ :keyword ] # 根据姓名/课程名搜索
@status = params [ :status ]
@school_id = params [ :school_id ]
@ -2044,11 +2052,13 @@ end
if params [ :status ] && params [ :status ] != ''
@courses = @courses . where ( :is_end = > @status . to_i )
end
if " u_name " == @keyword
if " c_name " == @keyword
@courses = @courses . where ( " name like ? " , " % #{ @search } % " )
elsif " u_name " == @keyword
if @search . blank?
@courses = @courses
else
user_id = User . where ( " concat(lastname, firstname) like '% #{ @search } %' " )
# user_id = User.where("concat(lastname, firstname) like '%#{@search}%'" )
@courses = @courses . joins ( " join users u on courses.tea_id = u.id " ) . where ( " concat(u.lastname, u.firstname) like '% #{ @search } %' " )
end
elsif " dep_name " == @keyword
@ -2818,17 +2828,17 @@ end
else
" status = 1 "
end
@users = User . where ( " #{ sql } " ) . includes ( :apply_actions , user_extensions : [ :department , :school ] ) . order ( " last_login_on #{ @sx_order } " )
@users = User . where ( " #{ sql } " ) . includes ( :real_name_authentication_apply , :professional_authentication_apply ,
user_extensions : [ :department , :school ] ) . order ( " last_login_on #{ @sx_order } " )
@has_cer_count = User . where ( :status = > 1 , :certification = > 1 ) . count
@reject_cer_count = User . where ( :status = > 1 , :certification = > 2 ) . count
@deal_cer_count = ApplyAction . where ( :status = > 0 ) . select ( " distinct user_id " ) . count
time = Time . at ( Time . now . to_i - 86400 )
cer = UserDayCertification . where ( " created_at > ' #{ time } ' " ) . pluck ( :user_id )
cer_ids = cer . join ( " , " )
@trial_cer_count = cer . blank? ? 0 : User . where ( " status = 1 and certification != 1 and id in ( #{ cer_ids } ) " ) . count
apply = ApplyAction . where ( :container_type = > " TrialAuthorization " ) . pluck ( :user_id )
apply_ids = apply . join ( " , " )
@nonn_cer_count = apply . blank? ? 0 : User . where ( " status = 1 and certification = 0 and id not in ( #{ apply_ids } ) " ) . count
subquery = UserDayCertification . where ( " created_at > ? " , Time . now . ago ( 1 . days ) ) . select ( :user_id ) . to_sql
@trial_cer_count = User . where ( " status = 1 and certification != 1 and id in ( #{ subquery } ) " ) . count
apply_subquery = ApplyAction . where ( container_type : " TrialAuthorization " ) . select ( :user_id ) . to_sql
@nonn_cer_count = User . where ( " status = 1 and certification = 0 and id not in ( #{ apply_subquery } ) " ) . count
@page = ( params [ 'page' ] || 1 ) . to_i
@users_count = @users . count
@ -3308,83 +3318,82 @@ end
end
end
all_ user_id s = User . where ( :status = > 1 ) . pluck ( :id )
users = User . where ( nil )
if params [ :trial ] == " -1 "
apply = ApplyAction . where ( :container_type = > " TrialAuthorization " ) . pluck ( :user_id )
apply_id = apply . blank? ? - 1 : " ( " + apply . join ( " , " ) + " ) "
apply_user_id = User . where ( " status = 1 and certification = 0 and id not in #{ apply_id } " ) . pluck ( :id )
users = users . where ( status : 1 , certification : 0 )
. joins ( 'LEFT JOIN apply_actions ON apply_actions.user_id = users.id AND apply_actions.container_type = "TrialAuthorization"' )
. where ( 'apply_actions.user_id IS NULL' )
elsif params [ :trial ] == " -2 "
apply_user_id = all_user_ids
users = users . where ( status : 1 )
elsif params [ :trial ] == " 0 "
apply_user_id = ApplyAction . where ( :status = > 0 ) . pluck ( :user_id )
users = users . joins ( 'LEFT JOIN apply_actions ON apply_actions.user_id = users.id' ) . where ( apply_actions : { status : 0 } )
elsif params [ :trial ] == " 3 "
time = Time . at ( Time . now . to_i - 86400 )
user_cer = UserDayCertification . where ( " created_at > ' #{ time } ' " ) . pluck ( :user_id )
cer_id = user_cer . blank? ? " (-1) " : " ( " + user_cer . map { | a | a . user_id } . join ( " , " ) + " ) "
apply_user_id = User . where ( " status = 1 and certification != 1 and id in #{ cer_id } " ) . pluck ( :id )
users = users . joins ( 'LEFT JOIN user_day_certifications udc ON udc.user_id = users.id' )
. where ( 'users.certification != 1' ) . where ( 'udc.created_at > ?' , Time . now . ago ( 1 . days ) )
else
apply_user_id = User . where ( :status = > 1 , :certification = > params [ :trial ] ) . pluck ( :id )
users = users . where ( status : 1 , certification : params [ :trial ] )
end
if params [ :school ] == " "
s_user_id = all_user_ids
else
school_ids = School . where ( " name like '% #{ params [ :school ] } %' " ) . pluck ( :id )
s_user_id = UserExtensions . where ( :school_id = > school_ids ) . pluck ( :user_id )
users = users . joins ( 'LEFT JOIN user_extensions ON user_extensions.user_id = users.id' )
. joins ( 'LEFT JOIN departments ON departments.id = user_extensions.department_id' )
. joins ( 'LEFT JOIN schools ON schools.id = user_extensions.school_id' )
if params [ :school ] . present?
users = users . where ( " schools.name LIKE ? " , " % #{ params [ :school ] } % " )
end
if params [ :department ] == " "
d_user_id = all_user_ids
else
dep_ids = Department . where ( " name like '% #{ params [ :department ] } %' " ) . pluck ( :id )
d_user_id = UserExtensions . where ( :department_id = > dep_ids ) . pluck ( :user_id )
if params [ :department ] . present?
users = users . where ( " departments.name LIKE ? " , " % #{ params [ :department ] } % " )
end
ide_user_id = all_user_ids
if params [ :identity ] == " 1 " || ( params [ :identity ] == " 0 " && params [ :te_technical_title ] == " 0 " ) || ( params [ :identity ] == " 2 " && params [ :pro_technical_title ] == " 0 " )
ide_user_id = UserExtensions . where ( " identity = #{ params [ :identity ] } " ) . pluck ( :user_id )
users = users . where ( user_extensions : { identity : params [ :identity ] } )
elsif ( params [ :identity ] == " 0 " && params [ :te_technical_title ] != " 0 " ) || ( params [ :identity ] == " 2 " && params [ :pro_technical_title ] != " 0 " )
technical_title = params [ :identity ] == " 0 " ? params [ :te_technical_title ] : params [ :pro_technical_title ]
ide_user_id = UserExtensions . where ( " identity = #{ params [ :identity ] } and technical_title = ' #{ technical_title } ' " ) . pluck ( :user_id )
users = users . where ( user_extensions : { identity : params [ :identity ] , technical_title : technical_title } )
end
if params [ :student_id ] && params [ :student_id ] != ''
stu_user_id = UserExtensions . where ( " student_id like '% #{ params [ :student_id ] } %' " ) . pluck ( :user_id )
else
stu_user_id = all_user_ids
if params [ :student_id ] . present?
users = users . where ( 'user_extensions.student_id like ?' , " % #{ params [ :student_id ] } % " )
end
user_id = s_user_id & d_user_id & apply_user_id & stu_user_id & ide_user_id
sql = " "
sql =
if params [ :research_condition ] == " name "
" concat(lastname, firstname) like '% #{ params [ :research_contents ] } %' "
elsif params [ :research_condition ] == " email "
" mail like '% #{ params [ :research_contents ] } %' "
elsif params [ :research_condition ] == " phone "
" phone like '% #{ params [ :research_contents ] } %' "
elsif params [ :research_condition ] == " nickname "
if params [ :research_contents ] . present?
" nickname like '% #{ params [ :research_contents ] } %' "
end
elsif params [ :research_condition ] == " login "
params [ :research_contents ] . present? ? " login like '% #{ params [ :research_contents ] } %' " : " "
end
if params [ :research_contents ] . present?
keyword = " % #{ params [ :research_contents ] } % "
if params [ :research_condition ] == " name "
users = users . where ( 'concat(lastname, firstname) like ?' , keyword )
elsif params [ :research_condition ] == " email "
users = users . where ( " mail like ? " , keyword )
elsif params [ :research_condition ] == " phone "
users = users . where ( " phone like ? " , keyword )
elsif params [ :research_condition ] == " nickname "
users = users . where ( " nickname like ? " , keyword )
elsif params [ :research_condition ] == " login "
users = users . where ( " login like ? " , keyword )
end
end
if params [ :province ] . present?
users = users . where ( schools : { province : params [ :province ] } )
end
users = users . select ( 'distinct users.*' ) . order ( " last_login_on desc " )
@users = User . where ( :id = > user_id ) . where ( " #{ sql } " ) . includes ( :apply_actions , user_extensions : [ :department , :school ] ) . order ( " last_login_on desc " )
@xls_users = @users . reorder ( " created_on desc " ) . limit ( 3000 ) #导出excel用户
@page = ( params [ 'page' ] || 1 ) . to_i
@users_count = @ users. count
@users_count = users . count
@limit = 20
@is_remote = true
@users_pages = Paginator . new @users_count , @limit , params [ 'page' ] || 1
@offset || = @users_pages . offset
@users = paginateHelper @users , @limit
@users = paginateHelper users . includes ( :real_name_authentication_apply , :professional_authentication_apply ,
user_extensions : [ :department , :school ] ) , @limit
respond_to do | format |
format . js
format . xls {
# @export_shixun_task = @export_shixun_task.all
@xls_users = users . reorder ( " created_on desc " ) . limit ( 3000 ) #导出excel用户
@xls_users = @xls_users . includes ( :real_name_authentication_apply , :professional_authentication_apply ,
user_extensions : [ :department , :school ] )
filename = " 用户列表.xls "
send_data ( user_list_xls ( @xls_users ) , :type = > 'application/octet-stream' , :filename = > filename_for_content_disposition ( filename ) )
}
@ -4184,7 +4193,7 @@ end
sheet1 = book . create_worksheet :name = > " users "
blue = Spreadsheet :: Format . new :color = > :blue , :weight = > :bold , :size = > 10
sheet1 . row ( 0 ) . default_format = blue
sheet1 . row ( 0 ) . concat ( [ " 用户姓名 " , " 性别 " , " 职业 " , " 职称 " , " 地区 " , " 单位 " , " 子单位 " , " 注册时间 " , " 最后登录时间 " , " 授权 " ] )
sheet1 . row ( 0 ) . concat ( [ " 用户姓名 " , " 性别 " , " 职业 " , " 职称 " , " 地区 " , " 单位 " , " 子单位 " , " 注册时间 " , " 最后登录时间 " , " 授权 " , " 邮箱 " ] )
count_row = 1
users . each do | user |
sheet1 [ count_row , 0 ] = user . try ( :show_real_name )
@ -4197,6 +4206,7 @@ end
sheet1 [ count_row , 7 ] = format_time user . created_on
sheet1 [ count_row , 8 ] = format_time user . last_login_on
sheet1 [ count_row , 9 ] = user . trial_authorization
sheet1 [ count_row , 10 ] = user . mail
count_row += 1
end
book . write xls_report
@ -4285,6 +4295,33 @@ end
return sheet . rows
end
def export_subject_level_system
xls_report = StringIO . new
book = Spreadsheet :: Workbook . new
sheet1 = book . create_worksheet :name = > " 实训课程等级体系 "
blue = Spreadsheet :: Format . new :color = > :blue , :weight = > :bold , :size = > 10
sheet1 . row ( 0 ) . default_format = blue
count_row = 1
sheet1 . row ( 0 ) . concat ( [ " 序号 " , " 等级 " , " 实训课程名称 " , " 实训课程url " , " 实训名称 " ] )
levels = SubjectLevelSystem . includes ( subjects : [ stage_shixuns : :shixun ] ) . where ( nil )
levels . each_with_index do | level , i |
sheet1 [ count_row , 0 ] = i + 1
sheet1 [ count_row , 1 ] = level . name
level . subjects . each do | subject |
sheet1 [ count_row , 2 ] = subject . name
sheet1 [ count_row , 3 ] = " #{ Setting . protocol } :// #{ Setting . host_name } #{ subject_path ( subject ) } "
count_row += 1
subject . shixuns . each do | shixun |
sheet1 [ count_row , 4 ] = shixun . name
count_row += 1
end
end
count_row += 1
end
book . write xls_report
xls_report . string
end
def shixun_feedback_xls shixun_ids , beginTime , endTime
xls_report = StringIO . new
book = Spreadsheet :: Workbook . new
@ -4294,7 +4331,7 @@ end
count_row = 1
shixuns = Shixun . where ( :id = > shixun_ids ) . includes ( discusses : [ :user ] )
sheet1 . row ( 0 ) . concat ( [ " 序号 " , " 实训ID " , " 实训名称 " , " 实训作者 " , " 作者单位 " , " 评论数 " , " 评论内容 " , " 关卡 " , " 评论者 " , " 评论者职业 " ,
" 评论者单位 " , " 评论时间 " , " 社区导师是否已回复 " ] )
" 评论者单位 " , " 评论时间 " , " 社区导师是否已回复 " , " 我的账号回复内容 " , " 回复时间 " ] )
shixuns . each_with_index do | shixun , i |
discusses = shixun . discusses . where ( " user_id != ? " , 1 )
if beginTime . present?
@ -4312,6 +4349,7 @@ end
discusses . each_with_index do | discuss , j |
user = discuss . user
content = discuss . content . gsub ( / <img.* \/ > / , " 【图片评论】 " ) . gsub ( / ! \ [ \ ].+ \ ) / , " 【图片评论】 " )
myself_discuss = discuss . children . where ( user_id : User . current . id ) . last
sheet1 [ count_row , 6 ] = strip_html content
sheet1 [ count_row , 7 ] = " 第 #{ discuss . position } 关 "
sheet1 [ count_row , 8 ] = user . show_real_name
@ -4319,6 +4357,8 @@ end
sheet1 [ count_row , 10 ] = user . school_name
sheet1 [ count_row , 11 ] = format_time discuss . created_at
sheet1 [ count_row , 12 ] = discuss . children . pluck ( :user_id ) . include? ( 1 ) ? " 是 " : " 否 "
sheet1 [ count_row , 13 ] = myself_discuss . try ( :content )
sheet1 [ count_row , 14 ] = myself_discuss ? ( format_time myself_discuss . created_at ) : " "
count_row += 1
end
#count_row += 1