2015-01-31 78 views
0

我有一張表,其中存儲了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個孩子,每個10個電話用戶,他將得到一個指示變更像高級技術支持。如果他有10個這樣的來電者,它將是經理。

要如果我通過5爲USER_ID,和4的深度做到這一點到目前爲止我做了什麼(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; 
} 

。它將一直持續到user_id並更新值。它的工作原理是5->4, 4->2, 2->1。但我需要達到的是5->4,並檢查4的孩子的電話。與3, 2, 1相同。我怎樣才能做到這一點?請幫幫我。

+0

任何幫助傢伙... – Rajkumar 2015-02-01 05:14:19

回答

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

+0

在這種情況下,如1 - > 3(3母) - > 2(1父)。我需要檢查? Bcoz我們需要處理所有用戶 – Rajkumar 2015-02-01 07:36:35

+0

使用COUNT查詢,您可以獲得呼叫> 10的父母的子女總數。檢查這個值是否大於2. 然後你可以得到這個父母下面的所有用戶,查詢如下: 'SELECT user_id from tablename WHERE parent_user_id = userIds;' 並且使用循環你可以更新它們。 希望它有幫助! – minarmahmud 2015-02-01 07:47:56

+0

我的問題是,如果用戶有2個技術支持> 10個電話,他是sr。高科技,如果一個擁有2 sr.teh支持的用戶將成爲經理。如何做這個邏輯?這是我原來的問題 – Rajkumar 2015-02-01 08:13:57