|
|
|
@ -100,15 +100,11 @@ public class RequestService { |
|
|
|
// Get generated primary key |
|
|
|
int userReqId = keyHolder.getKey().intValue(); |
|
|
|
|
|
|
|
// ================================================ |
|
|
|
// 🔥 Generate REF ID = yyyyMMdd + userReqId |
|
|
|
// ================================================ |
|
|
|
// Generate REF ID = yyyyMMdd + userReqId |
|
|
|
String prefix = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); |
|
|
|
String refId = prefix + userReqId; |
|
|
|
|
|
|
|
// ================================================ |
|
|
|
// 🔥 Update user_request_details with refId |
|
|
|
// ================================================ |
|
|
|
// Update user_request_details with refId |
|
|
|
String updateRefSql = "UPDATE user_request_details SET refid = ? WHERE id = ?"; |
|
|
|
mysqlJdbcTemplate.update(updateRefSql, refId, userReqId); |
|
|
|
|
|
|
|
@ -137,7 +133,7 @@ public class RequestService { |
|
|
|
s.get("durationDays"), |
|
|
|
s.get("ratePerPole"), |
|
|
|
userReqId, |
|
|
|
refId // 🔥 Insert same REF ID into street_details |
|
|
|
refId // Insert same REF ID into street_details |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
@ -151,7 +147,7 @@ public class RequestService { |
|
|
|
List<Map<String, Object>> streets, |
|
|
|
MultiValueMap<String, String> params) { |
|
|
|
|
|
|
|
// 1️⃣ Insert TEMP booking (without refid) |
|
|
|
// Insert TEMP booking (without refid) |
|
|
|
KeyHolder keyHolder = new GeneratedKeyHolder(); |
|
|
|
|
|
|
|
mysqlJdbcTemplate.update(con -> { |
|
|
|
@ -767,7 +763,7 @@ public class RequestService { |
|
|
|
|
|
|
|
List<Map<String, Object>> list = mysqlJdbcTemplate.queryForList(sql, refId, type); |
|
|
|
|
|
|
|
// ✅ Return null safely instead of throwing exception |
|
|
|
// Return null safely instead of throwing exception |
|
|
|
return list.isEmpty() ? null : list.get(0); |
|
|
|
} |
|
|
|
|
|
|
|
@ -1046,7 +1042,7 @@ public class RequestService { |
|
|
|
// urd.refid, |
|
|
|
// urd.payment_status, |
|
|
|
// urd.booking_status, |
|
|
|
// urd.cdate, -- ✅ ADD THIS |
|
|
|
// urd.cdate, |
|
|
|
// sd.street_name, |
|
|
|
// sd.zone, |
|
|
|
// sd.ward, |
|
|
|
@ -1076,13 +1072,13 @@ public class RequestService { |
|
|
|
// params.add(mobileNumber); |
|
|
|
// } |
|
|
|
|
|
|
|
// // ✅ LATEST RECORDS FIRST |
|
|
|
// // LATEST RECORDS FIRST |
|
|
|
// sql.append(" ORDER BY urd.cdate DESC, sd.id "); |
|
|
|
|
|
|
|
// List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql.toString(), |
|
|
|
// params.toArray()); |
|
|
|
|
|
|
|
// // 🔥 GROUP BY REFID (NO CHANGE) |
|
|
|
// // GROUP BY REFID (NO CHANGE) |
|
|
|
// Map<String, Map<String, Object>> resultMap = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
// for (Map<String, Object> row : rows) { |
|
|
|
@ -1102,9 +1098,9 @@ public class RequestService { |
|
|
|
// map.put("no_of_days", row.get("no_of_days")); |
|
|
|
// map.put("event_name", row.get("event_name")); |
|
|
|
// map.put("total_cost", row.get("total_cost")); |
|
|
|
// map.put("payment_status", row.get("payment_status")); // ✅ |
|
|
|
// map.put("booking_status", row.get("booking_status")); // ✅ |
|
|
|
// map.put("cdate", row.get("cdate")); // ✅ |
|
|
|
// map.put("payment_status", row.get("payment_status")); // |
|
|
|
// map.put("booking_status", row.get("booking_status")); // |
|
|
|
// map.put("cdate", row.get("cdate")); // |
|
|
|
// map.put("streets", new ArrayList<>()); |
|
|
|
// return map; |
|
|
|
// }); |
|
|
|
@ -1183,7 +1179,7 @@ public class RequestService { |
|
|
|
|
|
|
|
// List<Object> params = new ArrayList<>(); |
|
|
|
|
|
|
|
// // 🔹 Search priority: RefId first, else Mobile |
|
|
|
// // Search priority: RefId first, else Mobile |
|
|
|
// if (refId != null && !refId.trim().isEmpty()) { |
|
|
|
// sql.append(" AND urd.refid = ? "); |
|
|
|
// params.add(refId.trim()); |
|
|
|
@ -1198,7 +1194,7 @@ public class RequestService { |
|
|
|
// List<Map<String, Object>> rows = |
|
|
|
// mysqlJdbcTemplate.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) { |
|
|
|
@ -1339,7 +1335,7 @@ public class RequestService { |
|
|
|
|
|
|
|
List<Object> params = new ArrayList<>(); |
|
|
|
|
|
|
|
// 🔹 Search priority: RefId first, else Mobile |
|
|
|
// Search priority: RefId first, else Mobile |
|
|
|
if (refId != null && !refId.trim().isEmpty()) { |
|
|
|
sql.append(" AND urd.refid = ? "); |
|
|
|
params.add(refId.trim()); |
|
|
|
@ -1353,7 +1349,7 @@ public class RequestService { |
|
|
|
|
|
|
|
List<Map<String, Object>> rows = mysqlJdbcTemplate.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) { |
|
|
|
@ -1369,10 +1365,10 @@ public class RequestService { |
|
|
|
map.put("event_date", row.get("event_date")); |
|
|
|
map.put("ae_status", row.get("ae_status")); |
|
|
|
map.put("rdo_status", row.get("rdo_status")); |
|
|
|
map.put("final_status", row.get("final_status")); // ✅ NEW |
|
|
|
map.put("final_remarks", row.get("final_remarks")); // ✅ NEW |
|
|
|
map.put("final_approved_by", row.get("final_approved_by")); // ✅ OPTIONAL |
|
|
|
map.put("final_approved_date", row.get("final_approved_date")); // ✅ OPTIONAL |
|
|
|
map.put("final_status", row.get("final_status")); // |
|
|
|
map.put("final_remarks", row.get("final_remarks")); // |
|
|
|
map.put("final_approved_by", row.get("final_approved_by")); |
|
|
|
map.put("final_approved_date", row.get("final_approved_date")); |
|
|
|
map.put("rdo_remarks", row.get("rdo_remarks")); |
|
|
|
map.put("approved_by", row.get("approved_by")); |
|
|
|
map.put("approved_date", row.get("approved_date")); |
|
|
|
@ -1382,11 +1378,11 @@ public class RequestService { |
|
|
|
map.put("payment_status", row.get("payment_status")); |
|
|
|
map.put("booking_status", row.get("booking_status")); |
|
|
|
map.put("application_type", row.get("application_type")); |
|
|
|
map.put("application_type_name", row.get("application_type_name")); // ✅ NEW |
|
|
|
map.put("application_type_name", row.get("application_type_name")); |
|
|
|
map.put("application_option", row.get("application_option")); |
|
|
|
map.put("application_option_name", row.get("application_option_name")); // ✅ NEW |
|
|
|
map.put("application_option_name", row.get("application_option_name")); |
|
|
|
map.put("installation_type", row.get("installation_type")); |
|
|
|
map.put("installation_name", row.get("installation_name")); // ✅ NEW |
|
|
|
map.put("installation_name", row.get("installation_name")); |
|
|
|
map.put("aadhaar_no", row.get("aadhaar_no")); |
|
|
|
map.put("survey_no", row.get("survey_no")); |
|
|
|
map.put("place_of_erection", row.get("place_of_erection")); |
|
|
|
@ -1402,10 +1398,10 @@ public class RequestService { |
|
|
|
street.put("ward", row.get("ward")); |
|
|
|
street.put("no_of_poles", row.get("no_of_poles")); |
|
|
|
street.put("street_cost", row.get("street_cost")); |
|
|
|
street.put("pole_material_name", row.get("pole_material_name")); // ✅ NEW |
|
|
|
street.put("flag_material_name", row.get("flag_material_name")); // ✅ NEW |
|
|
|
street.put("statue_material_type", row.get("statue_material_type")); // ✅ NEW |
|
|
|
street.put("statue_pedestal_type", row.get("statue_pedestal_type")); // ✅ NEW |
|
|
|
street.put("pole_material_name", row.get("pole_material_name")); |
|
|
|
street.put("flag_material_name", row.get("flag_material_name")); |
|
|
|
street.put("statue_material_type", row.get("statue_material_type")); |
|
|
|
street.put("statue_pedestal_type", row.get("statue_pedestal_type")); |
|
|
|
|
|
|
|
((List<Map<String, Object>>) request.get("streets")).add(street); |
|
|
|
} |
|
|
|
@ -1560,14 +1556,14 @@ public class RequestService { |
|
|
|
WHERE refid = ? |
|
|
|
""", refId); |
|
|
|
|
|
|
|
// ✅ CORRECT CAST |
|
|
|
// CORRECT CAST |
|
|
|
LocalDateTime eventDate = (LocalDateTime) record.get("event_date"); |
|
|
|
|
|
|
|
if (LocalDateTime.now().isAfter(eventDate.minusHours(24))) { |
|
|
|
return "NOT_ALLOWED"; |
|
|
|
} |
|
|
|
|
|
|
|
// 🔥 INSERT HISTORY BEFORE UPDATE |
|
|
|
// INSERT HISTORY BEFORE UPDATE |
|
|
|
// insertIntoHistory(refId, "CANCELLED"); |
|
|
|
|
|
|
|
insertIntoHistoryAfterAction( |
|
|
|
@ -1641,37 +1637,37 @@ public class RequestService { |
|
|
|
// WHERE refid = ? |
|
|
|
// """, refId); |
|
|
|
|
|
|
|
// // ✅ CORRECT CAST |
|
|
|
// // CORRECT CAST |
|
|
|
// LocalDateTime oldEventDate = (LocalDateTime) record.get("event_date"); |
|
|
|
|
|
|
|
// int noOfDays = ((Number) record.get("no_of_days")).intValue(); |
|
|
|
|
|
|
|
// // ⏰ 24-hour rule |
|
|
|
// // 24-hour rule |
|
|
|
// if (LocalDateTime.now().isAfter(oldEventDate.minusHours(24))) { |
|
|
|
// return "NOT_ALLOWED"; |
|
|
|
// } |
|
|
|
|
|
|
|
// // 📅 calculate full new date range |
|
|
|
// // calculate full new date range |
|
|
|
// List<LocalDate> newDateRange = getEventDateRange(newStartDate, noOfDays); |
|
|
|
|
|
|
|
// // 🚧 get all streets for this request |
|
|
|
// // get all streets for this request |
|
|
|
// List<String> streets = jdbcTemplate.queryForList(""" |
|
|
|
// SELECT street_name |
|
|
|
// FROM street_details |
|
|
|
// WHERE refid = ? |
|
|
|
// """, String.class, refId); |
|
|
|
|
|
|
|
// // 🚫 check availability |
|
|
|
// // check availability |
|
|
|
// for (String street : streets) { |
|
|
|
// if (!isStreetAvailableForRange(street, newDateRange, refId)) { |
|
|
|
// return "STREET_NOT_AVAILABLE"; |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
// // 🔥 INSERT HISTORY BEFORE UPDATE |
|
|
|
// // INSERT HISTORY BEFORE UPDATE |
|
|
|
// insertIntoHistory(refId, "POSTPONED"); |
|
|
|
|
|
|
|
// // ✅ update event date |
|
|
|
// // update event date |
|
|
|
// jdbcTemplate.update(""" |
|
|
|
// UPDATE user_request_details |
|
|
|
// SET event_date = ?, |
|
|
|
@ -1695,7 +1691,7 @@ public class RequestService { |
|
|
|
// LocalDateTime oldEventDate = (LocalDateTime) record.get("event_date"); |
|
|
|
// int noOfDays = ((Number) record.get("no_of_days")).intValue(); |
|
|
|
|
|
|
|
// // ⏰ 24-hour rule |
|
|
|
// // 24-hour rule |
|
|
|
// if (LocalDateTime.now().isAfter(oldEventDate.minusHours(24))) { |
|
|
|
// return "NOT_ALLOWED"; |
|
|
|
// } |
|
|
|
@ -1714,7 +1710,7 @@ public class RequestService { |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
// // 🔥 Save old state into history |
|
|
|
// // Save old state into history |
|
|
|
// // insertIntoHistory(refId, "POSTPONED"); |
|
|
|
// insertIntoHistoryAfterAction( |
|
|
|
// refId, |
|
|
|
|