package com.steering.pss.plnsaleord.base;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import CoreFS.SC01.CoreConstantData;

import com.steering.comm.db.DBCommon;

public class CoreGetRolesById extends DBCommon{
    /**
     * 获取用户角色
     * @param userId
     * @return
     */
    public ArrayList<String> getUserRoles(String userId){
        ArrayList<String> listId = new ArrayList<String>();
        Connection conn = null;
        PreparedStatement ps = null;
        try {
            conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            conn.setAutoCommit(false);
            String sql  = "SELECT T.ID, T.ROLE_ID FROM CORE_APP_USER_ROLE T WHERE T.USER_ID = ?";
            ps = conn.prepareStatement(sql);
            ps.setObject(1, userId);
            ResultSet rs = ps.executeQuery();
            while(rs.next()){
                if(rs.getString("ROLE_ID")!= null){
                    listId.add(rs.getString("ROLE_ID"));
                }
            }
            rs.close();
            ps.close();
            conn.commit();
        }
        catch (SQLException sqle) {
            try {
                conn.rollback();
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        finally {
            try {
                if (conn != null && !conn.isClosed()) {
                    conn.close();
                }
            }
            catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return listId;
    }
    
}