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.

188 lines
6.8 KiB

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.DtoAgeAnalysis;
  16. @Service
  17. public class AgeAnalysisReports {
  18. @Autowired
  19. DBConnection dbcon;
  20. public List<DtoAgeAnalysis> getAllDtoAgeAnalysis() {
  21. List<DtoAgeAnalysis> 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(getdtoageanalysisQuery());
  28. while (rs.next()) {
  29. DtoAgeAnalysis dtoageanalysis = new DtoAgeAnalysis();
  30. dtoageanalysis.setId(rs.getString("id_dept"));
  31. dtoageanalysis.setName(rs.getString("dept_name"));
  32. complaintdept.add(dtoageanalysis);
  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 getdtoageanalysisQuery() {
  55. return "SELECT Distinct id_dept, dept_name "
  56. + "FROM EG_DEPARTMENT@ERP "
  57. + "ORDER BY id_dept";
  58. }
  59. public String getageanalysisQuery(String sFrDate,String sToDate,String DEPT_NAME) {
  60. 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"
  61. +" FROM eggr_complaintdetails@erp cd,"
  62. +" eggr_redressaldetails@erp rd,"
  63. +" eggr_complaintstatus@erp st,"
  64. +" eg_user@erp u"
  65. +" WHERE cd.complaintid = rd.complaintid "
  66. +" AND rd.complaintstatusid = st.complaintstatusid"
  67. +" AND rd.redressalofficerid = u.id_user and complaintdate >= '25-oct-2010'";
  68. int iPenReOpen = 0;
  69. if ( iPenReOpen == 0 )
  70. sQry += " AND st.statusname IN ('REGISTERED', 'PROCESSING', 'FORWARDED','REOPENED') and rd.COMPLAINTSTATUSID IN(2,3,4,9) ";
  71. else if ( iPenReOpen == 1 ) // Pending
  72. sQry += " AND st.statusname IN ('REGISTERED', 'PROCESSING', 'FORWARDED') and rd.COMPLAINTSTATUSID IN(2,3,4) ";
  73. else if ( iPenReOpen == 2 ) // ReOpen
  74. sQry += " AND st.statusname IN ('REOPENED') and rd.COMPLAINTSTATUSID IN(9) ";
  75. int iRptID = 0;
  76. if ( iRptID == 1 ) sQry += " and nvl(RECEIVINGCENTERID,0)=1 ";
  77. else if ( iRptID == 2 ) sQry += " and nvl(RECEIVINGCENTERID,0) !=1 ";
  78. //Object sComplainttype = "";
  79. // if ( sComplainttype .equals("52,1,22,32,57,59,70,18,69,7,71,19,58,75,43") ) sQry += " and complainttype not in("+ sComplainttype +") ";
  80. // else if ( !sComplainttype.equals("0") ) sQry += " and complainttype in("+ sComplainttype +") ";
  81. //if ( !sFrDate.equals("") ) sQry += " and trunc(complaintdate)=to_date('"+ sFrDate +"','dd/mm/yyyy') ";
  82. if ( !sFrDate.equals("") )
  83. {
  84. if (sToDate == null || sToDate.equals("") ) sToDate = sFrDate;
  85. //sQry += " trunc(complaintdate)=to_date('"+ sFrDate +"','dd/mm/yyyy') and ";
  86. sQry += " and trunc(complaintdate) between to_date('"+ sFrDate +"','yyyy/mm/dd') and to_date('"+ sToDate +"','yyyy/mm/dd') ";
  87. }
  88. int iDaysID = 0;
  89. if ( iDaysID == 1 ) sQry += " and (sysdate-complaintdate)>90 ";
  90. else if ( iDaysID == 2 ) sQry += " and sysdate-complaintdate>60 and sysdate-complaintdate<=90 ";
  91. else if ( iDaysID == 3 ) sQry += " and sysdate-complaintdate>30 and sysdate-complaintdate<=60 ";
  92. else if ( iDaysID == 4 ) sQry += " and sysdate-complaintdate>15 and sysdate-complaintdate<=30 ";
  93. else if ( iDaysID == 5 ) sQry += " and sysdate-complaintdate>0 and sysdate-complaintdate<=15 ";
  94. 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 ";
  95. sQry += " a.user_name=b.user_name AND (NVL(DEPT_NAME,0) NOT LIKE 'F%' AND DEPT_NAME IS NOT NULL)";
  96. int iDeptID = 0;
  97. if ( (iDeptID == 48 || iDeptID == 49 || iDeptID == 50) && iPenReOpen == 2) // ReOpen & Region
  98. {
  99. if ( iDeptID == 48 )
  100. sQry += " and nvl(a.deptid,0) in (32,33,34,35,36,48)";
  101. else if ( iDeptID == 49 )
  102. sQry += " and nvl(a.deptid,0) in (42,43,44,45,46,49)";
  103. else if ( iDeptID == 50 )
  104. sQry += " and nvl(a.deptid,0) in (37,38,39,40,41,50)";
  105. }
  106. else if ( iDeptID != 0 ) sQry += " and nvl(a.deptid,0)= "+ iDeptID;
  107. if (DEPT_NAME != null && !DEPT_NAME.equals("0")) {
  108. sQry += " AND UPPER(NVL(DEPT_NAME, '')) = UPPER('" + DEPT_NAME + "')";
  109. }
  110. //if ( sComplainttype.equals("52,1,22,32,57,59,70,18,69,7,71") ) sQry += " and a.complainttype not in("+ sComplainttype +") ";
  111. //else if ( !sComplainttype.equals("") ) sQry += " and complainttype in("+ sComplainttype +") ";
  112. sQry += " order by c.dept_name,a.user_name";
  113. System.out.println("Gen Query:" + sQry);
  114. return sQry;
  115. }
  116. public List<Map<String, Object>> getAgeAnalysiswise(String sFrDate,String sToDate,String DEPT_NAME) {
  117. Connection con =DBConnection.getConnection();
  118. Statement stmt3;
  119. try {
  120. stmt3 = con.createStatement();
  121. System.out.println( "checkingAgeAnalysis...");
  122. ResultSet rs3 = stmt3.executeQuery(getageanalysisQuery(sFrDate,sToDate,DEPT_NAME));
  123. List<Map<String, Object>> rows = new ArrayList<>();
  124. while (rs3.next()) {
  125. Map<String, Object> row = new HashMap<>();
  126. ResultSetMetaData metaData = rs3.getMetaData();
  127. int columnCount = metaData.getColumnCount();
  128. for (int i = 1; i <= columnCount; i++) {
  129. String columnName = metaData.getColumnName(i);
  130. Object columnValue = rs3.getObject(i);
  131. //System.out.println(columnName+" :"+columnValue);
  132. if (columnValue instanceof String) {
  133. columnValue = HtmlEntityDecoder.convertHtmlEntitiesToUtf8((String) columnValue);
  134. }
  135. row.put(columnName, columnValue);
  136. }
  137. rows.add(row);
  138. }
  139. return rows;
  140. }
  141. catch (Exception e){
  142. e.printStackTrace();
  143. }
  144. return null;
  145. }
  146. }