Merge branches 'competitions' and 'develop' of https://bdgit.educoder.net/Hjqreturn/educoder into ysmCompetitions
commit
847d2998e0
@ -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();
|
||||
});
|
||||
}
|
||||
});
|
@ -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);
|
||||
});
|
||||
}
|
||||
});
|
@ -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
|
@ -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
|
@ -0,0 +1,7 @@
|
||||
class HotKeywordsController < ApplicationController
|
||||
def index
|
||||
keywords = []
|
||||
keywords = HotSearchKeyword.hot(8) if HotSearchKeyword.available?
|
||||
render_ok(keywords: keywords)
|
||||
end
|
||||
end
|
@ -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
|
@ -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
|
||||
|
@ -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
|
@ -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
|
||||
|
@ -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
|
@ -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
|
@ -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
|
@ -0,0 +1 @@
|
||||
$('.competitions-list-container').html("<%= j( render partial: 'admins/competitions/shared/list', locals: { competitions: @competitions } ) %>");
|
@ -0,0 +1,4 @@
|
||||
var page_no = $("#competition-item-<%= @competition.id %>").children(":first").html();
|
||||
$("#competition-item-<%= @competition.id %>").html("<%= j render partial: "admins/competitions/shared/td", locals: {competition: @competition, page_no: 1} %>");
|
||||
$("#competition-item-<%= @competition.id %>").children(":first").html(page_no);
|
||||
show_success_flash();
|
@ -0,0 +1,4 @@
|
||||
var page_no = $("#competition-item-<%= @competition.id %>").children(":first").html();
|
||||
$("#competition-item-<%= @competition.id %>").html("<%= j render partial: "admins/competitions/shared/td", locals: {competition: @competition, page_no: 1} %>");
|
||||
$("#competition-item-<%= @competition.id %>").children(":first").html(page_no);
|
||||
show_success_flash();
|
@ -0,0 +1,28 @@
|
||||
<div class="modal fade admin-create-competition-modal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">新增竞赛</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="admin-create-competition-form" data-url="<%= admins_competitions_path %>">
|
||||
<div class="form-group d-flex">
|
||||
<label for="new_mirror_id" class="col-form-label">竞赛名称:</label>
|
||||
<div class="w-75 d-flex flex-column">
|
||||
<%= text_field_tag(:competition_name, nil, class: 'form-control', placeholder: '请输入竞赛名称') %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="error text-danger"></div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||
<button type="button" class="btn btn-primary submit-btn">确认</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,4 @@
|
||||
var page_no = $("#competition-item-<%= @competition.id %>").children(":first").html();
|
||||
$("#competition-item-<%= @competition.id %>").html("<%= j render partial: "admins/competitions/shared/td", locals: {competition: @competition, page_no: 1} %>");
|
||||
$("#competition-item-<%= @competition.id %>").children(":first").html(page_no);
|
||||
show_success_flash();
|
@ -0,0 +1,42 @@
|
||||
<table class="table text-center shixun-settings-list-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th width="4%" class="text-left">序号</th>
|
||||
<th width="6%"><%= sort_tag('战队ID', name: 'competition_team_id', path: admins_competition_enroll_lists_path(@competition)) %></th>
|
||||
<th width="12%">战队名称</th>
|
||||
<th width="10%">创建者</th>
|
||||
<th width="10%">队员姓名</th>
|
||||
<th width="6%">职业</th>
|
||||
<th width="12%">学号</th>
|
||||
<th width="10%">队员学校</th>
|
||||
<th width="6%">地区</th>
|
||||
<th width="16%">指导老师</th>
|
||||
<th width="8%"><%= sort_tag('报名时间', name: 'created_at', path: admins_competition_enroll_lists_path(@competition)) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% if enroll_lists.present? %>
|
||||
<% enroll_lists.each_with_index do |member, index| %>
|
||||
<tr id="competition-team-member-<%= member.id %>">
|
||||
<% team = member.competition_team %>
|
||||
<% page_no = list_index_no(@params_page.to_i, index) %>
|
||||
<td><%= page_no %></td>
|
||||
<td><%= member.competition_team_id %></td>
|
||||
<td><%= @personal ? "--" : team.name %></td>
|
||||
<td><%= team.user.real_name %></td>
|
||||
<td><%= member.user.real_name %></td>
|
||||
<td><%= member.user.identity %></td>
|
||||
<td><%= member.user.student_id %></td>
|
||||
<td><%= member.user.school_name %></td>
|
||||
<td><%= member.user.school_province %></td>
|
||||
<td><%= @personal ? "--" : team.teachers_info %></td>
|
||||
<td><%= member.created_at.strftime('%Y-%m-%d %H:%M') %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render 'admins/shared/no_data_for_table' %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= render partial: 'admins/shared/paginate', locals: { objects: enroll_lists } %>
|
@ -0,0 +1,33 @@
|
||||
<%
|
||||
define_admin_breadcrumbs do
|
||||
add_admin_breadcrumb('竞赛列表', admins_competitions_path)
|
||||
add_admin_breadcrumb(@competition.name)
|
||||
end
|
||||
%>
|
||||
|
||||
<div class="box search-form-container flex-column mb-0 pb-0 competition-enroll-list-form">
|
||||
<ul class="nav nav-tabs w-100 search-form-tabs">
|
||||
<li class="nav-item">
|
||||
<%= link_to '报名列表', admins_competition_enroll_lists_path(@competition), class: "nav-link search-form-tab active" %>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<%= link_to '获奖证书审批', admins_competition_enroll_lists_path(@competition), class: "nav-link search-form-tab" %>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="d-flex">
|
||||
<%= form_tag(admins_competition_enroll_lists_path(unsafe_params), method: :get, class: 'form-inline search-form mt-3 flex-1 d-flex', remote: true) do %>
|
||||
<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: '战队名称检索') %>
|
||||
<%= text_field_tag(:school, params[:school], class: 'form-control col-sm-2 ml-3', placeholder: '队员学校名称检索') %>
|
||||
<%= text_field_tag(:location, params[:location], class: 'form-control col-sm-2 ml-3', placeholder: '队员地区检索') %>
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
<%= link_to "清除", admins_competition_enroll_lists_path(@competition), class: "btn btn-default",'data-disable-with': '清除中...' %>
|
||||
<% end %>
|
||||
|
||||
<a href="javascript:void(0)" class="btn btn-primary mt-3" id="enroll-lists-export" data-competition-id="<%= @competition.id %>" data-disable-with = '导出中...'>导出</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="box competition-enroll-list-container">
|
||||
<%= render(partial: 'admins/enroll_lists/list', locals: { enroll_lists: @enroll_lists }) %>
|
||||
</div>
|
@ -0,0 +1 @@
|
||||
$('.competition-enroll-list-container').html("<%= j( render(partial: 'admins/enroll_lists/list', locals: { enroll_lists: @enroll_lists }) ) %>");
|
@ -0,0 +1,16 @@
|
||||
wb = xlsx_package.workbook
|
||||
wb.add_worksheet(name: '用户实训情况') do |sheet|
|
||||
sheet.add_row %w(姓名 单位部门 学习关卡数 完成关卡数 学习实训数 完成实训数)
|
||||
|
||||
@users.each do |user|
|
||||
data = [
|
||||
user.real_name,
|
||||
[user.school_name.presence, user.department_name.presence].compact.join(' - '),
|
||||
user.display_extra_data(:study_challenge_count),
|
||||
user.display_extra_data(:finish_challenge_count),
|
||||
user.display_extra_data(:study_shixun_count),
|
||||
user.display_extra_data(:finish_shixun_count)
|
||||
]
|
||||
sheet.add_row(data)
|
||||
end
|
||||
end
|
@ -0,0 +1,27 @@
|
||||
<% define_admin_breadcrumbs do %>
|
||||
<% add_admin_breadcrumb('用户实训情况') %>
|
||||
<% end %>
|
||||
|
||||
<div class="box search-form-container user-statistic-list-form">
|
||||
<%= form_tag(admins_user_statistics_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
|
||||
<div class="form-group col-12 col-md-auto">
|
||||
<label for="status">时间范围:</label>
|
||||
<% data_arrs = [['不限', ''], ['最近一周', 'weekly'], ['最近一个月', 'monthly'], ['最近三个月', 'quarterly'], ['最近一年', 'yearly']] %>
|
||||
<%= select_tag(:date, options_for_select(data_arrs, params[:date]), class: 'form-control') %>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-12 col-md-3">
|
||||
<label for="school_name">所属单位:</label>
|
||||
<%= hidden_field_tag(:school_id, params[:school_id]) %>
|
||||
<%= select_tag :school_name, options_for_select([''], params[:school_id]), class: 'form-control school-select flex-1' %>
|
||||
</div>
|
||||
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
|
||||
<% end %>
|
||||
<%= javascript_void_link '导出', class: 'btn btn-outline-primary export-action', 'data-url': export_admins_user_statistics_path(format: :xlsx) %>
|
||||
</div>
|
||||
|
||||
<div class="box user-statistic-list-container">
|
||||
<%= render partial: 'admins/user_statistics/shared/list', locals: { users: @users } %>
|
||||
</div>
|
@ -0,0 +1 @@
|
||||
$('.user-statistic-list-container').html("<%= j( render partial: 'admins/user_statistics/shared/list', locals: { users: @users } ) %>");
|
@ -0,0 +1,34 @@
|
||||
<table class="table table-hover text-center user-statistic-list-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th width="14%" class="text-left">姓名</th>
|
||||
<th width="38%" class="text-left">单位部门</th>
|
||||
<th width="12%"><%= sort_tag('学习关卡数', name: 'study_challenge_count', path: admins_user_statistics_path) %></th>
|
||||
<th width="12%"><%= sort_tag('完成关卡数', name: 'finish_challenge_count', path: admins_user_statistics_path) %></th>
|
||||
<th width="12%"><%= sort_tag('学习实训数', name: 'study_shixun_count', path: admins_user_statistics_path) %></th>
|
||||
<th width="12%"><%= sort_tag('完成实训数', name: 'finish_shixun_count', path: admins_user_statistics_path) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% if users.present? %>
|
||||
<% users.each do |user| %>
|
||||
<tr class="user-statistic-item-<%= user.id %>">
|
||||
<td class="text-left">
|
||||
<%= link_to "/users/#{user.login}", target: '_blank' do %>
|
||||
<%= overflow_hidden_span user.real_name, width: 100 %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="text-left"><%= display_text [user.school_name.presence, user.department_name.presence].compact.join(' - ') %></td>
|
||||
<td><%= user.display_extra_data(:study_challenge_count) %></td>
|
||||
<td><%= user.display_extra_data(:finish_challenge_count) %></td>
|
||||
<td><%= user.display_extra_data(:study_shixun_count) %></td>
|
||||
<td><%= user.display_extra_data(:finish_shixun_count) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render 'admins/shared/no_data_for_table' %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= render partial: 'admins/shared/paginate', locals: { objects: users } %>
|
@ -0,0 +1,9 @@
|
||||
json.count @results.total_count
|
||||
json.results do
|
||||
json.array! @results.with_highlights(multiple: true) do |obj, highlights|
|
||||
json.merge! obj.to_searchable_json
|
||||
json.type obj.class.name.downcase
|
||||
|
||||
json.title highlights.delete(:name)&.join('...') || obj.searchable_title
|
||||
end
|
||||
end
|
@ -0,0 +1,25 @@
|
||||
class MigrateExerciseChallengeScore < ActiveRecord::Migration[5.2]
|
||||
include ExercisesHelper
|
||||
def change
|
||||
exercise = Exercise.find_by(id: 2734)
|
||||
if exercise
|
||||
exercise.exercise_users.where("start_at is not null").each do |exercise_user|
|
||||
if exercise_user.end_at.nil?
|
||||
calculate_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
|
||||
subjective_score = exercise_user.subjective_score
|
||||
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
|
||||
total_score = calculate_score + total_score_subjective_score
|
||||
exercise_user.update_attributes!(score:total_score,objective_score:calculate_score,end_at:exercise.end_time,commit_status:1,status:1,commit_method:3)
|
||||
puts exercise_user.id
|
||||
else
|
||||
calculate_score = ExerciseShixunAnswer.where(user_id: exercise_user.user_id, exercise_question_id: exercise.exercise_questions.pluck(:id)).pluck(:score).sum
|
||||
subjective_score = exercise_user.subjective_score
|
||||
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
|
||||
total_score = calculate_score + total_score_subjective_score
|
||||
exercise_user.update_attributes!(score:total_score,objective_score:calculate_score) if total_score > exercise_user.score
|
||||
puts exercise_user.id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
File diff suppressed because one or more lines are too long
Binary file not shown.
Loading…
Reference in new issue