<?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 app_prj_save() {
                var root = $ctx.parameter;
                var bp_info_list = root.getChild('bp_info_list');
                var bp_contact_list = root.getChild('bp_contact_list');
                var app_prj_save_bm = $bm('app.app_calc');
                var app_prj_bp_save_bm = $bm('app.app_prj_bp_save');
                var app_prj_bp_contact_save_bm = $bm('app.app_prj_bp_contact_save');
            
                try {
                    app_prj_save_bm.update($ctx.parameter);
                    if (!bp_info_list.project_id) {
                        bp_info_list.project_id = $ctx.parameter.project_id;
                    }
                    if (!bp_info_list.user_id) {
                        bp_info_list.user_id = $ctx.parameter.user_id;
                    }
                    app_prj_bp_save_bm.update(bp_info_list);
            
                    if (!bp_contact_list.prj_bp_id) {
                        bp_contact_list.prj_bp_id = bp_info_list.prj_bp_id;
                    }
                    if (!bp_contact_list.user_id) {
                        bp_contact_list.user_id = $ctx.parameter.user_id;
                    }
            
                    app_prj_bp_contact_save_bm.update(bp_contact_list);
            
            
                    $ctx.parameter.return_status = 'S';
                    $ctx.parameter.return_message = '保存成功';
                } catch (e) {
                    $ctx.success = "true";
                    $ctx.parameter.return_status = 'E';
                    $ctx.parameter.return_message = $ctx.get('/error/@message') || String(e);
                }
                var result = {
                    result: $ctx.parameter.return_status,
                    message: $ctx.parameter.return_message,
                    resp_bp_info_list: [],
                    resp_bp_contact_list: []
                };
                var resp_bp_info_list = result.resp_bp_info_list;
                var resp_bp_contact_list = result.resp_bp_contact_list;
                resp_bp_info_list.push({
                    "prj_bp_id": String(bp_info_list.prj_bp_id)
                });
                resp_bp_contact_list.push({
                    "prj_contact_info_id": String(bp_contact_list.prj_contact_info_id)
                });
                $ctx.parameter.json = JSON.stringify(result);
            }
            if ($ctx.parameter.return_status != 'E'&& $ctx.parameter.return_status != 'TIMEOUT') {
                app_prj_save();
            }
        ]]></s:server-script>
    </a:init-procedure>
    <a:service-output output="/parameter/@json"/>
</a:service>