package cn.com.countrygarden.bi.main.repository;


import com.sunshine.common.repository.DataRepositoryJDBC;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Repository("userRoleRepository")
public class UserRoleRepository extends DataRepositoryJDBC {

    private String roleTable = "[HM_wygl_new_1853].[dbo].[Tb_Sys_Role]";

    public UserRoleRepository() {
        this.masterTable = "[HM_wygl_new_1853].[dbo].[Tb_Sys_UserRole]";
    }

    public Map<String, Object> findByUserCode(String userCode) {
        List paramList = new ArrayList();
        paramList.add(userCode);

        String sql = "SELECT r.RoleCode, r.RoleName, r.RoleDescribe, r.IsSysRole, r.CommID, r.SysRoleCode " +
                "FROM " + this.roleTable + " AS r " +
                "INNER JOIN " + this.masterTable + " AS ur ON(r.RoleCode = ur.RoleCode)" +
                "WHERE ur.UserCode = ?";
        return this.jdbcTemp.queryForMap(sql, paramList.toArray());
    }
}
