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.

174 lines
6.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. package in.gov.chennaicorporation.gccoffice.cdwaste.controller;
  2. import java.time.LocalDate;
  3. import java.util.ArrayList;
  4. import java.util.Collections;
  5. import java.util.List;
  6. import java.util.Map;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.format.annotation.DateTimeFormat;
  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.PostMapping;
  13. import org.springframework.web.bind.annotation.RequestBody;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestParam;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import org.springframework.web.client.RestTemplate;
  18. import in.gov.chennaicorporation.gccoffice.cdwaste.service.OfficerService;
  19. import in.gov.chennaicorporation.gccoffice.configuration.AppConfig;
  20. @RestController
  21. @RequestMapping("/gcc/api/dumpregistration")
  22. public class DumpRegistrationAPIController {
  23. @Autowired
  24. private OfficerService officerService;
  25. private final RestTemplate restTemplate;
  26. private final AppConfig appConfig;
  27. @Autowired
  28. public DumpRegistrationAPIController(RestTemplate restTemplate, AppConfig appConfig) {
  29. this.restTemplate = restTemplate;
  30. this.appConfig = appConfig;
  31. }
  32. @GetMapping("/wastecollectorlist")
  33. public ResponseEntity<String> getWasteCollectorList(
  34. @RequestParam(required = false) Long mobileNo,
  35. @RequestParam(required = false) Long refId) {
  36. StringBuilder apiUrl = new StringBuilder(appConfig.dumpregister + "/dumpregistration/api/wastecollectorlist");
  37. // If at least one param is present, append '?'
  38. if (mobileNo != null || refId != null) {
  39. apiUrl.append("?");
  40. }
  41. // Append parameters
  42. List<String> params = new ArrayList<>();
  43. if (mobileNo != null) {
  44. params.add("mobileNo=" + mobileNo);
  45. }
  46. if (refId != null) {
  47. params.add("refId=" + refId);
  48. }
  49. apiUrl.append(String.join("&", params));
  50. try {
  51. ResponseEntity<String> responseEntity = restTemplate.getForEntity(apiUrl.toString(), String.class);
  52. return ResponseEntity.ok(responseEntity.getBody());
  53. } catch (Exception e) {
  54. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  55. .body("Failed to fetch data: " + e.getMessage());
  56. }
  57. }
  58. @GetMapping("/getallcharges")
  59. public ResponseEntity<String> getpaymentcharges() {
  60. String apiUrl = appConfig.dumpregister + "/dumpregistration/dropdown/api/getallcharges";
  61. try {
  62. ResponseEntity<String> responseEntity = restTemplate.getForEntity(apiUrl, String.class);
  63. return ResponseEntity.ok(responseEntity.getBody()); // Return the real response, not a fixed string
  64. } catch (Exception e) {
  65. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  66. .body("Failed to fetch data: " + e.getMessage());
  67. }
  68. }
  69. @PostMapping("/saveWasteRequest")
  70. public ResponseEntity<String> saveWasteRequest(@RequestBody Map<String, Object> payload) {
  71. try {
  72. officerService.saveRequestDetails(payload);
  73. return ResponseEntity.ok("Saved successfully");
  74. } catch (Exception e) {
  75. e.printStackTrace();
  76. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error saving request");
  77. }
  78. }
  79. @GetMapping("/getless1tonlist")
  80. public ResponseEntity<String> getWasteCollectorLess1TonList() {
  81. StringBuilder apiUrl = new StringBuilder(appConfig.dumpregister + "/dumpregistration/api/getless1tonlist");
  82. try {
  83. ResponseEntity<String> responseEntity = restTemplate.getForEntity(apiUrl.toString(), String.class);
  84. return ResponseEntity.ok(responseEntity.getBody());
  85. } catch (Exception e) {
  86. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  87. .body("Failed to fetch data: " + e.getMessage());
  88. }
  89. }
  90. @GetMapping("/getless1tonlistbyId")
  91. public ResponseEntity<String> getWasteCollectorLess1TonListbyId(@RequestParam(required = true) Long refId) {
  92. if (refId == null) {
  93. return ResponseEntity.badRequest().body("refId is required");
  94. }
  95. try {
  96. String apiUrl = appConfig.dumpregister + "/dumpregistration/api/getless1tonlistbyid?refId=" + refId;
  97. ResponseEntity<String> responseEntity = restTemplate.getForEntity(apiUrl, String.class);
  98. return ResponseEntity.ok(responseEntity.getBody());
  99. } catch (Exception e) {
  100. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  101. .body("Failed to fetch data: " + e.getMessage());
  102. }
  103. }
  104. @GetMapping("/getAllDetails")
  105. public ResponseEntity<?> getAllRequestDetails(
  106. @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate fromDate,
  107. @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate toDate,
  108. @RequestParam(required = false) String wastequantity,
  109. @RequestParam(required = false) String zone) {
  110. try {
  111. List<Map<String, Object>> response = officerService.getAllRequestDetails(fromDate, toDate, wastequantity, zone);
  112. return ResponseEntity.ok(response);
  113. } catch (Exception e) {
  114. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  115. .body(Collections.singletonMap("error", "Failed to fetch data: " + e.getMessage()));
  116. }
  117. }
  118. @GetMapping("/getquantity")
  119. public List<Map<String, Object>> getwastequantity() {
  120. return officerService.getAllwastequantity();
  121. }
  122. //fetch all zones
  123. @GetMapping("/getzones")
  124. public ResponseEntity<?> getAllZones() {
  125. try {
  126. List<Map<String, Object>> response = officerService.getZonesList();
  127. return ResponseEntity.ok(response);
  128. } catch (Exception e) {
  129. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  130. .body(Collections.singletonMap("error", "Failed to fetch data: " + e.getMessage()));
  131. }
  132. }
  133. }