From 4041b0f5feb5ee127cce13075f3eea47a1006bd1 Mon Sep 17 00:00:00 2001 From: AJITHKUMAR12 <48044092+AJITHKUMAR12@users.noreply.github.com> Date: Sat, 8 Aug 2026 10:39:35 +0530 Subject: [PATCH] implemented goggle review on schedular and changes in dashboard for number hiding --- .../configuration/DataSourceConfig.java | 10 +- .../configuration/ReviewScheduler.java | 156 ++++++++++++++++ .../coworkspace/constants/AppConstants.java | 4 +- .../service/GoogleReviewService.java | 175 +++++++++++++++++- .../caretaker/officer-dashboard.html | 15 +- .../resources/templates/user/razor-pay.html | 2 +- 6 files changed, 346 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/gcc/coworkspace/configuration/ReviewScheduler.java diff --git a/src/main/java/com/gcc/coworkspace/configuration/DataSourceConfig.java b/src/main/java/com/gcc/coworkspace/configuration/DataSourceConfig.java index a9b025d..c066cb2 100644 --- a/src/main/java/com/gcc/coworkspace/configuration/DataSourceConfig.java +++ b/src/main/java/com/gcc/coworkspace/configuration/DataSourceConfig.java @@ -25,12 +25,13 @@ public class DataSourceConfig { // pass - Bonton#2K24 // DB:- coworkspace - // private static String host = "13.232.20.48"; - // private static String dbpassword = "Bonton#2K24"; + // private static String host = "13.232.20.48"; + // private static String dbpassword = "Bonton#2K24"; // AWS - // private static String host = "gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306"; - // private static String dbpassword = "gcc-facial-password"; + // private static String host = + // "gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306"; + // private static String dbpassword = "gcc-facial-password"; private static String host = "localhost:3306"; private static String dbpassword = "root"; @@ -52,6 +53,7 @@ public class DataSourceConfig { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://" + host + "/coworkingspace"); + // dataSource.setUrl("jdbc:mysql://" + host + "/coworkingspace_latest"); dataSource.setUsername("root"); dataSource.setPassword(dbpassword); return dataSource; diff --git a/src/main/java/com/gcc/coworkspace/configuration/ReviewScheduler.java b/src/main/java/com/gcc/coworkspace/configuration/ReviewScheduler.java new file mode 100644 index 0000000..0c1228f --- /dev/null +++ b/src/main/java/com/gcc/coworkspace/configuration/ReviewScheduler.java @@ -0,0 +1,156 @@ +package com.gcc.coworkspace.configuration; + +import com.gcc.coworkspace.constants.AppConstants; +import com.gcc.coworkspace.service.BookingService; +import com.gcc.coworkspace.service.PaymentService; +import com.gcc.coworkspace.service.RefundService; +import com.razorpay.Order; +import com.razorpay.Payment; +import com.razorpay.RazorpayClient; +import com.razorpay.RazorpayException; +import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Lazy; +import org.springframework.dao.DataAccessException; +import org.springframework.dao.EmptyResultDataAccessException; +import org.springframework.http.ResponseEntity; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; +import org.springframework.web.util.UriComponentsBuilder; + +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.*; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; + +@Component +@EnableScheduling +public class ReviewScheduler { + @Value("${google.api.key}") + private String apiKey; + + @Value("${google.place.id}") + private String placeId; + + @Autowired + public JdbcTemplate jdbcTemplate; + + private final String GOOGLE_PLACE_URL = "https://maps.googleapis.com/maps/api/place/details/json"; + + @Scheduled(cron = "0 0 1 * * *", zone = "Asia/Kolkata") // runs every 30 + // seconds (adjust as needed) + + public void syncGoogleReviews() { + RestTemplate restTemplate = new RestTemplate(); + + String url = UriComponentsBuilder.fromHttpUrl(GOOGLE_PLACE_URL) + .queryParam("place_id", placeId) + + .queryParam("fields", "name,rating,reviews") + .queryParam("key", apiKey) + .toUriString(); + + // return restTemplate.getForObject(url, Map.class); + Map response = restTemplate.getForObject(url, Map.class); + + Map result = (Map) response.get("result"); + + if (result != null) { + + List> reviews = (List>) result.get("reviews"); + + if (reviews != null) { + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); + DateTimeFormatter logFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss"); + + for (Map review : reviews) { + + Long timestamp = ((Number) review.get("time")).longValue(); + + /* + * String reviewDate = Instant.ofEpochSecond(timestamp) + * .atZone(ZoneId.systemDefault()) + * .format(formatter); + * + * review.put("review_date", reviewDate); + */ + + LocalDate localDate = Instant.ofEpochSecond(timestamp) + .atZone(ZoneId.systemDefault()) + .toLocalDate(); + + review.put("review_date", localDate.toString()); // API response: 2026-07-12 + + java.sql.Date sqlDate = java.sql.Date.valueOf(localDate); + + // Check whether review already exists + String checkSql = "SELECT COUNT(*) FROM review WHERE author_name=? AND time=?"; + + Integer count = jdbcTemplate.queryForObject( + checkSql, + Integer.class, + review.get("author_name"), + review.get("time")); + + if (count == null || count == 0) { + + String insertSql = """ + INSERT INTO review + (author_name, + author_url, + language, + original_language, + profile_photo_url, + rating, + relative_time_description, + text, + time, + review_date) + VALUES (?,?,?,?,?,?,?,?,?,?) + """; + + jdbcTemplate.update( + insertSql, + review.get("author_name"), + review.get("author_url"), + review.get("language"), + review.get("original_language"), + review.get("profile_photo_url"), + review.get("rating"), + review.get("relative_time_description"), + review.get("text"), + review.get("time"), + sqlDate); + System.out.println( + "[" + LocalDateTime.now().format(logFormatter) + "] " + + "Inserted Review : " + review.get("author_name")); + + // System.out.println("Inserted Review : " + review.get("author_name")); + + } else { + System.out.println( + "[" + LocalDateTime.now().format(logFormatter) + "] " + + "Review already exists. Skipping : " + review.get("author_name")); + + // System.out.println("Review already exists. Skipping : " + + // review.get("author_name")); + + } + } + } + } + + // return response; + + } + +} diff --git a/src/main/java/com/gcc/coworkspace/constants/AppConstants.java b/src/main/java/com/gcc/coworkspace/constants/AppConstants.java index 8a9d5fb..b503b83 100644 --- a/src/main/java/com/gcc/coworkspace/constants/AppConstants.java +++ b/src/main/java/com/gcc/coworkspace/constants/AppConstants.java @@ -1,8 +1,8 @@ package com.gcc.coworkspace.constants; public final class AppConstants { - // public static String key_id="rzp_live_ySI5Ns54Y7qOcJ"; - // public static String key_secret="Nwf1TjhUtaskof8vePkRR8Sb"; + // public static String key_id = "rzp_live_ySI5Ns54Y7qOcJ"; + // public static String key_secret = "Nwf1TjhUtaskof8vePkRR8Sb"; // uncomment for testing payment public static String key_id = "rzp_test_tDkHFEqWXmuEi8"; diff --git a/src/main/java/com/gcc/coworkspace/service/GoogleReviewService.java b/src/main/java/com/gcc/coworkspace/service/GoogleReviewService.java index 7c3149a..f90fd95 100644 --- a/src/main/java/com/gcc/coworkspace/service/GoogleReviewService.java +++ b/src/main/java/com/gcc/coworkspace/service/GoogleReviewService.java @@ -7,6 +7,12 @@ import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.HashMap; +import java.util.List; import java.util.Map; @Service @@ -23,21 +29,174 @@ public class GoogleReviewService { private final String GOOGLE_PLACE_URL = "https://maps.googleapis.com/maps/api/place/details/json"; + /* + * public Map getGoogleReviews() { + * RestTemplate restTemplate = new RestTemplate(); + * + * String url = UriComponentsBuilder.fromHttpUrl(GOOGLE_PLACE_URL) + * .queryParam("place_id", placeId) + * + * .queryParam("fields", "name,rating,reviews") + * .queryParam("key", apiKey) + * .toUriString(); + * + * // return restTemplate.getForObject(url, Map.class); + * Map response = restTemplate.getForObject(url, Map.class); + * + * Map result = (Map) response.get("result"); + * + * if (result != null) { + * + * List> reviews = (List>) + * result.get("reviews"); + * + * if (reviews != null) { + * + * DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); + * + * for (Map review : reviews) { + * + * Long timestamp = ((Number) review.get("time")).longValue(); + * + * + * + * LocalDate localDate = Instant.ofEpochSecond(timestamp) + * .atZone(ZoneId.systemDefault()) + * .toLocalDate(); + * + * review.put("review_date", localDate.toString()); // API response: 2026-07-12 + * + * java.sql.Date sqlDate = java.sql.Date.valueOf(localDate); + * + * // Check whether review already exists + * String checkSql = + * "SELECT COUNT(*) FROM review WHERE author_name=? AND time=?"; + * + * Integer count = jdbcTemplate.queryForObject( + * checkSql, + * Integer.class, + * review.get("author_name"), + * review.get("time")); + * + * if (count == null || count == 0) { + * + * String insertSql = """ + * INSERT INTO review + * (author_name, + * author_url, + * language, + * original_language, + * profile_photo_url, + * rating, + * relative_time_description, + * text, + * time, + * review_date) + * VALUES (?,?,?,?,?,?,?,?,?,?) + * """; + * + * jdbcTemplate.update( + * insertSql, + * review.get("author_name"), + * review.get("author_url"), + * review.get("language"), + * review.get("original_language"), + * review.get("profile_photo_url"), + * review.get("rating"), + * review.get("relative_time_description"), + * review.get("text"), + * review.get("time"), + * sqlDate); + * + * // System.out.println("Inserted Review : " + review.get("author_name")); + * + * } else { + * + * // System.out.println("Review already exists. Skipping : " + + * // review.get("author_name")); + * + * } + * } + * } + * } + * + * // return response; + * Map dbResponse = new HashMap<>(); + * Map resultMap = new HashMap<>(); + * + * String reviewSql = """ + * SELECT + * author_name, + * profile_photo_url, + * rating, + * text, + * relative_time_description + * FROM review + * ORDER BY id + * + * """; + * + * List> reviewList = jdbcTemplate.queryForList(reviewSql); + * + * Double avgRating = jdbcTemplate.queryForObject( + * "SELECT ROUND(AVG(rating),1) FROM review", + * Double.class); + * + * resultMap.put("rating", avgRating == null ? 0 : avgRating); + * resultMap.put("reviews", reviewList); + * + * dbResponse.put("result", resultMap); + * + * return dbResponse; + * + * } + */ public Map getGoogleReviews() { - RestTemplate restTemplate = new RestTemplate(); - String url = UriComponentsBuilder.fromHttpUrl(GOOGLE_PLACE_URL) - .queryParam("place_id", placeId) - .queryParam("fields", "name,rating,reviews") - .queryParam("key", apiKey) - .toUriString(); + Map dbResponse = new HashMap<>(); + Map resultMap = new HashMap<>(); - return restTemplate.getForObject(url, Map.class); - } + String reviewSql = """ + SELECT + author_name, + profile_photo_url, + rating, + text, + relative_time_description + FROM review + + ORDER BY id desc + limit 5 + + + """; + + List> reviewList = jdbcTemplate.queryForList(reviewSql); + + Double avgRating = jdbcTemplate.queryForObject( + "SELECT ROUND(AVG(rating),1) FROM review", + Double.class); + + resultMap.put("rating", avgRating == null ? 0 : avgRating); + resultMap.put("reviews", reviewList); + dbResponse.put("result", resultMap); + + return dbResponse; + } public Map getmarquee() { String sql = "SELECT * FROM marquee where is_active = 1"; return jdbcTemplate.queryForMap(sql); } + + public String getCronExpression() { + + String sql = "SELECT cron_expression FROM scheduler_config WHERE job_name=?"; + + return jdbcTemplate.queryForObject( + sql, + String.class, + "GOOGLE_REVIEW_SYNC"); + } } diff --git a/src/main/resources/templates/caretaker/officer-dashboard.html b/src/main/resources/templates/caretaker/officer-dashboard.html index c5f773f..6190849 100644 --- a/src/main/resources/templates/caretaker/officer-dashboard.html +++ b/src/main/resources/templates/caretaker/officer-dashboard.html @@ -703,15 +703,19 @@ position: "bottom", align: "start", labels: { + boxWidth: 10, + boxHeight: 10, + padding: 8, generateLabels: function (chart) { const dataset = chart.data.datasets[0]; return chart.data.labels.map((label, i) => ({ text: `${label}: ${dataset.data[i]}`, fillStyle: dataset.backgroundColor[i], + })); }, font: { - size: 12 + size: 10 } }, }, @@ -744,6 +748,9 @@ position: "bottom", align: "start", labels: { + boxWidth: 10, + boxHeight: 10, + padding: 8, generateLabels: function (chart) { const dataset = chart.data.datasets[0]; return chart.data.labels.map((label, i) => ({ @@ -797,6 +804,9 @@ position: "bottom", align: "start", labels: { + boxWidth: 10, + boxHeight: 10, + padding: 8, generateLabels: function (chart) { const dataset = chart.data.datasets[0]; return chart.data.labels.map((label, i) => ({ @@ -840,6 +850,9 @@ position: "bottom", align: "start", labels: { + boxWidth: 10, + boxHeight: 10, + padding: 8, generateLabels: function (chart) { const dataset = chart.data.datasets[0]; return chart.data.labels.map((label, i) => ({ diff --git a/src/main/resources/templates/user/razor-pay.html b/src/main/resources/templates/user/razor-pay.html index 4a78233..eb8e8d3 100644 --- a/src/main/resources/templates/user/razor-pay.html +++ b/src/main/resources/templates/user/razor-pay.html @@ -31,7 +31,7 @@ console.log(response); if (response.status == "created") { let options = { - // "key": "[[${keyId}]]", + //"key": "[[${keyId}]]", "key": "rzp_test_tDkHFEqWXmuEi8", // Enter the Key ID generated from the Dashboard "amount": response.amount, // Amount is in currency subunits. Default currency is INR. Hence, 50000 refers to 50000 paise "currency": "INR",