diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index bd93401f3..0242bff21 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -230,6 +230,7 @@ class GraduationTopicsController < ApplicationController topic_repeat: topic.topic_repeat, province: topic.province, city: topic.city, + topic_type: topic.topic_type, course_list_id: @course.course_list_id) topic_bank.attachments.destroy_all else @@ -241,6 +242,7 @@ class GraduationTopicsController < ApplicationController topic_repeat: topic.topic_repeat, province: topic.province, city: topic.city, + topic_type: topic.topic_type, course_list_id: @course.course_list_id, user_id: current_user.id, graduation_topic_id: topic.id) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 74d1d05e2..e910db8cc 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -8,11 +8,11 @@ class ShixunsController < ApplicationController before_action :find_shixun, except: [:index, :new, :create, :menus, :get_recommend_shixuns, :propaedeutics, :departments, :apply_shixun_mirror, - :get_mirror_script, :download_file] + :get_mirror_script, :download_file, :shixun_list] before_action :shixun_access_allowed, except: [:index, :new, :create, :menus, :get_recommend_shixuns, :propaedeutics, :departments, :apply_shixun_mirror, - :get_mirror_script, :download_file] + :get_mirror_script, :download_file, :shixun_list] before_action :find_repo_name, only: [:repository, :commits, :file_content, :update_file, :shixun_exec, :copy, :add_file] before_action :allowed, only: [:update, :close, :update_propaedeutics, :settings, :publish, @@ -98,6 +98,50 @@ class ShixunsController < ApplicationController .each_with_object({}) { |r, obj| obj[r.shixun_id] = r.name } end + def shixun_list + # 全部实训/我的实训 + type = params[:type] || "all" + # 状态:已发布/未发布 + status = params[:status] || "all" + + # 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭) + if type == "mine" + @shixuns = current_user.shixuns.none_closed + else + if current_user.admin? + @shixuns = Shixun.none_closed.where(hidden: 0) + else + none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) + + @shixuns = Shixun.where.not(id: none_shixun_ids).none_closed.where(hidden: 0) + end + end + + unless status == "all" + @shixuns = status == "published" ? @shixuns.where(status: 2) : @shixuns.where(status: [0, 1]) + end + + ## 搜索关键字创建者、实训名称、院校名称 + unless params[:search].blank? + keyword = params[:search].strip + @shixuns = @shixuns.joins(user: [user_extension: :school]). + where("schools.name like '%#{keyword}%' + or concat(lastname, firstname) like '%#{keyword}%' + or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct + end + + ## 筛选 难度 + if params[:diff].present? && params[:diff].to_i != 0 + @shixuns = @shixuns.where(trainee: params[:diff]) + end + + @total_count = @shixuns.count + page = params[:page] || 1 + limit = params[:limit] || 15 + + @shixuns = @shixuns.order("myshixuns_count desc").page(page).per(limit).includes(:shixun_info, :subjects, user: [user_extension: :school]) + end + ## 获取顶部菜单 def menus @repertoires = Repertoire.includes(sub_repertoires: [:tag_repertoires]).order("updated_at asc") diff --git a/app/models/shixun.rb b/app/models/shixun.rb index db6bca43e..33d36d026 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -59,6 +59,7 @@ class Shixun < ApplicationRecord scope :visible, -> { where.not(status: -1) } scope :published, lambda{ where(status: 2) } scope :published_closed, lambda{ where(status: [2, 3]) } + scope :none_closed, lambda{ where(status: [0, 1, 2]) } scope :unhidden, lambda{ where(hidden: 0, status: 2) } scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) } scope :find_by_ids,lambda{|k| where(id:k)} diff --git a/app/views/shixuns/shixun_list.json.jbuilder b/app/views/shixuns/shixun_list.json.jbuilder new file mode 100644 index 000000000..13c556014 --- /dev/null +++ b/app/views/shixuns/shixun_list.json.jbuilder @@ -0,0 +1,15 @@ +json.shixun_list @shixuns do |shixun| + json.shixun_id shixun.id + json.identifier shixun.identifier + json.shixun_name shixun.name + json.description shixun.description + json.myshixuns_count shixun.myshixuns_count + json.school shixun.user&.school_name + json.creator shixun.user&.full_name + json.level level_to_s(shixun.trainee) + json.subjects shixun.subjects do |subject| + json.(subject, :id, :name) + end +end + +json.shixuns_count @total_count \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index e92440ae7..417b8cbea 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -179,6 +179,7 @@ Rails.application.routes.draw do get :get_mirror_script post :apply_shixun_mirror get :download_file + get :shixun_list end member do diff --git a/lib/tasks/public_course_sync.rake b/lib/tasks/public_course_sync.rake new file mode 100644 index 000000000..928cd9113 --- /dev/null +++ b/lib/tasks/public_course_sync.rake @@ -0,0 +1,149 @@ +#coding=utf-8 +# 执行示例 bundle exec rake public_course:student args=149,2903 +# args 第一个参数是subject_id,第二个参数是课程course_id +# 第一期时间:2018-12-16 至2019-03-31 +# 第二期时间:2019-04-07 至2019-07-28 +# +# 这次学习很有收获,感谢老师提供这么好的资源和细心的服务🎉🎉🎉 +# + +desc "同步精品课数据" +namespace :public_classes do + if ENV['args'] + subject_id = ENV['args'].split(",")[0] # 对应课程的id + course_id = ENV['args'].split(",")[1] # 对应课堂的id + start_time = ENV['args'].split(",")[2] # 表示课程模块 + end_time = ENV['args'].split(",")[3] # 表示课程模块 + limit = ENV['args'].split(",")[4] # 限制导入的数量 + type = ENV['args'].split(",")[5] # 表示课程模块 + end + + + task :student => :environment do + puts "subject_id is #{subject_id}" + puts "course_id is #{course_id}" + + user_ids = Myshixun.find_by_sql("select distinct(user_id) from myshixuns where created_at between #{start_time} and #{end_time} and shixun_id in (select shixun_id from stage_shixuns + where stage_id in (select id from stages where subject_id=#{subject_id})) limit #{limit}").map(&:user_id) + puts user_ids + if user_ids.present? + user_ids.each do |user_id| + puts user_id + begin + CourseMember.create!(course_id: course_id, user_id: user_id, role: 4) + rescue Exception => e + Rails.logger(e.message) + end + end + end + end + + task :test_user => :environment do + users = User.where(is_test: true) + users.limit(limit).find_each do |user| + puts user.id + CourseMember.create!(course_id: course_id, user_id: user.id, role: 4) + end + end + + + # 更新某个课程的某类时间 + # 执行示例 RAILS_ENV=production bundle exec rake public_course:time args=-1,2932,1,1 + task :time => :environment do + # course_id = ENV['args'].split(",")[0] # 对应课堂的id + # type = ENV['args'].split(",")[1] + + course = Course.find(course_id) + + case type.to_i + when 1 + # 讨论区 + messages = Message.where(board_id: course.boards) + messages.each do |message| + created_on = random_time start_time, end_time + puts created_on + message.update_columns(created_on: created_on, updated_on: created_on) + MessageDetail.where(message_id: message.id).each do |detail| + rand_created_on = random_time start_time, end_time + detail.update_columns(created_at: rand_created_on, updated_at: rand_created_on) + end + end + when 2 + # 作业 + course.homework_commons.each do |homework| + created_at = random_time(start_time, end_time) + publish_time = random_larger_time created_at, start_time, end_time + end_time = random_larger_time publish_time, start_time, end_time + updated_at = end_time + + homework.update_columns(publish_time: publish_time, end_time: end_time, created_at: created_at, updated_at: updated_at) + homework.homework_detail_manual.update_columns(comment_status: 6, created_at: created_at, updated_at: updated_at) + + homework.student_works.where("work_status !=0 and update_time > '#{end_time}'").update_all(update_time: end_time) + end + when 3 + # 试卷 + course.exercises.each do |exercise| + created_at = random_time start_time, end_time + publish_time = random_larger_time created_at, start_time, end_time + end_time = random_larger_time publish_time, start_time, end_time + updated_at = end_time + + exercise.update_columns(publish_time: publish_time, end_time: end_time, created_at: created_at, updated_at: updated_at, exercise_status: 3) + end + when 4 + # 资源 + course.attachments.each do |atta| + created_on = random_time start_time, end_time + + atta.update_columns(is_publish: 1, created_on: created_on, publish_time: created_on) + end + end + + end + + task :create_homework_work => :environment do + course = Course.find(course_id) + course.practice_homeworks.each do |homework| + if homework.student_works.count == 0 + str = "" + CourseMember.students(course).each do |student| + str += "," if str != "" + str += "(#{homework.id},#{student.user_id}, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" + end + if str != "" + sql = "insert into student_works (homework_common_id, user_id, created_at, updated_at) values" + str + ActiveRecord::Base.connection.execute sql + end + end + end + end + + def min_swith(time) + puts time + return time < 9 ? "0#{time}" : time + end + + def random_time(start_time, end_time) + hour = (6..23).to_a.sample(1).first + min = rand(60) + sec = rand(60) + + start_time = Date.parse(start_time) + end_time = Date.parse(end_time) + date = (start_time..end_time).to_a.sample(1).first + + time = "#{date} #{min_swith(hour)}:#{min_swith(min)}:#{min_swith(sec)}" + + puts time + time + end + + def random_larger_time(time, start_time, end_time) + large_time = random_time(start_time, end_time) + while large_time <= time + large_time = random_time(start_time, end_time) + end + large_time + end +end \ No newline at end of file diff --git a/public/react/src/modules/courses/coursesDetail/CoursesLeftNav.js b/public/react/src/modules/courses/coursesDetail/CoursesLeftNav.js index 1a7c19824..24235d723 100644 --- a/public/react/src/modules/courses/coursesDetail/CoursesLeftNav.js +++ b/public/react/src/modules/courses/coursesDetail/CoursesLeftNav.js @@ -749,9 +749,9 @@ class Coursesleftnav extends Component{ {/*毕业设计*/} {/*{item.type==="graduation"?
this.Navmodalnames(1,"attachment",item.id)}>添加目录
:""}*/} {/*讨论区*/} - {item.type==="board"?
this.Navmodalnames(e,6,"board",item.main_id)}>添加目录
:""} + {item.type==="board"?this.props.current_user&&this.props.current_user.course_is_end===true?"":
this.Navmodalnames(e,6,"board",item.main_id)}>添加目录
:""} {/*分班*/} - {item.type==="course_group"?
this.Navmodalnames(e,2,"course_group",item.id)}>添加分班
:""} + {item.type==="course_group"?this.props.current_user&&this.props.current_user.course_is_end===true?"":
this.Navmodalnames(e,2,"course_group",item.id)}>添加分班
:""} {/*分班*/} {/*{item.type==="course_group"? :""}*/}
this.Navmodalnames(e,3,"editname",item.id,item.name)}>重命名
@@ -798,7 +798,6 @@ class Coursesleftnav extends Component{ // console.log("778"); // console.log("CoursesLeftNav"); - // console.log(this.props); // console.log(course_modules); return( diff --git a/public/react/src/modules/courses/shixunHomework/Listofworksstudentone.js b/public/react/src/modules/courses/shixunHomework/Listofworksstudentone.js index 73ea4a221..bba76386a 100644 --- a/public/react/src/modules/courses/shixunHomework/Listofworksstudentone.js +++ b/public/react/src/modules/courses/shixunHomework/Listofworksstudentone.js @@ -3157,16 +3157,16 @@ class Listofworksstudentone extends Component { 计算成绩时间:{teacherdata&&teacherdata.calculation_time==null?"--": moment(teacherdata&&teacherdata.calculation_time).format('YYYY-MM-DD HH:mm')} { course_is_end===true?"":teacherdata&&teacherdata.task_operation&&teacherdata.task_operation[0]==="开启挑战"?"": - {computeTimetype===true? - (this.props.isNotMember()===false?
- 计算成绩 -
:""): - teacherdata&&teacherdata.homework_status!==undefined&&teacherdata.homework_status[0]=== "未发布"? "": - (this.props.isNotMember()===false?
- 计算成绩 -
:"") - } -
} + {computeTimetype===true? + (this.props.isNotMember()===false?
+ 计算成绩 +
:""): + teacherdata&&teacherdata.homework_status!==undefined&&teacherdata.homework_status[0]=== "未发布"? "": + (this.props.isNotMember()===false?
+ 计算成绩 +
:"") + } + } {/*因为计算按钮占了和这个位置,和设计沟通学生视角取消这个按钮*/}