Browse Source
Merge branch 'master' of http://10.100.1.53:3000/hariprasaths/commissioner_review_1_may2025
master
Merge branch 'master' of http://10.100.1.53:3000/hariprasaths/commissioner_review_1_may2025
master
5 changed files with 351 additions and 7 deletions
-
38pom.xml
-
199src/main/java/com/gcc/commissionerreview/CsvImagePdfGenerator.java
-
12src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java
-
30src/main/java/com/gcc/commissionerreview/controller/NewsAPIController.java
-
69src/main/java/com/gcc/commissionerreview/service/NewsAPIService.java
@ -0,0 +1,199 @@ |
|||||
|
package com.gcc.commissionerreview; |
||||
|
|
||||
|
import com.opencsv.CSVReader; |
||||
|
import com.itextpdf.text.*; |
||||
|
import com.itextpdf.text.pdf.PdfPCell; |
||||
|
import com.itextpdf.text.pdf.PdfPTable; |
||||
|
import com.itextpdf.text.pdf.PdfWriter; |
||||
|
|
||||
|
import java.io.*; |
||||
|
import java.net.URL; |
||||
|
import java.util.*; |
||||
|
import java.util.List; |
||||
|
|
||||
|
public class CsvImagePdfGenerator { |
||||
|
|
||||
|
// Base output directory for generated PDFs |
||||
|
private static final String OUTPUT_DIR = "C:/Users/prave/Downloads/Banner Removal Report/14052026/"; |
||||
|
private static final String REPORT_DATE = "14/05/2026"; |
||||
|
|
||||
|
public static void main(String[] args) { |
||||
|
|
||||
|
String csvFile = "C:/Users/prave/Downloads/Banner_Removal_Report_14052026.csv"; |
||||
|
|
||||
|
try { |
||||
|
|
||||
|
CSVReader reader = new CSVReader(new FileReader(csvFile)); |
||||
|
|
||||
|
String[] row; |
||||
|
|
||||
|
// Skip Header |
||||
|
reader.readNext(); |
||||
|
|
||||
|
// Group rows by zone value (preserves insertion order) |
||||
|
Map<String, List<String[]>> zoneGroupedRows = new LinkedHashMap<>(); |
||||
|
|
||||
|
while ((row = reader.readNext()) != null) { |
||||
|
|
||||
|
String zone = row[6]; |
||||
|
|
||||
|
zoneGroupedRows |
||||
|
.computeIfAbsent(zone, k -> new ArrayList<>()) |
||||
|
.add(row); |
||||
|
} |
||||
|
|
||||
|
reader.close(); |
||||
|
|
||||
|
// Generate a separate PDF for each zone |
||||
|
for (Map.Entry<String, List<String[]>> entry : zoneGroupedRows.entrySet()) { |
||||
|
|
||||
|
String zone = entry.getKey(); |
||||
|
List<String[]> rows = entry.getValue(); |
||||
|
|
||||
|
// Sanitize zone name for use in filename |
||||
|
String safeZoneName = zone.replaceAll("[^a-zA-Z0-9_\\-]", "_"); |
||||
|
|
||||
|
String outputPdf = OUTPUT_DIR |
||||
|
+ "banner_removal_report_zone_" + safeZoneName |
||||
|
+ "_14052026.pdf"; |
||||
|
|
||||
|
generatePdfForZone(zone, rows, outputPdf); |
||||
|
|
||||
|
System.out.println("PDF Generated for Zone: " + zone |
||||
|
+ " -> " + outputPdf); |
||||
|
} |
||||
|
|
||||
|
System.out.println("All PDFs Generated Successfully!"); |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
|
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Generates a PDF file containing all records for the given zone. |
||||
|
*/ |
||||
|
private static void generatePdfForZone(String zone, List<String[]> rows, |
||||
|
String outputPdf) throws Exception { |
||||
|
|
||||
|
Document document = new Document(PageSize.A4.rotate()); |
||||
|
PdfWriter.getInstance(document, new FileOutputStream(outputPdf)); |
||||
|
|
||||
|
document.open(); |
||||
|
|
||||
|
for (String[] row : rows) { |
||||
|
|
||||
|
String id = row[0]; |
||||
|
String name = row[1]; |
||||
|
String categoryId = row[2]; |
||||
|
String latitude = row[4]; |
||||
|
String longitude = row[5]; |
||||
|
// zone is already known from the parameter |
||||
|
String ward = row[7]; |
||||
|
String streetId = row[8]; |
||||
|
String streetName = row[9]; |
||||
|
String cdate = row[10]; |
||||
|
|
||||
|
String beforeImageUrl = row[11]; |
||||
|
String afterImageUrl = row[13]; |
||||
|
|
||||
|
// Title |
||||
|
Font boldFont = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD); |
||||
|
|
||||
|
Paragraph title = new Paragraph( |
||||
|
"Banner Removal Report - " + REPORT_DATE |
||||
|
+ " | Zone: " + zone, |
||||
|
boldFont); |
||||
|
|
||||
|
document.add(title); |
||||
|
document.add(new Paragraph(" ")); |
||||
|
|
||||
|
// Details Table |
||||
|
PdfPTable detailsTable = new PdfPTable(2); |
||||
|
detailsTable.setWidthPercentage(100); |
||||
|
|
||||
|
detailsTable.addCell("Category ID"); |
||||
|
detailsTable.addCell(categoryId); |
||||
|
|
||||
|
detailsTable.addCell("Zone"); |
||||
|
detailsTable.addCell(zone); |
||||
|
|
||||
|
detailsTable.addCell("Ward"); |
||||
|
detailsTable.addCell(ward); |
||||
|
|
||||
|
detailsTable.addCell("Street"); |
||||
|
detailsTable.addCell(streetName); |
||||
|
|
||||
|
detailsTable.addCell("Latitude"); |
||||
|
detailsTable.addCell(latitude); |
||||
|
|
||||
|
detailsTable.addCell("Longitude"); |
||||
|
detailsTable.addCell(longitude); |
||||
|
|
||||
|
detailsTable.addCell("Enumerated Date"); |
||||
|
detailsTable.addCell(cdate); |
||||
|
|
||||
|
detailsTable.addCell("Removal Date"); |
||||
|
detailsTable.addCell(REPORT_DATE); |
||||
|
|
||||
|
document.add(detailsTable); |
||||
|
|
||||
|
document.add(new Paragraph(" ")); |
||||
|
|
||||
|
// Image Table |
||||
|
PdfPTable imageTable = new PdfPTable(2); |
||||
|
imageTable.setWidthPercentage(100); |
||||
|
|
||||
|
imageTable.addCell("Before Image"); |
||||
|
imageTable.addCell("After Image"); |
||||
|
|
||||
|
// BEFORE IMAGE |
||||
|
PdfPCell beforeCell; |
||||
|
|
||||
|
try { |
||||
|
|
||||
|
Image beforeImage = Image.getInstance(new URL(beforeImageUrl)); |
||||
|
|
||||
|
beforeImage.scaleToFit(250, 250); |
||||
|
|
||||
|
beforeCell = new PdfPCell(beforeImage); |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
|
||||
|
beforeCell = new PdfPCell( |
||||
|
new Phrase("Before Image Not Available")); |
||||
|
} |
||||
|
|
||||
|
// AFTER IMAGE |
||||
|
PdfPCell afterCell; |
||||
|
|
||||
|
try { |
||||
|
|
||||
|
Image afterImage = Image.getInstance(new URL(afterImageUrl)); |
||||
|
|
||||
|
afterImage.scaleToFit(250, 250); |
||||
|
|
||||
|
afterCell = new PdfPCell(afterImage); |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
|
||||
|
afterCell = new PdfPCell( |
||||
|
new Phrase("After Image Not Available")); |
||||
|
} |
||||
|
|
||||
|
imageTable.addCell(beforeCell); |
||||
|
imageTable.addCell(afterCell); |
||||
|
|
||||
|
document.add(imageTable); |
||||
|
|
||||
|
// Separator |
||||
|
document.add(new Paragraph( |
||||
|
"------------------------------------------------------------")); |
||||
|
|
||||
|
document.newPage(); |
||||
|
} |
||||
|
|
||||
|
document.close(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
package com.gcc.commissionerreview.controller; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
import com.gcc.commissionerreview.service.NewsAPIService; |
||||
|
|
||||
|
@RestController |
||||
|
@RequestMapping("/commissionerreview/api/newsapi") |
||||
|
public class NewsAPIController { |
||||
|
|
||||
|
@Autowired |
||||
|
NewsAPIService newsAPIService; |
||||
|
|
||||
|
@GetMapping("/getNewsFeed") |
||||
|
public List<Map<String, Object>> getNewsFeed() { |
||||
|
return newsAPIService.getNewsFeed(); |
||||
|
} |
||||
|
|
||||
|
// @GetMapping("/getNewsContent") |
||||
|
// public Map<String, Object> getNewsContent() { |
||||
|
// return newsAPIService.getNewsContent(); |
||||
|
// } |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,69 @@ |
|||||
|
package com.gcc.commissionerreview.service; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
import javax.sql.DataSource; |
||||
|
|
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.beans.factory.annotation.Qualifier; |
||||
|
import org.springframework.jdbc.core.JdbcTemplate; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
@Service |
||||
|
public class NewsAPIService { |
||||
|
|
||||
|
@Autowired |
||||
|
private JdbcTemplate jdbcTemplate; |
||||
|
|
||||
|
@Autowired |
||||
|
public void setDataSource(@Qualifier("mysqlNewsFeedDataSource") DataSource dataSource) { |
||||
|
this.jdbcTemplate = new JdbcTemplate(dataSource); |
||||
|
} |
||||
|
|
||||
|
public List<Map<String, Object>> getNewsFeed() { |
||||
|
String sql = "SELECT REGEXP_REPLACE(REGEXP_REPLACE(news_content, '<[^>]+>', ''),'[\r\n]+',' ') AS Content " |
||||
|
+ "FROM tbl_news ORDER BY news_id DESC LIMIT 15"; |
||||
|
return jdbcTemplate.queryForList(sql); |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* public Map<String, Object> getNewsContent() { |
||||
|
* |
||||
|
* String sql = "SELECT news_title, news_type FROM tbl_news " |
||||
|
* + "WHERE news_type = 1 ORDER BY news_id DESC LIMIT 10"; |
||||
|
* |
||||
|
* List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql); |
||||
|
* |
||||
|
* List<Map<String, Object>> unicodeList = new ArrayList<>(); |
||||
|
* |
||||
|
* for (Map<String, Object> row : rows) { |
||||
|
* String content = row.get("news_title") != null ? |
||||
|
* row.get("news_title").toString() : ""; |
||||
|
* if (!content.isEmpty()) { |
||||
|
* |
||||
|
* content = content.replaceAll( |
||||
|
* "<p class=MsoNormal><b style='mso-bidi-font-weight:normal'>" |
||||
|
* + "<span style='font-size:7.5pt;font-family:Latha'>", |
||||
|
* ""); |
||||
|
* content = content.replaceAll("</span></b></p>", ""); |
||||
|
* content = content.replaceAll("\n", ""); |
||||
|
* content = content.replaceAll("\r", ""); |
||||
|
* content = content.replaceAll("\r\n", ""); |
||||
|
* |
||||
|
* content = content.replaceAll("<[^>]+>", "").trim(); |
||||
|
* |
||||
|
* Map<String, Object> entry = new HashMap<>(); |
||||
|
* entry.put("Content", content); |
||||
|
* unicodeList.add(entry); |
||||
|
* } |
||||
|
* } |
||||
|
* |
||||
|
* Map<String, Object> result = new HashMap<>(); |
||||
|
* result.put("Unicode", unicodeList); |
||||
|
* return result; |
||||
|
* } |
||||
|
*/ |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue