|
|
|
@ -19,44 +19,36 @@ public class CompanyUserModel {
|
|
|
|
|
*/
|
|
|
|
|
public JSONArray getTreeData() {
|
|
|
|
|
// 1、获取所有父节点
|
|
|
|
|
String parentSql = "select distinct wx_user_id,wx_person_name from t_ext_company_user where wx_user_id not in (" +
|
|
|
|
|
String parentSql = "select distinct wx_user_id,wx_person_name from yltcharge.t_ext_company_user where wx_user_id not in (" +
|
|
|
|
|
"select child_person_id from t_ext_pm_parent)";
|
|
|
|
|
List<Record> listParent = Db.find(parentSql);
|
|
|
|
|
|
|
|
|
|
// 2、获取所有子节点
|
|
|
|
|
String childrenSql = "select t1.*,t2.person_name as child_person_name from t_ext_pm_parent as t1 " +
|
|
|
|
|
"inner join ds_db.t_sys_loginperson as t2 on t1.child_person_id=t2.person_id";
|
|
|
|
|
String childrenSql = "select t1.*,t2.person_name as child_person_name from yltcharge.t_ext_pm_parent as t1 " +
|
|
|
|
|
"inner join t_sys_loginperson as t2 on t1.child_person_id=t2.person_id";
|
|
|
|
|
List<Record> listChildren = Db.find(childrenSql);
|
|
|
|
|
|
|
|
|
|
// 3、使用HashMap预处理子节点数据
|
|
|
|
|
Map<String, JSONArray> childrenMap = new HashMap<>();
|
|
|
|
|
for (Record child : listChildren) {
|
|
|
|
|
String parentId = child.getStr("parent_person_id");
|
|
|
|
|
JSONObject childNode = new JSONObject();
|
|
|
|
|
childNode.put("id", child.getStr("child_person_id"));
|
|
|
|
|
childNode.put("name", child.getStr("child_person_name"));
|
|
|
|
|
childNode.put("type", "normal");
|
|
|
|
|
|
|
|
|
|
// 如果父节点ID已存在,获取其子节点数组;否则创建新数组
|
|
|
|
|
childrenMap.computeIfAbsent(parentId, k -> new JSONArray()).add(childNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 4、构建树形结构
|
|
|
|
|
JSONArray treeData = new JSONArray();
|
|
|
|
|
|
|
|
|
|
// 处理父节点,pId 设为 0 表示根节点
|
|
|
|
|
for (Record parent : listParent) {
|
|
|
|
|
JSONObject parentNode = new JSONObject();
|
|
|
|
|
String parentId = parent.getStr("wx_user_id");
|
|
|
|
|
parentNode.put("id", parentId);
|
|
|
|
|
parentNode.put("pId", 0);
|
|
|
|
|
parentNode.put("name", parent.getStr("wx_person_name"));
|
|
|
|
|
parentNode.put("open", true);
|
|
|
|
|
|
|
|
|
|
// 直接从HashMap中获取子节点数组
|
|
|
|
|
JSONArray children = childrenMap.get(parentId);
|
|
|
|
|
if (children != null && !children.isEmpty()) {
|
|
|
|
|
parentNode.put("children", children);
|
|
|
|
|
}
|
|
|
|
|
treeData.add(parentNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理子节点
|
|
|
|
|
for (Record child : listChildren) {
|
|
|
|
|
JSONObject childNode = new JSONObject();
|
|
|
|
|
childNode.put("id", child.getStr("child_person_id"));
|
|
|
|
|
childNode.put("pId", child.getStr("parent_person_id"));
|
|
|
|
|
childNode.put("name", child.getStr("child_person_name"));
|
|
|
|
|
treeData.add(childNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return treeData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -67,7 +59,7 @@ public class CompanyUserModel {
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public boolean isChild(String person_id) {
|
|
|
|
|
String sql = "select * from t_ext_pm_parent where child_person_id=?";
|
|
|
|
|
String sql = "select * from yltcharge.t_ext_pm_parent where child_person_id=?";
|
|
|
|
|
return Db.findFirst(sql, person_id) != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -79,14 +71,14 @@ public class CompanyUserModel {
|
|
|
|
|
*/
|
|
|
|
|
public void saveParentChild(String parent_person_id, String child_person_id) {
|
|
|
|
|
//1、删除子节点的关联关系
|
|
|
|
|
String sql = "delete from t_ext_pm_parent where child_person_id=?";
|
|
|
|
|
String sql = "delete from yltcharge.t_ext_pm_parent where child_person_id=?";
|
|
|
|
|
Db.update(sql, child_person_id);
|
|
|
|
|
//2、如果为根节点,就什么也不做
|
|
|
|
|
if (parent_person_id.equals("-1")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//3、如果是子节点,就保存父子关系
|
|
|
|
|
sql = "insert into t_ext_pm_parent(parent_person_id,child_person_id) values(?,?)";
|
|
|
|
|
sql = "insert into yltcharge.t_ext_pm_parent(parent_person_id,child_person_id) values(?,?)";
|
|
|
|
|
Db.update(sql, parent_person_id, child_person_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|