public void prepareDateRange() throws Exception { DetachedCriteria criteria = DetachedCriteria.forClass(ConfirmationRecord.class); ProjectionList pjl = Projections.projectionList(); pjl.add(Projections.property("cycleFrom")); pjl.add(Projections.property("cycleTo")); criteria.setProjection(Projections.distinct(pjl)); List<?> list = confirmationRecordService.findByCriteria(criteria); if (list.size() > 0) { Object[] objs = list.toArray(); selectionCycleFrom = new ArrayList<>(); selectionCycleFrom.add(new SelectItem(null, "Please Select")); cycleTos = new ArrayList<>(); for (Object obj : objs) { if (obj instanceof Object[]) { Object[] innerObjs = (Object[]) obj; if (innerObjs.length == 2) { Date dFrom = DateUtil.convStringToDate(MS_SQL_DATE_PATTERN, innerObjs[0].toString()); Date dTo = DateUtil.convStringToDate(MS_SQL_DATE_PATTERN, innerObjs[1].toString()); selectionCycleFrom.add( new SelectItem( DateUtil.convDateToString(SIMPLE_DATE_PATTERN, dFrom), DateUtil.convDateToString(DISPLAY_DATE_PATTERN, dFrom))); cycleTos.add(DateUtil.convDateToString(SIMPLE_DATE_PATTERN, dTo)); } else { System.err.println("ERR: obj[] length not eq to 2"); } } } } }
public void doDownload() throws Throwable { if (StringUtils.isBlank(selectedDateFrom) || StringUtils.isBlank(selectedDateTo)) { MessageUtils.getInstance().addErrorMessage("msgDialogDL", "Please select date"); return; } if (selectedDateFrom.compareTo(selectedDateTo) < 0) { try { Date cycleFrom = DateUtil.convStringToDate(SIMPLE_DATE_PATTERN, selectedDateFrom); Date cycleTo = DateUtil.convStringToDate(SIMPLE_DATE_PATTERN, selectedDateTo); DetachedCriteria criteria = DetachedCriteria.forClass(ConfirmationRecord.class); criteria.add(Restrictions.between("cycleFrom", cycleFrom, cycleTo)); criteria.add(Restrictions.between("cycleTo", cycleFrom, cycleTo)); criteria.addOrder(Order.asc("cycleFrom")); criteria.addOrder(Order.asc("id")); List<ConfirmationRecord> list = confirmationRecordService.findByCriteria(criteria); Workbook wb = createExcel(list); if (wb != null) { wb.removeSheetAt(0); FileTransfer ft = new FileTransfer(); String fileName = EXCEL_NAME_PATTERN + TEMPLATE_EXCEL_CONF_REPORT_PATH.substring( TEMPLATE_EXCEL_CONF_REPORT_PATH.lastIndexOf("."), TEMPLATE_EXCEL_CONF_REPORT_PATH.length()); fileName = fileName.replaceAll( "#fdd-MMM-yyyy", DateUtil.convDateToString(DISPLAY_DATE_PATTERN, maxCycleFrom)); fileName = fileName.replaceAll( "#tdd-MMM-yyyy", DateUtil.convDateToString(DISPLAY_DATE_PATTERN, maxCycleTo)); ft.fileDownload(fileName, wb); } init(); } catch (Exception e) { e.printStackTrace(); } } else { MessageUtils.getInstance().addErrorMessage("msgDialogDL", "Invalid date"); } }
public void cycleListener() throws ParseException { selectionCycleTo = new ArrayList<>(); if (!StringUtils.isBlank(selectedDateFrom)) { selectionCycleTo.add(new SelectItem(null, "Please Select")); for (String cycleTo : cycleTos) { if (cycleTo.compareTo(selectedDateFrom) > 0) { selectionCycleTo.add( new SelectItem( cycleTo, DateUtil.convDateToString( DISPLAY_DATE_PATTERN, DateUtil.convStringToDate(SIMPLE_DATE_PATTERN, cycleTo)))); } } } }