|
|
|
@ -565,16 +565,16 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
|
|
|
|
// 同步部门负责人
|
|
|
|
|
getJclOrgMapMapper().insertBmfzrToMapJZ(level,grade);
|
|
|
|
|
RecordSet rs = new RecordSet();
|
|
|
|
|
rs.execute("select c.id,a.id as departmentid from hrmdepartment a \n" +
|
|
|
|
|
"inner join hrmdepartmentdefined b on a.id=b.DEPTID\n" +
|
|
|
|
|
"inner join hrmresource c on cast(b.BMFZR as varchar(10))=cast(c.ID as varchar(10)) ");//sqlserver版
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
//同步人员信息
|
|
|
|
|
syncHrmResource(rs.getString("id"),rs.getString("departmentid"),3);
|
|
|
|
|
}
|
|
|
|
|
// rs.execute("select c.id,a.id as departmentid from hrmdepartment a \n" +
|
|
|
|
|
// "inner join hrmdepartmentdefined b on a.id=b.DEPTID\n" +
|
|
|
|
|
// "inner join hrmresource c on cast(b.BMFZR as varchar(10))=cast(c.ID as varchar(10)) ");//sqlserver版
|
|
|
|
|
// while (rs.next()) {
|
|
|
|
|
// //同步人员信息
|
|
|
|
|
// syncHrmResource(rs.getString("id"),rs.getString("departmentid"),3);
|
|
|
|
|
// }
|
|
|
|
|
// getJclOrgMapMapper().insertResToMap(level,grade);
|
|
|
|
|
//清除部门合并、转移造成的脏数据
|
|
|
|
|
getJclOrgMapMapper().deleteJobNull(date);
|
|
|
|
|
// getJclOrgMapMapper().deleteJobNull(date);
|
|
|
|
|
//刷新在岗数、编制数(从岗位向上刷,岗位不需处理)
|
|
|
|
|
// List<JclOrgMap> jclOrgMaps = getJclOrgMapMapper().getJclOrgMapByType("3",date);
|
|
|
|
|
// for (JclOrgMap jclOrgMap : jclOrgMaps){
|
|
|
|
@ -583,27 +583,26 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// 同步人员数据
|
|
|
|
|
String queryDept = "select id from hrmdepartment a where nvl(a.canceled,0)='0' ";
|
|
|
|
|
String queryDept = "select id from hrmdepartment a where isnull(a.canceled,0)='0' ";
|
|
|
|
|
RecordSet recordSet = new RecordSet();
|
|
|
|
|
recordSet.execute(queryDept);
|
|
|
|
|
while (recordSet.next()) {
|
|
|
|
|
String deptId = Util.null2String(recordSet.getString("id"));
|
|
|
|
|
// 处理部门(含子部门人数)
|
|
|
|
|
String recSql = "with children as\n" +
|
|
|
|
|
"(select id,supdepid from HrmDepartment where id = '6'\n" +
|
|
|
|
|
String getSupDeptSql = "with children as\n" +
|
|
|
|
|
"(select id,supdepid from HrmDepartment where id = '"+deptId+"'\n" +
|
|
|
|
|
"union all \n" +
|
|
|
|
|
"select b.id,b.supdepid from children a inner join HrmDepartment b on a.id=b.supdepid\n" +
|
|
|
|
|
")select * from children";
|
|
|
|
|
rs.execute(recSql);
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
}
|
|
|
|
|
String getSupDeptSql = "select wm_concat(id) as allSupDept from hrmdepartment a start with a.id=" + deptId + " connect by a.supdepid=prior a.id";
|
|
|
|
|
")select distinct\n" +
|
|
|
|
|
"STUFF((select ',' + cast(c.id as varchar(10)) from children c \n" +
|
|
|
|
|
"for XML path('')),1,1,'') as allSupDept from children ";
|
|
|
|
|
// String getSupDeptSql = "select wm_concat(id) as allSupDept from hrmdepartment a start with a.id=" + deptId + " connect by a.supdepid=prior a.id";
|
|
|
|
|
rs.execute(getSupDeptSql);
|
|
|
|
|
String allSupDeptIds = null;
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
allSupDeptIds = Util.null2String(rs.getString("allSupDept"));
|
|
|
|
|
}
|
|
|
|
|
String getZrs = "select nvl(sum(zrs),0) zrs from (\n" +
|
|
|
|
|
String getZrs = "select isnull(sum(zrs),0) zrs from (\n" +
|
|
|
|
|
"select a.departmentid,count(id) as zrs from hrmresource a where a.status<4 group by a.departmentid\n" +
|
|
|
|
|
") b where b.departmentid in (" + allSupDeptIds + ")";
|
|
|
|
|
rs.execute(getZrs);
|
|
|
|
@ -611,12 +610,12 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
zrs = Util.null2String(rs.getString("zrs"));
|
|
|
|
|
}
|
|
|
|
|
rs.execute("update junc_org_map set fonjob = '" + zrs + "' where ftype=2 and fdateend>sysdate and fobjid=" + deptId);
|
|
|
|
|
rs.execute("update jcl_org_map set fonjob = '" + zrs + "' where ftype=2 and fdateend>getDate() and fobjid=" + deptId);
|
|
|
|
|
|
|
|
|
|
// 找出没有下级的人员
|
|
|
|
|
String noHaveChildSql = "select a.id,a.managerid from hrmresource a \n" +
|
|
|
|
|
"inner join (select id from hrmresource where departmentid='" + deptId + "'\n" +
|
|
|
|
|
"MINUS\n" +
|
|
|
|
|
"EXCEPT\n" +
|
|
|
|
|
"select managerid from hrmresource a \n" +
|
|
|
|
|
"where a.managerid in (select id from hrmresource where departmentid='" + deptId + "')\n" +
|
|
|
|
|
"and a.departmentid='" + deptId + "') b on a.id=b.id";
|
|
|
|
@ -624,11 +623,111 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
String id = Util.null2String(rs.getString("id"));
|
|
|
|
|
String managerid = Util.null2String(rs.getString("managerid"));
|
|
|
|
|
// handleSuperior(id, managerid, deptId);
|
|
|
|
|
handleSuperior(id, managerid, deptId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 7、删除重复人员上级
|
|
|
|
|
String deleRepeatSql = "delete from jcl_org_map\n" +
|
|
|
|
|
" where fobjid in (select fobjid\n" +
|
|
|
|
|
" from jcl_org_map a\n" +
|
|
|
|
|
" where a.ftype = 4\n" +
|
|
|
|
|
" and a.fdateend > convert(varchar(100),getDate(),23)" +
|
|
|
|
|
" group by fobjid\n" +
|
|
|
|
|
" having count(fobjid) > 1)\n" +
|
|
|
|
|
" and fid not in\n" +
|
|
|
|
|
" (select min(fid)\n" +
|
|
|
|
|
" from jcl_org_map a\n" +
|
|
|
|
|
" where a.ftype = 4\n" +
|
|
|
|
|
" and a.fdateend >convert(varchar(100),getDate(),23)" +
|
|
|
|
|
" group by a.fobjid\n" +
|
|
|
|
|
" having count(*) > 1) and ftype=4\n";
|
|
|
|
|
rs.execute(deleRepeatSql);
|
|
|
|
|
// 8、同步分部人数
|
|
|
|
|
String queryAllSubCompanySql = "select id,subcompanyname,supsubcomid from hrmsubcompany a where isnull(a.canceled,0)='0'";
|
|
|
|
|
rs.execute(queryAllSubCompanySql);
|
|
|
|
|
String allSupComIds = "";
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
allSupComIds = "";
|
|
|
|
|
recordSet.execute(" with children as\n" +
|
|
|
|
|
"(select id,supsubcomid from hrmsubcompany where id = '"+rs.getString("id")+"'\n" +
|
|
|
|
|
"union all \n" +
|
|
|
|
|
"select b.id,b.supsubcomid from children a inner join hrmsubcompany b on a.id=b.supsubcomid\n" +
|
|
|
|
|
")select distinct\n" +
|
|
|
|
|
"STUFF((select ',' + cast(c.id as varchar(10)) from children c\n" +
|
|
|
|
|
"for XML path('')),1,1,'') as allSupCom from children");
|
|
|
|
|
if (recordSet.next()) {
|
|
|
|
|
allSupComIds = Util.null2String(recordSet.getString("allSupCom"));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(allSupComIds)) {
|
|
|
|
|
recordSet.execute("update jcl_org_map set fonjob = (\n" +
|
|
|
|
|
"select isnull(sum(fbrs),0) fbrs from (\n" +
|
|
|
|
|
"select subcompanyid1,count(id) fbrs from hrmresource where status<4 group by subcompanyid1) a\n" +
|
|
|
|
|
"where a.subcompanyid1 in ("+allSupComIds+")) " +
|
|
|
|
|
"where ftype=1 and fdateend>convert(varchar(100),getDate(),23) and fobjid=" + rs.getString("id"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "同步成功";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Author ml
|
|
|
|
|
* @Date 2023/3/7 15:47
|
|
|
|
|
* @Description 处理上级
|
|
|
|
|
*/
|
|
|
|
|
private void handleSuperior(String id, String managerid, String deptId) {
|
|
|
|
|
// 校验当前人员的直接上级是否在同一部门,如不在当前部门,map表中的上级应为部门id+
|
|
|
|
|
RecordSet rs = new RecordSet();
|
|
|
|
|
Boolean flag = checkManager(rs, managerid, deptId);
|
|
|
|
|
if (flag) {
|
|
|
|
|
rs.execute("insert into jcl_org_map\n" +
|
|
|
|
|
" (id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleaderimg,\n" +
|
|
|
|
|
" fleaderjobid,fleaderjob,fparentid,fobjparentid,\n" +
|
|
|
|
|
" fisvitual,fdatebegin,fdateend)\n" +
|
|
|
|
|
"select a.id+300000000,4,a.id,a.uuid,0,'行政维度',a.workcode,a.LASTNAME,a.messagerurl,\n" +
|
|
|
|
|
" b.id,b.jobtitlename, isnull( a.managerid, '' ) +300000000,a.managerid,\n" +
|
|
|
|
|
" 0,convert(varchar(100),getDate(),23), '2099-12-31'\n" +
|
|
|
|
|
"from hrmresource a\n" +
|
|
|
|
|
"left join hrmjobtitles b on a.jobtitle=b.id\n" +
|
|
|
|
|
"where a.status < 4 and a.id='" + id + "'");
|
|
|
|
|
// 找上级的上级
|
|
|
|
|
rs.execute("select id,managerid,departmentid from hrmresource where id='" + managerid + "'");
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
String supId = Util.null2String(rs.getString("id"));
|
|
|
|
|
String supManagerId = Util.null2String(rs.getString("managerid"));
|
|
|
|
|
String departmentid = Util.null2String(rs.getString("departmentid"));
|
|
|
|
|
handleSuperior(supId, supManagerId, departmentid);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
rs.execute("insert into jcl_org_map\n" +
|
|
|
|
|
" (id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleaderimg,\n" +
|
|
|
|
|
" fleaderjobid,fleaderjob,fparentid,fobjparentid,\n" +
|
|
|
|
|
" fisvitual,fdatebegin,fdateend)\n" +
|
|
|
|
|
"select a.id+300000000,4,a.id,a.uuid,0,'行政维度',a.workcode,a.LASTNAME,a.messagerurl,\n" +
|
|
|
|
|
" b.id,b.jobtitlename, isnull( cast(c.BMFZR as varchar(10)), '' ) +200000000,cast(c.BMFZR as varchar(10)),\n" +
|
|
|
|
|
" 0,convert(varchar(100),getDate(),23), '2099-12-31'\n" +
|
|
|
|
|
"from hrmresource a\n" +
|
|
|
|
|
"left join hrmjobtitles b on a.jobtitle=b.id\n" +
|
|
|
|
|
"left join hrmdepartmentdefined c on a.departmentid=c.deptid\n"+
|
|
|
|
|
"where a.status < 4 and a.id='" + id + "'");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Author ml
|
|
|
|
|
* @Date 2023/3/7 17:14
|
|
|
|
|
* @Description 校验上级是否在当前部门
|
|
|
|
|
*/
|
|
|
|
|
private Boolean checkManager(RecordSet recordSet, String managerid, String deptId) {
|
|
|
|
|
Boolean flag = false;
|
|
|
|
|
recordSet.execute("select departmentid from hrmresource where id='" + managerid + "'");
|
|
|
|
|
if (recordSet.next()) {
|
|
|
|
|
if (deptId.equals(Util.null2String(recordSet.getString("departmentid")))) {
|
|
|
|
|
flag = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 刷新在岗、编制数
|
|
|
|
|
*/
|
|
|
|
|