Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_harry

# Conflicts:
#	public/react/package.json
#	public/react/src/modules/courses/boards/TopicDetail.js
#	public/react/src/modules/courses/common/button/CheckAllGroup.js
#	public/react/src/modules/courses/coursesHome/CoursesHome.js
#	public/react/src/modules/page/main/ChooseRepositoryView.js
#	public/react/src/modules/paths/ShixunPathSearch.js
#	public/react/src/modules/paths/statics/DisplayTableData.js
#	public/react/src/modules/paths/statics/index.js
#	public/react/src/modules/tpm/TPMIndexHOC.js
#	public/react/src/modules/tpm/TPMsettings/Shixuninformation.js
合并
dev_aliyun2
杨树林 5 years ago
commit b05c23df75

@ -49,6 +49,8 @@ gem 'rqrcode_png'
gem 'acts-as-taggable-on', '~> 6.0'
gem 'omniauth-cas'
group :development, :test do
gem 'rspec-rails', '~> 3.8'
end

@ -120,5 +120,19 @@ $(document).on('turbolinks:load', function() {
});
}
});
// ------------ 上移/下移 -------------
$('.discipline-list-container').on('click', ".move-action", function () {
var $doAction = $(this);
var disciplineId = $doAction.data('id');
var opr = $doAction.data('opr');
$.ajax({
url: '/admins/disciplines/' + disciplineId + '/adjust_position',
method: 'POST',
dataType: 'script',
data: {opr: opr}
});
});
}
});

@ -3,19 +3,15 @@ $(document).on('turbolinks:load', function() {
// ============= 添加销售人员 ==============
var $addMemberModal = $('.admin-add-salesman-channel-user-modal');
var searchscForm = $(".saleman-channel-list-form .search-form");
var scFormUrl = searchscForm.data('data-search-form-url');
var $addMemberForm = $addMemberModal.find('.admin-add-salesman-channel-user-form');
var $memberSelect = $addMemberModal.find('.salesman-channel-user-select');
var $salesmanIdInput = $('.salesman-channel-list-form').find(".btn-primary");
var $start_time = $('#start_time');
var $end_time = $('#end_time');
var $form = $addMemberModal.find('form.admin-add-salesman-user-form');
// 搜索
var searchscForm = $(".saleman-channel-list-form .search-form");
$addMemberModal.on('show.bs.modal', function(event){
var $link = $(event.relatedTarget);
// var salesmanId = $link.data('salesman_id');
// $salesmanIdInput.val(salesmanId);
$addMemberModal.on('show.bs.modal', function(event){
$memberSelect.select2('val', ' ');
});
@ -52,23 +48,24 @@ $(document).on('turbolinks:load', function() {
// var salesmanId = $salesmanIdInput.val();
var memberIds = $memberSelect.val();
if (memberIds && memberIds.length > 0) {
alert(start_time);
var url = $form.data('url');
$.ajax({
method: 'POST',
dataType: 'json',
url: '/admins/salesman_channels/batch_add',
data: { salesman_id: $salesmanIdInput.data("salesman-id"), school_ids: memberIds },
url: url,
data: $form.serialize(),
success: function(){
$.notify({ message: '创建成功' });
$addMemberModal.modal('hide');
searchscForm.find('input[name="keyword"]').val('');
setTimeout(function(){
window.location.reload();
submitForm();
}, 500);
},
error: function(res){
var data = res.responseJSON;
$form.find('.error').html(data.message);
$addMemberForm.find('.error').html(data.message);
}
});
} else {
@ -76,6 +73,14 @@ $(document).on('turbolinks:load', function() {
}
});
// 清空
searchscForm.on('click', '.clear-btn', function () {
searchscForm.find('.start_date').val('');
searchscForm.find('.end_date').val('').trigger('change');
searchscForm.find('input[name="keyword"]').val('');
});
// 时间跨度
var baseOptions = {
autoclose: true,
@ -102,8 +107,8 @@ $(document).on('turbolinks:load', function() {
});
var submitForm = function(){
var url = searchscForm.data('search-form-url');
var form = searchscForm;
var url = "/admins/salesman_channels";
$.ajax({
url: url,
data: form.serialize(),

@ -58,7 +58,7 @@ $(document).on('turbolinks:load', function() {
$addMemberModal.modal('hide');
setTimeout(function(){
window.location.reload();
listForm();
}, 500);
},
error: function(res){
@ -70,5 +70,13 @@ $(document).on('turbolinks:load', function() {
$addMemberModal.modal('hide');
}
});
var listForm = function(){
$.ajax({
url: '/admins/salesman_customers?salesman_id='+ $salesmanIdInput.data("salesman-id"),
dataType: "script"
});
};
}
});

@ -72,5 +72,18 @@ $(document).on('turbolinks:load', function () {
data: json
});
});
// ------------ 上移/下移 -------------
$('.sub-discipline-list-container').on('click', ".move-action", function () {
var $doAction = $(this);
var objectId = $doAction.data('id');
var opr = $doAction.data('opr');
$.ajax({
url: '/admins/sub_disciplines/' + objectId + '/adjust_position',
method: 'POST',
dataType: 'script',
data: {opr: opr}
});
});
}
});

@ -30,22 +30,6 @@ $(document).on('turbolinks:load', function () {
});
$(".action-container").on("change", '.subject-mobile-form', function () {
var s_id = $(this).attr("data-id");
var s_value = $(this).val();
var s_name = $(this).attr("name");
var json = {};
var s_index = $(this).parent("td").siblings(".shixun-line-no").text();
json[s_name] = s_value;
json["page_no"] = s_index;
$.ajax({
url: "/admins/subject_settings/update_mobile_show?subject_id=" + s_id,
type: "POST",
dataType:'script',
data: json
});
});
$(".subject-setting-list-container").on("change", '.subject-setting-form', function () {
var s_id = $(this).attr("data-id");
var s_value = $(this).val();

@ -72,5 +72,19 @@ $(document).on('turbolinks:load', function () {
data: json
});
});
// ------------ 上移/下移 -------------
$('.tag-discipline-list-container').on('click', ".move-action", function () {
var $doAction = $(this);
var objectId = $doAction.data('id');
var opr = $doAction.data('opr');
$.ajax({
url: '/admins/tag_disciplines/' + objectId + '/adjust_position',
method: 'POST',
dataType: 'script',
data: {opr: opr}
});
});
}
});

@ -51,12 +51,12 @@ class AccountsController < ApplicationController
# todo user_extension
UserExtension.create!(user_id: @user.id)
# 注册完成手机号或邮箱想可以奖励500金币
RewardGradeService.call(
@user,
container_id: @user.id,
container_type: pre == 'p' ? 'Phone' : 'Mail',
score: 500
)
# RewardGradeService.call(
# @user,
# container_id: @user.id,
# container_type: pre == 'p' ? 'Phone' : 'Mail',
# score: 500
# )
# 注册时,记录是否是引流用户
ip = request.remote_ip
ua = UserAgent.find_by_ip(ip)

@ -7,7 +7,7 @@ class Admins::DisciplinesController < Admins::BaseController
def create
name = params[:name].to_s.strip
return render_error('名称重复') if Discipline.where(name: name).exists?
Discipline.create!(name: name)
Discipline.create!(name: name, position: Discipline.all.pluck(:position).max.to_i + 1)
render_ok
end
@ -39,7 +39,31 @@ class Admins::DisciplinesController < Admins::BaseController
def destroy
@discipline_id = params[:id]
current_discipline.destroy!
ActiveRecord::Base.transaction do
Discipline.where("position > #{current_discipline.position}").update_all("position=position-1")
current_discipline.destroy!
end
end
def adjust_position
max_position = Discipline.all.pluck(:position).max.to_i
opr = params[:opr] || "down"
if (params[:opr] == "up" && current_discipline.position == 1) || (params[:opr] == "down" && current_discipline.position == max_position)
@message = "超出范围"
else
ActiveRecord::Base.transaction do
if opr == "up"
Discipline.find_by("position = #{current_discipline.position - 1}")&.update!(position: current_discipline.position)
current_discipline.update!(position: current_discipline.position - 1)
else
Discipline.find_by("position = #{current_discipline.position + 1}")&.update!(position: current_discipline.position)
current_discipline.update!(position: current_discipline.position + 1)
end
end
end
@disciplines = Discipline.all
rescue Exception => e
@message = e.message
end
private

@ -2,10 +2,12 @@ class Admins::SalesmanChannelsController < Admins::BaseController
before_action :set_salesman
def index
@channels = SalesmanChannel.all
@start_time = params[:start_time]
@end_time = params[:end_time] || Time.now
@keyword = params[:keyword]
@channels = @salesman.salesman_channels
if params[:keyword].present?
@channels = @channels.joins(:school).where("schools.name like ?", "%#{params[:keyword]}%")
end
@start_time = params[:start_date]
@end_time = params[:end_date].blank? ? Time.now : params[:end_date]
end
def batch_add
@ -13,10 +15,12 @@ class Admins::SalesmanChannelsController < Admins::BaseController
school_ids = params[:school_ids] - channel_ids
school_ids.each do |school_id|
school = School.find_by(id: school_id)
next if school.blank?
next if school.blank? || @salesman.salesman_channels.where(school_id: school.id).exists?
@salesman.salesman_channels.create!(school_id: school.id)
end
render_ok
rescue Exception => ex
render_error(ex.message)
end
def destroy

@ -10,7 +10,7 @@ class Admins::SalesmanCustomersController < Admins::BaseController
user_ids = params[:user_ids] - customer_ids
user_ids.each do |user_id|
user = UserExtension.find_by(user_id: user_id)
next if user.blank?
next if user.blank? || @salesman.salesman_customers.where(user_id: user.user_id).exists?
@salesman.salesman_customers.create!(user_id: user.user_id, school_id: user.school_id)
end
render_ok

@ -18,7 +18,7 @@ class Admins::ShixunSettingsController < Admins::BaseController
task_pass: params[:task_pass].present? ? params[:task_pass] : false,
code_hidden: params[:code_hidden].present? ? params[:code_hidden] : false,
vip: params[:vip].present? ? params[:vip] : false,
is_wechat_support: params[:is_wechat_support].present? ? params[:is_wechat_support] : false
no_subject: params[:no_subject].present? ? params[:no_subject] : false
}
@shixuns_type_check = MirrorRepository.pluck(:type_name,:id)
@ -135,6 +135,6 @@ class Admins::ShixunSettingsController < Admins::BaseController
def setting_params
params.permit(:use_scope,:excute_time,:close,:status,:can_copy,:webssh,:hidden,:homepage_show,:task_pass,
:code_hidden,:vip,:page_no,:id, :is_wechat_support)
:code_hidden,:vip,:page_no,:id, :no_subject)
end
end

@ -9,7 +9,7 @@ class Admins::SubDisciplinesController < Admins::BaseController
name = params[:name].to_s.strip
return render_error('名称不能为空') if name.blank?
return render_error('名称重复') if current_discipline.sub_disciplines.where(name: name).exists?
SubDiscipline.create!(name: name, discipline_id: current_discipline.id)
SubDiscipline.create!(name: name, discipline_id: current_discipline.id, position: current_discipline.sub_disciplines.pluck(:position).max.to_i + 1)
render_ok
end
@ -38,9 +38,36 @@ class Admins::SubDisciplinesController < Admins::BaseController
def destroy
@sub_discipline_id = params[:id]
current_sub_discipline.destroy!
ActiveRecord::Base.transaction do
discipline = current_sub_discipline.discipline
discipline.sub_disciplines.where("position > #{current_sub_discipline.position}").update_all("position=position-1")
current_sub_discipline.destroy!
end
end
def adjust_position
discipline = current_sub_discipline.discipline
max_position = discipline.sub_disciplines.pluck(:position).max.to_i
opr = params[:opr] || "down"
if (params[:opr] == "up" && current_sub_discipline.position == 1) || (params[:opr] == "down" && current_sub_discipline.position == max_position)
@message = "超出范围"
else
ActiveRecord::Base.transaction do
if opr == "up"
discipline.sub_disciplines.find_by("position = #{current_sub_discipline.position - 1}")&.update!(position: current_sub_discipline.position)
current_sub_discipline.update!(position: current_sub_discipline.position - 1)
else
discipline.sub_disciplines.find_by("position = #{current_sub_discipline.position + 1}")&.update!(position: current_sub_discipline.position)
current_sub_discipline.update!(position: current_sub_discipline.position + 1)
end
end
end
@sub_disciplines = discipline&.sub_disciplines
rescue Exception => e
@message = e.message
end
private
def current_sub_discipline

@ -8,12 +8,6 @@ class Admins::SubjectSettingsController < Admins::BaseController
end
def update
# 为了复用代码
if params["show_moblie"]
subject.find(params[:id]).update_attributes(:show_moblie => params[:show_moblie])
return
end
sub_discipline_ids = params[:sub_disciplines] || []
sub_ids = sub_discipline_ids.reject(&:blank?).map(&:to_i)
old_sub_ids = current_subject.sub_discipline_containers.pluck(:sub_discipline_id)

@ -8,7 +8,8 @@ class Admins::TagDisciplinesController < Admins::BaseController
def create
name = params[:name].to_s.strip
return render_error('名称重复') if current_sub_discipline.tag_disciplines.where(name: name).exists?
TagDiscipline.create!(name: name, sub_discipline_id: current_sub_discipline.id, user_id: current_user.id)
TagDiscipline.create!(name: name, sub_discipline_id: current_sub_discipline.id, user_id: current_user.id,
position: current_sub_discipline.tag_disciplines.pluck(:position).max.to_i + 1)
render_ok
end
@ -32,9 +33,36 @@ class Admins::TagDisciplinesController < Admins::BaseController
def destroy
@tag_discipline_id = params[:id]
current_tag_discipline.destroy!
ActiveRecord::Base.transaction do
sub_discipline = current_tag_discipline.sub_discipline
sub_discipline.tag_disciplines.where("position > #{current_tag_discipline.position}").update_all("position=position-1")
current_tag_discipline.destroy!
end
end
def adjust_position
sub_discipline = current_tag_discipline.sub_discipline
max_position = sub_discipline.tag_disciplines.pluck(:position).max.to_i
opr = params[:opr] || "down"
if (params[:opr] == "up" && current_tag_discipline.position == 1) || (params[:opr] == "down" && current_tag_discipline.position == max_position)
@message = "超出范围"
else
ActiveRecord::Base.transaction do
if opr == "up"
sub_discipline.tag_disciplines.find_by("position = #{current_tag_discipline.position - 1}")&.update!(position: current_tag_discipline.position)
current_tag_discipline.update!(position: current_tag_discipline.position - 1)
else
sub_discipline.tag_disciplines.find_by("position = #{current_tag_discipline.position + 1}")&.update!(position: current_tag_discipline.position)
current_tag_discipline.update!(position: current_tag_discipline.position + 1)
end
end
end
@tag_disciplines = sub_discipline&.tag_disciplines
rescue Exception => e
@message = e.message
end
private
def current_sub_discipline

@ -13,7 +13,7 @@ class CoursesController < ApplicationController
end
before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups,
:left_banner, :top_banner, :informs, :online_learning, :course_groups]
:left_banner, :top_banner, :informs, :online_learning, :course_groups, :search_slim]
before_action :check_account, only: [:new, :create, :apply_to_join_course, :join_excellent_course]
before_action :check_auth, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups,
:left_banner, :top_banner, :apply_to_join_course, :exit_course, :course_groups]
@ -395,9 +395,7 @@ class CoursesController < ApplicationController
def destroy
if @course.is_delete == 0
@course.delete!
Tiding.where(belong_container: @course).update_all(is_delete: 1)
Tiding.create!(user_id: current_user.id, trigger_user_id: current_user.id, container_id: @course.id,
container_type: 'DeleteCourse', tiding_type: 'System', belong_container: @course, extra: @course.name)
DeleteCourseNotifyJob.perform_later(@course.id, current_user.id)
normal_status(0, "成功")
else
normal_status(-1, "课堂已删除,无需重复操作")
@ -742,12 +740,15 @@ class CoursesController < ApplicationController
# 切换为教师
def switch_to_teacher
begin
course_member = @course.course_members.find_by!(user_id: current_user.id, is_active: 1)
tip_exception("切换失败") unless course_member.STUDENT?
course_student = @course.students.find_by!(user_id: current_user.id, is_active: 1)
tip_exception("切换失败") unless course_student.present?
course_teacher = CourseMember.find_by!(user_id: current_user.id, role: %i[CREATOR PROFESSOR], course_id: @course.id)
course_member.update!(is_active: 0)
course_teacher.update!(is_active: 1)
ActiveRecord::Base.transaction do
course_student.destroy!
course_teacher.update!(is_active: 1)
CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id])
end
normal_status(0, "切换成功")
rescue => e
uid_logger_error(e.message)
@ -758,12 +759,15 @@ class CoursesController < ApplicationController
# 切换为助教
def switch_to_assistant
begin
course_member = @course.course_members.find_by!(user_id: current_user.id, is_active: 1)
tip_exception("切换失败") unless course_member.STUDENT?
course_student = @course.course_members.find_by!(user_id: current_user.id, is_active: 1)
tip_exception("切换失败") unless course_student.present?
course_teacher = CourseMember.find_by!(user_id: current_user.id, role: %i[ASSISTANT_PROFESSOR], course_id: @course.id)
course_member.update!(is_active: 0)
course_teacher.update!(is_active: 1)
ActiveRecord::Base.transaction do
course_student.destroy!
course_teacher.update!(is_active: 1)
CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id])
end
normal_status(0, "切换成功")
rescue => e
uid_logger_error(e.message)

@ -524,11 +524,11 @@ class GamesController < ApplicationController
else
{updated_at: Time.now}
end
logger.info("#############myshixuns_update: ##{myshixuns_update}")
#logger.info("#############myshixuns_update: ##{myshixuns_update}")
@myshixun.update_attributes!(myshixuns_update)
gitUrl = repo_ip_url @myshixun.repo_path
logger.info("#############giturl: ##{gitUrl}")
#logger.info("#############giturl: ##{gitUrl}")
gitUrl = Base64.urlsafe_encode64(gitUrl)
shixun_tomcat = edu_setting('cloud_bridge')
@ -554,7 +554,7 @@ class GamesController < ApplicationController
testSet << test_cases
end
logger.info("##############testSet: #{testSet}")
#logger.info("##############testSet: #{testSet}")
testCases = Base64.urlsafe_encode64(testSet.to_json) unless testSet.blank?
# 评测类型: 012 用于webssh的评测 3用于vnc
@ -581,7 +581,7 @@ class GamesController < ApplicationController
if secret_rep&.repo_name
secretGitUrl = repo_ip_url secret_rep.repo_path
br_params.merge!({secretGitUrl: Base64.urlsafe_encode64(secretGitUrl), secretDir: secret_rep.secret_dir_path})
logger.info("#######br_params:#{br_params}")
#logger.info("#######br_params:#{br_params}")
end
# 中间层交互
@ -691,7 +691,7 @@ class GamesController < ApplicationController
next_game: next_game&.identifier}
rescue Exception => e
uid_logger("choose build failed #{e.message}")
@result = [status: -1, contents: "#{e.message}"]
tip_exception(-1, e.message)
end
# 轮询获取状态
@ -700,10 +700,10 @@ class GamesController < ApplicationController
resubmit_identifier = @game.resubmit_identifier
# 如果没有超时并且正在评测中
# 判断评测中的状态有两种1、如果之前没有通关的只需判断status为1即可如果通过关则判断game的resubmit_identifier是否更新
uid_logger("################game_status: #{@game.status}")
uid_logger("################params[:resubmit]: #{params[:resubmit]}")
uid_logger("################resubmit_identifier: #{resubmit_identifier}")
uid_logger("################time_out: #{params[:time_out]}")
#uid_logger("################game_status: #{@game.status}")
#uid_logger("################params[:resubmit]: #{params[:resubmit]}")
#uid_logger("################resubmit_identifier: #{resubmit_identifier}")
#uid_logger("################time_out: #{params[:time_out]}")
sec_key = params[:sec_key]
if (params[:time_out] == "false") && ((params[:resubmit].blank? && @game.status == 1) || (params[:resubmit].present? &&
(params[:resubmit] != resubmit_identifier)))
@ -762,7 +762,7 @@ class GamesController < ApplicationController
end
end
uid_logger("game is #{@game.id}, record id is #{e_record.try(:id)}, time is**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
#uid_logger("game is #{@game.id}, record id is #{e_record.try(:id)}, time is**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
# 记录前端总耗时
record_consume_time = e_record.try(:pod_execute)
max_mem = e_record.try(:max_mem)
@ -848,7 +848,7 @@ class GamesController < ApplicationController
@allowed_hidden_testset = @identity < User::EDU_GAME_MANAGER || @game.test_sets_view #解锁的用户
if max_query_index > 0
uid_logger("max_query_index is #{max_query_index} game id is #{@game.id}, challenge_id is #{challenge.id}")
#uid_logger("max_query_index is #{max_query_index} game id is #{@game.id}, challenge_id is #{challenge.id}")
@qurey_test_sets = TestSet.find_by_sql("SELECT o.code, o.actual_output, o.out_put, o.result, o.test_set_position, o.ts_time, o.ts_mem,
o.query_index, t.is_public, t.input, t.output, o.compile_success FROM outputs o, games g, challenges c,
test_sets t where g.id=#{@game.id} and c.id=#{challenge.id} and o.query_index=#{max_query_index}

@ -70,9 +70,25 @@ class HomeworkCommonsController < ApplicationController
else
case order
when '1'
sql_str = %Q(homework_detail_manuals.comment_status = #{order} and homework_commons.end_time > '#{Time.now}')
if @user_course_identity == Course::STUDENT
unified_homework_ids = @homework_commons.published_no_end.unified_setting.pluck(:id)
group_homework_ids = @course.homework_group_settings.where("course_group_id = #{@member.course_group_id&.to_i}").published_no_end.pluck(:homework_common_id)
homework_ids = unified_homework_ids + group_homework_ids
homework_ids = homework_ids.blank? ? "(-1)" : "(" + homework_ids.join(",") + ")"
sql_str = %Q(homework_commons.id in #{homework_ids})
else
sql_str = %Q(homework_detail_manuals.comment_status = #{order} and homework_commons.end_time > '#{Time.now}')
end
when '2'
sql_str = %Q(allow_late = 1 and homework_commons.end_time < '#{Time.now}' and (late_time is null or late_time > '#{Time.now}'))
if @user_course_identity == Course::STUDENT
unified_homework_ids = @homework_commons.homework_ended.unified_setting.pluck(:id)
group_homework_ids = @course.homework_group_settings.where("course_group_id = #{@member.course_group_id&.to_i}").has_end.pluck(:homework_common_id)
homework_ids = unified_homework_ids + group_homework_ids
homework_ids = homework_ids.blank? ? "(-1)" : "(" + homework_ids.join(",") + ")"
sql_str = %Q(homework_commons.id in #{homework_ids} and allow_late = 1 and (late_time is null or late_time > '#{Time.now}'))
else
sql_str = %Q(allow_late = 1 and homework_commons.end_time < '#{Time.now}' and (late_time is null or late_time > '#{Time.now}'))
end
when '3'
sql_str = %Q(homework_detail_manuals.comment_status = #{order} and homework_detail_manuals.evaluation_end > '#{Time.now}')
when '4'
@ -87,16 +103,16 @@ class HomeworkCommonsController < ApplicationController
end
@task_count = @homework_commons.size
order_str = @homework_type == 4 ? "position DESC" : "IF(ISNULL(homework_commons.publish_time),0,1), homework_commons.publish_time DESC,
order_str = @homework_type == 4 ? "homework_commons.position DESC" : "IF(ISNULL(homework_commons.publish_time),0,1), homework_commons.publish_time DESC,
homework_commons.created_at DESC"
@homework_commons = @homework_commons.order(order_str).page(page).per(15)
if @homework_type == 4
@homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns)
@homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_group_settings, :shixuns, :course_second_category, user: :user_extension)
elsif @homework_type == 3
@homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_detail_group)
@homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_group_settings, :homework_detail_group, :course_second_category, user: :user_extension)
else
@homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings)
@homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_group_settings, :course_second_category, user: :user_extension)
end
end
@ -902,7 +918,8 @@ class HomeworkCommonsController < ApplicationController
def publish_groups
@current_user = current_user
if @homework.publish_immediately @current_user
charge_ids = @course.charge_group_ids(@current_user)
if @homework.publish_immediately charge_ids
# 可立即发布的分班:当前用户管理的分班去除已发布的分班
group_ids = @course.charge_group_ids(@current_user) - @homework.homework_group_settings.group_published.pluck(:course_group_id)
@course_groups = @course.course_groups.where(id: group_ids)
@ -983,8 +1000,8 @@ class HomeworkCommonsController < ApplicationController
end
homework.homework_detail_manual.update_attributes!(comment_status: 1)
if homework.course_acts.size == 0
homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id)
if homework.course_act.blank?
CourseActivity.create!(user_id: homework.user_id, course_id: homework.course_id, course_act: homework)
end
# 发消息
HomeworkCommonPushNotifyJob.perform_later(homework.id, tiding_group_ids)
@ -1031,7 +1048,8 @@ class HomeworkCommonsController < ApplicationController
def end_groups
@current_user = current_user
if @homework.end_immediately @current_user
charge_ids = @course.charge_group_ids(@current_user)
if @homework.end_immediately charge_ids
# 可立即截止的分班:统一设置则是用户管理的所有分班,否则是当前用户管理的分班中已发布且未截止的
charge_group_ids = @course.charge_group_ids(@current_user) # 当前用户管理的分班
group_ids = @homework.unified_setting ? charge_group_ids :
@ -1045,7 +1063,7 @@ class HomeworkCommonsController < ApplicationController
def end_homework
tip_exception("请至少选择一个分班") if params[:group_ids].blank? && @course.course_groups.size != 0
time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
time = Time.now
# 已发布且未截止的作业才能立即截止
@ -1086,7 +1104,7 @@ class HomeworkCommonsController < ApplicationController
homework.end_time = time
end
homework_detail_manual.update_attributes!(comment_status: 2) if homework.end_time <= time
# homework_detail_manual.update_attributes!(comment_status: 2) if homework.end_time <= time
# 实训作业的作品需要计算是否迟交
if homework.homework_type == "practice"
@ -1117,7 +1135,7 @@ class HomeworkCommonsController < ApplicationController
def choose_category
@main_catrgory = @course.course_modules.where(module_type: "shixun_homework")
@homework_category = @main_catrgory.take.course_second_categories
@homework_category = @main_catrgory.take.course_second_categories.includes(:homework_commons)
end
# 实训作业移动到目录
@ -1313,7 +1331,7 @@ class HomeworkCommonsController < ApplicationController
# 最新一次的查重时间
@last_review_time = format_time @homework.homework_group_reviews.last.try(:created_at)
@charge_ids = @course.charge_group_ids(@current_user)
end
# 代码查重代码的详情

@ -34,8 +34,9 @@ class ItemBasketsController < ApplicationController
def delete_item_type
baskets = basket_items.where(item_type: params[:item_type])
item_ids = baskets.pluck(:item_bank_id)
baskets.destroy_all
render_ok
render_ok({item_ids: item_ids})
end
def set_score

@ -20,11 +20,8 @@ class MainController < ApplicationController
uid_logger("main start is #{cookies[:_educoder_session]}")
end
if params[:path] && params[:path]&.include?("educoderh5") && params[:path].split("/").first == "educoderh5"
render file: 'public/h5build/index.html', :layout => false
# TODO: 这块之后需要整合到上面去或者架构重新变化统一跳转到index后再路由分发
elsif params[:path] && params[:path]&.include?("h5educoderbuild") && params[:path].split("/").first == "h5educoderbuild"
# TODO: 这块之后需要整合者架构重新变化统一跳转到index后再路由分发
if params[:path] && params[:path]&.include?("h5educoderbuild") && params[:path].split("/").first == "h5educoderbuild"
render file: 'public/h5educoderbuild/index.html', :layout => false
else
render file: 'public/react/build/index.html', :layout => false

@ -91,7 +91,7 @@ class MyshixunsController < ApplicationController
ActiveRecord::Base.transaction do
begin
t1 = Time.now
uid_logger_dubug("@@@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?
@ -100,7 +100,7 @@ class MyshixunsController < ApplicationController
game_id = jsonTestDetails['buildID']
sec_key = jsonTestDetails['sec_key']
uid_logger_dubug("training_task_status start-#{game_id}-1#{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'])
@ -262,7 +262,7 @@ 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_dubug("-- 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的都不需要走版本库
vnc = @myshixun.shixun&.vnc
@ -277,8 +277,6 @@ class MyshixunsController < ApplicationController
else
params[:content]
end
uid_logger_dubug("content_#{@myshixun.identifier}: #{content}")
uid_logger_dubug("###last_content_#{@myshixun.identifier}####{last_content}")
if content != last_content
@content_modified = 1
@ -286,9 +284,6 @@ 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_dubug("112233#{author_name}")
uid_logger_dubug("112233#{author_email}")
uid_logger_dubug("daiao_debug_#{@myshixun.identifier}: #{@repo_path}: #{path}; #{message}; #{content}; ")
@content = GitService.update_file(repo_path: @repo_path,
file_path: path,
message: message,

@ -0,0 +1,13 @@
class Oauth::CasController < Oauth::BaseController
def create
user, is_new_user = Oauth::CreateORFindCasUserService.call(current_user, auth_hash)
successful_authentication(user)
redirect_to root_url
end
def auth_hash
JSON.parse(CGI.unescape(request.env['omniauth.auth'].extra.to_json))
end
end

@ -17,76 +17,9 @@ class SubjectsController < ApplicationController
include CustomSortable
def index
@tech_system = current_laboratory.subject_repertoires
select = params[:select] # 路径导航类型
reorder = params[:order] || "publish_time"
search = params[:search]
## 分页参数
page = params[:page] || 1
limit = params[:limit] || 16
offset = (page.to_i-1) * limit
# 最热排序
if reorder == "myshixun_count"
subject_ids = current_laboratory.subjects.pluck(:id)
subject_ids = subject_ids.length > 0 ? "(" + subject_ids.join(",") + ")" : "(-1)"
laboratory_join = " AND subjects.id in #{subject_ids} "
if select
@subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.public,
subjects.shixuns_count, subjects.excellent, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns
on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where
subjects.hidden = 0 AND subjects.public = 2 AND subjects.name like '%#{search}%' #{laboratory_join}
AND subjects.repertoire_id = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC")
else
@subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.public,
subjects.shixuns_count, subjects.excellent, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns
on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where
subjects.hidden = 0 AND subjects.public = 2 AND subjects.name like '%#{search}%' #{laboratory_join}
GROUP BY subjects.id ORDER BY myshixun_member_count DESC")
end
else
@subjects = current_laboratory.subjects
# 我的路径
if reorder == "mine"
tip_exception(401, "..") unless current_user.logged?
mine_subject_id = StageShixun.find_by_sql("select DISTINCT(subject_id) from stage_shixuns where shixun_id in
(select distinct(shixun_id) from myshixuns where user_id=#{current_user.id})").map(&:subject_id)
manage_subject_id = SubjectMember.where(user_id: current_user.id).pluck(:subject_id)
total_subject_id = (mine_subject_id + manage_subject_id).uniq
@subjects = @subjects.where(id: total_subject_id)
elsif reorder == "publish_time"
@subjects = @subjects.unhidden
else
@subjects = @subjects.publiced.unhidden
end
# 类型
if select
@subjects = @subjects.where(repertoire_id: select)
end
if search.present?
@subjects = @subjects.where("name like ?", "%#{search}%")
end
# 排序
order_str = (reorder == "publish_time" ? "homepage_show desc, excellent desc, public = 2 desc, publish_time asc" : "homepage_show desc, excellent desc, updated_at desc")
@subjects = @subjects.reorder(order_str)
end
@total_count = @subjects.size
if reorder != "myshixun_count"
@subjects = @subjects.page(page).per(limit).includes(:shixuns, :repertoire)
else
@subjects = @subjects[offset, limit]
subject_ids = @subjects.pluck(:id)
order_ids = subject_ids.size > 0 ? subject_ids.join(',') : -1
@subjects = Subject.where(id: subject_ids).order("field(id,#{order_ids})").includes(:shixuns, :repertoire)
end
subjects = Weapps::SubjectQuery.call(current_laboratory, params)
@subject_count = subjects.map(&:id).size
@subjects = paginate subjects.includes(:shixuns, :repertoire)
end
def show

@ -4,7 +4,8 @@ class TagDisciplinesController < ApplicationController
def create
sub_discipline = SubDiscipline.find_by!(id: params[:sub_discipline_id])
tip_exception("重复的知识点") if sub_discipline.tag_disciplines.exists?(name: params[:name].to_s.strip)
tag_discipline = TagDiscipline.create!(name: params[:name].to_s.strip, sub_discipline: sub_discipline, user_id: current_user.id)
tag_discipline = TagDiscipline.create!(name: params[:name].to_s.strip, sub_discipline: sub_discipline, user_id: current_user.id,
position: sub_discipline.tag_disciplines.pluck(:position).max.to_i + 1)
render_ok({tag_discipline_id: tag_discipline.id})
end
end

@ -6,10 +6,10 @@ class Weapps::ChallengesController < Weapps::BaseController
# 关卡有展示效果 || 选择题 || jupyter实训 || vnc || 隐藏代码窗口 || html+css实训
# @challenge.show_type != -1 || @challenge.st == 1 || @shixun.is_jupyter? || @shixun.vnc ||
# @shixun.hide_code? || (@shixun.small_mirror_name & ["Css", "Html", "Web"]).present?
play = @challenge.st == 1 || @shixun.is_jupyter? || @shixun.vnc ||
play = @shixun.is_jupyter? || @shixun.vnc ||
@shixun.hide_code? || (@shixun.small_mirror_name & ["Css", "Html", "Web"]).present?
if play
if @challenge.st != 1 && play
normal_status(-5, "该关卡暂不支持小程序")
else
render_ok

@ -6,6 +6,24 @@ class Weapps::CoursesController < Weapps::BaseController
before_action :teacher_allowed, only: [:edit, :update]
before_action :teacher_or_admin_allowed, only: [:change_member_roles, :delete_course_teachers]
def course_activities
@course = current_course
homework_commons = @course.homework_commons.where(homework_type: ["practice", "normal"]).homework_published
member = @course.course_members.find_by(user_id: current_user.id, is_active: 1)
if (@user_course_identity == Course::STUDENT && member.try(:course_group_id).to_i == 0) || @user_course_identity > Course::STUDENT
homework_commons = homework_commons.unified_setting
elsif @user_course_identity == Course::STUDENT
not_homework_ids = @course.homework_group_settings.none_published.where("course_group_id = #{member.try(:course_group_id)}").pluck(:homework_common_id)
homework_commons = homework_commons.where.not(id: not_homework_ids)
end
homework_ids = homework_commons.blank? ? "(-1)" : "(" + homework_commons.pluck(:id).join(",") + ")"
activities = @course.course_activities.where("course_act_type in ('Course', 'CourseMessage') or
(course_act_type = 'HomeworkCommon' and course_act_id in #{homework_ids})").order("id desc")
@activities_count = activities.size
@activities = paginate activities.includes(:course_act, user: :user_extension)
end
def create
# return render_error("只有老师身份才能创建课堂") unless current_user.is_teacher?
course = Course.new(tea_id: current_user.id)

@ -1,5 +1,4 @@
class Weapps::ShixunListsController < ApplicationController
before_action :require_login
def index
results = Weapps::ShixunSearchService.call(search_params, current_laboratory)

@ -1,5 +1,5 @@
class Weapps::SubjectsController < Weapps::BaseController
before_action :require_login
before_action :require_login, except: [:index, :show]
before_action :find_subject, except: [:index]
# 首页

@ -14,6 +14,7 @@ class Users::UpdateAccountForm
validates :technical_title, presence: true, unless: -> { identity.to_s == 'student' }
validates :student_id, presence: true, if: -> { identity.to_s == 'student' }
validates :school_id, presence: true
validates :department_id, presence: true
validate :check_school_exist
def check_school_exist

@ -42,6 +42,14 @@ module CoursesHelper
end
end
def practice_homework_count course
homeworks = course.homework_commons.practices
publish_count = homeworks.select{|homework| homework.publish_time.present? && homework.publish_time <= Time.now}.size
unpublish_count = homeworks.select{|homework| homework.publish_time.nil? || homework.publish_time > Time.now}.size
all_count = homeworks.size
{publish_count: publish_count, unpublish_count: unpublish_count, all_count: all_count}
end
# 课堂模块的url
def module_url mod, course
return nil if mod.blank? or course.blank?

@ -117,9 +117,16 @@ module HomeworkCommonsHelper
time = "提交剩余时间:" + how_much_time(max_end_time)
time_status = 1
else
status << "已截止"
time = course.end_date.present? ? ("评阅剩余时间:" + how_much_time(course.end_date.end_of_day)) : ""
time_status = 5
if max_end_time.present? && max_end_time < Time.now && homework_common.allow_late &&
(homework_common.late_time.nil? || homework_common.late_time > Time.now)
status << "补交中"
time = "补交剩余时间:" + how_much_time(homework_common.late_time)
time_status = 2
else
status << "已截止"
time = course.end_date.present? ? ("评阅剩余时间:" + how_much_time(course.end_date.end_of_day)) : ""
time_status = 5
end
end
end
end
@ -183,7 +190,7 @@ module HomeworkCommonsHelper
student_works = homework_common.teacher_works(member)
count[:commit_count] = student_works.select{|work| work.work_status != 0 }.size
count[:uncommit_count] = student_works.select{|work| work.work_status == 0 }.size
count[:compelete_count] = Myshixun.where(id: student_works.pluck(:myshixun_id).reject(&:blank?), status: 1).size
count[:compelete_count] = Myshixun.where(id: student_works.pluck(:myshixun_id).reject{|ms| ms==0}, status: 1).size
count[:all_count] = student_works.size
count
end

@ -169,6 +169,7 @@ module ShixunsHelper
source_class_name << source if source.present?
end
end
logger.info("####source_class_name: #{source_class_name}")
script = if script.include?("sourceClassName") && script.include?("challengeProgramName")
script.gsub(/challengeProgramNames=\(.*\)/,"challengeProgramNames=\(#{challenge_program_name.reject(&:blank?).join(" ")}\)").gsub(/sourceClassNames=\(.*\)/, "sourceClassNames=\(#{source_class_name.reject(&:blank?).join(" ")}\)")
else

@ -0,0 +1,13 @@
# 删除课堂时将相应的课堂消息置为删除状态,并给老师发送删除消息
class DeleteCourseNotifyJob < ApplicationJob
queue_as :default
def perform(course_id, user_id)
course = Course.find_by(id: course_id)
return if course.blank?
Tiding.where(belong_container: course).update_all(is_delete: 1)
Tiding.create!(user_id: user_id, trigger_user_id: user_id, container_id: course.id,
container_type: 'DeleteCourse', tiding_type: 'System', belong_container: course, extra: course.name)
end
end

@ -70,7 +70,9 @@ class Course < ApplicationRecord
# 课堂动态
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
has_one :course_act, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
has_many :course_activities
has_many :tidings, as: :container, dependent: :destroy
# 开放课堂
@ -255,10 +257,10 @@ class Course < ApplicationRecord
# 老师负责的分班id
def charge_group_ids user
member = course_member(user.id)
member = user.is_a?(CourseMember) ? user : course_member(user&.id)
group_ids = if member.present?
member.teacher_course_groups.size > 0 ? member.teacher_course_groups.pluck(:course_group_id) : course_groups.pluck(:id)
elsif user.admin_or_business?
elsif user&.admin_or_business?
course_groups.pluck(:id)
else
[]
@ -300,7 +302,7 @@ class Course < ApplicationRecord
#课程动态公共表记录
def act_as_course_activity
self.course_acts << CourseActivity.new(user_id: tea_id, course_id: id)
CourseActivity.create(user_id: tea_id, course_id: id, course_act: self)
end
# 当前老师分班下的所有学生
@ -385,7 +387,7 @@ class Course < ApplicationRecord
end
def max_activity_time
course_acts.pluck(:updated_at).max
course_activities.pluck(:updated_at).max
end
# 课堂作业数

@ -4,9 +4,26 @@ class CourseActivity < ApplicationRecord
belongs_to :user
belongs_to :exercise
belongs_to :poll
belongs_to :course_message
belongs_to :homework_common
# after_create :add_course_lead
def container_name
case course_act_type
when "HomeworkCommon"
course_act&.name
when "Exercise"
course_act&.exercise_name
when "Poll"
course_act&.poll_name
when "Message"
course_act&.subject
else
""
end
end
# 发布新课导语
# 导语要放置在课程创建信息之后
def add_course_lead

@ -2,6 +2,7 @@ class CourseMessage < ApplicationRecord
enum status: { UNHANDLED: 0, PASSED: 1, REJECTED: 2 }
belongs_to :course
belongs_to :user
has_one :course_act, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
scope :find_by_course, ->(course) { where(course_id: course.id) }
scope :join_course_requests, -> { where(course_message_type: "JoinCourseRequest") }
@ -9,6 +10,8 @@ class CourseMessage < ApplicationRecord
scope :unhandled_join_course_requests_by_course, ->(course) { find_by_course(course).join_course_requests.unhandled }
after_create :act_as_course_activity
def pass!
update!(status: :PASSED)
send_deal_tiding(1)
@ -25,6 +28,11 @@ class CourseMessage < ApplicationRecord
private
#课程动态公共表记录
def act_as_course_activity
CourseActivity.create(user_id: course_message_id, course_id: course_id, course_act: self)
end
def send_deal_tiding deal_status
# 发送申请处理结果消息
Tiding.create!(

@ -12,4 +12,13 @@ class CourseSecondCategory < ApplicationRecord
category_type == "graduation" && name == "毕设任务" ? "graduation_tasks" : category_type
)
end
def homework_publish_count
homework_commons.select{|homework| homework.publish_time.present? && homework.publish_time <= Time.now}.size
end
def homework_unpublish_count
homework_commons.select{|homework| homework.publish_time.nil? || homework.publish_time > Time.now}.size
end
end

@ -1,5 +1,7 @@
class Discipline < ApplicationRecord
has_many :sub_disciplines, dependent: :destroy
default_scope { order(position: :asc) }
has_many :sub_disciplines, -> { order("sub_disciplines.position ASC") }, dependent: :destroy
has_many :shixun_sub_disciplines, -> { where("shixun = 1") }, class_name: "SubDiscipline"
has_many :subject_sub_disciplines, -> { where("subject = 1") }, class_name: "SubDiscipline"

@ -1,3 +1,4 @@
class HackCode < ApplicationRecord
# 编程题代码相关
belongs_to :hack
end

@ -28,7 +28,7 @@ class HomeworkCommon < ApplicationRecord
belongs_to :course_second_category, optional: true
# 课堂动态
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
has_one :course_act, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
has_many :tidings, as: :container, dependent: :destroy
# 实训作业的分班查重记录
has_many :homework_group_reviews, :dependent => :destroy
@ -47,6 +47,7 @@ class HomeworkCommon < ApplicationRecord
scope :homework_published, -> {where("homework_commons.publish_time IS NOT NULL AND homework_commons.publish_time <= ? ",Time.now)}
scope :published_no_end, -> {where("homework_commons.publish_time IS NOT NULL AND homework_commons.publish_time < ?
and homework_commons.end_time > ?", Time.now, Time.now)}
scope :homework_ended, -> {where("homework_commons.end_time IS NOT NULL AND homework_commons.end_time <= ? ",Time.now)}
scope :search_homework_type, lambda {|num| where(homework_type:num)}
scope :unified_setting, -> {where("unified_setting = ? ", 1)}
@ -141,15 +142,17 @@ class HomeworkCommon < ApplicationRecord
end
# 作业能否立即发布
def publish_immediately user
homework_detail_manual.try(:comment_status) == 0 || homework_group_settings.where(course_group_id: course.charge_group_ids(user)).
none_published.count > 0
def publish_immediately charge_ids
homework_detail_manual.try(:comment_status) == 0 ||
homework_group_settings.select{|setting| charge_ids.include?(setting.course_group_id) &&
(setting.publish_time.nil? || setting.publish_time > Time.now)}.size > 0
end
# 作业能否立即截止
def end_immediately user
(unified_setting && homework_detail_manual.try(:comment_status) == 1 && end_time > Time.now) || homework_group_settings.
where(course_group_id: course.charge_group_ids(user)).published_no_end.count > 0
def end_immediately charge_ids
(unified_setting && homework_detail_manual.try(:comment_status) == 1 && end_time.present? && end_time > Time.now) ||
homework_group_settings.select{|setting| charge_ids.include?(setting.course_group_id) &&
!setting.publish_time.nil? && setting.publish_time < Time.now && setting.end_time > Time.now}.size > 0
end
# 学生是否提交了作品

@ -7,5 +7,6 @@ class HomeworkGroupSetting < ApplicationRecord
scope :published_no_end, -> {where("homework_group_settings.publish_time IS NOT NULL AND homework_group_settings.publish_time < ?
and homework_group_settings.end_time > ?", Time.now, Time.now)}
scope :none_end, -> {where("homework_group_settings.end_time IS NULL or homework_group_settings.end_time > ?", Time.now)}
scope :has_end, -> {where("homework_group_settings.end_time IS NOT NULL AND homework_group_settings.end_time <= ?", Time.now)}
end

@ -0,0 +1,9 @@
class OpenUsers::Cas < OpenUser
def nickname
extra&.[]('nickname')
end
def en_type
'cas'
end
end

@ -6,22 +6,20 @@ class SalesmanChannel < ApplicationRecord
school.name
end
def teacher_count(start_time, end_time, keyword)
UserExtension.joins(:school).where("schools.name like '%#{keyword}%' and user_extensions.identity=0
and user_extensions.created_at between '#{start_time}' and '#{end_time}'").count
def teacher_count(start_time, end_time)
UserExtension.where("identity = 0 and school_id = #{school_id} and created_at between '#{start_time}' and '#{end_time}'").count
# UserExtension.where(school_id: school_id).where(query).count
end
def student_count(start_time, end_time, keyword)
UserExtension.joins(:school).where("schools.name like '%#{keyword}%' and user_extensions.identity=1
and user_extensions.created_at between '#{start_time}' and '#{end_time}'").count
def student_count(start_time, end_time)
UserExtension.where("identity = 1 and school_id = #{school_id} and created_at between '#{start_time}' and '#{end_time}'").count
end
def course_count(start_time, end_time, keyword)
Course.joins(:school).where("schools.name like '%#{keyword}%' and courses.created_at between '#{start_time}' and '#{end_time}'").count
def course_count(start_time, end_time)
Course.where("school_id = #{school_id} and courses.created_at between '#{start_time}' and '#{end_time}'").count
end
def shixuns_count(start_time, end_time, keyword)
def shixuns_count(start_time, end_time)
ShixunMember.joins("join user_extensions on user_extensions.user_id = shixun_members.user_id and shixun_members.created_at between '#{start_time}' and '#{end_time}'")
.where(user_extensions: {school_id: school_id}).pluck(:shixun_id).uniq.count
end

@ -1,6 +1,6 @@
class SalesmanCustomer < ApplicationRecord
belongs_to :salesman, :touch => true, counter_cache: true
belongs_to :school
belongs_to :school, optional: true
belongs_to :user
def name
@ -8,7 +8,7 @@ class SalesmanCustomer < ApplicationRecord
end
def school_name
school.name
school&.name
end
def courses_count

@ -1,6 +1,6 @@
class SubDiscipline < ApplicationRecord
belongs_to :discipline
has_many :tag_disciplines, dependent: :destroy
has_many :tag_disciplines, -> { order("tag_disciplines.position ASC") }, dependent: :destroy
has_many :sub_discipline_containers, dependent: :destroy
has_one :hack

@ -41,6 +41,7 @@ class Subject < ApplicationRecord
scope :published, lambda{where(status: 1)}
scope :unhidden, lambda{where(hidden: 0)}
scope :publiced, lambda{ where(public: 2) }
scope :show_moblied, lambda{ where(show_mobile: true) }
after_create :send_tiding
def send_tiding

@ -118,8 +118,8 @@ class User < ApplicationRecord
has_many :manage_courses, through: :manage_course_members, source: :course
# 关注
has_many :be_watchers, foreign_key: :user_id, dependent: :destroy # 我的关注
has_many :be_watcher_users, through: :be_watchers, dependent: :destroy # 我关注的用户
# has_many :be_watchers, foreign_key: :user_id, dependent: :destroy # 我的关注
# has_many :be_watcher_users, through: :be_watchers, dependent: :destroy # 我关注的用户
# 认证
has_many :apply_user_authentication
@ -655,6 +655,7 @@ class User < ApplicationRecord
# 邮箱w***l@qq.com
def hidden_mail
Rails.logger.info("######-----: #{mail}")
Util.conceal(mail, :email).to_s
end
@ -726,8 +727,8 @@ class User < ApplicationRecord
end
def validate_sensitive_string
raise("真实姓名包含敏感词汇,请重新输入") if lastname && !HarmoniousDictionary.clean?(lastname)
raise("昵称包含敏感词汇,请重新输入") if nickname && !HarmoniousDictionary.clean?(nickname)
raise("真实姓名包含敏感词汇,请重新输入#{lastname}") if lastname && !HarmoniousDictionary.clean?(lastname)
raise("昵称包含敏感词汇,请重新输入#{nickname}") if nickname && !HarmoniousDictionary.clean?(nickname)
end
def set_laboratory

@ -51,7 +51,10 @@ class Admins::ShixunSettingsQuery < ApplicationQuery
all_shixuns = all_shixuns.where(task_pass: params[:task_pass]) if params[:task_pass]
all_shixuns = all_shixuns.where(code_hidden: params[:code_hidden]) if params[:code_hidden]
all_shixuns = all_shixuns.where(vip: params[:vip]) if params[:vip]
all_shixuns = all_shixuns.where(is_wechat_support: params[:is_wechat_support]) if params[:is_wechat_support]
if params[:no_subject]
shixun_ids = StageShixun.pluck(:shixun_id).uniq
all_shixuns = all_shixuns.published.where.not(id: shixun_ids)
end
custom_sort(all_shixuns, params[:sort_by], params[:sort_direction])
end

@ -18,9 +18,9 @@ class Admins::SubjectQuery < ApplicationQuery
status =
case params[:status].to_s.strip
when "editing" then {status: 0}
when "processed" then {status: 2, public: 0}
when "applying" then {status: 2, public: [0, 1]}
when "pending" then {public: 1}
when "publiced" then {public: 2}
when "published" then {public: 2}
end
subjects = subjects.where(status) if status

@ -19,17 +19,20 @@ class OptionalItemQuery < ApplicationQuery
end
if hacks.present?
items = ItemBank.where(container_id: hacks.pluck(:id), container_type: "Hack").or(ItemBank.where(id: items.pluck(:id)))
items = ItemBank.where(container_id: hacks.where(status: 1).pluck(:id), container_type: "Hack")
.or(ItemBank.where(id: items.pluck(:id)).where("item_type != '6'"))
end
# 来源
public = source.present? ? source.to_i : 1
public = public == 2 ? [0, 1] : public
items = items.where(public: public)
if public == 1
items = items.where(public: 1)
elsif public == 0
items = items.where(user_id: User.current.id)
end
# 难度
difficulty = difficulty ? difficulty.to_i : 1
items = items.where(difficulty: difficulty)
diff = difficulty ? difficulty.to_i : 1
items = items.where(difficulty: diff)
items
end
end

@ -19,8 +19,8 @@ class Weapps::SubjectQuery < ApplicationQuery
subjects = subjects.joins(:sub_discipline_containers).where(sub_discipline_containers: {container_type: "Subject"})
end
subjects = subjects.left_joins(:shixuns).select('subjects.id, subjects.name, subjects.excellent, subjects.stages_count, subjects.status, subjects.homepage_show,
subjects.shixuns_count, subjects.updated_at, IFNULL(sum(shixuns.myshixuns_count), 0) myshixuns_count')
subjects = subjects.left_joins(:shixuns, :repertoire).select('subjects.id, subjects.name, subjects.excellent, subjects.stages_count, subjects.status, subjects.homepage_show,
subjects.shixuns_count, subjects.repertoire_id, subjects.updated_at, IFNULL(sum(shixuns.myshixuns_count), 0) myshixuns_count')
.group('subjects.id').order("subjects.homepage_show #{sort_type}, #{order_type} #{sort_type}")
subjects
end

@ -29,14 +29,14 @@ class Admins::ImportDisciplineService < ApplicationService
return unless discipline_name.present?
discipline = Discipline.find_by(name: discipline_name)
if discipline.blank?
discipline = Discipline.create!(name: discipline_name)
discipline = Discipline.create!(name: discipline_name, position: Discipline.all.pluck(:position).max.to_i + 1)
count += 1
end
if sub_discipline_name.present?
sub_discipline = SubDiscipline.find_by(name: discipline_name, discipline: discipline)
if sub_discipline.blank?
SubDiscipline.create!(name: sub_discipline_name, discipline: discipline)
SubDiscipline.create!(name: sub_discipline_name, discipline: discipline, position: discipline.sub_disciplines.pluck(:position).max.to_i + 1)
count += 1
end
end

@ -44,7 +44,7 @@ class Admins::SchoolDailyStatisticService < ApplicationService
courses = Course.where(is_delete: 0, school_id: ids).group('school_id')
course_map = courses.count
nearly_course_time_map = courses.joins(:course_acts).maximum('course_activities.updated_at')
nearly_course_time_map = courses.joins(:course_activities).maximum('course_activities.updated_at')
active_course_map = courses.where(is_end: false).count
shixun_map = Shixun.joins(user: :user_extension).where(user_extensions: { identity: :teacher, school_id: ids })

@ -133,8 +133,10 @@ class HomeworksService
# 计算实训作品学生的效率分
def update_student_eff_score homework
if homework.work_efficiency && homework.max_efficiency != 0
max_efficiency = homework.student_works.where("compelete_status != 0").pluck(:efficiency).max
homework.update_column("max_efficiency", max_efficiency)
homework.student_works.where("compelete_status != 0").each do |student_work|
eff_score = student_work.efficiency / homework.max_efficiency * homework.eff_score
eff_score = student_work.efficiency / max_efficiency * homework.eff_score
student_work.eff_score = format("%.2f", eff_score)
student_work.late_penalty = student_work.work_status == 1 ? 0 : homework.late_penalty
unless student_work.ultimate_score
@ -333,7 +335,10 @@ class HomeworksService
work.compelete_status = myshixun_endtime < setting_time.end_time ? 2 : 3
# 如果作业的最大效率值有变更则更新所有作品的效率分
homework.update_column("max_efficiency", work.efficiency) if homework.work_efficiency && homework.max_efficiency < work.efficiency
if homework.work_efficiency && homework.max_efficiency < work.efficiency
homework.max_efficiency = work.efficiency
homework.save(validate: false)
end
else
work.compelete_status = 1 # 未通关
end

@ -0,0 +1,31 @@
class Oauth::CreateORFindCasUserService < ApplicationService
def initialize(user, params)
@user = user
@params = params
end
def call
return [@user, false] if @user
open_user = OpenUsers::Cas.find_or_initialize_by(uid: @params['user']) do |u|
u.extra = @params
end
return [open_user.user, false] if open_user.persisted?
@user = User.new(login: "tfxy#{@params['user']}", type: 'User', status: User::STATUS_ACTIVE, lastname: @params['comsys_name'])
ActiveRecord::Base.transaction do
@user.save!
@user.create_user_extension!
open_user.user = @user
open_user.save!
Rails.cache.write(open_user.can_bind_cache_key, 1, expires_in: 1.hours)
end
[@user, true]
end
end

@ -73,9 +73,11 @@ class UpdateHomeworkPublishSettingService < ApplicationService
# 作业在"提交中"状态时
else
if homework.end_time > Time.now && homework.unified_setting
# 实训作业截止时间已过也可修改截止时间,其他作业暂不支持修改
if (homework.homework_type == "practice" || homework.end_time > Time.now) && homework.unified_setting
tip_exception("截止时间不能为空") if params[:end_time].blank?
tip_exception("截止时间不能早于当前时间") if params[:end_time].to_time <= Time.now
tip_exception("截止时间必须晚于发布时间") if params[:end_time].to_time <= homework.publish_time
# tip_exception("截止时间不能早于当前时间") if params[:end_time].to_time <= Time.now
tip_exception("截止时间不能晚于课堂结束时间(#{course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")}") if
course.end_date.present? && params[:end_time].to_time > course.end_date.end_of_day
@ -93,19 +95,29 @@ class UpdateHomeworkPublishSettingService < ApplicationService
# 如果该发布规则 没有已发布的分班则需判断发布时间
tip_exception("发布时间不能早于等于当前时间") if setting[:publish_time].to_time <= Time.now && group_settings.group_published.count == 0
tip_exception("截止时间不能早于等于当前时间") if setting[:end_time].to_time <= Time.now && group_settings.none_end.count > 0
# tip_exception("截止时间不能早于等于当前时间") if setting[:end_time].to_time <= Time.now && group_settings.none_end.count > 0
tip_exception("截止时间不能早于发布时间") if setting[:publish_time].to_time > setting[:end_time].to_time
tip_exception("截止时间不能晚于课堂结束时间(#{course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")}") if
course.end_date.present? && setting[:end_time].to_time > course.end_date.end_of_day
group_settings.none_published.update_all(publish_time: setting[:publish_time])
group_settings.none_end.update_all(end_time: setting[:end_time])
# 实训作业截止时间已过也可修改截止时间,其他作业暂不支持修改
if homework.homework_type == "practice"
group_settings.update_all(end_time: setting[:end_time])
else
group_settings.none_end.update_all(end_time: setting[:end_time])
end
end
homework.end_time = homework.max_group_end_time
end
end
if homework.end_time > Time.now && homework.homework_detail_manual.try(:comment_status) > 1
homework.homework_detail_manual.update_attributes!(comment_status: 1)
end
homework.save!
UpdateShixunWorkScoreJob.perform_later(homework.id)
HomeworkCommonPushNotifyJob.perform_later(homework.id, publish_group_ids) if send_tiding
end

@ -50,7 +50,7 @@ class Users::UpdateAccountService < ApplicationService
end
if first_full_reward
RewardGradeService.call(user, container_id: user.id, container_type: 'Account', score: 500)
# RewardGradeService.call(user, container_id: user.id, container_type: 'Account', score: 500)
if user.user_extension.teacher?
join_course(user.id,1309, 2)
# sms_notify_admin(user.lastname)

@ -0,0 +1,5 @@
<% if @message.present? %>
$.notify({ message: "<%= @message %>" });
<% else %>
$(".discipline-list-container").html("<%= j(render :partial => 'admins/disciplines/shared/list') %>");
<% end %>

@ -1,3 +1,4 @@
<% max_position = @disciplines.pluck(:position).max %>
<table class="table table-hover text-center discipline-list-table">
<thead class="thead-light">
<tr>
@ -11,9 +12,9 @@
</thead>
<tbody>
<% if @disciplines.present? %>
<% @disciplines.each_with_index do |discipline, index| %>
<% @disciplines.each do |discipline| %>
<tr class="discipline-item discipline-item-<%= discipline.id %>">
<td><%= index + 1 %></td>
<td><%= discipline.position %></td>
<td class="text-left">
<span><%= link_to discipline.name, admins_sub_disciplines_path(discipline_id: discipline), :title => discipline.name %></span>
</td>
@ -21,6 +22,9 @@
<td><%= check_box_tag :shixun,!discipline.shixun,discipline.shixun,remote:true,data:{id:discipline.id},class:"discipline-source-form" %></td>
<td><%= check_box_tag :question,!discipline.question,discipline.question,remote:true,data:{id:discipline.id},class:"discipline-source-form" %></td>
<td>
<%= javascript_void_link('上移', class: 'move-action', data: { id: discipline.id, opr: "up" }, style: discipline.position == 1 ? 'display:none' : '') %>
<%= javascript_void_link('下移', class: 'move-action', data: { id: discipline.id, opr: "down" }, style: discipline.position == max_position ? 'display:none' : '') %>
<%= link_to '编辑', edit_admins_discipline_path(discipline), remote: true, class: 'action' %>
<%= delete_link '删除', admins_discipline_path(discipline, element: ".discipline-item-#{discipline.id}"), class: 'delete-discipline-action' %>
</td>

@ -1,4 +1,9 @@
<% is_processed = params[:status].to_s != 'pending' %>
<link rel="stylesheet" href="/quill/quill.snow.css"/>
<div id="editor" style="display: none">
</div>
<script src="/quill/quill.min.js"></script>
<table class="table table-hover text-center professional-authentication-list-table">
<thead class="thead-light">
<tr>
@ -32,10 +37,10 @@
<td><%= raw [user.school_name.presence, user.department_name.presence].compact.join('<br/>') %></td>
<td class="text-left">
<% if item.item_type == "PROGRAM" %>
<%= link_to item.name, "/problems/#{item.container&.identifier}/edit", class: "d-inline-block text-truncate",
<%= link_to item.name, "/problems/#{item.container&.identifier}/edit", id: "item_name_#{index}", class: "d-inline-block text-truncate",
style: "max-width: 280px", target: "_blank", data: { toggle: 'tooltip', title: "#{item.name}"} %>
<% else %>
<%= link_to item.name, admins_item_authentication_path(apply), remote: true, class: "d-inline-block text-truncate",
<%= link_to item.name, admins_item_authentication_path(apply), remote: true, id: "item_name_#{index}", class: "d-inline-block text-truncate",
style: "max-width: 280px", data: { toggle: 'tooltip', title: "#{item.name}"} %>
<% end %>
</td>
@ -59,4 +64,18 @@
</tbody>
</table>
<%= render partial: 'admins/shared/paginate', locals: { objects: applies } %>
<%= render partial: 'admins/shared/paginate', locals: { objects: applies } %>
<script>
var quill = new Quill('#editor', {
theme: 'snow'
});
var content = "";
<% applies.each_with_index do |apply, index| %>
<% item = ItemBank.find apply.container_id %>
content = JSON.parse(<%= item.name %>);
quill.setContents(content);
$("#item_name_<%= index %>").html(quill.container.firstChild.innerHTML);
<% end %>
</script>

@ -1,5 +1,5 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb("#{@salesman.name}的渠道", admins_salesmans_path) %>
<% add_admin_breadcrumb("#{@salesman.name}跟踪的院校", admins_salesmans_path) %>
<% end %>
<% define_admin_breadcrumbs do %>
@ -7,23 +7,24 @@
<% end %>
<div class="box search-form-container saleman-channel-list-form">
<form class="form-inline search-form d-flex" data-search-form-url="<%= admins_salesman_channels_path %>">
<form class="form-inline search-form d-flex" data-search-form-url="<%= admins_salesman_channels_path(salesman_id: @salesman.id) %>">
<div class="time-select">
<div class="form-group grow-date-container">
<div class="input-group input-daterange grow-date-input-daterange">
<%= text_field_tag :start_date, params[:start_date], class: 'form-control start-date mx-0', placeholder: '开始时间' %>
<div class="input-group-prepend"><span class="input-group-text">到</span></div>
<%= text_field_tag :end_date, params[:start_date], class: 'form-control end-date mx-0', placeholder: '结束时间' %>
<%= text_field_tag :end_date, params[:end_date], class: 'form-control end-date mx-0', placeholder: '结束时间' %>
</div>
</div>
</div>
<%= text_field_tag :keyword, params[:keyword], placeholder: 'ID/单位名称检索', class: 'form-control mx-3 search-input' %>
<%= text_field_tag :keyword, params[:keyword], placeholder: 'ID/院校名称检索', class: 'form-control mx-3 search-input' %>
<%= javascript_void_link '搜索', class: 'btn btn-primary search-btn', target: '' %>
<input type="reset" class="btn btn-secondary clear-btn ml-3" value="清空"/>
</form>
<div class="flex-12">
<%= javascript_void_link '新增渠道', class: 'btn btn-primary', data: {salesman_id: @salesman.id, toggle: 'modal', target: '.admin-add-salesman-channel-user-modal' } %>
<%= javascript_void_link '新增院校', class: 'btn btn-primary', data: {toggle: 'modal', target: '.admin-add-salesman-channel-user-modal' } %>
</div>
</div>

@ -2,19 +2,18 @@
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">添加渠道</h5>
<h5 class="modal-title">添加院校</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form class="admin-add-salesman-user-form">
<%= hidden_field_tag(:salesman_id, nil) %>
<form class="admin-add-salesman-user-form" data-url="<%= batch_add_admins_salesman_channels_path(salesman_id: @salesman.id) %>">
<div class="form-group d-flex">
<label class="col-form-label">单位:</label>
<div class="d-flex flex-column-reverse w-75">
<select id="user_ids" name="user_ids" class="form-control salesman-channel-user-select"></select>
<select id="school_ids" name="school_ids[]" class="form-control salesman-channel-user-select"></select>
</div>
</div>

@ -19,16 +19,16 @@
<span><%= channel.school_name %></span>
</td>
<td class="text-left">
<span><%= channel.teacher_count(@start_time, @end_time, @keyword) %></span>
<span><%= channel.teacher_count(@start_time, @end_time) %></span>
</td>
<td class="text-left">
<span><%= channel.student_count(@start_time, @end_time, @keyword) %></span>
<span><%= channel.student_count(@start_time, @end_time) %></span>
</td>
<td>
<%= channel.course_count(@start_time, @end_time, @keyword) %>
<%= channel.course_count(@start_time, @end_time) %>
</td>
<td>
<%= channel.shixuns_count(@start_time, @end_time, @keyword) %>
<%= channel.shixuns_count(@start_time, @end_time) %>
</td>
<td>
<%= delete_link '删除', admins_salesman_channel_path(channel, salesman_id: channel.salesman_id, element: ".salesman-channel-item-#{channel.id}"), class: 'delete-salesman-action' %>

@ -1,10 +1,10 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb("#{@salesman.name}的客户", admins_salesmans_path) %>
<% add_admin_breadcrumb("#{@salesman.name}跟踪的用户", admins_salesmans_path) %>
<% end %>
<div class="box search-form-container salesman-customer-list-form rig">
<div class="flex-1">
<%= javascript_void_link '新增户', class: 'btn btn-primary', data: {salesman_id: @salesman.id, toggle: 'modal', target: '.admin-add-salesman-customer-user-modal' } %>
<%= javascript_void_link '新增户', class: 'btn btn-primary', data: {salesman_id: @salesman.id, toggle: 'modal', target: '.admin-add-salesman-customer-user-modal' } %>
</div>
</div>

@ -0,0 +1 @@
$(".salesman-customer-list-container").html("<%= j(render partial: 'admins/salesman_customers/shared/list') %>")

@ -2,7 +2,7 @@
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">添加户</h5>
<h5 class="modal-title">添加户</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>

@ -3,8 +3,8 @@
<tr>
<th width="6%">序号</th>
<th width="20%" class="text-left">业务员</th>
<th width="30%" class="text-left">重点跟踪客户(点击数字客户列表)</th>
<th width="30%" class="text-left">重点跟踪院校(点击数字渠道列表)</th>
<th width="30%" class="text-left">重点用户跟踪(点击数字进入列表)</th>
<th width="30%" class="text-left">重点院校跟踪(点击数字进入列表)</th>
<th width="14%">操作</th>
</tr>
</thead>
@ -14,15 +14,15 @@
<tr class="salesman-item salesman-item-<%= salesman.id %>">
<td><%= index + 1 %></td>
<td class="text-left">
<span><%= link_to salesman.name, admins_salesman_path(salesman), :title => salesman.name %></span>
<span><%= link_to salesman.name, users_path(salesman), :title => salesman.name %></span>
</td>
<td class="text-left">
<span><%= link_to salesman.salesman_customers_count.to_i,
admins_salesman_customers_path(salesman_id: salesman), :title => "点击进入户列表" %></span>
admins_salesman_customers_path(salesman_id: salesman), :title => "点击进入户列表" %></span>
</td>
<td class="text-left">
<span><%= link_to salesman.salesman_channels_count.to_i, admins_salesman_channels_path(salesman_id: salesman),
:title => "点击进入渠道列表" %></span>
:title => "点击进入院校列表" %></span>
</td>
<td>
<%= delete_link '删除', admins_salesman_path(salesman, element: ".salesman-item-#{salesman.id}"),

@ -88,14 +88,14 @@
</li>
<li>
<%= sidebar_item_group('#running_data', '运营数据', icon: 'bar-chart') do %>
<li><%= sidebar_item(admins_salesmans_path, '销售数据列表', icon: 'columns', controller: 'admins-salesman') %></li>
<%= sidebar_item_group('#running-data', '运营数据', icon: 'bar-chart') do %>
<li><%= sidebar_item(admins_salesmans_path, '销售数据列表', icon: 'columns', controller: 'admins-salesmans') %></li>
<% end %>
</li>
<li>
<%= sidebar_item_group('#other-submenu', '其他', icon: 'list-alt') do %>
<li><%= sidebar_item(admins_repertoires_path, '技术体系', icon: 'sitemap', controller: 'admins-repertoire') %></li>
<li><%= sidebar_item(admins_repertoires_path, '技术体系', icon: 'sitemap', controller: 'admins-repertoires') %></li>
<% end %>
</li>

@ -73,8 +73,8 @@
</div>
<div class="mr-5">
<label for="is_wechat_support">
<%= check_box_tag :is_wechat_support, !@sort_json[:is_wechat_support],@sort_json[:is_wechat_support], class:"shixun-settings-select" %>
<span class="only_view">只看小程序可用</span>
<%= check_box_tag :no_subject, !@sort_json[:no_subject],@sort_json[:no_subject], class:"shixun-settings-select" %>
<span class="only_view">已发布没关联课程</span>
</label>
</div>

@ -0,0 +1,5 @@
<% if @message.present? %>
$.notify({ message: "<%= @message %>" });
<% else %>
$(".sub-discipline-list-container").html("<%= j(render :partial => 'admins/sub_disciplines/shared/list') %>");
<% end %>

@ -1,3 +1,4 @@
<% max_position = @sub_disciplines.pluck(:position).max %>
<table class="table table-hover text-center sub-discipline-list-table">
<thead class="thead-light">
<tr>
@ -11,9 +12,9 @@
</thead>
<tbody>
<% if @sub_disciplines.present? %>
<% @sub_disciplines.each_with_index do |sub, index| %>
<% @sub_disciplines.each do |sub| %>
<tr class="sub-discipline-item sub-discipline-item-<%= sub.id %>">
<td><%= index + 1 %></td>
<td><%= sub.position %></td>
<td class="text-left">
<span><%= link_to sub.name, admins_tag_disciplines_path(sub_discipline_id: sub), :title => sub.name %></span>
</td>
@ -21,6 +22,9 @@
<td><%= check_box_tag :shixun,!sub.shixun,sub.shixun,disabled:!sub.discipline&.shixun,remote:true,data:{id:sub.id},class:"sub-discipline-source-form" %></td>
<td><%= check_box_tag :question,!sub.question,sub.question,disabled:!sub.discipline&.question,remote:true,data:{id:sub.id},class:"sub-discipline-source-form" %></td>
<td>
<%= javascript_void_link('上移', class: 'move-action', data: { id: sub.id, opr: "up" }, style: sub.position == 1 ? 'display:none' : '') %>
<%= javascript_void_link('下移', class: 'move-action', data: { id: sub.id, opr: "down" }, style: sub.position == max_position ? 'display:none' : '') %>
<%= link_to '编辑', edit_admins_sub_discipline_path(sub), remote: true, class: 'action' %>
<%= delete_link '删除', admins_sub_discipline_path(sub, element: ".sub-discipline-item-#{sub.id}"), class: 'delete-sub-discipline-action' %>
</td>

@ -6,7 +6,7 @@
<%= form_tag(admins_subject_settings_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
<div class="form-group mr-1">
<label for="status">状态:</label>
<% status_options = [['全部', ''], ['编辑中', 'pending'], ['审核中', 'applying'], ['已发布', 'published']] %>
<% status_options = [['全部', ''], ['编辑中', 'pending'], ['审核中', 'applying'], ['已公开', 'published']] %>
<%= select_tag(:status, options_for_select(status_options), class: 'form-control') %>
</div>

@ -5,7 +5,7 @@
<span class="badge badge-pill badge-info excellent-badge" style="<%= subject.excellent? ? '' : 'display:none' %>">金课</span>
</td>
<td><%= display_text subject.repertoire&.name %></td>
<td><%= display_text subject.status == 2 ? "已发布" : "未发布" %></td>
<td><%= display_text subject.public == 2 ? "已公开" : ((subject.public == 1 && subject.status == 2) ? "审核中" : "未发布") %></td>
<td>
<%= select_tag(:sub_disciplines, options_for_select(@sub_disciplines, subject.sub_disciplines.pluck(:id)),multiple:true,class:"form-control subject-setting-form",data:{id:subject.id},id:"tags-chosen-#{subject.id}") %>
</td>
@ -26,4 +26,22 @@
multiple: true,
maximumSelectionLength: 3,
placeholder: '请选择课程体系'});
$(".action-container").on("change", '.subject-mobile-form', function () {
var s_id = $(this).attr("data-id");
var s_value = $(this).val();
var s_name = $(this).attr("name");
var json = {};
var s_index = $(this).parent("td").siblings(".shixun-line-no").text();
json[s_name] = s_value;
json["page_no"] = s_index;
$.ajax({
url: "/admins/subject_settings/update_mobile_show?subject_id=" + s_id,
type: "POST",
dataType:'script',
data: json
});
});
</script>

@ -1 +0,0 @@
$.notify({ message: '更新成功' });

@ -0,0 +1,5 @@
<% if @message.present? %>
$.notify({ message: "<%= @message %>" });
<% else %>
$(".tag-discipline-list-container").html("<%= j(render :partial => 'admins/tag_disciplines/shared/list') %>");
<% end %>

@ -1,3 +1,4 @@
<% max_position = @tag_disciplines.pluck(:position).max %>
<table class="table table-hover text-center tag-discipline-list-table">
<thead class="thead-light">
<tr>
@ -12,9 +13,9 @@
</thead>
<tbody>
<% if @tag_disciplines.present? %>
<% @tag_disciplines.each_with_index do |tag, index| %>
<% @tag_disciplines.each do |tag| %>
<tr class="tag-discipline-item tag-discipline-item-<%= tag.id %>">
<td><%= index + 1 %></td>
<td><%= tag.position %></td>
<td class="text-left"><%= tag.name %></td>
<td>
<% if tag.user.present? %>
@ -36,6 +37,9 @@
<%= check_box_tag :question,!tag.question,tag.question,disabled:disabled,remote:true,data:{id:tag.id},class:"tag-discipline-source-form" %>
</td>
<td>
<%= javascript_void_link('上移', class: 'move-action', data: { id: tag.id, opr: "up" }, style: tag.position == 1 ? 'display:none' : '') %>
<%= javascript_void_link('下移', class: 'move-action', data: { id: tag.id, opr: "down" }, style: tag.position == max_position ? 'display:none' : '') %>
<%= link_to '编辑', edit_admins_tag_discipline_path(tag), remote: true, class: 'action' %>
<%= delete_link '删除', admins_tag_discipline_path(tag, element: ".tag-discipline-item-#{tag.id}"), class: 'delete-tag-discipline-action' %>
</td>

@ -1,5 +1,6 @@
# 教师身份的立即发布、立即截止、代码查重入口的判断
json.publish_immediately identity < Course::STUDENT && homework.publish_immediately(user)
json.end_immediately identity < Course::STUDENT && homework.end_immediately(user)
charge_ids = homework.course.charge_group_ids(user)
json.publish_immediately identity < Course::STUDENT && homework.publish_immediately(charge_ids)
json.end_immediately identity < Course::STUDENT && homework.end_immediately(charge_ids)
json.code_review identity < Course::STUDENT && homework.code_review if homework.homework_type == 'practice'
json.view_answer homework.view_answer(identity, user.id) if homework.homework_type != "practice"

@ -1,8 +1,15 @@
json.main_category main_catrgory do |category|
json.main_category_id 0
json.main_category_name category.module_name
homework_count = practice_homework_count category.course
json.publish_count homework_count[:publish_count]
json.unpublish_count homework_count[:unpublish_count]
json.all_count homework_count[:all_count]
end
json.homework_category homework_category do |category|
json.category_id category.id
json.category_name category.name
json.publish_count category.homework_publish_count
json.unpublish_count category.homework_unpublish_count
json.all_count category.homework_commons.size
end

@ -1,7 +1,9 @@
json.partial! "homework_public_navigation", locals: {homework: @homework, course: @course, user: @current_user}
json.last_review_time @last_review_time
json.publish_immediately @user_course_identity < Course::STUDENT && @homework.publish_immediately(@current_user)
json.end_immediately @user_course_identity < Course::STUDENT && @homework.end_immediately(@current_user)
json.publish_immediately @user_course_identity < Course::STUDENT && @homework.publish_immediately(@charge_ids)
json.end_immediately @user_course_identity < Course::STUDENT && @homework.end_immediately(@charge_ids)
# 分班情况
json.group_info do

@ -24,6 +24,10 @@ json.homeworks @homework_commons.each do |homework|
# 只有在主目录才显示
json.upper_category_name homework.course_second_category&.name unless params[:category]
charge_ids = @course.charge_group_ids(@member)
json.publish_immediately @user.logged? && @user_course_identity < Course::STUDENT && homework.publish_immediately(charge_ids)
json.end_immediately @user.logged? && @user_course_identity < Course::STUDENT && homework.end_immediately(charge_ids)
unless curr_status[:status].include?("未发布")
work_count = calculate_work_count homework, @member
json.commit_count work_count[:commit_count]

@ -1,8 +1,3 @@
json.tags @tech_system do |tag|
json.tag_id tag.id
json.tag_name tag.name
end
json.subjects do
json.partial! 'subject', locals: {subjects: @subjects}
end

@ -0,0 +1,13 @@
json.activities @activities do |activity|
json.(activity, :course_act_id, :course_act_type)
json.author do
user = activity.user
json.name user.real_name
json.login user.login
json.img url_to_avatar(user)
end
json.created_at activity.created_at.strftime('%m-%d %H:%M')
json.container_name activity.container_name
json.container_type activity.course_act_type == "HomeworkCommon" ? activity.course_act&.homework_type : ""
end
json.activities_count @activities_count

@ -29,6 +29,10 @@ module Educoderplus
# job
config.active_job.queue_adapter = :sidekiq
config.middleware.use OmniAuth::Builder do
provider :cas, url: 'https://urp.tfswufe.edu.cn/cas'
end
config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'

@ -357,7 +357,6 @@ H漫画
学生暴动
镇压学生
广安第二人民医院
胡新宇
趙紫陽
自由亚州
践踏中国女性
@ -682,7 +681,6 @@ A片
被迫
被逼
强暴
口技
破处
精液
幼交
@ -996,7 +994,6 @@ A片
李少民
李淑娴
李旺阳
李文斌
李月月鸟
李志绥
连胜德
@ -1157,7 +1154,6 @@ A片
信用危机
邢铮
熊炎
熊焱
徐邦秦
徐才厚
徐匡迪
@ -1194,7 +1190,6 @@ A片
张伯笠
张宏堡
张万年
张伟国
张昭富
张志清
赵海青

@ -8,8 +8,8 @@ Rails.application.routes.draw do
get 'attachments/download/:id/:filename', to: 'attachments#show'
get 'auth/qq/callback', to: 'oauth/qq#create'
get 'auth/failure', to: 'oauth/base#auth_failure'
get 'auth/cas/callback', to: 'oauth/cas#create'
resources :edu_settings
scope '/api' do
@ -26,7 +26,7 @@ Rails.application.routes.draw do
put 'commons/unhidden', to: 'commons#unhidden'
delete 'commons/delete', to: 'commons#delete'
resources :jupyters do
resources :jupyters do
collection do
get :save_with_tpi
get :save_with_tpm
@ -42,7 +42,7 @@ Rails.application.routes.draw do
post :import_with_tpm
end
end
resources :memos do
member do
post :sticky_or_cancel
@ -1040,12 +1040,13 @@ Rails.application.routes.draw do
member do
get :shixun_homework_category
get :teachers
delete :delete_course_teachers
post :change_member_roles
get :students
delete :delete_course_students
get :course_groups
get :basic_info
get :course_activities
post :change_member_roles
delete :delete_course_teachers
delete :delete_course_students
end
collection do
@ -1355,9 +1356,15 @@ Rails.application.routes.draw do
resources :projects, only: [:index, :destroy]
resources :disciplines, only: [:index, :create, :edit, :update, :destroy]
resources :sub_disciplines, only: [:index, :create, :edit, :update, :destroy]
resources :tag_disciplines, only: [:index, :create, :edit, :update, :destroy]
resources :disciplines, only: [:index, :create, :edit, :update, :destroy] do
post :adjust_position, on: :member
end
resources :sub_disciplines, only: [:index, :create, :edit, :update, :destroy] do
post :adjust_position, on: :member
end
resources :tag_disciplines, only: [:index, :create, :edit, :update, :destroy] do
post :adjust_position, on: :member
end
resources :repertoires, only: [:index, :create, :edit, :update, :destroy]
resources :sub_repertoires, only: [:index, :create, :edit, :update, :destroy]

@ -0,0 +1,8 @@
class SyncSubjectdsMobile < ActiveRecord::Migration[5.2]
def change
SubDisciplineContainer.find_each do |sc|
Subject.find(sc.container_id).update_column(:show_mobile, true)
end
end
end

@ -0,0 +1,7 @@
class AddPositionToDiscipline < ActiveRecord::Migration[5.2]
def change
add_column :disciplines, :position, :integer, default: 0
add_column :sub_disciplines, :position, :integer, default: 0
add_column :tag_disciplines, :position, :integer, default: 0
end
end

@ -0,0 +1,15 @@
class MigrateDisciplinePosition < ActiveRecord::Migration[5.2]
def change
Discipline.all.each_with_index do |discipline, i|
discipline.update_column("position", i + 1)
discipline.sub_disciplines.each_with_index do |sub, j|
sub.update_column("position", j + 1)
sub.tag_disciplines.each_with_index do |tag, k|
tag.update_column("position", k + 1)
end
end
end
end
end

@ -0,0 +1,10 @@
class AddUniqIndexToSalesmanChannel < ActiveRecord::Migration[5.2]
def change
sql = %Q(delete from salesman_channels where (salesman_id, school_id) in
(select * from (select salesman_id, school_id from salesman_channels group by salesman_id, school_id having count(*) > 1) a)
and id not in (select * from (select min(id) from salesman_channels group by salesman_id, school_id having count(*) > 1 order by id) b))
ActiveRecord::Base.connection.execute sql
add_index :salesman_channels, [:salesman_id, :school_id], unique: true
end
end

@ -0,0 +1,10 @@
class AddUniqIndexToSalesmanCustomer < ActiveRecord::Migration[5.2]
def change
sql = %Q(delete from salesman_customers where (salesman_id, user_id) in
(select * from (select salesman_id, user_id from salesman_customers group by salesman_id, user_id having count(*) > 1) a)
and id not in (select * from (select min(id) from salesman_customers group by salesman_id, user_id having count(*) > 1 order by id) b))
ActiveRecord::Base.connection.execute sql
add_index :salesman_customers, [:salesman_id, :user_id], unique: true
end
end

@ -0,0 +1,5 @@
class MigrateCourseMessageAct < ActiveRecord::Migration[5.2]
def change
CourseActivity.where(course_act_type: "JoinCourse").update_all(course_act_type: "CourseMessage")
end
end

@ -45,7 +45,7 @@ namespace :homework_publishtime do
end
end
homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id) if !homework.course_acts.exists?
CourseActivity.create(user_id: homework.user_id, course_id: homework.course_id, course_act: homework) if !homework.course_act.present?
end
# 分组设置发布时间的作业
@ -66,7 +66,7 @@ namespace :homework_publishtime do
.where("homework_type = 4 and end_time <= '#{Time.now}'")
homework_commons.each do |homework|
# homework_challenge_settings = homework.homework_challenge_settings
homework.homework_detail_manual.update_column("comment_status", 2)
# homework.homework_detail_manual.update_column("comment_status", 2)
if homework.allow_late
if homework.unified_setting

@ -0,0 +1,254 @@
# 执行示例 RAILS_ENV=production bundle exec rake migrate_course_resource:import_attachments args=3835,2526
#
desc "同步课堂学生数据"
namespace :migrate_course_resource do
if ENV['args']
source_id = ENV['args'].split(",")[0] # 源课堂id
target_id = ENV['args'].split(",")[1] # 目标课堂id
end
task import_attachments: :environment do
source_course = Course.find_by(id: source_id)
target_course = Course.find_by(id: target_id)
return if source_course.blank? || target_course.blank?
source_course.attachments.each do |atta|
if atta.course_second_category.present?
target_category = CourseSecondCategory.find_by(name: atta.course_second_category.name, course_id: target_course.id, category_type: "attachment")
unless target_category.present?
course_module = target_course.course_modules.find_by(module_type: "attachment")
target_category = CourseSecondCategory.create(name: atta.course_second_category.name, course_id: target_course.id,
category_type: "attachment", course_module_id: course_module&.id,
position: course_module&.course_second_categories&.count.to_i + 1)
end
end
target_course.attachments << target_course.attachments.build(atta.attributes.except("id").merge(
quotes: 0,
downloads: 0,
author_id: target_course.tea_id,
created_on: Time.now,
course_second_category_id: target_category&.id.to_i
))
end
end
task import_videos: :environment do
source_course = Course.find_by(id: source_id)
target_course = Course.find_by(id: target_id)
return if source_course.blank? || target_course.blank?
source_course.course_videos.each do |video|
target_course.course_videos << CourseVideo.new(video_id: video.video_id)
end
end
task import_homeworks: :environment do
source_course = Course.find_by(id: source_id)
target_course = Course.find_by(id: target_id)
return if source_course.blank? || target_course.blank?
source_course.homework_commons.each do |homework|
ActiveRecord::Base.transaction do
if homework.course_second_category.present?
target_category = CourseSecondCategory.find_by(name: homework.course_second_category.name, course_id: target_course.id, category_type: "shixun_homework")
unless target_category.present?
course_module = target_course.course_modules.find_by(module_type: "shixun_homework")
target_category = CourseSecondCategory.create(name: homework.course_second_category.name, course_id: target_course.id,
category_type: "shixun_homework", course_module_id: course_module&.id,
position: course_module&.course_second_categories&.count.to_i + 1)
end
end
# 复制作业的基本信息
new_homework = HomeworkCommon.new(name: homework.name, user_id: target_course.tea_id, description: homework.description,
homework_type: homework.homework_type, course_id: target_course.id,
reference_answer: homework.reference_answer, course_second_category_id: target_category&.id.to_i)
# 作业的基本设置复制
new_homework.homework_detail_manual = HomeworkDetailManual.new
new_homework_detail_manual = new_homework.homework_detail_manual
new_homework_detail_manual.te_proportion = 0.7
new_homework_detail_manual.ta_proportion = 0.3
if new_homework.homework_type == "group"
# 分组作业表的复制
old_homework_group = homework.homework_detail_group
new_homework.homework_detail_group = HomeworkDetailGroup.new
new_homework.homework_detail_group.min_num = old_homework_group&.min_num
new_homework.homework_detail_group.max_num = old_homework_group&.max_num
new_homework.homework_detail_group.base_on_project = old_homework_group&.base_on_project
end
if new_homework.homework_type == "practice"
# 分组作业表的复制
new_homework.homework_commons_shixun = HomeworkCommonsShixun.new
new_homework.homework_commons_shixun.shixun_id = homework.homework_commons_shixun&.shixun_id
homework.position = HomeworkCommon.where(course_id:target_course.id, homework_type: "practice").pluck(:position).max.to_i + 1
homework.homework_challenge_settings.each do |setting|
new_homework.homework_challenge_settings << HomeworkChallengeSetting.new(challenge_id: setting.challenge_id,
shixun_id: setting.shixun_id, score: setting.score)
end
end
# 附件
if new_homework.save
homework.attachments.try(:each) do |attachment|
att = attachment.copy
att.container_id = nil
att.container_type = nil
att.author_id = homework.user_id
att.attachtype = attachment.attachtype || 1
# att.attachtype = 1
att.copy_from = attachment.id
att.save!
new_homework.attachments << att
end
new_homework_detail_manual.save if new_homework_detail_manual
new_homework.homework_detail_group.save if new_homework.homework_detail_group
new_homework.homework_commons_shixun.save if new_homework.homework_commons_shixun
CreateStudentWorkJob.perform_later(new_homework.id)
end
end
end
end
task import_exercises: :environment do
source_course = Course.find_by(id: source_id)
target_course = Course.find_by(id: target_id)
return if source_course.blank? || target_course.blank?
source_course.exercises.each do |exercise|
ActiveRecord::Base.transaction do
new_exercise = Exercise.new(:exercise_name => exercise.exercise_name, :exercise_description => exercise.exercise_description,
:user_id => target_course.tea_id, :course_id => target_course.id)
# 复制试卷基本信息
exercise.exercise_questions.each do |q|
option = {
:question_title => q.question_title,
:question_type => q.question_type || 1,
:question_number => q.question_number,
:question_score => q.question_score,
:shixun_name => q.shixun_name,
:shixun_id => q.shixun_id,
:is_ordered => q.is_ordered
}
exercise_question = new_exercise.exercise_questions.new option
# question_type5实训题其他是非实训题
if q.question_type != 5
# 复制选择题题目选项
q.exercise_choices.try(:each_with_index) do |choice, index|
exercise_question.exercise_choices.new({choice_position: index+1, choice_text: choice.choice_text})
end
# 复制标准答案(填空题和问答题) 多空填空题的话应该是原标准答案的exercise_choice_id即为题空的位置。
q.exercise_standard_answers.try(:each) do |answer|
exercise_question.exercise_standard_answers.new({exercise_choice_id: answer.exercise_choice_id, answer_text: answer.answer_text})
end
else
# 复制实训题
q.exercise_shixun_challenges.try(:each_with_index) do |sc, index|
exercise_question.exercise_shixun_challenges.new({position: index+1, challenge_id: sc.challenge_id,
shixun_id: sc.shixun_id, question_score: sc.question_score})
end
end
end
new_exercise.save!
end
end
end
task import_polls: :environment do
source_course = Course.find_by(id: source_id)
target_course = Course.find_by(id: target_id)
return if source_course.blank? || target_course.blank?
source_course.polls.each do |poll|
new_poll = Poll.new(:polls_name => poll.polls_name, :polls_description => poll.polls_description, :user_id => target_course.tea_id,
:polls_type => 'Course', :course_id => target_course.id)
poll.poll_questions.try(:each) do |q|
option = {
:question_title => q.question_title,
:question_type => q.question_type || 1,
:is_necessary => q.is_necessary,
:question_number => q.question_number,
:max_choices => q.max_choices,
:min_choices => q.min_choices
}
poll_question = new_poll.poll_questions.new option
q.poll_answers.try(:each_with_index) do |choice, index|
poll_question.poll_answers.new({answer_position: index+1, answer_text: choice.answer_text})
end
end
new_poll.save!
end
end
task import_members: :environment do
source_course = Course.find_by(id: source_id)
target_course = Course.find_by(id: target_id)
return if source_course.blank? || target_course.blank?
# 先把target——course中的老师创建分班权限
target_course.teachers.each do |member|
if member.teacher_course_groups.blank?
target_course.course_groups.each do |group|
TeacherCourseGroup.create!(course_group_id: group.id, course_id: target_course.id, course_member_id: member&.id, user_id: member&.user_id)
end
end
end
source_course.course_members.where(role: %i[PROFESSOR ASSISTANT_PROFESSOR]).each do |teacher|
new_member = target_course.teachers.find_by(user_id: teacher.user_id)
unless new_member.present?
new_member = CourseMember.create!(course_id: target_course.id, user_id: teacher.user_id, role: teacher.role)
end
end
source_course.course_groups.each do |group|
unless target_course.course_groups.where(name: group.name).exists?
new_group = CourseGroup.create!(course_id: target_course.id, name: group.name, position: target_course.course_groups.pluck(:position).max.to_i + 1)
else
new_group = target_course.course_groups.find_by(name: group.name)
end
new_user_ids = []
group.course_members.where(role: 4).each do |member|
new_member = target_course.students.find_by(user_id: member.user_id)
if new_member.present?
new_member.update_attributes(course_group_id: new_group.id)
else
CourseMember.create!(course_id: target_course.id, course_group_id: new_group.id, user_id: member.user_id, role: member.role)
new_user_ids << member.user_id
end
end
CourseAddStudentCreateWorksJob.perform_later(target_course.id, new_user_ids) unless new_user_ids.blank?
group.teacher_course_groups.each do |teacher_group|
member = CourseMember.find_by(course_id: target_course.id, user_id: teacher_group.user_id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR])
if member.present? && !member.teacher_course_groups.where(course_group_id: new_group.id).exists?
TeacherCourseGroup.create!(course_group_id: new_group.id, course_id: target_course.id, course_member_id: member&.id, user_id: member&.user_id)
end
end
end
user_ids = []
source_course.students.where(course_group_id: 0).each do |member|
new_member = target_course.students.find_by(user_id: member.user_id)
if new_member.present?
new_member.update_attributes(course_group_id: 0)
else
CourseMember.create!(course_id: target_course.id, course_group_id: 0, user_id: member.user_id, role: member.role)
user_ids << member.user_id
end
end
CourseAddStudentCreateWorksJob.perform_later(target_course.id, user_ids) unless user_ids.blank?
end
end

@ -1,32 +0,0 @@
# 执行示例 RAILS_ENV=production bundle exec rake migrate_course_student:student args=3835,2526,21950,1000
# args 第一个课程 course_id第二个参数是学校school_id第三个参数是部门id第四个参数是迁移数量
#
desc "同步学校的学生"
namespace :migrate_course_student do
if ENV['args']
course_id = ENV['args'].split(",")[0] # 对应课堂的id
school_id = ENV['args'].split(",")[1] # 对应学校id
department_id = ENV['args'].split(",")[2] # 对应部门id
limit = ENV['args'].split(",")[3] # 限制导入的数量
end
task :student => :environment do
course = Course.find course_id
users = User.joins(:user_extension).where(user_extensions: {school_id: school_id, department_id: department_id, identity: 1}).limit(limit)
user_ids = []
users.each do |user|
if user.student_id.present? && !course.students.exists?(user_id: user.id)
begin
CourseMember.create!(course_id: course_id, user_id: user.id, role: 4)
user_ids << user.id
rescue Exception => e
Rails.logger(e.message)
end
end
end
CourseAddStudentCreateWorksJob.perform_later(course_id, user_ids)
end
end

@ -0,0 +1,261 @@
desc "同步天府学院数据, 执行顺序依次 import_teaches、 import_courses、 import_students、import_course_members"
namespace :tfxy do
xlsx =Roo::Spreadsheet.open(Rails.root.join("tfxy.xlsx").to_s)
task import_teaches: :environment do
desc "同步天府学院老师数据"
xlsx =Roo::Spreadsheet.open(Rails.root.join("tfxy.xlsx").to_s)
school = School.find_or_create_by(name: '西南财经大学天府学院') do |d|
d.province = '四川省'
d.city = '成都'
end
#导入教师用户
teach_data = xlsx.sheet(3)
teach_data_last_row = teach_data.last_row
2.upto(teach_data_last_row) do |r|
if teach_data.cell(r, 6).to_s&.strip.present?
old_user = User.where("phone = '#{teach_data.cell(r, 5)}' OR mail = '#{teach_data.cell(r, 6).to_s.strip}' OR login = 'tfxy#{teach_data.cell(r, 1)}' " ).first
else
old_user = User.where("phone = '#{teach_data.cell(r, 5)}' OR login = 'tfxy#{teach_data.cell(r, 1)}' ").first
end
if !old_user.present?
user = User.new(
phone: teach_data.cell(r, 5),
login: "tfxy#{teach_data.cell(r, 1)}",
type: 'User',
status: User::STATUS_ACTIVE,
lastname: teach_data.cell(r, 2),
nickname: teach_data.cell(r, 2),
password: "Edu#{teach_data.cell(r, 5)}",
mail: teach_data.cell(r, 6).to_s&.strip.present? ? teach_data.cell(r, 6).to_s&.strip : nil,
profile_completed: true,
professional_certification: 1,
certification: 1,
authentication: true,
laboratory_id: Laboratory.find(1)&.id
)
if user.save!
departemnt = school.departments.find_or_create_by!(name: teach_data.cell(r, 4))
user.create_user_extension!(
school_id: school.id,
location: school.province,
location_city: school.city,
gender: teach_data.cell(r, 3) == '女' ? 1 : 0,
identity: 0,
technical_title: '教师',
department_id: departemnt.id
)
open_user = OpenUsers::Cas.find_or_initialize_by(uid: teach_data.cell(r, 1)) do |u|
u.extra = {phone: teach_data.cell(r, 8)}
u.user_id = user.id
end
p "-------user -----#{user.inspect}"
open_user.save
end
else
old_user.update(
lastname: teach_data.cell(r, 2),
nickname: teach_data.cell(r, 2),
certification: true,
professional_certification: true,
authentication: true,
profile_completed: true)
OpenUsers::Cas.find_or_create_by(uid: teach_data.cell(r, 1)) do |u|
u.extra = {phone: teach_data.cell(r, 5)}
u.user_id = old_user.id
end
end
end
end
task import_courses: :environment do
desc "同步天府学院课堂数据"
school = School.find_or_create_by(name: '西南财经大学天府学院') do |d|
d.province = '四川省'
d.city = '成都'
end
course_info = {"C程序设计与实践"=>4, "数据库技术应用"=>2, "数据库应用"=>2, "数据库原理"=>2, "数据库实践"=>2, "面向对象程序设计与实践"=>2, "JavaSE程序设计及实践辅修"=>4, "编译原理"=>2, "电路与电子技术"=>3, "传感器原理与应用"=>3, "物联网技术与应用"=>2, "人工智能实践"=>3, "计算机组成原理"=>2, "移动应用开发实训"=>4, "面向对象程序课程设计"=>1, "Web程序设计"=>2, "数据仓库与数据挖掘"=>2, "定量分析技术"=>4, "Python程序设计"=>4, "信息系统分析与设计"=>3, "数据处理综合实训"=>2, "绘画基础Ⅱ(色彩构成)"=>2, "数字图像处理"=>4, "虚拟现实技术及应用"=>4, "三维建模技术"=>4, "游戏技术基础"=>4, "传感器与单片机实训"=>2, "数据库原理与实践"=>4, "高级程序设计(二)"=>4, "数据结构与算法分析"=>4, "实训"=>1, "Linux 操作系统"=>4, "Java Web程序设计与实践"=>8, "软件测试与项目管理"=>4, "Android程序设计"=>8, "移动应用开发"=>4, "商业智能案例分析"=>4, "数据分析与挖掘"=>4, "Oracle DBA"=>4, "信息网络安全测试与评估"=>4, "Android编程"=>8, "电子线路CAD设计"=>2, "ARM接口技术"=>4, "嵌入式Linux应用系统设计"=>4, "信息系统开发实训"=>2, "绘画基础I平面构成"=>2, "智能信息处理技术"=>3}
course_data = xlsx.sheet(4)
course_data_last_row = course_data.last_row
2.upto(course_data_last_row) do |r|
course_group = CourseGroup.find_or_initialize_by(invite_code: course_data.cell(r, 3))
teach_user = OpenUsers::Cas.find_by(uid: course_data.cell(r, 5))&.user
puts "----teach_user-----uid-----#{course_data.cell(r, 5)}------#{teach_user.inspect}---"
if !course_group.persisted? && teach_user.present?
course = Course.find_or_initialize_by(school_id: school.id, name: course_data.cell(r, 2), invite_code: course_data.cell(r, 1)[3..7]) do |d|
d.is_public = 0
d.tea_id = teach_user.id
d.laboratory_id = Laboratory.find(1)&.id
d.credit = course_info[course_data.cell(r, 1)]
end
if !course.persisted?
# 创建课堂
course_list = CourseList.find_or_initialize_by(name: course_data.cell(r, 2), user_id: teach_user.id) do |d|
d.is_admin = 0
end
course.course_list = course_list
course.invite_code = course_data.cell(r, 1)[3..7]
course.save!
CourseInfo.create!(user_id: teach_user.id, course_id: course.id)
course.create_course_modules(["shixun_homework", "common_homework", "group_homework", "exercise", "attachment", "course_group", "video"])
end
course_group.position = course.course_groups_count + 1
course_group.name = course_data.cell(r, 4)
course_group.course = course
course_group.save!
puts "---course_group----#{course_group.inspect}"
course_member = CourseMember.find_or_initialize_by(course_id: course.id, user_id: teach_user.id) do |d|
d.role = 2
d.course_group_id = 0
end
course_member.save! if !course_member.persisted?
TeacherCourseGroup.create!(course_id: course.id, course_member_id: course_member.id, user_id: teach_user.id, course_group_id: course_group.id)
end
end
end
task import_students: :environment do
desc "同步天府学院学生数据"
student_data = xlsx.sheet(5)
student_data_last_row = student_data.last_row
school = School.find_or_create_by(name: '西南财经大学天府学院') do |d|
d.province = '四川省'
d.city = '成都'
end
2.upto(student_data_last_row) do |r|
# 邮箱存在
if student_data.cell(r, 9).to_s&.strip.present?
old_user = User.where("phone = '#{student_data.cell(r, 8)}' OR mail = '#{student_data.cell(r, 9).to_s.strip}' OR login = 'tfxy#{student_data.cell(r, 1)}' " ).first
else
old_user = User.where("phone = '#{student_data.cell(r, 8)}' OR login = 'tfxy#{student_data.cell(r, 1)}' " ).first
end
if !old_user.present?
user = User.new(
phone: student_data.cell(r, 8),
login: "tfxy#{student_data.cell(r, 1)}",
type: 'User',
status: User::STATUS_ACTIVE,
lastname: student_data.cell(r, 2),
nickname: student_data.cell(r, 2),
password: "Edu#{student_data.cell(r, 1)}",
mail: student_data.cell(r, 9).to_s&.strip.present? ? student_data.cell(r, 9).to_s&.strip : nil,
profile_completed: true,
professional_certification: 1,
certification: 1,
authentication: true,
laboratory_id: Laboratory.find(1)&.id
)
puts "----user #{user.inspect}"
if user.save!
departemnt = school.departments.find_or_create_by!(name: student_data.cell(r, 4))
user.create_user_extension!(
school_id: school.id,
location: school.province,
location_city: school.city,
gender: student_data.cell(r, 3) == '女' ? 1 : 0,
identity: 1,
student_id: student_data.cell(r, 1),
department_id: departemnt.id
)
OpenUsers::Cas.find_or_create_by(uid: student_data.cell(r, 1)) do |u|
u.extra = {phone: student_data.cell(r, 8)}
u.user_id = user.id
end
end
else
# 系统已有用户关联sso认证用户
old_user.update(
lastname: student_data.cell(r, 2),
nickname: student_data.cell(r, 2),
certification: true,
professional_certification: true,
authentication: true,
profile_completed: true)
OpenUsers::Cas.find_or_create_by(uid: student_data.cell(r, 1)) do |u|
u.extra = {phone: student_data.cell(r, 8)}
u.user_id = old_user.id
end
end
end
end
task import_course_members: :environment do
desc "天府学院学生到课程分班"
course_member_data = xlsx.sheet(6)
course_member_data_last_row = course_member_data.last_row
school = School.find_or_create_by(name: '西南财经大学天府学院') do |d|
d.province = '四川省'
d.city = '成都'
end
2.upto(course_member_data_last_row) do |r|
course_group = CourseGroup.find_by(invite_code: course_member_data.cell(r, 5))
student = OpenUsers::Cas.find_by(uid: course_member_data.cell(r, 1))&.user
puts "------student --- #{course_member_data.cell(r, 1)}--course group--#{course_member_data.cell(r, 5)}"
if student.present? && course_group.present?
course_member = CourseMember.find_or_initialize_by(course_id: course_group.course_id, user_id: student.id) do |d|
d.role = 4
d.course_group_id = course_group.id
end
puts "--------course_member #{course_member.inspect}"
course_member.save! if !course_member.persisted?
end
end
end
end

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save