You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
weaver-hrm-organization/docs/脚本/Mysql/组织架构图触发器.sql

86 lines
4.5 KiB
SQL

insert into jcl_org_map
(id,ftype,fobjid,fecid,uuid,fclass,fclassname,fnumber,fname,fleader,fleaderimg,
fleadername,fleaderjobid,fleaderjob,fleaderlv,fleaderst,fparentid,fobjparentid,
fplan,fonjob,fisvitual,fdatebegin,fdateend)
select a.id,1,a.id,b.id,a.uuid,0,'行政维度',a.comp_no,a.comp_name,g.id,c.messagerurl,
c.lastname,c.jobtitle,d.jobtitlemark,g.job_level,g.job_grade,ifnull(parent_company,0),ifnull(parent_company,0),
ifnull(e.fcnt,0),ifnull(f.fcnt,0),0,NOW(),'2099-12-31'
from
JCL_ORG_comp as a
left join HrmSubCompany as b on a.uuid=b.uuid
left join hrmresource as c on a.comp_principal=c.id
left join hrmjobtitles as d on c.jobtitle=d.id
left join (select comp_id,sum(ifnull(staff_num,0)) fcnt from JCL_ORG_STAFF
where plan_id in (select id from JCL_ORG_STAFFPLAN
where time_start<=NOW() and time_end>NOW())
group by comp_id) e on a.id=e.comp_id
left join (select subcompanyid1,count(1) fcnt from hrmresource where status<=3 group by subcompanyid1) f
on f.subcompanyid1=b.id
left join jcl_org_hrmresource g on c.uuid=g.uuid
where ifnull(a.delete_type,0) <>1 and ifnull(a.forbidden_tag,0) <>1;
insert into jcl_org_map
(id,ftype,fobjid,fecid,uuid,fclass,fclassname,fnumber,fname,fleader,fleaderimg,
fleadername,fleaderjobid,fleaderjob,fleaderlv,fleaderst,fparentid,fobjparentid,
fplan,fonjob,fisvitual,fdatebegin,fdateend)
select a.id+100000000,2,a.id,b.id,a.uuid,0,'行政维度',a.dept_no,a.dept_name,g.id,c.messagerurl,
c.lastname,c.jobtitle,d.jobtitlemark,g.job_level,g.job_grade,
(case ifnull(parent_dept,0) when 0 then parent_comp else parent_dept+100000000 end),
(case ifnull(parent_dept,0) when 0 then parent_comp else parent_dept end),
ifnull(e.fcnt,0),ifnull(f.fcnt,0),0,NOW(),'2099-12-31'
from
JCL_ORG_dept as a
left join HrmDepartment as b on a.uuid=b.uuid
left join hrmresource as c on a.dept_principal=c.id
left join hrmjobtitles as d on c.jobtitle=d.id
left join (select dept_id,sum(ifnull(staff_num,0)) fcnt from JCL_ORG_STAFF
where plan_id in (select id from JCL_ORG_STAFFPLAN
where time_start<=NOW() and time_end>NOW())
group by dept_id) e on a.id=e.dept_id
left join (select departmentid,count(1) fcnt from hrmresource where status<=3 group by departmentid) f on f.departmentid=b.id
left join jcl_org_hrmresource g ON c.uuid = g.uuid
where ifnull(a.delete_type,0) <>1 and ifnull(a.forbidden_tag,0) <>1;
insert into jcl_org_map
(id,ftype,fobjid,fclass,fclassname,fnumber,fname,
fparentid,fobjparentid,
fplan,fonjob,fisvitual,fdatebegin,fdateend)
select a.id+200000000,3,a.id,0,'行政维度',a.job_no,a.job_name,
(case ifnull(parent_job,0) when 0 then parent_dept+100000000 else parent_job+200000000 end),
(case ifnull(parent_job,0) when 0 then parent_dept else parent_job end),
ifnull(e.fcnt,0),ifnull(f.fcnt,0),0,NOW(),'2099-12-31'
from JCL_ORG_job as a
left join (select job_id,sum(ifnull(staff_num,0)) fcnt from JCL_ORG_STAFF
where plan_id in (select id from JCL_ORG_STAFFPLAN
where time_start<=NOW() and time_end>NOW())
group by job_id) e on a.id=e.job_id
left join (select job_title,count(1) fcnt from jcl_org_hrmresource) f
on f.job_title=a.id
where ifnull(a.delete_type,0) <>1 and ifnull(a.forbidden_tag,0) <>1;
insert into jcl_org_map
(id,ftype,fobjid,fecid,uuid,fclass,fclassname,fnumber,fname,fleaderimg,
fleaderjobid,fleaderjob,fleaderlv,fleaderst,fparentid,fobjparentid,
fisvitual,fdatebegin,fdateend)
select a.id+300000000,4,a.id,c.id,a.uuid,0,'行政维度',a.work_code,a.last_name,c.messagerurl,b.id,
b.job_name,a.job_level,a.job_grade,
ifnull( b.id, '' ) +200000000,
b.id,
0,NOW(),'2099-12-31'
from jcl_org_hrmresource a
left join jcl_org_job b ON a.job_title = b.id
left join hrmresource c on a.uuid = c.uuid
where a.status<4;
insert into jcl_org_map
(id,ftype,fobjid,fecid,Uuid,fclass,fclassname,fnumber,fname,fleader,fleaderimg,
fleadername,fleaderjobid,fleaderjob,fleaderlv,fleaderst,fparentid,fobjparentid,
fplan,fonjob,fisvitual,fdatebegin,fdateend)
select 0,0,0,1,uuid,0,'行政维度','00',companyname,0,'',
'',0,'','','',-1,0,
0,0,0,cast(now() as date),'2099-12-31' from HrmCompany;