package in.gov.chennaicorporation.gccoffice.school.Controller; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.transaction.Transactional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import in.gov.chennaicorporation.gccoffice.school.Service.SchoolPropertyService; @RestController @CrossOrigin() @RequestMapping("/gcc/api/gccschool/schoolproperty") public class SchoolPropertyController { @Autowired private SchoolPropertyService schoolPropertyService; @Autowired public SchoolPropertyController(SchoolPropertyService schoolPropertyService) { this.schoolPropertyService = schoolPropertyService; } // To Get School Data @GetMapping("/getSchoolData") public ResponseEntity> getSchoolData(@RequestParam String udise) { try { List> data = schoolPropertyService.getSchoolData(udise); Map response = new HashMap<>(); if (data.size() != 0) { response.put("status", "OK"); response.put("data", data); } else { response.put("status", "Failed"); response.put("data", "No Data Found"); } return ResponseEntity.ok(response); } catch (Exception e) { // Log the exception details for debugging e.printStackTrace(); // Provide a user-friendly error message return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(Map.of("status", "Error", "message", "Error getting data: " + e.getMessage())); } } // For Other Details @PostMapping(value = "/saveSchoolBuildupArea") public String saveSchoolBuildupArea(@RequestParam("land_area") Double land_area, @RequestParam("buildup_area") Double buildup_area, @RequestParam("is_compound") Boolean is_compound, @RequestParam("is_nameboard") Boolean is_nameboard, @RequestParam("is_pasystem") Boolean is_pasystem, @RequestParam("is_bell") Boolean is_bell, @RequestParam("is_generator") Boolean is_generator, @RequestParam("school_id") int school_id) { return schoolPropertyService.saveSchoolBuildupArea(land_area, buildup_area, is_compound, is_nameboard, is_pasystem, is_bell, is_generator, school_id); } // For Student Strength @PostMapping(value = "/saveStudentStrength") public String saveStudentStrength(@RequestParam("total_students") int total_students, @RequestParam("total_girls") int total_girls, @RequestParam("total_boys") int total_boys, @RequestParam("others") int others, @RequestParam("school_id") int school_id) { return schoolPropertyService.saveStudentStrength(total_students, total_girls, total_boys, others, school_id); } // For Staff Strength // @PostMapping(value="/saveStaffStrength") // public String saveStaffStrength( // @RequestParam("tot_staff") int tot_staff, // @RequestParam("sg_staff") int sg_staff, // @RequestParam("bt_staff") int bt_staff, // @RequestParam("pg_staff") int pg_staff, // @RequestParam("temp_staff") int temp_staff, // @RequestParam("ngo_staff") int ngo_staff, // @RequestParam("kg_staff") int kg_staff, // @RequestParam("pt_staff") int pt_staff, // @RequestParam("part_staff") int part_staff, // @RequestParam("qa_staff") int qa_staff, // @RequestParam("kg_ayha") int kg_ayha, // @RequestParam("watchman") int watchman, // @RequestParam("comp_asst") int comp_asst, // @RequestParam("scavengers") int scavengers, // @RequestParam("maint_workers") int maint_workers, // @RequestParam("school_id") int school_id) { // // return schoolPropertyService.saveStaffStrength(tot_staff, sg_staff, bt_staff,pg_staff, temp_staff, ngo_staff, kg_staff, pt_staff,part_staff, qa_staff, kg_ayha, watchman, comp_asst, scavengers, maint_workers, school_id); // } // For Toilets @PostMapping(value = "/saveToilets") public String saveToilets(@RequestParam("total_toiletBlocks") int total_toiletBlocks, @RequestParam("total_male_urinals") int total_male_urinals, @RequestParam("total_wc_male") int total_wc_male, @RequestParam("total_wc_female") int total_wc_female, @RequestParam("total_diffAbled_toilet") int total_diffAbled_toilet, @RequestParam("is_napkins") Boolean is_napkins, @RequestParam("school_id") int school_id) { return schoolPropertyService.saveToilets(total_toiletBlocks, total_male_urinals, total_wc_male, total_wc_female, total_diffAbled_toilet, is_napkins, school_id); } // For Kitchen @PostMapping(value = "/saveKitchen") public String saveKitchen(@RequestParam(value = "is_cmbfs") Boolean is_cmbfs, @RequestParam(value = "is_cmbfsIndividual", required = false) Boolean is_cmbfsIndividual, @RequestParam(value = "is_noonmeal") Boolean is_noonmeal, @RequestParam(value = "is_noonIndividual", required = false) Boolean is_noonIndividual, @RequestParam(value = "is_vegGarden", required = false) Boolean is_vegGarden, @RequestParam(value = "is_anganwadi") Boolean is_anganwadi, @RequestParam(value = "anganwadi_unique", required = false) String anganwadi_unique, @RequestParam(value = "is_anganwadiIndividual", required = false) Boolean is_anganwadiIndividual, @RequestParam(value = "school_id") int school_id) { if (anganwadi_unique != null && anganwadi_unique.trim().isEmpty()) { anganwadi_unique = null; } return schoolPropertyService.saveKitchen(is_cmbfs, is_cmbfsIndividual, is_noonmeal, is_noonIndividual, is_vegGarden, is_anganwadi, anganwadi_unique, is_anganwadiIndividual, school_id); } // For Playground @PostMapping(value = "/savePlayground") public ResponseEntity> savePlayground(@RequestBody Map payload) { Map response = new HashMap<>(); try { Boolean is_playground = (Boolean) payload.get("is_playground"); Double playground_area = Double.valueOf(payload.get("playground_area").toString()); Boolean is_court = (Boolean) payload.get("is_court"); int school_id = Integer.parseInt(payload.get("school_id").toString()); // Boolean is_active = (Boolean) payload.get("is_active"); List equipmentidRaw = (List) payload.get("equipmentid"); List courtidRaw = (List) payload.get("courtid"); // Convert string IDs to integers // List equipmentid = equipmentidRaw.stream().map(Integer::parseInt).toList(); // List courtid = courtidRaw.stream().map(Integer::parseInt).toList(); int playground_id = schoolPropertyService.savePlayground(is_playground, playground_area, is_court, school_id); for (String equipment_id : equipmentidRaw) { schoolPropertyService.saveEquipmentDetails(equipment_id, school_id, playground_id); } for (String court_id : courtidRaw) { schoolPropertyService.saveCourtDetails(court_id, school_id, playground_id); } response.put("status", "OK"); response.put("message", "Playground Details saved successfully"); return ResponseEntity.ok(response); } catch (Exception e) { e.printStackTrace(); response.put("status", "ERROR"); response.put("message", "Failed to save playground details"); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); } } // For Drinking Water @PostMapping(value = "/saveDrinkingWater") public ResponseEntity> saveDrinkingWater(@RequestBody Map requestData) { try { // Extract data from the map List> water = (List>) requestData.get("water"); Boolean is_purifier = "1".equals(requestData.get("is_purifier")); Double purifier_capacity = requestData.get("purifier_capacity") != null ? Double.valueOf(requestData.get("purifier_capacity").toString()) : null; Boolean is_borewell = "1".equals(requestData.get("is_borewell")); Integer borewell_count = requestData.get("borewell_count") != null ? Integer.valueOf(requestData.get("borewell_count").toString()) : null; Boolean is_storage = "1".equals(requestData.get("is_storage")); List> storage = (List>) requestData.get("storage"); int school_id = Integer.parseInt(requestData.get("school_id").toString()); Map response = new HashMap<>(); int drinking_water_id = schoolPropertyService.saveDrinkingWater(is_purifier, purifier_capacity, is_borewell, borewell_count, is_storage, school_id); for (Map waterSupply : water) { int source_water_id = (int) waterSupply.get("source_water_id"); String supply_type = (String) waterSupply.get("supply_type"); schoolPropertyService.saveWaterSupply(source_water_id, supply_type, drinking_water_id, school_id); } if (!storage.isEmpty()) { for (Map waterStorage : storage) { double capacity = Double.valueOf(waterStorage.get("capacity").toString()); int storage_water_id = (int) waterStorage.get("storage_water_id"); schoolPropertyService.saveWaterStorage(capacity, storage_water_id, drinking_water_id, school_id); } } response.put("status", "OK"); return ResponseEntity.ok(response); } catch (Exception e) { e.printStackTrace(); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(Map.of("status", "Error", "message", "Error saving data: " + e.getMessage())); } } @PostMapping("/saveStaffStrength") public String saveStaffStrength(@RequestParam int sgRegTeacher, @RequestParam int sgTempTeacher, @RequestParam int sgPtTeacher, @RequestParam int sgNgoTeacher, @RequestParam int btRegTeacher, @RequestParam int btTempTeacher, @RequestParam int btPtTeacher, @RequestParam int btNgoTeacher, @RequestParam int pgRegTeacher, @RequestParam int pgTempTeacher, @RequestParam int pgPtTeacher, @RequestParam int pgNgoTeacher, @RequestParam int kgRegTeacher, @RequestParam int kgTempTeacher, @RequestParam int petRegTeacher, @RequestParam int petTempTeacher, @RequestParam int petGrade1Teacher, @RequestParam int petGrade2Teacher, @RequestParam int totOa, @RequestParam int kgAyah, @RequestParam int compAss, @RequestParam int watchmen, @RequestParam int scavengers, @RequestParam int maintenanceWork, @RequestParam int schoolId) { // Call service method schoolPropertyService.saveStaffStrength(sgRegTeacher, sgTempTeacher, sgPtTeacher, sgNgoTeacher, btRegTeacher, btTempTeacher, btPtTeacher, btNgoTeacher, pgRegTeacher, pgTempTeacher, pgPtTeacher, pgNgoTeacher, kgRegTeacher, kgTempTeacher, petRegTeacher, petTempTeacher, petGrade1Teacher, petGrade2Teacher, totOa, kgAyah, compAss, watchmen, scavengers, maintenanceWork, schoolId); return "Staff strength details saved successfully!"; } // For login @GetMapping(value = "/getLoginDetails") public List> getLoginDetails(@RequestParam String user_id) { List> schoolData = new ArrayList<>(); Map response = new HashMap<>(); String schoolId = schoolPropertyService.getSchoolId(user_id); if (schoolId == null || schoolId.trim().isEmpty() || schoolId.equalsIgnoreCase("error")) { response.put("Message", "Failure"); response.put("Data", List.of()); schoolData.add(response); return schoolData; } List> sch = schoolPropertyService.getSchoolData1(schoolId); if (!sch.isEmpty()) { response.put("Message", "Success"); response.put("Data", sch); schoolData.add(response); return schoolData; } else { response.put("Message", "No Data Found"); response.put("Data", List.of()); schoolData.add(response); return schoolData; } } @GetMapping("/getSchoolDetails") public ResponseEntity> getSchoolDetails(@RequestParam Long schoolId) { try { Map data = schoolPropertyService.getSchoolDetails(schoolId); if (data != null && !data.isEmpty()) { return ResponseEntity.ok(data); } else { return ResponseEntity.status(HttpStatus.NOT_FOUND) .body(Map.of("status", "Failed", "message", "No school found with given ID")); } } catch (Exception e) { e.printStackTrace(); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(Map.of("status", "Error", "message", e.getMessage())); } } @GetMapping("/filterSchools") public ResponseEntity filterSchools(@RequestParam String user_id, @RequestParam(required = false) String udise, @RequestParam(required = false) String category, @RequestParam(required = false) String zone, @RequestParam(required = false) String ward) { List> filteredSchools = schoolPropertyService.filterSchools(user_id, udise, category, zone, ward); Map result = new HashMap<>(); result.put("Message", "Success"); result.put("Data", filteredSchools); return ResponseEntity.ok(Collections.singletonList(result)); } @PostMapping("/updateOtherDetails") public String updateOtherDetails(@RequestParam("land_area") Double land_area, @RequestParam("buildup_area") Double buildup_area, @RequestParam("is_compound") Boolean is_compound, @RequestParam("is_nameboard") Boolean is_nameboard, @RequestParam("is_pasystem") Boolean is_pasystem, @RequestParam("is_bell") Boolean is_bell, @RequestParam("is_generator") Boolean is_generator, @RequestParam("school_id") int school_id) { try { return schoolPropertyService.updateOtherDetails(land_area, buildup_area, is_compound, is_nameboard, is_pasystem, is_bell, is_generator, school_id); } catch (Exception e) { e.printStackTrace(); return "Error"; } } @PostMapping(value = "/updateStudentDetails") public String updateStudentDetails(@RequestParam("total_students") int total_students, @RequestParam("total_girls") int total_girls, @RequestParam("total_boys") int total_boys, @RequestParam("others") int others, @RequestParam("school_id") int school_id) { System.out.println("Update Request => total: " + total_students + ", boys: " + total_boys + ", girls: " + total_girls + ", others: " + others + ", school_id: " + school_id); try { return schoolPropertyService.updateStudentDetails(total_students, total_girls, total_boys, others, school_id); } catch (Exception e) { e.printStackTrace(); return "Error"; } } @GetMapping("/checkPlaygroundDetails") public ResponseEntity checkPlaygroundDetails(@RequestParam int school_id) { Map playgroundDetails = schoolPropertyService.checkPlaygroundDetails(school_id); List> courtDetails = schoolPropertyService.checkCourtDetails(school_id); List> equipmentDetails = schoolPropertyService.checkEquipmentDetails(school_id); Map result = new HashMap<>(); result.put("Message", "Success"); result.put("playgroundDetails", playgroundDetails); result.put("CourtDetails", courtDetails); result.put("EquipmentDetails", equipmentDetails); return ResponseEntity.ok(Collections.singletonList(result)); } /* * @PostMapping(value = "/updatePlayground") public ResponseEntity * updatePlayground(@RequestBody Map payload) { try { Boolean * is_playground = (Boolean) payload.get("is_playground"); Double * playground_area = Double.valueOf(payload.get("playground_area").toString()); * Boolean is_court = (Boolean) payload.get("is_court"); int school_id = * Integer.parseInt(payload.get("school_id").toString()); int playground_id = * Integer.parseInt(payload.get("playground_id").toString()); * * List> equipments = (List>) * payload.get("equipments"); List> courts = * (List>) payload.get("courts"); * * String result = schoolPropertyService.updatePlaygroundDetails( is_playground, * playground_area, is_court, equipments, courts, playground_id, school_id ); * return ResponseEntity.ok(result); * * } catch (Exception e) { e.printStackTrace(); return * ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Error"); } } */ // @PostMapping(value = "/updatePlayground") // public ResponseEntity> updatePlayground(@RequestBody Map payload) { // Map response = new HashMap<>(); // try { // Boolean is_playground = (Boolean) payload.get("is_playground"); // Double playground_area = Double.valueOf(payload.get("playground_area").toString()); // Boolean is_court = (Boolean) payload.get("is_court"); // int school_id = Integer.parseInt(payload.get("school_id").toString()); // //Boolean is_active = (Boolean) payload.get("is_active"); // int playground_id = Integer.parseInt(payload.get("playground_id").toString()); // // // List equipmentidRaw = (List) payload.get("equipments"); // List courtidRaw = (List) payload.get("courts"); // // // Convert string IDs to integers // List equipmentid = equipmentidRaw.stream().map(Integer::parseInt).toList(); // List courtid = courtidRaw.stream().map(Integer::parseInt).toList(); // schoolPropertyService.deactiveCourts(school_id); // schoolPropertyService.deactiveEquipments(school_id); // schoolPropertyService.updatePlayground(is_playground, playground_area, is_court, school_id, playground_id); // //int playground_id = schoolPropertyService.savePlayground(is_playground, playground_area, is_court, // // school_id); // // for (Integer equipment_id : equipmentid) { // schoolPropertyService.saveEquipmentDetails(equipment_id, school_id, playground_id); // } // // for (Integer court_id : courtid) { // schoolPropertyService.saveCourtDetails(court_id, school_id, playground_id); // } // // response.put("status", "OK"); // response.put("message", "Playground Details updated successfully"); // return ResponseEntity.ok(response); // // } catch (Exception e) { // e.printStackTrace(); // response.put("status", "ERROR"); // response.put("message", "Failed to updated playground details"); // return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); // } // } @PostMapping(value = "/updatePlayground") public ResponseEntity> updatePlayground(@RequestBody Map payload) { Map response = new HashMap<>(); try { Boolean is_playground = (Boolean) payload.get("is_playground"); Double playground_area = Double.valueOf(payload.get("playground_area").toString()); Boolean is_court = (Boolean) payload.get("is_court"); int school_id = Integer.parseInt(payload.get("school_id").toString()); int playground_id = Integer.parseInt(payload.get("playground_id").toString()); List> equipmentList = (List>) payload.get("equipments"); List> courtList = (List>) payload.get("courts"); String status = schoolPropertyService.updatePlaygroundDetails(is_playground, playground_area, is_court, equipmentList, courtList, playground_id, school_id); response.put("status", status.equals("Success") ? "OK" : "ERROR"); response.put("message", status.equals("Success") ? "Playground updated successfully" : "Failed to update playground"); return ResponseEntity.ok(response); } catch (Exception e) { e.printStackTrace(); response.put("status", "ERROR"); response.put("message", "Exception occurred during update"); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); } } @PostMapping(value = "/updateKitchenDetails") public String updateKitchenDetails(@RequestParam(value = "is_cmbfs") Boolean is_cmbfs, @RequestParam(value = "is_cmbfsIndividual", required = false) Boolean is_cmbfsIndividual, @RequestParam(value = "is_noonmeal") Boolean is_noonmeal, @RequestParam(value = "is_noonIndividual", required = false) Boolean is_noonIndividual, @RequestParam(value = "is_vegGarden", required = false) Boolean is_vegGarden, @RequestParam(value = "is_anganwadi") Boolean is_anganwadi, @RequestParam(value = "anganwadi_unique", required = false) String anganwadi_unique, @RequestParam(value = "is_anganwadiIndividual", required = false) Boolean is_anganwadiIndividual, @RequestParam(value = "school_id") int school_id) { try { return schoolPropertyService.updateKitchenDetails(is_cmbfs, is_cmbfsIndividual, is_noonmeal, is_noonIndividual, is_vegGarden, is_anganwadi, anganwadi_unique, is_anganwadiIndividual, school_id); } catch (Exception e) { e.printStackTrace(); return "Error"; } } @GetMapping("/checkKitchenDetails") public ResponseEntity checkKitchenDetails(@RequestParam int school_id) { Map kitchenDetails = schoolPropertyService.checkKitchenDetails(school_id); Map result = new HashMap<>(); result.put("Message", "Success"); result.put("Data", kitchenDetails); return ResponseEntity.ok(Collections.singletonList(result)); } @PostMapping(value = "/updateStaffDetails") public String updateStaffDetails(@RequestParam int sgRegTeacher, @RequestParam int sgTempTeacher, @RequestParam int sgPtTeacher, @RequestParam int sgNgoTeacher, @RequestParam int btRegTeacher, @RequestParam int btTempTeacher, @RequestParam int btPtTeacher, @RequestParam int btNgoTeacher, @RequestParam int pgRegTeacher, @RequestParam int pgTempTeacher, @RequestParam int pgPtTeacher, @RequestParam int pgNgoTeacher, @RequestParam int kgRegTeacher, @RequestParam int kgTempTeacher, @RequestParam int petRegTeacher, @RequestParam int petTempTeacher, @RequestParam int petGrade1Teacher, @RequestParam int petGrade2Teacher, @RequestParam int totOa, @RequestParam int kgAyah, @RequestParam int compAss, @RequestParam int watchmen, @RequestParam int scavengers, @RequestParam int maintenanceWork, @RequestParam int school_id) { try { return schoolPropertyService.updateStaffDetails(sgRegTeacher, sgTempTeacher, sgPtTeacher, sgNgoTeacher, btRegTeacher, btTempTeacher, btPtTeacher, btNgoTeacher, pgRegTeacher, pgTempTeacher, pgPtTeacher, pgNgoTeacher, kgRegTeacher, kgTempTeacher, petRegTeacher, petTempTeacher, petGrade1Teacher, petGrade2Teacher, totOa, kgAyah, compAss, watchmen, scavengers, maintenanceWork, school_id); } catch (Exception e) { e.printStackTrace(); return "Error"; } } /* * @GetMapping("/checkWaterDetails") public ResponseEntity checkWaterDetails( * * @RequestParam int school_id) { * * Map drinkingWater = * schoolPropertyService.checkWaterDetails(school_id); List> * waterSource = schoolPropertyService.checkWaterSource(school_id); * List> waterStorage = * schoolPropertyService.checkWaterStotage(school_id); * * Map result = new HashMap<>(); result.put("Message", * "Success"); result.put("DrinkingWater", drinkingWater); * result.put("WaterSource", waterSource); result.put("WaterStorage", * waterStorage); * * return ResponseEntity.ok(Collections.singletonList(result)); } */ // @PostMapping(value = "/updateDrinkingWater") // public String updateDrinkingWater(@RequestParam("is_purifier") Boolean is_purifier, @RequestParam("purifier_capacity") Double purifier_capacity, // @RequestParam("is_borewell") Boolean is_borewell, @RequestParam("borewell_count") int borewell_count, @RequestParam("is_storage") Boolean is_storage, // @RequestParam("drinking_water_id") int drinking_water_id, @RequestParam("school_id") int school_id, @RequestParam("supply") List> supply, // @RequestParam("storage") List> storage) { // try { // // return schoolPropertyService.updateDrinkingWater(is_purifier, purifier_capacity, is_borewell, borewell_count, is_storage, drinking_water_id, school_id, supply, storage); // // } catch (Exception e) { // e.printStackTrace(); // return "Error"; // } // // } @PostMapping(value = "/updateDrinkingWater") public ResponseEntity> updateDrinkingWater(@RequestBody Map requestData) { try { System.out.println("Received update payload: " + requestData); // Extract data from the map // List> water = (List>) // requestData.get("water"); List> water = (List>) requestData.getOrDefault("supply", new ArrayList<>()); List> storage = (List>) requestData.getOrDefault("storage", new ArrayList<>()); Boolean is_purifier = (Boolean) requestData.get("is_purifier"); Double purifier_capacity = requestData.get("purifier_capacity") != null ? Double.valueOf(requestData.get("purifier_capacity").toString()) : 0; Boolean is_borewell = (Boolean) requestData.get("is_borewell"); Integer borewell_count = requestData.get("borewell_count") != null ? Integer.valueOf(requestData.get("borewell_count").toString()) : 0; Boolean is_storage = (Boolean) requestData.get("is_storage"); // List> storage = (List>) // requestData.get("storage"); int school_id = Integer.parseInt(requestData.get("school_id").toString()); int drinking_water_id = Integer.parseInt(requestData.get("drinking_water_id").toString()); Map response = new HashMap<>(); schoolPropertyService.updateDrinkWater(is_purifier, purifier_capacity, is_borewell, borewell_count, is_storage, school_id, drinking_water_id); schoolPropertyService.deactiveWaterSupply(school_id, drinking_water_id); schoolPropertyService.deactiveWaterStorage(school_id, drinking_water_id); for (Map waterSupply : water) { int source_water_id = (int) waterSupply.get("source_water_id"); String supply_type = (String) waterSupply.get("supply_type"); schoolPropertyService.saveWaterSupply(source_water_id, supply_type, drinking_water_id, school_id); } if (!storage.isEmpty()) { for (Map waterStorage : storage) { double capacity = Double.valueOf(waterStorage.get("capacity").toString()); int storage_water_id = (int) waterStorage.get("storage_water_id"); schoolPropertyService.saveWaterStorage(capacity, storage_water_id, drinking_water_id, school_id); } } response.put("status", "OK"); return ResponseEntity.ok(response); } catch (Exception e) { e.printStackTrace(); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(Map.of("status", "Error", "message", "Error saving data: " + e.getMessage())); } } @GetMapping("/checkWaterDetails") public ResponseEntity> checkWaterDetails(@RequestParam int school_id) { System.out.println("CHECK 11"); try { System.out.println("CHECK 1"); Map drinkingWater = schoolPropertyService.checkWaterDetails(school_id); List> waterSource = schoolPropertyService.checkWaterSource(school_id); List> waterStorage = schoolPropertyService.checkWaterStotage(school_id); System.out.println("WATER SOURCE = " + waterSource); Map response = new HashMap<>(); response.put("DrinkingWater", drinkingWater); response.put("WaterSource", waterSource); response.put("WaterStorage", waterStorage); // ✅ Set status based on content presence if (drinkingWater != null && !drinkingWater.isEmpty()) { response.put("status", "OK"); } else { response.put("status", "NEW"); } return ResponseEntity.ok(response); } catch (Exception e) { e.printStackTrace(); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(Map.of("status", "Error", "message", "Could not load drinking water data")); } } @GetMapping("/checkToiletDetails") public ResponseEntity checkToiletDetails(@RequestParam int school_id) { List> toiletDetails = schoolPropertyService.checkToiletDetails(school_id); Map result = new HashMap<>(); result.put("Message", "Success"); result.put("Data", toiletDetails); return ResponseEntity.ok(Collections.singletonList(result)); } @PostMapping(value = "/updateToiletDetails") public String updateToiletDetails(@RequestParam("total_toiletBlocks") int total_toiletBlocks, @RequestParam("total_male_urinals") int total_male_urinals, @RequestParam("total_wc_male") int total_wc_male, @RequestParam("total_wc_female") int total_wc_female, @RequestParam("total_diffAbled_toilet") int total_diffAbled_toilet, @RequestParam("is_napkins") Boolean is_napkins, @RequestParam("school_id") int school_id) { try { return schoolPropertyService.updateToiletDetails(total_toiletBlocks, total_male_urinals, total_wc_male, total_wc_female, total_diffAbled_toilet, is_napkins, school_id); } catch (Exception e) { e.printStackTrace(); return "Error"; } } @PostMapping(value = "/saveAssetMaster") public ResponseEntity> saveAssetMaster(@RequestBody Map payload) { Map response = new HashMap<>(); String status = ""; try { int school_id = Integer.parseInt(payload.get("school_id").toString()); int asset_id = Integer.parseInt(payload.get("asset_id").toString()); List> equipmentList = (List>) payload.get("data"); for (Map asset : equipmentList) { int sub_asset_id = Integer.parseInt(asset.get("sub_asset_id").toString()); int master_qty = Integer.parseInt(asset.get("master_qty").toString()); status = schoolPropertyService.saveAssetMaster(sub_asset_id, master_qty, school_id, asset_id); } response.put("status", status.equals("Success") ? "OK" : "ERROR"); response.put("message", status.equals("Success") ? "Asset Master Saved successfully" : "Failed to Save Asset Master"); return ResponseEntity.ok(response); } catch (Exception e) { e.printStackTrace(); response.put("status", "ERROR"); response.put("message", "Exception occurred during update"); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); } } @GetMapping("/getAssetMaster") public ResponseEntity getAssetMaster(@RequestParam int school_id, @RequestParam int asset_id) { List> data = schoolPropertyService.getAssetMaster(school_id, asset_id); // System.out.println("data=="+data); Map result = new HashMap<>(); result.put("status", "Success"); result.put("data", data); return ResponseEntity.ok(result); } @GetMapping("/getAssetMasterById") public ResponseEntity getAssetMasterById(@RequestParam int assetMasterId, @RequestParam int asset_id) { Map data = schoolPropertyService.getAssetMasterById(assetMasterId, asset_id); Map result = new HashMap<>(); result.put("status", "Success"); result.put("data", data); return ResponseEntity.ok(result); } @PostMapping(value = "/updateAssetMaster") public String updateStudentDetails(@RequestParam("master_qty") int master_qty, @RequestParam("assetMasterId") int assetMasterId, @RequestParam("asset_id") int asset_id) { try { Map assetMaster = schoolPropertyService.getAssetMasterById(assetMasterId, asset_id); int qty = (Integer) assetMaster.get("master_qty"); int unmapped_asset = (Integer) assetMaster.get("unmapped_qty"); int master = qty + master_qty; int unmapped = master_qty + unmapped_asset; return schoolPropertyService.updateAssetMaster(assetMasterId, master, asset_id, unmapped); } catch (Exception e) { e.printStackTrace(); return "Error"; } } }