diff --git a/app/controllers/colleges_controller.rb b/app/controllers/colleges_controller.rb index 5f1f094c..93d2df8e 100644 --- a/app/controllers/colleges_controller.rb +++ b/app/controllers/colleges_controller.rb @@ -85,7 +85,7 @@ class CollegesController < ApplicationController 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 + student_count = CourseMember.where(:course_id => course_ids.map(&:id), :role => 4).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 @@ -128,7 +128,7 @@ class CollegesController < ApplicationController # 在线课堂 def course_statistics @courses = Course.find_by_sql("SELECT c.id, (select concat(lastname,firstname) from users u where u.id=c.tea_id) as username, - (select count(sfc.id) from students_for_courses sfc where c.id=sfc.course_id group by c.id) as student_count, + (select count(cm.id) from course_members cm where c.id=cm.course_id and cm.role=4 group by c.id) as student_count, (select count(hc.id) from homework_commons hc where c.id=hc.course_id and hc.homework_type=4 group by c.id) as hcm_count, (select count(hc.id) from homework_commons hc where c.id=hc.course_id and hc.homework_type in (1,3) group by c.id) as hcm_nonshixun_count, (select count(e.id) from exercises e where c.id=e.course_id group by c.id) as exercises_count, @@ -258,7 +258,7 @@ class CollegesController < ApplicationController unless (User.current.admin? || User.current.business? || (@department.present? && DepartmentMember.where(:user_id => User.current.id, :department_id => @department.id).first.present?) || (User.current.user_extensions.try(:school_id) == @school.id && User.current.user_extensions.try(:identity) == 0) || - (@school.try(:customer_id) && User.current.try(:partner).try(:customer_ids) && User.current.try(:partner).try(:customer_ids).include?(@school.try(:customer_id)))) + (@school.try(:customer_id) && User.current.try(:partner).try(:customer_ids) && User.current.try(:partner).try(:customer_ids).include?(@school.try(:customer_id)))) render_403 end end diff --git a/app/controllers/competition_teams_controller.rb b/app/controllers/competition_teams_controller.rb index cfae2acf..c3a44fd8 100644 --- a/app/controllers/competition_teams_controller.rb +++ b/app/controllers/competition_teams_controller.rb @@ -18,9 +18,18 @@ class CompetitionTeamsController < ApplicationController def shixun_detail return render_404 if @competition.identifier != 'gcc-course-2019' + @competition_completed = false + # 竞赛正在进行,分数动态计算 @team_user_ids = @team.team_members.pluck(:user_id) + # 竞赛结束并且分数已经统计 + if @competition.end_time < Time.current && CompetitionCourseRecord.exists?(competition_id: @competition.id) + @competition_completed = true + @records = CompetitionCourseRecord.where(type: 'CompetitionCourseShixunRecord', competition_team_id: @team.id) + return + end + shixuns = Shixun.where(user_id: @team_user_ids, status: 2) .where('shixuns.created_at > ? && shixuns.created_at <= ?', Time.parse('2018-06-01'), @competition.end_time) shixuns = shixuns.joins('left join shixuns forked_shixuns on forked_shixuns.fork_from = shixuns.id and forked_shixuns.status = 2') @@ -48,9 +57,17 @@ class CompetitionTeamsController < ApplicationController def course_detail return render_404 if @competition.identifier != 'gcc-course-2019' + @competition_completed = false @team_user_ids = @team.team_members.pluck(:user_id) + # 竞赛结束并且分数已经统计 + if @competition.end_time < Time.current && CompetitionCourseRecord.exists?(competition_id: @competition.id) + @competition_completed = true + @records = CompetitionCourseRecord.where(type: 'CompetitionCourseCourseRecord', competition_team_id: @team.id) + return + end + 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') diff --git a/app/controllers/competitions_controller.rb b/app/controllers/competitions_controller.rb index 3b438e06..6cb547c7 100644 --- a/app/controllers/competitions_controller.rb +++ b/app/controllers/competitions_controller.rb @@ -188,7 +188,7 @@ class CompetitionsController < ApplicationController end end end - if @competition.identifier == "gcc-annotation-2018" + if @competition.identifier == "gcc-annotation-2018" || @competition.identifier == "gcc-course-2019" @rule_content = @competition.chart_rules.first else @rule_content = @competition.chart_rules.where(:competition_stage_id => @stage.try(:id)).first @@ -305,7 +305,7 @@ class CompetitionsController < ApplicationController end records_length = 97 @records = @records[0..records_length] - elsif @competition.identifier == "gcc-annotation-2018" + elsif @competition.identifier == "gcc-annotation-2018" || @competition.identifier == "gcc-course-2019" @records = @competition.competition_teams.includes(:user => [:user_extensions => [:school]]) @records.each do |team| team[:s_score] = team.competition_scores.where(:competition_id => @competition.id).first.try(:score).to_f.try(:round, 3) @@ -494,7 +494,7 @@ class CompetitionsController < ApplicationController sheet1[count_row,10] = com_spend_time team[:s_spend_time].to_i count_row += 1 end - elsif @competition.identifier == "gcc-annotation-2018" + elsif @competition.identifier == "gcc-annotation-2018" || @competition.identifier == "gcc-course-2019" records = @competition.competition_teams records.each do |team| team[:s_score] = team.competition_scores.where(:competition_id => @competition.id).first.try(:score).to_f.try(:round, 3) @@ -749,7 +749,7 @@ class CompetitionsController < ApplicationController # rate 关卡经验值与分数的比值 # challenge_count 每个实训的关卡数 # 对三个实训的所有关卡循环: 找到在比赛时间内通关的最低耗时 - def chart_exp_score_pre user_ids, s_time, e_time, challenges, rate, challenge_count + def chart_exp_score_pre user_ids, s_time, e_time, challenges, s_rate, challenge_count total_score = 0 total_time = 0 length = challenge_count #每个实训的关卡数 @@ -758,7 +758,7 @@ class CompetitionsController < ApplicationController time = 0 challenges.where(:position => i).each do |challenge| Game.where(:challenge_id => challenge.id, :user_id => user_ids, :status => 2).select{|game| game.open_time >= s_time && game.end_time <= e_time }.each do |game| - game_score = challenge.score * rate + game_score = challenge.score * s_rate cost_time = (game.end_time.to_i - s_time.to_i) > 0 ? (game.end_time.to_i - s_time.to_i) : 0 if score < game_score score = game_score diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index df14dd53..92173fc3 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -29,12 +29,21 @@ class ManagementsController < ApplicationController end def user_agents - @user_agents = UserAgent.where("user_agents.key is not order by action_status, register_status") + @user_agents = UserAgent.where("user_agents.key is not null").order("action_status asc, register_status asc") @agents_count = @user_agents.count limit = 20 @agents_pages = Paginator.new @agents_count, limit, params['page'] || 1 @offset ||= @agents_pages.offset @user_agents = paginateHelper @user_agents, limit + respond_to do |format| + format.html + format.xls{ + time = Time.now.strftime("%Y%m%d") + filename = "引流情况#{time}.xls" + send_data(user_agents_export(), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename)) + } + end + end # 实训课程等级体系 @@ -387,7 +396,7 @@ class ManagementsController < ApplicationController # 搜索镜像 def mirror_search @scope = [] - if params[:q] && params[:q].lstrip.rstrip != "" + if params[:q] && params[:q].strip != "" @scope = MirrorRepository.where("name like ?", "%#{params[:q]}%").map(&:name) end respond_to do |format| @@ -2210,6 +2219,16 @@ end end end + + # 讨论区邮件通知 + def course_board_email_notify + if params[:course_id] + course = Course.find params[:course_id] + course.update_attributes(:email_notify => !course.email_notify) + end + end + + # 课程实训 def class_shixuns @menu_type = 4 @@ -4359,6 +4378,39 @@ end return sheet.rows end + def user_agents_export + 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(["序号", "LoginId", "姓名", "学校名称", "手机号", "邮箱", "参赛人数", "参赛队伍", "访问量"]) + user_agents = UserAgent.where("user_agents.key is not null").pluck(:key).uniq + user_agents.each_with_index do |agent, index| + user = User.find_by_login(agent) + next if user.blank? + # 代理用户 + agents = UserAgent.where(key: agent) + agents_count = agents.count + competion_users = agents.where(action_status: 2).pluck(:ip) + rank_user_id = UserActions.where(ip: competion_users).pluck(:user_id).uniq + team_ids = TeamMember.where(user_id: rank_user_id).pluck(:competition_team_id).uniq + sheet1[count_row, 0] = index + 1 + sheet1[count_row, 1] = agent + sheet1[count_row, 2] = user.show_real_name + sheet1[count_row, 3] = user.school_name + sheet1[count_row, 4] = user.phone + sheet1[count_row, 5] = user.mail + sheet1[count_row, 6] = competion_users.count + sheet1[count_row, 7] = team_ids.count + sheet1[count_row, 8] = agents_count + count_row += 1 + end + book.write xls_report + xls_report.string + end + def export_subject_level_system xls_report = StringIO.new book = Spreadsheet::Workbook.new diff --git a/app/models/competition_course_course_record.rb b/app/models/competition_course_course_record.rb new file mode 100644 index 00000000..f51f2fea --- /dev/null +++ b/app/models/competition_course_course_record.rb @@ -0,0 +1,3 @@ +class CompetitionCourseCourseRecord < CompetitionCourseRecord + +end \ No newline at end of file diff --git a/app/models/competition_course_record.rb b/app/models/competition_course_record.rb new file mode 100644 index 00000000..43d05a09 --- /dev/null +++ b/app/models/competition_course_record.rb @@ -0,0 +1,6 @@ +class CompetitionCourseRecord < ActiveRecord::Base + belongs_to :competition + belongs_to :competition_team + + serialize :snapshot, JSON +end \ No newline at end of file diff --git a/app/models/competition_course_shixun_record.rb b/app/models/competition_course_shixun_record.rb new file mode 100644 index 00000000..c447cbd5 --- /dev/null +++ b/app/models/competition_course_shixun_record.rb @@ -0,0 +1,2 @@ +class CompetitionCourseShixunRecord < CompetitionCourseRecord +end \ No newline at end of file diff --git a/app/models/competition_team.rb b/app/models/competition_team.rb index a8f48b3e..a7d89546 100644 --- a/app/models/competition_team.rb +++ b/app/models/competition_team.rb @@ -5,7 +5,7 @@ class CompetitionTeam < ActiveRecord::Base has_many :team_members, :dependent => :destroy has_many :members, conditions: 'team_members.is_teacher = 0', class_name: 'TeamMember' - has_many :teachers, conditions: 'team_members.is_teacher = 1', class_name: 'TeamMember' + has_many :teachers, conditions: 'team_members.is_teacher = 1', class_name: 'TeamMember', :order => "team_members.role ASC" has_many :competition_scores, :dependent => :destroy # team_type 0:组队 1:个人 # attr_accessible :invite_code, :name, :team_type diff --git a/app/models/course.rb b/app/models/course.rb index 796ea3c9..ac073a44 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -26,7 +26,7 @@ class Course < ActiveRecord::Base attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public, :description,:class_period, :open_student, :enterprise_name, :is_delete, :syllabus_id, :end_time, :end_term, - :choose_group_allow, :is_end, :homepage_show, :course_list_id, :teacher_list, :student_list, :is_hidden + :choose_group_allow, :is_end, :homepage_show, :course_list_id, :teacher_list, :student_list, :is_hidden, :email_notify #belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表 belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表 @@ -139,7 +139,8 @@ class Course < ActiveRecord::Base 'choose_group_allow', 'credit', 'homepage_show', - 'show_unit' + 'show_unit', + 'email_notify' acts_as_customizable diff --git a/app/models/journal.rb b/app/models/journal.rb index 41d81de1..3f6e2563 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -72,10 +72,10 @@ class Journal < ActiveRecord::Base where("(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes, *args)}))", false) } - def save(*args) - # Do not save an empty journal - (details.empty? && notes.blank?) ? false : super - end + # def save(*args) + # # Do not save an empty journal + # (details.empty? && notes.blank?) ? false : super + # end # Returns the new status if the journal contains a status change, otherwise nil def new_status diff --git a/app/models/training.rb b/app/models/training.rb index d7e99620..c94dee50 100644 --- a/app/models/training.rb +++ b/app/models/training.rb @@ -3,7 +3,7 @@ class Training < ActiveRecord::Base attr_accessible :address, :email, :name, :phone, :position, :school, :sex, :openid, :training_type, :major, :student_id, :job_title, :uncertified_major - # training_type 1 2018-培训会 2 警察学院大数据培训会 3 大数据和人工智能 4 工程教育认证 5 EduCoder-创先源于实践 + # training_type 1 2018-培训会 2 警察学院大数据培训会 3 大数据和人工智能 4 工程教育认证 5 EduCoder-创新源于实践 has_one :training_payinfo diff --git a/app/views/colleges/_student_shixun.html.erb b/app/views/colleges/_student_shixun.html.erb index 44214bc6..bdda486b 100644 --- a/app/views/colleges/_student_shixun.html.erb +++ b/app/views/colleges/_student_shixun.html.erb @@ -28,7 +28,7 @@ \ No newline at end of file diff --git a/app/views/layouts/base_management.html.erb b/app/views/layouts/base_management.html.erb index fc5e0afe..11bc2527 100644 --- a/app/views/layouts/base_management.html.erb +++ b/app/views/layouts/base_management.html.erb @@ -114,8 +114,8 @@