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.

112 lines
4.1 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. package in.gov.chennaicorporation.gccoffice.callcenter.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 org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.http.HttpStatus;
  9. import org.springframework.http.ResponseEntity;
  10. import org.springframework.web.bind.annotation.GetMapping;
  11. import org.springframework.web.bind.annotation.PathVariable;
  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 in.gov.chennaicorporation.gccoffice.callcenter.service.AgentAssignService;
  18. @RequestMapping("/gcc/api/callcenter/admin")
  19. @RestController("callcentercontroller")
  20. public class AgentAssignAPIController
  21. {
  22. private AgentAssignService campaignmaster;
  23. @Autowired
  24. public AgentAssignAPIController(AgentAssignService campaignmaster) {
  25. this.campaignmaster = campaignmaster;
  26. }
  27. @GetMapping("/getcategory")
  28. public List<Map<String, Object>> getcategory()
  29. {
  30. return campaignmaster.getcategory();
  31. }
  32. @GetMapping("/getcampaignbycategory")
  33. public List<Map<String, Object>> getcampaignbycategory(@RequestParam int id)
  34. {
  35. return campaignmaster.getcampaignbycategory(id);
  36. }
  37. // @GetMapping("/getcampaignbyid")
  38. // public List<Map<String, Object>> getcampaignbyid(@RequestParam int id)
  39. // {
  40. // return campaignmaster.getcampaignbyid(id);
  41. // }
  42. @GetMapping("/getagentsfortask")
  43. public List<Map<String, Object>> getagentsfortask(@RequestParam int id)
  44. {
  45. return campaignmaster.getagentsfortask(id);
  46. }
  47. @PostMapping("/addagentsfortask")
  48. public ResponseEntity<List<Map<String, Object>>> addagentsfortask(@RequestBody List<Map<String, Object>> requestList) {
  49. //System.out.println("Received POST request with data: " + requestList);
  50. List<Map<String, Object>> insertedAgents = new ArrayList<>(); // To store successfully inserted agents
  51. try {
  52. for (Map<String, Object> request : requestList) {
  53. int agentId = (int) request.get("agentId");
  54. int categoryId = (int) request.get("categoryId");
  55. int campaignId = (int) request.get("campaignId");
  56. // Call the service method to insert the agent details
  57. int rowsAffected = campaignmaster.addagentsfortask(agentId, categoryId, campaignId);
  58. if (rowsAffected > 0) {
  59. // If the insert was successful, add the agent data to the response list
  60. Map<String, Object> insertedAgent = new HashMap<>();
  61. insertedAgent.put("categoryId", categoryId);
  62. insertedAgent.put("campaignId", campaignId);
  63. insertedAgent.put("agentId", agentId);
  64. insertedAgents.add(insertedAgent); // Add the successfully inserted agent to the list
  65. } else {
  66. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
  67. .body(Collections.singletonList(Collections.singletonMap("error", "Failed to add agent for campaignId: " + campaignId)));
  68. }
  69. }
  70. // Return the list of successfully inserted agents
  71. return ResponseEntity.status(HttpStatus.CREATED).body(insertedAgents);
  72. } catch (Exception e) {
  73. return ResponseEntity.status(HttpStatus.BAD_REQUEST)
  74. .body(Collections.singletonList(Collections.singletonMap("error", "Invalid request data: " + e.getMessage())));
  75. }
  76. }
  77. @GetMapping("/getassignedcampaign")
  78. public List<Map<String, Object>> checkcampaigninassignedtable(@RequestParam int id)
  79. {
  80. return campaignmaster.checkcampaigninassignedtable(id);
  81. }
  82. @GetMapping("/deleteassignedbyid")
  83. public int editagentsfortask(@RequestParam int id)
  84. {
  85. return campaignmaster.editagentsfortask(id);
  86. }
  87. @GetMapping("/getcampaignbyid")
  88. public List<Map<String, Object>> getcampaignquestionbyid(@RequestParam int id){
  89. return campaignmaster.getcampaignquestionbyid(id);
  90. }
  91. }