我试图使函数导出pdf,就像当您执行某些项目时,并且当您完成项目时,您可以导出pdf文件(在此值显示为正常),如果项目不兼容,您可以修改项目,您可以再次执行项目,完成项目后,您可以再次导出文件,但是在这里文件打印了两次,我已经在第一行exportToPdf()函数上设置了resetpdf(),但现在可以正常使用
public void resetpdf() {
listReportFinishProject.clear();
listSubReport.clear();
listProjectStatus.clear();
listTable.clear();
listReportFinishProject = new ArrayList<>();
listSubReport = new ArrayList<>();
listProjectStatus = new ArrayList<>();
listTable = new ArrayList<>();
lazyDeliveryProjectForGroupDataModel = null;
}
public JasperPrint exportTo() {
String path;
if(this.listReportFinishProject == null || this.listReportFinishProject.isEmpty()){
FacesMessage messageFailed = new FacesMessage(FacesMessage.SEVERITY_INFO,"Info","No data found");
RequestContext.getCurrentInstance().showMessageInDialog(messageFailed);
return null;
}
path = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/resources/report/DeliverableProject.jasper");
JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(this.listReportFinishProject);
System.out.println("Asdasdasdasd: "+listReportFinishProject.size());
try {
JasperPrint jasperPrint = JasperFillManager.fillReport(path, parameter, beanCollectionDataSource);
return jasperPrint;
} catch (JRException e) {
e.printStackTrace();
return null;
}
}
public void exportToPdf(ActionEvent actionEvent){
resetpdf();
listPRPKProject = prpkProjectDAO.retriveAll("AND a.master_project_sid = ? ", new Object[]{selectedProject.getId()});
listPRPK = prpkDAO.retriveAll("AND a.id = ?", new Object[]{listPRPKProject.get(0).getMasterPrpkId()});
listGroupPRPK = groupPRPKDAO.retriveAll("AND a.master_prpk_id = ? ", new Object[]{listPRPK.get(0).getId()}); //AND a.group_id NOT IN ( ? ) , userLogin.getGroupId()
listProjectStatus = deliveryProjectQuery.retriveAll("AND e.id = "+selectedProject.getPrpkId()+" GROUP BY a.sid, a.project_name, a.dp_number, h.group_name, e.prpk_number, k.status_name, b.is_freeze, l.file_name ORDER BY a.project_name ASC ", new Object[]{}); //AND a.sid NOT IN ("+selectedProject.getId()+"
lazyDeliveryProjectForGroupDataModel = new LazyDeliveryProjectForGroupDataModel(listProjectStatus);
if(this.selectedProject != null){
System.out.println("qqqq: "+listGroupPRPK.size());
System.out.println("aaashiyaapp");
if(selectedProject.getDPNumber() == null || selectedProject.getDPNumber().equals("")){
deliveryProject.setdPNumber("-");
}else{
deliveryProject.setdPNumber(selectedProject.getDPNumber());
}
if(userLogin.getGroupId() == null || userLogin.getGroupId().equals("")){
deliveryProject.setGroupName(selectedProject.getGroupName());
}else{
listGroup = projectController.getGroupName(userLogin.getGroupId());
deliveryProject.setGroupName(listGroup.get(0).getName());
}
if(selectedProject.getProjectName() == null || selectedProject.getProjectName().equals("")){
deliveryProject.setProjectName("-");
}else{
deliveryProject.setProjectName(selectedProject.getProjectName());
}
if(selectedProject.getPrpkNumber() == null || selectedProject.getPrpkNumber().equals("")){
deliveryProject.setPrpkNumber("-");
}else{
deliveryProject.setPrpkNumber(selectedProject.getPrpkNumber());
}
this.listReportFinishProject.add(deliveryProject);
listTable = new DeliverableProjectTableQuery().retriveAll("AND e.id = "+selectedProject.getPrpkId()+" GROUP BY a.sid, a.project_name, a.dp_number, h.group_name, e.prpk_number, k.status_name, b.is_freeze, h.id ORDER BY CASE WHEN h.id = "+userLogin.getGroupId()+" THEN 1 ELSE 0 END DESC", new Object[] {});
for(int a = 0; a<listTable.size(); a++) {
deliveryProject = new DeliverablesProject();
deliveryProject.setNoSoW(listTable.get(a).getNoSoW());
deliveryProject.setGroupTableName(listTable.get(a).getGroupName());
System.out.println(listProjectStatus.get(a).getGroupName());
if(listTable.get(a).getIsFreeze().equals("n")){
if(listTable.get(a).getStatusName().equals("New") || listTable.get(a).getStatusName().equals("Draft")){
deliveryProject.setStatusDesc(" Status masih dalam antrian (belum dikerjakan)");
}
if((listTable.get(a).getStatusName().equals("Waiting SoW")) || (listTable.get(a).getStatusName().equals("(Rev) Waiting SoW"))){
deliveryProject.setStatusDesc(" Status masih menunggu SoW dari Business Analyst");
}
if((listTable.get(a).getStatusName().equals("SoW Uploaded")) || (listTable.get(a).getStatusName().equals("(Rev) SoW Uploaded"))){
deliveryProject.setStatusDesc(" Status masih Di Business Analyst");
}
if((listTable.get(a).getStatusName().equals("Publish")) || (listTable.get(a).getStatusName().equals("(Rev) Publish"))){
deliveryProject.setStatusDesc(" Status masih menunggu dikerjakan oleh Developer");
}
if((listTable.get(a).getStatusName().equals("On Dev")) || (listTable.get(a).getStatusName().equals("(Rev) On Dev"))){
deliveryProject.setStatusDesc(" Status masih di Developer");
}
if((listTable.get(a).getStatusName().equals("Finish Dev")) || (listTable.get(a).getStatusName().equals("(Rev) Finish Dev"))){
deliveryProject.setStatusDesc(" Status masih menunggu dikerjakan oleh Data Analyst / Support SD");
}
if((listTable.get(a).getStatusName().equals("On DA")) || (listTable.get(a).getStatusName().equals("(Rev) On DA"))){
deliveryProject.setStatusDesc(" Status masih di Data Analyst");
}
if((listTable.get(a).getStatusName().equals("Finish DA")) || (listTable.get(a).getStatusName().equals("(Rev) Finish DA"))){
deliveryProject.setStatusDesc(" Status masih menunggu dikerjakan oleh Support SD");
}
if((listTable.get(a).getStatusName().equals("On Support")) || (listTable.get(a).getStatusName().equals("(Rev) On Support"))){
deliveryProject.setStatusDesc(" Status masih di Support SD" );
}
if((listTable.get(a).getStatusName().equals("Finish Support")) || (listTable.get(a).getStatusName().equals("(Rev) Finish Support"))){
deliveryProject.setStatusDesc(" Status masih menunggu dilakukan UAT");
}
if((listTable.get(a).getStatusName().equals("Finish - Need Revise")) || (listTable.get(a).getStatusName().equals("Finish")) || (listTable.get(a).getStatusName().equals("(Rev) Finish")) || (listTable.get(a).getStatusName().equals("Finish Completed"))){
deliveryProject.setStatusDesc("Status Pengerjaan Project sudah selesai dilakukan ");
}
if((listTable.get(a).getStatusName().equals("Rejected"))){
deliveryProject.setStatusDesc(" Status Project di-reject oleh Departemen IT bersangkutan");
}
}else{
deliveryProject.setStatusDesc(" Status Pengerjaan Project sedang di-freeze");
}
this.listSubReport.add(deliveryProject);
}
String sql = ((LazyDeliveryProjectForGroupDataModel) this.lazyDeliveryProjectForGroupDataModel).getSqlReportPrint();
List<Object> listObject = ((LazyDeliveryProjectForGroupDataModel) this.lazyDeliveryProjectForGroupDataModel).getObjectSqlListReportPrint();
this.listReportFinishProject = projectController.getListReportProject(sql, listObject);
String sql2 = ("AND e.id = "+selectedProject.getPrpkId()+" AND a.sid = "+selectedProject.getId()+" GROUP BY a.sid, a.project_name, a.dp_number, h.group_name, e.prpk_number, k.status_name, b.is_freeze ORDER BY a.project_name ASC");
this.listReportFinishProject = projectController.getListReportProject(sql2, listObject);
String imagePath = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/resources/image/indomaret.jpg");
Image logo = new ImageIcon(imagePath).getImage();
String waterMarkImagePath = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/resources/image/confidential.png");
Image watermark = new ImageIcon(waterMarkImagePath).getImage();
DateFormat dateFormat = new SimpleDateFormat("dd MMMMM yyyy");
Date uatDate = selectedProject.getUatDate();
parameter.put("logoImage", logo);
parameter.put("watermarkImage", watermark);
if(selectedProject.getUatDate() == null) {
parameter.put("releaseDate", "-");
System.out.println("1");
}else {
parameter.put("releaseDate", dateFormat.format(uatDate));
System.out.println("2");
}
parameter.put("reportData", new JRBeanCollectionDataSource(listSubReport));
System.out.println("list: "+listProjectStatus.size());
JasperPrint jasperPrint = exportTo();
//String formatFile = dateFormatFile.format(startDate).concat("-").concat(dateFormatFile.format(endDate));
String fileName = "Deliverables_Project_".concat(selectedProject.getDPNumber()).concat(".pdf");
if(jasperPrint != null) projectController.exportToPDF(fileName, jasperPrint);
else System.out.println("jasperprint null");
}else{
FacesMessage messageFailed = new FacesMessage(FacesMessage.SEVERITY_INFO,"Info","No data found");
RequestContext.getCurrentInstance().showMessageInDialog(messageFailed);
}
resetpdf();
}