Commit 51714387 by 胡强

修复独立版和企微版用户id重复问题

parent 925831fd
......@@ -21,13 +21,14 @@ class PushsController < ApplicationController
# param! :igetui_opts, String
param! :sync_push, :boolean
param! :user_ids, Array, required: true
param! :user_platform, String, required: true, in: UserDevice::user_platforms.keys
message = JSON.parse(params[:message]) rescue {}
igetui_opts = message
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')
user_devices = user_devices.where.not(client_id: client_id) if client_id
user_device_exist = user_devices.exists?
......@@ -43,7 +44,7 @@ class PushsController < ApplicationController
params[:sync_push] ||= false
# 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: '异步任务正在处理'}
# else
......
......@@ -4,6 +4,7 @@ class UserDevicesController < ApplicationController
param! :app_type, String, required: true, in: UserDevice::app_types.keys
param! :client_id, String, 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
......@@ -11,8 +12,8 @@ class UserDevicesController < ApplicationController
user_id = _user_device_params[:user_id]
UserDevice.where(user_id: user_id).delete_all
UserDevice.where(client_id: _user_device_params[:client_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],user_platform: _user_device_params[:user_platform]).delete_all
user_device = UserDevice.create!(_user_device_params)
......@@ -23,13 +24,14 @@ class UserDevicesController < ApplicationController
param! :old_user_id, Integer, required: true
param! :user_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]
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?
UserDevice.where(user_id: user_id).delete_all
UserDevice.where(user_id: old_user_id).delete_all
UserDevice.where(user_id: user_id,user_platform: params[:user_platform]).delete_all
UserDevice.where(user_id: old_user_id,user_platform: params[:user_platform]).delete_all
new_user_device = user_device.dup
......@@ -46,9 +48,10 @@ class UserDevicesController < ApplicationController
def destroy_by_user_id
param! :user_id, Integer, required: true
param! :user_platform, String, required: true, in: UserDevice::user_platforms.keys
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" }
end
......@@ -57,7 +60,7 @@ class UserDevicesController < ApplicationController
def permit_user_device_params
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
......@@ -9,4 +9,7 @@ class UserDevice < ApplicationRecord
# 用于区分当前的应用,为了推送准备, 因为推送需要根据不同的应用使用不同的 id,secret等。
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
\ No newline at end of file
......@@ -62,7 +62,9 @@ class PushToolClient
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"
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
if igetui_push_device_collections.is_a? Hash
......
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