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.

180 lines
6.7 KiB

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.ResultSet;
  4. import java.sql.ResultSetMetaData;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. import java.util.ArrayList;
  8. import java.util.Collections;
  9. import java.util.HashMap;
  10. import java.util.List;
  11. import java.util.Map;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Service;
  14. import in.gov.chennaicorporation.gccoffice.pgr.dbconnection.DBConnection;
  15. import in.gov.chennaicorporation.gccoffice.pgr.dto.Department;
  16. @Service
  17. public class ZonewiseReports {
  18. @Autowired
  19. DBConnection dbcon;
  20. public List<Department> getAlldeparments() {
  21. List<Department> complaintdept = new ArrayList<>();
  22. Connection con = DBConnection.getConnection();
  23. Statement stmt = null;
  24. ResultSet rs = null;
  25. try {
  26. stmt = con.createStatement();
  27. rs = stmt.executeQuery(getDepartmentQuery());
  28. while (rs.next()) {
  29. Department departments = new Department();
  30. departments.setId(rs.getString("id_dept"));
  31. departments.setName(rs.getString("dept_name"));
  32. complaintdept.add(departments);
  33. }
  34. return complaintdept;
  35. } catch (SQLException e) {
  36. e.printStackTrace();
  37. } finally {
  38. try {
  39. if (rs != null) {
  40. rs.close();
  41. }
  42. if (stmt != null) {
  43. stmt.close();
  44. }
  45. if (con != null) {
  46. con.close();
  47. }
  48. } catch (SQLException e) {
  49. e.printStackTrace();
  50. }
  51. }
  52. return Collections.emptyList(); // Return an empty list if there's an error
  53. }
  54. private String getDepartmentQuery() {
  55. return "SELECT id_dept, dept_name "
  56. + "FROM EG_DEPARTMENT@ERP "
  57. + "WHERE NVL(dept_name, '0') NOT LIKE 'F%' AND dept_name IS NOT NULL AND id_dept >= 32 "
  58. + "ORDER BY id_dept";
  59. }
  60. public String getzoneQuery(String sFrDate,String sToDate,String DEPT_NAME) {
  61. String sQry= "Select c.dept_name,a.iduser,a.user_name,nvl(b.extrafield2,' ') MOBILENO,a.nos,a.deptid from (SELECT cd.deptid,u.user_name, COUNT (cd.complaintid) nos,max(u.id_user) iduser"
  62. +" FROM eggr_complaintdetails@erp cd,"
  63. +" eggr_redressaldetails@erp rd,"
  64. +" eggr_complaintstatus@erp st,"
  65. +" eg_user@erp u"
  66. +" WHERE cd.complaintid = rd.complaintid "
  67. +" AND rd.complaintstatusid = st.complaintstatusid"
  68. +" AND rd.redressalofficerid = u.id_user and complaintdate >= '25-oct-2010'";
  69. int iPenReOpen=0;
  70. if ( iPenReOpen == 0 )
  71. sQry += " AND st.statusname IN ('REGISTERED', 'PROCESSING', 'FORWARDED','REOPENED') and rd.COMPLAINTSTATUSID IN(2,3,4,9) ";
  72. else if ( iPenReOpen == 1 ) // Pending
  73. sQry += " AND st.statusname IN ('REGISTERED', 'PROCESSING', 'FORWARDED') and rd.COMPLAINTSTATUSID IN(2,3,4) ";
  74. else if ( iPenReOpen == 2 ) // ReOpen
  75. sQry += " AND st.statusname IN ('REOPENED') and rd.COMPLAINTSTATUSID IN(9) ";
  76. int iRptID=0;
  77. if ( iRptID == 1 ) sQry += " and nvl(RECEIVINGCENTERID,0)=1 ";
  78. else if ( iRptID == 2 ) sQry += " and nvl(RECEIVINGCENTERID,0) !=1 ";
  79. //Object sComplainttype = "";
  80. // if ( sComplainttype .equals("52,1,22,32,57,59,70,18,69,7,71,19,58,75,43") ) sQry += " and complainttype not in("+ sComplainttype +") ";
  81. // else if ( !sComplainttype.equals("0") ) sQry += " and complainttype in("+ sComplainttype +") ";
  82. //if ( !sFrDate.equals("") ) sQry += " and trunc(complaintdate)=to_date('"+ sFrDate +"','dd/mm/yyyy') ";
  83. if ( !sFrDate.equals("") )
  84. {
  85. if (sToDate == null || sToDate.equals("") ) sToDate = sFrDate;
  86. //sQry += " trunc(complaintdate)=to_date('"+ sFrDate +"','dd/mm/yyyy') and ";
  87. sQry += " and trunc(complaintdate) between to_date('"+ sFrDate +"','yyyy/mm/dd') and to_date('"+ sToDate +"','yyyy/mm/dd') ";
  88. }
  89. int iDaysID=0;
  90. if ( iDaysID == 1 ) sQry += " and (sysdate-complaintdate)>90 ";
  91. else if ( iDaysID == 2 ) sQry += " and sysdate-complaintdate>60 and sysdate-complaintdate<=90 ";
  92. else if ( iDaysID == 3 ) sQry += " and sysdate-complaintdate>30 and sysdate-complaintdate<=60 ";
  93. else if ( iDaysID == 4 ) sQry += " and sysdate-complaintdate>15 and sysdate-complaintdate<=30 ";
  94. else if ( iDaysID == 5 ) sQry += " and sysdate-complaintdate>0 and sysdate-complaintdate<=15 ";
  95. sQry += " GROUP BY cd.deptid,u.user_name ORDER BY cd.deptid,u.user_name) a , eg_user@erp b,eg_department@erp c where a.deptid=c.id_dept(+) and ";
  96. sQry += " a.user_name=b.user_name AND (NVL(DEPT_NAME,0) NOT LIKE 'F%' AND DEPT_NAME IS NOT NULL)";
  97. int iDeptID = 0 ;
  98. if ( (iDeptID == 48 || iDeptID == 49 || iDeptID == 50) && iPenReOpen == 2) // ReOpen & Region
  99. {
  100. if ( iDeptID == 48 )
  101. sQry += " and nvl(a.deptid,0) in (32,33,34,35,36,48)";
  102. else if ( iDeptID == 49 )
  103. sQry += " and nvl(a.deptid,0) in (42,43,44,45,46,49)";
  104. else if ( iDeptID == 50 )
  105. sQry += " and nvl(a.deptid,0) in (37,38,39,40,41,50)";
  106. }
  107. else if ( iDeptID != 0 ) sQry += " and nvl(a.deptid,0)= "+ iDeptID;
  108. if (DEPT_NAME != null && !DEPT_NAME.equals("0")) {
  109. sQry += " AND UPPER(NVL(DEPT_NAME, '')) = UPPER('" + DEPT_NAME + "')";
  110. }
  111. //if ( sComplainttype.equals("52,1,22,32,57,59,70,18,69,7,71") ) sQry += " and a.complainttype not in("+ sComplainttype +") ";
  112. //else if ( !sComplainttype.equals("") ) sQry += " and complainttype in("+ sComplainttype +") ";
  113. sQry += " order by c.dept_name,a.user_name";
  114. System.out.println("Gen Query:" + sQry);
  115. return sQry;
  116. }
  117. public List<Map<String, Object>> getZonewise(String sFrDate,String sToDate,String DEPT_NAME) {
  118. Connection con =DBConnection.getConnection();
  119. Statement stmt3;
  120. try {
  121. stmt3 = con.createStatement();
  122. System.out.println( "checkingzonewise...");
  123. //String sComplainttype = "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";
  124. ResultSet rs3 = stmt3.executeQuery(getzoneQuery(sFrDate,sToDate,DEPT_NAME));
  125. List<Map<String, Object>> rows = new ArrayList<>();
  126. while (rs3.next()) {
  127. Map<String, Object> row = new HashMap<>();
  128. ResultSetMetaData metaData = rs3.getMetaData();
  129. int columnCount = metaData.getColumnCount();
  130. for (int i = 1; i <= columnCount; i++) {
  131. String columnName = metaData.getColumnName(i);
  132. Object columnValue = rs3.getObject(i);
  133. //System.out.println(columnName+" :"+columnValue);
  134. row.put(columnName, columnValue);
  135. }
  136. rows.add(row);
  137. }
  138. return rows;
  139. }
  140. catch (Exception e){
  141. e.printStackTrace();
  142. }
  143. return null;
  144. }
  145. }