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
254 lines
8.6 KiB
package in.gov.chennaicorporation.gccoffice.pgr.service;
|
|
|
|
import java.sql.Statement;
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
import java.sql.ResultSetMetaData;
|
|
import java.sql.SQLException;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import in.gov.chennaicorporation.gccoffice.pgr.dbconnection.DBConnection;
|
|
import in.gov.chennaicorporation.gccoffice.pgr.dto.ComplaintGroup;
|
|
import in.gov.chennaicorporation.gccoffice.pgr.dto.ComplaintType;
|
|
//import in.gov.chennaicorporation.gccoffice.pgr.repository.PgrReportRepository;
|
|
|
|
@Service
|
|
public class AllReports{
|
|
@Autowired
|
|
DBConnection dbcon;
|
|
|
|
//ComplaintTypes options method
|
|
public List<ComplaintType> getAllComplaintTypes() {
|
|
List<ComplaintType> complaintTypes = new ArrayList<>();
|
|
Connection con = DBConnection.getConnection();
|
|
Statement stmt = null;
|
|
ResultSet rs = null;
|
|
|
|
try {
|
|
stmt = con.createStatement();
|
|
rs = stmt.executeQuery(getComplainttypeQuery());
|
|
|
|
while (rs.next()) {
|
|
ComplaintType complaintType = new ComplaintType();
|
|
complaintType.setId(rs.getString("complainttypeid"));
|
|
complaintType.setName(rs.getString("complainttypename"));
|
|
complaintTypes.add(complaintType);
|
|
}
|
|
|
|
return complaintTypes;
|
|
} catch (SQLException e) {
|
|
e.printStackTrace();
|
|
} finally {
|
|
try {
|
|
if (rs != null) {
|
|
rs.close();
|
|
}
|
|
if (stmt != null) {
|
|
stmt.close();
|
|
}
|
|
if (con != null) {
|
|
con.close();
|
|
}
|
|
} catch (SQLException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
return Collections.emptyList(); // Return an empty list if there's an error
|
|
}
|
|
|
|
private String getComplainttypeQuery() {
|
|
return "SELECT DISTINCT ct.complainttypeid, ct.complainttypename " +
|
|
"FROM EGGR_COMPLAINTTYPES@erp ct";
|
|
|
|
}
|
|
|
|
//complaint group options method
|
|
|
|
public List<ComplaintGroup> getAllComplaintgroups() {
|
|
List<ComplaintGroup> complaintGroups = new ArrayList<>();
|
|
Connection con = DBConnection.getConnection();
|
|
Statement stmt = null;
|
|
ResultSet rs = null;
|
|
|
|
try {
|
|
stmt = con.createStatement();
|
|
rs = stmt.executeQuery(getComplaintgroupQuery());
|
|
|
|
while (rs.next()) {
|
|
ComplaintGroup complaintGroup = new ComplaintGroup();
|
|
complaintGroup.setId(rs.getString("id_complaintgroup"));
|
|
complaintGroup.setName(rs.getString("complaintgroupname"));
|
|
complaintGroups.add(complaintGroup);
|
|
}
|
|
|
|
return complaintGroups;
|
|
} catch (SQLException e) {
|
|
e.printStackTrace();
|
|
} finally {
|
|
try {
|
|
if (rs != null) {
|
|
rs.close();
|
|
}
|
|
if (stmt != null) {
|
|
stmt.close();
|
|
}
|
|
if (con != null) {
|
|
con.close();
|
|
}
|
|
} catch (SQLException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
return Collections.emptyList(); // Return an empty list if there's an error
|
|
}
|
|
|
|
private String getComplaintgroupQuery() {
|
|
return "SELECT DISTINCT id_complaintgroup, complaintgroupname " +
|
|
"FROM eggr_complaintgroup@erp";
|
|
}
|
|
|
|
|
|
public String getQuery(String sFrDate, String sToDate, String sRptGroup, String sRptType, String cbCompStatus,String mode) {
|
|
|
|
String sQry = "SELECT z.name AS zone_name, dn.name AS division_name, location.name AS location, " +
|
|
"dept_name, TO_CHAR(complaintdate, 'dd-mm-yyyy') COMPDATE, TO_CHAR(complaintdate, 'HH24:MI:SS') Time, " +
|
|
"cs.statusname AS status, usr.user_name, cd.complaintnumber, " +
|
|
"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\","+
|
|
"COALESCE(ct.complainttypename, 'Unspecified') AS complainttypename, cg.complaintgroupname " +
|
|
"FROM eggr_complaintdetails@erp cd " +
|
|
"INNER JOIN eggr_redressaldetails@erp rd ON cd.complaintid = rd.complaintid " +
|
|
"INNER JOIN eggr_complaintstatus@erp cs ON rd.complaintstatusid = cs.complaintstatusid " +
|
|
"INNER JOIN eggr_complainttypes@erp ct ON TRIM(cd.complainttype) = ct.complainttypeid " +
|
|
"INNER JOIN eg_user@erp usr ON rd.redressalofficerid = usr.id_user " +
|
|
"LEFT JOIN eg_department@erp d ON cd.deptid = d.id_dept " +
|
|
"INNER JOIN eggr_complaintgroup@erp cg ON cg.id_complaintgroup = ct.complaintgroup_id " +
|
|
"INNER JOIN eg_boundary@erp dn ON dn.id_bndry = cd.bndry " +
|
|
"INNER JOIN eg_boundary@erp z ON dn.parent = z.id_bndry " +
|
|
"INNER JOIN eg_boundary@ERP LOCATION ON LOCATION.id_bndry = cd.locbndryid " +
|
|
"WHERE " +
|
|
"(cd.deptid IS NULL OR (cd.deptid < 21 OR cd.deptid > 30)) " +
|
|
"AND complaintdate BETWEEN TO_DATE(?, 'yyyy-MM-dd') " +
|
|
"AND (TO_DATE(?, 'yyyy-MM-dd') + 1)";
|
|
|
|
// Add conditions based on parameters
|
|
List<String> conditions = new ArrayList<>();
|
|
List<Object> params = new ArrayList<>();
|
|
params.add(sFrDate);
|
|
params.add(sToDate);
|
|
|
|
if (cbCompStatus != null && cbCompStatus.equals("Pending")) {
|
|
conditions.add("cs.complaintstatusid NOT IN (5,6,8,10,11)");
|
|
} else if (cbCompStatus != null && cbCompStatus.equals("Completed")) {
|
|
conditions.add("cs.complaintstatusid IN (5,6,8,10,11)");
|
|
}
|
|
if (cbCompStatus != null && cbCompStatus.equals("Reopened")) {
|
|
conditions.add("cs.complaintstatusid IN (9)");
|
|
}
|
|
|
|
if (cbCompStatus != null && cbCompStatus.equals("Forwarded")) {
|
|
conditions.add("cs.complaintstatusid IN (3)");
|
|
}
|
|
|
|
if (sRptGroup != null && !sRptGroup.equals("0")) {
|
|
conditions.add("cg.complaintgroupname = ?");
|
|
params.add(sRptGroup);
|
|
}
|
|
|
|
if (sRptType != null && !sRptType.equals("0")) {
|
|
conditions.add("ct.complainttypename = ?");
|
|
params.add(sRptType);
|
|
}
|
|
if (mode != null && !mode.equals("0")) {
|
|
conditions.add("cd.ID_MODE = ?");
|
|
params.add(mode);
|
|
}
|
|
|
|
if (!conditions.isEmpty()) {
|
|
sQry += " AND " + String.join(" AND ", conditions);
|
|
}
|
|
|
|
sQry += " ORDER BY zone_name, division_name, complaintdate ";
|
|
|
|
System.out.println("allreports Query:" + sQry);
|
|
return sQry;
|
|
}
|
|
|
|
|
|
|
|
public List<Map<String, Object>> check(String sFrDate, String sToDate, String sRptGroup, String sRptType, String cbCompStatus,String mode) {
|
|
Connection con = DBConnection.getConnection();
|
|
PreparedStatement stmt3 = null;
|
|
|
|
try {
|
|
String query = getQuery(sFrDate, sToDate, sRptGroup, sRptType, cbCompStatus,mode);
|
|
stmt3 = con.prepareStatement(query);
|
|
|
|
// Set parameters
|
|
int parameterIndex = 1;
|
|
stmt3.setString(parameterIndex++, sFrDate);
|
|
stmt3.setString(parameterIndex++, sToDate);
|
|
|
|
if (sRptGroup != null && !sRptGroup.equals("0")) {
|
|
stmt3.setString(parameterIndex++, sRptGroup);
|
|
}
|
|
|
|
if (sRptType != null && !sRptType.equals("0")) {
|
|
stmt3.setString(parameterIndex++, sRptType);
|
|
}
|
|
|
|
if (cbCompStatus != null && !cbCompStatus.equals("0")) {
|
|
// No need to set a parameter for the status condition
|
|
}
|
|
if (mode != null && !mode.equals("0")) {
|
|
stmt3.setString(parameterIndex++, mode);
|
|
}
|
|
|
|
ResultSet rs3 = stmt3.executeQuery();
|
|
|
|
List<Map<String, Object>> rows = new ArrayList<>();
|
|
|
|
while (rs3.next()) {
|
|
Map<String, Object> row = new HashMap<>();
|
|
ResultSetMetaData metaData = rs3.getMetaData();
|
|
int columnCount = metaData.getColumnCount();
|
|
for (int i = 1; i <= columnCount; i++) {
|
|
String columnName = metaData.getColumnName(i);
|
|
Object columnValue = rs3.getObject(i);
|
|
row.put(columnName, columnValue);
|
|
}
|
|
rows.add(row);
|
|
}
|
|
|
|
return rows;
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
} finally {
|
|
try {
|
|
if (stmt3 != null) {
|
|
stmt3.close();
|
|
}
|
|
con.close();
|
|
} catch (SQLException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
}
|
|
|