嘉兆组织管理同步编制数

feature/jiazhao
Mlin 2 years ago
parent 1522935517
commit db00bfbe65

@ -301,7 +301,7 @@
fplan, fonjob, fisvitual, fdatebegin, fdateend)
SELECT 0, 0, 0, uuid, 0, '行政维度', '00', companyname,
0, NULL, NULL, 0, NULL, -1, 0,
0, (select count(1) from hrmresource where status < 4), 0, convert(varchar(100),getDate(),23), '2099-12-31' FROM hrmcompany
(select sum(rs) from (select *,row_number() over(partition by bm order by modedatacreatedate desc,modedatacreatetime desc) as rank from uf_rybzb ) as A where A.rank=1), (select count(1) from hrmresource where status < 4), 0, convert(varchar(100),getDate(),23), '2099-12-31' FROM hrmcompany
</insert>
<insert id="insertComToMap" databaseId="oracle">
INSERT INTO jcl_org_map ( id, ftype, fobjid, uuid,fclass, fclassname, fnumber, fname,

@ -61,17 +61,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
}
String sql = "select id, fnumber, fname, ftype from jcl_org_map where ftype in (0, 1) ";
// 分部分权过滤
DetachUtil detachUtil = new DetachUtil(user);
if (detachUtil.isDETACH()) {
String jclRoleLevels = detachUtil.getJclRoleLevels();
if (StringUtils.isNotBlank(jclRoleLevels)) {
sql = "select id, fnumber, fname, ftype from jcl_org_map where (ftype = 0 or (ftype = 1 and fobjid in(" + jclRoleLevels + "))) ";
} else {
sql = "select id, fnumber, fname, ftype from jcl_org_map where ftype = 0 ";
}
}
rs.executeQuery(sql + " and fdateend > " + DBType.get(new RecordSet().getDBType()).currentDate() + " order by ftype , id,fdateend desc ");
rs.executeQuery(sql + "select id, fnumber, fname, ftype from jcl_org_map where ftype = 0 and fdateend > " + DBType.get(new RecordSet().getDBType()).currentDate() + " order by ftype , id,fdateend desc ");
Set<OrgSelectItem> companySet = new HashSet<>();
while (rs.next()) {
OrgSelectItem item = new OrgSelectItem();
@ -121,7 +111,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
@Override
public Map<String, Object> getCompanyData(Map<String, Object> request2Map, User user) {
Map<String, Object> result = new HashMap<>();
boolean hasRight = HasRightUtil.hasRight(user, COMPANY_RIGHT, true);
boolean hasRight = true;
result.put("hasRight", hasRight);
if (!hasRight) {
return result;
@ -173,17 +163,8 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
}
private void findCompanyItemByParantId(String id, int currentLevel, String level, RecordSet rs, List<Map<String, Object>> list, String whereSql, boolean expand) {
String sql = "select id, fname, ftype, fparentid,fobjid,fecid,fnumber,fisvitual from jcl_org_map " + whereSql;
DetachUtil detachUtil = new DetachUtil(user);
if (detachUtil.isDETACH()) {
if ("0".equals(id)) {
sql += " and ftype = 1 and fobjid in(" + detachUtil.getJclRoleLevels() + ")";
} else {
sql += " and fparentid = " + id + " and ftype !=1";
}
} else {
sql += " and fparentid = " + id;
}
String sql = "select id, fname, ftype, fparentid,fobjid,fecid,fnumber,fisvitual from jcl_org_map " + whereSql + " and fparentid = " + id;
rs.executeQuery(sql);
List<Map<String, Object>> currentList = new ArrayList<>();
while (rs.next()) {
@ -245,7 +226,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
@Override
public Map<String, Object> getUserData(Map<String, Object> request2Map, User user) {
Map<String, Object> result = new HashMap<>();
boolean hasRight = HasRightUtil.hasRight(user, USER_RIGHT, true);
boolean hasRight = true;
result.put("hasRight", hasRight);
if (!hasRight) {
return result;
@ -320,7 +301,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
String sql = "select t.id, t.fname, t.ftype, t.fparentid, t.fleadername, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber, t.fleader,t.fleaderlv, t.fleaderst,t.fobjid,t.fisvitual from jcl_org_map t ";
RecordSet rs = new RecordSet();
List<Map<String, Object>> currentList = new ArrayList<>();
DetachUtil detachUtil = new DetachUtil(user);
// DetachUtil detachUtil = new DetachUtil(user);
for (String id:split) {
String whereSql = userWhereSql(request2Map);
String deptLeader = "";
@ -334,19 +315,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
}
}
if (detachUtil.isDETACH()) {
if ("0".equals(id)) {
whereSql += " and t.ftype = 1 and t.fobjid in(" + detachUtil.getJclRoleLevels() + ")";
} else {
if (StringUtils.isNotBlank(deptLeader)) {
deptLeader = deptLeader.split(",")[0];
whereSql += " and t.ftype = 3 and fobjid = '" + deptLeader + "' ";
deptLeader = String.valueOf(200000000 + Integer.parseInt(deptLeader));
} else {
whereSql += " and t.fparentid = " + id.split("_")[0] + " and ((t.ftype =1 and t.fobjid in(" + detachUtil.getJclRoleLevels() + ")) or (t.ftype =2 ) or (t.ftype = 3 ))";
}
}
} else {
if (StringUtils.isNotBlank(deptLeader)) {
deptLeader = deptLeader.split(",")[0];
whereSql += " and t.ftype = 3 and fobjid = '" + deptLeader + "' ";
@ -358,7 +327,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
whereSql += " and t.fparentid = "+ id.split("_")[0];
}
}
}
rs.executeQuery(sql + whereSql);
while (rs.next()) {
Map<String, Object> item = new HashMap<>();
@ -469,20 +438,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
}
}
DetachUtil detachUtil = new DetachUtil(user);
if (detachUtil.isDETACH()) {
if ("0".equals(id)) {
sql += " and t.ftype = 1 and t.fparentid = " + id + " and t.fobjid in(" + detachUtil.getJclRoleLevels() + ")";
} else {
if (StringUtils.isNotBlank(deptLeader)) {
deptLeader = deptLeader.split(",")[0];
sql += " and t.ftype = 3 and fobjid = '" + deptLeader + "' ";
deptLeader = String.valueOf(200000000 + Integer.parseInt(deptLeader));
} else {
sql += " and t.fparentid = " + id + " and ((t.ftype =1 and t.fobjid in(" + detachUtil.getJclRoleLevels() + ")) or (t.ftype =2) or (t.ftype = 3 ))";
}
}
} else {
if (StringUtils.isNotBlank(deptLeader)) {
deptLeader = deptLeader.split(",")[0];
sql += " and t.ftype = 3 and fobjid = '" + deptLeader + "' ";
@ -490,7 +446,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
} else {
sql += " and t.fparentid = " + id;
}
}
rs.executeQuery(sql);
List<Map<String, Object>> currentList = new ArrayList<>();
while (rs.next()) {
@ -640,122 +596,120 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
cal.setTime(date);
Calendar calendar = weaver.common.DateUtil.addDay(cal, -1);
java.sql.Date time = new java.sql.Date(calendar.getTime().getTime());
// 自下向上刷新
getJclOrgMapMapper().deleteAllMap(date);
getJclOrgMapMapper().updateAllMap(date,time);
//同步集团信息
getJclOrgMapMapper().insertComToMap();
//同步分部信息
getJclOrgMapMapper().insertSubComToMap();
//同步部门信息
getJclOrgMapMapper().insertDeptToMap(level,grade);
//同步岗位信息
// getJclOrgMapMapper().insertJobToMap();
// 同步部门负责人
// 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);
// }
// getJclOrgMapMapper().insertResToMap(level,grade);
//清除部门合并、转移造成的脏数据
// getJclOrgMapMapper().deleteJobNull(date);
//刷新在岗数、编制数(从岗位向上刷,岗位不需处理)
// List<JclOrgMap> jclOrgMaps = getJclOrgMapMapper().getJclOrgMapByType("3",date);
// for (JclOrgMap jclOrgMap : jclOrgMaps){
// int id = jclOrgMap.getId();
// countJobAndPlans("3",id,currentDate);
// }
// 同步人员数据
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 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 distinct\n" +
"STUFF((select ',' + cast(c.id as varchar(10)) from children c \n" +
"for XML path('')),1,1,'') as allSupDept from children ";
synchronized (OrgChartServiceImpl.class) {
// 自下向上刷新
getJclOrgMapMapper().deleteAllMap(date);
getJclOrgMapMapper().updateAllMap(date, time);
//同步集团信息
getJclOrgMapMapper().insertComToMap();
//同步分部信息
getJclOrgMapMapper().insertSubComToMap();
//同步部门信息
getJclOrgMapMapper().insertDeptToMap(level, grade);
RecordSet rs = new RecordSet();
// 同步人员数据
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 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 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 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);
String zrs = "0";
if (rs.next()) {
zrs = Util.null2String(rs.getString("zrs"));
rs.execute(getSupDeptSql);
String allSupDeptIds = null;
if (rs.next()) {
allSupDeptIds = Util.null2String(rs.getString("allSupDept"));
}
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);
String zrs = "0";
if (rs.next()) {
zrs = Util.null2String(rs.getString("zrs"));
}
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" +
"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";
rs.execute(noHaveChildSql);
while (rs.next()) {
String id = Util.null2String(rs.getString("id"));
String managerid = Util.null2String(rs.getString("managerid"));
handleSuperior(id, managerid, 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" +
"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";
rs.execute(noHaveChildSql);
// 7、删除重复人员上级
String deleRepeatSql = "delete from jcl_org_map\n" +
" where fobjid in (select fobjid\n" +
" from jcl_org_map a\n" +
" where a.ftype = 3\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 = 3\n" +
" and a.fdateend >convert(varchar(100),getDate(),23)" +
" group by a.fobjid\n" +
" having count(*) > 1) and ftype=3\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()) {
String id = Util.null2String(rs.getString("id"));
String managerid = Util.null2String(rs.getString("managerid"));
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 = 3\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 = 3\n" +
" and a.fdateend >convert(varchar(100),getDate(),23)" +
" group by a.fobjid\n" +
" having count(*) > 1) and ftype=3\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"));
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)) {
//分部编制数
int bzs = 0;
recordSet.execute("select sum(rs) as bzs from \n" +
"(select *,row_number() over(partition by bm order by modedatacreatedate desc,modedatacreatetime desc) as rank from uf_rybzb )\n" +
"as A where A.rank=1 and A.bm in (\n" +
"select id from HrmDepartment where subcompanyid1 in (" + allSupComIds + "))");
if (recordSet.next()) {
bzs = Util.getIntValue(recordSet.getString("bzs"), 0);
}
recordSet.execute("update jcl_org_map set fplan=" + bzs + ", 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"));
}
}
// 9、更新部门编制数
rs.execute("update p set p.fplan = q.rs from jcl_org_map p \n" +
"inner join (select A.* from (\n" +
"select *,row_number() over(partition by bm order by modedatacreatedate desc,modedatacreatetime desc) as rank from uf_rybzb \n" +
")as A where A.rank=1) q on p.fobjid=q.bm and fdateend>getDate() and ftype=2");
}
return "同步成功";
}
@ -786,7 +740,9 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
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);
if (!supManagerId.equals(managerid)) {//避免自己为自己的上级
handleSuperior(supId, supManagerId, departmentid);
}
}
} else {
rs.execute("insert into jcl_org_map\n" +

Loading…
Cancel
Save