From f82c7b26f8e403e4832eca8c6f40d1df94f13396 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 24 Apr 2019 11:22:19 +0800 Subject: [PATCH 01/69] =?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" %> - -
    @@ -79,28 +64,12 @@
  • <%= link_to '新建项目', new_project_path() %>
    • -
    • <%= link_to "加入课堂", join_private_courses_courses_path, :remote => true %>
    • -
    • <%= link_to "加入项目", applied_join_project_path, :remote => true %>
    • +
    • <%= link_to "加入课堂", join_private_courses_courses_path, :remote => true %>
    • +
    • <%= link_to "加入项目", applied_join_project_path, :remote => true %>
    - -
    - - - - - <% 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 02/69] =?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 03/69] =?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 372db525bd2d5ee1ba86e6352175ba3d6869778d Mon Sep 17 00:00:00 2001 From: winse Date: Wed, 24 Apr 2019 16:18:03 +0800 Subject: [PATCH 04/69] management school report feature --- .gitignore | 1 + .../managements/base_controller.rb | 5 ++ .../managements/schools_controller.rb | 20 +++++++ app/helpers/application_helper.rb | 26 +++++++++ app/libs/custom_sortable.rb | 45 ++++++++++++++ .../management/school_report_service.rb | 58 +++++++++++++++++++ app/views/layouts/base_management.html.erb | 5 ++ .../schools/_statistics_list.html.erb | 43 ++++++++++++++ .../managements/schools/statistics.html.erb | 19 ++++++ .../managements/schools/statistics.js.erb | 1 + config/routes.rb | 1 + .../javascripts/educoder/edu_application.js | 3 +- 12 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 app/controllers/managements/base_controller.rb create mode 100644 app/controllers/managements/schools_controller.rb create mode 100644 app/libs/custom_sortable.rb create mode 100644 app/services/management/school_report_service.rb create mode 100644 app/views/managements/schools/_statistics_list.html.erb create mode 100644 app/views/managements/schools/statistics.html.erb create mode 100644 app/views/managements/schools/statistics.js.erb diff --git a/.gitignore b/.gitignore index a6e5b74a..0966e944 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ .DS_Store public/api_doc/ /.metadata +.byebug_history vendor/cache /files /public/images/avatars diff --git a/app/controllers/managements/base_controller.rb b/app/controllers/managements/base_controller.rb new file mode 100644 index 00000000..cbb61c33 --- /dev/null +++ b/app/controllers/managements/base_controller.rb @@ -0,0 +1,5 @@ +class Managements::BaseController < ApplicationController + layout 'base_management' + + before_filter :require_admin +end \ No newline at end of file diff --git a/app/controllers/managements/schools_controller.rb b/app/controllers/managements/schools_controller.rb new file mode 100644 index 00000000..6684db66 --- /dev/null +++ b/app/controllers/managements/schools_controller.rb @@ -0,0 +1,20 @@ +class Managements::SchoolsController < Managements::BaseController + before_filter :set_navigation_bar + before_filter :set_default_sort_params, only: :statistics + + def statistics + @sub_type = 1 + schools = Management::SchoolReportService.new(params).call + @schools = paginateHelper schools + end + + private + def set_navigation_bar + @menu_type = 1 + end + + def set_default_sort_params + params[:sort_by] ||= :teacher_count + params[:sort_direction] ||= :desc + end +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 707ff571..6bc8f9f6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -668,6 +668,11 @@ module ApplicationHelper def managements_navigation_bar_show menu_type, sub_type, grandchild_type={} case menu_type + when 1 + case sub_type + when 1 then "统计总表" + when 2 then "变化报表" + end when 2 sub_type == 1 ? "课程列表" : (sub_type == 2? "课堂列表" : (sub_type == 3? "实训作业" : "项目列表")) when 3 @@ -5509,6 +5514,27 @@ challengeProgramNames=(CHALLENGEPROGRAMNAMES)" return sort_projects end end + + def sort_tag(content, **opts) + options = {} + options[:sort_by] = opts.delete(:name) + is_current_sort = params[:sort_by].to_s == options[:sort_by] + options[:sort_direction] = is_current_sort && params[:sort_direction].to_s == 'desc' ? 'asc' : 'desc' + + path = opts.delete(:path) + "?" + params.merge(options).to_query + arrow_class = case params[:sort_direction].to_s + when 'desc' then 'fa-long-arrow-down' + when 'asc' then 'fa-long-arrow-up' + else '' + end + + content_tag(:span, opts) do + link_to path, remote: true do + content += content_tag(:i, '', class: "fa color-light-green ml5 #{arrow_class}") if is_current_sort + raw content + end + end + end end def user_url_in_org(user_id) diff --git a/app/libs/custom_sortable.rb b/app/libs/custom_sortable.rb new file mode 100644 index 00000000..a127c9bd --- /dev/null +++ b/app/libs/custom_sortable.rb @@ -0,0 +1,45 @@ +module CustomSortable + extend ActiveSupport::Concern + + included do |base| + base.instance_variable_set("@_sort_options", {}) + base.instance_variable_set("@_sort_columns", []) + base.instance_variable_set("@_sort_directions", %w(asc desc)) + end + + def custom_sort(relations, sort_by, sort_direction) + 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) + + order_method = self.class.sort_options[:reorder] ? :reorder : :order + relations.send(order_method, "#{sort_by} #{sort_direction}") + end + + def multiple_custom_sort(relations, **opts) + opts.each do |sort_by, sort_direction| + relations = custom_sort(relations, sort_by, sort_direction) + end + relations + end + + module ClassMethods + def sort_columns(*columns) + opts = columns.extract_options! + @_sort_options[:default_by] = opts[:default_by].to_s + @_sort_options[:default_direction] = opts[:default_direction].to_s + @_sort_options[:reorder] = opts[:reorder] + + @_sort_columns = columns.map(&:to_s) + end + + def check_sort_parameter_validate(sort_by, sort_direction) + (sort_by.blank? || @_sort_columns.include?(sort_by)) && @_sort_directions.include?(sort_direction) + end + + def sort_options + @_sort_options + end + end +end diff --git a/app/services/management/school_report_service.rb b/app/services/management/school_report_service.rb new file mode 100644 index 00000000..f47230ac --- /dev/null +++ b/app/services/management/school_report_service.rb @@ -0,0 +1,58 @@ +class Management::SchoolReportService + include CustomSortable + + attr_reader :params + + sort_columns :student_count, :teacher_count, :homework_count, :other_homework_count, + :course_count, :active_course_count, :nearly_course_time, + default_by: :teacher_count, default_direction: :desc + + def initialize(params) + @params = params + end + + def call + schools = School.select(select_columns_sql) + + keyword = params[:keyword]&.to_s&.strip + if keyword.present? + schools = schools.where("schools.name LIKE :keyword OR schools.id LIKE :keyword", keyword: "%#{keyword}%") + end + + schools = custom_sort(schools, params[:sort_by], params[:sort_direction]) + + schools + end + + private + def select_columns_sql + <<-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} + ) 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} + ) teacher_count, + ( + SELECT COUNT(*) FROM homework_commons hc + LEFT JOIN courses ON courses.id = hc.course_id + WHERE courses.school_id = schools.id + ) homework_count, + ( + SELECT COUNT(*) FROM homework_commons hc + LEFT JOIN courses ON courses.id = hc.course_id + WHERE courses.school_id = schools.id AND hc.homework_type IN (1,3) + ) other_homework_count, + (SELECT COUNT(*) FROM courses cs WHERE cs.school_id = schools.id) course_count , + (SELECT MAX(cs.updated_at) FROM courses cs WHERE cs.school_id = schools.id) nearly_course_time , + (SELECT COUNT(*) FROM courses acs WHERE acs.school_id = schools.id AND acs.is_end = false) active_course_count + SQL + end +end diff --git a/app/views/layouts/base_management.html.erb b/app/views/layouts/base_management.html.erb index 86cdbe60..c38bf3eb 100644 --- a/app/views/layouts/base_management.html.erb +++ b/app/views/layouts/base_management.html.erb @@ -32,6 +32,11 @@

      +
    • 学校+ +
        +
      • <%= link_to '统计总表', school_report_managements_path %>
      • +
      +
    • 课堂+
      • <%= link_to "课程列表", classroom_managements_path %>
      • diff --git a/app/views/managements/schools/_statistics_list.html.erb b/app/views/managements/schools/_statistics_list.html.erb new file mode 100644 index 00000000..1675e6f1 --- /dev/null +++ b/app/views/managements/schools/_statistics_list.html.erb @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + <% @schools.as_json.each_with_index do |data, index| %> + + <% school = data["school"] %> + + + + + + + + + + + + <% end %> + +
        序号ID单位名称<%= sort_tag('教师总人数', name: 'teacher_count', path: school_report_managements_path) %><%= sort_tag('学生总人数', name: 'student_count', path: school_report_managements_path) %><%= sort_tag('课堂总数', name: 'course_count', path: school_report_managements_path) %><%= sort_tag('正在进行课堂数', name: 'active_course_count', path: school_report_managements_path) %><%= sort_tag('实训作业总数', name: 'homework_count', path: school_report_managements_path) %><%= sort_tag('其它作业总数', name: 'other_homework_count', path: school_report_managements_path) %><%= sort_tag('动态时间', name: 'nearly_course_time', path: school_report_managements_path) %>
        <%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %><%= school['id'] %><%= school['name'] %><%= school['teacher_count'] %><%= school['student_count'] %><%= school['course_count'] %><%= school['active_course_count'] %><%= school['homework_count'] %><%= school['other_homework_count'] %><%= format_time school['nearly_course_time'] %>
        + +
        +
        +
          + <%= pagination_links_full @obj_pages, @obj_count, per_page_links: false, remote: true, flag: true, is_new: true, path: school_report_managements_path(params.except(:page)) %> +
        +
        +
        +
        \ No newline at end of file diff --git a/app/views/managements/schools/statistics.html.erb b/app/views/managements/schools/statistics.html.erb new file mode 100644 index 00000000..1597fe45 --- /dev/null +++ b/app/views/managements/schools/statistics.html.erb @@ -0,0 +1,19 @@ +
        + <%= form_tag(school_report_managements_path(params), method: :get, remote: true, id: 'school_report_search_form') do %> + <%= 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', onclick: "$('#school_report_search_form').submit();" %> + <%= link_to '清除', 'javascript:clearSearchCondition()', class: 'fl task-btn ml5 mt2 mt10' %> + <% end %> +
        + +
        + <%= render 'managements/schools/statistics_list'%> +
        + + \ No newline at end of file diff --git a/app/views/managements/schools/statistics.js.erb b/app/views/managements/schools/statistics.js.erb new file mode 100644 index 00000000..d4152eb7 --- /dev/null +++ b/app/views/managements/schools/statistics.js.erb @@ -0,0 +1 @@ +$("#managements_school_report").html("<%= j(render 'managements/schools/statistics_list') %>") \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index ea70b6a2..9c70df82 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -720,6 +720,7 @@ RedmineApp::Application.routes.draw do ## oauth相关 post :add_customers delete :delete_customers get :customers_list + get :school_report, controller: 'managements::schools', action: 'statistics' end end # Enable Grack support diff --git a/public/javascripts/educoder/edu_application.js b/public/javascripts/educoder/edu_application.js index 862f9d41..01daa18d 100644 --- a/public/javascripts/educoder/edu_application.js +++ b/public/javascripts/educoder/edu_application.js @@ -158,7 +158,8 @@ $(function(){ } var new_href = href.replace(/page=(\d*)/, 'page=' + page); console.log(new_href); - $.get(new_href); + // $.get(new_href); + $.ajax({url: new_href, dataType: 'script'}) return false; } } From 44dadbc1733a83d18b1c9fdba5601f325452f51f Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 25 Apr 2019 08:54:39 +0800 Subject: [PATCH 05/69] fix ruby version not support ** operation --- app/helpers/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6bc8f9f6..c02f7e5a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -5515,7 +5515,7 @@ challengeProgramNames=(CHALLENGEPROGRAMNAMES)" end end - def sort_tag(content, **opts) + def sort_tag(content, opts) options = {} options[:sort_by] = opts.delete(:name) is_current_sort = params[:sort_by].to_s == options[:sort_by] From c9ed7351396aa0ecf88ceb931dd99bec1041fe47 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Thu, 25 Apr 2019 09:08:15 +0800 Subject: [PATCH 06/69] removeExceptGitDir --- public/react/scripts/build.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/public/react/scripts/build.js b/public/react/scripts/build.js index eb5bcbae..cf7c1377 100644 --- a/public/react/scripts/build.js +++ b/public/react/scripts/build.js @@ -43,13 +43,29 @@ if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) { process.exit(1); } +function removeExceptGitDir(dir) { + fs2.readdir(dir, function(err, list) { + if (err) return done(err); + var pending = list.length; + if (!pending) return done(null, results); + list.forEach(function(file) { + if (file.indexOf('.git') == -1) { + file = path.resolve(dir, file); + fs.remove(file) + } + }); + }); +} + // First, read the current file sizes in build directory. // This lets us display how much they changed later. measureFileSizesBeforeBuild(paths.appBuild) .then(previousFileSizes => { // Remove all content but keep the directory so that // if you're in it, you don't end up in Trash - fs.emptyDirSync(paths.appBuild); + // fs.emptyDirSync(paths.appBuild); + removeExceptGitDir(paths.appBuild) + // Merge with the public folder copyPublicFolder(); // Start the webpack build From f1b1ea0cd300fa335946a3758d85be897e1179fc Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 25 Apr 2019 09:33:14 +0800 Subject: [PATCH 07/69] fix not support &. operation in low ruby version --- app/services/management/school_report_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/management/school_report_service.rb b/app/services/management/school_report_service.rb index f47230ac..9b794b7b 100644 --- a/app/services/management/school_report_service.rb +++ b/app/services/management/school_report_service.rb @@ -14,7 +14,7 @@ class Management::SchoolReportService def call schools = School.select(select_columns_sql) - keyword = params[:keyword]&.to_s&.strip + keyword = params[:keyword].try(:to_s).try(:strip) if keyword.present? schools = schools.where("schools.name LIKE :keyword OR schools.id LIKE :keyword", keyword: "%#{keyword}%") end From f37d02bcfb93552a2f238c61ae2dddd0fb2d530d Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 25 Apr 2019 09:45:50 +0800 Subject: [PATCH 08/69] fix low ruby version support bug --- app/libs/custom_sortable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/libs/custom_sortable.rb b/app/libs/custom_sortable.rb index a127c9bd..721cbd1e 100644 --- a/app/libs/custom_sortable.rb +++ b/app/libs/custom_sortable.rb @@ -17,7 +17,7 @@ module CustomSortable relations.send(order_method, "#{sort_by} #{sort_direction}") end - def multiple_custom_sort(relations, **opts) + def multiple_custom_sort(relations, opts) opts.each do |sort_by, sort_direction| relations = custom_sort(relations, sort_by, sort_direction) end From 085e1ec44d817b348c557b84e6ad19e895760720 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 26 Apr 2019 09:56:27 +0800 Subject: [PATCH 09/69] =?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 c140b70818685e7409c13550a1dfcd917bccb9a9 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 26 Apr 2019 10:07:27 +0800 Subject: [PATCH 10/69] =?UTF-8?q?=E5=90=88=E4=BD=9C=E4=BC=99=E4=BC=B4?= =?UTF-8?q?=E6=94=B9=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/managements_controller.rb | 49 ++++++++++--------- app/models/customer.rb | 5 +- app/models/partner.rb | 5 +- app/models/partner_customer.rb | 5 ++ app/models/school.rb | 4 +- .../_partner_customer_list.html.erb | 2 +- app/views/managements/_partner_list.html.erb | 8 ++- app/views/managements/delete_partner.js.erb | 1 + app/views/managements/partners.html.erb | 6 +-- config/routes.rb | 1 + ...20190425072918_create_partner_customers.rb | 9 ++++ ...90425073328_modify_partner_and_customer.rb | 29 +++++++++++ spec/factories/partner_customers.rb | 5 ++ spec/models/partner_customer_spec.rb | 5 ++ 14 files changed, 97 insertions(+), 37 deletions(-) create mode 100644 app/models/partner_customer.rb create mode 100644 app/views/managements/delete_partner.js.erb create mode 100644 db/migrate/20190425072918_create_partner_customers.rb create mode 100644 db/migrate/20190425073328_modify_partner_and_customer.rb create mode 100644 spec/factories/partner_customers.rb create mode 100644 spec/models/partner_customer_spec.rb diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index b7e1bd56..1c454424 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -1191,7 +1191,7 @@ end if params[:search].blank? @partners = Partner.includes(:school).order("partners.created_at desc") else - @partners = Partner.where("name like ? ", "%#{params[:search]}%").includes(:school).order("partners.created_at desc") + @partners = Partner.includes(:school).where("schools.name like ? ", "%#{params[:search]}%").order("partners.created_at desc") end @current_partner = nil @@ -1212,6 +1212,14 @@ end end + def delete_partner + partner = Partner.find params[:partner_id] + partner.destroy + @partners = Partner.includes(:school).order("partners.created_at desc") + @current_partner = nil + end + + # 添加客户 def customers_list @search = params[:search] @@ -1219,11 +1227,10 @@ end partner_id = params[:partner_id] @partner = Partner.find partner_id @customers = @partner.customers - if @customers.present? - @schools = School.where("(partner_id != ? or partner_id is NULL) and customer_id is NULL", @partner.id) - else - @schools = School.where("customer_id is null and (partner_id != ? or partner_id is NULL)", @partner.id) - end + existed_school_ids = @customers.pluck(:school_id) + existed_school_ids = existed_school_ids.present? ? existed_school_ids.join(",") : -1 + @schools = School.where("id not in (#{existed_school_ids})") + if params[:search] @schools = @schools.where("name like ?", "%#{@search}%") end @@ -1247,13 +1254,14 @@ end def add_customers school_ids = params[:school_ids] - if school_ids.length > 0 + partner_id = params[:partner_id] + if school_ids.length > 0 && partner_id.present? school_ids.each do |s| school = School.where("id = ?",s).first if school.present? - customer = Customer.new(partner_id: params[:partner_id]) + customer = Customer.new(school_id: s) customer.save! - school.update_attributes(:customer_id => customer.id) + PartnerCustomer.create(partner_id: partner_id,customer_id: customer.id ) end end render :json => {status: 1, message: "创建成功!"} @@ -1262,17 +1270,20 @@ end def delete_customers if params[:customer] - customer = Customer.where(id: params[:customer]).first - @current_partner = customer.partner - customer.school.update_attributes(:customer_id => nil) + customer = Customer.find(params[:customer]) + @current_partner = Partner.find(params[:partner_id]) customer.destroy end end + # 添加合作伙伴弹框数据 def all_partners @search = params[:search] @province = params[:province] - @schools = School.where("partner_id IS NULL") + # 已经选过的合作伙伴不能再再列表中显示 + used_school_ids = Partner.pluck(:school_id) + used_school_ids = used_school_ids.blank? ? -1 : used_school_ids.join(",") + @schools = School.where("id not in (#{used_school_ids})") if params[:search] @schools = @schools.where("name like ?", "%#{@search}%") @@ -1296,26 +1307,20 @@ end end end - def add_partner school_ids = params[:school_ids] if school_ids.length > 0 school_ids.each do |s| - school = School.where("id = ?",s).first - if school.present? && school.partner_id.nil? - partner = Partner.new(name: school.name) + old_partner = Partner.where(:school_id => s) + if old_partner.blank? + partner = Partner.new(school_id: s) partner.save - school.update_attributes(:partner_id => partner.id) end end end render :json => {status: 1, message: "创建成功!"} end - - - - # 删除部门管理员 def delete_depart_member DepartmentMember.where(:department_id => params[:depart], :user_id => params[:user_id]).destroy_all diff --git a/app/models/customer.rb b/app/models/customer.rb index 673acd20..14b4d710 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,6 +1,7 @@ class Customer < ActiveRecord::Base default_scope :order => 'customers.created_at desc' - belongs_to :partner - has_one :school + has_many :partners, :through => :partner_customers + has_many :partner_customers, :dependent => :destroy + belongs_to :school has_many :users end diff --git a/app/models/partner.rb b/app/models/partner.rb index 217bc1a7..31920e53 100644 --- a/app/models/partner.rb +++ b/app/models/partner.rb @@ -2,7 +2,8 @@ class Partner < ActiveRecord::Base # attr_accessible :name, :active attr_accessor :active - has_one :school - has_many :customers + belongs_to :school + has_many :customers, :through => :partner_customers + has_many :partner_customers, :dependent => :destroy has_many :users end diff --git a/app/models/partner_customer.rb b/app/models/partner_customer.rb new file mode 100644 index 00000000..c9894cc9 --- /dev/null +++ b/app/models/partner_customer.rb @@ -0,0 +1,5 @@ +class PartnerCustomer < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :partner + belongs_to :customer +end diff --git a/app/models/school.rb b/app/models/school.rb index 8d377e97..021048fb 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -16,8 +16,8 @@ class School < ActiveRecord::Base has_many :ec_majors, :through => :ec_major_schools has_many :ec_major_schools, :dependent => :destroy - belongs_to :partner - belongs_to :customer + has_many :partners, :dependent => :destroy + has_many :customers, :dependent => :destroy # banner图片信息 has_many :school_images, :dependent => :destroy diff --git a/app/views/managements/_partner_customer_list.html.erb b/app/views/managements/_partner_customer_list.html.erb index e8f643fd..bbdb2ea8 100644 --- a/app/views/managements/_partner_customer_list.html.erb +++ b/app/views/managements/_partner_customer_list.html.erb @@ -10,7 +10,7 @@ <%= index + 1 %> <%= customer.school.name %> - 删除 diff --git a/app/views/managements/_partner_list.html.erb b/app/views/managements/_partner_list.html.erb index 0ee0a60f..cddf4e9d 100644 --- a/app/views/managements/_partner_list.html.erb +++ b/app/views/managements/_partner_list.html.erb @@ -1,14 +1,12 @@ <% @partners.each_with_index do |partner,index| %>
      • - <%= link_to "#{partner.name}", partners_managements_path(:partner => partner), :class => "#{partner.id == @current_partner.id ? 'active' : ''} fl" %> - <% if false %> + <%= link_to "#{partner.school.name}", partners_managements_path(:partner => partner), :class => "#{@current_partner && partner.id == @current_partner.id ? 'active' : ''} fl" %> - <% end %>
      • <% end %> diff --git a/app/views/managements/delete_partner.js.erb b/app/views/managements/delete_partner.js.erb new file mode 100644 index 00000000..276ae32b --- /dev/null +++ b/app/views/managements/delete_partner.js.erb @@ -0,0 +1 @@ +$("#partner_list").html("<%= j(render :partial => "partner_list") %>") \ No newline at end of file diff --git a/app/views/managements/partners.html.erb b/app/views/managements/partners.html.erb index 153ab505..06ac63b0 100644 --- a/app/views/managements/partners.html.erb +++ b/app/views/managements/partners.html.erb @@ -6,7 +6,7 @@
        - <%= link_to "+添加",all_partners_managements_path,remote:true,class:"color-blue addOperation" %> + <%= link_to "+添加", all_partners_managements_path,remote:true,class:"color-blue addOperation" %>
          <%= render :partial => "partner_list" %>
        @@ -31,7 +31,7 @@ } - function delPartners(){ - delete_confirm_box_2("","确定删除合作伙伴?"); + function delPartners(url){ + delete_confirm_box_2(url,"确定删除合作伙伴?"); } \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9c70df82..73cbadc6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -719,6 +719,7 @@ RedmineApp::Application.routes.draw do ## oauth相关 post 'update_level_for_subject' post :add_customers delete :delete_customers + delete :delete_partner get :customers_list get :school_report, controller: 'managements::schools', action: 'statistics' end diff --git a/db/migrate/20190425072918_create_partner_customers.rb b/db/migrate/20190425072918_create_partner_customers.rb new file mode 100644 index 00000000..69d13714 --- /dev/null +++ b/db/migrate/20190425072918_create_partner_customers.rb @@ -0,0 +1,9 @@ +class CreatePartnerCustomers < ActiveRecord::Migration + def change + create_table :partner_customers do |t| + t.references :partner + t.references :customer + t.timestamps + end + end +end diff --git a/db/migrate/20190425073328_modify_partner_and_customer.rb b/db/migrate/20190425073328_modify_partner_and_customer.rb new file mode 100644 index 00000000..c4f7b97a --- /dev/null +++ b/db/migrate/20190425073328_modify_partner_and_customer.rb @@ -0,0 +1,29 @@ +class ModifyPartnerAndCustomer < ActiveRecord::Migration + def up + add_column :customers, :school_id, :integer + add_column :partners, :school_id, :integer + + schools = School.where("customer_id is not null or partner_id is not null") + + schools.each do |school| + if school.customer_id + customer = Customer.find_by_id(school.customer_id) + customer.update_column(:school_id, school.id) if customer + end + if school.partner_id + partner = Partner.find_by_id(school.partner_id) + partner.update_column(:school_id, school.id) if partner + end + end + + # 迁移关联关系 + customers = Customer.where(nil) + customers.each do |customer| + PartnerCustomer.create(partner_id: customer.partner_id, customer_id: customer.id) + end + + end + + def down + end +end diff --git a/spec/factories/partner_customers.rb b/spec/factories/partner_customers.rb new file mode 100644 index 00000000..6327b7ca --- /dev/null +++ b/spec/factories/partner_customers.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :partner_customer do + + end +end diff --git a/spec/models/partner_customer_spec.rb b/spec/models/partner_customer_spec.rb new file mode 100644 index 00000000..6dc614cf --- /dev/null +++ b/spec/models/partner_customer_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe PartnerCustomer, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 95e1bc759c099be0faecded8adcecf7b0611f78b Mon Sep 17 00:00:00 2001 From: Alec Zhou Date: Fri, 26 Apr 2019 16:49:48 +0800 Subject: [PATCH 11/69] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86openi=E5=8D=95?= =?UTF-8?q?=E7=82=B9=E7=99=BB=E5=BD=95=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 + app/controllers/application_controller.rb | 21 ++++++++ app/controllers/oauth_controller.rb | 58 +++++++++++++++++++++- app/controllers/shixuns_controller.rb | 2 + app/controllers/subjects_controller.rb | 2 + app/models/openi.rb | 8 +++ config/routes.rb | 3 ++ db/migrate/20190426072359_create_openis.rb | 15 ++++++ spec/factories/openis.rb | 11 ++++ spec/models/openi_spec.rb | 5 ++ 10 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 app/models/openi.rb create mode 100644 db/migrate/20190426072359_create_openis.rb create mode 100644 spec/factories/openis.rb create mode 100644 spec/models/openi_spec.rb diff --git a/Gemfile b/Gemfile index a5bf637a..b9e1b4e2 100644 --- a/Gemfile +++ b/Gemfile @@ -60,6 +60,8 @@ gem 'kaminari' gem 'elasticsearch-model' gem 'elasticsearch-rails' +gem 'oauth2' + #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/application_controller.rb b/app/controllers/application_controller.rb index 5e107d39..22888abb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1120,4 +1120,25 @@ class ApplicationController < ActionController::Base Time.now < Time.new(2019, 4, 23, 2) end + # 获取Oauth Client + def get_client(site) + client_id = Redmine::Configuration['client_id'] + client_secret = Redmine::Configuration['client_secret'] + + OAuth2::Client.new(client_id, client_secret, site: site) + end + + def handle_openi_request + site = Redmine::Configuration['openi_domain'] + root_url = Redmine::Configuration['educoder_domain'] + get_code_url = "/oauth/get_code" + original_url = request.original_url + + client = get_client(site) + redirect_uri = "#{root_url}#{get_code_url}" + authorize_url = client.auth_code.authorize_url(redirect_uri: redirect_uri) + authorize_url = authorize_url + "&gen_code=true&state=1&original_url=#{original_url}" + + redirect_to authorize_url + end end diff --git a/app/controllers/oauth_controller.rb b/app/controllers/oauth_controller.rb index 54f15c43..64867d55 100644 --- a/app/controllers/oauth_controller.rb +++ b/app/controllers/oauth_controller.rb @@ -1,6 +1,5 @@ #encoding: utf-8 class OauthController < ApplicationController - require include ApplicationHelper before_filter :user_setup @@ -152,8 +151,65 @@ class OauthController < ApplicationController render json: user_info.to_json end + ####--Start-- 获取Openi的授权码,access_token,以及用户信息。为在openi登录的用户创建相关的educoder用户 #### + IDENTITY_SITE = Redmine::Configuration['openi_domain'] + ROOT_URL = Redmine::Configuration['educoder_domain'] + DEFAULT_PASSWORD = "a12345678" + TOKEN_CALL_BACK = "/oauth/get_token_callback" + USER_INFO = "/oauth/userinfo" + + def get_code + # 从OpenI发过来的回调中获取授权码 + code = params[:code] + + # 利用授权码从OpenI这里获取access_token + client = get_client(IDENTITY_SITE) + redirect_uri = "#{ROOT_URL}#{TOKEN_CALL_BACK}" + access_token_hash = client.auth_code.get_token(code, redirect_uri: redirect_uri).to_hash + + # 利用access_token获取OpenI的用户信息 + access_token = access_token_hash[:access_token] + get_info_url = "#{IDENTITY_SITE}#{USER_INFO}?access_token=#{access_token}" + response = HTTParty.get(get_info_url) + body_json = JSON.parse response.body + + openi_user_id = body_json['token'] + avatar_url = body_json['avatar_url'] + login = body_json['login'] + name = body_json['name'] + email = body_json['email'] + + # 根据获取的用户信息来查询数据库,如已经存在对应的Educoder用户,则直接访问用户要访问的实训页面,否则为其创建用户后再访问实训页面 + openi = Openi.find_by_login(login) + unless openi + ActiveRecord::Base.transaction do + user = User.new(lastname: name, mail: email, mail_notification: email) + user.login = custom_openi_login(login) + user.password = DEFAULT_PASSWORD + user.save! + + UserExtensions.create!(user_id: user.id, school_id: School.first.id, identity: 4, gender: 0) + + UserDayCertification.create!(user_id: user.id, status: 1) + + openi = Openi.create!(user_id: user.id, openi_user_id: openi_user_id, avatar_url: avatar_url, login: login, name: name, email: email) + end + end + + self.logged_user = openi.user + original_url = params[:original_url] + redirect_to original_url + end + + def get_token_callback + end + ####--End-- 获取Openi的授权码,access_token,以及用户信息。为在openi登录的用户创建相关的educoder用户 #### private + # 为了保证新创建的用户用户名不与系统中已存在的用户冲突,加上 _openi 后缀 + def custom_openi_login(login) + login + "_openi" + end def require_login require "base64" diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index b2761b60..0572f8fa 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -2,6 +2,8 @@ # REDO: 创建版本库权限控制 class ShixunsController < ApplicationController layout 'base_shixun' + # 如要添加或修改before_filter时,请将handle_openi_request这个before_filter放至第一位 + before_filter :handle_openi_request, if: -> {URI(request.referer).host == 'openi.org.cn' && !current_user.logged?} before_filter :require_login, :except => [:ghook, :download_file, :show, :index] before_filter :check_authentication, :except => [:ghook, :download_file, :show, :index] before_filter :find_shixun, :except => [ :index, :new, :create, :index, :search, :shixun_courses, :new_disscuss, :shixun_migrate, :qrcode, :download_file, :departments, :get_mirror_script, :send_message_to_administrator] diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index a59747aa..2db71ee7 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -1,6 +1,8 @@ # encoding: utf-8 class SubjectsController < ApplicationController layout 'base_subject' + # 如要添加或修改before_filter时,请将handle_openi_request这个before_filter放至第一位 + before_filter :handle_openi_request, if: -> {URI(request.referer).host == 'openi.org.cn' && !current_user.logged?} before_filter :require_login, :except => [:show, :index] before_filter :check_authentication, :except => [:show, :index] before_filter :find_subject, :except => [:index, :new, :create, :create_subject, :new_subject, :append_to_stage, :send_to_course] diff --git a/app/models/openi.rb b/app/models/openi.rb new file mode 100644 index 00000000..44e7ac83 --- /dev/null +++ b/app/models/openi.rb @@ -0,0 +1,8 @@ +class Openi < ActiveRecord::Base + attr_accessible :allow, :avatar_url, :email, :login, :name, :openi_user_id, :user_id + belongs_to :user + + def self.find_by_login(login) + Openi.where(login: login).first + end +end diff --git a/config/routes.rb b/config/routes.rb index 73cbadc6..9e0879e7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,6 +33,9 @@ RedmineApp::Application.routes.draw do ## oauth相关 match 'oauth/cb', to: 'oauth#test_callback', :via => :get match 'oauth/userinfo', to: 'oauth#get_userinfo', :via => :get + match 'oauth/get_code', to: 'oauth#get_code', :via => :get + match 'oauth/get_token_callback', to: 'oauth#get_token_callback', :via => :get + get 'ecloud/ecloud_login', to: 'ecloud#ecloud_login_callback' post 'ecloud/bs_new', to: 'ecloud#bs_new' post 'ecloud/bs_update', to: 'ecloud#bs_update' diff --git a/db/migrate/20190426072359_create_openis.rb b/db/migrate/20190426072359_create_openis.rb new file mode 100644 index 00000000..501b3fe7 --- /dev/null +++ b/db/migrate/20190426072359_create_openis.rb @@ -0,0 +1,15 @@ +class CreateOpenis < ActiveRecord::Migration + def change + create_table :openis do |t| + t.integer :user_id + t.integer :openi_user_id + t.string :login + t.string :avatar_url + t.string :name + t.string :email + t.integer :allow + + t.timestamps + end + end +end diff --git a/spec/factories/openis.rb b/spec/factories/openis.rb new file mode 100644 index 00000000..06f8944d --- /dev/null +++ b/spec/factories/openis.rb @@ -0,0 +1,11 @@ +FactoryGirl.define do + factory :openi do + user_id 1 + openi_user_id 1 + login "MyString" + avatar_url "MyString" + name "MyString" + email "MyString" + allow 1 + end +end diff --git a/spec/models/openi_spec.rb b/spec/models/openi_spec.rb new file mode 100644 index 00000000..96e0c489 --- /dev/null +++ b/spec/models/openi_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Openi, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 7104eee0c5d331168c30c0b458a5ca8202e6ebe4 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 26 Apr 2019 16:55:44 +0800 Subject: [PATCH 12/69] =?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 13/69] 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 14/69] =?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;"> + + +
      • name="business" value="<%= @user.business? ? 1 : 0 %>" id="person_9" class="magic-checkbox" style="float:left; margin-top: 8px;"> - + name="business" value="<%= @user.business? ? "1" : "0" %>" id="person_business" class="magic-checkbox" style="float:left; margin-top: 8px;"> +
      • From c349dd1621d14854ddbcd43ab239aa1ffbc69143 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 27 Apr 2019 10:45:43 +0800 Subject: [PATCH 21/69] .. --- app/controllers/welcome_controller.rb | 2 +- app/views/layouts/base_edu_user.html.erb | 36 ++++++++++++++++++------ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 729a9564..c9d41c0a 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 => 'base_local' + render :layout => 'educoder' end # 自动导入用户 diff --git a/app/views/layouts/base_edu_user.html.erb b/app/views/layouts/base_edu_user.html.erb index 37ba85ca..8de851ea 100644 --- a/app/views/layouts/base_edu_user.html.erb +++ b/app/views/layouts/base_edu_user.html.erb @@ -7,23 +7,43 @@ <%= csrf_meta_tag %> <%= favicon %> - <%= stylesheet_link_tag 'css/font-awesome','educoder/edu-main','educoder/edu-all','/assets/iconfont/iconfont.css', :media => 'all' %> + <%= 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 -%> + + + + -
        -
        - <%= render :partial => 'layouts/logined_header' %> +
        +
        + <% if User.current.logged? %> + <%= render :partial => 'layouts/logined_header' %> + <% else%> + <%= render :partial => 'layouts/unlogin_header' %> + <% end%>
        -
        +
        <%= yield %>
        - + <%= render :partial => 'users/returnTop_btn' %>
        - + + <%#= render :partial => 'layouts/public_left_info' %> <%= render :partial => 'layouts/footer' %>
        @@ -35,6 +55,4 @@
        -<%= javascript_heads_local %> -<%= javascript_include_tag 'edu/application', 'educoder/edu_application',"educoder/edu_user" %> \ No newline at end of file From 01017c3bd32cc33c5e0710b6f822d4354f177d6c Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 27 Apr 2019 11:01:27 +0800 Subject: [PATCH 22/69] =?UTF-8?q?checkout=20box=E9=80=89=E6=8B=A9=E8=BF=90?= =?UTF-8?q?=E8=90=A5=E4=BA=BA=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/managements/update_user.html.erb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/views/managements/update_user.html.erb b/app/views/managements/update_user.html.erb index 3203614d..554ea2a2 100644 --- a/app/views/managements/update_user.html.erb +++ b/app/views/managements/update_user.html.erb @@ -188,7 +188,7 @@ name="business" value="<%= @user.business? ? "1" : "0" %>" id="person_business" class="magic-checkbox" style="float:left; margin-top: 8px;"> - +
      • @@ -621,6 +621,13 @@ $("#user_form_link").on("click",function(){ + var check = document.getElementById('person_business').checked; + if(check){ + document.getElementById('person_business').value = "1"; + }else{ + document.getElementById('person_business').value = "0"; + } + my_account_form_submit(); }); function my_account_form_submit(){ From f103d0fe23012a7effee5dbd6d953edaed9fd401 Mon Sep 17 00:00:00 2001 From: Alec Zhou Date: Sat, 27 Apr 2019 11:04:10 +0800 Subject: [PATCH 23/69] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E6=9D=A5=E6=BA=90=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a143b03e..533cead1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1151,7 +1151,7 @@ class ApplicationController < ActionController::Base def user_login_and_from_openi url = request.referer.nil? ? Redmine::Configuration['educoder_domain'] : request.referer - flag = URI(url).host == 'localhost' && !current_user.logged? + flag = URI(url).host == URI(Redmine::Configuration['openi_domain']).host && !current_user.logged? logger.info "----------------------- #{url} -------------------------" logger.info "----------------------- #{URI(url).host} --------------------------" logger.info "----------------------- #{flag} -------------------------" From 26455d0efb085c82a3040a61d825f17b329a28bf Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 27 Apr 2019 11:20:12 +0800 Subject: [PATCH 24/69] add index to fix order slow issue --- app/services/management/school_data_contrast_service.rb | 8 +++----- .../20190427025209_add_index_to_school_daily_reports.rb | 9 +++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20190427025209_add_index_to_school_daily_reports.rb diff --git a/app/services/management/school_data_contrast_service.rb b/app/services/management/school_data_contrast_service.rb index 9390e46f..47c7f117 100644 --- a/app/services/management/school_data_contrast_service.rb +++ b/app/services/management/school_data_contrast_service.rb @@ -24,10 +24,8 @@ class Management::SchoolDataContrastService reports = reports.where("school_name LIKE :keyword OR school_id LIKE :keyword", keyword: "%#{keyword}%") end - reports = reports.group(:school_id) - count = reports.count.count - - reports = reports.limit(PAGE_SIZE).offset(offset) + count = reports.count('distinct(school_id)') + reports = reports.group(:school_id).limit(PAGE_SIZE).offset(offset) [count, reports] end @@ -56,7 +54,7 @@ class Management::SchoolDataContrastService end def select_columns - "school_id, school_name,"\ + "school_id, school_name, @total:=0, @other_total:=0,"\ "(@total:=SUM(IF(date BETWEEN '#{format_date(params[:begin_date])}' AND '#{format_date(params[:end_date])}', #{contrast_column}, 0))) total,"\ "(@other_total:=SUM(IF(date BETWEEN '#{format_date(params[:other_begin_date])}' AND '#{format_date(params[:other_end_date])}', #{contrast_column}, 0))) other_total,"\ "(IF(@other_total - @total = 0, 0.0, round((@other_total - @total) / IF(@total = 0, 1, @total), 5))) percentage,"\ diff --git a/db/migrate/20190427025209_add_index_to_school_daily_reports.rb b/db/migrate/20190427025209_add_index_to_school_daily_reports.rb new file mode 100644 index 00000000..5cfc2796 --- /dev/null +++ b/db/migrate/20190427025209_add_index_to_school_daily_reports.rb @@ -0,0 +1,9 @@ +class AddIndexToSchoolDailyReports < ActiveRecord::Migration + def change + add_index :school_daily_reports, [:date, :teacher_increase_count] + add_index :school_daily_reports, [:date, :student_increase_count] + add_index :school_daily_reports, [:date, :course_increase_count] + add_index :school_daily_reports, [:date, :shixun_increase_count] + add_index :school_daily_reports, [:date, :active_user_count] + end +end From 58a278f5838a93286770a02ff9d8d772a0253a4b Mon Sep 17 00:00:00 2001 From: Alec Zhou Date: Sat, 27 Apr 2019 11:33:06 +0800 Subject: [PATCH 25/69] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 533cead1..b1a66080 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1152,9 +1152,10 @@ class ApplicationController < ActionController::Base def user_login_and_from_openi url = request.referer.nil? ? Redmine::Configuration['educoder_domain'] : request.referer flag = URI(url).host == URI(Redmine::Configuration['openi_domain']).host && !current_user.logged? - logger.info "----------------------- #{url} -------------------------" - logger.info "----------------------- #{URI(url).host} --------------------------" - logger.info "----------------------- #{flag} -------------------------" + logger.info "----------------------- request referer: #{request.referer} -------------------------" + logger.info "----------------------- url after processed: #{url} -------------------------" + logger.info "----------------------- host: #{URI(url).host} --------------------------" + logger.info "----------------------- handle_flag: #{flag} -------------------------" flag end end From 92451b97205f57f66ed7d813b6c33c3c0d9f1e19 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 27 Apr 2019 11:39:25 +0800 Subject: [PATCH 26/69] fix issue --- app/controllers/managements/base_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/managements/base_controller.rb b/app/controllers/managements/base_controller.rb index cbb61c33..8d5ada3b 100644 --- a/app/controllers/managements/base_controller.rb +++ b/app/controllers/managements/base_controller.rb @@ -1,5 +1,5 @@ class Managements::BaseController < ApplicationController layout 'base_management' - before_filter :require_admin + before_filter :require_business end \ No newline at end of file From d067d4dbeddb312425f0e015b2dd0d17b658606d Mon Sep 17 00:00:00 2001 From: Alec Zhou Date: Sat, 27 Apr 2019 12:21:57 +0800 Subject: [PATCH 27/69] =?UTF-8?q?=E5=B0=86request.referer=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BArequest.original=5Furl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b1a66080..3e456b8f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1150,9 +1150,9 @@ class ApplicationController < ActionController::Base end def user_login_and_from_openi - url = request.referer.nil? ? Redmine::Configuration['educoder_domain'] : request.referer + url = request.original_url.nil? ? Redmine::Configuration['educoder_domain'] : request.original_url flag = URI(url).host == URI(Redmine::Configuration['openi_domain']).host && !current_user.logged? - logger.info "----------------------- request referer: #{request.referer} -------------------------" + logger.info "----------------------- request referer: #{request.original_url} -------------------------" logger.info "----------------------- url after processed: #{url} -------------------------" logger.info "----------------------- host: #{URI(url).host} --------------------------" logger.info "----------------------- handle_flag: #{flag} -------------------------" From c1b3dfadd2e53062a892dc036bc401bad924ce46 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Sat, 27 Apr 2019 14:04:04 +0800 Subject: [PATCH 28/69] removeExceptGitDir --- public/react/scripts/build.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/public/react/scripts/build.js b/public/react/scripts/build.js index cf7c1377..6dd9d3e5 100644 --- a/public/react/scripts/build.js +++ b/public/react/scripts/build.js @@ -44,16 +44,16 @@ if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) { } function removeExceptGitDir(dir) { - fs2.readdir(dir, function(err, list) { - if (err) return done(err); - var pending = list.length; - if (!pending) return done(null, results); - list.forEach(function(file) { - if (file.indexOf('.git') == -1) { - file = path.resolve(dir, file); - fs.remove(file) - } - }); + // readdirSync + const list = fs2.readdirSync(dir) + // if (err) return done(err); + var pending = list.length; + // if (!pending) return done(null, results); + list.forEach(function(file) { + if (file.indexOf('.git') == -1) { + file = path.resolve(dir, file); + fs.removeSync(file) + } }); } @@ -202,6 +202,14 @@ function generateNewIndexJsp() { fs2.writeFile(outputPath, result, 'utf8', function (err) { if (err) return console.log(err); + commitAndPush(); }); }); +} + +function commitAndPush() { + var exec = require('child_process').exec; + function puts(error, stdout, stderr) { console.log(stdout) } + var options = {cwd:"./build"}; + exec("git status && git commit -am 'b' && git push", options, puts); } \ No newline at end of file From 0cea78e89e46374c8c9b18aa183d6cf6875df2d3 Mon Sep 17 00:00:00 2001 From: Alec Zhou Date: Sat, 27 Apr 2019 14:34:02 +0800 Subject: [PATCH 29/69] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E8=8E=B7?= =?UTF-8?q?=E5=8F=96referer=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3e456b8f..b1a66080 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1150,9 +1150,9 @@ class ApplicationController < ActionController::Base end def user_login_and_from_openi - url = request.original_url.nil? ? Redmine::Configuration['educoder_domain'] : request.original_url + url = request.referer.nil? ? Redmine::Configuration['educoder_domain'] : request.referer flag = URI(url).host == URI(Redmine::Configuration['openi_domain']).host && !current_user.logged? - logger.info "----------------------- request referer: #{request.original_url} -------------------------" + logger.info "----------------------- request referer: #{request.referer} -------------------------" logger.info "----------------------- url after processed: #{url} -------------------------" logger.info "----------------------- host: #{URI(url).host} --------------------------" logger.info "----------------------- handle_flag: #{flag} -------------------------" From 35ec3b1744a04a2185cb49740fe4162236f31719 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 27 Apr 2019 14:47:18 +0800 Subject: [PATCH 30/69] fix school data contrast percentage zero issue --- .../school_data_contrast_service.rb | 8 +++--- .../schools/_data_contrast_list.html.erb | 27 ++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/app/services/management/school_data_contrast_service.rb b/app/services/management/school_data_contrast_service.rb index 47c7f117..e6a39e9b 100644 --- a/app/services/management/school_data_contrast_service.rb +++ b/app/services/management/school_data_contrast_service.rb @@ -54,10 +54,8 @@ class Management::SchoolDataContrastService end def select_columns - "school_id, school_name, @total:=0, @other_total:=0,"\ - "(@total:=SUM(IF(date BETWEEN '#{format_date(params[:begin_date])}' AND '#{format_date(params[:end_date])}', #{contrast_column}, 0))) total,"\ - "(@other_total:=SUM(IF(date BETWEEN '#{format_date(params[:other_begin_date])}' AND '#{format_date(params[:other_end_date])}', #{contrast_column}, 0))) other_total,"\ - "(IF(@other_total - @total = 0, 0.0, round((@other_total - @total) / IF(@total = 0, 1, @total), 5))) percentage,"\ - "(@other_total - @total) increase" + "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 end diff --git a/app/views/managements/schools/_data_contrast_list.html.erb b/app/views/managements/schools/_data_contrast_list.html.erb index ae2ecfd2..af63aee8 100644 --- a/app/views/managements/schools/_data_contrast_list.html.erb +++ b/app/views/managements/schools/_data_contrast_list.html.erb @@ -14,10 +14,9 @@ 序号 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) %> + 时段一
        <%= "(#{params[:begin_date]}至#{params[:end_date]})" %> + 时段二
        <%= "(#{params[:other_begin_date]}至#{params[:other_end_date]})" %> + 变化情况
        ( 新 增 数 | 新增百分比) @@ -31,21 +30,25 @@ <%= report.school_name %> <%= report['total'] %> <%= report['other_total'] %> - <% if report['increase'] > 0 %> + <% + increase = report['other_total'] - report['total'] + percentage = report['total'].zero? ? increase.to_f * 100 : (increase / report['total'].to_f) * 100 + %> + <% if increase > 0 %> - +<%= report['increase'] %> + +<%= increase %> - +<%= report['percentage'] %>% - <% elsif report['increase'].zero? %> + +<%= percentage.round(5) %>% + <% elsif increase.zero? %> - <%= report['increase'] %> + <%= increase %> - <%= report['percentage'] %> + <%= percentage.round(5) %>% <% else %> - <%= report['increase'] %> + <%= increase %> - <%= report['percentage'] %>% + <%= percentage.round(5) %>% <% end %> <% end %> From a8d347bbe46902a3d19923a38d534a508b42f80f Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 27 Apr 2019 14:48:23 +0800 Subject: [PATCH 31/69] =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=9D=83=E9=99=90?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E9=85=8D=E7=BD=AE=E9=BB=98=E8=AE=A4=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/managements/update_user.html.erb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/views/managements/update_user.html.erb b/app/views/managements/update_user.html.erb index 554ea2a2..a2ad1369 100644 --- a/app/views/managements/update_user.html.erb +++ b/app/views/managements/update_user.html.erb @@ -200,14 +200,12 @@ - 实训 - -
      • -
        - - - - - +
        + + +
        + + + + + +
        - + <%= link_to '登录', signin_path, :class => "mr5 color-white" %> - - <%= link_to '注册', user_join_path, :class => "ml5 color-white" %> + + <%= link_to '注册', user_join_path, :class => "ml5 color-white" %>
        -
      • <%= link_to "加入课堂", signin_path, :remote => true %>
      • -
      • <%= link_to "加入项目", applied_join_project_path, :remote => true %>
      • +
      • <%= link_to "加入课堂", signin_path, :remote => true %>
      • +
      • <%= link_to "加入项目", applied_join_project_path, :remote => true %>
    From 0817dc9e86196df0cb019f1bcf406746401eba1f Mon Sep 17 00:00:00 2001 From: p31729568 Date: Mon, 29 Apr 2019 16:44:52 +0800 Subject: [PATCH 49/69] remove whenever gem --- Gemfile | 3 --- config/schedule.rb | 24 -------------------- lib/tasks/statistic_school_daily_report.rake | 5 ++++ 3 files changed, 5 insertions(+), 27 deletions(-) delete mode 100644 config/schedule.rb diff --git a/Gemfile b/Gemfile index 9ff7d11f..b9e1b4e2 100644 --- a/Gemfile +++ b/Gemfile @@ -62,9 +62,6 @@ gem 'elasticsearch-rails' gem 'oauth2' -# 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/config/schedule.rb b/config/schedule.rb deleted file mode 100644 index 380494c6..00000000 --- a/config/schedule.rb +++ /dev/null @@ -1,24 +0,0 @@ -# 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/lib/tasks/statistic_school_daily_report.rake b/lib/tasks/statistic_school_daily_report.rake index 84b65204..67604fff 100644 --- a/lib/tasks/statistic_school_daily_report.rake +++ b/lib/tasks/statistic_school_daily_report.rake @@ -1,6 +1,11 @@ #coding=utf-8 namespace :school_daily_report do + desc 'daily statistic school task' + task daily_statistic: :environment do + StatisticSchoolDailyReportTask.new.call + end + desc 'statistic school daily report data before now' task :statistic, [:date] => :environment do |_, args| date = Time.zone.parse(args[:date]).beginning_of_day From 8cce3e27ba4a63693627e1ca233dab05280e8217 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 29 Apr 2019 16:57:27 +0800 Subject: [PATCH 50/69] =?UTF-8?q?=E9=9A=90=E8=97=8F=E5=92=8C=E5=B7=B2?= =?UTF-8?q?=E7=BB=8F=E5=88=A0=E9=99=A4=E7=9A=84=E5=AE=9E=E8=AE=AD=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E9=80=9A=E8=BF=87=E8=BF=9E=E6=8E=A5=E8=AE=BF?= =?UTF-8?q?=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 2 +- app/models/shixun.rb | 7 ++++++- app/services/games_service.rb | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 685f9f74..df1da6ca 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -467,7 +467,7 @@ class ChallengesController < ApplicationController render_404 return else - if (@shixun.status == 0 && !User.current.manager_of_shixun?(@shixun)) || @shixun.status == -1 + if (@shixun.status == 0 && !User.current.manager_of_shixun?(@shixun)) || (!@shixun.operable? && !User.current.admin?) render_403 return end diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 54882be1..c7d0460a 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -62,13 +62,18 @@ class Shixun < ActiveRecord::Base include ApplicationHelper has_many :tidings, :as => :container, :dependent => :destroy - scope :visible, -> { where(status: -1) } + #scope :visible, -> { where(status: -1) } after_create :send_tiding def should_compile? self.mirror_repositories.published_main_mirror.first.try(:should_compile) end + # 可供使用的实训 + def operable? + self.status != -1 && !self.hidden + end + def is_published? self.status > 1 ? true : false end diff --git a/app/services/games_service.rb b/app/services/games_service.rb index bddb03b7..f172edbd 100644 --- a/app/services/games_service.rb +++ b/app/services/games_service.rb @@ -17,7 +17,8 @@ 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.business? || current_user.id == shixun.try(:user_id) || current_user.is_certification_teacher) + unless ((myshixun.user_id == current_user.id || current_user.business? || current_user.id == shixun.try(:user_id) || + current_user.is_certification_teacher) && (shixun.operable?)) || current_user.admin? return{:status => 403} end game_challenge = Challenge.min.find(game.challenge_id) From 5002fd8a5cc6a31f6c91b7996379e1dd6fd6e9f6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 30 Apr 2019 09:45:32 +0800 Subject: [PATCH 51/69] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E6=97=B6=E8=BF=87=E6=BB=A4=E6=8E=89=E5=88=A0=E9=99=A4=E7=9A=84?= =?UTF-8?q?=E5=AE=9E=E8=AE=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8c7a1278..64e7aa86 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -940,7 +940,7 @@ class UsersController < ApplicationController @limit = 16 if 1 == @index # @shixuns_result = Shixun.where(:status => [2,3]).where("name like ?", "%#{@search}%").reorder("created_at desc") - @shixuns_result = Shixun.where("name like ? and hidden=0", "%#{@search}%").reorder("myshixuns_count desc") + @shixuns_result = Shixun.where("name like ? and hidden=0 and status != -1", "%#{@search}%").reorder("myshixuns_count desc") @shixuns_result_count = @shixuns_result.count @shixun_pages = Paginator.new @shixuns_result_count, @limit, params['page'] || 1 @offset ||= @shixun_pages.offset From fdec1f663debf88a13bb825aefc1bb864dfb1147 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 30 Apr 2019 10:51:11 +0800 Subject: [PATCH 52/69] =?UTF-8?q?=E8=B6=85=E7=BA=A7=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E7=9A=84=E8=AF=95=E7=94=A8=E6=8E=88=E6=9D=83=E2=80=9C?= =?UTF-8?q?=E5=B7=B2=E5=AE=A1=E6=89=B9=E2=80=9D=E5=A2=9E=E5=8A=A0=E5=AD=A6?= =?UTF-8?q?=E9=99=A2=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/colleges_controller.rb | 58 ++++++++++--------- app/models/school.rb | 2 +- app/views/colleges/_student_eval.html.erb | 8 +-- app/views/colleges/statistics.html.erb | 8 +-- .../_trial_authorization_passed_list.html.erb | 2 +- 5 files changed, 40 insertions(+), 38 deletions(-) diff --git a/app/controllers/colleges_controller.rb b/app/controllers/colleges_controller.rb index df500de8..960030c9 100644 --- a/app/controllers/colleges_controller.rb +++ b/app/controllers/colleges_controller.rb @@ -44,31 +44,31 @@ class CollegesController < ApplicationController 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` = #{@department.school_id} AND user_extensions.`identity` = 0").first.try(:teacher_count) + 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` = #{@department.school_id} AND user_extensions.`identity` = 1").first.try(:student_count) + 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` = #{@department.school_id}").map(&:id) + # 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.joins("join users u on courses.tea_id = u.id").joins("join user_extensions ue on u.id = ue.user_id").where("courses.id != 1309 and ue.school_id = #{@department.school_id}") + all_course_ids = Course.joins("join users u on courses.tea_id = u.id").joins("join user_extensions ue on u.id = ue.user_id").where("courses.id != 1309 and ue.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=#{@department.school_id}").first.try(:shixun_count) + 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=#{@department.school_id}").first.try(:cost_time).to_i / (24 * 60 * 60.0)).ceil + 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`=#{@department.school_id}) and work_status between 1 and 2 and myshixun_id !=0").first.try(:sw_count) + user_extensions.`school_id`=#{@school.id}) and work_status between 1 and 2 and myshixun_id !=0").first.try(:sw_count) @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, members m, member_roles mr WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) 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=#{@department.school_id} ORDER BY publish_shixun_count desc, course_count desc, id desc LIMIT 10") + 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| @@ -131,7 +131,7 @@ class CollegesController < ApplicationController (select count(m.id) from messages m inner join boards b on b.id=m.board_id and b.parent_id=0 where b.course_id=c.id group by c.id) as messages_count, c.tea_id, c.name, c.is_end, (SELECT MAX(created_at) FROM `course_activities` ca WHERE ca.course_id = c.id) AS update_time - FROM `courses` c WHERE (c.school_id = #{@department.school_id} and c.is_delete = 0)") + FROM `courses` c WHERE (c.school_id = #{@school.id} and c.is_delete = 0)") @courses.each do |course| course[:evaluating_count] = Output.find_by_sql("select sum(g.evaluate_count) as evaluating_count from games g inner join @@ -157,11 +157,11 @@ class CollegesController < ApplicationController # 学生实训 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` = #{@department.school_id}").map(&:id) + 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 = #{@department.school_id} AND ue.identity = 1 AND `users`.`type` IN ('User', 'AnonymousUser') ORDER BY experience DESC, myshixun_count DESC LIMIT 10") + 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{ @@ -172,7 +172,7 @@ class CollegesController < ApplicationController 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` = #{@department.school_id} + 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 @@ -197,50 +197,50 @@ class CollegesController < ApplicationController @eval_data = [] case @index when "day" - same_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b + same_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(end_day - 365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 365.days).end_of_day}'").first.try(:count).to_i - last_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b + last_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(end_day - 1.day).beginning_of_day}' AND outputs.created_at < '#{(end_day - 1.day).end_of_day}'").first.try(:count).to_i @time_range = "#{end_day.strftime("%Y-%m-%d")}~#{end_day.strftime("%Y-%m-%d")}" @time_data = ["2:00", "4:00", "6:00", "8:00", "10:00", "12:00", "14:00", "16:00", "18:00", "20:00", "22:00", "24:00"] for i in 0..11 - @eval_data << Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b + @eval_data << Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{end_day.beginning_of_day + (i * 2).hour}' AND outputs.created_at < '#{end_day.beginning_of_day + ((i + 1) * 2).hour}'").first.try(:count).to_i end when "week" start_day = end_day - 6.days - same_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b + same_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day - 365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 365.days).end_of_day}'").first.try(:count).to_i - last_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b + last_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day - 7.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 7.days).end_of_day}'").first.try(:count).to_i @time_range = "#{start_day.strftime("%Y-%m-%d")}~#{end_day.strftime("%Y-%m-%d")}" for i in 0..6 @time_data << (start_day + i.days).strftime("%m.%d") - @eval_data << Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b + @eval_data << Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day + i.days).beginning_of_day}' AND outputs.created_at < '#{(start_day + (i + 1).days).end_of_day}'").first.try(:count).to_i end when "mon" start_day = end_day - 30.days - same_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b + same_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day - 365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 365.days).end_of_day}'").first.try(:count).to_i - last_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b + last_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day - 30.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 30.days).end_of_day}'").first.try(:count).to_i @time_range = "#{start_day.strftime("%Y-%m-%d")}~#{end_day.strftime("%Y-%m-%d")}" for i in 0..9 @time_data << (start_day + (3 * i).days).strftime("%m.%d") - @eval_data << Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b + @eval_data << Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day + (3 * i).days).beginning_of_day}' AND outputs.created_at < '#{(start_day + (3 * (i + 1)).days).end_of_day}'").first.try(:count).to_i end when "year" start_day = end_day - 365.days - same_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b + same_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day - 365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day - 365.days).end_of_day}'").first.try(:count).to_i last_count = same_count @time_range = "#{start_day.strftime("%Y-%m-%d")}~#{end_day.strftime("%Y-%m-%d")}" for i in 0..11 @time_data << (start_day + i.month).strftime("%m.%d") - @eval_data << Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b + @eval_data << Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day + i.days).beginning_of_day}' AND outputs.created_at < '#{(start_day + (i + 1).days).end_of_day}'").first.try(:count).to_i end end @@ -248,9 +248,9 @@ class CollegesController < ApplicationController @same_rate = (@new_count == 0 || same_count == 0) ? 0 : (@new_count * 1.0 / same_count - 1).to_f @last_rate = (@new_count == 0 || last_count == 0) ? 0 : (@new_count * 1.0 / last_count - 1).to_f - @total_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b + @total_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 ").first.try(:count).to_i - @trend_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@department.school_id}) b + @trend_count = Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b ON outputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{Time.now - 7.days}'").first.try(:count).to_i end @@ -259,9 +259,9 @@ class CollegesController < ApplicationController def manager_auth # unless (User.current.admin? || DepartmentMember.where(:user_id => User.current.id, :department_id => @department.id).first.present?) unless (User.current.admin? || User.current.business? || - DepartmentMember.where(:user_id => User.current.id, :department_id => @department.id).first.present? || - (User.current.user_extensions.try(:school_id) == @department.school_id && User.current.user_extensions.try(:identity) == 0) || - (@department.school.try(:customer_id) && User.current.try(:partner).try(:customer_ids) && User.current.try(:partner).try(:customer_ids).include?(@department.school.try(:customer_id)))) + (@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)))) render_403 end end @@ -270,6 +270,8 @@ class CollegesController < ApplicationController @department = Department.find_by_identifier(params[:id]) if @department.present? @school = @department.school + else + @school = School.find_by_id(params[:id]) end rescue ActiveRecord::RecordNotFound render_404 diff --git a/app/models/school.rb b/app/models/school.rb index 021048fb..081f3c0c 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -64,7 +64,7 @@ class School < ActiveRecord::Base def statistic_url dep = departments.where("identifier is not null").first - url = dep.present? ? "/colleges/#{dep.identifier}/statistics" : "" + url = dep.present? ? "/colleges/#{dep.identifier}/statistics" : "/colleges/#{self.id}/statistics" end def course_act_time diff --git a/app/views/colleges/_student_eval.html.erb b/app/views/colleges/_student_eval.html.erb index 2f3d47bc..be5bd078 100644 --- a/app/views/colleges/_student_eval.html.erb +++ b/app/views/colleges/_student_eval.html.erb @@ -30,10 +30,10 @@
  • - ">日 - ">周 - ">月 - ">年 + ">日 + ">周 + ">月 + ">年
  • diff --git a/app/views/colleges/statistics.html.erb b/app/views/colleges/statistics.html.erb index e0d93cfa..15535571 100644 --- a/app/views/colleges/statistics.html.erb +++ b/app/views/colleges/statistics.html.erb @@ -44,15 +44,15 @@
  • <%= @shixuns_count %>
  • <%= @shixun_report_count %>
  • <%= @shixun_time_sum %>
  • -
  • <%= @department.host_count.to_i %>
  • +
  • <%= @department.present? ? @department.host_count.to_i : @school.departments.first.try(:host_count).to_i %>
  • @@ -153,7 +153,7 @@ }) }); - $.get('<%= course_statistics_college_path(@department) %>'); + $.get('<%= course_statistics_college_path(@school) %>'); $(".count_student_test a").click(function(){ $(".count_student_test a").removeClass("active"); diff --git a/app/views/managements/_trial_authorization_passed_list.html.erb b/app/views/managements/_trial_authorization_passed_list.html.erb index 2a07d59a..450058ee 100644 --- a/app/views/managements/_trial_authorization_passed_list.html.erb +++ b/app/views/managements/_trial_authorization_passed_list.html.erb @@ -17,7 +17,7 @@
  • <% if !user.try(:user_extensions).school_id.blank? && user.try(:user_extensions).try(:school) %> - <%= user.try(:user_extensions).school.name %><%= user.try(:user_extensions).department ? ' - '+user.try(:user_extensions).department.name.to_s : '' %> + <%= user.try(:user_extensions).school.name %><%= user.try(:user_extensions).department ? ' - '+user.try(:user_extensions).department.name.to_s : '' %> <% end %> <% if user.try(:user_extensions) && user.try(:user_extensions).identity %> <%= user.identity %> From b49c1f57527f3a62b86c6a84068cf456e4782d63 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 30 Apr 2019 11:21:51 +0800 Subject: [PATCH 53/69] 1 --- app/controllers/challenges_controller.rb | 4 +++- app/models/shixun.rb | 1 + app/views/challenges/_content_list.html.erb | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index df1da6ca..76f7b080 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -2,7 +2,7 @@ class ChallengesController < ApplicationController layout "base_shixun" # 如要添加或修改before_filter时,请将handle_openi_request这个before_filter放至第一位 - before_filter :handle_openi_request, if: -> { user_login_and_from_openi? }, only: [:index] + #before_filter :handle_openi_request, if: -> { user_login_and_from_openi? }, only: [:index] before_filter :check_authentication, :except => [:index] before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation, :add_choose_question, :new_choose_question, :choose_type_show, :edit_choose_question, :update_choose_question, :destroy_challenge_choose] @@ -467,6 +467,8 @@ class ChallengesController < ApplicationController render_404 return else + logger.info("operable: ##{@shixun.operable?}") + logger.info("@shixun.status: ##{@shixun.status}") if (@shixun.status == 0 && !User.current.manager_of_shixun?(@shixun)) || (!@shixun.operable? && !User.current.admin?) render_403 return diff --git a/app/models/shixun.rb b/app/models/shixun.rb index c7d0460a..85b6a2d4 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -71,6 +71,7 @@ class Shixun < ActiveRecord::Base # 可供使用的实训 def operable? + logger.info("####") self.status != -1 && !self.hidden end diff --git a/app/views/challenges/_content_list.html.erb b/app/views/challenges/_content_list.html.erb index bc7743de..dec91671 100644 --- a/app/views/challenges/_content_list.html.erb +++ b/app/views/challenges/_content_list.html.erb @@ -13,7 +13,7 @@ <% end %>

    - +

    全部任务 From 731d8532e47d7d2f714de5c098a95599795ca300 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 30 Apr 2019 11:25:36 +0800 Subject: [PATCH 54/69] 1 --- app/controllers/challenges_controller.rb | 2 +- app/views/challenges/_content_list.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 76f7b080..344976ab 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -2,7 +2,7 @@ class ChallengesController < ApplicationController layout "base_shixun" # 如要添加或修改before_filter时,请将handle_openi_request这个before_filter放至第一位 - #before_filter :handle_openi_request, if: -> { user_login_and_from_openi? }, only: [:index] + before_filter :handle_openi_request, if: -> { user_login_and_from_openi? }, only: [:index] before_filter :check_authentication, :except => [:index] before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation, :add_choose_question, :new_choose_question, :choose_type_show, :edit_choose_question, :update_choose_question, :destroy_challenge_choose] diff --git a/app/views/challenges/_content_list.html.erb b/app/views/challenges/_content_list.html.erb index dec91671..bc7743de 100644 --- a/app/views/challenges/_content_list.html.erb +++ b/app/views/challenges/_content_list.html.erb @@ -13,7 +13,7 @@ <% end %>

    - +

    全部任务 From 5f8341dcf5f8b65f8b094b248cd99730069afe36 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 30 Apr 2019 11:27:54 +0800 Subject: [PATCH 55/69] 1 --- app/models/shixun.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 85b6a2d4..439c0e44 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -55,8 +55,9 @@ class Shixun < ActiveRecord::Base scope :visible, lambda{where(status: [2,3])} - scope :min, lambda { select([:id, :name, :gpid, :modify_time, :reset_time, :language, :propaedeutics, :status, :identifier, :test_set_permission, :hide_code, :forbid_copy, - :webssh, :user_id, :code_hidden, :task_pass, :exec_time, :multi_webssh]) } + scope :min, lambda { select([:id, :name, :gpid, :modify_time, :reset_time, :language, :propaedeutics, :status, :identifier, + :test_set_permission, :hide_code, :forbid_copy, :hidden, :webssh, :user_id, :code_hidden, + :task_pass, :exec_time, :multi_webssh]) } scope :published, lambda{where(status: 2)} scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) } From 50d7ed2deb55a522f02451343d62995d91501c96 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 30 Apr 2019 11:34:45 +0800 Subject: [PATCH 56/69] export school statistic data feature --- Gemfile | 3 ++ .../managements/schools_controller.rb | 23 ++++++++++++- app/models/homework_common.rb | 32 ++++++------------- .../management/school_report_service.rb | 2 +- app/views/layouts/base_management.html.erb | 4 --- .../schools/_data_contrast_list.html.erb | 8 ++--- .../schools/_statistics_list.html.erb | 2 +- .../managements/schools/statistics.html.erb | 26 +++++++++++++++ .../schools/statistics_xlsx.xlsx.axlsx | 20 ++++++++++++ config/routes.rb | 1 + 10 files changed, 88 insertions(+), 33 deletions(-) create mode 100644 app/views/managements/schools/statistics_xlsx.xlsx.axlsx diff --git a/Gemfile b/Gemfile index b9e1b4e2..f4697bf5 100644 --- a/Gemfile +++ b/Gemfile @@ -62,6 +62,9 @@ gem 'elasticsearch-rails' gem 'oauth2' +# xlsx +gem 'axlsx_rails', '0.3.0' + #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 6dfe84fb..381c7493 100644 --- a/app/controllers/managements/schools_controller.rb +++ b/app/controllers/managements/schools_controller.rb @@ -7,8 +7,13 @@ class Managements::SchoolsController < Managements::BaseController params[:sort_by] ||= :teacher_count params[:sort_direction] ||= :desc - schools = Management::SchoolReportService.new(params).call + schools = Management::SchoolReportService.new(params).call @schools = paginateHelper schools + + respond_to do |format| + format.html { load_statistic_total } + format.js + end end def yesterday_data @@ -31,6 +36,13 @@ class Managements::SchoolsController < Managements::BaseController raise '参数错误' end + def statistics_xlsx + @schools = Management::SchoolReportService.new(params).call + + filename = ["学校统计总表", params[:keyword], Time.zone.now.strftime('%Y%m%d%H%M%S')].join('-') << ".xlsx" + render xlsx: "statistics_xlsx", filename: filename + end + private def set_navigation_bar @menu_type = 1 @@ -41,4 +53,13 @@ class Managements::SchoolsController < Managements::BaseController [I18n.t("school_daily_report.#{column}"), column] end end + + def load_statistic_total + @teacher_total = User.teacher.count + @student_total = User.student.count + @course_total = Course.count + @active_course_total = Course.where(is_end: false).count + @shixun_homework_total = HomeworkCommon.where(homework_type: 4).count + @other_homework_total = HomeworkCommon.where(homework_type: [1, 3]).count + end end diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 0b7aa420..abe09e08 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -63,33 +63,21 @@ class HomeworkCommon < ActiveRecord::Base #作业类型 def homework_type_ch - type = self.homework_type - case type - when 1 - type = "普通" - when 2 - type = "编程" - when 3 - type = "分组" - when 4 - type = "实训" + case homework_type + when 1 then '普通' + when 2 then '编程' + when 3 then '分组' + when 4 then '实训' end - type end def homework_type_module - type = self.homework_type - case type - when 1 - type = "common_homework" - when 2 - type = "code_homework" - when 3 - type = "group_homework" - when 4 - type = "shixun_homework" + case homework_type + when 1 then 'common_homework' + when 2 then 'code_homework' + when 3 then 'group_homework' + when 4 then 'shixun_homework' end - type end def act_as_activity diff --git a/app/services/management/school_report_service.rb b/app/services/management/school_report_service.rb index 5a962bd5..e9ee1bae 100644 --- a/app/services/management/school_report_service.rb +++ b/app/services/management/school_report_service.rb @@ -39,7 +39,7 @@ class Management::SchoolReportService ( SELECT COUNT(*) FROM homework_commons hc LEFT JOIN courses ON courses.id = hc.course_id - WHERE courses.school_id = schools.id + WHERE courses.school_id = schools.id AND hc.homework_type = 4 ) homework_count, ( SELECT COUNT(*) FROM homework_commons hc diff --git a/app/views/layouts/base_management.html.erb b/app/views/layouts/base_management.html.erb index 9d1d77c8..d357bd09 100644 --- a/app/views/layouts/base_management.html.erb +++ b/app/views/layouts/base_management.html.erb @@ -44,10 +44,6 @@

  • <%= link_to "课堂列表", classroom_classment_managements_path %>
  • <%= link_to "实训作业", shixun_task_managements_path%>
  • <%= link_to "项目列表", project_list_managements_path%>
  • - - - -
  • 精选实训+ diff --git a/app/views/managements/schools/_data_contrast_list.html.erb b/app/views/managements/schools/_data_contrast_list.html.erb index af63aee8..c2699601 100644 --- a/app/views/managements/schools/_data_contrast_list.html.erb +++ b/app/views/managements/schools/_data_contrast_list.html.erb @@ -35,20 +35,20 @@ percentage = report['total'].zero? ? increase.to_f * 100 : (increase / report['total'].to_f) * 100 %> <% if increase > 0 %> - + +<%= increase %> - +<%= percentage.round(5) %>% + +<%= percentage.round(5) %>% <% elsif increase.zero? %> <%= increase %> <%= percentage.round(5) %>% <% else %> - + <%= increase %> - <%= percentage.round(5) %>% + <%= percentage.round(5) %>% <% end %> <% end %> diff --git a/app/views/managements/schools/_statistics_list.html.erb b/app/views/managements/schools/_statistics_list.html.erb index 609a1cca..cffb316c 100644 --- a/app/views/managements/schools/_statistics_list.html.erb +++ b/app/views/managements/schools/_statistics_list.html.erb @@ -17,7 +17,7 @@ <% @schools.each_with_index do |school, index| %> - <% p school %><%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %> + <%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %> <%= school['id'] %> <%= school['name'] %> <%= school['teacher_count'] %> diff --git a/app/views/managements/schools/statistics.html.erb b/app/views/managements/schools/statistics.html.erb index 1597fe45..5a68f75c 100644 --- a/app/views/managements/schools/statistics.html.erb +++ b/app/views/managements/schools/statistics.html.erb @@ -4,7 +4,26 @@ 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', onclick: "$('#school_report_search_form').submit();" %> <%= link_to '清除', 'javascript:clearSearchCondition()', class: 'fl task-btn ml5 mt2 mt10' %> + +
    + <%= link_to '导出Excel', school_statistics_xlsx_managements_path(format: :xlsx), + class: 'fl task-btn task-btn-orange mt10 mr20 export-statistic-btn', + onclick: 'exportSchoolStatistic();' %> +
    <% end %> + +
  • + +
    +
    + 统计总计: + 教师总人数<%= @teacher_total %>人, + 学生总人数<%= @student_total %>人, + 课堂总数<%= @course_total %>个, + 正在进行课堂总数<%= @active_course_total %>个, + 实训作业总数<%= @shixun_homework_total %>个, + 其它作业总数<%= @other_homework_total %>个, +
    @@ -16,4 +35,11 @@ $("#school_report_search_form input[name='keyword']").val(""); $('#school_report_search_form').submit(); } + + function exportSchoolStatistic(){ + var form = $("#school_report_search_form") + var exportLink = form.find(".export-statistic-btn"); + var keyword = form.find("input[name='keyword'").val(); + exportLink.attr("href", exportLink.attr("href") + "?keyword=" + keyword); + } \ No newline at end of file diff --git a/app/views/managements/schools/statistics_xlsx.xlsx.axlsx b/app/views/managements/schools/statistics_xlsx.xlsx.axlsx new file mode 100644 index 00000000..b68a817c --- /dev/null +++ b/app/views/managements/schools/statistics_xlsx.xlsx.axlsx @@ -0,0 +1,20 @@ +wb = xlsx_package.workbook +wb.add_worksheet(name: "统计总表") do |sheet| + sheet.add_row %w(ID 单位名称 教师总人数 学生总人数 课堂总数 正在进行课堂数 实训作业总数 其它作业总数 动态时间) + + total = @schools.count + buffer_size = 500 + times = total % 500 > 0 ? total / 500 + 1 : total / 500 + + times.times do |index| + schools = @schools.limit(buffer_size).offset(index * buffer_size) + + schools.each do |school| + sheet.add_row([ + school['id'].to_s, school['name'].to_s, school['teacher_count'].to_s, school['student_count'].to_s, + school['course_count'].to_s, school['active_course_count'].to_s, school['homework_count'].to_s, + school['other_homework_count'].to_s, format_time(school['nearly_course_time']) + ]) + end + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 26cddf96..85ec25c9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -728,6 +728,7 @@ RedmineApp::Application.routes.draw do ## oauth相关 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' + get :school_statistics_xlsx, controller: 'managements::schools', action: 'statistics_xlsx' end end # Enable Grack support From 90e7e056ec7f1cb7fc9c906face74b7e4bde4a16 Mon Sep 17 00:00:00 2001 From: Alec Zhou Date: Tue, 30 Apr 2019 14:29:10 +0800 Subject: [PATCH 57/69] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=87=8D=E5=AE=9A?= =?UTF-8?q?=E5=90=91=E8=BF=87=E5=A4=9A=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/oauth_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/oauth_controller.rb b/app/controllers/oauth_controller.rb index 930f2b75..16f83291 100644 --- a/app/controllers/oauth_controller.rb +++ b/app/controllers/oauth_controller.rb @@ -202,7 +202,11 @@ class OauthController < ApplicationController self.logged_user = openi.user if openi.present? && openi.user.present? original_url = params[:original_url] - redirect_to original_url + if current_user.logged? + redirect_to original_url + else + redirect_to signin_path + end end def get_token_callback From 09abc5511fbb574cf8d0947592a8bbac8c520ef5 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 30 Apr 2019 14:53:26 +0800 Subject: [PATCH 58/69] =?UTF-8?q?=E7=BC=96=E8=BE=91=E9=83=A8=E9=97=A8url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/managements_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 53eb23ae..d4e08240 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -1416,7 +1416,8 @@ end def update_depart_identifier if params[:depart] && params[:identifier] @department = Department.where(:id => params[:depart]).first - @department.update_attributes(:identifier => params[:identifier]) if @department.present? + identifier = params[:identifier].strip.blank? ? nil : params[:identifier].strip + @department.update_attributes(:identifier => identifier) if @department.present? end end From cb8b80efe9d9da2ced8cd07fa5b953e05e06a3c7 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 30 Apr 2019 14:56:34 +0800 Subject: [PATCH 59/69] gem --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index f4697bf5..7dca07cd 100644 --- a/Gemfile +++ b/Gemfile @@ -63,7 +63,7 @@ gem 'elasticsearch-rails' gem 'oauth2' # xlsx -gem 'axlsx_rails', '0.3.0' +# gem 'axlsx_rails', '0.3.0' #Ruby 2.2+ has removed test/unit from the core library. if RUBY_VERSION>='2.2' From c28692ffc5cc924f29d6b559665824d1193d8e06 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 30 Apr 2019 15:01:50 +0800 Subject: [PATCH 60/69] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/school.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/school.rb b/app/models/school.rb index 081f3c0c..fd925f9a 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -64,7 +64,7 @@ class School < ActiveRecord::Base def statistic_url dep = departments.where("identifier is not null").first - url = dep.present? ? "/colleges/#{dep.identifier}/statistics" : "/colleges/#{self.id}/statistics" + url = dep.present? && !dep.identifier.blank? ? "/colleges/#{dep.identifier}/statistics" : "/colleges/#{self.id}/statistics" end def course_act_time From 451e06dcaa94c8e593969ea9472149f030614449 Mon Sep 17 00:00:00 2001 From: Alec Zhou Date: Tue, 30 Apr 2019 15:19:27 +0800 Subject: [PATCH 61/69] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E5=88=9B=E5=BB=BAopeni?= =?UTF-8?q?=E5=85=B3=E8=81=94=E7=94=A8=E6=88=B7=E6=97=B6=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E6=8E=88=E6=9D=83=EF=BC=8C=E5=B9=B6=E4=B8=94=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=86=E7=94=9F=E6=88=90=E7=94=A8=E6=88=B7=E5=90=8D=E7=9A=84?= =?UTF-8?q?=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/oauth_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/oauth_controller.rb b/app/controllers/oauth_controller.rb index 16f83291..4dd2e6fd 100644 --- a/app/controllers/oauth_controller.rb +++ b/app/controllers/oauth_controller.rb @@ -188,14 +188,13 @@ class OauthController < ApplicationController break if existing_user.present? user = User.new(lastname: name, mail: email, mail_notification: email) - user.login = custom_openi_login(login) + user.login = generate_login('m') user.password = DEFAULT_PASSWORD + user.certification = 1 user.save! UserExtensions.create!(user_id: user.id, school_id: School.first.id, identity: 4, gender: 0) - UserDayCertification.create!(user_id: user.id, status: 1) - openi = Openi.create!(user_id: user.id, openi_user_id: openi_user_id, avatar_url: avatar_url, login: login, name: name, email: email) end end @@ -214,9 +213,10 @@ class OauthController < ApplicationController ####--End-- 获取Openi的授权码,access_token,以及用户信息。为在openi登录的用户创建相关的educoder用户 #### private - # 为了保证新创建的用户用户名不与系统中已存在的用户冲突,加上 _openi 后缀 - def custom_openi_login(login) - login + '_openi' + # 为新创建的用户随机生成以m为前缀的用户名,m表示该用户是用邮箱注册 + def generate_login(login_pre) + us = UsersService.new + us.generate_user_login(login_pre) end def require_login From 8348c95b57db63df9f4a39de37d41163da5841be Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 30 Apr 2019 15:40:40 +0800 Subject: [PATCH 62/69] modify school contrast data feature --- Gemfile | 3 +- .../managements/schools_controller.rb | 19 ++- .../management/school_data_grow_service.rb | 59 ++++++++ .../school_yesterday_data_service.rb | 32 ---- app/views/layouts/base_management.html.erb | 2 +- .../schools/_contrast_search_form.html.erb | 142 ++++++++++++++---- .../schools/_data_contrast_list.html.erb | 9 ++ ...list.html.erb => _data_grow_list.html.erb} | 27 +++- ...erday_data.html.erb => data_grow.html.erb} | 2 +- ...yesterday_data.js.erb => data_grow.js.erb} | 2 +- config/routes.rb | 2 +- 11 files changed, 223 insertions(+), 76 deletions(-) create mode 100644 app/services/management/school_data_grow_service.rb delete mode 100644 app/services/management/school_yesterday_data_service.rb rename app/views/managements/schools/{_yesterday_data_list.html.erb => _data_grow_list.html.erb} (56%) rename app/views/managements/schools/{yesterday_data.html.erb => data_grow.html.erb} (79%) rename app/views/managements/schools/{yesterday_data.js.erb => data_grow.js.erb} (63%) diff --git a/Gemfile b/Gemfile index 7dca07cd..7a7deeab 100644 --- a/Gemfile +++ b/Gemfile @@ -63,7 +63,8 @@ gem 'elasticsearch-rails' gem 'oauth2' # xlsx -# gem 'axlsx_rails', '0.3.0' +gem 'axlsx', '2.1.0.pre' +gem 'axlsx_rails', '0.3.0' #Ruby 2.2+ has removed test/unit from the core library. if RUBY_VERSION>='2.2' diff --git a/app/controllers/managements/schools_controller.rb b/app/controllers/managements/schools_controller.rb index 381c7493..24889869 100644 --- a/app/controllers/managements/schools_controller.rb +++ b/app/controllers/managements/schools_controller.rb @@ -16,12 +16,16 @@ class Managements::SchoolsController < Managements::BaseController end end - def yesterday_data + def data_grow @sub_type = 2 + params[:data_type] ||= 'grow' params[:sort_by] ||= :teacher_increase_count params[:sort_direction] ||= :desc - reports = Management::SchoolYesterdayDataService.new(params).call + service = Management::SchoolDataGrowService.new(params) + @grow_summary = service.grow_summary + + reports = service.call @reports = paginateHelper reports end @@ -30,6 +34,12 @@ class Managements::SchoolsController < Managements::BaseController params[:sort_direction] ||= :desc params[:sort_by] ||= :percentage + # 无对比日期时直接返回无数据页面 + if useless_contrast_date_parameter? + @obj_count, @reports = 0, [] + return + end + @obj_count, @reports = Management::SchoolDataContrastService.new(params).call @obj_pages = Paginator.new(@obj_count, Management::SchoolDataContrastService::PAGE_SIZE, params[:page]) rescue Management::SchoolDataContrastService::ParameterError @@ -54,6 +64,11 @@ class Managements::SchoolsController < Managements::BaseController end end + def useless_contrast_date_parameter? + params[:begin_date].blank? && params[:end_date].blank? && + params[:other_begin_date].blank? &¶ms[:other_end_date].blank? + end + def load_statistic_total @teacher_total = User.teacher.count @student_total = User.student.count diff --git a/app/services/management/school_data_grow_service.rb b/app/services/management/school_data_grow_service.rb new file mode 100644 index 00000000..02df364b --- /dev/null +++ b/app/services/management/school_data_grow_service.rb @@ -0,0 +1,59 @@ +class Management::SchoolDataGrowService + include CustomSortable + + attr_reader :params + + sort_columns :teacher_increase_count, :student_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 + custom_sort(query_reports, params[:sort_by], params[:sort_direction]) + end + + def grow_summary + @_grow_summary ||= begin + query_reports.select( + 'SUM(teacher_increase_count) teacher_increase_count,'\ + 'SUM(student_increase_count) student_increase_count,'\ + 'SUM(course_increase_count) course_increase_count,'\ + 'SUM(shixun_increase_count) shixun_increase_count,'\ + 'SUM(active_user_count) active_user_count' + ).first + end + end + + private + def query_reports + reports = SchoolDailyReport.where(date: query_date) + + 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 + end + + def query_date + if params[:grow_begin_date].present? + begin_time = Time.zone.parse(params[:grow_begin_date]) + end_date = if params[:grow_end_date].present? + Time.zone.parse(params[:grow_end_date]) + end + + end_date.blank? || end_date == begin_time ? begin_time : begin_time..end_date + else + yesterday + end + end + + 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/services/management/school_yesterday_data_service.rb b/app/services/management/school_yesterday_data_service.rb deleted file mode 100644 index 238a7297..00000000 --- a/app/services/management/school_yesterday_data_service.rb +++ /dev/null @@ -1,32 +0,0 @@ -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/views/layouts/base_management.html.erb b/app/views/layouts/base_management.html.erb index 201e26f1..eb6ce06d 100644 --- a/app/views/layouts/base_management.html.erb +++ b/app/views/layouts/base_management.html.erb @@ -35,7 +35,7 @@
  • 学校+
    • <%= link_to '统计总表', school_report_managements_path %>
    • -
    • <%= link_to '数据变化报表', school_yesterday_data_managements_path %>
    • +
    • <%= link_to '数据变化报表', school_data_grow_managements_path %>
  • 课堂+ diff --git a/app/views/managements/schools/_contrast_search_form.html.erb b/app/views/managements/schools/_contrast_search_form.html.erb index 2140eb97..4d24a810 100644 --- a/app/views/managements/schools/_contrast_search_form.html.erb +++ b/app/views/managements/schools/_contrast_search_form.html.erb @@ -1,26 +1,37 @@
    + <%= 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] %> + + <%= hidden_field_tag :grow_begin_date, params[:grow_begin_date] %> + <%= hidden_field_tag :grow_end_date, params[:grow_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: '请选择时间段二' %> +
    + <%= text_field_tag :grow_date_input, params[:grow_date_input], + class: 'grow-date-input winput-220-30', placeholder: '请选择时间段', + style: 'width: 400px;' %> +
    +
    + <%= 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' %> + <%= hidden_field_tag :data_type, params[:data_type] || 'grow' %> <% if params[:data_type] == 'contrast' %> 时间对比 - 日新增 + 新增数据 <% else %> 时间对比 - 日新增 + 新增数据 <% end %>
    @@ -31,28 +42,36 @@
    \ 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 index c2699601..ef5b5b17 100644 --- a/app/views/managements/schools/_data_contrast_list.html.erb +++ b/app/views/managements/schools/_data_contrast_list.html.erb @@ -6,8 +6,12 @@ options_for_select(@select_options, params[:contrast_column]), class: 'fl task-height-30 contrast-column-select', style: 'position: absolute; right: 30px; top: 15px;' %> +
    + 说明:新增数=时段二-时段一;新增百分比=(新增数/时段一)*100%(保留小数点后五位) +
  • +<% if @obj_count.nonzero? %> @@ -63,6 +67,11 @@
    +<% else %> +
    + 暂无数据,请选择时间段对比 +
    +<% end %>