Browse Source

added permanent request messages

master
yoganandhan 8 months ago
parent
commit
5e5b5f1f58
  1. 87
      src/main/java/com/gcc/flagpoles/controller/ApiController.java
  2. 78
      src/main/java/com/gcc/flagpoles/service/RequestService.java
  3. 495
      src/main/java/com/gcc/flagpoles/service/SMSService.java

87
src/main/java/com/gcc/flagpoles/controller/ApiController.java

@ -45,15 +45,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.gcc.flagpoles.service.RequestService; import com.gcc.flagpoles.service.RequestService;
import com.gcc.flagpoles.service.SMSService; import com.gcc.flagpoles.service.SMSService;
// import com.dumpregistration.configuration.AppConfig;
// import com.dumpregistration.constants.AppConstants;
// import com.dumpregistration.service.PaymentService;
// import com.dumpregistration.service.RequestService;
// import com.fasterxml.jackson.databind.ObjectMapper;
// import com.razorpay.Order;
// import com.razorpay.RazorpayClient;
// import com.razorpay.RazorpayException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.HttpSession;
@ -101,20 +92,6 @@ public class ApiController {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy%20HH:mm"); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy%20HH:mm");
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
System.out.println(dtf.format(now)); System.out.println(dtf.format(now));
// String generatedToken = "Welcome to GCC! Your OTP for C%26D waste collectors
// Registration process is "+otp;
// String generatedToken = "Welcome to GCC "+otp+" is your OTP for gcc QR
// System";
// String generatedToken = "Welcome to GCC! Your OTP for C and D waste
// collectors Registration process is " + otp;
// // String key="qxg4mklD";
// String key = "pfTEYN6H";
// String urlString = appConfig.getGetOtpUrl() + "from=GCCCRP&key=" + key +
// "&sender=GCCCRP&to=" + MobileNo
// + "&body=" + generatedToken +
// "&entityid=1401572690000011081&templateid=1407172967243483268";
String key = "pfTEYN6H"; String key = "pfTEYN6H";
String entityId = "1401572690000011081"; String entityId = "1401572690000011081";
@ -126,12 +103,6 @@ public class ApiController {
+ MobileNo + "&body=" + MobileNo + "&body="
+ generatedMessage + "&entityid=" + entityId + "&templateid=" + templateId; + generatedMessage + "&entityid=" + entityId + "&templateid=" + templateId;
// String urlString =
// "https://tmegov.onex-aura.com/api/sms?from=GCCCRP&key=pfTEYN6H&sender=GCCCRP&to=9360777472&body=Welcome%20to%20GCC!%20Your%20OTP%20for%20C%26D%20waste%20collectors%20Registration%20process%20is%20"+otp+"&entityid=1401572690000011081&templateid=1407172959127552127";
// String urlString=
// appConfig.getGetOtpUrl()+"from=GCCCRP&key="+key+"&sender=GCCCRP&to="+MobileNo+"&body="+generatedToken+"&entityid=1401572690000011081&templateid=1407168250479102852";
// String
// urlString=appConfig.getGetOtpUrl()+"user=GCCtrans&authkey=92kOC1RBGBIws&sender=GCCCRP&mobile="+MobileNo+"&text="+generatedToken+"&rpt=1&summary=1&output=json&entityid=1401572690000011081&templateid=1407168250479102852";
System.out.print("\n urlString---: " + urlString); System.out.print("\n urlString---: " + urlString);
String bodyMessage = ""; String bodyMessage = "";
try { try {
@ -160,27 +131,9 @@ public class ApiController {
// Create an ObjectMapper instance // Create an ObjectMapper instance
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
// Check if mobile number is already registered
// List<WasteRegistration> registrations =
// wasteregistrationrepo.findByMobileNo(mobile);
// Create a response map // Create a response map
Map<String, Object> response = new HashMap<>(); Map<String, Object> response = new HashMap<>();
// if (registrations.isEmpty()) {
// // If mobile number is not registered
// response.put("status", "NOT_REGISTERED");
// response.put("mobile", mobile); // Return the mobile number
// try {
// return objectMapper.writeValueAsString(response); // Use the instance to
// convert map to JSON string
// } catch (Exception e) {
// // Handle JSON conversion error
// return "{\"status\": \"ERROR\", \"message\": \"Could not convert response to
// JSON.\"}";
// }
// }
String MobileNo = mobile; String MobileNo = mobile;
System.out.print("\n MobileNo---:" + mobile); System.out.print("\n MobileNo---:" + mobile);
Random rand = new Random(); Random rand = new Random();
@ -191,20 +144,6 @@ public class ApiController {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy%20HH:mm"); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy%20HH:mm");
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
System.out.println(dtf.format(now)); System.out.println(dtf.format(now));
// String generatedToken = "Welcome to GCC! Your OTP for C%26D waste collectors
// Registration process is "+otp;
// String generatedToken = "Welcome to GCC "+otp+" is your OTP for gcc QR
// System";
// String generatedToken = "Welcome to GCC! Your OTP for C and D waste
// collectors Registration process is " + otp;
// // String key="qxg4mklD";
// String key = "pfTEYN6H";
// String urlString = appConfig.getGetOtpUrl() + "from=GCCCRP&key=" + key +
// "&sender=GCCCRP&to=" + MobileNo
// + "&body=" + generatedToken +
// "&entityid=1401572690000011081&templateid=1407172967243483268";
String key = "pfTEYN6H"; String key = "pfTEYN6H";
String entityId = "1401572690000011081"; String entityId = "1401572690000011081";
@ -216,12 +155,6 @@ public class ApiController {
+ MobileNo + "&body=" + MobileNo + "&body="
+ generatedMessage + "&entityid=" + entityId + "&templateid=" + templateId; + generatedMessage + "&entityid=" + entityId + "&templateid=" + templateId;
// String urlString =
// "https://tmegov.onex-aura.com/api/sms?from=GCCCRP&key=pfTEYN6H&sender=GCCCRP&to=9360777472&body=Welcome%20to%20GCC!%20Your%20OTP%20for%20C%26D%20waste%20collectors%20Registration%20process%20is%20"+otp+"&entityid=1401572690000011081&templateid=1407172959127552127";
// String urlString=
// appConfig.getGetOtpUrl()+"from=GCCCRP&key="+key+"&sender=GCCCRP&to="+MobileNo+"&body="+generatedToken+"&entityid=1401572690000011081&templateid=1407168250479102852";
// String
// urlString=appConfig.getGetOtpUrl()+"user=GCCtrans&authkey=92kOC1RBGBIws&sender=GCCCRP&mobile="+MobileNo+"&text="+generatedToken+"&rpt=1&summary=1&output=json&entityid=1401572690000011081&templateid=1407168250479102852";
System.out.print("\n urlString---: " + urlString); System.out.print("\n urlString---: " + urlString);
String bodyMessage = ""; String bodyMessage = "";
try { try {
@ -695,7 +628,7 @@ public class ApiController {
// String tempRefId = data.get("id").toString(); // String tempRefId = data.get("id").toString();
// String amount = data.get("amt").toString(); // String amount = data.get("amt").toString();
// // 🔹 Get temp details
// // Get temp details
// Map<String, Object> details = // Map<String, Object> details =
// requestService.getDetailsByRequestIdTemp(tempRefId).get(0); // requestService.getDetailsByRequestIdTemp(tempRefId).get(0);
@ -703,22 +636,22 @@ public class ApiController {
// boolean bookingPaid = "PAID".equalsIgnoreCase(bookingStatus) // boolean bookingPaid = "PAID".equalsIgnoreCase(bookingStatus)
// || "COMPLETED".equalsIgnoreCase(bookingStatus); // || "COMPLETED".equalsIgnoreCase(bookingStatus);
// /* 🔴 BOOKING PAYMENT */
// /* BOOKING PAYMENT */
// if (!bookingPaid) { // if (!bookingPaid) {
// // 1️⃣ Update TEMP payment status
// // 1Update TEMP payment status
// requestService.updateTempPaymentStatus(tempRefId, "COMPLETED"); // requestService.updateTempPaymentStatus(tempRefId, "COMPLETED");
// // 2️⃣ Move TEMP → FINAL and get finalRefId
// // 2Move TEMP → FINAL and get finalRefId
// String finalRefId = requestService.moveTempToFinal(tempRefId); // String finalRefId = requestService.moveTempToFinal(tempRefId);
// // 3️⃣ NOW save payment with FINAL refId ✅
// // 3NOW save payment with FINAL refId
// paymentService.savePayment( // paymentService.savePayment(
// amount, // amount,
// data.get("payment_id").toString(), // data.get("payment_id").toString(),
// data.get("order_id").toString(), // data.get("order_id").toString(),
// data.get("status").toString(), // data.get("status").toString(),
// finalRefId, // ✅ IMPORTANT
// finalRefId,
// data.get("mobile_no").toString()); // data.get("mobile_no").toString());
// return ResponseEntity.ok(Map.of( // return ResponseEntity.ok(Map.of(
@ -760,7 +693,7 @@ public class ApiController {
data.get("status").toString(), data.get("status").toString(),
finalRefId, finalRefId,
data.get("mobile_no").toString(), data.get("mobile_no").toString(),
"BOOKING" // ✅
"BOOKING" //
); );
return ResponseEntity.ok(Map.of( return ResponseEntity.ok(Map.of(
@ -781,7 +714,7 @@ public class ApiController {
data.get("status").toString(), data.get("status").toString(),
refId, refId,
data.get("mobile_no").toString(), data.get("mobile_no").toString(),
"FINE" // ✅
"FINE" //
); );
return ResponseEntity.ok(Map.of( return ResponseEntity.ok(Map.of(
@ -814,7 +747,7 @@ public class ApiController {
throw new IllegalStateException("No pending payment"); throw new IllegalStateException("No pending payment");
} }
// 🔴 CANCEL EVENT
// CANCEL EVENT
@PostMapping("/cancelEvent") @PostMapping("/cancelEvent")
public ResponseEntity<Map<String, String>> cancelEvent( public ResponseEntity<Map<String, String>> cancelEvent(
@RequestParam String refId) { @RequestParam String refId) {
@ -824,7 +757,7 @@ public class ApiController {
return ResponseEntity.ok(Map.of("status", result)); return ResponseEntity.ok(Map.of("status", result));
} }
// 🟡 POSTPONE EVENT
// POSTPONE EVENT
@PostMapping("/postponeEvent") @PostMapping("/postponeEvent")
public ResponseEntity<Map<String, String>> postponeEvent( public ResponseEntity<Map<String, String>> postponeEvent(
@RequestParam String refId, @RequestParam String refId,

78
src/main/java/com/gcc/flagpoles/service/RequestService.java

@ -100,15 +100,11 @@ public class RequestService {
// Get generated primary key // Get generated primary key
int userReqId = keyHolder.getKey().intValue(); int userReqId = keyHolder.getKey().intValue();
// ================================================
// 🔥 Generate REF ID = yyyyMMdd + userReqId
// ================================================
// Generate REF ID = yyyyMMdd + userReqId
String prefix = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); String prefix = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
String refId = prefix + userReqId; String refId = prefix + userReqId;
// ================================================
// 🔥 Update user_request_details with refId
// ================================================
// Update user_request_details with refId
String updateRefSql = "UPDATE user_request_details SET refid = ? WHERE id = ?"; String updateRefSql = "UPDATE user_request_details SET refid = ? WHERE id = ?";
mysqlJdbcTemplate.update(updateRefSql, refId, userReqId); mysqlJdbcTemplate.update(updateRefSql, refId, userReqId);
@ -137,7 +133,7 @@ public class RequestService {
s.get("durationDays"), s.get("durationDays"),
s.get("ratePerPole"), s.get("ratePerPole"),
userReqId, userReqId,
refId // 🔥 Insert same REF ID into street_details
refId // Insert same REF ID into street_details
); );
} }
@ -151,7 +147,7 @@ public class RequestService {
List<Map<String, Object>> streets, List<Map<String, Object>> streets,
MultiValueMap<String, String> params) { MultiValueMap<String, String> params) {
// 1️⃣ Insert TEMP booking (without refid)
// Insert TEMP booking (without refid)
KeyHolder keyHolder = new GeneratedKeyHolder(); KeyHolder keyHolder = new GeneratedKeyHolder();
mysqlJdbcTemplate.update(con -> { mysqlJdbcTemplate.update(con -> {
@ -767,7 +763,7 @@ public class RequestService {
List<Map<String, Object>> list = mysqlJdbcTemplate.queryForList(sql, refId, type); List<Map<String, Object>> list = mysqlJdbcTemplate.queryForList(sql, refId, type);
// ✅ Return null safely instead of throwing exception
// Return null safely instead of throwing exception
return list.isEmpty() ? null : list.get(0); return list.isEmpty() ? null : list.get(0);
} }
@ -1046,7 +1042,7 @@ public class RequestService {
// urd.refid, // urd.refid,
// urd.payment_status, // urd.payment_status,
// urd.booking_status, // urd.booking_status,
// urd.cdate, -- ✅ ADD THIS
// urd.cdate,
// sd.street_name, // sd.street_name,
// sd.zone, // sd.zone,
// sd.ward, // sd.ward,
@ -1076,13 +1072,13 @@ public class RequestService {
// params.add(mobileNumber); // params.add(mobileNumber);
// } // }
// // ✅ LATEST RECORDS FIRST
// // LATEST RECORDS FIRST
// sql.append(" ORDER BY urd.cdate DESC, sd.id "); // sql.append(" ORDER BY urd.cdate DESC, sd.id ");
// List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql.toString(), // List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql.toString(),
// params.toArray()); // params.toArray());
// // 🔥 GROUP BY REFID (NO CHANGE)
// // GROUP BY REFID (NO CHANGE)
// Map<String, Map<String, Object>> resultMap = new LinkedHashMap<>(); // Map<String, Map<String, Object>> resultMap = new LinkedHashMap<>();
// for (Map<String, Object> row : rows) { // for (Map<String, Object> row : rows) {
@ -1102,9 +1098,9 @@ public class RequestService {
// map.put("no_of_days", row.get("no_of_days")); // map.put("no_of_days", row.get("no_of_days"));
// map.put("event_name", row.get("event_name")); // map.put("event_name", row.get("event_name"));
// map.put("total_cost", row.get("total_cost")); // map.put("total_cost", row.get("total_cost"));
// map.put("payment_status", row.get("payment_status")); // ✅
// map.put("booking_status", row.get("booking_status")); // ✅
// map.put("cdate", row.get("cdate")); // ✅
// map.put("payment_status", row.get("payment_status")); //
// map.put("booking_status", row.get("booking_status")); //
// map.put("cdate", row.get("cdate")); //
// map.put("streets", new ArrayList<>()); // map.put("streets", new ArrayList<>());
// return map; // return map;
// }); // });
@ -1183,7 +1179,7 @@ public class RequestService {
// List<Object> params = new ArrayList<>(); // List<Object> params = new ArrayList<>();
// // 🔹 Search priority: RefId first, else Mobile
// // Search priority: RefId first, else Mobile
// if (refId != null && !refId.trim().isEmpty()) { // if (refId != null && !refId.trim().isEmpty()) {
// sql.append(" AND urd.refid = ? "); // sql.append(" AND urd.refid = ? ");
// params.add(refId.trim()); // params.add(refId.trim());
@ -1198,7 +1194,7 @@ public class RequestService {
// List<Map<String, Object>> rows = // List<Map<String, Object>> rows =
// mysqlJdbcTemplate.queryForList(sql.toString(), params.toArray()); // mysqlJdbcTemplate.queryForList(sql.toString(), params.toArray());
// // 🔥 GROUP BY REFID
// // GROUP BY REFID
// Map<String, Map<String, Object>> resultMap = new LinkedHashMap<>(); // Map<String, Map<String, Object>> resultMap = new LinkedHashMap<>();
// for (Map<String, Object> row : rows) { // for (Map<String, Object> row : rows) {
@ -1339,7 +1335,7 @@ public class RequestService {
List<Object> params = new ArrayList<>(); List<Object> params = new ArrayList<>();
// 🔹 Search priority: RefId first, else Mobile
// Search priority: RefId first, else Mobile
if (refId != null && !refId.trim().isEmpty()) { if (refId != null && !refId.trim().isEmpty()) {
sql.append(" AND urd.refid = ? "); sql.append(" AND urd.refid = ? ");
params.add(refId.trim()); params.add(refId.trim());
@ -1353,7 +1349,7 @@ public class RequestService {
List<Map<String, Object>> rows = mysqlJdbcTemplate.queryForList(sql.toString(), params.toArray()); List<Map<String, Object>> rows = mysqlJdbcTemplate.queryForList(sql.toString(), params.toArray());
// 🔥 GROUP BY REFID
// GROUP BY REFID
Map<String, Map<String, Object>> resultMap = new LinkedHashMap<>(); Map<String, Map<String, Object>> resultMap = new LinkedHashMap<>();
for (Map<String, Object> row : rows) { for (Map<String, Object> row : rows) {
@ -1369,10 +1365,10 @@ public class RequestService {
map.put("event_date", row.get("event_date")); map.put("event_date", row.get("event_date"));
map.put("ae_status", row.get("ae_status")); map.put("ae_status", row.get("ae_status"));
map.put("rdo_status", row.get("rdo_status")); map.put("rdo_status", row.get("rdo_status"));
map.put("final_status", row.get("final_status")); // ✅ NEW
map.put("final_remarks", row.get("final_remarks")); // ✅ NEW
map.put("final_approved_by", row.get("final_approved_by")); // ✅ OPTIONAL
map.put("final_approved_date", row.get("final_approved_date")); // ✅ OPTIONAL
map.put("final_status", row.get("final_status")); //
map.put("final_remarks", row.get("final_remarks")); //
map.put("final_approved_by", row.get("final_approved_by"));
map.put("final_approved_date", row.get("final_approved_date"));
map.put("rdo_remarks", row.get("rdo_remarks")); map.put("rdo_remarks", row.get("rdo_remarks"));
map.put("approved_by", row.get("approved_by")); map.put("approved_by", row.get("approved_by"));
map.put("approved_date", row.get("approved_date")); map.put("approved_date", row.get("approved_date"));
@ -1382,11 +1378,11 @@ public class RequestService {
map.put("payment_status", row.get("payment_status")); map.put("payment_status", row.get("payment_status"));
map.put("booking_status", row.get("booking_status")); map.put("booking_status", row.get("booking_status"));
map.put("application_type", row.get("application_type")); map.put("application_type", row.get("application_type"));
map.put("application_type_name", row.get("application_type_name")); // ✅ NEW
map.put("application_type_name", row.get("application_type_name"));
map.put("application_option", row.get("application_option")); map.put("application_option", row.get("application_option"));
map.put("application_option_name", row.get("application_option_name")); // ✅ NEW
map.put("application_option_name", row.get("application_option_name"));
map.put("installation_type", row.get("installation_type")); map.put("installation_type", row.get("installation_type"));
map.put("installation_name", row.get("installation_name")); // ✅ NEW
map.put("installation_name", row.get("installation_name"));
map.put("aadhaar_no", row.get("aadhaar_no")); map.put("aadhaar_no", row.get("aadhaar_no"));
map.put("survey_no", row.get("survey_no")); map.put("survey_no", row.get("survey_no"));
map.put("place_of_erection", row.get("place_of_erection")); map.put("place_of_erection", row.get("place_of_erection"));
@ -1402,10 +1398,10 @@ public class RequestService {
street.put("ward", row.get("ward")); street.put("ward", row.get("ward"));
street.put("no_of_poles", row.get("no_of_poles")); street.put("no_of_poles", row.get("no_of_poles"));
street.put("street_cost", row.get("street_cost")); street.put("street_cost", row.get("street_cost"));
street.put("pole_material_name", row.get("pole_material_name")); // ✅ NEW
street.put("flag_material_name", row.get("flag_material_name")); // ✅ NEW
street.put("statue_material_type", row.get("statue_material_type")); // ✅ NEW
street.put("statue_pedestal_type", row.get("statue_pedestal_type")); // ✅ NEW
street.put("pole_material_name", row.get("pole_material_name"));
street.put("flag_material_name", row.get("flag_material_name"));
street.put("statue_material_type", row.get("statue_material_type"));
street.put("statue_pedestal_type", row.get("statue_pedestal_type"));
((List<Map<String, Object>>) request.get("streets")).add(street); ((List<Map<String, Object>>) request.get("streets")).add(street);
} }
@ -1560,14 +1556,14 @@ public class RequestService {
WHERE refid = ? WHERE refid = ?
""", refId); """, refId);
// ✅ CORRECT CAST
// CORRECT CAST
LocalDateTime eventDate = (LocalDateTime) record.get("event_date"); LocalDateTime eventDate = (LocalDateTime) record.get("event_date");
if (LocalDateTime.now().isAfter(eventDate.minusHours(24))) { if (LocalDateTime.now().isAfter(eventDate.minusHours(24))) {
return "NOT_ALLOWED"; return "NOT_ALLOWED";
} }
// 🔥 INSERT HISTORY BEFORE UPDATE
// INSERT HISTORY BEFORE UPDATE
// insertIntoHistory(refId, "CANCELLED"); // insertIntoHistory(refId, "CANCELLED");
insertIntoHistoryAfterAction( insertIntoHistoryAfterAction(
@ -1641,37 +1637,37 @@ public class RequestService {
// WHERE refid = ? // WHERE refid = ?
// """, refId); // """, refId);
// // ✅ CORRECT CAST
// // CORRECT CAST
// LocalDateTime oldEventDate = (LocalDateTime) record.get("event_date"); // LocalDateTime oldEventDate = (LocalDateTime) record.get("event_date");
// int noOfDays = ((Number) record.get("no_of_days")).intValue(); // int noOfDays = ((Number) record.get("no_of_days")).intValue();
// // ⏰ 24-hour rule
// // 24-hour rule
// if (LocalDateTime.now().isAfter(oldEventDate.minusHours(24))) { // if (LocalDateTime.now().isAfter(oldEventDate.minusHours(24))) {
// return "NOT_ALLOWED"; // return "NOT_ALLOWED";
// } // }
// // 📅 calculate full new date range
// // calculate full new date range
// List<LocalDate> newDateRange = getEventDateRange(newStartDate, noOfDays); // List<LocalDate> newDateRange = getEventDateRange(newStartDate, noOfDays);
// // 🚧 get all streets for this request
// // get all streets for this request
// List<String> streets = jdbcTemplate.queryForList(""" // List<String> streets = jdbcTemplate.queryForList("""
// SELECT street_name // SELECT street_name
// FROM street_details // FROM street_details
// WHERE refid = ? // WHERE refid = ?
// """, String.class, refId); // """, String.class, refId);
// // 🚫 check availability
// // check availability
// for (String street : streets) { // for (String street : streets) {
// if (!isStreetAvailableForRange(street, newDateRange, refId)) { // if (!isStreetAvailableForRange(street, newDateRange, refId)) {
// return "STREET_NOT_AVAILABLE"; // return "STREET_NOT_AVAILABLE";
// } // }
// } // }
// // 🔥 INSERT HISTORY BEFORE UPDATE
// // INSERT HISTORY BEFORE UPDATE
// insertIntoHistory(refId, "POSTPONED"); // insertIntoHistory(refId, "POSTPONED");
// // ✅ update event date
// // update event date
// jdbcTemplate.update(""" // jdbcTemplate.update("""
// UPDATE user_request_details // UPDATE user_request_details
// SET event_date = ?, // SET event_date = ?,
@ -1695,7 +1691,7 @@ public class RequestService {
// LocalDateTime oldEventDate = (LocalDateTime) record.get("event_date"); // LocalDateTime oldEventDate = (LocalDateTime) record.get("event_date");
// int noOfDays = ((Number) record.get("no_of_days")).intValue(); // int noOfDays = ((Number) record.get("no_of_days")).intValue();
// // ⏰ 24-hour rule
// // 24-hour rule
// if (LocalDateTime.now().isAfter(oldEventDate.minusHours(24))) { // if (LocalDateTime.now().isAfter(oldEventDate.minusHours(24))) {
// return "NOT_ALLOWED"; // return "NOT_ALLOWED";
// } // }
@ -1714,7 +1710,7 @@ public class RequestService {
// } // }
// } // }
// // 🔥 Save old state into history
// // Save old state into history
// // insertIntoHistory(refId, "POSTPONED"); // // insertIntoHistory(refId, "POSTPONED");
// insertIntoHistoryAfterAction( // insertIntoHistoryAfterAction(
// refId, // refId,

495
src/main/java/com/gcc/flagpoles/service/SMSService.java

@ -17,240 +17,323 @@ import com.gcc.flagpoles.util.MessageUtility;
@Service @Service
public class SMSService { public class SMSService {
@Autowired
private AppConfig appConfig;
@Autowired
private AppConfig appConfig;
@Autowired
private MessageUtility messageUtility;
@Autowired
private MessageUtility messageUtility;
private final String key = "pfTEYN6H";
public String sendBookingSuccesssms(String mobileNo, String requestId) {
private final String key = "pfTEYN6H";
String message = "Your Flag Pole permission request has been submitted successfully. "
+ "Request ID: " + requestId
+ ". You will be notified once the status is updated. By GCC";
public String sendBookingSuccesssms(String mobileNo, String requestId) {
// Encode message and fix colon issue (gateway not decoding %3A)
String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8)
.replace("%3A", ":");
String urlString = appConfig.getGetOtpUrl()
+ "from=GCCCRP"
+ "&key=" + key
+ "&sender=GCCCRP"
+ "&to=" + mobileNo
+ "&body=" + encodedMsg
+ "&entityid=1401572690000011081"
+ "&templateid=1407176959297472163";
System.out.println("SMS URL:- " + urlString);
String response = messageUtility.sendSMS(urlString);
System.out.println("SMS RESPONSE:- " + response);
return response;
}
public String userrequestApprovedsms(String mobileNo, String requestId) {
String message = "Your Flag Pole permission request has been approved. "
+ "Request ID: " + requestId
+ ". Please proceed as per the permitted guidelines. By GCC";
// Encode message and fix colon issue (gateway not decoding %3A)
String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8)
.replace("%3A", ":");
String message = "Your Flag Pole permission request has been submitted successfully. "
+ "Request ID: " + requestId
+ ". You will be notified once the status is updated. By GCC";
String urlString = appConfig.getGetOtpUrl()
+ "from=GCCCRP"
+ "&key=" + key
+ "&sender=GCCCRP"
+ "&to=" + mobileNo
+ "&body=" + encodedMsg
+ "&entityid=1401572690000011081"
+ "&templateid=1407176959297472163";
System.out.println("SMS URL:- " + urlString);
String response = messageUtility.sendSMS(urlString);
System.out.println("SMS RESPONSE:- " + response);
return response;
}
public String fineforunauthorizedflagpoleSms(String mobileNo,
String location,
String fineAmount,
String requestId) {
String message = "An unauthorized flag pole installation was found at " + location + ". "
+ "Fine amount: Rs." + fineAmount
+ " to be paid at https://gccservices.in/flagpolesregistration/paymentform?requestId="
+ requestId
+ " to avoid further action.\n"
+ "By GCC";
// Encode message and fix colon issue (gateway not decoding %3A)
String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8)
.replace("%3A", ":");
String urlString = appConfig.getGetOtpUrl()
+ "from=GCCCRP"
+ "&key=" + key
+ "&sender=GCCCRP"
+ "&to=" + mobileNo
+ "&body=" + encodedMsg
+ "&entityid=1401572690000011081"
+ "&templateid=1407176984622316740"; // <-- replace with correct template id
System.out.println("SMS URL:- " + urlString);
String response = messageUtility.sendSMS(urlString);
System.out.println("SMS RESPONSE:- " + response);
return response;
}
public String restorationflagpoleSms(String mobileNo,
String streetName,
String amount,
String requestId) {
try {
// Encode message and fix colon issue (gateway not decoding %3A)
String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8)
.replace("%3A", ":");
String message = "Your flagpole installation at " + streetName
+ " caused damage to the public property. "
+ "Restoration charges of RS." + amount
+ " to be paid at https://gccservices.in/flagpolesregistration/paymentform?requestId="
+ requestId
+ " to avoid further action.\r\n"
+ "By GCC";
String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8);
String urlString = appConfig.getGetOtpUrl()
+ "from=GCCCRP"
+ "&key=" + key
+ "&sender=GCCCRP"
+ "&to=" + mobileNo
+ "&body=" + encodedMsg
+ "&entityid=1401572690000011081"
+ "&templateid=1407176984612580095";
System.out.println("FINAL SMS URL:- " + urlString);
URL apiUrl = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) apiUrl.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(15000);
conn.setReadTimeout(15000);
BufferedReader in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuilder content = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
conn.disconnect();
System.out.println("DIRECT SMS RESPONSE:- " + content.toString());
return content.toString();
} catch (Exception e) {
e.printStackTrace();
return "FAILED";
String urlString = appConfig.getGetOtpUrl()
+ "from=GCCCRP"
+ "&key=" + key
+ "&sender=GCCCRP"
+ "&to=" + mobileNo
+ "&body=" + encodedMsg
+ "&entityid=1401572690000011081"
+ "&templateid=1407176959297472163";
System.out.println("SMS URL:- " + urlString);
String response = messageUtility.sendSMS(urlString);
System.out.println("SMS RESPONSE:- " + response);
return response;
}
public String userrequestApprovedsms(String mobileNo, String requestId) {
String message = "Your Flag Pole permission request has been approved. "
+ "Request ID: " + requestId
+ ". Please proceed as per the permitted guidelines. By GCC";
// Encode message and fix colon issue (gateway not decoding %3A)
String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8)
.replace("%3A", ":");
String urlString = appConfig.getGetOtpUrl()
+ "from=GCCCRP"
+ "&key=" + key
+ "&sender=GCCCRP"
+ "&to=" + mobileNo
+ "&body=" + encodedMsg
+ "&entityid=1401572690000011081"
+ "&templateid=1407176959297472163";
System.out.println("SMS URL:- " + urlString);
String response = messageUtility.sendSMS(urlString);
System.out.println("SMS RESPONSE:- " + response);
return response;
}
public String fineforunauthorizedflagpoleSms(String mobileNo,
String location,
String fineAmount,
String requestId) {
String message = "An unauthorized flag pole installation was found at " + location + ". "
+ "Fine amount: Rs." + fineAmount
+ " to be paid at https://gccservices.in/flagpolesregistration/paymentform?requestId="
+ requestId
+ " to avoid further action.\n"
+ "By GCC";
// Encode message and fix colon issue (gateway not decoding %3A)
String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8)
.replace("%3A", ":");
String urlString = appConfig.getGetOtpUrl()
+ "from=GCCCRP"
+ "&key=" + key
+ "&sender=GCCCRP"
+ "&to=" + mobileNo
+ "&body=" + encodedMsg
+ "&entityid=1401572690000011081"
+ "&templateid=1407176984622316740"; // <-- replace with correct template id
System.out.println("SMS URL:- " + urlString);
String response = messageUtility.sendSMS(urlString);
System.out.println("SMS RESPONSE:- " + response);
return response;
}
public String restorationflagpoleSms(String mobileNo,
String streetName,
String amount,
String requestId) {
try {
String message = "Your flagpole installation at " + streetName
+ " caused damage to the public property. "
+ "Restoration charges of RS." + amount
+ " to be paid at https://gccservices.in/flagpolesregistration/paymentform?requestId="
+ requestId
+ " to avoid further action.\r\n"
+ "By GCC";
String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8);
String urlString = appConfig.getGetOtpUrl()
+ "from=GCCCRP"
+ "&key=" + key
+ "&sender=GCCCRP"
+ "&to=" + mobileNo
+ "&body=" + encodedMsg
+ "&entityid=1401572690000011081"
+ "&templateid=1407176984612580095";
System.out.println("FINAL SMS URL:- " + urlString);
URL apiUrl = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) apiUrl.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(15000);
conn.setReadTimeout(15000);
BufferedReader in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuilder content = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
conn.disconnect();
System.out.println("DIRECT SMS RESPONSE:- " + content.toString());
return content.toString();
} catch (Exception e) {
e.printStackTrace();
return "FAILED";
}
} }
}
public String unauthorizedFlagPoleSms(String mobileNo,
String streetName,
String fineAmount,
String requestId) {
public String unauthorizedFlagPoleSms(String mobileNo,
String streetName,
String fineAmount,
String requestId) {
try {
String message = "An unauthorized flag pole installation was found at " + streetName + ". "
+ "Fine amount: Rs." + fineAmount
+ " to be paid at https://gccservices.in/flagpolesregistration/paymentform?requestId="
+ requestId
+ " to avoid further action.\r\n"
+ "By GCC";
String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8);
try {
String urlString = appConfig.getGetOtpUrl()
+ "from=GCCCRP"
+ "&key=" + key
+ "&sender=GCCCRP"
+ "&to=" + mobileNo
+ "&body=" + encodedMsg
+ "&entityid=1401572690000011081"
+ "&templateid=1407176984622316740";
String message = "An unauthorized flag pole installation was found at " + streetName + ". "
+ "Fine amount: Rs." + fineAmount
+ " to be paid at https://gccservices.in/flagpolesregistration/paymentform?requestId="
+ requestId
+ " to avoid further action.\r\n"
+ "By GCC";
System.out.println("FINAL SMS URL:- " + urlString);
String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8);
URL apiUrl = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) apiUrl.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(15000);
conn.setReadTimeout(15000);
String urlString = appConfig.getGetOtpUrl()
+ "from=GCCCRP"
+ "&key=" + key
+ "&sender=GCCCRP"
+ "&to=" + mobileNo
+ "&body=" + encodedMsg
+ "&entityid=1401572690000011081"
+ "&templateid=1407176984622316740";
BufferedReader in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuilder content = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
conn.disconnect();
System.out.println("DIRECT SMS RESPONSE:- " + content.toString());
return content.toString();
} catch (Exception e) {
e.printStackTrace();
return "FAILED";
}
}
System.out.println("FINAL SMS URL:- " + urlString);
///// for permanent flagpole/statue messages
URL apiUrl = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) apiUrl.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(15000);
conn.setReadTimeout(15000);
public String sendBookingSuccesssmspermanent(String mobileNo, String requestId) {
BufferedReader in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuilder content = new StringBuilder();
String message = "Your Permanent Flag Pole / Statue permission request has been submitted successfully. "
+ "Request ID: " + requestId
+ ". You will be notified once the status is updated. By GCC";
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
// Encode message and fix colon issue (gateway not decoding %3A)
String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8)
.replace("%3A", ":")
.replace("%2F", "/");
in.close();
conn.disconnect();
String urlString = appConfig.getGetOtpUrl()
+ "from=GCCCRP"
+ "&key=" + key
+ "&sender=GCCCRP"
+ "&to=" + mobileNo
+ "&body=" + encodedMsg
+ "&entityid=1401572690000011081"
+ "&templateid=1407177062205821043";
System.out.println("DIRECT SMS RESPONSE:- " + content.toString());
System.out.println("SMS URL:- " + urlString);
return content.toString();
String response = messageUtility.sendSMS(urlString);
System.out.println("SMS RESPONSE:- " + response);
} catch (Exception e) {
e.printStackTrace();
return "FAILED";
return response;
} }
}
///// for permanent flagpole/statue messages
// public String sendPermanentRequestApproved(String mobileNo, String requestId)
// {
// String message = "Your Permanent Flag Pole / Statue permission request has
// been approved. "
// + "Request ID: " + requestId
// + ". Please proceed as per the permitted guidelines. By GCC";
// // Encode message and fix colon issue (gateway not decoding %3A)
// String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8)
// .replace("%3A", ":")
// .replace("%2F", "/");
// String urlString = appConfig.getGetOtpUrl()
// + "from=GCCCRP"
// + "&key=" + key
// + "&sender=GCCCRP"
// + "&to=" + mobileNo
// + "&body=" + encodedMsg
// + "&entityid=1401572690000011081"
// + "&templateid=1407177062247610982";
// System.out.println("SMS URL:- " + urlString);
// String response = messageUtility.sendSMS(urlString);
// System.out.println("SMS RESPONSE:- " + response);
// return response;
// }
// public String sendPermanentRequestRejected(String mobileNo,
// String requestId) {
// try {
// String message = "Your Permanent Flag Pole / Statue permission request has
// been rejected. "
// + "Request ID: " + requestId
// + ". Review the details in the portal
// https://gccservices.in/flagpolesregistration/status\r\n"
// + "By GCC";
// String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8);
// String urlString = appConfig.getGetOtpUrl()
// + "from=GCCCRP"
// + "&key=" + key
// + "&sender=GCCCRP"
// + "&to=" + mobileNo
// + "&body=" + encodedMsg
// + "&entityid=1401572690000011081"
// + "&templateid=1407177062255650311";
// System.out.println("FINAL SMS URL:- " + urlString);
public String sendBookingSuccesssmspermanent(String mobileNo, String requestId) {
// URL apiUrl = new URL(urlString);
// HttpURLConnection conn = (HttpURLConnection) apiUrl.openConnection();
// conn.setRequestMethod("GET");
// conn.setConnectTimeout(15000);
// conn.setReadTimeout(15000);
String message = "Your Permanent Flag Pole / Statue permission request has been submitted successfully. "
+ "Request ID: " + requestId
+ ". You will be notified once the status is updated. By GCC";
// BufferedReader in = new BufferedReader(
// new InputStreamReader(conn.getInputStream()));
// String inputLine;
// StringBuilder content = new StringBuilder();
// Encode message and fix colon issue (gateway not decoding %3A)
String encodedMsg = URLEncoder.encode(message, StandardCharsets.UTF_8)
.replace("%3A", ":")
.replace("%2F", "/");
// while ((inputLine = in.readLine()) != null) {
// content.append(inputLine);
// }
String urlString = appConfig.getGetOtpUrl()
+ "from=GCCCRP"
+ "&key=" + key
+ "&sender=GCCCRP"
+ "&to=" + mobileNo
+ "&body=" + encodedMsg
+ "&entityid=1401572690000011081"
+ "&templateid=1407177062205821043";
// in.close();
// conn.disconnect();
System.out.println("SMS URL:- " + urlString);
// System.out.println("DIRECT SMS RESPONSE:- " + content.toString());
String response = messageUtility.sendSMS(urlString);
System.out.println("SMS RESPONSE:- " + response);
// return content.toString();
return response;
}
// } catch (Exception e) {
// e.printStackTrace();
// return "FAILED";
// }
// }
} }
Loading…
Cancel
Save