From 3210fce113223dbcbc397dd0d892540fd591a222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Fri, 11 Mar 2022 18:55:04 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E5=88=A0=E9=99=A4=20=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=20find=5Fin=5Fset=20=E5=87=BD=E6=95=B0=20?= =?UTF-8?q?=E5=9C=A8=E4=BB=A3=E7=A0=81=E5=B1=82=E9=9D=A2=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/helper/DataBaseHelper.java | 13 +++++++++++-- script/sql/oracle/oracle_ry_vue_4.X.sql | 16 ---------------- script/sql/postgres/postgres_ry_vue_4.X.sql | 14 -------------- 3 files changed, 11 insertions(+), 32 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/helper/DataBaseHelper.java b/ruoyi-common/src/main/java/com/ruoyi/common/helper/DataBaseHelper.java index 3d98def5..55a3a41c 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/helper/DataBaseHelper.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/helper/DataBaseHelper.java @@ -53,9 +53,18 @@ public class DataBaseHelper { public static String findInSet(Object var1, String var2) { DataBaseType dataBasyType = getDataBasyType(); + String var = Convert.toStr(var1); if (dataBasyType == DataBaseType.SQL_SERVER) { - return "charindex(" + Convert.toStr(var1) + ", " + var2 + ") <> 0"; + // charindex(',100,' , ',0,100,101,') <> 0 + return "charindex('," + var + ",' , ','+" + var2 + "+',') <> 0"; + } else if (dataBasyType == DataBaseType.POSTGRE_SQL) { + // (select position(',100,' in ',0,100,101,')) <> 0 + return "(select position('," + var + ",' in ','||" + var2 + "||',')) <> 0"; + } else if (dataBasyType == DataBaseType.ORACLE) { + // instr(',0,100,101,' , ',100,') <> 0 + return "instr(','||" + var2 + "||',' , '," + var + ",') <> 0"; } - return "find_in_set(" + Convert.toStr(var1) + ", " + var2 + ") <> 0"; + // find_in_set(100 , '0,100,101') + return "find_in_set(" + var + " , " + var2 + ") <> 0"; } } diff --git a/script/sql/oracle/oracle_ry_vue_4.X.sql b/script/sql/oracle/oracle_ry_vue_4.X.sql index 62952316..9b77d584 100644 --- a/script/sql/oracle/oracle_ry_vue_4.X.sql +++ b/script/sql/oracle/oracle_ry_vue_4.X.sql @@ -940,22 +940,6 @@ insert into sys_oss_config values (2, 'qiniu', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXX insert into sys_oss_config values (3, 'aliyun', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 'http://oss-cn-beijing.aliyuncs.com', 'N', '', '1', '', NULL, 'admin', sysdate, 'admin', sysdate); insert into sys_oss_config values (4, 'qcloud', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi-1250000000', '', 'http://cos.ap-beijing.myqcloud.com', 'N', 'ap-beijing', '1', '', NULL, 'admin', sysdate, 'admin', sysdate); - --- ---------------------------- --- 函数 ,代替mysql的find_in_set --- 例如: select * from sys_dept where FIND_IN_SET (101,ancestors) <> 0 --- mysql可接受0或其它number做为where 条件,oracle只接受表达式做为where 条件 --- ---------------------------- -create or replace function find_in_set(arg1 in varchar2,arg2 in varchar) -return number is Result number; -begin -select instr(','||arg2||',' , ','||arg1||',') into Result from dual; -return(Result); -end find_in_set; - --- 函数分隔符 -/ - -- ---------------------------- -- 钩子 ,用于session连接之后 自动设置默认的date类型格式化 简化时间查询 -- 如需设置其它配置 可在此钩子内任意增加处理语句 diff --git a/script/sql/postgres/postgres_ry_vue_4.X.sql b/script/sql/postgres/postgres_ry_vue_4.X.sql index b93309d5..8cf02c2f 100644 --- a/script/sql/postgres/postgres_ry_vue_4.X.sql +++ b/script/sql/postgres/postgres_ry_vue_4.X.sql @@ -951,17 +951,3 @@ insert into sys_oss_config values (1, 'minio', 'ruoyi', 'ruoyi123', insert into sys_oss_config values (2, 'qiniu', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 'http://XXX.XXXX.com', 'N', 'z0', '1', '', 'admin', now(), 'admin', now(), null); insert into sys_oss_config values (3, 'aliyun', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 'http://oss-cn-beijing.aliyuncs.com', 'N', '', '1', '', 'admin', now(), 'admin', now(), null); insert into sys_oss_config values (4, 'qcloud', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi-1250000000', '', 'http://cos.ap-beijing.myqcloud.com', 'N', 'ap-beijing', '1', '', 'admin', now(), 'admin', now(), null); - --- ---------------------------- --- 函数 ,代替mysql的find_in_set --- 例如: select * from sys_dept where FIND_IN_SET (101,ancestors) <> 0 --- ---------------------------- -create or replace function find_in_set(arg1 int8, arg2 varchar) -returns int8 as $body$ -declare pos int8; -begin -select position(','||arg1||',' IN ','||arg2||',') into pos; -return pos; -end; -$body$ -language plpgsql