Browse Source

implemented public section like pgr complaint

master
AJITHKUMAR12 3 months ago
parent
commit
3d5290ab39
  1. 176
      src/main/java/com/gcc/greencommitte/controller/Apicontroller.java
  2. 2
      src/main/resources/application.properties
  3. 28
      src/main/resources/templates/modules/home.html
  4. 185
      src/main/resources/templates/modules/public/form.html
  5. 13
      src/test/java/com/gcc/greencommitte/GreencommitteApplicationTests.java

176
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,7 +38,6 @@ import com.gcc.greencommitte.service.Greencommitteeservice;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
@RestController
@RequestMapping("/greencommittee/api")
public class Apicontroller {
@ -39,7 +48,6 @@ public class Apicontroller {
@Autowired
private Greencommitteeservice gcservice;
@GetMapping(value = "/sendOTP")
public String sendOtp(HttpServletRequest request, @RequestParam String mobileNo) {
@ -54,7 +62,8 @@ public class Apicontroller {
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="
String urlString = appConfig.getGetOtpUrl() + "from=GCCCRP" + "&key=" + key + "&sender=GCCCRP" + "&to="
+ MobileNo + "&body="
+ generatedMessage + "&entityid=" + entityId + "&templateid=" + templateId;
System.out.println("\n urlString---: " + urlString);
@ -204,26 +213,143 @@ public class Apicontroller {
// 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);
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"
));
"description", "Failed to save the details"));
}
return ResponseEntity.ok(Map.of(
"status", true,
"message", "success",
"description", "Details saved successfully",
"ref_id", saveStatus
));
"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<String, String> 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(
@ -259,31 +385,26 @@ public class Apicontroller {
// 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);
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"
));
"description", "Failed to save the details"));
}
return ResponseEntity.ok(Map.of(
"status", true,
"message", "success",
"description", "Details saved successfully",
"ref_id", saveStatus
));
"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()) {
@ -302,7 +423,8 @@ public class Apicontroller {
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="
String urlString = appConfig.getGetOtpUrl() + "from=GCCCRP" + "&key=" + key + "&sender=GCCCRP" + "&to="
+ MobileNo + "&body="
+ generatedMessage + "&entityid=" + entityId + "&templateid=" + templateId;
System.out.println("\n urlString---: " + urlString);
@ -327,9 +449,9 @@ public class Apicontroller {
return bodyMessage;
}
// @GetMapping("/checkwithdraw")
// public List<Map<String, Object>> checkWithdrawByMobileNumber(@RequestParam String mobile_num){
// public List<Map<String, Object>> checkWithdrawByMobileNumber(@RequestParam
// String mobile_num){
//
// return gcservice.checkwithdraw(mobile_num);
// }
@ -365,25 +487,21 @@ public class Apicontroller {
}
@PostMapping("/withdraw")
public ResponseEntity<?> withdraw(@RequestParam String id,@RequestParam String remarks)
{
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"
));
"description", "Failed to withdraw the Complaint"));
}
return ResponseEntity.ok(Map.of(
"status", true,
"message", "success",
"description", "Application withdrawn successfully",
"ref_id", saveStatus
));
"ref_id", saveStatus));
}
}

2
src/main/resources/application.properties

@ -1,3 +1,3 @@
spring.application.name=greencommitte
spring.profiles.active=dev
spring.profiles.active=prod

28
src/main/resources/templates/modules/home.html

@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>GCC Green Committee</title>
@ -52,7 +53,8 @@
padding: 10px;
display: none;
flex-direction: column;
z-index: 1000; /* Add z-index to bring the menu above other elements */
z-index: 1000;
/* Add z-index to bring the menu above other elements */
}
.menu-dropdown a {
@ -84,7 +86,8 @@
right: 0;
left: 0;
z-index: 1000; /* Add z-index to bring the menu above other elements */
z-index: 1000;
/* Add z-index to bring the menu above other elements */
}
}
@ -108,11 +111,10 @@
border-top-left-radius: 12px;
border-top-right-radius: 12px;
}
</style>
</head>
<body style="background-color: #ebf1fa;">
<!-- Header Start-->
@ -202,7 +204,7 @@
</div>
<!-- Withdraw Applications -->
<div class="row align-items-center">
<div class="row align-items-center mb-4">
<div class="col-md-5 pb-2 text-center text-md-right font-weight-bold">
Check Status
</div>
@ -212,6 +214,17 @@
</button>
</div>
</div>
<div class="row align-items-center mb-4">
<div class="col-md-5 pb-2 text-center text-md-right font-weight-bold">
Check Pruning Status
</div>
<div class="col-md-7">
<button type="button" class="btn btn-warning btn-block enhanced-btn" onclick="getpruning()">
<i class="fa fa-check-circle mr-2"></i>
Click Here to check pruning status
</button>
</div>
</div>
</div>
</div>
@ -245,7 +258,12 @@ function gotodept() {
function gotowithraw() {
window.location.href = '/greencommittee/withdrawpage';
}
function getpruning() {
window.location.href = "https://erp.chennaicorporation.gov.in/pgr/";
}
</script>
</body>
</html>

185
src/main/resources/templates/modules/public/form.html

@ -384,12 +384,12 @@
<input type="radio" name="gender" value="F" class="ms-3 ml-3"> Female
<input type="radio" name="gender" value="T" class="ms-3 ml-3"> Transgender
</div>
<div class="col-md-8">
<!--<div class="col-md-8">
<label class="form-label">Tree Land Location (Also click the street in Map)<span
class="text-danger">*</span></label>
<textarea class="form-control" id="address" name="address" maxlength="255"
placeholder="Type Tree Address Here" required></textarea>
</div>
</div>-->
</div>
<!-- <div class="row mb-3">
@ -425,14 +425,20 @@
<label for="longitude">Longitude<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="longitude" name="longitude" readonly>
</div>
<div class="col-md-3">
<div class="col-md-6">
<label for="streetName">Street<span class="text-danger">*</span></label>
<select id="streetName" name="streetName" class="form-control" required>
<option value="">Select Street</option>
</select>
</div>
<!-- <div class="col-md-3">
<label for="zone">Zone<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="zone" name="zone" required readonly>
</div>
<div class="col-md-3">
<label for="ward">Ward<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="ward" name="ward" required readonly>
</div>
</div>-->
</div>
@ -457,6 +463,21 @@
</div>
</div>-->
<div class="row mb-3">
<input type="hidden" id="streetId" name="streetId">
<!-- <div class="col-md-3">
<label for="streetId">Street Id</label>
<input type="text" class="form-control" id="streetId" readonly>
</div>-->
<div class="col-md-3">
<label for="zone">Zone<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="zone" name="zone" readonly>
</div>
<div class="col-md-3">
<label for="ward">Ward<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="ward" name="ward" readonly>
</div>
<!-- Left Side -->
<div class="col-md-4">
@ -489,7 +510,7 @@
</div>
<!-- Right Side -->
<div class="col-md-8">
<!--<div class="col-md-8">
<div class="alert alert-info mb-0 py-2">
<strong>Instructions:</strong><br>
@ -505,7 +526,7 @@
Click here to raise the complaint
</a>
</div>
</div>
</div>-->
</div>
@ -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";
});
}*/
if (response.status) {
if (complaintName &&
complaintName.trim().toLowerCase() === "pruning") {
Swal.fire({
icon: 'success',
allowOutsideClick: false,
allowEscapeKey: false,
title: 'Complaint Registered Successfully',
html: 'Complaint Number: <b>' + response.complaintNumber + '</b>'
}).then(() => {
window.location.href = "/greencommittee/home";
});
} else {
Swal.fire({
icon: 'success',
allowOutsideClick: false,
allowEscapeKey: false,
title: 'Details are Saved Successfully',
html: 'Reference ID: <b>' + response.ref_id + '</b>'
}).then(() => {
window.location.href = "/greencommittee/home";
});
}
}
else {
$('#pageLoader').hide();
Swal.fire({
icon: 'error',

13
src/test/java/com/gcc/greencommitte/GreencommitteApplicationTests.java

@ -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() {
}
}
Loading…
Cancel
Save