Compare commits

...

11 Commits

@ -48,4 +48,10 @@ public interface JclOrgMapper {
JclOrgMap getResInfo(@Param("level") String level, @Param("grade") String grade, @Param("id") String id);
JclOrgMap getJclOrgMapByManagerIdAndDeptId(@Param("managerId") String managerId,@Param("deptId") String deptId);
int insertResToMapJZ(@Param("level") String level, @Param("grade") String grade, @Param("parentField") String parentField, @Param("managerId") String managerId, @Param("deptId") String deptId);
int insertBmfzrToMapJZ(@Param("level") String level, @Param("grade") String grade);
}

@ -50,7 +50,7 @@
AND FDATEEND >= #{currentDate}
</select>
<select id="getSumPlanAndJobByFParentId" resultType="com.engine.organization.entity.map.JclOrgMap">
select sum(fplan) fplan,sum(fonjob) fonjob
select sum(isNull(fplan,0)) fplan,sum(isNull(fonjob,0)) fonjob
from jcl_org_map
where fparentid = #{fparentid}
AND FDATEBEGIN &lt;= #{currentDate}
@ -236,7 +236,7 @@
0,0,0,NOW(),'2099-12-31'
from
HrmDepartment as a
left join hrmdepartmentdefined as b on a.id=b.deptid
left join hrmdepartmentdefined as b on a.id=b.deptid and b.zzjgxs=1
left join hrmresource as c on b.BMFZR=c.ID
left join hrmjobtitles as d on c.JOBTITLE=d.id
left join cus_fielddata e on c.id = e.id and e.scope='HrmCustomFieldByInfoType' and e.scopeid=3
@ -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, 0, 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 &lt; 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,
@ -309,7 +309,7 @@
fplan, fonjob, fisvitual, fdatebegin, fdateend)
SELECT 0, 0, 0, uuid, 0, '行政维度', '00', companyname,
0, NULL, NULL, 0, NULL, -1, 0,
0, 0, 0, TO_DATE(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd'), TO_DATE('2099-12-31','yyyy-MM-dd') FROM hrmcompany
0, (select count(1) from hrmresource where status &lt; 4), 0, TO_DATE(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd'), TO_DATE('2099-12-31','yyyy-MM-dd') FROM hrmcompany
</insert>
<insert id="insertComToMap" databaseId="mysql">
INSERT INTO jcl_org_map ( id, ftype, fobjid, uuid,fclass, fclassname, fnumber, fname,
@ -317,7 +317,7 @@
fplan, fonjob, fisvitual, fdatebegin, fdateend)
SELECT 0, 0, 0, uuid, 0, '行政维度', '00', companyname,
0, NULL, NULL, 0, NULL, -1, 0,
0, 0, 0, NOW(), '2099-12-31' FROM hrmcompany
0, (select count(1) from hrmresource where status &lt; 4), 0, NOW(), '2099-12-31' FROM hrmcompany
</insert>
<delete id="deleteJobNull">
delete from jcl_org_map where ftype =3 and fdateend &gt; #{currentDate} and id not in (select a.FPARENTID from (select FPARENTID from jcl_org_map where ftype=4 and fdateend &gt; #{currentDate}) a)
@ -331,4 +331,77 @@
left join jcl_org_grade f on d.${grade}=f.id
where a.id=#{id}
</select>
<select id="getJclOrgMapByManagerIdAndDeptId" resultType="com.engine.organization.entity.map.JclOrgMap">
</select>
<!-- 嘉兆:下级人员初始化 -->
<insert id="insertResToMapJZ" databaseId="mysql">
insert into jcl_org_map
(id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleaderimg,
fleaderjobid,fleaderjob,fleaderlv,fleaderst,fparentid,fobjparentid,
fisvitual,fdatebegin,fdateend)
select a.id+300000000,4,a.id,a.uuid,0,'行政维度',a.workcode,a.LASTNAME,a.messagerurl,
c.id,c.jobtitlename,e.level_name,f.grade_name, ${parentField},a.MANAGERID,
0,NOW(),'2099-12-31'
from hrmresource a
left join jcl_org_job b ON a.JOBTITLE = b.ec_jobTitle and a.subcompanyid1=b.ec_company and a.departmentid=b.ec_department
left join HrmJobTitles c on b.ec_jobTitle = c.id
left join cus_fielddata d on a.id = d.id and d.scope='HrmCustomFieldByInfoType' and d.scopeid=3
left join jcl_org_level e on d.${level}=e.id
left join jcl_org_grade f on d.${grade}=f.id
where a.status &lt; 4 and a.MANAGERID=#{managerId} and a.departmentid=#{deptId}
</insert>
<insert id="insertResToMapJZ" databaseId="sqlserver">
insert into jcl_org_map
(id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleaderimg,
fleaderjobid,fleaderjob,fleaderlv,fleaderst,fparentid,fobjparentid,
fisvitual,fdatebegin,fdateend)
select a.id+300000000,4,a.id,a.uuid,0,'行政维度',a.workcode,a.LASTNAME,a.messagerurl,
c.id,c.jobtitlename,e.level_name,f.grade_name, ${parentField},a.MANAGERID,
0,convert(varchar(100),getDate(),23),'2099-12-31'
from hrmresource a
left join jcl_org_job b ON a.JOBTITLE = b.ec_jobTitle and a.subcompanyid1=b.ec_company and a.departmentid=b.ec_department
left join HrmJobTitles c on b.ec_jobTitle = c.id
left join cus_fielddata d on a.id = d.id and d.scope='HrmCustomFieldByInfoType' and d.scopeid=3
left join jcl_org_level e on d.${level}=e.id
left join jcl_org_grade f on d.${grade}=f.id
where a.status &lt; 4 and a.MANAGERID=#{managerId} and a.departmentid=#{deptId}
</insert>
<!-- 嘉兆:部门负责人初始化 -->
<insert id="insertBmfzrToMapJZ" databaseId="mysql">
insert into jcl_org_map
(id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleaderimg,
fleaderjobid,fleaderjob,fleaderlv,fleaderst,fparentid,fobjparentid,
fisvitual,fdatebegin,fdateend,this_dept)
select c.id+200000000,3,c.id,c.uuid,0,'行政维度',c.workcode,c.LASTNAME,c.messagerurl,
e.id,e.jobtitlename,g.level_name,h.grade_name, a.id +100000000,a.id,
0,NOW(),'2099-12-31',(case when a.id=c.departmentid then '1' else '0' end) this_dept
from hrmdepartment a
inner join hrmdepartmentdefined b on a.id=b.DEPTID and b.zzjgxs=1
inner join hrmresource c on b.BMFZR=c.id
left join jcl_org_job d on c.jobtitle = d.ec_jobTitle and c.SUBCOMPANYID1=d.ec_company and c.DEPARTMENTID=d.ec_department
left join hrmjobtitles e on d.ec_jobTitle=e.id
left join cus_fielddata f on c.id = f.id and f.scope='HrmCustomFieldByInfoType' and f.scopeid=3
left join jcl_org_level g on f.${level}=g.id
left join jcl_org_grade h on f.${grade}=h.id
</insert>
<insert id="insertBmfzrToMapJZ" databaseId="sqlserver">
insert into jcl_org_map
(id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleaderimg,
fleaderjobid,fleaderjob,fleaderlv,fleaderst,fparentid,fobjparentid,
fisvitual,fdatebegin,fdateend,this_dept)
select c.id+200000000,3,c.id,c.uuid,0,'行政维度',c.workcode,c.LASTNAME,c.messagerurl,
e.id,e.jobtitlename,g.level_name,h.grade_name, a.id +100000000,a.id,
0,convert(varchar(100),getDate(),23),'2099-12-31',(case when a.id=c.departmentid then '1' else '0' end) this_dept
from hrmdepartment a
inner join hrmdepartmentdefined b on a.id=b.DEPTID and b.zzjgxs=1
inner join hrmresource c on cast(b.BMFZR as varchar(10))=cast(c.ID as varchar(10))
left join jcl_org_job d on c.jobtitle = d.ec_jobTitle and c.SUBCOMPANYID1=d.ec_company and c.DEPARTMENTID=d.ec_department
left join hrmjobtitles e on d.ec_jobTitle=e.id
left join cus_fielddata f on c.id = f.id and f.scope='HrmCustomFieldByInfoType' and f.scopeid=3
left join jcl_org_level g on f.${level}=g.id
left join jcl_org_grade h on f.${grade}=h.id
</insert>
</mapper>

@ -38,5 +38,6 @@ public interface ResourceMapper {
*/
List<Long> getIdByKeyField(@Param("keyField") String keyField, @Param("keyFieldValue") String keyFieldValue);
List<HrmResourcePO> getHrmByManagerIdAndDeptId(@Param("managerId") String managerId, @Param("deptId") String deptId);
}

@ -155,6 +155,9 @@
AND t.last_name like '%'+#{param.lastName}+'%'
</if>
</sql>
<select id="getHrmByManagerIdAndDeptId" resultType="com.engine.organization.entity.hrmresource.po.HrmResourcePO" databaseId="sqlserver">
select a.id,a.workcode,a.lastName,a.sex,a.accountType,a.belongTo,a.departmentId
from hrmresource a where a.MANAGERID=#{managerId} and a.DEPARTMENTID=#{deptId}
</select>
</mapper>

@ -137,7 +137,7 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic
table.setSqlwhere(sqlWhere);
List<WeaTableColumn> weaTableColumnList = new ArrayList<>();
JclOrgCustomTemplatePO jclOrgCustomTemplatePO = MapperProxyFactory.getProxy(JclOrgCustomTemplateMapper.class).queryIsusedTemp("1", String.valueOf(user.getUID()));
String columns = null;
String columns = "";
List<String> fields = new ArrayList<>();
List<SearchConditionGroup> allConditions = getAllConditions();
@ -638,7 +638,8 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic
DBType dbType = DBType.get(new RecordSet().getDBType());
StringBuilder sb = new StringBuilder(" where 1=1 ");
if (params.containsKey("lastName")) {
sb.append(" and t.status = 1");
// sb.append(" and t.status = 1");
sb.append(" and t.status < 4");
}
for (Map.Entry<String, Object> entry : params.entrySet()) {
String key = entry.getKey();
@ -659,6 +660,9 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic
JobPO jobById = getJobMapper().getJobById(Long.parseLong(value));
if (null != jobById) {
sb.append(" and t.jobtitle ='").append(Util.null2String(jobById.getEcJobTitle())).append("' and t.subcompanyid1 = '").append(Util.null2String(jobById.getEcCompany())).append("' and t.departmentId ='").append(Util.null2String(jobById.getEcDepartment())).append("'");
} else {
sb = new StringBuilder(" where 1 = 2 ");
break;
}
}
@ -1097,8 +1101,12 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic
break;
case SELECT://选择框
if (!"-1".equals(value)) {
if ("t.status".equalsIgnoreCase(tableSql) && "10".equals(value)) {
sb.append(" and ").append(tableSql).append(" < 4 ");
} else {
sb.append(" and ").append(tableSql).append(" = '").append(value).append("' ");
}
}
break;
case DATE:
case DATEPICKER:
@ -1168,15 +1176,15 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic
private void addEmptyForSelect(SearchConditionItem searchConditionItem) {
searchConditionItem.setValue("-1");
if ("-1_hrm_status".equals(searchConditionItem.getDomkey()[0])) {
searchConditionItem.setValue("1");
// 默认赋值 在职状态
searchConditionItem.setValue("10");
}
List<SearchConditionOption> options = searchConditionItem.getOptions();
SearchConditionOption searchConditionOption = new SearchConditionOption();
searchConditionOption.setKey("-1");
searchConditionOption.setShowname("全部");
options.add(0, searchConditionOption);
options.forEach(item -> {
item.setSelected(false);
});
options.forEach(item -> item.setSelected(false));
}
/**

@ -3,11 +3,13 @@ package com.engine.organization.service.impl;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import com.engine.core.impl.Service;
import com.engine.organization.entity.hrmresource.po.HrmResourcePO;
import com.engine.organization.entity.map.JclOrgMap;
import com.engine.organization.entity.scheme.po.GradePO;
import com.engine.organization.entity.scheme.po.LevelPO;
import com.engine.organization.entity.staff.po.StaffPO;
import com.engine.organization.mapper.jclorgmap.JclOrgMapper;
import com.engine.organization.mapper.resource.ResourceMapper;
import com.engine.organization.mapper.scheme.GradeMapper;
import com.engine.organization.mapper.scheme.LevelMapper;
import com.engine.organization.mapper.staff.StaffMapper;
@ -17,6 +19,7 @@ import com.engine.organization.util.OrganizationDateUtil;
import com.engine.organization.util.db.DBType;
import com.engine.organization.util.db.MapperProxyFactory;
import com.engine.organization.util.detach.DetachUtil;
import com.weaver.formmodel.util.DateHelper;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.general.Util;
@ -60,15 +63,15 @@ 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 ";
}
}
// 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 ");
Set<OrgSelectItem> companySet = new HashSet<>();
while (rs.next()) {
@ -119,7 +122,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;
@ -171,17 +174,16 @@ 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; 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;
// }
rs.executeQuery(sql);
List<Map<String, Object>> currentList = new ArrayList<>();
while (rs.next()) {
@ -243,7 +245,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;
@ -268,6 +270,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
rs.executeQuery("select t.id, t.fname, t.ftype, t.fparentid, t.fleadername,t.fobjid,t.fecid, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber, t.fleader, t.fleaderlv, t.fleaderst, t.fecid, t.fisvitual from jcl_org_map t " + whereSql + whereItemSql);
List<Map<String, Object>> list = new ArrayList<>();
String id = null;
String type = "0";
if (rs.next()) {
Map<String, Object> item = new HashMap<>();
id = rs.getString("id");
@ -300,7 +303,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
}
int currentLevel = 1;
findUserItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, currentLevel + 1 <= Integer.parseInt(level));
findUserItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, currentLevel + 1 <= Integer.parseInt(level),type,null);
// 分部数据,构建层级关系
reBuildTreeList(list, root);
@ -313,23 +316,61 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
@Override
public Map<String, Object> asyncUserData(Map<String, Object> request2Map, User user) {
String ids = (String) request2Map.get("ids");
String whereSql = userWhereSql(request2Map);
whereSql += " and fparentid in (" + ids + ") ";
String[] split = ids.split(",");
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();
rs.executeQuery("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 " + whereSql);
List<Map<String, Object>> currentList = new ArrayList<>();
// DetachUtil detachUtil = new DetachUtil(user);
for (String id:split) {
String whereSql = userWhereSql(request2Map);
String deptLeader = "";
if (id.contains("_")) {
whereSql += " and t.id != '" + id.split("_")[1] + "'";
} else if (Integer.parseInt(id) > 100000000 && Integer.parseInt(id) < 200000000) {
rs.executeQuery(sql + whereSql + " and id = ? ", id);
if (rs.next()) {
deptLeader = rs.getString("fleader");
}
}
// 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 + "' ";
deptLeader = String.valueOf(200000000 + Integer.parseInt(deptLeader));
} else {
if (checkDeptManager(id.split("_")[0],whereSql)){
// whereSql += " and t.fparentid = "+ id.split("_")[0] +" or t.fparentid = "+ id.split("_")[1];
whereSql += " and t.fparentid = "+ id.split("_")[1];
}else{
whereSql += " and t.fparentid = "+ id.split("_")[0];
}
}
// }
rs.executeQuery(sql + whereSql);
while (rs.next()) {
Map<String, Object> item = new HashMap<>();
item.put("id", rs.getString("id"));
item.put("fname", rs.getString("fname"));
item.put("ftype", rs.getString("ftype"));
item.put("parentId", rs.getString("fparentid"));
item.put("parentId", id.contains("_") ? id : rs.getString("fparentid"));
item.put("fplan", rs.getString("fplan"));
item.put("fonjob", rs.getString("fonjob"));
item.put("fnumber", rs.getString("fnumber"));
item.put("hasChildren", hasChildren(rs.getString("id"), false));
// item.put("hasChildren", hasChildren(rs.getString("id"), false));
if (rs.getString("ftype").equals("2")) {
JclOrgMap jclOrgMap = getBmfzrInfo(rs.getString("fleader"));
item.put("fleader", jclOrgMap.getFLeader() == null ? "" : String.valueOf(jclOrgMap.getFLeader()));
@ -348,10 +389,19 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
}
item.put("fobjid", rs.getString("fobjid"));
item.put("fisvitual", rs.getString("fisvitual"));
if (deptLeader.equals(item.get("id"))) {
item.put("id", id + "_" + deptLeader);
item.put("parentId", id);
item.put("hasChildren", hasChildren(id, false));
item.put("this_dept",checkDeptManager(id,whereSql)?1:0);
} else {
item.put("hasChildren", hasChildren(rs.getString("id"), false));
}
currentList.add(item);
}
}
Map<String, Object> result = new HashMap<>();
result.put("api_status", true);
result.put("data", currentList);
@ -400,18 +450,49 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
return jclOrgMap;
}
private void findUserItemByParantId(String id, int currentLevel, String level, RecordSet rs, List<Map<String, Object>> list, String whereSql, boolean expand) {
private void findUserItemByParantId(String id, int currentLevel, String level, RecordSet rs, List<Map<String, Object>> list, String whereSql, boolean expand, String type, String parentDeptId) {
String sql = "select t.id, t.fname, t.ftype, t.fparentid, t.fobjparentid, t.fleader, t.fleadername, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber, t.fobjid, t.fecid, t.fleaderlv, t.fleaderst, t.fisvitual from jcl_org_map t " + whereSql;
DetachUtil detachUtil = new DetachUtil(user);
if (detachUtil.isDETACH()) {
if ("0".equals(id)) {
sql += " and t.ftype = 1 and t.fobjid in(" + detachUtil.getJclRoleLevels() + ")";
} else {
sql += " and t.fparentid = " + id + " and t.ftype !=1";
}
String deptLeader = "";
String manageDeptId = "";
if ("2".equals(type)) {
rs.executeQuery(sql +" and t.ftype = '2' and t.fobjid = '" + parentDeptId + "'");
if (rs.next()) {
deptLeader = rs.getString("fleader");
}
}
if ("3".equals(type)) {
manageDeptId = id;
id = id.split("_")[0];
//sql += " and ftype = 3 ";
if (manageDeptId.contains("_")) {
sql += " and t.id != '" + manageDeptId.split("_")[1] + "'";
}
}
// 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() + ")";
// sql += " and t.ftype = 1 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 + "' ";
deptLeader = String.valueOf(200000000 + Integer.parseInt(deptLeader));
} else {
sql += " and t.fparentid = " + id;
}
// }
rs.executeQuery(sql);
List<Map<String, Object>> currentList = new ArrayList<>();
while (rs.next()) {
@ -419,7 +500,11 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
item.put("id", rs.getString("id"));
item.put("fname", rs.getString("fname"));
item.put("ftype", rs.getString("ftype"));
if ("3".equals(type)) {
item.put("parentId", manageDeptId);
} else {
item.put("parentId", rs.getString("fparentid"));
}
item.put("fobjparentId", rs.getString("fobjparentid"));
item.put("fplan", rs.getString("fplan"));
item.put("fonjob", rs.getString("fonjob"));
@ -427,6 +512,8 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
item.put("expand", expand ? "1" : "0");
item.put("fobjid", rs.getString("fobjid"));
item.put("fecid", rs.getString("fecid"));
if (rs.getString("ftype").equals("2")) {
JclOrgMap jclOrgMap = getBmfzrInfo(rs.getString("fleader"));
item.put("fleader", jclOrgMap.getFLeader() == null ? "" : String.valueOf(jclOrgMap.getFLeader()));
@ -444,30 +531,38 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
item.put("fleaderst", convertGrade(rs.getString("fleaderst")));
}
item.put("fisvitual", rs.getString("fisvitual"));
if (deptLeader.equals(item.get("id"))) {
item.put("id", id + "_" + deptLeader);
item.put("parentId", id);
item.put("hasChildren", hasChildren(id, false));
item.put("this_dept",checkDeptManager(id,whereSql)?1:0);
} else {
item.put("hasChildren", hasChildren(rs.getString("id"), false));
}
currentList.add(item);
}
for (Map<String, Object> stringObjectMap : currentList) {
if ("4".equals(stringObjectMap.get("ftype"))) { // 员工信息
rs.executeQuery("select id, mobile, homeaddress from hrmresource where id = ? ", stringObjectMap.get("fnumber"));
if (rs.next()) {
stringObjectMap.put("mobile", rs.getString("mobile"));
stringObjectMap.put("address", rs.getString("homeaddress"));
}
rs.executeQuery("select departmentname from hrmresource hrm \n" +
"left join hrmdepartment d\n" +
"on hrm.departmentid = d.id\n" +
"where hrm.id = ? ", stringObjectMap.get("fnumber"));
if (rs.next()) {
stringObjectMap.put("department", rs.getString("departmentname"));
}
}
// if ("4".equals(stringObjectMap.get("ftype"))) { // 员工信息
// rs.executeQuery("select id, mobile, homeaddress from hrmresource where id = ? ", stringObjectMap.get("fnumber"));
// if (rs.next()) {
// stringObjectMap.put("mobile", rs.getString("mobile"));
// stringObjectMap.put("address", rs.getString("homeaddress"));
// }
// rs.executeQuery("select departmentname from hrmresource hrm \n" +
// "left join hrmdepartment d\n" +
// "on hrm.departmentid = d.id\n" +
// "where hrm.id = ? ", stringObjectMap.get("fnumber"));
// if (rs.next()) {
// stringObjectMap.put("department", rs.getString("departmentname"));
// }
//
// }
String fType = Util.null2String(stringObjectMap.get("ftype"));
if (currentLevel + 1 <= Integer.parseInt(level)) {
findUserItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, true);
findUserItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, true, fType, Util.null2String(stringObjectMap.get("fobjid")));
} else if (currentLevel == Integer.parseInt(level)) { // 多查一层
findUserItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, false);
findUserItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, false, fType, Util.null2String(stringObjectMap.get("fobjid")));
}
}
list.addAll(currentList);
@ -547,29 +642,210 @@ 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());
synchronized (OrgChartServiceImpl.class) {
// 自下向上刷新
getJclOrgMapMapper().deleteAllMap(date);
getJclOrgMapMapper().updateAllMap(date,time);
//同步人员信息
getJclOrgMapMapper().insertResToMap(level,grade);
//同步岗位信息
getJclOrgMapMapper().insertJobToMap();
//同步部门信息
getJclOrgMapMapper().insertDeptToMap(level,grade);
//同步分部信息
getJclOrgMapMapper().insertSubComToMap();
getJclOrgMapMapper().updateAllMap(date, time);
//同步集团信息
getJclOrgMapMapper().insertComToMap();
//清除部门合并、转移造成的脏数据
getJclOrgMapMapper().deleteJobNull(date);
//刷新在岗数、编制数(从岗位向上刷,岗位不需处理)
List<JclOrgMap> jclOrgMaps = getJclOrgMapMapper().getJclOrgMapByType("3",date);
for (JclOrgMap jclOrgMap : jclOrgMaps){
int id = jclOrgMap.getId();
countJobAndPlans("3",id,currentDate);
//同步分部信息
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("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);
}
}
// 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 = "";
String currentMonth = DateHelper.getCurrentMonth();
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)) {
//分部编制数
int bzs = 0;
recordSet.execute("select sum(rs) as bzs from \n" +
"(select *,row_number() over(partition by bm order by ny desc) as rank from uf_rybzb where ny='"+currentMonth+"' )\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 ny desc) as rank from uf_rybzb where ny='"+currentMonth+"' \n" +
")as A where A.rank=1) q on p.fobjid=q.bm and fdateend>getDate() and ftype=2");
}
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+200000000,3,a.id,a.uuid,0,'行政维度',a.workcode,a.LASTNAME,a.messagerurl,\n" +
" b.id,b.jobtitlename, isnull( a.managerid, '' ) +200000000,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"));
if (!supManagerId.equals(managerid)) {//避免自己为自己的上级
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+200000000,3,a.id,a.uuid,0,'行政维度',a.workcode,a.LASTNAME,a.messagerurl,\n" +
" b.id,b.jobtitlename, isnull( a.departmentid, '' ) +100000000,a.departmentid,\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 + "'");
}
}
/**
* @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;
}
private Boolean checkDeptManager(String id,String whereSql) {
RecordSet recordSet = new RecordSet();
boolean flag = false;
String sql = "select fleader,fobjid,ftype from jcl_org_map t ";
if (StringUtils.isBlank(id)){
return false;
}
recordSet.executeQuery(sql + whereSql + " and t.id='"+id+"' ");
String fleader = "";
String fobjid = "";
String ftype = "";
if (recordSet.next()){
fleader = recordSet.getString("fleader");
fobjid = recordSet.getString("fobjid");
ftype = recordSet.getString("ftype");
}
recordSet.execute("select departmentid from hrmresource where id='" + fleader + "'");
if (recordSet.next()) {
if (fobjid.equals(Util.null2String(recordSet.getString("departmentid")))) {
flag = true;
}
}
return flag;
}
/**
*
*/
@ -605,6 +881,37 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
}
}
private ResourceMapper getResourceMapper() {
return MapperProxyFactory.getProxy(ResourceMapper.class);
}
private void syncHrmResource(String managerId, String deptId,int ftype) {
String parentField = "";
// 根据直接上级id、部门Id确认该直接上级id在当前部门的下属
switch (ftype) {
case 3:
parentField = "a.MANAGERID +200000000";
break;
case 4:
parentField = "a.MANAGERID +300000000";
break;
default: break;
}
int flag = getJclOrgMapMapper().insertResToMapJZ(level, grade,parentField, managerId, deptId);
// 下属寻找下属,直至没有下属
List<HrmResourcePO> list = getResourceMapper().getHrmByManagerIdAndDeptId(managerId, deptId);
for (HrmResourcePO hrmResourcePO : list) {
List<HrmResourcePO> childList = getResourceMapper().getHrmByManagerIdAndDeptId(String.valueOf(hrmResourcePO.getId()), deptId);
if (childList.size() > 0) {
parentField = "a.MANAGERID +300000000";
getJclOrgMapMapper().insertResToMapJZ(level, grade,parentField, String.valueOf(hrmResourcePO.getId()), deptId);
for (HrmResourcePO hrmResourcePOChild : childList) {
syncHrmResource(String.valueOf(hrmResourcePOChild.getId()), deptId,4);
}
}
}
}
private String getFieldName(String fieldabel) {
RecordSet recordSet = new RecordSet();
String fieldname = null;

Loading…
Cancel
Save