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.

219 lines
7.5 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.List;
  5. import java.util.Map;
  6. import javax.servlet.http.HttpSession;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.http.ResponseEntity;
  9. import org.springframework.stereotype.Controller;
  10. import org.springframework.ui.Model;
  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.ResponseBody;
  17. import org.springframework.web.client.RestTemplate;
  18. import com.fasterxml.jackson.core.type.TypeReference;
  19. import com.fasterxml.jackson.databind.ObjectMapper;
  20. import in.gov.chennaicorporation.gccoffice.callcenter.service.AddcategoryServices;
  21. import in.gov.chennaicorporation.gccoffice.callcenter.service.AgentsService;
  22. import in.gov.chennaicorporation.gccoffice.callcenter.service.AttendanceService;
  23. import in.gov.chennaicorporation.gccoffice.callcenter.service.AgentAssignService;
  24. import in.gov.chennaicorporation.gccoffice.callcenter.service.CampaignService;
  25. import in.gov.chennaicorporation.gccoffice.configuration.AppConfig;
  26. import in.gov.chennaicorporation.gccoffice.service.LoginUserInfo;
  27. @RequestMapping("/gcc/callcenter")
  28. @Controller("callCenterCampaignMainController")
  29. public class MainController {
  30. @Autowired
  31. private AgentAssignService campaignmaster;
  32. @Autowired
  33. private CampaignService campaignService;
  34. @Autowired
  35. private AddcategoryServices addCategoryServices;
  36. @Autowired
  37. private AgentsService agentsService;
  38. @Autowired
  39. private AttendanceService attendanceSerivce;
  40. private AppConfig appConfig;
  41. private RestTemplate restTemplate;
  42. @Autowired
  43. public MainController(AgentAssignService campaignmaster,AgentsService agentsService,CampaignService campaignService,AddcategoryServices addCategoryServices,RestTemplate restTemplate, AppConfig appConfig)
  44. {
  45. this.campaignmaster=campaignmaster;
  46. this.campaignService=campaignService;
  47. this.addCategoryServices=addCategoryServices;
  48. this.agentsService=agentsService;
  49. this.restTemplate = restTemplate;
  50. this.appConfig = appConfig;
  51. }
  52. @GetMapping("/admin/addcategory")
  53. public String addcategory(Model model) {
  54. String LoginUserId = LoginUserInfo.getLoginUserId();
  55. model.addAttribute("LoginUserId",LoginUserId);
  56. String UserRole = LoginUserInfo.getUserRole();
  57. model.addAttribute("UserRole", UserRole);
  58. List<Map<String, Object>> categories = addCategoryServices.getAllCategories();
  59. //System.out.println(categories);
  60. model.addAttribute("categories", categories);
  61. return "modules/callcenter/addcategory";
  62. }
  63. @GetMapping("/admin/createcampaign")
  64. public String createcampaign(Model model) {
  65. String LoginUserId = LoginUserInfo.getLoginUserId();
  66. model.addAttribute("LoginUserId",LoginUserId);
  67. String UserRole = LoginUserInfo.getUserRole();
  68. model.addAttribute("UserRole", UserRole);
  69. /*
  70. * List<Map<String, Object>> campaigns = campaignService.getCampaignDetails();
  71. *
  72. *
  73. * System.out.println("campaignlist:"+campaigns);
  74. *
  75. * model.addAttribute("campaigns", campaigns);
  76. */
  77. return "modules/callcenter/createcampaign"; // Name of the Thymeleaf template (e.g., campaignList.html)
  78. }
  79. @GetMapping("/admin/campaignlist")
  80. public String viewCampaignList(Model model)
  81. {
  82. String LoginUserId = LoginUserInfo.getLoginUserId();
  83. model.addAttribute("LoginUserId",LoginUserId);
  84. String UserRole = LoginUserInfo.getUserRole();
  85. model.addAttribute("UserRole", UserRole);
  86. List<Map<String, Object>> campaigns = campaignService.getDetailsForStart();
  87. model.addAttribute("campaigns", campaigns);
  88. List<Map<String, Object>> activeCampaigns =campaignService.getActiveCampaigns();
  89. model.addAttribute("activeCampaigns", activeCampaigns);
  90. return "modules/callcenter/campaignlist";
  91. }
  92. @GetMapping("/agentscampaign")
  93. public String targetPage(Model model)
  94. {
  95. String LoginUserId = LoginUserInfo.getLoginUserId();
  96. int userId = Integer.parseInt(LoginUserId);
  97. model.addAttribute("LoginUserId",LoginUserId);
  98. String agent_name=LoginUserInfo.getCurrentUserDetails().getUsername();
  99. model.addAttribute("agent_name", agent_name);
  100. String UserRole = LoginUserInfo.getUserRole();
  101. model.addAttribute("UserRole", UserRole);
  102. List<Map<String, Object>> agentsCampaigns=agentsService.getAgentsALLCampaigns(userId);
  103. List<Map<String, Object>> agentsCampaignsList=agentsService.getAgentsALLCampaignsList(userId);
  104. List<Map<String, Object>> agentsCampaignsList1=agentsService.getAgentsALLCampaignsList1(userId);
  105. //List<Map<String, Object>> CampActions=agentsService.getCallCategories();
  106. //model.addAttribute("CampActions", CampActions);
  107. model.addAttribute("agentsCampaignsList", agentsCampaignsList);
  108. model.addAttribute("agentsCampaigns", agentsCampaigns);
  109. model.addAttribute("agentsCampaignsList1", agentsCampaignsList1);
  110. //System.out.println("Agents Campaigns List: " + agentsCampaignsList);
  111. //System.out.println("Agents Campaigns : " + agentsCampaigns);
  112. return "modules/callcenter/agentscampaign";
  113. }
  114. @GetMapping("/admin/campaignreport")
  115. public String campaignreport(Model model)
  116. {
  117. String LoginUserId = LoginUserInfo.getLoginUserId();
  118. model.addAttribute("LoginUserId",LoginUserId);
  119. String UserRole = LoginUserInfo.getUserRole();
  120. model.addAttribute("UserRole", UserRole);
  121. return "modules/callcenter/campaignreport";
  122. }
  123. @GetMapping("/attendancereport")
  124. public String AttendanceList(
  125. @RequestParam(required = false) String fromDate,
  126. @RequestParam(required = false) String toDate,
  127. Model model) {
  128. List<Map<String, Object>> attendanceData = Collections.emptyList();
  129. if (fromDate != null && !fromDate.isEmpty() && toDate != null && !toDate.isEmpty()) {
  130. String apiUrl = appConfig.attendanceReport + "/callcenter/api/attendance/getattendancereport?fromDate=" + fromDate + "&toDate=" + toDate;
  131. try {
  132. ResponseEntity<String> responseEntity = restTemplate.getForEntity(apiUrl, String.class);
  133. String responseBody = responseEntity.getBody();
  134. if (responseBody != null && !responseBody.isEmpty()) {
  135. ObjectMapper objectMapper = new ObjectMapper();
  136. if (responseBody.trim().startsWith("{")) {
  137. // Single object response
  138. Map<String, Object> singleData = objectMapper.readValue(responseBody, new TypeReference<>() {});
  139. attendanceData = List.of(singleData);
  140. } else {
  141. // Array response
  142. attendanceData = objectMapper.readValue(responseBody, new TypeReference<>() {});
  143. }
  144. }
  145. } catch (Exception e) {
  146. System.err.println("Error fetching attendance data: " + e.getMessage());
  147. }
  148. }
  149. model.addAttribute("attendanceData", attendanceData);
  150. model.addAttribute("fromDate", fromDate);
  151. model.addAttribute("toDate", toDate);
  152. model.addAttribute("LoginUserId", LoginUserInfo.getLoginUserId());
  153. model.addAttribute("UserRole", LoginUserInfo.getUserRole());
  154. return "modules/callcenter/attendancereport";
  155. }
  156. }