You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

720 lines
32 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. package in.gov.chennaicorporation.gccoffice.school.Controller;
  2. import java.util.ArrayList;
  3. import java.util.Collections;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import javax.transaction.Transactional;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.http.HttpStatus;
  10. import org.springframework.http.ResponseEntity;
  11. import org.springframework.web.bind.annotation.CrossOrigin;
  12. import org.springframework.web.bind.annotation.GetMapping;
  13. import org.springframework.web.bind.annotation.PostMapping;
  14. import org.springframework.web.bind.annotation.RequestBody;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestParam;
  17. import org.springframework.web.bind.annotation.RestController;
  18. import in.gov.chennaicorporation.gccoffice.school.Service.SchoolPropertyService;
  19. @RestController
  20. @CrossOrigin()
  21. @RequestMapping("/gcc/api/gccschool/schoolproperty")
  22. public class SchoolPropertyController {
  23. @Autowired
  24. private SchoolPropertyService schoolPropertyService;
  25. @Autowired
  26. public SchoolPropertyController(SchoolPropertyService schoolPropertyService) {
  27. this.schoolPropertyService = schoolPropertyService;
  28. }
  29. // To Get School Data
  30. @GetMapping("/getSchoolData")
  31. public ResponseEntity<Map<String, Object>> getSchoolData(@RequestParam String udise) {
  32. try {
  33. List<Map<String, Object>> data = schoolPropertyService.getSchoolData(udise);
  34. Map<String, Object> response = new HashMap<>();
  35. if (data.size() != 0) {
  36. response.put("status", "OK");
  37. response.put("data", data);
  38. } else {
  39. response.put("status", "Failed");
  40. response.put("data", "No Data Found");
  41. }
  42. return ResponseEntity.ok(response);
  43. } catch (Exception e) {
  44. // Log the exception details for debugging
  45. e.printStackTrace();
  46. // Provide a user-friendly error message
  47. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  48. .body(Map.of("status", "Error", "message", "Error getting data: " + e.getMessage()));
  49. }
  50. }
  51. // For Other Details
  52. @PostMapping(value = "/saveSchoolBuildupArea")
  53. public String saveSchoolBuildupArea(@RequestParam("land_area") Double land_area,
  54. @RequestParam("buildup_area") Double buildup_area, @RequestParam("is_compound") Boolean is_compound,
  55. @RequestParam("is_nameboard") Boolean is_nameboard, @RequestParam("is_pasystem") Boolean is_pasystem,
  56. @RequestParam("is_bell") Boolean is_bell, @RequestParam("is_generator") Boolean is_generator,
  57. @RequestParam("school_id") int school_id) {
  58. return schoolPropertyService.saveSchoolBuildupArea(land_area, buildup_area, is_compound, is_nameboard,
  59. is_pasystem, is_bell, is_generator, school_id);
  60. }
  61. // For Student Strength
  62. @PostMapping(value = "/saveStudentStrength")
  63. public String saveStudentStrength(@RequestParam("total_students") int total_students,
  64. @RequestParam("total_girls") int total_girls, @RequestParam("total_boys") int total_boys,
  65. @RequestParam("others") int others, @RequestParam("school_id") int school_id) {
  66. return schoolPropertyService.saveStudentStrength(total_students, total_girls, total_boys, others, school_id);
  67. }
  68. // For Staff Strength
  69. // @PostMapping(value="/saveStaffStrength")
  70. // public String saveStaffStrength(
  71. // @RequestParam("tot_staff") int tot_staff,
  72. // @RequestParam("sg_staff") int sg_staff,
  73. // @RequestParam("bt_staff") int bt_staff,
  74. // @RequestParam("pg_staff") int pg_staff,
  75. // @RequestParam("temp_staff") int temp_staff,
  76. // @RequestParam("ngo_staff") int ngo_staff,
  77. // @RequestParam("kg_staff") int kg_staff,
  78. // @RequestParam("pt_staff") int pt_staff,
  79. // @RequestParam("part_staff") int part_staff,
  80. // @RequestParam("qa_staff") int qa_staff,
  81. // @RequestParam("kg_ayha") int kg_ayha,
  82. // @RequestParam("watchman") int watchman,
  83. // @RequestParam("comp_asst") int comp_asst,
  84. // @RequestParam("scavengers") int scavengers,
  85. // @RequestParam("maint_workers") int maint_workers,
  86. // @RequestParam("school_id") int school_id) {
  87. //
  88. // 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);
  89. // }
  90. // For Toilets
  91. @PostMapping(value = "/saveToilets")
  92. public String saveToilets(@RequestParam("total_toiletBlocks") int total_toiletBlocks,
  93. @RequestParam("total_male_urinals") int total_male_urinals,
  94. @RequestParam("total_wc_male") int total_wc_male, @RequestParam("total_wc_female") int total_wc_female,
  95. @RequestParam("total_diffAbled_toilet") int total_diffAbled_toilet,
  96. @RequestParam("is_napkins") Boolean is_napkins, @RequestParam("school_id") int school_id) {
  97. return schoolPropertyService.saveToilets(total_toiletBlocks, total_male_urinals, total_wc_male, total_wc_female,
  98. total_diffAbled_toilet, is_napkins, school_id);
  99. }
  100. // For Kitchen
  101. @PostMapping(value = "/saveKitchen")
  102. public String saveKitchen(@RequestParam(value = "is_cmbfs") Boolean is_cmbfs,
  103. @RequestParam(value = "is_cmbfsIndividual", required = false) Boolean is_cmbfsIndividual,
  104. @RequestParam(value = "is_noonmeal") Boolean is_noonmeal,
  105. @RequestParam(value = "is_noonIndividual", required = false) Boolean is_noonIndividual,
  106. @RequestParam(value = "is_vegGarden", required = false) Boolean is_vegGarden,
  107. @RequestParam(value = "is_anganwadi") Boolean is_anganwadi,
  108. @RequestParam(value = "anganwadi_unique", required = false) String anganwadi_unique,
  109. @RequestParam(value = "is_anganwadiIndividual", required = false) Boolean is_anganwadiIndividual,
  110. @RequestParam(value = "school_id") int school_id) {
  111. if (anganwadi_unique != null && anganwadi_unique.trim().isEmpty()) {
  112. anganwadi_unique = null;
  113. }
  114. return schoolPropertyService.saveKitchen(is_cmbfs, is_cmbfsIndividual, is_noonmeal, is_noonIndividual,
  115. is_vegGarden, is_anganwadi, anganwadi_unique, is_anganwadiIndividual, school_id);
  116. }
  117. // For Playground
  118. @PostMapping(value = "/savePlayground")
  119. public ResponseEntity<Map<String, String>> savePlayground(@RequestBody Map<String, Object> payload) {
  120. Map<String, String> response = new HashMap<>();
  121. try {
  122. Boolean is_playground = (Boolean) payload.get("is_playground");
  123. Double playground_area = Double.valueOf(payload.get("playground_area").toString());
  124. Boolean is_court = (Boolean) payload.get("is_court");
  125. int school_id = Integer.parseInt(payload.get("school_id").toString());
  126. // Boolean is_active = (Boolean) payload.get("is_active");
  127. List<String> equipmentidRaw = (List<String>) payload.get("equipmentid");
  128. List<String> courtidRaw = (List<String>) payload.get("courtid");
  129. // Convert string IDs to integers
  130. // List<Integer> equipmentid = equipmentidRaw.stream().map(Integer::parseInt).toList();
  131. // List<Integer> courtid = courtidRaw.stream().map(Integer::parseInt).toList();
  132. int playground_id = schoolPropertyService.savePlayground(is_playground, playground_area, is_court,
  133. school_id);
  134. for (String equipment_id : equipmentidRaw) {
  135. schoolPropertyService.saveEquipmentDetails(equipment_id, school_id, playground_id);
  136. }
  137. for (String court_id : courtidRaw) {
  138. schoolPropertyService.saveCourtDetails(court_id, school_id, playground_id);
  139. }
  140. response.put("status", "OK");
  141. response.put("message", "Playground Details saved successfully");
  142. return ResponseEntity.ok(response);
  143. } catch (Exception e) {
  144. e.printStackTrace();
  145. response.put("status", "ERROR");
  146. response.put("message", "Failed to save playground details");
  147. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
  148. }
  149. }
  150. // For Drinking Water
  151. @PostMapping(value = "/saveDrinkingWater")
  152. public ResponseEntity<Map<String, Object>> saveDrinkingWater(@RequestBody Map<String, Object> requestData) {
  153. try {
  154. // Extract data from the map
  155. List<Map<String, Object>> water = (List<Map<String, Object>>) requestData.get("water");
  156. Boolean is_purifier = "1".equals(requestData.get("is_purifier"));
  157. Double purifier_capacity = requestData.get("purifier_capacity") != null
  158. ? Double.valueOf(requestData.get("purifier_capacity").toString())
  159. : null;
  160. Boolean is_borewell = "1".equals(requestData.get("is_borewell"));
  161. Integer borewell_count = requestData.get("borewell_count") != null
  162. ? Integer.valueOf(requestData.get("borewell_count").toString())
  163. : null;
  164. Boolean is_storage = "1".equals(requestData.get("is_storage"));
  165. List<Map<String, Object>> storage = (List<Map<String, Object>>) requestData.get("storage");
  166. int school_id = Integer.parseInt(requestData.get("school_id").toString());
  167. Map<String, Object> response = new HashMap<>();
  168. int drinking_water_id = schoolPropertyService.saveDrinkingWater(is_purifier, purifier_capacity, is_borewell,
  169. borewell_count, is_storage, school_id);
  170. for (Map<String, Object> waterSupply : water) {
  171. int source_water_id = (int) waterSupply.get("source_water_id");
  172. String supply_type = (String) waterSupply.get("supply_type");
  173. schoolPropertyService.saveWaterSupply(source_water_id, supply_type, drinking_water_id, school_id);
  174. }
  175. if (!storage.isEmpty()) {
  176. for (Map<String, Object> waterStorage : storage) {
  177. double capacity = Double.valueOf(waterStorage.get("capacity").toString());
  178. int storage_water_id = (int) waterStorage.get("storage_water_id");
  179. schoolPropertyService.saveWaterStorage(capacity, storage_water_id, drinking_water_id, school_id);
  180. }
  181. }
  182. response.put("status", "OK");
  183. return ResponseEntity.ok(response);
  184. } catch (Exception e) {
  185. e.printStackTrace();
  186. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  187. .body(Map.of("status", "Error", "message", "Error saving data: " + e.getMessage()));
  188. }
  189. }
  190. @PostMapping("/saveStaffStrength")
  191. public String saveStaffStrength(@RequestParam int sgRegTeacher, @RequestParam int sgTempTeacher,
  192. @RequestParam int sgPtTeacher, @RequestParam int sgNgoTeacher, @RequestParam int btRegTeacher,
  193. @RequestParam int btTempTeacher, @RequestParam int btPtTeacher, @RequestParam int btNgoTeacher,
  194. @RequestParam int pgRegTeacher, @RequestParam int pgTempTeacher, @RequestParam int pgPtTeacher,
  195. @RequestParam int pgNgoTeacher, @RequestParam int kgRegTeacher, @RequestParam int kgTempTeacher,
  196. @RequestParam int petRegTeacher, @RequestParam int petTempTeacher, @RequestParam int petGrade1Teacher,
  197. @RequestParam int petGrade2Teacher, @RequestParam int totOa, @RequestParam int kgAyah,
  198. @RequestParam int compAss, @RequestParam int watchmen, @RequestParam int scavengers,
  199. @RequestParam int maintenanceWork, @RequestParam int schoolId) {
  200. // Call service method
  201. schoolPropertyService.saveStaffStrength(sgRegTeacher, sgTempTeacher, sgPtTeacher, sgNgoTeacher, btRegTeacher,
  202. btTempTeacher, btPtTeacher, btNgoTeacher, pgRegTeacher, pgTempTeacher, pgPtTeacher, pgNgoTeacher,
  203. kgRegTeacher, kgTempTeacher, petRegTeacher, petTempTeacher, petGrade1Teacher, petGrade2Teacher, totOa,
  204. kgAyah, compAss, watchmen, scavengers, maintenanceWork, schoolId);
  205. return "Staff strength details saved successfully!";
  206. }
  207. // For login
  208. @GetMapping(value = "/getLoginDetails")
  209. public List<Map<String, Object>> getLoginDetails(@RequestParam String user_id) {
  210. List<Map<String, Object>> schoolData = new ArrayList<>();
  211. Map<String, Object> response = new HashMap<>();
  212. String schoolId = schoolPropertyService.getSchoolId(user_id);
  213. if (schoolId == null || schoolId.trim().isEmpty() || schoolId.equalsIgnoreCase("error")) {
  214. response.put("Message", "Failure");
  215. response.put("Data", List.of());
  216. schoolData.add(response);
  217. return schoolData;
  218. }
  219. List<Map<String, Object>> sch = schoolPropertyService.getSchoolData1(schoolId);
  220. if (!sch.isEmpty()) {
  221. response.put("Message", "Success");
  222. response.put("Data", sch);
  223. schoolData.add(response);
  224. return schoolData;
  225. } else {
  226. response.put("Message", "No Data Found");
  227. response.put("Data", List.of());
  228. schoolData.add(response);
  229. return schoolData;
  230. }
  231. }
  232. @GetMapping("/getSchoolDetails")
  233. public ResponseEntity<Map<String, Object>> getSchoolDetails(@RequestParam Long schoolId) {
  234. try {
  235. Map<String, Object> data = schoolPropertyService.getSchoolDetails(schoolId);
  236. if (data != null && !data.isEmpty()) {
  237. return ResponseEntity.ok(data);
  238. } else {
  239. return ResponseEntity.status(HttpStatus.NOT_FOUND)
  240. .body(Map.of("status", "Failed", "message", "No school found with given ID"));
  241. }
  242. } catch (Exception e) {
  243. e.printStackTrace();
  244. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  245. .body(Map.of("status", "Error", "message", e.getMessage()));
  246. }
  247. }
  248. @GetMapping("/filterSchools")
  249. public ResponseEntity<?> filterSchools(@RequestParam String user_id, @RequestParam(required = false) String udise,
  250. @RequestParam(required = false) String category, @RequestParam(required = false) String zone,
  251. @RequestParam(required = false) String ward) {
  252. List<Map<String, Object>> filteredSchools = schoolPropertyService.filterSchools(user_id, udise, category, zone,
  253. ward);
  254. Map<String, Object> result = new HashMap<>();
  255. result.put("Message", "Success");
  256. result.put("Data", filteredSchools);
  257. return ResponseEntity.ok(Collections.singletonList(result));
  258. }
  259. @PostMapping("/updateOtherDetails")
  260. public String updateOtherDetails(@RequestParam("land_area") Double land_area,
  261. @RequestParam("buildup_area") Double buildup_area, @RequestParam("is_compound") Boolean is_compound,
  262. @RequestParam("is_nameboard") Boolean is_nameboard, @RequestParam("is_pasystem") Boolean is_pasystem,
  263. @RequestParam("is_bell") Boolean is_bell, @RequestParam("is_generator") Boolean is_generator,
  264. @RequestParam("school_id") int school_id) {
  265. try {
  266. return schoolPropertyService.updateOtherDetails(land_area, buildup_area, is_compound, is_nameboard,
  267. is_pasystem, is_bell, is_generator, school_id);
  268. } catch (Exception e) {
  269. e.printStackTrace();
  270. return "Error";
  271. }
  272. }
  273. @PostMapping(value = "/updateStudentDetails")
  274. public String updateStudentDetails(@RequestParam("total_students") int total_students,
  275. @RequestParam("total_girls") int total_girls, @RequestParam("total_boys") int total_boys,
  276. @RequestParam("others") int others, @RequestParam("school_id") int school_id) {
  277. System.out.println("Update Request => total: " + total_students + ", boys: " + total_boys + ", girls: "
  278. + total_girls + ", others: " + others + ", school_id: " + school_id);
  279. try {
  280. return schoolPropertyService.updateStudentDetails(total_students, total_girls, total_boys, others,
  281. school_id);
  282. } catch (Exception e) {
  283. e.printStackTrace();
  284. return "Error";
  285. }
  286. }
  287. @GetMapping("/checkPlaygroundDetails")
  288. public ResponseEntity<?> checkPlaygroundDetails(@RequestParam int school_id) {
  289. Map<String, Object> playgroundDetails = schoolPropertyService.checkPlaygroundDetails(school_id);
  290. List<Map<String, Object>> courtDetails = schoolPropertyService.checkCourtDetails(school_id);
  291. List<Map<String, Object>> equipmentDetails = schoolPropertyService.checkEquipmentDetails(school_id);
  292. Map<String, Object> result = new HashMap<>();
  293. result.put("Message", "Success");
  294. result.put("playgroundDetails", playgroundDetails);
  295. result.put("CourtDetails", courtDetails);
  296. result.put("EquipmentDetails", equipmentDetails);
  297. return ResponseEntity.ok(Collections.singletonList(result));
  298. }
  299. /*
  300. * @PostMapping(value = "/updatePlayground") public ResponseEntity<String>
  301. * updatePlayground(@RequestBody Map<String, Object> payload) { try { Boolean
  302. * is_playground = (Boolean) payload.get("is_playground"); Double
  303. * playground_area = Double.valueOf(payload.get("playground_area").toString());
  304. * Boolean is_court = (Boolean) payload.get("is_court"); int school_id =
  305. * Integer.parseInt(payload.get("school_id").toString()); int playground_id =
  306. * Integer.parseInt(payload.get("playground_id").toString());
  307. *
  308. * List<Map<String, Object>> equipments = (List<Map<String, Object>>)
  309. * payload.get("equipments"); List<Map<String, Object>> courts =
  310. * (List<Map<String, Object>>) payload.get("courts");
  311. *
  312. * String result = schoolPropertyService.updatePlaygroundDetails( is_playground,
  313. * playground_area, is_court, equipments, courts, playground_id, school_id );
  314. * return ResponseEntity.ok(result);
  315. *
  316. * } catch (Exception e) { e.printStackTrace(); return
  317. * ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Error"); } }
  318. */
  319. // @PostMapping(value = "/updatePlayground")
  320. // public ResponseEntity<Map<String, String>> updatePlayground(@RequestBody Map<String, Object> payload) {
  321. // Map<String, String> response = new HashMap<>();
  322. // try {
  323. // Boolean is_playground = (Boolean) payload.get("is_playground");
  324. // Double playground_area = Double.valueOf(payload.get("playground_area").toString());
  325. // Boolean is_court = (Boolean) payload.get("is_court");
  326. // int school_id = Integer.parseInt(payload.get("school_id").toString());
  327. // //Boolean is_active = (Boolean) payload.get("is_active");
  328. // int playground_id = Integer.parseInt(payload.get("playground_id").toString());
  329. //
  330. //
  331. // List<String> equipmentidRaw = (List<String>) payload.get("equipments");
  332. // List<String> courtidRaw = (List<String>) payload.get("courts");
  333. //
  334. // // Convert string IDs to integers
  335. // List<Integer> equipmentid = equipmentidRaw.stream().map(Integer::parseInt).toList();
  336. // List<Integer> courtid = courtidRaw.stream().map(Integer::parseInt).toList();
  337. // schoolPropertyService.deactiveCourts(school_id);
  338. // schoolPropertyService.deactiveEquipments(school_id);
  339. // schoolPropertyService.updatePlayground(is_playground, playground_area, is_court, school_id, playground_id);
  340. // //int playground_id = schoolPropertyService.savePlayground(is_playground, playground_area, is_court,
  341. // // school_id);
  342. //
  343. // for (Integer equipment_id : equipmentid) {
  344. // schoolPropertyService.saveEquipmentDetails(equipment_id, school_id, playground_id);
  345. // }
  346. //
  347. // for (Integer court_id : courtid) {
  348. // schoolPropertyService.saveCourtDetails(court_id, school_id, playground_id);
  349. // }
  350. //
  351. // response.put("status", "OK");
  352. // response.put("message", "Playground Details updated successfully");
  353. // return ResponseEntity.ok(response);
  354. //
  355. // } catch (Exception e) {
  356. // e.printStackTrace();
  357. // response.put("status", "ERROR");
  358. // response.put("message", "Failed to updated playground details");
  359. // return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
  360. // }
  361. // }
  362. @PostMapping(value = "/updatePlayground")
  363. public ResponseEntity<Map<String, String>> updatePlayground(@RequestBody Map<String, Object> payload) {
  364. Map<String, String> response = new HashMap<>();
  365. try {
  366. Boolean is_playground = (Boolean) payload.get("is_playground");
  367. Double playground_area = Double.valueOf(payload.get("playground_area").toString());
  368. Boolean is_court = (Boolean) payload.get("is_court");
  369. int school_id = Integer.parseInt(payload.get("school_id").toString());
  370. int playground_id = Integer.parseInt(payload.get("playground_id").toString());
  371. List<Map<String, Object>> equipmentList = (List<Map<String, Object>>) payload.get("equipments");
  372. List<Map<String, Object>> courtList = (List<Map<String, Object>>) payload.get("courts");
  373. String status = schoolPropertyService.updatePlaygroundDetails(is_playground, playground_area, is_court,
  374. equipmentList, courtList, playground_id, school_id);
  375. response.put("status", status.equals("Success") ? "OK" : "ERROR");
  376. response.put("message",
  377. status.equals("Success") ? "Playground updated successfully" : "Failed to update playground");
  378. return ResponseEntity.ok(response);
  379. } catch (Exception e) {
  380. e.printStackTrace();
  381. response.put("status", "ERROR");
  382. response.put("message", "Exception occurred during update");
  383. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
  384. }
  385. }
  386. @PostMapping(value = "/updateKitchenDetails")
  387. public String updateKitchenDetails(@RequestParam(value = "is_cmbfs") Boolean is_cmbfs,
  388. @RequestParam(value = "is_cmbfsIndividual", required = false) Boolean is_cmbfsIndividual,
  389. @RequestParam(value = "is_noonmeal") Boolean is_noonmeal,
  390. @RequestParam(value = "is_noonIndividual", required = false) Boolean is_noonIndividual,
  391. @RequestParam(value = "is_vegGarden", required = false) Boolean is_vegGarden,
  392. @RequestParam(value = "is_anganwadi") Boolean is_anganwadi,
  393. @RequestParam(value = "anganwadi_unique", required = false) String anganwadi_unique,
  394. @RequestParam(value = "is_anganwadiIndividual", required = false) Boolean is_anganwadiIndividual,
  395. @RequestParam(value = "school_id") int school_id) {
  396. try {
  397. return schoolPropertyService.updateKitchenDetails(is_cmbfs, is_cmbfsIndividual, is_noonmeal,
  398. is_noonIndividual, is_vegGarden, is_anganwadi, anganwadi_unique, is_anganwadiIndividual, school_id);
  399. } catch (Exception e) {
  400. e.printStackTrace();
  401. return "Error";
  402. }
  403. }
  404. @GetMapping("/checkKitchenDetails")
  405. public ResponseEntity<?> checkKitchenDetails(@RequestParam int school_id) {
  406. Map<String, Object> kitchenDetails = schoolPropertyService.checkKitchenDetails(school_id);
  407. Map<String, Object> result = new HashMap<>();
  408. result.put("Message", "Success");
  409. result.put("Data", kitchenDetails);
  410. return ResponseEntity.ok(Collections.singletonList(result));
  411. }
  412. @PostMapping(value = "/updateStaffDetails")
  413. public String updateStaffDetails(@RequestParam int sgRegTeacher, @RequestParam int sgTempTeacher,
  414. @RequestParam int sgPtTeacher, @RequestParam int sgNgoTeacher, @RequestParam int btRegTeacher,
  415. @RequestParam int btTempTeacher, @RequestParam int btPtTeacher, @RequestParam int btNgoTeacher,
  416. @RequestParam int pgRegTeacher, @RequestParam int pgTempTeacher, @RequestParam int pgPtTeacher,
  417. @RequestParam int pgNgoTeacher, @RequestParam int kgRegTeacher, @RequestParam int kgTempTeacher,
  418. @RequestParam int petRegTeacher, @RequestParam int petTempTeacher, @RequestParam int petGrade1Teacher,
  419. @RequestParam int petGrade2Teacher, @RequestParam int totOa, @RequestParam int kgAyah,
  420. @RequestParam int compAss, @RequestParam int watchmen, @RequestParam int scavengers,
  421. @RequestParam int maintenanceWork, @RequestParam int school_id) {
  422. try {
  423. return schoolPropertyService.updateStaffDetails(sgRegTeacher, sgTempTeacher, sgPtTeacher, sgNgoTeacher,
  424. btRegTeacher, btTempTeacher, btPtTeacher, btNgoTeacher, pgRegTeacher, pgTempTeacher, pgPtTeacher,
  425. pgNgoTeacher, kgRegTeacher, kgTempTeacher, petRegTeacher, petTempTeacher, petGrade1Teacher,
  426. petGrade2Teacher, totOa, kgAyah, compAss, watchmen, scavengers, maintenanceWork, school_id);
  427. } catch (Exception e) {
  428. e.printStackTrace();
  429. return "Error";
  430. }
  431. }
  432. /*
  433. * @GetMapping("/checkWaterDetails") public ResponseEntity<?> checkWaterDetails(
  434. *
  435. * @RequestParam int school_id) {
  436. *
  437. * Map<String, Object> drinkingWater =
  438. * schoolPropertyService.checkWaterDetails(school_id); List<Map<String, Object>>
  439. * waterSource = schoolPropertyService.checkWaterSource(school_id);
  440. * List<Map<String, Object>> waterStorage =
  441. * schoolPropertyService.checkWaterStotage(school_id);
  442. *
  443. * Map<String, Object> result = new HashMap<>(); result.put("Message",
  444. * "Success"); result.put("DrinkingWater", drinkingWater);
  445. * result.put("WaterSource", waterSource); result.put("WaterStorage",
  446. * waterStorage);
  447. *
  448. * return ResponseEntity.ok(Collections.singletonList(result)); }
  449. */
  450. // @PostMapping(value = "/updateDrinkingWater")
  451. // public String updateDrinkingWater(@RequestParam("is_purifier") Boolean is_purifier, @RequestParam("purifier_capacity") Double purifier_capacity,
  452. // @RequestParam("is_borewell") Boolean is_borewell, @RequestParam("borewell_count") int borewell_count, @RequestParam("is_storage") Boolean is_storage,
  453. // @RequestParam("drinking_water_id") int drinking_water_id, @RequestParam("school_id") int school_id, @RequestParam("supply") List<Map<String, Object>> supply,
  454. // @RequestParam("storage") List<Map<String, Object>> storage) {
  455. // try {
  456. //
  457. // return schoolPropertyService.updateDrinkingWater(is_purifier, purifier_capacity, is_borewell, borewell_count, is_storage, drinking_water_id, school_id, supply, storage);
  458. //
  459. // } catch (Exception e) {
  460. // e.printStackTrace();
  461. // return "Error";
  462. // }
  463. //
  464. // }
  465. @PostMapping(value = "/updateDrinkingWater")
  466. public ResponseEntity<Map<String, Object>> updateDrinkingWater(@RequestBody Map<String, Object> requestData) {
  467. try {
  468. System.out.println("Received update payload: " + requestData);
  469. // Extract data from the map
  470. // List<Map<String, Object>> water = (List<Map<String, Object>>)
  471. // requestData.get("water");
  472. List<Map<String, Object>> water = (List<Map<String, Object>>) requestData.getOrDefault("supply",
  473. new ArrayList<>());
  474. List<Map<String, Object>> storage = (List<Map<String, Object>>) requestData.getOrDefault("storage",
  475. new ArrayList<>());
  476. Boolean is_purifier = (Boolean) requestData.get("is_purifier");
  477. Double purifier_capacity = requestData.get("purifier_capacity") != null
  478. ? Double.valueOf(requestData.get("purifier_capacity").toString())
  479. : 0;
  480. Boolean is_borewell = (Boolean) requestData.get("is_borewell");
  481. Integer borewell_count = requestData.get("borewell_count") != null
  482. ? Integer.valueOf(requestData.get("borewell_count").toString())
  483. : 0;
  484. Boolean is_storage = (Boolean) requestData.get("is_storage");
  485. // List<Map<String, Object>> storage = (List<Map<String, Object>>)
  486. // requestData.get("storage");
  487. int school_id = Integer.parseInt(requestData.get("school_id").toString());
  488. int drinking_water_id = Integer.parseInt(requestData.get("drinking_water_id").toString());
  489. Map<String, Object> response = new HashMap<>();
  490. schoolPropertyService.updateDrinkWater(is_purifier, purifier_capacity, is_borewell, borewell_count,
  491. is_storage, school_id, drinking_water_id);
  492. schoolPropertyService.deactiveWaterSupply(school_id, drinking_water_id);
  493. schoolPropertyService.deactiveWaterStorage(school_id, drinking_water_id);
  494. for (Map<String, Object> waterSupply : water) {
  495. int source_water_id = (int) waterSupply.get("source_water_id");
  496. String supply_type = (String) waterSupply.get("supply_type");
  497. schoolPropertyService.saveWaterSupply(source_water_id, supply_type, drinking_water_id, school_id);
  498. }
  499. if (!storage.isEmpty()) {
  500. for (Map<String, Object> waterStorage : storage) {
  501. double capacity = Double.valueOf(waterStorage.get("capacity").toString());
  502. int storage_water_id = (int) waterStorage.get("storage_water_id");
  503. schoolPropertyService.saveWaterStorage(capacity, storage_water_id, drinking_water_id, school_id);
  504. }
  505. }
  506. response.put("status", "OK");
  507. return ResponseEntity.ok(response);
  508. } catch (Exception e) {
  509. e.printStackTrace();
  510. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  511. .body(Map.of("status", "Error", "message", "Error saving data: " + e.getMessage()));
  512. }
  513. }
  514. @GetMapping("/checkWaterDetails")
  515. public ResponseEntity<Map<String, Object>> checkWaterDetails(@RequestParam int school_id) {
  516. System.out.println("CHECK 11");
  517. try {
  518. System.out.println("CHECK 1");
  519. Map<String, Object> drinkingWater = schoolPropertyService.checkWaterDetails(school_id);
  520. List<Map<String, Object>> waterSource = schoolPropertyService.checkWaterSource(school_id);
  521. List<Map<String, Object>> waterStorage = schoolPropertyService.checkWaterStotage(school_id);
  522. System.out.println("WATER SOURCE = " + waterSource);
  523. Map<String, Object> response = new HashMap<>();
  524. response.put("DrinkingWater", drinkingWater);
  525. response.put("WaterSource", waterSource);
  526. response.put("WaterStorage", waterStorage);
  527. // ✅ Set status based on content presence
  528. if (drinkingWater != null && !drinkingWater.isEmpty()) {
  529. response.put("status", "OK");
  530. } else {
  531. response.put("status", "NEW");
  532. }
  533. return ResponseEntity.ok(response);
  534. } catch (Exception e) {
  535. e.printStackTrace();
  536. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  537. .body(Map.of("status", "Error", "message", "Could not load drinking water data"));
  538. }
  539. }
  540. @GetMapping("/checkToiletDetails")
  541. public ResponseEntity<?> checkToiletDetails(@RequestParam int school_id) {
  542. List<Map<String, Object>> toiletDetails = schoolPropertyService.checkToiletDetails(school_id);
  543. Map<String, Object> result = new HashMap<>();
  544. result.put("Message", "Success");
  545. result.put("Data", toiletDetails);
  546. return ResponseEntity.ok(Collections.singletonList(result));
  547. }
  548. @PostMapping(value = "/updateToiletDetails")
  549. public String updateToiletDetails(@RequestParam("total_toiletBlocks") int total_toiletBlocks,
  550. @RequestParam("total_male_urinals") int total_male_urinals,
  551. @RequestParam("total_wc_male") int total_wc_male, @RequestParam("total_wc_female") int total_wc_female,
  552. @RequestParam("total_diffAbled_toilet") int total_diffAbled_toilet,
  553. @RequestParam("is_napkins") Boolean is_napkins, @RequestParam("school_id") int school_id) {
  554. try {
  555. return schoolPropertyService.updateToiletDetails(total_toiletBlocks, total_male_urinals, total_wc_male,
  556. total_wc_female, total_diffAbled_toilet, is_napkins, school_id);
  557. } catch (Exception e) {
  558. e.printStackTrace();
  559. return "Error";
  560. }
  561. }
  562. @PostMapping(value = "/saveAssetMaster")
  563. public ResponseEntity<Map<String, String>> saveAssetMaster(@RequestBody Map<String, Object> payload) {
  564. Map<String, String> response = new HashMap<>();
  565. String status = "";
  566. try {
  567. int school_id = Integer.parseInt(payload.get("school_id").toString());
  568. int asset_id = Integer.parseInt(payload.get("asset_id").toString());
  569. List<Map<String, Object>> equipmentList = (List<Map<String, Object>>) payload.get("data");
  570. for (Map<String, Object> asset : equipmentList) {
  571. int sub_asset_id = Integer.parseInt(asset.get("sub_asset_id").toString());
  572. int master_qty = Integer.parseInt(asset.get("master_qty").toString());
  573. status = schoolPropertyService.saveAssetMaster(sub_asset_id, master_qty, school_id, asset_id);
  574. }
  575. response.put("status", status.equals("Success") ? "OK" : "ERROR");
  576. response.put("message",
  577. status.equals("Success") ? "Asset Master Saved successfully" : "Failed to Save Asset Master");
  578. return ResponseEntity.ok(response);
  579. } catch (Exception e) {
  580. e.printStackTrace();
  581. response.put("status", "ERROR");
  582. response.put("message", "Exception occurred during update");
  583. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
  584. }
  585. }
  586. @GetMapping("/getAssetMaster")
  587. public ResponseEntity<?> getAssetMaster(@RequestParam int school_id, @RequestParam int asset_id) {
  588. List<Map<String, Object>> data = schoolPropertyService.getAssetMaster(school_id, asset_id);
  589. // System.out.println("data=="+data);
  590. Map<String, Object> result = new HashMap<>();
  591. result.put("status", "Success");
  592. result.put("data", data);
  593. return ResponseEntity.ok(result);
  594. }
  595. @GetMapping("/getAssetMasterById")
  596. public ResponseEntity<?> getAssetMasterById(@RequestParam int assetMasterId, @RequestParam int asset_id) {
  597. Map<String, Object> data = schoolPropertyService.getAssetMasterById(assetMasterId, asset_id);
  598. Map<String, Object> result = new HashMap<>();
  599. result.put("status", "Success");
  600. result.put("data", data);
  601. return ResponseEntity.ok(result);
  602. }
  603. @PostMapping(value = "/updateAssetMaster")
  604. public String updateStudentDetails(@RequestParam("master_qty") int master_qty,
  605. @RequestParam("assetMasterId") int assetMasterId, @RequestParam("asset_id") int asset_id) {
  606. try {
  607. Map<String, Object> assetMaster = schoolPropertyService.getAssetMasterById(assetMasterId, asset_id);
  608. int qty = (Integer) assetMaster.get("master_qty");
  609. int unmapped_asset = (Integer) assetMaster.get("unmapped_qty");
  610. int master = qty + master_qty;
  611. int unmapped = master_qty + unmapped_asset;
  612. return schoolPropertyService.updateAssetMaster(assetMasterId, master, asset_id, unmapped);
  613. } catch (Exception e) {
  614. e.printStackTrace();
  615. return "Error";
  616. }
  617. }
  618. }