Browse Source

changes added in pages

master
yoganandhan 8 months ago
parent
commit
ea900b6c20
  1. 447
      src/main/java/com/gcc/crslogs/controller/ApiController.java
  2. 23
      src/main/java/com/gcc/crslogs/service/BirthAndDeathDetailsService.java
  3. 1632
      src/main/resources/templates/modules/crslogspages/birth.html
  4. 1622
      src/main/resources/templates/modules/crslogspages/death.html

447
src/main/java/com/gcc/crslogs/controller/ApiController.java

@ -36,66 +36,69 @@ import jakarta.servlet.http.HttpSession;
@RequestMapping("/crs/api")
public class ApiController {
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
private AppConfig appConfig;
@Autowired
private AppConfig appConfig;
@Autowired
private BirthAndDeathDetailsService birthAndDeathDetailsService;
@Autowired
private BirthAndDeathDetailsService birthAndDeathDetailsService;
private final RestTemplate restTemplate = new RestTemplate();
private final RestTemplate restTemplate = new RestTemplate();
/*///////////////// otp configuration /////////////////////*/
/* ///////////////// otp configuration ///////////////////// */
@GetMapping(value = "/sendOTP")
public String sendOtp(HttpServletRequest request, @RequestParam String mobile) {
// Create an ObjectMapper instance
// Create an ObjectMapper instance
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> response = new HashMap<>();
String MobileNo=mobile;
System.out.print("\n MobileNo---:"+mobile);
String MobileNo = mobile;
System.out.print("\n MobileNo---:" + mobile);
Random rand = new Random();
int otp = rand.nextInt(90000) + 10000;
//int otp= 22222;
System.out.print("\n otp---:"+otp);
// int otp= 22222;
System.out.print("\n otp---:" + otp);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy%20HH:mm");
LocalDateTime now = LocalDateTime.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! 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 "+otp+" is your OTP for gcc QR
// System";
String generatedToken = "Welcome to GCC! Your OTP for Birth and Death Certificate login is " + otp;
//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=1407174687453240990";
//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);
// 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=1407174687453240990";
// 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);
String bodyMessage = "";
try {
RestTemplate restTemplate = new RestTemplate();
String Response = restTemplate.getForObject(urlString, String.class);
bodyMessage=Response;
System.out.println("\n bodyMessage"+bodyMessage);
bodyMessage = Response;
System.out.println("\n bodyMessage" + bodyMessage);
System.out.println("OTP sent successfully!");
} catch (Exception e) {
System.out.print("ERROR---: "+e);
System.out.print("ERROR---: " + e);
bodyMessage = "Error";
}
HttpSession session = request.getSession();
@ -104,11 +107,12 @@ public class ApiController {
}
/////////////////////verify otp method with session handling/////////////////////
///////////////////// verify otp method with session
///////////////////// handling/////////////////////
@GetMapping(value = "/verifyOTP")
public Map<String, String> verifyOtp(HttpServletRequest request, @RequestParam String otp,
@RequestParam String mobNo,@RequestParam String flag) {
@RequestParam String mobNo, @RequestParam String flag) {
HttpSession session = request.getSession();
Map<String, String> response = new HashMap<>();
Map<String, Object> userDetails;
@ -119,20 +123,21 @@ public class ApiController {
if (session_otp != null && session_otp.equals(entered_otp)) {
System.out.println("Entered OTP Correct");
if("1".equals(flag)) {
userDetails = birthAndDeathDetailsService.getUserDetails(mobNo);
if(userDetails != null) {
session.setAttribute("userId", userDetails.get("user_id"));
session.setAttribute("userName", userDetails.get("user_name"));
session.setAttribute("verifiedotp", "success");
response.put("userName", (String) userDetails.get("user_name"));
}
System.out.println("userId---:" + userDetails.get("user_id")+"\nuserName:"+userDetails.get("user_name"));
if ("1".equals(flag)) {
userDetails = birthAndDeathDetailsService.getUserDetails(mobNo);
if (userDetails != null) {
session.setAttribute("userId", userDetails.get("user_id"));
session.setAttribute("userName", userDetails.get("user_name"));
session.setAttribute("verifiedotp", "success");
response.put("userName", (String) userDetails.get("user_name"));
}
System.out.println(
"userId---:" + userDetails.get("user_id") + "\nuserName:" + userDetails.get("user_name"));
}
response.put("status", "Success");
} else {
//System.out.println("Incorrect OTP. Please enter correct OTP.");
// System.out.println("Incorrect OTP. Please enter correct OTP.");
session.setAttribute("verifiedotp", "error");
response.put("status", "Error");
@ -151,203 +156,185 @@ public class ApiController {
return response;
}
/////////////////////// birth details getting method///////////////////
// now using in live
// @GetMapping("/birth-details")
// public ResponseEntity<?> fetchBirthCertificateSecurely(
// @RequestParam String dob,
// @RequestParam String sex,
// @RequestParam(required = false) String regno,
// @RequestParam(required = false) String childname,
// @RequestParam(required = false) String fathername,
// @RequestParam(required = false) String mothername) {
// if (dob.isEmpty() || sex.isEmpty()) {
// Map<String, Object> error = new HashMap<>();
// error.put("status", false);
// error.put("message", "DOB and Sex are mandatory.");
// return ResponseEntity.badRequest().body(error);
// }
// try {
// Map<String, Object> result =
// birthAndDeathDetailsService.fetchBirthCertificate(dob, sex, regno, childname,
// fathername, mothername);
// return ResponseEntity.ok(result);
// } catch (Exception e) {
// e.printStackTrace();
// Map<String, Object> error = new HashMap<>();
// error.put("status", false);
// error.put("message", "Something went wrong: " + e.getMessage());
// return ResponseEntity.status(500).body(error);
// }
// }
// from external api restapiservices
@PostMapping("/birth-details")
public ResponseEntity<?> fetchBirthCertificateSecurely(@RequestBody Map<String, String> params) {
String dob = params.get("dob");
String sex = params.get("sex");
String childname = params.getOrDefault("childname", "");
String fathername = params.getOrDefault("fathername", "");
String mothername = params.getOrDefault("mothername", "");
if (dob == null || dob.isEmpty() || sex == null || sex.isEmpty()) {
Map<String, Object> error = new HashMap<>();
error.put("status", false);
error.put("message", "DOB and Sex are mandatory.");
return ResponseEntity.badRequest().body(error);
}
// System.out.println("fathername " + fathername);
// System.out.println("mothername " + mothername);
///////////////////////birth details getting method///////////////////
// now using in live
// @GetMapping("/birth-details")
// public ResponseEntity<?> fetchBirthCertificateSecurely(
// @RequestParam String dob,
// @RequestParam String sex,
// @RequestParam(required = false) String regno,
// @RequestParam(required = false) String childname,
// @RequestParam(required = false) String fathername,
// @RequestParam(required = false) String mothername) {
// if (dob.isEmpty() || sex.isEmpty()) {
// Map<String, Object> error = new HashMap<>();
// error.put("status", false);
// error.put("message", "DOB and Sex are mandatory.");
// return ResponseEntity.badRequest().body(error);
// }
// try {
// Map<String, Object> result = birthAndDeathDetailsService.fetchBirthCertificate(dob, sex, regno, childname, fathername, mothername);
// return ResponseEntity.ok(result);
// } catch (Exception e) {
// e.printStackTrace();
// Map<String, Object> error = new HashMap<>();
// error.put("status", false);
// error.put("message", "Something went wrong: " + e.getMessage());
// return ResponseEntity.status(500).body(error);
// }
// }
// from external api restapiservices
@PostMapping("/birth-details")
public ResponseEntity<?> fetchBirthCertificateSecurely(@RequestBody Map<String, String> params) {
String dob = params.get("dob");
String sex = params.get("sex");
String childname = params.getOrDefault("childname", "");
String fathername = params.getOrDefault("fathername", "");
String mothername = params.getOrDefault("mothername", "");
if (dob == null || dob.isEmpty() || sex == null || sex.isEmpty()) {
Map<String, Object> error = new HashMap<>();
error.put("status", false);
error.put("message", "DOB and Sex are mandatory.");
return ResponseEntity.badRequest().body(error);
}
//System.out.println("fathername " + fathername);
//System.out.println("mothername " + mothername);
try {
Map<String, Object> result = birthAndDeathDetailsService.fetchLocalBirthCertificate(
dob, fathername, mothername, childname, sex
);
return ResponseEntity.ok(result);
} catch (Exception e) {
e.printStackTrace();
Map<String, Object> error = new HashMap<>();
String message = e.getMessage() != null ? e.getMessage().toLowerCase() : "";
if (message.contains("404")) {
error.put("status", false);
error.put("message", "No matching birth record found.");
return ResponseEntity.status(404).body(error);
} else if (message.contains("400")) {
error.put("status", false);
error.put("message", "Invalid request. Please check your input details.");
return ResponseEntity.status(400).body(error);
} else if (message.contains("socket") || message.contains("connection")) {
error.put("status", false);
error.put("message", "Connection issue. Please try again later.");
return ResponseEntity.status(503).body(error);
} else {
error.put("status", false);
error.put("message", "Something went wrong. Please try again later.");
return ResponseEntity.status(500).body(error);
try {
Map<String, Object> result = birthAndDeathDetailsService.fetchLocalBirthCertificate(
dob, fathername, mothername, childname, sex);
return ResponseEntity.ok(result);
} catch (Exception e) {
e.printStackTrace();
Map<String, Object> error = new HashMap<>();
String message = e.getMessage() != null ? e.getMessage().toLowerCase() : "";
if (message.contains("404")) {
error.put("status", false);
error.put("message", "No matching birth record found.");
return ResponseEntity.status(404).body(error);
} else if (message.contains("400")) {
error.put("status", false);
error.put("message", "Invalid request. Please check your input details.");
return ResponseEntity.status(400).body(error);
} else if (message.contains("socket") || message.contains("connection")) {
error.put("status", false);
error.put("message", "Connection issue. Please try again later.");
return ResponseEntity.status(503).body(error);
} else {
error.put("status", false);
error.put("message", "Something went wrong. Please try again later.");
return ResponseEntity.status(500).body(error);
}
}
}
}
}
// from external api restapiservices death certificate
@PostMapping("/death-details")
public ResponseEntity<?> fetchDeathCertificateSecurely(@RequestBody Map<String, String> params) {
String dod = params.get("dod");
String sex = params.get("sex");
String personname = params.getOrDefault("personname", "");
String fathername = params.getOrDefault("fathername", "");
String mothername = params.getOrDefault("mothername", "");
if (dod == null || dod.isEmpty() || sex == null || sex.isEmpty()) {
Map<String, Object> error = new HashMap<>();
error.put("status", false);
error.put("message", "dod and Sex are mandatory.");
return ResponseEntity.badRequest().body(error);
}
// from external api restapiservices death certificate
@PostMapping("/death-details")
public ResponseEntity<?> fetchDeathCertificateSecurely(@RequestBody Map<String, String> params) {
String dod = params.get("dod");
String sex = params.get("sex");
String personname = params.getOrDefault("personname", "");
String fathername = params.getOrDefault("fathername", "");
String mothername = params.getOrDefault("mothername", "");
// System.out.println("fathername " + fathername);
// System.out.println("mothername " + mothername);
if (dod == null || dod.isEmpty() || sex == null || sex.isEmpty()) {
Map<String, Object> error = new HashMap<>();
error.put("status", false);
error.put("message", "dod and Sex are mandatory.");
return ResponseEntity.badRequest().body(error);
}
System.out.println("sex: " + sex);
//System.out.println("fathername " + fathername);
//System.out.println("mothername " + mothername);
try {
Map<String, Object> result = birthAndDeathDetailsService.fetchLocalDeathCertificate(
dod, fathername, mothername, personname, sex
);
return ResponseEntity.ok(result);
} catch (Exception e) {
e.printStackTrace();
Map<String, Object> error = new HashMap<>();
String message = e.getMessage() != null ? e.getMessage().toLowerCase() : "";
if (message.contains("404")) {
error.put("status", false);
error.put("message", "No matching death record found.");
return ResponseEntity.status(404).body(error);
} else if (message.contains("400")) {
error.put("status", false);
error.put("message", "Invalid request. Please check your input details.");
return ResponseEntity.status(400).body(error);
} else if (message.contains("socket") || message.contains("connection")) {
error.put("status", false);
error.put("message", "Connection issue. Please try again later.");
return ResponseEntity.status(503).body(error);
} else {
error.put("status", false);
error.put("message", "Something went wrong. Please try again later.");
return ResponseEntity.status(500).body(error);
}
try {
Map<String, Object> result = birthAndDeathDetailsService.fetchLocalDeathCertificate(
dod, fathername, mothername, personname, sex);
return ResponseEntity.ok(result);
} catch (Exception e) {
e.printStackTrace();
Map<String, Object> error = new HashMap<>();
String message = e.getMessage() != null ? e.getMessage().toLowerCase() : "";
if (message.contains("404")) {
error.put("status", false);
error.put("message", "No matching death record found.");
return ResponseEntity.status(404).body(error);
} else if (message.contains("400")) {
error.put("status", false);
error.put("message", "Invalid request. Please check your input details.");
return ResponseEntity.status(400).body(error);
} else if (message.contains("socket") || message.contains("connection")) {
error.put("status", false);
error.put("message", "Connection issue. Please try again later.");
return ResponseEntity.status(503).body(error);
} else {
error.put("status", false);
error.put("message", "Something went wrong. Please try again later.");
return ResponseEntity.status(500).body(error);
}
}
}
}
//////////////////////// death details getting method///////////////////
@GetMapping("/death-details")
public ResponseEntity<?> fetchDeathCertificateSecurely(
@RequestParam String dod,
@RequestParam String sex,
@RequestParam(required = false) String regno,
@RequestParam(required = false) String personname,
@RequestParam(required = false) String fathername,
@RequestParam(required = false) String mothername) {
if (dod.isEmpty() || sex.isEmpty()) {
Map<String, Object> error = new HashMap<>();
error.put("status", false);
error.put("message", "DOB and Sex are mandatory.");
return ResponseEntity.badRequest().body(error);
}
try {
Map<String, Object> result = birthAndDeathDetailsService.fetchDeathCertificate(dod, sex, regno, personname,
fathername, mothername);
return ResponseEntity.ok(result);
} catch (Exception e) {
e.printStackTrace();
Map<String, Object> error = new HashMap<>();
error.put("status", false);
error.put("message", "Something went wrong: " + e.getMessage());
return ResponseEntity.status(500).body(error);
}
}
////////////////////////death details getting method///////////////////
@GetMapping("/death-details")
public ResponseEntity<?> fetchDeathCertificateSecurely(
@RequestParam String dod,
@RequestParam String sex,
@RequestParam(required = false) String regno,
@RequestParam(required = false) String personname,
@RequestParam(required = false) String fathername,
@RequestParam(required = false) String mothername) {
if (dod.isEmpty() || sex.isEmpty()) {
Map<String, Object> error = new HashMap<>();
error.put("status", false);
error.put("message", "DOB and Sex are mandatory.");
return ResponseEntity.badRequest().body(error);
}
try {
Map<String, Object> result = birthAndDeathDetailsService.fetchDeathCertificate(dod, sex, regno, personname, fathername, mothername);
return ResponseEntity.ok(result);
} catch (Exception e) {
e.printStackTrace();
Map<String, Object> error = new HashMap<>();
error.put("status", false);
error.put("message", "Something went wrong: " + e.getMessage());
return ResponseEntity.status(500).body(error);
}
}
/////////////////save new user method/////////////////
///////////////// save new user method/////////////////
@PostMapping("/saveNewUser")
public ResponseEntity<?> saveNewUser (@RequestParam String user_name, @RequestParam(required = false) String user_address, @RequestParam String user_mobile) {
// Convert name to uppercase before saving
public ResponseEntity<?> saveNewUser(@RequestParam String user_name,
@RequestParam(required = false) String user_address, @RequestParam String user_mobile) {
// Convert name to uppercase before saving
String upperCaseName = user_name.toUpperCase();
return birthAndDeathDetailsService.saveNewUser(upperCaseName, user_address, user_mobile);
return birthAndDeathDetailsService.saveNewUser(upperCaseName, user_address, user_mobile);
}
/////////////////check existing or not method////////////
///////////////// check existing or not method////////////
@PostMapping("/checkUser")
public ResponseEntity<Map<String, Object>> checkUser(@RequestParam String mobile) {
@ -362,23 +349,21 @@ String message = e.getMessage() != null ? e.getMessage().toLowerCase() : "";
}
}
///////////////////////save certificate logs method///////////////////
/////////////////////// save certificate logs method///////////////////
@PostMapping("/saveCertificateLogs")
public ResponseEntity<?> saveCertificateLogs(HttpServletRequest request, @RequestParam String regNo, @RequestParam String eventDate,
@RequestParam String Url, @RequestParam String service){
public ResponseEntity<?> saveCertificateLogs(HttpServletRequest request, @RequestParam String regNo,
@RequestParam String eventDate,
@RequestParam String Url, @RequestParam String service) {
HttpSession session = request.getSession();
int userid = 0 ;
try{
int userid = 0;
try {
userid = (int) session.getAttribute("userId");
}catch(Exception e){
} catch (Exception e) {
e.printStackTrace();
}
return birthAndDeathDetailsService.saveCertificateLogs(regNo, eventDate, Url, service, userid);
}
}

23
src/main/java/com/gcc/crslogs/service/BirthAndDeathDetailsService.java

@ -122,11 +122,12 @@ public class BirthAndDeathDetailsService {
if (result.containsKey("certificate_details")) {
List<Map<String, Object>> details = (List<Map<String, Object>>) result.get("certificate_details");
List<Map<String, Object>> filtered = details.stream()
.filter(row -> row.get("pdf_url") != null && !row.get("pdf_url").toString().trim().isEmpty())
.toList();
// List<Map<String, Object>> filtered = details.stream()
// .filter(row -> row.get("pdf_url") != null &&
// !row.get("pdf_url").toString().trim().isEmpty())
// .toList();
result.put("certificate_details", filtered);
result.put("certificate_details", details);
}
return result;
@ -164,19 +165,23 @@ public class BirthAndDeathDetailsService {
ResponseEntity<String> response = restTemplate.postForEntity(apiUrl, entity, String.class);
System.out.println("api:" + apiUrl);
System.out.println("params:" + params);
String rawJson = response.getBody();
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> result = mapper.readValue(rawJson, new TypeReference<Map<String, Object>>() {
});
// ✅ Only keep records that actually have a PDF link
if (result.containsKey("certificate_details")) {
List<Map<String, Object>> details = (List<Map<String, Object>>) result.get("certificate_details");
List<Map<String, Object>> filtered = details.stream()
.filter(row -> row.get("pdf_url") != null && !row.get("pdf_url").toString().trim().isEmpty())
.toList();
// List<Map<String, Object>> filtered = details.stream()
// .filter(row -> row.get("pdf_url") != null &&
// !row.get("pdf_url").toString().trim().isEmpty())
// .toList();
result.put("certificate_details", filtered);
result.put("certificate_details", details);
}
return result;

1632
src/main/resources/templates/modules/crslogspages/birth.html
File diff suppressed because it is too large
View File

1622
src/main/resources/templates/modules/crslogspages/death.html
File diff suppressed because it is too large
View File

Loading…
Cancel
Save