Compare commits

..

4 Commits

12
.gitignore vendored

@ -1,11 +1,15 @@
/weaver-develop.iml
/out/
.idea/
/target/
HELP.md
target/
.idea
/test
/src/rebel.xml
/src/META-INF
/WEB-INF/config
/log
/src/META-INF/
/src/test/
/log

@ -0,0 +1,8 @@
<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>

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

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

@ -0,0 +1,13 @@
<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>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

@ -0,0 +1,188 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>
</head>
<body style="text-align:center;">
<div id="orgTree" class="OkrTree" style="display: inline-block; zoom:1">
</div>
</body>
<style>
.OkrTree .tagBox div.tagRight>.line {
width: 182px !important;
margin-top: -12px !important;
}
</style>
</html>
<script src="./okrTree.js"></script>
<script>
var json = [
{
"id": "topOne",
"name": "康晴",
"position": "存在以下多个顶点!",
"photos": "/img/t1.png",
"pid": "",
"children": [
{
"id": "zwx01",
"name": "邹文霞",
"position": "高级副总裁",
"photos": "/OrgChart/D02043.JPG",
"pid": "topOne",
"type": "tag",
"children": [
{
"id": "zb",
"name": "周斌",
"position": "(兼)AM",
"photos": "/OrgChart/D0002.JPG",
"pid": "zwx01",
"children": []
}
]
},
{
"id": "topId",
"name": "徐金尧",
"position": "存在以下多个顶点!",
"photos": "/img/t1.png",
"pid": "topOne",
"children": [{
"id": "00008",
"name": "张清龙",
"position": "MR",
"photos": "/Images/PER/bg_02.gif",
"pid": "topId",
"children": [
{
"id": "wym",
"name": "王益明",
"position": "(兼)AM",
"photos": "/OrgChart/D0002.JPG",
"pid": "00008",
"children": [
{
"id": "xh",
"name": "肖辉",
"position": "(兼)AM",
"photos": "/OrgChart/D0002.JPG",
"pid": "wym"
},{
"id": "cj",
"name": "陈静",
"position": "(兼)AM",
"photos": "/OrgChart/D0002.JPG",
"pid": "wym"
}
]
},{
"id": "whs",
"type":"tag",
"name": "吴海松",
"position": "(兼)AM",
"photos": "/OrgChart/D0002.JPG",
"pid": "00008",
"children": []
}
]
}, {
"id": "00009",
"name": "lex",
"position": "APM",
"photos": "/Images/PER/bg_02.gif",
"pid": "topId",
"children": []
}, {
"id": "1110222",
"name": "员工姓名",
"position": "MR",
"photos": "/Images/PER/bg_02.gif",
"pid": "topId",
"children": []
}, {
"id": "D0001",
"name": "Lex",
"position": "高级副总裁",
"photos": "/OrgChart/D0001.JPG",
"pid": "topId",
"children": [{
"id": "D0002",
"name": "atest",
"position": "(兼)AM",
"photos": "/OrgChart/D0002.JPG",
"pid": "D0001",
"children": []
},{
"id": "D0003",
"name": "btest",
"position": "(兼)AM",
"photos": "/OrgChart/D0002.JPG",
"pid": "D0001",
"children": []
}]
}, {
"id": "D0730",
"name": "LEX",
"position": "AM",
"photos": "/Images/PER/bg_02.gif",
"pid": "topId",
"children": []
}, {
"id": "D0732",
"name": "test",
"position": "AM",
"photos": "/Images/PER/bg_02.gif",
"pid": "topId",
"children": []
}, {
"id": "101BJ559",
"name": "肖锋",
"position": "(兼)AM",
"photos": "/Images/PER/bg_02.gif",
"pid": "topId",
"children": []
}]
}
]
}
]
var s = $("#orgTree").OkrTree({
data: json, // 数据源
isdrop: false, //是否支持拖拽
tagTemplate: function(data, path) {
console.log("tag",data);
if(data.id == 'zwx01') {
return ["<div style='width:120px;background:#eee;border-radius:2px;margin-left: 80px'>",
"<img draggable='false' width='100%' height='110' src='img/t.png' />",
data.name, "</div><div class='expandIcon' title='折叠'>-</div>",
"<div class='row'><div class='item' data-z='' data-path='0-1-3-0'><div class='lineTop'><div class='line-left'></div><div class='line-right top'></div></div><div class='content'><div class='template' draggable='false'><div style='width:120px;background:#eee;border-radius:2px;overflow:hidden'><img draggable='false' width='100%'' height='110' src='img/t.png'>atest</div></div></div></div><div class='item' data-z='' data-path='0-1-3-1'><div class='lineTop'><div class='line-left top'></div><div class='line-right ''></div></div><div class='content'><div class='template' draggable='false'><div style='width:120px;background:#eee;border-radius:2px;overflow:hidden'><img draggable='false' width='100%'' height='110' src='img/t.png'>btest</div></div></div></div></div>"
].join("");
}else {
return ["<div style='width:120px;background:#eee;border-radius:2px'>",
"<img draggable='false' width='100%' height='110' src='img/t.png' />",
data.name, "</div>",
].join("");
}
},
itemTemplate: function(data, path) {
console.log("item",data);
return ["<div style='width:120px;background:#eee;border-radius:2px;overflow:hidden'>",
"<img draggable='false' width='100%' height='110' src='img/t.png' />",
data.name , "</div>"
].join("");
}
})
</script>

@ -0,0 +1,305 @@
/**
* version:0.1
* 2020/12/18
* author:fanjiantao (abbe)
*/
!(function(name, factory) {
try {
if ($) {}
} catch (error) {
console.warn(error + "【本项目需要依赖jquery库】");
return
}
if (typeof exports === 'object') {
module.exports = factory();
} else if (typeof define === 'function' && define.amd) {
define(factory);
} else {
window[name] = factory();
}
})("OkrTree", function() {
/**模板区域**/
var namespace = "OkrTree",
dataArray = [],
tagCalback = null,
itemCallback = null,
isdrop = true,
dropDom = "", //当前正在拖动的dom
//带有子节点的需要这条dom树
lineDom = "<div class='line'><div class='left top'></div><div class='right top'></div><div style='clear:both'></div></div>",
//左叶子树需要
lineTop = function(left, right) {
return "<div class='lineTop'><div class='line-left ".concat(left ? "" : "top", "'></div><div class='line-right ").concat(right ? "" : "top", "'></div></div>");
},
// lineTop = "<div class='lineTop'><div class='line-left top'></div><div class='line-right top'></div></div>",
// leftDom = "<div class=leftWhite></div>",
// rightDom = "<div class=rightWhite></div>",
leftDom = "",
rightDom = "",
tagBox = function(data, path, last) {
// console.log(last)
return '<div class="tagBox" style="position:relative">' + (last ? '<div class="tagDownLine"></div>' : '') + '<div class="tagLeft" ' + (last && 'style="border:none"') + ' ><div class="noneLine"></div></div><div class="tagRight" ' + (last && 'style="border:none"') + ' ><div class="line"></div><div class="tagContent">' + (tagCalback && tagCalback(data, path)) + '</div><div class="noneLine"></div></div></div>'
},
expandBox = "<div class='expandIcon' title='折叠'>-</div>",
itemTemplate = function(data, path) {
if (itemCallback) { return itemCallback(data, path) };
return ""
};
/**core code----------------------------------------------------------------------------------------------------------------**/
function buildNode(data) {
var template = function(data, vip, root, path, tag_index, zType) {
var s = "",
len = data.length,
parent = path || "";
$.each(data, function(index, item) {
var path = "",
tag = "",
zr = "",
lastTag = item.children instanceof Array && item.children.length == 1 && item.children[0].type == "tag";
tagIndex = 0;
if (!parent) {
path = index + "";
} else {
path = parent + '-' + index;
}
/* 处理tag标记*/
item.children && $.each(item.children, function(index, item1) {
if (item1.type && item1.type == "tag") {
tag = tagBox(item1, path + '-' + index, lastTag);
if (item.children.length > 1 && index == 0) {
tagIndex = 1;
zr = "left";
} else {
(item.children.length - 1 == index) && (tagIndex = item.children.length - 2, zr = "right")
}
}
})
if (item.type && item.type == "tag") return;
s += "<div class=\"item\" data-z=\"".concat(zType, "\" data-path=").concat(path, ">").concat(root ? '' : lineTop(index == 0 && !root || index == tag_index && zType == 'left', index == len - 1 || index == tag_index && zType == 'right'), "<div class=\"content\"><div class=\"template\" draggable=\"").concat(isdrop, "\">").concat(itemTemplate(item, path), "</div></div>").concat(item.children && item.children.length > 0 && expandBox || "").concat(tag).concat(item.children && item.children.length > 0 ? "".concat(tag == "" ? lineDom : "", "<div class=\"row\">").concat(template(item.children, item.children.length == 1, false, parent + (parent && "-") + index, tagIndex, zr), "</div>") : '', "</div>");
//s += `<div class="item" data-z="${zType}" data-path=${path}>${root?'':lineTop((index==0&&!root||(index==tag_index&&zType=='left')),(index==len-1||(index==tag_index&&zType=='right')))}<div class="content"><div class="template" draggable="${isdrop}">${itemTemplate(item,path)}</div></div>${item.children&&item.children.length>0&&expandBox||""}${tag}${(item.children&& item.children.length > 0)?`${tag==""?lineDom:""}<div class="row">${template(item.children,item.children.length==1,false,parent+(parent&&"-")+index,tagIndex,zr)}</div>`:''}</div>`;
})
return s;
};
return "<div class='row'>" + template(data, false, true) + "</div>";
}
/**局部处理tag标记**/
function reverseObject(object) {
/**反转对象**/
var newObject = {};
var keys = [];
for (var key in object) {
keys.push(key);
}
for (var i = keys.length - 1; i >= 0; i--) {
var value = object[keys[i]];
newObject[keys[i]] = value;
}
return newObject;
}
function renderTagBox(contentWidth) {
// $("." + namespace + " .tagBox").each(function(index, item) {
// var tagContent = tagBox.find(".tagContent");
// var contentWidth = tagContent.outerWidth();
// tagBox.css({
// width: (contentWidth+50)*2 + "px"
// });
// })
}
function renderLayout() {
//待处理偏移量的元素;
var walkList = [];
//1.先处理宽度问题
$("." + namespace + " .tagBox").each(function(index, item) {
// var tagWidth = 170;
var tagBox = $(item);
var tagBoxwidth = $(item).outerWidth();
var row = tagBox.siblings('.row');
var tagContent = tagBox.find(".tagContent");
var contentHeight = tagContent.outerHeight();
var contentWidth = tagContent.outerWidth();
tagBox.css({
height: contentHeight + 82 + "px",
})
tagContent.css({
marginTop: -(contentHeight / 2) + "px"
})
if (tagBoxwidth / 2 > (contentWidth + 50)) {
return
}
tagBox.css({
width: (contentWidth + 50) * 2 + "px"
});
//把暂存区元素注入队列,后续处理
walkList.push({
tag: tagBox,
row: row, //row 元素
items: row.children(".item") //子元素,
});
})
$.each(walkList.reverse(), function(index, item) {
function sumWidth(arr) {
var s = 0;
for (var i = arr.length - 1; i >= 0; i--) {
s += $(arr[i]).outerWidth();
}
return s;
}
var diff = item.row.outerWidth() - (sumWidth(item.items));
if (diff > 0) {
item.row.css({
'paddingLeft': diff / 2 + "px"
});
} else {
item.tag.css({
width: "auto"
})
}
item.items.length == 1 && item.tag.children('div').css({
'borderBottom': 'none'
});
})
walkList = null;
}
function initEvent() {
$(document.body).on('click', "div.expandIcon", function() {
var parent = $(this).parent();
if (parent.hasClass("expand")) {
parent.removeClass("expand");
$(this).nextAll().css({
visibility: '',
// display: ''
}).end().text("-").attr("title", "折叠");
} else {
parent.addClass("expand");
$(this).nextAll().css({
visibility: 'hidden',
// display: "none"
}).end().text("+").attr('title', "展开");
}
renderLayout()
});
if (!isdrop) return;
// $(document).on("dragstart", function(e) {
// var e = e || window.event
// if (e.target.tagName == "IMG") {
// };
// })
$("." + namespace).on('dragstart', '.template', function(e) {
dropDom = $(this);
dropDom && $("#orgTree .template").not(dropDom && dropDom.parent().parent().find(".template")).css({
border: "dashed 1px black"
});
});
$("." + namespace).on('dragover', ".template", function(e) {
var e = e || window.event
e.preventDefault();
if ($(this)[0] !== dropDom[0]) {
$(this).not(dropDom.parent().parent().find(".template")).css({
border: "dashed 1px red"
})
}
});
$("." + namespace).on('dragleave', ".template", function(e) {
dropDom && $("#orgTree .template").not(dropDom && dropDom.parent().parent().find(".template")).css({
border: "dashed 1px black"
});
});
$("." + namespace).on('drop', '.template', function(e) {
var e = e || window.event
e.preventDefault();
var to = $(this).parent().parent()[0],
form = dropDom.parent().parent()[0];
if ($.contains(form, to) || dropDom[0] == $(this)[0]) {
// console.log('不能执行自己的拖拽逻辑')
} else {
walkData($(to).attr('data-path'), $(form).attr("data-path"));
}
})
$("." + namespace).on('dragend', function(e) {
$("." + namespace + " .template").css({
border: ""
});
})
}
/**拖拽节点后处理布局**/
function walkData(toPath, formPath) {
var formPatharrray = formPath.split("-");
var toData = new Function("dataArray", "return dataArray" + "[" + toPath.split("-").join("].children[") + "]")(dataArray);
var formData = new Function("dataArray", "return dataArray" + "[" + formPath.split("-").join("].children[") + "]")(dataArray);
var popIndex = formPatharrray.pop();
var formParent = new Function("dataArray", "return dataArray" + "[" + formPatharrray.join("].children[") + "]")(dataArray);
if (toData.children) {
toData.children.push(formData);
formParent.children.splice(popIndex, 1);
} else {
toData.children = [formData];
formParent.children.splice(popIndex, 1);
}
formParent.children.length == 0 && (formParent.children = "")
$("." + namespace).html(buildNode(dataArray)); // 插入模板
renderLayout(); // 渲染布局
}
function init() {
$("." + namespace).html(buildNode(dataArray)); // 插入模板
renderLayout(); // 渲染布局
initEvent(); // 注册事件
}
$.fn[namespace] = function(options) {
var defaults = {
version: "1.0",
isdrop: true,
data: [],
css: {
lineColor: "black",
background: "#fff"
},
style: document.createElement('style'),
},
opts = $.extend({}, defaults, options),
style = ".OkrTree .row {zoom: 1}.OkrTree .row::after {content: \" \";display: block;clear: both}.OkrTree .item {display: table-cell;position: relative;text-align: center;vertical-align: top;}.OkrTree .line {margin: auto;height: 20px}.OkrTree .line .left {width: 50%;height: 100%;float: left;box-sizing: border-box;border-right: solid 1px ".concat(opts.css.lineColor, ";}.OkrTree .line .right {width: 50%;height: 100%;float: left;box-sizing: border-box;border-left: solid 1px ").concat(opts.css.lineColor, ";}.OkrTree .row .item:first-child {margin-left: 0}.OkrTree .content {text-align: center;margin: auto;box-sizing: border-box;padding: 0 10px;border-radius: 4px;white-space: normal}.OkrTree .content>.template {width: auto;margin: auto;display: inline-block;border-radius: 4px;word-break: break-all;white-space: pre-wrap}.OkrTree .lineTop {height: 20px;margin: auto;position: relative;}.OkrTree .lineTop>.line-left {width: 50%;position: absolute;box-sizing: border-box;height: 100%;border-right: solid 1px ").concat(opts.css.lineColor, ";}.OkrTree .lineTop>.line-left.top {border-top: solid 2px ").concat(opts.css.lineColor, ";}.OkrTree .lineTop>.line-right.top {border-top: solid 2px ").concat(opts.css.lineColor, ";}.OkrTree .lineTop>.line-right {position: absolute;left: 50%;box-sizing: border-box;width: 50%;border-left: solid 1px ").concat(opts.css.lineColor, ";height: 100%;}.OkrTree .tagBox {overflow: hidden;min-height: 50px;box-sizing: border-box}.OkrTree .tagBox>div {float: left;width: 50%;height: 100%;box-sizing: border-box;}.OkrTree .tagBox div.tagLeft {border-right: solid 1px ").concat(opts.css.lineColor, ";position: relative}.OkrTree .tagBox>.tagDownLine {width: 0px;border-right: 2px solid ").concat(opts.css.lineColor, ";position: absolute;left: 50%;margin-left: -1px;height: 50%}.OkrTree .tagBox div.tagRight {border-left: solid 1px ").concat(opts.css.lineColor, ";position: relative}.OkrTree .tagBox div.tagRight>.line {width: 50px;height: 0;top: 50%;margin-top: -1px;border-bottom: solid 2px ").concat(opts.css.lineColor, ";position: absolute}.OkrTree .tagContent {position: absolute;top: 50%;left: 50px;width: auto;text-align: center;border-radius: 4px;}.OkrTree .tagBox div.tagRight .tagItem {height: 40px;background-color: green;position: absolute;right: 0;top: 50%;margin-top: -20px;border-radius: 2px;color: #fff;text-align: center;line-height: 40px}.OkrTree .expandIcon {display: inline-block;width: 20px;height: 20px;background-color: ").concat(opts.css.lineColor, ";color: #fff;font-size: 100%;line-height: 20px;text-align: center;border-radius: 50%;cursor: pointer;font-weight: bold}.OkrTree .template {border: solid 1px transparent;}");;
this.addClass(namespace);
opts.style.innerHTML = style;
document.getElementsByTagName('head')[0].appendChild(opts.style);
dataArray = opts.data instanceof Array && opts.data;
typeof opts.itemTemplate == 'function' && (itemCallback = opts.itemTemplate);
typeof opts.tagTemplate == 'function' && (tagCalback = opts.tagTemplate);
typeof opts.isdrop == 'boolean' && (isdrop = opts.isdrop);
init();
return opts;
}
})

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

@ -0,0 +1,13 @@
package com.api.jhsecond.web;
import javax.ws.rs.Path;
/**
* @Author liang.cheng
* @Date 2024/7/16 5:14 PM
* @Description: nbjh
* @Version 1.0
*/
@Path("/jhsecond/chart")
public class OrganizationChartAction extends com.engine.jhsecond.web.OrganizationChartAction {
}

@ -0,0 +1,60 @@
package com.engine.jhsecond.entity.vo;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import java.util.List;
/**
* @Author liang.cheng
* @Date 2024/7/16 5:19 PM
* @Description: TODO
* @Version 1.0
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OrganizationChartVo {
private Integer id;
private String deptName;
private String lastName;
private String jobName;
private String photoUrl;
private String type;
private String halfType;
/**
* 线
*/
private String addLine;
/**
*
*/
private String addCount;
/**
* 0 1
*/
private Integer show;
private Integer pId;
private Integer orderId;
private List<OrganizationChartVo> children;
}

@ -0,0 +1,24 @@
package com.engine.jhsecond.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author liang.cheng
* @Date 2024/7/29 4:57 PM
* @Description:
* @Version 1.0
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PersonInfoVo {
private String lastName;
private String photoUrl;
}

@ -0,0 +1,31 @@
package com.engine.jhsecond.service;
import java.util.Map;
/**
* @Author liang.cheng
* @Date 2024/7/16 5:16 PM
* @Description:
* @Version 1.0
*/
public interface OrganizationChartService {
/**
* @Description:
* @Author: liang.cheng
* @Date: 2024/7/16 5:25 PM
* @param: [params]
* @return: java.util.Map<java.lang.String,java.lang.Object>
*/
Map<String, Object> selectData(Map<String, Object> params);
/**
* @Description:
* @Author: liang.cheng
* @Date: 2024/7/29 1:55 PM
* @param: [request2Map]
* @return: java.util.Map<java.lang.String,java.lang.Object>
*/
Map<String, Object> selectChart(Map<String, Object> request2Map);
}

@ -0,0 +1,214 @@
package com.engine.jhsecond.service.impl;
import com.engine.core.impl.Service;
import com.engine.jhsecond.entity.vo.OrganizationChartVo;
import com.engine.jhsecond.entity.vo.PersonInfoVo;
import com.engine.jhsecond.service.OrganizationChartService;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.job.JobTitlesComInfo;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author liang.cheng
* @Date 2024/7/16 5:17 PM
* @Description:
* @Version 1.0
*/
public class OrganizationChartServiceImpl extends Service implements OrganizationChartService {
@Override
public Map<String, Object> selectData(Map<String, Object> params) {
BaseBean bb = new BaseBean();
RecordSet rs = new RecordSet();
Map<String,Object> data = new HashMap<>();
JobTitlesComInfo jopInfo = new JobTitlesComInfo();
String topId = bb.getPropValue("jhsecond", "topId");
String halfId = bb.getPropValue("jhsecond", "halfId");
String superId = bb.getPropValue("jhsecond", "superId");
String halfNodeId = bb.getPropValue("jhsecond", "halfNodeId");
//1.获取当前有效人员数据
rs.executeQuery("select a.id,a.departmentid,a.lastname,a.jobtitle,a.resourceimageid,b."+superId+",b."+halfNodeId+" from " +
" hrmresource a left join cus_fielddata b on a.id = b.id and b.scopeid = 3 where status < 4");
List<OrganizationChartVo> voList = new ArrayList<>();
while (rs.next()) {
OrganizationChartVo build = OrganizationChartVo.builder()
.id(Util.getIntValue(rs.getString("id")))
.deptName(getDepartmentName(Util.null2String(rs.getString("departmentid"))))
.lastName(Util.null2String(rs.getString("lastname")))
.jobName(jopInfo.getJobTitlesname(Util.null2String(rs.getString("jobtitle"))))
.photoUrl(getPhotoUrl(Util.null2String(rs.getString("resourceimageid"))))
.pId(Util.getIntValue(rs.getString(superId)))
.type("0".equals(Util.null2String(rs.getString(halfNodeId))) ? "tag" : "")
.build();
voList.add(build);
}
//2.筛选出顶部节点
OrganizationChartVo parentNode = voList.stream()
.filter(vo -> vo.getId() == Integer.parseInt(topId))
.findFirst()
.orElse(null);
//3.设置半节点存在下级属性值并获取下级
voList.stream()
.filter(vo -> vo.getId() == Integer.parseInt(halfId))
.forEach(vo -> vo.setHalfType("true"));
List<OrganizationChartVo> filteredList = voList.stream()
.filter(vo -> vo.getPId() != null && vo.getPId() == Integer.parseInt(halfId))
.collect(Collectors.toList());
//4.递归处理
buildHierarchy(voList,parentNode);
data.put("result",parentNode);
data.put("halfResult",filteredList);
return data;
}
@Override
public Map<String, Object> selectChart(Map<String, Object> request2Map) {
BaseBean bb = new BaseBean();
RecordSet rs = new RecordSet();
Map<String,Object> data = new HashMap<>(4);
String topId = bb.getPropValue("jhsecond", "topId");
String halfId = bb.getPropValue("jhsecond", "halfId");
String jobId = bb.getPropValue("jhsecond", "jobId");
//1.获取建模组织架构图数据
rs.executeQuery("select a.gwszbm,a.zzjggw,b.zzjgtgw,a.zzjggwsj,a.sfbj,a.gjsx,a.sfycx,a.yccj from uf_zzjgdygx a left join uf_zzjggw b on a.zzjggw = b.id");
List<OrganizationChartVo> voList = new ArrayList<>();
while (rs.next()) {
PersonInfoVo personInfoVo = selectPersonInfo(Util.null2String(rs.getString("zzjggw")), jobId);
OrganizationChartVo build = OrganizationChartVo.builder()
.id(Util.getIntValue(rs.getString("zzjggw")))
.deptName(Util.null2String(rs.getString("gwszbm")))
.lastName(personInfoVo.getLastName())
.jobName(Util.null2String(rs.getString("zzjgtgw")))
.photoUrl(personInfoVo.getPhotoUrl())
.pId(Util.getIntValue(rs.getString("zzjggwsj")))
.orderId(Util.getIntValue(rs.getString("gjsx"),999))
.addLine("0".equals(Util.null2String(rs.getString("sfycx"))) ? "true" : "false")
.addCount(Util.null2String(rs.getString("yccj")))
.type("0".equals(Util.null2String(rs.getString("sfbj"))) ? "tag" : "")
.show(personInfoVo.getLastName() == null ? 1 : 0)
.build();
voList.add(build);
}
//2.筛选出顶部节点
OrganizationChartVo parentNode = voList.stream()
.filter(vo -> vo.getId() == Integer.parseInt(topId))
.findFirst()
.orElse(null);
//3.设置半节点存在下级属性值并获取下级
voList.stream()
.filter(vo -> vo.getId() == Integer.parseInt(halfId))
.forEach(vo -> vo.setHalfType("true"));
List<OrganizationChartVo> filteredList = voList.stream()
.filter(vo -> vo.getPId() != null && vo.getPId() == Integer.parseInt(halfId))
.collect(Collectors.toList());
//4.递归处理
buildHierarchyChart(voList,parentNode);
data.put("result",parentNode);
data.put("halfResult",filteredList);
return data;
}
private void buildHierarchyChart(List<OrganizationChartVo> list, OrganizationChartVo parentNode) {
List<OrganizationChartVo> children = list.stream()
.filter(vo -> vo.getPId().equals(parentNode.getId()))
.collect(Collectors.toList());
//排序处理
children = children.stream()
.sorted(Comparator.comparingInt(OrganizationChartVo::getOrderId))
.collect(Collectors.toList());
for (OrganizationChartVo child : children) {
buildHierarchyChart(list, child);
}
parentNode.setChildren(children);
}
private PersonInfoVo selectPersonInfo(String zzjggw, String jobId) {
PersonInfoVo personInfo = new PersonInfoVo();
RecordSet rs = new RecordSet();
//rs.getDBType().equals("")
rs.executeQuery("select a.id,a."+jobId+",b.lastname,b.resourceimageid from cus_fielddata a left join hrmresource b on a.id = b.id \n" +
" and a.scopeid = 3 where b.status < 4 and a."+jobId+" = ?",zzjggw);
if (rs.next()) {
personInfo.setLastName(Util.null2String(rs.getString("lastname")));
personInfo.setPhotoUrl(getPhotoUrl(Util.null2String(rs.getString("resourceimageid"))));
}
return personInfo;
}
/**
*
* @param list
* @param parentNode
*/
private void buildHierarchy(List<OrganizationChartVo> list, OrganizationChartVo parentNode) {
List<OrganizationChartVo> children = list.stream()
.filter(vo -> vo.getPId().equals(parentNode.getId()))
.collect(Collectors.toList());
for (OrganizationChartVo child : children) {
buildHierarchy(list, child);
}
parentNode.setChildren(children);
}
/**
*
* @param departmentId
* @return
*/
private String getDepartmentName(String departmentId) {
try {
DepartmentComInfo deptInfo = new DepartmentComInfo();
return deptInfo.getDepartmentName(departmentId);
}catch (Exception e) {
return "";
}
}
/**
*
* @param resourceImageId
* @return
*/
private String getPhotoUrl(String resourceImageId){
if("".equals(resourceImageId)){
return "/messager/images/icon_w_wev8.jpg";
}else {
return "/weaver/weaver.file.FileDownload?fileid=" + resourceImageId;
}
}
}

@ -0,0 +1,68 @@
package com.engine.jhsecond.web;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.jhsecond.service.OrganizationChartService;
import com.engine.jhsecond.service.impl.OrganizationChartServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
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 liang.cheng
* @Date 2024/7/16 5:15 PM
* @Description: nbjh
* @Version 1.0
*/
public class OrganizationChartAction {
private OrganizationChartService getOrganizationChartService(User user) {
return ServiceUtil.getService(OrganizationChartServiceImpl.class,user);
}
@GET
@Path("/selectData")
@Produces(MediaType.APPLICATION_JSON)
public String selectData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
Map<String, Object> apidatas = new HashMap<>(4);
try {
User user = HrmUserVarify.getUser(request, response);
apidatas = getOrganizationChartService(user).selectData(ParamUtil.request2Map(request));
apidatas.put("api_status", true);
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(apidatas);
} catch (Exception e) {
apidatas.put("api_status", false);
return apidatas.toString();
}
}
@GET
@Path("/selectChart")
@Produces(MediaType.APPLICATION_JSON)
public String selectChart(@Context HttpServletRequest request, @Context HttpServletResponse response) {
Map<String, Object> apidatas = new HashMap<>(4);
try {
User user = HrmUserVarify.getUser(request, response);
apidatas = getOrganizationChartService(user).selectChart(ParamUtil.request2Map(request));
apidatas.put("api_status", true);
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(apidatas);
} catch (Exception e) {
apidatas.put("api_status", false);
return apidatas.toString();
}
}
}

@ -0,0 +1,14 @@
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