package com.dsideal.sso.Model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.redis.Redis;


public class LoginModel {

    /**
     * 根据登录名获取登录信息
     *
     * @param userName
     * @return
     */
    public Map<String,String>  getLoginInfoByUserName(String userName) {
        Map<String,String> loginMap = new HashMap<>();
        String sql = Db.getSql("login.getLoginInfoByUserName");
        Record record = Db.findFirst(sql, userName);
        loginMap.put("person_id", record.get("person_id").toString());
        loginMap.put("person_name", record.get("person_name").toString());
        loginMap.put("identity_id", record.get("identity_id").toString());
        loginMap.put("bureau_id", record.get("bureau_id").toString());
        loginMap.put("password", record.get("pwd").toString());
        loginMap.put("city_id", record.get("city_id").toString());
        loginMap.put("area_id", record.get("area_id").toString());
        return loginMap;
    }

    /**
     * 功能：根据全局变量的KEY获取VALUE
     *
     * @param key
     * @return
     */
    public String getGlobalValueByKey(String key) {
        String sql = Db.getSql("login.getGlobalValueByKey");
        Record record = Db.findFirst(sql, key);
        if (record == null) return null;
        return record.getStr("global_value");
    }

}
