from cms.common import util
from dataAccess import dataAccess


def init_proc(user_id):
    db_access = dataAccess.DBAccess()
    now_date = util.now_datetime().strftime('%Y/%m/%d')

    check_list_kbn = db_access.select_rows(
        "select"
        "  kbnKey"
        "  , name"
        "  , (select count(*) "
        "     from m_checkperiod mcp "
        "     inner join t_checkresult tcr "
        "       on  mcp.checkKbn = tcr.checkKbn "
        "       and mcp.stDate   = tcr.implementationDate "
        "       and tcr.userId   = '" + user_id + "'"
        "     where mcp.checkKbn = m_kbnmeisyo.kbnKey"
        "     and   mcp.stDate <= '" + now_date + "' "
        "     and   mcp.edDate >= '" + now_date + "'"
        "    ) as cnt"
        " from m_kbnmeisyo"
        " where kbn = 1")

    return check_list_kbn
