我有一个表格,其中存储了user_id
和parent_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个孩子,每个孩子有10个电话,他将获得类似Sr.技术支持的指定更改。如果他有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个孩子的来电。与3, 2, 1
相同。我怎样才能做到这一点?请帮帮我。
答案 0 :(得分:0)
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 calls = jdbcTemplate.queryForObject(LOCAL_SQL, Integer.class, userIds);