Aurora 自定文件下载

Aurora 自带的文件下载只能按照框架定义的方式去下载指定目录的文件,这样非常的不方便,不能实现一些自定的下载方式
这里提供一种方式可以按照自己的方式下载自定义的文件列表

BM 文件

bm 查询出文件列表

<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.aurora-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
            select fam.table_name,
                fam.table_pk_value,
                fam.record_id,
                faa.attachment_id,
                faa.file_name,
                faa.file_path
            from prj_cdd_item_doc_ref@cf_app doc,
                fnd_atm_attachment_multi@cf_app fam,
                fnd_atm_attachment@cf_app faa
            where fam.table_name in ('PRJ_CDD_ITEM_CHECK','CSH_PAYMENT_REQ_HD','CON_CONTRACT_ITEM_DETAIL')
            and fam.table_pk_value = doc.check_id
            and fam.attachment_id = faa.attachment_id
            and (
                (doc.document_table = 'PRJ_PROJECT'
                    and doc.document_id = ${@PROJECT_ID})
                OR
                (
                    doc.DOCUMENT_TABLE = 'CON_CONTRACT'
                    and doc.DOCUMENT_ID = (select CON_CONTRACT.CONTRACT_ID from CON_CONTRACT@cf_app where PROJECT_ID = ${@PROJECT_ID} )
                    )
                )

   ]]></bm:query-sql>
            <bm:parameters>
                <!-- <bm:parameter name="table_pk_value"/>
                <bm:parameter name="table_name"/> -->
                <bm:parameter name="PROJECT_ID"/>
            </bm:parameters>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="table_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="TABLE_NAME" required="true"/>
        <bm:field name="table_pk_value" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="TABLE_PK_VALUE" required="true"/>
        <bm:field name="record_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="RECORD_ID" required="true"/>
        <bm:field name="attachment_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="ATTACHMENT_ID" required="true"/>
        <bm:field name="file_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FILE_NAME"/>
        <bm:field name="file_path" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FILE_PATH"/>
    </bm:fields>
</bm:model>

SVC 文件

svc 调用 bm 查询需要下载的文件列表,然后通过文件流将文件转出并打包下载到客户端

<?xml version="1.0" encoding="UTF-8"?>
<a:service xmlns:s="aurora.plugin.script" xmlns:a="http://www.aurora-framework.org/application" trace="true">
    <a:init-procedure>
        <s:server-script><![CDATA[
            //importPackage(java.util.zip);
            importPackage(java.io);
            importPackage(org.apache.tools.zip); /*可以传入参数*/
            var logger = $logger("server-script");
            function writeFile(zos, fn, fp) {
                var ze = new ZipEntry(fn);
                zos.putNextEntry(ze);
                var fis = new FileInputStream(fp);
                var b = new java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024 * 64);
                var len = -1;
                while ((len = fis.read(b)) != -1) {
                    zos.write(b, 0, len);
                }
                fis.close();
            }
            function getdate() {
                var now = new Date()
                y = now.getFullYear()
                m = now.getMonth() + 1
                d = now.getDate()
                m = m < 10 ? "0" + m : m
                d = d < 10 ? "0" + d : d
                return y + "" + m + "" + d
            }
            $ctx["__request_type__"] = 'file'; //to indicate this request is not a JSON_REQUEST
            var resp = $ctx['_instance.javax.servlet.http.HttpServletResponse'];
            resp.setHeader("Pragma", "No-cache");
            resp.setHeader("Cache-Control", "no-cache, must-revalidate");
            var date_str = getdate();
            var doc_code = $ctx.parameter.PROJECT_ID;
            var filename = doc_code + '-' + date_str + ".zip"
            resp.setHeader("Content-disposition", "attachment; filename=" + filename);
            resp.setDateHeader("Expires", 0);
            resp.setContentType("application/x-msdownload");
            var zos = new ZipOutputStream(resp.getOutputStream());
            zos.setEncoding("GBK"); //如果是org.apache.tools.zip需要追加字符集
            try {
                logger.severe("开始查询");
                var attachment_batch_dl = $bm('cont.CON9300.lease_atm_batch_dl_plus');
                var result = attachment_batch_dl.queryAsMap({PROJECT_ID:$ctx.parameter.PROJECT_ID});
                var arr = result.getChildren();
                logger.severe("数据:"+result);
                for (var i = 0;i < arr.length;i++) {
                    var f = arr[i];
                    if (f.file_path) {
                        writeFile(zos, f.file_name, f.file_path);
                    }
                }
            } catch (e) {
                logger.severe("错误:"+e.message)
            }
            zos.close();
        ]]></s:server-script>
    </a:init-procedure>
</a:service>

SCREEN 文件

screen 完善调用svc 方法及客户端操作按钮

<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.aurora-framework.org/application" customizationEnabled="true" trace="true">
    <a:view>
            <script><![CDATA[
            // 影像件材料打包下载
            function prj_wfl_download() {
                <!-- var document_id = ${/parameter/@PROJECT_ID}; -->
                var url = '${/request/@context_path}/modules/cont/CON930/lease_atm_batch_dl_plus.svc?PROJECT_ID=' + ${/parameter/@PROJECT_ID} ;
                window.open(url);
            }
      ]]></script>
        <a:dataSets>
            <a:dataSet id="csh_payment_req_create_ds" autoQuery="true" bindName="sub"  fetchAll="true" queryUrl="${/request/@context_path}/autocrud/cont.CON9300.csh_payment_req_ln_query/query?PROJECT_ID=${/parameter/@PROJECT_ID}" selectable="false">
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:hBox labelWidth="300">
                <a:button click="prj_wfl_download" text="影像资料下载"></a:button>
            </a:hBox>
            <a:form column="4" labelWidth="100" marginWidth="30" title="CSH502.CSH_PAYMENT_REQ_QUERY">
                <a:textField name="rn" bindTarget="csh_payment_req_create_ds" prompt="RN号" readOnly="true"></a:textField>
                <a:textField name="bp_tenant_name" bindTarget="csh_payment_req_create_ds" prompt="对象名称" readOnly="true"></a:textField>
                <a:textField name="contract_number" bindTarget="csh_payment_req_create_ds" prompt="合同编号" readOnly="true"></a:textField>
                <a:textField name="project_number" bindTarget="csh_payment_req_create_ds" prompt="项目号" readOnly="true"></a:textField>
                <a:textField name="contract_name" bindTarget="csh_payment_req_create_ds" prompt="合同名称" readOnly="true"></a:textField>
                <a:textField name="project_name" bindTarget="csh_payment_req_create_ds" prompt="项目名称" readOnly="true"></a:textField>
                <a:textField name="bank_full_name" bindTarget="csh_payment_req_create_ds" prompt="银行" readOnly="true"></a:textField>
                <a:textField name="bank_branch_name" bindTarget="csh_payment_req_create_ds" prompt="分行" readOnly="true"></a:textField>
                <a:textField name="bank_account_name" bindTarget="csh_payment_req_create_ds" prompt="银行账户" readOnly="true"></a:textField>
                <a:textField name="bank_account_num" bindTarget="csh_payment_req_create_ds" prompt="账号" readOnly="true"></a:textField>
                <a:textField name="lease_times" bindTarget="csh_payment_req_create_ds" prompt="期数" readOnly="true"></a:textField>
                <a:numberField name="due_amount" bindTarget="csh_payment_req_create_ds" prompt="应付金额" readOnly="true"></a:numberField>
                <a:textField name="description" bindTarget="csh_payment_req_create_ds" prompt="备注" readOnly="true" showTitle="true" width="280"></a:textField>
            </a:form>
        </a:screenBody>
    </a:view>
</a:screen>

相关文章

转载请注明: 转载自 浮生一程
本文链接地址 Aurora 自定文件下载
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇