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.

133 lines
4.7 KiB

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.Statement;
  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 AgeAnalysisComplaintReports {
  15. @Autowired
  16. DBConnection dbcon;
  17. public String sFrDate ="";
  18. public String sToDate ="";
  19. public String getAgeAnalysisComplaintQuery(String sFrDate,String sToDate,Integer iDeptID, Integer iPgrUserID) {
  20. int iPenReOpen = 0;
  21. StringBuilder queryBuilder = new StringBuilder();
  22. queryBuilder.append("SELECT a.*, NVL(TO_CHAR(a.complaintdate, 'dd-mm-rrrr'), ' ') compdate, c.DEPT_NAME, u.user_name FROM ");
  23. queryBuilder.append("eggr_complaintdetails@erp a, EG_DEPARTMENT@ERP c, eggr_redressaldetails@erp b, eg_user@erp u ");
  24. queryBuilder.append("WHERE a.deptid = c.id_dept AND (NVL(DEPT_NAME, '0') NOT LIKE 'F%' AND DEPT_NAME IS NOT NULL) ");
  25. queryBuilder.append("AND a.complaintid = b.complaintid AND complaintdate >= TO_DATE('25-Oct-2010', 'DD-Mon-YYYY') ");
  26. queryBuilder.append("AND u.id_user = b.redressalofficerid ");
  27. if (iPenReOpen == 0) {
  28. queryBuilder.append("AND b.COMPLAINTSTATUSID IN (2, 3, 4, 9) ");
  29. } else if (iPenReOpen == 1) {
  30. queryBuilder.append("AND b.COMPLAINTSTATUSID IN (2, 3, 4) ");
  31. } else if (iPenReOpen == 2) {
  32. queryBuilder.append("AND b.COMPLAINTSTATUSID IN (9) ");
  33. }
  34. /* if (iRptID == 1) {
  35. queryBuilder.append("AND NVL(a.RECEIVINGCENTERID, 0) = 1 ");
  36. } else if (iRptID == 2) {
  37. queryBuilder.append("AND NVL(a.RECEIVINGCENTERID, 0) != 1 ");
  38. }
  39. */
  40. if (iDeptID != 0) {
  41. queryBuilder.append("AND NVL(a.deptid, 0) = ").append(iDeptID).append(" ");
  42. }
  43. /*
  44. if (iDaysID == 1) {
  45. queryBuilder.append("AND (SYSDATE - complaintdate) > 90 ");
  46. } else if (iDaysID == 2) {
  47. queryBuilder.append("AND SYSDATE - complaintdate > 60 AND SYSDATE - complaintdate <= 90 ");
  48. } else if (iDaysID == 3) {
  49. queryBuilder.append("AND SYSDATE - complaintdate > 30 AND SYSDATE - complaintdate <= 60 ");
  50. } else if (iDaysID == 4) {
  51. queryBuilder.append("AND SYSDATE - complaintdate > 15 AND SYSDATE - complaintdate <= 30 ");
  52. } else if (iDaysID == 5) {
  53. queryBuilder.append("AND SYSDATE - complaintdate > 0 AND SYSDATE - complaintdate <= 15 ");
  54. }
  55. */
  56. if (iPgrUserID != 0 && iDeptID != 37) {
  57. queryBuilder.append("AND NVL(b.redressalofficerid, 0) = ").append(iPgrUserID).append(" ");
  58. }
  59. if (!sFrDate.isEmpty() && !sToDate.isEmpty()) {
  60. queryBuilder.append("AND TRUNC(complaintdate) BETWEEN TO_DATE('").append(sFrDate).append("', 'yyyy/MM/dd') ");
  61. queryBuilder.append("AND TO_DATE('").append(sToDate).append("', 'yyyy/MM/dd') ");
  62. }
  63. /*
  64. if ("52,1,22,32,57,59,70,18,69,7,71,19,58,75,43".equals(sComplainttype)) {
  65. queryBuilder.append("AND a.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') ");
  66. } else if (!"0".equals(sComplainttype)) {
  67. queryBuilder.append("AND complainttype IN (").append(sComplainttype).append(") ");
  68. }
  69. */
  70. queryBuilder.append("ORDER BY user_name, a.complaintdate");
  71. String sqlQuery = queryBuilder.toString();
  72. System.out.println("sQry: " + sqlQuery);
  73. return sqlQuery;
  74. }
  75. public List<Map<String, Object>> getAgeAnalysisComplaints(String sFrDate,String sToDate, Integer deptId, Integer pgrUserId) {
  76. Connection con =DBConnection.getConnection();
  77. Statement stmt3;
  78. try {
  79. stmt3 = con.createStatement();
  80. System.out.println( "checkingAgeAnalysiscomreports...");
  81. // 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";
  82. ResultSet rs4 = stmt3.executeQuery(getAgeAnalysisComplaintQuery(sFrDate,sToDate,deptId, pgrUserId ));
  83. List<Map<String, Object>> rows = new ArrayList<>();
  84. while (rs4.next()) {
  85. Map<String, Object> row = new HashMap<>();
  86. ResultSetMetaData metaData = rs4.getMetaData();
  87. int columnCount = metaData.getColumnCount();
  88. for (int i = 1; i <= columnCount; i++) {
  89. String columnName = metaData.getColumnName(i);
  90. Object columnValue = rs4.getObject(i);
  91. //System.out.println(columnName+" :"+columnValue);
  92. row.put(columnName, columnValue);
  93. }
  94. rows.add(row);
  95. }
  96. return rows;
  97. }
  98. catch (Exception e){
  99. e.printStackTrace();
  100. }
  101. return null;
  102. }
  103. }