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.

254 lines
8.6 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
​
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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
  1. package in.gov.chennaicorporation.gccoffice.pgr.service;
  2. import java.sql.Statement;
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.ResultSetMetaData;
  7. import java.sql.SQLException;
  8. import java.util.ArrayList;
  9. import java.util.Collections;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. import java.util.Map;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import in.gov.chennaicorporation.gccoffice.pgr.dbconnection.DBConnection;
  16. import in.gov.chennaicorporation.gccoffice.pgr.dto.ComplaintGroup;
  17. import in.gov.chennaicorporation.gccoffice.pgr.dto.ComplaintType;
  18. //import in.gov.chennaicorporation.gccoffice.pgr.repository.PgrReportRepository;
  19. @Service
  20. public class AllReports{
  21. @Autowired
  22. DBConnection dbcon;
  23. //ComplaintTypes options method
  24. public List<ComplaintType> getAllComplaintTypes() {
  25. List<ComplaintType> complaintTypes = new ArrayList<>();
  26. Connection con = DBConnection.getConnection();
  27. Statement stmt = null;
  28. ResultSet rs = null;
  29. try {
  30. stmt = con.createStatement();
  31. rs = stmt.executeQuery(getComplainttypeQuery());
  32. while (rs.next()) {
  33. ComplaintType complaintType = new ComplaintType();
  34. complaintType.setId(rs.getString("complainttypeid"));
  35. complaintType.setName(rs.getString("complainttypename"));
  36. complaintTypes.add(complaintType);
  37. }
  38. return complaintTypes;
  39. } catch (SQLException e) {
  40. e.printStackTrace();
  41. } finally {
  42. try {
  43. if (rs != null) {
  44. rs.close();
  45. }
  46. if (stmt != null) {
  47. stmt.close();
  48. }
  49. if (con != null) {
  50. con.close();
  51. }
  52. } catch (SQLException e) {
  53. e.printStackTrace();
  54. }
  55. }
  56. return Collections.emptyList(); // Return an empty list if there's an error
  57. }
  58. private String getComplainttypeQuery() {
  59. return "SELECT DISTINCT ct.complainttypeid, ct.complainttypename " +
  60. "FROM EGGR_COMPLAINTTYPES@erp ct";
  61. }
  62. //complaint group options method
  63. public List<ComplaintGroup> getAllComplaintgroups() {
  64. List<ComplaintGroup> complaintGroups = new ArrayList<>();
  65. Connection con = DBConnection.getConnection();
  66. Statement stmt = null;
  67. ResultSet rs = null;
  68. try {
  69. stmt = con.createStatement();
  70. rs = stmt.executeQuery(getComplaintgroupQuery());
  71. while (rs.next()) {
  72. ComplaintGroup complaintGroup = new ComplaintGroup();
  73. complaintGroup.setId(rs.getString("id_complaintgroup"));
  74. complaintGroup.setName(rs.getString("complaintgroupname"));
  75. complaintGroups.add(complaintGroup);
  76. }
  77. return complaintGroups;
  78. } catch (SQLException e) {
  79. e.printStackTrace();
  80. } finally {
  81. try {
  82. if (rs != null) {
  83. rs.close();
  84. }
  85. if (stmt != null) {
  86. stmt.close();
  87. }
  88. if (con != null) {
  89. con.close();
  90. }
  91. } catch (SQLException e) {
  92. e.printStackTrace();
  93. }
  94. }
  95. return Collections.emptyList(); // Return an empty list if there's an error
  96. }
  97. private String getComplaintgroupQuery() {
  98. return "SELECT DISTINCT id_complaintgroup, complaintgroupname " +
  99. "FROM eggr_complaintgroup@erp";
  100. }
  101. public String getQuery(String sFrDate, String sToDate, String sRptGroup, String sRptType, String cbCompStatus,String mode) {
  102. String sQry = "SELECT z.name AS zone_name, dn.name AS division_name, location.name AS location, " +
  103. "dept_name, TO_CHAR(complaintdate, 'dd-mm-yyyy') COMPDATE, TO_CHAR(complaintdate, 'HH24:MI:SS') Time, " +
  104. "cs.statusname AS status, usr.user_name, cd.complaintnumber, " +
  105. "decode(cd.ID_MODE,1,'Internet',2,'Phone',3,'Paper form',4,'WHATSAPP',5,'FLOOD CONTROL',6,'MOBILE APPLICATION',7,'SOCIAL MEDIA',8,'NEWS PAPER') AS \"MODE\","+
  106. "COALESCE(ct.complainttypename, 'Unspecified') AS complainttypename, cg.complaintgroupname " +
  107. "FROM eggr_complaintdetails@erp cd " +
  108. "INNER JOIN eggr_redressaldetails@erp rd ON cd.complaintid = rd.complaintid " +
  109. "INNER JOIN eggr_complaintstatus@erp cs ON rd.complaintstatusid = cs.complaintstatusid " +
  110. "INNER JOIN eggr_complainttypes@erp ct ON TRIM(cd.complainttype) = ct.complainttypeid " +
  111. "INNER JOIN eg_user@erp usr ON rd.redressalofficerid = usr.id_user " +
  112. "LEFT JOIN eg_department@erp d ON cd.deptid = d.id_dept " +
  113. "INNER JOIN eggr_complaintgroup@erp cg ON cg.id_complaintgroup = ct.complaintgroup_id " +
  114. "INNER JOIN eg_boundary@erp dn ON dn.id_bndry = cd.bndry " +
  115. "INNER JOIN eg_boundary@erp z ON dn.parent = z.id_bndry " +
  116. "INNER JOIN eg_boundary@ERP LOCATION ON LOCATION.id_bndry = cd.locbndryid " +
  117. "WHERE " +
  118. "(cd.deptid IS NULL OR (cd.deptid < 21 OR cd.deptid > 30)) " +
  119. "AND complaintdate BETWEEN TO_DATE(?, 'yyyy-MM-dd') " +
  120. "AND (TO_DATE(?, 'yyyy-MM-dd') + 1)";
  121. // Add conditions based on parameters
  122. List<String> conditions = new ArrayList<>();
  123. List<Object> params = new ArrayList<>();
  124. params.add(sFrDate);
  125. params.add(sToDate);
  126. if (cbCompStatus != null && cbCompStatus.equals("Pending")) {
  127. conditions.add("cs.complaintstatusid NOT IN (5,6,8,10,11)");
  128. } else if (cbCompStatus != null && cbCompStatus.equals("Completed")) {
  129. conditions.add("cs.complaintstatusid IN (5,6,8,10,11)");
  130. }
  131. if (cbCompStatus != null && cbCompStatus.equals("Reopened")) {
  132. conditions.add("cs.complaintstatusid IN (9)");
  133. }
  134. if (cbCompStatus != null && cbCompStatus.equals("Forwarded")) {
  135. conditions.add("cs.complaintstatusid IN (3)");
  136. }
  137. if (sRptGroup != null && !sRptGroup.equals("0")) {
  138. conditions.add("cg.complaintgroupname = ?");
  139. params.add(sRptGroup);
  140. }
  141. if (sRptType != null && !sRptType.equals("0")) {
  142. conditions.add("ct.complainttypename = ?");
  143. params.add(sRptType);
  144. }
  145. if (mode != null && !mode.equals("0")) {
  146. conditions.add("cd.ID_MODE = ?");
  147. params.add(mode);
  148. }
  149. if (!conditions.isEmpty()) {
  150. sQry += " AND " + String.join(" AND ", conditions);
  151. }
  152. sQry += " ORDER BY zone_name, division_name, complaintdate ";
  153. System.out.println("allreports Query:" + sQry);
  154. return sQry;
  155. }
  156. public List<Map<String, Object>> check(String sFrDate, String sToDate, String sRptGroup, String sRptType, String cbCompStatus,String mode) {
  157. Connection con = DBConnection.getConnection();
  158. PreparedStatement stmt3 = null;
  159. try {
  160. String query = getQuery(sFrDate, sToDate, sRptGroup, sRptType, cbCompStatus,mode);
  161. stmt3 = con.prepareStatement(query);
  162. // Set parameters
  163. int parameterIndex = 1;
  164. stmt3.setString(parameterIndex++, sFrDate);
  165. stmt3.setString(parameterIndex++, sToDate);
  166. if (sRptGroup != null && !sRptGroup.equals("0")) {
  167. stmt3.setString(parameterIndex++, sRptGroup);
  168. }
  169. if (sRptType != null && !sRptType.equals("0")) {
  170. stmt3.setString(parameterIndex++, sRptType);
  171. }
  172. if (cbCompStatus != null && !cbCompStatus.equals("0")) {
  173. // No need to set a parameter for the status condition
  174. }
  175. if (mode != null && !mode.equals("0")) {
  176. stmt3.setString(parameterIndex++, mode);
  177. }
  178. ResultSet rs3 = stmt3.executeQuery();
  179. List<Map<String, Object>> rows = new ArrayList<>();
  180. while (rs3.next()) {
  181. Map<String, Object> row = new HashMap<>();
  182. ResultSetMetaData metaData = rs3.getMetaData();
  183. int columnCount = metaData.getColumnCount();
  184. for (int i = 1; i <= columnCount; i++) {
  185. String columnName = metaData.getColumnName(i);
  186. Object columnValue = rs3.getObject(i);
  187. row.put(columnName, columnValue);
  188. }
  189. rows.add(row);
  190. }
  191. return rows;
  192. } catch (Exception e) {
  193. e.printStackTrace();
  194. } finally {
  195. try {
  196. if (stmt3 != null) {
  197. stmt3.close();
  198. }
  199. con.close();
  200. } catch (SQLException e) {
  201. e.printStackTrace();
  202. }
  203. }
  204. return null;
  205. }
  206. }