----------------------------------------------------------------------- 数据检查
select count(*) from bd.dlg_25w_resa; -- 157217
select count(*) from bd.dlg_25w_boul; -- 7453
select count(*) from bd.dlg_agnp;     -- 3248

select count(*) from bd.dlg_25w_hyda; -- 297884
select count(*) from bd.dlg_25w_hydl; -- 2212590
select count(*) from bd.dlg_25w_lrdl; -- 4690386
select count(*) from bd.dlg_25w_lrrl; -- 51338
select count(*) from bs.m_pipeline;   -- 26

select * from bd.dlg_25w_resa order by gid limit 10;
select * from bd.dlg_25w_boul order by gid limit 10;
select * from bd.dlg_agnp     order by gid limit 10;
----------------------------------------------------------------------- 设置数据单位
select * from lf.sys_dep order by id;

-- pid = 15, 生产业务部门
update bd.dlg_25w_resa set depid = 20 where gid % 7 = 0; -- 线路室
update bd.dlg_25w_resa set depid = 21 where gid % 7 = 1; -- 穿跨越室
--update bd.dlg_25w_resa set depid = 22 where gid % 7 = 2; -- 土建室

-- pid = 38, 勘察事业部
update bd.dlg_25w_resa set depid = 55 where gid % 7 = 3; -- 勘察室
--update bd.dlg_25w_resa set depid = 56 where gid % 7 = 4; -- 岩土设计室
--update bd.dlg_25w_resa set depid = 54 where gid % 7 = 5; -- 测绘室

update bd.dlg_25w_boul set depid = 20 where gid % 7 = 0; -- 线路室
update bd.dlg_25w_boul set depid = 21 where gid % 7 = 1; -- 穿跨越室
update bd.dlg_25w_boul set depid = 55 where gid % 7 = 3; -- 勘察室

update bd.dlg_agnp     set depid = 20 where gid % 7 = 0; -- 线路室
update bd.dlg_agnp     set depid = 21 where gid % 7 = 1; -- 穿跨越室
update bd.dlg_agnp     set depid = 55 where gid % 7 = 3; -- 勘察室

update bd.dlg_25w_resa set depid = 22 where depid is null or depid = 0 or depid = 1; -- 土建室
update bd.dlg_25w_boul set depid = 22 where depid is null or depid = 0 or depid = 1; -- 土建室
update bd.dlg_agnp     set depid = 22 where depid is null or depid = 0 or depid = 1; -- 土建室

update bd.dlg_agnp set depid = null where gid = 3247;
update bd.dlg_agnp set depid = 0    where gid = 3246;

select depid from bd.dlg_25w_resa group by depid order by depid;
select depid from bd.dlg_25w_boul group by depid order by depid;
select depid from bd.dlg_agnp     group by depid order by depid;
----------------------------------------------------------------------- 设置用户
select * from lf.sys_user order by id;

update lf.sys_user set depid = 38 where uname = '管理员';   -- id = 1
update lf.sys_user set depid = 20 where uname = '线路室';   -- id = 2
update lf.sys_user set depid = 21 where uname = '穿跨越室'; -- id = 3
update lf.sys_user set depid = 55 where uname = '勘察室';   -- id = 5
----------------------------------------------------------------------- 设置角色
select * from lf.sys_role order by id;

update lf.sys_role set is_admin=2 where descr='数据管理员';
delete from lf.sys_role where id between 2 and 11;
insert into lf.sys_role (depid,name,descr,is_admin,create_user) values (20,'线路室-数据管理员', '数据管理员',2,1);
insert into lf.sys_role (depid,name,descr,is_admin,create_user) values (21,'穿跨越室-数据管理员','数据管理员',2,1);
insert into lf.sys_role (depid,name,descr,is_admin,create_user) values (55,'勘察室-数据管理员',  '数据管理员',2,1);
insert into lf.sys_role (depid,name,descr,is_admin,create_user) values (22,'土建室-数据管理员',  '数据管理员',2,1);

----------------------------------------------------------------------- 设置用户角色
select * from lf.sys_role_user order by id;

-- delete from lf.sys_role_user where id > 1;
insert into lf.sys_role_user (id, roleid, userid, create_user) values (2, 12, 2, 1);
insert into lf.sys_role_user (id, roleid, userid, create_user) values (3, 13, 3, 1);
insert into lf.sys_role_user (id, roleid, userid, create_user) values (4, 14, 5, 1);
insert into lf.sys_role_user (id, roleid, userid, create_user) values (5, 15, 4, 1);

alter sequence lf.sys_apply_id_seq restart with 3;
alter sequence lf.sys_flow_id_seq restart with 7;
----------------------------------------------------------------------- 递归查询
select depid from bd.dlg_25w_boul where depid > 0 and depid != ALL(fn_rec_array(38, 'dep'))
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))', 4490))
group by depid;

select c.* from lf.sys_role a inner join lf.sys_role_user b on a.id = b.roleid inner join lf.sys_user c on b.userid = c.id
where a.is_admin = 2 and a.depid = 55 order by c.id limit 1

select c.*, fn_rec_query(c.depid, 'dep') depName,fn_uname(c.create_user) createName,fn_uname(c.update_user) updateName
from lf.sys_user a inner join lf.sys_role_user b on a.id = b.userid inner join lf.sys_role c on b.roleid = c.id
where a.id = 1;

select a.*, fn_rec_query(a.depid, 'dep') depName,fn_uname(a.create_user) createName,fn_uname(a.update_user) updateName
from lf.sys_user a inner join lf.sys_role_user b on a.id = b.userid inner join lf.sys_role c on b.roleid = c.id
where c.id = 15
----------------------------------------------------------------------- 查询 57, 163
select * from lf.sys_meta order by id desc limit 10;
select * from lf.sys_fme_log order by id desc;
select * from lf.sys_layer;
select * from lf.sys_user where id = 1;
-- update lf.sys_user set depid = 36 where id = 1

select * from lf.sys_dict where ns='bd' and tab='dlg_agnp'; -- 地名表
select * from bd.dlg_agnp;
select depid from bd.dlg_agnp group by depid;
-- update bd.dlg_agnp set depid=1 where depid is null or depid=0

select * from lf.sys_meta order by id desc limit 10;
select * from lf.sys_fme_log order by id desc;

select * from lf.sys_flow where applyid = 9; -- 47,48,49
select id,userid,depids,tabs,entities,pwd,status,count,descr,wkt from lf.sys_apply;
-- status is '状态：-10-作废，-1-打回，0~9-审核中，10-通过';
update lf.sys_apply set status = 0 where id = 9;
-- delete from lf.sys_flow; delete from lf.sys_apply;
-- 密码：test@12345_lf
select * from lf.sys_user where id in (47,48,49);
select * from lf.sys_download;

select * from bs.m_marker where parentid is not null; -- 三桩一牌 photono
-- update bs.m_marker set parentid='df150a0d-eb8c-48d6-887d-c0901f4f61c5' where photono in ('警示牌10002', '警示牌10004', '警示牌10013');
-- INSERT INTO bs.m_marker(eventid, segname, markername, photono, createtime, createuser, dirid, depid, verid) VALUES (md5(''), 'seg', '10002', '警示牌10002', now(), 1, 1, 1, 0);
-- INSERT INTO bs.m_marker(eventid, segname, markername, photono, createtime, createuser, dirid, depid, verid) VALUES (md5(''), 'seg', '10004', '警示牌10004', now(), 1, 1, 1, 0);
select * from lf.sys_meta where type='xls' order by id desc;
select * from lf.sys_meta where type in ('xls', 'xlsx') and eventid is not null and tab is not null and rows > 0 and id in (1209,1180,1387);
select * from lf.sys_attach order by id desc;















