Browse Source
implemented goggle review on schedular and changes in dashboard for number hiding
master
implemented goggle review on schedular and changes in dashboard for number hiding
master
6 changed files with 346 additions and 16 deletions
-
4src/main/java/com/gcc/coworkspace/configuration/DataSourceConfig.java
-
156src/main/java/com/gcc/coworkspace/configuration/ReviewScheduler.java
-
4src/main/java/com/gcc/coworkspace/constants/AppConstants.java
-
175src/main/java/com/gcc/coworkspace/service/GoogleReviewService.java
-
15src/main/resources/templates/caretaker/officer-dashboard.html
-
2src/main/resources/templates/user/razor-pay.html
@ -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<String, Object> response = restTemplate.getForObject(url, Map.class); |
||||
|
|
||||
|
Map<String, Object> result = (Map<String, Object>) response.get("result"); |
||||
|
|
||||
|
if (result != null) { |
||||
|
|
||||
|
List<Map<String, Object>> reviews = (List<Map<String, Object>>) 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<String, Object> 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; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue