gpt4 book ai didi

java - 更新基于父子数据的排名

转载 作者:行者123 更新时间:2023-11-29 23:07:04 25 4
gpt4 key购买 nike

我有一个存储 user_idparent_user_id 的表。例如:

user_id    parent_user_id   calls      designation
---------------------------------------------------
1 0 10 Tech Support
2 1 5 Sr. Tech Support
3 2 11 Tech Support
4 2 12 Tech Support
5 4 10 Tech Support

场景是,如果一个用户有 2 个 child ,每个 child 有 10 个电话,他将获得像高级技术支持这样的任命更改。如果他有 10 个这样的来电者,那就是经理。

到目前为止,我已经做到了这一点(java),

@Override
public boolean updateDesignation(int userId, int depth) {
// check whether maximum depth is reached
if (depth == 0)
return false;
depth--;

int userIds = getIds(userId);//Will get parent_id

String LOCAL_SQL = SQLconstants.getSQL("get-total-calls.sql");

if(userIds>0) {
int calls = jdbcTemplate.queryForObject(LOCAL_SQL, Integer.class, userIds);
// I get 4's calls with which I need to see if I have 2 users with 10 calls each!
updateDesignation(userIds, depth);
}
//updateRanks(userId, depth);
return true;
}

如果我传递 5 作为 user_id,传递 4 作为深度。它将继续直到 user_id 并更新值。它的工作原理是5->4, 4->2, 2->1。但我需要实现的是5->4,并检查4的 child 的调用。与 3, 2, 1 相同。我怎样才能做到这一点?请帮助我。

最佳答案

if(userIds>=0) {    // process 0 too, as it is a parent 
/* execute this sql
SELECT COUNT(*) FROM tablename WHERE parent_user_id=userIds AND calls>=10;
then check if the returned value is >= 2 or other chekings...
and update designations..
*/
updateDesignation(userIds, depth);
}

这样您就不需要接到每个家长的电话。所以不再需要这一行:

int requests = jdbcTemplate.queryForObject(LOCAL_SQL, Integer.class, userIds);

关于java - 更新基于父子数据的排名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28256443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com