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.

150 lines
6.3 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 ReopenZoneWiseDaskboards {
  16. @Autowired
  17. DBConnection dbcon;
  18. public String sFrDate ="";
  19. public String sToDate ="";
  20. public String getReopenZonewisedaskboardQuery(String DEPTID) {
  21. String sQry = "SELECT * FROM (SELECT a.deptid, " +
  22. "nvl(sum(case when complainttype in (52,146) then 1 end),0) as \"NonBURSTLT\", " +
  23. "nvl(sum(case when complainttype in (1,97) then 1 end),0) as \"REOFGAR\", " +
  24. "nvl(sum(case when complainttype in (22,32,57,59,70,113,114,130,145) then 1 end),0) as \"ROAD\", " +
  25. "nvl(sum(case when complainttype in (18,118) then 1 end),0) as \"MOSQUITE\", " +
  26. "nvl(sum(case when complainttype in (69,138) then 1 end),0) as \"WATER\", " +
  27. "nvl(sum(case when complainttype in (7,99) then 1 end),0) as \"REOFDEB\", " +
  28. "nvl(sum(case when complainttype in (71,152) then 1 end),0) as \"TREE\", " +
  29. "nvl(sum(case when complainttype in (19,119) then 1 end),0) as \"DOGS\", " +
  30. "nvl(sum(case when complainttype in (75,181) then 1 end),0) as \"ENCMTN\", " +
  31. "nvl(sum(case when complainttype in (58,112) then 1 end),0) as \"POT\", " +
  32. "nvl(sum(case when complainttype in (43,166) then 1 end),0) as \"PTAX\", " +
  33. "nvl(sum(case when complainttype not in (52,1,22,32,57,59,70,18,69,7,71,19,75,58,43,146,97,113,114,130,145,118,138,99,152,119,181,112,166) then 1 end),0) as \"OTHERS\", " +
  34. "COUNT(*) as Total FROM eggr_complaintdetails@erp a, eggr_redressaldetails@erp b WHERE ";
  35. int iRptID = 0;
  36. if (iRptID == 1) {
  37. sQry += "nvl(RECEIVINGCENTERID,0) = 1 AND ";
  38. } else if (iRptID == 2) {
  39. sQry += "nvl(RECEIVINGCENTERID,0) != 1 AND ";
  40. }
  41. if (!sFrDate.equals("")) {
  42. if (sToDate == null || sToDate.equals("")) {
  43. sToDate = sFrDate;
  44. }
  45. sQry += "trunc(complaintdate) BETWEEN to_date('" + sFrDate + "','dd/mm/yyyy') AND to_date('" + sToDate + "','dd/mm/yyyy') AND ";
  46. }
  47. sQry += "a.complaintid = b.complaintid AND b.COMPLAINTSTATUSID IN (2,3,4) AND TRUNC(COMPLAINTDATE) >= trunc(sysdate-730) " +
  48. "AND a.deptid = " + DEPTID + // Add condition for specific DEPTID
  49. " GROUP BY a.deptid) a INNER JOIN EG_DEPARTMENT@ERP c ON a.deptid = c.id_dept " +
  50. "LEFT OUTER JOIN (SELECT a.deptid, " +
  51. "nvl(sum(case when sysdate-complaintdate>90 and b.COMPLAINTSTATUSID IN(2,3,4) then 1 end),'0') as days_90_pen, " +
  52. "nvl(sum(case when sysdate-complaintdate>60 and sysdate-complaintdate<=90 and b.COMPLAINTSTATUSID IN(2,3,4) then 1 end),'0') as days_61_90_pen, " +
  53. "nvl(sum(case when sysdate-complaintdate>30 and sysdate-complaintdate<=60 and b.COMPLAINTSTATUSID IN(2,3,4) then 1 end),'0') as days_31_60_pen, " +
  54. "nvl(sum(case when sysdate-complaintdate>15 and sysdate-complaintdate<=30 and b.COMPLAINTSTATUSID IN(2,3,4) then 1 end),'0') as days_16_30_pen, " +
  55. "nvl(sum(case when sysdate-complaintdate<=15 and b.COMPLAINTSTATUSID IN(2,3,4) then 1 end),'0') as days_0_15_pen, " +
  56. "nvl(count(case when b.COMPLAINTSTATUSID IN(2,3,4) then 1 end),'0') as Total_pen " +
  57. "FROM eggr_complaintdetails@erp a, eggr_redressaldetails@erp b " +
  58. "WHERE a.complaintid = b.complaintid AND TRUNC(COMPLAINTDATE) >= trunc(sysdate-730) ";
  59. if (iRptID == 1) {
  60. sQry += "AND nvl(RECEIVINGCENTERID,0) = 1 ";
  61. } else if (iRptID == 2) {
  62. sQry += "AND nvl(RECEIVINGCENTERID,0) != 1 ";
  63. }
  64. if (!sFrDate.equals("")) {
  65. if (sToDate == null || sToDate.equals("")) {
  66. sToDate = sFrDate;
  67. }
  68. sQry += "AND trunc(complaintdate) BETWEEN to_date('" + sFrDate + "','dd/mm/yyyy') AND to_date('" + sToDate + "','dd/mm/yyyy') ";
  69. }
  70. if (DEPTID != null && !DEPTID.equals("0")) {
  71. sQry += "AND EXISTS (SELECT 1 FROM EG_DEPARTMENT@ERP c WHERE a.deptid = c.id_dept " +
  72. "AND (NVL(c.id_dept, 0) NOT LIKE 'F%' AND c.id_dept IS NOT NULL) " +
  73. "AND c.id_dept = " + DEPTID + ") ";
  74. }
  75. sQry += "GROUP BY a.deptid) d ON d.deptid = c.id_dept " +
  76. "WHERE (NVL(DEPT_NAME,0) NOT LIKE 'F%' AND DEPT_NAME IS NOT NULL) " +
  77. "AND a.deptid >= 32 " +
  78. "ORDER BY a.deptid";
  79. System.out.println("PGR sQry : " + sQry);
  80. return sQry;
  81. }
  82. public List<Map<String, Object>> getReopenZonewisedashboardquery(String DEPTID) {
  83. Connection con = DBConnection.getConnection();
  84. try {
  85. String query = getReopenZonewisedaskboardQuery(DEPTID);
  86. PreparedStatement pstmt = con.prepareStatement(query);
  87. if (query.contains(":deptID") && DEPTID != null && !DEPTID.equals("0")) {
  88. pstmt.setString(1, DEPTID);
  89. }
  90. System.out.println("Checking ReOpen Zonewise Dashboard...");
  91. System.out.println("sQry : " + pstmt.toString()); // Check the generated SQL query
  92. ResultSet rs = pstmt.executeQuery();
  93. List<Map<String, Object>> rows = new ArrayList<>();
  94. while (rs.next()) {
  95. Map<String, Object> row = new HashMap<>();
  96. ResultSetMetaData metaData = rs.getMetaData();
  97. int columnCount = metaData.getColumnCount();
  98. for (int i = 1; i <= columnCount; i++) {
  99. String columnName = metaData.getColumnName(i);
  100. Object columnValue = rs.getObject(i);
  101. //System.out.println(columnName + " : " + columnValue);
  102. row.put(columnName, columnValue);
  103. }
  104. rows.add(row);
  105. }
  106. return rows;
  107. } catch (Exception e) {
  108. e.printStackTrace();
  109. } finally {
  110. try {
  111. con.close();
  112. } catch (SQLException e) {
  113. e.printStackTrace();
  114. }
  115. }
  116. return null;
  117. }
  118. }