[ADD]phenglei user list and cron job

This commit is contained in:
vilet.yy 2021-03-10 14:02:41 +08:00
parent 0aa75e077e
commit 3e7ae82258
15 changed files with 157 additions and 6 deletions

View File

@ -0,0 +1,36 @@
class Admins::PhengleiUsersController < Admins::BaseController
before_action :phenglei_project, only: [:index]
def index
if params[:keyword].present?
@phenglei_users = PhengleiUser.ransack(phone_cont: params[:keyword]).result
else
@phenglei_users = PhengleiUser
end
@phenglei_users = @phenglei_users.page(page).per(per_page)
end
def new
@phenglei_user = PhengleiUser.new
end
def create
@phenglei_user = PhengleiUser.new(phenglei_user_params)
if @phenglei_user.save
redirect_to admins_phenglei_users_path
flash[:success] = "创建成功"
else
redirect_to admins_phenglei_users_path
flash[:error] = "创建失败"
end
end
private
def phenglei_project
@phenglei_project = Project.find_by_id(EduSetting.get("sync_phenglei_user_project"))
end
def phenglei_user_params
params.require(:phenglei_user).permit(:phone)
end
end

View File

@ -27,10 +27,10 @@ class Admins::ProjectsController < Admins::BaseController
def sync_phenglei_user def sync_phenglei_user
if @project.is_secret if @project.is_secret
SyncPhengleiUserJob.perform_later(@project.id) SyncPhengleiUserJob.perform_later(@project.id)
redirect_to admins_projects_path redirect_to admins_phenglei_users_path
flash[:success] = "已开启后台同步任务" flash[:success] = "已开启后台同步任务"
else else
redirect_to admins_projects_path redirect_to admins_phenglei_users_path
flash[:danger] = "非风雷协议项目" flash[:danger] = "非风雷协议项目"
end end
end end

View File

@ -1,7 +1,8 @@
class SyncPhengleiUserJob < ApplicationJob class SyncPhengleiUserJob < ApplicationJob
queue_as :default queue_as :default
def perform(project_id) def perform(project_id=nil)
project_id ||= EduSetting.get("sync_phenglei_user_project")
project = Project.find_by_id(project_id) project = Project.find_by_id(project_id)
return if project.nil? return if project.nil?
member_count, success_count, error_count, not_exsit_count = 0, 0, 0, 0 member_count, success_count, error_count, not_exsit_count = 0, 0, 0, 0

View File

@ -0,0 +1,18 @@
# == Schema Information
#
# Table name: phenglei_users
#
# id :integer not null, primary key
# phone :string(255)
# created_at :datetime not null
# updated_at :datetime not null
#
class PhengleiUser < ApplicationRecord
validates :phone, uniqueness: true
def register
User.find_by(phone: self.phone)
end
end

View File

@ -0,0 +1,19 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('风雷意向用户管理', admins_phenglei_users_path) %>
<% end %>
<div class="box search-form-container user-list-form">
<%= form_tag(admins_phenglei_users_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: '手机号检索') %>
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
<%= link_to "同步", sync_phenglei_user_admins_project_path(@phenglei_project.id), method: :get, data: {confirm: "确认同步吗?"}, class: "btn btn-primary pull-right ml-3", "data-disabled-with":"...同步" %>
<% end %>
<%= link_to "新增", new_admins_phenglei_user_path, remote: true, class: "btn btn-primary ml-3", "data-disabled-with":"...新增" %>
</div>
<div class="box admin-list-container phenglei-users-list-container">
<%= render partial: 'admins/phenglei_users/shared/list', locals: { phenglei_users: @phenglei_users } %>
</div>
<div id="phenglei-users-modals">
</div>

View File

@ -0,0 +1 @@
$('.phenglei-users-list-container').html("<%= j( render partial: 'admins/phenglei_users/shared/list', locals: { phenglei_users: @phenglei_users } ) %>");

View File

@ -0,0 +1,2 @@
$("#phenglei-users-modals").html("<%= j render(partial: 'admins/phenglei_users/shared/create_form_modal') %>")
$(".phenglei-user-create-modal").modal('show');

View File

@ -0,0 +1,21 @@
<div class="modal fade phenglei-user-create-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">新增</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<%= form_for @phenglei_user, url: {controller: "phenglei_users", action: 'create'} do |p| %>
<div class="modal-body">
<%= p.text_field :phone, class: "form-control input-lg",placeholder: "手机号",required: true, maxlength: 64%>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<%= p.submit "确认", class: "btn btn-primary submit-btn" %>
</div>
<% end %>
</div>
</div>
</div>

View File

@ -0,0 +1,30 @@
<table class="table table-hover users-list-table">
<thead class="thead-light">
<tr>
<th width="4%">序号</th>
<th width="10%">手机号码</th>
<th width="12%">状态</th>
</tr>
</thead>
<tbody>
<% if phenglei_users.present? %>
<% phenglei_users.each_with_index do |user, index| %>
<tr class="user-item-<%= user.id %>">
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
<td><%= overflow_hidden_span display_text(user.phone), width: 100 %></td>
<td>
<% if user.register.present? %>
<%= @phenglei_project.member?(user.register.id) ? "已同步" : "未同步" %>
<% else %>
未注册
<% end %>
</td>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>
<%= render partial: 'admins/shared/paginate', locals: { objects: phenglei_users } %>

View File

@ -39,9 +39,6 @@
</td> </td>
<td><%= project.created_on&.strftime('%Y-%m-%d %H:%M') %></td> <td><%= project.created_on&.strftime('%Y-%m-%d %H:%M') %></td>
<td class="action-container"> <td class="action-container">
<% if project.is_secret %>
<%= link_to "同步", sync_phenglei_user_admins_project_path(project.id), method: :get, data:{confirm: "确认同步吗?"}, class: "sync-phenglei-user-project-action" %>
<% end %>
<%= link_to "删除", admins_project_path(project.id), method: :delete, data:{confirm: "确认删除的吗?"}, class: "delete-project-action" %> <%= link_to "删除", admins_project_path(project.id), method: :delete, data:{confirm: "确认删除的吗?"}, class: "delete-project-action" %>
</td> </td>
</tr> </tr>

View File

@ -17,6 +17,7 @@
<li> <li>
<%= sidebar_item_group('#user-submenu', '用户', icon: 'user') do %> <%= sidebar_item_group('#user-submenu', '用户', icon: 'user') do %>
<li><%= sidebar_item(admins_users_path, '用户列表', icon: 'user', controller: 'admins-users') %></li> <li><%= sidebar_item(admins_users_path, '用户列表', icon: 'user', controller: 'admins-users') %></li>
<li><%= sidebar_item(admins_phenglei_users_path, '风雷意向用户列表', icon: 'user', controller: 'admins-phenglei_users') %></li>
<% end %> <% end %>
</li> </li>
<li> <li>

View File

@ -647,6 +647,7 @@ Rails.application.routes.draw do
post :reset_login_times post :reset_login_times
end end
end end
resources :phenglei_users, only: [:index, :new, :create]
resource :import_disciplines, only: [:create] resource :import_disciplines, only: [:create]
resource :import_users, only: [:create] resource :import_users, only: [:create]
resource :import_course_members, only: [:create] resource :import_course_members, only: [:create]

View File

@ -2,3 +2,7 @@ sync_gitea_repo_update_time:
cron: "0 0 * * *" cron: "0 0 * * *"
class: "SyncRepoUpdateTimeJob" class: "SyncRepoUpdateTimeJob"
queue: default queue: default
sync_phenglei_user:
cron: "0 23 * * *"
class: "SyncPhengleiUserJob"
queue: default

View File

@ -0,0 +1,15 @@
class CreatePhengleiUsers < ActiveRecord::Migration[5.2]
def change
create_table :phenglei_users do |t|
t.string :phone
t.timestamps
end
doc = SimpleXlsxReader.open("#{Rails.root}/public/phenglei_user.xlsx")
data = doc.sheets.first.rows
data.each_with_index do |i, index|
next if index == 0 || i[1].nil?
PhengleiUser.find_or_create_by(phone: i[1])
end
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe PhengleiUser, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end