Merge branch 'dev_military' of https://git.trustie.net/jasder/forgeplus into dev_military

This commit is contained in:
jasder 2021-06-04 11:35:18 +08:00
commit abc21413ac
23 changed files with 224 additions and 11 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

@ -1,4 +1,5 @@
class Admins::ProjectsController < Admins::BaseController class Admins::ProjectsController < Admins::BaseController
before_action :load_project, only: [:sync_phenglei_user]
def index def index
sort_by = params[:sort_by] ||= 'created_on' sort_by = params[:sort_by] ||= 'created_on'
@ -6,7 +7,7 @@ class Admins::ProjectsController < Admins::BaseController
search = params[:search].to_s.strip search = params[:search].to_s.strip
projects = Project.where("name like ?", "%#{search}%").order("#{sort_by} #{sort_direction}") projects = Project.where("name like ?", "%#{search}%").order("#{sort_by} #{sort_direction}")
@projects = paginate projects.includes(:owner, :members, :issues, :versions, :attachments, :project_score) @projects = paginate projects.includes(:owner, :members, :issues, :versions, :attachments, :project_score, :license)
end end
def destroy def destroy
@ -22,4 +23,20 @@ class Admins::ProjectsController < Admins::BaseController
redirect_to admins_projects_path redirect_to admins_projects_path
flash[:danger] = "删除失败" flash[:danger] = "删除失败"
end end
def sync_phenglei_user
if @project.is_secret
SyncPhengleiUserJob.perform_later(@project.id)
redirect_to admins_phenglei_users_path
flash[:success] = "已开启后台同步任务"
else
redirect_to admins_phenglei_users_path
flash[:danger] = "非风雷协议项目"
end
end
private
def load_project
@project = Project.find_by!(id: params[:id])
end
end end

View File

@ -5,8 +5,9 @@ class ApplySignaturesController < ApplicationController
before_action :find_apply_signature, only: [:update] before_action :find_apply_signature, only: [:update]
def index def index
search = params[:search].to_s.downcase
@apply_signatures = @project.apply_signatures.with_status(status).includes(user: :user_extension) @apply_signatures = @project.apply_signatures.with_status(status).includes(user: :user_extension)
@apply_signatures = @apply_signatures.joins(:user).where("LOWER(concat(users.lastname, users.firstname, users.login, users.mail, users.nickname)) LIKE ?", "%#{search.split(" ").join('|')}%") @apply_signatures = @apply_signatures.joins(:user).where("LOWER(CONCAT_WS(users.lastname, users.firstname, users.login, users.mail, users.nickname)) LIKE ?", "%#{search.split(" ").join('|')}%") if search.present?
@apply_signatures = kaminari_paginate(@apply_signatures) @apply_signatures = kaminari_paginate(@apply_signatures)
end end
@ -64,10 +65,6 @@ class ApplySignaturesController < ApplicationController
params.permit(:status) params.permit(:status)
end end
def search
params.fetch(:search, "").to_s.downcase
end
def status def status
params.fetch(:status, "all") params.fetch(:status, "all")
end end

View File

@ -18,7 +18,7 @@ class MembersController < ApplicationController
scope = @project.members.includes(:roles, user: :user_extension) scope = @project.members.includes(:roles, user: :user_extension)
search = params[:search].to_s.downcase search = params[:search].to_s.downcase
role = params[:role].to_s role = params[:role].to_s
scope = scope.joins(:user).where("LOWER(concat(users.lastname, users.firstname, users.login, users.mail, users.nickname)) LIKE ?", "%#{search.split(" ").join('|')}%") if search.present? scope = scope.joins(:user).where("LOWER(CONCAT_WS(users.lastname, users.firstname, users.login, users.mail, users.nickname)) LIKE ?", "%#{search.split(" ").join('|')}%") if search.present?
scope = scope.joins(:roles).where("roles.name LIKE ?", "%#{role}%") if role.present? scope = scope.joins(:roles).where("roles.name LIKE ?", "%#{role}%") if role.present?
@total_count = scope.size @total_count = scope.size

View File

@ -52,7 +52,7 @@ module ProjectsHelper
type: project.numerical_for_project_type, type: project.numerical_for_project_type,
author: render_owner(project), author: render_owner(project),
is_secret: project.is_secret, is_secret: project.is_secret,
is_member: !project.members.where(user_id: user.id).blank?, is_member: project.member?(user.id),
user_apply_signatures: project.apply_signatures.with_user_id(user.id).collect{|s| {id: s.id, status: s.status}} user_apply_signatures: project.apply_signatures.with_user_id(user.id).collect{|s| {id: s.id, status: s.status}}
}).compact }).compact

View File

@ -0,0 +1,36 @@
class SyncPhengleiUserJob < ApplicationJob
queue_as :default
def perform(project_id=nil)
project_id ||= EduSetting.get("sync_phenglei_user_project")
project = Project.find_by_id(project_id)
return if project.nil?
member_count, success_count, error_count, not_exsit_count = 0, 0, 0, 0
Rails.logger.info("======begin to sync phenglei user to project#{project.owner.login + "/" + project.identifier}")
PhengleiUser.find_each do |i|
puts "======开始处理#{i.phone}"
user = User.find_by(phone: i.phone)
if user.present?
if project.member?(user.id)
puts "======#{i.phone}用户已经是外围贡献者了"
member_count += 1
else
interactor = Projects::AddMemberInteractor.call(project.owner, project, user, "read", true)
if interactor.error.nil?
puts "========用户#{i.phone}成功添加为项目的外围贡献者======="
success_count += 1
else
puts "========用户#{i.phone}添加失败"
error_count += 1
end
end
else
puts "=====#{i.phone}用户不存在"
not_exsit_count += 1
next
end
end
Rails.logger.info("======已存在外围贡献者数量#{member_count}, 成功添加用户数量#{success_count}, 添加失败用户数量#{error_count}, 找不到用户数量#{not_exsit_count}")
Rails.logger.info("======end to sync phenglei user to project#{project.owner.login + "/" + project.identifier}")
end
end

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

@ -15,7 +15,7 @@ class Projects::ListQuery < ApplicationQuery
scope = q scope = q
.with_project_type(params[:project_type]) .with_project_type(params[:project_type])
.with_project_category(params[:category_id]) .with_project_category(params[:category_id])
.with_project_language(params[:language_id]) .with_project_language(params[:language_id]).order(order_index: :desc)
sort = params[:sort_by] || "updated_on" sort = params[:sort_by] || "updated_on"
sort_direction = params[:sort_direction] || "desc" sort_direction = params[:sort_direction] || "desc"

View File

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

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

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

@ -48,7 +48,7 @@ json.projects @projects do |project|
json.name project.project_language.name json.name project.project_language.name
end end
end end
json.is_member !project.members.where(user_id: current_user.id).blank? json.is_member project.member?(current_user.id)
user_apply_signatures = project.apply_signatures.with_user_id(current_user.id) user_apply_signatures = project.apply_signatures.with_user_id(current_user.id)
json.user_apply_signatures user_apply_signatures do |signature| json.user_apply_signatures user_apply_signatures do |signature|
json.id signature.id json.id signature.id

View File

@ -650,6 +650,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]
@ -827,7 +828,11 @@ Rails.application.routes.draw do
resources :courses, only: [:index, :destroy, :update] resources :courses, only: [:index, :destroy, :update]
resources :projects, only: [:index, :destroy] resources :projects, only: [:index, :destroy] do
member do
get :sync_phenglei_user
end
end
resources :disciplines, only: [:index, :create, :edit, :update, :destroy] do resources :disciplines, only: [:index, :create, :edit, :update, :destroy] do
post :adjust_position, on: :member post :adjust_position, on: :member

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 @@
class AddOrderIndexToProject < ActiveRecord::Migration[5.2]
def change
add_column :projects, :order_index, :integer, default: 0
end
end

BIN
public/phenglei_user.xlsx Normal file

Binary file not shown.

BIN
public/police.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

View File

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