From 3d5290ab391218ac754c9318970ad955569f8ed7 Mon Sep 17 00:00:00 2001 From: AJITHKUMAR12 <48044092+AJITHKUMAR12@users.noreply.github.com> Date: Mon, 13 Jul 2026 10:46:49 +0530 Subject: [PATCH] implemented public section like pgr complaint --- .../controller/Apicontroller.java | 814 ++++++++++-------- .../resources/application-prod.properties | 2 +- src/main/resources/application.properties | 2 +- .../resources/templates/modules/home.html | 444 +++++----- .../templates/modules/public/form.html | 187 +++- .../GreencommitteApplicationTests.java | 13 - 6 files changed, 871 insertions(+), 591 deletions(-) delete mode 100644 src/test/java/com/gcc/greencommitte/GreencommitteApplicationTests.java diff --git a/src/main/java/com/gcc/greencommitte/controller/Apicontroller.java b/src/main/java/com/gcc/greencommitte/controller/Apicontroller.java index bedd262..8ff4da2 100644 --- a/src/main/java/com/gcc/greencommitte/controller/Apicontroller.java +++ b/src/main/java/com/gcc/greencommitte/controller/Apicontroller.java @@ -1,11 +1,17 @@ package com.gcc.greencommitte.controller; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; +import org.springframework.http.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -17,6 +23,10 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import org.springframework.web.multipart.MultipartFile; +import java.net.URL; +import java.net.URLEncoder; +import java.util.Base64; +//import org.springframework.http.MediaType; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; @@ -28,362 +38,470 @@ import com.gcc.greencommitte.service.Greencommitteeservice; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; - @RestController -@RequestMapping("/greencommittee/api") +@RequestMapping("/greencommittee/api") public class Apicontroller { - - @Autowired - private AppConfig appConfig; - + + @Autowired + private AppConfig appConfig; + @Autowired private Greencommitteeservice gcservice; - - + @GetMapping(value = "/sendOTP") - public String sendOtp(HttpServletRequest request, @RequestParam String mobileNo) { + public String sendOtp(HttpServletRequest request, @RequestParam String mobileNo) { - // Generate OTP logic as before - String MobileNo = mobileNo; - Random rand = new Random(); - int otp = rand.nextInt(90000) + 10000; + // Generate OTP logic as before + String MobileNo = mobileNo; + Random rand = new Random(); + int otp = rand.nextInt(90000) + 10000; - String key = "pfTEYN6H"; + String key = "pfTEYN6H"; String entityId = "1401572690000011081"; String templateId = "1407175765770900925"; - String appName="Green Committe"; - - String generatedMessage = "Welcome to GCC! Your OTP for " + appName + " is " + otp + "."; - String urlString = appConfig.getGetOtpUrl() + "from=GCCCRP" + "&key=" + key + "&sender=GCCCRP" + "&to=" + MobileNo + "&body=" - + generatedMessage + "&entityid=" + entityId + "&templateid=" + templateId; - - System.out.println("\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); - - System.out.println("OTP sent successfully!"); - - } catch (Exception e) { - System.out.print("ERROR---: " + e); - bodyMessage = "Error"; - } - - HttpSession session = request.getSession(); - session.setAttribute("otp", otp); - session.setAttribute("mobileNo", mobileNo); - return bodyMessage; - } - + String appName = "Green Committe"; + + String generatedMessage = "Welcome to GCC! Your OTP for " + appName + " is " + otp + "."; + String urlString = appConfig.getGetOtpUrl() + "from=GCCCRP" + "&key=" + key + "&sender=GCCCRP" + "&to=" + + MobileNo + "&body=" + + generatedMessage + "&entityid=" + entityId + "&templateid=" + templateId; + + System.out.println("\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); + + System.out.println("OTP sent successfully!"); + + } catch (Exception e) { + System.out.print("ERROR---: " + e); + bodyMessage = "Error"; + } + + HttpSession session = request.getSession(); + session.setAttribute("otp", otp); + session.setAttribute("mobileNo", mobileNo); + return bodyMessage; + } + @GetMapping(value = "/verifyOTP") - public String verifyOtp(HttpServletRequest request, @RequestParam String otp) { - HttpSession session = request.getSession(); - - try { - Integer session_otp = (Integer) session.getAttribute("otp"); - //System.out.println("session_otp---:" + session_otp); - Integer entered_otp = Integer.parseInt(otp); - - if (session_otp != null && session_otp.equals(entered_otp)) { - System.out.println("Entered OTP Correct"); - session.setAttribute("verifiedotp", "success"); - return "Success"; - } else { - System.out.println("Incorrect OTP. Please enter correct OTPs."); - session.setAttribute("verifiedotp", "error"); - return "Error"; - } - } catch (NumberFormatException e) { - System.out.println("Invalid OTP format: " + otp); - return "Error"; - } catch (Exception e) { - System.out.println("Error verifying OTP: " + e.getMessage()); - return "Error"; - } - } - - @GetMapping("/getcompnatureforpublic") - public ResponseEntity getCompNatureForPublic(){ - try { - List> list = gcservice.getCompNatureForPublic(); - - Map response = new HashMap<>(); - response.put("status", "success"); - response.put("data", list); - - return ResponseEntity.ok(response); - - } catch (Exception ex) { - ex.printStackTrace(); - - Map error = new HashMap<>(); - error.put("status", "error"); - error.put("message", ex.getMessage()); - - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error); - } - } - - @GetMapping("/getcompnaturefordept") - public ResponseEntity getCompNatureForDept(){ - try { - List> list = gcservice.getCompNatureForDept(); - - Map response = new HashMap<>(); - response.put("status", "success"); - response.put("data", list); - - return ResponseEntity.ok(response); - - } catch (Exception ex) { - ex.printStackTrace(); - - Map error = new HashMap<>(); - error.put("status", "error"); - error.put("message", ex.getMessage()); - - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error); - } - } - - @GetMapping("/getAllDepts") - public ResponseEntity getAllDepts(){ - try { - List> list = gcservice.getAllDepts(); - - Map response = new HashMap<>(); - response.put("status", "success"); - response.put("data", list); - - return ResponseEntity.ok(response); - - } catch (Exception ex) { - ex.printStackTrace(); - - Map error = new HashMap<>(); - error.put("status", "error"); - error.put("message", ex.getMessage()); - - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error); - } - } - - @PostMapping("/savepublicform") - public ResponseEntity savepublicform( - @RequestParam String p_name, - @RequestParam String ph_no, - @RequestParam String gender, - @RequestParam String address, - @RequestParam String latitude, - @RequestParam String longitude, - @RequestParam String zone, - @RequestParam String ward, - @RequestParam String remarks, - @RequestParam MultipartFile c1image, - @RequestParam MultipartFile c2image, - @RequestParam String comp_details, - @RequestParam String source) throws JsonMappingException, JsonProcessingException{ - - ObjectMapper mapper = new ObjectMapper(); - List> compList = mapper.readValue(comp_details, - new TypeReference>>() { - }); - - int totalTreeCount = compList.stream() - .mapToInt(item -> Integer.parseInt(item.get("count").toString())) - .sum(); - - String c1imagePath=null; - String c2imagePath=null; - c1imagePath=gcservice.fileUpload(c1image, "comp_image1"); - c2imagePath=gcservice.fileUpload(c2image, "comp_image1"); - - //System.out.println("======="+latitude+","+longitude); - - String saveStatus = gcservice.savepublicform(p_name,ph_no,gender,address,latitude,longitude,zone,ward,remarks,c1imagePath,c2imagePath,compList,totalTreeCount,source); - - - if (saveStatus == null || saveStatus.equals("error")) { - return ResponseEntity.ok(Map.of( - "status", false, - "message", "failed", - "description", "Failed to save the details" - )); - } - - - return ResponseEntity.ok(Map.of( - "status", true, - "message", "success", - "description", "Details saved successfully", - "ref_id", saveStatus - )); - } - - - @PostMapping("/savedeptform") - public ResponseEntity savedeptform( - @RequestParam String dept_id, - @RequestParam (required = false) String dept_name, - @RequestParam String ph_no, - @RequestParam String designation, - @RequestParam String govt_type, - @RequestParam String address, - @RequestParam String latitude, - @RequestParam String longitude, - @RequestParam String zone, - @RequestParam String ward, - @RequestParam String remarks, - @RequestParam MultipartFile c1image, - @RequestParam MultipartFile c2image, - @RequestParam String comp_details, - @RequestParam String source) throws JsonMappingException, JsonProcessingException{ - - ObjectMapper mapper = new ObjectMapper(); - List> compList = mapper.readValue(comp_details, - new TypeReference>>() { - }); - - int totalTreeCount = compList.stream() - .mapToInt(item -> Integer.parseInt(item.get("count").toString())) - .sum(); - - String c1imagePath=null; - String c2imagePath=null; - c1imagePath=gcservice.fileUpload(c1image, "comp_image1"); - c2imagePath=gcservice.fileUpload(c2image, "comp_image1"); - - // System.out.println("======="+latitude+","+longitude); - - String saveStatus = gcservice.savedeptform(dept_id,dept_name,ph_no,designation,govt_type,address,latitude,longitude,zone,ward,remarks,c1imagePath,c2imagePath,compList,totalTreeCount,source); - - - if (saveStatus == null || saveStatus.equals("error")) { - return ResponseEntity.ok(Map.of( - "status", false, - "message", "failed", - "description", "Failed to save the details" - )); - } - - - return ResponseEntity.ok(Map.of( - "status", true, - "message", "success", - "description", "Details saved successfully", - "ref_id", saveStatus - )); - } - - - @GetMapping(value = "/sendOTPforwithdraw") - public String sendOtpforwithdraw(HttpServletRequest request, @RequestParam String mobileNo) { - - - List CompDetailsList = gcservice.findByMobileNo(mobileNo); - System.out.println("CompDetailsList="+CompDetailsList); - if (CompDetailsList == null || CompDetailsList.isEmpty()) { - // If the mobile number is not registered, return an error message - return "Error: This number is not registered."; - } - - // Generate OTP logic as before - String MobileNo = mobileNo; - Random rand = new Random(); - int otp = rand.nextInt(90000) + 10000; - - String key = "pfTEYN6H"; - String entityId = "1401572690000011081"; - String templateId = "1407175765770900925"; - String appName="Green Committe"; - - String generatedMessage = "Welcome to GCC! Your OTP for " + appName + " is " + otp + "."; - String urlString = appConfig.getGetOtpUrl() + "from=GCCCRP" + "&key=" + key + "&sender=GCCCRP" + "&to=" + MobileNo + "&body=" - + generatedMessage + "&entityid=" + entityId + "&templateid=" + templateId; - - System.out.println("\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); - - System.out.println("OTP sent successfully!"); - - } catch (Exception e) { - System.out.print("ERROR---: " + e); - bodyMessage = "Error"; - } - - HttpSession session = request.getSession(); - session.setAttribute("otp", otp); - session.setAttribute("mobileNo", mobileNo); - return bodyMessage; - } - - -// @GetMapping("/checkwithdraw") -// public List> checkWithdrawByMobileNumber(@RequestParam String mobile_num){ -// -// return gcservice.checkwithdraw(mobile_num); -// } - - @GetMapping("/checkwithdraw") - public List> checkWithdrawByMobileNumber(@RequestParam String mobile_num) { - - List refnums = gcservice.getrefnums(mobile_num); - System.out.println("refnums="+refnums); - - Map wrapper = new HashMap<>(); - List> finalList = new ArrayList<>(); - - if (refnums.isEmpty()) { - wrapper.put("message", "Empty List"); - wrapper.put("status", "Success"); - return Collections.singletonList(wrapper); - } - - for (String ref : refnums) { - System.out.println("ref="+ref); - Map data = gcservice.getfulldetailsdata(ref); - if (data != null && !data.isEmpty()) { - finalList.add(data); - } - } - - wrapper.put("data", finalList); - wrapper.put("message", "Complaint List"); - wrapper.put("status", "Success"); - - return Collections.singletonList(wrapper); - } - - @PostMapping("/withdraw") - public ResponseEntity withdraw(@RequestParam String id,@RequestParam String remarks) - { - String saveStatus=gcservice.withdraw(id,remarks); - - if (saveStatus == null || saveStatus.equals("error")) { - return ResponseEntity.ok(Map.of( - "status", false, - "message", "failed", - "description", "Failed to withdraw the Complaint" - )); - } - - - return ResponseEntity.ok(Map.of( - "status", true, - "message", "success", - "description", "Application withdrawn successfully", - "ref_id", saveStatus - )); - } - + public String verifyOtp(HttpServletRequest request, @RequestParam String otp) { + HttpSession session = request.getSession(); + + try { + Integer session_otp = (Integer) session.getAttribute("otp"); + // System.out.println("session_otp---:" + session_otp); + Integer entered_otp = Integer.parseInt(otp); + + if (session_otp != null && session_otp.equals(entered_otp)) { + System.out.println("Entered OTP Correct"); + session.setAttribute("verifiedotp", "success"); + return "Success"; + } else { + System.out.println("Incorrect OTP. Please enter correct OTPs."); + session.setAttribute("verifiedotp", "error"); + return "Error"; + } + } catch (NumberFormatException e) { + System.out.println("Invalid OTP format: " + otp); + return "Error"; + } catch (Exception e) { + System.out.println("Error verifying OTP: " + e.getMessage()); + return "Error"; + } + } + + @GetMapping("/getcompnatureforpublic") + public ResponseEntity getCompNatureForPublic() { + try { + List> list = gcservice.getCompNatureForPublic(); + + Map response = new HashMap<>(); + response.put("status", "success"); + response.put("data", list); + + return ResponseEntity.ok(response); + + } catch (Exception ex) { + ex.printStackTrace(); + + Map error = new HashMap<>(); + error.put("status", "error"); + error.put("message", ex.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error); + } + } + + @GetMapping("/getcompnaturefordept") + public ResponseEntity getCompNatureForDept() { + try { + List> list = gcservice.getCompNatureForDept(); + + Map response = new HashMap<>(); + response.put("status", "success"); + response.put("data", list); + + return ResponseEntity.ok(response); + + } catch (Exception ex) { + ex.printStackTrace(); + + Map error = new HashMap<>(); + error.put("status", "error"); + error.put("message", ex.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error); + } + } + + @GetMapping("/getAllDepts") + public ResponseEntity getAllDepts() { + try { + List> list = gcservice.getAllDepts(); + + Map response = new HashMap<>(); + response.put("status", "success"); + response.put("data", list); + + return ResponseEntity.ok(response); + + } catch (Exception ex) { + ex.printStackTrace(); + + Map error = new HashMap<>(); + error.put("status", "error"); + error.put("message", ex.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error); + } + } + + @PostMapping("/savepublicform") + public ResponseEntity savepublicform( + @RequestParam String p_name, + @RequestParam String ph_no, + @RequestParam String gender, + @RequestParam String address, + @RequestParam String latitude, + @RequestParam String longitude, + @RequestParam String zone, + @RequestParam String ward, + @RequestParam String remarks, + @RequestParam MultipartFile c1image, + @RequestParam MultipartFile c2image, + @RequestParam String comp_details, + @RequestParam String source) throws JsonMappingException, JsonProcessingException { + + ObjectMapper mapper = new ObjectMapper(); + List> compList = mapper.readValue(comp_details, + new TypeReference>>() { + }); + + int totalTreeCount = compList.stream() + .mapToInt(item -> Integer.parseInt(item.get("count").toString())) + .sum(); + + String c1imagePath = null; + String c2imagePath = null; + c1imagePath = gcservice.fileUpload(c1image, "comp_image1"); + c2imagePath = gcservice.fileUpload(c2image, "comp_image1"); + + // System.out.println("======="+latitude+","+longitude); + + String saveStatus = gcservice.savepublicform(p_name, ph_no, gender, address, latitude, longitude, zone, ward, + remarks, c1imagePath, c2imagePath, compList, totalTreeCount, source); + + if (saveStatus == null || saveStatus.equals("error")) { + return ResponseEntity.ok(Map.of( + "status", false, + "message", "failed", + "description", "Failed to save the details")); + } + + return ResponseEntity.ok(Map.of( + "status", true, + "message", "success", + "description", "Details saved successfully", + "ref_id", saveStatus)); + } + + @PostMapping("/savepruningform") + public ResponseEntity registerComplaint( + @RequestParam(value = "p_name", required = false) String complainantName, + @RequestParam(value = "address", required = false) String complainantAddr, + @RequestParam(value = "ph_no", required = false) String mobileNo, + @RequestParam(value = "Email", required = false) String email, + @RequestParam(value = "ComplaintType", required = false) String complaintType, + @RequestParam(value = "ComplaintTitle", required = false) String complaintTitle, + @RequestParam(value = "remarks", required = false) String complaintDetails, + @RequestParam(value = "StreetId", required = false) String streetId, + @RequestParam(value = "c1image", required = false) MultipartFile compImage, + @RequestParam(value = "latitude", required = false) String latitude, + @RequestParam(value = "longitude", required = false) String longtitude, + @RequestParam(value = "Landmark", required = false) String landmark, + @RequestParam(value = "gender", required = false) String gender) { + complaintType = "454"; + complaintTitle = "Tree Pruning"; + System.out.println("========== Incoming Request =========="); + System.out.println("Complainant Name : " + complainantName); + System.out.println("Address : " + complainantAddr); + System.out.println("Mobile No : " + mobileNo); + System.out.println("Email : " + email); + System.out.println("Complaint Type : " + complaintType); + System.out.println("Complaint Title : " + complaintTitle); + System.out.println("Complaint Details: " + complaintDetails); + System.out.println("Street ID : " + streetId); + System.out.println("Latitude : " + latitude); + System.out.println("Longitude : " + longtitude); + System.out.println("Landmark : " + landmark); + System.out.println("Gender : " + gender); + + String externalUrl = "https://erp.chennaicorporation.gov.in/pgr/external/mobileservice"; + + try { + URL url = new URL(externalUrl); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + conn.setDoOutput(true); + + // 1) Convert MultipartFile to Base64 string + String compImageBase64 = ""; + if (compImage != null && !compImage.isEmpty()) { + byte[] bytes = compImage.getBytes(); + compImageBase64 = Base64.getEncoder().encodeToString(bytes); + } + System.out.println("compImage.." + compImage); + + String params = "serviceId=RegComplaint" + + "&ComplainantName=" + URLEncoder.encode(complainantName != null ? complainantName : "", "UTF-8") + + "&ComplainantAddr=" + URLEncoder.encode(complainantAddr != null ? complainantAddr : "", "UTF-8") + + "&MobileNo=" + URLEncoder.encode(mobileNo != null ? mobileNo : "", "UTF-8") + + "&Email=" + URLEncoder.encode(email != null ? email : "", "UTF-8") + + "&ComplaintType=" + URLEncoder.encode(complaintType != null ? complaintType : "", "UTF-8") + + "&ComplaintTitle=" + URLEncoder.encode(complaintTitle != null ? complaintTitle : "", "UTF-8") + + "&ComplaintDetails=" + URLEncoder.encode(complaintDetails != null ? complaintDetails : "", "UTF-8") + + + "&StreetId=" + URLEncoder.encode(streetId != null ? streetId : "", "UTF-8") + + "&Comp_Image=" + URLEncoder.encode(compImageBase64, "UTF-8") + + "&latitude=" + URLEncoder.encode(latitude != null ? latitude : "", "UTF-8") + + "&longtitude=" + URLEncoder.encode(longtitude != null ? longtitude : "", "UTF-8") + + "&Landmark=" + URLEncoder.encode(landmark != null ? landmark : "", "UTF-8") + + "&gender=" + URLEncoder.encode(gender != null ? gender : "", "UTF-8") + + "&compmode=1"; + + /* + * System.out.println("========================================"); + * System.out.println("External URL : " + externalUrl); + * + * System.out.println("========================================"); + */ + + try (OutputStream os = conn.getOutputStream()) { + byte[] input = params.getBytes("UTF-8"); + os.write(input, 0, input.length); + } + + int responseCode = conn.getResponseCode(); + System.out.println("responseCode" + responseCode); + BufferedReader reader; + if (responseCode == HttpURLConnection.HTTP_OK) { + reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); + + } else { + reader = new BufferedReader(new InputStreamReader(conn.getErrorStream())); + } + + StringBuilder response = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + response.append(line); + System.out.println("response" + response); + + } + reader.close(); + + // ✅ Parse and return only the complaint number + ObjectMapper mapper = new ObjectMapper(); + Map responseMap = mapper.readValue(response.toString(), Map.class); + System.out.println("responseMap" + responseMap); + + String complaintNo = responseMap.getOrDefault("Complaint Number", "N/A"); + System.out.println("complaintNo====" + complaintNo); + return ResponseEntity.ok( + Map.of( + "status", true, + "complaintNumber", complaintNo)); + + /* + * return ResponseEntity.ok() + * .contentType(MediaType.APPLICATION_JSON).body(Map.of("complaintNumber", + * complaintNo)); + */ + + } catch (IOException e) { + e.printStackTrace(); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body(Map.of("error", "An error occurred while processing the request.")); + } + } + + @PostMapping("/savedeptform") + public ResponseEntity savedeptform( + @RequestParam String dept_id, + @RequestParam(required = false) String dept_name, + @RequestParam String ph_no, + @RequestParam String designation, + @RequestParam String govt_type, + @RequestParam String address, + @RequestParam String latitude, + @RequestParam String longitude, + @RequestParam String zone, + @RequestParam String ward, + @RequestParam String remarks, + @RequestParam MultipartFile c1image, + @RequestParam MultipartFile c2image, + @RequestParam String comp_details, + @RequestParam String source) throws JsonMappingException, JsonProcessingException { + + ObjectMapper mapper = new ObjectMapper(); + List> compList = mapper.readValue(comp_details, + new TypeReference>>() { + }); + + int totalTreeCount = compList.stream() + .mapToInt(item -> Integer.parseInt(item.get("count").toString())) + .sum(); + + String c1imagePath = null; + String c2imagePath = null; + c1imagePath = gcservice.fileUpload(c1image, "comp_image1"); + c2imagePath = gcservice.fileUpload(c2image, "comp_image1"); + + // System.out.println("======="+latitude+","+longitude); + + String saveStatus = gcservice.savedeptform(dept_id, dept_name, ph_no, designation, govt_type, address, latitude, + longitude, zone, ward, remarks, c1imagePath, c2imagePath, compList, totalTreeCount, source); + + if (saveStatus == null || saveStatus.equals("error")) { + return ResponseEntity.ok(Map.of( + "status", false, + "message", "failed", + "description", "Failed to save the details")); + } + + return ResponseEntity.ok(Map.of( + "status", true, + "message", "success", + "description", "Details saved successfully", + "ref_id", saveStatus)); + } + + @GetMapping(value = "/sendOTPforwithdraw") + public String sendOtpforwithdraw(HttpServletRequest request, @RequestParam String mobileNo) { + + List CompDetailsList = gcservice.findByMobileNo(mobileNo); + System.out.println("CompDetailsList=" + CompDetailsList); + if (CompDetailsList == null || CompDetailsList.isEmpty()) { + // If the mobile number is not registered, return an error message + return "Error: This number is not registered."; + } + + // Generate OTP logic as before + String MobileNo = mobileNo; + Random rand = new Random(); + int otp = rand.nextInt(90000) + 10000; + + String key = "pfTEYN6H"; + String entityId = "1401572690000011081"; + String templateId = "1407175765770900925"; + String appName = "Green Committe"; + + String generatedMessage = "Welcome to GCC! Your OTP for " + appName + " is " + otp + "."; + String urlString = appConfig.getGetOtpUrl() + "from=GCCCRP" + "&key=" + key + "&sender=GCCCRP" + "&to=" + + MobileNo + "&body=" + + generatedMessage + "&entityid=" + entityId + "&templateid=" + templateId; + + System.out.println("\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); + + System.out.println("OTP sent successfully!"); + + } catch (Exception e) { + System.out.print("ERROR---: " + e); + bodyMessage = "Error"; + } + + HttpSession session = request.getSession(); + session.setAttribute("otp", otp); + session.setAttribute("mobileNo", mobileNo); + return bodyMessage; + } + + // @GetMapping("/checkwithdraw") + // public List> checkWithdrawByMobileNumber(@RequestParam + // String mobile_num){ + // + // return gcservice.checkwithdraw(mobile_num); + // } + + @GetMapping("/checkwithdraw") + public List> checkWithdrawByMobileNumber(@RequestParam String mobile_num) { + + List refnums = gcservice.getrefnums(mobile_num); + System.out.println("refnums=" + refnums); + + Map wrapper = new HashMap<>(); + List> finalList = new ArrayList<>(); + + if (refnums.isEmpty()) { + wrapper.put("message", "Empty List"); + wrapper.put("status", "Success"); + return Collections.singletonList(wrapper); + } + + for (String ref : refnums) { + System.out.println("ref=" + ref); + Map data = gcservice.getfulldetailsdata(ref); + if (data != null && !data.isEmpty()) { + finalList.add(data); + } + } + + wrapper.put("data", finalList); + wrapper.put("message", "Complaint List"); + wrapper.put("status", "Success"); + + return Collections.singletonList(wrapper); + } + + @PostMapping("/withdraw") + public ResponseEntity withdraw(@RequestParam String id, @RequestParam String remarks) { + String saveStatus = gcservice.withdraw(id, remarks); + + if (saveStatus == null || saveStatus.equals("error")) { + return ResponseEntity.ok(Map.of( + "status", false, + "message", "failed", + "description", "Failed to withdraw the Complaint")); + } + + return ResponseEntity.ok(Map.of( + "status", true, + "message", "success", + "description", "Application withdrawn successfully", + "ref_id", saveStatus)); + } + } diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 4b6c65c..2f43901 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -8,7 +8,7 @@ app.title=GREEN COMMITTEE app.filebaseurl=https://gccservices.in spring.datasource.url=jdbc:mysql://gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306/green_committee -spring.datasource.username=root +spring.datasource.username=root spring.datasource.password=gcc-facial-password spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index da16dc0..b55e125 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,3 +1,3 @@ spring.application.name=greencommitte -spring.profiles.active=dev +spring.profiles.active=prod diff --git a/src/main/resources/templates/modules/home.html b/src/main/resources/templates/modules/home.html index c4f2646..ab0b7dd 100644 --- a/src/main/resources/templates/modules/home.html +++ b/src/main/resources/templates/modules/home.html @@ -1,159 +1,161 @@ + - -GCC Green Committee - - - - - - - - - - - - + + GCC Green Committee + + + + + + + + + + + + + - -
-
- - - - -
- GREATER CHENNAI CORPORATION -
- - - -
- - - - -
- - -
- - +
+
+ + + + +
+ GREATER CHENNAI CORPORATION +
+ + + +
+ + + + +
+ + +
+ + - - -
-
-

Green Committee Application Forms

-
-
- - -
-
- For Citizen Form (Public) -
-
- -
+ +
+
+

Green Committee Application Forms

- -
-
- For Department Form -
-
- +
+ + +
+
+ For Citizen Form (Public) +
+
+ +
-
- - -
-
- Check Status -
-
- + + +
+
+ For Department Form +
+
+ +
-
+ +
+
+ Check Status +
+
+ +
+
+
+
+ Check Pruning Status +
+
+ +
+
+ +
-
-
+
+ + + + + - - - - + + window.location.href = "https://erp.chennaicorporation.gov.in/pgr/"; + } + + \ No newline at end of file diff --git a/src/main/resources/templates/modules/public/form.html b/src/main/resources/templates/modules/public/form.html index d2f5b9b..4ccad71 100644 --- a/src/main/resources/templates/modules/public/form.html +++ b/src/main/resources/templates/modules/public/form.html @@ -384,12 +384,12 @@ Female Transgender -
+
@@ -457,6 +463,21 @@ -->
+ + +
+ + +
+ +
+ + +
@@ -489,7 +510,7 @@
-
+
@@ -727,6 +748,22 @@ let id = $(this).val(); let name = $("#complaintDropdown option:selected").data("name"); + if (name && name.toLowerCase() === "pruning") { + + // Hide second image + $("#c2image").closest(".col-md-6").hide(); + + // Remove required validation + $("#c2image").prop("required", false).val(""); + + } else { + + // Show second image + $("#c2image").closest(".col-md-6").show(); + + // Existing workflow + $("#c2image").prop("required", true); + } if (!id) { return; @@ -929,10 +966,10 @@ //const url = `https://gisgcc.chennaicorporation.gov.in/server/rest/services/GCCDepts/EDPMobile2025/ //FeatureServer/2/query?where=&objectIds=&time=&geometry={encodedGeometry}&geometryType=esriGeometryPoint&inSR=4326&defaultSR=4326&spatialRel=esriSpatialRelIntersects&distance=1&units=esriSRUnit_Meter&outFields=zone,ward&returnGeometry=false&f=geojson`; - const url = `https://gisgcc.chennaicorporation.gov.in/server/rest/services/GCCDepts/EDPMobile2025/FeatureServer/2/query?` + + const url = `https://gisgcc.chennaicorporation.gov.in/server/rest/services/GCCDepts/EDPMobile2025/FeatureServer/0/query?` + `where=&objectIds=&time=&geometry=${encodedGeometry}` + - `&geometryType=esriGeometryPoint&inSR=4326&defaultSR=4326&spatialRel=esriSpatialRelIntersects&distance=1` + - `&units=esriSRUnit_Meter&relationParam=&outFields=zone,ward` + + `&geometryType=esriGeometryPoint&inSR=4326&defaultSR=4326&spatialRel=esriSpatialRelIntersects&distance=25` + + `&units=esriSRUnit_Meter&relationParam=&outFields=region%2Cnew_zone%2C+new_ward%2Croad_id%2C+road_name%2Cgis_id%2Ctype` + `&returnGeometry=false&maxAllowableOffset=&geometryPrecision=&outSR=&havingClause=&gdbVersion=&historicMoment=` + `&returnDistinctValues=false&returnIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&orderByFields=` + `&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&multipatchOption=xyFootprint&resultOffset=` + @@ -940,6 +977,7 @@ `&timeReferenceUnknownClient=false&maxRecordCountFactor=&sqlFormat=none&resultType=&featureEncoding=esriDefault` + `&datumTransformation=&f=geojson`; + //console.log(url); fetch(url) @@ -951,13 +989,14 @@ }) .then(data => { - //console.log("GIS API Response:", data); + console.log("GIS API Response:", data); const features = data.features; if (features.length > 0) { const props = features[0].properties; - const zone = props.zone; - const ward = props.ward; + const zone = props.new_zone; + const ward = props.new_ward; + console.log("Zone:", zone, "Ward:", ward); // 👉 You can update form fields or DOM elements here @@ -972,7 +1011,73 @@ .catch(error => { console.error("Error fetching zone/ward:", error); }); + + + const streetSelect = document.getElementById("streetName"); + streetSelect.innerHTML = ""; + + const defaultOption = document.createElement("option"); + defaultOption.value = ""; + defaultOption.text = "-- Select Street --"; + streetSelect.appendChild(defaultOption); + + document.getElementById("streetId").value = ""; + + // Timeout mechanism: 1 seconds + const timeout = new Promise((_, reject) => + setTimeout(() => reject(new Error("Request timed out")), 1000) + ); + + // Actual fetch + const fetchRequest = fetch(url).then(res => res.json()); + + Promise.race([fetchRequest, timeout]) + .then(data => { + const features = data.features; + if (!features || features.length === 0) { + Swal.fire({ + icon: 'warning', + title: 'No Street Found', + text: 'Please select the nearby street.', + }); + return; + } + + streetsList = features.map(f => f.properties); //Save for use in dropdown + streetsList.forEach((props, index) => { + const option = document.createElement("option"); + option.value = index; + option.text = props.road_name; + streetSelect.appendChild(option); + }); + }) + .catch(err => { + console.error("Error fetching street:", err); + Swal.fire("Failed to load street data", '', 'error'); + }); + } + + document.getElementById("streetName").addEventListener("change", function () { + const selectedIndex = this.value; + console.log("heck") + console.log(selectedIndex); + + + if (selectedIndex !== "") { + const selectedStreet = streetsList[selectedIndex]; + console.log(selectedStreet); + + document.getElementById("streetId").value = selectedStreet.road_id; + + + + console.log("Selected street:", selectedStreet); + } else { + document.getElementById("streetId").value = ""; + + } + }); } $('#publicform').submit(function (e) { @@ -1071,6 +1176,13 @@ } const name = $('#pname').val(); + const streetName = $('#streetName option:selected').text(); + const street_id = $('#streetId').val(); + console.log("cfefefef"); + console.log(streetName); + console.log("Streetid"); + console.log(street_id); + // const streetName = $('#streetName').val(); const c1image = $('#c1image')[0]; @@ -1142,21 +1254,35 @@ formData.append("p_name", name); formData.append("source", "1"); + formData.append("address", streetName) formData.append("c1image", c1image); formData.append("c2image", c2image); formData.append("comp_details", JSON.stringify(compDetailsList)); + let complaintName = $("#complaintDropdown option:selected").data("name"); + let apiUrl = "/greencommittee/api/savepublicform"; + if (complaintName && + complaintName.trim().toLowerCase() === "pruning") { + + apiUrl = "/greencommittee/api/savepruningform"; + formData.append("StreetId", street_id); + + // Only one image for pruning + formData.delete("c2image"); + } + console.log(formData); + $.ajax({ - url: "/greencommittee/api/savepublicform", + url: apiUrl, method: "POST", data: formData, processData: false, contentType: false, success: function (response) { $('#pageLoader').hide(); - if (response.status) { + /*if (response.status) { Swal.fire({ icon: 'success', allowOutsideClick: false, @@ -1167,7 +1293,38 @@ window.location.href = "/greencommittee/home"; }); - } else { + }*/ + if (response.status) { + + if (complaintName && + complaintName.trim().toLowerCase() === "pruning") { + + Swal.fire({ + icon: 'success', + allowOutsideClick: false, + allowEscapeKey: false, + title: 'Complaint Registered Successfully', + html: 'Complaint Number: ' + response.complaintNumber + '' + }).then(() => { + window.location.href = "/greencommittee/home"; + }); + + } else { + + Swal.fire({ + icon: 'success', + allowOutsideClick: false, + allowEscapeKey: false, + title: 'Details are Saved Successfully', + html: 'Reference ID: ' + response.ref_id + '' + }).then(() => { + window.location.href = "/greencommittee/home"; + }); + + } + + } + else { $('#pageLoader').hide(); Swal.fire({ icon: 'error', diff --git a/src/test/java/com/gcc/greencommitte/GreencommitteApplicationTests.java b/src/test/java/com/gcc/greencommitte/GreencommitteApplicationTests.java deleted file mode 100644 index 6a5f476..0000000 --- a/src/test/java/com/gcc/greencommitte/GreencommitteApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.gcc.greencommitte; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class GreencommitteApplicationTests { - - @Test - void contextLoads() { - } - -}