| | |
| | | |
| | | select fn_get_entity('dlg_25w_boua_s'); |
| | | ----------------------------------------------------------------------------------------------------- 08.查询字典表并统计记录 * |
| | | -- drop function fn_tab_count(varchar, varchar, varchar, integer); |
| | | create or replace function fn_tab_count(ns varchar, tab varchar, dirs varchar, depid integer) |
| | | -- drop function fn_tab_count(varchar, varchar, varchar); |
| | | create or replace function fn_tab_count(ns varchar, tab varchar, filters varchar) |
| | | returns integer as $$ |
| | | declare |
| | | sql varchar; |
| | | cc integer; |
| | | begin |
| | | sql := 'select count(*) from ' || ns || '.' || tab || ' where 1 = 1'; |
| | | |
| | | if (dirs is not null) then |
| | | sql := sql || ' and dirid = ANY(fn_dir_arrs(''' || dirs || '''))'; |
| | | end if; |
| | | |
| | | if (depid is not null) then |
| | | sql := sql || ' and depid = ANY(fn_rec_array(' || depid || ', ''dep''))'; |
| | | end if; |
| | | |
| | | execute sql into cc; |
| | | raise notice 'select count(*) from %s.%s where %s', ns, tab, filters; |
| | | execute format('select count(*) from %s.%s where %s', ns, tab, filters) into cc; |
| | | |
| | | return cc; |
| | | end; |
| | | $$ language plpgsql; |
| | | |
| | | select fn_tab_count('bd', 'dlg_agnp', '1,57', 1); |
| | | -- select count(*) from bd.dlg_agnp where 1=1 and dirid = ANY(fn_dir_arrs('1,57')) and depid = ANY(fn_rec_array(1, 'dep')); |
| | | select ns,tab,tab_desc,fn_get_entity(tab) entity,fn_tab_count(ns, tab, '1,57', 1) "len" from lf.sys_dict where tab_desc like '%' group by ns,tab,tab_desc limit 10; |
| | | |
| | | with rs as (select ns,tab,tab_desc,fn_get_entity(tab) entity from lf.sys_dict where tab_desc like '%' group by ns,tab,tab_desc limit 10) |
| | | select rs.*,fn_tab_count(rs.ns, rs.tab, null, 1) "len" from rs; |
| | | |
| | | select fn_rec_array(1, 'dep') |
| | | select count(*) from lf.sys_meta where depid = ANY(fn_rec_array(1, 'dep')); |
| | | select count(*) from bd.dlg_25w_lrdl where depid = ANY(fn_rec_array(1, 'dep')); |
| | | select fn_tab_count('bd', 'dlg_agnp', '1 = 1'); |
| | | ----------------------------------------------------------------------------------------------------- 09.10进制转62进制 |
| | | -- drop function fn_10_to_62(numeric); |
| | | create or replace function fn_10_to_62(num numeric(30, 0)) |
| | |
| | | return rs; |
| | | end; |
| | | $$ language plpgsql; |
| | | ----------------------------------------------------------------------------------------------------- |
| | | ----------------------------------------------------------------------------------------------------- 09 修改表结构 |
| | | -- drop function fn_alter_tab_fields(); |
| | | create or replace function fn_alter_tab_fields() |
| | | returns integer as $$ |
| | | declare |
| | | rec record; |
| | | tn varchar; |
| | | cc integer := 0; |
| | | begin |
| | | for rec in (select ns, tab from lf.sys_dict group by ns, tab order by ns, tab) |
| | | loop |
| | | raise notice 'ns = %, tab = %.', rec.ns, rec.tab; |
| | | |
| | | tn := rec.tab; |
| | | if length(tn) > 32 then |
| | | tn := replace(tn, 'standard_frozen_depth_', 's_f_d_'); |
| | | tn := replace(tn, 'general_report_on_', 'g_r_o_'); |
| | | tn := replace(tn, 'prevention_and_control_', 'p_a_c_'); |
| | | tn := replace(tn, 'water_curtain_roadway_', 'w_c_r_'); |
| | | end if; |
| | | |
| | | execute format('alter table %s.%s alter column %s type varchar(24)', rec.ns, rec.tab, 'depid'); |
| | | execute format('alter table %s.%s alter column %s type varchar(24)', rec.ns, rec.tab, 'dirid'); |
| | | |
| | | execute format('update %s.%s a set depid = (select code from lf.sys_dep b where b.id = cast(a.depid as integer))', rec.ns, rec.tab); |
| | | execute format('update %s.%s a set dirid = (select code from lf.sys_dir b where b.id = cast(a.dirid as integer))', rec.ns, rec.tab); |
| | | |
| | | --execute format('drop index if exists %s.idx_%s_depid', rec.ns, rec.tab); |
| | | execute format('create index idx_%s_depid on %s.%s (depid)', tn, rec.ns, rec.tab); |
| | | |
| | | --execute format('drop index if exists %s.idx_%s_dirid', rec.ns, rec.tab); |
| | | execute format('create index idx_%s_dirid on %s.%s (dirid)', tn, rec.ns, rec.tab); |
| | | |
| | | cc := cc + 1; |
| | | end loop; |
| | | |
| | | return cc; |
| | | end; |
| | | $$ language plpgsql; |
| | | |
| | | select fn_alter_tab_fields(); |
| | | |
| | | select gid,depid,dirid from bd.b_borehole limit 10; |
| | | select gid,depid,dirid from bd.dlg_agnp limit 10; |
| | | select gid,depid,dirid from bd.dlg_25w_resa limit 10; |
| | | select gid,depid,dirid from bd.dlg_25w_boul limit 10; |
| | | ----------------------------------------------------------------------------------------------------- |
| | |
| | | select * from lf.sys_meta where substr(path,1,2) = '2\'; |
| | | --------------------------------------------------------- 更新内容 --------------------------------------------------------- |
| | | bd.* 140,bs.* 284,lf.* 34,md.* 64 |
| | | --------------------------------------------------------- 00 lf.sys_dict |
| | | update lf.sys_dict set type='integer' where field='gid' and type='double'; |
| | | update lf.sys_dict set type='integer' where field='verid' and type='double'; |
| | | update lf.sys_dict set type='integer' where field='createuser' and type='text'; |
| | | update lf.sys_dict set type='integer' where field='updateuser' and type='text'; |
| | | --------------------------------------------------------- 01 lf.sys_dep |
| | | -- alter sequence lf.sys_meta_id_seq restart with 1; |
| | | update lf.sys_operate set modular2='源数据管理' where modular2='元数据'; |
| | |
| | | |
| | | select fn_alter_tab_fields(); |
| | | |
| | | select count(*) from bd.b_borehole; |
| | | |
| | | select gid,depid,dirid,verid from bd.b_borehole; -- 357824 |
| | | select * from lf.sys_dir where id=0; |
| | | select * from lf.sys_dep where id=0; |
| | | |
| | | select gid,depid,dirid from bd.b_borehole limit 10; |
| | | select gid,depid,dirid from bd.dlg_agnp limit 10; |
| | | select gid,depid,dirid from bd.dlg_25w_resa limit 10; |
| | | select gid,depid,dirid from bd.dlg_25w_boul limit 10; |
| | | --------------------------------------------------------- |
| | | select count(*) from bd.b_borehole; |
| | | |
| | | select gid,depid,dirid,verid from bd.b_borehole; -- 357824 |
| | | select * from lf.sys_dir where id=0; |
| | | select * from lf.sys_dep where id=0; |
| | | --------------------------------------------------------- |
| | | -- 0100000000,02000000,030000,040100,0100000002,02000002,040102,0100000003,02000003,0100000001,02000001,040101,030001,01,02,02000001 |
| | | select * from lf.sys_meta where dircode like '01%' or dircode like '02%' or dircode like '030000%' |
| | | or dircode like '030001%' or dircode like '040100%' or dircode like '040101%' or dircode like '040102%'; |
| | | |
| | | select code "key",name "value" from lf.sys_dir where pid = 1; |
| | | select code "key", name "value" from lf.sys_dir where pid = 0 and id > 1; |
| | | select code "key", name "value" from lf.sys_dir where pid = 1; |
| | | select (select string_agg(code, ',') from lf.sys_dir where name = a.name) "key", name "value" from lf.sys_dir a |
| | | where name in ('测量(ESV)', '勘察(EGE)', '地灾(EGD)', '洞库(EGD)') group by name order by name; |
| | | |
| | | select count(*) from bd.dlg_25w_aanp where 1 = 1 |
| | | |
| | | |
| | | select a.*, fn_tab_count(a.ns, a.tab, '1=1') "rows" from |
| | | (select distinct ns,tab,fn_get_entity(tab) entity,tab_desc,tableType from lf.sys_dict |
| | | order by tab |
| | | limit 10 offset 0) a |
| | | |
| | | |
| | | |
| | |
| | | return fail("单位代码含有非法字符", null); |
| | | } |
| | | |
| | | String filter = "1=1"; |
| | | String filters = "1=1"; |
| | | if (!StringHelper.isEmpty(depcode)) { |
| | | filter += String.format(" and depid like '%s%%'", depcode); |
| | | filters += String.format(" and depid like '%s%%'", depcode); |
| | | } |
| | | dirs = DataLibService.copeCodes(dirs, "dircode"); |
| | | dirs = DataLibService.copeCodes(dirs, "dirid"); |
| | | if (dirs != null) { |
| | | filter += String.format(" and (%s)", dirs); |
| | | filters += String.format(" and (%s)", dirs); |
| | | } |
| | | filter = filter.replace("1=1 and ", ""); |
| | | |
| | | int count = baseQueryService.selectTabsForCount(tab, filter); |
| | | int count = baseQueryService.selectTabsForCount(tab); |
| | | if (count == 0) { |
| | | return success(0, null); |
| | | } |
| | | |
| | | List<TabEntity> rs = baseQueryService.selectTabsByPage(tab, filter, pageSize, pageSize * (pageIndex - 1)); |
| | | List<TabEntity> rs = baseQueryService.selectTabsByPage(tab, filters, pageSize, pageSize * (pageIndex - 1)); |
| | | |
| | | return success(count, rs); |
| | | } catch (Exception ex) { |
| | |
| | | * @return 是/否 |
| | | */ |
| | | public static boolean isSqlInjection(String str) { |
| | | if (null == str) { |
| | | return false; |
| | | } |
| | | |
| | | Matcher m = sqlPattern.matcher(str); |
| | | |
| | | return m.matches(); |
| | |
| | | /** |
| | | * 根据表名查询记录数 |
| | | * |
| | | * @param tab 表名 |
| | | * @param filter 过滤条件 |
| | | * @param tab 表名 |
| | | * @return |
| | | */ |
| | | public Integer selectTabsForCount(String tab, String filter); |
| | | public Integer selectTabsForCount(String tab); |
| | | |
| | | /** |
| | | * 根据表名分页查询 |
| | | * |
| | | * @param tab 表名 |
| | | * @param filter 过滤条件 |
| | | * @param limit 记录数 |
| | | * @param offset 偏移量 |
| | | * @param tab 表名 |
| | | * @param filters 过滤条件 |
| | | * @param limit 记录数 |
| | | * @param offset 偏移量 |
| | | * @return |
| | | */ |
| | | public List<TabEntity> selectTabsByPage(String tab, String filter, Integer limit, Integer offset); |
| | | public List<TabEntity> selectTabsByPage(String tab, String filters, Integer limit, Integer offset); |
| | | |
| | | /** |
| | | * 查询字段信息 |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Integer selectTabsForCount(String tab, String filter) { |
| | | public Integer selectTabsForCount(String tab) { |
| | | tab = StringHelper.getLikeStr(tab); |
| | | |
| | | return baseQueryMapper.selectTabsForCount(tab, filter); |
| | | return baseQueryMapper.selectTabsForCount(tab); |
| | | } |
| | | |
| | | @Override |
| | | public List<TabEntity> selectTabsByPage(String tab, String filter, Integer limit, Integer offset) { |
| | | public List<TabEntity> selectTabsByPage(String tab, String filters, Integer limit, Integer offset) { |
| | | tab = StringHelper.getLikeStr(tab); |
| | | |
| | | return baseQueryMapper.selectTabsByPage(tab, filter, limit, offset); |
| | | return baseQueryMapper.selectTabsByPage(tab, filters, limit, offset); |
| | | } |
| | | |
| | | @Override |
| | |
| | | </select> |
| | | |
| | | <select id="selectTabsByPage" resultType="com.lf.server.entity.ctrl.TabEntity"> |
| | | select distinct ns,tab,fn_get_entity(tab) entity,tab_desc,tableType from lf.sys_dict |
| | | <where> |
| | | <if test="tab != null"> |
| | | tab like #{tab} or tab_desc like #{tab} |
| | | </if> |
| | | </where> |
| | | order by tab |
| | | limit #{limit} offset #{offset} |
| | | select a.*, fn_tab_count(a.ns, a.tab, #{filters}) "rows" from ( |
| | | select distinct ns,tab,fn_get_entity(tab) entity,tab_desc,tableType from lf.sys_dict |
| | | <where> |
| | | <if test="tab != null"> |
| | | tab like #{tab} or tab_desc like #{tab} |
| | | </if> |
| | | </where> |
| | | order by tab |
| | | limit #{limit} offset #{offset} |
| | | ) a |
| | | </select> |
| | | |
| | | <select id="selectFields" resultType="com.lf.server.entity.data.DictEntity"> |
| | |
| | | </select> |
| | | |
| | | <select id="selectBaseType" resultType="com.lf.server.entity.ctrl.KeyValueEntity"> |
| | | select code "key",name "value" from lf.sys_dir where pid = 1 |
| | | select code "key", name "value" from lf.sys_dir where pid = 1 |
| | | </select> |
| | | |
| | | <select id="selectBusinessType" resultType="com.lf.server.entity.ctrl.KeyValueEntity"> |
| | |
| | | </select> |
| | | |
| | | <select id="selectProject" resultType="com.lf.server.entity.ctrl.KeyValueEntity"> |
| | | select cast(id as varchar) "key",name "value" from lf.sys_dir where pid = 0 and id > 1 |
| | | select code "key", name "value" from lf.sys_dir where pid = 0 and id > 1 |
| | | </select> |
| | | </mapper> |