|
|
|
@ -126,19 +126,19 @@ public class RdoService { |
|
|
|
String refid, |
|
|
|
String gccUserId) { |
|
|
|
|
|
|
|
/* 🔥 Resolve appuser_id from gccuserid (gcc_apps) */ |
|
|
|
/* Resolve appuser_id from gccuserid (gcc_apps) */ |
|
|
|
Long appUserId = getAppUserIdByGccUserId(gccUserId); |
|
|
|
if (appUserId == null) { |
|
|
|
throw new RuntimeException("Invalid gccUserId: " + gccUserId); |
|
|
|
} |
|
|
|
|
|
|
|
/* 🔥 Resolve department id (gcc_flag_pole) */ |
|
|
|
/* Resolve department id (gcc_flag_pole) */ |
|
|
|
Integer deptId = getDepartmentIdByUserId(gccUserId); |
|
|
|
|
|
|
|
/* 🔥 Resolve access (gcc_apps) */ |
|
|
|
/* Resolve access (gcc_apps) */ |
|
|
|
List<Map<String, Object>> access = getUserAccess(appUserId); |
|
|
|
|
|
|
|
/* 🔥 Resolve officer details (for DRO check) */ |
|
|
|
/* Resolve officer details (for DRO check) */ |
|
|
|
Map<String, Object> officerDetails = getOfficerDetailsByUserId(gccUserId); |
|
|
|
Integer droMember = (officerDetails != null) ? (Integer) officerDetails.get("dro_member") : null; |
|
|
|
boolean isDro = (droMember != null && droMember == 1); |
|
|
|
@ -170,12 +170,12 @@ public class RdoService { |
|
|
|
// wardArray = row.get("wardarray") != null ? row.get("wardarray").toString() : |
|
|
|
// null; |
|
|
|
|
|
|
|
/* ✅ RDO → zonearray + wardarray */ |
|
|
|
/* RDO → zonearray + wardarray */ |
|
|
|
// if (hasValue(zoneArray) && hasValue(wardArray)) { |
|
|
|
// isRdo = true; |
|
|
|
// } |
|
|
|
|
|
|
|
/* ✅ Zonal Officer → zone 01–15 */ |
|
|
|
/* Zonal Officer → zone 01–15 */ |
|
|
|
if (hasValue(zone) && zone.matches("^(0[1-9]|1[0-5])$")) { |
|
|
|
isZonalOfficer = true; |
|
|
|
} |
|
|
|
@ -201,7 +201,7 @@ public class RdoService { |
|
|
|
params.add(refid); |
|
|
|
|
|
|
|
/* |
|
|
|
* 🔥 Only NON-RDO & NON-ZONAL & NON-DRO & NON-Zlsc & NON-DLC & |
|
|
|
* Only NON-RDO & NON-ZONAL & NON-DRO & NON-Zlsc & NON-DLC & |
|
|
|
* NON-FINAL-AUTH-PERM are |
|
|
|
* restricted |
|
|
|
*/ |
|
|
|
@ -264,7 +264,7 @@ public class RdoService { |
|
|
|
return mysqlAppJdbcTemplate.queryForList(sql, appUserId); |
|
|
|
} |
|
|
|
|
|
|
|
/* 🔥 Fetch all Zonal Officers (userids) for a given zone */ |
|
|
|
/* Fetch all Zonal Officers (userids) for a given zone */ |
|
|
|
public List<String> getZonalOfficerUserIdsByZone(String zone) { |
|
|
|
// We need 'userid' from appusers. login_mapping_user has appuser_id. |
|
|
|
// So we join login_mapping_user -> appusers |
|
|
|
@ -407,13 +407,13 @@ public class RdoService { |
|
|
|
String applicationType // 1 = TEMP, 2 = PERM, null = ALL |
|
|
|
) { |
|
|
|
|
|
|
|
/* 🔥 Resolve appuser_id */ |
|
|
|
/* Resolve appuser_id */ |
|
|
|
Long appUserId = getAppUserIdByGccUserId(gccUserId); |
|
|
|
if (appUserId == null) { |
|
|
|
throw new RuntimeException("Invalid gccUserId: " + gccUserId); |
|
|
|
} |
|
|
|
|
|
|
|
/* 🔥 Resolve department & zlsC */ |
|
|
|
/* Resolve department & zlsC */ |
|
|
|
Map<String, Object> officerDetails = getOfficerDetailsByUserId(gccUserId); |
|
|
|
if (officerDetails == null) { |
|
|
|
throw new RuntimeException("Department mapping missing for gccUserId: " + gccUserId); |
|
|
|
@ -442,7 +442,7 @@ public class RdoService { |
|
|
|
// System.out.println("DEBUG: verificationQuestions is NULL"); |
|
|
|
} |
|
|
|
|
|
|
|
/* 🔥 Resolve access */ |
|
|
|
/* Resolve access */ |
|
|
|
List<Map<String, Object>> access = getUserAccess(appUserId); |
|
|
|
|
|
|
|
String zone = null, zoneArray = null, wardArray = null; |
|
|
|
@ -531,14 +531,14 @@ public class RdoService { |
|
|
|
|
|
|
|
List<Object> params = new ArrayList<>(); |
|
|
|
|
|
|
|
/* 🔥 fileBaseUrl for all images */ |
|
|
|
/* fileBaseUrl for all images */ |
|
|
|
params.add(fileBaseUrlImages); |
|
|
|
params.add(fileBaseUrlImages); |
|
|
|
params.add(fileBaseUrlImages); |
|
|
|
params.add(fileBaseUrlImages); |
|
|
|
params.add(fileBaseUrlImages); |
|
|
|
|
|
|
|
/* 🔥 Only pending final */ |
|
|
|
/* Only pending final */ |
|
|
|
sql.append(" AND (urd.final_status IS NULL OR urd.final_status = '') "); |
|
|
|
|
|
|
|
/* Zlsc → PERMANENT only & Processed by DRO */ |
|
|
|
@ -548,7 +548,7 @@ public class RdoService { |
|
|
|
} else if (isZlscMember || isDlcMember) { |
|
|
|
sql.append(" AND urd.application_type = 2 "); |
|
|
|
|
|
|
|
/* 🔥 Must be processed by DRO first */ |
|
|
|
/* Must be processed by DRO first */ |
|
|
|
sql.append(""" |
|
|
|
AND urd.refid IN ( |
|
|
|
SELECT ofb.refid |
|
|
|
@ -562,7 +562,7 @@ public class RdoService { |
|
|
|
"""); |
|
|
|
} |
|
|
|
|
|
|
|
/* 🔥 Exclude already decided by same dept */ |
|
|
|
/* Exclude already decided by same dept */ |
|
|
|
sql.append(""" |
|
|
|
AND urd.refid NOT IN ( |
|
|
|
SELECT ofb.refid |
|
|
|
@ -575,30 +575,30 @@ public class RdoService { |
|
|
|
"""); |
|
|
|
params.add(deptId); |
|
|
|
|
|
|
|
/* 🔥 TEMP / PERM filter */ |
|
|
|
/* TEMP / PERM filter */ |
|
|
|
if (hasValue(applicationType)) { |
|
|
|
sql.append(" AND urd.application_type = ? "); |
|
|
|
params.add(applicationType); |
|
|
|
} |
|
|
|
|
|
|
|
/* 🔥 RDO */ |
|
|
|
/* RDO */ |
|
|
|
if (isRdo) { |
|
|
|
sql.append(" AND FIND_IN_SET(sd.zone, ?) AND FIND_IN_SET(sd.ward, ?) "); |
|
|
|
params.add(zoneArray); |
|
|
|
params.add(wardArray); |
|
|
|
} |
|
|
|
/* 🔥 Zonal */ |
|
|
|
/* Zonal */ |
|
|
|
else if (isZonalOfficer) { |
|
|
|
sql.append(" AND sd.zone = ? "); |
|
|
|
params.add(zone); |
|
|
|
} |
|
|
|
/* 🔥 DRO Logic */ |
|
|
|
/* DRO Logic */ |
|
|
|
else if (isDro) { |
|
|
|
|
|
|
|
/* 🔥 DRO → PERMANENT only */ |
|
|
|
/* DRO → PERMANENT only */ |
|
|
|
sql.append(" AND urd.application_type = 2 "); |
|
|
|
|
|
|
|
/* 🔥 Fetch all Zonal Officers grouped by Zone */ |
|
|
|
/* Fetch all Zonal Officers grouped by Zone */ |
|
|
|
Map<String, List<String>> zoneOfficersMap = getMapOfZonalOfficersByZone(); |
|
|
|
|
|
|
|
if (zoneOfficersMap.isEmpty()) { |
|
|
|
@ -651,14 +651,14 @@ public class RdoService { |
|
|
|
sql.append(" ) "); |
|
|
|
} |
|
|
|
|
|
|
|
/* 🔥 If DRO is mapped to a specific Zone, restrict to that zone as well */ |
|
|
|
/* If DRO is mapped to a specific Zone, restrict to that zone as well */ |
|
|
|
if (hasValue(zone)) { |
|
|
|
sql.append(" AND sd.zone = ? "); |
|
|
|
params.add(zone); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* 🔹 Date filter */ |
|
|
|
/* Date filter */ |
|
|
|
if (hasValue(startDate) && hasValue(endDate)) { |
|
|
|
sql.append(" AND DATE(urd.event_date) BETWEEN ? AND ? "); |
|
|
|
params.add(startDate); |
|
|
|
@ -677,7 +677,7 @@ public class RdoService { |
|
|
|
|
|
|
|
List<Map<String, Object>> rows = mysqlFlagPoleJdbcTemplate.queryForList(sql.toString(), params.toArray()); |
|
|
|
|
|
|
|
/* 🔥 GROUP BY REFID */ |
|
|
|
/* GROUP BY REFID */ |
|
|
|
Map<String, Map<String, Object>> resultMap = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
for (Map<String, Object> row : rows) { |
|
|
|
@ -744,7 +744,7 @@ public class RdoService { |
|
|
|
((List<Map<String, Object>>) request.get("streets")).add(street); |
|
|
|
} |
|
|
|
|
|
|
|
/* 🔥 Fetch History for all refIds */ |
|
|
|
/* Fetch History for all refIds */ |
|
|
|
if (!resultMap.isEmpty()) { |
|
|
|
String ids = resultMap.keySet().stream() |
|
|
|
.map(id -> "'" + id + "'") |
|
|
|
@ -864,23 +864,13 @@ public class RdoService { |
|
|
|
Integer applicationType = (appTypeNum != null) ? appTypeNum.intValue() : null; |
|
|
|
|
|
|
|
/* |
|
|
|
* 🔥 Resolve officer details (for Permanent Final Authority) |
|
|
|
* Resolve officer details (for Permanent Final Authority) |
|
|
|
*/ |
|
|
|
Map<String, Object> officerDetails = getOfficerDetailsByUserId(gccUserId); |
|
|
|
Integer finalAuthPerm = (officerDetails != null) ? (Integer) officerDetails.get("final_authority_permanent") |
|
|
|
: null; |
|
|
|
boolean isFinalAuthorityPermanent = (finalAuthPerm != null && finalAuthPerm == 1); |
|
|
|
|
|
|
|
/* |
|
|
|
* 🔥 ZOs act as Final Authority ONLY if configured (1) and Application Type is |
|
|
|
* TEMPORARY (1). |
|
|
|
* If PERMANENT (2): |
|
|
|
* - Normal ZOs should NOT update final_status. |
|
|
|
* - Users with 'final_authority_permanent = 1' SHOULD update final_status. |
|
|
|
* |
|
|
|
* If Application Type is unknown (null), we assume it's NOT Final Authority to |
|
|
|
* allow workflow flexibility. |
|
|
|
*/ |
|
|
|
if (applicationType != null && applicationType == 2) { |
|
|
|
if (isFinalAuthorityPermanent) { |
|
|
|
isFinalAuthority = true; |
|
|
|
@ -903,9 +893,7 @@ public class RdoService { |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
* ===================================================== |
|
|
|
* INSERT FEEDBACK (EXISTING) |
|
|
|
* ===================================================== |
|
|
|
*/ |
|
|
|
|
|
|
|
insertOfficerFeedback( |
|
|
|
@ -917,9 +905,7 @@ public class RdoService { |
|
|
|
username); |
|
|
|
|
|
|
|
/* |
|
|
|
* ===================================================== |
|
|
|
* 🔥 NEW: get fid + save verification answers |
|
|
|
* ===================================================== |
|
|
|
* NEW: get fid + save verification answers |
|
|
|
*/ |
|
|
|
|
|
|
|
Integer fid = mysqlFlagPoleJdbcTemplate.queryForObject( |
|
|
|
@ -948,9 +934,7 @@ public class RdoService { |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
* ===================================================== |
|
|
|
* FINAL AUTHORITY FLOW (UNCHANGED) |
|
|
|
* ===================================================== |
|
|
|
*/ |
|
|
|
|
|
|
|
if (isFinalAuthority) { |
|
|
|
@ -1029,9 +1013,7 @@ public class RdoService { |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
* ===================================================== |
|
|
|
* RDO FLOW (UNCHANGED) |
|
|
|
* ===================================================== |
|
|
|
*/ |
|
|
|
|
|
|
|
if (isRdo) { |
|
|
|
@ -1077,13 +1059,13 @@ public class RdoService { |
|
|
|
String endDate, |
|
|
|
String status) { |
|
|
|
|
|
|
|
/* 🔥 Resolve appuser_id */ |
|
|
|
/* Resolve appuser_id */ |
|
|
|
Long appUserId = getAppUserIdByGccUserId(gccUserId); |
|
|
|
if (appUserId == null) { |
|
|
|
throw new RuntimeException("Invalid gccUserId: " + gccUserId); |
|
|
|
} |
|
|
|
|
|
|
|
/* 🔥 Resolve department details and ZLSC status */ |
|
|
|
/* Resolve department details and ZLSC status */ |
|
|
|
Map<String, Object> officerDetails = getOfficerDetailsByUserId(gccUserId); |
|
|
|
if (officerDetails == null) { |
|
|
|
throw new RuntimeException("Department mapping missing for gccUserId: " + gccUserId); |
|
|
|
@ -1106,7 +1088,7 @@ public class RdoService { |
|
|
|
|
|
|
|
// System.out.println("verificationQuestions: " + verificationQuestions); |
|
|
|
|
|
|
|
/* 🔥 Resolve access */ |
|
|
|
/* Resolve access */ |
|
|
|
List<Map<String, Object>> access = getUserAccess(appUserId); |
|
|
|
|
|
|
|
String zone = null; |
|
|
|
@ -1193,26 +1175,26 @@ public class RdoService { |
|
|
|
List<Object> params = new ArrayList<>(); |
|
|
|
params.add(deptId); |
|
|
|
|
|
|
|
/* 🔹 Optional status */ |
|
|
|
/* Optional status */ |
|
|
|
if (hasValue(status)) { |
|
|
|
sql.append(" AND ofb.status = ? "); |
|
|
|
params.add(status); |
|
|
|
} |
|
|
|
|
|
|
|
/* 🔹 RDO → zone + ward */ |
|
|
|
/* RDO → zone + ward */ |
|
|
|
if (isRdo) { |
|
|
|
sql.append(" AND FIND_IN_SET(sd.zone, ?) "); |
|
|
|
sql.append(" AND FIND_IN_SET(sd.ward, ?) "); |
|
|
|
params.add(zoneArray); |
|
|
|
params.add(wardArray); |
|
|
|
} |
|
|
|
/* 🔹 Zonal → only zone */ |
|
|
|
/* Zonal → only zone */ |
|
|
|
else if (isZonalOfficer) { |
|
|
|
sql.append(" AND sd.zone = ? "); |
|
|
|
params.add(zone); |
|
|
|
} |
|
|
|
|
|
|
|
/* 🔹 Date */ |
|
|
|
/* Date */ |
|
|
|
if (hasValue(startDate) && hasValue(endDate)) { |
|
|
|
|
|
|
|
sql.append(" AND DATE(urd.event_date) BETWEEN ? AND ? "); |
|
|
|
@ -1229,7 +1211,7 @@ public class RdoService { |
|
|
|
|
|
|
|
List<Map<String, Object>> rows = mysqlFlagPoleJdbcTemplate.queryForList(sql.toString(), params.toArray()); |
|
|
|
|
|
|
|
/* 🔥 GROUP BY REFID */ |
|
|
|
/* GROUP BY REFID */ |
|
|
|
Map<String, Map<String, Object>> resultMap = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
for (Map<String, Object> row : rows) { |
|
|
|
@ -1261,7 +1243,7 @@ public class RdoService { |
|
|
|
map.put("installation_name", row.get("installation_name")); |
|
|
|
map.put("streets", new ArrayList<>()); |
|
|
|
|
|
|
|
// 🔥 Add verification questions for Permanent requests if user is ZLSC OR DRO |
|
|
|
// Add verification questions for Permanent requests if user is ZLSC OR DRO |
|
|
|
// member |
|
|
|
if ((isZlscMember || isDlcMember || isDro) |
|
|
|
&& "PERMANENT".equalsIgnoreCase((String) row.get("application_type_name"))) { |
|
|
|
|