package psdi.util.sso.webclient;
import com.dbms.dbcon.DBCon;
import com.dbms.dbcon.QueryResult;
import com.dbms.dbcon.ResultRow;
import psdi.security.ConnectionKey;
import psdi.server.MXServer;
import psdi.util.MXCustomCipher;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
public class SSOSystemUserInfo {
    /**
     * 通过用户名称返回一个用户名的密码，为明码
     * @param username
     *
     * @throws Exception
     */
    public static String getThisUserNamePass(String username) throws Exception
    {
        String password = "";
        String fsql = "select u.PASSWORD from MAXUSER u where u.USERID ='" + username.toUpperCase() + "'";
        ConnectionKey connectionKey = MXServer.getMXServer().getSystemUserInfo().getConnectionKey();
        QueryResult fresult = DBCon.runQuery(fsql.toString(), connectionKey);
        int loopCount = fresult.size();
        if (loopCount > 0) {
            ResultRow resultRow = fresult.getRow(0);
            String encdata = resultRow.getValue("PASSWORD".toUpperCase());
            encdata = (encdata == null) ? "" : encdata.trim();
            //System.out.println("encdata =" + encdata);
            MXCustomCipher custcipher = new MXCustomCipher();
            String decpassword = custcipher.decData(encdata);
            decpassword = (decpassword == null) ? "" : decpassword.trim();
            password = decpassword;
        }
        return password;
    }
    /**
     * 通过用户名称返回一个用户名的密码，为明码
     * @param username
     *
     * @throws Exception
     */
    public static String getThisPersonByUserName(String username) throws Exception
    {
        String personid = "";
        String fsql = "select u.PERSONID from MAXUSER u where u.USERID ='" + username.toUpperCase() + "'";
        ConnectionKey connectionKey = MXServer.getMXServer().getSystemUserInfo().getConnectionKey();
        QueryResult fresult = DBCon.runQuery(fsql.toString(), connectionKey);
        int loopCount = fresult.size();
        if (loopCount > 0) {
            ResultRow resultRow = fresult.getRow(0);
            personid = resultRow.getValue("PERSONID".toUpperCase());
        }
        return personid;
    }
}
