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.

139 lines
6.6 KiB

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.util.ArrayList;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Map;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Service;
  13. import in.gov.chennaicorporation.gccoffice.pgr.dbconnection.DBConnection;
  14. @Service
  15. public class AgeAnalysisDaskboards {
  16. @Autowired
  17. DBConnection dbcon;
  18. public String sFrDate ="";
  19. public String sToDate ="";
  20. public String getgenlysisdaskboardQuery(String DEPT_NAME) {
  21. String sQry = "SELECT c.dept_name, a.deptid, a.days_90, a.days_90_pen, a.days_90_reopen, "
  22. + "a.days_61_90, a.days_61_90_pen, a.days_61_90_reopen, "
  23. + "a.days_31_60, a.days_31_60_pen, a.days_31_60_reopen, "
  24. + "a.days_16_30, a.days_16_30_pen, a.days_16_30_reopen, "
  25. + "a.days_0_15, a.days_0_15_pen, a.days_0_15_reopen, "
  26. + "a.Total, a.Total_pen, a.Total_reopen "
  27. + "FROM ( "
  28. + "SELECT "
  29. + "a.deptid, "
  30. + "nvl(sum(case when sysdate - a.complaintdate > 90 then 1 end), '0') AS days_90, "
  31. + "nvl(sum(case when sysdate - a.complaintdate > 90 AND b.COMPLAINTSTATUSID IN (2, 3, 4) then 1 end), '0') AS days_90_pen, "
  32. + "nvl(sum(case when sysdate - a.complaintdate > 90 AND b.COMPLAINTSTATUSID IN (9) then 1 end), '0') AS days_90_reopen, "
  33. + "nvl(sum(case when sysdate - a.complaintdate > 60 AND sysdate - a.complaintdate <= 90 then 1 end), '0') AS days_61_90, "
  34. + "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, "
  35. + "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, "
  36. + "nvl(sum(case when sysdate - a.complaintdate > 30 AND sysdate - a.complaintdate <= 60 then 1 end), '0') AS days_31_60, "
  37. + "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, "
  38. + "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, "
  39. + "nvl(sum(case when sysdate - a.complaintdate > 15 AND sysdate - a.complaintdate <= 30 then 1 end), '0') AS days_16_30, "
  40. + "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, "
  41. + "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, "
  42. + "nvl(sum(case when sysdate - a.complaintdate > 0 AND sysdate - a.complaintdate <= 15 then 1 end), '0') AS days_0_15, "
  43. + "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, "
  44. + "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, "
  45. + "nvl(count(*), '0') AS Total, "
  46. + "nvl(count(case when b.COMPLAINTSTATUSID IN (2, 3, 4) then 1 end), '0') AS Total_pen, "
  47. + "nvl(count(case when b.COMPLAINTSTATUSID IN (9) then 1 end), '0') AS Total_reopen "
  48. + "FROM eggr_complaintdetails@erp a, eggr_redressaldetails@erp b "
  49. + "WHERE a.complaintid = b.complaintid ";
  50. int iRptID = 0;
  51. if (iRptID == 1) sQry += " AND nvl(RECEIVINGCENTERID,0) = 1 ";
  52. else if (iRptID == 2) sQry += " AND nvl(RECEIVINGCENTERID,0) != 1 ";
  53. String sComplainttype = "0";
  54. if (sComplainttype.equals("52,1,22,32,57,59,70,18,69,7,71,19,58,75"))
  55. sQry += " AND complainttype NOT IN(" + sComplainttype + ") ";
  56. else if (!sComplainttype.equals("0")) sQry += " AND complainttype IN(" + sComplainttype + ") ";
  57. if (!sFrDate.equals("")) {
  58. if (sToDate == null || sToDate.equals("")) sToDate = sFrDate;
  59. sQry += " AND trunc(a.complaintdate) BETWEEN to_date('" + sFrDate + "','dd/mm/yyyy') AND to_date('" + sToDate + "','dd/mm/yyyy') ";
  60. }
  61. if (!sComplainttype.equals("0")) {
  62. sQry += " AND a.deptid >= 33 ";
  63. }
  64. if (DEPT_NAME != null && !DEPT_NAME.equals("0")) {
  65. // Add condition to filter by dept_name
  66. 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) ";
  67. }
  68. sQry += " AND a.complaintdate >= '25-oct-2010' GROUP BY a.deptid) a, EG_DEPARTMENT@ERP c " +
  69. "WHERE a.deptid = c.id_dept AND (NVL(DEPT_NAME, 0) NOT LIKE 'F%' AND DEPT_NAME IS NOT NULL)";
  70. System.out.println("ageanalysisquery : "+ sQry);
  71. return sQry;
  72. }
  73. public List<Map<String, Object>> getdashboardquery(String DEPT_NAME) {
  74. Connection con = DBConnection.getConnection();
  75. try {
  76. PreparedStatement pstmt = con.prepareStatement(getgenlysisdaskboardQuery(DEPT_NAME));
  77. if (DEPT_NAME != null && !DEPT_NAME.equals("0")) {
  78. // Set the parameter value for :deptName
  79. pstmt.setString(1, DEPT_NAME);
  80. }
  81. System.out.println("sQry : " + pstmt.toString()); // Check the generated SQL query
  82. ResultSet rs3 = pstmt.executeQuery();
  83. List<Map<String, Object>> rows = new ArrayList<>();
  84. while (rs3.next()) {
  85. Map<String, Object> row = new HashMap<>();
  86. ResultSetMetaData metaData = rs3.getMetaData();
  87. int columnCount = metaData.getColumnCount();
  88. for (int i = 1; i <= columnCount; i++) {
  89. String columnName = metaData.getColumnName(i);
  90. Object columnValue = rs3.getObject(i);
  91. System.out.println(columnName + " : " + columnValue);
  92. row.put(columnName, columnValue);
  93. }
  94. rows.add(row);
  95. }
  96. return rows;
  97. } catch (Exception e) {
  98. e.printStackTrace();
  99. } finally {
  100. try {
  101. con.close();
  102. } catch (SQLException e) {
  103. e.printStackTrace();
  104. }
  105. }
  106. return null;
  107. }
  108. }