管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-11-02 eb1af5f77f2c16e580173553e548ff4e41653e4e
data/db_fn.sql
@@ -1,4 +1,4 @@
----------------------------------------------------------------------------------------------------- 1.查询连接数
----------------------------------------------------------------------------------------------------- 0.查询连接数
show max_connections;
select count(1) from pg_stat_activity;
@@ -152,7 +152,27 @@
select fn_rec_array(1, 'dep');
select fn_rec_array(10, 'dir');
select * from lf.sys_user a where a.depid=ANY(fn_rec_array(15,'dep'));
----------------------------------------------------------------------------------------------------- g.索引
----------------------------------------------------------------------------------------------------- g.获取实体名
create or replace function fn_get_entity(tab varchar)
returns varchar as $$
  declare
   str varchar;
   rs varchar = '';
  begin
   foreach str in array (select string_to_array(tab, '_')) loop
     if (length(rs) = 0 or length(str) = 1) then
       rs = rs || str;
     else
      rs = rs || initcap(str);
     end if;
   end loop;
   return rs;
  end;
$$ language plpgsql;
select fn_get_entity('dlg_25w_boua_s'); select fn_get_entity('dlg_25w_vega');
----------------------------------------------------------------------------------------------------- h.索引
alter table lf.sys_role_user add constraint idx_unique_role_user unique (roleid, userid); -- 联合唯一索引
insert into lf.sys_role_user (roleid,userid) values (1,1); -- 测试
select * from lf.sys_role_user;
@@ -168,7 +188,7 @@
alter table lf.sys_role_menu_auth add constraint idx_unique_role_menu_auth unique (roleid,menu_auth_id); -- 联合唯一索引
insert into lf.sys_role_menu_auth (roleid,menu_auth_id) values (1,1);
select * from lf.sys_role_menu_auth;
-----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------- i.联合查询
select a.*,fn_uname(a.create_user) createUserName,fn_uname(a.update_user) updateUserName from lf.sys_blacklist a order by a.id;
select * from lf.sys_user a where uname like '%' and a.depid=ANY(fn_rec_array(1,'dep'));
select * from lf.sys_user a left join lf.sys_role_user b on a.id=b.userid
@@ -195,7 +215,7 @@
update lf.sys_operate set modular1='运维管理',modular2='资源管理' where position('/res/select' in url)>0 and (modular1 is null or modular2 is null);
delete from lf.sys_operate where modular1 is null or modular2 is null;
-----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------- j.查询授权
select gid,gb,name,st_astext(a.geom) from bd.dlg_agnp a;
-- 根据用户Uid查询资源
@@ -229,7 +249,7 @@
inner join lf.sys_menu e on d.menuid = e.id
inner join lf.sys_auth f on d.authid = f.id
where a.uid = 'admin';
---------------------------------------------------------------------------------------------- 数据统计
---------------------------------------------------------------------------------------------- k.数据统计
select modular2,count(*) from lf.sys_operate group by modular2;
select to_char(optime,'yyyy-mm-dd') as optime,count(*) from lf.sys_login where optime between (select optime - interval '30 day')
@@ -249,11 +269,9 @@
and ST_Intersects(geom, 
ST_PolygonFromText('POLYGON ((115.94927385452 32.3754479115071 0,121.989371092554 32.2766788010181 0,121.850621222894 29.6874200067864 0,115.9727267226 29.7835368627922 0,115.94927385452 32.3754479115071 0))', 4326))
select st_astext(geom) from bd.dlg_25w_hfcl limit 10;
select * from lf.sys_attach where 1=1 limit 1
select * from lf.sys_download;
select * from lf.sys_user;