/* 更新业务单元是否勾选相应职能的标志  */
UPDATE t_org_org set fisadministrative=0, fispurchase=0, fissale=0, fisproduce=0, fisinventory=0, fisqc=0, fissettlement=0, fisbankroll=0, fisasset=0, fisaccounting=0, fishr=0, fisscc=0, fisbudget=0, fiscontrolunit=0;

update t_org_org set FISADMINISTRATIVE = '1' where FID in 
(SELECT s.forgid from t_org_structure s 
INNER JOIN t_org_viewschema v
on s.fviewid = v.fid
INNER JOIN t_org_bizlist b
on v.ftreetype = b.fnumber
where b.fnumber = '01'
);

update t_org_org set fispurchase = '1' where FID in 
(SELECT s.forgid from t_org_structure s 
INNER JOIN t_org_viewschema v
on s.fviewid = v.fid
INNER JOIN t_org_bizlist b
on v.ftreetype = b.fnumber
where b.fnumber = '02'
);

update t_org_org set fissale = '1' where FID in 
(SELECT s.forgid from t_org_structure s 
INNER JOIN t_org_viewschema v
on s.fviewid = v.fid
INNER JOIN t_org_bizlist b
on v.ftreetype = b.fnumber
where b.fnumber = '03'
);

update t_org_org set fisproduce = '1' where FID in 
(SELECT s.forgid from t_org_structure s 
INNER JOIN t_org_viewschema v
on s.fviewid = v.fid
INNER JOIN t_org_bizlist b
on v.ftreetype = b.fnumber
where b.fnumber = '04'
);

update t_org_org set fisinventory = '1' where FID in 
(SELECT s.forgid from t_org_structure s 
INNER JOIN t_org_viewschema v
on s.fviewid = v.fid
INNER JOIN t_org_bizlist b
on v.ftreetype = b.fnumber
where b.fnumber = '05'
);

update t_org_org set fisqc = '1' where FID in 
(SELECT s.forgid from t_org_structure s 
INNER JOIN t_org_viewschema v
on s.fviewid = v.fid
INNER JOIN t_org_bizlist b
on v.ftreetype = b.fnumber
where b.fnumber = '06'
);

update t_org_org set fissettlement = '1' where FID in 
(SELECT s.forgid from t_org_structure s 
INNER JOIN t_org_viewschema v
on s.fviewid = v.fid
INNER JOIN t_org_bizlist b
on v.ftreetype = b.fnumber
where b.fnumber = '07'
);

update t_org_org set fisbankroll = '1' where FID in 
(SELECT s.forgid from t_org_structure s 
INNER JOIN t_org_viewschema v
on s.fviewid = v.fid
INNER JOIN t_org_bizlist b
on v.ftreetype = b.fnumber
where b.fnumber = '08'
);

update t_org_org set fisasset = '1' where FID in 
(SELECT s.forgid from t_org_structure s 
INNER JOIN t_org_viewschema v
on s.fviewid = v.fid
INNER JOIN t_org_bizlist b
on v.ftreetype = b.fnumber
where b.fnumber = '09'
);

update t_org_org set fisaccounting = '1' where FID in 
(SELECT s.forgid from t_org_structure s 
INNER JOIN t_org_viewschema v
on s.fviewid = v.fid
INNER JOIN t_org_bizlist b
on v.ftreetype = b.fnumber
where b.fnumber = '10'
);

update t_org_org set fishr = '1' where FID in 
(SELECT s.forgid from t_org_structure s 
INNER JOIN t_org_viewschema v
on s.fviewid = v.fid
INNER JOIN t_org_bizlist b
on v.ftreetype = b.fnumber
where b.fnumber = '11'
);

update t_org_org set fisscc = '1' where FID in 
(SELECT s.forgid from t_org_structure s 
INNER JOIN t_org_viewschema v
on s.fviewid = v.fid
INNER JOIN t_org_bizlist b
on v.ftreetype = b.fnumber
where b.fnumber = '12'
);

update t_org_org set fisbudget = '1' where FID in 
(SELECT s.forgid from t_org_structure s 
INNER JOIN t_org_viewschema v
on s.fviewid = v.fid
INNER JOIN t_org_bizlist b
on v.ftreetype = b.fnumber
where b.fnumber = '13'
);

update t_org_org set fiscontrolunit = '1' where FID in 
(SELECT s.forgid from t_org_structure s 
INNER JOIN t_org_viewschema v
on s.fviewid = v.fid
INNER JOIN t_org_bizlist b
on v.ftreetype = b.fnumber
where b.fnumber = '14'
);


/** 更新是否叶子节点 */
update t_org_structure p set fisleaf = 1,fisbizunit = 1;
update t_org_structure p set fisleaf = 0,fisbizunit = 0 where EXISTS(
		select fparentid from (select c.fparentid,c.FVIEWID from t_org_structure c) as t
		where t.fviewid = p.fviewid and p.forgid = t.fparentid);
