diff --git a/app/controllers/colleges_controller.rb b/app/controllers/colleges_controller.rb index d95fd848..5f1f094c 100644 --- a/app/controllers/colleges_controller.rb +++ b/app/controllers/colleges_controller.rb @@ -1,7 +1,9 @@ # encoding: utf-8 class CollegesController < ApplicationController - before_filter :find_department, :only => [:statistics, :course_statistics, :student_shixun, :engineering_capability, :student_eval] + before_filter :find_department, :only => [:statistics, :course_statistics, :student_shixun, :engineering_capability, + :student_eval, :shixun_time, :shixun_report_count, :teachers, :shixun_chart_data, + :student_hot_evaluations] before_filter :manager_auth, :except => [:home, :get_home_data] include ApplicationHelper @@ -42,81 +44,85 @@ class CollegesController < ApplicationController end def statistics - logger.info("#########################{params}") - @teachers_count = User.find_by_sql("SELECT COUNT(users.`id`) AS teacher_count FROM users LEFT JOIN user_extensions ON users.id=user_extensions.user_id WHERE - user_extensions.`school_id` = #{@school.id} AND user_extensions.`identity` = 0").first.try(:teacher_count) - @students_count = User.find_by_sql("SELECT COUNT(users.`id`) AS student_count FROM users LEFT JOIN user_extensions ON users.id=user_extensions.user_id WHERE - user_extensions.`school_id` = #{@school.id} AND user_extensions.`identity` = 1").first.try(:student_count) - # Redo:这样做内存会卡死的 - # user_ids = User.find_by_sql("SELECT users.id FROM users LEFT JOIN user_extensions ON users.id=user_extensions.user_id WHERE user_extensions.`school_id` = #{@school.id}").map(&:id) - # Redo:是否直接使用count会更好 - all_course_ids = Course.where("id != 1309 and is_delete = 0 and school_id = #{@school.id}") - @courses_count = all_course_ids.size - - # Redo:对于量比较大的尽量不使用笛卡尔积 - # @shixuns_count = Shixun.where(:status => [2, 3], :user_id => user_ids).size - @shixuns_count = Shixun.find_by_sql("select count(s.id) as shixun_count from users u right join shixuns s on u.id=s.user_id and s.status in (2, 3) inner join user_extensions ue on - u.id=ue.user_id and ue.school_id=#{@school.id}").first.try(:shixun_count) - # @shixun_time_sum = (Game.where(:user_id => user_ids).pluck(:cost_time).sum / (24*60*60.0)).ceil - @shixun_time_sum = (Game.find_by_sql("select sum(g.cost_time) cost_time from users u RIGHT join games g on u.id=g.user_id inner join user_extensions ue on - u.id=ue.user_id and ue.school_id=#{@school.id}").first.try(:cost_time).to_i / (24 * 60 * 60.0)).ceil - - # select count(sw.id) from users u left join student_works sw on u.id=sw.user_id and sw.myshixun_id is not null and sw.work_status !=0 inner join user_extensions ue on u.id=ue.user_id and ue.school_id=117 ; - # @shixun_report_count = StudentWork.where("work_status != 0 and user_id in (#{user_ids.join(',').strip == "" ? -1 : user_ids.join(',')}) and myshixun_id is not null").count - @shixun_report_count = StudentWork.find_by_sql("SELECT count(*) as sw_count FROM `student_works` where user_id in (SELECT users.id FROM users RIGHT JOIN user_extensions ON users.id=user_extensions.user_id WHERE - user_extensions.`school_id`=#{@school.id}) and work_status between 1 and 2 and myshixun_id !=0").first.try(:sw_count) + # 教师、学生总数 + count_statistic = UserExtensions.where(school_id: @school.id).select('SUM(IF(identity=0, 1, 0)) AS teachers_count, SUM(IF(identity=1, 1, 0)) AS students_count').first + @teachers_count = count_statistic['teachers_count'] + @students_count = count_statistic['students_count'] + # 课堂总数 + @courses_count = Course.where(school_id: @school.id, is_delete: 0).where('id != 1309').count + # 实训总数 + @shixuns_count = Shixun.visible.joins('left join user_extensions on user_extensions.user_id = shixuns.user_id').where(user_extensions: { school_id: @school.id }).count + + respond_to do |format| + format.html {render :layout => "base_edu"} + end + end + + def shixun_time + time_sum = Game.joins('left join user_extensions on user_extensions.user_id = games.user_id').where(user_extensions: { school_id: @school.id }).sum(:cost_time) + shixun_time_sum = (time_sum / (24 * 60 * 60.0)).ceil + + render json: { shixun_time: shixun_time_sum } + end + + def shixun_report_count + shixun_report_count = StudentWork.where(work_status: [1, 2]).where('myshixun_id != 0') + .joins('left join user_extensions on user_extensions.user_id = student_works.user_id') + .where(user_extensions: { school_id: @school.id }).count + render json: { shixun_report_count: shixun_report_count } + end + + def teachers @teachers = User.find_by_sql("SELECT users.id, users.login, users.lastname, users.firstname, users.nickname, IFNULL((SELECT count(shixuns.id) FROM shixuns where shixuns.user_id =users.id group by shixuns.user_id), 0) AS publish_shixun_count, (SELECT count(c.id) FROM courses c, course_members m WHERE c.id != 1309 and m.course_id = c.id AND m.role in (1,2,3) and c.school_id = #{@school.id} AND m.user_id=users.id AND c.is_delete = 0) as course_count FROM `users`, user_extensions ue where users.id=ue.user_id and ue.identity=0 and ue.school_id=#{@school.id} ORDER BY publish_shixun_count desc, course_count desc, id desc LIMIT 10") # ).order("publish_shixun_count desc, experience desc").limit(10) @teachers = - @teachers.map do |teacher| - course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m WHERE c.id != 1309 and m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{teacher.id} AND c.is_delete = 0 and c.school_id = #{@school.id}") - course_count = course_ids.size - homeworks = HomeworkCommon.where(:homework_type => 4, :course_id => course_ids.map(&:id)) - un_shixun_work_count = homeworks.where("publish_time > '#{Time.now}' or publish_time is null").count - shixun_work_count = homeworks.size - un_shixun_work_count - student_count = StudentsForCourse.where(:course_id => course_ids.map(&:id)).count - myshixun_ids = StudentWork.select("myshixun_id").where("homework_common_id in (#{homeworks.map(&:id).join(',').strip == "" ? -1 : homeworks.map(&:id).join(',')}) and myshixun_id is not null") - complete_myshixun = Myshixun.select("id").where(:status => 1, :id => myshixun_ids.map(&:myshixun_id)).size - all_myshixun = Myshixun.select("id").where(:id => myshixun_ids.map(&:myshixun_id)).size - complete_rate = all_myshixun == 0 ? 0 : ((complete_myshixun * 100) / all_myshixun).try(:round, 2).to_f - real_name = teacher.show_real_name - teacher = teacher.attributes.dup.merge({ - real_name: real_name, - course_count: course_count, - shixun_work_count: shixun_work_count, - un_shixun_work_count: un_shixun_work_count, - student_count: student_count, - complete_rate: complete_rate - }).to_json - JSON.parse(teacher) - end - - shixun_ids = HomeworkCommonsShixuns.find_by_sql("SELECT hcs.shixun_id FROM homework_commons_shixuns hcs, homework_commons hc - WHERE hc.course_id in (#{all_course_ids.map(&:id).join(',').strip == "" ? -1 : all_course_ids.map(&:id).join(',')}) - AND hcs.homework_common_id = hc.id").map(&:shixun_id) - shixun_tags = TagRepertoire.find_by_sql("SELECT tr.`name`, COUNT(str.shixun_id) as shixun_count FROM tag_repertoires tr, - shixun_tag_repertoires str WHERE tr.id = str.tag_repertoire_id AND str.shixun_id - IN (#{shixun_ids.join(',').strip == "" ? -1 : shixun_ids.join(',')}) GROUP BY tr.id - order by shixun_count desc") - all_shixun_count = shixun_tags.map(&:shixun_count).sum - other_count = all_shixun_count.to_i - shixun_tags[0..8].map(&:shixun_count).sum.to_i - @shixun_tags_name = [] - @shixun_tags_data = [] - shixun_tags[0..8].each do |tag| - @shixun_tags_name << tag.name - @shixun_tags_data << {value: tag.shixun_count, name: tag.name} - end - if shixun_tags.size > 9 - @shixun_tags_name << 'Others' - @shixun_tags_data << {value: other_count, name: 'Others'} + @teachers.map do |teacher| + course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m WHERE c.id != 1309 and m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{teacher.id} AND c.is_delete = 0 and c.school_id = #{@school.id}") + course_count = course_ids.size + homeworks = HomeworkCommon.where(:homework_type => 4, :course_id => course_ids.map(&:id)) + un_shixun_work_count = homeworks.where("publish_time > '#{Time.now}' or publish_time is null").count + shixun_work_count = homeworks.size - un_shixun_work_count + student_count = StudentsForCourse.where(:course_id => course_ids.map(&:id)).count + myshixun_ids = StudentWork.select("myshixun_id").where("homework_common_id in (#{homeworks.map(&:id).join(',').strip == "" ? -1 : homeworks.map(&:id).join(',')}) and myshixun_id is not null") + complete_myshixun = Myshixun.select("id").where(:status => 1, :id => myshixun_ids.map(&:myshixun_id)).size + all_myshixun = Myshixun.select("id").where(:id => myshixun_ids.map(&:myshixun_id)).size + complete_rate = all_myshixun == 0 ? 0 : ((complete_myshixun * 100) / all_myshixun).try(:round, 2).to_f + real_name = teacher.show_real_name + teacher = teacher.attributes.dup.merge({ + real_name: real_name, + course_count: course_count, + shixun_work_count: shixun_work_count, + un_shixun_work_count: un_shixun_work_count, + student_count: student_count, + complete_rate: complete_rate + }).to_json + JSON.parse(teacher) + end + end + + def shixun_chart_data + shixun_ids = HomeworkCommonsShixuns.joins(homework_common: :course).where(courses: {school_id: @school.id, is_delete: 0}).where('courses.id != 1309').pluck('distinct shixun_id') + shixun_count_map = ShixunTagRepertoire.joins(:tag_repertoire).where(shixun_id: shixun_ids).group('tag_repertoires.name').order('count_shixun_id desc').count(:shixun_id) + + names = [] + data = [] + shixun_count_map.each do |name, count| + break if names.size == 9 + + names << name + data << { value: count, name: name } end - respond_to do |format| - format.html {render :layout => "base_edu"} + if shixun_count_map.keys.size > 9 + other_count = shixun_count_map.values[9..-1].reduce(:+) + names << 'Others' + data << { name: 'Others', value: other_count } end + + render json: { names: names, data: data } end # 在线课堂 @@ -152,33 +158,24 @@ class CollegesController < ApplicationController # @courses = Course.where("courses.school_id = #{@department.school_id} and courses.is_delete = 0").select("courses.id, courses.tea_id, courses.name, courses.is_end, # (SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS update_time").order("update_time desc") @courses = paginateHelper @courses, 8 - # @courses = @courses.includes(:student, :boards, :exercises, :polls, :attachments, :homework_commons, :teacher => [:user_extensions]) end # 学生实训 def student_shixun - user_ids = User.find_by_sql("SELECT users.id FROM users, user_extensions WHERE users.id=user_extensions.user_id AND user_extensions.`school_id` = #{@school.id}").map(&:id) - @students = User.find_by_sql("SELECT users.id, users.login, users.lastname, users.firstname, users.nickname, users.grade, - users.experience, ue.student_id, (SELECT COUNT(myshixuns.id) FROM `myshixuns` WHERE myshixuns.user_id - = users.id AND myshixuns.status = 1 GROUP BY users.id) AS myshixun_count FROM users join user_extensions ue on - users.id = ue.user_id where ue.school_id = #{@school.id} AND ue.identity = 1 AND `users`.`type` IN ('User', 'AnonymousUser') ORDER BY experience DESC, myshixun_count DESC LIMIT 10") - - ## outputs基数过大,用inner join有奇效 - @shixun_tags = TagRepertoire.find_by_sql(%Q{ - select name, COUNT(outputs.id) AS test_count from outputs inner join ( - SELECT tr.id as trid, tr.`name` as name, games.id as id - FROM tag_repertoires tr, shixun_tag_repertoires str, games, myshixuns - WHERE tr.id = str.tag_repertoire_id - AND str.shixun_id = myshixuns.`shixun_id` - AND myshixuns.id = games.`myshixun_id` - AND myshixuns.`user_id` IN ( - SELECT users.id FROM users, user_extensions WHERE users.id=user_extensions.user_id AND user_extensions.`school_id` = #{@school.id} - ) - ) a on a.id = outputs.game_id and outputs.`test_set_position` = 1 group by trid - ORDER BY test_count DESC - LIMIT 10 - }) + @students = User.joins(:user_extensions).where(user_extensions: { school_id: @school.id, identity: 1 }).includes(:user_extensions).order('experience desc').limit(10) + + student_ids = @students.map(&:id) + @shixun_count = Myshixun.where(user_id: student_ids).group(:user_id).count + @study_shixun_count = Myshixun.where(user_id: student_ids, status: 0).group(:user_id).count + end + + def student_hot_evaluations + games = Game.joins(:myshixun).joins('join shixun_tag_repertoires str on str.shixun_id = myshixuns.shixun_id') + games = games.joins('join tag_repertoires tr on tr.id = str.tag_repertoire_id') + games = games.joins("join user_extensions ue on ue.user_id = myshixuns.user_id and ue.school_id = #{@school.id}") + evaluate_count_map = games.group('tr.name').reorder('sum_games_evaluate_count desc').limit(10).sum('games.evaluate_count') + render json: { names: evaluate_count_map.keys, values: evaluate_count_map.values } end # 工程能力 diff --git a/app/controllers/competition_teams_controller.rb b/app/controllers/competition_teams_controller.rb index b1d6788e..cfae2acf 100644 --- a/app/controllers/competition_teams_controller.rb +++ b/app/controllers/competition_teams_controller.rb @@ -14,6 +14,10 @@ class CompetitionTeamsController < ApplicationController def show return render_404 if @competition.identifier != 'gcc-course-2019' + end + + def shixun_detail + return render_404 if @competition.identifier != 'gcc-course-2019' @team_user_ids = @team.team_members.pluck(:user_id) @@ -40,13 +44,17 @@ class CompetitionTeamsController < ApplicationController @forked_course_count_map[forked_shixun_map[forked_id]] += course_count end @forked_shixun_map = forked_shixun_map + end + def course_detail + return render_404 if @competition.identifier != 'gcc-course-2019' + + @team_user_ids = @team.team_members.pluck(:user_id) - # 课堂 student_count_subquery = CourseMember.where('course_id = courses.id AND role = 4').select('count(*)').to_sql subquery = StudentWork.where('homework_common_id = hcs.id') - .select('sum(compelete_status !=0 ) as finish, count(*) as total') - .having('total != 0 and finish >= (total / 2)').to_sql + .select('sum(compelete_status !=0 ) as finish, count(*) as total') + .having('total != 0 and finish >= (total / 2)').to_sql course_ids = Course.where('courses.created_at > ?', Time.parse('2018-06-01')) .where('courses.created_at <= ?', @competition.end_time) .where("(#{student_count_subquery}) >= 3") @@ -55,7 +63,7 @@ class CompetitionTeamsController < ApplicationController .where(course_members: { user_id: @team_user_ids }).pluck(:id) courses = Course.where(id: course_ids).joins(:shixun_homework_commons).where('homework_commons.publish_time < now()') @courses = courses.select('courses.id, courses.name, courses.members_count, count(*) shixun_homework_count') - .group('courses.id').order('shixun_homework_count desc').having('shixun_homework_count > 0') + .group('courses.id').order('shixun_homework_count desc').having('shixun_homework_count > 0') course_ids = @courses.map(&:id) @course_myshixun_map = Myshixun.joins(student_works: :homework_common) diff --git a/app/controllers/competitions_controller.rb b/app/controllers/competitions_controller.rb index 57ff871c..cd3a9ef6 100644 --- a/app/controllers/competitions_controller.rb +++ b/app/controllers/competitions_controller.rb @@ -327,9 +327,9 @@ class CompetitionsController < ApplicationController elsif @type == "决赛" # '92b7vt8x','a7fxenvc','wt2xfzny','xa4m9cng','tng6heyf','am5o73er','9fla2zry','fzp3iu4w','qlsy6xb4' # 预赛的实训id 第一阶段:1289,1373,1256 第二阶段:1488, 1453, 1487 第三阶段:1470, 1473, 1408 - shixun1_id = Shixun.where(:identifier => ['92b7vt8x','a7fxenvc','wt2xfzny']).pluck(:id) - shixun2_id = Shixun.where(:identifier => ['xa4m9cng','tng6heyf','am5o73er']).pluck(:id) - shixun3_id = Shixun.where(:identifier => ['9fla2zry','fzp3iu4w','qlsy6xb4']).pluck(:id) + shixun1_id = Shixun.where(:identifier => ['ftlc4x38']).pluck(:id) + shixun2_id = Shixun.where(:identifier => ['y9npgih2','ucqt7fw3','2p7ouzwk']).pluck(:id) + shixun3_id = Shixun.where(:identifier => ['fj49r7xv','gf2cvxfh','cmoxhtbs']).pluck(:id) end if @competition.competition_scores.where(:competition_stage_id => @stage.id).count == 0 @@ -385,7 +385,7 @@ class CompetitionsController < ApplicationController f_score = team.competition_scores.where(:competition_stage_id => final_stage.try(:id)).first # 预赛记录 p_score = team.competition_scores.where(:competition_stage_id => pre_stage.try(:id)).first - team[:s_score] = (f_score.try(:score).to_f * 0.85 + p_score.try(:score).to_f * 0.15).try(:round, 2) + team[:s_score] = (f_score.try(:score).to_f * 0.80 + p_score.try(:score).to_f * 0.20).try(:round, 2) team[:s_spend_time] = f_score.try(:cost_time).to_i + p_score.try(:cost_time).to_i end end diff --git a/app/controllers/ec_graduation_requirements_controller.rb b/app/controllers/ec_graduation_requirements_controller.rb index 091588cd..79c678de 100644 --- a/app/controllers/ec_graduation_requirements_controller.rb +++ b/app/controllers/ec_graduation_requirements_controller.rb @@ -50,9 +50,14 @@ class EcGraduationRequirementsController < ApplicationController @year = requirement.ec_year @template_major = admin_or_business? || @year.ec_major_school.school.ec_school_users.pluck(:user_id).include?(User.current.id) requirement.update_attribute(:content, params[:requirement]) - requirement.ec_graduation_subitems.destroy_all + # requirement.ec_graduation_subitems.destroy_all params[:subitems].try(:each_with_index) do |sub, index| - EcGraduationSubitem.create(:content => sub, :position => index+1, :ec_graduation_requirement_id => requirement.id) + subitem = requirement.ec_graduation_subitems.where(position: index+1).first + if subitem.present? + subitem.update_attributes(:content => sub) + else + EcGraduationSubitem.create(:content => sub, :position => index+1, :ec_graduation_requirement_id => requirement.id) + end end @ec_graduation_requirements = requirement.ec_year.ec_graduation_requirements diff --git a/app/controllers/ec_graduation_subitems_controller.rb b/app/controllers/ec_graduation_subitems_controller.rb index b281e3f3..1248f450 100644 --- a/app/controllers/ec_graduation_subitems_controller.rb +++ b/app/controllers/ec_graduation_subitems_controller.rb @@ -82,9 +82,13 @@ class EcGraduationSubitemsController < ApplicationController # DELETE /ec_graduation_subitems/1.json def destroy @ec_graduation_subitem = EcGraduationSubitem.find(params[:id]) + @ec_graduation_requirement = @ec_graduation_subitem.ec_graduation_requirement + @ec_graduation_requirement.ec_graduation_subitems.where("position > #{@ec_graduation_subitem.position}").update_all("position = position - 1") + @ec_graduation_requirements = @ec_graduation_requirement.ec_year.ec_graduation_requirements @ec_graduation_subitem.destroy respond_to do |format| + format.js format.html { redirect_to ec_graduation_subitems_url } format.json { head :no_content } end diff --git a/app/controllers/ecloud_controller.rb b/app/controllers/ecloud_controller.rb index ac303ce3..3e02c579 100644 --- a/app/controllers/ecloud_controller.rb +++ b/app/controllers/ecloud_controller.rb @@ -18,7 +18,7 @@ class EcloudController < ApplicationController skip_before_filter :verify_authenticity_token before_filter :save_para - # before_filter :check_sign, only: [:ps_new, :ps_update, :bs_new, :bs_update] + before_filter :check_sign, only: [:ps_new, :ps_update, :bs_new, :bs_update] before_filter :user_setup # before_filter :require_login, only: [:authorize] diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index cc896ef2..b766ad07 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -29,7 +29,7 @@ class ManagementsController < ApplicationController end def user_agents - @user_agents = UserAgent.where("user_agents.key is not null") + @user_agents = UserAgent.where("user_agents.key is not order by action_status, register_status") @agents_count = @user_agents.count limit = 20 @agents_pages = Paginator.new @agents_count, limit, params['page'] || 1 @@ -179,6 +179,8 @@ class ManagementsController < ApplicationController if params[:search] if params[:search].to_i.to_s == params[:search].to_s myshixun_id = Game.where(:myshixun_id => params[:search].to_i).pluck(:myshixun_id) + game_myshixun_id = Game.where(:id => params[:search].to_i).pluck(:myshixun_id) + myshixun_id = myshixun_id + game_myshixun_id else myshixun_id = Game.where(:identifier => params[:search]).pluck(:myshixun_id) end @@ -221,7 +223,9 @@ class ManagementsController < ApplicationController @user.admin = params[:admin].to_i end @user.firstname = "" - @user.mail = params[:mail].strip == "" ? nil : params[:mail] + if params[:mail].present? + @user.mail = params[:mail].strip + end @user.phone = params[:phone].strip == "" ? nil : params[:phone] #@user.password = params[:new_password] # if params[:new_password].strip != "" && params[:new_password_confirmation].strip != "" @@ -1742,22 +1746,26 @@ end # 删除 def delete_applied_departments - applied_department = ApplyAddDepartment.find params[:depart_id] - applied_message = AppliedMessage.where(:applied_id => applied_department.id, :applied_type => "ApplyAddDepartment") - applied_message.update_all(:status => 3) - applied_department.update_attribute(:status, 3) - # 未审批删除 - if params[:tip] == "unapplied" - # AppliedMessage.create(:user_id => applied_department.user_id, :status => 3, :viewed => 0, :applied_id => applied_department.id, :applied_type => "ApplyAddDepartment", :name => applied_department.name ) - Tiding.where(:user_id => 1, :trigger_user_id => applied_department.user_id, :container_id => applied_department.id, :container_type => 'ApplyAddDepartment', :status => 0, :tiding_type => "Apply").update_all(:status => 1) - Tiding.create(:user_id => applied_department.user_id, :trigger_user_id => 0, :container_id => applied_department.id, :container_type =>'ApplyAddDepartment', :belong_container_id => applied_department.department.school_id, :belong_container_type=> 'School', :tiding_type => "System", :status => 2, :extra => params[:reason]) - # 删除学校的用户 - users = UserExtensions.where("department_id = #{applied_department.department_id}") - users.update_all(department_id: nil, profile_completed: false) - applied_department.department.destroy - # 已审批删除 - elsif params[:tip] == "applied" - applied_department.destroy + ActiveRecord::Base.transaction do + applied_department = ApplyAddDepartment.find params[:depart_id] + applied_message = AppliedMessage.where(:applied_id => applied_department.id, :applied_type => "ApplyAddDepartment") + applied_message.update_all(:status => 3) + applied_department.update_attribute(:status, 3) + # 未审批删除 + if params[:tip] == "unapplied" + # AppliedMessage.create(:user_id => applied_department.user_id, :status => 3, :viewed => 0, :applied_id => applied_department.id, :applied_type => "ApplyAddDepartment", :name => applied_department.name ) + Tiding.where(:user_id => 1, :trigger_user_id => applied_department.user_id, :container_id => applied_department.id, :container_type => 'ApplyAddDepartment', :status => 0, :tiding_type => "Apply").update_all(:status => 1) + Tiding.create(:user_id => applied_department.user_id, :trigger_user_id => 0, :container_id => applied_department.id, :container_type =>'ApplyAddDepartment', :belong_container_id => applied_department.department.school_id, :belong_container_type=> 'School', :tiding_type => "System", :status => 2, :extra => params[:reason]) + # 删除学校的用户 + user_exs = UserExtensions.where("department_id = #{applied_department.department_id}") + users = User.where(id: user_exs.pluck(:user_id)) + user_exs.update_all(department_id: nil) + users.update_all(profile_completed: false) + applied_department.department.destroy + # 已审批删除 + elsif params[:tip] == "applied" + applied_department.destroy + end end respond_to do |format| format.html{ redirect_to depart_managements_path } @@ -2080,7 +2088,7 @@ end @school_id = params[:school_id] if params[:school_id] && params[:school_id] != '' - @courses = @courses.joins("join user_extensions ue on courses.tea_id = ue.user_id").where("ue.school_id = #{params[:school_id]}") + @courses = @courses.where(school_id: params[:school_id]) end if params[:homepage_show] @@ -2963,7 +2971,7 @@ end member = course.course_members.where(:user_id => user.id, :role => member_role).first # 如果已是课堂成员且是学生身份and不在指定的分班则移动到该分班 if member.present? && member.role == 4 && member.course_group_id != course_group.try(:id).to_i - member.update_column("course_group_id", course_group.try(:id).to_i) + member.update_attributes(course_group_id: course_group.try(:id).to_i) member_count += 1 elsif !member.present? member = CourseMember.new(:role => member_role, :user_id => user.id) @@ -2984,9 +2992,9 @@ end @status = 1 @message = "已导入/更新#{member_count}个成员" end - rescue + rescue Exception => e @status = 0 - @message = "文件内容无法读取" + @message = e.message end else @status = 0 @@ -3028,18 +3036,12 @@ end # 用户不存在则创建账号 if !user.present? && school.present? department = school.departments.where(:name => list[2]).first - user = User.new - user.admin = false - user.activate - user.login = prefix + list[0].to_s.strip - user.lastname = list[1].to_s.strip - user.nickname = list[1].to_s.strip - user.professional_certification = 1 - user.certification = 1 - user.grade = 0 - user.password = "12345678" - user.phone = list[5].blank? ? nil : list[5] - if user.save + user_params = {status: 1, login: prefix + list[0].to_s.strip, lastname: list[1].to_s.strip, + nickname: list[1].to_s.strip, professional_certification: 1, certification: 1, grade: 0, + password: "12345678", phone: list[5].blank? ? nil : list[5], mail: "#{prefix+list[0].to_s.strip}@qq.com", profile_completed: 1} + user = User.create(user_params) + user = User.find(prefix + list[0].to_s.strip) + if user ue = UserExtensions.new(:user_id => user.id, :gender => 0, :school_id => school_id, :location => school.province, :location_city => school.city, :identity => list[3].to_i, :student_id => list[0].to_s.strip, :department_id => department.try(:id)) if list[3] && list[3].to_i == 0 ue.technical_title = ["教授", "副教授", "讲师", "助教"].include?(list[4]) ? list[4] : "讲师" @@ -4202,7 +4204,7 @@ end sheet1[count_row, 5] = show_shixun_mirror(shixun) sheet1[count_row, 6] = shixun.fork_identifier sheet1[count_row, 7] = shixun.challenges.count - sheet1[count_row, 8] = Setting.server_url + shixun_path(shixun) + sheet1[count_row, 8] = Setting.server_url + shixun_path(shixun).sub("/", "") count_row += 1 end book.write xls_report diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 251e6de7..bd850ac6 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -42,7 +42,9 @@ class WelcomeController < ApplicationController # 运营引流个人数据展示 def user_agents - @user_agents = UserAgent.where(key: params[:edu]) + @user_agents = UserAgent.where(key: params[:edu]).order("register_status desc, action_status desc") + @action_count = @user_agents.where(action_status: 2).count + @register_count = @user_agents.where(register_status: 2).count @agents_count = @user_agents.count limit = 20 @agents_pages = Paginator.new @agents_count, limit, params['page'] || 1 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c497cb4e..3a2b0560 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3036,11 +3036,11 @@ module ApplicationHelper elsif @contest title << (@contest.name.nil? ? "创新源于实践" : @contest.name) elsif @shixun - title << (@shixun.name.nil? ? "开发社区" : @shixun.name) + title << (@shixun.name.nil? ? "实训项目" : @shixun.name) elsif @my_shixun - title << ("我的实训") + title << ("我的实训项目") elsif params[:controller] == "shixuns" && params[:action] == "index" - title << ("开发社区") + title << ("实训项目") elsif @subject title << (@subject.name.nil? ? "实践课程" : @subject.name) elsif params[:controller] == "subjects" && params[:action] == "index" diff --git a/app/models/competition_team.rb b/app/models/competition_team.rb index e2551710..a8f48b3e 100644 --- a/app/models/competition_team.rb +++ b/app/models/competition_team.rb @@ -11,7 +11,8 @@ class CompetitionTeam < ActiveRecord::Base # attr_accessible :invite_code, :name, :team_type def teacher - User.where(:id => self.teacher_id).first + teacher_id = self.teachers.first&.user_id + User.where(id: teacher_id).first end def group_members diff --git a/app/models/course_group.rb b/app/models/course_group.rb index c5b66d87..2986e6ac 100644 --- a/app/models/course_group.rb +++ b/app/models/course_group.rb @@ -1,6 +1,6 @@ class CourseGroup < ActiveRecord::Base # attr_accessible :title, :body - belongs_to :course + belongs_to :course, :counter_cache => true has_many :course_members has_many :members has_many :memberships, :class_name => 'Member' diff --git a/app/models/course_member.rb b/app/models/course_member.rb index d67994ef..788f87aa 100644 --- a/app/models/course_member.rb +++ b/app/models/course_member.rb @@ -15,6 +15,7 @@ class CourseMember < ActiveRecord::Base homeworks = course.homework_commons.includes(:homework_detail_manual).where("homework_type in (1, 3, 4)") if homeworks.count != 0 homeworks.each do |hw| + next if hw.student_works.where(user_id: user_id).any? str += "," if str != "" str += "('#{hw.name}的作品提交',#{hw.id},#{user_id}, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end @@ -34,6 +35,7 @@ class CourseMember < ActiveRecord::Base exercises = course.exercises if exercises.count != 0 exercises.each do |ex| + next if ex.exercise_users.where(user_id: user_id).any? str += "," if str != "" str += "(#{ex.id},#{user_id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end @@ -53,6 +55,7 @@ class CourseMember < ActiveRecord::Base polls = course.polls if polls.count != 0 polls.each do |poll| + next if poll.poll_users.where(user_id: user_id).any? str += "," if str != "" str += "(#{poll.id},#{user_id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end @@ -72,6 +75,7 @@ class CourseMember < ActiveRecord::Base tasks = course.graduation_tasks if tasks.count != 0 tasks.each do |task| + next if task.graduation_works.where(user_id: user_id).any? str += "," if str != "" str += "(#{task.id}, #{user_id}, #{course.id}, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end diff --git a/app/models/message.rb b/app/models/message.rb index 9e516acb..91fdefac 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -119,6 +119,10 @@ class Message < ActiveRecord::Base message_detail.try(:content) end + def content + message_detail.try(:content) + end + # def content # self.try(:content) # end diff --git a/app/models/tag_repertoire.rb b/app/models/tag_repertoire.rb index c33faa5c..7b7891e7 100644 --- a/app/models/tag_repertoire.rb +++ b/app/models/tag_repertoire.rb @@ -1,8 +1,8 @@ class TagRepertoire < ActiveRecord::Base # attr_accessible :title, :body belongs_to :sub_repertoire - has_many :shixuns, :through => :shixun_tag_repertoires has_many :shixun_tag_repertoires, :dependent => :destroy + has_many :shixuns, :through => :shixun_tag_repertoires has_many :memos, :through => :memo_tag_repertoires has_many :memo_tag_repertoires, :dependent => :destroy diff --git a/app/models/user.rb b/app/models/user.rb index dbb77124..58f293d6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -300,7 +300,7 @@ class User < Principal attr_accessor :password, :password_confirmation attr_accessor :last_before_login_on # Prevents unauthorized assignments - attr_protected :login, :admin, :password, :password_confirmation, :hashed_password + # attr_protected :login, :admin, :password, :password_confirmation, :hashed_password LOGIN_LENGTH_LIMIT = 30 MAIL_LENGTH_LIMIT = 60 @@ -308,15 +308,15 @@ class User < Principal #validates_presence_of :login, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } validates_presence_of :login, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, :case_sensitive => false - validates_uniqueness_of :mail, :if => Proc.new { |user| user.mail_changed? && user.mail.present? }, :case_sensitive => false + #validates_uniqueness_of :mail, :if => Proc.new { |user| user.mail_changed? && user.mail.present? }, :case_sensitive => false validates_uniqueness_of :phone, :if => Proc.new { |user| user.phone_changed? && user.phone.present? }, :case_sensitive => false # Login must contain letters, numbers, underscores only #validates_format_of :login, :with => /\A[a-z0-9_\-]*\z/i validates_length_of :login, :maximum => LOGIN_LENGTH_LIMIT validates_length_of :firstname, :maximum => 30 validates_length_of :lastname, :maximum => 30 - validates_format_of :mail, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, :allow_blank => true - validates_length_of :mail, :maximum => MAIL_LENGTH_LIMIT, :allow_nil => true + #validates_format_of :mail, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, :allow_blank => true + #validates_length_of :mail, :maximum => MAIL_LENGTH_LIMIT, :allow_nil => true validates_confirmation_of :password, :allow_nil => true # validates_inclusion_of :mail_notification, :in => MAIL_NOTIFICATION_OPTIONS.collect(&:first), :allow_blank => true validate :validate_password_length @@ -673,9 +673,9 @@ class User < Principal base_reload(*args) end - def mail=(arg) - write_attribute(:mail, arg.to_s.strip) - end + # def mail=(arg) + # write_attribute(:mail, arg.to_s.strip) + # end def identity_url=(url) if url.blank? diff --git a/app/views/colleges/_student_shixun.html.erb b/app/views/colleges/_student_shixun.html.erb index f0999075..5fd310d1 100644 --- a/app/views/colleges/_student_shixun.html.erb +++ b/app/views/colleges/_student_shixun.html.erb @@ -21,8 +21,8 @@ <%= student.show_real_name %>
' + '' + ''+liNum+''+ - ''+ + ''+ ''+ ''+ '
'+ '* '+liNum+'-1'+ - ''+ + ''+ '
'+ '* '+liNum+'-2'+ - ''+ + ''+ '
'+ '* '+liNum+'-3'+ - ''+ + ''+ '
'+ '内容不能为空'+ '保存'+ @@ -121,6 +127,11 @@ ''; $(".ListTableLine").append(html); $("#requirementNew").find("input[name='requirement']").focus(); + var subInputs=document.getElementsByName("subitems[]"); + for (var i = 0; i < subInputs.length; i++) { + autoTextarea(subInputs[i], 0, 140); + } + autoTextarea(document.getElementsByName("requirement")[0], 0, 140); flagAdd=false; } @@ -128,8 +139,8 @@ //取消添加 function removePanel(value){ if(value!=undefined){ - $("#"+value).html($("#editFormContent").html()); - $("#editFormContent").remove(); + $("#"+value).show(); + // $("#editFormContent").remove(); } $("#form_data_for_requirements").remove(); flagAdd=true; @@ -141,9 +152,9 @@ console.log("#########type:"+ type) console.log("#########url:"+ url) - var requirement = $("input[name='requirement']").val(); + var requirement = $("textarea[name='requirement']").val(); if(requirement.trim() == ""){ - $("input[name='requirement']").addClass("bor-red"); + $("textarea[name='requirement']").addClass("bor-red"); $("#option_Item_notice").removeClass("none").html("内容不能为空"); return; } @@ -170,7 +181,7 @@ } }) console.log(in_vain); - $("input[name='requirement']").removeClass("bor-red"); + $("textarea[name='requirement']").removeClass("bor-red"); $("input[name='subitems[]']").removeClass("bor-red"); $("#option_Item_notice").addClass("none"); } diff --git a/app/views/ecs/_ec_top_navigation.html.erb b/app/views/ecs/_ec_top_navigation.html.erb index 40f3b50e..c9e0a0ed 100644 --- a/app/views/ecs/_ec_top_navigation.html.erb +++ b/app/views/ecs/_ec_top_navigation.html.erb @@ -58,7 +58,7 @@ " href="<%= requirement_vs_courses_ec_major_school_ec_year_path(@year, :ec_major_school_id => @year.ec_major_school_id) %>">课程体系 vs 毕业要求
data-shixun="<%= shixun.id %>" type="checkbox" class="select<%= count %> magic-checkbox" id="<%= count %>_<%= tag.name %>_<%= tag.id %>" value="<%= tag.name %>"/> - +
<% end %> diff --git a/app/views/managements/_user_agent_list.html.erb b/app/views/managements/_user_agent_list.html.erb index 43886c8d..6b47e51c 100644 --- a/app/views/managements/_user_agent_list.html.erb +++ b/app/views/managements/_user_agent_list.html.erb @@ -4,9 +4,9 @@新建项目
+新建开发项目
<%= l(:label_projects_new_name) %>
<%= @user.show_real_name %> > - 精选实训 > 我的实训
+ 精选实训 > 我的实训项目暂无数据哦~
ID | +序号 | 代理人登录名 | 代理人姓名 | 注册情况 | diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index f7a6dbc4..29370db3 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -69,7 +69,7 @@
---|