diff --git a/app/assets/javascripts/admins/glcc_pr_check.js b/app/assets/javascripts/admins/glcc_pr_check.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/admins/glcc_pr_check.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/admins/glcc_pr_check.scss b/app/assets/stylesheets/admins/glcc_pr_check.scss new file mode 100644 index 000000000..7dfa6e7cf --- /dev/null +++ b/app/assets/stylesheets/admins/glcc_pr_check.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the admins/glcc_pr_check controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/admins/glcc_pr_check_controller.rb b/app/controllers/admins/glcc_pr_check_controller.rb new file mode 100644 index 000000000..1d79ba802 --- /dev/null +++ b/app/controllers/admins/glcc_pr_check_controller.rb @@ -0,0 +1,32 @@ +class Admins::GlccPrCheckController < Admins::BaseController + def index + params[:sort_by] = params[:sort_by].presence || 'created_on' + params[:sort_direction] = params[:sort_direction].presence || 'desc' + examine_materials = Admins::GlccExamineMaterial.call(params) + @examine_materials = paginate examine_materials.includes(:glcc_student) + end + + def send_mail + year = if params[:date].present? + params[:date][:year] + end + if year.nil? + return redirect_to admins_glcc_pr_check_index_path + flash[:error] = "时间不能为空" + end + if params[:term].blank? + return redirect_to admins_glcc_pr_check_index_path + flash[:error] = "考核选项不能为空" + end + + examine_materials = GlccMediumTermExamineMaterial.where(\ + term: params[:term], + created_on: [Time.now.change(year:year).beginning_of_year .. Time.now.change(year:year).end_of_year] + ) + examine_materials.map{ |e| + e.send_mail + } + flash[:danger] = "#{year} 年 #{params[:term].to_i == 1 ? "中期考核": "结项考核"} PR 检测邮件已全部发送完毕,一共#{examine_materials.count}封邮件" + redirect_to admins_glcc_pr_check_index_path + end +end diff --git a/app/helpers/admins/glcc_pr_check_helper.rb b/app/helpers/admins/glcc_pr_check_helper.rb new file mode 100644 index 000000000..9934b83bf --- /dev/null +++ b/app/helpers/admins/glcc_pr_check_helper.rb @@ -0,0 +1,2 @@ +module Admins::GlccPrCheckHelper +end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 28bbccf63..a99948879 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -30,4 +30,11 @@ class UserMailer < ApplicationMailer def feedback_email(mail, title, content) mail(to: mail, subject: title, content_type: "text/html", body: content) end + + def glcc_pr_check_email(mail, title, name, content) + @content = content + @name = name + mail(to: mail, subject: title) + end + end diff --git a/app/models/glcc_medium_term_examine_material.rb b/app/models/glcc_medium_term_examine_material.rb new file mode 100644 index 000000000..70bed6b9a --- /dev/null +++ b/app/models/glcc_medium_term_examine_material.rb @@ -0,0 +1,85 @@ +# == Schema Information +# +# Table name: ignores +# +# student_reg_id +# task_id +# defence_video_url +# code_or_pr_url +# PPT_attachment_id +# term +# created_on +# updated_on +# is_delete +# round + +class GlccMediumTermExamineMaterial < ActiveRecord::Base + self.table_name = "glcc_medium_term_examine_material" + belongs_to :glcc_student, :class_name => :GlccRegistrationStudent, :foreign_key => "student_reg_id" + + def check_pr_url + state = [] + # code_or_pr_url = "https://www.gitlink.org.cn/Gitlink/forgeplus/pulls/337" + url_array = code_or_pr_url.split("/") + gitlink_index = url_array.index("www.gitlink.org.cn") || url_array.index("gitlink.org.cn") + pull_index = url_array.index("pulls") + + #发送没有在gitlink上提交PR的邮件 + unless gitlink_index.present? + state << 1 + end + + # 输入的地址有问题邮件内容 + unless pull_index == 5 + state << 2 + end + + project = Project.find_by(identifier: url_array[4]) + pr = PullRequest.where(project:project, gitea_number:url_array[6]) + + unless pr.present? + state << 3 + end + state + end + + + def send_mail + gcs = glcc_student + mail = gcs.mail + return if mail.nil? || code_or_pr_url.nil? + + state = check_pr_url + return unless state.present? + title = "2023年GitLink确实开源GLCC开源夏令营#{term == 1 ? "中期考核" : "结项考核"}提醒" + content = "" + state.map{|e| + content = content + number_to_content(e) + } + puts content + UserMailer.glcc_pr_check_email(mail,title, gcs.student_name, content).deliver_now + end + + def state_to_html + gcs = glcc_student + mail = gcs.mail + return "数据异常PR连接为空" if mail.nil? || code_or_pr_url.nil? + state = check_pr_url + content = "" + state.map{|e| + content = content + number_to_content(e) + } + content + end + + def number_to_content(num) + case num + when 1 + "
PR链接为非GitLink平台链接
" + when 2 + "PR链接为GitLink平台非PR链接
" + when 3 + "PR链接中的PR不存在
" + end + end +end diff --git a/app/models/glcc_registration_student.rb b/app/models/glcc_registration_student.rb new file mode 100644 index 000000000..3ea0c3134 --- /dev/null +++ b/app/models/glcc_registration_student.rb @@ -0,0 +1,22 @@ +# == Schema Information +# +# Table name: ignores +# user_id +# student_name +# school +# profession +# location +# grade +# phone +# mail +# created_on +# is_delete +# prove_attachment_id +# cancel_count +# round +# + +class GlccRegistrationStudent < ActiveRecord::Base + self.table_name = "glcc_registration_student" + has_many :examines, :class_name => :GlccMediumTermExamineMaterial, :foreign_key => "student_reg_id" +end diff --git a/app/queries/admins/glcc_examine_material.rb b/app/queries/admins/glcc_examine_material.rb new file mode 100644 index 000000000..4e8f2bea7 --- /dev/null +++ b/app/queries/admins/glcc_examine_material.rb @@ -0,0 +1,29 @@ +class Admins::GlccExamineMaterial < ApplicationQuery + include CustomSortable + + attr_reader :params + + sort_columns :created_on, default_direction: :desc + + def initialize(params) + @params = params + end + + def call + materials = GlccMediumTermExamineMaterial.all + + # term + term = params[:term] || [1,2] + if term.present? + materials = materials.where(term: term) + end + #year + year = if params[:date] + params[:date][:year] + end + year = year || Time.now.year + date = Time.now.change(year:year) + materials = materials.where(created_on: [date.beginning_of_year..date.end_of_year]) + custom_sort(materials, params[:sort_by], params[:sort_direction]) + end +end \ No newline at end of file diff --git a/app/views/admins/glcc_pr_check/_examine_material.html.erb b/app/views/admins/glcc_pr_check/_examine_material.html.erb new file mode 100644 index 000000000..6daf14546 --- /dev/null +++ b/app/views/admins/glcc_pr_check/_examine_material.html.erb @@ -0,0 +1,34 @@ +序号 | +昵称 | +邮件地址 | +视频地址 | +PR地址 | +考核阶段 | +检测状态 | +提交时间 | +
---|---|---|---|---|---|---|---|
<%= list_index_no((params[:page] || 1).to_i, index) %> | +<%= user.glcc_student.student_name %> | +<%= user.glcc_student.mail %> | +查看视频 > | +查看PR > | +<%= user.term == 1 ? "中期考核" : "结项考核"%> | +<%= user.state_to_html.html_safe %> | +<%= user.created_on.strftime("%Y-%m-%d %H:%M")%> | +
+ 尊敬的<%=@name%>同学: +
+ ++ 您好!经过一个多月的开发,GLCC开源编程夏令营终于迎来中期考核。为了确保您能够顺利通过考核,现对您提交的PR链接进行检测,发现存在以下问题: +
+ ++ 您提交的PR链接的真实有效性对于后期的开发和奖金的发放至关重要,请您务必予以重视。请您尽快核查链接的有效性,并按照组委会要求提交中期考核材料。若确认链接无误,请忽略本邮件。 +
+ ++ 如有其他问题,请联系:glcc@ccf.org.cn +
+ ++ GLCC组委会 +
++ <%=Time.now.strftime('%Y年%m月%d日')%> +
+