`
tangkuo
  • 浏览: 103144 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

查询分页excele

 
阅读更多
/**
     * 下载商户前一日的交易对账单
     * @param dateTime
     * @return
     * @throws TtyException
     */
@Override
public void downloadMerchantBillsTask(Date beginDate,Date endDate) throws TtyException {
List<MemberMerchant> list = memberService.queryAllMerchants();
FileOutputStream fOut = null;
InputStream fin = null;
for(int i=0;i<list.size();i++){
MemberMerchant memberMerchant = list.get(i);
log.info("循环当前商户的登录账号为{}",memberMerchant.getLoginId());
String newBeginDate = "";
if(Utils.isNull(beginDate)){
newBeginDate = DateUtil.format(new Date(), DateUtil.YYYY_MM_DD, -1);//前一日的交易对账单
}else{
newBeginDate = DateUtil.format(beginDate,DateUtil.YYYY_MM_DD);
}
log.info("开始时间="+newBeginDate);
String fileName = memberMerchant.getLoginId();
//对账单结束时间
String newEndDate = "";
if(Utils.isNull(endDate)){
newEndDate = DateUtil.format(new Date(), DateUtil.YYYY_MM_DD, -1);//前一日的交易对账单
}else{
newEndDate = DateUtil.format(endDate,DateUtil.YYYY_MM_DD);
}
        if (!StringUtils.isEmpty(newBeginDate) && !StringUtils.isEmpty(newEndDate)) {
            fileName += "(" + newBeginDate + "-" + newEndDate + ")"+"_";
        }
        //模板路径
        String templateUrl = Property.getProperty("url.downloadMerchantBills.template", "");
        //导出到指定路径
        String newfilePath = Property.getProperty("url.merchantBills.path");
        //根据商户登陆帐户生成目录结构
        String memberId = memberMerchant.getMemberId()+"/";
        newfilePath +=memberId;
        File dirFile = new File(newfilePath);
                log.info("----newfilePath----:" + newfilePath);
                if (!dirFile.exists()) {
                log.info("创建文件夹:" + newfilePath);
                    dirFile.mkdirs();
                }
               
        //存放对帐单数据的文件路径
        newfilePath +=fileName;
        //查询当前商户前一交易日的对账单数据参数
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("beginDate", newBeginDate);
        data.put("endDate", newEndDate);
        data.put("mchLoginId", memberMerchant.getLoginId());
       
        //处理大数据量的导出
        String tempFilePath="";
        //查询当前商户的总对帐数量
        int totalRecord = this.queryMerchantBillsCountByLoginId(data);
        //根据传入的分页开始与结束值查询数据
        int startPageNo=0,pageSize=0,pagesTotal = 0,size=2,endPageNo=0;
        if(totalRecord >0){
        //此商户存在对帐单数据
        startPageNo = 1;
        pagesTotal=(totalRecord-1)/size+1;
        }
        for(int j=0;j<pagesTotal;j++){
        /*startPageNo = j*size+1;
        endPageNo = (j+1)*size;*/
        //导出多个excele文件
        IPage<SettlementOrder> pList = orderQueryService.querySettlementListByMchLoginId(data, j+1, size);
if (null != pList && null != pList.getRows()) {
List<SettlementOrder> list2 = (List<SettlementOrder>) pList.getRows();
data.put("items", list2);
}
        try {
        tempFilePath = newfilePath +j+".xls";
        //模板文件从服务器下载方式
        XLSTransformer transformer = new XLSTransformer(); 
        URL inUrl = new URL(templateUrl);
        URLConnection connection = inUrl.openConnection();
        fin = connection.getInputStream();
        fOut = new FileOutputStream(tempFilePath);
            transformer = new XLSTransformer();
            Workbook workbook = transformer.transformXLS(fin, data);
            workbook.write(fOut);
        } catch (Exception e) { 
            e.printStackTrace(); 
        }finally {
            try {
                if (fOut != null) {
                    fOut.flush();
                    fOut.close();
                }
                if (fin != null) {
                    fin.close();
                }
            } catch (IOException ie) {
                log.error("定时任务报表导出异常", ie);
            }
        }
        }

}

}












/**
     * 下载商户前一日的交易对账单
     * @param dateTime
     * @return
     * @throws TtyException
     */
@Autowired
@Override
public void downloadMerchantBillsTask(Date beginDate,Date endDate) throws TtyException {
List<MemberMerchant> list = memberService.queryAllMerchants();
FileOutputStream fOut = null;
InputStream fin = null;
for(int i=0;i<list.size();i++){
MemberMerchant memberMerchant = list.get(i);
log.info("循环当前商户的登录账号为{}",memberMerchant.getLoginId());
String newBeginDate = "";
if(Utils.isNull(beginDate)){
newBeginDate = DateUtil.format(new Date(), DateUtil.YYYY_MM_DD, -1);//前一日的交易对账单
}else{
newBeginDate = DateUtil.format(beginDate,DateUtil.YYYY_MM_DD);
}
log.info("开始时间="+newBeginDate);
String fileName = memberMerchant.getLoginId();
//对账单结束时间
String newEndDate = "";
if(Utils.isNull(endDate)){
newEndDate = DateUtil.format(new Date(), DateUtil.YYYY_MM_DD, -1);//前一日的交易对账单
}else{
newEndDate = DateUtil.format(endDate,DateUtil.YYYY_MM_DD);
}
        if (!StringUtils.isEmpty(newBeginDate) && !StringUtils.isEmpty(newEndDate)) {
            fileName += "(" + newBeginDate + "-" + newEndDate + ")";
        }
        //模板路径
        String templateUrl = Property.getProperty("url.downloadMerchantBills.template", "");
        //导出到指定路径
        String newfilePath = Property.getProperty("url.merchantBills.path");
        //根据商户登陆帐户生成目录结构
        String memberId = memberMerchant.getMemberId()+"/";
        newfilePath +=memberId;
        File dirFile = new File(newfilePath);
                log.info("----newfilePath----:" + newfilePath);
                if (!dirFile.exists()) {
                log.info("创建文件夹:" + newfilePath);
                    dirFile.mkdirs();
                }
               
        //存放对帐单数据的文件路径
        newfilePath +=fileName;
        //查询当前商户前一交易日的对账单数据参数
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("beginDate", newBeginDate);
        data.put("endDate", newEndDate);
        data.put("mchLoginId", memberMerchant.getLoginId());
       
        String tempFilePath="";
        int totalRecord = this.queryMerchantBillsCountByLoginId(data);
        int pagesTotal = 0,size=2;
        if(totalRecord >0){
        //此商户存在对帐单数据
        pagesTotal=(totalRecord-1)/size+1;
        for(int j=0;j<pagesTotal;j++){
        //循环导出多个excele文件
        log.info("正在导出商户编号为:"+memberMerchant.getMemberId()+"第"+j+"个excel文件");
        IPage<SettlementOrder> pList = orderQueryService.querySettlementListByMchLoginId(data, j+1, size);
if (null != pList && null != pList.getRows()) {
List<SettlementOrder> list2 = (List<SettlementOrder>) pList.getRows();
data.put("items", list2);
}
tempFilePath = newfilePath +"_" +j+".xls";
ExportController.reportExp(tempFilePath,templateUrl,data);

        /*try {
        tempFilePath = newfilePath +"_" +j+".xls";
        //模板文件从服务器下载方式
        XLSTransformer transformer = new XLSTransformer(); 
        URL inUrl = new URL(templateUrl);
        URLConnection connection = inUrl.openConnection();
        fin = connection.getInputStream();
        fOut = new FileOutputStream(tempFilePath);
            transformer = new XLSTransformer();
            Workbook workbook = transformer.transformXLS(fin, data);
            workbook.write(fOut);
        } catch (Exception e) { 
            e.printStackTrace(); 
        }finally {
            try {
                if (fOut != null) {
                    fOut.flush();
                    fOut.close();
                }
                if (fin != null) {
                    fin.close();
                }
            } catch (IOException ie) {
                log.error("定时任务报表导出异常", ie);
            }
        }*/
        }
        }else{
        //没有对帐单数据信息.
        List<SettlementOrder> list3 = new ArrayList<SettlementOrder>();
        data.put("items", list3);
        tempFilePath = newfilePath +".xls";
        ExportController.reportExp(tempFilePath,templateUrl,data);
        /*try {
        List<SettlementOrder> list3 = new ArrayList<SettlementOrder>();
        data.put("items", list3);
        tempFilePath = newfilePath +".xls";
        //模板文件从服务器下载方式
        XLSTransformer transformer = new XLSTransformer(); 
        URL inUrl = new URL(templateUrl);
        URLConnection connection = inUrl.openConnection();
        fin = connection.getInputStream();
        fOut = new FileOutputStream(tempFilePath);
            transformer = new XLSTransformer();
            Workbook workbook = transformer.transformXLS(fin, data);
            workbook.write(fOut);
        } catch (Exception e) { 
            e.printStackTrace(); 
        }finally {
            try {
                if (fOut != null) {
                    fOut.flush();
                    fOut.close();
                }
                if (fin != null) {
                    fin.close();
                }
            } catch (IOException ie) {
                log.error("定时任务报表导出异常", ie);
            }
        }*/
        }
      

}

}













/**
* Copyright (c) 2011-2015 All Rights Reserved.
*/
package com.kame.micropay.order.service.utils;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Map;

import net.sf.jxls.transformer.XLSTransformer;

import org.apache.poi.ss.usermodel.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;

/**
*
* @author Administrator
*
*/
@Controller
public abstract class ExportController {

private static Logger log = LoggerFactory.getLogger(ExportController.class);

/**
* 输出报表
* @param tempFilePath
* @param templateUrl
* @param data
*/
    public static void reportExp(String tempFilePath, String templateUrl, Map<String, Object> data) {
        OutputStream fOut = null;
        InputStream fin = null;
        try {
            URL url = new URL(templateUrl);
            URLConnection connection = url.openConnection();
            fin = connection.getInputStream();
            XLSTransformer transformer = new XLSTransformer(); 
        fin = connection.getInputStream();
        fOut = new FileOutputStream(tempFilePath);
            transformer = new XLSTransformer();
            Workbook workbook = transformer.transformXLS(fin, data);
            workbook.write(fOut);
           
        } catch (Exception e) {
            log.error("报表导出异常", e);
        } finally {
            try {
                if (fOut != null) {
                    fOut.flush();
                    fOut.close();
                }
                if (fin != null) {
                    fin.close();
                }
            } catch (IOException ie) {
                log.error("报表导出异常", ie);
            }
        }
    }
}
分享到:
评论

相关推荐

    qt实现数据excel导出数据查询分页实例

    使用Qtcreator实现数据库查询,记录分页显示,含有下一页,上一页,跳转等功能,此外还实现了将查询数据导出到excel

    数据分页导入Excel

    数据分页导入Excel是一项在大数据处理中常见的任务,它涉及到如何高效地从数据库中提取大量数据并将其组织成Excel格式。在这个过程中,我们通常会利用Java的Apache POI库,这是一个强大的工具,允许开发者创建、修改...

    EXCEL利用VBA实现自动分页汇总

    EXCEL利用VBA实现自动分页汇总 EXCEL中的自动分页汇总是指在EXCEL表格中按照一定的规则将数据分页,并对每一页的数据进行汇总和统计。这种功能可以通过VBA语言实现。 VBA语言是EXCEL中的宏语言,它允许用户编写...

    Excel表格如何分页打印、自动分页、取消分页等技巧

    在本文中,我们将详细探讨Excel表格在打印时的分页技巧,包括手动分页、自动分页以及快速插入和删除分页符的方法。 首先,我们来了解如何通过手动分页来实现对Excel表格内容的精确控制。手动分页的核心在于将一个长...

    C#大量数据导出到Excel自动分页导出

    C#大量数据导出到Excel,超过65536行时自动分页导出

    excel 宏分页等四个功能 vb

    关于excle分页的功能, alt+f11可以进入excle进行调试

    npoi导出excel分页功能

    private void ToExcel(HttpContext context, string TempletFileName//模版文件, string ReportFileName//导出文件, DataTable dt2) { //模板文件 //string TempletFileName = context.Server.MapPath...

    JSF+Spring+Hibernate配置以及分页查询和Excel文件导出

    在这个场景中,"JSF+Spring+Hibernate配置以及分页查询和Excel文件导出"是一个典型的企业级应用开发组合。下面将详细阐述这些技术及其整合方式。 1. JavaServer Faces (JSF): JSF是一种Java标准的MVC(模型-视图-...

    JSP Struts2 分页 导出Excel

    本教程将介绍如何使用这两者结合jQuery来实现数据查询、分页以及Excel导出功能。 1. **JSP基础** JSP是一种服务器端脚本语言,用于生成动态HTML页面。开发者可以在JSP文件中混合使用HTML、Java代码和自定义标签库...

    vue el-table前端 file-saver 导出excel可导出分页数据.zip

    本篇文章将深入探讨如何在Vue.js项目中结合`el-table`和`file-saver`库,实现前端导出分页数据到Excel的功能。 首先,我们需要了解`el-table`。它是Element UI的一部分,提供了一种灵活的方式来展示和操作表格数据...

    FastAPI后端查询数据在前端进行分页展示(html、py文件)

    2. 使用`mysql-connector-python`库连接MySQL数据库,执行SQL查询,特别是分页查询。 3. 通过前端框架LayUImini实现前端页面的布局和交互,包括分页组件的使用。 4. 前后端交互,利用AJAX进行异步数据请求和页面更新...

    EXCEL自动分页插件

    EXCEL自动分页插件,容易上手。好用。

    excel 报表分页小计

    《报表分页小计》 轻松学习excel,以后陆续上传

    Excel表格如何分页打印自动分页取消分页等技巧.doc

    Excel表格如何分页打印自动分页取消分页等技巧 在Excel表格中,如何实现分页打印、自动分页、取消分页等技巧是一个非常重要的问题。特别是在制作多个表格时,我们希望将每个表格分别打印到每一张纸上面,每张纸上面...

    poi excel example,分页,行高,列宽

    标题中的“poi excel example,分页,行高,列宽”指的是使用Apache POI库来操作Excel文件的一些关键功能,包括设置分页、调整行高和列宽。Apache POI是一个流行的Java API,用于读取和写入Microsoft Office格式的...

    excel 自动分页小计

    在Excel中,自动分页小计是一项非常实用的功能,它能帮助用户在处理大量数据时进行有效的分组和计算,使报表更清晰易读。在标题提到的"excel 自动分页小计"中,主要涉及到以下几个关键知识点: 1. **分页符**:在...

    Aspose21.3全系列,excel转pdf,pdf分页合并

    在本资源中,我们关注的是Aspose的21.3版本,特别是其在Excel到PDF转换以及PDF的分页和合并方面的功能。 首先,Aspose.Excel API允许开发者方便地将Excel工作簿转换为PDF格式。这种转换不仅保留了原始电子表格的...

    winfrom分页控件(含导出excel)

    可以和datagridview合用的分页控件

    基于Python实现Excel数据处理自动化生成Word文档(含索引目录 分页).zip

    在本项目中,我们将探讨如何使用Python编程语言来自动化处理Excel数据,并将其转换为结构化的Word文档,同时包含索引目录和分页功能。这样的任务对于数据报告、数据分析或者日常办公自动化具有很高的实用价值。主要...

    php常用代码(分页,excel,图片缩放,汉字编码)

    1 advance_fenye2.0.php 一个分页的类,非常实用 2 char.php 汉字编码解决 3 class-excel-xml.inc.php excel文件生成类 4 image.php 图片缩放类

Global site tag (gtag.js) - Google Analytics