main
HuangHai 3 months ago
parent 48cb872132
commit 95cfce5f31

@ -58,9 +58,9 @@ public class SSHUtil {
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect(600);
session.connect(6000);
Channel channel = session.openChannel("sftp");
channel.connect(600);
channel.connect(6000);
sftp = (ChannelSftp) channel;
log.info("连接到SFTP成功。host: " + host);
}

@ -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);
}

Loading…
Cancel
Save