<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang 
    $Date: 2015-4-13 下午05:06:40  
    $Revision: 1.0  
    $Purpose: 
-->
<a:service xmlns:s="leaf.plugin.script" xmlns:a="http://www.leaf-framework.org/application" xmlns:p="uncertain.proc" trace="true">
    <a:init-procedure>
        <s:server-script><![CDATA[
            /**
             *read me
             *1.bm部分需改为相应系统的逻辑,此处逻辑为hr系统,仅供参考
             *2.session、cookie部分不用修改,如果出现session、cookie方面的问题,可检查此处的session、cookie(如'/session/@session_id'是否有值)
             *3.调试函数:println(Object);会将Object打印在控制台(如应用服务器tomcat的控制台)。例如:println($session.toXML());会将session对象以xml格式打印出来。
             */
            try {
                var result, details, order_details_bm, order_details_records, parameter = $ctx.parameter;
                result = {
                    head: {
                        message: " ",
                        code: $ctx.success ? 'success' : 'failure'
                    },
                    body: {
                        details: []
                    }
                };
                details = result.body.details;
                order_details_bm = new ModelService('app.detailList');
                param = {
                    "project_id": parameter.project_id,
                    "project_number": parameter.project_number
                };
                order_details_records = order_details_bm.queryAsMap(param).getChildren();
                details_len = order_details_records.length;
            
                for (var i = 0;i < details_len;i++) {
                    details.push({
                        "project_number": order_details_records[i].project_number || "null",
                        "bp_name": order_details_records[i].bp_name || "null",
                        "check_id": order_details_records[i].check_id || "null",
                        "description": order_details_records[i].description || "null",
                        "cdd_count": order_details_records[i].cdd_count || "null",
                        "project_id": order_details_records[i].project_id || "null",
                        "cdd_item_id": order_details_records[i].cdd_item_id || "null",
            
                    })
                }; /*test*/
                // result.head.message = model_len;
            
            
            } catch (e) {
                println(e);
            } finally {
                //执行finally代码,将result对象回写
                // $ctx.parameter.json = JSON.stringify(result);
                $ctx.parameter.json = JSON.stringify(result);
            }
        ]]></s:server-script>
    </a:init-procedure>
    <a:service-output output="/parameter/@json"/>
</a:service>