71 changed files with 10350 additions and 152 deletions
-
BIN.DS_Store
-
BINmobileservice/.DS_Store
-
8mobileservice/pom.xml
-
BINmobileservice/src/.DS_Store
-
BINmobileservice/src/main/.DS_Store
-
2mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/MobileServiceApplication.java
-
64mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/buildingDemolition/controller/BuildingDemolitionController.java
-
325mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/buildingDemolition/service/BuildingDemolitionActivity.java
-
115mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/busshelters/controller/BusShelterController_renovation.java
-
879mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/busshelters/service/BusShelterRenovationActivity.java
-
18mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/c_d_waste/controller/APIC_D_WasteController.java
-
83mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/c_d_waste/service/c_d_WasteService.java
-
92mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/configuration/DataSourceConfig.java
-
177mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/constructionGuidelines/controller/APIController.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/constructionGuidelines/controller/package-info.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/constructionGuidelines/package-info.java
-
983mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/constructionGuidelines/service/GuidelinesService.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/constructionGuidelines/service/package-info.java
-
5mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/controller/APIOfficialController.java
-
75mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/controller/PdfTemplateController.java
-
5mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/erpPostData/erppostdataController.java
-
191mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/erpPostData/erppostdataService.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/erpPostData/package-info.java
-
145mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccDomesticWaste/Controller/DomesticWasteController.java
-
28mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccDomesticWaste/Scheduler/DomesticWasteScheduler.java
-
631mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccDomesticWaste/Service/DomesticWasteService.java
-
14mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/controller/APIActivityController.java
-
479mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/service/Activity.java
-
72mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gcceducation/service/EducationActivity.java
-
38mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccparks/service/ParksService.java
-
531mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccpothole/controller/PotholeApiController.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccpothole/controller/package-info.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccpothole/package-info.java
-
1031mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccpothole/service/PotholeService.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccpothole/service/package-info.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccschools/controller/SchoolUserController.java
-
3mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccschools/service/SchoolUserActivity.java
-
15mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccstreetvendor/controller/StreetVendorController.java
-
101mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccstreetvendor/service/StreetVendorService.java
-
29mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/penalty/controller/APICommonPrintController.java
-
204mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/penalty/service/PenaltyPrintService.java
-
189mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/privateToilets/controller/APIController.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/privateToilets/controller/package-info.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/privateToilets/package-info.java
-
851mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/privateToilets/service/ToiletService.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/privateToilets/service/package-info.java
-
130mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/roadcut/controller/RoadCutController.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/roadcut/controller/package-info.java
-
33mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/roadcut/modelclass/RoadCutDetail.java
-
9mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/roadcut/modelclass/RoadCutResponse.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/roadcut/modelclass/package-info.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/roadcut/package-info.java
-
976mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/roadcut/service/RoadCutService.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/roadcut/service/package-info.java
-
23mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/service/OfficialAPIService.java
-
42mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/service/PdfGeneratorService.java
-
93mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/speedbrake/controller/APIController.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/speedbrake/controller/package-info.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/speedbrake/package-info.java
-
453mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/speedbrake/service/APIService.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/speedbrake/service/package-info.java
-
7mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/toilets/controller/APIController.java
-
33mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/toilets/service/activity.java
-
135mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/viewCutter/controller/viewCutterController.java
-
1mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/viewCutter/package-info.java
-
1037mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/viewCutter/service/viewCutterActivity.java
-
2mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/works/controller/WorksController.java
-
10mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/works/service/WorksService.java
-
BINmobileservice/src/main/resources/.DS_Store
-
9mobileservice/src/main/resources/application.properties
-
108mobileservice/src/main/resources/templates/pdf-template.html
@ -0,0 +1,64 @@ |
|||
package in.gov.chennaicorporation.mobileservice.buildingDemolition.controller; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import in.gov.chennaicorporation.mobileservice.buildingDemolition.service.BuildingDemolitionActivity; |
|||
|
|||
@RequestMapping("/gccofficialapp/api/buildingdemolition/") |
|||
@RestController("buildingDemolitionRest") |
|||
public class BuildingDemolitionController { |
|||
@Autowired |
|||
BuildingDemolitionActivity buildingDemolitionService; |
|||
|
|||
@GetMapping("/list") |
|||
public ResponseEntity<List<Map<String, Object>>> getBuildingList( |
|||
@RequestParam String loginId) { |
|||
return ResponseEntity.ok(buildingDemolitionService.getBuildingList(loginId)); |
|||
} |
|||
|
|||
@PostMapping("/update") |
|||
public ResponseEntity<List<Map<String, Object>>> updateDetails( |
|||
@RequestParam String id, |
|||
@RequestParam String status, |
|||
@RequestParam String cby, |
|||
@RequestParam(required = true) String latitude, |
|||
@RequestParam(required = true) String longitude, |
|||
@RequestParam(required = true) String remarks, |
|||
@RequestParam(required = true) MultipartFile file) { |
|||
return ResponseEntity.ok(buildingDemolitionService.updateDetails(id, status, cby, latitude, longitude, remarks, file)); |
|||
} |
|||
|
|||
// Zone wise Report |
|||
@GetMapping("/report/zone") |
|||
public ResponseEntity<List<Map<String, Object>>> zoneReport() { |
|||
return ResponseEntity.ok(buildingDemolitionService.zoneReport()); |
|||
} |
|||
|
|||
// Ward wise Report (filter by zone) |
|||
@GetMapping("/report/ward") |
|||
public ResponseEntity<List<Map<String, Object>>> wardReport(@RequestParam String zone) { |
|||
return ResponseEntity.ok(buildingDemolitionService.wardReport(zone)); |
|||
} |
|||
|
|||
// Pending list Report (filter by ward) |
|||
@GetMapping("/report/pending") |
|||
public ResponseEntity<List<Map<String, Object>>> pendingReport(@RequestParam String ward) { |
|||
return ResponseEntity.ok(buildingDemolitionService.pendingReport(ward)); |
|||
} |
|||
|
|||
// Completed list Report (filter by ward) |
|||
@GetMapping("/report/completed") |
|||
public ResponseEntity<List<Map<String, Object>>> completedReport(@RequestParam String ward) { |
|||
return ResponseEntity.ok(buildingDemolitionService.completedReport(ward)); |
|||
} |
|||
} |
|||
@ -0,0 +1,325 @@ |
|||
package in.gov.chennaicorporation.mobileservice.buildingDemolition.service; |
|||
|
|||
import java.awt.image.BufferedImage; |
|||
import java.io.ByteArrayInputStream; |
|||
import java.io.ByteArrayOutputStream; |
|||
import java.io.IOException; |
|||
import java.nio.file.Files; |
|||
import java.nio.file.Path; |
|||
import java.nio.file.Paths; |
|||
import java.security.SecureRandom; |
|||
import java.util.Collections; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.Random; |
|||
|
|||
import javax.imageio.ImageIO; |
|||
import javax.imageio.ImageWriteParam; |
|||
import javax.imageio.ImageWriter; |
|||
import javax.imageio.stream.ImageOutputStream; |
|||
import javax.sql.DataSource; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Qualifier; |
|||
import org.springframework.core.env.Environment; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.util.MultiValueMap; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import in.gov.chennaicorporation.mobileservice.gccactivity.service.DateTimeUtil; |
|||
|
|||
@Service |
|||
public class BuildingDemolitionActivity { |
|||
private JdbcTemplate jdbcBuildingDemolitionTemplate; |
|||
|
|||
private final Environment environment; |
|||
private String fileBaseUrl; |
|||
|
|||
private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
|||
private static final int STRING_LENGTH = 15; |
|||
private static final Random RANDOM = new SecureRandom(); |
|||
|
|||
@Autowired |
|||
public void setDataSource(@Qualifier("mysqlGccBuildingDemolitionSource") DataSource BuildingDemolitionDataSource) { |
|||
this.jdbcBuildingDemolitionTemplate = new JdbcTemplate(BuildingDemolitionDataSource); |
|||
} |
|||
|
|||
@Autowired |
|||
public BuildingDemolitionActivity(Environment environment) { |
|||
this.environment = environment; |
|||
this.fileBaseUrl=environment.getProperty("fileBaseUrl"); |
|||
} |
|||
|
|||
public static String generateRandomString() { |
|||
StringBuilder result = new StringBuilder(STRING_LENGTH); |
|||
for (int i = 0; i < STRING_LENGTH; i++) { |
|||
result.append(CHARACTERS.charAt(RANDOM.nextInt(CHARACTERS.length()))); |
|||
} |
|||
return result.toString(); |
|||
} |
|||
|
|||
public static String generateRandomStringForFile(int String_Lenth) { |
|||
StringBuilder result = new StringBuilder(String_Lenth); |
|||
for (int i = 0; i < STRING_LENGTH; i++) { |
|||
result.append(CHARACTERS.charAt(RANDOM.nextInt(CHARACTERS.length()))); |
|||
} |
|||
return result.toString(); |
|||
} |
|||
|
|||
private byte[] compressImage(BufferedImage image, float quality) throws IOException { |
|||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
|||
ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(byteArrayOutputStream); |
|||
|
|||
ImageWriter writer = ImageIO.getImageWritersByFormatName("jpg").next(); |
|||
writer.setOutput(imageOutputStream); |
|||
|
|||
ImageWriteParam param = writer.getDefaultWriteParam(); |
|||
if (param.canWriteCompressed()) { |
|||
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
|||
param.setCompressionQuality(quality); |
|||
} |
|||
|
|||
writer.write(null, new javax.imageio.IIOImage(image, null, null), param); |
|||
|
|||
writer.dispose(); |
|||
imageOutputStream.close(); |
|||
|
|||
return byteArrayOutputStream.toByteArray(); |
|||
} |
|||
|
|||
public String fileUpload(String name, String id, MultipartFile file) { |
|||
|
|||
int lastInsertId = 0; |
|||
// Set the file path where you want to save it |
|||
String uploadDirectory = environment.getProperty("file.upload.directory"); |
|||
String serviceFolderName = environment.getProperty("buildingdemolition_foldername"); |
|||
var year =DateTimeUtil.getCurrentYear(); |
|||
var month =DateTimeUtil.getCurrentMonth(); |
|||
|
|||
uploadDirectory = uploadDirectory + serviceFolderName + year +"/"+month; |
|||
|
|||
try { |
|||
// Create directory if it doesn't exist |
|||
Path directoryPath = Paths.get(uploadDirectory); |
|||
if (!Files.exists(directoryPath)) { |
|||
Files.createDirectories(directoryPath); |
|||
} |
|||
|
|||
// Datetime string |
|||
String datetimetxt = DateTimeUtil.getCurrentDateTime(); |
|||
// File name |
|||
System.out.println(file.getOriginalFilename()); |
|||
String fileName = name+ "_" +id + "_" + datetimetxt + "_" + generateRandomStringForFile(10) + "_" + file.getOriginalFilename(); |
|||
fileName = fileName.replaceAll("\\s+", ""); // Remove space on filename |
|||
|
|||
String filePath = uploadDirectory + "/" + fileName; |
|||
|
|||
String filepath_txt = "/"+serviceFolderName + year + "/" + month + "/" + fileName; |
|||
|
|||
// Create a new Path object |
|||
Path path = Paths.get(filePath); |
|||
|
|||
// Get the bytes of the file |
|||
byte[] bytes = file.getBytes(); |
|||
|
|||
// Compress the image |
|||
BufferedImage image = ImageIO.read(new ByteArrayInputStream(bytes)); |
|||
byte[] compressedBytes = compressImage(image, 0.5f); // Compress with 50% quality |
|||
|
|||
// Write the bytes to the file |
|||
Files.write(path, bytes); |
|||
|
|||
System.out.println(filePath); |
|||
return filepath_txt; |
|||
|
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
return "Failed to save file " + file.getOriginalFilename(); |
|||
} |
|||
} |
|||
|
|||
public List<Map<String, Object>> getBuildingList(String aeUserId) { |
|||
|
|||
String sql = "SELECT zone, ward FROM gcc_penalty_hoardings.`hoading_user_list` WHERE userid = ? AND type='ae'"; |
|||
List<Map<String, Object>> userList = jdbcBuildingDemolitionTemplate.queryForList(sql, aeUserId); |
|||
|
|||
if (userList.isEmpty()) { |
|||
// You can return an empty list or throw a custom exception |
|||
return Collections.emptyList(); // or handle as needed |
|||
} |
|||
|
|||
Map<String, Object> vendorData = userList.get(0); |
|||
String ward = String.valueOf(vendorData.get("ward")); |
|||
|
|||
sql = "SELECT " |
|||
+ " bd.* " |
|||
+ "FROM building_demolition bd " |
|||
+ "LEFT JOIN building_demolition_status bds ON bd.id = bds.bdid " |
|||
+ "WHERE bds.bdid IS NULL " |
|||
+ " AND bd.ward = ?"; |
|||
List<Map<String, Object>> result = jdbcBuildingDemolitionTemplate.queryForList(sql, ward); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Building Demolition List."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> updateDetails( |
|||
String id, |
|||
String status, |
|||
String cby, |
|||
String latitude, |
|||
String longitude, |
|||
String remarks, |
|||
MultipartFile file) { |
|||
|
|||
String filepath = null; |
|||
// 1. Fetch building details |
|||
String sql = "SELECT `id` as bdid, `council_resolution_date`, `year`, `zone`, `ward`, " + |
|||
"`description`, `category_of_building`, `area_sqm` " + |
|||
"FROM `building_demolition` WHERE id=?"; |
|||
|
|||
List<Map<String, Object>> result = jdbcBuildingDemolitionTemplate.queryForList(sql, id); |
|||
|
|||
if (result.isEmpty()) { |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Failed"); |
|||
response.put("message", "No record found for id " + id); |
|||
return Collections.singletonList(response); |
|||
} |
|||
Map<String, Object> building = result.get(0); |
|||
|
|||
// 2. Check if record already exists in building_demolition_status |
|||
String checkSql = "SELECT COUNT(*) FROM `building_demolition_status` WHERE bdid = ?"; |
|||
Integer count = jdbcBuildingDemolitionTemplate.queryForObject(checkSql, Integer.class, building.get("bdid")); |
|||
|
|||
if (count != null && count > 0) { |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Failed"); |
|||
response.put("message", "Duplicate entry: Demolition status already exists for building id " + id); |
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
// 2.1. Handle file upload (optional) |
|||
if (file != null && !file.isEmpty()) { |
|||
filepath = fileUpload(id, cby, file); |
|||
} |
|||
|
|||
// 3. Insert into building_demolition_status |
|||
String insertSql = "INSERT INTO `building_demolition_status` " + |
|||
"(`bdid`, `council_resolution_date`, `year`, `zone`, `ward`, `description`, " + |
|||
"`category_of_building`, `area_sqm`, `status`, `inby`, " + |
|||
" `file1`, `remarks`, `latitude`, `longitude`) " + |
|||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; |
|||
|
|||
jdbcBuildingDemolitionTemplate.update(insertSql, |
|||
building.get("bdid"), |
|||
building.get("council_resolution_date"), |
|||
building.get("year"), |
|||
building.get("zone"), |
|||
building.get("ward"), |
|||
building.get("description"), |
|||
building.get("category_of_building"), |
|||
building.get("area_sqm"), |
|||
status, |
|||
cby, |
|||
filepath, |
|||
remarks, |
|||
latitude, |
|||
longitude |
|||
); |
|||
|
|||
// 4. Build response |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Building Demolition Status inserted successfully."); |
|||
response.put("data", building); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
// Reports |
|||
public List<Map<String, Object>> zoneReport() { |
|||
String sqlQuery = "SELECT " |
|||
+ " bd.zone, " |
|||
+ " COUNT(bd.id) AS total_building, " |
|||
+ " SUM(CASE WHEN bds.bdid IS NULL THEN 1 ELSE 0 END) AS pending, " |
|||
+ " SUM(CASE WHEN bds.bdid IS NOT NULL THEN 1 ELSE 0 END) AS completed " |
|||
+ "FROM building_demolition bd " |
|||
+ "LEFT JOIN building_demolition_status bds ON bd.id = bds.bdid " |
|||
+ "GROUP BY bd.zone " |
|||
+ "ORDER BY bd.zone"; |
|||
|
|||
List<Map<String, Object>> result = jdbcBuildingDemolitionTemplate.queryForList(sqlQuery); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", 200); |
|||
response.put("message", "Zone list report."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> wardReport(String zone) { |
|||
String sqlQuery = "SELECT " |
|||
+ " bd.ward, " |
|||
+ " COUNT(bd.id) AS total_building, " |
|||
+ " SUM(CASE WHEN bds.bdid IS NULL THEN 1 ELSE 0 END) AS pending, " |
|||
+ " SUM(CASE WHEN bds.bdid IS NOT NULL THEN 1 ELSE 0 END) AS completed " |
|||
+ "FROM building_demolition bd " |
|||
+ "LEFT JOIN building_demolition_status bds ON bd.id = bds.bdid " |
|||
+ "WHERE bd.zone = ? " |
|||
+ "GROUP BY bd.ward " |
|||
+ "ORDER BY bd.ward"; |
|||
|
|||
List<Map<String, Object>> result = jdbcBuildingDemolitionTemplate.queryForList(sqlQuery,zone); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", 200); |
|||
response.put("message", "Ward list report."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> pendingReport(String ward) { |
|||
String sqlQuery = "SELECT " |
|||
+ " bd.* " |
|||
+ "FROM building_demolition bd " |
|||
+ "LEFT JOIN building_demolition_status bds ON bd.id = bds.bdid " |
|||
+ "WHERE bds.bdid IS NULL " |
|||
+ " AND bd.ward = ?"; |
|||
|
|||
List<Map<String, Object>> result = jdbcBuildingDemolitionTemplate.queryForList(sqlQuery,ward); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", 200); |
|||
response.put("message", "Pending list report."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> completedReport(String ward) { |
|||
String sqlQuery = "SELECT " |
|||
+ " bds.*," |
|||
+ " CONCAT('" + fileBaseUrl + "/gccofficialapp/files', bds.file1) AS image_url " |
|||
+ "FROM building_demolition bd " |
|||
+ "INNER JOIN building_demolition_status bds ON bd.id = bds.bdid " |
|||
+ "WHERE bd.ward = ?"; |
|||
|
|||
List<Map<String, Object>> result = jdbcBuildingDemolitionTemplate.queryForList(sqlQuery,ward); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", 200); |
|||
response.put("message", "Completed list report."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,115 @@ |
|||
package in.gov.chennaicorporation.mobileservice.busshelters.controller; |
|||
|
|||
import java.util.List; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
import org.springframework.util.MultiValueMap; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import in.gov.chennaicorporation.mobileservice.busshelters.service.BusShelterRenovationActivity; |
|||
|
|||
@RequestMapping("/gccofficialapp/api/busshelter/renovation/") |
|||
@RestController("busshelterRenovationRest") |
|||
public class BusShelterController_renovation { |
|||
@Autowired |
|||
private JdbcTemplate jdbcBusShelterTemplate; |
|||
@Autowired |
|||
private BusShelterRenovationActivity busShelterRenovationActivity; |
|||
|
|||
@GetMapping(value="/getBusShelterList") |
|||
public List<?> getBusShelterList(@RequestParam MultiValueMap<String, String> formData, |
|||
@RequestParam(value = "latitude", required = true) String latitude, |
|||
@RequestParam(value = "longitude", required = true) String longitude, |
|||
@RequestParam(value = "loginid", required = false) String loginid){ |
|||
return busShelterRenovationActivity.getBusShelterList(formData, latitude, longitude, loginid); |
|||
} |
|||
|
|||
@GetMapping(value="/getBusCompletedShelterList") |
|||
public List<?> getBusCompletedShelterList(@RequestParam MultiValueMap<String, String> formData, |
|||
@RequestParam(value = "latitude", required = false) String latitude, |
|||
@RequestParam(value = "longitude", required = false) String longitude, |
|||
@RequestParam(value = "loginid", required = true) String loginid){ |
|||
return busShelterRenovationActivity.getBusCompletedShelterList(formData, latitude, longitude, loginid); |
|||
} |
|||
|
|||
@GetMapping(value="/getStageList") // Old App |
|||
public List<?> getQuestionsList(@RequestParam(value="loginId", required = false) String cby){ |
|||
return busShelterRenovationActivity.getStageList(); |
|||
} |
|||
|
|||
@GetMapping(value="/getBusShelterDetails") |
|||
public List<?> getBusShelterDetails( |
|||
@RequestParam MultiValueMap<String, String> formData, |
|||
@RequestParam(value="id", required = true) String id, |
|||
@RequestParam(value="latitude", required = true) String latitude, |
|||
@RequestParam(value="longitude", required = true) String longitude, |
|||
@RequestParam(value="loginid", required = false) String loginid, |
|||
@RequestParam(value="renovation_required_condition", required = false) String renovation_required_condition){ |
|||
return busShelterRenovationActivity.getBusShelterDetails(formData,id,loginid, latitude, longitude, renovation_required_condition); |
|||
} |
|||
|
|||
@PostMapping(value="/saveStageActivityData") |
|||
public List<?> saveStageActivityData( |
|||
@RequestParam(value="shelter_id", required = true) String shelter_id, |
|||
@RequestParam(value="loginId", required = true) String cby, |
|||
@RequestParam(value="latitude", required = true) String latitude, |
|||
@RequestParam(value="longitude", required = true) String longitude, |
|||
@RequestParam(value="zone", required = true) String zone, |
|||
@RequestParam(value="ward", required = true) String ward, |
|||
@RequestParam(value="streetname", required = false) String streetname, |
|||
@RequestParam(value="streetid", required = false) String streetid, |
|||
@RequestParam(value="stageid", required = true) String stageid, |
|||
@RequestParam(value="remarks", required = true) String remarks, |
|||
@RequestParam(value="weightage", required = true) String weightage, |
|||
@RequestParam(value="renovation_required", required = false) String renovation_required, |
|||
|
|||
@RequestParam(value = "file", required = false) MultipartFile file, |
|||
@RequestParam(value="stagefile", required = false) MultipartFile stage_file |
|||
){ |
|||
return busShelterRenovationActivity.saveStageActivityData(shelter_id, cby, latitude, longitude, zone, ward, |
|||
streetname, streetid, stageid, remarks, weightage, file, stage_file, renovation_required); |
|||
} |
|||
|
|||
// Reports |
|||
|
|||
@GetMapping(value="/getZoneList") |
|||
public List<?> getZoneList(){ |
|||
return busShelterRenovationActivity.getZoneList(); |
|||
} |
|||
|
|||
@GetMapping(value="/getWardList") |
|||
public List<?> getWardList(@RequestParam(value="zone", required = true) String zone){ |
|||
return busShelterRenovationActivity.getWardList(zone); |
|||
} |
|||
|
|||
@GetMapping(value="/getVistPendingList") |
|||
public List<?> getVistPendingList(@RequestParam(value="ward", required = true) String ward){ |
|||
return busShelterRenovationActivity.getVistPendingList(ward); |
|||
} |
|||
|
|||
@GetMapping(value="/getRenovationRequiredList") |
|||
public List<?> getRenovationRequiredList(@RequestParam(value="ward", required = true) String ward){ |
|||
return busShelterRenovationActivity.getRenovationRequiredList(ward); |
|||
} |
|||
|
|||
@GetMapping(value="/getRenovationNotRequiredList") |
|||
public List<?> getRenovationNotRequiredList(@RequestParam(value="ward", required = true) String ward){ |
|||
return busShelterRenovationActivity.getRenovationNotRequiredList(ward); |
|||
} |
|||
|
|||
@GetMapping(value="/getWorkPendingList") |
|||
public List<?> getWorkPendingList(@RequestParam(value="ward", required = true) String ward){ |
|||
return busShelterRenovationActivity.getWorkPendingList(ward); |
|||
} |
|||
|
|||
@GetMapping(value="/getWorkCompletedList") |
|||
public List<?> getWorkCompletedList(@RequestParam(value="ward", required = true) String ward){ |
|||
return busShelterRenovationActivity.getWorkCompletedList(ward); |
|||
} |
|||
} |
|||
@ -0,0 +1,879 @@ |
|||
package in.gov.chennaicorporation.mobileservice.busshelters.service; |
|||
|
|||
import java.awt.image.BufferedImage; |
|||
import java.io.ByteArrayInputStream; |
|||
import java.io.ByteArrayOutputStream; |
|||
import java.io.IOException; |
|||
import java.nio.file.Files; |
|||
import java.nio.file.Path; |
|||
import java.nio.file.Paths; |
|||
import java.security.SecureRandom; |
|||
import java.sql.Connection; |
|||
import java.sql.PreparedStatement; |
|||
import java.sql.SQLException; |
|||
import java.time.LocalDate; |
|||
import java.time.format.DateTimeFormatter; |
|||
import java.util.ArrayList; |
|||
import java.util.Collections; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.Random; |
|||
|
|||
import javax.imageio.ImageIO; |
|||
import javax.imageio.ImageWriteParam; |
|||
import javax.imageio.ImageWriter; |
|||
import javax.imageio.stream.ImageOutputStream; |
|||
import javax.sql.DataSource; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Qualifier; |
|||
import org.springframework.core.env.Environment; |
|||
import org.springframework.dao.DataAccessException; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
import org.springframework.jdbc.core.PreparedStatementCreator; |
|||
import org.springframework.jdbc.support.GeneratedKeyHolder; |
|||
import org.springframework.jdbc.support.KeyHolder; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.util.MultiValueMap; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
|
|||
import in.gov.chennaicorporation.mobileservice.gccactivity.service.DateTimeUtil; |
|||
|
|||
@Service |
|||
public class BusShelterRenovationActivity { |
|||
private JdbcTemplate jdbcBusShelterTemplate; |
|||
|
|||
private final Environment environment; |
|||
private String fileBaseUrl; |
|||
|
|||
private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
|||
private static final int STRING_LENGTH = 15; |
|||
private static final Random RANDOM = new SecureRandom(); |
|||
|
|||
@Autowired |
|||
public void setDataSource(@Qualifier("mysqlBusShelterDataSource") DataSource BusShelterDataSource) { |
|||
this.jdbcBusShelterTemplate = new JdbcTemplate(BusShelterDataSource); |
|||
} |
|||
|
|||
@Autowired |
|||
public BusShelterRenovationActivity(Environment environment) { |
|||
this.environment = environment; |
|||
this.fileBaseUrl=environment.getProperty("fileBaseUrl"); |
|||
} |
|||
|
|||
public static String generateRandomString() { |
|||
StringBuilder result = new StringBuilder(STRING_LENGTH); |
|||
for (int i = 0; i < STRING_LENGTH; i++) { |
|||
result.append(CHARACTERS.charAt(RANDOM.nextInt(CHARACTERS.length()))); |
|||
} |
|||
return result.toString(); |
|||
} |
|||
|
|||
public static String generateRandomStringForFile(int String_Lenth) { |
|||
StringBuilder result = new StringBuilder(String_Lenth); |
|||
for (int i = 0; i < STRING_LENGTH; i++) { |
|||
result.append(CHARACTERS.charAt(RANDOM.nextInt(CHARACTERS.length()))); |
|||
} |
|||
return result.toString(); |
|||
} |
|||
|
|||
private byte[] compressImage(BufferedImage image, float quality) throws IOException { |
|||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
|||
ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(byteArrayOutputStream); |
|||
|
|||
ImageWriter writer = ImageIO.getImageWritersByFormatName("jpg").next(); |
|||
writer.setOutput(imageOutputStream); |
|||
|
|||
ImageWriteParam param = writer.getDefaultWriteParam(); |
|||
if (param.canWriteCompressed()) { |
|||
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
|||
param.setCompressionQuality(quality); |
|||
} |
|||
|
|||
writer.write(null, new javax.imageio.IIOImage(image, null, null), param); |
|||
|
|||
writer.dispose(); |
|||
imageOutputStream.close(); |
|||
|
|||
return byteArrayOutputStream.toByteArray(); |
|||
} |
|||
|
|||
public String fileUpload(String name, String id, MultipartFile file) { |
|||
|
|||
int lastInsertId = 0; |
|||
// Set the file path where you want to save it |
|||
String uploadDirectory = environment.getProperty("file.upload.directory"); |
|||
String serviceFolderName = environment.getProperty("busshelter_renovation_foldername"); |
|||
var year =DateTimeUtil.getCurrentYear(); |
|||
var month =DateTimeUtil.getCurrentMonth(); |
|||
|
|||
uploadDirectory = uploadDirectory + serviceFolderName + year +"/"+month; |
|||
|
|||
try { |
|||
// Create directory if it doesn't exist |
|||
Path directoryPath = Paths.get(uploadDirectory); |
|||
if (!Files.exists(directoryPath)) { |
|||
Files.createDirectories(directoryPath); |
|||
} |
|||
|
|||
// Datetime string |
|||
String datetimetxt = DateTimeUtil.getCurrentDateTime(); |
|||
// File name |
|||
System.out.println(file.getOriginalFilename()); |
|||
String fileName = name+ "_" +id + "_" + datetimetxt + "_" + generateRandomStringForFile(10) + "_" + file.getOriginalFilename(); |
|||
fileName = fileName.replaceAll("\\s+", ""); // Remove space on filename |
|||
|
|||
String filePath = uploadDirectory + "/" + fileName; |
|||
|
|||
String filepath_txt = "/"+serviceFolderName + year + "/" + month + "/" + fileName; |
|||
|
|||
// Create a new Path object |
|||
Path path = Paths.get(filePath); |
|||
|
|||
// Get the bytes of the file |
|||
byte[] bytes = file.getBytes(); |
|||
|
|||
// Compress the image |
|||
BufferedImage image = ImageIO.read(new ByteArrayInputStream(bytes)); |
|||
byte[] compressedBytes = compressImage(image, 0.5f); // Compress with 50% quality |
|||
|
|||
// Write the bytes to the file |
|||
Files.write(path, bytes); |
|||
|
|||
System.out.println(filePath); |
|||
return filepath_txt; |
|||
|
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
return "Failed to save file " + file.getOriginalFilename(); |
|||
} |
|||
} |
|||
|
|||
////////////////////////////// |
|||
public String getConfigValue() { |
|||
String sqlQuery = "SELECT `id`, `lat_long_radius` FROM `config` LIMIT 1"; |
|||
String value = "50"; // default fallback value |
|||
List<Map<String, Object>> results = jdbcBusShelterTemplate.queryForList(sqlQuery); |
|||
|
|||
if (!results.isEmpty()) { |
|||
Map<String, Object> row = results.get(0); |
|||
value = String.valueOf(row.get("lat_long_radius")); // corrected key name |
|||
} |
|||
|
|||
return value; |
|||
} |
|||
|
|||
|
|||
public String getWardByLoginId(String loginid, String type) { |
|||
String sqlQuery = "SELECT `ward` FROM gcc_penalty_hoardings.`hoading_user_list` WHERE `userid` = ? AND `type` = ? LIMIT 1"; |
|||
|
|||
// Query the database using queryForList |
|||
List<Map<String, Object>> results = jdbcBusShelterTemplate.queryForList(sqlQuery, loginid, type); |
|||
|
|||
// Check if results is not empty and extract the ward value |
|||
if (!results.isEmpty()) { |
|||
// Extract the ward value from the first result |
|||
return (String) results.get(0).get("ward"); |
|||
} |
|||
|
|||
// Handle the case where no result is found |
|||
return "000"; // or return null based on your needs |
|||
} |
|||
|
|||
////////////////////////////// |
|||
|
|||
public List<Map<String, Object>> getBusShelterList( |
|||
MultiValueMap<String, String> formData, |
|||
String latitude, |
|||
String longitude, |
|||
String loginid |
|||
) { |
|||
|
|||
String sqlWhere = ""; |
|||
|
|||
String radius = getConfigValue(); |
|||
/* |
|||
if (latitude != null && longitude != null && !latitude.isBlank() && !latitude.isEmpty() && !longitude.isBlank() |
|||
&& !longitude.isEmpty()) { |
|||
sqlWhere += " AND ((6371008.8 * acos((cos(radians(" + latitude |
|||
+ ")) * cos(radians(bsl.latitude)) * cos(radians(bsl.longitude) - radians(" + longitude |
|||
+ ")) + sin(radians(" + latitude + ")) * sin(radians(bsl.latitude))))) < "+radius+")" |
|||
+ " ORDER BY" |
|||
+ " bsl.`id` DESC"; |
|||
} |
|||
*/ |
|||
|
|||
String ward = getWardByLoginId(loginid,"ae"); |
|||
|
|||
sqlWhere = " AND (bsr.`stage_status` <> 'Completed' OR bsr.`stage_status` is NULL) ORDER BY bsl.`id` DESC"; |
|||
|
|||
String sql = "SELECT " |
|||
+ " bsl.`id`, " |
|||
+ " bsl.`zone`, " |
|||
+ " bsl.`ward`, " |
|||
+ " bsl.`latitude`, " |
|||
+ " bsl.`longitude`, " |
|||
+ " bsl.`road`, " |
|||
+ " bsl.`category`, " |
|||
+ " bsr.renovation_required, " |
|||
+ " IF(bsr.shelter_image IS NOT NULL AND bsr.shelter_image != '', " |
|||
+ " CONCAT('" + fileBaseUrl + "/gccofficialapp/files', bsr.shelter_image), " |
|||
+ " NULL) AS shelter_image, " |
|||
+ " COALESCE(bsr.stage_status,'Pending') AS stage_status " |
|||
+ "FROM `bus_shelter_list` bsl " |
|||
+ "LEFT JOIN `bus_shelter_renovation` bsr " |
|||
+ " ON bsr.bsid = bsl.id AND bsr.isactive = 1 " |
|||
+ "WHERE bsl.isactive = 1 AND bsl.ward = ? "+sqlWhere; |
|||
|
|||
//System.out.println(sql); |
|||
|
|||
List<Map<String, Object>> result = jdbcBusShelterTemplate.queryForList(sql,ward); |
|||
|
|||
ObjectMapper mapper = new ObjectMapper(); |
|||
for (Map<String, Object> row : result) { |
|||
|
|||
Object renovation_required = row.get("renovation_required"); |
|||
|
|||
if (renovation_required != null) { |
|||
sql = "SELECT COALESCE(SUM(`weightage`), 0) AS total_weightage " |
|||
+ "FROM `bus_shelter_renovation_data` " |
|||
+ "WHERE bsid = ?"; |
|||
|
|||
List<Map<String, Object>> presentage = jdbcBusShelterTemplate.queryForList(sql, row.get("id")); |
|||
|
|||
// Safely get the first result |
|||
if (!presentage.isEmpty()) { |
|||
row.put("stage_presentage", presentage.get(0).get("total_weightage")); |
|||
} else { |
|||
row.put("stage_presentage", 0); |
|||
} |
|||
} else { |
|||
row.put("stage_presentage", 0); |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Bus Shelter List."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getBusCompletedShelterList( |
|||
MultiValueMap<String, String> formData, |
|||
String latitude, |
|||
String longitude, |
|||
String loginid |
|||
) { |
|||
|
|||
String sqlWhere = ""; |
|||
String radius = getConfigValue(); |
|||
/* |
|||
if (latitude != null && longitude != null && !latitude.isBlank() && !latitude.isEmpty() && !longitude.isBlank() |
|||
&& !longitude.isEmpty()) { |
|||
sqlWhere += " AND ((6371008.8 * acos((cos(radians(" + latitude |
|||
+ ")) * cos(radians(bsl.latitude)) * cos(radians(bsl.longitude) - radians(" + longitude |
|||
+ ")) + sin(radians(" + latitude + ")) * sin(radians(bsl.latitude))))) < "+radius+")" |
|||
+ " ORDER BY" |
|||
+ " bsl.`id` DESC"; |
|||
} |
|||
*/ |
|||
String sql = "SELECT " |
|||
+ " bsl.`id`, " |
|||
+ " bsl.`zone`, " |
|||
+ " bsl.`ward`, " |
|||
+ " bsl.`latitude`, " |
|||
+ " bsl.`longitude`, " |
|||
+ " bsl.`road`, " |
|||
+ " bsl.`category`, " |
|||
+ " bsr.renovation_required, " |
|||
+ " IF(bsr.shelter_image IS NOT NULL AND bsr.shelter_image != '', " |
|||
+ " CONCAT('" + fileBaseUrl + "/gccofficialapp/files', bsr.shelter_image), " |
|||
+ " NULL) AS shelter_image, " |
|||
+ " COALESCE(bsr.stage_status,'Pending') AS stage_status " |
|||
+ "FROM `bus_shelter_list` bsl " |
|||
+ "LEFT JOIN `bus_shelter_renovation` bsr " |
|||
+ " ON bsr.bsid = bsl.id AND bsr.isactive = 1 " |
|||
+ "WHERE bsl.isactive = 1 AND bsr.stage_status='Completed'"; // +sqlWhere; |
|||
|
|||
System.out.println(sql); |
|||
|
|||
List<Map<String, Object>> result = jdbcBusShelterTemplate.queryForList(sql); |
|||
|
|||
ObjectMapper mapper = new ObjectMapper(); |
|||
for (Map<String, Object> row : result) { |
|||
|
|||
Object renovation_required = row.get("renovation_required"); |
|||
|
|||
if (renovation_required != null) { |
|||
sql = "SELECT COALESCE(SUM(`weightage`), 0) AS total_weightage " |
|||
+ "FROM `bus_shelter_renovation_data` " |
|||
+ "WHERE bsid = ?"; |
|||
|
|||
List<Map<String, Object>> presentage = jdbcBusShelterTemplate.queryForList(sql, row.get("id")); |
|||
|
|||
// Safely get the first result |
|||
if (!presentage.isEmpty()) { |
|||
row.put("stage_presentage", presentage.get(0).get("total_weightage")); |
|||
} else { |
|||
row.put("stage_presentage", 0); |
|||
} |
|||
} else { |
|||
row.put("stage_presentage", 0); |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Bus Shelter Completed List."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getStageList() { |
|||
String sql = "SELECT * FROM `renovation_statge` WHERE isactive=1 ORDER BY orderby"; |
|||
List<Map<String, Object>> result = jdbcBusShelterTemplate.queryForList(sql); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Bus Shelter Stages."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getBusShelterDetails( |
|||
MultiValueMap<String, String> formData, |
|||
String id, |
|||
String loginid, |
|||
String latitude, |
|||
String longitude, |
|||
String renovation_required_condition |
|||
) { |
|||
|
|||
String sqlWhere = ""; |
|||
//String radius = getConfigValue(); |
|||
|
|||
String sql = "SELECT " |
|||
+ " bsl.`id`, " |
|||
+ " bsl.`zone`, " |
|||
+ " bsl.`ward`, " |
|||
+ " bsl.`latitude`, " |
|||
+ " bsl.`longitude`, " |
|||
+ " bsl.`road`, " |
|||
+ " bsl.`category`, " |
|||
+ " bsr.renovation_required, " |
|||
+ " IF(bsr.shelter_image IS NOT NULL AND bsr.shelter_image != '', " |
|||
+ " CONCAT('" + fileBaseUrl + "/gccofficialapp/files', bsr.shelter_image), " |
|||
+ " NULL) AS shelter_image, " |
|||
+ " COALESCE(bsr.stage_status,'Pending') AS stage_status " |
|||
+ "FROM `bus_shelter_list` bsl " |
|||
+ "LEFT JOIN `bus_shelter_renovation` bsr " |
|||
+ " ON bsr.bsid = bsl.id AND bsr.isactive = 1 " |
|||
+ "WHERE bsl.id = ? "; |
|||
|
|||
System.out.println(sql); |
|||
|
|||
List<Map<String, Object>> result = jdbcBusShelterTemplate.queryForList(sql, id); |
|||
|
|||
ObjectMapper mapper = new ObjectMapper(); |
|||
for (Map<String, Object> row : result) { |
|||
|
|||
Object renovation_required = row.get("renovation_required"); |
|||
|
|||
if (renovation_required != null) { |
|||
sql = "SELECT COALESCE(SUM(`weightage`), 0) AS total_weightage " |
|||
+ "FROM `bus_shelter_renovation_data` " |
|||
+ "WHERE bsid = ?"; |
|||
|
|||
List<Map<String, Object>> presentage = jdbcBusShelterTemplate.queryForList(sql, row.get("id")); |
|||
|
|||
// Safely get the first result |
|||
if (!presentage.isEmpty()) { |
|||
row.put("stage_presentage", presentage.get(0).get("total_weightage")); |
|||
} else { |
|||
row.put("stage_presentage", 0); |
|||
} |
|||
} else { |
|||
row.put("stage_presentage", 0); |
|||
} |
|||
|
|||
// Location Check |
|||
double shelterLat = Double.parseDouble(row.get("latitude").toString()); |
|||
double shelterLng = Double.parseDouble(row.get("longitude").toString()); |
|||
double userLat = Double.parseDouble(latitude); |
|||
double userLng = Double.parseDouble(longitude); |
|||
|
|||
// Calculate distance using Haversine formula |
|||
double earthRadius = 6371008.8; // in meters |
|||
double dLat = Math.toRadians(userLat - shelterLat); |
|||
double dLng = Math.toRadians(userLng - shelterLng); |
|||
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) |
|||
+ Math.cos(Math.toRadians(shelterLat)) * Math.cos(Math.toRadians(userLat)) |
|||
* Math.sin(dLng / 2) * Math.sin(dLng / 2); |
|||
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); |
|||
double distance = earthRadius * c; |
|||
|
|||
double radiusInMeters = Double.parseDouble(getConfigValue()); |
|||
row.put("user_on_correct_location", distance <= radiusInMeters); // true if within radius meters |
|||
//////// |
|||
|
|||
if(!"0".equals(renovation_required_condition)) { |
|||
|
|||
// Stages |
|||
List<Map<String, Object>> stageListRaw = getStageList(); |
|||
List<Map<String, Object>> stageList = (List<Map<String, Object>>) stageListRaw.get(0).get("data"); |
|||
List<Map<String, Object>> stagedata = new ArrayList<>(); |
|||
|
|||
for (Map<String, Object> stage : stageList) { |
|||
Map<String, Object> stageEntry = new HashMap<>(stage); // Clone base stage info |
|||
|
|||
stageEntry.put("stageid", stage.get("sid")); |
|||
stageEntry.put("stage_name", stage.get("name")); |
|||
stageEntry.put("weightage", stage.get("weightage")); |
|||
stageEntry.put("orderby", stage.get("orderby")); |
|||
|
|||
sql = "SELECT `dataid`, `bsid`, `stageid`, " |
|||
+ "CONCAT('"+fileBaseUrl+"/gccofficialapp/files', `image`) AS `image`, " |
|||
+ "`remarks`, `weightage`, " |
|||
+ "`zone`, `ward`, `latitude`, `longitude`, `streetname`, `streetid`, " |
|||
+ " DATE_FORMAT(`cdate`, '%d-%m-%Y') AS `cdate`, " |
|||
+ "`cby`, `isactive` FROM `bus_shelter_renovation_data` " |
|||
+ "WHERE `bsid` = ? AND `stageid` = ? AND isactive = 1"; |
|||
|
|||
List<Map<String, Object>> resultStageData = jdbcBusShelterTemplate.queryForList(sql, row.get("id"), stage.get("sid")); |
|||
|
|||
if (!resultStageData.isEmpty()) { |
|||
Map<String, Object> stageDataRow = resultStageData.get(0); |
|||
stageEntry.put("stage_image", stageDataRow.get("image")); |
|||
stageEntry.put("stage_remarks", stageDataRow.get("remarks")); |
|||
stageEntry.put("stage_date", stageDataRow.get("cdate")); |
|||
stageEntry.put("stage_status", "Completed"); |
|||
stageEntry.put("stage_presentage", stageDataRow.get("weightage")); |
|||
} else { |
|||
// Defaults if no data available |
|||
stageEntry.put("stage_image", null); |
|||
stageEntry.put("stage_remarks", null); |
|||
stageEntry.put("stage_date", null); |
|||
stageEntry.put("stage_status", "Pending"); |
|||
stageEntry.put("stage_presentage", 0); |
|||
} |
|||
|
|||
stagedata.add(stageEntry); |
|||
} |
|||
row.put("stages", stagedata); |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Bus Shelter With Stage Details."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
@Transactional |
|||
public String addRenovationBaseData( |
|||
String shelter_id, String renovation_required, String image, |
|||
String latitude, String longitude, String zone, String ward, |
|||
String streetname, String streetid, String stage_status |
|||
) { |
|||
String sql ="INSERT INTO `bus_shelter_renovation`(" |
|||
+ "`bsid`, `renovation_required`, `shelter_image`, " |
|||
+ "`latitude`, `longitude`, `zone`, `ward`, `streetname`, `streetid`, " |
|||
+ "`stage_status`) " |
|||
+ "VALUES (?,?,?,?,?,?,?,?,?,?)"; |
|||
|
|||
jdbcBusShelterTemplate.update(sql, shelter_id, renovation_required, image, latitude, longitude , zone, ward, streetname, streetid, stage_status); |
|||
return "success"; |
|||
} |
|||
|
|||
public String updateStageStatus(String shelter_id, String stage_status, String datetxt) { |
|||
|
|||
String sql = "UPDATE `bus_shelter_renovation` SET `stage_status`=?,`lastcdate` =? WHERE `bsid`=?"; |
|||
jdbcBusShelterTemplate.update(sql,stage_status, datetxt, shelter_id); |
|||
|
|||
return "sussess"; |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> saveStageActivityData( |
|||
String shelter_id, |
|||
String cby, |
|||
String latitude, |
|||
String longitude, |
|||
String zone, |
|||
String ward, |
|||
String streetname, |
|||
String streetid, |
|||
String stageid, |
|||
String remarks, |
|||
String weightage, |
|||
MultipartFile file, |
|||
|
|||
MultipartFile stage_file, |
|||
String renovation_required) { |
|||
List<Map<String, Object>> result = null; |
|||
Map<String, Object> response = new HashMap<>(); |
|||
int lastInsertId = 0; |
|||
|
|||
String image = ""; |
|||
String stage_image = ""; |
|||
|
|||
var year = DateTimeUtil.getCurrentYear(); |
|||
var month = DateTimeUtil.getCurrentMonth(); |
|||
|
|||
// Handle file upload if a file is provided |
|||
if (file != null && !file.isEmpty()) { |
|||
image = fileUpload("bushshelter", shelter_id, file); |
|||
} |
|||
|
|||
// Question Images |
|||
if (stage_file != null && !stage_file.isEmpty()) { |
|||
stage_image = fileUpload("stage", stageid, stage_file); |
|||
} |
|||
|
|||
String baseimg = image; |
|||
|
|||
String stage_image_txt = stage_image; |
|||
|
|||
//String type = // Get before & after |
|||
|
|||
// Get today's date |
|||
LocalDate today = LocalDate.now(); |
|||
|
|||
// Format it in the desired format (yyyy-MM-dd) |
|||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|||
String todayDate = today.format(formatter); |
|||
|
|||
String stage_status = "Pending"; |
|||
|
|||
if("0".equals(renovation_required) || "1".equals(renovation_required)) { |
|||
|
|||
addRenovationBaseData(shelter_id, renovation_required, image, latitude, longitude , zone, ward, streetname, streetid, stage_status); |
|||
} |
|||
if("0".equals(renovation_required)) { |
|||
stage_status = "Completed"; |
|||
updateStageStatus(shelter_id, stage_status, todayDate); |
|||
} |
|||
if(!"0".equals(renovation_required)) { |
|||
String sqlQuery = "INSERT INTO `bus_shelter_renovation_data`(" |
|||
+ "`bsid`, `stageid`, `image`, `remarks`, `weightage`, `zone`, " |
|||
+ "`ward`, `latitude`, `longitude`, `streetname`, `streetid`, `cby`" |
|||
+ ") " |
|||
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"; |
|||
|
|||
KeyHolder keyHolder = new GeneratedKeyHolder(); |
|||
|
|||
try { |
|||
int affectedRows = jdbcBusShelterTemplate.update(new PreparedStatementCreator() { |
|||
@Override |
|||
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { |
|||
PreparedStatement ps = connection.prepareStatement(sqlQuery, new String[] { "dataid" }); |
|||
ps.setString(1, shelter_id); |
|||
ps.setString(2, stageid); |
|||
ps.setString(3, stage_image_txt); |
|||
ps.setString(4, remarks); |
|||
ps.setString(5, weightage); |
|||
ps.setString(6, zone); |
|||
ps.setString(7, ward); |
|||
ps.setString(8, latitude); |
|||
ps.setString(9, longitude); |
|||
ps.setString(10, streetname); |
|||
ps.setString(11, streetid); |
|||
ps.setString(12, cby); |
|||
|
|||
return ps; |
|||
} |
|||
}, keyHolder); |
|||
|
|||
if (affectedRows > 0) { |
|||
Number generatedId = keyHolder.getKey(); |
|||
lastInsertId = (generatedId != null) ? generatedId.intValue() : 0; |
|||
response.put("insertId", lastInsertId); |
|||
response.put("status", "success"); |
|||
response.put("message", "A Bus Shelter stage data was inserted successfully!"); |
|||
System.out.println("A Bus Shelter stage data was inserted successfully! Bus Shelter ID: " + generatedId); |
|||
|
|||
String sql = "SELECT COALESCE(SUM(`weightage`), 0) AS total_weightage " |
|||
+ "FROM `bus_shelter_renovation_data` " |
|||
+ "WHERE bsid = ?"; |
|||
List<Map<String, Object>> resultStageData = jdbcBusShelterTemplate.queryForList(sql, shelter_id ); |
|||
|
|||
Object totalWeightageObj = resultStageData.get(0).get("total_weightage"); |
|||
double totalWeightage = totalWeightageObj != null ? Double.parseDouble(totalWeightageObj.toString()) : 0; |
|||
|
|||
if (totalWeightage >= 100) { |
|||
stage_status = "Completed"; |
|||
} |
|||
|
|||
updateStageStatus(shelter_id, stage_status, todayDate); |
|||
|
|||
} else { |
|||
response.put("status", "error"); |
|||
response.put("message", "Failed to insert a Bus Shelter stage data. Bus Shelter ID:" + shelter_id); |
|||
} |
|||
|
|||
} catch (DataAccessException e) { |
|||
System.out.println("Data Access Exception:"); |
|||
Throwable rootCause = e.getMostSpecificCause(); |
|||
if (rootCause instanceof SQLException) { |
|||
SQLException sqlException = (SQLException) rootCause; |
|||
System.out.println("SQL State: " + sqlException.getSQLState()); |
|||
System.out.println("Error Code: " + sqlException.getErrorCode()); |
|||
System.out.println("Message: " + sqlException.getMessage()); |
|||
response.put("status", "error"); |
|||
response.put("message", sqlException.getMessage()); |
|||
response.put("sqlState", sqlException.getSQLState()); |
|||
response.put("errorCode", sqlException.getErrorCode()); |
|||
} else { |
|||
System.out.println("Message: " + rootCause.getMessage()); |
|||
response.put("status", "error"); |
|||
response.put("message", rootCause.getMessage()); |
|||
} |
|||
} |
|||
} |
|||
else { |
|||
response.put("insertId", 0); |
|||
response.put("status", "success"); |
|||
response.put("message", "0 - A Bus Shelter stage data was inserted successfully!"); |
|||
} |
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
// Reports |
|||
|
|||
public List<Map<String, Object>> getZoneList() { |
|||
String sql = "SELECT " |
|||
+ " bsl.zone, " |
|||
+ " COUNT(DISTINCT bsl.id) AS total_shelters, " |
|||
+ " COUNT(DISTINCT CASE WHEN bsr.bsid IS NULL THEN bsl.id END) AS total_not_visited, " |
|||
+ " COUNT(DISTINCT CASE WHEN bsr.renovation_required = 1 THEN bsr.bsid END) AS total_need_improvement, " |
|||
+ " COUNT(DISTINCT CASE WHEN bsr.renovation_required = 0 THEN bsr.bsid END) AS total_no_improvement, " |
|||
+ " COUNT(DISTINCT CASE WHEN bsr.stage_status != 'Completed' AND bsr.stage_status IS NOT NULL THEN bsr.bsid END) AS total_pending, " |
|||
+ " COUNT(DISTINCT CASE WHEN bsr.stage_status = 'Completed' THEN bsr.bsid END) AS total_completed " |
|||
+ "FROM " |
|||
+ " bus_shelter_list bsl " |
|||
+ "LEFT JOIN " |
|||
+ " bus_shelter_renovation bsr ON bsr.bsid = bsl.id AND bsr.isactive = 1 " |
|||
+ "WHERE " |
|||
+ " bsl.isactive = 1 " |
|||
+ "GROUP BY " |
|||
+ " bsl.zone " |
|||
+ "ORDER BY " |
|||
+ " bsl.zone"; |
|||
List<Map<String, Object>> result = jdbcBusShelterTemplate.queryForList(sql); |
|||
// Compute totals |
|||
Map<String, Object> totals = new HashMap<>(); |
|||
totals.put("zone", "Total"); |
|||
|
|||
String[] keys = { |
|||
"total_shelters", "total_not_visited", |
|||
"total_need_improvement", "total_no_improvement", |
|||
"total_pending", "total_completed" |
|||
}; |
|||
|
|||
for (String key : keys) { |
|||
int sum = result.stream() |
|||
.mapToInt(row -> row.get(key) != null ? ((Number) row.get(key)).intValue() : 0) |
|||
.sum(); |
|||
totals.put(key, sum); |
|||
} |
|||
// Add totals row at the end |
|||
result.add(totals); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Bus Shelter Zone Report."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getWardList(String zone) { |
|||
String sql = "SELECT " |
|||
+ " bsl.ward," |
|||
+ " COUNT(DISTINCT bsl.id) AS total_shelters," |
|||
+ " COUNT(DISTINCT CASE WHEN bsr.bsid IS NULL THEN bsl.id END) AS total_not_visited," |
|||
+ " COUNT(DISTINCT CASE WHEN bsr.renovation_required = 1 THEN bsr.bsid END) AS total_need_improvement," |
|||
+ " COUNT(DISTINCT CASE WHEN bsr.renovation_required = 0 THEN bsr.bsid END) AS total_no_improvement," |
|||
+ " COUNT(DISTINCT CASE WHEN bsr.stage_status != 'Completed' AND bsr.stage_status IS NOT NULL THEN bsr.bsid END) AS total_pending," |
|||
+ " COUNT(DISTINCT CASE WHEN bsr.stage_status = 'Completed' THEN bsr.bsid END) AS total_completed " |
|||
+ "FROM " |
|||
+ " bus_shelter_list bsl " |
|||
+ "LEFT JOIN " |
|||
+ " bus_shelter_renovation bsr ON bsr.bsid = bsl.id AND bsr.isactive = 1 " |
|||
+ "WHERE " |
|||
+ " bsl.isactive = 1 " |
|||
+ " AND bsl.zone = ? " |
|||
+ "GROUP BY " |
|||
+ " bsl.ward " |
|||
+ "ORDER BY " |
|||
+ " bsl.ward"; |
|||
List<Map<String, Object>> result = jdbcBusShelterTemplate.queryForList(sql,zone); |
|||
// Compute totals |
|||
Map<String, Object> totals = new HashMap<>(); |
|||
totals.put("ward", "Total"); |
|||
|
|||
String[] keys = { |
|||
"total_shelters", "total_not_visited", |
|||
"total_need_improvement", "total_no_improvement", |
|||
"total_pending", "total_completed" |
|||
}; |
|||
|
|||
for (String key : keys) { |
|||
int sum = result.stream() |
|||
.mapToInt(row -> row.get(key) != null ? ((Number) row.get(key)).intValue() : 0) |
|||
.sum(); |
|||
totals.put(key, sum); |
|||
} |
|||
|
|||
// Add totals row at the end |
|||
result.add(totals); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Bus Shelter Ward Report."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getVistPendingList(String ward) { |
|||
String sql = "SELECT bsl.id, bsl.zone, bsl.ward, bsl.road, bsl.latitude, bsl.longitude " + |
|||
"FROM bus_shelter_list bsl " + |
|||
"LEFT JOIN bus_shelter_renovation bsr ON bsr.bsid = bsl.id AND bsr.isactive = 1 " + |
|||
"WHERE bsl.isactive = 1 " + |
|||
"AND bsl.ward = ? AND bsr.bsid IS NULL"; |
|||
|
|||
List<Map<String, Object>> result = jdbcBusShelterTemplate.queryForList(sql, ward); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Bus Shelters not yet visited (pending) in ward " + ward); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getRenovationRequiredList(String ward) { |
|||
String sql = "SELECT bsl.id, bsl.zone, bsl.ward, bsl.road, bsl.latitude, bsl.longitude, bsr.stage_status " + |
|||
"FROM bus_shelter_list bsl " + |
|||
"LEFT JOIN bus_shelter_renovation bsr ON bsr.bsid = bsl.id AND bsr.isactive = 1 " + |
|||
"WHERE bsl.isactive = 1 " + |
|||
"AND bsl.ward = ? AND bsr.renovation_required=1"; |
|||
|
|||
List<Map<String, Object>> result = jdbcBusShelterTemplate.queryForList(sql, ward); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Bus Shelters not yet visited (pending) in ward " + ward); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getRenovationNotRequiredList(String ward) { |
|||
String sql = "SELECT bsl.id, bsl.zone, bsl.ward, bsl.road, bsl.latitude, bsl.longitude, bsr.stage_status " + |
|||
"FROM bus_shelter_list bsl " + |
|||
"LEFT JOIN bus_shelter_renovation bsr ON bsr.bsid = bsl.id AND bsr.isactive = 1 " + |
|||
"WHERE bsl.isactive = 1 " + |
|||
"AND bsl.ward = ? AND bsr.renovation_required=0"; |
|||
|
|||
List<Map<String, Object>> result = jdbcBusShelterTemplate.queryForList(sql, ward); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Bus Shelters improvement Needed List in ward " + ward); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getWorkPendingList(String ward) { |
|||
String sql = "SELECT bsl.id, bsl.zone, bsl.ward, bsl.road, bsl.latitude, bsl.longitude, bsr.stage_status " + |
|||
"FROM bus_shelter_list bsl " + |
|||
"INNER JOIN bus_shelter_renovation bsr ON bsr.bsid = bsl.id AND bsr.isactive = 1 " + |
|||
"WHERE bsl.isactive = 1 " + |
|||
"AND bsl.ward = ? AND COALESCE(bsr.stage_status, 'Pending') != 'Completed'"; |
|||
|
|||
List<Map<String, Object>> result = jdbcBusShelterTemplate.queryForList(sql, ward); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Bus Shelter improvement Not Needed List for ward " + ward); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getWorkCompletedList(String ward) { |
|||
String sql = "SELECT bsl.id, bsl.zone, bsl.ward, bsl.road, bsl.latitude, bsl.longitude, bsr.stage_status " + |
|||
"FROM bus_shelter_list bsl " + |
|||
"INNER JOIN bus_shelter_renovation bsr ON bsr.bsid = bsl.id AND bsr.isactive = 1 " + |
|||
"WHERE bsl.isactive = 1 " + |
|||
"AND bsl.ward = ? AND COALESCE(bsr.stage_status, 'Pending') = 'Completed'"; |
|||
|
|||
List<Map<String, Object>> result = jdbcBusShelterTemplate.queryForList(sql, ward); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Bus Shelter work pending list for ward " + ward); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
/* |
|||
Zone wise: |
|||
SELECT |
|||
bsl.zone, |
|||
COUNT(DISTINCT bsl.id) AS total_shelters, |
|||
COUNT(DISTINCT CASE WHEN bsr.bsid IS NULL THEN bsl.id END) AS total_not_visited, |
|||
COUNT(DISTINCT CASE WHEN bsr.renovation_required = 1 THEN bsr.bsid END) AS total_need_improvement, |
|||
COUNT(DISTINCT CASE WHEN bsr.renovation_required = 0 THEN bsr.bsid END) AS total_no_improvement, |
|||
COUNT(DISTINCT CASE WHEN bsr.stage_status != 'Completed' AND bsr.stage_status IS NOT NULL THEN bsr.bsid END) AS total_pending, |
|||
COUNT(DISTINCT CASE WHEN bsr.stage_status = 'Completed' THEN bsr.bsid END) AS total_completed |
|||
FROM |
|||
bus_shelter_list bsl |
|||
LEFT JOIN |
|||
bus_shelter_renovation bsr ON bsr.bsid = bsl.id AND bsr.isactive = 1 |
|||
WHERE |
|||
bsl.isactive = 1 |
|||
GROUP BY |
|||
bsl.zone |
|||
ORDER BY |
|||
bsl.zone; |
|||
|
|||
// ward wise |
|||
SELECT |
|||
bsl.ward, |
|||
COUNT(DISTINCT bsl.id) AS total_shelters, |
|||
COUNT(DISTINCT CASE WHEN bsr.bsid IS NULL THEN bsl.id END) AS total_not_visited, |
|||
COUNT(DISTINCT CASE WHEN bsr.renovation_required = 1 THEN bsr.bsid END) AS total_need_improvement, |
|||
COUNT(DISTINCT CASE WHEN bsr.renovation_required = 0 THEN bsr.bsid END) AS total_no_improvement, |
|||
COUNT(DISTINCT CASE WHEN bsr.stage_status != 'Completed' AND bsr.stage_status IS NOT NULL THEN bsr.bsid END) AS total_pending, |
|||
COUNT(DISTINCT CASE WHEN bsr.stage_status = 'Completed' THEN bsr.bsid END) AS total_completed |
|||
FROM |
|||
bus_shelter_list bsl |
|||
LEFT JOIN |
|||
bus_shelter_renovation bsr ON bsr.bsid = bsl.id AND bsr.isactive = 1 |
|||
WHERE |
|||
bsl.isactive = 1 AND bsl.isdelete = 0 |
|||
AND bsl.zone = '01' |
|||
GROUP BY |
|||
bsl.ward |
|||
ORDER BY |
|||
bsl.ward; |
|||
*/ |
|||
} |
|||
@ -0,0 +1,177 @@ |
|||
package in.gov.chennaicorporation.mobileservice.constructionGuidelines.controller; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import in.gov.chennaicorporation.mobileservice.constructionGuidelines.service.GuidelinesService; |
|||
|
|||
@RequestMapping("/gccofficialapp/api/constructionguidelines/") |
|||
@RestController("gccofficialappsconstructionguidelines") |
|||
public class APIController { |
|||
@Autowired |
|||
private GuidelinesService guidelinesService; |
|||
|
|||
@GetMapping(value="/getConstructionList") |
|||
public List<?> getToiletsList( |
|||
@RequestParam(value="loginId", required = true) String cby, |
|||
@RequestParam(value = "latitude", required = true) String latitude, |
|||
@RequestParam(value = "longitude", required = true) String longitude |
|||
){ |
|||
return guidelinesService.getConstructionList(cby,latitude,longitude); |
|||
} |
|||
|
|||
@GetMapping(value="/getUnitOfficeList") |
|||
public List<?> getUnitOfficeList( |
|||
@RequestParam(value="zone", required = true) String zone, |
|||
@RequestParam(value="ward", required = true) String ward |
|||
){ |
|||
return guidelinesService.getUnitOfficeList(zone,ward); |
|||
} |
|||
|
|||
@GetMapping(value="/getBuildingType") |
|||
public List<?> getBuildingTypeList(){ |
|||
return guidelinesService.getBuildingTypeList(); |
|||
} |
|||
|
|||
@PostMapping(value="/saveDetails") |
|||
public List<Map<String, Object>> saveConstructionDetails( |
|||
@RequestParam(value = "contractor_name", required = true) String contractorName, |
|||
@RequestParam(value = "contractor_mobile", required = true) String contractorMobile, |
|||
@RequestParam(value = "buildup_area", required = true) String buildupArea, |
|||
@RequestParam(value = "building_type", required = true) String buildingType, |
|||
@RequestParam(value = "high_rise", required = true) String highRise, |
|||
@RequestParam(value = "zone", required = true) String zone, |
|||
@RequestParam(value = "ward", required = true) String ward, |
|||
@RequestParam(value = "unit", required = true) String unit, |
|||
@RequestParam(value = "under_guidelines", required = true) String underGuidelines, |
|||
@RequestParam(value = "site_address", required = true) String siteAddress, |
|||
@RequestParam(value = "cby", required = true) String cby, |
|||
@RequestParam(value = "latitude", required = true) String latitude, |
|||
@RequestParam(value = "longitude", required = true) String longitude, |
|||
@RequestParam(value = "mainfile", required = true) MultipartFile mainFile |
|||
){ |
|||
return guidelinesService.saveConstructionDetails( |
|||
contractorName, contractorMobile, buildupArea, buildingType, highRise, |
|||
zone, ward, unit, underGuidelines, siteAddress, cby, latitude, longitude, mainFile |
|||
); |
|||
} |
|||
|
|||
@GetMapping(value="/getguidelines") |
|||
public List<?> getGuidelinesList(){ |
|||
return guidelinesService.getGuidelinesList(); |
|||
} |
|||
|
|||
@PostMapping(value="/saveFeedback") |
|||
public List<?> saveGuidelinesFeedback( |
|||
@RequestParam(value = "cdid", required = true) String cdid, |
|||
@RequestParam(value = "ciid", required = true) String ciid, |
|||
@RequestParam(value = "cby", required = true) String cby, |
|||
@RequestParam(value = "latitude", required = true) String latitude, |
|||
@RequestParam(value = "longitude", required = true) String longitude, |
|||
@RequestParam(value = "zone", required = true) String zone, |
|||
@RequestParam(value = "ward", required = true) String ward, |
|||
@RequestParam(value = "q1", required = true) String q1, |
|||
@RequestParam(value = "q2", required = true) String q2, |
|||
@RequestParam(value = "q3", required = true) String q3, |
|||
@RequestParam(value = "q4", required = true) String q4, |
|||
@RequestParam(value = "q5", required = true) String q5, |
|||
@RequestParam(value = "q6", required = true) String q6, |
|||
@RequestParam(value = "q7", required = true) String q7, |
|||
@RequestParam(value = "q8", required = true) String q8, |
|||
@RequestParam(value = "q9", required = true) String q9, |
|||
@RequestParam(value = "q10", required = true) String q10, |
|||
@RequestParam(value = "q11", required = true) String q11, |
|||
@RequestParam(value = "q12", required = true) String q12, |
|||
@RequestParam(value = "q13", required = true) String q13, |
|||
@RequestParam(value = "q14", required = true) String q14, |
|||
@RequestParam(value = "q15", required = true) String q15, |
|||
@RequestParam(value = "q16", required = true) String q16, |
|||
@RequestParam(value = "q17", required = true) String q17, |
|||
@RequestParam(value = "q18", required = true) String q18, |
|||
@RequestParam(value = "image1", required = true) MultipartFile image1, |
|||
@RequestParam(value = "image2", required = true) MultipartFile image2, |
|||
@RequestParam(value = "image3", required = true) MultipartFile image3, |
|||
@RequestParam(value = "image4", required = true) MultipartFile image4, |
|||
@RequestParam(value = "image5", required = true) MultipartFile image5 |
|||
){ |
|||
return guidelinesService.saveGuidlinesFeedback( |
|||
cdid, ciid, cby, latitude, longitude, zone, ward, |
|||
q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, |
|||
q11, q12, q13, q14, q15, q16, q17, q18, |
|||
image1, image2, image3, image4, image5 |
|||
); |
|||
} |
|||
|
|||
@GetMapping(value="/getRevisitConstructionList") |
|||
public List<?> getRevisitConstructionList( |
|||
@RequestParam(value="loginId", required = true) String cby, |
|||
@RequestParam(value = "latitude", required = true) String latitude, |
|||
@RequestParam(value = "longitude", required = true) String longitude |
|||
){ |
|||
return guidelinesService.getRevisitConstructionList(cby,latitude,longitude); |
|||
} |
|||
|
|||
@GetMapping(value="/getRevisitConstructionListWithFeedback") |
|||
public List<?> getRevisitConstructionListWithFeedback( |
|||
@RequestParam(value="loginId", required = true) String cby, |
|||
@RequestParam(value = "cdid", required = true) String cdid, |
|||
@RequestParam(value = "ciid", required = true) String ciid |
|||
){ |
|||
return guidelinesService.getRevisitConstructionListWithFeedback(cby,cdid,ciid); |
|||
} |
|||
|
|||
@GetMapping(value="/get7thRevisitConstructionList") |
|||
public List<?> get7RevisitConstructionList( |
|||
@RequestParam(value="loginId", required = true) String cby, |
|||
@RequestParam(value = "latitude", required = true) String latitude, |
|||
@RequestParam(value = "longitude", required = true) String longitude |
|||
){ |
|||
return guidelinesService.getRevisitConstructionList(cby,latitude,longitude); |
|||
} |
|||
|
|||
@PostMapping(value = "/saveAfterNoticeDetails") |
|||
public List<Map<String, Object>> saveAfterNoticeDetails( |
|||
@RequestParam(value = "cdid", required = true) String cdid, |
|||
@RequestParam(value = "ciid", required = true) String ciid, |
|||
@RequestParam(value = "giid", required = true) String giid, |
|||
@RequestParam(value = "remarks", required = true) String remarks, |
|||
@RequestParam(value = "status", required = true) String status, |
|||
@RequestParam(value = "zone", required = true) String zone, |
|||
@RequestParam(value = "ward", required = true) String ward, |
|||
@RequestParam(value = "loginId", required = true) String cby, |
|||
@RequestParam(value = "latitude", required = true) String latitude, |
|||
@RequestParam(value = "longitude", required = true) String longitude, |
|||
@RequestParam(value = "mainfile", required = true) MultipartFile mainfile |
|||
) { |
|||
return guidelinesService.saveAfterNoticeDetails( |
|||
cdid, ciid, giid, remarks, status, zone, ward, cby, latitude, longitude, mainfile |
|||
); |
|||
} |
|||
|
|||
@PostMapping(value = "/saveFinalNoticeDetails") |
|||
public List<Map<String, Object>> saveFinalNoticeDetails( |
|||
@RequestParam(value = "cdid", required = true) String cdid, |
|||
@RequestParam(value = "ciid", required = true) String ciid, |
|||
@RequestParam(value = "giid", required = true) String giid, |
|||
@RequestParam(value = "remarks", required = true) String remarks, |
|||
@RequestParam(value = "status", required = true) String status, |
|||
@RequestParam(value = "zone", required = true) String zone, |
|||
@RequestParam(value = "ward", required = true) String ward, |
|||
@RequestParam(value = "loginId", required = true) String cby, |
|||
@RequestParam(value = "latitude", required = true) String latitude, |
|||
@RequestParam(value = "longitude", required = true) String longitude, |
|||
@RequestParam(value = "mainfile", required = true) MultipartFile mainfile |
|||
) { |
|||
return guidelinesService.saveFinalNoticeDetails( |
|||
cdid, ciid, giid, remarks, status, zone, ward, cby, latitude, longitude, mainfile |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.constructionGuidelines.controller; |
|||
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.constructionGuidelines; |
|||
@ -0,0 +1,983 @@ |
|||
package in.gov.chennaicorporation.mobileservice.constructionGuidelines.service; |
|||
|
|||
import java.awt.image.BufferedImage; |
|||
import java.io.ByteArrayInputStream; |
|||
import java.io.ByteArrayOutputStream; |
|||
import java.io.IOException; |
|||
import java.net.URLEncoder; |
|||
import java.nio.charset.StandardCharsets; |
|||
import java.nio.file.Files; |
|||
import java.nio.file.Path; |
|||
import java.nio.file.Paths; |
|||
import java.security.SecureRandom; |
|||
import java.sql.PreparedStatement; |
|||
import java.time.LocalDate; |
|||
import java.time.LocalDateTime; |
|||
import java.time.format.DateTimeFormatter; |
|||
import java.util.ArrayList; |
|||
import java.util.Collections; |
|||
import java.util.HashMap; |
|||
import java.util.LinkedHashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.Random; |
|||
|
|||
import javax.imageio.ImageIO; |
|||
import javax.imageio.ImageWriteParam; |
|||
import javax.imageio.ImageWriter; |
|||
import javax.imageio.stream.ImageOutputStream; |
|||
import javax.sql.DataSource; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Qualifier; |
|||
import org.springframework.core.env.Environment; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
import org.springframework.jdbc.support.GeneratedKeyHolder; |
|||
import org.springframework.jdbc.support.KeyHolder; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import in.gov.chennaicorporation.mobileservice.gccactivity.service.DateTimeUtil; |
|||
|
|||
@Service |
|||
public class GuidelinesService { |
|||
private JdbcTemplate jdbcGuidlines; |
|||
private final Environment environment; |
|||
private String fileBaseUrl; |
|||
|
|||
private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
|||
private static final int STRING_LENGTH = 15; |
|||
private static final Random RANDOM = new SecureRandom(); |
|||
|
|||
@Autowired |
|||
public void setDataSource(@Qualifier("mysqlGccConstructionGuidelinesSource") DataSource guidlinesDataSource) { |
|||
this.jdbcGuidlines = new JdbcTemplate(guidlinesDataSource); |
|||
} |
|||
|
|||
@Autowired |
|||
public GuidelinesService(Environment environment) { |
|||
this.environment = environment; |
|||
this.fileBaseUrl=environment.getProperty("fileBaseUrl"); |
|||
} |
|||
|
|||
public static String generateRandomString() { |
|||
StringBuilder result = new StringBuilder(STRING_LENGTH); |
|||
for (int i = 0; i < STRING_LENGTH; i++) { |
|||
result.append(CHARACTERS.charAt(RANDOM.nextInt(CHARACTERS.length()))); |
|||
} |
|||
return result.toString(); |
|||
} |
|||
|
|||
public static String generateRandomFileString(int lenthval) { |
|||
StringBuilder result = new StringBuilder(lenthval); |
|||
for (int i = 0; i < lenthval; i++) { |
|||
result.append(CHARACTERS.charAt(RANDOM.nextInt(CHARACTERS.length()))); |
|||
} |
|||
return result.toString(); |
|||
} |
|||
|
|||
private byte[] compressImage(BufferedImage image, float quality) throws IOException { |
|||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
|||
ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(byteArrayOutputStream); |
|||
|
|||
ImageWriter writer = ImageIO.getImageWritersByFormatName("jpg").next(); |
|||
writer.setOutput(imageOutputStream); |
|||
|
|||
ImageWriteParam param = writer.getDefaultWriteParam(); |
|||
if (param.canWriteCompressed()) { |
|||
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
|||
param.setCompressionQuality(quality); |
|||
} |
|||
|
|||
writer.write(null, new javax.imageio.IIOImage(image, null, null), param); |
|||
|
|||
writer.dispose(); |
|||
imageOutputStream.close(); |
|||
|
|||
return byteArrayOutputStream.toByteArray(); |
|||
} |
|||
|
|||
public String fileUpload(String name, String id, MultipartFile file) { |
|||
|
|||
int lastInsertId = 0; |
|||
// Set the file path where you want to save it |
|||
String uploadDirectory = environment.getProperty("file.upload.directory"); |
|||
String serviceFolderName = environment.getProperty("construction_guidelines_foldername"); |
|||
var year = DateTimeUtil.getCurrentYear(); |
|||
var month = DateTimeUtil.getCurrentMonth(); |
|||
var date = DateTimeUtil.getCurrentDay(); |
|||
|
|||
uploadDirectory = uploadDirectory + serviceFolderName + year + "/" + month + "/" + date; |
|||
|
|||
try { |
|||
// Create directory if it doesn't exist |
|||
Path directoryPath = Paths.get(uploadDirectory); |
|||
if (!Files.exists(directoryPath)) { |
|||
Files.createDirectories(directoryPath); |
|||
} |
|||
|
|||
// Datetime string |
|||
String datetimetxt = DateTimeUtil.getCurrentDateTime(); |
|||
|
|||
datetimetxt = datetimetxt + "_"+ generateRandomFileString(6); // Attached Random text |
|||
|
|||
// File name |
|||
String fileName = name + "_" + id + "_" + datetimetxt + "_" + file.getOriginalFilename(); |
|||
fileName = fileName.replaceAll("\\s+", ""); // Remove space on filename |
|||
|
|||
String filePath = uploadDirectory + "/" + fileName; |
|||
|
|||
String filepath_txt = "/" + serviceFolderName + year + "/" + month + "/" + date + "/" + fileName; |
|||
|
|||
// Create a new Path object |
|||
Path path = Paths.get(filePath); |
|||
|
|||
// Get the bytes of the file |
|||
byte[] bytes = file.getBytes(); |
|||
|
|||
// Compress the image |
|||
BufferedImage image = ImageIO.read(new ByteArrayInputStream(bytes)); |
|||
byte[] compressedBytes = compressImage(image, 0.5f); // Compress with 50% quality |
|||
|
|||
// Write the bytes to the file |
|||
Files.write(path, compressedBytes); |
|||
|
|||
System.out.println(filePath); |
|||
return filepath_txt; |
|||
|
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
return "Failed to save file " + file.getOriginalFilename(); |
|||
} |
|||
} |
|||
|
|||
public List<Map<String, Object>> getConstructionList(String loginid, |
|||
String latitude, |
|||
String longitude) { |
|||
String sql = "SELECT cd.*" |
|||
+ ",CONCAT('"+fileBaseUrl+"/gccofficialapp/files',cd.image) AS photo," |
|||
+ "ci.`ciid`, ci.`under_guidelines`, ci.`penalty` " |
|||
+ " FROM `construction_details` cd " |
|||
+ "LEFT JOIN `construction_inspection` ci ON ci.cdid=cd.cdid " |
|||
+ "WHERE cd.`isactive`=1 AND ci.`isactive`=1"; |
|||
List<Map<String, Object>> result = jdbcGuidlines.queryForList(sql); |
|||
|
|||
for (Map<String, Object> row : result) { |
|||
String downloadLink =""; |
|||
if(row.get("penalty") != null) { |
|||
downloadLink = "https://gccservices.in/gccofficialapp/api/pdf/template?" |
|||
+ "cdid="+row.get("cdid") |
|||
+ "&ciid="+row.get("ciid"); |
|||
} |
|||
row.put("downloadNoticeLink", downloadLink); |
|||
} |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Construction List."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getBuildingTypeList() { |
|||
String sql = "SELECT * FROM `building_type_master` WHERE `isactive`=1"; |
|||
List<Map<String, Object>> result = jdbcGuidlines.queryForList(sql); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Building Type List."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getUnitOfficeList(String zone, String ward) { |
|||
String sql = "SELECT * FROM `unit_office_master` WHERE `zone`=? AND `ward`=?"; |
|||
List<Map<String, Object>> result = jdbcGuidlines.queryForList(sql,zone, ward); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Unit Office List."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getGuidelinesList() { |
|||
String sql = "SELECT * FROM `guidelines` WHERE `isactive`=1 ORDER BY `orderby`"; |
|||
List<Map<String, Object>> result = jdbcGuidlines.queryForList(sql); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Unit Office List."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> saveConstructionDetails( |
|||
String contractor_name, |
|||
String contractor_mobile, |
|||
String buildup_area, |
|||
String building_type, |
|||
String high_rise, |
|||
String zone, |
|||
String ward, |
|||
String unit, |
|||
String under_guidelines, |
|||
String site_address, |
|||
String cby, |
|||
String latitude, |
|||
String longitude, |
|||
MultipartFile mainfile |
|||
) { |
|||
Map<String, Object> response = new HashMap<>(); |
|||
List<Map<String, Object>> result = new ArrayList<>(); |
|||
|
|||
String constimg = fileUpload("Construction", "main", mainfile); |
|||
|
|||
String type = ""; |
|||
|
|||
// Prepare question image uploads |
|||
MultipartFile[] files = { |
|||
mainfile |
|||
}; |
|||
|
|||
// Insert query |
|||
String insertSql = "INSERT INTO `construction_details`(`contractor_name`, `contractor_mobile`, `buildup_area`, " |
|||
+ "`building_type`, `high_rise`, `zone`, `ward`, `unit`, `site_address`, `cby`, `latitude`, `longitude`, " |
|||
+ "`image`) VALUES " |
|||
+ "(?,?,?,?,?,?,?,?,?,?,?,?,?)"; |
|||
|
|||
KeyHolder keyHolder = new GeneratedKeyHolder(); |
|||
|
|||
int affectedRows = jdbcGuidlines.update(connection -> { |
|||
PreparedStatement ps = connection.prepareStatement(insertSql, new String[]{"cdid"}); |
|||
int i = 1; |
|||
ps.setString(i++, contractor_name); |
|||
ps.setString(i++, contractor_mobile); |
|||
ps.setString(i++, buildup_area); |
|||
ps.setString(i++, building_type); |
|||
ps.setString(i++, high_rise); |
|||
ps.setString(i++, zone); |
|||
ps.setString(i++, ward); |
|||
ps.setString(i++, unit); |
|||
ps.setString(i++, site_address); |
|||
ps.setString(i++, cby); |
|||
ps.setString(i++, latitude); |
|||
ps.setString(i++, longitude); |
|||
ps.setString(i++, constimg); |
|||
return ps; |
|||
}, keyHolder); |
|||
|
|||
if (affectedRows > 0) { |
|||
int lastInsertId = keyHolder.getKey().intValue(); |
|||
int cdid = saveConstructionInspection(lastInsertId, under_guidelines, cby); |
|||
if(cdid>0) { |
|||
response.put("insertId", lastInsertId); |
|||
response.put("status", "success"); |
|||
response.put("message", "New Construction details inserted successfully."); |
|||
} |
|||
else { |
|||
response.put("status", "error"); |
|||
response.put("message", "New Construction details insert failed."); |
|||
} |
|||
|
|||
} else { |
|||
response.put("status", "error"); |
|||
response.put("message", "New Construction details insert failed."); |
|||
} |
|||
|
|||
result.add(response); |
|||
return result; |
|||
} |
|||
|
|||
@Transactional |
|||
public int saveConstructionInspection(int cdid, String under_guidelines, String cby) { |
|||
int ciid = 0; |
|||
// Insert query |
|||
String insertSql = "INSERT INTO `construction_inspection`(`cdid`, `under_guidelines`, `cby`) VALUES " |
|||
+ "(?,?,?)"; |
|||
|
|||
KeyHolder keyHolder = new GeneratedKeyHolder(); |
|||
|
|||
int affectedRows = jdbcGuidlines.update(connection -> { |
|||
PreparedStatement ps = connection.prepareStatement(insertSql, new String[]{"ciid"}); |
|||
int i = 1; |
|||
ps.setInt(i++, cdid); |
|||
ps.setString(i++, under_guidelines); |
|||
ps.setString(i++, cby); |
|||
return ps; |
|||
}, keyHolder); |
|||
|
|||
if (affectedRows > 0) { |
|||
int lastInsertId = keyHolder.getKey().intValue(); |
|||
ciid = lastInsertId; |
|||
} else { |
|||
// ❗ Rollback action: mark the original cdid as inactive |
|||
String updateSql = "UPDATE `construction_details` SET `isactive` = 0 WHERE `cdid` = ?"; |
|||
jdbcGuidlines.update(updateSql, cdid); |
|||
} |
|||
return ciid; |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> saveGuidlinesFeedback( |
|||
String cdid, |
|||
String ciid, |
|||
String cby, |
|||
String latitude, |
|||
String longitude, |
|||
String zone, |
|||
String ward, |
|||
String q1, String q2, String q3, String q4, String q5, String q6, String q7, String q8, String q9, String q10, |
|||
String q11, String q12, String q13, String q14, String q15, String q16, String q17, String q18, |
|||
MultipartFile image1, MultipartFile image2, MultipartFile image3, MultipartFile image4, MultipartFile image5 |
|||
) { |
|||
Map<String, Object> response = new HashMap<>(); |
|||
List<Map<String, Object>> result = new ArrayList<>(); |
|||
|
|||
String type = ""; |
|||
|
|||
// Prepare question image uploads |
|||
MultipartFile[] files = { |
|||
image1, image2, image3, image4, image5 |
|||
}; |
|||
String[] imagePaths = new String[5]; |
|||
for (int i = 0; i < files.length; i++) { |
|||
if (files[i] != null && !files[i].isEmpty()) { |
|||
imagePaths[i] = fileUpload(cdid, "_"+ciid+"_"+(i + 1), files[i]); |
|||
} else { |
|||
imagePaths[i] = ""; |
|||
} |
|||
} |
|||
|
|||
// Insert query |
|||
String insertSql = "INSERT INTO `guildelines_inspection` " |
|||
+ "(`cdid`, `ciid`, `cby`, `latitude`, `longitude`, `zone`, `ward`," |
|||
+ "`q1`, `q2`, `q3`, `q4`, `q5`, `q6`, `q7`, `q8`, `q9`, `q10`, " |
|||
+ "`q11`, `q12`, `q13`, `q14`, `q15`, `q16`, `q17`, `q18`, " |
|||
+ "`img1`, `img2`, `img3`, `img4`, `img5`) " + |
|||
"VALUES (" + "?,".repeat(7 + 18 + 5).replaceAll(",$", "") + ")"; |
|||
|
|||
KeyHolder keyHolder = new GeneratedKeyHolder(); |
|||
|
|||
int affectedRows = jdbcGuidlines.update(connection -> { |
|||
PreparedStatement ps = connection.prepareStatement(insertSql, new String[]{"giid"}); |
|||
int i = 1; |
|||
ps.setString(i++, cdid); |
|||
ps.setString(i++, ciid); |
|||
ps.setString(i++, cby); |
|||
ps.setString(i++, latitude); |
|||
ps.setString(i++, longitude); |
|||
ps.setString(i++, zone); |
|||
ps.setString(i++, ward); |
|||
|
|||
// 18 question answers |
|||
for (String q : new String[]{q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, |
|||
q11, q12, q13, q14, q15, q16, q17, q18}) { |
|||
ps.setString(i++, q); |
|||
} |
|||
|
|||
// 5 image paths |
|||
for (String path : imagePaths) { |
|||
ps.setString(i++, path); |
|||
} |
|||
|
|||
return ps; |
|||
}, keyHolder); |
|||
|
|||
if (affectedRows > 0) { |
|||
int lastInsertId = keyHolder.getKey().intValue(); |
|||
response.put("insertId", lastInsertId); |
|||
// Get penalty type |
|||
String penalty= findPenaltyType(q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, |
|||
q11, q12, q13, q14, q15, q16, q17, q18); |
|||
|
|||
if(updateConstructionInspection(lastInsertId, ciid, cdid, penalty)) { |
|||
response.put("status", "success"); |
|||
response.put("message", "Feedback inserted successfully."); |
|||
} |
|||
else { |
|||
response.put("status", "error"); |
|||
response.put("message", "Feedback Insert failed."); |
|||
} |
|||
} else { |
|||
response.put("status", "error"); |
|||
response.put("message", "Insert failed."); |
|||
} |
|||
|
|||
result.add(response); |
|||
return result; |
|||
} |
|||
|
|||
@Transactional |
|||
public boolean updateConstructionInspection(int giid, String ciid, String cdid, String penalty) { |
|||
String updateCISql = "UPDATE `construction_inspection` SET `penalty` = ? WHERE ciid = ? AND cdid = ?"; |
|||
|
|||
int affectedRows = jdbcGuidlines.update(updateCISql, penalty, ciid, cdid); |
|||
|
|||
if (affectedRows > 0) { |
|||
return true; |
|||
} else { |
|||
// Optional rollback: mark original inspection inactive |
|||
String updateSql = "UPDATE `guildelines_inspection` SET `isactive` = 0 WHERE giid = ?"; |
|||
jdbcGuidlines.update(updateSql, giid); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
private String findPenaltyType(String q1, String q2, String q3, String q4, String q5, String q6, String q7, String q8, String q9, String q10, |
|||
String q11, String q12, String q13, String q14, String q15, String q16, String q17, String q18) { |
|||
// Check High Penalty: any of q1–q14 is "No" |
|||
if ("No".equalsIgnoreCase(q1) || "No".equalsIgnoreCase(q2) || "No".equalsIgnoreCase(q3) || |
|||
"No".equalsIgnoreCase(q4) || "No".equalsIgnoreCase(q5) || "No".equalsIgnoreCase(q6) || |
|||
"No".equalsIgnoreCase(q7) || "No".equalsIgnoreCase(q8) || "No".equalsIgnoreCase(q9) || |
|||
"No".equalsIgnoreCase(q10) || "No".equalsIgnoreCase(q11) || "No".equalsIgnoreCase(q12) || |
|||
"No".equalsIgnoreCase(q13) || "No".equalsIgnoreCase(q14)) |
|||
{ |
|||
return "High"; |
|||
} |
|||
// Check Medium Penalty: any of q15–q17 is "No" |
|||
if("No".equalsIgnoreCase(q15) || "No".equalsIgnoreCase(q16) || "No".equalsIgnoreCase(q17)) |
|||
{ |
|||
return "Medium"; |
|||
} |
|||
// Default to Low Penalty |
|||
return "Low"; |
|||
} |
|||
/* |
|||
public List<Map<String, Object>> getRevisitConstructionList(String loginid, String latitude, String longitude) { |
|||
String sql = "SELECT cd.*, " |
|||
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', cd.image) AS photo, " |
|||
+ "ci.ciid, ci.under_guidelines, ci.penalty " |
|||
+ "FROM construction_details cd " |
|||
+ "LEFT JOIN construction_inspection ci ON ci.cdid = cd.cdid " |
|||
+ "WHERE cd.isactive = 1 AND ci.isactive = 1 AND ci.penalty IN ('High','Medium','Low')"; |
|||
|
|||
List<Map<String, Object>> result = jdbcGuidlines.queryForList(sql); |
|||
|
|||
for (Map<String, Object> row : result) { |
|||
|
|||
Boolen allowRevisit = false; |
|||
Object cdate = row.get("cdate"); |
|||
Object finalDate = cdate + 15 Days |
|||
if(finalDate>todaydate) { |
|||
allowRevisit = true; |
|||
} |
|||
row.put("allowRevisit", allowRevisit); |
|||
|
|||
String downloadLink = "https://gccservices.in/gccofficialapp/api/pdf/template?" |
|||
+ "cdid="+row.get("cdid") |
|||
+ "&ciid="+row.get("ciid"); |
|||
|
|||
row.put("downloadNoticeLink", downloadLink); |
|||
} |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Construction List with Guidelines & Answers."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
*/ |
|||
|
|||
public List<Map<String, Object>> getRevisitConstructionList(String loginid, String latitude, String longitude) { |
|||
String sql = "SELECT cd.*, " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', cd.image) AS photo, " + |
|||
"ci.ciid, ci.under_guidelines, ci.penalty " + |
|||
"FROM construction_details cd " + |
|||
"LEFT JOIN construction_inspection ci ON ci.cdid = cd.cdid " + |
|||
"WHERE cd.isactive = 1 AND ci.isactive = 1 AND ci.penalty IN ('High','Medium','Low')" |
|||
+ "AND cd.cdid NOT IN ( " |
|||
+ " SELECT cdid " |
|||
+ " FROM after_notice_inspection " |
|||
+ " WHERE isactive = 1 " |
|||
+ " )"; |
|||
|
|||
List<Map<String, Object>> result = jdbcGuidlines.queryForList(sql); |
|||
|
|||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|||
LocalDate today = LocalDate.now(); |
|||
|
|||
for (Map<String, Object> row : result) { |
|||
Boolean allowRevisit = false; |
|||
Object cdateObj = row.get("cdate"); |
|||
/* |
|||
if (cdateObj != null) { |
|||
System.err.println("Raw cdate type: " + cdateObj.getClass().getName() + " | value: " + cdateObj); |
|||
} |
|||
*/ |
|||
|
|||
if (cdateObj != null) { |
|||
LocalDate cdate = null; |
|||
|
|||
if (cdateObj instanceof LocalDate) { |
|||
cdate = (LocalDate) cdateObj; |
|||
} else if (cdateObj instanceof java.sql.Date) { |
|||
cdate = ((java.sql.Date) cdateObj).toLocalDate(); |
|||
} else if (cdateObj instanceof java.sql.Timestamp) { |
|||
cdate = ((java.sql.Timestamp) cdateObj).toLocalDateTime().toLocalDate(); |
|||
} else if (cdateObj instanceof LocalDateTime) { |
|||
cdate = ((LocalDateTime) cdateObj).toLocalDate(); // ✅ FIX |
|||
} else if (cdateObj instanceof String) { |
|||
try { |
|||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|||
cdate = LocalDateTime.parse((String) cdateObj, dtf).toLocalDate(); |
|||
} catch (Exception e) { |
|||
System.err.println("❌ Could not parse cdate: " + cdateObj); |
|||
} |
|||
} |
|||
|
|||
if (cdate != null) { |
|||
LocalDate finalDate = cdate.plusDays(15); |
|||
allowRevisit = !today.isBefore(finalDate); // true if today >= finalDate |
|||
/* |
|||
System.err.println("ID: " + row.get("cdid") |
|||
+ " | finalDate: " + finalDate |
|||
+ " | today: " + today |
|||
+ " | allowRevisit: " + allowRevisit); |
|||
/* |
|||
if (finalDate.isBefore(today) || finalDate.isEqual(today)) { |
|||
allowRevisit = true; |
|||
} |
|||
*/ |
|||
} |
|||
} |
|||
|
|||
row.put("allowRevisit", allowRevisit); |
|||
|
|||
String downloadLink = "https://gccservices.in/gccofficialapp/api/pdf/template?" + |
|||
"cdid=" + row.get("cdid") + |
|||
"&ciid=" + row.get("ciid"); |
|||
|
|||
row.put("downloadNoticeLink", downloadLink); |
|||
} |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Construction List with Guidelines & Answers."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getRevisitConstructionListWithFeedback(String loginid, String cdidtxt, String ciidtxt) { |
|||
String sql = "SELECT cd.*, " |
|||
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', cd.image) AS photo, " |
|||
+ "DATE_FORMAT(cd.cdate, '%d-%m-%Y') AS ddate, " |
|||
+ "ci.ciid, ci.under_guidelines, ci.penalty " |
|||
+ "FROM construction_details cd " |
|||
+ "LEFT JOIN construction_inspection ci ON ci.cdid = cd.cdid " |
|||
+ "WHERE cd.isactive = 1 AND ci.isactive = 1 AND ci.penalty IN ('High','Medium','Low') AND cd.cdid=? AND ci.ciid=?"; |
|||
|
|||
List<Map<String, Object>> result = jdbcGuidlines.queryForList(sql, cdidtxt, ciidtxt); |
|||
|
|||
// Fetch master guideline list only once |
|||
String guidelinesSql = "SELECT `gid`, `guideline`, `significance`, `orderby`, `isactive` FROM guidelines WHERE isactive = 1 ORDER BY orderby"; |
|||
List<Map<String, Object>> guidelineList = jdbcGuidlines.queryForList(guidelinesSql); |
|||
|
|||
for (Map<String, Object> row : result) { |
|||
Object cdid = row.get("cdid"); |
|||
Object ciid = row.get("ciid"); |
|||
|
|||
// Fetch answer row for this cdid + ciid |
|||
String ansSql = "SELECT `giid`, `cdate`, `q1`, `q2`, `q3`, `q4`, `q5`, `q6`, `q7`, `q8`, `q9`, `q10`, `q11`, `q12`, `q13`, `q14`, `q15`, `q16`, `q17`, `q18`, " |
|||
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', img1) AS photo1, " |
|||
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', img2) AS photo2, " |
|||
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', img3) AS photo3, " |
|||
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', img4) AS photo4, " |
|||
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', img5) AS photo5 " |
|||
+ "FROM guildelines_inspection WHERE isactive = 1 AND cdid = ? AND ciid = ? LIMIT 1"; |
|||
List<Map<String, Object>> ansList = jdbcGuidlines.queryForList(ansSql, cdid, ciid); |
|||
|
|||
Map<String, Object> answers = ansList.isEmpty() ? new HashMap<>() : ansList.get(0); |
|||
|
|||
// Merge each guideline with its corresponding answer |
|||
List<Map<String, Object>> guidelineWithAnswers = new ArrayList<>(); |
|||
for (int i = 1; i <= guidelineList.size(); i++) { |
|||
Map<String, Object> guideline = guidelineList.get(i - 1); |
|||
String qKey = "q" + i; |
|||
Map<String, Object> qa = new LinkedHashMap<>(); |
|||
qa.put("question", guideline.get("guideline")); |
|||
qa.put("question_type", guideline.get("significance")); |
|||
qa.put("answer", answers.getOrDefault(qKey, "")); |
|||
guidelineWithAnswers.add(qa); |
|||
} |
|||
|
|||
List<Map<String, Object>> guidelineWithImages = new ArrayList<>(); |
|||
Map<String, Object> qa_img = new LinkedHashMap<>(); |
|||
qa_img.put("image1", answers.get("photo1")); |
|||
qa_img.put("image2", answers.get("photo2")); |
|||
qa_img.put("image3", answers.get("photo3")); |
|||
qa_img.put("image4", answers.get("photo4")); |
|||
qa_img.put("image5", answers.get("photo5")); |
|||
guidelineWithImages.add(qa_img); |
|||
|
|||
// attach to response |
|||
row.put("guidelines_id", answers.get("giid")); |
|||
row.put("guidelines_images", guidelineWithImages); |
|||
row.put("guidelines_answers", guidelineWithAnswers); |
|||
} |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Construction List with Guidelines & Answers."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> saveAfterNoticeDetails( |
|||
String cdid, |
|||
String ciid, |
|||
String giid, |
|||
String remarks, |
|||
String status, |
|||
String zone, |
|||
String ward, |
|||
String cby, |
|||
String latitude, |
|||
String longitude, |
|||
MultipartFile mainfile |
|||
) { |
|||
Map<String, Object> response = new HashMap<>(); |
|||
List<Map<String, Object>> result = new ArrayList<>(); |
|||
|
|||
String constimg = fileUpload("After_Notice",cdid+"_"+ciid+"_"+giid+"_"+status , mainfile); |
|||
|
|||
String type = ""; |
|||
|
|||
// Prepare question image uploads |
|||
MultipartFile[] files = { |
|||
mainfile |
|||
}; |
|||
|
|||
// Insert query |
|||
String insertSql = "INSERT INTO `after_notice_inspection`(`cdid`, `ciid`, `giid`, `image1`, `remarks`, `zone`, `ward`, `latitude`, `longitude`, `cby`, `status`) VALUES " |
|||
+ "(?,?,?,?,?,?,?,?,?,?,?)"; |
|||
|
|||
KeyHolder keyHolder = new GeneratedKeyHolder(); |
|||
|
|||
int affectedRows = jdbcGuidlines.update(connection -> { |
|||
PreparedStatement ps = connection.prepareStatement(insertSql, new String[]{"cdid"}); |
|||
int i = 1; |
|||
ps.setString(i++, cdid); |
|||
ps.setString(i++, ciid); |
|||
ps.setString(i++, giid); |
|||
ps.setString(i++, constimg); |
|||
ps.setString(i++, remarks); |
|||
ps.setString(i++, zone); |
|||
ps.setString(i++, ward); |
|||
ps.setString(i++, latitude); |
|||
ps.setString(i++, longitude); |
|||
ps.setString(i++, cby); |
|||
ps.setString(i++, status); |
|||
return ps; |
|||
}, keyHolder); |
|||
|
|||
if (affectedRows > 0) { |
|||
int lastInsertId = keyHolder.getKey().intValue(); |
|||
response.put("insertId", lastInsertId); |
|||
response.put("status", "success"); |
|||
response.put("message", "New After Notice details inserted successfully."); |
|||
} else { |
|||
response.put("status", "error"); |
|||
response.put("message", "New After Notice details insert failed."); |
|||
} |
|||
|
|||
result.add(response); |
|||
return result; |
|||
} |
|||
|
|||
public List<Map<String, Object>> get7thRevisitConstructionList(String loginid, String latitude, String longitude) { |
|||
String sql = "SELECT cd.*, " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', cd.image) AS photo, " + |
|||
"ci.ciid, ci.under_guidelines, ci.penalty " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', ani.image1) AS finephoto, " + |
|||
"date_format(ani.cdate, '%d-%m-%Y') as Fine Date, " + |
|||
"ani.cdate as finedate " + |
|||
"FROM construction_details cd " + |
|||
"LEFT JOIN construction_inspection ci ON ci.cdid = cd.cdid " + |
|||
"LEFT JOIN after_notice_inspection ani ON ani.cdid = cd.cdid " + |
|||
"WHERE cd.isactive = 1 AND ci.isactive = 1 AND ci.penalty IN ('High','Medium','Low')"; |
|||
|
|||
List<Map<String, Object>> result = jdbcGuidlines.queryForList(sql); |
|||
|
|||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|||
LocalDate today = LocalDate.now(); |
|||
|
|||
for (Map<String, Object> row : result) { |
|||
Boolean allowRevisit = false; |
|||
Object cdateObj = row.get("finedate"); |
|||
|
|||
if (cdateObj != null) { |
|||
System.err.println("Raw cdate type: " + cdateObj.getClass().getName() + " | value: " + cdateObj); |
|||
} |
|||
|
|||
if (cdateObj != null) { |
|||
LocalDate cdate = null; |
|||
|
|||
if (cdateObj instanceof LocalDate) { |
|||
cdate = (LocalDate) cdateObj; |
|||
} else if (cdateObj instanceof java.sql.Date) { |
|||
cdate = ((java.sql.Date) cdateObj).toLocalDate(); |
|||
} else if (cdateObj instanceof java.sql.Timestamp) { |
|||
cdate = ((java.sql.Timestamp) cdateObj).toLocalDateTime().toLocalDate(); |
|||
} else if (cdateObj instanceof LocalDateTime) { |
|||
cdate = ((LocalDateTime) cdateObj).toLocalDate(); // ✅ FIX |
|||
} else if (cdateObj instanceof String) { |
|||
try { |
|||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|||
cdate = LocalDateTime.parse((String) cdateObj, dtf).toLocalDate(); |
|||
} catch (Exception e) { |
|||
System.err.println("❌ Could not parse cdate: " + cdateObj); |
|||
} |
|||
} |
|||
|
|||
if (cdate != null) { |
|||
LocalDate finalDate = cdate.plusDays(7); |
|||
allowRevisit = !today.isBefore(finalDate); // true if today >= finalDate |
|||
|
|||
System.err.println("ID: " + row.get("cdid") |
|||
+ " | finalDate: " + finalDate |
|||
+ " | today: " + today |
|||
+ " | allowRevisit: " + allowRevisit); |
|||
/* |
|||
if (finalDate.isBefore(today) || finalDate.isEqual(today)) { |
|||
allowRevisit = true; |
|||
} |
|||
*/ |
|||
} |
|||
} |
|||
|
|||
row.put("allowRevisit", allowRevisit); |
|||
|
|||
String downloadLink = "https://gccservices.in/gccofficialapp/api/pdf/template?" + |
|||
"cdid=" + row.get("cdid") + |
|||
"&ciid=" + row.get("ciid"); |
|||
|
|||
row.put("downloadNoticeLink", downloadLink); |
|||
} |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Construction List with Guidelines & Answers."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> saveFinalNoticeDetails( |
|||
String cdid, |
|||
String ciid, |
|||
String giid, |
|||
String remarks, |
|||
String status, |
|||
String zone, |
|||
String ward, |
|||
String cby, |
|||
String latitude, |
|||
String longitude, |
|||
MultipartFile mainfile |
|||
) { |
|||
Map<String, Object> response = new HashMap<>(); |
|||
List<Map<String, Object>> result = new ArrayList<>(); |
|||
|
|||
String constimg = fileUpload("Final_Notice",cdid+"_"+ciid+"_"+giid+"_"+status , mainfile); |
|||
|
|||
String type = ""; |
|||
|
|||
// Prepare question image uploads |
|||
MultipartFile[] files = { |
|||
mainfile |
|||
}; |
|||
|
|||
// Insert query |
|||
String insertSql = "INSERT INTO `final_notice_inspection`(`cdid`, `ciid`, `giid`, `image1`, `remarks`, `zone`, `ward`, `latitude`, `longitude`, `cby`, `status`) VALUES " |
|||
+ "(?,?,?,?,?,?,?,?,?,?,?)"; |
|||
|
|||
KeyHolder keyHolder = new GeneratedKeyHolder(); |
|||
|
|||
int affectedRows = jdbcGuidlines.update(connection -> { |
|||
PreparedStatement ps = connection.prepareStatement(insertSql, new String[]{"cdid"}); |
|||
int i = 1; |
|||
ps.setString(i++, cdid); |
|||
ps.setString(i++, ciid); |
|||
ps.setString(i++, giid); |
|||
ps.setString(i++, constimg); |
|||
ps.setString(i++, remarks); |
|||
ps.setString(i++, zone); |
|||
ps.setString(i++, ward); |
|||
ps.setString(i++, latitude); |
|||
ps.setString(i++, longitude); |
|||
ps.setString(i++, cby); |
|||
ps.setString(i++, status); |
|||
return ps; |
|||
}, keyHolder); |
|||
|
|||
if (affectedRows > 0) { |
|||
int lastInsertId = keyHolder.getKey().intValue(); |
|||
response.put("insertId", lastInsertId); |
|||
response.put("status", "success"); |
|||
response.put("message", "New Final Notice details inserted successfully."); |
|||
} else { |
|||
response.put("status", "error"); |
|||
response.put("message", "New Final Notice details insert failed."); |
|||
} |
|||
|
|||
result.add(response); |
|||
return result; |
|||
} |
|||
|
|||
public Map<String, Object> getNoticeData(String cdidtxt, String ciidtxt) { |
|||
|
|||
String sql = "SELECT cd.*, " |
|||
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', cd.image) AS photo, " |
|||
+ "DATE_FORMAT(cd.cdate, '%d-%m-%Y') AS ddate, " |
|||
+ "ci.ciid, ci.under_guidelines, ci.penalty " |
|||
+ "FROM construction_details cd " |
|||
+ "LEFT JOIN construction_inspection ci ON ci.cdid = cd.cdid " |
|||
+ "WHERE cd.isactive = 1 AND ci.isactive = 1 AND ci.penalty IN ('High','Medium','Low') AND cd.cdid=? AND ci.ciid=?"; |
|||
|
|||
List<Map<String, Object>> result = jdbcGuidlines.queryForList(sql, cdidtxt, ciidtxt); |
|||
|
|||
Map<String, Object> data = new HashMap<>(); |
|||
|
|||
// Fetch master guideline list only once |
|||
String guidelinesSql = "SELECT `gid`, `guideline`, `significance`, `orderby`, `isactive` FROM guidelines WHERE isactive = 1 ORDER BY orderby"; |
|||
List<Map<String, Object>> guidelineList = jdbcGuidlines.queryForList(guidelinesSql); |
|||
|
|||
for (Map<String, Object> row : result) { |
|||
Object cdid = row.get("cdid"); |
|||
Object ciid = row.get("ciid"); |
|||
|
|||
// Fetch answer row for this cdid + ciid |
|||
String ansSql = "SELECT `giid`, `cdate`, `q1`, `q2`, `q3`, `q4`, `q5`, `q6`, `q7`, `q8`, `q9`, `q10`, `q11`, `q12`, `q13`, `q14`, `q15`, `q16`, `q17`, `q18`, " |
|||
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', img1) AS photo1, " |
|||
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', img2) AS photo2, " |
|||
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', img3) AS photo3, " |
|||
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', img4) AS photo4, " |
|||
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', img5) AS photo5 " |
|||
+ "FROM guildelines_inspection WHERE isactive = 1 AND cdid = ? AND ciid = ? LIMIT 1"; |
|||
List<Map<String, Object>> ansList = jdbcGuidlines.queryForList(ansSql, cdid, ciid); |
|||
|
|||
Map<String, Object> answers = ansList.isEmpty() ? new HashMap<>() : ansList.get(0); |
|||
|
|||
// Merge each guideline with its corresponding answer |
|||
List<Map<String, Object>> guidelineWithAnswers = new ArrayList<>(); |
|||
List<Integer> clauseList = new ArrayList<>(); |
|||
List<Map<String, Object>> violations = new ArrayList<>(); |
|||
for (int i = 1; i <= guidelineList.size(); i++) { |
|||
Map<String, Object> guideline = guidelineList.get(i - 1); |
|||
String qKey = "q" + i; |
|||
Map<String, Object> qa = new LinkedHashMap<>(); |
|||
String ans = String.valueOf(answers.get(qKey)); |
|||
if("No".equalsIgnoreCase(ans)) { |
|||
Map<String, Object> v = new HashMap<>(); |
|||
v.put("message", guideline.get("guideline")); // You can also include clause if needed |
|||
violations.add(v); |
|||
clauseList.add(i); |
|||
} |
|||
} |
|||
|
|||
String buildupAreaStr = row.get("buildup_area").toString(); |
|||
int buildup_area = Integer.parseInt(buildupAreaStr); |
|||
|
|||
System.out.println("buildup_area : "+buildup_area); |
|||
|
|||
String penaltyCategory = row.get("penalty").toString(); // should be "High" or "Low" |
|||
|
|||
System.out.println("penaltyCategory : "+penaltyCategory); |
|||
|
|||
int fineAmount = 0; |
|||
|
|||
if (buildup_area > 20000) { |
|||
if ("High".equalsIgnoreCase(penaltyCategory)) { |
|||
fineAmount = 500000; |
|||
} else { |
|||
fineAmount = 100000; |
|||
} |
|||
} else if (buildup_area > 500) { |
|||
if ("High".equalsIgnoreCase(penaltyCategory)) { |
|||
fineAmount = 25000; |
|||
} else { |
|||
fineAmount = 10000; |
|||
} |
|||
} else if (buildup_area >= 300 && buildup_area <= 500) { |
|||
if ("High".equalsIgnoreCase(penaltyCategory)) { |
|||
fineAmount = 10000; |
|||
} else { |
|||
fineAmount = 1000; |
|||
} |
|||
} |
|||
System.out.println("fineAmount : "+fineAmount); |
|||
|
|||
data.put("siteLocation", row.get("site_address")); |
|||
data.put("violations", violations); |
|||
data.put("violationLevel", row.get("penalty")); |
|||
data.put("clause", clauseList); |
|||
data.put("fineAmount", fineAmount); |
|||
data.put("fineAmountWords", convertNumberToIndianWords(fineAmount)); |
|||
data.put("date", row.get("ddate")); |
|||
} |
|||
return data; |
|||
} |
|||
|
|||
public static String convertNumberToIndianWords(long number) { |
|||
if (number == 0) return "Zero"; |
|||
|
|||
final String[] units = { "", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", |
|||
"Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", |
|||
"Seventeen", "Eighteen", "Nineteen" }; |
|||
|
|||
final String[] tens = { "", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" }; |
|||
|
|||
final String[] places = { "", "Thousand", "Lakh", "Crore" }; |
|||
|
|||
StringBuilder words = new StringBuilder(); |
|||
|
|||
int[] parts = new int[4]; |
|||
parts[0] = (int) (number % 1000); // hundreds |
|||
parts[1] = (int) ((number / 1000) % 100); // thousands |
|||
parts[2] = (int) ((number / 100000) % 100); // lakhs |
|||
parts[3] = (int) (number / 10000000); // crores |
|||
|
|||
for (int i = 3; i >= 0; i--) { |
|||
if (parts[i] != 0) { |
|||
if (parts[i] < 20) { |
|||
words.append(units[parts[i]]); |
|||
} else { |
|||
words.append(tens[parts[i] / 10]); |
|||
if ((parts[i] % 10) != 0) { |
|||
words.append(" ").append(units[parts[i] % 10]); |
|||
} |
|||
} |
|||
words.append(" ").append(places[i]).append(" "); |
|||
} |
|||
} |
|||
|
|||
if (parts[0] > 0) { |
|||
int h = parts[0] / 100; |
|||
int rem = parts[0] % 100; |
|||
if (h > 0) { |
|||
words.append(units[h]).append(" Hundred "); |
|||
} |
|||
if (rem > 0) { |
|||
if (rem < 20) { |
|||
words.append(units[rem]); |
|||
} else { |
|||
words.append(tens[rem / 10]); |
|||
if ((rem % 10) != 0) { |
|||
words.append(" ").append(units[rem % 10]); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
return words.toString().trim(); |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.constructionGuidelines.service; |
|||
@ -0,0 +1,75 @@ |
|||
package in.gov.chennaicorporation.mobileservice.controller; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.http.HttpHeaders; |
|||
import org.springframework.http.HttpStatus; |
|||
import org.springframework.http.MediaType; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import in.gov.chennaicorporation.mobileservice.constructionGuidelines.service.GuidelinesService; |
|||
import in.gov.chennaicorporation.mobileservice.service.PdfGeneratorService; |
|||
|
|||
@RestController |
|||
@RequestMapping("/gccofficialapp/api/pdf") |
|||
public class PdfTemplateController { |
|||
|
|||
@Autowired |
|||
private PdfGeneratorService pdfGeneratorService; |
|||
|
|||
@Autowired |
|||
private GuidelinesService guidelinesService; |
|||
/* |
|||
@GetMapping("/template") |
|||
public ResponseEntity<byte[]> generateFromTemplate( |
|||
@RequestParam(value = "cdid", required = false) String cdid, |
|||
@RequestParam(value = "ciid", required = false) String ciid |
|||
) { |
|||
//Map<String, Object> data = new HashMap<>(); |
|||
|
|||
//data.put("siteLocation", siteLocation); |
|||
//data.put("violations", violations); |
|||
//data.put("violationLevel", violationLevel); |
|||
//data.put("clause", clause); |
|||
//data.put("fineAmount", fineAmount); |
|||
//data.put("date", LocalDate.now().toString()); |
|||
|
|||
|
|||
String attachmentFileName="UNDER_CLEAN_AND_SAFE_CONSTRUCTION_GUIDELINES_NOTICE_"+LocalDate.now().toString()+"pdf"; |
|||
|
|||
byte[] pdfBytes = pdfGeneratorService.generatePdf(guidelinesService.getNoticeData(cdid, ciid)); |
|||
|
|||
HttpHeaders headers = new HttpHeaders(); |
|||
headers.setContentType(MediaType.APPLICATION_PDF); |
|||
headers.setContentDispositionFormData("attachment", attachmentFileName); |
|||
|
|||
return new ResponseEntity<>(pdfBytes, headers, HttpStatus.OK); |
|||
} |
|||
*/ |
|||
@GetMapping("/template") |
|||
public ResponseEntity<byte[]> generateFromTemplate( |
|||
@RequestParam(value = "cdid", required = false) String cdid, |
|||
@RequestParam(value = "ciid", required = false) String ciid |
|||
) { |
|||
String attachmentFileName = "UNDER_CLEAN_AND_SAFE_CONSTRUCTION_GUIDELINES_NOTICE_" + LocalDate.now() + ".pdf"; |
|||
|
|||
// Generate PDF content |
|||
byte[] pdfBytes = pdfGeneratorService.generatePdf( |
|||
guidelinesService.getNoticeData(cdid, ciid) |
|||
); |
|||
|
|||
// Prepare response headers |
|||
HttpHeaders headers = new HttpHeaders(); |
|||
headers.setContentType(MediaType.APPLICATION_PDF); |
|||
headers.setContentDispositionFormData("attachment", attachmentFileName); |
|||
|
|||
return new ResponseEntity<>(pdfBytes, headers, HttpStatus.OK); |
|||
} |
|||
} |
|||
@ -0,0 +1,5 @@ |
|||
package in.gov.chennaicorporation.mobileservice.erpPostData; |
|||
|
|||
public class erppostdataController { |
|||
|
|||
} |
|||
@ -0,0 +1,191 @@ |
|||
package in.gov.chennaicorporation.mobileservice.erpPostData; |
|||
|
|||
import java.sql.Timestamp; |
|||
import java.time.LocalDateTime; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
import javax.sql.DataSource; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Qualifier; |
|||
import org.springframework.http.HttpStatus; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
import org.springframework.scheduling.annotation.Scheduled; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import org.springframework.http.*; |
|||
import org.springframework.web.client.RestTemplate; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
|
|||
@Service |
|||
public class erppostdataService { |
|||
|
|||
@Autowired |
|||
private JdbcTemplate jdbcTemplate; |
|||
|
|||
@Autowired |
|||
public void setDataSource(@Qualifier("mysqlPenaltyDataSource") DataSource penaltyDataSource) { |
|||
this.jdbcTemplate = new JdbcTemplate(penaltyDataSource); |
|||
} |
|||
// This method runs every 1 hour (3600000 ms) |
|||
@Scheduled(fixedRate = 60 * 60 * 1000) |
|||
//@Scheduled(cron = "0 0 * * * *") // every hour at 0th minute |
|||
public void postDataToERP() { |
|||
// Call the logic you currently expose through controller |
|||
System.out.println("Posting data to ERP at " + java.time.LocalDateTime.now()); |
|||
postPOSToERP(); // FOR PENALTY POS (gcc_penalty_pos) |
|||
} |
|||
|
|||
private String postPOSToERP() { |
|||
System.out.println("ERP txn: Started"); |
|||
String sql = "SELECT " |
|||
+ " bt.id, " |
|||
+ " bt.txnDate, " |
|||
+ " DATE_FORMAT(bt.txnDate, '%Y') AS TRANSACTIONYEAR, " |
|||
+ " DATE_FORMAT(bt.txnDate, '%d/%m/%Y') AS TRANSACTIONDATE, " |
|||
+ " bt.txnId AS TRANSACTIONNO, " |
|||
+ " bt.transactionAmount AS TOTALTRANSACTIONAMOUNT, " |
|||
+ " bt.txnRefNo AS TRANSACTIONREFNO, " |
|||
+ " '450310000' AS TOTALTRANSACTIONCODE, " |
|||
+ " pcat.erpcode AS MSTRCODEONE, " |
|||
+ " 0 AS SPLITAMOUNTONE, " |
|||
+ " pc.violator_name AS PARTYNAME, " |
|||
+ " pc.violator_company AS PARTYADDRESS, " |
|||
+ " pc.violator_phone AS PARTYMOBILE, " |
|||
+ " pc.id AS UNIQUERECEIPTID " |
|||
+ "FROM " |
|||
+ " `bank_transactions` bt " |
|||
+ "LEFT JOIN " |
|||
+ " `penalty_challan` pc ON bt.txnId = pc.orderid " |
|||
+ " AND pc.isactive = 1 " |
|||
+ " AND pc.isdelete = 0 " |
|||
+ " AND bt.txnMode NOT IN ('Hand cash','Cheque','DD') " |
|||
+ "LEFT JOIN " |
|||
+ " `penalty_category` pcat ON pcat.id = pc.category_id " |
|||
+ "WHERE bt.erp_post_status IS NULL OR bt.erp_post_status != 'posted' " |
|||
+ " AND bt.erp_post_message != 'Already Updated this collection' " |
|||
+ "ORDER BY `bt`.`id` ASC"; |
|||
try { |
|||
|
|||
System.out.println("Running ERP sync..."); |
|||
System.out.println("Using SQL:\n" + sql); |
|||
System.out.println("Connecting to: " + jdbcTemplate.getDataSource().getConnection().getMetaData().getURL()); |
|||
|
|||
List<Map<String, Object>> result = jdbcTemplate.queryForList(sql); |
|||
System.out.println("ERP txt Total records: : "+result.size()); |
|||
for (Map<String, Object> row : result) { |
|||
String ID = String.valueOf(row.get("id")); |
|||
System.out.println("ERP TXT DATA : "+ID); |
|||
String ASSESSMENTNO = row.get("TRANSACTIONYEAR")+"/Fine/"+row.get("id"); |
|||
String UNIQUERECEIPTID = String.valueOf(row.get("UNIQUERECEIPTID")); |
|||
String TRANSACTIONNO = String.valueOf(row.get("TRANSACTIONNO")); |
|||
String TRANSACTIONREFNO = String.valueOf(row.get("TRANSACTIONREFNO")); // optional mapping |
|||
String TRANSACTIONDATE = String.valueOf(row.get("TRANSACTIONDATE")); |
|||
String TOTALTRANSACTIONAMOUNT = String.valueOf(row.get("TOTALTRANSACTIONAMOUNT")); |
|||
String TOTALTRANSACTIONCODE = String.valueOf(row.get("TOTALTRANSACTIONCODE")); |
|||
String MSTRCODEONE = String.valueOf(row.get("MSTRCODEONE")); |
|||
String SPLITAMOUNTONE = String.valueOf(row.get("SPLITAMOUNTONE")); |
|||
String PARTYNAME = String.valueOf(row.get("PARTYNAME")); |
|||
String PARTYADDRESS = String.valueOf(row.get("PARTYADDRESS")); |
|||
String PARTYMOBILE = String.valueOf(row.get("PARTYMOBILE")); |
|||
|
|||
String response = postToErp( |
|||
ID, |
|||
ASSESSMENTNO, |
|||
UNIQUERECEIPTID, |
|||
TRANSACTIONNO, |
|||
TRANSACTIONREFNO, |
|||
TRANSACTIONDATE, |
|||
TOTALTRANSACTIONAMOUNT, |
|||
TOTALTRANSACTIONCODE, |
|||
MSTRCODEONE, |
|||
SPLITAMOUNTONE, |
|||
PARTYNAME, |
|||
PARTYADDRESS, |
|||
PARTYMOBILE |
|||
); |
|||
|
|||
// ✅ Exit loop immediately if ERP server down or response is not "success" |
|||
if ("server_down".equalsIgnoreCase(response)) { |
|||
System.out.println("ERP server is down or unreachable. Halting current loop..."); |
|||
break; // stop further processing in this cycle |
|||
} |
|||
|
|||
// Optionally log response |
|||
System.out.println("ERP Response for txn: " + TRANSACTIONNO + " → " + response); |
|||
} |
|||
|
|||
return "success"; |
|||
|
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return "erp error: " + e.getMessage(); |
|||
} |
|||
} |
|||
|
|||
private String postToErp( |
|||
String id, |
|||
String ASSESSMENTNO, |
|||
String UNIQUERECEIPTID, |
|||
String TRANSACTIONNO, |
|||
String TRANSACTIONREFNO, |
|||
String TRANSACTIONDATE, |
|||
String TOTALTRANSACTIONAMOUNT, |
|||
String TOTALTRANSACTIONCODE, |
|||
String MSTRCODEONE, |
|||
String SPLITAMOUNTONE, |
|||
String PARTYNAME, |
|||
String PARTYADDRESS, |
|||
String PARTYMOBILE) { |
|||
System.out.println("ERP txn request: ERP"); |
|||
String erpURL = "http://coc-staging.egovernments.org:9980/pgr/external/mobileservice?serviceId=getOtherCollection" |
|||
+ "&COLLECTION_TYPE=Fine Collection" |
|||
+ "&ASSESSMENTNO=" + ASSESSMENTNO |
|||
+ "&UNIQUERECEIPTID=" + UNIQUERECEIPTID |
|||
+ "&TRANSACTIONNO=" + TRANSACTIONNO |
|||
+ "&TRANSACTIONREFNO=" + TRANSACTIONREFNO |
|||
+ "&TRANSACTIONDATE=" + TRANSACTIONDATE |
|||
+ "&TOTALTRANSACTIONAMOUNT=" + TOTALTRANSACTIONAMOUNT |
|||
+ "&TOTALTRANSACTIONCODE=" + TOTALTRANSACTIONCODE |
|||
+ "&MSTRCODEONE=" + MSTRCODEONE |
|||
+ "&SPLITAMOUNTONE=" + SPLITAMOUNTONE |
|||
+ "&PARTYNAME=" + PARTYNAME |
|||
+ "&PARTYADDRESS=" + PARTYADDRESS |
|||
+ "&PARTYMOBILE=" + PARTYMOBILE; |
|||
|
|||
RestTemplate restTemplate = new RestTemplate(); |
|||
System.out.println("ERP URL:" + erpURL); |
|||
try { |
|||
ResponseEntity<String> response = restTemplate.exchange(erpURL, HttpMethod.GET, null, String.class); |
|||
|
|||
if (response.getStatusCode() == HttpStatus.OK) { |
|||
ObjectMapper mapper = new ObjectMapper(); |
|||
JsonNode jsonNode = mapper.readTree(response.getBody()); |
|||
|
|||
boolean resultStatus = jsonNode.path("ResultStatus").asBoolean(); // this is already a boolean |
|||
String message = jsonNode.path("Message").asText(); // capture the message string |
|||
|
|||
if (resultStatus) { |
|||
String updateSql = "UPDATE bank_transactions SET erp_post_status = 'posted', erp_post_message = ?, erp_post_date = ? WHERE id = ?"; |
|||
jdbcTemplate.update(updateSql, message, Timestamp.valueOf(LocalDateTime.now()), id); |
|||
} else { |
|||
String updateSql = "UPDATE bank_transactions SET erp_post_status = 'failed', erp_post_message = ?, erp_post_date = ? WHERE id = ?"; |
|||
jdbcTemplate.update(updateSql, message, Timestamp.valueOf(LocalDateTime.now()), id); |
|||
} |
|||
|
|||
return resultStatus ? "success" : "failed"; |
|||
|
|||
} else { |
|||
return "failed"; // Non-200 response from server |
|||
} |
|||
|
|||
} catch (Exception ex) { |
|||
System.out.println("Error contacting ERP server: " + ex.getMessage()); |
|||
return "server_down"; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.erpPostData; |
|||
@ -0,0 +1,145 @@ |
|||
package in.gov.chennaicorporation.mobileservice.gccDomesticWaste.Controller; |
|||
import in.gov.chennaicorporation.mobileservice.gccDomesticWaste.Service.DomesticWasteService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.http.HttpStatus; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@RestController |
|||
@RequestMapping("/gccofficialapp/api/domesticwaste") |
|||
public class DomesticWasteController { |
|||
|
|||
@Autowired |
|||
DomesticWasteService domesticWasteService; |
|||
|
|||
|
|||
|
|||
@PostMapping("/save-request") |
|||
public ResponseEntity<?> saveRequest( |
|||
@RequestParam String user_name, |
|||
@RequestParam String mobile, |
|||
@RequestParam String address, |
|||
@RequestParam String latitude, |
|||
@RequestParam String longitude, |
|||
@RequestParam String zone, |
|||
@RequestParam String division, |
|||
@RequestParam String street_name, |
|||
@RequestParam String street_id, |
|||
@RequestParam String remarks, |
|||
@RequestParam("items") String itemsJson, |
|||
@RequestParam (name = "image") MultipartFile imageFile) { |
|||
|
|||
try { |
|||
Map<String, Object> result = domesticWasteService.saveMultipleWasteRequests( |
|||
user_name, mobile, address, |
|||
latitude, longitude, zone, division, |
|||
street_name, street_id, remarks, |
|||
imageFile, itemsJson |
|||
); |
|||
|
|||
return ResponseEntity.ok(result); |
|||
|
|||
} catch (Exception e) { |
|||
return ResponseEntity.status(500).body(Map.of("status", false, "message", e.getMessage())); |
|||
} |
|||
} |
|||
|
|||
|
|||
@GetMapping("/get-all-requests") |
|||
public ResponseEntity<List<Map<String, Object>>> getAllWasteRequests() { |
|||
List<Map<String, Object>> results = domesticWasteService.getAllWasteRequests(); |
|||
return ResponseEntity.ok(results); |
|||
} |
|||
|
|||
@GetMapping("/get-all-requests-by-login") |
|||
public ResponseEntity<List<Map<String, Object>>> getAllWasteRequests(@RequestParam String loginId) { |
|||
List<Map<String, Object>> results = domesticWasteService.getAllWasteRequestsbylogin(loginId); |
|||
return ResponseEntity.ok(results); |
|||
} |
|||
|
|||
@GetMapping("/get-all-masters") |
|||
public ResponseEntity<List<Map<String, Object>>> getAllmasters() { |
|||
List<Map<String, Object>> results = domesticWasteService.getAllmasters(); |
|||
return ResponseEntity.ok(results); |
|||
} |
|||
|
|||
@GetMapping("/get-user-bymobile") |
|||
public ResponseEntity<List<Map<String, Object>>> getuserbymobile(@RequestParam String mobile) { |
|||
List<Map<String,Object>> results =domesticWasteService.getuserbymobile(mobile); |
|||
return ResponseEntity.ok(results); |
|||
} |
|||
|
|||
@GetMapping("/get-user-AE2") |
|||
public ResponseEntity<List<Map<String, Object>>> getUserAE2(@RequestParam String loginId) { |
|||
List<Map<String, Object>> results = domesticWasteService.getuserAE2(loginId); |
|||
return ResponseEntity.ok(results); |
|||
} |
|||
|
|||
// Zonal Requests based on loginId |
|||
@GetMapping("/get-user-zonal") |
|||
public ResponseEntity<List<Map<String, Object>>> getUserZonal(@RequestParam String loginId) { |
|||
List<Map<String, Object>> results = domesticWasteService.getuserZonal(loginId); |
|||
return ResponseEntity.ok(results); |
|||
} |
|||
|
|||
@GetMapping("/userdetailsfilter") |
|||
public ResponseEntity<List<Map<String, Object>>> userdetailsfilter(@RequestParam int id) { |
|||
List<Map<String,Object>> results =domesticWasteService.userdetailsfilter(id); |
|||
return ResponseEntity.ok(results); |
|||
} |
|||
|
|||
@PostMapping("/action-taken") |
|||
public ResponseEntity<?> saveActionTaken( |
|||
@RequestParam int reqid, |
|||
@RequestParam(value = "image") MultipartFile image, |
|||
@RequestParam("created_by") int createdBy, |
|||
@RequestParam String latitude, |
|||
@RequestParam String longitude |
|||
) { |
|||
Map<String, Object> result = domesticWasteService.actionTaken(String.valueOf(reqid), image, createdBy,latitude,longitude); |
|||
|
|||
if ((boolean) result.get("status")) { |
|||
return ResponseEntity.ok(result); |
|||
} else { |
|||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/reject-user-req") |
|||
public ResponseEntity<?> rejectuserreq(@RequestParam String requestId) { |
|||
Map<String, Object> result = domesticWasteService.rejectuserreq(requestId); |
|||
return ResponseEntity.ok(result); |
|||
} |
|||
|
|||
@GetMapping("/verify-latlong") |
|||
public ResponseEntity<Map<String, Object>> verifyLatLong( |
|||
@RequestParam String requestId, |
|||
@RequestParam String latitude, |
|||
@RequestParam String longitude) { |
|||
|
|||
boolean result = domesticWasteService.verifylatlong(requestId, latitude, longitude); |
|||
|
|||
Map<String, Object> response = Map.of( |
|||
"status", true, |
|||
"message", String.valueOf(result) |
|||
); |
|||
|
|||
return ResponseEntity.ok(response); |
|||
} |
|||
|
|||
@PostMapping("/reject-request-officer") |
|||
public ResponseEntity<Map<String, Object>> rejectUserRequestByOfficer( |
|||
@RequestParam String requestId, |
|||
@RequestParam String officer_remark, |
|||
@RequestParam String rejecttype, |
|||
@RequestParam int cancelled_by, |
|||
@RequestParam String latitude, |
|||
@RequestParam String longitude) { |
|||
|
|||
Map<String, Object> result = domesticWasteService.rejectuserreqofficer(requestId, officer_remark, rejecttype, cancelled_by,latitude,longitude); |
|||
return ResponseEntity.ok(result); |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
package in.gov.chennaicorporation.mobileservice.gccDomesticWaste.Scheduler; |
|||
|
|||
import in.gov.chennaicorporation.mobileservice.gccDomesticWaste.Service.DomesticWasteService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.scheduling.annotation.EnableScheduling; |
|||
import org.springframework.scheduling.annotation.Scheduled; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Map; |
|||
|
|||
@Component |
|||
@EnableScheduling |
|||
public class DomesticWasteScheduler { |
|||
@Autowired |
|||
private DomesticWasteService domesticWasteService; |
|||
|
|||
|
|||
@Scheduled(cron = "0 0 1 * * WED", zone = "Asia/Kolkata") |
|||
//@Scheduled(fixedRate = 3000) |
|||
public void domesticWasteScheduler() { |
|||
System.out.println("DomesticWasteScheduler Started......"); |
|||
Map<String,Object> result= domesticWasteService.updateOrderStatus("3"); |
|||
System.out.println("Scheduler Result: " + result); |
|||
|
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,631 @@ |
|||
package in.gov.chennaicorporation.mobileservice.gccDomesticWaste.Service; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Qualifier; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.core.env.Environment; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
import org.springframework.jdbc.support.GeneratedKeyHolder; |
|||
import org.springframework.jdbc.support.KeyHolder; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
import java.io.File; |
|||
import java.io.IOException; |
|||
import java.sql.PreparedStatement; |
|||
import java.sql.Statement; |
|||
import java.time.LocalDate; |
|||
import java.time.LocalDateTime; |
|||
import java.time.format.DateTimeFormatter; |
|||
import java.util.ArrayList; |
|||
import java.util.Collections; |
|||
import java.util.HashMap; |
|||
import java.util.LinkedHashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import com.fasterxml.jackson.core.type.TypeReference; |
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
|
|||
import javax.sql.DataSource; |
|||
|
|||
@Service |
|||
public class DomesticWasteService { |
|||
|
|||
@Autowired |
|||
|
|||
private JdbcTemplate jdbcDomesticWasteTemplate; |
|||
|
|||
@Value("${file.upload.directory}") |
|||
private String baseUploadDir; |
|||
|
|||
@Value("${domestic_waste_foldername}") |
|||
private String wasteFolder; |
|||
|
|||
|
|||
private String fileBaseUrl; |
|||
|
|||
@Autowired |
|||
private Environment environment; |
|||
|
|||
@Autowired |
|||
public void setDataSource(@Qualifier("mysqlGccDomesticWasteManagementDataSource") DataSource DomesticWasteManagementDataSource) { |
|||
this.jdbcDomesticWasteTemplate = new JdbcTemplate(DomesticWasteManagementDataSource); |
|||
} |
|||
|
|||
|
|||
|
|||
public DomesticWasteService(Environment environment) { |
|||
this.environment = environment; |
|||
this.fileBaseUrl = environment.getProperty("fileBaseUrl"); |
|||
} |
|||
|
|||
|
|||
public String fileUpload(MultipartFile file, String prefix) { |
|||
if (file == null || file.isEmpty()) { |
|||
return null; |
|||
} |
|||
|
|||
try { |
|||
String year = String.valueOf(LocalDate.now().getYear()); |
|||
String month = String.format("%02d", LocalDate.now().getMonthValue()); |
|||
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("ddMMyyyyHHmmss")); |
|||
|
|||
// Clean original file name |
|||
String originalFilename = file.getOriginalFilename().replaceAll("\\s+", ""); |
|||
String fileName = prefix + "_" + timestamp + "_" + originalFilename; |
|||
|
|||
// Create upload directory path |
|||
String uploadDirPath = baseUploadDir + wasteFolder + year + "/" + month; |
|||
File uploadDir = new File(uploadDirPath); |
|||
if (!uploadDir.exists()) { |
|||
uploadDir.mkdirs(); |
|||
} |
|||
|
|||
// Save file to server |
|||
File fullFilePath = new File(uploadDirPath + File.separator + fileName); |
|||
file.transferTo(fullFilePath); |
|||
|
|||
// Return relative path to save in DB |
|||
return "/" + wasteFolder + year + "/" + month + "/" + fileName; |
|||
|
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
public Map<String, Object> saveMultipleWasteRequests(String user_name, String mobile, String address, |
|||
String latitude, String longitude, String zone, String division, |
|||
String street_name, String street_id, String remarks, |
|||
MultipartFile imageFile, String itemsJson) { |
|||
|
|||
String imagePath = fileUpload(imageFile, "domestic_waste_photo"); |
|||
if (imagePath == null) { |
|||
return Map.of("status", false, "message", "Image upload failed"); |
|||
} |
|||
|
|||
try { |
|||
// Step 1: Insert main request (one time) |
|||
String insertMainSql = "INSERT INTO user_request_table " + |
|||
"(request_id, user_name, mobile, address, latitude, longitude, zone, division, street_name, street_id, remarks, image_url) " + |
|||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; |
|||
|
|||
KeyHolder keyHolder = new GeneratedKeyHolder(); |
|||
jdbcDomesticWasteTemplate.update(con -> { |
|||
PreparedStatement ps = con.prepareStatement(insertMainSql, Statement.RETURN_GENERATED_KEYS); |
|||
ps.setString(1, "TEMP"); // placeholder |
|||
ps.setString(2, user_name); |
|||
ps.setString(3, mobile); |
|||
ps.setString(4, address); |
|||
ps.setString(5, latitude); |
|||
ps.setString(6, longitude); |
|||
ps.setString(7, zone); |
|||
ps.setString(8, division); |
|||
ps.setString(9, street_name); |
|||
ps.setString(10, street_id); |
|||
ps.setString(11, remarks); |
|||
ps.setString(12, imagePath); |
|||
return ps; |
|||
}, keyHolder); |
|||
|
|||
int generatedId = keyHolder.getKey().intValue(); |
|||
String requestId = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")) + generatedId; |
|||
|
|||
// Update request_id in user_request_table |
|||
jdbcDomesticWasteTemplate.update("UPDATE user_request_table SET request_id = ? WHERE id = ?", requestId, generatedId); |
|||
|
|||
// Step 2: Insert items under the same request_id into the `items` table |
|||
ObjectMapper objectMapper = new ObjectMapper(); |
|||
List<Map<String, Object>> items = objectMapper.readValue(itemsJson, new TypeReference<>() {}); |
|||
|
|||
String insertItemSql = "INSERT INTO items (iteam_id, quantity, req_table_id, requedt_id) VALUES (?, ?, ?, ?)"; |
|||
|
|||
for (Map<String, Object> item : items) { |
|||
Object itemIdObj = item.get("item_id"); |
|||
Object quantityObj = item.get("quantity"); |
|||
|
|||
if (itemIdObj == null || quantityObj == null) { |
|||
continue; |
|||
} |
|||
|
|||
int itemId = Integer.parseInt(itemIdObj.toString()); |
|||
int quantity = Integer.parseInt(quantityObj.toString()); |
|||
|
|||
jdbcDomesticWasteTemplate.update(insertItemSql, itemId, quantity, generatedId, requestId); |
|||
} |
|||
|
|||
return Map.of( |
|||
"status", true, |
|||
"message", "Request saved successfully", |
|||
"requestId", requestId |
|||
); |
|||
|
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return Map.of("status", false, "message", "Error: " + e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
public List<Map<String, Object>> getAllWasteRequests() { |
|||
/*String sql = "SELECT " + |
|||
"u.id, u.request_id, u.user_name, u.mobile, u.address, u.latitude, u.longitude, " + |
|||
"u.zone, u.division, u.street_name, u.street_id, u.quantity, u.remarks, " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', u.image_url) AS image_url, " + |
|||
"itm.quantity, i.item_name " + |
|||
"FROM user_request_table u " + |
|||
"LEFT JOIN items itm ON u.id = itm.req_table_id " + |
|||
"LEFT JOIN item_master i ON itm.iteam_id = i.id AND i.is_active = 1"; |
|||
*/ |
|||
String sql = "SELECT " + |
|||
"u.*, " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', u.image_url) AS image_full_url, " + |
|||
"itm.quantity, i.item_name " + |
|||
"FROM user_request_table u " + |
|||
"LEFT JOIN items itm ON u.id = itm.req_table_id " + |
|||
"LEFT JOIN item_master i ON itm.iteam_id = i.id AND i.is_active = 1"; |
|||
|
|||
List<Map<String, Object>> rawData = jdbcDomesticWasteTemplate.queryForList(sql); |
|||
return groupRequestsWithItems(rawData); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getAllWasteRequestsbylogin(String loginId) { |
|||
String zoneSql = "SELECT zone, division FROM officer_master WHERE loginId = ? AND is_active = 1 AND is_delete = 0"; |
|||
List<Map<String, Object>> zoneList = jdbcDomesticWasteTemplate.queryForList(zoneSql, loginId); |
|||
|
|||
//if (zoneList.isEmpty()) return List.of(); |
|||
if (zoneList.isEmpty()) { |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
return Collections.singletonList(response); // or just `response` depending on your return type |
|||
} |
|||
|
|||
List<Object> params = new ArrayList<>(); |
|||
StringBuilder zoneCondition = new StringBuilder("("); |
|||
|
|||
for (int i = 0; i < zoneList.size(); i++) { |
|||
Map<String, Object> row = zoneList.get(i); |
|||
zoneCondition.append("(u.zone = ? AND u.division = ?)"); |
|||
if (i < zoneList.size() - 1) zoneCondition.append(" OR "); |
|||
params.add(row.get("zone")); |
|||
params.add(row.get("division")); |
|||
} |
|||
zoneCondition.append(") ORDER BY u.cdate DESC"); |
|||
/* |
|||
String sql = "SELECT " + |
|||
"u.*, " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', u.image_url) AS image_full_url, " + |
|||
"itm.quantity, i.item_name " + |
|||
"FROM user_request_table u " + |
|||
"LEFT JOIN items itm ON u.id = itm.req_table_id " + |
|||
"LEFT JOIN item_master i ON itm.iteam_id = i.id AND i.is_active = 1"; |
|||
*/ |
|||
String sql = "SELECT " + |
|||
"u.id, u.request_id, u.user_name, u.mobile, u.address, u.latitude, u.longitude, " + |
|||
"u.zone, u.division, u.street_name, u.quantity AS main_quantity, u.remarks, " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', u.image_url) AS image_url, " + |
|||
"DATE_FORMAT(u.cdate, '%d-%m-%Y') AS cdate, " + |
|||
"u.is_active, u.is_delete, u.street_id, sm.status_master AS status, u.is_app, " + |
|||
"DATE_FORMAT(u.close_date, '%d-%m-%Y') AS close_date, " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', u.officer_upload_url) AS officer_upload_url, " + |
|||
"itm.quantity, im.item_name " + |
|||
"FROM user_request_table u " + |
|||
"LEFT JOIN items itm ON u.id = itm.req_table_id " + |
|||
"LEFT JOIN item_master im ON itm.iteam_id = im.id AND im.is_active = 1 " + |
|||
"LEFT JOIN status_master sm ON sm.id = u.status AND sm.is_active = 1 AND sm.is_delete = 0 " + |
|||
"WHERE u.status IN(1,3) " + |
|||
"AND u.is_active = 1 AND " + zoneCondition; |
|||
|
|||
List<Map<String, Object>> rawData = jdbcDomesticWasteTemplate.queryForList(sql, params.toArray()); |
|||
return groupRequestsWithItems(rawData); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getAllmasters() { |
|||
String sql = "select id,item_name from item_master where is_active= 1"; |
|||
return jdbcDomesticWasteTemplate.queryForList(sql); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getuserbymobile(String mobile) { |
|||
String sql = "SELECT " + |
|||
"u.id, u.request_id, u.user_name, u.mobile, u.address, u.latitude, u.longitude, " + |
|||
"u.zone, u.division, u.street_name, u.quantity AS main_quantity, u.remarks, " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', u.image_url) AS image_url, " + |
|||
"DATE_FORMAT(u.cdate, '%d-%m-%Y') AS cdate, " + |
|||
"u.is_active, u.is_delete, u.street_id, sm.status_master AS status, u.is_app, " + |
|||
"DATE_FORMAT(u.close_date, '%d-%m-%Y') AS close_date, " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', u.officer_upload_url) AS officer_upload_url, " + |
|||
"itm.iteam_id, itm.quantity, im.item_name " + |
|||
"FROM user_request_table u " + |
|||
"LEFT JOIN items itm ON u.id = itm.req_table_id " + |
|||
"LEFT JOIN item_master im ON itm.iteam_id = im.id AND im.is_active = 1 " + |
|||
"LEFT JOIN status_master sm ON sm.id = u.status AND sm.is_active = 1 AND sm.is_delete = 0 " + |
|||
"WHERE u.mobile = ? AND u.is_active = 1"; |
|||
|
|||
List<Map<String, Object>> rawList = jdbcDomesticWasteTemplate.queryForList(sql, mobile); |
|||
|
|||
Map<Integer, Map<String, Object>> groupedMap = new LinkedHashMap<>(); |
|||
|
|||
for (Map<String, Object> row : rawList) { |
|||
Integer id = (Integer) row.get("id"); |
|||
|
|||
Map<String, Object> item = null; |
|||
if (row.get("item_name") != null) { |
|||
item = new LinkedHashMap<>(); |
|||
item.put("item_name", row.get("item_name")); |
|||
item.put("quantity", row.get("quantity")); |
|||
} |
|||
|
|||
if (groupedMap.containsKey(id)) { |
|||
if (item != null) { |
|||
((List<Map<String, Object>>) groupedMap.get(id).get("items")).add(item); |
|||
} |
|||
} else { |
|||
Map<String, Object> newEntry = new LinkedHashMap<>(); |
|||
newEntry.put("id", id); |
|||
newEntry.put("request_id", row.get("request_id")); |
|||
newEntry.put("user_name", row.get("user_name")); |
|||
newEntry.put("mobile", row.get("mobile")); |
|||
newEntry.put("address", row.get("address")); |
|||
newEntry.put("latitude", row.get("latitude")); |
|||
newEntry.put("longitude", row.get("longitude")); |
|||
newEntry.put("zone", row.get("zone")); |
|||
newEntry.put("division", row.get("division")); |
|||
newEntry.put("street_name", row.get("street_name")); |
|||
newEntry.put("main_quantity", row.get("main_quantity")); |
|||
newEntry.put("remarks", row.get("remarks")); |
|||
newEntry.put("image_url", row.get("image_url")); |
|||
newEntry.put("cdate", row.get("cdate")); |
|||
newEntry.put("is_active", row.get("is_active")); |
|||
newEntry.put("is_delete", row.get("is_delete")); |
|||
newEntry.put("street_id", row.get("street_id")); |
|||
newEntry.put("status", row.get("status")); // Now this is human-readable |
|||
newEntry.put("is_app", row.get("is_app")); |
|||
newEntry.put("close_date", row.get("close_date")); |
|||
newEntry.put("officer_upload_url", row.get("officer_upload_url")); |
|||
|
|||
List<Map<String, Object>> items = new ArrayList<>(); |
|||
if (item != null) { |
|||
items.add(item); |
|||
} |
|||
newEntry.put("items", items); |
|||
|
|||
groupedMap.put(id, newEntry); |
|||
} |
|||
} |
|||
|
|||
return new ArrayList<>(groupedMap.values()); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getuserAE2(String loginId) { |
|||
String zoneSql = "SELECT zone, division FROM officer_master WHERE loginId = ? AND is_active = 1 AND is_delete = 0"; |
|||
List<Map<String, Object>> zoneList = jdbcDomesticWasteTemplate.queryForList(zoneSql, loginId); |
|||
|
|||
//if (zoneList.isEmpty()) return List.of(); |
|||
if (zoneList.isEmpty()) { |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
return Collections.singletonList(response); // or just `response` depending on your return type |
|||
} |
|||
|
|||
List<Object> params = new ArrayList<>(); |
|||
StringBuilder zoneCondition = new StringBuilder("("); |
|||
|
|||
for (int i = 0; i < zoneList.size(); i++) { |
|||
Map<String, Object> row = zoneList.get(i); |
|||
zoneCondition.append("(u.zone = ? AND u.division = ?)"); |
|||
if (i < zoneList.size() - 1) zoneCondition.append(" OR "); |
|||
params.add(row.get("zone")); |
|||
params.add(row.get("division")); |
|||
} |
|||
zoneCondition.append(")"); |
|||
|
|||
String sql = "SELECT " + |
|||
"u.id, u.request_id, u.user_name, u.mobile, u.address, u.latitude, u.longitude, " + |
|||
"u.zone, u.division, u.street_name, u.quantity AS main_quantity, u.remarks, " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', u.image_url) AS image_url, " + |
|||
"DATE_FORMAT(u.cdate, '%d-%m-%Y') AS cdate, " + |
|||
"u.is_active, u.is_delete, u.street_id, sm.status_master AS status, u.is_app, " + |
|||
"DATE_FORMAT(u.close_date, '%d-%m-%Y') AS close_date, " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', u.officer_upload_url) AS officer_upload_url, " + |
|||
"itm.quantity, im.item_name " + |
|||
"FROM user_request_table u " + |
|||
"LEFT JOIN items itm ON u.id = itm.req_table_id " + |
|||
"LEFT JOIN item_master im ON itm.iteam_id = im.id AND im.is_active = 1 " + |
|||
"LEFT JOIN status_master sm ON sm.id = u.status AND sm.is_active = 1 AND sm.is_delete = 0 " + |
|||
"WHERE u.status != '2' " + |
|||
"AND u.cdate <= ( CURDATE() - INTERVAL ((WEEKDAY(CURDATE()) + 5) % 7) DAY ) " + |
|||
"AND u.is_active = 1 AND " + zoneCondition; |
|||
|
|||
List<Map<String, Object>> rawData = jdbcDomesticWasteTemplate.queryForList(sql, params.toArray()); |
|||
return groupRequestsWithItems(rawData); |
|||
} |
|||
|
|||
|
|||
public List<Map<String, Object>> getuserZonal(String loginId) { |
|||
String zoneSql = "SELECT zone, division FROM officer_master WHERE loginId = ? AND is_active = 1 AND is_delete = 0"; |
|||
List<Map<String, Object>> zoneList = jdbcDomesticWasteTemplate.queryForList(zoneSql, loginId); |
|||
|
|||
//if (zoneList.isEmpty()) return List.of(); |
|||
if (zoneList.isEmpty()) { |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
return Collections.singletonList(response); // or just `response` depending on your return type |
|||
} |
|||
|
|||
List<Object> params = new ArrayList<>(); |
|||
StringBuilder zoneCondition = new StringBuilder("("); |
|||
|
|||
for (int i = 0; i < zoneList.size(); i++) { |
|||
Map<String, Object> row = zoneList.get(i); |
|||
zoneCondition.append("(u.zone = ? AND u.division = ?)"); |
|||
if (i < zoneList.size() - 1) zoneCondition.append(" OR "); |
|||
params.add(row.get("zone")); |
|||
params.add(row.get("division")); |
|||
} |
|||
zoneCondition.append(")"); |
|||
|
|||
String sql = "SELECT " + |
|||
"u.id, u.request_id, u.user_name, u.mobile, u.address, u.latitude, u.longitude, " + |
|||
"u.zone, u.division, u.street_name, u.remarks, " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', u.image_url) AS image_url, " + |
|||
"DATE_FORMAT(u.cdate, '%d-%m-%Y') AS cdate, " + |
|||
"u.is_active, u.is_delete, u.street_id, sm.status_master AS status, u.is_app, " + |
|||
"DATE_FORMAT(u.close_date, '%d-%m-%Y') AS close_date, " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', u.officer_upload_url) AS officer_upload_url, " + |
|||
"itm.quantity, im.item_name " + |
|||
"FROM user_request_table u " + |
|||
"LEFT JOIN items itm ON u.id = itm.req_table_id " + |
|||
"LEFT JOIN item_master im ON itm.iteam_id = im.id AND im.is_active = 1 " + |
|||
"LEFT JOIN status_master sm ON sm.id = u.status AND sm.is_active = 1 AND sm.is_delete = 0 " + |
|||
"WHERE u.status != '2' " + |
|||
"AND u.cdate <= ( CURDATE() - INTERVAL ((WEEKDAY(CURDATE()) + 4) % 7) DAY ) " + |
|||
"AND u.is_active = 1 AND " + zoneCondition; |
|||
|
|||
List<Map<String, Object>> rawData = jdbcDomesticWasteTemplate.queryForList(sql, params.toArray()); |
|||
return groupRequestsWithItems(rawData); |
|||
} |
|||
|
|||
|
|||
public List<Map<String, Object>> userdetailsfilter(int id) { |
|||
String fileBaseUrl = environment.getProperty("fileBaseUrl"); |
|||
|
|||
// Step 1: Fetch zone, division, and street_id for the given request ID |
|||
String sql = "SELECT zone, division, street_id FROM user_request_table WHERE id = ?"; |
|||
List<Map<String, Object>> result = jdbcDomesticWasteTemplate.queryForList(sql, id); |
|||
|
|||
if (result.isEmpty()) { |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
return Collections.singletonList(response); // or just `response` depending on your return type |
|||
} |
|||
|
|||
Map<String, Object> user = result.get(0); |
|||
String zone = (String) user.get("zone"); |
|||
String division = (String) user.get("division"); |
|||
Object streetIdObj = user.get("street_id"); |
|||
|
|||
// Step 2: Construct dynamic SQL query with/without street_id |
|||
String finalSql; |
|||
List<Object> params = new ArrayList<>(); |
|||
params.add(zone); |
|||
params.add(division); |
|||
|
|||
if (streetIdObj != null && !streetIdObj.toString().isBlank()) { |
|||
params.add(streetIdObj); |
|||
params.add(id); |
|||
finalSql = "SELECT u.id, u.request_id, u.user_name, u.mobile, u.address, u.latitude, u.longitude, " + |
|||
"u.zone, u.division, u.street_name, u.remarks, " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', u.image_url) AS image_url, " + |
|||
"DATE_FORMAT(u.cdate, '%d-%m-%Y') AS cdate, u.is_active, u.is_delete, u.street_id, " + |
|||
"sm.status_master AS status, u.is_app, DATE_FORMAT(u.close_date, '%d-%m-%Y') AS close_date, " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', u.officer_upload_url) AS officer_upload_url, " + |
|||
"itm.quantity, im.item_name " + |
|||
"FROM user_request_table u " + |
|||
"LEFT JOIN items itm ON u.id = itm.req_table_id " + |
|||
"LEFT JOIN item_master im ON itm.iteam_id = im.id AND im.is_active = 1 " + |
|||
"LEFT JOIN status_master sm ON sm.id = u.status AND sm.is_active = 1 AND sm.is_delete = 0 " + |
|||
"WHERE u.zone = ? AND u.division = ? AND u.street_id = ? AND u.id = ? AND u.is_active = 1"; |
|||
} else { |
|||
params.add(id); |
|||
finalSql = "SELECT u.id, u.request_id, u.user_name, u.mobile, u.address, u.latitude, u.longitude, " + |
|||
"u.zone, u.division, u.street_name, u.remarks, " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', u.image_url) AS image_url, " + |
|||
"DATE_FORMAT(u.cdate, '%d-%m-%Y') AS cdate, u.is_active, u.is_delete, u.street_id, " + |
|||
"sm.status_master AS status, u.is_app, DATE_FORMAT(u.close_date, '%d-%m-%Y') AS close_date, " + |
|||
"CONCAT('" + fileBaseUrl + "/gccofficialapp/files', u.officer_upload_url) AS officer_upload_url, " + |
|||
"itm.quantity, im.item_name " + |
|||
"FROM user_request_table u " + |
|||
"LEFT JOIN items itm ON u.id = itm.req_table_id " + |
|||
"LEFT JOIN item_master im ON itm.iteam_id = im.id AND im.is_active = 1 " + |
|||
"LEFT JOIN status_master sm ON sm.id = u.status AND sm.is_active = 1 AND sm.is_delete = 0 " + |
|||
"WHERE u.zone = ? AND u.division = ? AND u.id = ? AND u.is_active = 1"; |
|||
} |
|||
|
|||
List<Map<String, Object>> rawData = jdbcDomesticWasteTemplate.queryForList(finalSql, params.toArray()); |
|||
return groupRequestsWithItems(rawData); |
|||
} |
|||
|
|||
|
|||
public Map<String, Object> actionTaken(String requestId, MultipartFile imageFile, int createdBy,String latitude,String longitude ) { |
|||
try { |
|||
// Step 0: Fetch internal id using requestId |
|||
String fetchIdSql = "SELECT id FROM user_request_table WHERE request_id = ?"; |
|||
List<Integer> idList = jdbcDomesticWasteTemplate.queryForList(fetchIdSql, new Object[]{requestId}, Integer.class); |
|||
if (idList.isEmpty()) { |
|||
return Map.of("status", false, "message", "No record found for the given requestId: " + requestId); |
|||
} |
|||
Integer id = idList.get(0); |
|||
|
|||
// Step 1: Upload image |
|||
String imagePath = fileUpload(imageFile, "officer_action_photo"); |
|||
|
|||
// Step 2: Insert into officer_data |
|||
String insertSql = "INSERT INTO officer_data (request_id, image_url, cdate, is_active, created_by,latitude,longitude) " + |
|||
"VALUES (?, ?, NOW(), ?, ?,?,?)"; |
|||
jdbcDomesticWasteTemplate.update(insertSql, requestId, imagePath, true, createdBy,latitude,longitude); |
|||
|
|||
// Step 3: Update user_request_table - status, officer_upload_url, and close_date from officer_data |
|||
String updateSql = "UPDATE user_request_table u " + |
|||
"JOIN officer_data o ON o.request_id = u.request_id " + |
|||
"SET u.status = '1', " + |
|||
" u.officer_upload_url = ?, " + |
|||
" u.close_date = DATE(o.cdate) " + |
|||
"WHERE u.id = ?"; |
|||
jdbcDomesticWasteTemplate.update(updateSql, imagePath, id); |
|||
|
|||
|
|||
|
|||
return Map.of("status", true, "message", "Action taken recorded successfully"); |
|||
|
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return Map.of("status", false, "message", "Error: " + e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
//scheduler method |
|||
public Map<String, Object> updateOrderStatus(String status) { |
|||
try { |
|||
String sql = "UPDATE user_request_table " + |
|||
"SET status = ? " + |
|||
"WHERE status = '1' AND DATE(cdate) < CURDATE()";// |
|||
|
|||
int updated = jdbcDomesticWasteTemplate.update(sql, status); |
|||
|
|||
return Map.of("status", true, "message", "Order status updated", "rowsAffected", updated); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return Map.of("status", false, "message", "Error: " + e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
//to group items and quantity common method |
|||
private List<Map<String, Object>> groupRequestsWithItems(List<Map<String, Object>> flatList) { |
|||
Map<Integer, Map<String, Object>> groupedMap = new LinkedHashMap<>(); |
|||
|
|||
for (Map<String, Object> row : flatList) { |
|||
Integer id = (Integer) row.get("id"); |
|||
|
|||
if (!groupedMap.containsKey(id)) { |
|||
Map<String, Object> base = new LinkedHashMap<>(row); |
|||
base.remove("item_name"); |
|||
base.remove("quantity"); |
|||
base.remove("iteam_id"); |
|||
base.put("items", new ArrayList<Map<String, Object>>()); |
|||
groupedMap.put(id, base); |
|||
} |
|||
|
|||
Map<String, Object> item = new LinkedHashMap<>(); |
|||
item.put("item_name", row.get("item_name")); |
|||
item.put("quantity", row.get("quantity")); |
|||
|
|||
((List<Map<String, Object>>) groupedMap.get(id).get("items")).add(item); |
|||
} |
|||
|
|||
//return new ArrayList<>(groupedMap.values()); |
|||
List<Object> result = new ArrayList<>(groupedMap.values()); |
|||
|
|||
if (result.isEmpty()) { |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
return Collections.singletonList(response); // or just `response` depending on your return type |
|||
} else { |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", true); |
|||
response.put("message", "Data retrieved successfully"); |
|||
response.put("data", result); |
|||
return Collections.singletonList(response); // or `response` directly |
|||
} |
|||
} |
|||
|
|||
public boolean verifylatlong(String requestId, String latitude, String longitude) { |
|||
int radius = 50; |
|||
|
|||
try { |
|||
String sql = "SELECT 1 FROM user_request_table u " + |
|||
"WHERE u.request_id = ? AND " + |
|||
"((6371008.8 * ACOS(" + |
|||
"COS(RADIANS(?)) * COS(RADIANS(u.latitude)) * COS(RADIANS(u.longitude) - RADIANS(?)) + " + |
|||
"SIN(RADIANS(?)) * SIN(RADIANS(u.latitude)))) < ?)"; |
|||
|
|||
List<Map<String, Object>> rows = jdbcDomesticWasteTemplate.queryForList(sql, |
|||
requestId, latitude, longitude, latitude, radius); |
|||
|
|||
return !rows.isEmpty(); // true if one or more rows match the criteria |
|||
|
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
|
|||
public Map<String, Object> rejectuserreq(String requestId) { |
|||
try { |
|||
// Step 0: Fetch internal id using requestId |
|||
String fetchIdSql = "SELECT id FROM user_request_table WHERE request_id = ?"; |
|||
Integer id = jdbcDomesticWasteTemplate.queryForObject(fetchIdSql, new Object[]{requestId}, Integer.class); |
|||
if (id == null) { |
|||
return Map.of("status", false, "message", "No record found for the given requestId"); |
|||
} |
|||
|
|||
// Step 1: Update using id |
|||
String sql = "UPDATE user_request_table SET status = '4' WHERE id = ?"; |
|||
jdbcDomesticWasteTemplate.update(sql, id); |
|||
|
|||
return Map.of("status", true, "message", "Rejected user request successfully"); |
|||
|
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return Map.of("status", false, "message", "Error: " + e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
public Map<String, Object> rejectuserreqofficer(String requestId, String officer_remark, |
|||
String rejecttype, int cancelled_by, |
|||
String latitude, String longitude){ |
|||
try { |
|||
// Step 0: Fetch internal id using requestId |
|||
String fetchIdSql = "SELECT id FROM user_request_table WHERE request_id = ?"; |
|||
Integer id = jdbcDomesticWasteTemplate.queryForObject(fetchIdSql, new Object[]{requestId}, Integer.class); |
|||
if (id == null) { |
|||
return Map.of("status", false, "message", "No record found for the given requestId"); |
|||
} |
|||
|
|||
// Step 1: Proper SQL with commas |
|||
String sql = "UPDATE user_request_table SET `status` = '5', officer_remark = ?, " |
|||
+ "cancelled_by = ?, rejecttype = ?, reject_latitude = ?, reject_longitude = ? WHERE id = ?"; |
|||
|
|||
jdbcDomesticWasteTemplate.update(sql, officer_remark, cancelled_by, rejecttype, latitude, longitude, id); |
|||
|
|||
return Map.of("status", true, "message", "Rejected user request successfully"); |
|||
|
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return Map.of("status", false, "message", "Error: " + e.getMessage()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,531 @@ |
|||
package in.gov.chennaicorporation.mobileservice.gccpothole.controller; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.time.LocalDateTime; |
|||
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.http.HttpStatus; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import in.gov.chennaicorporation.mobileservice.gccpothole.service.PotholeService; |
|||
|
|||
|
|||
@RequestMapping("/gccofficialapp/api/pothole") |
|||
@RestController("gccofficialapppothole") |
|||
|
|||
public class PotholeApiController { |
|||
|
|||
|
|||
@Autowired |
|||
private PotholeService potholeService; |
|||
|
|||
|
|||
@PostMapping("/save-complaint") |
|||
public ResponseEntity<Map<String, Object>> saveNewComplaints( |
|||
|
|||
@RequestParam("zone") String zone, |
|||
@RequestParam("ward") String ward, |
|||
@RequestParam(required = false, name = "latitude") String latitude, |
|||
@RequestParam(required = false, name = "longitude") String longitude, |
|||
@RequestParam(required = false, name = "length") String length, |
|||
@RequestParam(required = false, name = "width") String width, |
|||
@RequestParam(required = false, name = "area") String area, |
|||
@RequestParam("case_id") String caseId, |
|||
@RequestParam("street_id") String streetId, |
|||
@RequestParam("street_name") String streetName, |
|||
@RequestParam("status_id") String statusId, |
|||
@RequestParam(required = true, name = "complaint_photo") MultipartFile complaintPhoto, |
|||
@RequestParam("login_id") String loginId, |
|||
@RequestParam(required = false, name = "user_length") String userLength, |
|||
@RequestParam(required = false, name = "user_width") String userWidth, |
|||
@RequestParam(required = false, name = "user_height") String userHeight, |
|||
@RequestParam("risk_level") String riskLevel, |
|||
@RequestParam(required = false, name = "damage_type") String damage_type) { |
|||
|
|||
// File upload paths |
|||
String complaintPhotoPath = (complaintPhoto != null) ? |
|||
potholeService.fileUpload(complaintPhoto, "complaint_photo") : ""; |
|||
|
|||
// Save to DB |
|||
String saveStatus = potholeService.saveComplaintDetails( |
|||
zone, ward, latitude, longitude, length, width, area, streetId, |
|||
streetName, statusId, complaintPhotoPath, loginId, caseId, userLength, userWidth, userHeight, riskLevel, damage_type); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (saveStatus == null || saveStatus.isEmpty() || saveStatus.equals("error")) { |
|||
response.put("status", false); |
|||
response.put("message", "failed"); |
|||
response.put("description", "Failed to save the details"); |
|||
return ResponseEntity.ok(response); |
|||
} else if (saveStatus.equals("duplicate")) { |
|||
response.put("status", false); |
|||
response.put("message", "failed"); |
|||
response.put("description", "Complaints already exist"); |
|||
return ResponseEntity.ok(response); |
|||
} |
|||
|
|||
response.put("status", true); |
|||
response.put("message", "success"); |
|||
response.put("description", "Details were saved successfully"); |
|||
return ResponseEntity.ok(response); |
|||
} |
|||
|
|||
// Status Master |
|||
@GetMapping("/status") |
|||
public List<Map<String, Object>> getAllStatus() { |
|||
return potholeService.getAllStatus(); |
|||
} |
|||
|
|||
// AE Complaint List against ward |
|||
@GetMapping("/aecomplaintlist") |
|||
public ResponseEntity<Map<String, Object>> getComplaintsByWard(@RequestParam("aeUserId") String aeUserId) { |
|||
List<Map<String, Object>> result = potholeService.getComplaintsByWard(aeUserId); |
|||
|
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (result.isEmpty()) { |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
response.put("data", Collections.emptyList()); |
|||
} else { |
|||
response.put("status", true); |
|||
response.put("message", "Data found"); |
|||
response.put("data", result); |
|||
} |
|||
|
|||
//System.out.println("result: " + result); |
|||
return ResponseEntity.ok(response); |
|||
} |
|||
|
|||
// Vendor Complaint List against ward |
|||
@GetMapping("/vendor") |
|||
public ResponseEntity<Map<String, Object>> getComplaintsByVendor(@RequestParam("vendorUserId") String vendorUserId) { |
|||
List<Map<String, Object>> result = potholeService.getComplaintsByVendorId(vendorUserId); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (result.isEmpty()) { |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
response.put("data", Collections.emptyList()); |
|||
} else { |
|||
response.put("status", true); |
|||
response.put("message", "Data found"); |
|||
response.put("data", result); |
|||
} |
|||
|
|||
return ResponseEntity.ok(response); |
|||
} |
|||
|
|||
// My Complaint List |
|||
@GetMapping("/viewRequestList") |
|||
public ResponseEntity<Map<String, Object>> viewRequestList(@RequestParam("loginId") String loginId) { |
|||
|
|||
List<Map<String, Object>> result = potholeService.getRequestList(loginId); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (result.isEmpty()) { |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
response.put("data", Collections.emptyList()); |
|||
} else { |
|||
response.put("status", true); |
|||
response.put("message", "Data found"); |
|||
response.put("data", result); |
|||
} |
|||
|
|||
return ResponseEntity.ok(response); |
|||
|
|||
} |
|||
|
|||
// Vendor Update |
|||
|
|||
@PostMapping("/updateComplaint") |
|||
public ResponseEntity<Map<String, Object>> updateComplaint(@RequestParam("zone") String zone, |
|||
@RequestParam("ward") String ward, @RequestParam(name = "latitude") String latitude, |
|||
@RequestParam(name = "longitude") String longitude, |
|||
@RequestParam(required = false, name = "length") String length, |
|||
@RequestParam(required = false, name = "width") String width, |
|||
@RequestParam(required = false, name = "area") String area, |
|||
@RequestParam("street_id") String streetId, |
|||
@RequestParam("street_name") String streetName, |
|||
@RequestParam("status_id") String statusId, |
|||
@RequestParam("complaint_photo") MultipartFile vendorPhoto, |
|||
@RequestParam("login_id") String loginId, |
|||
@RequestParam("complaint_no") String complaint_no, |
|||
@RequestParam(required = false, name = "vendor_length") String vendorLength, |
|||
@RequestParam(required = false, name = "vendor_width") String vendorWidth, |
|||
@RequestParam(required = false, name = "vendor_height") String vendorHeight, |
|||
@RequestParam(required = false, name = "ae_length") String aeLength, |
|||
@RequestParam(required = false, name = "ae_width") String aeWidth, |
|||
@RequestParam(required = false, name = "ae_height") String aeHeight) { |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
|
|||
String vendorPhotoPath = null; |
|||
//LocalDate updatedDate = LocalDate.now(); |
|||
LocalDateTime updatedDate = LocalDateTime.now(); |
|||
|
|||
if (statusId.equals("2")) { |
|||
vendorPhotoPath = (vendorPhoto != null) ? potholeService.fileUpload(vendorPhoto, "vendor_photo") : ""; |
|||
|
|||
} else if (statusId.equals("4")) { |
|||
vendorPhotoPath = (vendorPhoto != null) ? potholeService.fileUpload(vendorPhoto, "rectified_photo") : ""; |
|||
|
|||
} else if (statusId.equals("3")) { |
|||
vendorPhotoPath = (vendorPhoto != null) ? potholeService.fileUpload(vendorPhoto, "reopen_photo") : ""; |
|||
|
|||
} else if (statusId.equals("5")) { |
|||
vendorPhotoPath = (vendorPhoto != null) ? potholeService.fileUpload(vendorPhoto, "completed_photo") : ""; |
|||
|
|||
} else { |
|||
vendorPhotoPath = null; |
|||
|
|||
} |
|||
|
|||
String updationStatus = potholeService.updateComplaintbyVendor(statusId, loginId, updatedDate, vendorLength, vendorWidth, vendorHeight, |
|||
vendorPhotoPath, aeLength, aeWidth, aeHeight, complaint_no); |
|||
|
|||
if (updationStatus.equals("Success")) { |
|||
response.put("status", true); |
|||
response.put("message", "success"); |
|||
response.put("description", "Details were saved successfully"); |
|||
System.out.println(response); |
|||
return ResponseEntity.ok(response); |
|||
} |
|||
|
|||
response.put("status", false); |
|||
response.put("message", "Failed to update complaint Details"); |
|||
//System.err.println("Pot Hole : "+ updationStatus); |
|||
return ResponseEntity |
|||
.status(HttpStatus.INTERNAL_SERVER_ERROR) |
|||
.body(response); |
|||
|
|||
} |
|||
|
|||
@GetMapping("/validateLocation") |
|||
public ResponseEntity<Map<String, Object>> validateLocation(@RequestParam(name = "latitude") String latitude, |
|||
@RequestParam(name = "longitude") String longitude, @RequestParam("complaint_no") String complaint_no) { |
|||
|
|||
boolean locationStatus = false; |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
|
|||
if (!latitude.isEmpty() && !longitude.isEmpty() && latitude != null && longitude != null) { |
|||
locationStatus = potholeService.checkLocation(latitude, longitude); |
|||
} |
|||
|
|||
if (locationStatus) { |
|||
response.put("status", true); |
|||
response.put("message", "Location Matched"); |
|||
return ResponseEntity.ok(response); |
|||
} |
|||
|
|||
response.put("status", false); |
|||
response.put("message", "Location Issue"); |
|||
response.put("description", "Please go to nearest location"); |
|||
return ResponseEntity.ok(response); |
|||
|
|||
} |
|||
|
|||
// report related api |
|||
|
|||
// zone wise AE pending and completed |
|||
|
|||
@GetMapping("/ae-zone-wise") |
|||
public ResponseEntity<Map<String, Object>> getZoneWiseAEReport( |
|||
@RequestParam("fromDate") String fromDate, |
|||
@RequestParam("toDate") String toDate, |
|||
@RequestParam(required = false, name = "damage_type") String damage_type) { |
|||
|
|||
List<Map<String, Object>> report = potholeService.getZoneWiseAEReport(fromDate, toDate, damage_type); |
|||
|
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (report.isEmpty()) { |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
response.put("data", Collections.emptyList()); |
|||
} else { |
|||
response.put("status", true); |
|||
response.put("message", "Data found"); |
|||
response.put("data", report); |
|||
} |
|||
|
|||
return ResponseEntity.ok(response); |
|||
|
|||
} |
|||
|
|||
|
|||
@GetMapping("/ae-ward-wise") |
|||
public ResponseEntity<Map<String, Object>> getWardWiseAEReport( |
|||
@RequestParam("fromDate") String fromDate, |
|||
@RequestParam("toDate") String toDate, |
|||
@RequestParam("zone") String zone, |
|||
@RequestParam(required = false, name = "damage_type") String damage_type) { |
|||
|
|||
List<Map<String, Object>> report = potholeService.getWardWiseAEReport(fromDate, toDate, zone, damage_type); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (report.isEmpty()) { |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
response.put("data", Collections.emptyList()); |
|||
} else { |
|||
response.put("status", true); |
|||
response.put("message", "Data found"); |
|||
response.put("data", report); |
|||
} |
|||
|
|||
return ResponseEntity.ok(response); |
|||
|
|||
} |
|||
|
|||
|
|||
// report api for zone wise Vendor pending and completed |
|||
|
|||
|
|||
@GetMapping("/vendor-zone-wise") |
|||
public ResponseEntity<Map<String, Object>> getZoneVendorWiseReport( |
|||
@RequestParam("fromDate") String fromDate, |
|||
@RequestParam("toDate") String toDate, |
|||
@RequestParam(required = false, name = "damage_type") String damage_type) { |
|||
|
|||
List<Map<String, Object>> report = potholeService.getZoneWiseVendorReport(fromDate, toDate, damage_type); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (report.isEmpty()) { |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
response.put("data", Collections.emptyList()); |
|||
} else { |
|||
response.put("status", true); |
|||
response.put("message", "Data found"); |
|||
response.put("data", report); |
|||
} |
|||
|
|||
return ResponseEntity.ok(response); |
|||
} |
|||
|
|||
|
|||
@GetMapping("/vendor-ward-wise") |
|||
public ResponseEntity<Map<String, Object>> getWardWiseVendorReport( |
|||
@RequestParam("fromDate") String fromDate, |
|||
@RequestParam("toDate") String toDate, |
|||
@RequestParam("zone") String zone, |
|||
@RequestParam(required = false, name = "damage_type") String damage_type) { |
|||
|
|||
List<Map<String, Object>> report = potholeService.getWardWiseVendorReport(fromDate, toDate, zone, damage_type); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (report.isEmpty()) { |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
response.put("data", Collections.emptyList()); |
|||
} else { |
|||
response.put("status", true); |
|||
response.put("message", "Data found"); |
|||
response.put("data", report); |
|||
} |
|||
|
|||
return ResponseEntity.ok(response); |
|||
} |
|||
|
|||
|
|||
@GetMapping("/getdetailsbycomplaintno") |
|||
public ResponseEntity<Map<String, Object>> getDetailsByComplaintNo(@RequestParam("complaintNo") String complaintNo) { |
|||
|
|||
List<Map<String, Object>> result = potholeService.getDetailsByComplaintNo(complaintNo); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (result.isEmpty()) { |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
response.put("data", Collections.emptyList()); |
|||
} else { |
|||
response.put("status", true); |
|||
response.put("message", "Data found"); |
|||
response.put("data", result); |
|||
} |
|||
|
|||
return ResponseEntity.ok(response); |
|||
|
|||
} |
|||
|
|||
|
|||
// get the details by between date,zone and ward |
|||
@GetMapping("/getcomplaintdetails") |
|||
public ResponseEntity<Map<String, Object>> getComplaintDetails( |
|||
|
|||
@RequestParam("fromDate") String fromDate, |
|||
@RequestParam("toDate") String toDate, |
|||
@RequestParam("zone") String zone, |
|||
@RequestParam("ward") String ward, |
|||
@RequestParam("streetId") String streetId, |
|||
@RequestParam(required = false, name = "damage_type") String damage_type, |
|||
@RequestParam(required = false, name = "status") String status |
|||
) { |
|||
|
|||
List<Map<String, Object>> result = potholeService.getAllComplaintNo(fromDate, toDate, zone, ward, streetId, damage_type, status); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (result.isEmpty()) { |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
response.put("data", Collections.emptyList()); |
|||
} else { |
|||
response.put("status", true); |
|||
response.put("message", "Data found"); |
|||
response.put("data", result); |
|||
} |
|||
|
|||
return ResponseEntity.ok(response); |
|||
|
|||
} |
|||
|
|||
@GetMapping("/getstreetdetails-ae") |
|||
public ResponseEntity<Map<String, Object>> getStreetDetails( |
|||
|
|||
@RequestParam("fromDate") String fromDate, |
|||
@RequestParam("toDate") String toDate, |
|||
@RequestParam("zone") String zone, |
|||
@RequestParam("ward") String ward, |
|||
@RequestParam(required = false, name = "damage_type") String damage_type) { |
|||
|
|||
List<Map<String, Object>> result = potholeService.getStreetDetailsAE(fromDate, toDate, zone, ward, damage_type); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (result.isEmpty()) { |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
response.put("data", Collections.emptyList()); |
|||
} else { |
|||
response.put("status", true); |
|||
response.put("message", "Data found"); |
|||
response.put("data", result); |
|||
} |
|||
|
|||
return ResponseEntity.ok(response); |
|||
|
|||
} |
|||
|
|||
@GetMapping("/getstreetdetails-vendor") |
|||
public ResponseEntity<Map<String, Object>> getStreetDetailsVendor( |
|||
@RequestParam("fromDate") String fromDate, |
|||
@RequestParam("toDate") String toDate, |
|||
@RequestParam("zone") String zone, |
|||
@RequestParam("ward") String ward, |
|||
@RequestParam(required = false, name = "damage_type") String damage_type) { |
|||
|
|||
List<Map<String, Object>> result = potholeService.getStreetDetailsVE(fromDate, toDate, zone, ward, damage_type); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (result.isEmpty()) { |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
response.put("data", Collections.emptyList()); |
|||
} else { |
|||
response.put("status", true); |
|||
response.put("message", "Data found"); |
|||
response.put("data", result); |
|||
} |
|||
|
|||
return ResponseEntity.ok(response); |
|||
|
|||
} |
|||
|
|||
// to save user complaints - new API |
|||
|
|||
@PostMapping("/save-user-complaint") |
|||
public ResponseEntity<Map<String, Object>> saveUserComplaints( |
|||
@RequestParam("zone") String zone, |
|||
@RequestParam("ward") String ward, |
|||
@RequestParam(required = false, name = "latitude") String latitude, |
|||
@RequestParam(required = false, name = "longitude") String longitude, |
|||
@RequestParam(required = false, name = "length") String length, |
|||
@RequestParam(required = false, name = "width") String width, |
|||
@RequestParam(required = false, name = "area") String area, |
|||
@RequestParam("case_id") String caseId, |
|||
@RequestParam("street_id") String streetId, |
|||
@RequestParam("street_name") String streetName, |
|||
@RequestParam("status_id") String statusId, |
|||
@RequestParam(required = true, name = "complaint_photo") MultipartFile complaintPhoto, |
|||
@RequestParam(required = false, name = "user_length") String userLength, |
|||
@RequestParam(required = false, name = "user_width") String userWidth, |
|||
@RequestParam(required = false, name = "user_height") String userHeight, |
|||
@RequestParam("risk_level") String riskLevel) { |
|||
|
|||
// File upload paths |
|||
String complaintPhotoPath = (complaintPhoto != null) ? |
|||
potholeService.fileUpload(complaintPhoto, "user_complaint_photo") : ""; |
|||
|
|||
// Save to DB |
|||
String saveStatus = potholeService.saveUserComplaintDetails( |
|||
zone, ward, latitude, longitude, length, width, area, streetId, |
|||
streetName, statusId, complaintPhotoPath, caseId, userLength, userWidth, userHeight, riskLevel); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (saveStatus == null || saveStatus.isEmpty() || saveStatus.equals("error")) { |
|||
response.put("status", false); |
|||
response.put("message", "failed"); |
|||
response.put("description", "Failed to save the details"); |
|||
return ResponseEntity.ok(response); |
|||
} else if (saveStatus.equals("duplicate")) { |
|||
response.put("status", false); |
|||
response.put("message", "failed"); |
|||
response.put("description", "Complaints already exist"); |
|||
return ResponseEntity.ok(response); |
|||
} |
|||
|
|||
response.put("status", true); |
|||
response.put("message", "success"); |
|||
response.put("description", "Details were saved successfully"); |
|||
return ResponseEntity.ok(response); |
|||
} |
|||
|
|||
// get Pending user request for Approval |
|||
@GetMapping("/getPendingApprovalList") |
|||
public ResponseEntity<Map<String, Object>> getPendingUserRequest(@RequestParam String loginId, |
|||
@RequestParam(required = false, name="fromDate") String fromDate, |
|||
@RequestParam(required = false, name="toDate") String toDate){ |
|||
|
|||
List<Map<String, Object>> result = potholeService.getPendingUserRequest(loginId, fromDate, toDate); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (result.isEmpty()) { |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
response.put("data", Collections.emptyList()); |
|||
} else { |
|||
response.put("status", true); |
|||
response.put("message", "Data found"); |
|||
response.put("data", result); |
|||
} |
|||
|
|||
return ResponseEntity.ok(response); |
|||
} |
|||
|
|||
// save AE approval of pending user request |
|||
@PostMapping("/approveUserRequest") |
|||
public ResponseEntity<Map<String, Object>> approveUserRequest(@RequestParam String loginId, @RequestParam String complaintNo, |
|||
@RequestParam(required = false, name="remarks") String remarks, |
|||
@RequestParam String status, @RequestParam String locationStatus){ |
|||
|
|||
Map<String,Object> result = potholeService.approveUserRequest(loginId, complaintNo, remarks, status, locationStatus); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (result.isEmpty()) { |
|||
response.put("status", false); |
|||
response.put("message", "No data found"); |
|||
response.put("data", Collections.emptyList()); |
|||
} else { |
|||
response.put("status", true); |
|||
response.put("message", "Data found"); |
|||
response.put("data", result); |
|||
} |
|||
|
|||
return ResponseEntity.ok(response); |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.gccpothole.controller; |
|||
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.gccpothole; |
|||
1031
mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccpothole/service/PotholeService.java
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.gccpothole.service; |
|||
@ -0,0 +1,29 @@ |
|||
package in.gov.chennaicorporation.mobileservice.penalty.controller; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import in.gov.chennaicorporation.mobileservice.penalty.service.PenaltyPrintService; |
|||
|
|||
@RequestMapping("/gccofficialapp/api/penalty") |
|||
@RestController("apiPenaltyprintRest") |
|||
public class APICommonPrintController { |
|||
@Autowired |
|||
private PenaltyPrintService penaltyPrintService; |
|||
|
|||
@GetMapping(value="/getSuccessList") |
|||
public List<Map<String, Object>> getPenaltyTypes( |
|||
@RequestParam(value = "loginId", required = true) String loginId, |
|||
@RequestParam(value = "type", required = true) int type, |
|||
@RequestParam(value = "fromDate", required = true) String fromDate, |
|||
@RequestParam(value = "toDate", required = true) String toDate |
|||
) { |
|||
return penaltyPrintService.getSuccessList(loginId, type,fromDate,toDate); |
|||
} |
|||
} |
|||
@ -0,0 +1,204 @@ |
|||
package in.gov.chennaicorporation.mobileservice.penalty.service; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Collections; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
import javax.sql.DataSource; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Qualifier; |
|||
import org.springframework.core.env.Environment; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
@Service |
|||
public class PenaltyPrintService { |
|||
private JdbcTemplate jdbcPenaltyTemplate; |
|||
private final Environment environment; |
|||
private String fileBaseUrl; |
|||
|
|||
@Autowired |
|||
public void setDataSource(@Qualifier("mysqlActivityDataSource") DataSource penaltyDataSource) { |
|||
this.jdbcPenaltyTemplate = new JdbcTemplate(penaltyDataSource); |
|||
} |
|||
|
|||
@Autowired |
|||
public PenaltyPrintService(Environment environment) { |
|||
this.environment = environment; |
|||
this.fileBaseUrl=environment.getProperty("fileBaseUrl"); |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> getSuccessList(String loginId, int type, String fromDate, String toDate) { |
|||
List<Map<String, Object>> result = new ArrayList<>(); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
switch (type) { |
|||
case 1: |
|||
result = getPenalty_SuccessList(loginId, fromDate, toDate); |
|||
break; |
|||
case 2: |
|||
result = getCattle_SuccessList(loginId, fromDate, toDate); |
|||
break; |
|||
case 3: |
|||
result = getHoarding_SuccessList(loginId, fromDate, toDate); |
|||
break; |
|||
default: |
|||
// Optional: throw exception if type is invalid |
|||
//throw new IllegalArgumentException("Invalid type: " + type); |
|||
response.put("status", 400); |
|||
response.put("message", "Invalid type: " + type); |
|||
response.put("data", Collections.emptyList()); |
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
response.put("status", 200); |
|||
response.put("message", "Fine Collected List"); |
|||
response.put("data", result); |
|||
|
|||
//return Collections.singletonList(response); |
|||
return result; |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> getPenalty_SuccessList(String loginId, String fromDate, String toDate) { |
|||
String sqlQuery = |
|||
"SELECT " + |
|||
" bt.id, " + |
|||
" bt.mid, " + |
|||
" bt.tid, " + |
|||
" bt.transactionResponseStatus, " + |
|||
" bt.txnCode, " + |
|||
" bt.txnId, " + |
|||
" bt.bankName, " + |
|||
" bt.batchNumber, " + |
|||
" bt.transactionAmount, " + |
|||
" bt.transactionTitle, " + |
|||
" bt.txnAID, " + |
|||
" bt.txnApprCode, " + |
|||
" bt.txnCardNo, " + |
|||
" bt.txnCardType, " + |
|||
" DATE_FORMAT(bt.txnDate, '%d-%m-%Y') AS txnDate, " + |
|||
" bt.txnInvoice, " + |
|||
" bt.txnMode, " + |
|||
" bt.txnRefNo, " + |
|||
" bt.txnTC, " + |
|||
" bt.txnTSI, " + |
|||
" bt.txnTVR, " + |
|||
" bt.txnTime, " + |
|||
" bt.branchname, " + |
|||
" bt.extraInfo, " + |
|||
" bt.extraInfo2, " + |
|||
" bt.extraInfo3, " + |
|||
" bt.file, " + |
|||
" bt.loginId, " + |
|||
" c3.violator_name, " + |
|||
" c3.violator_phone, " + |
|||
" c3.orderid, " + |
|||
" pc.name AS penaltyType " + |
|||
"FROM gcc_penalty_pos.bank_transactions bt " + |
|||
"LEFT JOIN gcc_penalty_pos.penalty_challan c3 ON bt.txnId = c3.orderid " + |
|||
"LEFT JOIN gcc_penalty_pos.penalty_category pc ON c3.category_id = pc.id " + |
|||
"WHERE bt.txnDate BETWEEN ? AND ? " + |
|||
"AND c3.challan_by = ? " + |
|||
"ORDER BY bt.txnDate DESC"; |
|||
|
|||
return jdbcPenaltyTemplate.queryForList(sqlQuery, fromDate, toDate, loginId); |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> getCattle_SuccessList(String loginId, String fromDate, String toDate) { |
|||
String sqlQuery = "SELECT " |
|||
+ " bt.id, " |
|||
+ " bt.mid, " |
|||
+ " bt.tid, " |
|||
+ " bt.transactionResponseStatus, " |
|||
+ " bt.txnCode, " |
|||
+ " bt.txnId, " |
|||
+ " bt.bankName, " |
|||
+ " bt.batchNumber, " |
|||
+ " bt.transactionAmount, " |
|||
+ " bt.transactionTitle, " |
|||
+ " bt.txnAID, " |
|||
+ " bt.txnApprCode, " |
|||
+ " bt.txnCardNo, " |
|||
+ " bt.txnCardType, " |
|||
+ " DATE_FORMAT(bt.txnDate, '%d-%m-%Y') AS txnDate, " |
|||
+ " bt.txnInvoice, " |
|||
+ " bt.txnMode, " |
|||
+ " bt.txnRefNo, " |
|||
+ " bt.txnTC, " |
|||
+ " bt.txnTSI, " |
|||
+ " bt.txnTVR, " |
|||
+ " bt.txnTime, " |
|||
+ " bt.branchname, " |
|||
+ " bt.extraInfo, " |
|||
+ " bt.extraInfo2, " |
|||
+ " bt.extraInfo3, " |
|||
+ " bt.file, " |
|||
+ " bt.loginId, " |
|||
+ " c3.violator_name, " |
|||
+ " c3.violator_phone, " |
|||
+ " c3.orderid, " |
|||
+ " 'Cattel Catch' AS penaltyType " |
|||
+ "FROM gcc_penalty.bank_transactions bt " |
|||
+ "LEFT JOIN gcc_penalty.cc_step3 c3 " |
|||
+ " ON bt.txnId = c3.orderid " |
|||
+ "WHERE bt.txnDate BETWEEN ? AND ? " |
|||
+ "AND c3.challan_by = ? " |
|||
+ "ORDER BY bt.txnDate DESC"; |
|||
//System.out.println("SQL : " + sqlQuery); |
|||
//List<Map<String, Object>> result = jdbcPenaltyTemplate.queryForList(sqlQuery); |
|||
return jdbcPenaltyTemplate.queryForList(sqlQuery, fromDate, toDate, loginId); |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> getHoarding_SuccessList(String loginId, String fromDate, String toDate) { |
|||
String sqlQuery = "SELECT " |
|||
+ " bt.id, " |
|||
+ " bt.mid, " |
|||
+ " bt.tid, " |
|||
+ " bt.transactionResponseStatus, " |
|||
+ " bt.txnCode, " |
|||
+ " bt.txnId, " |
|||
+ " bt.bankName, " |
|||
+ " bt.batchNumber, " |
|||
+ " bt.transactionAmount, " |
|||
+ " bt.transactionTitle, " |
|||
+ " bt.txnAID, " |
|||
+ " bt.txnApprCode, " |
|||
+ " bt.txnCardNo, " |
|||
+ " bt.txnCardType, " |
|||
+ " DATE_FORMAT(bt.txnDate, '%d-%m-%Y') AS txnDate, " |
|||
+ " bt.txnInvoice, " |
|||
+ " bt.txnMode, " |
|||
+ " bt.txnRefNo, " |
|||
+ " bt.txnTC, " |
|||
+ " bt.txnTSI, " |
|||
+ " bt.txnTVR, " |
|||
+ " bt.txnTime, " |
|||
+ " bt.branchname, " |
|||
+ " bt.extraInfo, " |
|||
+ " bt.extraInfo2, " |
|||
+ " bt.extraInfo3, " |
|||
+ " bt.file, " |
|||
+ " bt.loginId, " |
|||
+ " c3.agency_name As violator_name, " |
|||
+ " c3.agency_mobile As violator_phone, " |
|||
+ " c3.orderid, " |
|||
+ " 'Hoarding' AS penaltyType " |
|||
+ "FROM gcc_penalty_hoardings.bank_transactions bt " |
|||
+ "LEFT JOIN gcc_penalty_hoardings.hoardings_info c3 " |
|||
+ " ON bt.txnId = c3.orderid " |
|||
+ "WHERE bt.txnDate BETWEEN ? AND ? " |
|||
+ "AND c3.cby = ? " |
|||
+ "ORDER BY bt.txnDate DESC"; |
|||
//System.out.println("SQL : " + sqlQuery); |
|||
//List<Map<String, Object>> result = jdbcPenaltyTemplate.queryForList(sqlQuery); |
|||
return jdbcPenaltyTemplate.queryForList(sqlQuery, fromDate, toDate, loginId); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,189 @@ |
|||
package in.gov.chennaicorporation.mobileservice.privateToilets.controller; |
|||
|
|||
import java.util.List; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.util.MultiValueMap; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import in.gov.chennaicorporation.mobileservice.privateToilets.service.ToiletService; |
|||
|
|||
@RequestMapping("/gccofficialapp/api/privatetoilets/") |
|||
@RestController("gccofficialappsprivatetoiltes") |
|||
public class APIController { |
|||
@Autowired |
|||
private ToiletService toiletService; |
|||
|
|||
@GetMapping(value="/getToiletsList") |
|||
public List<?> getToiletsList(@RequestParam(value="loginId", required = true) String cby){ |
|||
return toiletService.getToiletsList(cby); |
|||
} |
|||
|
|||
@GetMapping("/toiletlistRest") |
|||
public List<?> toiletlistRest(@RequestParam MultiValueMap<String, String> formData, |
|||
@RequestParam(value = "latitude", required = true) String latitude, |
|||
@RequestParam(value = "longitude", required = true) String longitude) { |
|||
return toiletService.toiletlistRest(formData, latitude, longitude); |
|||
} |
|||
|
|||
@GetMapping("/toiletlistbylatlong") |
|||
public List<?> toiletlistbylatlong(@RequestParam MultiValueMap<String, String> formData, |
|||
@RequestParam(value = "latitude", required = true) String latitude, |
|||
@RequestParam(value = "longitude", required = true) String longitude, |
|||
//@RequestParam(value = "assetid", required = true) String id, |
|||
@RequestParam(value = "loginId", required = false) String loginId) { |
|||
return toiletService.toiletlistbylatlong(formData, latitude, longitude,loginId); |
|||
} |
|||
|
|||
@GetMapping(value="/getParentQuestionsList") |
|||
public List<?> getParentQuestionsList(@RequestParam(value="loginId", required = false) String cby){ |
|||
return toiletService.getParentQuestionsList(); |
|||
} |
|||
|
|||
@GetMapping(value="/getChildQuestionsList") |
|||
public List<?> getChildQuestionsList( |
|||
@RequestParam(value="loginId", required = false) String cby, |
|||
@RequestParam(value="pid", required = true) String pid |
|||
){ |
|||
return toiletService.getChildQuestionsList(pid); |
|||
} |
|||
|
|||
@PostMapping(value="/saveFeedback") |
|||
public List<?> saveFeedback( |
|||
@RequestParam(value="toilet_id", required = true) String toilet_id, |
|||
@RequestParam(value="loginId", required = true) String cby, |
|||
@RequestParam(value="latitude", required = true) String latitude, |
|||
@RequestParam(value="longitude", required = true) String longitude, |
|||
@RequestParam(value="zone", required = true) String zone, |
|||
@RequestParam(value="ward", required = true) String ward, |
|||
@RequestParam(value = "file", required = true) MultipartFile filedata, |
|||
@RequestParam(value="remarks", required = false) String remarks, |
|||
|
|||
@RequestParam(value="q1", required = false) String q1, |
|||
@RequestParam(value="q2", required = false) String q2, |
|||
@RequestParam(value="q3", required = false) String q3, |
|||
@RequestParam(value="q4", required = false) String q4, |
|||
@RequestParam(value="q5", required = false) String q5, |
|||
@RequestParam(value="q6", required = false) String q6, |
|||
@RequestParam(value="q7", required = false) String q7, |
|||
@RequestParam(value="q8", required = false) String q8, |
|||
@RequestParam(value="q9", required = false) String q9, |
|||
@RequestParam(value="q10", required = false) String q10, |
|||
@RequestParam(value="q11", required = false) String q11, |
|||
@RequestParam(value="q12", required = false) String q12, |
|||
@RequestParam(value="q13", required = false) String q13, |
|||
@RequestParam(value="q14", required = false) String q14, |
|||
@RequestParam(value="q15", required = false) String q15, |
|||
@RequestParam(value="q16", required = false) String q16, |
|||
@RequestParam(value="q17", required = false) String q17, |
|||
@RequestParam(value="q18", required = false) String q18, |
|||
@RequestParam(value="q19", required = false) String q19, |
|||
@RequestParam(value="q20", required = false) String q20, |
|||
@RequestParam(value="q21", required = false) String q21, |
|||
@RequestParam(value="q22", required = false) String q22, |
|||
@RequestParam(value="q23", required = false) String q23, |
|||
@RequestParam(value="q24", required = false) String q24, |
|||
@RequestParam(value="q25", required = false) String q25, |
|||
@RequestParam(value="q26", required = false) String q26, |
|||
@RequestParam(value="q27", required = false) String q27, |
|||
|
|||
@RequestParam(value="q1_image", required = false) MultipartFile q1_image, |
|||
@RequestParam(value="q2_image", required = false) MultipartFile q2_image, |
|||
@RequestParam(value="q3_image", required = false) MultipartFile q3_image, |
|||
@RequestParam(value="q4_image", required = false) MultipartFile q4_image, |
|||
@RequestParam(value="q5_image", required = false) MultipartFile q5_image, |
|||
@RequestParam(value="q6_image", required = false) MultipartFile q6_image, |
|||
@RequestParam(value="q7_image", required = false) MultipartFile q7_image, |
|||
@RequestParam(value="q8_image", required = false) MultipartFile q8_image, |
|||
@RequestParam(value="q9_image", required = false) MultipartFile q9_image, |
|||
@RequestParam(value="q10_image", required = false) MultipartFile q10_image, |
|||
@RequestParam(value="q11_image", required = false) MultipartFile q11_image, |
|||
@RequestParam(value="q12_image", required = false) MultipartFile q12_image, |
|||
@RequestParam(value="q13_image", required = false) MultipartFile q13_image, |
|||
@RequestParam(value="q14_image", required = false) MultipartFile q14_image, |
|||
@RequestParam(value="q15_image", required = false) MultipartFile q15_image, |
|||
@RequestParam(value="q16_image", required = false) MultipartFile q16_image, |
|||
@RequestParam(value="q17_image", required = false) MultipartFile q17_image, |
|||
@RequestParam(value="q18_image", required = false) MultipartFile q18_image, |
|||
@RequestParam(value="q19_image", required = false) MultipartFile q19_image, |
|||
@RequestParam(value="q20_image", required = false) MultipartFile q20_image, |
|||
@RequestParam(value="q21_image", required = false) MultipartFile q21_image, |
|||
@RequestParam(value="q22_image", required = false) MultipartFile q22_image, |
|||
@RequestParam(value="q23_image", required = false) MultipartFile q23_image, |
|||
@RequestParam(value="q24_image", required = false) MultipartFile q24_image, |
|||
@RequestParam(value="q25_image", required = false) MultipartFile q25_image, |
|||
@RequestParam(value="q26_image", required = false) MultipartFile q26_image, |
|||
@RequestParam(value="q27_image", required = false) MultipartFile q27_image |
|||
) { |
|||
return toiletService.saveFeedback( |
|||
toilet_id, cby, latitude, longitude, zone, ward, |
|||
q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, |
|||
q11, q12, q13, q14, q15, q16, q17, q18, q19, q20, |
|||
q21, q22, q23, q24, q25, q26, q27, remarks, filedata, |
|||
q1_image, q2_image, q3_image, q4_image, q5_image, q6_image, q7_image, q8_image, q9_image, q10_image, |
|||
q11_image, q12_image, q13_image, q14_image, q15_image, q16_image, q17_image, q18_image, q19_image, q20_image, |
|||
q21_image, q22_image, q23_image, q24_image, q25_image, q26_image, q27_image |
|||
); |
|||
} |
|||
|
|||
@GetMapping(value="/zoneReport") |
|||
public List<?> zoneReport( |
|||
@RequestParam MultiValueMap<String, String> formData, |
|||
@RequestParam(value="fromDate", required = true) String fromDate, |
|||
@RequestParam(value="toDate", required = true) String toDate, |
|||
@RequestParam(value="loginId", required = false) String cby |
|||
){ |
|||
return toiletService.zoneReport(formData,fromDate,toDate,cby); |
|||
} |
|||
|
|||
@GetMapping(value="/wardReport") |
|||
public List<?> wardReport( |
|||
@RequestParam MultiValueMap<String, String> formData, |
|||
@RequestParam(value="fromDate", required = true) String fromDate, |
|||
@RequestParam(value="toDate", required = true) String toDate, |
|||
@RequestParam(value="zone", required = true) String zone, |
|||
@RequestParam(value="loginId", required = false) String cby |
|||
){ |
|||
return toiletService.wardReport(formData,fromDate,toDate,zone,cby); |
|||
} |
|||
|
|||
@GetMapping(value="/toiletReport") |
|||
public List<?> toiletReport( |
|||
@RequestParam MultiValueMap<String, String> formData, |
|||
@RequestParam(value="fromDate", required = true) String fromDate, |
|||
@RequestParam(value="toDate", required = true) String toDate, |
|||
@RequestParam(value="ward", required = true) String ward, |
|||
@RequestParam(value="loginId", required = false) String cby |
|||
){ |
|||
return toiletService.toiletReport(formData,fromDate,toDate,ward,cby); |
|||
} |
|||
|
|||
@GetMapping(value="/toiletDailyFeedbackReport") |
|||
public List<?> toiletDailyFeedbackReport( |
|||
@RequestParam MultiValueMap<String, String> formData, |
|||
@RequestParam(value="fromDate", required = true) String fromDate, |
|||
@RequestParam(value="toDate", required = true) String toDate, |
|||
@RequestParam(value="toilet_id", required = false) String toilet_id, |
|||
@RequestParam(value="type", required = true) String type, |
|||
@RequestParam(value="loginId", required = false) String cby |
|||
){ |
|||
return toiletService.getToiletDailyFeedbackReport(formData,fromDate,toDate,toilet_id,type,cby); |
|||
} |
|||
|
|||
@GetMapping(value="/feedbackReport") |
|||
public List<?> feedbackReport( |
|||
@RequestParam MultiValueMap<String, String> formData, |
|||
@RequestParam(value="filterDate", required = true) String filterDate, |
|||
//@RequestParam(value="toDate", required = true) String toDate, |
|||
//@RequestParam(value="type", required = true) String type, |
|||
@RequestParam(value="toilet_id", required = true) String id, |
|||
@RequestParam(value="loginId", required = false) String cby |
|||
){ |
|||
return toiletService.feedbackReport(formData,filterDate,id,cby); |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.privateToilets.controller; |
|||
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.privateToilets; |
|||
@ -0,0 +1,851 @@ |
|||
package in.gov.chennaicorporation.mobileservice.privateToilets.service; |
|||
|
|||
import java.awt.image.BufferedImage; |
|||
import java.io.ByteArrayInputStream; |
|||
import java.io.ByteArrayOutputStream; |
|||
import java.io.IOException; |
|||
import java.nio.file.Files; |
|||
import java.nio.file.Path; |
|||
import java.nio.file.Paths; |
|||
import java.security.SecureRandom; |
|||
import java.sql.PreparedStatement; |
|||
import java.time.LocalDate; |
|||
import java.time.format.DateTimeFormatter; |
|||
import java.util.ArrayList; |
|||
import java.util.Arrays; |
|||
import java.util.Collections; |
|||
import java.util.Comparator; |
|||
import java.util.HashMap; |
|||
import java.util.HashSet; |
|||
import java.util.Iterator; |
|||
import java.util.LinkedHashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.Optional; |
|||
import java.util.Random; |
|||
import java.util.Set; |
|||
import java.util.stream.Collectors; |
|||
|
|||
import javax.imageio.ImageIO; |
|||
import javax.imageio.ImageWriteParam; |
|||
import javax.imageio.ImageWriter; |
|||
import javax.imageio.stream.ImageOutputStream; |
|||
import javax.sql.DataSource; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Qualifier; |
|||
import org.springframework.core.env.Environment; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
import org.springframework.jdbc.support.GeneratedKeyHolder; |
|||
import org.springframework.jdbc.support.KeyHolder; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.util.MultiValueMap; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
|
|||
import in.gov.chennaicorporation.mobileservice.gccactivity.service.DateTimeUtil; |
|||
|
|||
@Service |
|||
public class ToiletService { |
|||
|
|||
private JdbcTemplate jdbcToiletsTemplate; |
|||
private final Environment environment; |
|||
private String fileBaseUrl; |
|||
|
|||
private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
|||
private static final int STRING_LENGTH = 15; |
|||
private static final Random RANDOM = new SecureRandom(); |
|||
|
|||
@Autowired |
|||
public void setDataSource(@Qualifier("mysqlPrivateToiletsDataSource") DataSource toiletsDataSource) { |
|||
this.jdbcToiletsTemplate = new JdbcTemplate(toiletsDataSource); |
|||
} |
|||
|
|||
@Autowired |
|||
public ToiletService(Environment environment) { |
|||
this.environment = environment; |
|||
this.fileBaseUrl=environment.getProperty("fileBaseUrl"); |
|||
} |
|||
|
|||
public static String generateRandomString() { |
|||
StringBuilder result = new StringBuilder(STRING_LENGTH); |
|||
for (int i = 0; i < STRING_LENGTH; i++) { |
|||
result.append(CHARACTERS.charAt(RANDOM.nextInt(CHARACTERS.length()))); |
|||
} |
|||
return result.toString(); |
|||
} |
|||
|
|||
public static String generateRandomFileString(int lenthval) { |
|||
StringBuilder result = new StringBuilder(lenthval); |
|||
for (int i = 0; i < lenthval; i++) { |
|||
result.append(CHARACTERS.charAt(RANDOM.nextInt(CHARACTERS.length()))); |
|||
} |
|||
return result.toString(); |
|||
} |
|||
|
|||
private byte[] compressImage(BufferedImage image, float quality) throws IOException { |
|||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
|||
ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(byteArrayOutputStream); |
|||
|
|||
ImageWriter writer = ImageIO.getImageWritersByFormatName("jpg").next(); |
|||
writer.setOutput(imageOutputStream); |
|||
|
|||
ImageWriteParam param = writer.getDefaultWriteParam(); |
|||
if (param.canWriteCompressed()) { |
|||
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
|||
param.setCompressionQuality(quality); |
|||
} |
|||
|
|||
writer.write(null, new javax.imageio.IIOImage(image, null, null), param); |
|||
|
|||
writer.dispose(); |
|||
imageOutputStream.close(); |
|||
|
|||
return byteArrayOutputStream.toByteArray(); |
|||
} |
|||
|
|||
public String fileUpload(String name, String id, MultipartFile file) { |
|||
|
|||
int lastInsertId = 0; |
|||
// Set the file path where you want to save it |
|||
String uploadDirectory = environment.getProperty("file.upload.directory"); |
|||
String serviceFolderName = environment.getProperty("private_toilets_foldername"); |
|||
var year = DateTimeUtil.getCurrentYear(); |
|||
var month = DateTimeUtil.getCurrentMonth(); |
|||
var date = DateTimeUtil.getCurrentDay(); |
|||
|
|||
uploadDirectory = uploadDirectory + serviceFolderName + year + "/" + month + "/" + date; |
|||
|
|||
try { |
|||
// Create directory if it doesn't exist |
|||
Path directoryPath = Paths.get(uploadDirectory); |
|||
if (!Files.exists(directoryPath)) { |
|||
Files.createDirectories(directoryPath); |
|||
} |
|||
|
|||
// Datetime string |
|||
String datetimetxt = DateTimeUtil.getCurrentDateTime(); |
|||
|
|||
datetimetxt = datetimetxt + "_"+ generateRandomFileString(6); // Attached Random text |
|||
|
|||
// File name |
|||
String fileName = name + "_" + id + "_" + datetimetxt + "_" + file.getOriginalFilename(); |
|||
fileName = fileName.replaceAll("\\s+", ""); // Remove space on filename |
|||
|
|||
String filePath = uploadDirectory + "/" + fileName; |
|||
|
|||
String filepath_txt = "/" + serviceFolderName + year + "/" + month + "/" + date + "/" + fileName; |
|||
|
|||
// Create a new Path object |
|||
Path path = Paths.get(filePath); |
|||
|
|||
// Get the bytes of the file |
|||
byte[] bytes = file.getBytes(); |
|||
|
|||
// Compress the image |
|||
BufferedImage image = ImageIO.read(new ByteArrayInputStream(bytes)); |
|||
byte[] compressedBytes = compressImage(image, 0.5f); // Compress with 50% quality |
|||
|
|||
// Write the bytes to the file |
|||
Files.write(path, compressedBytes); |
|||
|
|||
System.out.println(filePath); |
|||
return filepath_txt; |
|||
|
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
return "Failed to save file " + file.getOriginalFilename(); |
|||
} |
|||
} |
|||
|
|||
public List<Map<String, Object>> getToiletsList(String loginid) { |
|||
String sql = "SELECT *" |
|||
//+ ",CONCAT('"+fileBaseUrl+"/gccofficialapp/files',image) AS photo " |
|||
+ " FROM `gcc_toilet_list` WHERE `isactive`=1"; |
|||
List<Map<String, Object>> result = jdbcToiletsTemplate.queryForList(sql,loginid); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Toilets List."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> toiletlistRest( |
|||
MultiValueMap<String, String> formData, |
|||
String latitude, |
|||
String longitude) { |
|||
|
|||
String sqlWhere = ""; |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
|
|||
if (latitude != null && longitude != null && !latitude.isBlank() && !latitude.isEmpty() && !longitude.isBlank() |
|||
&& !longitude.isEmpty()) { |
|||
String sqlQuery = "SELECT gl.*, tf.last_feedback_date " + |
|||
"FROM gcc_toilet_list gl " + |
|||
"LEFT JOIN ( " + |
|||
" SELECT toilet_id, DATE_FORMAT(MAX(cdate), '%d-%m-%Y') AS last_feedback_date " + |
|||
" FROM toilet_feedback WHERE isactive = 1 " + |
|||
" GROUP BY toilet_id " + |
|||
") tf ON tf.toilet_id = gl.id " + |
|||
"WHERE gl.isactive = 1 " + |
|||
" AND ( " + |
|||
" (6371008.8 * ACOS(ROUND( " + |
|||
" COS(RADIANS(" + latitude + ")) * COS(RADIANS(gl.latitude)) * " + |
|||
" COS(RADIANS(gl.longitude) - RADIANS(" + longitude + ")) + " + |
|||
" SIN(RADIANS(" + latitude + ")) * SIN(RADIANS(gl.latitude)), " + |
|||
" 9))) < 200 " + |
|||
" ) " + |
|||
"ORDER BY gl.id DESC"; |
|||
|
|||
List<Map<String, Object>> result = jdbcToiletsTemplate.queryForList(sqlQuery); |
|||
|
|||
response.put("status", 200); |
|||
response.put("message", "Nearby toilet list."); |
|||
if(result.isEmpty()) { |
|||
response.put("message", "No toilet found nearby."); |
|||
} |
|||
response.put("data", result); |
|||
} |
|||
else { |
|||
response.put("status", 200); |
|||
response.put("message", "No toilet found nearby."); |
|||
} |
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> toiletlistbylatlong( |
|||
MultiValueMap<String, String> formData, |
|||
String latitude, |
|||
String longitude, |
|||
//String id, |
|||
String loginid) { |
|||
|
|||
String sqlWhere = ""; |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
|
|||
if (latitude != null && longitude != null && !latitude.isBlank() && !latitude.isEmpty() && !longitude.isBlank() |
|||
&& !longitude.isEmpty()) { |
|||
/* |
|||
sqlWhere += " AND ((6371008.8 * acos(ROUND(cos(radians(" + latitude |
|||
+ ")) * cos(radians(latitude)) * cos(radians(longitude) - radians(" + longitude |
|||
+ ")) + sin(radians(" + latitude + ")) * sin(radians(latitude)), 9))) < 200)" |
|||
+ " ORDER BY `id` DESC"; |
|||
*/ |
|||
/* |
|||
String sqlQuery = "SELECT * " |
|||
//+ ", CONCAT('https://gccservices.in/gccofficialapp/files', image) AS photo\n" |
|||
+ "FROM gcc_toilet_list " |
|||
+ "WHERE isactive = 1 " |
|||
+ " AND ( " |
|||
+ " (6371008.8 * ACOS(ROUND( " |
|||
+ " COS(RADIANS("+ latitude +")) * COS(RADIANS(latitude)) * " |
|||
+ " COS(RADIANS(longitude) - RADIANS("+longitude+")) + " |
|||
+ " SIN(RADIANS("+latitude+")) * SIN(RADIANS(latitude)), " |
|||
+ " 9))) < 200 " |
|||
+ " ) " |
|||
+ "ORDER BY id DESC"; |
|||
*/ |
|||
String sqlQuery = "SELECT gl.*, tf.last_feedback_date " + |
|||
"FROM gcc_toilet_list gl " + |
|||
"LEFT JOIN ( " + |
|||
" SELECT toilet_id, DATE_FORMAT(MAX(cdate), '%d-%m-%Y') AS last_feedback_date " + |
|||
" FROM toilet_feedback WHERE isactive = 1 " + |
|||
" GROUP BY toilet_id " + |
|||
") tf ON tf.toilet_id = gl.id " + |
|||
"WHERE gl.isactive = 1 " + |
|||
" AND ( " + |
|||
" (6371008.8 * ACOS(ROUND( " + |
|||
" COS(RADIANS(" + latitude + ")) * COS(RADIANS(gl.latitude)) * " + |
|||
" COS(RADIANS(gl.longitude) - RADIANS(" + longitude + ")) + " + |
|||
" SIN(RADIANS(" + latitude + ")) * SIN(RADIANS(gl.latitude)), " + |
|||
" 9))) < 200 " + |
|||
" ) " + |
|||
"ORDER BY gl.id DESC"; |
|||
|
|||
List<Map<String, Object>> result = jdbcToiletsTemplate.queryForList(sqlQuery); |
|||
|
|||
response.put("status", 200); |
|||
response.put("message", "Nearby toilet list."); |
|||
if(result.isEmpty()) { |
|||
response.put("message", "No toilet found nearby."); |
|||
} |
|||
response.put("data", result); |
|||
} |
|||
else { |
|||
response.put("status", 200); |
|||
response.put("message", "No toilet found nearby."); |
|||
} |
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getParentQuestionsList() { |
|||
String sql = "SELECT " |
|||
+ " ql.*, " |
|||
+ " CASE " |
|||
+ " WHEN (ql.question_type = 'select' OR ql.question_type = 'radio') THEN JSON_ARRAYAGG( " |
|||
+ " JSON_OBJECT( " |
|||
+ " 'option_id', qov.id, " |
|||
+ " 'english_name', qov.name, " |
|||
+ " 'value', qov.id, " |
|||
+ " 'orderby', qov.orderby " |
|||
+ " ) " |
|||
+ " ) " |
|||
+ " ELSE NULL " |
|||
+ " END AS options " |
|||
+ "FROM question_list ql " |
|||
+ "LEFT JOIN question_option_values qov " |
|||
+ " ON qov.qid = ql.id " |
|||
+ " AND qov.isactive = 1 " |
|||
+ " AND qov.isdelete = 0 " |
|||
+ "WHERE ql.isactive = 1 " |
|||
+ " AND ql.pid = 0 " |
|||
+ "GROUP BY ql.id"; |
|||
|
|||
List<Map<String, Object>> result = jdbcToiletsTemplate.queryForList(sql); |
|||
Iterator<Map<String, Object>> iterator = result.iterator(); |
|||
ObjectMapper mapper = new ObjectMapper(); |
|||
while (iterator.hasNext()) { |
|||
Map<String, Object> row = iterator.next(); |
|||
Object optionsRaw = row.get("options"); |
|||
if (optionsRaw != null && optionsRaw instanceof String) { |
|||
try { |
|||
List<Map<String, Object>> optionsParsed = mapper.readValue((String) optionsRaw, List.class); |
|||
|
|||
// Sort options by 'orderby' |
|||
optionsParsed.sort(Comparator.comparing(opt -> { |
|||
Object order = opt.get("orderby"); |
|||
return (order instanceof Number) ? ((Number) order).intValue() : 0; |
|||
})); |
|||
|
|||
row.put("options", optionsParsed); |
|||
} catch (Exception e) { |
|||
row.put("options", null); // fallback if malformed |
|||
} |
|||
} |
|||
} |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Toilet Parent Question List."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getChildQuestionsList(String pid) { |
|||
String sql = "SELECT * FROM question_list WHERE isactive=1 AND `pid`=?"; |
|||
List<Map<String, Object>> result = jdbcToiletsTemplate.queryForList(sql,pid); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Toilet Child Question List."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> saveFeedback( |
|||
String toilet_id, |
|||
String cby, |
|||
String latitude, |
|||
String longitude, |
|||
String zone, |
|||
String ward, |
|||
String q1, String q2, String q3, String q4, String q5, String q6, String q7, String q8, String q9, String q10, |
|||
String q11, String q12, String q13, String q14, String q15, String q16, String q17, String q18, String q19, String q20, |
|||
String q21, String q22, String q23, String q24, String q25, String q26, String q27, |
|||
String remarks, MultipartFile filedata, |
|||
MultipartFile q1_image, MultipartFile q2_image, MultipartFile q3_image, MultipartFile q4_image, MultipartFile q5_image, |
|||
MultipartFile q6_image, MultipartFile q7_image, MultipartFile q8_image, MultipartFile q9_image, MultipartFile q10_image, |
|||
MultipartFile q11_image, MultipartFile q12_image, MultipartFile q13_image, MultipartFile q14_image, MultipartFile q15_image, |
|||
MultipartFile q16_image, MultipartFile q17_image, MultipartFile q18_image, MultipartFile q19_image, MultipartFile q20_image, |
|||
MultipartFile q21_image, MultipartFile q22_image, MultipartFile q23_image, MultipartFile q24_image, MultipartFile q25_image, |
|||
MultipartFile q26_image, MultipartFile q27_image |
|||
) { |
|||
Map<String, Object> response = new HashMap<>(); |
|||
List<Map<String, Object>> result = new ArrayList<>(); |
|||
|
|||
String feedbackimg = fileUpload("feedback", "main", filedata); |
|||
|
|||
String type = ""; |
|||
|
|||
// Prepare question image uploads |
|||
MultipartFile[] files = { |
|||
q1_image, q2_image, q3_image, q4_image, q5_image, q6_image, q7_image, q8_image, q9_image, q10_image, |
|||
q11_image, q12_image, q13_image, q14_image, q15_image, q16_image, q17_image, q18_image, q19_image, q20_image, |
|||
q21_image, q22_image, q23_image, q24_image, q25_image, q26_image, q27_image |
|||
}; |
|||
String[] imagePaths = new String[27]; |
|||
for (int i = 0; i < files.length; i++) { |
|||
if (files[i] != null && !files[i].isEmpty()) { |
|||
imagePaths[i] = fileUpload(String.valueOf(i + 1), "q" + (i + 1), files[i]); |
|||
} else { |
|||
imagePaths[i] = ""; |
|||
} |
|||
} |
|||
|
|||
// Insert query |
|||
String insertSql = "INSERT INTO toilet_feedback (toilet_id, cby, latitude, longitude, zone, ward, image, remarks, type, " + |
|||
"q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20, q21, q22, q23, q24, q25, q26, q27, " + |
|||
"q1_image, q2_image, q3_image, q4_image, q5_image, q6_image, q7_image, q8_image, q9_image, q10_image, q11_image, q12_image, " + |
|||
"q13_image, q14_image, q15_image, q16_image, q17_image, q18_image, q19_image, q20_image, q21_image, q22_image, q23_image, " + |
|||
"q24_image, q25_image, q26_image, q27_image) " + |
|||
"VALUES (" + "?,".repeat(9 + 27 + 27).replaceAll(",$", "") + ")"; |
|||
|
|||
KeyHolder keyHolder = new GeneratedKeyHolder(); |
|||
|
|||
int affectedRows = jdbcToiletsTemplate.update(connection -> { |
|||
PreparedStatement ps = connection.prepareStatement(insertSql, new String[]{"id"}); |
|||
int i = 1; |
|||
ps.setString(i++, toilet_id); |
|||
ps.setString(i++, cby); |
|||
ps.setString(i++, latitude); |
|||
ps.setString(i++, longitude); |
|||
ps.setString(i++, zone); |
|||
ps.setString(i++, ward); |
|||
ps.setString(i++, feedbackimg); |
|||
ps.setString(i++, remarks); |
|||
ps.setString(i++, type); |
|||
|
|||
// 27 question answers |
|||
for (String q : new String[]{q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, |
|||
q11, q12, q13, q14, q15, q16, q17, q18, q19, q20, |
|||
q21, q22, q23, q24, q25, q26, q27}) { |
|||
ps.setString(i++, q); |
|||
} |
|||
|
|||
// 27 question image paths |
|||
for (String path : imagePaths) { |
|||
ps.setString(i++, path); |
|||
} |
|||
|
|||
return ps; |
|||
}, keyHolder); |
|||
|
|||
if (affectedRows > 0) { |
|||
int lastInsertId = keyHolder.getKey().intValue(); |
|||
response.put("insertId", lastInsertId); |
|||
response.put("status", "success"); |
|||
response.put("message", "Feedback inserted successfully."); |
|||
} else { |
|||
response.put("status", "error"); |
|||
response.put("message", "Insert failed."); |
|||
} |
|||
|
|||
result.add(response); |
|||
return result; |
|||
} |
|||
|
|||
// Report |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> zoneReport( |
|||
MultiValueMap<String, String> formData, |
|||
String fromDate, |
|||
String toDate, |
|||
String loginid) { |
|||
|
|||
String sqlQuery = "SELECT " |
|||
+ " `gcc_toilet_list`.`zone`, " |
|||
+ " COUNT(DISTINCT `gcc_toilet_list`.`id`) AS Total_Toilets, " |
|||
+ " COUNT(DISTINCT `toilet_feedback`.`toilet_id`) AS Completed, " |
|||
+ " (COUNT(DISTINCT gcc_toilet_list.id) - COUNT(DISTINCT toilet_feedback.toilet_id)) AS Pending " |
|||
+ "FROM " |
|||
+ " `gcc_toilet_list` " |
|||
+ "LEFT JOIN " |
|||
+ " `toilet_feedback` " |
|||
+ " ON `toilet_feedback`.`toilet_id` = `gcc_toilet_list`.`id` " |
|||
+ " AND `toilet_feedback`.`isactive` = 1 " |
|||
+ " AND DATE(`toilet_feedback`.`cdate`) BETWEEN STR_TO_DATE(?, '%d-%m-%Y') AND STR_TO_DATE(?, '%d-%m-%Y') " |
|||
+ "WHERE " |
|||
//+ " `gcc_toilet_list`.`user_id` = ? AND " |
|||
+ " `gcc_toilet_list`.`isactive` = 1 " |
|||
+ "GROUP BY " |
|||
+ " `gcc_toilet_list`.`zone` " |
|||
+ "ORDER BY " |
|||
+ " `gcc_toilet_list`.`zone`"; |
|||
|
|||
List<Map<String, Object>> result = jdbcToiletsTemplate.queryForList(sqlQuery, fromDate, toDate); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", 200); |
|||
response.put("message", "Zone report."); |
|||
if(result.isEmpty()) { |
|||
response.put("message", "No data found."); |
|||
} |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> wardReport( |
|||
MultiValueMap<String, String> formData, |
|||
String fromDate, |
|||
String toDate, |
|||
String zone, |
|||
String loginid) { |
|||
|
|||
String sqlQuery = "SELECT " |
|||
+ " `gcc_toilet_list`.`ward`, " |
|||
+ " COUNT(DISTINCT `gcc_toilet_list`.`id`) AS Total_Toilets, " |
|||
+ " COUNT(DISTINCT `toilet_feedback`.`toilet_id`) AS Completed, " |
|||
+ " (COUNT(DISTINCT gcc_toilet_list.id) - COUNT(DISTINCT toilet_feedback.toilet_id)) AS Pending " |
|||
+ "FROM " |
|||
+ " `gcc_toilet_list` " |
|||
+ "LEFT JOIN " |
|||
+ " `toilet_feedback` " |
|||
+ " ON `toilet_feedback`.`toilet_id` = `gcc_toilet_list`.`id` " |
|||
+ " AND `toilet_feedback`.`isactive` = 1 " |
|||
+ " AND DATE(`toilet_feedback`.`cdate`) BETWEEN STR_TO_DATE(?, '%d-%m-%Y') AND STR_TO_DATE(?, '%d-%m-%Y') " |
|||
+ "WHERE " |
|||
+ " `gcc_toilet_list`.`zone` = ? AND " |
|||
+ " `gcc_toilet_list`.`isactive` = 1 " |
|||
+ "GROUP BY " |
|||
+ " `gcc_toilet_list`.`ward` " |
|||
+ "ORDER BY " |
|||
+ " `gcc_toilet_list`.`ward`"; |
|||
|
|||
List<Map<String, Object>> result = jdbcToiletsTemplate.queryForList(sqlQuery, fromDate, toDate, zone); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", 200); |
|||
response.put("message", "Ward report."); |
|||
if(result.isEmpty()) { |
|||
response.put("message", "No data found."); |
|||
} |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public static List<String> getDateRange(String start, String end) { |
|||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); |
|||
LocalDate startDate = LocalDate.parse(start, formatter); |
|||
LocalDate endDate = LocalDate.parse(end, formatter); |
|||
List<String> dates = new ArrayList<>(); |
|||
|
|||
while (!startDate.isAfter(endDate)) { |
|||
dates.add(startDate.format(formatter)); |
|||
startDate = startDate.plusDays(1); |
|||
} |
|||
|
|||
return dates; |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> toiletReport( |
|||
MultiValueMap<String, String> formData, |
|||
String fromDate, |
|||
String toDate, |
|||
String ward, |
|||
String loginid) { |
|||
|
|||
String sqlQuery = "SELECT " |
|||
+ " gtl.id AS toilet_id, " |
|||
+ " gtl.pct_name AS name, " |
|||
+ " gtl.zone, " |
|||
+ " gtl.ward, " |
|||
+ " " |
|||
+ " DATEDIFF( " |
|||
+ " STR_TO_DATE(?, '%d-%m-%Y'), " |
|||
+ " STR_TO_DATE(?, '%d-%m-%Y') " |
|||
+ " ) + 1 AS total_inspection_need_to_be_done, " |
|||
+ " " |
|||
+ " COUNT(DISTINCT DATE(tf.cdate)) AS total_inspection_done, " |
|||
+ " " |
|||
+ " ( " |
|||
+ " DATEDIFF( " |
|||
+ " STR_TO_DATE(?, '%d-%m-%Y'), " |
|||
+ " STR_TO_DATE(?, '%d-%m-%Y') " |
|||
+ " ) + 1 " |
|||
+ " - COUNT(DISTINCT DATE(tf.cdate)) " |
|||
+ " ) AS total_inspection_pending " |
|||
+ " " |
|||
+ "FROM " |
|||
+ " gcc_toilet_list gtl " |
|||
+ "LEFT JOIN " |
|||
+ " toilet_feedback tf ON tf.toilet_id = gtl.id " |
|||
+ " AND tf.isactive = 1 " |
|||
+ " AND DATE(tf.cdate) BETWEEN STR_TO_DATE(?, '%d-%m-%Y') AND STR_TO_DATE(?, '%d-%m-%Y') " |
|||
+ " " |
|||
+ "WHERE " |
|||
+ " gtl.isactive = 1 " |
|||
+ " AND gtl.ward = ? " |
|||
+ " " |
|||
+ "GROUP BY " |
|||
+ " gtl.id " |
|||
+ "ORDER BY " |
|||
+ " gtl.id"; |
|||
|
|||
List<Map<String, Object>> result = jdbcToiletsTemplate.queryForList( |
|||
sqlQuery, |
|||
toDate, fromDate, |
|||
toDate, fromDate, |
|||
fromDate, toDate, |
|||
ward |
|||
); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", 200); |
|||
response.put("message", "Toilet list report."); |
|||
if(result.isEmpty()) { |
|||
response.put("message", "No data found."); |
|||
} |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getToiletDailyFeedbackReport(MultiValueMap<String, String> formData, |
|||
String fromDate, |
|||
String toDate, |
|||
String toilet_id, |
|||
String type, |
|||
String loginid) { |
|||
List<Map<String, Object>> finalResult = new ArrayList<>(); |
|||
|
|||
// Step 1: Get all dates between fromDate and toDate |
|||
List<String> allDates = getDateRange(fromDate, toDate); |
|||
|
|||
// Step 2: Execute the SQL |
|||
String sql = "SELECT gtl.id AS toilet_id, gtl.pct_name, gtl.zone, gtl.ward, " + |
|||
"gtl.latitude, gtl.longitude, " + |
|||
"MAX(tf.image) AS image, " + |
|||
"GROUP_CONCAT(DATE(tf.cdate) ORDER BY tf.cdate ASC) AS feedback_dates " + |
|||
"FROM gcc_toilet_list gtl " + |
|||
"LEFT JOIN toilet_feedback tf ON tf.toilet_id = gtl.id AND tf.isactive = 1 " + |
|||
"AND DATE(tf.cdate) BETWEEN STR_TO_DATE(?, '%d-%m-%Y') AND STR_TO_DATE(?, '%d-%m-%Y') " + |
|||
"WHERE gtl.id = ? AND gtl.isactive = 1 " + |
|||
"GROUP BY gtl.id"; |
|||
|
|||
List<Map<String, Object>> toiletData = jdbcToiletsTemplate.queryForList(sql, fromDate, toDate, toilet_id); |
|||
|
|||
for (Map<String, Object> toilet : toiletData) { |
|||
Map<String, Object> report = new LinkedHashMap<>(); |
|||
String toiletId = toilet.get("toilet_id").toString(); |
|||
String image = toilet.get("image") != null ? toilet.get("image").toString() : ""; |
|||
String feedbackImage = image.isEmpty() ? "" : fileBaseUrl+"/gccofficialapp/files" + image; |
|||
|
|||
report.put("id", toiletId); |
|||
report.put("name", toilet.get("pct_name")); |
|||
report.put("zone", toilet.get("zone")); |
|||
report.put("ward", toilet.get("ward")); |
|||
report.put("latitude", toilet.get("latitude")); |
|||
report.put("longitude", toilet.get("longitude")); |
|||
report.put("photo", feedbackImage); |
|||
|
|||
// Step 3: Build Completed Dates |
|||
List<Map<String, String>> completedDates = new ArrayList<>(); |
|||
List<Map<String, String>> pendingDates = new ArrayList<>(); |
|||
|
|||
// if(toilet.get("toilet_id").equals("59")) { |
|||
System.out.println("Toilet"+toilet.get("toilet_id")+" :" + toilet.get("feedback_dates")); |
|||
//} |
|||
|
|||
String[] completed = Optional.ofNullable(toilet.get("feedback_dates")) |
|||
.map(Object::toString) |
|||
.map(d -> d.split(",")) |
|||
.orElse(new String[0]); |
|||
|
|||
// Set<String> completedSet = new HashSet<>(Arrays.asList(completed)); |
|||
|
|||
DateTimeFormatter fromFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|||
DateTimeFormatter toFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); |
|||
|
|||
String[] completedRaw = Optional.ofNullable(toilet.get("feedback_dates")) |
|||
.map(Object::toString) |
|||
.map(d -> d.split(",")) |
|||
.orElse(new String[0]); |
|||
|
|||
Set<String> completedSet = Arrays.stream(completedRaw) |
|||
.map(date -> { |
|||
try { |
|||
return LocalDate.parse(date.trim(), fromFormatter).format(toFormatter); |
|||
} catch (Exception e) { |
|||
return ""; // skip malformed |
|||
} |
|||
}) |
|||
.filter(s -> !s.isEmpty()) |
|||
.collect(Collectors.toSet()); |
|||
|
|||
for (String date : allDates) { |
|||
Map<String, String> statusMap = new HashMap<>(); |
|||
statusMap.put("Date", date); |
|||
if (completedSet.contains(date)) { |
|||
statusMap.put("Status", "Done"); |
|||
completedDates.add(statusMap); |
|||
} else { |
|||
statusMap.put("Status", "NotDone"); |
|||
pendingDates.add(statusMap); |
|||
} |
|||
} |
|||
|
|||
if("completed".equals(type)) { |
|||
report.put("Dates", completedDates); |
|||
} |
|||
else { |
|||
report.put("Dates", pendingDates); |
|||
} |
|||
|
|||
|
|||
finalResult.add(report); |
|||
} |
|||
|
|||
return finalResult; |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> toiletReport2( |
|||
MultiValueMap<String, String> formData, |
|||
String fromDate, |
|||
String toDate, |
|||
String ward, |
|||
String loginid) { |
|||
|
|||
String sqlQuery = "SELECT " |
|||
+ " `gcc_toilet_list`.`id`,`gcc_toilet_list`.`name`,`gcc_toilet_list`.`zone`,`gcc_toilet_list`.`ward`, " |
|||
+ " CONCAT('"+fileBaseUrl+"/gccofficialapp/files', `toilet_feedback`.`image`) AS photo," |
|||
+ " COUNT(`toilet_feedback`.`toilet_id`) AS Completed " |
|||
+ "FROM " |
|||
+ " `gcc_toilet_list` " |
|||
+ "LEFT JOIN " |
|||
+ " `toilet_feedback` " |
|||
+ " ON `toilet_feedback`.`toilet_id` = `gcc_toilet_list`.`id` " |
|||
+ " AND `toilet_feedback`.`isactive` = 1 " |
|||
+ " AND DATE(`toilet_feedback`.`cdate`) BETWEEN STR_TO_DATE(?, '%d-%m-%Y') AND STR_TO_DATE(?, '%d-%m-%Y') " |
|||
+ "WHERE " |
|||
+ " `gcc_toilet_list`.`ward` = ? AND " |
|||
+ " `gcc_toilet_list`.`isactive` = 1 " |
|||
+ "GROUP BY " |
|||
+ " `gcc_toilet_list`.`id` " |
|||
+ "ORDER BY " |
|||
+ " `gcc_toilet_list`.`id`"; |
|||
|
|||
List<Map<String, Object>> result = jdbcToiletsTemplate.queryForList(sqlQuery, fromDate, toDate, ward); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", 200); |
|||
response.put("message", "Toilet list report."); |
|||
if(result.isEmpty()) { |
|||
response.put("message", "No data found."); |
|||
} |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> feedbackReport( |
|||
MultiValueMap<String, String> formData, |
|||
String filterDate, |
|||
String toiletid, |
|||
String loginid) { |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
|
|||
String sqlQuery = "SELECT " |
|||
+ " gtl.id AS assetid, " |
|||
+ " gtl.pct_name AS name, " |
|||
+ " gtl.zone, " |
|||
+ " gtl.ward, " |
|||
+ " CONCAT('" + fileBaseUrl + "/gccofficialapp/files', tf.image) AS toiletPhoto, " |
|||
+ " DATE_FORMAT(tf.cdate, '%d-%m-%Y %I:%i %p') AS feedbackDate, " |
|||
+ " tf.*, " |
|||
+ " CONCAT('" + fileBaseUrl + "/gccofficialapp/files', tf.image) AS feedbackPhoto " |
|||
+ "FROM gcc_toilet_list gtl " |
|||
+ "RIGHT JOIN toilet_feedback tf ON tf.toilet_id = gtl.id AND tf.isactive = 1 " |
|||
+ " AND DATE(tf.cdate) = STR_TO_DATE(?, '%d-%m-%Y') " |
|||
+ "WHERE gtl.id = ? AND gtl.isactive = 1 " |
|||
+ "ORDER BY feedbackDate LIMIT 1"; |
|||
|
|||
List<Map<String, Object>> result = jdbcToiletsTemplate.queryForList(sqlQuery, filterDate, toiletid); |
|||
List<Map<String, Object>> finalQA = new ArrayList<>(); |
|||
|
|||
if (!result.isEmpty()) { |
|||
Map<String, Object> feedback = result.get(0); |
|||
|
|||
// 1. Load all questions |
|||
String questionSql = "SELECT ql.*, " |
|||
+ "CASE WHEN (ql.question_type IN ('select', 'radio')) THEN JSON_ARRAYAGG(JSON_OBJECT( " |
|||
+ " 'option_id', qov.id, " |
|||
+ " 'english_name', qov.name, " |
|||
+ " 'value', qov.id, " |
|||
+ " 'orderby', qov.orderby " |
|||
+ ")) ELSE NULL END AS options " |
|||
+ "FROM question_list ql " |
|||
+ "LEFT JOIN question_option_values qov ON qov.qid = ql.id " |
|||
+ "AND qov.isactive = 1 AND qov.isdelete = 0 " |
|||
+ "WHERE (ql.isactive = 1 OR ql.showonreport = 1) " |
|||
+ "GROUP BY ql.id"; |
|||
List<Map<String, Object>> questions = jdbcToiletsTemplate.queryForList(questionSql); |
|||
|
|||
// 2. Build answer map from feedback row |
|||
Map<String, String> answerMap = new HashMap<>(); |
|||
for (int i = 1; i <= 27; i++) { |
|||
String key = "q" + i; |
|||
Object val = feedback.get(key); |
|||
answerMap.put(String.valueOf(i), val != null ? val.toString() : ""); |
|||
} |
|||
|
|||
// 3. Combine Questions + Answers + Optional Images |
|||
for (Map<String, Object> q : questions) { |
|||
Map<String, Object> entry = new HashMap<>(); |
|||
String qid = q.get("id") != null ? q.get("id").toString() : ""; |
|||
|
|||
entry.put("qid", qid); |
|||
entry.put("question", q.get("q_english")); |
|||
entry.put("question_type", q.get("question_type")); |
|||
String answerValue = answerMap.getOrDefault(qid, ""); |
|||
|
|||
if (q.get("question_type") != null && |
|||
(q.get("question_type").toString().equalsIgnoreCase("select") || |
|||
q.get("question_type").toString().equalsIgnoreCase("radio"))) { |
|||
|
|||
// Resolve the label from options |
|||
if (q.get("options") != null && !answerValue.isBlank()) { |
|||
try { |
|||
List<Map<String, Object>> options = new ObjectMapper().readValue(q.get("options").toString(), List.class); |
|||
for (Map<String, Object> opt : options) { |
|||
if (opt.get("option_id").toString().equals(answerValue)) { |
|||
answerValue = opt.get("english_name").toString(); |
|||
break; |
|||
} |
|||
} |
|||
} catch (Exception e) { |
|||
// fallback: leave answerValue as-is |
|||
} |
|||
} |
|||
} |
|||
|
|||
entry.put("answer", answerValue); |
|||
entry.put("img_required", q.get("img_required")); |
|||
|
|||
// Optional image |
|||
String imageField = "q" + qid + "_image"; |
|||
if (feedback.containsKey(imageField)) { |
|||
Object imgPath = feedback.get(imageField); |
|||
if (imgPath != null && !imgPath.toString().isBlank()) { |
|||
entry.put("image", fileBaseUrl + "/gccofficialapp/files" + imgPath.toString()); |
|||
} |
|||
} |
|||
|
|||
finalQA.add(entry); |
|||
} |
|||
|
|||
response.put("status", 200); |
|||
response.put("message", "Feedback list report."); |
|||
response.put("data", result); |
|||
response.put("question", finalQA); |
|||
} else { |
|||
response.put("status", 200); |
|||
response.put("message", "No data found."); |
|||
response.put("data", Collections.emptyList()); |
|||
response.put("question", Collections.emptyList()); |
|||
} |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.privateToilets.service; |
|||
@ -0,0 +1,130 @@ |
|||
package in.gov.chennaicorporation.mobileservice.roadcut.controller; |
|||
|
|||
import java.util.List; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import in.gov.chennaicorporation.mobileservice.roadcut.service.RoadCutService; |
|||
|
|||
@RequestMapping("/gccofficialapp/api/readcut/") |
|||
@RestController("restRoadCut") |
|||
public class RoadCutController { |
|||
@Autowired |
|||
private RoadCutService roadCutService; |
|||
|
|||
@GetMapping("/fetch-roadcut-json") |
|||
public ResponseEntity<?> loadData( |
|||
@RequestParam("fromdate") String fromDate, |
|||
@RequestParam("todate") String toDate) { |
|||
try { |
|||
roadCutService.fetchAndSave(fromDate,toDate); |
|||
return ResponseEntity.ok("Data saved successfully"); |
|||
} catch (Exception e) { |
|||
return ResponseEntity.status(500).body("Error: " + e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
// TNEB & Metro Water |
|||
@GetMapping(value="/get-roadcut-list") |
|||
public List<?> getRoadCutList(@RequestParam(value="loginId", required = true) String cby){ |
|||
return roadCutService.getRoadCutList(cby); |
|||
} |
|||
|
|||
|
|||
@GetMapping(value="/check-roadcut-loation") |
|||
public List<?> getLoactionCheck( |
|||
@RequestParam(value="loginId", required = true) String cby, |
|||
@RequestParam(value="refId", required = true) String refid, |
|||
@RequestParam(value="streetId", required = true) String streetid, |
|||
@RequestParam(value="streetName", required = true) String streetname |
|||
){ |
|||
return roadCutService.getLoactionCheck(cby,refid,streetid,streetname); |
|||
} |
|||
|
|||
|
|||
@GetMapping(value="/get-roadcut-details") |
|||
public List<?> getRoadCutDetails( |
|||
@RequestParam(value="loginId", required = true) String cby, |
|||
@RequestParam(value="refId", required = true) String refid |
|||
){ |
|||
return roadCutService.getRoadCutDetails(cby,refid); |
|||
} |
|||
|
|||
@PostMapping(value="/saveAction") |
|||
public List<?> saveFeedback( |
|||
@RequestParam("uid") String uid, |
|||
@RequestParam("cby") String cby, |
|||
@RequestParam("latitude") String latitude, |
|||
@RequestParam("longitude") String longitude, |
|||
@RequestParam("zone") String zone, |
|||
@RequestParam("ward") String ward, |
|||
@RequestParam("streetid") String streetid, |
|||
@RequestParam("streetname") String streetname, |
|||
@RequestParam("action") String action, |
|||
@RequestParam("workstatus") String workstatus, |
|||
@RequestParam("remarks") String remarks, |
|||
@RequestParam("nocid") String nocid, |
|||
@RequestParam(value = "file", required = false) MultipartFile filedata) { |
|||
|
|||
return roadCutService.saveStatusUpdate( |
|||
uid, cby, latitude, longitude, zone, ward, streetid, |
|||
streetname, action, workstatus, remarks, nocid, filedata |
|||
); |
|||
|
|||
} |
|||
|
|||
// AE GCC Officer |
|||
@GetMapping(value="/get-roadcut-list-offical") |
|||
public List<?> getRoadCutList_offical(@RequestParam(value="loginId", required = true) String cby){ |
|||
return roadCutService.getRoadCutList_offical(cby); |
|||
} |
|||
|
|||
@GetMapping(value="/check-roadcut-loation-offical") |
|||
public List<?> getLoactionCheck_offical( |
|||
@RequestParam(value="loginId", required = true) String cby, |
|||
@RequestParam(value="refId", required = true) String refid, |
|||
@RequestParam(value="streetId", required = true) String streetid, |
|||
@RequestParam(value="streetName", required = true) String streetname |
|||
){ |
|||
return roadCutService.getLoactionCheck(cby,refid,streetid,streetname); |
|||
} |
|||
|
|||
|
|||
@GetMapping(value="/get-roadcut-details-offical") |
|||
public List<?> getRoadCutDetails_offical( |
|||
@RequestParam(value="loginId", required = true) String cby, |
|||
@RequestParam(value="refId", required = true) String refid |
|||
){ |
|||
return roadCutService.getRoadCutDetails_offical(cby,refid); |
|||
} |
|||
|
|||
@PostMapping(value="/saveAction-offical") |
|||
public List<?> saveFeedback_offical( |
|||
@RequestParam("uid") String uid, |
|||
@RequestParam("cby") String cby, |
|||
@RequestParam("latitude") String latitude, |
|||
@RequestParam("longitude") String longitude, |
|||
@RequestParam("zone") String zone, |
|||
@RequestParam("ward") String ward, |
|||
@RequestParam("streetid") String streetid, |
|||
@RequestParam("streetname") String streetname, |
|||
@RequestParam("action") String action, |
|||
@RequestParam("workstatus") String workstatus, |
|||
@RequestParam("remarks") String remarks, |
|||
@RequestParam("nocid") String nocid, |
|||
@RequestParam(value = "file", required = false) MultipartFile filedata) { |
|||
|
|||
return roadCutService.saveStatusUpdate_offical( |
|||
uid, cby, latitude, longitude, zone, ward, streetid, |
|||
streetname, action, workstatus, remarks, nocid, filedata |
|||
); |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.roadcut.controller; |
|||
@ -0,0 +1,33 @@ |
|||
package in.gov.chennaicorporation.mobileservice.roadcut.modelclass; |
|||
|
|||
public class RoadCutDetail { |
|||
public String NOC_APP_REM; |
|||
public String ROAD_BREADTH; |
|||
public String DAMAGE_FEE; |
|||
public String ROAD_REMARKS; |
|||
public String DEPT_NAME; |
|||
public String PAYMENT_STATUS; |
|||
public String STREET; |
|||
public String LOC; |
|||
public String TENT_WORK_STARTDATE; |
|||
public String ROAD_LENGTH; |
|||
public String NOC_STATUS; |
|||
public String APPLICATION_NO; |
|||
public String INTERLOCKING; |
|||
public String NOC_APP_FROMDT; |
|||
public String APPLICATION_DATE; |
|||
public String AREA; |
|||
public String ADDRESS; |
|||
public String WARD; |
|||
public String DEPOSIT_WORKS_CATEGORY; |
|||
public String ZONE; |
|||
public String UNIQUEID; |
|||
public String TENT_WORK_ENDDATE; |
|||
public String APP_STATUS; |
|||
public String NOC_APP_TODT; |
|||
public String NOC_APP_DATE; |
|||
public String NO_OF_PIT; |
|||
public String APPLICANT_NAME; |
|||
public String TYPE_OF_ROAD; |
|||
public String ROAD_DEPTH; |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
package in.gov.chennaicorporation.mobileservice.roadcut.modelclass; |
|||
|
|||
import java.util.List; |
|||
|
|||
public class RoadCutResponse { |
|||
public List<RoadCutDetail> ListResult; |
|||
public String Message; |
|||
public boolean ResultStatus; |
|||
} |
|||
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.roadcut.modelclass; |
|||
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.roadcut; |
|||
@ -0,0 +1,976 @@ |
|||
package in.gov.chennaicorporation.mobileservice.roadcut.service; |
|||
|
|||
import java.awt.image.BufferedImage; |
|||
import java.io.ByteArrayInputStream; |
|||
import java.io.ByteArrayOutputStream; |
|||
import java.io.IOException; |
|||
import java.nio.file.Files; |
|||
import java.nio.file.Path; |
|||
import java.nio.file.Paths; |
|||
import java.security.SecureRandom; |
|||
import java.sql.PreparedStatement; |
|||
import java.util.ArrayList; |
|||
import java.util.Collections; |
|||
import java.util.HashMap; |
|||
import java.util.LinkedHashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.Random; |
|||
|
|||
import javax.imageio.ImageIO; |
|||
import javax.imageio.ImageWriteParam; |
|||
import javax.imageio.ImageWriter; |
|||
import javax.imageio.stream.ImageOutputStream; |
|||
import javax.sql.DataSource; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Qualifier; |
|||
import org.springframework.core.env.Environment; |
|||
import org.springframework.dao.EmptyResultDataAccessException; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
import org.springframework.jdbc.support.GeneratedKeyHolder; |
|||
import org.springframework.jdbc.support.KeyHolder; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.web.client.RestTemplate; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
|
|||
import in.gov.chennaicorporation.mobileservice.gccactivity.service.DateTimeUtil; |
|||
import in.gov.chennaicorporation.mobileservice.roadcut.modelclass.RoadCutDetail; |
|||
import in.gov.chennaicorporation.mobileservice.roadcut.modelclass.RoadCutResponse; |
|||
|
|||
@Service |
|||
public class RoadCutService { |
|||
|
|||
@Autowired |
|||
private JdbcTemplate jdbcRoadCutTemplate; |
|||
private final Environment environment; |
|||
private String fileBaseUrl; |
|||
|
|||
private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
|||
private static final int STRING_LENGTH = 15; |
|||
private static final Random RANDOM = new SecureRandom(); |
|||
|
|||
@Autowired |
|||
public void setDataSource(@Qualifier("mysqlRoadCutDataSource") DataSource roadCutDataSource) { |
|||
this.jdbcRoadCutTemplate = new JdbcTemplate(roadCutDataSource); |
|||
} |
|||
|
|||
@Autowired |
|||
public RoadCutService(Environment environment) { |
|||
this.environment = environment; |
|||
this.fileBaseUrl=environment.getProperty("fileBaseUrl"); |
|||
} |
|||
|
|||
public static String generateRandomString() { |
|||
StringBuilder result = new StringBuilder(STRING_LENGTH); |
|||
for (int i = 0; i < STRING_LENGTH; i++) { |
|||
result.append(CHARACTERS.charAt(RANDOM.nextInt(CHARACTERS.length()))); |
|||
} |
|||
return result.toString(); |
|||
} |
|||
|
|||
public static String generateRandomFileString(int lenthval) { |
|||
StringBuilder result = new StringBuilder(lenthval); |
|||
for (int i = 0; i < lenthval; i++) { |
|||
result.append(CHARACTERS.charAt(RANDOM.nextInt(CHARACTERS.length()))); |
|||
} |
|||
return result.toString(); |
|||
} |
|||
|
|||
private byte[] compressImage(BufferedImage image, float quality) throws IOException { |
|||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
|||
ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(byteArrayOutputStream); |
|||
|
|||
ImageWriter writer = ImageIO.getImageWritersByFormatName("jpg").next(); |
|||
writer.setOutput(imageOutputStream); |
|||
|
|||
ImageWriteParam param = writer.getDefaultWriteParam(); |
|||
if (param.canWriteCompressed()) { |
|||
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
|||
param.setCompressionQuality(quality); |
|||
} |
|||
|
|||
writer.write(null, new javax.imageio.IIOImage(image, null, null), param); |
|||
|
|||
writer.dispose(); |
|||
imageOutputStream.close(); |
|||
|
|||
return byteArrayOutputStream.toByteArray(); |
|||
} |
|||
|
|||
public String fileUpload(String name, String id, MultipartFile file) { |
|||
|
|||
int lastInsertId = 0; |
|||
// Set the file path where you want to save it |
|||
String uploadDirectory = environment.getProperty("file.upload.directory"); |
|||
String serviceFolderName = environment.getProperty("roadcut_foldername"); |
|||
var year = DateTimeUtil.getCurrentYear(); |
|||
var month = DateTimeUtil.getCurrentMonth(); |
|||
var date = DateTimeUtil.getCurrentDay(); |
|||
|
|||
uploadDirectory = uploadDirectory + serviceFolderName + year + "/" + month + "/" + date; |
|||
|
|||
try { |
|||
// Create directory if it doesn't exist |
|||
Path directoryPath = Paths.get(uploadDirectory); |
|||
if (!Files.exists(directoryPath)) { |
|||
Files.createDirectories(directoryPath); |
|||
} |
|||
|
|||
// Datetime string |
|||
String datetimetxt = DateTimeUtil.getCurrentDateTime(); |
|||
|
|||
datetimetxt = datetimetxt + "_"+ generateRandomFileString(6); // Attached Random text |
|||
|
|||
// File name |
|||
String fileName = name + "_" + id + "_" + datetimetxt + "_" + file.getOriginalFilename(); |
|||
fileName = fileName.replaceAll("\\s+", ""); // Remove space on filename |
|||
|
|||
String filePath = uploadDirectory + "/" + fileName; |
|||
|
|||
String filepath_txt = "/" + serviceFolderName + year + "/" + month + "/" + date + "/" + fileName; |
|||
|
|||
// Create a new Path object |
|||
Path path = Paths.get(filePath); |
|||
|
|||
// Get the bytes of the file |
|||
byte[] bytes = file.getBytes(); |
|||
|
|||
// Compress the image |
|||
BufferedImage image = ImageIO.read(new ByteArrayInputStream(bytes)); |
|||
byte[] compressedBytes = compressImage(image, 0.5f); // Compress with 50% quality |
|||
|
|||
// Write the bytes to the file |
|||
Files.write(path, compressedBytes); |
|||
|
|||
System.out.println(filePath); |
|||
return filepath_txt; |
|||
|
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
return "Failed to save file " + file.getOriginalFilename(); |
|||
} |
|||
} |
|||
|
|||
private String safeValue(String val) { |
|||
return (val == null || val.trim().equalsIgnoreCase("N/A")) ? null : val.trim(); |
|||
} |
|||
|
|||
public void fetchAndSave(String fromDate, String toDate) throws Exception { |
|||
|
|||
// expected format = dd-MM-yyyy → convert to dd/MM/yyyy for URL |
|||
String formattedFromDate = fromDate.replace("-", "/"); |
|||
|
|||
String formattedToDate = toDate.replace("-", "/"); |
|||
|
|||
String url = "http://coc-staging.egovernments.org:9980/pgr/external/mobileservice?" |
|||
+ "serviceId=common_api" |
|||
+ "&jsonResp=Yes" |
|||
+ "&subService=getRoadcutselfDet" |
|||
+ "&fromDate=" + formattedFromDate |
|||
+ "&toDate=" + formattedToDate; |
|||
|
|||
RestTemplate restTemplate = new RestTemplate(); |
|||
String json = restTemplate.getForObject(url, String.class); |
|||
|
|||
ObjectMapper mapper = new ObjectMapper(); |
|||
RoadCutResponse response = mapper.readValue(json, RoadCutResponse.class); |
|||
|
|||
String sql = "INSERT INTO road_cut_details (" + |
|||
"NOC_APP_REM, ROAD_BREADTH, DAMAGE_FEE, ROAD_REMARKS, DEPT_NAME, PAYMENT_STATUS, " + |
|||
"STREET, LOC, TENT_WORK_STARTDATE, ROAD_LENGTH, NOC_STATUS, APPLICATION_NO, " + |
|||
"INTERLOCKING, NOC_APP_FROMDT, APPLICATION_DATE, AREA, ADDRESS, WARD, " + |
|||
"DEPOSIT_WORKS_CATEGORY, ZONE, UNIQUEID, TENT_WORK_ENDDATE, APP_STATUS, " + |
|||
"NOC_APP_TODT, NOC_APP_DATE, NO_OF_PIT, APPLICANT_NAME, TYPE_OF_ROAD, ROAD_DEPTH) " + |
|||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"+ |
|||
"ON DUPLICATE KEY UPDATE " + |
|||
"NOC_APP_REM = VALUES(NOC_APP_REM), " + |
|||
"ROAD_BREADTH = VALUES(ROAD_BREADTH), " + |
|||
"DAMAGE_FEE = VALUES(DAMAGE_FEE), " + |
|||
"ROAD_REMARKS = VALUES(ROAD_REMARKS), " + |
|||
"DEPT_NAME = VALUES(DEPT_NAME), " + |
|||
"PAYMENT_STATUS = VALUES(PAYMENT_STATUS), " + |
|||
"STREET = VALUES(STREET), " + |
|||
"LOC = VALUES(LOC), " + |
|||
"TENT_WORK_STARTDATE = VALUES(TENT_WORK_STARTDATE), " + |
|||
"ROAD_LENGTH = VALUES(ROAD_LENGTH), " + |
|||
"NOC_STATUS = VALUES(NOC_STATUS), " + |
|||
"APPLICATION_NO = VALUES(APPLICATION_NO), " + |
|||
"INTERLOCKING = VALUES(INTERLOCKING), " + |
|||
"NOC_APP_FROMDT = VALUES(NOC_APP_FROMDT), " + |
|||
"APPLICATION_DATE = VALUES(APPLICATION_DATE), " + |
|||
"AREA = VALUES(AREA), " + |
|||
"ADDRESS = VALUES(ADDRESS), " + |
|||
"WARD = VALUES(WARD), " + |
|||
"DEPOSIT_WORKS_CATEGORY = VALUES(DEPOSIT_WORKS_CATEGORY), " + |
|||
"ZONE = VALUES(ZONE), " + |
|||
"TENT_WORK_ENDDATE = VALUES(TENT_WORK_ENDDATE), " + |
|||
"APP_STATUS = VALUES(APP_STATUS), " + |
|||
"NOC_APP_TODT = VALUES(NOC_APP_TODT), " + |
|||
"NOC_APP_DATE = VALUES(NOC_APP_DATE), " + |
|||
"NO_OF_PIT = VALUES(NO_OF_PIT), " + |
|||
"APPLICANT_NAME = VALUES(APPLICANT_NAME), " + |
|||
"TYPE_OF_ROAD = VALUES(TYPE_OF_ROAD), " + |
|||
"ROAD_DEPTH = VALUES(ROAD_DEPTH)"; |
|||
|
|||
for (RoadCutDetail rc : response.ListResult) { |
|||
//System.out.println("======="); |
|||
//System.out.println(mapper.writeValueAsString(rc)); |
|||
//System.out.println("======="); |
|||
try { |
|||
jdbcRoadCutTemplate.update(sql, |
|||
safeValue(rc.NOC_APP_REM), |
|||
safeValue(rc.ROAD_BREADTH), |
|||
safeValue(rc.DAMAGE_FEE), |
|||
safeValue(rc.ROAD_REMARKS), |
|||
safeValue(rc.DEPT_NAME), |
|||
safeValue(rc.PAYMENT_STATUS), |
|||
safeValue(rc.STREET), |
|||
safeValue(rc.LOC), |
|||
safeValue(rc.TENT_WORK_STARTDATE), |
|||
safeValue(rc.ROAD_LENGTH), |
|||
safeValue(rc.NOC_STATUS), |
|||
safeValue(rc.APPLICATION_NO), |
|||
safeValue(rc.INTERLOCKING), |
|||
safeValue(rc.NOC_APP_FROMDT), |
|||
safeValue(rc.APPLICATION_DATE), |
|||
safeValue(rc.AREA), |
|||
safeValue(rc.ADDRESS), |
|||
safeValue(rc.WARD), |
|||
safeValue(rc.DEPOSIT_WORKS_CATEGORY), |
|||
safeValue(rc.ZONE), |
|||
safeValue(rc.UNIQUEID), // NOTE: This is NOT NULL. Must not be null! |
|||
safeValue(rc.TENT_WORK_ENDDATE), |
|||
safeValue(rc.APP_STATUS), |
|||
safeValue(rc.NOC_APP_TODT), |
|||
safeValue(rc.NOC_APP_DATE), |
|||
safeValue(rc.NO_OF_PIT), |
|||
safeValue(rc.APPLICANT_NAME), |
|||
safeValue(rc.TYPE_OF_ROAD), |
|||
safeValue(rc.ROAD_DEPTH) |
|||
); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); // shows exact SQL error |
|||
} |
|||
} |
|||
} |
|||
|
|||
// TNEB & Metro Water |
|||
|
|||
public List<Map<String, Object>> getRoadCutList(String loginid) { |
|||
String sql = "SELECT " |
|||
+ " rcd.*, " |
|||
+ " CASE " |
|||
+ " WHEN rcd.NOC_STATUS = 'NOC Pending' THEN 1 " |
|||
+ " WHEN rcd.NOC_STATUS = 'NOC Approved' THEN 2 " |
|||
+ " ELSE 0 " |
|||
+ " END AS NOC_STATUS_CODE, " |
|||
+ " IFNULL(rcs.status, 'new') AS status " |
|||
+ "FROM " |
|||
+ " road_cut_details rcd " |
|||
+ "LEFT JOIN ( " |
|||
+ " SELECT * " |
|||
+ " FROM road_cut_status rcs1 " |
|||
+ " WHERE rcs1.id IN ( " |
|||
+ " SELECT MAX(id) " |
|||
+ " FROM road_cut_status " |
|||
+ " GROUP BY uid " |
|||
+ " ) " |
|||
+ ") rcs ON rcs.uid = rcd.uid " |
|||
+ "WHERE " |
|||
+ " rcd.isactive = 1 " |
|||
+ " AND rcd.isdelete = 0 " |
|||
+ " AND rcd.PAYMENT_STATUS = 'Payment Done' " |
|||
+ " AND rcd.NOC_STATUS IS NOT NULL " |
|||
+ " AND IFNULL(rcs.status, 'new') <> 'completed'"; |
|||
|
|||
List<Map<String, Object>> result = jdbcRoadCutTemplate.queryForList(sql); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (result.isEmpty()) { |
|||
response.put("status", "No Data"); |
|||
response.put("message", "No road cut list found."); |
|||
response.put("data", Collections.emptyList()); // or just null |
|||
} else { |
|||
response.put("status", "Success"); |
|||
response.put("message", "RoadCut List."); |
|||
response.put("data", result); |
|||
} |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getLoactionCheck(String loginid, String refid, String streetid, String streetname) { |
|||
String sql = "SELECT " + |
|||
" rcd.*, " + |
|||
" CASE " + |
|||
" WHEN rcd.NOC_STATUS = 'NOC Pending' THEN 1 " + |
|||
" WHEN rcd.NOC_STATUS = 'NOC Approved' THEN 2 " + |
|||
" ELSE 0 " + |
|||
" END AS NOC_STATUS_CODE, " + |
|||
" IFNULL(rcs.status, 'new') AS status " + |
|||
"FROM " + |
|||
" road_cut_details rcd " + |
|||
"LEFT JOIN ( " + |
|||
" SELECT * " + |
|||
" FROM road_cut_status rcs1 " + |
|||
" WHERE rcs1.id IN ( " + |
|||
" SELECT MAX(id) " + |
|||
" FROM road_cut_status " + |
|||
" GROUP BY uid " + |
|||
" ) " + |
|||
") rcs ON rcs.uid = rcd.uid " + |
|||
"WHERE " + |
|||
" rcd.isactive = 1 " + |
|||
" AND rcd.isdelete = 0 " + |
|||
" AND rcd.PAYMENT_STATUS = 'Payment Done' " + |
|||
" AND rcd.NOC_STATUS IS NOT NULL " + |
|||
" AND rcd.UNIQUEID = ? " + |
|||
" AND rcd.STREET = ?"; |
|||
|
|||
List<Map<String, Object>> result = jdbcRoadCutTemplate.queryForList(sql,refid,streetname); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
|
|||
if (result.isEmpty()) { |
|||
response.put("status", "False"); |
|||
response.put("message", "No road cut details found for the given criteria."); |
|||
} else { |
|||
response.put("status", "True"); |
|||
response.put("message", "Road cut found."); |
|||
} |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getRoadCutDetails(String loginid, String refid) { |
|||
String sql = "SELECT rcd.*, IFNULL(rcs.status, 'new') AS status " |
|||
+ "FROM road_cut_details rcd " |
|||
+ "LEFT JOIN ( " |
|||
+ " SELECT * FROM road_cut_status rcs1 " |
|||
+ " WHERE rcs1.id IN ( " |
|||
+ " SELECT MAX(id) FROM road_cut_status GROUP BY uid " |
|||
+ " ) " |
|||
+ ") rcs ON rcs.uid = rcd.uid " |
|||
+ "WHERE rcd.isactive = 1 " |
|||
+ "AND rcd.isdelete = 0 " |
|||
+ "AND rcd.PAYMENT_STATUS = 'Payment Done' " |
|||
+ "AND rcd.NOC_STATUS IS NOT NULL " |
|||
+ "AND rcd.UNIQUEID = ? " |
|||
+ "AND IFNULL(rcs.status, 'new') <> 'completed'"; |
|||
|
|||
List<Map<String, Object>> result = jdbcRoadCutTemplate.queryForList(sql, refid); |
|||
|
|||
for (Map<String, Object> roadCut : result) { |
|||
String uid = String.valueOf(roadCut.get("uid")); |
|||
|
|||
String statusSql = "SELECT id, uid, " |
|||
+ " DATE_FORMAT(indate, '%d-%m-%Y %I:%i %p') AS indate, " |
|||
+ "inby, status, " |
|||
+ " CONCAT('" + fileBaseUrl + "/gccofficialapp/files', filepath) AS filepath, " |
|||
+ " action, isactive, " |
|||
+ "latitude, longitude, zone, ward, streetid, streetname, nocid " |
|||
+ "FROM road_cut_status WHERE uid = ? ORDER BY id ASC"; |
|||
|
|||
List<Map<String, Object>> statusList = jdbcRoadCutTemplate.queryForList(statusSql, uid); |
|||
|
|||
List<Map<String, Object>> nocList = new ArrayList<>(); |
|||
Map<String, Object> nocEntry = null; |
|||
int count = 1; |
|||
|
|||
for (Map<String, Object> statusRow : statusList) { |
|||
String action = String.valueOf(statusRow.get("action")).toLowerCase(); |
|||
|
|||
if ("before".equals(action)) { |
|||
// Save existing 'before' if it had no 'after' |
|||
if (nocEntry != null) { |
|||
nocEntry.put("after_date", null); |
|||
nocEntry.put("after_image", null); |
|||
nocEntry.put("after_status", null); |
|||
nocEntry.put("after_latitude", null); |
|||
nocEntry.put("after_longitude", null); |
|||
nocEntry.put("after_zone", null); |
|||
nocEntry.put("after_ward", null); |
|||
nocEntry.put("NOC_LINK", null); |
|||
nocList.add(nocEntry); |
|||
count++; |
|||
} |
|||
|
|||
nocEntry = new LinkedHashMap<>(); |
|||
nocEntry.put("name", "NOC - " + count); |
|||
nocEntry.put("before_date", statusRow.get("indate")); |
|||
nocEntry.put("before_image", statusRow.get("filepath")); |
|||
nocEntry.put("before_status", statusRow.get("status")); |
|||
nocEntry.put("before_latitude", statusRow.get("latitude")); |
|||
nocEntry.put("before_longitude", statusRow.get("longitude")); |
|||
nocEntry.put("before_zone", statusRow.get("zone")); |
|||
nocEntry.put("before_ward", statusRow.get("ward")); |
|||
nocEntry.put("NOC_ID", statusRow.get("nocid")); |
|||
|
|||
} else if ("after".equals(action) && nocEntry != null) { |
|||
nocEntry.put("after_date", statusRow.get("indate")); |
|||
nocEntry.put("after_image", statusRow.get("filepath")); |
|||
nocEntry.put("after_status", statusRow.get("status")); |
|||
nocEntry.put("after_latitude", statusRow.get("latitude")); |
|||
nocEntry.put("after_longitude", statusRow.get("longitude")); |
|||
nocEntry.put("after_zone", statusRow.get("zone")); |
|||
nocEntry.put("after_ward", statusRow.get("ward")); |
|||
|
|||
nocEntry.put("NOC_LINK", statusRow.get("filepath")); |
|||
|
|||
nocList.add(nocEntry); |
|||
nocEntry = null; |
|||
count++; |
|||
} |
|||
} |
|||
|
|||
// Final unmatched 'before' |
|||
if (nocEntry != null) { |
|||
nocEntry.put("after_date", null); |
|||
nocEntry.put("after_image", null); |
|||
nocEntry.put("after_status", null); |
|||
nocEntry.put("after_latitude", null); |
|||
nocEntry.put("after_longitude", null); |
|||
nocEntry.put("after_zone", null); |
|||
nocEntry.put("after_ward", null); |
|||
nocEntry.put("NOC_LINK", null); |
|||
nocList.add(nocEntry); |
|||
} |
|||
|
|||
roadCut.put("NOC_LIST", nocList); |
|||
} |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (result.isEmpty()) { |
|||
response.put("status", "No Data"); |
|||
response.put("message", "No road cut details found for the given refid (" + refid + ")."); |
|||
response.put("data", Collections.emptyList()); |
|||
} else { |
|||
response.put("status", "Success"); |
|||
response.put("message", "RoadCut Details."); |
|||
response.put("data", result); |
|||
} |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> saveStatusUpdate( |
|||
String uid, |
|||
String cby, |
|||
String latitude, |
|||
String longitude, |
|||
String zone, |
|||
String ward, |
|||
String streetid, |
|||
String streetname, |
|||
String action, |
|||
String workstatus, |
|||
String remarks, |
|||
String nocid, |
|||
MultipartFile filedata) { |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
List<Map<String, Object>> result = new ArrayList<>(); |
|||
|
|||
try { |
|||
// Step 1: Get last action for the given uid |
|||
String checkSql = "SELECT action, status FROM road_cut_status " |
|||
+ "WHERE uid = ? ORDER BY id DESC LIMIT 1"; |
|||
|
|||
String lastAction = null; |
|||
String lastStatus = null; |
|||
try { |
|||
//lastAction = jdbcRoadCutTemplate.queryForObject(checkSql, new Object[]{uid}, String.class); |
|||
Map<String, Object> lastRow = jdbcRoadCutTemplate.queryForMap(checkSql, uid); |
|||
lastAction = (String) lastRow.get("action"); |
|||
lastStatus = (String) lastRow.get("status"); |
|||
} catch (EmptyResultDataAccessException e) { |
|||
// No previous entry — lastAction stays null |
|||
} |
|||
|
|||
// Step 2: Logic check |
|||
if("completed".equalsIgnoreCase(lastStatus)) { |
|||
response.put("status", "error"); |
|||
response.put("message", "Cannot update ‘after’ or `before` status — This action is already completed"); |
|||
result.add(response); |
|||
return result; |
|||
} |
|||
|
|||
if ("after".equalsIgnoreCase(action)) { |
|||
if (!"before".equalsIgnoreCase(lastAction)) { |
|||
response.put("status", "error"); |
|||
response.put("message", "Cannot upload ‘after’ status — please upload a ‘before’ status first."); |
|||
result.add(response); |
|||
return result; |
|||
} |
|||
} else if ("before".equalsIgnoreCase(action)) { |
|||
if ("before".equalsIgnoreCase(lastAction)) { |
|||
response.put("status", "error"); |
|||
response.put("message", "'Before' already exists. You cannot insert it again before 'after'."); |
|||
result.add(response); |
|||
return result; |
|||
} |
|||
} |
|||
|
|||
// Step 3: Upload file |
|||
String actionimg = fileUpload("other_"+uid, action, filedata); |
|||
|
|||
// Step 4: Insert data |
|||
|
|||
// Before Create new NOC |
|||
if ("before".equalsIgnoreCase(action)) { |
|||
String insertNOCSql = "INSERT INTO `road_cut_noc_list`(`uid`, `other_before`) VALUES (?,?)"; |
|||
KeyHolder keyHolder_noc = new GeneratedKeyHolder(); |
|||
int affectedRows_noc = jdbcRoadCutTemplate.update(connection -> { |
|||
PreparedStatement ps_noc = connection.prepareStatement(insertNOCSql, new String[]{"nocid"}); |
|||
int i = 1; |
|||
ps_noc.setString(i++, uid); |
|||
ps_noc.setInt(i++, 1); |
|||
return ps_noc; |
|||
}, keyHolder_noc); |
|||
|
|||
if (affectedRows_noc > 0) { |
|||
int nocInsertId = keyHolder_noc.getKey().intValue(); |
|||
nocid=""+nocInsertId; |
|||
} else { |
|||
response.put("status", "error"); |
|||
response.put("message", "'NOC - Insert `before` failed."); |
|||
result.add(response); |
|||
return result; |
|||
} |
|||
} |
|||
|
|||
String noc_id = nocid; |
|||
|
|||
// Update After NOC |
|||
if ("after".equalsIgnoreCase(action)) { |
|||
String updateNOCSql = "UPDATE `road_cut_noc_list` SET `other_after`=? WHERE `nocid`=?"; |
|||
int affectedRowsNOC = jdbcRoadCutTemplate.update(updateNOCSql, 1, nocid); |
|||
|
|||
if (affectedRowsNOC > 0) { |
|||
|
|||
} else { |
|||
response.put("status", "error"); |
|||
response.put("message", "NOC - Update 'after' failed."); |
|||
result.add(response); |
|||
return result; |
|||
} |
|||
} |
|||
|
|||
String insertSql = "INSERT INTO road_cut_status " |
|||
+ "(uid, inby, latitude, longitude, zone, ward, streetid, streetname, " |
|||
+ "status, filepath, action, isactive, nocid) " |
|||
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; |
|||
|
|||
KeyHolder keyHolder = new GeneratedKeyHolder(); |
|||
int affectedRows = jdbcRoadCutTemplate.update(connection -> { |
|||
PreparedStatement ps = connection.prepareStatement(insertSql, new String[]{"id"}); |
|||
int i = 1; |
|||
ps.setString(i++, uid); |
|||
ps.setString(i++, cby); |
|||
ps.setString(i++, latitude); |
|||
ps.setString(i++, longitude); |
|||
ps.setString(i++, zone); |
|||
ps.setString(i++, ward); |
|||
ps.setString(i++, streetid); |
|||
ps.setString(i++, streetname); |
|||
ps.setString(i++, workstatus); |
|||
ps.setString(i++, actionimg); |
|||
ps.setString(i++, action); |
|||
ps.setInt(i++, 1); |
|||
ps.setString(i++, noc_id); |
|||
return ps; |
|||
}, keyHolder); |
|||
|
|||
if (affectedRows > 0) { |
|||
int lastInsertId = keyHolder.getKey().intValue(); |
|||
response.put("insertId", lastInsertId); |
|||
response.put("status", "success"); |
|||
response.put("message", "Status update inserted successfully."); |
|||
} else { |
|||
response.put("status", "error"); |
|||
response.put("message", "Insert failed."); |
|||
} |
|||
|
|||
} catch (Exception e) { |
|||
response.put("status", "error"); |
|||
response.put("message", "Exception occurred: " + e.getMessage()); |
|||
e.printStackTrace(); |
|||
} |
|||
|
|||
result.add(response); |
|||
return result; |
|||
} |
|||
|
|||
/////// ********************************************************** /////// |
|||
|
|||
// AE GCC Officer |
|||
|
|||
public List<Map<String, Object>> getRoadCutList_offical(String loginid) { |
|||
String sql = "SELECT " |
|||
+ " rcd.*, " |
|||
+ " CASE " |
|||
+ " WHEN rcd.NOC_STATUS = 'NOC Pending' THEN 1 " |
|||
+ " WHEN rcd.NOC_STATUS = 'NOC Approved' THEN 2 " |
|||
+ " ELSE 0 " |
|||
+ " END AS NOC_STATUS_CODE, " |
|||
+ " status_summary.status " |
|||
+ "FROM road_cut_details rcd " |
|||
+ "JOIN ( " |
|||
+ " SELECT " |
|||
+ " noc.uid, " |
|||
+ " CASE " |
|||
+ " WHEN SUM(CASE WHEN noc.gcc_before != 1 OR noc.gcc_after != 1 THEN 1 ELSE 0 END) > 0 THEN 'pending' " |
|||
+ " ELSE 'completed' " |
|||
+ " END AS status " |
|||
+ " FROM road_cut_noc_list noc " |
|||
+ " WHERE noc.isactive = 1 AND noc.other_before = 1 AND noc.other_after = 1 " |
|||
+ " GROUP BY noc.uid " |
|||
+ ") AS status_summary " |
|||
+ "ON rcd.uid = status_summary.uid " |
|||
+ "WHERE " |
|||
+ " rcd.isactive = 1 " |
|||
+ " AND rcd.isdelete = 0 " |
|||
+ " AND rcd.PAYMENT_STATUS = 'Payment Done' " |
|||
+ " AND rcd.NOC_STATUS IS NOT NULL " |
|||
+ "ORDER BY rcd.uid"; |
|||
|
|||
List<Map<String, Object>> result = jdbcRoadCutTemplate.queryForList(sql); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (result.isEmpty()) { |
|||
response.put("status", "No Data"); |
|||
response.put("message", "No officer road cut list found."); |
|||
response.put("data", Collections.emptyList()); // or just null |
|||
} else { |
|||
response.put("status", "Success"); |
|||
response.put("message", "Officer RoadCut List."); |
|||
response.put("data", result); |
|||
} |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getLoactionCheck_offical(String loginid, String refid, String streetid, String streetname) { |
|||
String sql = "SELECT " + |
|||
" rcd.*, " + |
|||
" CASE " + |
|||
" WHEN rcd.NOC_STATUS = 'NOC Pending' THEN 1 " + |
|||
" WHEN rcd.NOC_STATUS = 'NOC Approved' THEN 2 " + |
|||
" ELSE 0 " + |
|||
" END AS NOC_STATUS_CODE, " + |
|||
" IFNULL(rcs.status, 'new') AS status " + |
|||
"FROM " + |
|||
" road_cut_details rcd " + |
|||
"LEFT JOIN ( " + |
|||
" SELECT * " + |
|||
" FROM road_cut_status rcs1 " + |
|||
" WHERE rcs1.id IN ( " + |
|||
" SELECT MAX(id) " + |
|||
" FROM road_cut_status " + |
|||
" GROUP BY uid " + |
|||
" ) " + |
|||
") rcs ON rcs.uid = rcd.uid " + |
|||
"WHERE " + |
|||
" rcd.isactive = 1 " + |
|||
" AND rcd.isdelete = 0 " + |
|||
" AND rcd.PAYMENT_STATUS = 'Payment Done' " + |
|||
" AND rcd.NOC_STATUS IS NOT NULL " + |
|||
" AND rcd.UNIQUEID = ? " + |
|||
" AND rcd.STREET = ?"; |
|||
|
|||
List<Map<String, Object>> result = jdbcRoadCutTemplate.queryForList(sql,refid,streetname); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
|
|||
if (result.isEmpty()) { |
|||
response.put("status", "False"); |
|||
response.put("message", "No road cut details found for the given criteria."); |
|||
} else { |
|||
response.put("status", "True"); |
|||
response.put("message", "Road cut found."); |
|||
} |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getRoadCutDetails_offical(String loginid, String refid) { |
|||
String sql = "SELECT rcd.*, IFNULL(rcs.status, 'new') AS status " |
|||
+ "FROM road_cut_details rcd " |
|||
+ "LEFT JOIN ( " |
|||
+ " SELECT * FROM road_cut_status rcs1 " |
|||
+ " WHERE rcs1.id IN ( " |
|||
+ " SELECT MAX(id) FROM road_cut_status GROUP BY uid " |
|||
+ " ) " |
|||
+ ") rcs ON rcs.uid = rcd.uid " |
|||
+ "WHERE rcd.isactive = 1 " |
|||
+ "AND rcd.isdelete = 0 " |
|||
+ "AND rcd.PAYMENT_STATUS = 'Payment Done' " |
|||
+ "AND rcd.NOC_STATUS IS NOT NULL " |
|||
+ "AND rcd.UNIQUEID = ?"; |
|||
|
|||
List<Map<String, Object>> result = jdbcRoadCutTemplate.queryForList(sql, refid); |
|||
|
|||
for (Map<String, Object> roadCut : result) { |
|||
String uid = String.valueOf(roadCut.get("uid")); |
|||
|
|||
String statusSql = "SELECT `nocid`, `uid`, `other_before`, `other_after`, " |
|||
+ "`gcc_before`, `gcc_after`, `noc_file` " |
|||
+ "FROM `road_cut_noc_list` " |
|||
+ "WHERE uid=? AND `isactive`=1 " |
|||
+ "ORDER BY `nocid` ASC"; |
|||
|
|||
List<Map<String, Object>> statusList = jdbcRoadCutTemplate.queryForList(statusSql, uid); |
|||
List<Map<String, Object>> nocList = new ArrayList<>(); |
|||
|
|||
for (Map<String, Object> statusRow : statusList) { |
|||
String nocid = String.valueOf(statusRow.get("nocid")); |
|||
|
|||
String formattedStatusSql = "SELECT id, uid, " |
|||
+ "DATE_FORMAT(indate, '%d-%m-%Y %I:%i %p') AS indate, " |
|||
+ "inby, status, " |
|||
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', filepath) AS filepath, " |
|||
+ "action, isactive, latitude, longitude, zone, ward, streetid, streetname, nocid " |
|||
+ "FROM road_cut_status " |
|||
+ "WHERE uid = ? AND nocid = ? " |
|||
+ "ORDER BY id ASC"; |
|||
|
|||
List<Map<String, Object>> formattedList = jdbcRoadCutTemplate.queryForList(formattedStatusSql, uid, nocid); |
|||
|
|||
String statusNOCSql = "SELECT id, uid, " |
|||
+ "DATE_FORMAT(indate, '%d-%m-%Y %I:%i %p') AS indate, " |
|||
+ "inby, status, " |
|||
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', filepath) AS filepath, " |
|||
+ "action, isactive, latitude, longitude, zone, ward, streetid, streetname, nocid " |
|||
+ "FROM road_cut_officer_status " |
|||
+ "WHERE uid = ? AND nocid = ? " |
|||
+ "ORDER BY id ASC"; |
|||
|
|||
List<Map<String, Object>> officerList = jdbcRoadCutTemplate.queryForList(statusNOCSql, uid, nocid); |
|||
|
|||
Map<String, Object> nocEntry = new LinkedHashMap<>(); |
|||
nocEntry.put("name", "NOC - " + nocid); |
|||
nocEntry.put("NOC_ID", nocid); |
|||
|
|||
// 🟩 Add default nulls for officer_* fields |
|||
nocEntry.put("officer_before_date", null); |
|||
nocEntry.put("officer_before_image", null); |
|||
nocEntry.put("officer_before_status", null); |
|||
nocEntry.put("officer_before_latitude", null); |
|||
nocEntry.put("officer_before_longitude", null); |
|||
nocEntry.put("officer_before_zone", null); |
|||
nocEntry.put("officer_before_ward", null); |
|||
nocEntry.put("officer_after_date", null); |
|||
nocEntry.put("officer_after_image", null); |
|||
nocEntry.put("officer_after_status", null); |
|||
nocEntry.put("officer_after_latitude", null); |
|||
nocEntry.put("officer_after_longitude", null); |
|||
nocEntry.put("officer_after_zone", null); |
|||
nocEntry.put("officer_after_ward", null); |
|||
|
|||
// Add formatted (app) status |
|||
for (Map<String, Object> formattedRow : formattedList) { |
|||
String action = String.valueOf(formattedRow.get("action")).trim().toLowerCase(); |
|||
if ("before".equals(action)) { |
|||
nocEntry.put("before_date", formattedRow.get("indate")); |
|||
nocEntry.put("before_image", formattedRow.get("filepath")); |
|||
nocEntry.put("before_status", formattedRow.get("status")); |
|||
nocEntry.put("before_latitude", formattedRow.get("latitude")); |
|||
nocEntry.put("before_longitude", formattedRow.get("longitude")); |
|||
nocEntry.put("before_zone", formattedRow.get("zone")); |
|||
nocEntry.put("before_ward", formattedRow.get("ward")); |
|||
} else if ("after".equals(action)) { |
|||
nocEntry.put("after_date", formattedRow.get("indate")); |
|||
nocEntry.put("after_image", formattedRow.get("filepath")); |
|||
nocEntry.put("after_status", formattedRow.get("status")); |
|||
nocEntry.put("after_latitude", formattedRow.get("latitude")); |
|||
nocEntry.put("after_longitude", formattedRow.get("longitude")); |
|||
nocEntry.put("after_zone", formattedRow.get("zone")); |
|||
nocEntry.put("after_ward", formattedRow.get("ward")); |
|||
nocEntry.put("NOC_LINK", formattedRow.get("filepath")); |
|||
} |
|||
} |
|||
|
|||
// Add officer_* if available |
|||
for (Map<String, Object> officerRow : officerList) { |
|||
System.out.println("I am IN "+officerRow.get("id")); |
|||
String action = String.valueOf(officerRow.get("action")).trim().toLowerCase(); |
|||
if ("before".equals(action)) { |
|||
nocEntry.put("officer_before_date", officerRow.get("indate")); |
|||
nocEntry.put("officer_before_image", officerRow.get("filepath")); |
|||
nocEntry.put("officer_before_status", officerRow.get("status")); |
|||
nocEntry.put("officer_before_latitude", officerRow.get("latitude")); |
|||
nocEntry.put("officer_before_longitude", officerRow.get("longitude")); |
|||
nocEntry.put("officer_before_zone", officerRow.get("zone")); |
|||
nocEntry.put("officer_before_ward", officerRow.get("ward")); |
|||
} else if ("after".equals(action)) { |
|||
nocEntry.put("officer_after_date", officerRow.get("indate")); |
|||
nocEntry.put("officer_after_image", officerRow.get("filepath")); |
|||
nocEntry.put("officer_after_status", officerRow.get("status")); |
|||
nocEntry.put("officer_after_latitude", officerRow.get("latitude")); |
|||
nocEntry.put("officer_after_longitude", officerRow.get("longitude")); |
|||
nocEntry.put("officer_after_zone", officerRow.get("zone")); |
|||
nocEntry.put("officer_after_ward", officerRow.get("ward")); |
|||
//nocEntry.put("NOC_LINK", officerRow.get("filepath")); // fallback |
|||
} |
|||
} |
|||
|
|||
nocList.add(nocEntry); |
|||
} |
|||
|
|||
roadCut.put("NOC_LIST", nocList); |
|||
} |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (result.isEmpty()) { |
|||
response.put("status", "No Data"); |
|||
response.put("message", "No road cut details found for the given refid (" + refid + ")."); |
|||
response.put("data", Collections.emptyList()); |
|||
} else { |
|||
response.put("status", "Success"); |
|||
response.put("message", "RoadCut Details."); |
|||
response.put("data", result); |
|||
} |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> saveStatusUpdate_offical( |
|||
String uid, |
|||
String cby, |
|||
String latitude, |
|||
String longitude, |
|||
String zone, |
|||
String ward, |
|||
String streetid, |
|||
String streetname, |
|||
String action, |
|||
String workstatus, |
|||
String remarks, |
|||
String nocid, |
|||
MultipartFile filedata) { |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
List<Map<String, Object>> result = new ArrayList<>(); |
|||
|
|||
try { |
|||
// Step 1: Get last action for the given uid |
|||
String checkSql = "SELECT action, status FROM `road_cut_officer_status` " |
|||
+ "WHERE uid = ? AND nocid = ? ORDER BY id DESC LIMIT 1"; |
|||
|
|||
String lastAction = null; |
|||
String lastStatus = null; |
|||
try { |
|||
//lastAction = jdbcRoadCutTemplate.queryForObject(checkSql, new Object[]{uid}, String.class); |
|||
Map<String, Object> lastRow = jdbcRoadCutTemplate.queryForMap(checkSql, uid, nocid); |
|||
lastAction = (String) lastRow.get("action"); |
|||
lastStatus = (String) lastRow.get("status"); |
|||
} catch (EmptyResultDataAccessException e) { |
|||
// No previous entry — lastAction stays null |
|||
} |
|||
|
|||
// Step 2: Logic check |
|||
if("completed".equalsIgnoreCase(lastStatus)) { |
|||
response.put("status", "error"); |
|||
response.put("message", "Officer - Cannot update ‘after’ or `before` status — This action is already completed"); |
|||
result.add(response); |
|||
return result; |
|||
} |
|||
|
|||
if ("after".equalsIgnoreCase(action)) { |
|||
if (!"before".equalsIgnoreCase(lastAction)) { |
|||
response.put("status", "error"); |
|||
response.put("message", "Cannot upload ‘after’ status — please upload a ‘before’ status first."); |
|||
result.add(response); |
|||
return result; |
|||
} |
|||
} else if ("before".equalsIgnoreCase(action)) { |
|||
if ("before".equalsIgnoreCase(lastAction)) { |
|||
response.put("status", "error"); |
|||
response.put("message", "'Before' already exists. You cannot insert it again before 'after'."); |
|||
result.add(response); |
|||
return result; |
|||
} |
|||
} |
|||
|
|||
// Step 3: Upload file |
|||
String actionimg = fileUpload("officer_"+uid, action, filedata); |
|||
|
|||
// Step 4: Insert data |
|||
|
|||
// Update before NOC |
|||
if ("before".equalsIgnoreCase(action)) { |
|||
String updateNOCSql = "UPDATE `road_cut_noc_list` SET `gcc_before`=? WHERE `nocid`=?"; |
|||
int affectedRowsNOC = jdbcRoadCutTemplate.update(updateNOCSql, 1, nocid); |
|||
|
|||
if (affectedRowsNOC > 0) { |
|||
|
|||
} else { |
|||
response.put("status", "error"); |
|||
response.put("message", "Oficer NOC - Update 'before' failed."); |
|||
result.add(response); |
|||
return result; |
|||
} |
|||
} |
|||
|
|||
// Update After NOC |
|||
if ("after".equalsIgnoreCase(action)) { |
|||
String updateNOCSql = "UPDATE `road_cut_noc_list` SET `gcc_after`=? WHERE `nocid`=?"; |
|||
int affectedRowsNOC = jdbcRoadCutTemplate.update(updateNOCSql, 1, nocid); |
|||
|
|||
if (affectedRowsNOC > 0) { |
|||
|
|||
} else { |
|||
response.put("status", "error"); |
|||
response.put("message", "Oficer NOC - Update 'after' failed."); |
|||
result.add(response); |
|||
return result; |
|||
} |
|||
} |
|||
|
|||
String insertSql = "INSERT INTO road_cut_officer_status " |
|||
+ "(uid, inby, latitude, longitude, zone, ward, streetid, streetname, " |
|||
+ "status, filepath, action, isactive, nocid) " |
|||
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; |
|||
|
|||
KeyHolder keyHolder = new GeneratedKeyHolder(); |
|||
int affectedRows = jdbcRoadCutTemplate.update(connection -> { |
|||
PreparedStatement ps = connection.prepareStatement(insertSql, new String[]{"id"}); |
|||
int i = 1; |
|||
ps.setString(i++, uid); |
|||
ps.setString(i++, cby); |
|||
ps.setString(i++, latitude); |
|||
ps.setString(i++, longitude); |
|||
ps.setString(i++, zone); |
|||
ps.setString(i++, ward); |
|||
ps.setString(i++, streetid); |
|||
ps.setString(i++, streetname); |
|||
ps.setString(i++, workstatus); |
|||
ps.setString(i++, actionimg); |
|||
ps.setString(i++, action); |
|||
ps.setInt(i++, 1); |
|||
ps.setString(i++, nocid); |
|||
return ps; |
|||
}, keyHolder); |
|||
|
|||
if (affectedRows > 0) { |
|||
int lastInsertId = keyHolder.getKey().intValue(); |
|||
response.put("insertId", lastInsertId); |
|||
response.put("status", "success"); |
|||
response.put("message", "Officer Status update inserted successfully."); |
|||
} else { |
|||
response.put("status", "error"); |
|||
response.put("message", "Officer Insert failed."); |
|||
} |
|||
|
|||
} catch (Exception e) { |
|||
response.put("status", "error"); |
|||
response.put("message", "Exception occurred: " + e.getMessage()); |
|||
e.printStackTrace(); |
|||
} |
|||
|
|||
result.add(response); |
|||
return result; |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.roadcut.service; |
|||
@ -0,0 +1,42 @@ |
|||
package in.gov.chennaicorporation.mobileservice.service; |
|||
|
|||
import java.util.Map; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thymeleaf.TemplateEngine; |
|||
import org.thymeleaf.context.Context; |
|||
|
|||
import com.openhtmltopdf.pdfboxout.PdfRendererBuilder; |
|||
|
|||
import java.io.ByteArrayOutputStream; |
|||
import java.io.IOException; |
|||
import java.time.LocalDate; |
|||
import java.util.Map; |
|||
|
|||
@Service |
|||
public class PdfGeneratorService { |
|||
@Autowired |
|||
private TemplateEngine templateEngine; |
|||
|
|||
public byte[] generatePdf(Map<String, Object> data) { |
|||
Context context = new Context(); |
|||
context.setVariables(data); |
|||
|
|||
String htmlContent = templateEngine.process("pdf-template", context); |
|||
|
|||
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
|||
PdfRendererBuilder builder = new PdfRendererBuilder(); |
|||
builder.useFastMode(); |
|||
builder.withHtmlContent(htmlContent, null); |
|||
builder.toStream(os); |
|||
try { |
|||
builder.run(); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); // or log it properly |
|||
throw new RuntimeException("PDF generation failed", e); |
|||
} |
|||
|
|||
return os.toByteArray(); |
|||
} |
|||
} |
|||
@ -0,0 +1,93 @@ |
|||
package in.gov.chennaicorporation.mobileservice.speedbrake.controller; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import in.gov.chennaicorporation.mobileservice.speedbrake.service.APIService; |
|||
|
|||
@RequestMapping("/gccofficialapp/api/speedbrake/") |
|||
@RestController("gccofficialappsspeedbrake") |
|||
public class APIController { |
|||
@Autowired |
|||
private APIService apiService; |
|||
|
|||
@GetMapping(value="/getQuestions") |
|||
public List<?> getQuestions(){ |
|||
return apiService.getQuestions(); |
|||
} |
|||
|
|||
@GetMapping(value="/checkAssetExists") |
|||
public List<?> checkAssetExists( |
|||
@RequestParam(value = "latitude", required = true) String latitude, |
|||
@RequestParam(value = "longitude", required = true) String longitude |
|||
){ |
|||
return apiService.checkAssetExists(latitude,longitude); |
|||
} |
|||
|
|||
@PostMapping(value="/saveSpeedBrakeDetails") |
|||
public List<Map<String, Object>> saveConstructionDetails( |
|||
@RequestParam(value = "zone", required = true) String zone, |
|||
@RequestParam(value = "ward", required = true) String ward, |
|||
@RequestParam(value = "streetid", required = true) String streetid, |
|||
@RequestParam(value = "streetname", required = true) String streetname, |
|||
@RequestParam(value = "streettype", required = true) String streettype, |
|||
@RequestParam(value = "roadtype", required = true) String roadtype, |
|||
@RequestParam(value = "marktype", required = true) String marktype, |
|||
@RequestParam(value = "q1", required = false) String q1, |
|||
@RequestParam(value = "q2", required = false) String q2, |
|||
@RequestParam(value = "q3", required = false) String q3, |
|||
@RequestParam(value = "cby", required = true) String cby, |
|||
@RequestParam(value = "latitude", required = true) String latitude, |
|||
@RequestParam(value = "longitude", required = true) String longitude, |
|||
@RequestParam(value = "sb_condition", required = false) String sb_condition, |
|||
@RequestParam(value = "mainfile", required = true) MultipartFile mainFile |
|||
){ |
|||
return apiService.saveSpeedBrakeDetails( |
|||
zone, ward, streetid, streetname, streettype, |
|||
roadtype, marktype, q1, q2, q3, cby, latitude, longitude, sb_condition, mainFile |
|||
); |
|||
} |
|||
|
|||
// 1. Zone-wise report |
|||
@GetMapping("/zone-wise") |
|||
public List<Map<String, Object>> getZoneWiseReport() { |
|||
return apiService.getZoneWiseReport(); |
|||
} |
|||
|
|||
// 2. Ward-wise report by zone |
|||
@GetMapping("/ward-wise") |
|||
public List<Map<String, Object>> getWardWiseReport(@RequestParam String zone) { |
|||
return apiService.getWardeWiseReport(zone); |
|||
} |
|||
|
|||
// 3. Street-wise report (New) by ward |
|||
@GetMapping("/new-street-wise") |
|||
public List<Map<String, Object>> getNewStreetWiseReport(@RequestParam String ward) { |
|||
return apiService.getNewStreetWiseReport(ward); |
|||
} |
|||
|
|||
// 4. Street-wise report (Existing) by ward |
|||
@GetMapping("/existing-street-wise") |
|||
public List<Map<String, Object>> getExistingStreetWiseReport(@RequestParam String ward) { |
|||
return apiService.getExistingStreetWiseReport(ward); |
|||
} |
|||
|
|||
// 5. Detailed Speedbrake Entry with Q&A |
|||
@GetMapping("/details") |
|||
public List<Map<String, Object>> getSpeedbrakeDetails( |
|||
@RequestParam String ward, |
|||
@RequestParam String streetname, |
|||
@RequestParam String marktype, |
|||
@RequestParam(required = false) String sb_condition |
|||
) { |
|||
return apiService.getSpeedbrakeDetailsWithQuestions(ward, marktype, sb_condition, streetname); |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.speedbrake.controller; |
|||
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.speedbrake; |
|||
@ -0,0 +1,453 @@ |
|||
package in.gov.chennaicorporation.mobileservice.speedbrake.service; |
|||
|
|||
import java.awt.image.BufferedImage; |
|||
import java.io.ByteArrayInputStream; |
|||
import java.io.ByteArrayOutputStream; |
|||
import java.io.IOException; |
|||
import java.nio.file.Files; |
|||
import java.nio.file.Path; |
|||
import java.nio.file.Paths; |
|||
import java.security.SecureRandom; |
|||
import java.sql.PreparedStatement; |
|||
import java.util.ArrayList; |
|||
import java.util.Collections; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.Random; |
|||
|
|||
import javax.imageio.ImageIO; |
|||
import javax.imageio.ImageWriteParam; |
|||
import javax.imageio.ImageWriter; |
|||
import javax.imageio.stream.ImageOutputStream; |
|||
import javax.sql.DataSource; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Qualifier; |
|||
import org.springframework.core.env.Environment; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
import org.springframework.jdbc.support.GeneratedKeyHolder; |
|||
import org.springframework.jdbc.support.KeyHolder; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import in.gov.chennaicorporation.mobileservice.gccactivity.service.DateTimeUtil; |
|||
|
|||
@Service |
|||
public class APIService { |
|||
|
|||
private JdbcTemplate jdbcSpeedBrake; |
|||
private final Environment environment; |
|||
private String fileBaseUrl; |
|||
|
|||
private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
|||
private static final int STRING_LENGTH = 15; |
|||
private static final Random RANDOM = new SecureRandom(); |
|||
|
|||
@Autowired |
|||
public void setDataSource(@Qualifier("mysqlGccSpeedBrakeSource") DataSource speedBrakeDataSource) { |
|||
this.jdbcSpeedBrake = new JdbcTemplate(speedBrakeDataSource); |
|||
} |
|||
|
|||
@Autowired |
|||
public APIService(Environment environment) { |
|||
this.environment = environment; |
|||
this.fileBaseUrl=environment.getProperty("fileBaseUrl"); |
|||
} |
|||
|
|||
public static String generateRandomString() { |
|||
StringBuilder result = new StringBuilder(STRING_LENGTH); |
|||
for (int i = 0; i < STRING_LENGTH; i++) { |
|||
result.append(CHARACTERS.charAt(RANDOM.nextInt(CHARACTERS.length()))); |
|||
} |
|||
return result.toString(); |
|||
} |
|||
|
|||
public static String generateRandomFileString(int lenthval) { |
|||
StringBuilder result = new StringBuilder(lenthval); |
|||
for (int i = 0; i < lenthval; i++) { |
|||
result.append(CHARACTERS.charAt(RANDOM.nextInt(CHARACTERS.length()))); |
|||
} |
|||
return result.toString(); |
|||
} |
|||
|
|||
private byte[] compressImage(BufferedImage image, float quality) throws IOException { |
|||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
|||
ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(byteArrayOutputStream); |
|||
|
|||
ImageWriter writer = ImageIO.getImageWritersByFormatName("jpg").next(); |
|||
writer.setOutput(imageOutputStream); |
|||
|
|||
ImageWriteParam param = writer.getDefaultWriteParam(); |
|||
if (param.canWriteCompressed()) { |
|||
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
|||
param.setCompressionQuality(quality); |
|||
} |
|||
|
|||
writer.write(null, new javax.imageio.IIOImage(image, null, null), param); |
|||
|
|||
writer.dispose(); |
|||
imageOutputStream.close(); |
|||
|
|||
return byteArrayOutputStream.toByteArray(); |
|||
} |
|||
|
|||
public String fileUpload(String name, String id, MultipartFile file) { |
|||
|
|||
int lastInsertId = 0; |
|||
// Set the file path where you want to save it |
|||
String uploadDirectory = environment.getProperty("file.upload.directory"); |
|||
String serviceFolderName = environment.getProperty("speedbrake_foldername"); |
|||
var year = DateTimeUtil.getCurrentYear(); |
|||
var month = DateTimeUtil.getCurrentMonth(); |
|||
var date = DateTimeUtil.getCurrentDay(); |
|||
|
|||
uploadDirectory = uploadDirectory + serviceFolderName + year + "/" + month + "/" + date; |
|||
|
|||
try { |
|||
// Create directory if it doesn't exist |
|||
Path directoryPath = Paths.get(uploadDirectory); |
|||
if (!Files.exists(directoryPath)) { |
|||
Files.createDirectories(directoryPath); |
|||
} |
|||
|
|||
// Datetime string |
|||
String datetimetxt = DateTimeUtil.getCurrentDateTime(); |
|||
|
|||
datetimetxt = datetimetxt + "_"+ generateRandomFileString(6); // Attached Random text |
|||
|
|||
// File name |
|||
String fileName = name + "_" + id + "_" + datetimetxt + "_" + file.getOriginalFilename(); |
|||
fileName = fileName.replaceAll("\\s+", ""); // Remove space on filename |
|||
|
|||
String filePath = uploadDirectory + "/" + fileName; |
|||
|
|||
String filepath_txt = "/" + serviceFolderName + year + "/" + month + "/" + date + "/" + fileName; |
|||
|
|||
// Create a new Path object |
|||
Path path = Paths.get(filePath); |
|||
|
|||
// Get the bytes of the file |
|||
byte[] bytes = file.getBytes(); |
|||
|
|||
// Compress the image |
|||
BufferedImage image = ImageIO.read(new ByteArrayInputStream(bytes)); |
|||
byte[] compressedBytes = compressImage(image, 0.5f); // Compress with 50% quality |
|||
|
|||
// Write the bytes to the file |
|||
Files.write(path, compressedBytes); |
|||
|
|||
System.out.println(filePath); |
|||
return filepath_txt; |
|||
|
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
return "Failed to save file " + file.getOriginalFilename(); |
|||
} |
|||
} |
|||
|
|||
public List<Map<String, Object>> getQuestions(){ |
|||
String sql = "SELECT * FROM `Questions` WHERE `isactive`=1 ORDER BY `orderby`"; |
|||
List<Map<String, Object>> result = jdbcSpeedBrake.queryForList(sql); |
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("status", "Success"); |
|||
response.put("message", "Question List."); |
|||
response.put("data", result); |
|||
|
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> checkAssetExists(String latitudeStr, String longitudeStr) { |
|||
double latitude = Double.parseDouble(latitudeStr); |
|||
double longitude = Double.parseDouble(longitudeStr); |
|||
|
|||
String checkSql = "SELECT COUNT(*) FROM speedbrake_list sbl " + |
|||
"WHERE (6371008.8 * ACOS(COS(RADIANS(?)) * COS(RADIANS(sbl.latitude)) * " + |
|||
"COS(RADIANS(sbl.longitude) - RADIANS(?)) + SIN(RADIANS(?)) * SIN(RADIANS(sbl.latitude)))) < 2"; |
|||
//Integer count = jdbcSpeedBrake.queryForObject(checkSql,new Object[]{latitude, longitude, latitude}, Integer.class); |
|||
|
|||
Integer count = jdbcSpeedBrake.queryForObject( |
|||
checkSql, |
|||
Integer.class, |
|||
latitude, longitude, latitude |
|||
); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
if (count != null && count > 0) { |
|||
response.put("count", count); |
|||
response.put("status", "error"); |
|||
response.put("message", "Duplicate: Speed breaker already exists."); |
|||
} else { |
|||
response.put("count", count); |
|||
response.put("status", "success"); |
|||
response.put("message", "No existing speed breaker found."); |
|||
} |
|||
return Collections.singletonList(response); |
|||
} |
|||
|
|||
@Transactional |
|||
public List<Map<String, Object>> saveSpeedBrakeDetails( |
|||
String zone, |
|||
String ward, |
|||
String streetid, |
|||
String streetname, |
|||
String streettype, |
|||
String roadtype, |
|||
String marktype, |
|||
String q1, |
|||
String q2, |
|||
String q3, |
|||
String cby, |
|||
String latitude, |
|||
String longitude, |
|||
String sb_condition, |
|||
MultipartFile mainfile |
|||
) { |
|||
Map<String, Object> response = new HashMap<>(); |
|||
List<Map<String, Object>> result = new ArrayList<>(); |
|||
|
|||
String roadimg = fileUpload("Construction", "main", mainfile); |
|||
|
|||
String roadcategorytxt = "GCC"; |
|||
|
|||
if("HY".equalsIgnoreCase(roadtype)) { |
|||
roadcategorytxt = "Highways"; |
|||
} |
|||
|
|||
String roadcategory = roadcategorytxt; |
|||
|
|||
// Insert query |
|||
String insertSql = "INSERT INTO `speedbrake_list`(`zone`, `ward`, `streetid`, `streetname`, `streettype`, `roadcategory`, " |
|||
+ "`roadtype`, `marktype`, `file`, " |
|||
+ "`q1`, `q2`, `q3`, `cby`,`latitude`, `longitude`,`sb_condition`) VALUES " |
|||
+ "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; |
|||
|
|||
KeyHolder keyHolder = new GeneratedKeyHolder(); |
|||
|
|||
int affectedRows = jdbcSpeedBrake.update(connection -> { |
|||
PreparedStatement ps = connection.prepareStatement(insertSql, new String[]{"cdid"}); |
|||
int i = 1; |
|||
ps.setString(i++, zone); |
|||
ps.setString(i++, ward); |
|||
ps.setString(i++, streetid); |
|||
ps.setString(i++, streetname); |
|||
ps.setString(i++, streettype); |
|||
ps.setString(i++, roadcategory); |
|||
ps.setString(i++, roadtype); |
|||
ps.setString(i++, marktype); |
|||
ps.setString(i++, roadimg); |
|||
ps.setString(i++, q1); |
|||
ps.setString(i++, q2); |
|||
ps.setString(i++, q3); |
|||
ps.setString(i++, cby); |
|||
ps.setString(i++, latitude); |
|||
ps.setString(i++, longitude); |
|||
ps.setString(i++, sb_condition); |
|||
|
|||
return ps; |
|||
}, keyHolder); |
|||
|
|||
if (affectedRows > 0) { |
|||
int lastInsertId = keyHolder.getKey().intValue(); |
|||
|
|||
response.put("insertId", lastInsertId); |
|||
response.put("status", "success"); |
|||
response.put("message", "Speed Brake details inserted successfully."); |
|||
|
|||
|
|||
} else { |
|||
response.put("status", "error"); |
|||
response.put("message", "Speed Brake details insert failed."); |
|||
} |
|||
|
|||
result.add(response); |
|||
return result; |
|||
} |
|||
|
|||
public List<Map<String, Object>> getZoneWiseReport() { |
|||
String sql = "SELECT " |
|||
+ " zone, " |
|||
+ " COUNT(*) AS total_mapping, " |
|||
+ " SUM(CASE WHEN marktype = 'New' THEN 1 ELSE 0 END) AS new_count, " |
|||
+ " SUM(CASE WHEN marktype = 'Existing' THEN 1 ELSE 0 END) AS existing_count " |
|||
+ "FROM " |
|||
+ " speedbrake_list " |
|||
+ "WHERE " |
|||
+ " isactive = 1 AND isdelete = 0 " |
|||
+ "GROUP BY " |
|||
+ " zone " |
|||
+ " " |
|||
+ "UNION ALL " |
|||
+ " " |
|||
+ "SELECT " |
|||
+ " 'Total' AS zone, " |
|||
+ " COUNT(*) AS total_mapping, " |
|||
+ " SUM(CASE WHEN marktype = 'New' THEN 1 ELSE 0 END), " |
|||
+ " SUM(CASE WHEN marktype = 'Existing' THEN 1 ELSE 0 END) " |
|||
+ "FROM " |
|||
+ " speedbrake_list " |
|||
+ "WHERE " |
|||
+ " isactive = 1 AND isdelete = 0 " |
|||
+ " " |
|||
+ "ORDER BY " |
|||
+ " CASE " |
|||
+ " WHEN zone = 'Total' THEN 1 " |
|||
+ " ELSE 0 " |
|||
+ " END, " |
|||
+ " zone"; |
|||
|
|||
return jdbcSpeedBrake.queryForList(sql); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getWardeWiseReport(String zone) { |
|||
String sql = "SELECT " |
|||
+ " ward, " |
|||
+ " COUNT(*) AS total_mapping, " |
|||
+ " SUM(CASE WHEN marktype = 'New' THEN 1 ELSE 0 END) AS new_count, " |
|||
+ " SUM(CASE WHEN marktype = 'Existing' THEN 1 ELSE 0 END) AS existing_count " |
|||
+ "FROM " |
|||
+ " speedbrake_list " |
|||
+ "WHERE " |
|||
+ " isactive = 1 AND isdelete = 0 AND zone = ? " |
|||
+ "GROUP BY " |
|||
+ " ward " |
|||
+ " " |
|||
+ "UNION ALL " |
|||
+ " " |
|||
+ "SELECT " |
|||
+ " 'Total' AS ward, " |
|||
+ " COUNT(*) AS total_mapping, " |
|||
+ " SUM(CASE WHEN marktype = 'New' THEN 1 ELSE 0 END), " |
|||
+ " SUM(CASE WHEN marktype = 'Existing' THEN 1 ELSE 0 END) " |
|||
+ "FROM " |
|||
+ " speedbrake_list " |
|||
+ "WHERE " |
|||
+ " isactive = 1 AND isdelete = 0 AND zone = ? " |
|||
+ "ORDER BY " |
|||
+ " CASE " |
|||
+ " WHEN ward = 'Total' THEN 1 " |
|||
+ " ELSE 0 " |
|||
+ " END, " |
|||
+ " ward"; |
|||
|
|||
return jdbcSpeedBrake.queryForList(sql,zone,zone); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getNewStreetWiseReport(String ward) { |
|||
String sql = "SELECT " |
|||
+ " streetname, " |
|||
+ " COUNT(*) AS count " |
|||
+ "FROM " |
|||
+ " speedbrake_list " |
|||
+ "WHERE " |
|||
+ " isactive = 1 " |
|||
+ " AND isdelete = 0 " |
|||
+ " AND marktype = 'New' " |
|||
+ " AND ward = ? " |
|||
+ "GROUP BY " |
|||
+ " streetname " |
|||
+ " " |
|||
+ "UNION ALL " |
|||
+ " " |
|||
+ "SELECT " |
|||
+ " 'Total' AS streetname, " |
|||
+ " COUNT(*) AS count " |
|||
+ "FROM " |
|||
+ " speedbrake_list " |
|||
+ "WHERE " |
|||
+ " isactive = 1 " |
|||
+ " AND isdelete = 0 " |
|||
+ " AND marktype = 'New' " |
|||
+ " AND ward = ?"; |
|||
|
|||
return jdbcSpeedBrake.queryForList(sql,ward,ward); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getExistingStreetWiseReport(String ward) { |
|||
String sql = "SELECT " |
|||
+ " streetname, " |
|||
+ " SUM(CASE WHEN sb_condition = 'Good' THEN 1 ELSE 0 END) AS good_count, " |
|||
+ " SUM(CASE WHEN sb_condition = 'Complete reconstruction' THEN 1 ELSE 0 END) AS complete_reconstruction_count, " |
|||
+ " SUM(CASE WHEN sb_condition = 'Improvement to the existing' THEN 1 ELSE 0 END) AS improvement_count " |
|||
+ "FROM " |
|||
+ " speedbrake_list " |
|||
+ "WHERE " |
|||
+ " isactive = 1 " |
|||
+ " AND isdelete = 0 " |
|||
+ " AND marktype = 'Existing' " |
|||
+ " AND ward = ? " |
|||
+ "GROUP BY " |
|||
+ " streetname " |
|||
+ " " |
|||
+ "UNION ALL " |
|||
+ " " |
|||
+ "SELECT " |
|||
+ " 'Total' AS streetname, " |
|||
+ " SUM(CASE WHEN sb_condition = 'Good' THEN 1 ELSE 0 END), " |
|||
+ " SUM(CASE WHEN sb_condition = 'Complete reconstruction' THEN 1 ELSE 0 END), " |
|||
+ " SUM(CASE WHEN sb_condition = 'Improvement to the existing' THEN 1 ELSE 0 END) " |
|||
+ "FROM " |
|||
+ " speedbrake_list " |
|||
+ "WHERE " |
|||
+ " isactive = 1 " |
|||
+ " AND isdelete = 0 " |
|||
+ " AND marktype = 'Existing' " |
|||
+ " AND ward = ?"; |
|||
|
|||
return jdbcSpeedBrake.queryForList(sql,ward,ward); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getSpeedbrakeDetailsWithQuestions(String ward, String marktype, String sb_condition, String streetname) { |
|||
String where = ""; |
|||
List<Object> params = new ArrayList<>(); |
|||
params.add(marktype); |
|||
params.add(ward); |
|||
params.add(streetname); |
|||
|
|||
if (sb_condition != null) { |
|||
where = " AND sb_condition = ?"; |
|||
params.add(sb_condition); |
|||
} |
|||
|
|||
// 1. Fetch questions list |
|||
String qSql = "SELECT orderby, english FROM Questions ORDER BY orderby"; |
|||
List<Map<String, Object>> questions = jdbcSpeedBrake.queryForList(qSql); |
|||
|
|||
// 2. Fetch speedbrake entries |
|||
String sql = "SELECT id, zone, ward, streetid, streetname, streettype, " |
|||
+ "roadcategory, roadtype, marktype, q1, q2, q3, q4, cby, cddate, " |
|||
+ "latitude, longitude, sb_condition, " |
|||
+ "CONCAT('" + fileBaseUrl + "/gccofficialapp/files', file) AS complaint_image_url " |
|||
+ "FROM speedbrake_list " |
|||
+ "WHERE isactive = 1 AND isdelete = 0 AND marktype = ? AND ward = ? AND streetname = ? " + where; |
|||
|
|||
List<Map<String, Object>> entries = jdbcSpeedBrake.queryForList(sql, params.toArray()); |
|||
|
|||
// 3. Merge Q&A into each entry |
|||
for (Map<String, Object> row : entries) { |
|||
List<Map<String, String>> qnaList = new ArrayList<>(); |
|||
|
|||
for (int i = 1; i <= 4; i++) { |
|||
Object qVal = row.get("q" + i); |
|||
if (qVal != null && i <= questions.size()) { |
|||
String questionText = String.valueOf(questions.get(i - 1).get("english")); |
|||
Map<String, String> qna = new HashMap<>(); |
|||
qna.put("q", questionText); |
|||
qna.put("ans", String.valueOf(qVal)); |
|||
qnaList.add(qna); |
|||
} |
|||
} |
|||
|
|||
row.put("questions", qnaList); |
|||
|
|||
// Remove q1–q4 from main record |
|||
row.remove("q1"); |
|||
row.remove("q2"); |
|||
row.remove("q3"); |
|||
row.remove("q4"); |
|||
} |
|||
return entries; |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.speedbrake.service; |
|||
@ -0,0 +1,135 @@ |
|||
package in.gov.chennaicorporation.mobileservice.viewCutter.controller; |
|||
|
|||
import java.util.List; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.util.MultiValueMap; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import in.gov.chennaicorporation.mobileservice.viewCutter.service.viewCutterActivity; |
|||
|
|||
|
|||
@RequestMapping("/gccofficialapp/api/viewcutter/") |
|||
@RestController("viewCutterRest") |
|||
public class viewCutterController { |
|||
@Autowired |
|||
private viewCutterActivity viewCutterActivity; |
|||
|
|||
@PostMapping(value="/saveViewCutterData") |
|||
public List<?> saveViewCutterData( |
|||
@RequestParam(value="loginId", required = true) String cby, |
|||
@RequestParam(value="latitude", required = true) String latitude, |
|||
@RequestParam(value="longitude", required = true) String longitude, |
|||
@RequestParam(value="zone", required = true) String zone, |
|||
@RequestParam(value="ward", required = true) String ward, |
|||
@RequestParam(value="streetname", required = false) String streetname, |
|||
@RequestParam(value="streetid", required = false) String streetid, |
|||
@RequestParam(value="remarks", required = true) String remarks, |
|||
|
|||
@RequestParam(value="file", required = false) MultipartFile file |
|||
){ |
|||
return viewCutterActivity.saveViewCutterData(cby, zone, ward, streetid, streetname, latitude, longitude, remarks, file); |
|||
} |
|||
|
|||
@GetMapping(value="/getViewCutterList") |
|||
public List<?> getViewCutterList(@RequestParam MultiValueMap<String, String> formData, |
|||
@RequestParam(value = "latitude", required = true) String latitude, |
|||
@RequestParam(value = "longitude", required = true) String longitude, |
|||
@RequestParam(value = "loginid", required = false) String loginid){ |
|||
return viewCutterActivity.getViewCutterList(formData, latitude, longitude, loginid); |
|||
} |
|||
|
|||
@GetMapping(value="/getViewCutterCompletedList") |
|||
public List<?> getViewCutterCompletedList(@RequestParam MultiValueMap<String, String> formData, |
|||
@RequestParam(value = "latitude", required = false) String latitude, |
|||
@RequestParam(value = "longitude", required = false) String longitude, |
|||
@RequestParam(value = "loginid", required = true) String loginid){ |
|||
return viewCutterActivity.getViewCutterCompletedList(formData, latitude, longitude, loginid); |
|||
} |
|||
|
|||
@GetMapping(value="/getStageList") // Old App |
|||
public List<?> getQuestionsList(@RequestParam(value="loginId", required = false) String cby){ |
|||
return viewCutterActivity.getStageList(); |
|||
} |
|||
|
|||
@GetMapping(value="/getViewCutterDetails") |
|||
public List<?> getViewCutterDetails( |
|||
@RequestParam MultiValueMap<String, String> formData, |
|||
@RequestParam(value="id", required = true) String id, |
|||
@RequestParam(value="latitude", required = true) String latitude, |
|||
@RequestParam(value="longitude", required = true) String longitude, |
|||
@RequestParam(value="loginid", required = false) String loginid, |
|||
@RequestParam(value="streetid", required = true) String streetid, |
|||
@RequestParam(value="undertaken_condition", required = false) String undertaken_condition){ |
|||
return viewCutterActivity.getViewCutterDetails(formData,id,loginid, latitude, longitude, undertaken_condition, streetid); |
|||
} |
|||
|
|||
@PostMapping(value="/saveStageActivityData") |
|||
public List<?> saveStageActivityData( |
|||
@RequestParam(value="id", required = true) String id, |
|||
@RequestParam(value="loginId", required = true) String cby, |
|||
@RequestParam(value="latitude", required = true) String latitude, |
|||
@RequestParam(value="longitude", required = true) String longitude, |
|||
@RequestParam(value="zone", required = true) String zone, |
|||
@RequestParam(value="ward", required = true) String ward, |
|||
@RequestParam(value="streetname", required = false) String streetname, |
|||
@RequestParam(value="streetid", required = false) String streetid, |
|||
@RequestParam(value="stageid", required = true) String stageid, |
|||
@RequestParam(value="remarks", required = true) String remarks, |
|||
@RequestParam(value="weightage", required = true) String weightage, |
|||
@RequestParam(value="undertaken", required = false) String undertaken, |
|||
|
|||
@RequestParam(value="stagefile", required = false) MultipartFile stage_file |
|||
){ |
|||
return viewCutterActivity.saveStageActivityData(id, cby, latitude, longitude, zone, ward, |
|||
streetname, streetid, stageid, remarks, weightage, stage_file, undertaken); |
|||
} |
|||
|
|||
// Reports |
|||
|
|||
@GetMapping(value="/getZoneList") |
|||
public List<?> getZoneList(){ |
|||
return viewCutterActivity.getZoneList(); |
|||
} |
|||
|
|||
@GetMapping(value="/getWardList") |
|||
public List<?> getWardList(@RequestParam(value="zone", required = true) String zone){ |
|||
return viewCutterActivity.getWardList(zone); |
|||
} |
|||
|
|||
@GetMapping(value="/getUndertakenList") |
|||
public List<?> getUndertakenList(@RequestParam(value="ward", required = true) String ward){ |
|||
return viewCutterActivity.getUndertakenList(ward); |
|||
} |
|||
|
|||
@GetMapping(value="/getNotUndertakenList") |
|||
public List<?> getNotUndertakenList(@RequestParam(value="ward", required = true) String ward){ |
|||
return viewCutterActivity.getNotUndertakenList(ward); |
|||
} |
|||
|
|||
@GetMapping(value="/getWorkPendingList") |
|||
public List<?> getWorkPendingList(@RequestParam(value="ward", required = true) String ward){ |
|||
return viewCutterActivity.getWorkPendingList(ward); |
|||
} |
|||
|
|||
@GetMapping(value="/getWorkCompletedList") |
|||
public List<?> getWorkCompletedList(@RequestParam(value="ward", required = true) String ward){ |
|||
return viewCutterActivity.getWorkCompletedList(ward); |
|||
} |
|||
|
|||
@GetMapping(value="/getReportViewCutterDetails") |
|||
public List<?> getReportViewCutterDetails( |
|||
@RequestParam MultiValueMap<String, String> formData, |
|||
@RequestParam(value="id", required = true) String id, |
|||
@RequestParam(value="latitude", required = true) String latitude, |
|||
@RequestParam(value="longitude", required = true) String longitude, |
|||
@RequestParam(value="loginid", required = false) String loginid, |
|||
@RequestParam(value="undertaken_condition", required = false) String undertaken_condition){ |
|||
return viewCutterActivity.getReportViewCutterDetails(formData,id,loginid, latitude, longitude, undertaken_condition); |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
package in.gov.chennaicorporation.mobileservice.viewCutter; |
|||
1037
mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/viewCutter/service/viewCutterActivity.java
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,108 @@ |
|||
<!DOCTYPE html> |
|||
<html xmlns:th="http://www.thymeleaf.org"> |
|||
<head> |
|||
<meta charset="UTF-8" /> |
|||
<style> |
|||
body { |
|||
font-family: Arial, sans-serif; |
|||
margin: 40px; |
|||
line-height: 1.6; |
|||
} |
|||
.header { |
|||
text-align: center; |
|||
} |
|||
.header img { |
|||
width: 100px; |
|||
height: auto; |
|||
} |
|||
.title { |
|||
text-align: center; |
|||
font-size: 20px; |
|||
font-weight: bold; |
|||
margin-top: 10px; |
|||
} |
|||
.subtitle { |
|||
text-align: center; |
|||
font-size: 16px; |
|||
font-weight: bold; |
|||
margin-bottom: 30px; |
|||
} |
|||
.date-container { |
|||
display: flex; |
|||
justify-content: flex-end; |
|||
margin-bottom: 20px; |
|||
} |
|||
.violations { |
|||
margin-left: 20px; |
|||
} |
|||
.footer { |
|||
/*position: absolute;*/ |
|||
bottom: 40px; |
|||
right: 40px; |
|||
text-align: left; |
|||
} |
|||
</style> |
|||
</head> |
|||
<body> |
|||
|
|||
<!-- GCC Logo and Header --> |
|||
<div class="header"> |
|||
<img src="https://chennaicorporation.gov.in/gcc/images/270-2709575_greater-chennai-corporation-dr-greater-chennai-corporation-logo.png" alt="GCC Logo" width="40px" /> |
|||
<div style="font-size: 18px; font-weight: bold;">Greater Chennai Corporation</div> |
|||
<div style="font-size: 16px;">Chennai</div> |
|||
</div> |
|||
|
|||
<!-- Notice Title --> |
|||
<div class="title">NOTICE</div> |
|||
<div class="subtitle">UNDER CLEAN AND SAFE CONSTRUCTION GUIDELINES 2025</div> |
|||
|
|||
<!-- Date aligned to right --> |
|||
<div class="date-container"> |
|||
Date: <span th:text="${date}">dd/mm/yyyy</span> |
|||
</div> |
|||
|
|||
<!-- Notice Body --> |
|||
<p> |
|||
Be under the notice that during a recent inspection conducted by the engineers, Greater Chennai Corporation (GCC), |
|||
your construction site located at <u><span th:utext="' ' + ${siteLocation} + ' '"></span></u> was found to be in |
|||
violation of the "Clean and Safe Construction Guidelines 2025". |
|||
</p> |
|||
|
|||
<p>The following violation(s) have been observed at your site:</p> |
|||
<ul class="violations"> |
|||
<li th:each="v : ${violations}" th:text="${v.message}"></li> |
|||
</ul> |
|||
|
|||
<p> |
|||
These lapses fall under the category of |
|||
<strong><span th:text="${violationLevel}"></span></strong> Significance Violations as per GCC norms. |
|||
As per Clause (<span th:text="${#strings.arrayJoin(clause, ', ')}"></span>) of the guidelines, you are hereby directed to: |
|||
</p> |
|||
|
|||
<ol> |
|||
<li>Rectify the violations within 15 days from the date of receipt of this notice.</li> |
|||
<li>Submit photographic/video evidence and compliance report to this office upon rectification.</li> |
|||
</ol> |
|||
|
|||
<p>Failure to comply within 15 days from the date of receipt of this notice shall attract:</p> |
|||
<ol> |
|||
<li> |
|||
Penalty of Rs <u><span th:text="' ' + ${fineAmount} + ' '"></span></u> |
|||
(<span th:text="' ' + ${fineAmountWords} + ' '"></span>) |
|||
</li> |
|||
<li> |
|||
Failing to comply within 7 Days of imposing of fine may result in a |
|||
<strong>“Stop Work Notice”</strong> and construction activity at your site will be halted. |
|||
</li> |
|||
</ol> |
|||
|
|||
<!-- Footer Signature --> |
|||
<div class="footer"> |
|||
<p> |
|||
AE/JE – DVS: <span th:text="${engineerName}">_____</span><br /> |
|||
Zone <span th:text="${zone}">_____</span>, GCC |
|||
</p> |
|||
</div> |
|||
|
|||
</body> |
|||
</html> |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue