-- 更新表结构
alter table JCL_ORG_COMP add ec_company int;
alter table JCL_ORG_DEPT add ec_company int;
alter table JCL_ORG_DEPT add ec_department int;
alter table jcl_org_staffplan add ec_company varchar(100);
alter table jcl_org_staff add ec_company int;
alter table jcl_org_staff add ec_department int;
alter table JCL_ORG_STAFFS add  description varchar(200);
-- 插入自定义信息
insert INTO jcl_field_extendinfo (extend_type, table_name, field_name, field_name_desc, field_type, control_type, extend_group_id, isenable, isrequired, list_show, search_show, edit_show, add_show, browser_show, show_order, creator, delete_type, create_time, update_time, browser_type, custom_value, is_system_default) VALUES (1, 'JCL_ORG_COMP', 'ec_company', '上级公司', 'int', 3, 1, 1, 0, 1, 1, 1, 1, 1, 6, 1, 0,  SYSDATE, NULL, '164', '["browser",{"valueSpan":"分部","replaceDatas":[{"name":"分部","id":"164"}],"value":"164"}]', 0);
insert INTO jcl_field_extendinfo (extend_type, table_name, field_name, field_name_desc, field_type, control_type, extend_group_id, isenable, isrequired, list_show, search_show, edit_show, add_show, browser_show, show_order, creator, delete_type, create_time, update_time, browser_type, custom_value, is_system_default) VALUES (2, 'JCL_ORG_DEPT', 'ec_company', '所属分部', 'int', 3, 2, 1, 1, 1, 1, 1, 1, 1, 4, 1, 0,  SYSDATE, NULL, '164', '["browser",{"valueSpan":"分部","replaceDatas":[{"name":"分部","id":"164"}],"value":"164"}]', 0);
insert INTO jcl_field_extendinfo (extend_type, table_name, field_name, field_name_desc, field_type, control_type, extend_group_id, isenable, isrequired, list_show, search_show, edit_show, add_show, browser_show, show_order, creator, delete_type, create_time, update_time, browser_type, custom_value, is_system_default) VALUES (2, 'JCL_ORG_DEPT', 'ec_department', '上级部门', 'int', 3, 2, 1, 0, 1, 1, 1, 1, 1, 5, 1, 0,  SYSDATE, NULL, '4', '["browser",{"valueSpan":"部门","replaceDatas":[{"name":"部门","id":"4"}],"value":"4"}]', 0);

-- 更新自定义字段信息
update jcl_field_extendinfo set list_show =0,search_show =0,edit_show =0,add_show =0 where table_name ='JCL_ORG_COMP' and field_name ='parent_company';
update jcl_field_extendinfo set list_show =0,search_show =0,edit_show =0,add_show =0 where table_name ='JCL_ORG_DEPT' and field_name ='parent_comp';
update jcl_field_extendinfo set list_show =0,search_show =0,edit_show =0,add_show =0 where table_name ='JCL_ORG_DEPT' and field_name ='parent_dept';
update jcl_field_extendinfo set search_show=0,edit_show=0,add_show=0 where table_name ='JCL_ORG_JOB' and field_name='ec_company';

-- 更新浏览按钮
update WORKFLOW_BROWSERURL set TYPEID ='2' where ID = '666';
update datashowparam set ISSHOWNAME =0 where SEARCHNAME = 'post_info_no';
update datashowparam set ISSHOWNAME =1 where SEARCHNAME = 'post_info_name';

-- 更新视图
drop view v_jcl_zdzj;
drop view v_jcl_post;

create or replace view v_jcl_zdzj as
select  'A'||xl.id fid,xl.sequence_name fname,'0' fparentid,xl.sequence_no fno,xl.id fobjid,'1' as ftype
from jcl_org_sequence xl
         INNER JOIN JCL_ORG_GRADE zj ON zj.scheme_id=xl.scheme_id AND nvl(zj.forbidden_tag,0)<>1 and nvl(zj.delete_type,0)<>1
         INNER JOIN JCL_ORG_LEVEL zd ON zd.scheme_id=xl.scheme_id AND nvl(zd.forbidden_tag,0)<>1 and nvl(zd.delete_type,0)<>1
where nvl(xl.forbidden_tag,0)<>1 and nvl(xl.delete_type,0)<>1
union
select xl.id ||'A'|| zj.id ,zj.grade_name,'A'|| xl.id ,zj.grade_no,zj.id,'2' as ftype
from JCL_ORG_GRADE zj
         inner join jcl_org_sequence xl on zj.scheme_id=xl.scheme_id
         INNER JOIN JCL_ORG_LEVEL zd on  ','|| zj.level_id ||',' like '%,'|| zd.id ||',%' AND nvl(zd.forbidden_tag,0)<>1 and nvl(zd.delete_type,0)<>1
where nvl(zj.forbidden_tag,0)<>1 and nvl(zj.delete_type,0)<>1
union
select xl.id ||'A'|| zj.id ||'A'|| zd.id ,zd.level_name, xl.id ||'A'|| zj.id ,zd.level_no,zd.id,'3' as ftype
from JCL_ORG_LEVEL zd
         inner join JCL_ORG_GRADE zj on  ','|| zj.level_id ||',' like '%,'|| zd.id ||',%'
         inner join jcl_org_sequence xl on zj.scheme_id=xl.scheme_id
where nvl(zd.forbidden_tag,0)<>1 and nvl(zd.delete_type,0)<>1;

create or replace view v_jcl_post as
select a.id*-1 fid,a.post_name fname,0 fparentid from JCL_ORG_POST a
                                                          inner join JCL_ORG_POST_INFO b on a.id =b.post_id and nvl(b.forbidden_tag,0)<>1 and nvl(b.delete_type,0)<>1
where nvl(a.delete_type,0)<>1
union
select id,post_info_name,post_id*-1 from JCL_ORG_POST_INFO
where nvl(forbidden_tag,0)<>1 and nvl(delete_type,0)<>1;


-- SqlServer
-- 更新分部ec_company
update jcl_org_comp set ec_company = ( select eccompany from ( select DISTINCT b.id as parent_company, c.id as eccompany from jcl_org_comp a inner join jcl_org_comp b on a.parent_company = b.id inner join hrmsubcompany c on b.uuid = c.uuid ) e where jcl_org_comp.parent_company = e.parent_company );
-- 更新部门ec_department、ec_company
update JCL_ORG_DEPT set ec_department = ( select ecdepartment from ( select DISTINCT b.id as parent_dept, c.id as ecdepartment from JCL_ORG_DEPT a inner join JCL_ORG_DEPT b on a.parent_dept = b.id inner join hrmdepartment c on b.uuid = c.uuid  ) e where JCL_ORG_DEPT.parent_dept = e.parent_dept );
update JCL_ORG_DEPT set ec_company = ( select eccompany from ( select a.id as id, c.id as eccompany from jcl_org_comp a inner join hrmsubcompany c on a.uuid = c.uuid) e where JCL_ORG_DEPT.parent_comp = e.id );
-- 更新岗位ec_company、ec_department
update jcl_org_job set ec_company = (select eccompany from ( select a.id as id, c.id as eccompany from jcl_org_comp a inner join hrmsubcompany c on a.uuid = c.uuid) e where jcl_org_job.parent_comp = e.id  );
update jcl_org_job set ec_department = ( select ec_department from ( select a.id as id, c.id as ec_department from jcl_org_dept a inner join hrmdepartment c on a.uuid = c.uuid) e where jcl_org_job.parent_dept = e.id );
