diff --git a/app/assets/javascripts/admins/competitions/index.js b/app/assets/javascripts/admins/competitions/index.js index ae4593d33..c476dbf24 100644 --- a/app/assets/javascripts/admins/competitions/index.js +++ b/app/assets/javascripts/admins/competitions/index.js @@ -5,7 +5,69 @@ $(document).on('turbolinks:load', function() { $imageElement.attr('src', data.url); $imageElement.show(); $imageElement.next().html('重新上传'); - }) + }); } + + $(".admin-competition-list-form").on("change", '.competitions-hot-select', function () { + var s_value = $(this).get(0).checked ? 1 : 0; + var json = {}; + json["hot"] = s_value; + $.ajax({ + url: "/admins/competitions/hot_setting", + type: "POST", + dataType:'json', + data: json, + success: function(){ + $.notify({ message: '操作成功' }); + } + }); + }); + + // ============== 新增竞赛 =============== + var $modal = $('.modal.admin-create-competition-modal'); + var $form = $modal.find('form.admin-create-competition-form'); + var $competitionNameInput = $form.find('input[name="competition_name"]'); + + $form.validate({ + errorElement: 'span', + errorClass: 'danger text-danger', + rules: { + competition_name: { + required: true + } + } + }); + + // modal ready fire + $modal.on('show.bs.modal', function () { + $competitionNameInput.val(''); + }); + + $modal.on('click', '.submit-btn', function(){ + $form.find('.error').html(''); + + if ($form.valid()) { + var url = $form.data('url'); + + $.ajax({ + method: 'POST', + dataType: 'json', + url: url, + data: $form.serialize(), + success: function(){ + $.notify({ message: '创建成功' }); + $modal.modal('hide'); + + setTimeout(function(){ + window.location.reload(); + }, 500); + }, + error: function(res){ + var data = res.responseJSON; + $form.find('.error').html(data.message); + } + }); + } + }); }); diff --git a/app/assets/javascripts/admins/enroll_lists/index.js b/app/assets/javascripts/admins/enroll_lists/index.js new file mode 100644 index 000000000..04bd95070 --- /dev/null +++ b/app/assets/javascripts/admins/enroll_lists/index.js @@ -0,0 +1,9 @@ +$(document).on('turbolinks:load', function() { + if($('body.admins-enroll-lists-index-page').length > 0){ + let search_form = $(".search-form"); + //导出 + $(".competition-enroll-list-form").on("click","#enroll-lists-export",function () { + window.location.href = "/admins/competitions/"+$(this).attr("data-competition-id")+"/enroll_lists.xls?" + search_form.serialize(); + }); + } +}); \ No newline at end of file diff --git a/app/assets/javascripts/admins/modals/admin-upload-file-modal.js b/app/assets/javascripts/admins/modals/admin-upload-file-modal.js index cf1333381..a53173959 100644 --- a/app/assets/javascripts/admins/modals/admin-upload-file-modal.js +++ b/app/assets/javascripts/admins/modals/admin-upload-file-modal.js @@ -4,14 +4,17 @@ $(document).on('turbolinks:load', function() { var $form = $modal.find('form.admin-upload-file-form') var $sourceIdInput = $modal.find('input[name="source_id"]'); var $sourceTypeInput = $modal.find('input[name="source_type"]'); + var $suffixInput = $modal.find('input[name="suffix"]'); $modal.on('show.bs.modal', function(event){ var $link = $(event.relatedTarget); var sourceId = $link.data('sourceId'); var sourceType = $link.data('sourceType'); + var suffix = $link.data('suffix'); $sourceIdInput.val(sourceId); $sourceTypeInput.val(sourceType); + if(suffix != undefined){ $suffixInput.val(suffix); } $modal.find('.upload-file-input').trigger('click'); }); @@ -48,6 +51,7 @@ $(document).on('turbolinks:load', function() { contentType: false, success: function(data){ $.notify({ message: '上传成功' }); + $modal.find('.file-names').html(''); $modal.trigger('upload:success', data); $modal.modal('hide'); }, diff --git a/app/assets/javascripts/admins/shixun_settings/index.js b/app/assets/javascripts/admins/shixun_settings/index.js index f99574673..8b3eee505 100644 --- a/app/assets/javascripts/admins/shixun_settings/index.js +++ b/app/assets/javascripts/admins/shixun_settings/index.js @@ -34,10 +34,17 @@ $(document).on('turbolinks:load', function() { }); $('.modal.admin-upload-file-modal').on('upload:success', function(e, data){ - var $imageElement = $('.shixun-image-' + data.source_id); - $imageElement.attr('src', data.url); - $imageElement.show(); - $imageElement.next().html('重新上传'); + if(data.suffix == '_weapp'){ + var $imageElement = $('.shixun-weapp-image-' + data.source_id); + $imageElement.attr('src', data.url); + $imageElement.show(); + $imageElement.next().html('重新上传'); + } else { + var $imageElement = $('.shixun-image-' + data.source_id); + $imageElement.attr('src', data.url); + $imageElement.show(); + $imageElement.next().html('重新上传'); + } }) } }); diff --git a/app/assets/javascripts/admins/user_statistics/index.js b/app/assets/javascripts/admins/user_statistics/index.js new file mode 100644 index 000000000..3ffb288ac --- /dev/null +++ b/app/assets/javascripts/admins/user_statistics/index.js @@ -0,0 +1,73 @@ +$(document).on('turbolinks:load', function() { + if ($('body.admins-user-statistics-index-page').length > 0) { + var $form = $('.user-statistic-list-form'); + + // ************** 学校选择 ************* + var matcherFunc = function(params, data){ + if ($.trim(params.term) === '') { + return data; + } + if (typeof data.text === 'undefined') { + return null; + } + + if (data.name && data.name.indexOf(params.term) > -1) { + var modifiedData = $.extend({}, data, true); + return modifiedData; + } + + // Return `null` if the term should not be displayed + return null; + } + + var defineSchoolSelect = function (schools) { + $form.find('.school-select').select2({ + theme: 'bootstrap4', + placeholder: '选择学校/单位', + minimumInputLength: 1, + data: schools, + templateResult: function (item) { + if(!item.id || item.id === '') return item.text; + return item.name; + }, + templateSelection: function(item){ + if (item.id) { + $form.find('#school_id').val(item.id); + } + return item.name || item.text; + }, + matcher: matcherFunc + }); + }; + + + // 初始化学校选择器 + $.ajax({ + url: '/api/schools/for_option.json', + dataType: 'json', + type: 'GET', + success: function(data) { + defineSchoolSelect(data.schools); + } + }); + + // 清空 + $form.on('click', '.clear-btn', function(){ + $form.find('select[name="date"]').val(''); + $form.find('.school-select').val('').trigger('change'); + $form.find('input[type="submit"]').trigger('click'); + }) + + + // 导出 + $('.export-action').on('click', function(){ + var form = $(".user-statistic-list-form .search-form") + var exportLink = $(this); + var date = form.find("select[name='date']").val(); + var schoolId = form.find('input[name="school_id"]').val(); + + var url = exportLink.data("url").split('?')[0] + "?date=" + date + "&school_id=" + schoolId; + window.open(url); + }); + } +}); \ No newline at end of file diff --git a/app/controllers/admins/competitions_controller.rb b/app/controllers/admins/competitions_controller.rb index f501564ab..2e2dbd4e2 100644 --- a/app/controllers/admins/competitions_controller.rb +++ b/app/controllers/admins/competitions_controller.rb @@ -18,12 +18,27 @@ class Admins::CompetitionsController < Admins::BaseController end end + def create + name = params[:competition_name].to_s.strip + Competition.create!(name: name) + render_ok + end + + def hot_setting + if params[:hot].to_i == 1 && !ModuleSetting.exists?(module_type: "Competition", property: "hot") + ModuleSetting.create!(module_type: "Competition", property: "hot") + elsif params[:hot].to_i == 0 && ModuleSetting.exists?(module_type: "Competition", property: "hot") + ModuleSetting.where(module_type: "Competition", property: "hot").destroy_all + end + render_ok + end + def publish - @competition.update_attributes!(:published_at, Time.now) + @competition.update_attributes!(published_at: Time.now) end def unpublish - @competition.update_attributes!(:published_at, nil) + @competition.update_attributes!(published_at: nil) end def online_switch @@ -34,10 +49,6 @@ class Admins::CompetitionsController < Admins::BaseController end end - def enroll_list - - end - private def find_competition diff --git a/app/controllers/admins/enroll_lists_controller.rb b/app/controllers/admins/enroll_lists_controller.rb new file mode 100644 index 000000000..ccac6a72d --- /dev/null +++ b/app/controllers/admins/enroll_lists_controller.rb @@ -0,0 +1,25 @@ +class Admins::EnrollListsController < Admins::BaseController + + def index + @competition = current_competition + params[:sort_by] = params[:sort_by].presence || 'created_at' + params[:sort_direction] = params[:sort_direction].presence || 'desc' + enroll_lists = Admins::CompetitionEnrollListQuery.call(@competition, params) + + @params_page = params[:page] || 1 + @enroll_lists = paginate enroll_lists.preload(competition_team: [:user, :teachers], user: { user_extension: :school }) + @personal = @competition.personal? + + respond_to do |format| + format.js + format.html + format.xls + end + end + + private + def current_competition + @_current_competition ||= Competition.find(params[:competition_id]) + end + +end \ No newline at end of file diff --git a/app/controllers/admins/files_controller.rb b/app/controllers/admins/files_controller.rb index b269f8e27..cb8b66119 100644 --- a/app/controllers/admins/files_controller.rb +++ b/app/controllers/admins/files_controller.rb @@ -6,7 +6,12 @@ class Admins::FilesController < Admins::BaseController Util.write_file(@file, file_path) - render_ok(source_id: params[:source_id], source_type: params[:source_type].to_s, url: file_url + "?t=#{Random.rand}") + render_ok( + source_id: params[:source_id], + source_type: params[:source_type].to_s, + suffix: params[:suffix].presence, + url: file_url + ) rescue StandardError => ex logger_error(ex) render_error('上传失败') @@ -33,14 +38,14 @@ class Admins::FilesController < Admins::BaseController @_file_path ||= begin case params[:source_type].to_s when 'Shixun' then - Util::FileManage.disk_filename('Shixun', params[:source_id]) + Util::FileManage.disk_filename('Shixun', params[:source_id], params[:suffix].presence) else - Util::FileManage.disk_filename(params[:source_type].to_s, params[:source_id].to_s) + Util::FileManage.disk_filename(params[:source_type].to_s, params[:source_id].to_s, params[:suffix].presence) end end end def file_url - Util::FileManage.disk_file_url(params[:source_type].to_s, params[:source_id].to_s) + Util::FileManage.disk_file_url(params[:source_type].to_s, params[:source_id].to_s, params[:suffix].presence) end end \ No newline at end of file diff --git a/app/controllers/admins/user_statistics_controller.rb b/app/controllers/admins/user_statistics_controller.rb new file mode 100644 index 000000000..71dc3096a --- /dev/null +++ b/app/controllers/admins/user_statistics_controller.rb @@ -0,0 +1,19 @@ +class Admins::UserStatisticsController < Admins::BaseController + def index + default_sort('finish_shixun_count', 'desc') + + total_count, users = Admins::UserStatisticQuery.call(params) + + @users = paginate users, total_count: total_count + end + + def export + default_sort('finish_shixun_count', 'desc') + + params[:per_page] = 10000 + _count, @users = Admins::UserStatisticQuery.call(params) + + filename = ['用户实训情况', Time.zone.now.strftime('%Y%m%d%H%M%S')].join('-') << '.xlsx' + render xlsx: 'export', filename: filename + end +end \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e6b58bc3b..df3e9c96e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -353,10 +353,10 @@ class ApplicationController < ActionController::Base # Post请求 def uri_post(uri, params) begin - uid_logger("--uri_exec: params is #{params}, url is #{uri}") + uid_logger_dubug("--uri_exec: params is #{params}, url is #{uri}") uri = URI.parse(URI.encode(uri.strip)) res = Net::HTTP.post_form(uri, params).body - logger.info("--uri_exec: .....res is #{res}") + uid_logger_dubug("--uri_exec: .....res is #{res}") JSON.parse(res) rescue Exception => e uid_logger_error("--uri_exec: exception #{e.message}") @@ -367,10 +367,10 @@ class ApplicationController < ActionController::Base # 处理返回非0就报错的请求 def interface_post(uri, params, status, message) begin - uid_logger("--uri_exec: params is #{params}, url is #{uri}") + uid_logger_dubug("--uri_exec: params is #{params}, url is #{uri}") uri = URI.parse(URI.encode(uri.strip)) res = Net::HTTP.post_form(uri, params).body - logger.info("--uri_exec: .....res is #{res}") + uid_logger_dubug("--uri_exec: .....res is #{res}") res = JSON.parse(res) if (res && res['code'] != 0) tip_exception(status, message) @@ -623,4 +623,13 @@ class ApplicationController < ActionController::Base end user end + + # 记录热门搜索关键字 + def record_search_keyword + keyword = params[:keyword].to_s.strip + return if keyword.blank? || keyword.size <= 1 + return unless HotSearchKeyword.available? + + HotSearchKeyword.add(keyword) + end end diff --git a/app/controllers/competitions/competition_teams_controller.rb b/app/controllers/competitions/competition_teams_controller.rb index f504b226e..6a4dbfd34 100644 --- a/app/controllers/competitions/competition_teams_controller.rb +++ b/app/controllers/competitions/competition_teams_controller.rb @@ -59,6 +59,7 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController end def index + @personal = current_competition.personal? admin_or_business? ? all_competition_teams : user_competition_teams end diff --git a/app/controllers/concerns/base/paginate_helper.rb b/app/controllers/concerns/base/paginate_helper.rb index a10d7eb2e..7a81da2b9 100644 --- a/app/controllers/concerns/base/paginate_helper.rb +++ b/app/controllers/concerns/base/paginate_helper.rb @@ -1,6 +1,11 @@ module Base::PaginateHelper extend ActiveSupport::Concern + def default_sort(sort_by, direction) + params[:sort_by] = params[:sort_by].presence || sort_by + params[:sort_direction] = params[:sort_direction].presence || direction + end + def offset (page - 1) * per_page end diff --git a/app/controllers/concerns/logger_helper.rb b/app/controllers/concerns/logger_helper.rb index 44d0448ce..af368a007 100644 --- a/app/controllers/concerns/logger_helper.rb +++ b/app/controllers/concerns/logger_helper.rb @@ -9,6 +9,12 @@ module LoggerHelper Rails.logger.info("##:#{current_user.try(:id)} --#{message}") end + # debug日志 + def uid_logger_dubug(message) + Rails.logger.info("##dubug-#{current_user.try(:id)} --#{message}") + + end + # 以用户id开始的日志定义 def uid_logger_error(message) Rails.logger.error("##:#{current_user.try(:id)} --#{message}") diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index d71b72618..99356946f 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1129,7 +1129,7 @@ class ExercisesController < ApplicationController :subjective_score => subjective_score, :commit_method => @answer_committed_user&.commit_method.to_i > 0 ? @answer_committed_user&.commit_method.to_i : params[:commit_method].to_i } - @answer_committed_user.update_attributes(commit_option) + @answer_committed_user.update_attributes!(commit_option) CommitExercsieNotifyJobJob.perform_later(@exercise.id, current_user.id) normal_status(0,"试卷提交成功!") else diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 5a86fa06e..78f665b3d 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -60,7 +60,7 @@ class GamesController < ApplicationController praise_count: praise_count, user_praise: user_praise, time_limit: time_limit, tomcat_url: edu_setting('cloud_tomcat_php'), is_teacher: is_teacher, myshixun_manager: myshixun_manager, git_url: (@shixun.vnc ? repo_url(@myshixun.repo_path) : "")} - if @shixun.vnc && @st == 0 + if @shixun.vnc get_vnc_link(@game) end diff --git a/app/controllers/hot_keywords_controller.rb b/app/controllers/hot_keywords_controller.rb new file mode 100644 index 000000000..e0c536e42 --- /dev/null +++ b/app/controllers/hot_keywords_controller.rb @@ -0,0 +1,7 @@ +class HotKeywordsController < ApplicationController + def index + keywords = [] + keywords = HotSearchKeyword.hot(8) if HotSearchKeyword.available? + render_ok(keywords: keywords) + end +end \ No newline at end of file diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 869ba27f6..0e2628c3e 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -1,5 +1,5 @@ class MainController < ApplicationController def index - render file: 'public/react/build/index', formats: [:html] + render file: 'public/react/build/index.html', :layout => false end end \ No newline at end of file diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 74f02f1ab..4e587513a 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -90,7 +90,7 @@ class MyshixunsController < ApplicationController ActiveRecord::Base.transaction do begin t1 = Time.now - Rails.logger.info("@@@222222#{params[:jsonTestDetails]}") + uid_logger_dubug("@@@222222#{params[:jsonTestDetails]}") jsonTestDetails = JSON.parse(params[:jsonTestDetails]) timeCost = JSON.parse(params[:timeCost]) brige_end_time = Time.parse(timeCost['evaluateEnd']) if timeCost['evaluateEnd'].present? @@ -99,7 +99,7 @@ class MyshixunsController < ApplicationController game_id = jsonTestDetails['buildID'] sec_key = jsonTestDetails['sec_key'] - logger.info("training_task_status start#1**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") + uid_logger_dubug("training_task_status start-#{game_id}-1#{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") resubmit = jsonTestDetails['resubmit'] outPut = tran_base64_decode64(jsonTestDetails['outPut']) @@ -116,17 +116,14 @@ class MyshixunsController < ApplicationController pics = params[:tpiRepoPath] game.update_column(:picture_path, pics) end - logger.info("training_task_status start#2**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") max_query_index = game.outputs ? (game.outputs.first.try(:query_index).to_i + 1) : 1 test_set_score = 0 unless jenkins_testsets.blank? jenkins_testsets.each_with_index do |j_test_set, i| - logger.info("j_test_set: ############## #{j_test_set}") actual_output = tran_base64_decode64(j_test_set['output']) #ts_time += j_test_set['testSetTime'].to_i # is_public = test_sets.where(:position => j_test_set['caseId']).first.try(:is_public) - logger.info "actual_output:################################################# #{actual_output}" ts_time = format("%.2f", j_test_set['testSetTime'].to_f/1000000000).to_f if j_test_set['testSetTime'] ts_mem = format("%.2f", j_test_set['testSetMem'].to_f/1024/1024).to_f if j_test_set['testSetMem'] @@ -139,15 +136,12 @@ class MyshixunsController < ApplicationController end end end - uid_logger("#############status: #{status}") record = EvaluateRecord.where(:identifier => sec_key).first - logger.info("training_task_status start#3**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") answer_deduction_percentage = (100 - game.answer_deduction) / 100.to_f # 查看答案后剩余分数的百分比. # answer_deduction是查看答案的扣分比例 # status:0表示评测成功 if status == "0" if resubmit.present? - uid_logger("#############resubmitdaiao: #{resubmit}") game.update_attributes!(:retry_status => 2, :resubmit_identifier => resubmit) challenge.path.split(";").each do |path| game_passed_code(path.try(:strip), myshixun, game_id) @@ -205,7 +199,6 @@ class MyshixunsController < ApplicationController :pod_execute => timeCost['execute'], :test_cases => test_cases_time, :brige => timeCost['evaluateAllTime'], :return_back => return_back_time) end - uid_logger("training_task_status start#4**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") sucess_status # rescue Exception => e # tip_exception(e.message) @@ -265,10 +258,10 @@ class MyshixunsController < ApplicationController @sec_key = generate_identifier(EvaluateRecord, 12) record = EvaluateRecord.create!(:user_id => current_user.id, :shixun_id => @myshixun.shixun_id, :game_id => game_id, :identifier => @sec_key, :exec_time => exec_time) - uid_logger("-- game build: file update #{@sec_key}, record id is #{record.id}, time is **** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") + uid_logger_dubug("-- game build: file update #{@sec_key}, record id is #{record.id}, time is **** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") end # 隐藏代码文件 和 VNC的都不需要走版本库 - unless @hide_code || @myshixun.shixun&.vnc_evaluate + unless @hide_code || (@myshixun.shixun&.vnc_evaluate && params[:evaluate].present?) # 远程版本库文件内容 last_content = GitService.file_content(repo_path: @repo_path, path: path)["content"] content = if @myshixun.mirror_name.select {|a| a.include?("MachineLearning") || a.include?("Python")}.present? && params[:content].present? @@ -276,8 +269,8 @@ class MyshixunsController < ApplicationController else params[:content] end - Rails.logger.info("###11222333####{content}") - Rails.logger.info("###222333####{last_content}") + uid_logger_dubug("###11222333####{content}") + uid_logger_dubug("###222333####{last_content}") if content != last_content @content_modified = 1 @@ -285,8 +278,8 @@ class MyshixunsController < ApplicationController author_name = current_user.real_name author_email = current_user.git_mail message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted" - uid_logger("112233#{author_name}") - uid_logger("112233#{author_email}") + uid_logger_dubug("112233#{author_name}") + uid_logger_dubug("112233#{author_email}") @content = GitService.update_file(repo_path: @repo_path, file_path: path, message: message, diff --git a/app/controllers/searchs_controller.rb b/app/controllers/searchs_controller.rb index 1ea1c5d05..130e8a5cd 100644 --- a/app/controllers/searchs_controller.rb +++ b/app/controllers/searchs_controller.rb @@ -1,9 +1,12 @@ class SearchsController < ApplicationController + after_action :record_search_keyword, only: [:index] + def index @results = SearchService.call(search_params) end private + def search_params params.permit(:keyword, :type, :page, :per_page) end diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 98af25b7d..05c3500ee 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -232,10 +232,12 @@ class ShixunsController < ApplicationController # 同步私密版本库 if @shixun.shixun_secret_repository - repo_name = "#{current_user.login}/secret_#{@shixun.identifier}" + # 源仓库的的私密版本库地址 + repo_name = @shixun.shixun_secret_repository.repo_name + # 新生成的地址 fork_repository_name = "#{current_user.login}/secret_#{@new_shixun.identifier}" ShixunSecretRepository.create!(shixun_id: @new_shixun.id, - repo_name: "#{repo_name}", + repo_name: "#{fork_repository_name}", secret_dir_path: @shixun.shixun_secret_repository.secret_dir_path) GitService.fork_repository(repo_path: "#{repo_name}.git", fork_repository_path: (fork_repository_name + ".git")) end @@ -262,6 +264,11 @@ class ShixunsController < ApplicationController :mirror_repository_id => config.mirror_repository_id) end + # 同步高校限制 + @shixun.shixun_schools.each do |school| + ShixunSchool.create!(shixun_id: @new_shixun.id, school_id: school.school_id) + end + # fork版本库 logger.info("###########fork_repo_path: ######{@repo_path}") project_fork(@new_shixun, @repo_path, current_user.login) @@ -330,7 +337,10 @@ class ShixunsController < ApplicationController end rescue Exception => e uid_logger_error("copy shixun failed ##{e.message}") - g.delete_project(gshixungshixun.id) if gshixun.try(:id).present? # 异常后,如果已经创建了版本库需要删除该版本库 + # 删除版本库 + # 删除私密版本库 + GitService.delete_repository(repo_path: "#{fork_repository_name}.git") if @new_shixun.shixun_secret_repository&.repo_name + GitService.delete_repository(repo_path: @new_shixun.repo_path) if @new_shixun.repo_path tip_exception("实训Fork失败") raise ActiveRecord::Rollback end diff --git a/app/controllers/weapps/code_sessions_controller.rb b/app/controllers/weapps/code_sessions_controller.rb index b5886efd8..687605fc4 100644 --- a/app/controllers/weapps/code_sessions_controller.rb +++ b/app/controllers/weapps/code_sessions_controller.rb @@ -5,16 +5,23 @@ class Weapps::CodeSessionsController < Weapps::BaseController result = Wechat::Weapp.jscode2session(params[:code]) - # 已授权,绑定过账号 + # 能根据 code 拿到 unionid open_user = OpenUsers::Wechat.find_by(uid: result['unionid']) if open_user.present? && open_user.user successful_authentication(open_user.user) set_session_unionid(result['unionid']) logged = true else - # 新用户 + # 根据 code没拿到 unionid user_info = Wechat::Weapp.decrypt(result['session_key'], params[:encrypted_data], params[:iv]) + # 老用户,已绑定 + open_user = OpenUsers::Wechat.find_by(uid: user_info['unionId']) + if open_user.present? && open_user.user + successful_authentication(open_user.user) + logged = true + end + set_session_unionid(user_info['unionId']) end @@ -22,5 +29,7 @@ class Weapps::CodeSessionsController < Weapps::BaseController set_weapp_session_key(result['session_key']) # weapp session_key写入缓存 后续解密需要 render_ok(openid: result['openid'], logged: logged) + rescue Wechat::Error => ex + render_error(ex.message) end end \ No newline at end of file diff --git a/app/controllers/weapps/searchs_controller.rb b/app/controllers/weapps/searchs_controller.rb new file mode 100644 index 000000000..b4960e7b1 --- /dev/null +++ b/app/controllers/weapps/searchs_controller.rb @@ -0,0 +1,13 @@ +class Weapps::SearchsController < Weapps::BaseController + after_action :record_search_keyword, only: [:index] + + def index + @results = Weapps::SearchQuery.call(search_params) + end + + private + + def search_params + params.permit(:keyword, :type, :page, :per_page) + end +end \ No newline at end of file diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 395d67913..eadbfa05c 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -414,7 +414,7 @@ module ExercisesHelper score2 = 0.0 #填空题 score5 = 0.0 #实训题 ques_stand = [] #问题是否正确 - exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges) + exercise_questions = exercise.exercise_questions.includes(:exercise_standard_answers,:exercise_shixun_challenges) exercise_questions&.each do |q| begin if q.question_type != 5 diff --git a/app/libs/hot_search_keyword.rb b/app/libs/hot_search_keyword.rb index f026142cb..f79d1641e 100644 --- a/app/libs/hot_search_keyword.rb +++ b/app/libs/hot_search_keyword.rb @@ -3,6 +3,7 @@ class HotSearchKeyword class << self def add(keyword) return if keyword.blank? + Rails.logger.info("[Hot Keyword] #{keyword} score increment ~") Rails.cache.data.zincrby(redis_key, 1, keyword) end diff --git a/app/libs/wechat/client.rb b/app/libs/wechat/client.rb index 5ac0a28f2..43d5b0732 100644 --- a/app/libs/wechat/client.rb +++ b/app/libs/wechat/client.rb @@ -53,13 +53,13 @@ class Wechat::Client private def request(method, url, **params) - Rails.logger.error("[wechat] request: #{method} #{url} #{params.except(:secret).inspect}") + Rails.logger.info("[wechat] request: #{method} #{url} #{params.except(:secret).inspect}") client = Faraday.new(url: BASE_SITE) response = client.public_send(method, url, params) result = JSON.parse(response.body) - Rails.logger.error("[wechat] response:#{response.status} #{result.inspect}") + Rails.logger.info("[wechat] response:#{response.status} #{result.inspect}") if response.status != 200 raise Wechat::Error.parse(result) diff --git a/app/libs/wechat/weapp.rb b/app/libs/wechat/weapp.rb index 755c9351a..9684206cd 100644 --- a/app/libs/wechat/weapp.rb +++ b/app/libs/wechat/weapp.rb @@ -34,7 +34,7 @@ class Wechat::Weapp data = cipher.update(encrypted_data) << cipher.final result = JSON.parse(data[0...-data.last.ord]) - raise Wechat::Error, '解密错误' if result.dig('watermark', 'appid') != appid + raise Wechat::Error.new(-1, '解密错误') if result.dig('watermark', 'appid') != appid result end diff --git a/app/models/application_record.rb b/app/models/application_record.rb index a876440c3..ded4119cd 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,9 +1,15 @@ class ApplicationRecord < ActiveRecord::Base include NumberDisplayHelper + attr_accessor :_extra_data + self.abstract_class = true def format_time(time) time.present? ? time.strftime('%Y-%m-%d %H:%M') : '' end + + def display_extra_data(key) + _extra_data&.[](key) + end end diff --git a/app/models/competition.rb b/app/models/competition.rb index 23b1e3c81..8b9d59ed2 100644 --- a/app/models/competition.rb +++ b/app/models/competition.rb @@ -55,7 +55,7 @@ class Competition < ApplicationRecord # 是否为个人赛 def personal? - competition_staffs.maximum(:maximum) == 1 + competition_staffs.maximum(:maximum) == 1 || max_num == 1 end # 报名是否结束 @@ -80,12 +80,12 @@ class Competition < ApplicationRecord # 老师是否能多次报名 def teacher_multiple_limited? - teacher_staff.mutiple_limited? + teacher_staff&.mutiple_limited? end # 队员是否能多次报名 def member_multiple_limited? - member_staff.mutiple_limited? + member_staff&.mutiple_limited? end def max_min_stage_time @@ -101,7 +101,7 @@ class Competition < ApplicationRecord private def create_competition_modules - CompetitionModule.bulk_insert(*%i[competition_id name position]) do |worker| + CompetitionModule.bulk_insert(*%i[competition_id name position created_at updated_at]) do |worker| %w(首页 报名 通知公告 排行榜 资料下载).each_with_index do |name, index| worker.add(competition_id: id, name: name, position: index + 1) end diff --git a/app/models/competition_team.rb b/app/models/competition_team.rb index 878f58882..6c2b99859 100644 --- a/app/models/competition_team.rb +++ b/app/models/competition_team.rb @@ -32,6 +32,15 @@ class CompetitionTeam < ApplicationRecord code end + def teachers_info + info = "" + teachers.each do |teacher| + teacher_info = "#{teacher.user.real_name}/#{teacher.user.school_name}" + info += info == "" ? teacher_info : "、#{teacher_info}" + end + info + end + def teachers_name teachers.map{|teacher| teacher.user.real_name}.join(",") end diff --git a/app/models/user.rb b/app/models/user.rb index 103f9e0b5..135b85e25 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -237,6 +237,11 @@ class User < ApplicationRecord professional_certification end + # 学校所在的地区 + def school_province + user_extension&.school&.province || '' + end + # 用户的学校名称 def school_name user_extension&.school&.name || '' diff --git a/app/queries/admins/competition_enroll_list_query.rb b/app/queries/admins/competition_enroll_list_query.rb new file mode 100644 index 000000000..64f5dc7f8 --- /dev/null +++ b/app/queries/admins/competition_enroll_list_query.rb @@ -0,0 +1,40 @@ +class Admins::CompetitionEnrollListQuery < ApplicationQuery + include CustomSortable + + attr_reader :competition, :params + + sort_columns :created_at, :competition_team_id, default_by: :created_at, default_direction: :desc + + def initialize(competition, params) + @competition = competition + @params = params + end + + def call + members = competition.team_members + only_teacher = competition.competition_staffs.count == 1 && competition.competition_staffs.first.category == 'teacher' + members = members.where("team_members.is_teacher = 0") unless only_teacher # 只有老师报名时才显示老师,此时老师作为队员 + + + school = params[:school].to_s.strip + if school.present? + school_ids = School.where("schools.name like ?", "%#{school}%").pluck(:id) + school_ids = school_ids.size == 0 ? "(-1)" : "(" + school_ids.join(",") + ")" + members = members.joins(user: :user_extension).where("user_extensions.school_id in #{school_ids}") + end + + location = params[:location].to_s.strip + if location.present? + members = members.joins(user: { user_extension: :school }).where("schools.province like ?", "%#{location}%") + end + + # 关键字模糊查询 + keyword = params[:keyword].to_s.strip + if keyword.present? + members = members.joins(:competition_team) + .where('competition_teams.name LIKE :keyword', keyword: "%#{keyword}%") + end + + custom_sort(members, params[:sort_by], params[:sort_direction]) + end +end \ No newline at end of file diff --git a/app/queries/admins/user_statistic_query.rb b/app/queries/admins/user_statistic_query.rb new file mode 100644 index 000000000..d1811e5ab --- /dev/null +++ b/app/queries/admins/user_statistic_query.rb @@ -0,0 +1,138 @@ +class Admins::UserStatisticQuery < ApplicationQuery + include CustomSortable + + attr_reader :params + + sort_columns :study_challenge_count, :finish_challenge_count, :study_shixun_count, :finish_shixun_count, + default_by: :finish_shixun_count, default_direction: :desc + + def initialize(params) + @params = params + end + + def call + users = User.where(type: 'User').group(:id) + + users = users.joins(:user_extension).where(user_extensions: { school_id: params[:school_id] }) if params[:school_id].present? + + total = users.count.count + + # 根据排序字段进行查询 + users = query_by_sort_column(users, params[:sort_by]) + users = custom_sort(users, params[:sort_by], params[:sort_direction]) + + users = users.includes(user_extension: [:school, :department]) + users = users.limit(page_size).offset(offset).to_a + # 查询并组装其它数据 + users = package_other_data(users) + + [total, users] + end + + private + + def package_other_data(users) + ids = users.map(&:id) + + study_myshixun = Myshixun.where(user_id: ids) + finish_myshixun = Myshixun.where(user_id: ids, status: 1) + study_challenge = Game.joins(:myshixun).where(myshixuns: { user_id: ids }).where(status: [0, 1, 2]) + finish_challenge = Game.joins(:myshixun).where(myshixuns: { user_id: ids }).where(status: 2) + + if time_range.present? + study_myshixun = study_myshixun.where(updated_at: time_range) + finish_myshixun = finish_myshixun.where(updated_at: time_range) + study_challenge = study_challenge.where(updated_at: time_range) + finish_challenge = finish_challenge.where(updated_at: time_range) + end + + study_myshixun_map = study_myshixun.group(:user_id).count + finish_myshixun_map = finish_myshixun.group(:user_id).count + study_challenge_map = study_challenge.group(:user_id).count + finish_challenge_map = finish_challenge.group(:user_id).count + + users.each do |user| + user._extra_data = { + study_shixun_count: study_myshixun_map.fetch(user.id, 0), + finish_shixun_count: finish_myshixun_map.fetch(user.id, 0), + study_challenge_count: study_challenge_map.fetch(user.id, 0), + finish_challenge_count: finish_challenge_map.fetch(user.id, 0), + } + end + + users + end + + def query_by_sort_column(users, sort_by_column) + base_query_column = 'users.*' + + case sort_by_column.to_s + when 'study_shixun_count' then + users = + if time_range.present? + users.joins("LEFT JOIN myshixuns ON myshixuns.user_id = users.id "\ + "AND myshixuns.updated_at BETWEEN '#{time_range.min}' AND '#{time_range.max}'") + else + users.left_joins(:myshixuns) + end + + users.select("#{base_query_column}, COUNT(*) study_shixun_count") + when 'finish_shixun_count' then + users = + if time_range.present? + users.joins("LEFT JOIN myshixuns ON myshixuns.user_id = users.id AND myshixuns.status = 1 AND "\ + "myshixuns.updated_at BETWEEN '#{time_range.min}' AND '#{time_range.max}'") + else + users.joins('LEFT JOIN myshixuns ON myshixuns.user_id = users.id AND myshixuns.status = 1') + end + + users.select("#{base_query_column}, COUNT(*) finish_shixun_count") + when 'study_challenge_count' then + users = + if time_range.present? + users.joins('LEFT JOIN myshixuns ON myshixuns.user_id = users.id') + .joins("LEFT JOIN games ON games.myshixun_id = myshixuns.id "\ + "AND games.status IN (0,1,2) AND games.updated_at BETWEEN '#{time_range.min}' AND '#{time_range.max}'") + else + users.joins('LEFT JOIN myshixuns ON myshixuns.user_id = users.id') + .joins("LEFT JOIN games ON games.myshixun_id = myshixuns.id AND games.status IN (0,1,2)") + end + + users.select("#{base_query_column}, COUNT(*) study_challenge_count") + when 'finish_challenge_count' then + users = + if time_range.present? + users.joins('LEFT JOIN myshixuns ON myshixuns.user_id = users.id') + .joins("LEFT JOIN games ON games.myshixun_id = myshixuns.id "\ + "AND games.status = 2 AND games.updated_at BETWEEN '#{time_range.min}' AND '#{time_range.max}'") + else + users.joins('LEFT JOIN myshixuns ON myshixuns.user_id = users.id') + .joins("LEFT JOIN games ON games.myshixun_id = myshixuns.id AND games.status = 2") + end + + users.select("#{base_query_column}, COUNT(*) finish_challenge_count") + else + users + end + end + + def time_range + @_time_range ||= begin + case params[:date] + when 'weekly' then 1.weeks.ago..Time.now + when 'monthly' then 1.months.ago..Time.now + when 'quarterly' then 3.months.ago..Time.now + when 'yearly' then 1.years.ago..Time.now + else '' + end + end + end + + def page_size + params[:per_page].to_i.zero? ? 20 : params[:per_page].to_i + end + + def offset + (params[:page].to_i.zero? ? 0 : params[:page].to_i - 1) * page_size + end +end diff --git a/app/queries/weapps/search_query.rb b/app/queries/weapps/search_query.rb new file mode 100644 index 000000000..665480073 --- /dev/null +++ b/app/queries/weapps/search_query.rb @@ -0,0 +1,37 @@ +class Weapps::SearchQuery < ApplicationQuery + include ElasticsearchAble + + attr_reader :params + + def initialize(params) + @params = params + end + + def call + modal_name.search(keyword, search_options) + end + + private + + def search_options + hash = { + fields: [:name], + page: page, + per_page: per_page + } + hash.merge(where: { status: 2 }) if modal_name == Shixun + + hash + end + + def modal_name + @_modal_name ||= begin + case params[:type].to_s + when 'subject' then Subject + when 'shixun' then Shixun + when 'course' then Course + else Subject + end + end + end +end \ No newline at end of file diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index a7b533d05..4e34320ea 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -69,7 +69,7 @@ class ExercisePublishTask :subjective_score => subjective_score, :commit_method => exercise_user&.commit_method.to_i > 0 ? exercise_user&.commit_method.to_i : 3 } - exercise_user.update_attributes(commit_option) + exercise_user.update_attributes!(commit_option) end rescue Exception => e Rails.logger.info("rescue errors ___________________________#{e}") diff --git a/app/views/admins/competitions/enroll_list.html.erb b/app/views/admins/competitions/enroll_list.html.erb deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/views/admins/competitions/index.html.erb b/app/views/admins/competitions/index.html.erb index 736f0514e..41e061fc1 100644 --- a/app/views/admins/competitions/index.html.erb +++ b/app/views/admins/competitions/index.html.erb @@ -2,22 +2,26 @@ <% add_admin_breadcrumb('竞赛列表', admins_competitions_path) %> <% end %> -
序号 | +<%= sort_tag('战队ID', name: 'competition_team_id', path: admins_competition_enroll_lists_path(@competition)) %> | +战队名称 | +创建者 | +队员姓名 | +职业 | +学号 | +队员学校 | +地区 | +指导老师 | +<%= sort_tag('报名时间', name: 'created_at', path: admins_competition_enroll_lists_path(@competition)) %> | +
---|---|---|---|---|---|---|---|---|---|---|
<%= page_no %> | +<%= member.competition_team_id %> | +<%= @personal ? "--" : team.name %> | +<%= team.user.real_name %> | +<%= member.user.real_name %> | +<%= member.user.identity %> | +<%= member.user.student_id %> | +<%= member.user.school_name %> | +<%= member.user.school_province %> | +<%= @personal ? "--" : team.teachers_info %> | +<%= member.created_at.strftime('%Y-%m-%d %H:%M') %> | +