Commit 8a24404d by Kevin. Mei

Merge branch 'fix/adapt-lixiao-login-push-notification' into 'master'

Fix/adapt lixiao login push notification

See merge request !11
parents 925831fd e0b404da
...@@ -21,13 +21,14 @@ class PushsController < ApplicationController ...@@ -21,13 +21,14 @@ class PushsController < ApplicationController
# param! :igetui_opts, String # param! :igetui_opts, String
param! :sync_push, :boolean param! :sync_push, :boolean
param! :user_ids, Array, required: true param! :user_ids, Array, required: true
param! :user_platform, String, required: true, in: UserDevice::user_platforms.keys
message = JSON.parse(params[:message]) rescue {} message = JSON.parse(params[:message]) rescue {}
igetui_opts = message igetui_opts = message
user_ids = params[:user_ids] rescue [] user_ids = params[:user_ids] rescue []
user_devices = UserDevice.where(user_id: user_ids) user_devices = UserDevice.where(user_id: user_ids,user_platform: params[:user_platform])
client_id = message.dig('transmission_content', 'extras', 'extra', 'client_id') client_id = message.dig('transmission_content', 'extras', 'extra', 'client_id')
user_devices = user_devices.where.not(client_id: client_id) if client_id user_devices = user_devices.where.not(client_id: client_id) if client_id
user_device_exist = user_devices.exists? user_device_exist = user_devices.exists?
...@@ -43,7 +44,7 @@ class PushsController < ApplicationController ...@@ -43,7 +44,7 @@ class PushsController < ApplicationController
params[:sync_push] ||= false params[:sync_push] ||= false
# if validate_token(params[:app_name], token_array.first) # if validate_token(params[:app_name], token_array.first)
push_sync(params[:sync_push], {user_ids: user_ids, message: message, igetui_opts: igetui_opts.merge(pusher_type: 'push_message_to_list')}) push_sync(params[:sync_push], {user_ids: user_ids, message: message, igetui_opts: igetui_opts.merge(pusher_type: 'push_message_to_list'), user_platform: params[:user_platform]})
render json: { code: 0, message: 'success', describe: '异步任务正在处理'} render json: { code: 0, message: 'success', describe: '异步任务正在处理'}
# else # else
......
...@@ -4,6 +4,7 @@ class UserDevicesController < ApplicationController ...@@ -4,6 +4,7 @@ class UserDevicesController < ApplicationController
param! :app_type, String, required: true, in: UserDevice::app_types.keys param! :app_type, String, required: true, in: UserDevice::app_types.keys
param! :client_id, String, required: true param! :client_id, String, required: true
param! :user_id, Integer, required: true param! :user_id, Integer, required: true
param! :user_platform, String, required: true, in: UserDevice::user_platforms.keys
_user_device_params = permit_user_device_params _user_device_params = permit_user_device_params
...@@ -11,8 +12,8 @@ class UserDevicesController < ApplicationController ...@@ -11,8 +12,8 @@ class UserDevicesController < ApplicationController
user_id = _user_device_params[:user_id] user_id = _user_device_params[:user_id]
UserDevice.where(user_id: user_id).delete_all UserDevice.where(user_id: user_id,user_platform: _user_device_params[:user_platform]).delete_all
UserDevice.where(client_id: _user_device_params[:client_id]).delete_all UserDevice.where(client_id: _user_device_params[:client_id],user_platform: _user_device_params[:user_platform]).delete_all
user_device = UserDevice.create!(_user_device_params) user_device = UserDevice.create!(_user_device_params)
...@@ -23,13 +24,14 @@ class UserDevicesController < ApplicationController ...@@ -23,13 +24,14 @@ class UserDevicesController < ApplicationController
param! :old_user_id, Integer, required: true param! :old_user_id, Integer, required: true
param! :user_id, Integer, required: true param! :user_id, Integer, required: true
param! :organization_id, Integer, required: true param! :organization_id, Integer, required: true
param! :user_platform, String, required: true, in: UserDevice::user_platforms.keys
user_id = params[:user_id] user_id = params[:user_id]
old_user_id = params[:old_user_id] old_user_id = params[:old_user_id]
user_device = UserDevice.where(user_id: old_user_id).last user_device = UserDevice.where(user_id: old_user_id,user_platform: params[:user_platform]).last
if user_device.present? if user_device.present?
UserDevice.where(user_id: user_id).delete_all UserDevice.where(user_id: user_id,user_platform: params[:user_platform]).delete_all
UserDevice.where(user_id: old_user_id).delete_all UserDevice.where(user_id: old_user_id,user_platform: params[:user_platform]).delete_all
new_user_device = user_device.dup new_user_device = user_device.dup
...@@ -46,9 +48,10 @@ class UserDevicesController < ApplicationController ...@@ -46,9 +48,10 @@ class UserDevicesController < ApplicationController
def destroy_by_user_id def destroy_by_user_id
param! :user_id, Integer, required: true param! :user_id, Integer, required: true
param! :user_platform, String, required: true, in: UserDevice::user_platforms.keys
user_id = params[:user_id] user_id = params[:user_id]
UserDevice.where(user_id: user_id).delete_all UserDevice.where(user_id: user_id,user_platform: params[:user_platform]).delete_all
render json: { code: 0, message: "success" } render json: { code: 0, message: "success" }
end end
...@@ -57,7 +60,7 @@ class UserDevicesController < ApplicationController ...@@ -57,7 +60,7 @@ class UserDevicesController < ApplicationController
def permit_user_device_params def permit_user_device_params
params.permit(:platform, :device_token, :client_id, :device_model, :device_platform, params.permit(:platform, :device_token, :client_id, :device_model, :device_platform,
:device_id, :device_version, :device_phone, :app_type, :user_id, :organization_id, :ip) :device_id, :device_version, :device_phone, :app_type, :user_id, :organization_id, :ip, :user_platform)
end end
end end
...@@ -9,4 +9,7 @@ class UserDevice < ApplicationRecord ...@@ -9,4 +9,7 @@ class UserDevice < ApplicationRecord
# 用于区分当前的应用,为了推送准备, 因为推送需要根据不同的应用使用不同的 id,secret等。 # 用于区分当前的应用,为了推送准备, 因为推送需要根据不同的应用使用不同的 id,secret等。
enum app_type: %i[ik_duli lx_duli lx_yun aike_yun] enum app_type: %i[ik_duli lx_duli lx_yun aike_yun]
# 用户区分用户所在平台,0-ikcrm:默认值,独立版用户,1-wxwork: 企微版用户,2-dingtalk: 钉钉版用户
enum user_platform: %i[ikcrm wxwork dingtalk]
end end
\ No newline at end of file
...@@ -62,7 +62,9 @@ class PushToolClient ...@@ -62,7 +62,9 @@ class PushToolClient
huawei_client_ids = {"#{@opts[:app_type]}" => @opts[:device_ids_opts][:huawei]} if push_devices.include? "huawei" huawei_client_ids = {"#{@opts[:app_type]}" => @opts[:device_ids_opts][:huawei]} if push_devices.include? "huawei"
xiaomi_client_ids = {"#{@opts[:app_type]}" => @opts[:device_ids_opts][:xiaomi]} if push_devices.include? "xiaomi" xiaomi_client_ids = {"#{@opts[:app_type]}" => @opts[:device_ids_opts][:xiaomi]} if push_devices.include? "xiaomi"
else else
push_device_collections = UserDevice.where(user_id: @user_ids).group_by(&:platform) user_devices = UserDevice.where(user_id: @user_ids)
user_devices = user_devices.where(user_platform: @opts[:user_platform]) if @opts[:user_platform].present?
push_device_collections = user_devices.group_by(&:platform)
igetui_push_device_collections = push_device_collections['igetui'].group_by(&:device_platform) if push_device_collections['igetui'].is_a? Array 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 if igetui_push_device_collections.is_a? Hash
......
class AddUserPlatformToUserDevices < ActiveRecord::Migration
def change
add_column :user_devices, :user_platform, :integer, default: 0
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment