Java tutorial
/* * 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.dto.ComboBoxDto; import com.kcs.model.ConfParamFM; import com.kcs.model.OutstandingReport; import com.kcs.service.BatchDataSetService; import com.kcs.service.OutstReportService; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.PrintWriter; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.struts2.ServletActionContext; import org.springframework.beans.factory.annotation.Autowired; /** * * @author chawachote */ public class OutstandingReportAction extends BaseAction { Logger logger = Logger.getLogger(this.getClass()); private List<ComboBoxDto> listOutstReport; private List<ComboBoxDto> listParamConfig; private String outstReport; private String txtParamConfig; private String txtParamType; private String txtDatasetDate; private PaggingList paging; private List<OutstandingReport> list; private String fileName; private InputStream excelStream; private HttpServletRequest servletRequest; private HttpServletResponse servletResponse; private List<ConfParamFM> listConfParamFM; private ConfParamFM confParamFM; private String seq; private String hidOutsReport; private String hidType; private String type; @Autowired OutstReportService outstReportService; @Autowired private BatchDataSetService batchDataSetService; @Override public String success() throws Exception { logger.debug("= = = = = SUCCESS = = = = ="); txtDatasetDate = DateUtil.format(batchDataSetService.findCurrDateFromSyst(), DateUtil.DEFAULT_DATE_FORMAT); initComboBox(); return SUCCESS; //To change body of generated methods, choose Tools | Templates. } @Override public String search() throws Exception { logger.debug("= = = = = SEARCH = = = = ="); logger.debug("txtDatasetDate >>> " + txtDatasetDate + " >>> " + txtParamConfig); String strReturn = SUCCESS; if ("Deposit".equals(txtParamConfig)) { strReturn = "successDeposit"; list = outstReportService.findByCriteriaDepositService(DateUtil.convertDateFromJsp(txtDatasetDate)); } else if ("Forward".equals(txtParamConfig)) { strReturn = "successForward"; list = outstReportService.findByCriteriaForwardService(DateUtil.convertDateFromJsp(txtDatasetDate)); } else if ("Loan".equals(txtParamConfig)) { strReturn = "successLoan"; list = outstReportService.findByCriteriaLoanService(DateUtil.convertDateFromJsp(txtDatasetDate)); } return strReturn; //To change body of generated methods, choose Tools | Templates. } @Override public String delete() throws Exception { logger.debug("= = = = = DELETE = = = = ="); return SUCCESS; //To change body of generated methods, choose Tools | Templates. } @Override public String edit() throws Exception { logger.debug("= = = = = EDIT = = = = ="); return EDIT; //To change body of generated methods, choose Tools | Templates. } @Override public String save() throws Exception { logger.debug("= = = = = SAVE = = = = ="); return SUCCESS; //To change body of generated methods, choose Tools | Templates. } @Override public String add() throws Exception { logger.debug("= = = = = ADD = = = = ="); return ADD; //To change body of generated methods, choose Tools | Templates. } public String findParamType() throws Exception { logger.debug("findParamType : outstReport >>> " + outstReport); txtParamType = outstReportService.retrieveParamTypeService(outstReport); return "findParamType"; //To change body of generated methods, choose Tools | Templates. } private void initComboBox() throws Exception { listOutstReport = outstReportService.findAllOutstReportService(); listParamConfig = new ArrayList<ComboBoxDto>(); } @Override public String export() throws Exception { logger.debug("= = = = = EXPORT = = = = ="); logger.debug("txtDatasetDate >>> " + txtDatasetDate + " >>> " + txtParamConfig); // servletRequest = ServletActionContext.getRequest(); // servletResponse = ServletActionContext.getResponse(); // // servletResponse.setContentType("application/vnd.ms-excel"); // servletResponse.setCharacterEncoding("UTF-8"); // DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss"); // servletResponse.setHeader("Content-Disposition", "attachment; filename=excelTracking_" + dateFormat.format(new Date()) + ".xls"); // PrintWriter out = servletResponse.getWriter(); // // out.println(" <head> "); // out.println(" <meta http-equiv=\"Content-Type\" content=\"application/vnd.ms-excel; charset=UTF-8\"> "); // out.println(" </head> "); // out.println(" <table width=\"100%\" border=\"1\" cellspacing=\"1\" cellpadding=\"0\"> "); // out.println(" <tr> "); // out.println(" <td style=\"width:150px;text-align:center;background:#CCC;font-weight:bold\">App Date</td> "); // out.println(" <td style=\"width:150px;text-align:center;background:#CCC;font-weight:bold\">App Ref</td> "); // out.println(" <td style=\"width:150px;text-align:center;background:#CCC;font-weight:bold\">Company ID</td> "); // out.println(" <td style=\"width:150px;text-align:center;background:#CCC;font-weight:bold\">Company Name</td> "); // out.println(" <td style=\"width:150px;text-align:center;background:#CCC;font-weight:bold\">Action</td> "); // out.println(" <td style=\"width:150px;text-align:center;background:#CCC;font-weight:bold\">System</td> "); // out.println(" <td style=\"width:150px;text-align:center;background:#CCC;font-weight:bold\">Submit ID</td> "); // out.println(" <td style=\"width:150px;text-align:center;background:#CCC;font-weight:bold\">Submit Name</td> "); // out.println(" <td style=\"width:150px;text-align:center;background:#CCC;font-weight:bold\">Overall Status</td> "); // out.println(" <td style=\"width:150px;text-align:center;background:#CCC;font-weight:bold\">Accepted Date</td> "); // out.println(" <td style=\"width:150px;text-align:center;background:#CCC;font-weight:bold\">Completed Date</td> "); // out.println(" </tr> "); list = outstReportService.findByCriteriaDepositService(DateUtil.convertDateFromJsp(txtDatasetDate)); DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss"); HSSFWorkbook myWorkBook = new HSSFWorkbook(); HSSFSheet mySheet = myWorkBook.createSheet("Dataset IRF"); setFileName("outstanding_report_deposit_" + dateFormat.format(new Date()) + "excel".concat(".xls")); Row headerRow = mySheet.createRow(0); if (null != list && list.size() > 0) { int rownum = 1; String[] column = new String[] { "DATA_DATE", "SYS_CODE", "DATA_PVDR_IBF_IND", "FI_ARRG_NO", "CURR", "TRAN_AMT", "LAST_OUTST_DATA_SET_DATE", "CUST_CODE", "NAT", "CTRY" }; Row rowColumn = mySheet.createRow(1); for (String columnName : column) { int cellnum = 0; Cell cell = rowColumn.createCell(cellnum++); cell.setCellValue(columnName); } for (OutstandingReport obj : list) { Row row = mySheet.createRow(rownum++); int cellnum = 0; row.createCell(cellnum++).setCellValue(obj.getDepositDataDate()); row.createCell(cellnum++).setCellValue(obj.getDepositSysCode()); row.createCell(cellnum++).setCellValue(obj.getDepositDataPvdrIbfInd()); row.createCell(cellnum++).setCellValue(obj.getDepositFiArrgNo()); row.createCell(cellnum++).setCellValue(obj.getDepositCurr()); row.createCell(cellnum++).setCellValue(String.valueOf(obj.getDepositTranAmt())); row.createCell(cellnum++).setCellValue(obj.getDepositLastOutstDataSetDate()); row.createCell(cellnum++).setCellValue(obj.getDepositCustCode()); row.createCell(cellnum++).setCellValue(obj.getDepositNat()); row.createCell(cellnum++).setCellValue(obj.getDepositCtry()); } } ByteArrayOutputStream boas = new ByteArrayOutputStream(); myWorkBook.write(boas); setExcelStream(new ByteArrayInputStream(boas.toByteArray())); logger.debug("exportExcel : end..."); return "excelDeposit"; // String strReturn = SUCCESS; // if("Deposit".equals(txtParamConfig)){ // strReturn = "exportDeposit"; // list = outstReportService.findByCriteriaDepositService(DateUtil.convertDateFromJsp(txtDatasetDate)); // }else if("Forward".equals(txtParamConfig)){ // strReturn = "exportForward"; // list = outstReportService.findByCriteriaForwardService(DateUtil.convertDateFromJsp(txtDatasetDate)); // }else if("Loan".equals(txtParamConfig)){ // strReturn = "exportLoan"; // list = outstReportService.findByCriteriaLoanService(DateUtil.convertDateFromJsp(txtDatasetDate)); // } // return strReturn; //To change body of generated methods, choose Tools | Templates. } //----- manage Outst Report public String getDetailOutstReport() throws Exception { logger.debug("= = = = = getDetailOutstReport = = = = ="); hidType = "outsReport"; listConfParamFM = outstReportService.getAllOutsReportService(); return "getDetailOutstReport"; } public String addDetailOutstReport() throws Exception { logger.debug("= = = = = addDetailOutstReport = = = = ="); hidType = "outsReport"; type = "insert"; confParamFM = new ConfParamFM(); confParamFM.setParamConfig("ETL_to_DMS_Outst_Report"); confParamFM.setParamType("Criteria Report"); confParamFM.setUpdDate(DateUtil.getCurrentDateTime()); confParamFM.setUpdBy("KTBCS"); return "addDetailOutstReport"; } public String editDetailOutstReport() throws Exception { logger.debug("= = = = = editDetailOutstReport = = = = ="); hidType = "outsReport"; type = "update"; confParamFM = outstReportService.getOutsReportBySeqService(Long.parseLong(seq)); confParamFM.setParamConfig("ETL_to_DMS_Outst_Report"); confParamFM.setParamType("Criteria Report"); confParamFM.setUpdDate(DateUtil.getCurrentDateTime()); confParamFM.setUpdBy("KTBCS"); return "editDetailOutstReport"; } public String updateDetailOutstReport() throws Exception { logger.debug("= = = = = updateDetailOutstReport = = = = ="); boolean result = outstReportService.updateOutsReportService(confParamFM); if (result) { logger.debug("Update detail outstanding report success."); } else { logger.debug("Update detail outstanding report fail."); } String strReturn = "getDetailOutstReport"; if ("paramConfig".equals(hidType)) { strReturn = "getDetailParamConfig"; listConfParamFM = outstReportService.getAllParamConfigService(confParamFM.getParamConfig()); hidOutsReport = confParamFM.getParamConfig(); } else { listConfParamFM = outstReportService.getAllOutsReportService(); } return strReturn; } public String deleteDetailOutstReport() throws Exception { logger.debug("= = = = = deleteDetailOutstReport = = = = ="); logger.debug("chk.length >>> " + servletRequest.getParameterValues("chk")); String[] tmp = servletRequest.getParameterValues("chk"); List<Long> longSeq = new ArrayList<Long>(); if (tmp.length > 0) { for (String s : tmp) { logger.debug("Param seq >>> " + s); longSeq.add(Long.parseLong(s)); } } boolean result = outstReportService.deleteOutsReportService(longSeq); if (result) { logger.debug("Delete detail outstanding report success."); } else { logger.debug("Delete detail outstanding report fail."); } String strReturn = "getDetailOutstReport"; if ("paramConfig".equals(hidType)) { strReturn = "getDetailParamConfig"; listConfParamFM = outstReportService.getAllParamConfigService(hidOutsReport); } else { listConfParamFM = outstReportService.getAllOutsReportService(); } return strReturn; } public String saveDetailOutstReport() throws Exception { logger.debug("= = = = = saveDetailOutstReport = = = = ="); Utility.traceObject(confParamFM); boolean result = outstReportService.saveOutsReportService(confParamFM); if (result) { logger.debug("Add detail outstanding report success."); } else { logger.debug("Add detail outstanding report fail."); } String strReturn = "getDetailOutstReport"; if ("paramConfig".equals(hidType)) { strReturn = "getDetailParamConfig"; hidOutsReport = confParamFM.getParamConfig(); listConfParamFM = outstReportService.getAllParamConfigService(confParamFM.getParamConfig()); } else { listConfParamFM = outstReportService.getAllOutsReportService(); } return strReturn; } //----- manage Param Config public String getDetailParamConfig() throws Exception { logger.debug("= = = = = getDetailParamConfig = = = = ="); hidType = "paramConfig"; hidOutsReport = outstReport; listConfParamFM = outstReportService.getAllParamConfigService(outstReport); return "getDetailParamConfig"; } public String addDetailParamConfig() throws Exception { logger.debug("= = = = = addDetailParamConfig = = = = ="); hidType = "paramConfig"; type = "insert"; confParamFM = new ConfParamFM(); confParamFM.setParamConfig(hidOutsReport); confParamFM.setParamType("Report"); confParamFM.setUpdDate(DateUtil.getCurrentDateTime()); confParamFM.setUpdBy("KTBCS"); return "addDetailOutstReport"; } public String editDetailParamConfig() throws Exception { logger.debug("= = = = = editDetailParamConfig = = = = ="); hidType = "paramConfig"; type = "update"; confParamFM = outstReportService.getOutsReportBySeqService(Long.parseLong(seq)); confParamFM.setParamConfig(hidOutsReport); confParamFM.setParamType("Report"); confParamFM.setUpdDate(DateUtil.getCurrentDateTime()); confParamFM.setUpdBy("KTBCS"); return "editDetailOutstReport"; } //---------- Bean /** * @return the listOutstReport */ public List<ComboBoxDto> getListOutstReport() { return listOutstReport; } /** * @param listOutstReport the listOutstReport to set */ public void setListOutstReport(List<ComboBoxDto> listOutstReport) { this.listOutstReport = listOutstReport; } /** * @return the listParamConfig */ public List<ComboBoxDto> getListParamConfig() { return listParamConfig; } /** * @param listParamConfig the listParamConfig to set */ public void setListParamConfig(List<ComboBoxDto> listParamConfig) { this.listParamConfig = listParamConfig; } /** * @return the outstReport */ public String getOutstReport() { return outstReport; } /** * @param outstReport the outstReport to set */ public void setOutstReport(String outstReport) { this.outstReport = outstReport; } /** * @return the txtParamConfig */ public String getTxtParamConfig() { return txtParamConfig; } /** * @param txtParamConfig the txtParamConfig to set */ public void setTxtParamConfig(String txtParamConfig) { this.txtParamConfig = txtParamConfig; } /** * @return the txtParamType */ public String getTxtParamType() { return txtParamType; } /** * @param txtParamType the txtParamType to set */ public void setTxtParamType(String txtParamType) { this.txtParamType = txtParamType; } /** * @return the txtDatasetDate */ public String getTxtDatasetDate() { return txtDatasetDate; } /** * @param txtDatasetDate the txtDatasetDate to set */ public void setTxtDatasetDate(String txtDatasetDate) { this.txtDatasetDate = txtDatasetDate; } /** * @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<OutstandingReport> getList() { return list; } /** * @param list the list to set */ public void setList(List<OutstandingReport> 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; } @Override public void setServletRequest(HttpServletRequest servletRequest) { this.servletRequest = servletRequest; } public void setServletResponse(HttpServletResponse servletResponse) { this.servletResponse = servletResponse; } /** * @return the listConfParamFM */ public List<ConfParamFM> getListConfParamFM() { return listConfParamFM; } /** * @param listConfParamFM the listConfParamFM to set */ public void setListConfParamFM(List<ConfParamFM> listConfParamFM) { this.listConfParamFM = listConfParamFM; } /** * @return the confParamFM */ public ConfParamFM getConfParamFM() { return confParamFM; } /** * @param confParamFM the confParamFM to set */ public void setConfParamFM(ConfParamFM confParamFM) { this.confParamFM = confParamFM; } /** * @return the seq */ public String getSeq() { return seq; } /** * @param seq the seq to set */ public void setSeq(String seq) { this.seq = seq; } /** * @return the hidOutsReport */ public String getHidOutsReport() { return hidOutsReport; } /** * @param hidOutsReport the hidOutsReport to set */ public void setHidOutsReport(String hidOutsReport) { this.hidOutsReport = hidOutsReport; } /** * @return the hidType */ public String getHidType() { return hidType; } /** * @param hidType the hidType to set */ public void setHidType(String hidType) { this.hidType = hidType; } /** * @return the type */ public String getType() { return type; } /** * @param type the type to set */ public void setType(String type) { this.type = type; } }