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.

148 lines
6.0 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
​
​
​
​
​
​
​
​
​
​
  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.util.ArrayList;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Map;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import in.gov.chennaicorporation.gccoffice.pgr.dbconnection.DBConnection;
  13. @Service
  14. public class ZoneWiseDaskboards {
  15. @Autowired
  16. DBConnection dbcon;
  17. public String sFrDate ;
  18. public String sToDate ;
  19. public String getzonedaskboardQuery(String sFrDate,String sToDate,String DEPTID) {
  20. String sQry= "select * from (SELECT deptid , "
  21. +"nvl(sum( case when complainttype in (52,146) then 1 end),0) as \"NonBURSTLT\" , "
  22. +"nvl(sum( case when complainttype in (1,97) then 1 end),0) as \"REOFGAR\" , "
  23. +"nvl(sum( case when complainttype in (22,32,57,59,70,113,114,130,145) then 1 end),0) as \"ROAD\" , "
  24. +"nvl(sum( case when complainttype in (18,118) then 1 end),0) as \"MOSQUITE\" , "
  25. +"nvl(sum( case when complainttype in (69,138) then 1 end),0) as \"WATER\" , "
  26. +"nvl(sum( case when complainttype in (7,99) then 1 end),0) as \"REOFDEB\" , "
  27. +"nvl(sum( case when complainttype in (71,152) then 1 end),0) as \"TREE\" , "
  28. +"nvl(sum( case when complainttype in (19,119) then 1 end),0) as \"DOGS\" , "
  29. +"nvl(sum( case when complainttype in (75,181) then 1 end),0) as \"ENCMTN\" , "
  30. +"nvl(sum( case when complainttype in (58,112) then 1 end),0) as \"POT\" , "
  31. +"nvl(sum( case when complainttype in (43,166) then 1 end),0) as \"PTAX\" , "
  32. +"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\" , "
  33. +"COUNT(*) Total FROM eggr_complaintdetails@erp a, eggr_redressaldetails@erp b WHERE ";
  34. int iRptID = 0;
  35. if ( iRptID == 1 ) {
  36. sQry += " nvl(RECEIVINGCENTERID,0)=1 and ";
  37. } else if ( iRptID == 2 ) {
  38. sQry += " nvl(RECEIVINGCENTERID,0) !=1 and ";
  39. }
  40. //else sQry += " nvl(RECEIVINGCENTERID,0) !=3 and ";
  41. if ( !sFrDate.equals("") )
  42. {
  43. if (sToDate == null || sToDate.equals("") ) {
  44. sToDate = sFrDate;
  45. }
  46. //sQry += " trunc(complaintdate)=to_date('"+ sFrDate +"','dd/mm/yyyy') and ";
  47. sQry += " trunc(complaintdate) between to_date('"+ sFrDate +"','yyyy/mm/dd') and to_date('"+ sToDate +"','yyyy/mm/dd') and ";
  48. }
  49. sQry += " a.complaintid=b.complaintid and b.COMPLAINTSTATUSID IN(2,3,4,9) and TRUNC(COMPLAINTDATE) >= trunc(sysdate-730)"
  50. +"AND a.deptid = " + DEPTID
  51. +"group by a.deptid ) a inner join EG_DEPARTMENT@ERP c on a.deptid=c.id_dept ";
  52. sQry+= " left outer join ( SELECT deptid , "
  53. +"nvl(sum( case when sysdate-complaintdate>90 and b.COMPLAINTSTATUSID IN(2,3,4,9) then 1 end),'0') as days_90_pen , "
  54. +"nvl(sum( case when sysdate-complaintdate>60 and sysdate-complaintdate<=90 and b.COMPLAINTSTATUSID IN(2,3,4,9) then 1 end),'0') as days_61_90_pen , "
  55. +"nvl(sum( case when sysdate-complaintdate>30 and sysdate-complaintdate<=60 and b.COMPLAINTSTATUSID IN(2,3,4,9) then 1 end),'0') as days_31_60_pen , "
  56. +"nvl(sum( case when sysdate-complaintdate>15 and sysdate-complaintdate<=30 and b.COMPLAINTSTATUSID IN(2,3,4,9) then 1 end),'0') as days_16_30_pen , "
  57. +"nvl(sum( case when sysdate-complaintdate<=15 and b.COMPLAINTSTATUSID IN(2,3,4,9) then 1 end),'0') as days_0_15_pen , "
  58. +"nvl(count(case when b.COMPLAINTSTATUSID IN(2,3,4,9) then 1 end),'0') as Total_pen "
  59. +"FROM eggr_complaintdetails@erp a, eggr_redressaldetails@erp b "
  60. +"WHERE a.complaintid=b.complaintid and TRUNC(COMPLAINTDATE) >= trunc(sysdate-730) ";
  61. if ( iRptID == 1 ) {
  62. sQry += "and nvl(RECEIVINGCENTERID,0)=1 ";
  63. } else if ( iRptID == 2 ) {
  64. sQry += "and nvl(RECEIVINGCENTERID,0) !=1 ";
  65. }
  66. //else sQry += "and nvl(RECEIVINGCENTERID,0) !=3 ";
  67. if ( !sFrDate.equals("") ) {
  68. if (sToDate == null || sToDate.equals("") ) {
  69. sToDate = sFrDate;
  70. }
  71. //sQry += " trunc(complaintdate)=to_date('"+ sFrDate +"','dd/mm/yyyy') and ";
  72. sQry += "and trunc(complaintdate) between to_date('"+ sFrDate +"','yyyy/mm/dd') and to_date('"+ sToDate +"','yyyy/mm/dd') ";
  73. }
  74. if (DEPTID != null && !DEPTID.equals("0")) {
  75. sQry += "AND EXISTS (SELECT 1 FROM EG_DEPARTMENT@ERP c WHERE a.deptid = c.id_dept " +
  76. "AND (NVL(c.id_dept, 0) NOT LIKE 'F%' AND c.id_dept IS NOT NULL) " +
  77. "AND c.id_dept = " + DEPTID + ") ";
  78. }
  79. sQry +="group by a.deptid ) d on d.deptid=c.id_dept ";
  80. sQry +=" where (NVL(DEPT_NAME,0) NOT LIKE 'F%' AND DEPT_NAME IS NOT NULL) AND a.deptid>=32 "
  81. +"order by a.deptid";
  82. System.out.println("Gen Query:" + sQry);
  83. return sQry;
  84. }
  85. public List<Map<String, Object>> getzonewisedaskboardQuery(String sFrDate,String sToDate,String DEPTID) {
  86. Connection con =DBConnection.getConnection();
  87. // Statement stmt3;
  88. try {
  89. // stmt3 = con.createStatement();
  90. String query = getzonedaskboardQuery(sFrDate,sToDate,DEPTID);
  91. PreparedStatement pstmt = con.prepareStatement(query);
  92. if (query.contains(":deptID") && DEPTID != null && !DEPTID.equals("0")) {
  93. pstmt.setString(1, DEPTID);
  94. }
  95. System.out.println( "checkingzonewise...");
  96. ResultSet rs3 = pstmt.executeQuery();
  97. List<Map<String, Object>> rows = new ArrayList<>();
  98. while (rs3.next()) {
  99. Map<String, Object> row = new HashMap<>();
  100. ResultSetMetaData metaData = rs3.getMetaData();
  101. int columnCount = metaData.getColumnCount();
  102. for (int i = 1; i <= columnCount; i++) {
  103. String columnName = metaData.getColumnName(i);
  104. Object columnValue = rs3.getObject(i);
  105. //System.out.println(columnName+" :"+columnValue);
  106. row.put(columnName, columnValue);
  107. }
  108. rows.add(row);
  109. }
  110. return rows;
  111. }
  112. catch (Exception e){
  113. e.printStackTrace();
  114. }
  115. return null;
  116. }
  117. }