Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
app_push
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_server
app_push
Commits
7843d3f1
Commit
7843d3f1
authored
Dec 24, 2019
by
liangyuzhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mulit db
parent
6e731a60
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
16 deletions
+67
-16
app/controllers/pushs_controller.rb
+29
-4
app/models/user_device.rb
+3
-0
app/services/push_tool_client.rb
+12
-7
config/database.yml
+23
-5
No files found.
app/controllers/pushs_controller.rb
View file @
7843d3f1
...
...
@@ -23,11 +23,18 @@ class PushsController < ApplicationController
param!
:app_type
,
String
param!
:sync_push
,
:boolean
param!
:user_id
,
String
,
required:
true
param!
:db_role
,
String
,
in:
%w(dev test staging production)
igetui_opts
=
JSON
.
parse
(
params
[
:igetui_opts
])
rescue
{}
message
=
JSON
.
parse
(
params
[
:message
])
rescue
{}
db_role
=
fetch_db_role
user_device_exist
=
false
ActiveRecord
::
Base
.
connected_to
(
role:
db_role
)
do
user_device_exist
=
UserDevice
.
where
(
user_id:
params
[
:user_id
]).
exists?
end
unless
user_device_exist
return
render
json:
{
code:
-
1
,
message:
'user_device找不到,user_id错误'
}
end
...
...
@@ -37,7 +44,7 @@ class PushsController < ApplicationController
return
render
json:
{
code:
-
1
,
message:
'token错误'
}
end
if
validate_token
(
params
[
:app_name
],
token_array
.
first
)
push_sync
(
params
[
:sync_push
],
{
user_ids:
Array
(
params
[
:user_id
]),
message:
message
,
app_type:
params
[
:app_type
],
igetui_opts:
igetui_opts
.
merge
(
pusher_type:
'push_message_to_single'
)})
push_sync
(
params
[
:sync_push
],
{
db_role:
db_role
,
user_ids:
Array
(
params
[
:user_id
]),
message:
message
,
app_type:
params
[
:app_type
],
igetui_opts:
igetui_opts
.
merge
(
pusher_type:
'push_message_to_single'
)})
render
json:
{
code:
0
,
message:
'success'
,
describe:
'异步任务正在处理'
}
...
...
@@ -55,13 +62,18 @@ class PushsController < ApplicationController
param!
:app_type
,
String
param!
:sync_push
,
String
param!
:user_ids
,
Array
,
required:
true
param!
:db_role
,
String
,
in:
%w(dev test staging production)
igetui_opts
=
JSON
.
parse
(
params
[
:igetui_opts
])
rescue
{}
message
=
JSON
.
parse
(
params
[
:message
])
rescue
{}
user_ids
=
params
[
:user_ids
]
rescue
[]
user_devices_exists
=
UserDevice
.
where
(
user_id:
user_ids
).
exists?
unless
user_devices_exists
db_role
=
fetch_db_role
user_device_exist
=
false
ActiveRecord
::
Base
.
connected_to
(
role:
db_role
)
do
user_device_exist
=
UserDevice
.
where
(
user_id:
user_ids
).
exists?
end
unless
user_device_exist
return
render
json:
{
code:
-
1
,
message:
'user_device找不到,user_ids错误'
}
end
...
...
@@ -71,7 +83,7 @@ class PushsController < ApplicationController
end
if
validate_token
(
params
[
:app_name
],
token_array
.
first
)
push_sync
(
params
[
:sync_push
],
{
user_ids:
user_ids
,
message:
message
,
app_type:
params
[
:app_type
],
igetui_opts:
igetui_opts
.
merge
(
pusher_type:
'push_message_to_list'
)})
push_sync
(
params
[
:sync_push
],
{
db_role:
db_role
,
user_ids:
user_ids
,
message:
message
,
app_type:
params
[
:app_type
],
igetui_opts:
igetui_opts
.
merge
(
pusher_type:
'push_message_to_list'
)})
render
json:
{
code:
0
,
message:
'success'
,
describe:
'异步任务正在处理'
}
else
...
...
@@ -97,4 +109,17 @@ class PushsController < ApplicationController
::
PushWorker
.
perform_async
(
opts
)
end
end
def
fetch_db_role
return
params
[
:db_role
].
to_sym
if
params
[
:db_role
].
present?
case
request
.
host
when
'lxcrm-dev.weiwenjia.com'
,
'ik-dev.ikcrm.com'
:dev
when
'lxcrm-test.weiwenjia.com'
,
'ik-test.weiwenjia.com'
:test
else
:production
end
end
end
app/models/user_device.rb
View file @
7843d3f1
class
UserDevice
<
ApplicationRecord
self
.
table_name
=
'user_devices'
connects_to
database:
{
dev: :dev_development
,
test: :test_development
,
staging: :staging_development
,
production: :production
}
# 当前app端传递的platform的值:
# android: igetui, xiaomi, huawei
...
...
app/services/push_tool_client.rb
View file @
7843d3f1
...
...
@@ -9,11 +9,16 @@ class PushToolClient
def
do_push
Settings
.
platform
=
@opts
[
:app_type
]
||
Settings
::
DEFAULT
@push_device_collections
||=
UserDevice
.
where
(
user_id:
@user_ids
).
group_by
(
&
:platform
)
@igetui_push_device_collections
||=
@push_device_collections
[
'igetui'
].
group_by
(
&
:device_platform
)
if
@push_device_collections
[
'igetui'
].
is_a?
Array
if
@igetui_push_device_collections
.
is_a?
Hash
igetui_android_client_ids
=
@igetui_push_device_collections
[
'android'
].
map
(
&
:client_id
)
if
@igetui_push_device_collections
[
'android'
].
is_a?
Array
igetui_ios_client_ids
=
@igetui_push_device_collections
[
'ios'
].
map
(
&
:client_id
)
if
@igetui_push_device_collections
[
'ios'
].
is_a?
Array
push_device_collections
||=
{}
ActiveRecord
::
Base
.
connected_to
(
role:
@opt
[
:db_role
].
to_sym
)
do
push_device_collections
=
UserDevice
.
where
(
user_id:
@user_ids
).
group_by
(
&
:platform
)
end
igetui_push_device_collections
=
push_device_collections
[
'igetui'
].
group_by
(
&
:device_platform
)
if
push_device_collections
[
'igetui'
].
is_a?
Array
if
igetui_push_device_collections
.
is_a?
Hash
igetui_android_client_ids
=
igetui_push_device_collections
[
'android'
].
map
(
&
:client_id
)
if
igetui_push_device_collections
[
'android'
].
is_a?
Array
igetui_ios_client_ids
=
igetui_push_device_collections
[
'ios'
].
map
(
&
:client_id
)
if
igetui_push_device_collections
[
'ios'
].
is_a?
Array
end
Igetui
::
Pusher
.
new
(
igetui_android_client_ids
,
@opts
.
merge
(
device_platform:
'android'
)).
perform
if
igetui_android_client_ids
.
present?
...
...
@@ -23,8 +28,8 @@ class PushToolClient
# Push::IgetuiIos.push(@push_collections[:igetui_ios], @opts) if @push_collections[:apns].present?
# Push::IgetuiAndroid.push(@push_collections[:igetui_android], @opts) if @push_collections[:apns].present?
xiaomi_client_ids
=
@push_device_collections
[
'xiaomi'
].
map
(
&
:client_id
)
if
@
push_device_collections
[
'xiaomi'
].
is_a?
Array
huawei_client_ids
=
@push_device_collections
[
'huawei'
].
map
(
&
:client_id
)
if
@
push_device_collections
[
'huawei'
].
is_a?
Array
xiaomi_client_ids
=
push_device_collections
[
'xiaomi'
].
map
(
&
:client_id
)
if
push_device_collections
[
'xiaomi'
].
is_a?
Array
huawei_client_ids
=
push_device_collections
[
'huawei'
].
map
(
&
:client_id
)
if
push_device_collections
[
'huawei'
].
is_a?
Array
Xiaomi
::
Pusher
.
new
(
xiaomi_client_ids
,
@opts
[
:message
]).
perform
if
xiaomi_client_ids
.
present?
Huawei
::
Pusher
.
new
(
huawei_client_ids
,
@opts
[
:message
]).
perform
if
huawei_client_ids
.
present?
...
...
config/database.yml
View file @
7843d3f1
...
...
@@ -10,17 +10,35 @@ default: &default
pool
:
10
host
:
rm-m5eu4m6a4rugr22fcno.mysql.rds.aliyuncs.com
development
:
<<
:
*default
#database: vcooline_ikcrm_testing
#host: 10.140.235.122
#username: vcooline_ikcrm_testing
#password: ikcrm_123
database
:
crm_staging
username
:
crm_staging
password
:
rCxWfEbdJrEp3Mff
dev_development
:
<<
:
*default
host
:
rm-m5ef10gzq1n5e7b9a.mysql.rds.aliyuncs.com
database
:
crm_dev
username
:
crm_dev
password
:
4LwSJlWiM9Krlb8g
test_development
:
<<
:
*default
host
:
rdscbq34656z0ix59br0.mysql.rds.aliyuncs.com
database
:
crm_test
username
:
crm_test
password
:
UpS7AbiESvhkm5TY
staging_development
:
<<
:
*default
database
:
crm_staging
username
:
crm_staging
password
:
rCxWfEbdJrEp3Mff
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment