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.

156 lines
4.8 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 ReopenZonewiseComplaintReports {
  15. @Autowired
  16. DBConnection dbcon;
  17. public String sFrDate ="";
  18. public String sToDate ="";
  19. public String getReopenZoneComplaintQuery(String sFrDate,String sToDate,Integer iDeptID, Integer iPgrUserID) {
  20. int iPenReOpen = 1;
  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. /* if (iDaysID == 1) {
  44. queryBuilder.append("AND (SYSDATE - complaintdate) > 90 ");
  45. } else if (iDaysID == 2) {
  46. queryBuilder.append("AND SYSDATE - complaintdate > 60 AND SYSDATE - complaintdate <= 90 ");
  47. } else if (iDaysID == 3) {
  48. queryBuilder.append("AND SYSDATE - complaintdate > 30 AND SYSDATE - complaintdate <= 60 ");
  49. } else if (iDaysID == 4) {
  50. queryBuilder.append("AND SYSDATE - complaintdate > 15 AND SYSDATE - complaintdate <= 30 ");
  51. } else if (iDaysID == 5) {
  52. queryBuilder.append("AND SYSDATE - complaintdate > 0 AND SYSDATE - complaintdate <= 15 ");
  53. }
  54. */
  55. if (iPgrUserID != 0 && iDeptID != 37) {
  56. queryBuilder.append("AND NVL(b.redressalofficerid, 0) = ").append(iPgrUserID).append(" ");
  57. }
  58. if (!sFrDate.isEmpty() && !sToDate.isEmpty()) {
  59. queryBuilder.append("AND TRUNC(complaintdate) BETWEEN TO_DATE('").append(sFrDate).append("', 'yyyy/MM/dd') ");
  60. queryBuilder.append("AND TO_DATE('").append(sToDate).append("', 'yyyy/MM/dd') ");
  61. }
  62. /* if ("52,1,22,32,57,59,70,18,69,7,71,19,58,75,43".equals(sComplainttype)) {
  63. 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') ");
  64. } else if (!"0".equals(sComplainttype)) {
  65. queryBuilder.append("AND complainttype IN (").append(sComplainttype).append(") ");
  66. }
  67. */
  68. queryBuilder.append("ORDER BY user_name, a.complaintdate");
  69. String sqlQuery = queryBuilder.toString();
  70. System.out.println("sQry: " + sqlQuery);
  71. return sqlQuery;
  72. }
  73. public List<Map<String, Object>> getReopenZoneWiseComplaints(String sFrDate,String sToDate ,Integer deptId, Integer pgrUserId) {
  74. Connection con =DBConnection.getConnection();
  75. Statement stmt3;
  76. try {
  77. stmt3 = con.createStatement();
  78. System.out.println( "checkingreopenzonewisecomreports...");
  79. ResultSet rs4 = stmt3.executeQuery(getReopenZoneComplaintQuery(sFrDate,sToDate,deptId, pgrUserId ));
  80. List<Map<String, Object>> rows = new ArrayList<>();
  81. while (rs4.next()) {
  82. Map<String, Object> row = new HashMap<>();
  83. ResultSetMetaData metaData = rs4.getMetaData();
  84. int columnCount = metaData.getColumnCount();
  85. for (int i = 1; i <= columnCount; i++) {
  86. String columnName = metaData.getColumnName(i);
  87. Object columnValue = rs4.getObject(i);
  88. //System.out.println(columnName+" :"+columnValue);
  89. if (columnValue instanceof String) {
  90. columnValue = HtmlEntityDecoder.convertHtmlEntitiesToUtf8((String) columnValue);
  91. }
  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. }