Browse Source

Added uploaded files in update screen of road war register

master
Hariprasath S 5 days ago
parent
commit
e2b80a058d
  1. 14
      src/main/java/in/gov/chennaicorporation/gccoffice/configuration/DataSourceConfig.java
  2. 10
      src/main/java/in/gov/chennaicorporation/gccoffice/roadwar/controller/RegisterApiController.java
  3. 63
      src/main/java/in/gov/chennaicorporation/gccoffice/roadwar/service/RegisterService.java
  4. 4
      src/main/resources/application-local.properties
  5. 227
      src/main/resources/templates/modules/roadwar/updateform.html

14
src/main/java/in/gov/chennaicorporation/gccoffice/configuration/DataSourceConfig.java

@ -408,7 +408,7 @@ public class DataSourceConfig {
return dataSource; return dataSource;
} }
/////////////// Road War /////////////////////
/////////////// Road War Web /////////////////////
@Bean(name = "mysqlRoadWarDataSource") @Bean(name = "mysqlRoadWarDataSource")
public DataSource mysqlRoadWarDataSource() { public DataSource mysqlRoadWarDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource(); DriverManagerDataSource dataSource = new DriverManagerDataSource();
@ -419,6 +419,18 @@ public class DataSourceConfig {
return dataSource; return dataSource;
} }
/////////////// Road War Mobile Service /////////////////////
@Bean(name = "mysqlGccRoadWarSource")
public DataSource mysqlGccRoadWarSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://" + host + "/gcc_roadwar");
dataSource.setUsername("root");
dataSource.setPassword(dbpassword);
return dataSource;
}
// homeles // homeles
@Bean(name = "mysqlHomelessSurveyDataSource") @Bean(name = "mysqlHomelessSurveyDataSource")
public DataSource mysqlHomelessSurveyDataSource() { public DataSource mysqlHomelessSurveyDataSource() {

10
src/main/java/in/gov/chennaicorporation/gccoffice/roadwar/controller/RegisterApiController.java

@ -216,13 +216,11 @@ public class RegisterApiController {
@GetMapping("/getRoadWarDetailsById") @GetMapping("/getRoadWarDetailsById")
public ResponseEntity<?> getRoadWarDetailsById(
@RequestParam String refid) {
public ResponseEntity<?> getRoadWarDetailsById(@RequestParam String refid) {
try { try {
Map<String, Object> response =
registerService.getRoadWarDetailsById(refid);
Map<String, Object> response = registerService.getRoadWarDetailsById(refid);
return ResponseEntity.ok(response); return ResponseEntity.ok(response);
@ -232,9 +230,7 @@ public class RegisterApiController {
error.put("status", false); error.put("status", false);
error.put("message", "Failed to fetch data : " + e.getMessage()); error.put("message", "Failed to fetch data : " + e.getMessage());
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(error);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error);
} }
} }

63
src/main/java/in/gov/chennaicorporation/gccoffice/roadwar/service/RegisterService.java

@ -17,6 +17,7 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCreator; import org.springframework.jdbc.core.PreparedStatementCreator;
@ -35,14 +36,34 @@ public class RegisterService {
@Autowired @Autowired
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
@Autowired
@Value("${fileBaseUrl}")
private String fileBaseUrl;
@Autowired @Autowired
private Environment environment; private Environment environment;
@Autowired
private JdbcTemplate roadwarjdbcTemplate;
@Autowired @Autowired
public void setDataSource(@Qualifier("mysqlRoadWarDataSource") DataSource dataSource) { public void setDataSource(@Qualifier("mysqlRoadWarDataSource") DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource); this.jdbcTemplate = new JdbcTemplate(dataSource);
} }
@Autowired
public void setDataSource2(@Qualifier("mysqlGccRoadWarSource") DataSource DataSource) {
this.roadwarjdbcTemplate = new JdbcTemplate(DataSource);
}
public RegisterService(Environment environment) {
this.environment = environment;
this.fileBaseUrl = environment.getProperty("fileBaseUrl");
}
public List<Map<String, Object>> ViewZoneDropdown() { public List<Map<String, Object>> ViewZoneDropdown() {
String sql = "SELECT zone_name " String sql = "SELECT zone_name "
+ "FROM zone_master " + "FROM zone_master "
@ -397,6 +418,48 @@ public class RegisterService {
refid); refid);
result.put("relayingDetails", relayingDetails); result.put("relayingDetails", relayingDetails);
List<Map<String, Object>> fileDetails =jdbcTemplate.queryForList(
"SELECT *, CONCAT('" + fileBaseUrl + "/gccofficialapp/files',file_path) as file_url "
+" FROM road_master_files "
+ " WHERE road_ref_id = ? AND is_active=1 AND is_delete=0 ",
refid);
for (Map<String, Object> row : fileDetails) {
for (Map.Entry<String, Object> entry : row.entrySet()) {
if (entry.getValue() == null) {
entry.setValue("");
}
}
}
result.put("fileDetails", fileDetails);
String roadId = String.valueOf(road.get("road_id"));
List<Map<String,Object>> inspectiondetails=roadwarjdbcTemplate.queryForList(
"select ssd.road_id,ssd.start_latitude,ssd.start_longitude, CONCAT('" + fileBaseUrl + "/gccofficialapp/files',ssd.start_img) as start_img, "
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files',csd.centre_img) as centre_img, "
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files',esd.end_img) as end_img "
+ "from start_street_details ssd "
+ "left join centre_street_details csd on ssd.road_id = csd.road_id "
+ "left join end_street_details esd on ssd.road_id = esd.road_id "
+ "where ssd.road_id = ? and ssd.isactive = 1 and ssd.isdelete = 0 limit 1 ",
roadId
);
for (Map<String, Object> row : inspectiondetails) {
for (Map.Entry<String, Object> entry : row.entrySet()) {
if (entry.getValue() == null) {
entry.setValue("");
}
}
}
result.put("inspectiondetails", inspectiondetails);
result.put("status", true); result.put("status", true);
} catch (Exception e) { } catch (Exception e) {

4
src/main/resources/application-local.properties

@ -1,4 +1,4 @@
assets.base-url=/assets/ assets.base-url=/assets/
fileBaseUrl=http://localhost:8064
fileBaseUrl=https://gccservices.in
#fileBaseUrl=http://localhost:8064

227
src/main/resources/templates/modules/roadwar/updateform.html

@ -20,6 +20,27 @@
overflow-y: auto; overflow-y: auto;
/* Enable vertical scrolling */ /* Enable vertical scrolling */
} }
.pdf-file-box{
height:60px;
display:flex;
align-items:center;
justify-content:center;
border:1px solid #ced4da;
border-radius:5px;
background:#f8f9fa;
color:#495057;
font-weight:bold;
cursor:pointer;
transition:all .3s ease;
}
.pdf-file-box:hover{
background:#007bff;
color:#fff;
border-color:#007bff;
transform:scale(1.03);
box-shadow:0 4px 10px rgba(0,0,0,.2);
}
</style> </style>
<body> <body>
@ -181,6 +202,11 @@
</div> </div>
<!-- modal body --> <!-- modal body -->
<div class="modal fade" id="roadWarModal" tabindex="-1" role="dialog" aria-labelledby="roadWarModalLabel" <div class="modal fade" id="roadWarModal" tabindex="-1" role="dialog" aria-labelledby="roadWarModalLabel"
@ -857,6 +883,41 @@
</button> </button>
</div> </div>
<div id="viewFileContainer" class="mt-4"></div>
<div id="InspectionFileContainer" class="mt-4"></div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="imagePreviewModal" tabindex="-1" role="dialog" aria-labelledby="imagePreviewModalLabel"
aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-xl modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">File Preview</h5>
<button type="button" class="close" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<div class="modal-body text-center">
<img id="previewImage"
class="img-fluid rounded"
style="max-height:80vh; display:none;">
<iframe id="previewPdf"
style="width:100%;height:80vh;border:none;display:none;">
</iframe>
</div> </div>
</div> </div>
@ -2608,8 +2669,64 @@
}); });
} }
let fileContainer = $("#viewFileContainer");
fileContainer.empty();
if (response.fileDetails && response.fileDetails.length > 0) {
let html = `
<h5 class="mt-4">Uploaded Files</h5>
<div class="row">
`;
$.each(response.fileDetails, function(index, file) {
let url = file.file_url;
let extension = url.split('.').pop().toLowerCase();
if (extension === "pdf") {
html += `
<div class="col-md-2 col-4 mb-3 text-center">
<div class="pdf-file-box" onclick="showPreview('${url}')">
PDF File ${index + 1}
</div>
</div>
`;
} else {
html += `
<div class="col-md-2 col-4 mb-3 text-center">
<img src="${url}"
class="img-thumbnail"
style="height:120px;width:100%;object-fit:cover;cursor:pointer;"
onclick="showPreview('${url}')">
</div>
`;
}
});
html += "</div>";
fileContainer.html(html);
}
renderInspectionDetails(response.inspectiondetails);
$('#titleModalLabel').text(`Road War Details - ${response.ref_id}`); $('#titleModalLabel').text(`Road War Details - ${response.ref_id}`);
$("#roadWarModal").modal("show"); $("#roadWarModal").modal("show");
}, },
@ -2627,6 +2744,116 @@
}); });
} }
function renderInspectionDetails(data) {
let container = $("#InspectionFileContainer");
container.empty();
if (data && data.length > 0) {
let inspection = data[0];
let html = `
<h5 class="mt-4 mb-3">Street Images</h5>
<div class="row">
`;
let url = inspection.start_img;
// Get latitude and longitude
let latitude = inspection.start_latitude;
let longitude = inspection.start_longitude;
// Google Maps Embed URL
let mapUrl = '';
if (latitude && longitude) {
mapUrl =
"https://maps.google.com/maps?q=" +
latitude + "," + longitude +
"&z=18&output=embed";
}
if (url) {
let extension = url.split('?')[0].split('.').pop().toLowerCase();
if (extension === "pdf") {
html += `
<div class="col-md-2 col-4 mb-3 text-center">
<div class="pdf-file-box"
onclick="showPreview('${url}')">
PDF File
</div>
</div>
`;
} else {
html += `
<div class="col-md-4 col-4 mb-3 text-center">
<img src="${url}"
class="img-thumbnail"
style="height:200px;width:100%;object-fit:cover;cursor:pointer;"
onclick="showPreview('${url}')">
</div>
`;
}
}
if (mapUrl) {
html += `
<div class="col-md-4 col-12 mb-3">
<iframe
src="${mapUrl}"
width="100%"
height="200"
style="border:0;"
allowfullscreen=""
loading="lazy"
referrerpolicy="no-referrer-when-downgrade">
</iframe>
</div>
`;
}
html += `</div>`;
container.html(html);
}
}
function showPreview(fileUrl) {
let extension = fileUrl.split('.').pop().toLowerCase();
if (extension === "pdf") {
$("#previewImage").hide();
$("#previewPdf").show();
$("#previewPdf").attr("src", fileUrl);
} else {
$("#previewPdf").hide();
$("#previewImage").show();
$("#previewImage").attr("src", fileUrl);
}
$("#imagePreviewModal").modal("show");
}
$(document).on('click', '.removeRelayRow', function () { $(document).on('click', '.removeRelayRow', function () {
let totalRows = $('.relay-block').length; let totalRows = $('.relay-block').length;

Loading…
Cancel
Save