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.

197 lines
7.8 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.Dtoworeopen;
  17. @Service
  18. public class ReopenZoneWiseDaskboards {
  19. @Autowired
  20. DBConnection dbcon;
  21. public String sFrDate ;
  22. public String sToDate ;
  23. public List<Dtoworeopen> getAlldtozwreopen() {
  24. List<Dtoworeopen> 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(getdtozwreopenQuery());
  31. while (rs.next()) {
  32. Dtoworeopen dtozwreopen = new Dtoworeopen();
  33. dtozwreopen.setId(rs.getString("id_dept"));
  34. dtozwreopen.setName(rs.getString("dept_name"));
  35. complaintdept.add(dtozwreopen);
  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 getdtozwreopenQuery() {
  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 AND id_dept >= 32 "
  61. + "ORDER BY id_dept";
  62. }
  63. public String getReopenZonewisedaskboardQuery(String sFrDate,String sToDate,String DEPTID) {
  64. String sQry = "SELECT * FROM (SELECT a.deptid, " +
  65. "nvl(sum(case when complainttype in (52,146) then 1 end),0) as \"NonBURSTLT\", " +
  66. "nvl(sum(case when complainttype in (1,97) then 1 end),0) as \"REOFGAR\", " +
  67. "nvl(sum(case when complainttype in (22,32,57,59,70,113,114,130,145) then 1 end),0) as \"ROAD\", " +
  68. "nvl(sum(case when complainttype in (18,118) then 1 end),0) as \"MOSQUITE\", " +
  69. "nvl(sum(case when complainttype in (69,138) then 1 end),0) as \"WATER\", " +
  70. "nvl(sum(case when complainttype in (7,99) then 1 end),0) as \"REOFDEB\", " +
  71. "nvl(sum(case when complainttype in (71,152) then 1 end),0) as \"TREE\", " +
  72. "nvl(sum(case when complainttype in (19,119) then 1 end),0) as \"DOGS\", " +
  73. "nvl(sum(case when complainttype in (75,181) then 1 end),0) as \"ENCMTN\", " +
  74. "nvl(sum(case when complainttype in (58,112) then 1 end),0) as \"POT\", " +
  75. "nvl(sum(case when complainttype in (43,166) then 1 end),0) as \"PTAX\", " +
  76. "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\", " +
  77. "COUNT(*) as Total FROM eggr_complaintdetails@erp a, eggr_redressaldetails@erp b WHERE ";
  78. int iRptID = 0;
  79. if (iRptID == 1) {
  80. sQry += "nvl(RECEIVINGCENTERID,0) = 1 AND ";
  81. } else if (iRptID == 2) {
  82. sQry += "nvl(RECEIVINGCENTERID,0) != 1 AND ";
  83. }
  84. if (!sFrDate.equals("")) {
  85. if (sToDate == null || sToDate.equals("")) {
  86. sToDate = sFrDate;
  87. }
  88. sQry += "trunc(complaintdate) BETWEEN to_date('" + sFrDate + "','yyyy/mm/dd') AND to_date('" + sToDate + "','yyyy/mm/dd') AND ";
  89. }
  90. sQry += "a.complaintid = b.complaintid AND b.COMPLAINTSTATUSID IN (2,3,4) AND TRUNC(COMPLAINTDATE) >= trunc(sysdate-730) " +
  91. "AND a.deptid = " + DEPTID + // Add condition for specific DEPTID
  92. " GROUP BY a.deptid) a INNER JOIN EG_DEPARTMENT@ERP c ON a.deptid = c.id_dept " +
  93. "LEFT OUTER JOIN (SELECT a.deptid, " +
  94. "nvl(sum(case when sysdate-complaintdate>90 and b.COMPLAINTSTATUSID IN(2,3,4) then 1 end),'0') as days_90_pen, " +
  95. "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, " +
  96. "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, " +
  97. "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, " +
  98. "nvl(sum(case when sysdate-complaintdate<=15 and b.COMPLAINTSTATUSID IN(2,3,4) then 1 end),'0') as days_0_15_pen, " +
  99. "nvl(count(case when b.COMPLAINTSTATUSID IN(2,3,4) then 1 end),'0') as Total_pen " +
  100. "FROM eggr_complaintdetails@erp a, eggr_redressaldetails@erp b " +
  101. "WHERE a.complaintid = b.complaintid AND TRUNC(COMPLAINTDATE) >= trunc(sysdate-730) ";
  102. if (iRptID == 1) {
  103. sQry += "AND nvl(RECEIVINGCENTERID,0) = 1 ";
  104. } else if (iRptID == 2) {
  105. sQry += "AND nvl(RECEIVINGCENTERID,0) != 1 ";
  106. }
  107. if (!sFrDate.equals("")) {
  108. if (sToDate == null || sToDate.equals("")) {
  109. sToDate = sFrDate;
  110. }
  111. sQry += "AND trunc(complaintdate) BETWEEN to_date('" + sFrDate + "','yyyy/mm/dd') AND to_date('" + sToDate + "','yyyy/mm/dd') ";
  112. }
  113. if (DEPTID != null && !DEPTID.equals("0")) {
  114. sQry += "AND EXISTS (SELECT 1 FROM EG_DEPARTMENT@ERP c WHERE a.deptid = c.id_dept " +
  115. "AND (NVL(c.id_dept, 0) NOT LIKE 'F%' AND c.id_dept IS NOT NULL) " +
  116. "AND c.id_dept = " + DEPTID + ") ";
  117. }
  118. sQry += "GROUP BY a.deptid) d ON d.deptid = c.id_dept " +
  119. "WHERE (NVL(DEPT_NAME,0) NOT LIKE 'F%' AND DEPT_NAME IS NOT NULL) " +
  120. "AND a.deptid >= 32 " +
  121. "ORDER BY a.deptid";
  122. System.out.println("PGR sQry : " + sQry);
  123. return sQry;
  124. }
  125. public List<Map<String, Object>> getReopenZonewisedashboardquery(String sFrDate,String sToDate,String DEPTID) {
  126. Connection con = DBConnection.getConnection();
  127. try {
  128. String query = getReopenZonewisedaskboardQuery(sFrDate,sToDate,DEPTID);
  129. PreparedStatement pstmt = con.prepareStatement(query);
  130. if (query.contains(":deptID") && DEPTID != null && !DEPTID.equals("0")) {
  131. pstmt.setString(1, DEPTID);
  132. }
  133. System.out.println("Checking ReOpen Zonewise Dashboard...");
  134. System.out.println("sQry : " + pstmt.toString()); // Check the generated SQL query
  135. ResultSet rs = pstmt.executeQuery();
  136. List<Map<String, Object>> rows = new ArrayList<>();
  137. while (rs.next()) {
  138. Map<String, Object> row = new HashMap<>();
  139. ResultSetMetaData metaData = rs.getMetaData();
  140. int columnCount = metaData.getColumnCount();
  141. for (int i = 1; i <= columnCount; i++) {
  142. String columnName = metaData.getColumnName(i);
  143. Object columnValue = rs.getObject(i);
  144. //System.out.println(columnName + " : " + columnValue);
  145. row.put(columnName, columnValue);
  146. }
  147. rows.add(row);
  148. }
  149. return rows;
  150. } catch (Exception e) {
  151. e.printStackTrace();
  152. } finally {
  153. try {
  154. con.close();
  155. } catch (SQLException e) {
  156. e.printStackTrace();
  157. }
  158. }
  159. return null;
  160. }
  161. }