//#import Util.js
//#import $owl_mall_u:services/modelService.jsx
//#import $owl_r_apps:services/modelService.jsx
//#import $owl_backend_session:services/modelService.jsx
//#import session.js

function main(){
    var isid = SessionService.getSessionId(request);
    var sessionId = 'owl_backend_session_' + isid;

    var session = owl_backend_sessionService.get(sessionId);
    if(!session){
        var ret = {
            state: 'err',
            msg:"not login",
            apps:[]
        }
        out.print(JSON.stringify(ret));
        return;
    }
    var roleId = session.roleId;
    var userId = session.userId;
    var orgId = session.orgId;

    var id = "owl_r_apps_" + orgId + userId + roleId;

    var rapps = owl_r_appsService.get(id);
    if(!rapps){
       var ret = {
           state: 'ok',
           apps:[]
       }
       out.print(JSON.stringify(ret));
    }
    else{
        var ret = {
            state: 'ok',
            apps:rapps.apps,
            rapps:rapps,
            id:id
        }
        out.print(JSON.stringify(ret));
    }
}
main();