weaver-hrm-organization/src/com/engine/organization/service/impl/OrgChartServiceImpl.java

403 lines
17 KiB
Java
Raw Normal View History

2022-07-07 10:14:25 +08:00
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.service.OrgChartService;
2022-08-17 19:29:46 +08:00
import com.engine.organization.util.HasRightUtil;
2022-08-12 10:12:55 +08:00
import com.engine.organization.util.db.DBType;
2022-07-07 10:14:25 +08:00
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.hrm.User;
import java.util.*;
/**
* @className: OrgChartServiceImpl
* @author: dengjp
* @date: 2022/7/7
* @description: 组织架构图ServiceImpl
**/
public class OrgChartServiceImpl extends Service implements OrgChartService {
2022-07-21 11:01:36 +08:00
private RecordSet grs = new RecordSet();
2022-08-18 15:17:59 +08:00
private static final String COMPANY_RIGHT = "OrgChart:All";
private static final String USER_RIGHT = "OrgPerspective:All";
2022-07-07 10:14:25 +08:00
@Override
public Map<String, Object> getOptionCondition(Map<String, Object> request2Map, User user) {
2022-08-18 14:27:16 +08:00
Map<String, Object> result = new HashMap<>();
2022-07-07 10:14:25 +08:00
RecordSet rs = new RecordSet();
2022-08-18 14:27:16 +08:00
2022-07-07 10:14:25 +08:00
rs.executeQuery("select id, companyname from HrmCompanyVirtual order by id");
List<Map<String, Object>> fclasslist = new ArrayList<>();
Map<String, Object> defaultItem = new HashMap<>();
defaultItem.put("id", "0");
defaultItem.put("companyname", "行政维度");
fclasslist.add(defaultItem);
2022-08-12 10:12:55 +08:00
while (rs.next()) {
2022-07-07 10:14:25 +08:00
Map<String, Object> item = new HashMap<>();
item.put("id", rs.getString("id"));
item.put("companyname", rs.getString("companyname"));
fclasslist.add(item);
}
2022-08-10 15:35:43 +08:00
rs.executeQuery("select id, fnumber, fname from jcl_org_map where ftype in (0, 1) order by ftype , id ");
2022-07-07 10:14:25 +08:00
List<Map<String, Object>> companylist = new ArrayList<>();
Map<String, Object> defaultCompanyItem = new HashMap<>();
companylist.add(defaultCompanyItem);
2022-08-12 10:12:55 +08:00
while (rs.next()) {
2022-07-07 10:14:25 +08:00
Map<String, Object> item = new HashMap<>();
item.put("id", rs.getString("id"));
item.put("fnumber", rs.getString("fnumber"));
item.put("fname", rs.getString("fname"));
companylist.add(item);
}
result.put("api_status", true);
result.put("fclasslist", fclasslist);
result.put("companylist", companylist);
return result;
}
2022-07-21 11:56:54 +08:00
private String companyDateWhereSql(Map<String, Object> request2Map) {
2022-07-07 10:14:25 +08:00
String date = (String) request2Map.get("date"); // 数据日期
2022-08-12 10:12:55 +08:00
if (StringUtils.isBlank(date)) {
date = DateUtil.format(DateUtil.offset(new Date(), DateField.DAY_OF_MONTH, 1), "yyyy-MM-dd");
2022-07-07 10:14:25 +08:00
}
String fclass = (String) request2Map.get("fclass"); // 维度
2022-07-21 11:56:54 +08:00
2022-07-07 10:14:25 +08:00
String fisvitual = (String) request2Map.get("fisvitual"); // 是否显示虚拟组织
2022-08-12 10:12:55 +08:00
if (StringUtils.isBlank(fisvitual)) {
2022-07-07 10:14:25 +08:00
fisvitual = "0";
}
String whereSql = " where 1 = 1 ";
2022-08-12 10:12:55 +08:00
if (DBType.isOracle()) {
whereSql += " and ((fdatebegin <= to_date('" + date + "','yyyy-MM-DD') and fdateend >= to_date('" + date + "','yyyy-MM-DD')) or (fdatebegin <= to_date('" + date + "','yyyy-MM-DD') and fdateend is null )) ";
} else {
whereSql += " and ((fdatebegin <= '" + date + "' and fdateend >= '" + date + "') or (fdatebegin <= '" + date + "' and fdateend is null )) ";
}
whereSql += " and fclass = " + fclass + " ";
2022-07-07 10:14:25 +08:00
2022-08-12 10:12:55 +08:00
if ("0".equals(fisvitual)) {
2022-07-07 10:14:25 +08:00
whereSql += " and fisvitual = 0 ";
2022-08-12 10:12:55 +08:00
} else {
2022-07-07 10:14:25 +08:00
whereSql += " and fisvitual in (0, 1) ";
}
2022-07-21 11:01:36 +08:00
whereSql += " and ftype in (0 , 1 ,2) ";
2022-07-21 11:56:54 +08:00
return whereSql;
}
@Override
public Map<String, Object> getCompanyData(Map<String, Object> request2Map, User user) {
2022-08-18 15:17:59 +08:00
Map<String, Object> result = new HashMap<>();
boolean hasRight = HasRightUtil.hasRight(user, COMPANY_RIGHT, true);
result.put("hasRight", hasRight);
if (!hasRight) {
return result;
}
2022-07-21 11:56:54 +08:00
String root = (String) request2Map.get("root"); // 根节点
String level = (String) request2Map.get("level"); // 显示层级
2022-08-12 10:12:55 +08:00
if (StringUtils.isBlank(level)) {
2022-07-21 11:56:54 +08:00
level = "3";
}
String whereSql = companyDateWhereSql(request2Map);
2022-07-21 11:01:36 +08:00
2022-07-07 10:14:25 +08:00
String whereItemSql = " ";
2022-08-12 10:12:55 +08:00
if ("0".equals(root)) { // 集团的情况
2022-07-07 10:14:25 +08:00
whereItemSql += " and ftype = 0 ";
} else {
2022-08-12 10:12:55 +08:00
whereItemSql += " and id = '" + root + "' ";
2022-07-07 10:14:25 +08:00
}
// 获取根节点
RecordSet rs = new RecordSet();
2022-10-10 18:24:07 +08:00
rs.executeQuery("select id, fname, ftype, fparentid, fnumber, fobjid from jcl_org_map " + whereSql + whereItemSql);
2022-07-07 10:14:25 +08:00
List<Map<String, Object>> list = new ArrayList<>();
String id = null;
2022-08-12 10:12:55 +08:00
if (rs.next()) {
2022-07-07 10:14:25 +08:00
Map<String, Object> item = new HashMap<>();
id = rs.getString("id");
item.put("id", rs.getString("id"));
item.put("fname", rs.getString("fname"));
item.put("ftype", rs.getString("ftype"));
2022-07-21 11:08:08 +08:00
item.put("fnumber", rs.getString("fnumber"));
2022-10-10 18:24:07 +08:00
item.put("fobjid",rs.getString("fobjid"));
2022-07-07 10:14:25 +08:00
item.put("parentId", null);
2022-07-21 11:01:36 +08:00
item.put("expand", "1");
item.put("hasChildren", hasChildren(rs.getString("id"), true));
2022-07-07 10:14:25 +08:00
list.add(item);
}
2022-10-10 18:24:07 +08:00
int currentLevel = 0;
2022-08-12 10:12:55 +08:00
if (currentLevel + 1 <= Integer.parseInt(level)) {
2022-07-21 11:01:36 +08:00
findCompanyItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, true);
2022-07-07 10:14:25 +08:00
}
result.put("api_status", true);
result.put("data", list);
return result;
}
2022-07-21 11:01:36 +08:00
private void findCompanyItemByParantId(String id, int currentLevel, String level, RecordSet rs, List<Map<String, Object>> list, String whereSql, boolean expand) {
2022-08-30 11:40:30 +08:00
rs.executeQuery("select id, fname, ftype, fparentid,fobjid,fecid,fnumber from jcl_org_map " + whereSql + " and fparentid = " + id);
2022-07-07 10:14:25 +08:00
List<Map<String, Object>> currentList = new ArrayList<>();
2022-08-12 10:12:55 +08:00
while (rs.next()) {
2022-07-07 10:14:25 +08:00
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"));
2022-07-21 11:08:08 +08:00
item.put("fnumber", rs.getString("fnumber"));
2022-08-30 11:40:30 +08:00
item.put("fobjid", rs.getString("fobjid"));
item.put("fecid", rs.getString("fecid"));
2022-07-21 11:01:36 +08:00
item.put("expand", expand ? "1" : "0");
item.put("hasChildren", hasChildren(rs.getString("id"), true));
2022-07-07 10:14:25 +08:00
currentList.add(item);
}
list.addAll(currentList);
for (Map<String, Object> stringObjectMap : currentList) {
2022-08-12 10:12:55 +08:00
if (currentLevel + 1 <= Integer.parseInt(level)) {
2022-07-21 11:01:36 +08:00
findCompanyItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, true);
2022-08-12 10:12:55 +08:00
} else if (currentLevel == Integer.parseInt(level)) {
2022-07-21 11:01:36 +08:00
findCompanyItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, false);
2022-07-07 10:14:25 +08:00
}
}
}
2022-07-21 11:56:54 +08:00
private String userWhereSql(Map<String, Object> request2Map) {
2022-07-07 10:14:25 +08:00
String date = (String) request2Map.get("date"); // 数据日期
2022-08-12 10:12:55 +08:00
if (StringUtils.isBlank(date)) {
date = DateUtil.format(DateUtil.offset(new Date(), DateField.DAY_OF_MONTH, 1), "yyyy-MM-dd");
2022-07-07 10:14:25 +08:00
}
String fclass = (String) request2Map.get("fclass"); // 维度
2022-07-21 11:56:54 +08:00
2022-07-07 10:14:25 +08:00
String fisvitual = (String) request2Map.get("fisvitual"); // 是否显示虚拟组织
2022-08-12 10:12:55 +08:00
if (StringUtils.isBlank(fisvitual)) {
2022-07-07 10:14:25 +08:00
fisvitual = "0";
}
String whereSql = " where 1 = 1 ";
2022-08-12 10:12:55 +08:00
if (DBType.isOracle()) {
whereSql += " and ((t.fdatebegin <= to_date('" + date + "','yyyy-MM-DD') and t.fdateend >= to_date('" + date + "','yyyy-MM-DD')) or (t.fdatebegin <= to_date('" + date + "','yyyy-MM-DD') and t.fdateend is null )) ";
} else {
whereSql += " and ((t.fdatebegin <= '" + date + "' and t.fdateend >= '" + date + "') or (t.fdatebegin <= '" + date + "' and t.fdateend is null )) ";
}
whereSql += " and t.fclass = " + fclass + " ";
2022-07-07 10:14:25 +08:00
2022-08-12 10:12:55 +08:00
if ("0".equals(fisvitual)) {
2022-07-07 10:14:25 +08:00
whereSql += " and t.fisvitual = 0 ";
2022-08-12 10:12:55 +08:00
} else {
2022-07-07 10:14:25 +08:00
whereSql += " and t.fisvitual in (0, 1) ";
}
2022-07-21 11:56:54 +08:00
return whereSql;
}
@Override
public Map<String, Object> getUserData(Map<String, Object> request2Map, User user) {
2022-08-18 15:17:59 +08:00
Map<String, Object> result = new HashMap<>();
2022-08-30 11:40:30 +08:00
boolean hasRight = HasRightUtil.hasRight(user, USER_RIGHT, true);
2022-08-18 15:17:59 +08:00
result.put("hasRight", hasRight);
if (!hasRight) {
return result;
}
2022-07-21 11:56:54 +08:00
String root = (String) request2Map.get("root"); // 根节点
String level = (String) request2Map.get("level"); // 显示层级
2022-08-12 10:12:55 +08:00
if (StringUtils.isBlank(level)) {
2022-07-21 11:56:54 +08:00
level = "3";
}
String whereSql = userWhereSql(request2Map);
2022-07-07 10:14:25 +08:00
String whereItemSql = " ";
2022-08-12 10:12:55 +08:00
if ("0".equals(root)) { // 集团的情况
2022-07-07 10:14:25 +08:00
whereItemSql += " and t.ftype = 0 ";
} else {
2022-08-12 10:12:55 +08:00
whereItemSql += " and t.id = '" + root + "' ";
2022-07-07 10:14:25 +08:00
}
// 获取根节点
RecordSet rs = new RecordSet();
2022-08-18 17:41:05 +08:00
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 from jcl_org_map t " + whereSql + whereItemSql);
2022-07-07 10:14:25 +08:00
List<Map<String, Object>> list = new ArrayList<>();
String id = null;
2022-08-12 10:12:55 +08:00
if (rs.next()) {
2022-07-07 10:14:25 +08:00
Map<String, Object> item = new HashMap<>();
id = rs.getString("id");
item.put("id", rs.getString("id"));
item.put("fname", rs.getString("fname"));
item.put("ftype", rs.getString("ftype"));
item.put("parentId", null);
item.put("fleadername", rs.getString("fleadername"));
item.put("fleaderimg", rs.getString("fleaderimg"));
item.put("fleaderjob", rs.getString("fleaderjob"));
item.put("fplan", rs.getString("fplan"));
item.put("fonjob", rs.getString("fonjob"));
2022-07-21 11:01:36 +08:00
item.put("hasChildren", hasChildren(rs.getString("id"), false));
item.put("expand", "1");
2022-07-21 11:08:08 +08:00
item.put("fnumber", rs.getString("fnumber"));
2022-07-21 13:49:06 +08:00
item.put("fleader", rs.getString("fleader"));
2022-08-30 11:40:30 +08:00
item.put("fobjid",rs.getString("fobjid"));
2022-07-07 10:14:25 +08:00
list.add(item);
}
int currentLevel = 1;
2022-08-12 10:12:55 +08:00
if (currentLevel + 1 <= Integer.parseInt(level)) {
2022-07-21 11:01:36 +08:00
findUserItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, true);
2022-07-07 10:14:25 +08:00
}
result.put("api_status", true);
result.put("data", list);
return result;
}
2022-07-21 11:01:36 +08:00
@Override
public Map<String, Object> asyncUserData(Map<String, Object> request2Map, User user) {
String ids = (String) request2Map.get("ids");
2022-07-21 11:56:54 +08:00
String whereSql = userWhereSql(request2Map);
2022-07-21 11:01:36 +08:00
2022-08-12 10:12:55 +08:00
whereSql += " and fparentid in (" + ids + ") ";
2022-07-21 11:01:36 +08:00
RecordSet rs = new RecordSet();
2022-08-12 10:12:55 +08:00
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 from jcl_org_map t " + whereSql);
2022-07-21 11:01:36 +08:00
List<Map<String, Object>> currentList = new ArrayList<>();
2022-08-12 10:12:55 +08:00
while (rs.next()) {
2022-07-21 11:01:36 +08:00
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("fleadername", rs.getString("fleadername"));
item.put("fleaderimg", rs.getString("fleaderimg"));
item.put("fleaderjob", rs.getString("fleaderjob"));
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));
2022-07-21 13:49:06 +08:00
item.put("fleader", rs.getString("fleader"));
2022-07-21 11:01:36 +08:00
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"));
}
}
}
Map<String, Object> result = new HashMap<>();
result.put("api_status", true);
result.put("data", currentList);
return result;
}
@Override
public Map<String, Object> asyncCompanyData(Map<String, Object> request2Map, User user) {
String ids = (String) request2Map.get("ids");
2022-07-21 11:56:54 +08:00
String whereSql = companyDateWhereSql(request2Map);
2022-07-21 11:01:36 +08:00
2022-08-12 10:12:55 +08:00
whereSql += " and fparentid in (" + ids + ") ";
2022-07-21 11:01:36 +08:00
RecordSet rs = new RecordSet();
2022-07-21 11:08:08 +08:00
rs.executeQuery("select id, fname, ftype, fparentid, fnumber from jcl_org_map " + whereSql);
2022-07-21 11:01:36 +08:00
List<Map<String, Object>> currentList = new ArrayList<>();
2022-08-12 10:12:55 +08:00
while (rs.next()) {
2022-07-21 11:01:36 +08:00
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"));
2022-07-21 11:08:08 +08:00
item.put("fnumber", rs.getString("fnumber"));
2022-07-21 11:01:36 +08:00
item.put("hasChildren", hasChildren(rs.getString("id"), true));
currentList.add(item);
}
Map<String, Object> result = new HashMap<>();
result.put("api_status", true);
result.put("data", currentList);
return result;
}
2022-08-17 19:29:46 +08:00
2022-07-21 11:01:36 +08:00
private void findUserItemByParantId(String id, int currentLevel, String level, RecordSet rs, List<Map<String, Object>> list, String whereSql, boolean expand) {
2022-09-29 10:28:04 +08:00
rs.executeQuery("select t.id, t.fname, t.ftype, t.fparentid,t.fleader, t.fleadername, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber,t.fobjid,fecid from jcl_org_map t " + whereSql + " and t.fparentid = " + id);
2022-07-07 10:14:25 +08:00
List<Map<String, Object>> currentList = new ArrayList<>();
2022-08-12 10:12:55 +08:00
while (rs.next()) {
2022-07-07 10:14:25 +08:00
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("fleadername", rs.getString("fleadername"));
item.put("fleaderimg", rs.getString("fleaderimg"));
item.put("fleaderjob", rs.getString("fleaderjob"));
item.put("fplan", rs.getString("fplan"));
item.put("fonjob", rs.getString("fonjob"));
item.put("fnumber", rs.getString("fnumber"));
2022-07-21 11:01:36 +08:00
item.put("expand", expand ? "1" : "0");
2022-08-30 11:40:30 +08:00
item.put("fobjid", rs.getString("fobjid"));
item.put("fecid", rs.getString("fecid"));
2022-09-29 10:28:04 +08:00
item.put("fleader", rs.getString("fleader"));
2022-07-21 11:01:36 +08:00
item.put("hasChildren", hasChildren(rs.getString("id"), false));
2022-07-07 10:14:25 +08:00
currentList.add(item);
}
for (Map<String, Object> stringObjectMap : currentList) {
2022-08-12 10:12:55 +08:00
if ("4".equals(stringObjectMap.get("ftype"))) { // 员工信息
2022-07-07 10:14:25 +08:00
rs.executeQuery("select id, mobile, homeaddress from hrmresource where id = ? ", stringObjectMap.get("fnumber"));
2022-08-12 10:12:55 +08:00
if (rs.next()) {
2022-07-07 10:14:25 +08:00
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"));
2022-08-12 10:12:55 +08:00
if (rs.next()) {
2022-07-07 10:14:25 +08:00
stringObjectMap.put("department", rs.getString("departmentname"));
}
}
2022-08-12 10:12:55 +08:00
if (currentLevel + 1 <= Integer.parseInt(level)) {
2022-07-21 11:01:36 +08:00
findUserItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, true);
2022-08-12 10:12:55 +08:00
} else if (currentLevel == Integer.parseInt(level)) { // 多查一层
2022-07-21 11:01:36 +08:00
findUserItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, false);
2022-07-07 10:14:25 +08:00
}
}
list.addAll(currentList);
2022-07-21 11:01:36 +08:00
}
2022-07-07 10:14:25 +08:00
2022-07-21 11:01:36 +08:00
private boolean hasChildren(String id, boolean isCompany) {
String whereSql = " where fparentid = " + id + " ";
2022-08-12 10:12:55 +08:00
if (isCompany) {
2022-07-21 11:01:36 +08:00
whereSql += " and ftype in (0, 1, 2) ";
}
grs.executeQuery("select count(1) as count from jcl_org_map " + whereSql);
String count = "0";
2022-08-12 10:12:55 +08:00
if (grs.next()) {
2022-07-21 11:01:36 +08:00
count = grs.getString("count");
}
return !"0".equals(count);
2022-07-07 10:14:25 +08:00
}
}