pr check and send email

This commit is contained in:
呱呱呱 2023-08-08 16:27:54 +08:00
parent 5fb8c7739f
commit e3b3dacde7
16 changed files with 359 additions and 0 deletions

View File

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

View File

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

View File

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

View File

@ -0,0 +1,2 @@
module Admins::GlccPrCheckHelper
end

View File

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

View File

@ -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
"<p> PR链接为非GitLink平台链接 </p>"
when 2
"<p> PR链接为GitLink平台非PR链接 </p>"
when 3
"<p> PR链接中的PR不存在 </p>"
end
end
end

View File

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

View File

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

View File

@ -0,0 +1,34 @@
<table class="table table-hover glcc_pr_check-list-table">
<thead class="thead-light">
<tr>
<th width="4%">序号</th>
<th width="8%" class="text-left">昵称</th>
<th width="13%">邮件地址</th>
<th width="6%">视频地址</th>
<th width="6%">PR地址</th>
<th width="14%">考核阶段</th>
<th width="14%">检测状态</th>
<th width="14%">提交时间</th></th>
</tr>
</thead>
<tbody>
<% if examine_materials.present? %>
<% examine_materials.each_with_index do |user, index| %>
<tr class="user-item-<%= user.id %>">
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
<td><%= user.glcc_student.student_name %></td>
<td><%= user.glcc_student.mail %></td>
<td><a target="_blank" href="<%= user.defence_video_url %>"> 查看视频 </a></></td>
<td><a target="_blank" href="<%= user.code_or_pr_url %>"> 查看PR </a></></td>
<td><%= user.term == 1 ? "中期考核" : "结项考核"%></td>
<td><%= user.state_to_html.html_safe %></td>
<td><%= user.created_on.strftime("%Y-%m-%d %H:%M")%></td>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>
<%= render partial: 'admins/shared/paginate', locals: { objects: examine_materials } %>

View File

@ -0,0 +1,44 @@
<div class="box search-form-container glcc_pr_check-list-form">
<%= form_tag(admins_glcc_pr_check_index_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
<div class="form-group mr-2">
<label for="status">考核选项:</label>
<% status_options = [['中期考核',1], ['结项考核', 2]] %>
<%= select_tag(:term, options_for_select(status_options), class: 'form-control') %>
</div>
<div class="form-group mr-2">
<label for="status">第 </label>
<%= select_year(Date.today, {field_name:"year"}, {class:"form-control"})%>
<label for="status"> 期</label>
</div>
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
<% end %>
<button onclick="$('.send-email-list-form').show();$('.glcc_pr_check-list-form').hide();$('.glcc-examine-list-container').hide()" > 前去发送邮件</button>
</div>
<div class="box search-form-container send-email-list-form" style ="display:none">
<h5> 请重新选择参数,谨慎操作</h5>
<%= form_tag(send_mail_admins_glcc_pr_check_index_path, method: :post, class: 'form-inline search-form flex-1', remote: true) do %>
<div class="form-group mr-2">
<label for="status">  请选择考核选项:</label>
<% status_options = [['中期考核',1], ['结项考核', 2]] %>
<%= select_tag(:term, options_for_select(status_options), class: 'form-control') %>
</div>
<div class="form-group mr-2">
<label for="status">第 </label>
<%= select_year((Date.today + 1.years), {field_name:"year"}, {class:"form-control"})%>
<label for="status"> 期(注:此处为一年中的数据)</label>
</div>
<%= submit_tag('发送邮件', class: 'btn btn-primary ml-3',data: { confirm: '您是否真的需要进行邮件发送操作?请确认 考核选项 和 期数' }) %>
<% end %>
<button onclick="$('.glcc_pr_check-list-form').show();$('.send-email-list-form').hide();$('.glcc-examine-list-container').show()" > 取消发送邮件</button>
</div>
<div class="box admin-list-container glcc-examine-list-container">
<%= render partial: 'examine_material', locals: { examine_materials: @examine_materials } %>
</div>

View File

@ -0,0 +1 @@
$('.glcc-examine-list-container').html("<%= j( render partial: 'examine_material', locals: { examine_materials: @examine_materials } ) %>");

View File

@ -57,6 +57,7 @@
<%= sidebar_item(EduSetting.get("glcc_apply_informations_admin_url"), '报名列表', icon: 'user', controller: 'root') %>
<% end %>
</li>
<li><%= sidebar_item(admins_glcc_pr_check_index_path, '考核PR检测', icon: 'edit', controller: 'admins-glcc_pr_check') %></li>
<% end %>
</li>
<li>

View File

@ -0,0 +1,71 @@
<html>
<head>
<meta charset="utf-8">
<title>验证码发送</title>
<style type="text/css">
/* 验证链接页面 */
body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fieldset,legend,button,input,textarea,th,td{ margin:0; padding:0;}
body,table,input,textarea,select,button { font-family: "微软雅黑","宋体"; font-size:12px;line-height:1.5; background:#eaebec;}
div,img,tr,td,table{ border:0;}
table,tr,td{border:0;}
ol,ul,li{ list-style-type:none}
.new_content{ background:#fff; width: 100%;}
.email-page-link{ }
.email-link-top{ }
.c_white{ color:#fff;}
.email-link-con{ }
.email-link-line{ }
.email-link-footer{ padding:15px; color:#333; line-height: 1.9; }
.c_grey02{ color: #888;}
.fb{ font-weight: normal;}
.f14{ }
</style>
</head>
<body style="background:#fff;">
<div class="new_content">
<div style="width: 598px; background:#fff; margin:20px auto; font-size:14px; ">
<div style="height:50px; width: 578px; background:#46484c; padding:9px 10px 6px;border:1px solid #ddd; border-bottom:none;">
<a href="https://www.gitlink.org.cn">
<img src="https:///www.gitlink.org.cn/images/email_logo.png" width="100" style="float:left; margin-top: 8px;" >
</a>
<div style="clear:both; overflow:hidden;"></div>
</div>
<div style="width: 558px; border-left:1px solid #ddd;border-right:1px solid #ddd; background:#fff; padding:30px 20px; color:#333; line-height: 1.9;">
<p style="color:#333; font-size:16px; margin: 15px 0; font-weight: bold">
<b>尊敬的<%=@name%>同学:</b>
</p>
<p style="font-size: 15px; font-family: 微软雅黑, 宋体; color: rgb(51, 51, 51); text-decoration: none; background-color: rgba(0, 0, 0, 0); font-weight: 400; font-style: normal;">
  您好经过一个多月的开发GLCC开源编程夏令营终于迎来中期考核。为了确保您能够顺利通过考核现对您提交的PR链接进行检测发现存在以下问题
</p>
<div style="text-align: center; margin: 15px 0; font-size: 15px; font-family: 微软雅黑, 宋体; color: rgb(51, 51, 51); text-decoration: none; background-color: rgba(0, 0, 0, 0); font-weight: 400; font-style: normal;text-align: center;">
<%=@content.html_safe%>
</div>
<p style="font-size: 15px; margin: 15px 0; font-family: 微软雅黑, 宋体; color: rgb(51, 51, 51); text-decoration: none; background-color: rgba(0, 0, 0, 0); font-weight: 400; font-style: normal;">
  您提交的PR链接的真实有效性对于后期的开发和奖金的发放至关重要请您务必予以重视。请您尽快核查链接的有效性并按照组委会要求提交中期考核材料。若确认链接无误请忽略本邮件。
</p>
<p style="margin: 15px 0;font-size: 15px; font-family: 微软雅黑, 宋体; color: rgb(51, 51, 51); text-decoration: none; background-color: rgba(0, 0, 0, 0); font-weight: 400; font-style: normal;">
  如有其他问题请联系glcc@ccf.org.cn
</p>
<p style="font-size: 15px; font-family: 微软雅黑, 宋体; color: rgb(51, 51, 51); text-decoration: none; background-color: rgba(0, 0, 0, 0); font-weight: 400; font-style: normal; text-align: right;">
GLCC组委会
</p>
<p style="font-size: 15px; font-family: 微软雅黑, 宋体; color: rgb(51, 51, 51); text-decoration: none; background-color: rgba(0, 0, 0, 0); font-weight: 400; font-style: normal; text-align: right;">
<%=Time.now.strftime('%Y年%m月%d日')%>
</p>
</div>
<div style="padding:20px; color:#333; line-height: 1.9;background:#46484c;border:1px solid #ddd; border-top:none; width: 558px;">
<a href="https:///www.gitlink.org.cn/" style="font-weight: normal; color:#fff;">www.gitlink.org.cn</a>
</div>
</div>
</div>
</body>
</html>

View File

@ -789,6 +789,12 @@ Rails.application.routes.draw do
resources :glcc_news
resources :pinned_forums
end
resources :glcc_pr_check do
collection do
post :send_mail
end
end
resources :project_statistics, only: [:index] do
collection do
get :visits_static

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Admins::GlccPrCheckController, type: :controller do
end

View File

@ -0,0 +1,15 @@
require 'rails_helper'
# Specs in this file have access to a helper object that includes
# the Admins::GlccPrCheckHelper. For example:
#
# describe Admins::GlccPrCheckHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe Admins::GlccPrCheckHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end