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/src/com/engine/organization/service/impl/OrgChartServiceImpl.java

746 lines
33 KiB
Java

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.chart.CompanyTreePO;
import com.engine.organization.entity.chart.TimeLinesBO;
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.mapper.jclorgmap.JclOrgMapper;
import com.engine.organization.mapper.scheme.GradeMapper;
import com.engine.organization.mapper.scheme.LevelMapper;
import com.engine.organization.service.OrgChartService;
import com.engine.organization.util.HasRightUtil;
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 org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
public class OrgChartServiceImpl extends Service implements OrgChartService {
private RecordSet grs = new RecordSet();
private static final String COMPANY_RIGHT = "OrgChart:All";
private static final String USER_RIGHT = "OrgPerspective:All";
private final String level = getFieldName("职等");
private final String grade = getFieldName("职级");
@Override
public Map<String, Object> getOptionCondition(Map<String, Object> request2Map, User user) {
Map<String, Object> result = new HashMap<>();
RecordSet rs = new RecordSet();
Map<String, Object> defaultItem = new HashMap<>();
rs.executeQuery("select companyname from hrmcompany");
rs.next();
int fkey = 0;
defaultItem.put("key", fkey++);
defaultItem.put("id", "0");
defaultItem.put("companyname", Util.null2String(rs.getString("companyname")));
rs.executeQuery("select id, companyname from HrmCompanyVirtual order by id");
List<Map<String, Object>> fclasslist = new ArrayList<>();
fclasslist.add(defaultItem);
while (rs.next()) {
Map<String, Object> item = new HashMap<>();
item.put("key", fkey++);
item.put("id", rs.getString("id"));
item.put("companyname", rs.getString("companyname"));
fclasslist.add(item);
}
result.put("api_status", true);
result.put("fclasslist", fclasslist);
Map<String, Object> subCompanyTree = getSubCompanyTree(request2Map);
result.putAll(subCompanyTree);
return result;
}
@Override
public Map<String, Object> getSubCompanyTree(Map<String, Object> params) {
Map<String, Object> result = new HashMap<>(2);
List<CompanyTreePO> departmentTree = ChartServiceImpl.getDepartmentTreeList(params);
result.put("companyTree", departmentTree);
return result;
}
private String getSubCompanyTreeSql(String id, String fclass, String subcompany) {
// 是否展示当前数据
boolean isSearchCurrent = StringUtils.isBlank(id) || "0".equals(id);
String sql;
if (isSearchCurrent) {
sql = "select id as id, id as value, subcompanyname as title, supsubcomid as pId from hrmsubcompany where (canceled is null or canceled != '1') and " + DBType.get(new RecordSet().getDBType()).ifNull("supsubcomid", "0") + " = ? ";
boolean isRealDimension = StringUtils.isBlank(fclass) || "0".equals(fclass);
boolean isRealTime = StringUtils.isBlank(id) || "0".equals(id);
if (isRealTime && user.getUID() != 1 && isRealDimension) {
DetachUtil detachUtil = new DetachUtil(user);
if (detachUtil.isDETACH()) {
String ids = detachUtil.getJclRoleLevels();
if ("0".equals(subcompany)) {
sql = sql + " and id in (" + ids + ")";
}
}
}
if (StringUtils.isNotBlank(fclass) && !"0".equals(fclass)) {
sql = "select id as id, id as value, subcompanyname as title, supsubcomid as pId from hrmsubcompanyvirtual where (canceled is null or canceled != '1') and " + DBType.get(new RecordSet().getDBType()).ifNull("supsubcomid", "0") + " = ? and companyid = '" + fclass + "'";
}
} else {
sql = "select subcompanyid as id, id as value, subcompanyname as title, supsubcompanyid as pId from jcl_chart_subcompany where (canceled is null or canceled != '1') and " + DBType.get(new RecordSet().getDBType()).ifNull("supsubcompanyid", "0") + " = ? ";
if (StringUtils.isNotBlank(fclass) && !"0".equals(fclass)) {
sql = "select subcompanyvirtualid as id, id as value, subcompanyname as title, supsubcompanyid as pId from jcl_chart_subcompanyvirtual where (canceled is null or canceled != '1') and " + DBType.get(new RecordSet().getDBType()).ifNull("supsubcompanyid", "0") + " = ? and companyid = '" + fclass + "'";
}
// 添加时间轴条件
sql += " and versionid = " + id;
}
return sql;
}
private String companyDateWhereSql(Map<String, Object> request2Map) {
String date = (String) request2Map.get("date");
if (StringUtils.isBlank(date)) {
date = DateUtil.format(DateUtil.offset(new Date(), DateField.DAY_OF_MONTH, 1), "yyyy-MM-dd");
}
String fclass = (String) request2Map.get("fclass");
String fisvitual = (String) request2Map.get("fisvitual");
if (StringUtils.isBlank(fisvitual)) {
fisvitual = "0";
}
String whereSql = " where 1 = 1 ";
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 + " ";
if ("0".equals(fisvitual)) {
whereSql += " and fisvitual = 0 ";
} else {
whereSql += " and fisvitual in (0, 1) ";
}
whereSql += " and ftype in (0 , 1 ,2) ";
return whereSql;
}
@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);
result.put("hasRight", hasRight);
if (!hasRight) {
return result;
}
String root = (String) request2Map.get("root");
String level = (String) request2Map.get("level");
if (StringUtils.isBlank(level)) {
level = "3";
}
String whereSql = companyDateWhereSql(request2Map);
String whereItemSql = " ";
if ("0".equals(root)) {
whereItemSql += " and ftype = 0 ";
} else {
whereItemSql += " and id = '" + root + "' ";
}
// 获取根节点
RecordSet rs = new RecordSet();
String sql = "select id, fname, ftype, fparentid, fnumber, fobjid, fisvitual from jcl_org_map " + whereSql + whereItemSql;
rs.executeQuery(sql);
List<Map<String, Object>> list = new ArrayList<>();
String id = null;
if (rs.next()) {
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("fnumber", rs.getString("fnumber"));
item.put("fobjid", rs.getString("fobjid"));
item.put("parentId", null);
item.put("expand", "1");
item.put("fisvitual", rs.getString("fisvitual"));
item.put("hasChildren", hasChildren(rs.getString("id"), true));
list.add(item);
}
int currentLevel = 1;
findCompanyItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, currentLevel + 1 <= Integer.parseInt(level));
// 分部数据,构建层级关系
reBuildTreeList(list, root);
result.put("api_status", true);
result.put("data", list);
return result;
}
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;
}
rs.executeQuery(sql);
List<Map<String, Object>> currentList = new ArrayList<>();
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("fnumber", rs.getString("fnumber"));
item.put("fobjid", rs.getString("fobjid"));
item.put("fecid", rs.getString("fecid"));
item.put("fisvitual", rs.getString("fisvitual"));
item.put("expand", expand ? "1" : "0");
item.put("hasChildren", hasChildren(rs.getString("id"), true));
currentList.add(item);
}
list.addAll(currentList);
for (Map<String, Object> stringObjectMap : currentList) {
if (currentLevel + 1 <= Integer.parseInt(level)) {
findCompanyItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, true);
} else if (currentLevel == Integer.parseInt(level)) {
findCompanyItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, false);
}
}
}
private String userWhereSql(Map<String, Object> request2Map) {
String date = (String) request2Map.get("date");
if (StringUtils.isBlank(date)) {
date = DateUtil.format(DateUtil.offset(new Date(), DateField.DAY_OF_MONTH, 1), "yyyy-MM-dd");
}
String fclass = (String) request2Map.get("fclass");
String fisvitual = (String) request2Map.get("fisvitual");
if (StringUtils.isBlank(fisvitual)) {
fisvitual = "0";
}
String whereSql = " where 1 = 1 ";
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 + " ";
if ("0".equals(fisvitual)) {
whereSql += " and t.fisvitual = 0 ";
} else {
whereSql += " and t.fisvitual in (0, 1) ";
}
return whereSql;
}
@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);
result.put("hasRight", hasRight);
if (!hasRight) {
return result;
}
String root = (String) request2Map.get("root");
String level = (String) request2Map.get("level");
if (StringUtils.isBlank(level)) {
level = "3";
}
String whereSql = userWhereSql(request2Map);
String whereItemSql = " ";
if ("0".equals(root)) {
whereItemSql += " and t.ftype = 0 ";
} else {
whereItemSql += " and t.id = '" + root + "' ";
}
// 获取根节点
RecordSet rs = new RecordSet();
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;
if (rs.next()) {
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);
if ("0".equals(id)) {
item.put("fleadername", "");
item.put("fleaderimg", "");
item.put("fleaderjob", "");
item.put("fleader", "");
} else {
item.put("fleadername", rs.getString("fleadername"));
item.put("fleaderimg", rs.getString("fleaderimg"));
item.put("fleaderjob", rs.getString("fleaderjob"));
item.put("fleader", rs.getString("fleader"));
}
item.put("fplan", rs.getString("fplan"));
item.put("fonjob", rs.getString("fonjob"));
item.put("hasChildren", hasChildren(rs.getString("id"), false));
item.put("expand", "1");
item.put("fnumber", rs.getString("fnumber"));
item.put("fobjid", rs.getString("fobjid"));
item.put("fleaderlv", convertLevel(rs.getString("fleaderlv")));
item.put("fleaderst", convertGrade(rs.getString("fleaderst")));
item.put("fecid", rs.getString("fecid"));
item.put("fisvitual", rs.getString("fisvitual"));
list.add(item);
}
int currentLevel = 1;
findUserItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, currentLevel + 1 <= Integer.parseInt(level));
// 分部数据,构建层级关系
reBuildTreeList(list, root);
result.put("api_status", true);
result.put("data", list);
return result;
}
@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 + ") ";
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<>();
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("fplan", rs.getString("fplan"));
item.put("fonjob", rs.getString("fonjob"));
item.put("fnumber", rs.getString("fnumber"));
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()));
item.put("fleaderimg", jclOrgMap.getFLeaderImg());
item.put("fleadername", jclOrgMap.getFLeaderName() == null ? "" : jclOrgMap.getFLeaderName());
item.put("fleaderjob", jclOrgMap.getFLeaderJob());
item.put("fleaderlv", convertLevel(rs.getString("fleaderlv")));
item.put("fleaderst", convertGrade(rs.getString("fleaderst")));
} else {
item.put("fleader", rs.getString("fleader"));
item.put("fleaderimg", rs.getString("fleaderimg"));
item.put("fleadername", rs.getString("fleadername"));
item.put("fleaderjob", rs.getString("fleaderjob"));
item.put("fleaderlv", convertLevel(rs.getString("fleaderlv")));
item.put("fleaderst", convertGrade(rs.getString("fleaderst")));
}
item.put("fobjid", rs.getString("fobjid"));
item.put("fisvitual", rs.getString("fisvitual"));
currentList.add(item);
}
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");
String whereSql = companyDateWhereSql(request2Map);
whereSql += " and fparentid in (" + ids + ") ";
RecordSet rs = new RecordSet();
rs.executeQuery("select id, fname, ftype, fparentid, fnumber,fobjid,fisvitual from jcl_org_map " + whereSql);
List<Map<String, Object>> currentList = new ArrayList<>();
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("fnumber", rs.getString("fnumber"));
item.put("fobjid", rs.getString("fobjid"));
item.put("fisvitual", rs.getString("fisvitual"));
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;
}
//处理多个部门负责人
private JclOrgMap getBmfzrInfo(String bmfzr) {
JclOrgMap jclOrgMap = new JclOrgMap();
if (StringUtils.isNotBlank(bmfzr)) {
String[] split = bmfzr.split(",");
for (String s : split) {
jclOrgMap = MapperProxyFactory.getProxy(JclOrgMapper.class).getResInfo(level, grade, s);
break;
}
}
return jclOrgMap;
}
private void findUserItemByParantId(String id, int currentLevel, String level, RecordSet rs, List<Map<String, Object>> list, String whereSql, boolean expand) {
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";
}
} else {
sql += " and t.fparentid = " + id;
}
rs.executeQuery(sql);
List<Map<String, Object>> currentList = new ArrayList<>();
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("fobjparentId", rs.getString("fobjparentid"));
item.put("fplan", rs.getString("fplan"));
item.put("fonjob", rs.getString("fonjob"));
item.put("fnumber", rs.getString("fnumber"));
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()));
item.put("fleaderimg", jclOrgMap.getFLeaderImg());
item.put("fleadername", jclOrgMap.getFLeaderName() == null ? "" : jclOrgMap.getFLeaderName());
item.put("fleaderjob", jclOrgMap.getFLeaderJob());
item.put("fleaderlv", convertLevel(rs.getString("fleaderlv")));
item.put("fleaderst", convertGrade(rs.getString("fleaderst")));
} else {
item.put("fleader", rs.getString("fleader"));
item.put("fleaderimg", rs.getString("fleaderimg"));
item.put("fleadername", rs.getString("fleadername"));
item.put("fleaderjob", rs.getString("fleaderjob"));
item.put("fleaderlv", convertLevel(rs.getString("fleaderlv")));
item.put("fleaderst", convertGrade(rs.getString("fleaderst")));
}
item.put("fisvitual", rs.getString("fisvitual"));
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 (currentLevel + 1 <= Integer.parseInt(level)) {
findUserItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, true);
} else if (currentLevel == Integer.parseInt(level)) { // 多查一层
findUserItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, false);
}
}
list.addAll(currentList);
}
private boolean hasChildren(String id, boolean isCompany) {
String whereSql = " where fparentid = " + id + " ";
if (isCompany) {
whereSql += " and ftype in (0, 1, 2) ";
}
grs.executeQuery("select count(1) as count from jcl_org_map " + whereSql);
String count = "0";
if (grs.next()) {
count = grs.getString("count");
}
return !"0".equals(count);
}
private String convertLevel(String fLeaderLv) {
StringBuilder jobLevelName = new StringBuilder();
if (StringUtils.isNotBlank(fLeaderLv)) {
try {
String[] split = fLeaderLv.split(",");
for (String s : split) {
long parseLong = Long.parseLong(s);
LevelPO levelByID = MapperProxyFactory.getProxy(LevelMapper.class).getLevelByID(parseLong);
if (null != levelByID) {
jobLevelName.append(levelByID.getLevelName());
}
}
} catch (NumberFormatException exception) {
jobLevelName = new StringBuilder(fLeaderLv);
}
}
return jobLevelName.toString();
}
private String convertGrade(String fLeaderSt) {
StringBuilder jobGradeName = new StringBuilder();
if (StringUtils.isNotBlank(fLeaderSt)) {
try {
String[] split = fLeaderSt.split(",");
for (String s : split) {
long parseLong = Long.parseLong(s);
GradePO gradeByID = MapperProxyFactory.getProxy(GradeMapper.class).getGradeByID(parseLong);
if (null != gradeByID) {
jobGradeName.append(gradeByID.getGradeName());
}
}
} catch (NumberFormatException exception) {
jobGradeName = new StringBuilder(fLeaderSt);
}
}
return jobGradeName.toString();
}
private void reBuildTreeList(List<Map<String, Object>> list, String root) {
// 分部数据,构建层级关系
Set<String> idSet = list.stream().filter(item -> "1".equals(Util.null2String(item.get("ftype")))).map(item -> Util.null2String(item.get("id"))).collect(Collectors.toSet());
list.forEach(item -> {
if (!root.equals(Util.null2String(item.get("id"))) && "1".equals(Util.null2String(item.get("ftype"))) && !idSet.contains(Util.null2String(item.get("parentId")))) {
item.put("parentId", root);
item.put("fobjparentId", root);
}
});
}
private JclOrgMapper getJclOrgMapMapper() {
return MapperProxyFactory.getProxy(JclOrgMapper.class);
}
@Override
public String synchronousData(Map<String, Object> request2Map, User user) {
String currentDate = OrganizationDateUtil.getFormatLocalDate(new java.util.Date());
java.sql.Date date = new java.sql.Date(OrganizationDateUtil.stringToDate(currentDate).getTime());
Calendar cal = Calendar.getInstance();
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().insertResToMap(level, grade);
//同步岗位信息
getJclOrgMapMapper().insertJobToMap();
//同步部门信息
getJclOrgMapMapper().insertDeptToMap(level, grade);
//同步分部信息
getJclOrgMapMapper().insertSubComToMap();
//同步集团信息
getJclOrgMapMapper().insertComToMap();
//清除部门合并、转移造成的脏数据
getJclOrgMapMapper().deleteJobNull(date);
//刷新在岗数、编制数(从岗位向上刷,岗位不需处理)
List<JclOrgMap> jclOrgMaps = getJclOrgMapMapper().getJclOrgMapByType("3", date);
for (JclOrgMap jclOrgMap : jclOrgMaps) {
int id = jclOrgMap.getId();
countJobAndPlans("3", id, currentDate);
}
return "同步成功";
}
@Override
public void insertChartVersion(Integer fclass, String description) {
RecordSet rs = new RecordSet();
String recordDate = OrganizationDateUtil.getFormatLocalDateTime(LocalDateTime.now());
String createDate = OrganizationDateUtil.getFormatLocalDate(LocalDate.now());
rs.executeQuery("select id from JCL_ORG_CHARTVERSION where fclass = ? and createtime = ?", fclass, createDate);
rs.next();
String id = Util.null2String(rs.getString("id"));
if (StringUtils.isNotEmpty(id)) {
rs.executeUpdate("update JCL_ORG_CHARTVERSION set recorddate = ?,description = ?,creator = ? where fclass = ? and createtime = ?", recordDate, description, user.getUID(), fclass, createDate);
} else {
rs.executeUpdate("insert into JCL_ORG_CHARTVERSION (recorddate,description,creator,deletetype,createtime,fclass) values(?,?,?,?,?,?)", recordDate, description, user.getUID(), 0, createDate, fclass);
}
}
@Override
public Map<String, Object> searchTimeLines(Map<String, Object> params) {
Map<String, Object> datas = new HashMap<>();
RecordSet rs = new RecordSet();
String fclass = Util.null2String(params.get("fclass"));
List<TimeLinesBO> timeLinesBOList = new ArrayList<>();
timeLinesBOList.add(TimeLinesBO.builder().key(0).id(0).title("当前版本").color("blue").time("").build());
rs.executeQuery("SELECT id,recorddate,description from JCL_ORG_CHARTVERSION where fclass = ? and deletetype = ? order by id desc", fclass, 0);
while (rs.next()) {
timeLinesBOList.add(TimeLinesBO.builder()
.key(rs.getInt("id"))
.id(rs.getInt("id"))
.title(Util.null2String(rs.getString("description")))
.color("grey")
.time(Util.null2String(rs.getString("recorddate")))
.build());
}
datas.put("timelineList", timeLinesBOList);
return datas;
}
/**
* 刷新在岗、编制数
*/
void countJobAndPlans(String type, int id, String currentDate) {
java.sql.Date date = new java.sql.Date(OrganizationDateUtil.stringToDate(currentDate).getTime());
RecordSet rs = new RecordSet();
//处理上级
String sql = "select fparentid from jcl_org_map where ftype=" + type + " and id=" + id + " ";
String whereSql = "";
if (DBType.isOracle()) {
whereSql += " and ((fdatebegin <= to_date('" + currentDate + "','yyyy-MM-DD') and fdateend >= to_date('" + currentDate + "','yyyy-MM-DD')) or (fdatebegin <= to_date('" + currentDate + "','yyyy-MM-DD') and fdateend is null )) ";
} else {
whereSql += " and ((fdatebegin <= '" + currentDate + "' and fdateend >= '" + currentDate + "') or (fdatebegin <= '" + currentDate + "' and fdateend is null )) ";
}
rs.executeQuery(sql + whereSql);
String fparentid = null;
String ftype = null;
if (rs.next()) {
fparentid = rs.getString("fparentid");
String typeSql = "select ftype from jcl_org_map where id=" + fparentid + whereSql;
rs.executeQuery(typeSql + whereSql);
if (rs.next()) {
ftype = rs.getString("ftype");
}
}
JclOrgMap jclOrgMap = getJclOrgMapMapper().getSumPlanAndJobByFParentId(date, fparentid);
if (fparentid != null) {
getJclOrgMapMapper().updateMapById(Integer.parseInt(fparentid), jclOrgMap.getFPlan(), jclOrgMap.getFOnJob(), date);
if (!"-1".equals(fparentid)) {
countJobAndPlans(ftype, Integer.parseInt(fparentid), String.valueOf(currentDate));
}
}
}
private String getFieldName(String fieldabel) {
RecordSet recordSet = new RecordSet();
String fieldname = null;
recordSet.executeQuery("select fieldname from jcl_org_field where fieldlabel='" + fieldabel + "'");
if (recordSet.next()) {
fieldname = recordSet.getString("fieldname");
}
return fieldname;
}
/**
* 判断树是否为叶子节点
*
* @param versionId
* @param dimension
* @param subCompany
* @return
*/
private boolean judgeTreeLeaf(String versionId, String dimension, String subCompany) {
RecordSet recordSet = new RecordSet();
String sql = getSubCompanyTreeSql(versionId, dimension, subCompany);
recordSet.executeQuery(sql, subCompany);
return !recordSet.next();
}
static class OrgSelectItem {
private Integer key;
private String id;
private String fnumber;
private String fname;
public Integer getKey() {
return key;
}
public void setKey(Integer key) {
this.key = key;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFnumber() {
return fnumber;
}
public void setFnumber(String fnumber) {
this.fnumber = fnumber;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof OrgSelectItem) {
OrgSelectItem item = (OrgSelectItem) obj;
return this.getId().equals(item.getId());
}
return false;
}
@Override
public int hashCode() {
return Integer.parseInt(this.getId());
}
}
}