cddGrid.lsc 3.06 KB
Newer Older
Spencer Chang's avatar
Spencer Chang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
<?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, grid, cdd_grid_bm, cdd_grid_records, parameter = $ctx.parameter;
                result = {
                    head: {
                        message: " ",
                        code: $ctx.success ? 'success' : 'failure'
                    },
                    body: {
                        grid: []
                    }
                };
                grid = result.body.grid;
                cdd_grid_bm = new ModelService('app.cddGrid');
                param = {
                    "project_number": parameter.project_number,
                    "project_id": parameter.project_id,
                    "cdd_item_id": parameter.cdd_item_id
                };
                cdd_grid_records = cdd_grid_bm.queryAsMap(param).getChildren();
                records_len = cdd_grid_records.length;
                for (var i = 0;i < records_len;i++) {
                    var regS = new RegExp("\\\\", "g");
                    file_path = cdd_grid_records[i].file_path.replace(regS, "/");
                    file_path = file_path.match(/excel\/.*/) ? file_path.match(/excel\/.*/).toString() : null;
                    file_path = '/atm_download.lsc?attachment_id=' + cdd_grid_records[i].attachment_id;
                    grid.push({
                        "attachment_id": cdd_grid_records[i].attachment_id || 'null',
                        "cdd_item_id": cdd_grid_records[i].cdd_item_id || 'null',
                        "file_path": file_path || 'null',
                        "description": cdd_grid_records[i].description || 'null',
                        "file_name": cdd_grid_records[i].file_name || 'null',
                        "file_suffix": cdd_grid_records[i].file_name.split('.').pop() || '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>