<?xml version="1.0" encoding="UTF-8"?>
<!--<a:service  xmlns:a="http://www.leaf-framework.org/application"  xmlns:s="leaf.plugin.script" trace="true">-->
<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 ><![CDATA[
            importPackage(Packages.java.util);
            importPackage(Packages.java.lang);
            importPackage(Packages.com.hand.hl);
            importPackage(Packages.java.io);
            importPackage(java.io);
            try{
                 var sys_url_bm=$bm('cont.CON4000.get_sys_url');
                 var parameter_code='HLS_SYSTEM_URL';
                 var SysurlQuery = sys_url_bm.queryAsMap({
                                        parameter_code: parameter_code
                                });

                var sys_url = SysurlQuery.getChildren()[0].parameter_value;
                var down_url =sys_url+'modules/cont/CON3200/contract_receipt_detail_print.lsc?template_name='+'aa.xls'
                              + '&contract_id=' +$ctx.parameter.p_contract_id
                              + '&file_name=' + encodeURI('应收明细表','utf-8');
                var now = new Date();
                y = now.getFullYear();
                m = now.getMonth() + 1;
                m = m < 10 ? "0" + m : m;
                d = now.getDate();
                d = d < 10 ? "0" + d : d;
                var fileDir_bm=$bm('cont.CON4000.get_sys_url');
                var parameter_code='HLCM_EMAIL_URL';        //存放文件路径 待修改
               var fileDirQuery = fileDir_bm.queryAsMap({
                                parameter_code: parameter_code
                                                });
                var f_fileDir = fileDirQuery.getChildren()[0].parameter_value;

                var filePath = (f_fileDir + y + "\\" + m + "\\").toString();
                var tranfer_dir= new File(String(filePath));
                if(!tranfer_dir.exists()){//如果文件夹不存在,创建文件夹
                       tranfer_dir.mkdirs();//创建文件夹
                                    }
                var contract_number =  $ctx.parameter.p_contract_number;
                var f_fileName = (contract_number+'应收明细表'+y+m+d+'.xlsx').toString();
                var result_flag=DoloadFileByUrl.downloadFile(down_url, filePath, f_fileName);
                file_size=get_file_length(filePath+f_fileName);
                if(result_flag=true){
                var business_daily_email=$bm('cont.CON3200.receipt_detail_insert_atm').update({
                        p_file_path      :(filePath+f_fileName).toString(),
                        p_file_name     :f_fileName,
                        p_file_size     :file_size,
                        p_user_id      :1,
                        p_check_id     :$ctx.parameter.p_check_id
                });
                }
            }catch(e){
                 raise_app_error(e.message);
            }

            function get_file_length(path){
                var file=new File(String(path));
                if(file.exists() && file.isFile()){
                    //println(f.length());
                    length=file.length();
                    return length;}
                else{
                     return 0 ;}
            }

        ]]></s:server-script>
    </a:init-procedure>
    <a:service-output output="/parameter"/>
</a:service>