From c92c99c8da92fd9d7dc4af9534419d0679fcc207 Mon Sep 17 00:00:00 2001
From: zlyx <1242874891@qq.com>
Date: 星期三, 02 八月 2023 14:21:12 +0800
Subject: [PATCH] update 优化 SysLoginService#socialRegister 判断是否已经绑定用户 ; fix 修正 SysSocialServiceImpl#selectByAuthId 重复数据报错问题 ;

---
 script/sql/postgres/postgres_ry_vue_5.X.sql |  142 +++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 136 insertions(+), 6 deletions(-)

diff --git a/script/sql/postgres/postgres_ry_vue_5.X.sql b/script/sql/postgres/postgres_ry_vue_5.X.sql
index b510042..d2f39f0 100644
--- a/script/sql/postgres/postgres_ry_vue_5.X.sql
+++ b/script/sql/postgres/postgres_ry_vue_5.X.sql
@@ -1,4 +1,72 @@
 -- ----------------------------
+-- 绗笁鏂瑰钩鍙版巿鏉冭〃
+-- ----------------------------
+create table sys_social
+(
+    id                 int8             not null,
+    user_id            int8             not null,
+    tenant_id          varchar(20)      default null::varchar,
+    auth_id            varchar(255)     not null,
+    source             varchar(255)     not null,
+    open_id            varchar(255)     default null::varchar,
+    user_name          varchar(30)      not null,
+    nick_name          varchar(30)      default ''::varchar,
+    email              varchar(255)     default ''::varchar,
+    avatar             varchar(500)     default ''::varchar,
+    access_token       varchar(255)     not null,
+    expire_in          int8             default null,
+    refresh_token      varchar(255)     default null::varchar,
+    access_code        varchar(255)     default null::varchar,
+    union_id           varchar(255)     default null::varchar,
+    scope              varchar(255)     default null::varchar,
+    token_type         varchar(255)     default null::varchar,
+    id_token           varchar(255)     default null::varchar,
+    mac_algorithm      varchar(255)     default null::varchar,
+    mac_key            varchar(255)     default null::varchar,
+    code               varchar(255)     default null::varchar,
+    oauth_token        varchar(255)     default null::varchar,
+    oauth_token_secret varchar(255)     default null::varchar,
+    create_dept        int8,
+    create_by          int8,
+    create_time        timestamp,
+    update_by          int8,
+    update_time        timestamp,
+    del_flag           char             default '0'::bpchar,
+    constraint "pk_sys_social" primary key (id)
+);
+
+comment on table   sys_social                   is '绀句細鍖栧叧绯昏〃';
+comment on column  sys_social.id                is '涓婚敭';
+comment on column  sys_social.user_id           is '鐢ㄦ埛ID';
+comment on column  sys_social.tenant_id         is '绉熸埛id';
+comment on column  sys_social.auth_id           is '骞冲彴+骞冲彴鍞竴id';
+comment on column  sys_social.source            is '鐢ㄦ埛鏉ユ簮';
+comment on column  sys_social.open_id           is '骞冲彴缂栧彿鍞竴id';
+comment on column  sys_social.user_name         is '鐧诲綍璐﹀彿';
+comment on column  sys_social.nick_name         is '鐢ㄦ埛鏄电О';
+comment on column  sys_social.email             is '鐢ㄦ埛閭';
+comment on column  sys_social.avatar            is '澶村儚鍦板潃';
+comment on column  sys_social.access_token      is '鐢ㄦ埛鐨勬巿鏉冧护鐗�';
+comment on column  sys_social.expire_in         is '鐢ㄦ埛鐨勬巿鏉冧护鐗岀殑鏈夋晥鏈燂紝閮ㄥ垎骞冲彴鍙兘娌℃湁';
+comment on column  sys_social.refresh_token     is '鍒锋柊浠ょ墝锛岄儴鍒嗗钩鍙板彲鑳芥病鏈�';
+comment on column  sys_social.access_code       is '骞冲彴鐨勬巿鏉冧俊鎭紝閮ㄥ垎骞冲彴鍙兘娌℃湁';
+comment on column  sys_social.union_id          is '鐢ㄦ埛鐨� unionid';
+comment on column  sys_social.scope             is '鎺堜簣鐨勬潈闄愶紝閮ㄥ垎骞冲彴鍙兘娌℃湁';
+comment on column  sys_social.token_type        is '涓埆骞冲彴鐨勬巿鏉冧俊鎭紝閮ㄥ垎骞冲彴鍙兘娌℃湁';
+comment on column  sys_social.id_token          is 'id token锛岄儴鍒嗗钩鍙板彲鑳芥病鏈�';
+comment on column  sys_social.mac_algorithm     is '灏忕背骞冲彴鐢ㄦ埛鐨勯檮甯﹀睘鎬э紝閮ㄥ垎骞冲彴鍙兘娌℃湁';
+comment on column  sys_social.mac_key           is '灏忕背骞冲彴鐢ㄦ埛鐨勯檮甯﹀睘鎬э紝閮ㄥ垎骞冲彴鍙兘娌℃湁';
+comment on column  sys_social.code              is '鐢ㄦ埛鐨勬巿鏉僣ode锛岄儴鍒嗗钩鍙板彲鑳芥病鏈�';
+comment on column  sys_social.oauth_token       is 'Twitter骞冲彴鐢ㄦ埛鐨勯檮甯﹀睘鎬э紝閮ㄥ垎骞冲彴鍙兘娌℃湁';
+comment on column  sys_social.oauth_token_secret is 'Twitter骞冲彴鐢ㄦ埛鐨勯檮甯﹀睘鎬э紝閮ㄥ垎骞冲彴鍙兘娌℃湁';
+comment on column  sys_social.create_dept       is '鍒涘缓閮ㄩ棬';
+comment on column  sys_social.create_by         is '鍒涘缓鑰�';
+comment on column  sys_social.create_time       is '鍒涘缓鏃堕棿';
+comment on column  sys_social.update_by         is '鏇存柊鑰�';
+comment on column  sys_social.update_time       is '鏇存柊鏃堕棿';
+comment on column  sys_social.del_flag          is '鍒犻櫎鏍囧織锛�0浠h〃瀛樺湪 2浠h〃鍒犻櫎锛�';
+
+-- ----------------------------
 -- 绉熸埛琛�
 -- ----------------------------
 drop table if exists sys_tenant;
@@ -379,14 +447,15 @@
 insert into sys_menu values('114',  '琛ㄥ崟鏋勫缓',     '3',   '1', 'build',            'tool/build/index',             '', '1', '0', 'C', '0', '0', 'tool:build:list',             'build',         103, 1, now(), null, null, '琛ㄥ崟鏋勫缓鑿滃崟');
 insert into sys_menu values('115',  '浠g爜鐢熸垚',     '3',   '2', 'gen',              'tool/gen/index',               '', '1', '0', 'C', '0', '0', 'tool:gen:list',               'code',          103, 1, now(), null, null, '浠g爜鐢熸垚鑿滃崟');
 insert into sys_menu values('121',  '绉熸埛绠$悊',     '6',   '1', 'tenant',           'system/tenant/index',          '', '1', '0', 'C', '0', '0', 'system:tenant:list',          'list',          103, 1, now(), null, null, '绉熸埛绠$悊鑿滃崟');
-insert into sys_menu values('122',  '绉熸埛濂楅绠$悊',  '6',   '2', 'tenantPackage',    'system/tenantPackage/index',   '', '1', '0', 'C', '0', '0', 'system:tenantPackage:list',   'form',          103, 1, now(), null, null, '绉熸埛濂楅绠$悊鑿滃崟');
+insert into sys_menu values('122',  '绉熸埛濂楅绠$悊', '6',   '2', 'tenantPackage',    'system/tenantPackage/index',   '', '1', '0', 'C', '0', '0', 'system:tenantPackage:list',   'form',          103, 1, now(), null, null, '绉熸埛濂楅绠$悊鑿滃崟');
+insert into sys_menu values('123',  '瀹㈡埛绔鐞�',   '1',   '11', 'client',           'system/client/index',          '', '1', '0', 'C', '0', '0', 'system:client:list',          'international', 103, 1, now(), null, null, '瀹㈡埛绔鐞嗚彍鍗�');
 
 -- springboot-admin鐩戞帶
 insert into sys_menu values('117',  'Admin鐩戞帶',   '2',   '5',  'Admin',            'monitor/admin/index',         '', '1', '0', 'C', '0', '0', 'monitor:admin:list',          'dashboard',     103, 1, now(), null, null, 'Admin鐩戞帶鑿滃崟');
 -- oss鑿滃崟
 insert into sys_menu values('118',  '鏂囦欢绠$悊',     '1',   '10', 'oss',              'system/oss/index',            '', '1', '0', 'C', '0', '0', 'system:oss:list',             'upload',        103, 1, now(), null, null, '鏂囦欢绠$悊鑿滃崟');
--- xxl-job-admin鎺у埗鍙�
-insert into sys_menu values('120',  '浠诲姟璋冨害涓績',  '2',   '5',  'XxlJob',           'monitor/xxljob/index',        '', '1', '0', 'C', '0', '0', 'monitor:xxljob:list',         'job',           103, 1, now(), null, null, 'Xxl-Job鎺у埗鍙拌彍鍗�');
+-- powerjob server鎺у埗鍙�
+insert into sys_menu values('120',  '浠诲姟璋冨害涓績',  '2',   '5',  'powerjob',           'monitor/powerjob/index',        '', '1', '0', 'C', '0', '0', 'monitor:powerjob:list',         'job',           103, 1, now(), null, null, 'PowerJob鎺у埗鍙拌彍鍗�');
 
 -- 涓夌骇鑿滃崟
 insert into sys_menu values('500',  '鎿嶄綔鏃ュ織', '108', '1', 'operlog',    'monitor/operlog/index',    '', '1', '0', 'C', '0', '0', 'monitor:operlog:list',    'form',          103, 1, now(), null, null, '鎿嶄綔鏃ュ織鑿滃崟');
@@ -477,7 +546,12 @@
 insert into sys_menu values('1613', '绉熸埛濂楅淇敼', '122', '3', '#', '', '', '1', '0', 'F', '0', '0', 'system:tenantPackage:edit',    '#', 103, 1, now(), null, null, '');
 insert into sys_menu values('1614', '绉熸埛濂楅鍒犻櫎', '122', '4', '#', '', '', '1', '0', 'F', '0', '0', 'system:tenantPackage:remove',  '#', 103, 1, now(), null, null, '');
 insert into sys_menu values('1615', '绉熸埛濂楅瀵煎嚭', '122', '5', '#', '', '', '1', '0', 'F', '0', '0', 'system:tenantPackage:export',  '#', 103, 1, now(), null, null, '');
-
+-- 瀹㈡埛绔鐞嗘寜閽�
+insert into sys_menu values('1061', '瀹㈡埛绔鐞嗘煡璇�', '123', '1',  '#', '', '', '1', '0', 'F', '0', '0', 'system:client:query',        '#', 103, 1, now(), null, null, '');
+insert into sys_menu values('1062', '瀹㈡埛绔鐞嗘柊澧�', '123', '2',  '#', '', '', '1', '0', 'F', '0', '0', 'system:client:add',          '#', 103, 1, now(), null, null, '');
+insert into sys_menu values('1063', '瀹㈡埛绔鐞嗕慨鏀�', '123', '3',  '#', '', '', '1', '0', 'F', '0', '0', 'system:client:edit',         '#', 103, 1, now(), null, null, '');
+insert into sys_menu values('1064', '瀹㈡埛绔鐞嗗垹闄�', '123', '4',  '#', '', '', '1', '0', 'F', '0', '0', 'system:client:remove',       '#', 103, 1, now(), null, null, '');
+insert into sys_menu values('1065', '瀹㈡埛绔鐞嗗鍑�', '123', '5',  '#', '', '', '1', '0', 'F', '0', '0', 'system:client:export',       '#', 103, 1, now(), null, null, '');
 
 -- ----------------------------
 -- 6銆佺敤鎴峰拰瑙掕壊鍏宠仈琛�  鐢ㄦ埛N-1瑙掕壊
@@ -598,6 +672,11 @@
 insert into sys_role_menu values ('2', '1058');
 insert into sys_role_menu values ('2', '1059');
 insert into sys_role_menu values ('2', '1060');
+insert into sys_role_menu values ('2', '1061');
+insert into sys_role_menu values ('2', '1062');
+insert into sys_role_menu values ('2', '1063');
+insert into sys_role_menu values ('2', '1064');
+insert into sys_role_menu values ('2', '1065');
 
 -- ----------------------------
 -- 8銆佽鑹插拰閮ㄩ棬鍏宠仈琛�  瑙掕壊1-N閮ㄩ棬
@@ -737,8 +816,9 @@
 insert into sys_dict_type values(7, '000000', '閫氱煡绫诲瀷', 'sys_notice_type',     '0', 103, 1, now(), null, null, '閫氱煡绫诲瀷鍒楄〃');
 insert into sys_dict_type values(8, '000000', '閫氱煡鐘舵��', 'sys_notice_status',   '0', 103, 1, now(), null, null, '閫氱煡鐘舵�佸垪琛�');
 insert into sys_dict_type values(9, '000000', '鎿嶄綔绫诲瀷', 'sys_oper_type',       '0', 103, 1, now(), null, null, '鎿嶄綔绫诲瀷鍒楄〃');
-insert into sys_dict_type values(10, '000000', '绯荤粺鐘舵��', 'sys_common_status',   '0', 103, 1, now(), null, null, '鐧诲綍鐘舵�佸垪琛�');
-
+insert into sys_dict_type values(10, '000000', '绯荤粺鐘舵��', 'sys_common_status',  '0', 103, 1, now(), null, null, '鐧诲綍鐘舵�佸垪琛�');
+insert into sys_dict_type values(11, '000000', '鎺堟潈绫诲瀷', 'sys_grant_type',     '0', 103, 1, now(), null, null, '璁よ瘉鎺堟潈绫诲瀷');
+insert into sys_dict_type values(12, '000000', '璁惧绫诲瀷', 'sys_device_type',    '0', 103, 1, now(), null, null, '瀹㈡埛绔澶囩被鍨�');
 
 -- ----------------------------
 -- 12銆佸瓧鍏告暟鎹〃
@@ -808,6 +888,13 @@
 insert into sys_dict_data values(26, '000000', 9,  '娓呯┖鏁版嵁', '9',       'sys_oper_type',       '',   'danger',  'N', '0', 103, 1, now(), null, null, '娓呯┖鎿嶄綔');
 insert into sys_dict_data values(27, '000000', 1,  '鎴愬姛',     '0',       'sys_common_status',   '',   'primary', 'N', '0', 103, 1, now(), null, null, '姝e父鐘舵��');
 insert into sys_dict_data values(28, '000000', 2,  '澶辫触',     '1',       'sys_common_status',   '',   'danger',  'N', '0', 103, 1, now(), null, null, '鍋滅敤鐘舵��');
+insert into sys_dict_data values(30, '000000', 0,  '瀵嗙爜璁よ瘉', 'password',   'sys_grant_type',   '',   'default', 'N', '0', 103, 1, now(), null, null, '瀵嗙爜璁よ瘉');
+insert into sys_dict_data values(31, '000000', 0,  '鐭俊璁よ瘉', 'sms',        'sys_grant_type',   '',   'default', 'N', '0', 103, 1, now(), null, null, '鐭俊璁よ瘉');
+insert into sys_dict_data values(32, '000000', 0,  '閭欢璁よ瘉', 'email',      'sys_grant_type',   '',   'default', 'N', '0', 103, 1, now(), null, null, '閭欢璁よ瘉');
+insert into sys_dict_data values(33, '000000', 0,  '灏忕▼搴忚璇�', 'xcx',      'sys_grant_type',   '',   'default', 'N', '0', 103, 1, now(), null, null, '灏忕▼搴忚璇�');
+insert into sys_dict_data values(34, '000000', 0,  '涓夋柟鐧诲綍璁よ瘉', 'social', 'sys_grant_type',   '',   'default', 'N', '0', 103, 1, now(), null, null, '涓夋柟鐧诲綍璁よ瘉');
+insert into sys_dict_data values(35, '000000', 0,  'PC绔�', 'pc',            'sys_device_type',   '',   'default', 'N', '0', 103, 1, now(), null, null, 'PC绔�');
+insert into sys_dict_data values(36, '000000', 0,  'APP绔�', 'app',          'sys_device_type',   '',   'default', 'N', '0', 103, 1, now(), null, null, 'APP绔�');
 
 
 -- ----------------------------
@@ -1132,6 +1219,49 @@
 insert into sys_oss_config values (4, '000000', 'qcloud', 'XXXXXXXXXXXXXXX',  'XXXXXXXXXXXXXXX', 'ruoyi-1250000000',  '', 'cos.ap-beijing.myqcloud.com',         '','N', 'ap-beijing',  '1', '1', '', 103, 1, now(), 1, now(), null);
 insert into sys_oss_config values (5, '000000', 'image',  'ruoyi',            'ruoyi123',        'ruoyi',             'image', '127.0.0.1:9000',                 '','N', '',            '1', '1', '', 103, 1, now(), 1, now(), NULL);
 
+-- ----------------------------
+-- 绯荤粺鎺堟潈琛�
+-- ----------------------------
+drop table if exists sys_client;
+create table sys_client (
+    id                  int8,
+    client_id           varchar(64)   default ''::varchar,
+    client_key          varchar(32)   default ''::varchar,
+    client_secret       varchar(255)  default ''::varchar,
+    grant_type          varchar(255)  default ''::varchar,
+    device_type         varchar(32)   default ''::varchar,
+    active_timeout      int4          default 1800,
+    timeout             int4          default 604800,
+    status              char(1)       default '0'::bpchar,
+    del_flag            char(1)       default '0'::bpchar,
+    create_dept         int8,
+    create_by           int8,
+    create_time         timestamp,
+    update_by           int8,
+    update_time         timestamp,
+    constraint sys_client_pk primary key (id)
+);
+
+comment on table sys_client                         is '绯荤粺鎺堟潈琛�';
+comment on column sys_client.id                     is '涓诲缓';
+comment on column sys_client.client_id              is '瀹㈡埛绔痠d';
+comment on column sys_client.client_key             is '瀹㈡埛绔痥ey';
+comment on column sys_client.client_secret          is '瀹㈡埛绔閽�';
+comment on column sys_client.grant_type             is '鎺堟潈绫诲瀷';
+comment on column sys_client.device_type            is '璁惧绫诲瀷';
+comment on column sys_client.active_timeout         is 'token娲昏穬瓒呮椂鏃堕棿';
+comment on column sys_client.timeout                is 'token鍥哄畾瓒呮椂';
+comment on column sys_client.status                 is '鐘舵�侊紙0姝e父 1鍋滅敤锛�';
+comment on column sys_client.del_flag               is '鍒犻櫎鏍囧織锛�0浠h〃瀛樺湪 2浠h〃鍒犻櫎锛�';
+comment on column sys_client.create_dept            is '鍒涘缓閮ㄩ棬';
+comment on column sys_client.create_by              is '鍒涘缓鑰�';
+comment on column sys_client.create_time            is '鍒涘缓鏃堕棿';
+comment on column sys_client.update_by              is '鏇存柊鑰�';
+comment on column sys_client.update_time            is '鏇存柊鏃堕棿';
+
+insert into sys_client values (1, 'e5cd7e4891bf95d1d19206ce24a7b32e', 'pc', 'pc123', 'password,social', 'pc', 1800, 604800, 0, 0, 103, 1, now(), 1, now());
+insert into sys_client values (2, '428a8310cd442757ae699df5d894f051', 'app', 'app123', 'password,sms,social', 'app', 1800, 604800, 0, 0, 103, 1, now(), 1, now());
+
 -- 瀛楃涓茶嚜鍔ㄨ浆鏃堕棿 閬垮厤妗嗘灦鏃堕棿鏌ヨ鎶ラ敊闂
 create or replace function cast_varchar_to_timestamp(varchar) returns timestamptz as $$
 select to_timestamp($1, 'yyyy-mm-dd hh24:mi:ss');

--
Gitblit v1.9.3