diff --git a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025124945_bird.jpg b/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025124945_bird.jpg deleted file mode 100644 index 82d0eb5..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025124945_bird.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025124945_duck-7406987.jpg b/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025124945_duck-7406987.jpg deleted file mode 100644 index 84ff232..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025124945_duck-7406987.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025130138_bird.jpg b/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025130138_bird.jpg deleted file mode 100644 index 82d0eb5..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025130138_bird.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025130138_joban-khangura-hG8B9pKiilw-unsplash.jpg b/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025130138_joban-khangura-hG8B9pKiilw-unsplash.jpg deleted file mode 100644 index 755d359..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025130138_joban-khangura-hG8B9pKiilw-unsplash.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025130247_bird.jpg b/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025130247_bird.jpg deleted file mode 100644 index 82d0eb5..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025130247_bird.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025130247_duck-7406987.jpg b/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025130247_duck-7406987.jpg deleted file mode 100644 index 84ff232..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025130247_duck-7406987.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025160944_sc1.jpeg b/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025160944_sc1.jpeg deleted file mode 100644 index bb6bae3..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025160944_sc1.jpeg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025161152_sc1.jpeg b/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025161152_sc1.jpeg deleted file mode 100644 index bb6bae3..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025161152_sc1.jpeg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025161603_sc1.jpeg b/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025161603_sc1.jpeg deleted file mode 100644 index bb6bae3..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025161603_sc1.jpeg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025161755_sc1.jpeg b/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025161755_sc1.jpeg deleted file mode 100644 index bb6bae3..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025161755_sc1.jpeg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025162323_sc1.jpeg b/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025162323_sc1.jpeg deleted file mode 100644 index bb6bae3..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025162323_sc1.jpeg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025162414_sc1.jpeg b/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025162414_sc1.jpeg deleted file mode 100644 index bb6bae3..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_27122025162414_sc1.jpeg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_29122025110136_sc1.jpeg b/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_29122025110136_sc1.jpeg deleted file mode 100644 index bb6bae3..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_29122025110136_sc1.jpeg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_29122025112848_sc1.jpeg b/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_29122025112848_sc1.jpeg deleted file mode 100644 index bb6bae3..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_29122025112848_sc1.jpeg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_29122025113046_sc1.jpeg b/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_29122025113046_sc1.jpeg deleted file mode 100644 index bb6bae3..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2025/12/comp_image1_29122025113046_sc1.jpeg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_02012026134533_sample1.jpg b/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_02012026134533_sample1.jpg deleted file mode 100644 index cedf558..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_02012026134533_sample1.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_02012026134650_sample1.jpg b/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_02012026134650_sample1.jpg deleted file mode 100644 index cedf558..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_02012026134650_sample1.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_02012026165041_newuser.jpg b/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_02012026165041_newuser.jpg deleted file mode 100644 index 46976d4..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_02012026165041_newuser.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_02012026165137_newuser.jpg b/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_02012026165137_newuser.jpg deleted file mode 100644 index 46976d4..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_02012026165137_newuser.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_02012026165232_newuser.jpg b/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_02012026165232_newuser.jpg deleted file mode 100644 index 46976d4..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_02012026165232_newuser.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026113726_MacBookPro14_-1.jpg b/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026113726_MacBookPro14_-1.jpg deleted file mode 100644 index e383eae..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026113726_MacBookPro14_-1.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026113726_sample1.jpg b/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026113726_sample1.jpg deleted file mode 100644 index cedf558..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026113726_sample1.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026115813_MacBookPro14_-1.jpg b/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026115813_MacBookPro14_-1.jpg deleted file mode 100644 index e383eae..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026115813_MacBookPro14_-1.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026115813_sample1.jpg b/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026115813_sample1.jpg deleted file mode 100644 index cedf558..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026115813_sample1.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026132432_MacBookPro14_-1.jpg b/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026132432_MacBookPro14_-1.jpg deleted file mode 100644 index e383eae..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026132432_MacBookPro14_-1.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026132432_sample1.jpg b/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026132432_sample1.jpg deleted file mode 100644 index cedf558..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_12012026132432_sample1.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_22012026125708_newuser.jpg b/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_22012026125708_newuser.jpg deleted file mode 100644 index 46976d4..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_22012026125708_newuser.jpg and /dev/null differ diff --git a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_22012026125832_newuser.jpg b/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_22012026125832_newuser.jpg deleted file mode 100644 index 46976d4..0000000 Binary files a/gcc_mobile_service_uploads/green_committee_files/2026/01/comp_image1_22012026125832_newuser.jpg and /dev/null differ diff --git a/src/main/java/com/gcc/greencommitte/controller/Apicontroller.java b/src/main/java/com/gcc/greencommitte/controller/Apicontroller.java index 197833e..22fc3ef 100644 --- a/src/main/java/com/gcc/greencommitte/controller/Apicontroller.java +++ b/src/main/java/com/gcc/greencommitte/controller/Apicontroller.java @@ -196,6 +196,7 @@ public class Apicontroller { @RequestParam MultipartFile c1image, @RequestParam MultipartFile c2image, @RequestParam String comp_details, + @RequestParam String streetName, @RequestParam String source) throws JsonMappingException, JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); @@ -215,7 +216,7 @@ 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); + remarks, c1imagePath, c2imagePath, compList, totalTreeCount, source, streetName); if (saveStatus == null || saveStatus.equals("error")) { return ResponseEntity.ok(Map.of( @@ -352,6 +353,127 @@ public class Apicontroller { } } + @PostMapping("/savedeptpruningform") + public ResponseEntity deptregisterComplaint( + @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("========== DEPT 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, @@ -368,6 +490,8 @@ public class Apicontroller { @RequestParam MultipartFile c1image, @RequestParam MultipartFile c2image, @RequestParam String comp_details, + @RequestParam String streetName, + @RequestParam String source) throws JsonMappingException, JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); @@ -387,7 +511,7 @@ 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); + longitude, zone, ward, remarks, c1imagePath, c2imagePath, compList, totalTreeCount, streetName, source); if (saveStatus == null || saveStatus.equals("error")) { return ResponseEntity.ok(Map.of( @@ -504,26 +628,21 @@ public class Apicontroller { "description", "Application withdrawn successfully", "ref_id", saveStatus)); } - - - //getpurninglist - + + // getpurninglist + @GetMapping("/getpurninglist") public List> getpurninglist() { - + return gcservice.getpurninglist(); - + } - @PostMapping("/generatepgrcomplaints") @ResponseBody - public ResponseEntity generatepgrcomplaints(String refid){ - + public ResponseEntity generatepgrcomplaints(String refid) { + return gcservice.generatepgrcomplaints(refid); } - - - - + } diff --git a/src/main/java/com/gcc/greencommitte/service/Greencommitteeservice.java b/src/main/java/com/gcc/greencommitte/service/Greencommitteeservice.java index a7ed0ea..2eb8e05 100644 --- a/src/main/java/com/gcc/greencommitte/service/Greencommitteeservice.java +++ b/src/main/java/com/gcc/greencommitte/service/Greencommitteeservice.java @@ -24,7 +24,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; - import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.InputStream; @@ -43,112 +42,112 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.gcc.greencommitte.config.AppConfig; - - @Service public class Greencommitteeservice { - + @Autowired private AppConfig appconfig; - + @Autowired - private JdbcTemplate jdbcTemplate; - + private JdbcTemplate jdbcTemplate; + private final Environment environment; - + public Greencommitteeservice(Environment environment) { - this.environment = environment; - } + this.environment = environment; + } public List> getCompNatureForPublic() { - String sql="SELECT * FROM comp_nature WHERE category='public' AND is_active=1 AND is_delete=0"; + String sql = "SELECT * FROM comp_nature WHERE category='public' AND is_active=1 AND is_delete=0"; try { - return jdbcTemplate.queryForList(sql); - } catch (Exception ex) { - ex.printStackTrace(); - return new ArrayList<>(); // return empty list on error - } + return jdbcTemplate.queryForList(sql); + } catch (Exception ex) { + ex.printStackTrace(); + return new ArrayList<>(); // return empty list on error + } } - + public List> getCompNatureForDept() { - String sql="SELECT * FROM comp_nature WHERE category='dept' AND is_active=1 AND is_delete=0"; + String sql = "SELECT * FROM comp_nature WHERE category='dept' AND is_active=1 AND is_delete=0"; try { - return jdbcTemplate.queryForList(sql); - } catch (Exception ex) { - ex.printStackTrace(); - return new ArrayList<>(); // return empty list on error - } + return jdbcTemplate.queryForList(sql); + } catch (Exception ex) { + ex.printStackTrace(); + return new ArrayList<>(); // return empty list on error + } } - + public List> getAllDepts() { - String sql="SELECT * FROM dept_master WHERE is_active=1 AND is_delete=0"; + String sql = "SELECT * FROM dept_master WHERE is_active=1 AND is_delete=0"; try { - return jdbcTemplate.queryForList(sql); - } catch (Exception ex) { - ex.printStackTrace(); - return new ArrayList<>(); // return empty list on error - } + return jdbcTemplate.queryForList(sql); + } catch (Exception ex) { + ex.printStackTrace(); + return new ArrayList<>(); // return empty list on error + } } - + public String fileUpload(MultipartFile file, String name) { - // Set the file path where you want to save it - String uploadDirectory = environment.getProperty("file.upload.directory.mobile"); - String serviceFolderName = environment.getProperty("green_committee_foldername"); - var year = DateTimeUtil.getCurrentYear(); - var month = DateTimeUtil.getCurrentMonth(); + // Set the file path where you want to save it + String uploadDirectory = environment.getProperty("file.upload.directory.mobile"); + String serviceFolderName = environment.getProperty("green_committee_foldername"); + var year = DateTimeUtil.getCurrentYear(); + var month = DateTimeUtil.getCurrentMonth(); - uploadDirectory = uploadDirectory + serviceFolderName + "/" + year + "/" + month; + uploadDirectory = uploadDirectory + serviceFolderName + "/" + year + "/" + month; - try { - // Create directory if it doesn't exist - Path directoryPath = Paths.get(uploadDirectory); - if (!Files.exists(directoryPath)) { - Files.createDirectories(directoryPath); - } + try { + // Create directory if it doesn't exist + Path directoryPath = Paths.get(uploadDirectory); + if (!Files.exists(directoryPath)) { + Files.createDirectories(directoryPath); + } - // Datetime string - String datetimetxt = DateTimeUtil.getCurrentDateTime(); - - // File name - String fileName = name + "_" + datetimetxt + "_" + file.getOriginalFilename(); - fileName = fileName.replaceAll("\\s+", ""); // Remove space on filename + // Datetime string + String datetimetxt = DateTimeUtil.getCurrentDateTime(); - String filePath = uploadDirectory + "/" + fileName; + // File name + String fileName = name + "_" + datetimetxt + "_" + file.getOriginalFilename(); + fileName = fileName.replaceAll("\\s+", ""); // Remove space on filename - String filepath_txt = "/" + serviceFolderName + "/" + year + "/" + month + "/" + fileName; + String filePath = uploadDirectory + "/" + fileName; - // Create a new Path object - Path path = Paths.get(filePath); + String filepath_txt = "/" + serviceFolderName + "/" + year + "/" + month + "/" + fileName; - // Get the bytes of the file - byte[] bytes = file.getBytes(); - - Files.write(path, bytes); + // Create a new Path object + Path path = Paths.get(filePath); - //System.out.println(filePath); - return filepath_txt; + // Get the bytes of the file + byte[] bytes = file.getBytes(); - } catch (IOException e) { - e.printStackTrace(); - return "Failed to save file " + file.getOriginalFilename(); - } - } + Files.write(path, bytes); + + // System.out.println(filePath); + return filepath_txt; + + } catch (IOException e) { + e.printStackTrace(); + return "Failed to save file " + file.getOriginalFilename(); + } + } @Transactional - public String savepublicform(String p_name, String ph_no, String gender, String address,String latitude,String longitude, String zone, String ward,String remarks, - String c1imagePath, String c2imagePath, List> compList,int totalTreeCount ,String source) { - - String cby="public"; - + public String savepublicform(String p_name, String ph_no, String gender, String address, String latitude, + String longitude, String zone, String ward, String remarks, + String c1imagePath, String c2imagePath, List> compList, int totalTreeCount, + String source, String streetName) { + + String cby = "public"; + String remarksVal = (remarks != null && !remarks.isEmpty()) ? remarks : null; - + String sql = "INSERT INTO reg_details (" - + "cby,p_name,ph_no,gender,address,zone,ward,total_trees,remarks,latitude,longitude,source " - + ") VALUES (?,?, ?, ?, ?, ?, ?, ?,?,?,?,?)"; - + + "cby,p_name,ph_no,gender,address,zone,ward,total_trees,remarks,latitude,longitude,source,street_name " + + ") VALUES (?,?, ?, ?, ?, ?, ?, ?,?,?,?,?,?)"; + KeyHolder keyHolder = new GeneratedKeyHolder(); - + try { int result = jdbcTemplate.update(connection -> { PreparedStatement ps = connection.prepareStatement(sql, new String[] { "id" }); @@ -161,63 +160,66 @@ public class Greencommitteeservice { ps.setString(7, ward); ps.setInt(8, totalTreeCount); ps.setString(9, remarksVal); - ps.setString(10,latitude ); - ps.setString(11,longitude); - ps.setString(12,source); + ps.setString(10, latitude); + ps.setString(11, longitude); + ps.setString(12, source); + ps.setString(13, streetName); return ps; }, keyHolder); - //return keyHolder.getKey().intValue(); + // return keyHolder.getKey().intValue(); if (result > 0) { - int generatedId = keyHolder.getKey().intValue(); - String prefix = "GC"+LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); - String refId = prefix + generatedId; - - String updateSql = "UPDATE reg_details SET ref_id = ? WHERE id = ? "; - jdbcTemplate.update(updateSql,refId, generatedId); - - String img1sql="INSERT INTO img_uploads (ref_id,img_path) VALUES (?,?)"; - jdbcTemplate.update(img1sql,refId, c1imagePath); - - String img2sql="INSERT INTO img_uploads (ref_id,img_path) VALUES (?,?)"; - jdbcTemplate.update(img2sql,refId, c2imagePath); - - String compSql = "INSERT INTO complaint_details (ref_id, comp_nature_id, no_of_trees) " - + "VALUES (?, ?, ?)"; - - for (Map item : compList) { - int compNatureId = Integer.parseInt(item.get("id").toString()); - int noOfTrees = Integer.parseInt(item.get("count").toString()); - - jdbcTemplate.update(compSql, refId, compNatureId, noOfTrees); - } - - return refId; - } - //return "error"; + int generatedId = keyHolder.getKey().intValue(); + String prefix = "GC" + LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); + String refId = prefix + generatedId; + + String updateSql = "UPDATE reg_details SET ref_id = ? WHERE id = ? "; + jdbcTemplate.update(updateSql, refId, generatedId); + + String img1sql = "INSERT INTO img_uploads (ref_id,img_path) VALUES (?,?)"; + jdbcTemplate.update(img1sql, refId, c1imagePath); + + String img2sql = "INSERT INTO img_uploads (ref_id,img_path) VALUES (?,?)"; + jdbcTemplate.update(img2sql, refId, c2imagePath); + + String compSql = "INSERT INTO complaint_details (ref_id, comp_nature_id, no_of_trees) " + + "VALUES (?, ?, ?)"; + + for (Map item : compList) { + int compNatureId = Integer.parseInt(item.get("id").toString()); + int noOfTrees = Integer.parseInt(item.get("count").toString()); + + jdbcTemplate.update(compSql, refId, compNatureId, noOfTrees); + } + + return refId; + } + // return "error"; } catch (Exception e) { e.printStackTrace(); } return "error"; - + } @Transactional public String savedeptform(String dept_id, String dept_name, String ph_no, String designation, String govt_type, - String address,String latitude,String longitude, String zone, String ward, String remarks, String c1imagePath, String c2imagePath, - List> compList, int totalTreeCount,String source) { + String address, String latitude, String longitude, String zone, String ward, String remarks, + String c1imagePath, String c2imagePath, + List> compList, int totalTreeCount, String streetName, String source) { - - String cby="department"; + String cby = "department"; int deptIdInt = Integer.parseInt(dept_id); - + System.out.println("address = " + address); + System.out.println("streetName = " + streetName); + String remarksVal = (remarks != null && !remarks.isEmpty()) ? remarks : null; - + String sql = "INSERT INTO reg_details (" - + "cby,dept_id,dept_name,govt_type,designation,ph_no,address,zone,ward,total_trees,remarks,latitude,longitude,source " - + ") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - + + "cby,dept_id,dept_name,govt_type,designation,ph_no,address,zone,ward,total_trees,remarks,latitude,longitude,street_name,source " + + ") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + KeyHolder keyHolder = new GeneratedKeyHolder(); - + try { int result = jdbcTemplate.update(connection -> { PreparedStatement ps = connection.prepareStatement(sql, new String[] { "id" }); @@ -232,388 +234,378 @@ public class Greencommitteeservice { ps.setString(9, ward); ps.setInt(10, totalTreeCount); ps.setString(11, remarksVal); - ps.setString(12,latitude ); - ps.setString(13,longitude); - ps.setString(14,source); + ps.setString(12, latitude); + ps.setString(13, longitude); + ps.setString(14, streetName); + ps.setString(15, source); + return ps; }, keyHolder); - //return keyHolder.getKey().intValue(); + // return keyHolder.getKey().intValue(); if (result > 0) { - int generatedId = keyHolder.getKey().intValue(); - String prefix = "GC"+LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); - String refId = prefix + generatedId; - - String updateSql = "UPDATE reg_details SET ref_id = ? WHERE id = ? "; - jdbcTemplate.update(updateSql,refId, generatedId); - - String img1sql="INSERT INTO img_uploads (ref_id,img_path) VALUES (?,?)"; - jdbcTemplate.update(img1sql,refId, c1imagePath); - - String img2sql="INSERT INTO img_uploads (ref_id,img_path) VALUES (?,?)"; - jdbcTemplate.update(img2sql,refId, c2imagePath); - - String compSql = "INSERT INTO complaint_details (ref_id, comp_nature_id, no_of_trees) " - + "VALUES (?, ?, ?)"; - - for (Map item : compList) { - int compNatureId = Integer.parseInt(item.get("id").toString()); - int noOfTrees = Integer.parseInt(item.get("count").toString()); - - jdbcTemplate.update(compSql, refId, compNatureId, noOfTrees); - } - - return refId; - } - //return "error"; + int generatedId = keyHolder.getKey().intValue(); + String prefix = "GC" + LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); + String refId = prefix + generatedId; + + String updateSql = "UPDATE reg_details SET ref_id = ? WHERE id = ? "; + jdbcTemplate.update(updateSql, refId, generatedId); + + String img1sql = "INSERT INTO img_uploads (ref_id,img_path) VALUES (?,?)"; + jdbcTemplate.update(img1sql, refId, c1imagePath); + + String img2sql = "INSERT INTO img_uploads (ref_id,img_path) VALUES (?,?)"; + jdbcTemplate.update(img2sql, refId, c2imagePath); + + String compSql = "INSERT INTO complaint_details (ref_id, comp_nature_id, no_of_trees) " + + "VALUES (?, ?, ?)"; + + for (Map item : compList) { + int compNatureId = Integer.parseInt(item.get("id").toString()); + int noOfTrees = Integer.parseInt(item.get("count").toString()); + + jdbcTemplate.update(compSql, refId, compNatureId, noOfTrees); + } + + return refId; + } + // return "error"; } catch (Exception e) { e.printStackTrace(); } return "error"; } - + @Transactional - public List> findByMobileNo(String mobileNo){ - String sqlQuery = "select id from reg_details where ph_no =?"; - System.out.println(sqlQuery); - return jdbcTemplate.queryForList(sqlQuery,mobileNo); - } - -// public List> checkwithdraw(String mobile_num) { -// -// String sql="SELECT rd.ref_id " -// + " FROM reg_details rd " -// + " WHERE rd.ph_no = ? AND is_active=1 " -// + " AND NOT EXISTS ( " -// + " SELECT 1 " -// + " FROM inspection_data id " -// + " WHERE id.ref_id = rd.ref_id AND id.isactive=1 " -// + " )"; -// -// List refIds=jdbcTemplate.query(sql,new Object[]{mobile_num},(rs, rowNum) -> rs.getString("ref_id")); -// Map wrapper = new HashMap<>(); -// List> dataList = new ArrayList<>(); -// -// if(!refIds.isEmpty()) { -// -// for (String refId : refIds) { -// -// Map fullData = getfulldetailsdata(refId); -// -// if (fullData != null && !fullData.isEmpty()) { -// dataList.add((Map) fullData.get("data")); -// } -// } -// -// wrapper.put("data", dataList); -// wrapper.put("message", "Complaint List"); -// wrapper.put("status", "Success"); -// -// return Collections.singletonList(wrapper); -// -// } -// else { -// -// -// wrapper.put("message", "Empty List"); -// wrapper.put("status", "Success"); -// -// return Collections.singletonList(wrapper); -// -// } -// -// } + public List> findByMobileNo(String mobileNo) { + String sqlQuery = "select id from reg_details where ph_no =?"; + System.out.println(sqlQuery); + return jdbcTemplate.queryForList(sqlQuery, mobileNo); + } + + // public List> checkwithdraw(String mobile_num) { + // + // String sql="SELECT rd.ref_id " + // + " FROM reg_details rd " + // + " WHERE rd.ph_no = ? AND is_active=1 " + // + " AND NOT EXISTS ( " + // + " SELECT 1 " + // + " FROM inspection_data id " + // + " WHERE id.ref_id = rd.ref_id AND id.isactive=1 " + // + " )"; + // + // List refIds=jdbcTemplate.query(sql,new Object[]{mobile_num},(rs, + // rowNum) -> rs.getString("ref_id")); + // Map wrapper = new HashMap<>(); + // List> dataList = new ArrayList<>(); + // + // if(!refIds.isEmpty()) { + // + // for (String refId : refIds) { + // + // Map fullData = getfulldetailsdata(refId); + // + // if (fullData != null && !fullData.isEmpty()) { + // dataList.add((Map) fullData.get("data")); + // } + // } + // + // wrapper.put("data", dataList); + // wrapper.put("message", "Complaint List"); + // wrapper.put("status", "Success"); + // + // return Collections.singletonList(wrapper); + // + // } + // else { + // + // + // wrapper.put("message", "Empty List"); + // wrapper.put("status", "Success"); + // + // return Collections.singletonList(wrapper); + // + // } + // + // } public Map getfulldetailsdata(String refId) { Map response = new HashMap<>(); - // 1 — Application details - Map app = jdbcTemplate.queryForMap( - "SELECT *,DATE_FORMAT(cdate, '%d-%m-%Y %l:%i %p') as r_Cdate,IFNULL(reinspection_id, '') AS com_reinspection_id FROM reg_details WHERE ref_id=?", - refId - ); - - // 2 — Complaint details (grouped) - List> complaints = jdbcTemplate.queryForList( - "SELECT cn.name AS nature, SUM(cd.no_of_trees) AS count " + - "FROM complaint_details cd JOIN comp_nature cn ON cn.id=cd.comp_nature_id " + - "WHERE cd.ref_id=? GROUP BY cn.name", refId - ); - - String compDetails = complaints.stream() - .map(c -> c.get("nature") + "-" + c.get("count")) - .collect(Collectors.joining(",")); - - // 3 — Complaint images - List> imagePaths = - jdbcTemplate.queryForList( - "SELECT img_path FROM img_uploads WHERE ref_id=? AND is_active=1", - new Object[]{refId} - ).stream() - .map(row -> { - Map img = new HashMap<>(); - img.put( - "img_path", - appconfig.getFilebaseurl() + "/gccofficialapp/files" + row.get("img_path").toString() - ); - return img; - }) - .collect(Collectors.toList()); - - app.put("complaints", complaints); - app.put("comp_details", compDetails); - app.put("image_paths", imagePaths); - - List> inspectionList = new ArrayList<>(); - - String sql = - "SELECT id.*, um.name AS inspector_name, " + - " DATE_FORMAT(id.cdate, '%d-%m-%Y %l:%i %p') AS f_Cdate " + - "FROM inspection_data id " + - "LEFT JOIN user_maping um ON um.userid = id.cby " + - "INNER JOIN ( " + - " SELECT inspection_by, MAX(cdate) AS latest_date " + - " FROM inspection_data " + - " WHERE ref_id = ? AND isactive = 1 " + - " GROUP BY inspection_by " + - ") latest ON id.inspection_by = latest.inspection_by " + - " AND id.cdate = latest.latest_date " + - "WHERE id.ref_id = ? AND id.isactive = 1 " + - "ORDER BY FIELD(id.inspection_by, 'GCC', 'NGO', 'TNFD')"; - - List> rows = jdbcTemplate.queryForList( - sql, refId, refId - ); - - - for (Map row : rows) { - - Integer inspId = (Integer) row.get("inspection_data_id"); - - // 4a — Recommendation details - List> recommend = jdbcTemplate.queryForList( - "SELECT rm.name, itd.nooftrees AS count " + - "FROM inspection_tree_data itd " + - "JOIN inspection_recommend_master rm ON rm.rid = itd.action " + - "WHERE itd.inspection_data_id=? AND itd.isactive=1", - inspId - ); - - row.put("recommendations", recommend); - List imgs = new ArrayList<>(); - if (row.get("file_1") != null) { - imgs.add(appconfig.getFilebaseurl() + "/gccofficialapp/files" + row.get("file_1").toString()); - } - if (row.get("file_2") != null) { - imgs.add(appconfig.getFilebaseurl() + "/gccofficialapp/files" + row.get("file_2").toString()); - } - if (row.get("file_3") != null) { - imgs.add(appconfig.getFilebaseurl() + "/gccofficialapp/files" + row.get("file_3").toString()); - } - - row.put("images", imgs); - - inspectionList.add(row); - } - - app.put("inspections", inspectionList); - - - String reSql = - "SELECT r.id AS reins_id, r.committee_action, r.remarks AS reins_remarks, " + - " DATE_FORMAT(r.cdate, '%d-%m-%Y %l:%i %p') AS reins_date, " + - " cm.event_name, DATE_FORMAT(cm.event_date, '%d-%m-%Y') AS event_date, crm.name as ins_name " + - "FROM reinspection r " + - "LEFT JOIN create_meeting cm ON cm.id = r.meeting_id " + - " LEFT JOIN committee_recommend_master crm ON crm.id=r.committee_action " + - "WHERE r.ref_id = ? AND r.isactive = 1 " + - "ORDER BY r.id DESC"; - - List> reinspectionList = jdbcTemplate.queryForList(reSql, refId); - - app.put("reinspections", reinspectionList); - - Map c1 = null; - - List> committeeList = jdbcTemplate.queryForList( - "SELECT cd.*, DATE_FORMAT(cd.cdate, '%d-%m-%Y %l:%i %p') AS c_Cdate, " + - "cm.event_name AS meeting_name, cm.event_date AS meeting_date " + - "FROM committee_data cd " + - "LEFT JOIN create_meeting cm ON cm.id = cd.meeting_id " + - "WHERE cd.ref_id = ? AND cd.isactive = 1", - refId - ); - - if (!committeeList.isEmpty()) { - c1 = committeeList.get(0); - - List> com_complaints = jdbcTemplate.queryForList( - "SELECT crm.name AS nature, SUM(ctd.nooftrees) AS count " + - "FROM committee_tree_data ctd " + - "JOIN committee_recommend_master crm ON crm.id = ctd.committee_action " + - "WHERE ctd.ref_id = ? " + - "GROUP BY crm.name", - refId - ); - - c1.put("com_complaints", com_complaints); - } - - // IMPORTANT: always put committee key (even if null) - app.put("committee", c1); - - - //response.put("data", app); - - return app; + // 1 — Application details + Map app = jdbcTemplate.queryForMap( + "SELECT *,DATE_FORMAT(cdate, '%d-%m-%Y %l:%i %p') as r_Cdate,IFNULL(reinspection_id, '') AS com_reinspection_id FROM reg_details WHERE ref_id=?", + refId); + + // 2 — Complaint details (grouped) + List> complaints = jdbcTemplate.queryForList( + "SELECT cn.name AS nature, SUM(cd.no_of_trees) AS count " + + "FROM complaint_details cd JOIN comp_nature cn ON cn.id=cd.comp_nature_id " + + "WHERE cd.ref_id=? GROUP BY cn.name", + refId); + + String compDetails = complaints.stream() + .map(c -> c.get("nature") + "-" + c.get("count")) + .collect(Collectors.joining(",")); + + // 3 — Complaint images + List> imagePaths = jdbcTemplate.queryForList( + "SELECT img_path FROM img_uploads WHERE ref_id=? AND is_active=1", + new Object[] { refId }).stream() + .map(row -> { + Map img = new HashMap<>(); + img.put( + "img_path", + appconfig.getFilebaseurl() + "/gccofficialapp/files" + row.get("img_path").toString()); + return img; + }) + .collect(Collectors.toList()); + + app.put("complaints", complaints); + app.put("comp_details", compDetails); + app.put("image_paths", imagePaths); + + List> inspectionList = new ArrayList<>(); + + String sql = "SELECT id.*, um.name AS inspector_name, " + + " DATE_FORMAT(id.cdate, '%d-%m-%Y %l:%i %p') AS f_Cdate " + + "FROM inspection_data id " + + "LEFT JOIN user_maping um ON um.userid = id.cby " + + "INNER JOIN ( " + + " SELECT inspection_by, MAX(cdate) AS latest_date " + + " FROM inspection_data " + + " WHERE ref_id = ? AND isactive = 1 " + + " GROUP BY inspection_by " + + ") latest ON id.inspection_by = latest.inspection_by " + + " AND id.cdate = latest.latest_date " + + "WHERE id.ref_id = ? AND id.isactive = 1 " + + "ORDER BY FIELD(id.inspection_by, 'GCC', 'NGO', 'TNFD')"; + + List> rows = jdbcTemplate.queryForList( + sql, refId, refId); + + for (Map row : rows) { + + Integer inspId = (Integer) row.get("inspection_data_id"); + + // 4a — Recommendation details + List> recommend = jdbcTemplate.queryForList( + "SELECT rm.name, itd.nooftrees AS count " + + "FROM inspection_tree_data itd " + + "JOIN inspection_recommend_master rm ON rm.rid = itd.action " + + "WHERE itd.inspection_data_id=? AND itd.isactive=1", + inspId); + + row.put("recommendations", recommend); + List imgs = new ArrayList<>(); + if (row.get("file_1") != null) { + imgs.add(appconfig.getFilebaseurl() + "/gccofficialapp/files" + row.get("file_1").toString()); + } + if (row.get("file_2") != null) { + imgs.add(appconfig.getFilebaseurl() + "/gccofficialapp/files" + row.get("file_2").toString()); + } + if (row.get("file_3") != null) { + imgs.add(appconfig.getFilebaseurl() + "/gccofficialapp/files" + row.get("file_3").toString()); + } + + row.put("images", imgs); + + inspectionList.add(row); + } + + app.put("inspections", inspectionList); + + String reSql = "SELECT r.id AS reins_id, r.committee_action, r.remarks AS reins_remarks, " + + " DATE_FORMAT(r.cdate, '%d-%m-%Y %l:%i %p') AS reins_date, " + + " cm.event_name, DATE_FORMAT(cm.event_date, '%d-%m-%Y') AS event_date, crm.name as ins_name " + + "FROM reinspection r " + + "LEFT JOIN create_meeting cm ON cm.id = r.meeting_id " + + " LEFT JOIN committee_recommend_master crm ON crm.id=r.committee_action " + + "WHERE r.ref_id = ? AND r.isactive = 1 " + + "ORDER BY r.id DESC"; + + List> reinspectionList = jdbcTemplate.queryForList(reSql, refId); + + app.put("reinspections", reinspectionList); + + Map c1 = null; + + List> committeeList = jdbcTemplate.queryForList( + "SELECT cd.*, DATE_FORMAT(cd.cdate, '%d-%m-%Y %l:%i %p') AS c_Cdate, " + + "cm.event_name AS meeting_name, cm.event_date AS meeting_date " + + "FROM committee_data cd " + + "LEFT JOIN create_meeting cm ON cm.id = cd.meeting_id " + + "WHERE cd.ref_id = ? AND cd.isactive = 1", + refId); + + if (!committeeList.isEmpty()) { + c1 = committeeList.get(0); + + List> com_complaints = jdbcTemplate.queryForList( + "SELECT crm.name AS nature, SUM(ctd.nooftrees) AS count " + + "FROM committee_tree_data ctd " + + "JOIN committee_recommend_master crm ON crm.id = ctd.committee_action " + + "WHERE ctd.ref_id = ? " + + "GROUP BY crm.name", + refId); + + c1.put("com_complaints", com_complaints); + } + + // IMPORTANT: always put committee key (even if null) + app.put("committee", c1); + + // response.put("data", app); + + return app; } - - + public List getrefnums(String mobile_num) { - try { + try { - String sql="SELECT ref_id " + String sql = "SELECT ref_id " + " FROM reg_details " + " WHERE ph_no = ?"; - - System.out.println(sql); - return jdbcTemplate.query(sql,new Object[]{mobile_num},(rs, rowNum) -> rs.getString("ref_id")); + System.out.println(sql); + + return jdbcTemplate.query(sql, new Object[] { mobile_num }, (rs, rowNum) -> rs.getString("ref_id")); - } catch (Exception e) { - System.err.println("Error in getrefnums(): " + e.getMessage()); - e.printStackTrace(); - return Collections.emptyList(); - } + } catch (Exception e) { + System.err.println("Error in getrefnums(): " + e.getMessage()); + e.printStackTrace(); + return Collections.emptyList(); + } } - - -// public Map getlistdata(String ref) { -// -// Map regDetails = getRegDetails(ref); -// -// List> compDetails = getComplaintDetails(ref); -// -// regDetails.put("comp_details", compDetails); -// -// -// -// String linecompDetails = compDetails.stream() -// .map(c -> c.get("nature") + "-" + c.get("count")) -// .collect(Collectors.joining(",")); -// -// List> inspectionList = new ArrayList<>(); -// -// String sql = -// "SELECT id.*, um.name AS inspector_name, " + -// " DATE_FORMAT(id.cdate, '%d-%m-%Y %l:%i %p') AS f_Cdate " + -// "FROM inspection_data id " + -// "LEFT JOIN user_maping um ON um.userid = id.cby " + -// "INNER JOIN ( " + -// " SELECT inspection_by, MAX(cdate) AS latest_date " + -// " FROM inspection_data " + -// " WHERE ref_id = ? AND isactive = 1 " + -// " GROUP BY inspection_by " + -// ") latest ON id.inspection_by = latest.inspection_by " + -// " AND id.cdate = latest.latest_date " + -// "WHERE id.ref_id = ? AND id.isactive = 1 " + -// "ORDER BY FIELD(id.inspection_by, 'GCC', 'NGO', 'TNFD')"; -// -// List> rows = jdbcTemplate.queryForList( -// sql, ref, ref -// ); -// -// -// for (Map row : rows) { -// -// Integer inspId = (Integer) row.get("inspection_data_id"); -// -// // 4a — Recommendation details -// List> recommend = jdbcTemplate.queryForList( -// "SELECT rm.name, itd.nooftrees AS count " + -// "FROM inspection_tree_data itd " + -// "JOIN inspection_recommend_master rm ON rm.rid = itd.action " + -// "WHERE itd.inspection_data_id=? AND itd.isactive=1", -// inspId -// ); -// -// row.put("recommendations", recommend); -// -// inspectionList.add(row); -// } -// -// regDetails.put("inspections", inspectionList); -// -// -// String reSql = -// "SELECT r.id AS reins_id, r.committee_action, r.remarks AS reins_remarks, " + -// " DATE_FORMAT(r.cdate, '%d-%m-%Y %l:%i %p') AS reins_date, " + -// " cm.event_name, DATE_FORMAT(cm.event_date, '%d-%m-%Y') AS event_date, crm.name as ins_name " + -// "FROM reinspection r " + -// "LEFT JOIN create_meeting cm ON cm.id = r.meeting_id " + -// " LEFT JOIN committee_recommend_master crm ON crm.id=r.committee_action " + -// "WHERE r.ref_id = ? AND r.isactive = 1 " + -// "ORDER BY r.id DESC"; -// -// List> reinspectionList = jdbcTemplate.queryForList(reSql, ref); -// -// regDetails.put("reinspections", reinspectionList); -// -// Map c1 = null; -// -// List> committeeList = jdbcTemplate.queryForList( -// "SELECT cd.*, DATE_FORMAT(cd.cdate, '%d-%m-%Y %l:%i %p') AS c_Cdate, " + -// "cm.event_name AS meeting_name, cm.event_date AS meeting_date " + -// "FROM committee_data cd " + -// "LEFT JOIN create_meeting cm ON cm.id = cd.meeting_id " + -// "WHERE cd.ref_id = ? AND cd.isactive = 1", -// ref -// ); -// -// if (!committeeList.isEmpty()) { -// c1 = committeeList.get(0); -// -// List> com_complaints = jdbcTemplate.queryForList( -// "SELECT crm.name AS nature, SUM(ctd.nooftrees) AS count " + -// "FROM committee_tree_data ctd " + -// "JOIN committee_recommend_master crm ON crm.id = ctd.committee_action " + -// "WHERE ctd.ref_id = ? " + -// "GROUP BY crm.name", -// ref -// ); -// -// c1.put("com_complaints", com_complaints); -// } -// -// // IMPORTANT: always put committee key (even if null) -// regDetails.put("committee", c1); -// -// -// return regDetails; -// } -// -// public Map getRegDetails(String ref) { -// String sql = "SELECT * FROM reg_details WHERE is_active = 1 AND ref_id = ?"; -// return jdbcTemplate.queryForMap(sql, ref); -// } -// -// public List> getComplaintDetails(String ref) { -// -// String sql = "SELECT cn.name AS nature, SUM(cd.no_of_trees) AS total_trees " + -// "FROM complaint_details cd " + -// "JOIN comp_nature cn ON cn.id = cd.comp_nature_id " + -// "WHERE cd.is_active = 1 AND cd.ref_id = ? " + -// "GROUP BY cn.name"; -// -// return jdbcTemplate.queryForList(sql, ref); -// } - + + // public Map getlistdata(String ref) { + // + // Map regDetails = getRegDetails(ref); + // + // List> compDetails = getComplaintDetails(ref); + // + // regDetails.put("comp_details", compDetails); + // + // + // + // String linecompDetails = compDetails.stream() + // .map(c -> c.get("nature") + "-" + c.get("count")) + // .collect(Collectors.joining(",")); + // + // List> inspectionList = new ArrayList<>(); + // + // String sql = + // "SELECT id.*, um.name AS inspector_name, " + + // " DATE_FORMAT(id.cdate, '%d-%m-%Y %l:%i %p') AS f_Cdate " + + // "FROM inspection_data id " + + // "LEFT JOIN user_maping um ON um.userid = id.cby " + + // "INNER JOIN ( " + + // " SELECT inspection_by, MAX(cdate) AS latest_date " + + // " FROM inspection_data " + + // " WHERE ref_id = ? AND isactive = 1 " + + // " GROUP BY inspection_by " + + // ") latest ON id.inspection_by = latest.inspection_by " + + // " AND id.cdate = latest.latest_date " + + // "WHERE id.ref_id = ? AND id.isactive = 1 " + + // "ORDER BY FIELD(id.inspection_by, 'GCC', 'NGO', 'TNFD')"; + // + // List> rows = jdbcTemplate.queryForList( + // sql, ref, ref + // ); + // + // + // for (Map row : rows) { + // + // Integer inspId = (Integer) row.get("inspection_data_id"); + // + // // 4a — Recommendation details + // List> recommend = jdbcTemplate.queryForList( + // "SELECT rm.name, itd.nooftrees AS count " + + // "FROM inspection_tree_data itd " + + // "JOIN inspection_recommend_master rm ON rm.rid = itd.action " + + // "WHERE itd.inspection_data_id=? AND itd.isactive=1", + // inspId + // ); + // + // row.put("recommendations", recommend); + // + // inspectionList.add(row); + // } + // + // regDetails.put("inspections", inspectionList); + // + // + // String reSql = + // "SELECT r.id AS reins_id, r.committee_action, r.remarks AS reins_remarks, " + + // " DATE_FORMAT(r.cdate, '%d-%m-%Y %l:%i %p') AS reins_date, " + + // " cm.event_name, DATE_FORMAT(cm.event_date, '%d-%m-%Y') AS event_date, + // crm.name as ins_name " + + // "FROM reinspection r " + + // "LEFT JOIN create_meeting cm ON cm.id = r.meeting_id " + + // " LEFT JOIN committee_recommend_master crm ON crm.id=r.committee_action " + + // "WHERE r.ref_id = ? AND r.isactive = 1 " + + // "ORDER BY r.id DESC"; + // + // List> reinspectionList = jdbcTemplate.queryForList(reSql, + // ref); + // + // regDetails.put("reinspections", reinspectionList); + // + // Map c1 = null; + // + // List> committeeList = jdbcTemplate.queryForList( + // "SELECT cd.*, DATE_FORMAT(cd.cdate, '%d-%m-%Y %l:%i %p') AS c_Cdate, " + + // "cm.event_name AS meeting_name, cm.event_date AS meeting_date " + + // "FROM committee_data cd " + + // "LEFT JOIN create_meeting cm ON cm.id = cd.meeting_id " + + // "WHERE cd.ref_id = ? AND cd.isactive = 1", + // ref + // ); + // + // if (!committeeList.isEmpty()) { + // c1 = committeeList.get(0); + // + // List> com_complaints = jdbcTemplate.queryForList( + // "SELECT crm.name AS nature, SUM(ctd.nooftrees) AS count " + + // "FROM committee_tree_data ctd " + + // "JOIN committee_recommend_master crm ON crm.id = ctd.committee_action " + + // "WHERE ctd.ref_id = ? " + + // "GROUP BY crm.name", + // ref + // ); + // + // c1.put("com_complaints", com_complaints); + // } + // + // // IMPORTANT: always put committee key (even if null) + // regDetails.put("committee", c1); + // + // + // return regDetails; + // } + // + // public Map getRegDetails(String ref) { + // String sql = "SELECT * FROM reg_details WHERE is_active = 1 AND ref_id = ?"; + // return jdbcTemplate.queryForMap(sql, ref); + // } + // + // public List> getComplaintDetails(String ref) { + // + // String sql = "SELECT cn.name AS nature, SUM(cd.no_of_trees) AS total_trees " + // + + // "FROM complaint_details cd " + + // "JOIN comp_nature cn ON cn.id = cd.comp_nature_id " + + // "WHERE cd.is_active = 1 AND cd.ref_id = ? " + + // "GROUP BY cn.name"; + // + // return jdbcTemplate.queryForList(sql, ref); + // } @Transactional public String withdraw(String id, String remarks) { - - String sql="UPDATE reg_details SET is_active=0,is_delete=1,is_withdraw=1,withdraw_remarks=?,withdraw_date=NOW() WHERE id=?"; - + + String sql = "UPDATE reg_details SET is_active=0,is_delete=1,is_withdraw=1,withdraw_remarks=?,withdraw_date=NOW() WHERE id=?"; + try { jdbcTemplate.update(sql, remarks, id); return "success"; @@ -622,13 +614,12 @@ public class Greencommitteeservice { e.printStackTrace(); return "error"; } - + } - - -public List> getpurninglist() { - - String sql=" SELECT " + + public List> getpurninglist() { + + String sql = " SELECT " + " r.ref_id,r.cby, " + " r.p_name, dm.name as deptname," + " r.dept_name," @@ -674,22 +665,20 @@ public List> getpurninglist() { + " WHERE cd.ref_id = r.ref_id " + " AND cd.comp_nature_id IN (1,3) " + ") "; - - try { - return jdbcTemplate.queryForList(sql); - } catch (Exception e) { - e.printStackTrace(); - return Collections.emptyList(); - } + + try { + return jdbcTemplate.queryForList(sql); + } catch (Exception e) { + e.printStackTrace(); + return Collections.emptyList(); } - - + } public ResponseEntity generatepgrcomplaints(String refid) { - + try { - - String sql=" SELECT " + + String sql = " SELECT " + " r.ref_id,r.cby, " + " r.p_name,dm.name as deptname, " + " r.dept_name," @@ -698,7 +687,7 @@ public List> getpurninglist() { + " r.gender, " + " r.latitude, " + " r.longitude, " - + " r.streetid,r.remarks, " + + " r.streetid,r.remarks, " + " ( " + " SELECT cd.comp_nature_id " + " FROM complaint_details cd " @@ -727,292 +716,279 @@ public List> getpurninglist() { + " WHERE cd.ref_id = r.ref_id " + " AND cd.comp_nature_id IN (1,3) " + ") "; - - List> list = jdbcTemplate.queryForList(sql,refid); + + List> list = jdbcTemplate.queryForList(sql, refid); System.out.println("Total Generating Complaints : " + list.size()); - - if(list.isEmpty()) { - return ResponseEntity.ok(Map.of( - "status", false, - "message", "No eligible complaint found for this Ref ID." - )); + if (list.isEmpty()) { + + return ResponseEntity.ok(Map.of( + "status", false, + "message", "No eligible complaint found for this Ref ID.")); } - - String complaintNumber=""; - + + String complaintNumber = ""; + for (Map row : list) { - try { - - String refId = String.valueOf(row.get("ref_id")); - -// String imageUrl = ""; -// -// if(row.get("img_path") != null){ -// imageUrl = "https://gccservices.in/gccofficialapp/files" + row.get("img_path"); -// } - - //String imageBase64 = convertUrlToBase64(imageUrl); - - complaintNumber = sendComplaintToERP(row); - if(complaintNumber == null) { - - return ResponseEntity.ok(Map.of( - "status", false, - "message", "ERP complaint generation failed." - )); - } - - if(complaintNumber != null && !complaintNumber.equals("N/A")){ - - jdbcTemplate.update( - "UPDATE reg_details SET pgrticketno=? WHERE ref_id=?", - complaintNumber, - refId - ); - - jdbcTemplate.update( - "UPDATE complaint_details " - + "SET is_active=0, is_delete=1 " - + "WHERE ref_id=? " - + "AND comp_nature_id IN (1,3)", - refId - ); - - System.out.println(refId + " -> " + complaintNumber); - - } - - } catch (Exception e) { - System.out.println("Failed RefId : " + row.get("ref_id")); - e.printStackTrace(); - } + try { + + String refId = String.valueOf(row.get("ref_id")); + + // String imageUrl = ""; + // + // if(row.get("img_path") != null){ + // imageUrl = "https://gccservices.in/gccofficialapp/files" + + // row.get("img_path"); + // } + + // String imageBase64 = convertUrlToBase64(imageUrl); + + complaintNumber = sendComplaintToERP(row); + if (complaintNumber == null) { + + return ResponseEntity.ok(Map.of( + "status", false, + "message", "ERP complaint generation failed.")); + } + + if (complaintNumber != null && !complaintNumber.equals("N/A")) { + + jdbcTemplate.update( + "UPDATE reg_details SET pgrticketno=? WHERE ref_id=?", + complaintNumber, + refId); + + jdbcTemplate.update( + "UPDATE complaint_details " + + "SET is_active=0, is_delete=1 " + + "WHERE ref_id=? " + + "AND comp_nature_id IN (1,3)", + refId); + + System.out.println(refId + " -> " + complaintNumber); + + } + + } catch (Exception e) { + System.out.println("Failed RefId : " + row.get("ref_id")); + e.printStackTrace(); + } } - + return ResponseEntity.ok(Map.of( - "status", true, - "message", "PGR Complaint generation completed.", - "complaintNumber",complaintNumber, - "total", list.size() - )); - - - + "status", true, + "message", "PGR Complaint generation completed.", + "complaintNumber", complaintNumber, + "total", list.size())); + } catch (Exception e) { e.printStackTrace(); return ResponseEntity.internalServerError().body( - Map.of( - "status", false, - "message", e.getMessage() - ) - ); + Map.of( + "status", false, + "message", e.getMessage())); } - + } -private String sendComplaintToERP(Map row) { + private String sendComplaintToERP(Map row) { - try { + try { - String externalUrl = "https://erp.chennaicorporation.gov.in/pgr/external/mobileservice"; + String externalUrl = "https://erp.chennaicorporation.gov.in/pgr/external/mobileservice"; - URL url = new URL(externalUrl); + URL url = new URL(externalUrl); - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setRequestMethod("POST"); - conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - conn.setDoOutput(true); - - String complaintType = "454"; - String complaintTitle = "Tree Pruning"; - - //System.out.println("Name : " + getString(row.get("p_name"))); - - String complainantName = getComplainantName(row); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + conn.setDoOutput(true); - String params = - "serviceId=RegComplaint" - + "&ComplainantName=" + URLEncoder.encode(complainantName, "UTF-8") - + "&ComplainantAddr=" + URLEncoder.encode(getString(row.get("address")), "UTF-8") - + "&MobileNo=" + URLEncoder.encode(getString(row.get("ph_no")), "UTF-8") - + "&Email="+ URLEncoder.encode( "", "UTF-8") - + "&ComplaintType=" + URLEncoder.encode(complaintType, "UTF-8") - + "&ComplaintTitle=" + URLEncoder.encode(complaintTitle, "UTF-8") - + "&ComplaintDetails=" + URLEncoder.encode(getString(row.get("remarks")), "UTF-8")+ URLEncoder.encode(getString(row.get("ref_id")), "UTF-8") - + "&StreetId=" + URLEncoder.encode(getString(row.get("streetid")), "UTF-8") - //+ "&Comp_Image=" + URLEncoder.encode(imageBase64 == null ? "" : imageBase64, "UTF-8") - + "&Comp_Image="+ URLEncoder.encode( "", "UTF-8") - + "&latitude=" + URLEncoder.encode(getString(row.get("latitude")), "UTF-8") - + "&longtitude=" + URLEncoder.encode(getString(row.get("longitude")), "UTF-8") - + "&Landmark="+ URLEncoder.encode( "", "UTF-8") - + "&gender=" + URLEncoder.encode(getString(row.get("gender")), "UTF-8") - + "&compmode=1"; + String complaintType = "454"; + String complaintTitle = "Tree Pruning"; - + // System.out.println("Name : " + getString(row.get("p_name"))); - System.out.println(params); - - try(OutputStream os = conn.getOutputStream()){ + String complainantName = getComplainantName(row); - os.write(params.getBytes("UTF-8")); + String params = "serviceId=RegComplaint" + + "&ComplainantName=" + URLEncoder.encode(complainantName, "UTF-8") + + "&ComplainantAddr=" + URLEncoder.encode(getString(row.get("address")), "UTF-8") + + "&MobileNo=" + URLEncoder.encode(getString(row.get("ph_no")), "UTF-8") + + "&Email=" + URLEncoder.encode("", "UTF-8") + + "&ComplaintType=" + URLEncoder.encode(complaintType, "UTF-8") + + "&ComplaintTitle=" + URLEncoder.encode(complaintTitle, "UTF-8") + + "&ComplaintDetails=" + URLEncoder.encode(getString(row.get("remarks")), "UTF-8") + + URLEncoder.encode(getString(row.get("ref_id")), "UTF-8") + + "&StreetId=" + URLEncoder.encode(getString(row.get("streetid")), "UTF-8") + // + "&Comp_Image=" + URLEncoder.encode(imageBase64 == null ? "" : imageBase64, + // "UTF-8") + + "&Comp_Image=" + URLEncoder.encode("", "UTF-8") + + "&latitude=" + URLEncoder.encode(getString(row.get("latitude")), "UTF-8") + + "&longtitude=" + URLEncoder.encode(getString(row.get("longitude")), "UTF-8") + + "&Landmark=" + URLEncoder.encode("", "UTF-8") + + "&gender=" + URLEncoder.encode(getString(row.get("gender")), "UTF-8") + + "&compmode=1"; - } + System.out.println(params); - BufferedReader reader; + try (OutputStream os = conn.getOutputStream()) { - System.out.println(conn.getResponseCode()); - System.out.println(conn.getResponseMessage()); - if(conn.getResponseCode()==200){ + os.write(params.getBytes("UTF-8")); - reader = new BufferedReader( - new InputStreamReader(conn.getInputStream())); + } - }else{ + BufferedReader reader; - reader = new BufferedReader( - new InputStreamReader(conn.getErrorStream())); - } + System.out.println(conn.getResponseCode()); + System.out.println(conn.getResponseMessage()); + if (conn.getResponseCode() == 200) { - StringBuilder response = new StringBuilder(); + reader = new BufferedReader( + new InputStreamReader(conn.getInputStream())); - String line; + } else { - while((line = reader.readLine()) != null){ + reader = new BufferedReader( + new InputStreamReader(conn.getErrorStream())); + } - response.append(line); + StringBuilder response = new StringBuilder(); - } + String line; - reader.close(); - - - String responseText = response.toString(); + while ((line = reader.readLine()) != null) { - System.out.println("================================="); - System.out.println("Response Code : " + conn.getResponseCode()); - System.out.println("Response Body : "); - System.out.println(responseText); - System.out.println("================================="); + response.append(line); - if (!responseText.trim().startsWith("{")) { - System.out.println("Response is not JSON."); - return null; - } + } - ObjectMapper mapper = new ObjectMapper(); - Map responseMap = - mapper.readValue(responseText, Map.class); + reader.close(); - return String.valueOf(responseMap.get("Complaint Number")); + String responseText = response.toString(); - } - catch(Exception e){ + System.out.println("================================="); + System.out.println("Response Code : " + conn.getResponseCode()); + System.out.println("Response Body : "); + System.out.println(responseText); + System.out.println("================================="); - e.printStackTrace(); - return null; - } + if (!responseText.trim().startsWith("{")) { + System.out.println("Response is not JSON."); + return null; + } -} + ObjectMapper mapper = new ObjectMapper(); + Map responseMap = mapper.readValue(responseText, Map.class); -private String getString(Object obj){ + return String.valueOf(responseMap.get("Complaint Number")); - return obj == null ? "" : obj.toString(); + } catch (Exception e) { -} + e.printStackTrace(); + return null; + } + + } + + private String getString(Object obj) { -public String convertUrlToBase64(String urlString) { - try { - URL url = new URL(urlString); + return obj == null ? "" : obj.toString(); - try (InputStream inputStream = url.openStream(); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { + } - byte[] buffer = new byte[4096]; - int bytesRead; + public String convertUrlToBase64(String urlString) { + try { + URL url = new URL(urlString); - while ((bytesRead = inputStream.read(buffer)) != -1) { - outputStream.write(buffer, 0, bytesRead); - } + try (InputStream inputStream = url.openStream(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { - byte[] fileBytes = outputStream.toByteArray(); - System.out.println("Image Size : " + fileBytes.length + " bytes"); - return Base64.getEncoder().encodeToString(fileBytes); + byte[] buffer = new byte[4096]; + int bytesRead; - } + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } - } catch (Exception e) { - e.printStackTrace(); - return null; - } -} + byte[] fileBytes = outputStream.toByteArray(); + System.out.println("Image Size : " + fileBytes.length + " bytes"); + return Base64.getEncoder().encodeToString(fileBytes); -private String getComplainantName(Map row) { + } - String name = getString(row.get("p_name")).trim(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } - if (name.isEmpty()) { - name = getString(row.get("dept_name")).trim(); - } + private String getComplainantName(Map row) { - if (name.isEmpty()) { - name = getString(row.get("deptname")).trim(); - } + String name = getString(row.get("p_name")).trim(); - if (name.isEmpty()) { - System.out.println("No Complainant Name found."); - return ""; - } + if (name.isEmpty()) { + name = getString(row.get("dept_name")).trim(); + } - System.out.println("Original Name : " + name); - System.out.println("Original Length : " + name.length()); + if (name.isEmpty()) { + name = getString(row.get("deptname")).trim(); + } - if (name.length() <= 31) { - return name; - } + if (name.isEmpty()) { + System.out.println("No Complainant Name found."); + return ""; + } - String temp = name.substring(0, 31); + System.out.println("Original Name : " + name); + System.out.println("Original Length : " + name.length()); - int lastSpace = temp.lastIndexOf(' '); + if (name.length() <= 31) { + return name; + } - if (lastSpace > 0) { - temp = temp.substring(0, lastSpace); - } + String temp = name.substring(0, 31); - System.out.println("Trimmed Name : " + temp); - System.out.println("Trimmed Length : " + temp.length()); + int lastSpace = temp.lastIndexOf(' '); - return temp; -} + if (lastSpace > 0) { + temp = temp.substring(0, lastSpace); + } + + System.out.println("Trimmed Name : " + temp); + System.out.println("Trimmed Length : " + temp.length()); + + return temp; + } + // private String getComplainantName(Map row) { + // + // String pName = getString(row.get("p_name")).trim(); + // if (!pName.isEmpty()) { + // System.out.println("Using p_name : " + pName); + // System.out.println("Length : " + pName.length()); + // return pName; + // } + // + // String deptName = getString(row.get("dept_name")).trim(); + // if (!deptName.isEmpty()) { + // System.out.println("Using dept_name : " + deptName); + // System.out.println("Length : " + deptName.length()); + // return deptName; + // } + // + // String deptMasterName = getString(row.get("deptname")).trim(); + // if (!deptMasterName.isEmpty()) { + // System.out.println("Using deptname : " + deptMasterName); + // System.out.println("Length : " + deptMasterName.length()); + // return deptMasterName; + // } + // + // System.out.println("No Complainant Name found."); + // System.out.println("Length : 0"); + // return ""; + // } -//private String getComplainantName(Map row) { -// -// String pName = getString(row.get("p_name")).trim(); -// if (!pName.isEmpty()) { -// System.out.println("Using p_name : " + pName); -// System.out.println("Length : " + pName.length()); -// return pName; -// } -// -// String deptName = getString(row.get("dept_name")).trim(); -// if (!deptName.isEmpty()) { -// System.out.println("Using dept_name : " + deptName); -// System.out.println("Length : " + deptName.length()); -// return deptName; -// } -// -// String deptMasterName = getString(row.get("deptname")).trim(); -// if (!deptMasterName.isEmpty()) { -// System.out.println("Using deptname : " + deptMasterName); -// System.out.println("Length : " + deptMasterName.length()); -// return deptMasterName; -// } -// -// System.out.println("No Complainant Name found."); -// System.out.println("Length : 0"); -// return ""; -//} - } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b55e125..da16dc0 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,3 +1,3 @@ spring.application.name=greencommitte -spring.profiles.active=prod +spring.profiles.active=dev diff --git a/src/main/resources/templates/modules/department/form.html b/src/main/resources/templates/modules/department/form.html index 84aee18..8756e3e 100644 --- a/src/main/resources/templates/modules/department/form.html +++ b/src/main/resources/templates/modules/department/form.html @@ -1,675 +1,727 @@ + - -GCC Green Committee - - - - - - - - - - - - - + /* Multi-select dropdown box */ + .multi-select-dropdown .form-control { + background: #f8f9fa; + cursor: pointer; + } + + /* Dropdown list */ + .dropdown-checkbox-menu { + border-radius: 8px; + border-color: #aaa; + background: #fefefe; + box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2); + } + + /* File inputs */ + #img_container input { + height: 53px !important; + padding: 10px; + border-radius: 6px; + } + + /* Submit button */ + #submitBtn { + width: 180px; + height: 45px; + font-size: 16px; + border-radius: 8px; + } + + /* Back button */ + #backBtn { + border-radius: 8px; + padding: 10px 25px; + } + + /* Improved spacing on mobile */ + @media (max-width: 768px) { + .row { + row-gap: 15px; + } + + #sendOtpButton { + margin-top: 10px !important; + } + } + + - -
-
- - + +
+
+ + + + +
+ GREATER CHENNAI CORPORATION +
+ + + +
- -
- GREATER CHENNAI CORPORATION -
+ + - - -
- - - - -
- - -
- -
-
-
GREEN COMMITTEE DEPARTMENT FORM
-
- This form is for the department, not for the citizen(public) -
-
-
- - -
- - - -
-
- Central Government - State Government -
-
-
-
- - -
-
- - -
-
- -
- -
- + +
+ +
+ +
+
GREEN COMMITTEE DEPARTMENT FORM
+
+
+ This form is for the department, not for the + citizen(public) +
+
+
+ + +
+ + + +
+
+ Central Government + State Government +
+
+
+
+ + +
+
+ + +
+
+ +
+ +
+ - -
-
- - -
-
- -
- -
-
-
- -
-
- -
-
- - -
-
- - -
-
- - -
-
- - -
- -
- -
-
- - - -
- - - - -
-
-
- - -
- -
-
- - -
-
- -
-
- - -
-
- - -
-
- - - - - - - OTP validation is mandatory for submitting the form.* -
- - -
- - -
- -
-
- -
- - -
+ + + + + - - - - - - + + + + + + + + - + + + $(document).ready(function () { + $("#address").closest(".col-md-6").hide(); + $("#address").prop("required", false); + $('#sendOtpButton').click(function () { + + // Get the entered mobile number + const mobileNumber = $('#mobile_no').val(); + + // Basic check to ensure mobile number is entered + if (mobileNumber.length === 10) { + // Display the mobile number in the OTP modal + $("#mobilenotxt").html(mobileNumber); + + $.ajax({ + type: "GET", + url: '/greencommittee/api/sendOTP', + data: { 'mobileNo': mobileNumber }, // Pass mobile number and purpose + dataType: 'json', + success: function (response) { + + /* if (response === "Error: This number is not registered.") { + alert("This number is not registered."); + } */ if (response !== "Error") { + // Open OTP Modal + + $(".otp-input").val(''); + $("#otperror").html(""); + + $('#otpForm').modal({ + backdrop: 'static', + keyboard: false + }); + $('#otpForm').modal('show'); + + + // Start countdown for resend OTP (60 seconds) + startResendCountdown(60); + } else { + alert("OTP not sent. Please try again."); + } + }, + error: function () { + alert("Issue in OTP"); + } + }); + } else { + //alert("Please enter a valid 10-digit mobile number."); + Swal.fire({ + icon: "warning", + title: "Validation", + text: "Please enter a valid 10-digit mobile number.", + }); + } + }); + }); + + \ 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 4ccad71..c9fdc7d 100644 --- a/src/main/resources/templates/modules/public/form.html +++ b/src/main/resources/templates/modules/public/form.html @@ -479,10 +479,13 @@ + +
+
+
+
@@ -748,23 +760,56 @@ let id = $(this).val(); let name = $("#complaintDropdown option:selected").data("name"); - if (name && name.toLowerCase() === "pruning") { + if (!name) { - // Hide second image - $("#c2image").closest(".col-md-6").hide(); + // Nothing selected + $("#c2image").closest(".col-md-6").show(); + $("#c2image").prop("required", true); + + $("#address").closest(".col-md-6").hide(); + $("#address").prop("required", false).val(""); + + } else if (name.toLowerCase() === "pruning") { - // Remove required validation + // Pruning selected + $("#c2image").closest(".col-md-6").hide(); $("#c2image").prop("required", false).val(""); + $("#address").closest(".col-md-6").hide(); + $("#address").prop("required", false).val(""); + } else { - // Show second image + // Any complaint other than pruning $("#c2image").closest(".col-md-6").show(); - - // Existing workflow $("#c2image").prop("required", true); + + $("#address").closest(".col-md-6").show(); + $("#address").prop("required", true); } + /* if (name && name.toLowerCase() === "pruning") { + + + // Hide second image + $("#c2image").closest(".col-md-6").hide(); + + // Remove required validation + $("#c2image").prop("required", false).val(""); + $("#address").closest(".col-md-6").hide(); + $("#address").prop("required", false).val(""); + + } else { + + // Show second image + $("#c2image").closest(".col-md-6").show(); + + // Existing workflow + $("#c2image").prop("required", true); + $("#address").closest(".col-md-6").show(); + $("#address").prop("required", true); + }*/ + if (!id) { return; } @@ -862,6 +907,7 @@ // Apply to all file inputs inside the form $("#publicform input[type='file']").on("change", function () { const fileInput = this; + console.log(" cehcking"); if (fileInput.files.length > 0) { let file = fileInput.files[0]; @@ -1178,7 +1224,7 @@ const name = $('#pname').val(); const streetName = $('#streetName option:selected').text(); const street_id = $('#streetId').val(); - console.log("cfefefef"); + // console.log("cfefefef"); console.log(streetName); console.log("Streetid"); console.log(street_id); @@ -1254,7 +1300,10 @@ formData.append("p_name", name); formData.append("source", "1"); - formData.append("address", streetName) + //formData.append("address", streetName) + formData.set("streetName", streetName); + let address = $("#address").val().trim(); + formData.append("address", address) formData.append("c1image", c1image); @@ -1264,6 +1313,61 @@ let apiUrl = "/greencommittee/api/savepublicform"; if (complaintName && complaintName.trim().toLowerCase() === "pruning") { + if (name.length > 31) { + $('#pageLoader').hide(); + $('#submitBtn').prop('disabled', false).text('Submit'); + + Swal.fire({ + icon: "warning", + title: "Invalid Petitioner Name", + text: "Petitioner name cannot exceed 31 characters." + }); + return; // Stop form submission + } + const file = $("#c1image")[0].files[0]; + + if (!file) { + $('#pageLoader').hide(); + $('#submitBtn').prop('disabled', false).text('Submit'); + + Swal.fire({ + icon: "warning", + title: "Image Required", + text: "Please upload Image 1." + }); + return; + } + + // Allow only JPG, JPEG, PNG + const allowedTypes = ["image/jpeg", "image/jpg", "image/png"]; + + if (!allowedTypes.includes(file.type)) { + $('#pageLoader').hide(); + $('#submitBtn').prop('disabled', false).text('Submit'); + + Swal.fire({ + icon: "warning", + title: "Invalid File", + text: "Only JPG, JPEG and PNG images are allowed." + }); + $("#c1image").val(""); + return; + } + + // Maximum size: 1 MB + if (file.size > (1 * 1024 * 1024)) { + $('#pageLoader').hide(); + $('#submitBtn').prop('disabled', false).text('Submit'); + + Swal.fire({ + icon: "warning", + title: "File Too Large", + text: "Image size should not exceed 1 MB." + }); + $("#c1image").val(""); + return; + } + apiUrl = "/greencommittee/api/savepruningform"; formData.append("StreetId", street_id); @@ -1502,6 +1606,8 @@ } $(document).ready(function () { + $("#address").closest(".col-md-6").hide(); + $("#address").prop("required", false); $('#sendOtpButton').click(function () { // Get the entered mobile number