Compare commits

..

11 Commits
master ... jcgj

12
.gitignore vendored

@ -1,15 +1,17 @@
/weaver-develop.iml
/weaver-hrm-organization.iml
/out/
.idea/
/.idea/
HELP.md
target/
### IntelliJ IDEA ###
.idea
/test
/src/test
/src/rebel.xml
/src/META-INF
/WEB-INF/config
/log
/log
/weaver-develop.iml

@ -1,8 +0,0 @@
<component name="ArtifactManager">
<artifact type="jar" name="weaver-develop:jar">
<output-path>$PROJECT_DIR$/out/artifacts/weaver_develop_jar</output-path>
<root id="archive" name="weaver-develop.jar">
<element id="module-output" name="weaver-develop" />
</root>
</artifact>
</component>

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
</annotationProcessing>
</component>
</project>

@ -1,9 +0,0 @@
<component name="libraryTable">
<library name="classbean">
<CLASSES>
<root url="file://$PROJECT_DIR$/../../../../weaver/ecology/classbean" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="lib">
<CLASSES>
<root url="file://$PROJECT_DIR$/../../../../weaver/ecology/WEB-INF/lib" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/../../../../weaver/ecology/WEB-INF/lib" />
</SOURCES>
<jarDirectory url="file://$PROJECT_DIR$/../../../../weaver/ecology/WEB-INF/lib" recursive="false" />
<jarDirectory url="file://$PROJECT_DIR$/../../../../weaver/ecology/WEB-INF/lib" recursive="false" type="SOURCES" />
</library>
</component>

@ -1,3 +0,0 @@
Manifest-Version: 1.0
Main-Class: test.MainTest

@ -0,0 +1,12 @@
package com.api.junchuang.web;
import javax.ws.rs.Path;
/**
* @Author ml
* @Date 2023/2/27 17:17
* @Description
* @Since version-1.0
*/
@Path("/bs/junchuangorgchart")
public class OrgChartController extends com.engine.junchuang.web.OrgChartController {
}

@ -0,0 +1,28 @@
package com.engine.junchuang.common;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.util.Date;
@Data
@Builder
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class LocalDateRange {
//"开始日期
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date fromDate;
//结束日期
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date endDate;
}

@ -0,0 +1,52 @@
package com.engine.junchuang.entity;
import lombok.Data;
import java.sql.Date;
/**
* @author:dxfeng
* @createTime: 2022/09/01
* @version: 1.0
*/
@Data
public class JclOrgMap {
Integer fId;
Integer id;
Integer fType;
Integer fObjId;
Integer fEcId;
String uuid;
Integer fClass;
String fClassName;
String fNumber;
String fName;
Integer fLeader;
String fLeaderImg;
String fLeaderName;
Integer fLeaderJobId;
String fLeaderJob;
String fLeaderLv;
String fLeaderSt;
Integer fParentId;
Integer fObjParentId;
Integer fPlan;
Integer fOnJob;
Integer fIsVitual;
Date fDateBegin;
Date fDateEnd;
public Integer getFPlan() {
if (null == fPlan) {
fPlan = 0;
}
return fPlan;
}
public Integer getFOnJob() {
if (null == fOnJob) {
fOnJob = 0;
}
return fOnJob;
}
}

@ -0,0 +1,18 @@
package com.engine.junchuang.exception;
/**
* @Author weaver_cl
* @description:
* @Date 2022/4/26
* @Version V1.0
**/
public class OrganizationRunTimeException extends RuntimeException{
public OrganizationRunTimeException(String message) {
super(message);
}
public OrganizationRunTimeException(Throwable cause) {
super(cause);
}
}

@ -0,0 +1,17 @@
package com.engine.junchuang.service;
import weaver.hrm.User;
import java.util.Map;
public interface OrgChartService {
Map<String, Object> getOptionCondition(Map<String, Object> request2Map, User user);
Map<String, Object> getUserData(Map<String, Object> request2Map, User user);
Map<String, Object> asyncUserData(Map<String, Object> request2Map, User user);
String syncOrgMapData(Map<String, Object> request2Map, User user);
}

@ -0,0 +1,568 @@
package com.engine.junchuang.service;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import com.engine.core.impl.Service;
import com.engine.junchuang.util.OrganizationDateUtil;
import com.engine.junchuang.util.db.DBType;
import com.engine.junchuang.util.detach.DetachUtil;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import java.util.*;
import java.util.stream.Collectors;
public class OrgChartServiceImpl extends Service implements OrgChartService {
private RecordSet grs = new RecordSet();
@Override
public Map<String, Object> getOptionCondition(Map<String, Object> request2Map, User user) {
Map<String, Object> result = new HashMap<>();
RecordSet rs = new RecordSet();
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);
while (rs.next()) {
Map<String, Object> item = new HashMap<>();
item.put("id", rs.getString("id"));
item.put("companyname", rs.getString("companyname"));
fclasslist.add(item);
}
String sql = "select id, fnumber, fname, ftype from junc_org_map where ftype in (0, 1) ";
DetachUtil detachUtil = new DetachUtil(user);
if (detachUtil.isDetach()) {
String companyIds = detachUtil.getCompanyIds();
if (StringUtils.isNotBlank(companyIds)) {
sql = "select id, fnumber, fname, ftype from junc_org_map where (ftype = 0 or (ftype = 1 and fobjid in(" + companyIds + "))) ";
} else {
sql = "select id, fnumber, fname, ftype from junc_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()) {
OrgSelectItem item = new OrgSelectItem();
item.setId(rs.getString("id"));
item.setFnumber(rs.getString("fnumber"));
item.setFname(rs.getString("fname"));
companySet.add(item);
}
result.put("api_status", true);
result.put("fclasslist", fclasslist);
result.put("companylist", companySet);
return result;
}
@Override
public Map<String, Object> getUserData(Map<String, Object> request2Map, User user) {
Map<String, Object> result = new HashMap<>();
result.put("hasRight", true);
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 junc_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");
type = rs.getString("ftype");
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", Util.null2String(rs.getString("fleadername")));
item.put("fleaderimg", Util.null2String(rs.getString("fleaderimg")));
// item.put("fleaderjob", Util.null2String(rs.getString("fleaderjob")));
// item.put("fleader", Util.null2String(rs.getString("fleader")));
item.put("fleader", "");
// item.put("fleaderimg", "");
item.put("fleadername", "");
item.put("fleaderjob", "");
}
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("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), type, null);
// 分部数据,构建层级关系
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[] 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 junc_org_map t ";
RecordSet rs = new RecordSet();
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.getCompanyIds() + ")";
} 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.getCompanyIds() + ")) or (t.ftype =2 and t.fobjid in(" + detachUtil.getDepartmentIds() + ")) 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 {
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", 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("fleader", rs.getString("fleader"));
item.put("fleaderimg", Util.null2String(rs.getString("fleaderimg")));
//item.put("fleadername", rs.getString("fleadername"));
//item.put("fleaderjob", rs.getString("fleaderjob"));
item.put("fleader", "");
// item.put("fleaderimg", "");
item.put("fleadername", "");
item.put("fleaderjob", "");
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));
} 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);
return result;
}
@Override
public String syncOrgMapData(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 yesterday = new java.sql.Date(calendar.getTime().getTime());
RecordSet rs = new RecordSet();
// 1、清空当天所有数据
rs.execute("delete from junc_org_map where fdatebegin = TO_DATE('" + date + "','yyyy-MM-dd')");
// 2、修改所有失效数据
rs.execute("update junc_org_map set fdateend=TO_DATE('" + yesterday + "','yyyy-MM-dd') where fdateend > TO_DATE('" + date + "','yyyy-MM-dd')");
// 3、同步集团数据
String jtSql = "INSERT INTO junc_org_map ( id, ftype, fobjid, uuid,fclass, fclassname, fnumber, fname,\n" +
" fleader, fleaderimg, fleadername, fleaderjobid, fleaderjob, fparentid,fobjparentid,\n" +
" fplan, fonjob, fisvitual, fdatebegin, fdateend)\n" +
" SELECT 0, 0, 0, uuid, 0, '行政维度', '00', companyname,\n" +
" 0, NULL, NULL, 0, NULL, -1, 0,\n" +
" 0, (select count(1) from hrmresource where status<4), 0, TO_DATE(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd'), TO_DATE('2099-12-31','yyyy-MM-dd') FROM hrmcompany";
rs.execute(jtSql);
// 4、同步分部数据
String fbSql = "insert into junc_org_map\n" +
" (id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleader,fleaderimg,\n" +
" fleadername,fleaderjobid,fleaderjob,fleaderlv,fleaderst,fparentid,fobjparentid,\n" +
" fplan,fonjob,fisvitual,fdatebegin,fdateend)\n" +
" select a.id,1,a.id,a.uuid,0,'行政维度', '',a.subcompanyname,null,'',\n" +
" '',NULL,'','','',nvl(a.supsubcomid,0),nvl(a.supsubcomid,0),\n" +
" 0,0,0,TO_DATE(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd'), TO_DATE('2099-12-31','yyyy-MM-dd') from hrmsubcompany a\n" +
" where nvl(a.canceled,0) <> 1";
rs.execute(fbSql);
// 5、同步部门数据
String bmSql = "insert into junc_org_map\n" +
"(id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleader,fleaderimg,\n" +
" fleadername,fleaderjobid,fleaderjob,fparentid,fobjparentid,\n" +
" fplan,fonjob,fisvitual,fdatebegin,fdateend)\n" +
"select a.id+100000000,2,a.id,a.uuid,0,'行政维度',a.DEPARTMENTCODE,a.departmentname,regexp_substr(b.bmfzr,'[^,]+',1,1),c.messagerurl,\n" +
" c.lastname,c.jobtitle,d.jobtitlemark,\n" +
" (case nvl(a.supdepid,0) when 0 then a.subcompanyid1 else a.supdepid+100000000 end),\n" +
" (case nvl(a.supdepid,0) when 0 then a.subcompanyid1 else a.supdepid end),\n" +
" 0,0,0,TO_DATE(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd'), TO_DATE('2099-12-31','yyyy-MM-dd')\n" +
"from HrmDepartment a\n" +
"left join hrmdepartmentdefined b on a.id=b.deptid\n" +
"left join hrmresource c on to_char(regexp_substr(b.bmfzr,'[^,]+',1,1))=to_char(c.ID)\n" +
"left join hrmjobtitles d on c.JOBTITLE=d.id\n" +
"where nvl(a.canceled,0) <> 1";
rs.execute(bmSql);
// 6、同步人员数据
String queryDept = "select id from hrmdepartment a where nvl(a.canceled,0)='0' ";
RecordSet recordSet = new RecordSet();
recordSet.execute(queryDept);
while (recordSet.next()) {
String deptId = Util.null2String(recordSet.getString("id"));
// 处理部门(含子部门人数)
String getSupDeptSql = "select wm_concat(id) as allSupDept from hrmdepartment a start with a.id=" + deptId + " connect by a.supdepid=prior a.id";
rs.execute(getSupDeptSql);
String allSupDeptIds = null;
if (rs.next()) {
allSupDeptIds = Util.null2String(rs.getString("allSupDept"));
}
String getZrs = "select nvl(sum(zrs),0) zrs from (\n" +
"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 junc_org_map set fonjob = '" + zrs + "' where ftype=2 and fdateend>sysdate and fobjid=" + deptId);
// 找出没有下级的人员
String noHaveChildSql = "select a.id,a.managerid from hrmresource a \n" +
"inner join (select id from hrmresource where departmentid='" + deptId + "'\n" +
"MINUS\n" +
"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 junc_org_map\n" +
" where fobjid in (select fobjid\n" +
" from junc_org_map a\n" +
" where a.ftype = 3\n" +
" and a.fdateend > TO_DATE(to_char(SYSDATE, 'yyyy-MM-dd'),\n" +
" 'yyyy-MM-dd')\n" +
" group by fobjid\n" +
" having count(fobjid) > 1)\n" +
" and rowid not in\n" +
" (select min(rowid)\n" +
" from junc_org_map a\n" +
" where a.ftype = 3\n" +
" and a.fdateend >\n" +
" TO_DATE(to_char(SYSDATE, 'yyyy-MM-dd'), 'yyyy-MM-dd')\n" +
" 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 nvl(a.canceled,0)='0'";
rs.execute(queryAllSubCompanySql);
while (rs.next()) {
recordSet.execute("update junc_org_map set fonjob = (\n" +
"select nvl(sum(fbrs),0) fbrs from (\n" +
"select subcompanyid1,count(id) fbrs from hrmresource where status<4 group by subcompanyid1) \n" +
"where subcompanyid1 in (select id from hrmsubcompany a start with a.id=" + rs.getString("id") + " connect by a.supsubcomid=prior a.id)) \n" +
"where ftype=1 and fdateend>sysdate and fobjid=" + rs.getString("id"));
}
return "同步成功";
}
/**
* @Author ml
* @Date 2023/3/7 15:47
* @Description
*/
private void handleSuperior(String id, String managerid, String deptId) {
// 校验当前人员的直接上级是否在同一部门如不在当前部门map表中的上级应为部门id+
RecordSet rs = new RecordSet();
Boolean flag = checkManager(rs, managerid, deptId);
if (flag) {
rs.execute("insert into junc_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, nvl( a.managerid, '' ) +200000000,a.managerid,\n" +
" 0,TO_DATE(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd'), TO_DATE('2099-12-31','yyyy-MM-dd')\n" +
"from hrmresource a\n" +
"left join hrmjobtitles b on a.jobtitle=b.id\n" +
"where a.status < 4 and a.id='" + id + "'");
// 找上级的上级
rs.execute("select id,managerid,departmentid from hrmresource where id='" + managerid + "'");
if (rs.next()) {
String supId = Util.null2String(rs.getString("id"));
String supManagerId = Util.null2String(rs.getString("managerid"));
String departmentid = Util.null2String(rs.getString("departmentid"));
handleSuperior(supId, supManagerId, departmentid);
}
} else {
rs.execute("insert into junc_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, nvl( a.departmentid, '' ) +100000000,a.departmentid,\n" +
" 0,TO_DATE(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd'), TO_DATE('2099-12-31','yyyy-MM-dd')\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 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;
}
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 junc_org_map " + whereSql);
String count = "0";
if (grs.next()) {
count = grs.getString("count");
}
return !"0".equals(count);
}
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 junc_org_map t " + whereSql;
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.getCompanyIds() + ")";
} 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.getCompanyIds() + ")) or (t.ftype =2 and t.fobjid in(" + detachUtil.getDepartmentIds() + ")) 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()) {
Map<String, Object> item = new HashMap<>();
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"));
item.put("fnumber", rs.getString("fnumber"));
item.put("expand", expand ? "1" : "0");
item.put("fobjid", rs.getString("fobjid"));
item.put("fecid", rs.getString("fecid"));
item.put("fleader", "");
item.put("fleaderimg", Util.null2String(rs.getString("fleaderimg")));
item.put("fleadername", "");
item.put("fleaderjob", "");
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));
} else {
item.put("hasChildren", hasChildren(rs.getString("id"), false));
}
currentList.add(item);
}
for (Map<String, Object> stringObjectMap : currentList) {
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, fType, Util.null2String(stringObjectMap.get("fobjid")));
} else if (currentLevel == Integer.parseInt(level)) {
// 多查一层
findUserItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, false, fType, Util.null2String(stringObjectMap.get("fobjid")));
}
}
list.addAll(currentList);
}
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);
}
});
}
static class OrgSelectItem {
private String id;
private String fnumber;
private String fname;
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;
}
}
}

@ -0,0 +1,460 @@
package com.engine.junchuang.util;
import com.engine.junchuang.common.LocalDateRange;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.lang3.time.FastDateFormat;
import weaver.general.BaseBean;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Slf4j
public class OrganizationDateUtil {
public static final ZoneId CTT = ZoneId.of(ZoneId.SHORT_IDS.get("CTT"));
public static final ZoneOffset SHANGHAI_ZONE_OFF_SET = ZoneOffset.ofHours(8);
public static final FastDateFormat DATE_FORMAT = FastDateFormat.getInstance("yyyy-MM-dd");
public static final FastDateFormat DATETIME_FORMAT = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
public static final DateTimeFormatter MONTH_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM");
public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
public static final String MONTH_FORMATTER_PATTERN = "yyyy-MM";
public static final String DATE_FORMATTER_PATTERN = "yyyy-MM-dd";
public static final String DATE_TIME_FORMATTER_PATTERN = "yyyy-MM-dd HH:mm:ss";
/**
* yyyy-MM
**/
private static final String MONTH_REGEX = "^([1-9]\\d{3})-(([0]{0,1}[1-9])|([1][0-2]))$";
/**
* yyyy-MM-dd
**/
private static final String DAY_REGEX = "^[1-9]\\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$";
/**
*
*/
private static final String DAY_BAR_REGEX = "^[1-9]\\d{3}/([1-9]|1[0-2])/([1-9]|[1-2][0-9]|3[0-1])$";
public static Long localDate2EpochMilli(LocalDate localDate) {
if (localDate == null) {
return NumberUtils.LONG_ZERO;
}
return localDate.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli();
}
public static Long localDateTime2EpochMilli(LocalDateTime localDateTime) {
if (localDateTime == null) {
return NumberUtils.LONG_ZERO;
}
return localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
}
public static Long localDateTime2EpochMilli(Date localDateTime) {
if (localDateTime == null) {
return NumberUtils.LONG_ZERO;
}
return localDateTime.getTime();
}
public static String getFormatYearMonth(LocalDate localDate) {
if (localDate == null) {
return StringUtils.EMPTY;
}
try {
return localDate.format(MONTH_FORMATTER);
} catch (Exception e) {
log.warn("格式化月份错误", e);
return StringUtils.EMPTY;
}
}
public static String getFormatYearMonth(Date localDate) {
if (localDate == null) {
return StringUtils.EMPTY;
}
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(MONTH_FORMATTER_PATTERN);
return simpleDateFormat.format(localDate);
} catch (Exception e) {
log.warn("格式化月份错误", e);
return StringUtils.EMPTY;
}
}
public static String getFormatLocalDate(LocalDate localDate) {
if (localDate == null) {
return StringUtils.EMPTY;
}
try {
return localDate.format(DATE_FORMATTER);
} catch (Exception e) {
log.warn("格式化日期错误", e);
return StringUtils.EMPTY;
}
}
public static String getFormatLocalDate(LocalDateTime localDateTime) {
if (localDateTime == null) {
return StringUtils.EMPTY;
}
try {
return localDateTime.format(DATE_FORMATTER);
} catch (Exception e) {
log.warn("格式化日期错误", e);
return StringUtils.EMPTY;
}
}
public static String getFormatLocalDateTime(LocalDateTime localDateTime) {
if (localDateTime == null) {
return StringUtils.EMPTY;
}
try {
return localDateTime.format(DATE_TIME_FORMATTER);
} catch (Exception e) {
log.warn("格式化日期错误", e);
return StringUtils.EMPTY;
}
}
public static String getFormatLocalDateTime(Date localDateTime) {
if (localDateTime == null) {
return StringUtils.EMPTY;
}
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_TIME_FORMATTER_PATTERN);
return simpleDateFormat.format(localDateTime);
} catch (Exception e) {
log.warn("格式化日期错误", e);
return StringUtils.EMPTY;
}
}
public static LocalDateTime dateToLocalDateTime(Date date) {
Instant instant = date.toInstant();
ZoneId zone = ZoneId.systemDefault();
return LocalDateTime.ofInstant(instant, zone);
}
public static LocalDate dateToLocalDate(Date date) {
return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
}
public static Date localDateToDate(LocalDate localDate) {
if (null == localDate) {
return null;
}
ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
return Date.from(zonedDateTime.toInstant());
}
public static Date localDateTimeToDate(LocalDateTime localDateTime) {
if (null == localDateTime) {
return null;
}
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}
public static String getFormatLocalDate(Date date) {
if (date == null) {
return StringUtils.EMPTY;
}
LocalDateTime localDateTime = dateToLocalDateTime(date);
return getFormatLocalDate(localDateTime);
}
public static YearMonth localDate2YearMonth(Date localDate) {
if (localDate == null) {
return null;
}
Calendar c = Calendar.getInstance();
c.setTime(localDate);
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH) + 1;
return YearMonth.of(year, month);
}
public static YearMonth String2YearMonth(String localDate) {
if (checkDay(localDate)) {
return null;
}
return YearMonth.parse(localDate);
}
public static LocalDateRange localDate2Range(Date localDate) {
if (localDate == null) {
return null;
}
return LocalDateRange.builder()
.fromDate(getFirstDayDateOfMonth(localDate))
.endDate(getLastDayOfMonth(localDate))
.build();
}
public static LocalDateRange localDate2YearRange(Date localDate) {
if (localDate == null) {
return null;
}
return LocalDateRange.builder()
.fromDate(getFirstDayDateOfYear(localDate))
.endDate(getLastDayOfYear(localDate))
.build();
}
public static Date getFirstDayDateOfMonth(final Date date) {
final Calendar cal = Calendar.getInstance();
cal.setTime(date);
final int last = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
cal.set(Calendar.DAY_OF_MONTH, last);
return cal.getTime();
}
public static Date getLastDayOfMonth(final Date date) {
final Calendar cal = Calendar.getInstance();
cal.setTime(date);
final int last = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
cal.set(Calendar.DAY_OF_MONTH, last);
return cal.getTime();
}
public static Date getFirstDayDateOfYear(final Date date) {
final Calendar cal = Calendar.getInstance();
cal.setTime(date);
final int last = cal.getActualMinimum(Calendar.DAY_OF_YEAR);
cal.set(Calendar.DAY_OF_YEAR, last);
return cal.getTime();
}
public static Date getLastDayOfYear(final Date date) {
final Calendar cal = Calendar.getInstance();
cal.setTime(date);
final int last = cal.getActualMaximum(Calendar.DAY_OF_YEAR);
cal.set(Calendar.DAY_OF_YEAR, last);
return cal.getTime();
}
public static String getMonthBegin(String specifiedDay) {
int year;
int month;
Pattern pattern = Pattern.compile("\\d+-\\d+");
Matcher matcher = pattern.matcher(specifiedDay);
if (StringUtils.isEmpty(specifiedDay) || !matcher.matches()) {
return null;
} else {
year = Integer.parseInt(specifiedDay.split("-")[0]);
month = Integer.parseInt(specifiedDay.split("-")[1]);
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
Date startDate = calendar.getTime();
return sdf.format(startDate);
}
public static String getYearMonth(int yearNum, int monthNum) {
LocalDateTime dateTime = LocalDateTime.now();
int year = dateTime.getYear() + yearNum;
int month = dateTime.getMonthValue() + monthNum;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
Date startDate = calendar.getTime();
return sdf.format(startDate);
}
/**
*
*
* @param yearMonth
* @return
*/
public static boolean checkYearMonth(String yearMonth) {
return Pattern.matches(MONTH_REGEX, yearMonth);
}
/**
*
*
* @param day
* @return
*/
public static boolean checkDay(String day) {
return Pattern.matches(DAY_REGEX, day) || Pattern.matches(DAY_BAR_REGEX, day);
}
public static Date parse(String date, String pattern) {
SimpleDateFormat format = new SimpleDateFormat(pattern);
try {
return format.parse(date);
} catch (ParseException e) {
new BaseBean().writeLog(String.format("日期解析异常: %s, %s", date, pattern));
}
return null;
}
/**
* LocalDateYearMonth
*
* @param localDate
* @return
*/
public static YearMonth toYearMonth(LocalDate localDate) {
Objects.requireNonNull(localDate, "localDate");
return YearMonth.of(localDate.getYear(), localDate.getMonthValue());
}
/**
* YearMonthDate
* dayOfMonth13122928
* 使toDateEndOfMonth(YearMonth)
*
* @param yearMonth
* @param dayOfMonth
* @return
*/
public static Date toDate(YearMonth yearMonth, int dayOfMonth) {
Objects.requireNonNull(yearMonth, "yearMonth");
return localDateToDate(yearMonth.atDay(dayOfMonth));
}
/**
* YearMonthDate
*
* @param yearMonth
* @return
*/
public static Date toDateStartOfMonth(YearMonth yearMonth) {
return toDate(yearMonth, 1);
}
/**
* YearMonthDate
*
* @param yearMonth
* @return
*/
public static Date toDateEndOfMonth(YearMonth yearMonth) {
Objects.requireNonNull(yearMonth, "yearMonth");
return localDateToDate(yearMonth.atEndOfMonth());
}
/**
* YearMonthLocalDate
* dayOfMonth13122928
* 使toLocalDateEndOfMonth(YearMonth)
*
* @param yearMonth
* @param dayOfMonth
* @return
*/
public static LocalDate toLocalDate(YearMonth yearMonth, int dayOfMonth) {
Objects.requireNonNull(yearMonth, "yearMonth");
return yearMonth.atDay(dayOfMonth);
}
/**
* YearMonthLocalDate
*
* @param yearMonth
* @return
*/
public static LocalDate toLocalDateStartOfMonth(YearMonth yearMonth) {
return toLocalDate(yearMonth, 1);
}
/**
* YearMonthLocalDate
*
* @param yearMonth
* @return
*/
public static LocalDate toLocalDateEndOfMonth(YearMonth yearMonth) {
Objects.requireNonNull(yearMonth, "yearMonth");
return yearMonth.atEndOfMonth();
}
/**
* StringDate
*
* @param date
* @return
*/
public static Date stringToDateTime(String date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date parse = null;
if (date != null) {
try {
parse = sdf.parse(date);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
return parse;
}
public static Date stringToDate(String date) {
return dateStrToLocalDate(date);
}
//格式化日期
public static String strToDateLong(String strDate) {
Date date = new Date();
try {
date = new SimpleDateFormat("yyyyMMddHHmmss").parse(strDate + "000000");//先按照原格式转换为时间
} catch (ParseException e) {
e.printStackTrace();
}
String str = new SimpleDateFormat("yyyy-MM").format(date);//再将时间转换为对应格式字符串
return str;
}
private static Date dateStrToLocalDate(String date) {
Date localDate = null;
try {
date = date.substring(0, 10);
if (date.contains("/")) {
SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
localDate = format.parse(date);
} else if (date.contains("-")) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
localDate = format.parse(date);
}
} catch (Exception e) {
log.error("日期解析异常,{}", date);
localDate = null;
}
return localDate;
}
}

@ -0,0 +1,11 @@
package com.engine.junchuang.util.db;
public interface DBOperateAdapter {
String like(String some);
String concat(String some);
String currentDate();
String ifNull(String some, String defaultValue);
}

@ -0,0 +1,92 @@
package com.engine.junchuang.util.db;
import com.engine.junchuang.exception.OrganizationRunTimeException;
import weaver.conn.RecordSet;
public enum DBType implements DBOperateAdapter {
MYSQL("mysql") {
@Override
public String like(String some) {
return " like '%" + some + "%' ";
}
@Override
public String concat(String some) {
return " concat(','," + some + ",',') ";
}
@Override
public String currentDate() {
return "now()";
}
@Override
public String ifNull(String some, String defaultValue) {
return " ifnull(" + some + ",'" + defaultValue + "')";
}
},
SQLSERVER("sqlserver") {
@Override
public String like(String some) {
return " like '%" + some + "%' ";
}
@Override
public String concat(String some) {
return " ','+" + some + "+',' ";
}
@Override
public String currentDate() {
return "GETDATE()";
}
@Override
public String ifNull(String some, String defaultValue) {
return " isnull(" + some + ",'" + defaultValue + "')";
}
},
ORACLE("oracle") {
@Override
public String like(String some) {
return " like '%" + some + "%' ";
}
@Override
public String concat(String some) {
return " ',' ||" + some + "|| ',' ";
}
@Override
public String currentDate() {
return "SYSDATE";
}
@Override
public String ifNull(String some, String defaultValue) {
return " NVL(" + some + ",'" + defaultValue + "')";
}
};
private String dbtype;
DBType(String dbtype) {
this.dbtype = dbtype;
}
public static DBType get(String dbtype) {
for (DBType t : DBType.values()) {
if (t.dbtype.equalsIgnoreCase(dbtype)) {
return t;
}
}
throw new OrganizationRunTimeException("不支持的数据库类型");
}
public static boolean isOracle() {
return DBType.get(new RecordSet().getDBType()).equals(DBType.ORACLE);
}
}

@ -0,0 +1,109 @@
package com.engine.junchuang.util.detach;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.hrm.User;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.company.SubCompanyComInfo;
import java.util.*;
/**
* @author:dxfeng
* @createTime: 2022/10/28
* @version: 1.0
*/
public class DetachUtil {
private boolean detach = true;
private final Set<String> companyIds = new HashSet<>();
private final Set<String> departmentIds = new HashSet<>();
public DetachUtil(User user) {
if (1 == user.getUID() || user.isAdmin()) {
detach = false;
}
if (detach) {
try {
RecordSet rs = new RecordSet();
// 查询建模表、添加相应的权限
rs.executeQuery("select fbqx from uf_zzjgtqx where yh = ? ", user.getUID());
if (rs.next()) {
String fbqx = rs.getString("fbqx");
if (StringUtils.isNotBlank(fbqx)) {
String[] manageCompanyIds = fbqx.split(",");
for (String companyId : manageCompanyIds) {
rs.executeQuery("select id from hrmdepartment where subcompanyid1 = ? ", companyId);
while (rs.next()) {
getDetachDepartment(rs.getString("id"));
}
getDetachCompany(companyId);
}
}
}
// 拥有所辖部门及所在部门的权限
rs.executeQuery("select a.id, a.subcompanyid1 from hrmdepartment a inner join hrmdepartmentdefined b on a.id = b.deptid where a.id = ? or b.bmfzr = ? ", String.valueOf(user.getUserDepartment()), String.valueOf(user.getUID()));
while (rs.next()) {
String departmentId = rs.getString("id");
getDetachDepartment(departmentId);
String subCompanyId = rs.getString("subcompanyid1");
getDetachCompany(subCompanyId);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
public boolean isDetach() {
return detach;
}
public String getCompanyIds() {
if (CollectionUtils.isNotEmpty(companyIds)) {
return StringUtils.join(companyIds, ",");
}
return "";
}
public String getDepartmentIds() {
if (CollectionUtils.isNotEmpty(departmentIds)) {
return StringUtils.join(departmentIds, ",");
}
return "";
}
private void getDetachDepartment(String departmentId) throws Exception {
if (StringUtils.isBlank(departmentId)) {
return;
}
String allSupDepartment = new DepartmentComInfo().getAllSupDepartment(departmentId);
if (StringUtils.isNotBlank(allSupDepartment)) {
List<String> ids = Arrays.asList(allSupDepartment.split(","));
departmentIds.addAll(ids);
}
ArrayList<String> childDeptIds = new ArrayList<>();
new DepartmentComInfo().getAllChildDeptByDepId(childDeptIds, departmentId);
departmentIds.addAll(childDeptIds);
departmentIds.add(departmentId);
}
private void getDetachCompany(String companyId) throws Exception {
if (StringUtils.isBlank(companyId)) {
return;
}
String allSupCompany = new SubCompanyComInfo().getAllSupCompany(companyId);
if (StringUtils.isNotBlank(allSupCompany)) {
List<String> ids = Arrays.asList(allSupCompany.split(","));
companyIds.addAll(ids);
}
ArrayList<String> childCompIds = new ArrayList<>();
new SubCompanyComInfo().getSubCompanyLists(companyId, childCompIds);
companyIds.addAll(childCompIds);
companyIds.add(companyId);
}
}

@ -0,0 +1,38 @@
package com.engine.junchuang.util.response;
public enum ResultCode implements IErrorCode {
SUCCESS(200,"操作成功"),
FAILED(500,"操作失败"),
VALIDATE_FAILED(404,"参数检验失败"),
UNAUTHORIZED(401,"暂未登陆或相关token已经过期"),
FORBIDDEN(403,"没有相关权限"),
BODY_NOT_MATCH(400,"请求的数据格式不符!"),
INTERNAL_SERVER_ERROR(500, "服务器内部错误!"),
SERVER_BUSY(503,"服务器正忙,请稍后再试!");
private long code;
private String msg;
ResultCode(long code, String msg) {
this.code = code;
this.msg = msg;
}
@Override
public long getCode() {
return code;
}
@Override
public String getMessage() {
return msg;
}
}
interface IErrorCode {
long getCode();
String getMessage();
}

@ -0,0 +1,197 @@
package com.engine.junchuang.util.response;
/**
* @Author weaver_cl
* @description:
* @Date 2022/4/26
* @Version V1.0
**/
import weaver.general.BaseBean;
import java.io.Serializable;
public class ReturnResult<T> implements Serializable {
private static final long serialVersionUID = 1L;
private long code;
private T data;
private String msg;
public ReturnResult() {
this.code = ResultCode.SUCCESS.getCode();
this.msg = ResultCode.SUCCESS.getMessage();
}
/**
* @param code
* @param msg
* @param data
*/
public ReturnResult(long code, String msg, T data) {
this.code = code;
this.data = data;
this.msg = msg;
}
/**
* code data
*
* @param data
*/
public ReturnResult(T data) {
this.code = ResultCode.SUCCESS.getCode();
this.data = data;
}
/**
* code msg
*
* @param code
* @param msg
*/
public ReturnResult(long code, String msg) {
this.code = code;
this.msg = msg;
}
public long getCode() {
return code;
}
public void setCode(long code) {
this.code = code;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public ReturnResult Msg(String msg) {
this.setMsg(msg);
return this;
}
public ReturnResult Code(long code) {
this.setCode(code);
return this;
}
public ReturnResult Data(T data) {
this.setData(data);
return this;
}
/**
*
*/
public static <T> ReturnResult<T> successed() {
return new ReturnResult<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage());
}
/**
*
*
* @param data
* @return
*/
public static <T> ReturnResult<T> successed(T data) {
return new ReturnResult<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
}
/**
*
*
* @param errorCode
* @param <T>
* @return
*/
public static <T> ReturnResult<T> failed(IErrorCode errorCode) {
return new ReturnResult<>(errorCode.getCode(), errorCode.getMessage(), null);
}
/**
*
*
* @param msg
* @return
*/
public static <T> ReturnResult<T> failed(String msg) {
return failed(ResultCode.FAILED);
}
/**
*
*
* @param <T>
* @return
*/
public static <T> ReturnResult<T> validateFailed() {
return failed(ResultCode.VALIDATE_FAILED);
}
/**
*
*
* @param msg
* @param <T>
* @return
*/
public static <T> ReturnResult<T> validateFailed(String msg) {
return new ReturnResult<>(ResultCode.VALIDATE_FAILED.getCode(), msg);
}
/**
*
*
* @param e
* @param <T>
* @return
*/
public static <T> ReturnResult<T> exceptionHandle(Exception e) {
new BaseBean().writeLog(e);
return new ReturnResult<>(ResultCode.FAILED.getCode(), e.getMessage());
}
/**
* token..
*
* @param data
* @param <T>
* @return
*/
public static <T> ReturnResult<T> unauthorized(T data) {
return new ReturnResult<>(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data);
}
/**
*
*
* @param data
* @param <T>
* @return
*/
public static <T> ReturnResult<T> forbiden(T data) {
return new ReturnResult<>(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data);
}
}

@ -0,0 +1,119 @@
package com.engine.junchuang.web;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.junchuang.util.response.ReturnResult;
import com.engine.junchuang.wrapper.OrgChartWrapper;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;
/**
* @Author ml
* @Date 2023/2/27 17:30
* @Description This is description of class
* @Since version-1.0
*/
public class OrgChartController {
public OrgChartWrapper getOrgChartWrapper(User user) {
return ServiceUtil.getService(OrgChartWrapper.class, user);
}
/**
*
*/
@GET
@Path("/getCondition")
@Produces(MediaType.APPLICATION_JSON)
public String getCondition(@Context HttpServletRequest request, @Context HttpServletResponse
response) {
Map<String, Object> apidatas = new HashMap<String, Object>();
try {
User user = HrmUserVarify.getUser(request, response);
//实例化Service 并调用业务类处理
apidatas = getOrgChartWrapper(user).getOptionCondition(ParamUtil.request2Map(request), user);
} catch (Exception e) {
//异常处理
e.printStackTrace();
apidatas.put("api_status", false);
apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
}
//数据转换
return JSONObject.toJSONString(apidatas);
}
/**
*
*/
@GET
@Path("/userData")
@Produces(MediaType.APPLICATION_JSON)
public String getUserData(@Context HttpServletRequest request, @Context HttpServletResponse
response) {
Map<String, Object> apidatas = new HashMap<String, Object>();
try {
User user = HrmUserVarify.getUser(request, response);
//实例化Service 并调用业务类处理
apidatas = getOrgChartWrapper(user).getUserData(ParamUtil.request2Map(request), user);
} catch (Exception e) {
//异常处理
e.printStackTrace();
apidatas.put("api_status", false);
apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
}
//数据转换
return JSONObject.toJSONString(apidatas);
}
/**
*
*/
@GET
@Path("/asyncUserData")
@Produces(MediaType.APPLICATION_JSON)
public String asyncUserData(@Context HttpServletRequest request, @Context HttpServletResponse
response) {
Map<String, Object> apidatas = new HashMap<String, Object>();
try {
User user = HrmUserVarify.getUser(request, response);
//实例化Service 并调用业务类处理
apidatas = getOrgChartWrapper(user).asyncUserData(ParamUtil.request2Map(request), user);
} catch (Exception e) {
//异常处理
e.printStackTrace();
apidatas.put("api_status", false);
apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
}
//数据转换
return JSONObject.toJSONString(apidatas);
}
/**
*
*/
@GET
@Path("/syncOrgMapData")
@Produces(MediaType.APPLICATION_JSON)
public ReturnResult synchronousData(@Context HttpServletRequest request, @Context HttpServletResponse
response) {
try {
User user = HrmUserVarify.getUser(request, response);
Map<String, Object> params = ParamUtil.request2Map(request);
return ReturnResult.successed(getOrgChartWrapper(user).syncOrgMapData(params));
} catch (Exception e) {
return ReturnResult.exceptionHandle(e);
}
}
}

@ -0,0 +1,38 @@
package com.engine.junchuang.wrapper;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.junchuang.service.OrgChartService;
import com.engine.junchuang.service.OrgChartServiceImpl;
import weaver.hrm.User;
import java.util.Map;
/**
* @Author ml
* @Date 2023/3/2 14:29
* @Description This is description of class
* @Since version-1.0
*/
public class OrgChartWrapper extends Service {
private OrgChartService getOrgChartService(User user) {
return ServiceUtil.getService(OrgChartServiceImpl.class, user);
}
public Map<String, Object> getOptionCondition(Map<String, Object> request2Map, User user) {
return getOrgChartService(user).getOptionCondition(request2Map, user);
}
public Map<String, Object> getUserData(Map<String, Object> request2Map, User user) {
return getOrgChartService(user).getUserData(request2Map, user);
}
public Map<String, Object> asyncUserData(Map<String, Object> request2Map, User user) {
return getOrgChartService(user).asyncUserData(request2Map, user);
}
public String syncOrgMapData(Map<String, Object> request2Map) {
return getOrgChartService(user).syncOrgMapData(request2Map, user);
}
}

@ -1,14 +0,0 @@
package test;
/**
* @Author weaver_cl
* @Description:
* @Date 2022/10/9
* @Version V1.0
**/
public class MainTest {
public static void main(String[] args) {
}
}
Loading…
Cancel
Save