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.

183 lines
8.0 KiB

3 years ago
​
​
​
​
​
​
​
3 years ago
3 years ago
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. package in.gov.chennaicorporation.gccoffice.pgr.service;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.ResultSetMetaData;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8. import java.util.ArrayList;
  9. import java.util.Collections;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. import java.util.Map;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import in.gov.chennaicorporation.gccoffice.pgr.dbconnection.DBConnection;
  16. import in.gov.chennaicorporation.gccoffice.pgr.dto.DtoAgeAnalysisDaskboard;
  17. @Service
  18. public class AgeAnalysisDaskboards {
  19. @Autowired
  20. DBConnection dbcon;
  21. public String sFrDate ="";
  22. public String sToDate ="";
  23. public List<DtoAgeAnalysisDaskboard> getAlldtoageanalysisDaskboard() {
  24. List<DtoAgeAnalysisDaskboard> complaintdept = new ArrayList<>();
  25. Connection con = DBConnection.getConnection();
  26. Statement stmt = null;
  27. ResultSet rs = null;
  28. try {
  29. stmt = con.createStatement();
  30. rs = stmt.executeQuery(getdtoageanalysisdaskboardQuery());
  31. while (rs.next()) {
  32. DtoAgeAnalysisDaskboard dtoageanalysisdaskboard = new DtoAgeAnalysisDaskboard();
  33. dtoageanalysisdaskboard.setId(rs.getString("id_dept"));
  34. dtoageanalysisdaskboard.setName(rs.getString("dept_name"));
  35. complaintdept.add(dtoageanalysisdaskboard);
  36. }
  37. return complaintdept;
  38. } catch (SQLException e) {
  39. e.printStackTrace();
  40. } finally {
  41. try {
  42. if (rs != null) {
  43. rs.close();
  44. }
  45. if (stmt != null) {
  46. stmt.close();
  47. }
  48. if (con != null) {
  49. con.close();
  50. }
  51. } catch (SQLException e) {
  52. e.printStackTrace();
  53. }
  54. }
  55. return Collections.emptyList(); // Return an empty list if there's an error
  56. }
  57. private String getdtoageanalysisdaskboardQuery() {
  58. return "SELECT Distinct id_dept, dept_name "
  59. + "FROM EG_DEPARTMENT@ERP "
  60. + "ORDER BY id_dept";
  61. }
  62. public String getgenlysisdaskboardQuery(String DEPT_NAME) {
  63. String sQry = "SELECT c.dept_name, a.deptid, a.days_90, a.days_90_pen, a.days_90_reopen, "
  64. + "a.days_61_90, a.days_61_90_pen, a.days_61_90_reopen, "
  65. + "a.days_31_60, a.days_31_60_pen, a.days_31_60_reopen, "
  66. + "a.days_16_30, a.days_16_30_pen, a.days_16_30_reopen, "
  67. + "a.days_0_15, a.days_0_15_pen, a.days_0_15_reopen, "
  68. + "a.Total, a.Total_pen, a.Total_reopen "
  69. + "FROM ( "
  70. + "SELECT "
  71. + "a.deptid, "
  72. + "nvl(sum(case when sysdate - a.complaintdate > 90 then 1 end), '0') AS days_90, "
  73. + "nvl(sum(case when sysdate - a.complaintdate > 90 AND b.COMPLAINTSTATUSID IN (2, 3, 4) then 1 end), '0') AS days_90_pen, "
  74. + "nvl(sum(case when sysdate - a.complaintdate > 90 AND b.COMPLAINTSTATUSID IN (9) then 1 end), '0') AS days_90_reopen, "
  75. + "nvl(sum(case when sysdate - a.complaintdate > 60 AND sysdate - a.complaintdate <= 90 then 1 end), '0') AS days_61_90, "
  76. + "nvl(sum(case when sysdate - a.complaintdate > 60 AND sysdate - a.complaintdate <= 90 AND b.COMPLAINTSTATUSID IN (2, 3, 4) then 1 end), '0') AS days_61_90_pen, "
  77. + "nvl(sum(case when sysdate - a.complaintdate > 60 AND sysdate - a.complaintdate <= 90 AND b.COMPLAINTSTATUSID IN (9) then 1 end), '0') AS days_61_90_reopen, "
  78. + "nvl(sum(case when sysdate - a.complaintdate > 30 AND sysdate - a.complaintdate <= 60 then 1 end), '0') AS days_31_60, "
  79. + "nvl(sum(case when sysdate - a.complaintdate > 30 AND sysdate - a.complaintdate <= 60 AND b.COMPLAINTSTATUSID IN (2, 3, 4) then 1 end), '0') AS days_31_60_pen, "
  80. + "nvl(sum(case when sysdate - a.complaintdate > 30 AND sysdate - a.complaintdate <= 60 AND b.COMPLAINTSTATUSID IN (9) then 1 end), '0') AS days_31_60_reopen, "
  81. + "nvl(sum(case when sysdate - a.complaintdate > 15 AND sysdate - a.complaintdate <= 30 then 1 end), '0') AS days_16_30, "
  82. + "nvl(sum(case when sysdate - a.complaintdate > 15 AND sysdate - a.complaintdate <= 30 AND b.COMPLAINTSTATUSID IN (2, 3, 4) then 1 end), '0') AS days_16_30_pen, "
  83. + "nvl(sum(case when sysdate - a.complaintdate > 15 AND sysdate - a.complaintdate <= 30 AND b.COMPLAINTSTATUSID IN (9) then 1 end), '0') AS days_16_30_reopen, "
  84. + "nvl(sum(case when sysdate - a.complaintdate > 0 AND sysdate - a.complaintdate <= 15 then 1 end), '0') AS days_0_15, "
  85. + "nvl(sum(case when sysdate - a.complaintdate > 0 AND sysdate - a.complaintdate <= 15 AND b.COMPLAINTSTATUSID IN (2, 3, 4) then 1 end), '0') AS days_0_15_pen, "
  86. + "nvl(sum(case when sysdate - a.complaintdate > 0 AND sysdate - a.complaintdate <= 15 AND b.COMPLAINTSTATUSID IN (9) then 1 end), '0') AS days_0_15_reopen, "
  87. + "nvl(count(*), '0') AS Total, "
  88. + "nvl(count(case when b.COMPLAINTSTATUSID IN (2, 3, 4) then 1 end), '0') AS Total_pen, "
  89. + "nvl(count(case when b.COMPLAINTSTATUSID IN (9) then 1 end), '0') AS Total_reopen "
  90. + "FROM eggr_complaintdetails@erp a, eggr_redressaldetails@erp b "
  91. + "WHERE a.complaintid = b.complaintid ";
  92. int iRptID = 0;
  93. if (iRptID == 1) sQry += " AND nvl(RECEIVINGCENTERID,0) = 1 ";
  94. else if (iRptID == 2) sQry += " AND nvl(RECEIVINGCENTERID,0) != 1 ";
  95. String sComplainttype = "0";
  96. if (sComplainttype.equals("52,1,22,32,57,59,70,18,69,7,71,19,58,75"))
  97. sQry += " AND complainttype NOT IN(" + sComplainttype + ") ";
  98. else if (!sComplainttype.equals("0")) sQry += " AND complainttype IN(" + sComplainttype + ") ";
  99. if (!sFrDate.equals("")) {
  100. if (sToDate == null || sToDate.equals("")) sToDate = sFrDate;
  101. sQry += " AND trunc(a.complaintdate) BETWEEN to_date('" + sFrDate + "','dd/mm/yyyy') AND to_date('" + sToDate + "','dd/mm/yyyy') ";
  102. }
  103. if (!sComplainttype.equals("0")) {
  104. sQry += " AND a.deptid >= 33 ";
  105. }
  106. if (DEPT_NAME != null && !DEPT_NAME.equals("0")) {
  107. // Add condition to filter by dept_name
  108. sQry += " AND EXISTS (SELECT 1 FROM EG_DEPARTMENT@ERP c WHERE a.deptid = c.id_dept AND (NVL(c.DEPT_NAME, 0) NOT LIKE 'F%' AND c.DEPT_NAME IS NOT NULL) AND c.dept_name = :deptName) ";
  109. }
  110. sQry += " AND a.complaintdate >= '25-oct-2010' GROUP BY a.deptid) a, EG_DEPARTMENT@ERP c " +
  111. "WHERE a.deptid = c.id_dept AND (NVL(DEPT_NAME, 0) NOT LIKE 'F%' AND DEPT_NAME IS NOT NULL)";
  112. System.out.println("ageanalysisquery : "+ sQry);
  113. return sQry;
  114. }
  115. public List<Map<String, Object>> getdashboardquery(String DEPT_NAME) {
  116. Connection con = DBConnection.getConnection();
  117. try {
  118. PreparedStatement pstmt = con.prepareStatement(getgenlysisdaskboardQuery(DEPT_NAME));
  119. if (DEPT_NAME != null && !DEPT_NAME.equals("0")) {
  120. // Set the parameter value for :deptName
  121. pstmt.setString(1, DEPT_NAME);
  122. }
  123. System.out.println("sQry : " + pstmt.toString()); // Check the generated SQL query
  124. ResultSet rs3 = pstmt.executeQuery();
  125. List<Map<String, Object>> rows = new ArrayList<>();
  126. while (rs3.next()) {
  127. Map<String, Object> row = new HashMap<>();
  128. ResultSetMetaData metaData = rs3.getMetaData();
  129. int columnCount = metaData.getColumnCount();
  130. for (int i = 1; i <= columnCount; i++) {
  131. String columnName = metaData.getColumnName(i);
  132. Object columnValue = rs3.getObject(i);
  133. System.out.println(columnName + " : " + columnValue);
  134. row.put(columnName, columnValue);
  135. }
  136. rows.add(row);
  137. }
  138. return rows;
  139. } catch (Exception e) {
  140. e.printStackTrace();
  141. } finally {
  142. try {
  143. con.close();
  144. } catch (SQLException e) {
  145. e.printStackTrace();
  146. }
  147. }
  148. return null;
  149. }
  150. }