package com.steerinfo.auth.shiro.realm;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.fastjson.JSON;
import com.steerinfo.framework.constant.ShiroConstant;
import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.user.IUser;
import com.steerinfo.framework.user.UserPayload;

/**
 * 
 * @ClassName: SysUserStatelessRealm 
 * @Description: TODO
 * @author 鄢利
 * @date 2018年7月20日 下午7:48:10 
 *
 */
public class SysUserStatelessRealm extends AbstractStatelessRealm{

    // @Autowired
    //ISysUserService sysUserService;
    
    @Autowired
    OssServiceClient ossService;
    
	@Override
	public IUser findByLogin(UserPayload payload) {
		SysUser sysUser = new SysUser();
		RESTfulResult re = ossService.getUser(payload.getId());
		// System.out.println("re.getData()---------" + re.getData());
		Map m = (Map)re.getData();
		sysUser.setUserId(m.get("userId").toString());
		sysUser.setUserName(m.get("userName").toString());
		sysUser.setUserCode(m.get("userCode").toString());
		sysUser.setPassword(m.get("password").toString());
		sysUser.setOrgCode(m.get("orgCode").toString());
		// SysUser sysUser = sysUserService.selectByUserCode(payload.getUserCode());
		// 数据权限-暂时隐藏
//		try {
//			Object re2 = ossService.getDaTablePolicys();
//			List<HashMap<String, Object>> l = (ArrayList<HashMap<String, Object>>)re2;
//			List<SysDaTablePolicy> sysDaTablePolicyList = new ArrayList<SysDaTablePolicy>();
//			for(HashMap<String, Object> mp:l){
//				SysDaTablePolicy s = JSON.parseObject(JSON.toJSONString(mp), SysDaTablePolicy.class);
//				sysDaTablePolicyList.add(s);
//			}
//			caches.getDefaultCache().put(ShiroConstant.TABLE_POLICY + m.get("userId").toString(), (Serializable) sysDaTablePolicyList);
//	    } catch (Exception exception) {}
		return sysUser;
	}
}
