<?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/CON4000/hlcm_business_daily.lsc';
                var now = new Date()
                y = now.getFullYear()
                m = now.getMonth() + 1
                m = m < 10 ? "0" + m : m
                d = (now.getDate()) < 10 ? "0"+ (now.getDate()) : (now.getDate());
                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 f_fileName = ('建机营业日报'+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.CON4000.business_daily_email').update({
                        p_file_path      :(filePath+f_fileName).toString(),
                        p_file_name     :f_fileName,
                        p_file_size     :file_size,
                        p_user_id      :1
                });
                }
            }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>