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.

184 lines
8.2 KiB

3 years ago
​
​
​
3 years ago
​
​
​
3 years ago
3 years ago
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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 id_dept, dept_name "
  59. + "FROM EG_DEPARTMENT@ERP "
  60. + "WHERE NVL(dept_name, '0') NOT LIKE 'F%' AND dept_name IS NOT NULL "
  61. + "ORDER BY id_dept";
  62. }
  63. public String getgenlysisdaskboardQuery(String sFrDate,String sToDate,String DEPT_NAME) {
  64. String sQry = "SELECT c.dept_name, a.deptid, a.days_90, a.days_90_pen, a.days_90_reopen, "
  65. + "a.days_61_90, a.days_61_90_pen, a.days_61_90_reopen, "
  66. + "a.days_31_60, a.days_31_60_pen, a.days_31_60_reopen, "
  67. + "a.days_16_30, a.days_16_30_pen, a.days_16_30_reopen, "
  68. + "a.days_0_15, a.days_0_15_pen, a.days_0_15_reopen, "
  69. + "a.Total, a.Total_pen, a.Total_reopen "
  70. + "FROM ( "
  71. + "SELECT "
  72. + "a.deptid, "
  73. + "nvl(sum(case when sysdate - a.complaintdate > 90 then 1 end), '0') AS days_90, "
  74. + "nvl(sum(case when sysdate - a.complaintdate > 90 AND b.COMPLAINTSTATUSID IN (2, 3, 4) then 1 end), '0') AS days_90_pen, "
  75. + "nvl(sum(case when sysdate - a.complaintdate > 90 AND b.COMPLAINTSTATUSID IN (9) then 1 end), '0') AS days_90_reopen, "
  76. + "nvl(sum(case when sysdate - a.complaintdate > 60 AND sysdate - a.complaintdate <= 90 then 1 end), '0') AS days_61_90, "
  77. + "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, "
  78. + "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, "
  79. + "nvl(sum(case when sysdate - a.complaintdate > 30 AND sysdate - a.complaintdate <= 60 then 1 end), '0') AS days_31_60, "
  80. + "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, "
  81. + "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, "
  82. + "nvl(sum(case when sysdate - a.complaintdate > 15 AND sysdate - a.complaintdate <= 30 then 1 end), '0') AS days_16_30, "
  83. + "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, "
  84. + "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, "
  85. + "nvl(sum(case when sysdate - a.complaintdate > 0 AND sysdate - a.complaintdate <= 15 then 1 end), '0') AS days_0_15, "
  86. + "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, "
  87. + "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, "
  88. + "nvl(count(*), '0') AS Total, "
  89. + "nvl(count(case when b.COMPLAINTSTATUSID IN (2, 3, 4) then 1 end), '0') AS Total_pen, "
  90. + "nvl(count(case when b.COMPLAINTSTATUSID IN (9) then 1 end), '0') AS Total_reopen "
  91. + "FROM eggr_complaintdetails@erp a, eggr_redressaldetails@erp b "
  92. + "WHERE a.complaintid = b.complaintid ";
  93. int iRptID = 0;
  94. if (iRptID == 1) sQry += " AND nvl(RECEIVINGCENTERID,0) = 1 ";
  95. else if (iRptID == 2) sQry += " AND nvl(RECEIVINGCENTERID,0) != 1 ";
  96. String sComplainttype = "0";
  97. if (sComplainttype.equals("52,1,22,32,57,59,70,18,69,7,71,19,58,75"))
  98. sQry += " AND complainttype NOT IN(" + sComplainttype + ") ";
  99. else if (!sComplainttype.equals("0")) sQry += " AND complainttype IN(" + sComplainttype + ") ";
  100. if (!sFrDate.equals("")) {
  101. if (sToDate == null || sToDate.equals("")) sToDate = sFrDate;
  102. sQry += " AND trunc(a.complaintdate) BETWEEN to_date('" + sFrDate + "','yyyy/mm/dd') AND to_date('" + sToDate + "','yyyy/mm/dd') ";
  103. }
  104. if (!sComplainttype.equals("0")) {
  105. sQry += " AND a.deptid >= 33 ";
  106. }
  107. if (DEPT_NAME != null && !DEPT_NAME.equals("0")) {
  108. // Add condition to filter by dept_name
  109. 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) ";
  110. }
  111. sQry += " AND a.complaintdate >= '25-oct-2010' GROUP BY a.deptid) a, EG_DEPARTMENT@ERP c " +
  112. "WHERE a.deptid = c.id_dept AND (NVL(DEPT_NAME, 0) NOT LIKE 'F%' AND DEPT_NAME IS NOT NULL)";
  113. System.out.println("ageanalysisquery : "+ sQry);
  114. return sQry;
  115. }
  116. public List<Map<String, Object>> getdashboardquery(String sFrDate,String sTodate,String DEPT_NAME) {
  117. Connection con = DBConnection.getConnection();
  118. try {
  119. PreparedStatement pstmt = con.prepareStatement(getgenlysisdaskboardQuery(sFrDate,sTodate,DEPT_NAME));
  120. if (DEPT_NAME != null && !DEPT_NAME.equals("0")) {
  121. // Set the parameter value for :deptName
  122. pstmt.setString(1, DEPT_NAME);
  123. }
  124. System.out.println("sQry : " + pstmt.toString()); // Check the generated SQL query
  125. ResultSet rs3 = pstmt.executeQuery();
  126. List<Map<String, Object>> rows = new ArrayList<>();
  127. while (rs3.next()) {
  128. Map<String, Object> row = new HashMap<>();
  129. ResultSetMetaData metaData = rs3.getMetaData();
  130. int columnCount = metaData.getColumnCount();
  131. for (int i = 1; i <= columnCount; i++) {
  132. String columnName = metaData.getColumnName(i);
  133. Object columnValue = rs3.getObject(i);
  134. System.out.println(columnName + " : " + columnValue);
  135. row.put(columnName, columnValue);
  136. }
  137. rows.add(row);
  138. }
  139. return rows;
  140. } catch (Exception e) {
  141. e.printStackTrace();
  142. } finally {
  143. try {
  144. con.close();
  145. } catch (SQLException e) {
  146. e.printStackTrace();
  147. }
  148. }
  149. return null;
  150. }
  151. }