<?xml version="1.0" encoding="UTF-8"?>
<a:service xmlns:ns1="leaf.application.action" xmlns:p="uncertain.proc" xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">
    <a:init-procedure>
        <s:server-script import="app/app_login_check.js"><![CDATA[
            function lov_query() {
                var app_project_details;
                var app_lease_details;
                var app_financing_details;
                var app_prj_bp_details;
                var app_prj_bp_contact_details;
                var app_prj_cdd_details;
                try {
                    var app_project_view_list_bm = $bm('app.lov.app_prj_project_list');
                    var prj_lease_bm = $bm('app.lov.app_prj_lease_info');
                    var prj_financing_bm = $bm('app.lov.app_prj_financing');
                    var prj_bp_bm = $bm('app.lov.app_prj_bp_query');
                    var prj_bp_contact_info_bm = $bm('app.lov.app_prj_bp_contact_info_query');
                    var app_prj_cdd_bm = $bm('app.lov.app_prj_cdd');
            
                    var prj_lease_map = prj_lease_bm.queryAsMap({
                        'project_id': $ctx.parameter.project_id
                    });
                    var app_project_view_list_map = app_project_view_list_bm.queryAsMap({
                        'project_id': $ctx.parameter.project_id
                    });
            
                    var prj_financing_bm_map = prj_financing_bm.queryAsMap({
                        'project_id': $ctx.parameter.project_id
                    });
            
                    var prj_bp_bm_map = prj_bp_bm.queryAsMap({
                        'project_id': $ctx.parameter.project_id
                    });
            
                    var prj_bp_contact_info_bm_map = prj_bp_contact_info_bm.queryAsMap({
                        'project_id': $ctx.parameter.project_id
                    });
            
                    var app_prj_cdd_bm_map = app_prj_cdd_bm.queryAsMap({
                        'project_id': $ctx.parameter.project_id
                    });
                    app_project_details = app_project_view_list_map.getChildren();
                    app_lease_details = prj_lease_map.getChildren();
                    app_financing_details = prj_financing_bm_map.getChildren();
                    app_prj_bp_details = prj_bp_bm_map.getChildren();
                    app_prj_bp_contact_details = prj_bp_contact_info_bm_map.getChildren();
                    app_prj_cdd_details = app_prj_cdd_bm_map.getChildren();
                    $ctx.parameter.return_status = 'S';
                    $ctx.parameter.return_message = '执行成功';
                } catch (e) {
                    $ctx.success = "true";
                    $ctx.parameter.return_status = 'E';
                    $ctx.parameter.return_message = String(e);
                }
            
            
                var result = {
                    result: $ctx.parameter.return_status,
                    message: $ctx.parameter.return_message,
                    app_project_list: {},
                    app_prj_lease_list: {},
                    app_financing_list: {},
                    app_prj_bp_list: {},
                    app_prj_bp_contact_list: {},
                    app_prj_cdd_list: []
                };
            
                var app_project_list = result.app_project_list;
                var app_prj_lease_list = result.app_prj_lease_list;
                var app_financing_list = result.app_financing_list;
                var app_prj_bp_list = result.app_prj_bp_list;
                var app_prj_bp_contact_list = result.app_prj_bp_contact_list;
                var app_prj_cdd_list = result.app_prj_cdd_list;
            
                if (app_project_details) {
                    for (var j = 0;j < app_project_details.length;j++) {
                        var app_project_detail = app_project_details[j];
                        for (var name in app_project_detail) {
                            app_project_list[name.toLowerCase()] = String(app_project_detail[name]);
                        }
                    }
                }
            
                if (app_lease_details) {
                    for (var m = 0;m < app_lease_details.length;m++) {
                        var app_lease_detail = app_lease_details[m];
                        for (var name in app_lease_detail) {
                            app_prj_lease_list[name.toLowerCase()] = String(app_lease_detail[name]);
                        }
                    }
                }
                if (app_financing_details) {
                    for (var m = 0;m < app_financing_details.length;m++) {
                        var app_financing_detail = app_financing_details[m];
                        for (var name in app_financing_detail) {
                            app_financing_list[name.toLowerCase()] = String(app_financing_detail[name]);
                        }
                    }
                }
            
                if (app_prj_bp_details) {
                    for (var m = 0;m < app_prj_bp_details.length;m++) {
                        var app_prj_bp_detail = app_prj_bp_details[m];
                        for (var name in app_prj_bp_detail) {
                            app_prj_bp_list[name.toLowerCase()] = String(app_prj_bp_detail[name]);
                        }
                    }
                }
            
                if (app_prj_bp_contact_details) {
                    for (var m = 0;m < app_prj_bp_contact_details.length;m++) {
                        var app_prj_bp_contact_detail = app_prj_bp_contact_details[m];
                        for (var name in app_prj_bp_contact_detail) {
                            app_prj_bp_contact_list[name.toLowerCase()] = String(app_prj_bp_contact_detail[name]);
                        }
                    }
                }
                if (app_prj_cdd_details) {
                    for (var m = 0;m < app_prj_cdd_details.length;m++) {
                        var app_prj_cdd_detail = app_prj_cdd_details[m];
                        var app_prj_cdd_list_para = {};
                        for (var name in app_prj_cdd_detail) {
                            app_prj_cdd_list_para[name.toLowerCase()] = String(app_prj_cdd_detail[name]);
                        }
                        app_prj_cdd_list.push(app_prj_cdd_list_para);
                    }
                }
                $ctx.parameter.json = JSON.stringify(result);
            }
            
            if ($ctx.parameter.return_status != 'E' && $ctx.parameter.return_status != 'TIMEOUT') {
                lov_query();
            }
        ]]></s:server-script>
    </a:init-procedure>
    <a:service-output output="/parameter/@json"/>
</a:service>
