Merge branch 'develop' into educoder

dev_partners
daiao 6 years ago
commit aa525adae9

@ -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]

@ -4,11 +4,12 @@ class Managements::SchoolsController < Managements::BaseController
def statistics
@sub_type = 1
params[:sort_by] ||= :teacher_count
params[:sort_direction] ||= :desc
params[:sort_by] = :teacher_count if params[:sort_by].blank?
params[:sort_direction] = :desc if params[:sort_direction].blank?
schools = Management::SchoolReportService.new(params).call
@schools = paginateHelper schools
service = Management::SchoolReportService.new(params)
@obj_count, @schools = service.call
@obj_pages = Paginator.new(@obj_count, 20, params[:page])
respond_to do |format|
format.html { load_statistic_total }
@ -19,20 +20,20 @@ class Managements::SchoolsController < Managements::BaseController
def data_grow
@sub_type = 2
params[:data_type] ||= 'grow'
params[:sort_by] ||= :teacher_increase_count
params[:sort_direction] ||= :desc
params[:sort_by] = :teacher_increase_count if params[:sort_by].blank?
params[:sort_direction] = :desc if params[:sort_direction].blank?
service = Management::SchoolDataGrowService.new(params)
@grow_summary = service.grow_summary
@obj_count, @reports = service.call
@obj_pages = Paginator.new(@obj_count, Management::SchoolDataGrowService::PAGE_SIZE, params[:page])
@obj_pages = Paginator.new(@obj_count, 20, params[:page])
end
def data_contrast
params[:contrast_column] = :teacher_increase_count if params[:contrast_column].blank?
params[:sort_direction] ||= :desc
params[:sort_by] ||= :percentage
params[:sort_by] = :percentage
# 无对比日期时直接返回无数据页面
if useless_contrast_date_parameter?
@ -41,16 +42,17 @@ class Managements::SchoolsController < Managements::BaseController
end
@obj_count, @reports = Management::SchoolDataContrastService.new(params).call
@obj_pages = Paginator.new(@obj_count, Management::SchoolDataContrastService::PAGE_SIZE, params[:page])
@obj_pages = Paginator.new(@obj_count, 20, params[:page])
rescue Management::SchoolDataContrastService::ParameterError
raise '参数错误'
end
def statistics_xlsx
@schools = Management::SchoolReportService.new(params).call
params[:per_page] = 10000
_count, @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
filename = ['学校统计总表', params[:keyword], Time.zone.now.strftime('%Y%m%d%H%M%S')].join('-') << '.xlsx'
render xlsx: 'statistics_xlsx', filename: filename
end
private

@ -4119,7 +4119,7 @@ end
sheet1[count_row, 5] = show_shixun_mirror(shixun)
sheet1[count_row, 6] = shixun.fork_identifier
sheet1[count_row, 7] = shixun.challenges.count
sheet1[count_row, 7] = Setting.server_url + shixun_path(shixun)
sheet1[count_row, 8] = Setting.server_url + shixun_path(shixun)
count_row += 1
end
book.write xls_report

@ -185,7 +185,7 @@ class OauthController < ApplicationController
ActiveRecord::Base.transaction do
# 如果Educoder中已存在与该OpenI用户的邮箱相同的用户则会直接跳转到登录educoder的登录页面
existing_user = User.find_by_mail(email)
break if existing_user.present?
break if existing_user.present? && email.present?
user = User.new(lastname: name, mail: email, mail_notification: email)
user.login = generate_login('m')

@ -3,7 +3,7 @@
class ShixunsController < ApplicationController
layout 'base_shixun'
before_filter :require_login, :except => [:ghook, :download_file, :show, :index]
before_filter :check_authentication, :except => [:ghook, :download_file, :show, :index]
before_filter :check_authentication, :except => [:ghook, :download_file, :show, :index, :operation]
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]
skip_before_filter :verify_authenticity_token, :only => [:ghook, :download_file]

@ -2,7 +2,7 @@
class SubjectsController < ApplicationController
layout 'base_subject'
# 如要添加或修改before_filter时请将handle_openi_request这个before_filter放至第一位
# before_filter :handle_openi_request, if: -> { user_login_and_from_openi? }, only: [:show]
before_filter :handle_openi_request, if: -> { user_login_and_from_openi? }, only: [:show]
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]

@ -612,13 +612,12 @@ module ApplicationHelper
=end
user_e = UserExtensions.where(:user_id => User.current.id).first
if User.current.lastname.blank? || user_e.school_id.blank? || user_e.identity.blank? || User.current.mail.blank?
redirect_to user_info_path()
redirect_to my_account_path
Rails.logger.info("check_authentication end")
return
elsif User.current.certification != 1 # 系统没有授权
day_cer = UserDayCertification.where(:user_id => User.current.id).last
unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400
redirect_to my_account_path()
redirect_to my_account_path
Rails.logger.info("check_authentication end")
return
end

@ -56,6 +56,8 @@ class Course < ActiveRecord::Base
has_many :course_homework_categories, :dependent => :destroy, :order => "CONVERT(name USING gbk) COLLATE gbk_chinese_ci ASC"
has_many :homework_commons, :dependent => :destroy
has_many :shixun_homework_commons, class_name: 'HomeworkCommon', conditions: 'homework_type = 4'
has_many :other_homework_commons, class_name: 'HomeworkCommon', conditions: 'homework_type IN (1, 3)'
has_many :homework_group_settings, :dependent => :destroy
has_many :student_works, :through => :homework_commons, :dependent => :destroy

@ -6,6 +6,7 @@ class School < ActiveRecord::Base
:identifier, :is_online, :video_desc, :video_name,:course_link,
:course_name, :partner_id, :customer_id
has_many :courses
has_many :active_courses, class_name: 'Course', conditions: 'is_end = false'
has_many :departments, :dependent => :destroy
has_many :shixun_schools, :dependent => :destroy
has_many :shixuns, :through => :shixun_schools
@ -22,6 +23,12 @@ class School < ActiveRecord::Base
# banner图片信息
has_many :school_images, :dependent => :destroy
# 报表信息
has_many :school_daily_reports
has_many :teacher_extensions, conditions: "identity = #{User::TEACHER}", class_name: 'UserExtensions'
has_many :student_extensions, conditions: "identity = #{User::STUDENT}", class_name: 'UserExtensions'
# 视频附件
acts_as_attachable

@ -17,15 +17,17 @@ class Management::SchoolDataContrastService
def call
validate_parameter!
reports = SchoolDailyReport.select(select_columns)
reports = School.joins(:school_daily_reports).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}%")
reports = reports.where("schools.name LIKE :keyword OR schools.id LIKE :keyword", keyword: "%#{keyword}%")
end
count = reports.count('distinct(school_id)')
reports = reports.group(:school_id).limit(PAGE_SIZE).offset(offset)
count = reports.count('distinct(schools.id)')
sql = query_report_sql(reports.group('schools.id').to_sql)
reports = SchoolDailyReport.find_by_sql(sql)
[count, reports]
end
@ -54,8 +56,13 @@ class Management::SchoolDataContrastService
end
def select_columns
"school_id, school_name,"\
"schools.id school_id, schools.name 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

@ -14,12 +14,12 @@ class Management::SchoolDataGrowService
end
def call
reports = query_reports.group(:school_id)
reports = query_reports.group('schools.id')
count = reports.count.count
reports = reports.select(
'school_id, school_name,'\
'schools.id school_id, schools.name school_name,'\
'SUM(teacher_increase_count) teacher_increase_count,'\
'SUM(student_increase_count) student_increase_count,'\
'SUM(course_increase_count) course_increase_count,'\
@ -28,7 +28,7 @@ class Management::SchoolDataGrowService
)
reports = custom_sort(reports, params[:sort_by], params[:sort_direction])
reports = reports.limit(PAGE_SIZE).offset(offset)
reports = reports.order('school_id asc').limit(PAGE_SIZE).offset(offset)
[count, reports]
end
@ -47,11 +47,18 @@ class Management::SchoolDataGrowService
private
def query_reports
reports = SchoolDailyReport.where(date: query_date)
date = query_date
date_condition = if date.is_a?(Range)
"sdr.date BETWEEN '#{date.min.strftime('%Y-%m-%d')}' AND '#{date.max.strftime('%Y-%m-%d')}'"
else
"sdr.date = '#{date.strftime('%Y-%m-%d')}'"
end
reports = School.joins("LEFT JOIN school_daily_reports sdr ON sdr.school_id = schools.id AND #{date_condition}")
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}%")
reports = reports.where("schools.name LIKE :keyword OR schools.id LIKE :keyword", keyword: "%#{keyword}%")
end
reports

@ -12,43 +12,85 @@ class Management::SchoolReportService
end
def call
schools = School.select(select_columns_sql)
schools = School.group('schools.id')
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
count = schools.count.count
# 根据排序字段进行查询
schools = query_by_sort_column(schools, params[:sort_by])
schools = custom_sort(schools, params[:sort_by], params[:sort_direction])
schools
schools = schools.limit(page_size).offset(offset)
# 查询并组装其它数据
schools = package_other_data(schools)
[count, schools]
end
def package_other_data(schools)
ids = schools.map(&:id)
student_map = UserExtensions.where(school_id: ids, identity: User::STUDENT).group(:school_id).count
teacher_map = UserExtensions.where(school_id: ids, identity: User::TEACHER).group(:school_id).count
homeworks = HomeworkCommon.joins(:course)
shixun_homework_map = homeworks.where(homework_type: 4, courses: { school_id: ids }).group('school_id').count
other_homework_map = homeworks.where(homework_type: [1, 3], courses: { school_id: ids }).group('school_id').count
courses = Course.where(school_id: ids).group('school_id')
course_map = courses.count
nearly_course_time_map = courses.joins(:course_activities).maximum('course_activities.updated_at')
active_course_map = courses.where(is_end: false).count
schools.map do |school|
{
id: school.id,
name: school.name,
teacher_count: teacher_map[school.id],
student_count: student_map[school.id],
homework_count: shixun_homework_map[school.id],
other_homework_count: other_homework_map[school.id],
course_count: course_map[school.id],
nearly_course_time: nearly_course_time_map[school.id],
active_course_count: active_course_map[school.id],
}
end
end
private
def select_columns_sql
<<-SQL
schools.id, schools.name,
(
SELECT COUNT(*) FROM user_extensions ue
WHERE ue.school_id = schools.id AND ue.identity = #{User::STUDENT}
) student_count,
(
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
LEFT JOIN courses ON courses.id = hc.course_id
WHERE courses.school_id = schools.id AND hc.homework_type = 4
) 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
def query_by_sort_column(schools, sort_by_column)
base_query_column = 'schools.id, schools.name'
case sort_by_column.to_s
when 'teacher_count' then
schools.joins(:teacher_extensions).select("#{base_query_column}, COUNT(*) teacher_count")
when 'student_count' then
schools.joins(:student_extensions).select("#{base_query_column}, COUNT(*) student_count")
when 'homework_count' then
schools.joins(courses: :shixun_homework_commons).select("#{base_query_column}, COUNT(*) homework_count")
when 'other_homework_count' then
schools.joins(courses: :other_homework_commons).select("#{base_query_column}, COUNT(*) other_homework_count")
when 'course_count' then
schools.joins(:courses).select("#{base_query_column}, COUNT(*) course_count")
when 'nearly_course_time' then
schools.joins(courses: :course_activities).select("#{base_query_column}, MAX(course_activities.updated_at) nearly_course_time")
when 'active_course_count' then
schools.joins(:active_courses).select("#{base_query_column}, COUNT(*) active_course_count")
else
schools.joins(:teacher_extensions).select("#{base_query_column}, COUNT(*) teacher_count")
end
end
def page_size
params[:per_page] || 20
end
def offset
(params[:page].to_i.zero? ? 0 : params[:page].to_i - 1) * page_size
end
end

@ -18,6 +18,8 @@ class StatisticSchoolDailyReportTask
shixun_count = Shixun.joins(creator: :user_extensions)
.where('user_extensions.school_id = ?', school.id)
.where(created_at: yesterday).count
# 无有效数据时不记录
next if [teacher_count, student_count, course_count, shixun_count, active_user_count].all?(&:zero?)
create_params = {
school_id: school.id, school_name: school.name, teacher_increase_count: teacher_count,

@ -0,0 +1,69 @@
<div class="task-popup" style="width:600px;">
<div class=" task-popup-title clearfix task-popup-bggrey">
撤销授权
</div>
<div class="mt15 ml30 pb20">
<div class="mr15">
<%= form_tag({:controller => 'courses', :action => 'join_course_multi_role'}, :remote => true, :method => :post, :id => 'new-watcher-form') do %>
<ul>
<li class="clearfix">
<label class="panel-form-label fl">撤销原因:</label>
</li>
<li class="ml20">
<span>
<input type="checkbox" name="role[]" value="1" id="join_course_role_1" class="ml-3 mr5 magic-checkbox" style="float:left; margin-top: 8px;"/>
<label for="join_course_role_1" class="color4C4C4C">请如实填写您的个人资料</label>
</span>
<span>
<input type="checkbox" name="role[]" value="2" id="join_course_role_2" class="ml5 mr5 magic-checkbox" style="float:left; margin-top: 8px;"/>
<label for="join_course_role_2" class="color4C4C4C">请如实填写您的学校/单位信息</label>
</span>
<span>
<input type="checkbox" name="role[]" value="3" id="join_course_role_3" class="ml5 mr5 magic-checkbox" style="float:left; margin-top: 8px;"/>
<label for="join_course_role_3" class="color4C4C4C">请在职业栏中修改正确的身份信息</label>
</span>
<span>
<input type="checkbox" name="role[]" value="4" id="join_course_role_4" class="ml5 mr5 magic-checkbox" style="float:left; margin-top: 8px;"/>
<label for="join_course_role_4" class="color4C4C4C">请填写您的推荐人信息</label>
</span>
<span>
<input type="checkbox" name="role[]" value="5" id="join_course_role_5" class="ml5 mr5 magic-checkbox" style="float:left; margin-top: 8px;"/>
<label for="join_course_role_5" class="color4C4C4C">请告知获取平台资源的渠道,以及您的手机号,我们将主动联系您并授权使用</label>
</span>
<span>
<input type="checkbox" name="role[]" value="6" id="join_course_role_6" class="ml5 mr5 magic-checkbox" style="float:left; margin-top: 8px;"/>
<label for="join_course_role_6" class="color4C4C4C">您好,您的账号试用期限已过</label>
</span>
<span>
<input type="checkbox" name="role[]" value="7" id="join_course_role_7" class="ml5 mr5 magic-checkbox" style="float:left; margin-top: 8px;"/>
<label for="join_course_role_7" class="color4C4C4C">其他</label>
</span>
</li>
<li class="clearfix mt10">
<label class="panel-form-label fl">备注说明:</label>
<textarea class="remarktextarea fl panel-box-sizing candiate_answer" name="question_answer[]" placeholder="为选择的撤销原因补充备注说明...."></textarea>
</li>
<li class="clearfix mt20 edu-txt-center mb20">
<a href="javascript:void(0);" class="task-btn mr10" onclick="hideModal()">取消</a>
<a href="javascript:void(0);" class="task-btn task-btn-orange ml20" onclick="submit_join_course();">确定</a>
</li>
</ul>
<% end %>
</div>
</div>
</div>
<script>
</script>

@ -37,7 +37,8 @@
<span>申请理由:<%= authorization.apply_reason %></span>
</li>
<% if authorization.status == 2 %>
<li>原因:<span class="color-orange"><%= authorization.reason.blank? ? "空" : authorization.reason %></span></li>
<li><span class="color-red">撤销原因:</span><span><%= authorization.reason.blank? ? "空" : authorization.reason %></span></li>
<li><span class="color-red">备注说明:</span><span><%= authorization.reason.blank? ? "空" : authorization.reason %></span></li>
<% end %>
<div class="reason none">
<li class="clearfix edu-form-border mb10">

@ -24,7 +24,7 @@
<th width="22%">时段一<br><%= "#{params[:begin_date]}至#{params[:end_date]}" %></th>
<th width="22%">时段二<br><%= "#{params[:other_begin_date]}至#{params[:other_end_date]}" %></th>
<th width="20%" colspan="2">
变化情况
<%= sort_tag('变化情况', name: 'percentage', path: school_data_contrast_managements_path) %>
<br> 新 增 数 | 新增百分比)
</th>
</tr>

@ -31,11 +31,11 @@
<td><%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %></td>
<td><%= report.school_id %></td>
<td class="edu-txt-left"><%= report.school_name %></td>
<td><%= report.teacher_increase_count %></td>
<td><%= report.student_increase_count %></td>
<td><%= report.course_increase_count %></td>
<td><%= report.shixun_increase_count %></td>
<td><%= report.active_user_count %></td>
<td><%= report.teacher_increase_count.to_i %></td>
<td><%= report.student_increase_count.to_i %></td>
<td><%= report.course_increase_count.to_i %></td>
<td><%= report.shixun_increase_count.to_i %></td>
<td><%= report.active_user_count.to_i %></td>
</tr>
<% end %>
</tbody>

@ -18,15 +18,15 @@
<% @schools.each_with_index do |school, index| %>
<tr>
<td><%= (@obj_pages.page - 1) * @obj_pages.per_page + index + 1 %></td>
<td><%= school['id'] %></td>
<td class="edu-txt-left"><%= school['name'] %></td>
<td><%= school['teacher_count'] %></td>
<td><%= school['student_count'] %></td>
<td><%= school['course_count'] %></td>
<td><%= school['active_course_count'] %></td>
<td><%= school['homework_count'] %></td>
<td><%= school['other_homework_count'] %></td>
<td><%= format_time school['nearly_course_time'] %></td>
<td><%= school[:id] %></td>
<td class="edu-txt-left"><%= school[:name] %></td>
<td><%= school[:teacher_count].to_i %></td>
<td><%= school[:student_count].to_i %></td>
<td><%= school[:course_count].to_i %></td>
<td><%= school[:active_course_count].to_i %></td>
<td><%= school[:homework_count].to_i %></td>
<td><%= school[:other_homework_count].to_i %></td>
<td><%= format_time school[:nearly_course_time] %></td>
</tr>
<% end %>
</tbody>

@ -1,20 +1,12 @@
wb = xlsx_package.workbook
wb.add_worksheet(name: "统计总表") do |sheet|
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
@schools.each do |school|
sheet.add_row([
school['id'].to_s, school['name'].to_s, (school['teacher_count'] || 0).to_s, (school['student_count'] || 0).to_s,
(school['course_count'] || 0).to_s, (school['active_course_count'] || 0).to_s, (school['homework_count'] || 0).to_s,
(school['other_homework_count'] || 0).to_s, format_time(school['nearly_course_time'])
])
end
end

@ -1,6 +1,6 @@
<% if @mail %>
flag=true;
sure_box_redirect_btn('<%= security_settings_path %>', '开启实训,请先绑定邮箱','绑定邮箱');
sure_box_redirect_btn('<%= my_account_path %>', '开启实训,请先绑定邮箱','绑定邮箱');
<% else %>
<% if @is_modify.blank? %>
//为了防止浏览器阻挡,在实训路径中需要弹出新的页面,而实训首页又不需要弹出新的页面

@ -81,7 +81,7 @@
<td><%= user_query.blank? ? "--" : user_query.first[1] %></td>
<td><%= game.try(:end_time).nil? ? "--" : format_time(game.end_time) %></td>
<td><%= game.consumes_time %></td>
<td><%= game.status == 2 ? (game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i) : 0 %> / <%= game.challenge.st == 1 ? game.challenge.choose_score : game.challenge.score %></td>
<td><%= game.status == 2 ? (game.final_score.to_i < 0 ? 0 : game.challenge.choose_score.to_i) : 0 %> / <%= game.challenge.choose_score %></td>
</tr>
<% end %>
</tbody>

@ -30,11 +30,14 @@ namespace :school_daily_report do
reports = School.find_by_sql(sql)
data = reports.map do |report|
# 无效数据不记录
next if %w(teacher_count student_count course_count shixun_count active_user_count).all? { |key| report[key].zero? }
[
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
end.compact
batch_create_school_daily_reports!(data)
end
custom_logger("Statistic complete! date: #{date_str}")
@ -43,9 +46,27 @@ namespace :school_daily_report do
end
end
desc 'clear school daily report data'
task clear: :environment do
SchoolDailyReport.destroy_all
desc 'clear useless school daily report data'
task clear_useless_data: :environment do
condition = {
teacher_increase_count: 0, student_increase_count: 0, course_increase_count: 0,
shixun_increase_count: 0, active_user_count: 0
}
reports = SchoolDailyReport.where(condition)
# 因为数据量太大直接删除全部的话mysql会报错(Lock wait timeout exceeded)
min_date = reports.minimum(:date).to_time
now_date = Time.zone.now
custom_logger("Useless data total: #{reports.count}")
while min_date < now_date
custom_logger("Delete record in date range: #{min_date.strftime('%Y-%m-%d')} .. #{(min_date + 1.months).strftime('%Y-%m-%d')}) ~")
reports.where(date: min_date..(min_date + 1.months)).delete_all
custom_logger("Delete Success!")
min_date += 1.months
end
end
def query_size

@ -892,4 +892,15 @@ html>body #ajax-indicator { position: fixed; }
.coolor838383{
color:#838383;
}
.color4C4C4C{
color:#4C4C4C;
}
.remarktextarea{
width: 500px;
margin-left: 20px;
text-indent: 25px;
min-height: 100px;
}
Loading…
Cancel
Save