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.

477 lines
16 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 java.util.stream.Collectors;
  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.GetMapping;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RequestParam;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import in.gov.chennaicorporation.gccoffice.school.Service.DropdownsService;
  16. @RestController
  17. @RequestMapping("/gcc/api/gccschool/dropdown")
  18. public class DropdownsController {
  19. @Autowired
  20. private DropdownsService dropdownsService;
  21. @Autowired
  22. public DropdownsController(DropdownsService dropdownsService) {
  23. this.dropdownsService = dropdownsService;
  24. }
  25. // To Get Court Dropdown Data
  26. @GetMapping("/getCourtData")
  27. public ResponseEntity<Map<String, Object>> getCourtData() {
  28. try {
  29. List<Map<String, Object>> data = dropdownsService.getCourtData();
  30. Map<String, Object> response = new HashMap<>();
  31. if (data.size() != 0) {
  32. response.put("status", "OK");
  33. response.put("data", data);
  34. } else {
  35. response.put("status", "Failed");
  36. response.put("data", "No Data Found");
  37. }
  38. return ResponseEntity.ok(response);
  39. } catch (Exception e) {
  40. // Log the exception details for debugging
  41. e.printStackTrace();
  42. // Provide a user-friendly error message
  43. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  44. .body(Map.of("status", "Error", "message", "Error getting data: " + e.getMessage()));
  45. }
  46. }
  47. // To Get Equipmengt Dropdown Data
  48. @GetMapping("/getEquipmentData")
  49. public ResponseEntity<Map<String, Object>> getEquipmentData() {
  50. try {
  51. List<Map<String, Object>> data = dropdownsService.getEquipmentData();
  52. Map<String, Object> response = new HashMap<>();
  53. if (data.size() != 0) {
  54. response.put("status", "OK");
  55. response.put("data", data);
  56. } else {
  57. response.put("status", "Failed");
  58. response.put("data", "No Data Found");
  59. }
  60. return ResponseEntity.ok(response);
  61. } catch (Exception e) {
  62. // Log the exception details for debugging
  63. e.printStackTrace();
  64. // Provide a user-friendly error message
  65. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  66. .body(Map.of("status", "Error", "message", "Error getting data: " + e.getMessage()));
  67. }
  68. }
  69. // To Get Building Material Dropdown Data
  70. @GetMapping("/getBuildingMaterial")
  71. public ResponseEntity<Map<String, Object>> getBuildingMaterial() {
  72. try {
  73. List<Map<String, Object>> data = dropdownsService.getBuildingMaterial();
  74. Map<String, Object> response = new HashMap<>();
  75. if (data.size() != 0) {
  76. response.put("status", "OK");
  77. response.put("data", data);
  78. } else {
  79. response.put("status", "Failed");
  80. response.put("data", "No Data Found");
  81. }
  82. return ResponseEntity.ok(response);
  83. } catch (Exception e) {
  84. // Log the exception details for debugging
  85. e.printStackTrace();
  86. // Provide a user-friendly error message
  87. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  88. .body(Map.of("status", "Error", "message", "Error getting data: " + e.getMessage()));
  89. }
  90. }
  91. // To Get Roof Material Dropdown Data
  92. @GetMapping("/getRoofMaterial")
  93. public ResponseEntity<Map<String, Object>> getRoofMaterial() {
  94. try {
  95. List<Map<String, Object>> data = dropdownsService.getRoofMaterial();
  96. Map<String, Object> response = new HashMap<>();
  97. if (data.size() != 0) {
  98. response.put("status", "OK");
  99. response.put("data", data);
  100. } else {
  101. response.put("status", "Failed");
  102. response.put("data", "No Data Found");
  103. }
  104. return ResponseEntity.ok(response);
  105. } catch (Exception e) {
  106. // Log the exception details for debugging
  107. e.printStackTrace();
  108. // Provide a user-friendly error message
  109. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  110. .body(Map.of("status", "Error", "message", "Error getting data: " + e.getMessage()));
  111. }
  112. }
  113. // To Get Water Source Dropdown Data
  114. @GetMapping("/getWaterSource")
  115. public ResponseEntity<Map<String, Object>> getWaterSource() {
  116. try {
  117. List<Map<String, Object>> data = dropdownsService.getWaterSource();
  118. Map<String, Object> response = new HashMap<>();
  119. if (data.size() != 0) {
  120. response.put("status", "OK");
  121. response.put("data", data);
  122. } else {
  123. response.put("status", "Failed");
  124. response.put("data", "No Data Found");
  125. }
  126. return ResponseEntity.ok(response);
  127. } catch (Exception e) {
  128. // Log the exception details for debugging
  129. e.printStackTrace();
  130. // Provide a user-friendly error message
  131. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  132. .body(Map.of("status", "Error", "message", "Error getting data: " + e.getMessage()));
  133. }
  134. }
  135. // To Get Water Storage Dropdown Data
  136. @GetMapping("/getWaterStorage")
  137. public ResponseEntity<Map<String, Object>> getWaterStorage() {
  138. try {
  139. List<Map<String, Object>> data = dropdownsService.getWaterStorage();
  140. Map<String, Object> response = new HashMap<>();
  141. if (data.size() != 0) {
  142. response.put("status", "OK");
  143. response.put("data", data);
  144. } else {
  145. response.put("status", "Failed");
  146. response.put("data", "No Data Found");
  147. }
  148. return ResponseEntity.ok(response);
  149. } catch (Exception e) {
  150. // Log the exception details for debugging
  151. e.printStackTrace();
  152. // Provide a user-friendly error message
  153. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  154. .body(Map.of("status", "Error", "message", "Error getting data: " + e.getMessage()));
  155. }
  156. }
  157. // To Get Rooms Dropdown Data
  158. @GetMapping("/getRooms")
  159. public ResponseEntity<Map<String, Object>> getRooms() {
  160. try {
  161. List<Map<String, Object>> data = dropdownsService.getRooms();
  162. Map<String, Object> response = new HashMap<>();
  163. if (data.size() != 0) {
  164. response.put("status", "OK");
  165. response.put("data", data);
  166. } else {
  167. response.put("status", "Failed");
  168. response.put("data", "No Data Found");
  169. }
  170. return ResponseEntity.ok(response);
  171. } catch (Exception e) {
  172. // Log the exception details for debugging
  173. e.printStackTrace();
  174. // Provide a user-friendly error message
  175. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  176. .body(Map.of("status", "Error", "message", "Error getting data: " + e.getMessage()));
  177. }
  178. }
  179. @GetMapping("/getFloorsByBuilding")
  180. public ResponseEntity<Map<String, Object>> getFloorsByBuilding(@RequestParam("building_id") int buildingId) {
  181. try {
  182. List<Map<String, Object>> data = dropdownsService.getFloorsByBuilding(buildingId);
  183. Map<String, Object> response = new HashMap<>();
  184. if (!data.isEmpty()) {
  185. response.put("status", "OK");
  186. response.put("data", data);
  187. } else {
  188. response.put("status", "Failed");
  189. response.put("data", "No floors found for the selected building.");
  190. }
  191. return ResponseEntity.ok(response);
  192. } catch (Exception e) {
  193. e.printStackTrace();
  194. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  195. .body(Map.of("status", "Error", "message", "Failed to fetch floors."));
  196. }
  197. }
  198. @GetMapping("/getBuildingsBySchoolId")
  199. public ResponseEntity<Map<String, Object>> getBuildingsBySchoolId(@RequestParam int school_id) {
  200. try {
  201. List<Map<String, Object>> data = dropdownsService.getBuildingsBySchoolId(school_id);
  202. Map<String, Object> response = new HashMap<>();
  203. if (!data.isEmpty()) {
  204. response.put("status", "OK");
  205. response.put("data", data);
  206. } else {
  207. response.put("status", "Failed");
  208. response.put("data", "No buildings found for the selected school.");
  209. }
  210. return ResponseEntity.ok(response);
  211. } catch (Exception e) {
  212. e.printStackTrace();
  213. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  214. .body(Map.of("status", "Error", "message", "Failed to fetch buildings."));
  215. }
  216. }
  217. @GetMapping("/getDropdownValues")
  218. public List<Map<String, Object>> getDropdownValues(@RequestParam String user_id) {
  219. List<Map<String, Object>> resultList = new ArrayList<>();
  220. Map<String, Object> response = new HashMap<>();
  221. String schoolId = dropdownsService.getSchoolId(user_id);
  222. if (schoolId == null || schoolId.trim().isEmpty() || schoolId.equalsIgnoreCase("error")) {
  223. response.put("Message", "Failure");
  224. response.put("Data", List.of());
  225. resultList.add(response);
  226. return resultList;
  227. }
  228. List<Map<String, Object>> udiseData = dropdownsService.getUdiseNumbersBySchoolId(schoolId);
  229. if (!udiseData.isEmpty()) {
  230. List<String> udiseList = udiseData.stream().map(m -> (String) m.get("udise")).collect(Collectors.toList());
  231. response.put("Message", "Success");
  232. response.put("Data", udiseList);
  233. } else {
  234. response.put("Message", "No Data Found");
  235. response.put("Data", List.of());
  236. }
  237. resultList.add(response);
  238. return resultList;
  239. }
  240. @GetMapping("/getCategoryValues")
  241. public List<Map<String, Object>> getCategoryValues(@RequestParam String user_id) {
  242. List<Map<String, Object>> resultList = new ArrayList<>();
  243. Map<String, Object> response = new HashMap<>();
  244. String schoolId = dropdownsService.getSchoolId(user_id);
  245. if (schoolId == null || schoolId.trim().isEmpty() || schoolId.equalsIgnoreCase("error")) {
  246. response.put("Message", "Failure");
  247. response.put("Data", List.of());
  248. resultList.add(response);
  249. return resultList;
  250. }
  251. List<Map<String, Object>> categoryData = dropdownsService.getCategoryBySchoolId(schoolId);
  252. if (!categoryData.isEmpty()) {
  253. List<String> categoryList = categoryData.stream().map(m -> (String) m.get("category"))
  254. .collect(Collectors.toList());
  255. response.put("Message", "Success");
  256. response.put("Data", categoryList);
  257. } else {
  258. response.put("Message", "No Data Found");
  259. response.put("Data", List.of());
  260. }
  261. resultList.add(response);
  262. return resultList;
  263. }
  264. @GetMapping("/getZoneValues")
  265. public List<Map<String, Object>> getZoneValues(@RequestParam String user_id) {
  266. List<Map<String, Object>> resultList = new ArrayList<>();
  267. Map<String, Object> response = new HashMap<>();
  268. String schoolId = dropdownsService.getSchoolId(user_id);
  269. if (schoolId == null || schoolId.trim().isEmpty() || schoolId.equalsIgnoreCase("error")) {
  270. response.put("Message", "Failure");
  271. response.put("Data", List.of());
  272. resultList.add(response);
  273. return resultList;
  274. }
  275. List<Map<String, Object>> zoneData = dropdownsService.getZoneBySchoolId(schoolId);
  276. if (!zoneData.isEmpty()) {
  277. List<String> zoneList = zoneData.stream().map(m -> (String) m.get("zone")).collect(Collectors.toList());
  278. response.put("Message", "Success");
  279. response.put("Data", zoneList);
  280. } else {
  281. response.put("Message", "No Data Found");
  282. response.put("Data", List.of());
  283. }
  284. resultList.add(response);
  285. return resultList;
  286. }
  287. @GetMapping("/getwardValues")
  288. public List<Map<String, Object>> getWardValues(@RequestParam String user_id) {
  289. List<Map<String, Object>> resultList = new ArrayList<>();
  290. Map<String, Object> response = new HashMap<>();
  291. String schoolId = dropdownsService.getSchoolId(user_id);
  292. if (schoolId == null || schoolId.trim().isEmpty() || schoolId.equalsIgnoreCase("error")) {
  293. response.put("Message", "Failure");
  294. response.put("Data", List.of());
  295. resultList.add(response);
  296. return resultList;
  297. }
  298. List<Map<String, Object>> wardData = dropdownsService.getWardBySchoolId(schoolId);
  299. if (!wardData.isEmpty()) {
  300. List<String> wardList = wardData.stream().map(m -> (String) m.get("division")).collect(Collectors.toList());
  301. response.put("Message", "Success");
  302. response.put("Data", wardList);
  303. } else {
  304. response.put("Message", "No Data Found");
  305. response.put("Data", List.of());
  306. }
  307. resultList.add(response);
  308. return resultList;
  309. }
  310. @GetMapping("/getAllDropdownValues")
  311. public ResponseEntity<?> getAllDropdownValues(@RequestParam String user_id, @RequestParam String type) {
  312. Map<String, Object> response = new HashMap<>();
  313. List<String> dropdownList = Collections.emptyList();
  314. // First get school_id(s) for this user
  315. String schoolId = dropdownsService.getSchoolId(user_id);
  316. if (schoolId.equals("error")) {
  317. response.put("Message", "Failed to fetch school ID");
  318. response.put("Data", dropdownList);
  319. return ResponseEntity.ok(Collections.singletonList(response));
  320. }
  321. try {
  322. List<Map<String, Object>> rawData;
  323. switch (type.toLowerCase()) {
  324. case "udise":
  325. rawData = dropdownsService.getUdiseNumbersBySchoolId(schoolId);
  326. dropdownList = rawData.stream().map(map -> String.valueOf(map.get("udise")))
  327. .collect(Collectors.toList());
  328. break;
  329. case "category":
  330. rawData = dropdownsService.getCategoryBySchoolId(schoolId);
  331. dropdownList = rawData.stream().map(map -> String.valueOf(map.get("category"))).distinct()
  332. .collect(Collectors.toList());
  333. break;
  334. case "zone":
  335. rawData = dropdownsService.getZoneBySchoolId(schoolId);
  336. dropdownList = rawData.stream().map(map -> String.valueOf(map.get("zone"))).distinct()
  337. .collect(Collectors.toList());
  338. break;
  339. case "ward":
  340. rawData = dropdownsService.getWardBySchoolId(schoolId);
  341. dropdownList = rawData.stream().map(map -> String.valueOf(map.get("division"))).distinct()
  342. .collect(Collectors.toList());
  343. break;
  344. default:
  345. response.put("Message", "Invalid dropdown type");
  346. response.put("Data", dropdownList);
  347. return ResponseEntity.badRequest().body(Collections.singletonList(response));
  348. }
  349. response.put("Message", "Success");
  350. response.put("Data", dropdownList);
  351. return ResponseEntity.ok(Collections.singletonList(response));
  352. } catch (Exception e) {
  353. e.printStackTrace();
  354. response.put("Message", "Error while processing dropdown values");
  355. response.put("Data", dropdownList);
  356. return ResponseEntity.ok(Collections.singletonList(response));
  357. }
  358. }
  359. // To Get Asset Types Data
  360. @GetMapping("/getAssetType")
  361. public ResponseEntity<Map<String, Object>> getAssetType() {
  362. try {
  363. List<Map<String, Object>> data = dropdownsService.getAssetType();
  364. Map<String, Object> response = new HashMap<>();
  365. if (data.size() != 0) {
  366. response.put("status", "OK");
  367. response.put("data", data);
  368. } else {
  369. response.put("status", "Failed");
  370. response.put("data", "No Data Found");
  371. }
  372. return ResponseEntity.ok(response);
  373. } catch (Exception e) {
  374. // Log the exception details for debugging
  375. e.printStackTrace();
  376. // Provide a user-friendly error message
  377. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  378. .body(Map.of("status", "Error", "message", "Error getting data: " + e.getMessage()));
  379. }
  380. }
  381. // To Get Sub Asset Types Data
  382. @GetMapping("/getSubAssetType")
  383. public ResponseEntity<Map<String, Object>> getSubAssetType(int assetid) {
  384. try {
  385. List<Map<String, Object>> data = dropdownsService.getSubAssetType(assetid);
  386. Map<String, Object> response = new HashMap<>();
  387. if (data.size() != 0) {
  388. response.put("status", "OK");
  389. response.put("data", data);
  390. } else {
  391. response.put("status", "Failed");
  392. response.put("data", "No Data Found");
  393. }
  394. return ResponseEntity.ok(response);
  395. } catch (Exception e) {
  396. e.printStackTrace();
  397. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  398. .body(Map.of("status", "Error", "message", "Error getting data: " + e.getMessage()));
  399. }
  400. }
  401. @GetMapping("/getSplSubAssetType")
  402. public ResponseEntity<Map<String, Object>> getSplSubAssetType(int school_id, int assetid) {
  403. try {
  404. List<String> assets = dropdownsService.getAssetList(school_id, assetid);
  405. List<Map<String, Object>> data = dropdownsService.getSplSubAssetType(assets, assetid);
  406. Map<String, Object> response = new HashMap<>();
  407. if (data.size() != 0) {
  408. response.put("status", "OK");
  409. response.put("data", data);
  410. } else {
  411. response.put("status", "Failed");
  412. response.put("data", "No Data Found");
  413. }
  414. return ResponseEntity.ok(response);
  415. } catch (Exception e) {
  416. e.printStackTrace();
  417. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  418. .body(Map.of("status", "Error", "message", "Error getting data: " + e.getMessage()));
  419. }
  420. }
  421. }