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.

320 lines
12 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. package in.gov.chennaicorporation.gccoffice.callcenter.controller;
  2. import java.io.IOException;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import javax.servlet.http.HttpSession;
  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.PathVariable;
  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.ResponseBody;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import com.fasterxml.jackson.core.JsonProcessingException;
  20. import com.fasterxml.jackson.core.type.TypeReference;
  21. import com.fasterxml.jackson.databind.ObjectMapper;
  22. import in.gov.chennaicorporation.gccoffice.callcenter.service.AgentsService;
  23. @RequestMapping("/gcc/api/agents")
  24. @RestController
  25. public class AgentsAPIController {
  26. @Autowired
  27. private AgentsService agentsService;
  28. @GetMapping("/excel")
  29. public List<Map<String, Object>> fetchDataFromExcel(@RequestParam int categoryId,@RequestParam Long campaignId) {
  30. try {
  31. return agentsService.fetchDataFromExcel(categoryId,campaignId);
  32. } catch (IOException e) {
  33. e.printStackTrace();
  34. return null; // Handle the exception as needed
  35. }
  36. }
  37. @PostMapping("/saveExcelData")
  38. public String saveExcelData( @RequestParam int categoryId,@RequestParam Long campaignId,@RequestParam String filePath) {
  39. try {
  40. // Fetch data from Excel
  41. List<Map<String, Object>> excelData = agentsService.getExcelData(categoryId,campaignId, filePath);
  42. // Save data into the database
  43. agentsService.saveExcelData(excelData);
  44. return "Data saved successfully";
  45. } catch (IOException e) {
  46. e.printStackTrace();
  47. return "Failed to save data";
  48. }
  49. }
  50. @GetMapping("/getdataByIds")
  51. public List<Map<String, Object>> getdataByIds(@RequestParam List<Integer> ids) {
  52. return agentsService.getdataByIds(ids);
  53. }
  54. @GetMapping("/getPendingDataByIds")
  55. public List<Map<String, Object>> getPendingDataByIds(@RequestParam List<Integer> ids) {
  56. return agentsService.getPendingDataByIds(ids);
  57. }
  58. // @PostMapping("/updatecall")
  59. // public ResponseEntity<String> updatecall(@RequestBody Map<String, Object> callData)
  60. // {
  61. // String call_status = (String) callData.get("call_status");
  62. // int data_id = (int) callData.get("data_id");
  63. // int agent_id=(int) callData.get("agent_id");
  64. // int campaign_id=(int) callData.get("campaign_id");
  65. //
  66. // if (call_status == null || call_status.isEmpty()) {
  67. // return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Call status is required.");
  68. // }
  69. //
  70. // agentsService.saveInLogsTable(campaign_id, agent_id, data_id,call_status);
  71. //
  72. // return ResponseEntity.ok("Data Inserted successfully.");
  73. // }
  74. @GetMapping("/getAgentNames")
  75. public List<Map<String, Object>> getAgentsNameById(@RequestParam List<Integer> agentIds){
  76. return agentsService.getAgentsNameById(agentIds);
  77. }
  78. @GetMapping("/getDataFields")
  79. public List<Map<String, Object>> getDataDetailsById(
  80. @RequestParam String originalDataIds) throws JsonProcessingException {
  81. // Parse originalDataIds from JSON string
  82. ObjectMapper objectMapper = new ObjectMapper();
  83. List<List<Integer>> originalDataIdsList = objectMapper.readValue(originalDataIds, new TypeReference<List<List<Integer>>>() {});
  84. // Prepare a list to hold the results for each sub-array
  85. List<Map<String, Object>> groupedResults = new ArrayList<>();
  86. // Iterate through each sub-array of originalDataIds
  87. for (List<Integer> dataIds : originalDataIdsList) {
  88. List<Map<String, Object>> results = agentsService.getDataDetailsById(dataIds);
  89. // Group results according to your business logic
  90. Map<String, Object> combinedResult = new HashMap<>();
  91. for (Map<String, Object> result : results) {
  92. combinedResult.putAll(result);
  93. }
  94. groupedResults.add(combinedResult);
  95. }
  96. return groupedResults;
  97. }
  98. @GetMapping("/getCompletedDataFields")
  99. public Map<String, Object> getCompletedDataDetailsById(
  100. @RequestParam String originalCDataIds) throws JsonProcessingException {
  101. // Parse originalDataIds from JSON string
  102. ObjectMapper objectMapper = new ObjectMapper();
  103. List<Integer> originalCDataIdsList = objectMapper.readValue(originalCDataIds, new TypeReference<List<Integer>>() {});
  104. // Prepare a list to hold the results for each sub-array
  105. //List<Map<String, Object>> groupedCompletedResults = new ArrayList<>();
  106. List<Integer> completedDataIds = new ArrayList<>(); // List to hold data_ids with Complete_count > 0
  107. // Iterate through each sub-array of originalDataIds
  108. List<Map<String, Object>> results = agentsService.getCompletedDataDetailsById(originalCDataIdsList);
  109. // Group results according to your business logic
  110. //Map<String, Object> CompletedcombinedResult = new HashMap<>();
  111. for (Map<String, Object> result : results) {
  112. if (result.get("Complete_count") != null && ((Number) result.get("Complete_count")).intValue() > 0) {
  113. completedDataIds.add((Integer) result.get("data_id"));
  114. }
  115. //groupedCompletedResults.add(result);
  116. }
  117. // Prepare the final response containing grouped results and completed dataIds
  118. Map<String, Object> response = new HashMap<>();
  119. //response.put("groupedCompletedResults", groupedCompletedResults);
  120. response.put("completedDataIds", completedDataIds);
  121. return response;
  122. }
  123. @GetMapping("/getCompletedDataById")
  124. public List<Map<String, Object>> getCompletedDataById(@RequestParam List<Integer> completedDataIds){
  125. return agentsService.getCompletedDataById(completedDataIds);
  126. }
  127. @PostMapping("/furtherAssignedAgents")
  128. public ResponseEntity<Map<String, String>> updateAgentAssigndata(
  129. @RequestBody Map<String, Object> requestData) {
  130. String campaign_id = (String) requestData.get("campaign_id");
  131. String category_id = (String) requestData.get("category_id");
  132. String call_per_agent = (String) requestData.get("call_per_agent");
  133. // Correct key name for selected agents
  134. List<String> selectedAgentsList = (List<String>) requestData.get("selected_agents");
  135. //System.out.println("campaign_id=" + campaign_id);
  136. //System.out.println("category_id=" + category_id);
  137. //System.out.println("call_per_agent=" + call_per_agent);
  138. //System.out.println("selectedAgentsList=" + selectedAgentsList);
  139. int campaignId = Integer.parseInt(campaign_id);
  140. int categoryId = Integer.parseInt(category_id);
  141. int callperagent = Integer.parseInt(call_per_agent);
  142. agentsService.resetAgentAssignmentForNextDay(categoryId,campaignId);
  143. int calls_assign = callperagent * selectedAgentsList.size();
  144. //System.out.println("calls_assign== " + calls_assign);
  145. List<Integer> DataIds=agentsService.getDataIdForFurtherAssign(categoryId, campaignId);
  146. //System.out.println("dataids=== " + DataIds);
  147. if (!DataIds.isEmpty()) {
  148. int dataIndex = 0; // Initialize data index pointer
  149. for (String agentId : selectedAgentsList) {
  150. int selectedAgentId = Integer.parseInt(agentId);
  151. agentsService.addAgentsForCampaign(selectedAgentId, categoryId, campaignId);
  152. // Iterate for noOfCalls times and assign data IDs to the current agent
  153. for (int i = 0; i < callperagent && dataIndex < DataIds.size(); i++, dataIndex++) {
  154. int DataId = DataIds.get(dataIndex);
  155. agentsService.updateAgentForCampaign(
  156. selectedAgentId,
  157. categoryId,
  158. campaignId,
  159. DataId
  160. );
  161. }
  162. }
  163. }
  164. else {
  165. return ResponseEntity.status(HttpStatus.NOT_FOUND)
  166. .body(Map.of("status", "error", "message", "No data available for Further assign."));
  167. }
  168. return ResponseEntity.ok(Map.of("status", "success", "message", "Campaign details saved successfully"));
  169. }
  170. ////////////////////Ajith code//////////////////////
  171. @GetMapping("/Campaignview")
  172. public ResponseEntity<?> getCampaignview(@RequestParam int categoryId, @RequestParam int agentId, @RequestParam int dataId) {
  173. try {
  174. List<Map<String, Object>> response = agentsService.getFilteredFields(categoryId, agentId, dataId);
  175. if (response.isEmpty()) {
  176. return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No matching data found.");
  177. }
  178. return ResponseEntity.ok(response);
  179. } catch (Exception e) {
  180. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error: " + e.getMessage());
  181. }
  182. }
  183. @GetMapping("/questions")
  184. public List<Map<String, Object>> getCampaignQuestions(
  185. @RequestParam int categoryId,
  186. @RequestParam int campaignId) {
  187. return agentsService.getCampaignQuestions(categoryId, campaignId);
  188. }
  189. @GetMapping("/fetchAnswer")
  190. public List<Map<String, Object>> fetchAnswer(
  191. @RequestParam int campaignId,
  192. @RequestParam int agentId,
  193. @RequestParam int questionId,
  194. @RequestParam int dataId) {
  195. return agentsService.FetchAnswer(campaignId,agentId,questionId,dataId);
  196. }
  197. @PostMapping("/submitAnswers")
  198. public ResponseEntity<String> submitAnswers(@RequestBody Map<String, List<Map<String, Object>>> requestData) {
  199. List<Map<String, Object>> answers = requestData.get("answers");
  200. if (answers == null || answers.isEmpty()) {
  201. return ResponseEntity.badRequest().body("No answers provided.");
  202. }
  203. agentsService.saveAnswers(answers);
  204. return ResponseEntity.ok("Answers submitted successfully");
  205. }
  206. @GetMapping("/callstatus")
  207. public List<Map<String, Object>> getCallStatus() {
  208. //System.out.println("dropdown");
  209. return agentsService.getCallStatus();
  210. }
  211. @GetMapping("/checkCounts")
  212. public List<Map<String, Object>> checkCounts(
  213. @RequestParam int campaignId,
  214. @RequestParam int dataId) {
  215. return agentsService.checkCounts(campaignId,dataId);
  216. }
  217. @PostMapping("/savecall")
  218. public ResponseEntity<String> savecall(@RequestBody Map<String, Object> callData) {
  219. String call_status = (String) callData.get("call_status");
  220. String remarks = (String) callData.get("remarks");
  221. int data_id = Integer.parseInt(callData.get("data_id").toString());
  222. int agent_id = Integer.parseInt(callData.get("agent_id").toString());
  223. int campaign_id = Integer.parseInt(callData.get("campaign_id").toString());
  224. // System.out.println("controler");
  225. //System.out.println(call_status);
  226. // Add a debug statement to check the received values
  227. // System.out.println("Received call_status: " + call_status);
  228. if (call_status == null || call_status.isEmpty()) {
  229. return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Call status is required.");
  230. }
  231. agentsService.saveCallLogs(call_status, remarks,data_id,agent_id);
  232. agentsService.saveInLogsTable(campaign_id, agent_id, data_id,call_status,remarks);
  233. return ResponseEntity.ok("Data Inserted successfully.");
  234. }
  235. }