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.
197 lines
7.7 KiB
197 lines
7.7 KiB
package in.gov.chennaicorporation.gccoffice.pgr.service;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
import java.sql.ResultSetMetaData;
|
|
import java.sql.SQLException;
|
|
import java.sql.Statement;
|
|
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.Dtoworeopen;
|
|
|
|
@Service
|
|
public class ReopenZoneWiseDaskboards {
|
|
|
|
@Autowired
|
|
DBConnection dbcon;
|
|
|
|
public String sFrDate ="";
|
|
public String sToDate ="";
|
|
public List<Dtoworeopen> getAlldtozwreopen() {
|
|
List<Dtoworeopen> complaintdept = new ArrayList<>();
|
|
Connection con = DBConnection.getConnection();
|
|
Statement stmt = null;
|
|
ResultSet rs = null;
|
|
|
|
try {
|
|
stmt = con.createStatement();
|
|
rs = stmt.executeQuery(getdtozwreopenQuery());
|
|
|
|
while (rs.next()) {
|
|
Dtoworeopen dtozwreopen = new Dtoworeopen();
|
|
dtozwreopen.setId(rs.getString("id_dept"));
|
|
dtozwreopen.setName(rs.getString("dept_name"));
|
|
complaintdept.add(dtozwreopen);
|
|
}
|
|
|
|
return complaintdept;
|
|
} 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 getdtozwreopenQuery() {
|
|
return "SELECT id_dept, dept_name "
|
|
+ "FROM EG_DEPARTMENT@ERP "
|
|
+ "WHERE NVL(dept_name, '0') NOT LIKE 'F%' AND dept_name IS NOT NULL AND id_dept >= 32 "
|
|
+ "ORDER BY id_dept";
|
|
}
|
|
|
|
public String getReopenZonewisedaskboardQuery(String DEPTID) {
|
|
String sQry = "SELECT * FROM (SELECT a.deptid, " +
|
|
"nvl(sum(case when complainttype in (52,146) then 1 end),0) as \"NonBURSTLT\", " +
|
|
"nvl(sum(case when complainttype in (1,97) then 1 end),0) as \"REOFGAR\", " +
|
|
"nvl(sum(case when complainttype in (22,32,57,59,70,113,114,130,145) then 1 end),0) as \"ROAD\", " +
|
|
"nvl(sum(case when complainttype in (18,118) then 1 end),0) as \"MOSQUITE\", " +
|
|
"nvl(sum(case when complainttype in (69,138) then 1 end),0) as \"WATER\", " +
|
|
"nvl(sum(case when complainttype in (7,99) then 1 end),0) as \"REOFDEB\", " +
|
|
"nvl(sum(case when complainttype in (71,152) then 1 end),0) as \"TREE\", " +
|
|
"nvl(sum(case when complainttype in (19,119) then 1 end),0) as \"DOGS\", " +
|
|
"nvl(sum(case when complainttype in (75,181) then 1 end),0) as \"ENCMTN\", " +
|
|
"nvl(sum(case when complainttype in (58,112) then 1 end),0) as \"POT\", " +
|
|
"nvl(sum(case when complainttype in (43,166) then 1 end),0) as \"PTAX\", " +
|
|
"nvl(sum(case when 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) then 1 end),0) as \"OTHERS\", " +
|
|
"COUNT(*) as Total FROM eggr_complaintdetails@erp a, eggr_redressaldetails@erp b WHERE ";
|
|
|
|
int iRptID = 0;
|
|
if (iRptID == 1) {
|
|
sQry += "nvl(RECEIVINGCENTERID,0) = 1 AND ";
|
|
} else if (iRptID == 2) {
|
|
sQry += "nvl(RECEIVINGCENTERID,0) != 1 AND ";
|
|
}
|
|
|
|
if (!sFrDate.equals("")) {
|
|
if (sToDate == null || sToDate.equals("")) {
|
|
sToDate = sFrDate;
|
|
}
|
|
sQry += "trunc(complaintdate) BETWEEN to_date('" + sFrDate + "','dd/mm/yyyy') AND to_date('" + sToDate + "','dd/mm/yyyy') AND ";
|
|
}
|
|
|
|
sQry += "a.complaintid = b.complaintid AND b.COMPLAINTSTATUSID IN (2,3,4) AND TRUNC(COMPLAINTDATE) >= trunc(sysdate-730) " +
|
|
"AND a.deptid = " + DEPTID + // Add condition for specific DEPTID
|
|
" GROUP BY a.deptid) a INNER JOIN EG_DEPARTMENT@ERP c ON a.deptid = c.id_dept " +
|
|
"LEFT OUTER JOIN (SELECT a.deptid, " +
|
|
"nvl(sum(case when sysdate-complaintdate>90 and b.COMPLAINTSTATUSID IN(2,3,4) then 1 end),'0') as days_90_pen, " +
|
|
"nvl(sum(case when sysdate-complaintdate>60 and sysdate-complaintdate<=90 and b.COMPLAINTSTATUSID IN(2,3,4) then 1 end),'0') as days_61_90_pen, " +
|
|
"nvl(sum(case when sysdate-complaintdate>30 and sysdate-complaintdate<=60 and b.COMPLAINTSTATUSID IN(2,3,4) then 1 end),'0') as days_31_60_pen, " +
|
|
"nvl(sum(case when sysdate-complaintdate>15 and sysdate-complaintdate<=30 and b.COMPLAINTSTATUSID IN(2,3,4) then 1 end),'0') as days_16_30_pen, " +
|
|
"nvl(sum(case when sysdate-complaintdate<=15 and b.COMPLAINTSTATUSID IN(2,3,4) then 1 end),'0') as days_0_15_pen, " +
|
|
"nvl(count(case when b.COMPLAINTSTATUSID IN(2,3,4) then 1 end),'0') as Total_pen " +
|
|
"FROM eggr_complaintdetails@erp a, eggr_redressaldetails@erp b " +
|
|
"WHERE a.complaintid = b.complaintid AND TRUNC(COMPLAINTDATE) >= trunc(sysdate-730) ";
|
|
|
|
if (iRptID == 1) {
|
|
sQry += "AND nvl(RECEIVINGCENTERID,0) = 1 ";
|
|
} else if (iRptID == 2) {
|
|
sQry += "AND nvl(RECEIVINGCENTERID,0) != 1 ";
|
|
}
|
|
|
|
if (!sFrDate.equals("")) {
|
|
if (sToDate == null || sToDate.equals("")) {
|
|
sToDate = sFrDate;
|
|
}
|
|
sQry += "AND trunc(complaintdate) BETWEEN to_date('" + sFrDate + "','dd/mm/yyyy') AND to_date('" + sToDate + "','dd/mm/yyyy') ";
|
|
}
|
|
|
|
if (DEPTID != null && !DEPTID.equals("0")) {
|
|
sQry += "AND EXISTS (SELECT 1 FROM EG_DEPARTMENT@ERP c WHERE a.deptid = c.id_dept " +
|
|
"AND (NVL(c.id_dept, 0) NOT LIKE 'F%' AND c.id_dept IS NOT NULL) " +
|
|
"AND c.id_dept = " + DEPTID + ") ";
|
|
}
|
|
|
|
sQry += "GROUP BY a.deptid) d ON d.deptid = c.id_dept " +
|
|
"WHERE (NVL(DEPT_NAME,0) NOT LIKE 'F%' AND DEPT_NAME IS NOT NULL) " +
|
|
"AND a.deptid >= 32 " +
|
|
"ORDER BY a.deptid";
|
|
|
|
System.out.println("PGR sQry : " + sQry);
|
|
return sQry;
|
|
}
|
|
|
|
|
|
public List<Map<String, Object>> getReopenZonewisedashboardquery(String DEPTID) {
|
|
Connection con = DBConnection.getConnection();
|
|
|
|
try {
|
|
String query = getReopenZonewisedaskboardQuery(DEPTID);
|
|
|
|
PreparedStatement pstmt = con.prepareStatement(query);
|
|
|
|
if (query.contains(":deptID") && DEPTID != null && !DEPTID.equals("0")) {
|
|
pstmt.setString(1, DEPTID);
|
|
}
|
|
|
|
System.out.println("Checking ReOpen Zonewise Dashboard...");
|
|
System.out.println("sQry : " + pstmt.toString()); // Check the generated SQL query
|
|
|
|
ResultSet rs = pstmt.executeQuery();
|
|
|
|
List<Map<String, Object>> rows = new ArrayList<>();
|
|
|
|
while (rs.next()) {
|
|
Map<String, Object> row = new HashMap<>();
|
|
|
|
ResultSetMetaData metaData = rs.getMetaData();
|
|
int columnCount = metaData.getColumnCount();
|
|
|
|
for (int i = 1; i <= columnCount; i++) {
|
|
String columnName = metaData.getColumnName(i);
|
|
Object columnValue = rs.getObject(i);
|
|
//System.out.println(columnName + " : " + columnValue);
|
|
row.put(columnName, columnValue);
|
|
}
|
|
|
|
rows.add(row);
|
|
}
|
|
|
|
return rows;
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
} finally {
|
|
try {
|
|
con.close();
|
|
} catch (SQLException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|