query pagination excele

/**
     * Download the transaction statement of the previous day
     * @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
("Recycle the current merchant's The login account is {}",memberMerchant.getLoginId());
String newBeginDate = "";
if(Utils.isNull(beginDate)){
newBeginDate = DateUtil.format(new Date(), DateUtil.YYYY_MM_DD, -1);/ /The previous day's transaction statement
}else{
newBeginDate = DateUtil.format(beginDate,DateUtil.YYYY_MM_DD);
}
log.info("Start time="+newBeginDate);
String fileName = memberMerchant.getLoginId();
//Statement end time
String newEndDate = "";
if( Utils.isNull(endDate)){
newEndDate = DateUtil.format(new Date(), DateUtil.YYYY_MM_DD, -1);//The transaction statement of the previous day
}else{
newEndDate = DateUtil.format(endDate,DateUtil.YYYY_MM_DD );
}
        if (!StringUtils.isEmpty(newBeginDate) && !StringUtils.isEmpty(newEndDate)) {
            fileName += "(" + newBeginDate + "-" + newEndDate + ")"+"_";
        }
        //template path
        String templateUrl = Property.getProperty("url.downloadMerchantBills.template", "");
        //Export to the specified path
        String newfilePath = Property.getProperty("url.merchantBills.path");
        //Generate the directory structure according to the merchant login account
        String memberId = memberMerchant.getMemberId()+"/";
        newfilePath +=memberId;
        File dirFile = new File(newfilePath); log.info
                ("----newfilePath----:" + newfilePath);
                if (! dirFile.exists()) {
                log.info("Create folder:" + newfilePath);
                    dirFile.mkdirs();
                }
               
        //File path for storing statement data
        newfilePath +=fileName;
        //Query the statement data parameters of the current merchant on the previous trading day
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("beginDate", newBeginDate);
        data.put("endDate" , newEndDate);
        data.put("mchLoginId", memberMerchant.getLoginId());
       
        //Process large data volume export
        String tempFilePath="";
        //Query the total reconciliation quantity of the current merchant
        int totalRecord = this.queryMerchantBillsCountByLoginId( data);
        //Query data according to the incoming paging start and end values
        ​​int startPageNo=0,pageSize=0,pagesTotal = 0,size=2,endPageNo=0;
        if(totalRecord >0){
        //This merchant has a pair Billing data
        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("Export exception of scheduled task report", ie);
            }
        }
        }

}

}












/**
     * Download the merchant's transaction statement of the previous day
     * @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
("The login account of the current merchant is {}", memberMerchant.getLoginId());
String newBeginDate = "";
if(Utils.isNull(beginDate)){
newBeginDate = DateUtil.format(new Date(), DateUtil.YYYY_MM_DD, -1);//The transaction statement of the previous day
}else{
newBeginDate = DateUtil .format(beginDate,DateUtil.YYYY_MM_DD);
}
log.info("start time="+newBeginDate);
String fileName = memberMerchant.getLoginId();
// statement end time
String newEndDate = "";
if(Utils.isNull (endDate)){
newEndDate = DateUtil.format(new Date(), DateUtil.YYYY_MM_DD, -1);//The transaction statement of the previous day
}else{
newEndDate = DateUtil.format(endDate,DateUtil.YYYY_MM_DD);
}
        if (!StringUtils.isEmpty(newBeginDate) && !StringUtils.isEmpty(newEndDate)) {
            fileName += "(" + newBeginDate + "-" + newEndDate + ")";
        }
        //Template path
        String templateUrl = Property.getProperty("url.downloadMerchantBills.template", "");
        //Export to specified path
        String newfilePath = Property.getProperty("url.merchantBills.path");
        //Generate directory structure according to the merchant login account
        String memberId = memberMerchant.getMemberId()+"/";
        newfilePath +=memberId;
        File dirFile = new File(newfilePath) ;
                log.info("----newfilePath----:" + newfilePath);
                if (!dirFile.exists()) {
                log.info("Create folder:" + newfilePath);
                    dirFile.mkdirs ();
                }
               
        //The file path for storing the statement data
        newfilePath +=fileName;
        //Query the statement data parameters of the current merchant on the previous trading day
        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){
        //This merchant has statement data
        pagesTotal=(totalRecord-1)/size+1;
        for(int j=0;j<pagesTotal; j++){
        //loop to export multiple excele files
        log.info("Exporting the merchant ID: "+memberMerchant.getMemberId()+"the "+j+" excel file");
        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";
        //The template file is downloaded from the server
        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("Export exception of scheduled task report", ie);
            }
        }*/
        }
        }else{
        //There is no statement data information.
        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";
        //The template file is downloaded from the server
        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(" Report export exception", ie);
            }
        }
    }
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326949053&siteId=291194637