com.kcs.action.CompareDsFcpDsFtsAction.java Source code

Java tutorial

Introduction

Here is the source code for com.kcs.action.CompareDsFcpDsFtsAction.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.kcs.action;

import com.kcs.core.actions.BaseAction;
import com.kcs.core.utilities.DateUtil;
import com.kcs.core.utilities.PaggingList;
import com.kcs.core.utilities.Utility;
import com.kcs.model.CompareDsFcpDsFts;
import com.kcs.model.PositionReport;
import com.kcs.service.CompareDsFcpDsFtsService;
import com.kcs.service.PositionReportService;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @author LENOVO
 */
public class CompareDsFcpDsFtsAction extends BaseAction {
    private String dataSetDate;
    private PaggingList paging;
    private List<CompareDsFcpDsFts> list;
    private String fileName;
    private InputStream excelStream;
    @Autowired
    private CompareDsFcpDsFtsService service;

    @Override
    public String success() throws Exception {
        dataSetDate = service.getDataSetDate();
        if (Utility.isNull(getPaging())) {
            setPaging(new PaggingList());
        }
        search();
        return SUCCESS;

    }

    @Override
    public String search() throws Exception {

        paging = service.findMainListPaging(createPaginate(),
                DateUtil.getDateFromString(dataSetDate, DateUtil.DEFAULT_DATE_FORMAT));
        return SEARCH;
    }

    public String print() throws Exception {
        list = service.findMainList(DateUtil.getDateFromString(dataSetDate, DateUtil.DEFAULT_DATE_FORMAT));
        return "print";
    }

    @Override
    public String export() throws Exception {
        list = service.findMainList(DateUtil.getDateFromString(dataSetDate, DateUtil.DEFAULT_DATE_FORMAT));
        logger.debug("exportExcel : begin...");
        logger.debug("exportExcel : list >>> " + list.size());

        DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
        HSSFWorkbook myWorkBook = new HSSFWorkbook();
        HSSFSheet mySheet = myWorkBook.createSheet("Compate Ds FCP with Ds FTS Report");
        setFileName("Compate Ds FCP with Ds FTS Report_" + dateFormat.format(new Date()) + "excel".concat(".xls"));

        if (null != list && list.size() > 0) {
            int rownum = 0;
            Row row = mySheet.createRow(rownum++);
            int cellnum = 0;

            row.createCell(cellnum++).setCellValue("data_set_Date");
            row.createCell(cellnum++).setCellValue("pos_item");
            row.createCell(cellnum++).setCellValue("cl_nm_thai_fcp");
            row.createCell(cellnum++).setCellValue("fcp_amt");
            row.createCell(cellnum++).setCellValue("fcp_curr");
            row.createCell(cellnum++).setCellValue("tran_item");
            row.createCell(cellnum++).setCellValue("cl_nm_thai_fts");
            row.createCell(cellnum++).setCellValue("buy_fts_amt");
            row.createCell(cellnum++).setCellValue("sell_fts_amt");
            row.createCell(cellnum++).setCellValue("fts_curr");
            row.createCell(cellnum++).setCellValue("Diff_amt");

            for (CompareDsFcpDsFts obj : list) {
                Row rowData = mySheet.createRow(rownum++);
                cellnum = 0;
                rowData.createCell(cellnum++).setCellValue(obj.getDataSetDate() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getPosItem() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getClNmThaiFcp() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getFcpAmt() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getFcpCurr() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getTranItem() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getClNmThaiFts() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getBuyFtsAmt() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getSellFtsAmt() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getFtsCurr() + "");
                rowData.createCell(cellnum++).setCellValue(obj.getDiffAmt() + "");

            }

            for (int j = 0; j < cellnum; j++) {
                mySheet.autoSizeColumn(j);
            }
        }

        ByteArrayOutputStream boas = new ByteArrayOutputStream();
        myWorkBook.write(boas);
        setExcelStream(new ByteArrayInputStream(boas.toByteArray()));

        logger.debug("exportExcel : end...");
        return "excel";
    }

    /**
     * @return the dataSetDate
     */
    public String getDataSetDate() {
        return dataSetDate;
    }

    /**
     * @param dataSetDate the dataSetDate to set
     */
    public void setDataSetDate(String dataSetDate) {
        this.dataSetDate = dataSetDate;
    }

    /**
     * @return the paging
     */
    public PaggingList getPaging() {
        return paging;
    }

    /**
     * @param paging the paging to set
     */
    public void setPaging(PaggingList paging) {
        this.paging = paging;
    }

    /**
     * @return the list
     */
    public List<CompareDsFcpDsFts> getList() {
        return list;
    }

    /**
     * @param list the list to set
     */
    public void setList(List<CompareDsFcpDsFts> list) {
        this.list = list;
    }

    /**
     * @return the fileName
     */
    public String getFileName() {
        return fileName;
    }

    /**
     * @param fileName the fileName to set
     */
    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    /**
     * @return the excelStream
     */
    public InputStream getExcelStream() {
        return excelStream;
    }

    /**
     * @param excelStream the excelStream to set
     */
    public void setExcelStream(InputStream excelStream) {
        this.excelStream = excelStream;
    }

    /**
     * @return the service
     */
    public CompareDsFcpDsFtsService getService() {
        return service;
    }

    /**
     * @param service the service to set
     */
    public void setService(CompareDsFcpDsFtsService service) {
        this.service = service;
    }

}