From 59ff646a4ff4f240835ff6beead4278fe0f8cc87 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 13 Apr 2019 11:25:28 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/welcome_controller.rb | 11 +++++++++++ config/routes.rb | 1 + 2 files changed, 12 insertions(+) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index c6fa78d9..06602a5c 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -30,6 +30,17 @@ class WelcomeController < ApplicationController require 'simple_xlsx_reader' DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z) + def local_init + LocalShixun.delete_all + LocalMirrorRepository.delete_all + LocalShixunTagRepertoire.delete_all + LocalChallenge.delete_all + LocalTestSet.delete_all + LocalChallengeTag.delete_all + render :json => {status: 0, message: "success"} + end + + def shixun_to_local identifiers = params[:identifiers].split(",") shixuns = Shixun.where(identifier: identifiers) diff --git a/config/routes.rb b/config/routes.rb index ea70b6a2..47a052db 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -283,6 +283,7 @@ RedmineApp::Application.routes.draw do ## oauth相关 get 'welcome/ccf' => 'welcome#ccf' get 'welcome/shixun_to_local' => 'welcome#shixun_to_local' get 'welcome/local_to_shixun' => 'welcome#local_to_shixun' + get 'welcome/local_init' => 'welcome#local_init' # get 'competitions/home' => 'competitions#home' # get 'competitions/hn' => 'competitions#index' From 98c5bcca6e3b200e7901faa9c8cfe30000492753 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 13 Apr 2019 18:26:07 +0800 Subject: [PATCH 02/12] local to shixun --- app/controllers/welcome_controller.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 06602a5c..00bab5b6 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -73,7 +73,7 @@ class WelcomeController < ApplicationController if shixun.challenges.present? shixun.challenges.each do |challenge| new_challenge = LocalChallenge.new - new_challenge.attributes = challenge.attributes.dup.except("id","shixun_id","user_id") + new_challenge.attributes = challenge.attributes.dup.except("id","shixun_id","user_id", "test_set_score") new_challenge.local_shixun_id = local_shixun.id new_challenge.save! # 评测题,选择题暂时不考虑 @@ -109,6 +109,7 @@ class WelcomeController < ApplicationController def local_to_shixun ActiveRecord::Base.transaction do + shixun_list = [] LocalShixun.find_each do |local_shixun| identifier = generate_identifier shixun = Shixun.create!(name: local_shixun.name, description: local_shixun.description, user_id: User.current.id, @@ -177,8 +178,9 @@ class WelcomeController < ApplicationController end end end - render :json => {status: 0, message: "success", identifier: shixun.identifier} + shixun_list << shixun.identifier end + render :json => {status: 0, message: "success", identifier: shixun_list} end end From a3e3fa096566e648e729a68b21b94c61b9200d79 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 13 Apr 2019 18:30:00 +0800 Subject: [PATCH 03/12] .. --- app/controllers/welcome_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 00bab5b6..c9d41c0a 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -153,7 +153,7 @@ class WelcomeController < ApplicationController if local_challenges.present? local_challenges.each do |local_challenge| new_challenge = Challenge.new - new_challenge.attributes = local_challenge.attributes.dup.except("id","local_shixun_id","user_id") + new_challenge.attributes = local_challenge.attributes.dup.except("id","local_shixun_id","user_id", "test_set_score") new_challenge.user_id = User.current.id new_challenge.shixun_id = shixun.id new_challenge.save! From 83f0ec016b4134c2ba60189b8f8168130963adf3 Mon Sep 17 00:00:00 2001 From: huang Date: Mon, 15 Apr 2019 10:01:27 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/users.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/users.rake b/lib/tasks/users.rake index d8ae770e..bfa0678c 100644 --- a/lib/tasks/users.rake +++ b/lib/tasks/users.rake @@ -89,7 +89,7 @@ task :add_test_users => :environment do (1..1000).each do |i| no = sprintf("%04d", i) - phone = "1560731#{no}" + phone = "5160731#{no}" us = UsersService.new user = us.register phone: phone, password: 'edu12345678' @@ -109,7 +109,7 @@ task :add_test_users => :environment do lastname: lastname, nickname: '', sex: 0, - mail: "educoder#{no}@qq.com", + mail: "00educoder#{no}@qq.com", identity: 1, te_technical_title: 0, pro_technical_title: 0, From 52af31be38f369835361ae057112f5f4b632f432 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 22 Apr 2019 09:59:50 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E8=B6=85=E7=BA=A7=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E7=9A=84=E5=AF=BC=E5=87=BA=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/managements_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index b7e1bd56..11796cb0 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -3345,7 +3345,7 @@ end end @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(1000) #导出excel用户 + @xls_users = @users.reorder("created_on desc").limit(3000) #导出excel用户 @page = (params['page'] || 1).to_i @users_count = @users.count @limit = 20 @@ -4176,7 +4176,7 @@ end sheet1 = book.create_worksheet :name => "course" blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 sheet1.row(0).default_format = blue - sheet1.row(0).concat(["ID","课堂名称","成员","资源","普通作业"," 实训作业","试卷","私有","状态","创建者单位","创建者","动态时间"]) + sheet1.row(0).concat(["ID","课堂名称","成员","资源","普通作业"," 实训作业","试卷","私有","状态","创建者单位","创建者","动态时间","创建时间"]) count_row = 1 courses.each do |course| school = course.teacher.try(:user_extensions).try(:school).try(:name).blank? ? "--" : course.teacher.school_name @@ -4193,6 +4193,7 @@ end sheet1[count_row,9] = school sheet1[count_row,10] = teacher_name sheet1[count_row,11] = format_time(course.updatetime) + sheet1[count_row,12] = format_time(course.created_at) count_row += 1 end book.write xls_report From f82c7b26f8e403e4832eca8c6f40d1df94f13396 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 24 Apr 2019 11:22:19 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E7=89=88=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/welcome_controller.rb | 2 +- app/views/layouts/_logined_header.html.erb | 83 ++++++------------- app/views/layouts/_unlogin_header.html.erb | 11 --- app/views/layouts/base_local.html.erb | 31 +++++++ .../javascripts/educoder/edu_application.js | 12 --- 5 files changed, 58 insertions(+), 81 deletions(-) create mode 100644 app/views/layouts/base_local.html.erb diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index c9d41c0a..729a9564 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -218,7 +218,7 @@ class WelcomeController < ApplicationController @tea_users = User.where(homepage_teacher: 1).includes(:user_extensions).limit(10).order("experience desc") @stu_users = User.includes(:user_extensions).where(user_extensions: {identity: 1}).limit(10).order("experience desc") - render :layout => 'educoder' + render :layout => 'base_local' end # 自动导入用户 diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb index 0cfd2916..9068a95b 100644 --- a/app/views/layouts/_logined_header.html.erb +++ b/app/views/layouts/_logined_header.html.erb @@ -6,25 +6,8 @@
  • "><%= link_to "翻转课堂", courses_path %>
  • "><%= link_to "开发社区", shixuns_path %>
  • - - <% careers = Career.published.order("created_at asc") %> - <% if careers.present? %> -
  • " style="cursor: auto;"> -

    职业路径

    - -
  • - <% end %>
  • "><%= link_to "竞赛", competitions_path %>
  • "><%= link_to "问答", forums_path %>
  • - <% if User.current.ec_school.present? %> -
  • " id="ec_banner"> - <%= link_to "认证", department_ecs_path(:school_id => User.current.ec_school) %> -
  • - <% end %> -
    - <%= link_to (image_tag(url_to_avatar(User.current), :width =>"34", :height => "34", :class => "radius mt13", :nhname => "avatar_image", :alt=>"头像", :id => "nh_user_logo")), user_path(User.current),:class => "fl" %> -
      - <%= User.current.show_name %> -
    • <%= link_to '我的课堂', user_path(User.current) %>
    • -
    • <%= link_to '我的实训', user_path(User.current, :type => 'a_shixun') %>
    • -
    • <%= link_to '我的实训课程', user_path(User.current, :type => 'a_path') %>
    • - <% if User.current.partner.present? %> -
    • <%= link_to '客户管理', partner_list_cooperate_path(User.current.partner) %>
    • - <% end %> -
    • <%= link_to '我的项目', user_path(User.current, :type => 'a_project') %>
    • + <% if User.current.logged? %> +
      + <%= link_to (image_tag(url_to_avatar(User.current), :width =>"34", :height => "34", :class => "radius mt13", :nhname => "avatar_image", :alt=>"头像", :id => "nh_user_logo")), user_path(User.current),:class => "fl" %> +
        + <%= User.current.show_name %> +
      • <%= link_to '我的课堂', user_path(User.current) %>
      • +
      • <%= link_to '我的实训', user_path(User.current, :type => 'a_shixun') %>
      • +
      • <%= link_to '我的实训课程', user_path(User.current, :type => 'a_path') %>
      • +
      • <%= link_to '我的项目', user_path(User.current, :type => 'a_project') %>
      • +
      • <%= link_to '账号管理', my_account_path %>
      • +
      • <%= link_to '退出', signout_path %>
      • +
      +
      + <% else %> + + <%= link_to '登录', signin_path, :class => "mr5 color-white" %> + + <%= link_to '注册', user_join_path, :class => "ml5 color-white" %> + + <% end %> - <% if User.current.department_members.count > 0 %> -
    • <%= link_to '学院统计', statistics_college_path(User.current.department_members.first.try(:department)) %>
    • - <% end %> -
    • <%= link_to '账号管理', my_account_path %>
    • -
    • <%= link_to '退出', signout_path %>
    • -
    -
    - -
    - - - - - <% new_tidings_count = User.current.tidings.where("created_at > '#{User.current.onclick_time.onclick_time}'").count %> - <% new_pri_message_count = User.current.private_messages.where("created_at > '#{User.current.onclick_time.onclick_time}'").count %> - <% count = new_tidings_count + new_pri_message_count %> - <% if count > 0 %> - <%= count > 99 ? "99+" : count %> - - <% end %> -
    @@ -126,11 +95,11 @@ <% notice = SystemUpdateNotice.last %> <% if @noticed_update || ((User.current.certification == 1 || params[:controller] != "welcome") && notice.present? && notice.end_time > Time.now && notice.start_time >= (Time.now - 21600) && User.current.user_system_notices.where(:notice_type => notice.notice_type).count == 0) %> - var htmlvalue = "<%= escape_javascript(render :partial => 'account/user_update_notice', :locals => {:notice => notice})%>"; - pop_box_new(htmlvalue, 500, 380); - <% UserSystemNotice.create(:user_id => User.current.id, :notice_type => notice.notice_type) %> + var htmlvalue = "<%= escape_javascript(render :partial => 'account/user_update_notice', :locals => {:notice => notice})%>"; + pop_box_new(htmlvalue, 500, 380); + <% UserSystemNotice.create(:user_id => User.current.id, :notice_type => notice.notice_type) %> <%# elsif notice.present? && notice.end_time < Time.now %> - <%# notice.destroy %> + <%# notice.destroy %> <% end %> }); diff --git a/app/views/layouts/_unlogin_header.html.erb b/app/views/layouts/_unlogin_header.html.erb index d970fffc..72dd2731 100644 --- a/app/views/layouts/_unlogin_header.html.erb +++ b/app/views/layouts/_unlogin_header.html.erb @@ -8,17 +8,6 @@
  • "><%= link_to "开发社区", shixuns_path %>
  • - <% careers = Career.published.order("created_at asc") %> - <% if careers.present? %> -
  • " style="cursor: auto;"> -

    职业路径

    - -
  • - <% end %>
  • "><%= link_to "竞赛", competitions_path %>
  • "><%= link_to "问答", forums_path %>
  • diff --git a/app/views/layouts/base_local.html.erb b/app/views/layouts/base_local.html.erb new file mode 100644 index 00000000..5ce69147 --- /dev/null +++ b/app/views/layouts/base_local.html.erb @@ -0,0 +1,31 @@ + + + + + <%= h html_title %> + + + <%= csrf_meta_tag %> + <%= favicon %> + <%= javascript_edu_index_heads %> + <%= stylesheet_link_tag 'educoder/edu-main', 'educoder/edu-all', 'educoder/magic-check' %> + + + +
    +
    + <%= render 'layouts/logined_header' %> +
    +
    + <%= yield %> +
    + <%= render :partial => 'layouts/footer' %> +
    + + + +<%= javascript_include_tag 'educoder/edu_application','educoder/jquery.raty' %> + + diff --git a/public/javascripts/educoder/edu_application.js b/public/javascripts/educoder/edu_application.js index 862f9d41..a94d72c2 100644 --- a/public/javascripts/educoder/edu_application.js +++ b/public/javascripts/educoder/edu_application.js @@ -15,18 +15,6 @@ $(function(){ var searchText = result[1] $('#search-input').val(searchText) } - // 未报名用户登录时弹框 - // console.log(Cookies.get('enroll_status')); - // if(Cookies.get('enroll_status') == 0){ - // Cookies.remove('enroll_status'); - // var html='
    '+ - // '
    '+ - // ''+ - // ''+ - // '立即报名'+ - // '
    '; - // $(".newContainer").append(html); - // } }); function CloseBox(){ From cdfda26c99586006eea5da7fd36302350bdef5d5 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 24 Apr 2019 15:28:01 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/account/login.html.erb | 9 --------- app/views/layouts/login.html.erb | 18 ++---------------- 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/app/views/account/login.html.erb b/app/views/account/login.html.erb index a4af9782..83b6b152 100644 --- a/app/views/account/login.html.erb +++ b/app/views/account/login.html.erb @@ -73,15 +73,6 @@ <% end %> - - <%= render :partial => "account/copyright_info" %> diff --git a/app/views/layouts/login.html.erb b/app/views/layouts/login.html.erb index 818ba099..e8ad5ae9 100644 --- a/app/views/layouts/login.html.erb +++ b/app/views/layouts/login.html.erb @@ -7,23 +7,9 @@ <%= csrf_meta_tag %> <%= favicon %> - <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','educoder/edu-main','educoder/edu-all', 'css/font-awesome','educoder/magic-check.css' %> - <%#= javascript_heads %> - <%= javascript_include_tag 'jquery-1.8.3-ui-1.9.2-ujs-2.0.3', 'jquery.colorbox-min', 'edu/application', 'educoder/edu_application','educoder/edu_account','educoder/avatars' %> - <%#= stylesheet_link_tag 'css/edu-showpage','css/edu-index', 'css/font-awesome', 'css/edu-common', 'css/edu-login', 'css/edu-public', 'css/edu-popup' %> - <%#= javascript_include_tag 'edu/application', "bigdata" %> - - -
    From 978fbf47e54abe40c64a6b1df10ebb87d05350b9 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 24 Apr 2019 16:04:14 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=BB=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E4=B8=80=E4=BA=9B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/layouts/base_edu_user.html.erb | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/app/views/layouts/base_edu_user.html.erb b/app/views/layouts/base_edu_user.html.erb index 293b9426..6143c8ca 100644 --- a/app/views/layouts/base_edu_user.html.erb +++ b/app/views/layouts/base_edu_user.html.erb @@ -7,31 +7,13 @@ <%= csrf_meta_tag %> <%= favicon %> - <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/font-awesome','educoder/edu-main','educoder/edu-all','educoder/magic-check.css','/assets/iconfont/iconfont.css', :media => 'all' %> <%= javascript_heads %> - <%= javascript_include_tag 'edu/application', 'educoder/edu_application','educoder/edu_account',"educoder/edu_user" %> - <%= yield :header_tags -%> - - - -
    - <% if User.current.logged? %> - <%= render :partial => 'layouts/logined_header' %> - <% else%> - <%= render :partial => 'layouts/unlogin_header' %> - <% end%> + <%= render :partial => 'layouts/logined_header' %>
    @@ -55,4 +37,5 @@
    +<%= javascript_include_tag 'educoder/edu_application','educoder/edu_account',"educoder/edu_user" %> \ No newline at end of file From 085e1ec44d817b348c557b84e6ad19e895760720 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 26 Apr 2019 09:56:27 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E7=9A=84=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/application_helper.rb | 11 ++++++++++- app/views/layouts/base_edu_user.html.erb | 17 ++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 707ff571..ede8c6b6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3990,7 +3990,7 @@ module ApplicationHelper # Returns the javascript tags that are included in the html layout head def javascript_heads - tags = javascript_include_tag('jquery-1.8.3-ui-1.9.2-ujs-2.0.3', 'application', 'jquery.colorbox-min', 'baiduTemplate') + tags = javascript_include_tag('jquery-1.8.3-ui-1.9.2-ujs-2.0.3', 'jquery.colorbox-min', 'baiduTemplate') unless User.current.pref.warn_on_leaving_unsaved == '0' tags << "\n".html_safe + javascript_tag("$(window).load(function(){ warnLeavingUnsaved('#{escape_javascript l(:text_warn_on_leaving_unsaved)}'); });") end @@ -4004,6 +4004,15 @@ module ApplicationHelper tags end + # 临时本地版 + def javascript_heads_local + tags = javascript_include_tag('jquery-1.8.3-ui-1.9.2-ujs-2.0.3', 'jquery.colorbox-min') + unless User.current.pref.warn_on_leaving_unsaved == '0' + tags << "\n".html_safe + javascript_tag("$(window).load(function(){ warnLeavingUnsaved('#{escape_javascript l(:text_warn_on_leaving_unsaved)}'); });") + end + tags + end + def hubspot_head tags = javascript_include_tag('hubspot/messenger.min', 'hubspot/messenger-theme-future') tags << stylesheet_link_tag('hubspot/messenger', 'hubspot/messenger-theme-future', 'hubspot/messenger-theme-flat') diff --git a/app/views/layouts/base_edu_user.html.erb b/app/views/layouts/base_edu_user.html.erb index 6143c8ca..37ba85ca 100644 --- a/app/views/layouts/base_edu_user.html.erb +++ b/app/views/layouts/base_edu_user.html.erb @@ -7,25 +7,23 @@ <%= csrf_meta_tag %> <%= favicon %> - <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/font-awesome','educoder/edu-main','educoder/edu-all','/assets/iconfont/iconfont.css', :media => 'all' %> - + <%= stylesheet_link_tag 'css/font-awesome','educoder/edu-main','educoder/edu-all','/assets/iconfont/iconfont.css', :media => 'all' %> -
    -
    +
    +
    <%= render :partial => 'layouts/logined_header' %>
    -
    +
    <%= yield %>
    - + <%= render :partial => 'users/returnTop_btn' %>
    - - <%#= render :partial => 'layouts/public_left_info' %> + <%= render :partial => 'layouts/footer' %>
    @@ -37,5 +35,6 @@
    -<%= javascript_include_tag 'educoder/edu_application','educoder/edu_account',"educoder/edu_user" %> +<%= javascript_heads_local %> +<%= javascript_include_tag 'edu/application', 'educoder/edu_application',"educoder/edu_user" %> \ No newline at end of file From 7104eee0c5d331168c30c0b458a5ca8202e6ebe4 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 26 Apr 2019 16:55:44 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E8=BF=90=E8=90=A5=E4=BA=BA=E5=91=98?= =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 7 +++++++ app/controllers/courses_controller.rb | 2 +- app/controllers/managements_controller.rb | 3 +-- app/controllers/shixuns_controller.rb | 1 + app/controllers/users_controller.rb | 2 +- app/models/open_source_project.rb | 7 ------- app/services/games_service.rb | 2 +- db/migrate/20190426020414_add_business_to_user.rb | 5 +++++ 8 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20190426020414_add_business_to_user.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5e107d39..5bbe534e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -362,6 +362,13 @@ class ApplicationController < ActionController::Base true end + # 运营人员 + def require_business + unless (User.current.business? || User.current.admin?) + render_403 + end + end + def deny_access User.current.logged? ? render_403 : require_login end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index b65f2219..421e5da3 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1635,7 +1635,7 @@ class CoursesController < ApplicationController @course_modules = @course.course_modules.where(:hidden => 0) course_module_type = @course_modules.map(&:module_type) - @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? + @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? || User.current.business? if User.current.member_of_course?(@course) && !@is_teacher member = @course.members.where(:user_id => User.current.id).first if member.try(:course_group_id).to_i == 0 diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 11796cb0..cc883b9c 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -1,6 +1,6 @@ # encoding: utf-8 class ManagementsController < ApplicationController - before_filter :require_admin + before_filter :require_business layout 'base_management' include ManagementsHelper include SortHelper @@ -63,7 +63,6 @@ class ManagementsController < ApplicationController # 工程认证视频导入模板 def ec_template @template = EcTemplate.where(nil) - end def add_template diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index b2761b60..f6578f18 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -10,6 +10,7 @@ class ShixunsController < ApplicationController before_filter :view_allow, :only => [:collaborators, :propaedeutics, :shixun_discuss, :ranking_list] before_filter :require_manager, :only => [ :settings, :add_script, :publish, :collaborators_delete, :shixun_members_added, :add_collaborators, :update, :destroy] before_filter :validation_email, :only => [:new] + before_filter :require_admin, :only => [:destroy] # 移动云ToC模式权限控制 # before_filter :ecloud_auth, :except => [:show, :index] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d13db006..df2ce0cd 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -274,7 +274,7 @@ class UsersController < ApplicationController # 私信 def private_messages - if User.current == @user || User.current.admin? + if User.current == @user || User.current.admin? || User.current.business? @onclick_time = User.current.onclick_time.onclick_time User.current.onclick_time.update_attribute(:onclick_time, Time.now) @messages = PrivateMessage.find_by_sql("SELECT ui.* FROM (SELECT * FROM private_messages WHERE STATUS != 2 AND user_id = #{@user.id} ORDER BY id DESC) ui GROUP BY ui.target_id ORDER BY ui.send_time DESC") diff --git a/app/models/open_source_project.rb b/app/models/open_source_project.rb index 0adc0957..93b91fbb 100644 --- a/app/models/open_source_project.rb +++ b/app/models/open_source_project.rb @@ -121,13 +121,6 @@ class OpenSourceProject < ActiveRecord::Base ApplyProjectMaster.delete_all "apply_type = '#{self.class}' AND apply_id = #{self.id} AND user_id = #{user.id}" end - def admin?(user) - if user.admin? or ApplyProjectMaster.find(:all, :conditions => ["user_id = ? and apply_type = 'OpenSourceProject' and apply_id = ? and status = ?", user.id, self.id, 2]).present? - return true - else - return false - end - end def reset_counters! self.class.reset_counters!(id) diff --git a/app/services/games_service.rb b/app/services/games_service.rb index 8573c683..bddb03b7 100644 --- a/app/services/games_service.rb +++ b/app/services/games_service.rb @@ -17,7 +17,7 @@ class GamesService myshixun = Myshixun.min.find(game.myshixun_id) shixun = Shixun.min.find(myshixun.shixun_id) - unless (myshixun.user_id == current_user.id || current_user.admin? || current_user.id == shixun.try(:user_id) || current_user.is_certification_teacher) + unless (myshixun.user_id == current_user.id || current_user.admin? || current_user.business? || current_user.id == shixun.try(:user_id) || current_user.is_certification_teacher) return{:status => 403} end game_challenge = Challenge.min.find(game.challenge_id) diff --git a/db/migrate/20190426020414_add_business_to_user.rb b/db/migrate/20190426020414_add_business_to_user.rb new file mode 100644 index 00000000..c9ab35ca --- /dev/null +++ b/db/migrate/20190426020414_add_business_to_user.rb @@ -0,0 +1,5 @@ +class AddBusinessToUser < ActiveRecord::Migration + def change + add_column :users, :business, :boolean, :default => false + end +end From 01668fe3f84791429f1b1bdf3146f4315d2e1593 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 26 Apr 2019 17:37:24 +0800 Subject: [PATCH 11/12] school contrast data feature --- Gemfile | 3 + .../managements/schools_controller.rb | 34 ++- app/helpers/application_helper.rb | 2 +- app/libs/custom_sortable.rb | 2 +- app/models/school_daily_report.rb | 3 + app/models/shixun.rb | 1 + .../school_data_contrast_service.rb | 66 ++++++ .../management/school_report_service.rb | 12 +- .../school_yesterday_data_service.rb | 32 +++ .../statistic_school_daily_report_task.rb | 44 ++++ app/views/layouts/base_management.html.erb | 1 + .../schools/_contrast_search_form.html.erb | 223 ++++++++++++++++++ .../schools/_data_contrast_list.html.erb | 72 ++++++ .../schools/_statistics_list.html.erb | 5 +- .../schools/_yesterday_data_list.html.erb | 38 +++ .../managements/schools/data_contrast.js.erb | 2 + .../schools/yesterday_data.html.erb | 9 + .../managements/schools/yesterday_data.js.erb | 2 + config/locales/school_daily_reports/zh.yml | 7 + config/routes.rb | 2 + config/schedule.rb | 24 ++ ...90425073829_create_school_daily_reports.rb | 18 ++ lib/tasks/statistic_school_daily_report.rake | 103 ++++++++ 23 files changed, 687 insertions(+), 18 deletions(-) create mode 100644 app/models/school_daily_report.rb create mode 100644 app/services/management/school_data_contrast_service.rb create mode 100644 app/services/management/school_yesterday_data_service.rb create mode 100644 app/tasks/statistic_school_daily_report_task.rb create mode 100644 app/views/managements/schools/_contrast_search_form.html.erb create mode 100644 app/views/managements/schools/_data_contrast_list.html.erb create mode 100644 app/views/managements/schools/_yesterday_data_list.html.erb create mode 100644 app/views/managements/schools/data_contrast.js.erb create mode 100644 app/views/managements/schools/yesterday_data.html.erb create mode 100644 app/views/managements/schools/yesterday_data.js.erb create mode 100644 config/locales/school_daily_reports/zh.yml create mode 100644 config/schedule.rb create mode 100644 db/migrate/20190425073829_create_school_daily_reports.rb create mode 100644 lib/tasks/statistic_school_daily_report.rake diff --git a/Gemfile b/Gemfile index a5bf637a..7d4ab7bf 100644 --- a/Gemfile +++ b/Gemfile @@ -60,6 +60,9 @@ gem 'kaminari' gem 'elasticsearch-model' gem 'elasticsearch-rails' +# cronjob +gem 'whenever', require: false + #Ruby 2.2+ has removed test/unit from the core library. if RUBY_VERSION>='2.2' gem 'test-unit', '~> 3.0' diff --git a/app/controllers/managements/schools_controller.rb b/app/controllers/managements/schools_controller.rb index 6684db66..6dfe84fb 100644 --- a/app/controllers/managements/schools_controller.rb +++ b/app/controllers/managements/schools_controller.rb @@ -1,20 +1,44 @@ class Managements::SchoolsController < Managements::BaseController before_filter :set_navigation_bar - before_filter :set_default_sort_params, only: :statistics + before_filter :contrast_column_select_options, only: [:data_contrast] def statistics @sub_type = 1 + params[:sort_by] ||= :teacher_count + params[:sort_direction] ||= :desc + schools = Management::SchoolReportService.new(params).call @schools = paginateHelper schools end + def yesterday_data + @sub_type = 2 + params[:sort_by] ||= :teacher_increase_count + params[:sort_direction] ||= :desc + + reports = Management::SchoolYesterdayDataService.new(params).call + @reports = paginateHelper reports + end + + def data_contrast + params[:contrast_column] = :teacher_increase_count if params[:contrast_column].blank? + params[:sort_direction] ||= :desc + params[:sort_by] ||= :percentage + + @obj_count, @reports = Management::SchoolDataContrastService.new(params).call + @obj_pages = Paginator.new(@obj_count, Management::SchoolDataContrastService::PAGE_SIZE, params[:page]) + rescue Management::SchoolDataContrastService::ParameterError + raise '参数错误' + end + private def set_navigation_bar @menu_type = 1 end - def set_default_sort_params - params[:sort_by] ||= :teacher_count - params[:sort_direction] ||= :desc + def contrast_column_select_options + @select_options = Management::SchoolDataContrastService::CONTRAST_COLUMN_LIST.map do |column| + [I18n.t("school_daily_report.#{column}"), column] + end end -end \ No newline at end of file +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c02f7e5a..6a5f8b8d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -671,7 +671,7 @@ module ApplicationHelper when 1 case sub_type when 1 then "统计总表" - when 2 then "变化报表" + when 2 then "数据变化报表" end when 2 sub_type == 1 ? "课程列表" : (sub_type == 2? "课堂列表" : (sub_type == 3? "实训作业" : "项目列表")) diff --git a/app/libs/custom_sortable.rb b/app/libs/custom_sortable.rb index 721cbd1e..a8549452 100644 --- a/app/libs/custom_sortable.rb +++ b/app/libs/custom_sortable.rb @@ -11,7 +11,7 @@ module CustomSortable sort_by ||= self.class.sort_options[:default_by] sort_direction ||= self.class.sort_options[:default_direction] - return relations unless self.class.check_sort_parameter_validate(sort_by, sort_direction) + return relations unless self.class.check_sort_parameter_validate(sort_by.to_s, sort_direction.to_s) order_method = self.class.sort_options[:reorder] ? :reorder : :order relations.send(order_method, "#{sort_by} #{sort_direction}") diff --git a/app/models/school_daily_report.rb b/app/models/school_daily_report.rb new file mode 100644 index 00000000..494eacfd --- /dev/null +++ b/app/models/school_daily_report.rb @@ -0,0 +1,3 @@ +class SchoolDailyReport < ActiveRecord::Base + belongs_to :school +end \ No newline at end of file diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 6ab98172..54882be1 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -28,6 +28,7 @@ class Shixun < ActiveRecord::Base :propaedeutics, :trainee, :major_id, :homepage_show, :webssh, :hidden, :fork_from, :can_copy, :modify_time, :reset_time, :git_url, :use_scope, :vnc, :evaluate_script, :image_text, :exec_time, :test_set_permission, :hide_code, :excute_time, :forbid_copy + belongs_to :creator, foreign_key: :user_id, class_name: 'User' has_many :users, :through => :shixun_members has_many :shixun_members, :dependent => :destroy has_one :repository, :dependent => :destroy diff --git a/app/services/management/school_data_contrast_service.rb b/app/services/management/school_data_contrast_service.rb new file mode 100644 index 00000000..a1ad4c24 --- /dev/null +++ b/app/services/management/school_data_contrast_service.rb @@ -0,0 +1,66 @@ +class Management::SchoolDataContrastService + ParameterError = Class.new(StandardError) + + PAGE_SIZE = 20 + CONTRAST_COLUMN_LIST = %w( + teacher_increase_count student_increase_count course_increase_count + shixun_increase_count active_user_count + ).freeze + + attr_reader :params, :sort_direction, :contrast_column + + def initialize(params) + @params = params + @sort_direction = params[:sort_direction].to_s + @contrast_column = params[:contrast_column].to_s + end + + def call + validate_parameter! + reports = SchoolDailyReport.select(select_columns) + + keyword = params[:keyword].try(:to_s).try(:strip) + if keyword.present? + reports = reports.where("school_name LIKE :keyword OR school_id LIKE :keyword", keyword: "%#{keyword}%") + end + + reports = reports.group(:school_id) + count = reports.count.count + + [count, SchoolDailyReport.find_by_sql(query_report_sql(reports.to_sql))] + end + + private + def validate_parameter! + if %i[begin_date end_date other_begin_date other_end_date].any? { |key| params[key].blank? } + raise ParameterError + end + + unless %w(desc asc).include?(sort_direction) + raise ParameterError + end + + unless CONTRAST_COLUMN_LIST.include?(contrast_column) + raise ParameterError + end + end + + def format_date(date) + Time.zone.parse(date).strftime("%Y-%m-%d") + end + + def offset + (params[:page].to_i.zero? ? 0 : params[:page].to_i - 1) * PAGE_SIZE + end + + def select_columns + "school_id, school_name,"\ + "SUM(IF(date BETWEEN '#{format_date(params[:begin_date])}' AND '#{format_date(params[:end_date])}', #{contrast_column}, 0)) total,"\ + "SUM(IF(date BETWEEN '#{format_date(params[:other_begin_date])}' AND '#{format_date(params[:other_end_date])}', #{contrast_column}, 0)) other_total" + end + + def query_report_sql(from_sql) + "SELECT reports.*, (other_total - total) increase, (IF(other_total - total = 0, 0.0, round((other_total - total) / IF(total = 0, 1, total), 5))) percentage "\ + "FROM (#{from_sql}) reports ORDER BY percentage #{sort_direction} LIMIT #{PAGE_SIZE} OFFSET #{offset}" + end +end diff --git a/app/services/management/school_report_service.rb b/app/services/management/school_report_service.rb index 9b794b7b..5a962bd5 100644 --- a/app/services/management/school_report_service.rb +++ b/app/services/management/school_report_service.rb @@ -29,16 +29,12 @@ class Management::SchoolReportService <<-SQL schools.id, schools.name, ( - SELECT COUNT(*) FROM users u - LEFT JOIN user_extensions ue ON ue.user_id = u.id - LEFT JOIN ec_school_users esu ON esu.user_id = u.id - WHERE esu.school_id = schools.id AND ue.identity = #{User::STUDENT} + SELECT COUNT(*) FROM user_extensions ue + WHERE ue.school_id = schools.id AND ue.identity = #{User::STUDENT} ) student_count, ( - SELECT COUNT(*) FROM users u - LEFT JOIN user_extensions ue ON ue.user_id = u.id - LEFT JOIN ec_school_users esu ON esu.user_id = u.id - WHERE esu.school_id = schools.id AND ue.identity = #{User::TEACHER} + SELECT COUNT(*) FROM user_extensions ue + WHERE ue.school_id = schools.id AND ue.identity = #{User::TEACHER} ) teacher_count, ( SELECT COUNT(*) FROM homework_commons hc diff --git a/app/services/management/school_yesterday_data_service.rb b/app/services/management/school_yesterday_data_service.rb new file mode 100644 index 00000000..238a7297 --- /dev/null +++ b/app/services/management/school_yesterday_data_service.rb @@ -0,0 +1,32 @@ +class Management::SchoolYesterdayDataService + include CustomSortable + + attr_reader :params + + sort_columns :student_increase_count, :teacher_increase_count, + :course_increase_count, :shixun_increase_count, :active_user_count, + default_by: :teacher_increase_count, default_direction: :desc + + def initialize(params) + @params = params + end + + def call + reports = SchoolDailyReport.where(date: yesterday) + + keyword = params[:keyword].try(:to_s).try(:strip) + if keyword.present? + reports = reports.where("school_name LIKE :keyword OR school_id LIKE :keyword", keyword: "%#{keyword}%") + end + + reports = custom_sort(reports, params[:sort_by], params[:sort_direction]) + + reports + end + + private + def yesterday + # 每日凌晨5点为节点, 25日凌晨4点、3点、2点等等,未到更新数据时间点,看到的数据是:23日-24日的统计数据 + (Time.zone.now - 5.hours).beginning_of_day - 1.days + end +end diff --git a/app/tasks/statistic_school_daily_report_task.rb b/app/tasks/statistic_school_daily_report_task.rb new file mode 100644 index 00000000..3569351f --- /dev/null +++ b/app/tasks/statistic_school_daily_report_task.rb @@ -0,0 +1,44 @@ +class StatisticSchoolDailyReportTask + def call + School.find_each do |school| + # 新增教师和学生 + users = User.joins(:user_extensions) + .where(user_extensions: { school_id: school.id }) + + teacher_count = users.where(created_on: yesterday, user_extensions: { identity: User::TEACHER }).count + student_count = users.where(created_on: yesterday, user_extensions: { identity: User::STUDENT }).count + + # 活跃用户 + active_user_count = users.where(last_login_on: yesterday).count + + # 新增课堂 + course_count = school.courses.where(created_at: yesterday).count + + # 新增实训 + shixun_count = Shixun.joins(creator: :user_extensions) + .where('user_extensions.school_id = ?', school.id) + .where(created_at: yesterday).count + + create_params = { + school_id: school.id, school_name: school.name, teacher_increase_count: teacher_count, + student_increase_count: student_count, course_increase_count: course_count, + shixun_increase_count: shixun_count, active_user_count: active_user_count, date: current_date + } + SchoolDailyReport.create!(create_params) + end + end + + private + def current_date + @_current_date ||= Time.zone.now.beginning_of_day - 1.day + end + + def yesterday + @_yesterday ||= begin + # 每日凌晨5点为节点 + end_time = Time.zone.now.beginning_of_day + 5.hour + begin_time = end_time - 1.day + begin_time..end_time + end + end +end diff --git a/app/views/layouts/base_management.html.erb b/app/views/layouts/base_management.html.erb index c38bf3eb..9d1d77c8 100644 --- a/app/views/layouts/base_management.html.erb +++ b/app/views/layouts/base_management.html.erb @@ -35,6 +35,7 @@
  • 学校+
    • <%= link_to '统计总表', school_report_managements_path %>
    • +
    • <%= link_to '数据变化报表', school_yesterday_data_managements_path %>
  • 课堂+ diff --git a/app/views/managements/schools/_contrast_search_form.html.erb b/app/views/managements/schools/_contrast_search_form.html.erb new file mode 100644 index 00000000..2140eb97 --- /dev/null +++ b/app/views/managements/schools/_contrast_search_form.html.erb @@ -0,0 +1,223 @@ +
    +
    + <%= hidden_field_tag :contrast_column, params[:contrast_column] %> + <%= hidden_field_tag :begin_date, params[:begin_date] %> + <%= hidden_field_tag :end_date, params[:end_date] %> + <%= hidden_field_tag :other_begin_date, params[:other_begin_date] %> + <%= hidden_field_tag :other_end_date, params[:other_end_date] %> + + <%= text_field_tag :date_input, params[:date_input], + class: 'date-input winput-200-30', placeholder: '请选择时间段一' %> + VS + <%= text_field_tag :other_date_input, params[:other_date_input], + class: 'other-date-input winput-200-30', placeholder: '请选择时间段二' %> +
    + +
    + <%= hidden_field_tag :data_type, params[:data_type] || 'yesterday' %> + <% if params[:data_type] == 'contrast' %> + 时间对比 + 日新增 + <% else %> + 时间对比 + 日新增 + <% end %> +
    + + <%= text_field_tag :keyword, params[:keyword], placeholder: '请输入单位名称或者ID关键字进行搜索', + class: 'fl task-form-30 task-height-30 mt10', style: 'margin: 10px 10px 10px 25px;' %> + <%= link_to '搜索', 'javascript:void(0)', class: 'fl task-btn task-btn-orange ml5 mt10 search-btn' %> + <%= link_to '清除', 'javascript:void(0)', class: 'fl task-btn ml5 mt2 mt10 reset-btn' %> +
    + \ No newline at end of file diff --git a/app/views/managements/schools/_data_contrast_list.html.erb b/app/views/managements/schools/_data_contrast_list.html.erb new file mode 100644 index 00000000..0a9ee965 --- /dev/null +++ b/app/views/managements/schools/_data_contrast_list.html.erb @@ -0,0 +1,72 @@ +
    +
    + 学校数据统计(<%= I18n.t("school_daily_report.#{params[:contrast_column]}") %>变化统计情况) +
    + <%= select_tag :contrast_column, + options_for_select(@select_options, params[:contrast_column]), + class: 'fl task-height-30 contrast-column-select', + style: 'position: absolute; right: 30px; top: 15px;' %> +
    + + + + + + + + + + + + + + <% @reports.each_with_index do |report, index| %> + + + + + + + <% if report['increase'] > 0 %> + + + <% elsif report['increase'].zero? %> + + + <% else %> + + + <% end %> + + <% end %> + +
    序号ID单位名称时段一
    <%= "(#{params[:begin_date]}至#{params[:end_date]})" %>
    时段二
    <%= "(#{params[:other_begin_date]}至#{params[:other_end_date]})" %>
    + <%= sort_tag('变化情况', name: 'percentage', path: school_data_contrast_managements_path) %> +
    ( 新 增 数 | 新增百分比) +
    <%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %><%= report.school_id %><%= report.school_name %><%= report['total'] %><%= report['other_total'] %> + +<%= report['increase'] %> + +<%= report['percentage'] %>% + <%= report['increase'] %> + <%= report['percentage'] %> + <%= report['increase'] %> + <%= report['percentage'] %>%
    + +
    +
    +
      + <%= pagination_links_full @obj_pages, @obj_count, per_page_links: false, remote: true, flag: true, is_new: true, path: school_data_contrast_managements_path(params.except(:page)) %> +
    +
    +
    +
    + \ No newline at end of file diff --git a/app/views/managements/schools/_statistics_list.html.erb b/app/views/managements/schools/_statistics_list.html.erb index 1675e6f1..609a1cca 100644 --- a/app/views/managements/schools/_statistics_list.html.erb +++ b/app/views/managements/schools/_statistics_list.html.erb @@ -15,10 +15,9 @@ - <% @schools.as_json.each_with_index do |data, index| %> + <% @schools.each_with_index do |school, index| %> - <% school = data["school"] %> - <%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %> + <% p school %><%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %> <%= school['id'] %> <%= school['name'] %> <%= school['teacher_count'] %> diff --git a/app/views/managements/schools/_yesterday_data_list.html.erb b/app/views/managements/schools/_yesterday_data_list.html.erb new file mode 100644 index 00000000..51c4bbdc --- /dev/null +++ b/app/views/managements/schools/_yesterday_data_list.html.erb @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + <% @reports.each_with_index do |report, index| %> + + + + + + + + + + + <% end %> + +
    序号ID单位名称<%= sort_tag('新增教师', name: 'teacher_increase_count', path: school_yesterday_data_managements_path) %><%= sort_tag('新增学生', name: 'student_increase_count', path: school_yesterday_data_managements_path) %><%= sort_tag('新增课堂', name: 'course_increase_count', path: school_yesterday_data_managements_path) %><%= sort_tag('新增实训', name: 'shixun_increase_count', path: school_yesterday_data_managements_path) %><%= sort_tag('活跃用户', name: 'active_user_count', path: school_yesterday_data_managements_path) %>
    <%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %><%= report.school_id %><%= report.school_name %><%= report.teacher_increase_count %><%= report.student_increase_count %><%= report.course_increase_count %><%= report.shixun_increase_count %><%= report.active_user_count %>
    + +
    +
    +
      + <%= pagination_links_full @obj_pages, @obj_count, per_page_links: false, remote: true, flag: true, is_new: true, path: school_yesterday_data_managements_path(params.except(:page)) %> +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/managements/schools/data_contrast.js.erb b/app/views/managements/schools/data_contrast.js.erb new file mode 100644 index 00000000..a7c2746f --- /dev/null +++ b/app/views/managements/schools/data_contrast.js.erb @@ -0,0 +1,2 @@ +$("#managements-school-data").html("<%= j(render 'managements/schools/data_contrast_list') %>") +$(".management-school-data-form-box").html("<%= j(render 'managements/schools/contrast_search_form') %>") \ No newline at end of file diff --git a/app/views/managements/schools/yesterday_data.html.erb b/app/views/managements/schools/yesterday_data.html.erb new file mode 100644 index 00000000..af96997d --- /dev/null +++ b/app/views/managements/schools/yesterday_data.html.erb @@ -0,0 +1,9 @@ +
    +
    + <%= render 'managements/schools/contrast_search_form' %> +
    +
    + +
    + <%= render 'managements/schools/yesterday_data_list'%> +
    \ No newline at end of file diff --git a/app/views/managements/schools/yesterday_data.js.erb b/app/views/managements/schools/yesterday_data.js.erb new file mode 100644 index 00000000..1a9a8ebb --- /dev/null +++ b/app/views/managements/schools/yesterday_data.js.erb @@ -0,0 +1,2 @@ +$("#managements-school-data").html("<%= j(render 'managements/schools/yesterday_data_list') %>") +$(".management-school-data-form-box").html("<%= j(render 'managements/schools/contrast_search_form') %>") \ No newline at end of file diff --git a/config/locales/school_daily_reports/zh.yml b/config/locales/school_daily_reports/zh.yml new file mode 100644 index 00000000..57caf343 --- /dev/null +++ b/config/locales/school_daily_reports/zh.yml @@ -0,0 +1,7 @@ +zh: + school_daily_report: + teacher_increase_count: 新增教师 + student_increase_count: 新增学生 + course_increase_count: 新增课堂 + shixun_increase_count: 新增实训 + active_user_count: 活跃用户 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9c70df82..f539af9c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -721,6 +721,8 @@ RedmineApp::Application.routes.draw do ## oauth相关 delete :delete_customers get :customers_list get :school_report, controller: 'managements::schools', action: 'statistics' + get :school_yesterday_data, controller: 'managements::schools', action: 'yesterday_data' + get :school_data_contrast, controller: 'managements::schools', action: 'data_contrast' end end # Enable Grack support diff --git a/config/schedule.rb b/config/schedule.rb new file mode 100644 index 00000000..380494c6 --- /dev/null +++ b/config/schedule.rb @@ -0,0 +1,24 @@ +# Use this file to easily define all of your cron jobs. +# +# It's helpful, but not entirely necessary to understand cron before proceeding. +# http://en.wikipedia.org/wiki/Cron + +# Example: +# +# set :output, "/path/to/my/cron_log.log" +# +# every 2.hours do +# command "/usr/bin/some_great_command" +# runner "MyModel.some_method" +# rake "some:great:rake:task" +# end +# +# every 4.days do +# runner "AnotherModel.prune_old_records" +# end + +# Learn more: http://github.com/javan/whenever + +every 1.days, at: '5:00 am' do + runner 'StatisticSchoolDailyReportTask.new.call' +end diff --git a/db/migrate/20190425073829_create_school_daily_reports.rb b/db/migrate/20190425073829_create_school_daily_reports.rb new file mode 100644 index 00000000..e66f5722 --- /dev/null +++ b/db/migrate/20190425073829_create_school_daily_reports.rb @@ -0,0 +1,18 @@ +class CreateSchoolDailyReports < ActiveRecord::Migration + def change + create_table :school_daily_reports do |t| + t.integer :school_id + t.string :school_name + t.integer :teacher_increase_count + t.integer :student_increase_count + t.integer :course_increase_count + t.integer :shixun_increase_count + t.integer :active_user_count + + t.date :date + t.timestamps + end + + add_index :school_daily_reports, [:school_id, :date], unique: true + end +end diff --git a/lib/tasks/statistic_school_daily_report.rake b/lib/tasks/statistic_school_daily_report.rake new file mode 100644 index 00000000..84b65204 --- /dev/null +++ b/lib/tasks/statistic_school_daily_report.rake @@ -0,0 +1,103 @@ +#coding=utf-8 + +namespace :school_daily_report do + desc 'statistic school daily report data before now' + task :statistic, [:date] => :environment do |_, args| + date = Time.zone.parse(args[:date]).beginning_of_day + current_date = (Time.zone.now - 5.hour).beginning_of_day + custom_logger("statistic range: #{date}..#{current_date}") + + while current_date > date + date_str = date.strftime('%Y-%m-%d') + # 检查当天数据是否已经统计 + if SchoolDailyReport.exists?(date: date) + custom_logger("Skip! statistics data exist, date: #{date_str}") + date += 1.day + next + end + + school_count = School.count + query_times = school_count % query_size == 0 ? school_count / query_size : (school_count / query_size) + 1 + + custom_logger("Start statistic => Date: #{date_str}, school count: #{school_count}, insert times: #{query_times} ~") + query_times.times do |index| + sql = school_daily_report_sql(date, query_size, index * query_size) + reports = School.find_by_sql(sql) + + data = reports.map do |report| + [ + report['id'], report['name'], report['teacher_count'], report['student_count'], report['course_count'], + report['shixun_count'], report['active_user_count'], date_str, current_datetime, current_datetime + ] + end + batch_create_school_daily_reports!(data) + end + custom_logger("Statistic complete! date: #{date_str}") + + date += 1.day + end + end + + desc 'clear school daily report data' + task clear: :environment do + SchoolDailyReport.destroy_all + end + + def query_size + 100 + end + + def current_datetime + Time.zone.now.strftime('%Y-%m-%d %H:%M:%S') + end + + def custom_logger(str) + p(str) + end + + def batch_create_school_daily_reports!(arr) + sql = build_insert_report_sql(arr) + SchoolDailyReport.connection.execute(sql) + end + + def build_insert_report_sql(arr) + prefix = 'INSERT INTO school_daily_reports(school_id, school_name, teacher_increase_count, student_increase_count, '\ + 'course_increase_count, shixun_increase_count, active_user_count, date, created_at, updated_at) VALUES' + # [[1,2], [3,4]] => ['"1", "2"', '"3", "4"'] => '("1", "2"),("3", "4")' + values = '(' + arr.map { |item| '"' + item.join('","') + '"' }.join('),(') + ')' + + prefix + values + end + + def school_daily_report_sql(date, limit, offset) + begin_date = (date + 5.hour).strftime('%Y-%m-%d %H:%M:%S') + end_date = (date + 1.day + 5.hour).strftime('%Y-%m-%d %H:%M:%S') + + <<-SQL + SELECT schools.id, schools.name, ( + SELECT COUNT(*) FROM users u + LEFT JOIN user_extensions ue ON ue.user_id = u.id + WHERE ue.school_id = schools.id AND ue.identity = #{User::STUDENT} + AND u.created_on BETWEEN "#{begin_date}" AND "#{end_date}" + ) student_count, ( + SELECT COUNT(*) FROM users u + LEFT JOIN user_extensions ue ON ue.user_id = u.id + WHERE ue.school_id = schools.id AND ue.identity = #{User::TEACHER} + AND u.created_on BETWEEN "#{begin_date}" AND "#{end_date}" + ) teacher_count, ( + SELECT COUNT(*) FROM courses cs + WHERE cs.school_id = schools.id + AND cs.created_at BETWEEN "#{begin_date}" AND "#{end_date}" + ) course_count, ( + SELECT COUNT(*) FROM shixuns sx + LEFT JOIN users u ON sx.user_id = u.id + LEFT JOIN user_extensions ue ON ue.user_id = u.id + WHERE ue.school_id = schools.id AND sx.created_at BETWEEN "#{begin_date}" AND "#{end_date}" + ) shixun_count, ( + SELECT COUNT(*) FROM users u + LEFT JOIN user_extensions ue ON ue.user_id = u.id + WHERE ue.school_id = schools.id AND u.last_login_on BETWEEN "#{begin_date}" AND "#{end_date}" + ) active_user_count FROM schools LIMIT #{limit} OFFSET #{offset} + SQL + end +end From 5c6b6f4c957d8c7464204d1176f4a3ab6faca9a2 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 26 Apr 2019 17:48:56 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BF=90=E8=90=A5?= =?UTF-8?q?=E5=AE=9A=E5=88=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/managements_controller.rb | 1 + app/views/managements/update_user.html.erb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 07381e57..74560941 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -196,6 +196,7 @@ class ManagementsController < ApplicationController if request.post? @user.nickname = params[:nickname] @user.lastname = params[:lastname] + @user.business = params[:business].to_i @user.firstname = "" @user.mail = params[:mail].strip == "" ? nil : params[:mail] @user.phone = params[:phone].strip == "" ? nil : params[:phone] diff --git a/app/views/managements/update_user.html.erb b/app/views/managements/update_user.html.erb index 05b6e7f1..232275ce 100644 --- a/app/views/managements/update_user.html.erb +++ b/app/views/managements/update_user.html.erb @@ -184,6 +184,13 @@ <% end %>
  • +
  • + + + name="business" value="<%= @user.business? ? 1 : 0 %>" id="person_9" class="magic-checkbox" style="float:left; margin-top: 8px;"> + + +