Browse Source

getDrainReport Query changed

master
KaNi-04 2 months ago
parent
commit
20bdcd7826
  1. 250
      src/main/java/in/gov/chennaicorporation/mobileservice/manhole/service/ManHoleActivity.java
  2. 16
      src/main/java/in/gov/chennaicorporation/mobileservice/penalty/controller/APIPenaltyControllerPOS.java

250
src/main/java/in/gov/chennaicorporation/mobileservice/manhole/service/ManHoleActivity.java

@ -59,7 +59,6 @@ public class ManHoleActivity {
this.fileBaseUrl = environment.getProperty("fileBaseUrl");
}
public static String generateRandomString() {
StringBuilder result = new StringBuilder(STRING_LENGTH);
for (int i = 0; i < STRING_LENGTH; i++) {
@ -135,15 +134,13 @@ public class ManHoleActivity {
// Get the bytes of the file
byte[] bytes = file.getBytes();
if(filetype.equalsIgnoreCase("image"))
{
if (filetype.equalsIgnoreCase("image")) {
// 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);
}
else {
} else {
// Write the bytes to the file
Files.write(path, bytes);
}
@ -185,22 +182,23 @@ public class ManHoleActivity {
}
/*
public List<Map<String, Object>> getDrainList(String loginid) {
String ward = getWardByLoginId(loginid,"ae");
String sql = "SELECT *, "
+ " CONCAT('"+fileBaseUrl+"/gccofficialapp/files', `file`) AS file_url "
+ "FROM `drain_master` WHERE `ward`= ? AND isactive = 1 AND isdelete = 0 ";
List<Map<String, Object>> result = jdbcManHoleTemplate.queryForList(sql, ward);
Map<String, Object> response = new HashMap<>();
response.put("status", "Success");
response.put("message", "Drain List.");
response.put("data", result);
return Collections.singletonList(response);
}
* public List<Map<String, Object>> getDrainList(String loginid) {
*
* String ward = getWardByLoginId(loginid,"ae");
*
* String sql = "SELECT *, "
* + " CONCAT('"+fileBaseUrl+"/gccofficialapp/files', `file`) AS file_url "
* + "FROM `drain_master` WHERE `ward`= ? AND isactive = 1 AND isdelete = 0 ";
* List<Map<String, Object>> result = jdbcManHoleTemplate.queryForList(sql,
* ward);
*
* Map<String, Object> response = new HashMap<>();
* response.put("status", "Success");
* response.put("message", "Drain List.");
* response.put("data", result);
*
* return Collections.singletonList(response);
* }
*/
public List<Map<String, Object>> getDrainList(String loginid) {
@ -284,8 +282,7 @@ public class ManHoleActivity {
Integer count = jdbcManHoleTemplate.queryForObject(
checkSql,
Integer.class,
new Object[]{street_id, drain_side}
);
new Object[] { street_id, drain_side });
return (count != null && count > 0) ? "true" : "false";
@ -309,8 +306,7 @@ public class ManHoleActivity {
String latitude,
String longitude,
String inby,
MultipartFile file
) {
MultipartFile file) {
String action = "New Drain";
@ -385,48 +381,52 @@ public class ManHoleActivity {
}
/*
public List<Map<String, Object>> getManHoleList(String loginid, String swdid) {
String sql = "SELECT * FROM `manhole_master` WHERE `swdid`= ?";
List<Map<String, Object>> result = jdbcManHoleTemplate.queryForList(sql, swdid);
Map<String, Object> response = new HashMap<>();
response.put("status", "Success");
response.put("message", "ManHole List.");
response.put("data", result);
return Collections.singletonList(response);
}
public List<Map<String, Object>> getManHoleBeforeStatus(String manhole_id) {
String sql = "SELECT *,"
+ " CONCAT('"+fileBaseUrl+"/gccofficialapp/files', `file`) AS file_url "
+ " FROM `before_activity` WHERE `manhole_id`= ?";
List<Map<String, Object>> result = jdbcManHoleTemplate.queryForList(sql, manhole_id);
Map<String, Object> response = new HashMap<>();
response.put("status", "Success");
response.put("message", "ManHole before activity list.");
response.put("data", result);
return Collections.singletonList(response);
}
public List<Map<String, Object>> getManHoleAfterStatus(String manhole_id) {
String sql = "SELECT *,"
+ " CONCAT('"+fileBaseUrl+"/gccofficialapp/files', `file`) AS file_url "
+ " FROM `after_activity` WHERE `manhole_id`= ?";
List<Map<String, Object>> result = jdbcManHoleTemplate.queryForList(sql, manhole_id);
Map<String, Object> response = new HashMap<>();
response.put("status", "Success");
response.put("message", "ManHole before activity list.");
response.put("data", result);
return Collections.singletonList(response);
}
* public List<Map<String, Object>> getManHoleList(String loginid, String swdid)
* {
*
* String sql = "SELECT * FROM `manhole_master` WHERE `swdid`= ?";
* List<Map<String, Object>> result = jdbcManHoleTemplate.queryForList(sql,
* swdid);
*
* Map<String, Object> response = new HashMap<>();
* response.put("status", "Success");
* response.put("message", "ManHole List.");
* response.put("data", result);
*
* return Collections.singletonList(response);
* }
*
* public List<Map<String, Object>> getManHoleBeforeStatus(String manhole_id) {
*
* String sql = "SELECT *,"
* + " CONCAT('"+fileBaseUrl+"/gccofficialapp/files', `file`) AS file_url "
* + " FROM `before_activity` WHERE `manhole_id`= ?";
* List<Map<String, Object>> result = jdbcManHoleTemplate.queryForList(sql,
* manhole_id);
*
* Map<String, Object> response = new HashMap<>();
* response.put("status", "Success");
* response.put("message", "ManHole before activity list.");
* response.put("data", result);
*
* return Collections.singletonList(response);
* }
*
* public List<Map<String, Object>> getManHoleAfterStatus(String manhole_id) {
*
* String sql = "SELECT *,"
* + " CONCAT('"+fileBaseUrl+"/gccofficialapp/files', `file`) AS file_url "
* + " FROM `after_activity` WHERE `manhole_id`= ?";
* List<Map<String, Object>> result = jdbcManHoleTemplate.queryForList(sql,
* manhole_id);
*
* Map<String, Object> response = new HashMap<>();
* response.put("status", "Success");
* response.put("message", "ManHole before activity list.");
* response.put("data", result);
*
* return Collections.singletonList(response);
* }
*/
@Transactional
@ -448,18 +448,17 @@ public class ManHoleActivity {
Integer count = jdbcManHoleTemplate.queryForObject(
checkSql,
Integer.class,
latitude, longitude, latitude
);
latitude, longitude, latitude);
/*
String checkSqlstr = "SELECT COUNT(*) FROM manhole_master " +
"WHERE isactive = 1 AND isdelete = 0 " + // fixed delete flag
"AND (6371008.8 * ACOS(" +
"COS(RADIANS("+latitude+")) * COS(RADIANS(latitude)) * " +
"COS(RADIANS(longitude) - RADIANS("+longitude+")) + " +
"SIN(RADIANS("+latitude+")) * SIN(RADIANS(latitude))" +
")) < 0.5";
System.out.println("Duplicate check sql:"+ checkSqlstr);
* String checkSqlstr = "SELECT COUNT(*) FROM manhole_master " +
* "WHERE isactive = 1 AND isdelete = 0 " + // fixed delete flag
* "AND (6371008.8 * ACOS(" +
* "COS(RADIANS("+latitude+")) * COS(RADIANS(latitude)) * " +
* "COS(RADIANS(longitude) - RADIANS("+longitude+")) + " +
* "SIN(RADIANS("+latitude+")) * SIN(RADIANS(latitude))" +
* ")) < 0.5";
*
* System.out.println("Duplicate check sql:"+ checkSqlstr);
*/
return (count != null && count > 0);
@ -479,8 +478,7 @@ public class ManHoleActivity {
checkSql,
Integer.class,
drain_id,
street_id
);
street_id);
return (count != null && count == 1);
@ -498,8 +496,7 @@ public class ManHoleActivity {
String street_id,
String latitude,
String longitude,
String inby
) {
String inby) {
String action = "Save";
Map<String, Object> response = new HashMap<>();
@ -600,7 +597,8 @@ public class ManHoleActivity {
}
// 4. Overall manhole status
String overallStatus = (!beforeActivities.isEmpty() && !afterActivities.isEmpty()) ? "Completed" : "Pending";
String overallStatus = (!beforeActivities.isEmpty() && !afterActivities.isEmpty()) ? "Completed"
: "Pending";
manholeResponse.put("status", overallStatus);
manholeResponse.put("before", beforeData);
manholeResponse.put("after", afterData);
@ -633,8 +631,7 @@ public class ManHoleActivity {
Integer count = jdbcManHoleTemplate.queryForObject(
checkSql,
Integer.class,
new Object[]{manhole_id, latitude, longitude, latitude}
);
new Object[] { manhole_id, latitude, longitude, latitude });
return (count != null && count > 0) ? "true" : "false";
@ -658,8 +655,7 @@ public class ManHoleActivity {
String action,
String beforeActivityId,
String clean_type,
String case_id
) {
String case_id) {
String filetxt = manhole_id + "_" + drain_id;
@ -734,8 +730,7 @@ public class ManHoleActivity {
}
public List<Map<String, Object>> getZoneReport() {
String sql =
"SELECT "
String sql = "SELECT "
+ " z.zone,"
+ " COUNT(t.drain_id) AS total_drain,"
+ " SUM(CASE WHEN t.total_manhole = t.completed_manhole THEN 1 ELSE 0 END) AS total_drain_completed,"
@ -781,8 +776,7 @@ public class ManHoleActivity {
}
public List<Map<String, Object>> getWardReport(String zone) {
String sql =
"SELECT "
String sql = "SELECT "
+ " t.zone,"
+ " t.ward,"
+ " COUNT(t.drain_id) AS total_drain,"
@ -814,31 +808,55 @@ public class ManHoleActivity {
}
public List<Map<String, Object>> getDrainReport(String ward) {
String sql =
"SELECT "
+ " t.drain_name AS drain, "
+ " t.total_manhole AS total_manhole, "
+ " t.completed_manhole AS manhole_completed, "
+ " (t.total_manhole - t.completed_manhole) AS manhole_pending, "
+ " ROUND(t.completed_manhole * 100.0 / t.total_manhole, 2) AS completed_percentage, "
+ " ROUND((t.total_manhole - t.completed_manhole) * 100.0 / t.total_manhole, 2) AS pending_percentage "
+ "FROM ( "
+ " SELECT "
+ " CONCAT(d.street_name, '-', d.drain_side) AS drain_name, "
+ " d.drain_id, "
+ " SUM(d.manhole_count) AS total_manhole, "
+ " COUNT(DISTINCT CASE "
+ " WHEN ba.activity_id IS NOT NULL AND aa.activity_id IS NOT NULL THEN m.manhole_id "
+ " END) AS completed_manhole "
+ " FROM drain_master d "
+ " LEFT JOIN manhole_master m ON d.drain_id = m.drain_id AND m.isactive=1 AND m.isdelete=0 "
+ " LEFT JOIN before_activity ba ON m.manhole_id = ba.manhole_id AND ba.isactive=1 AND ba.isdelete=0 "
+ " LEFT JOIN after_activity aa ON m.manhole_id = aa.manhole_id AND aa.isactive=1 AND aa.isdelete=0 "
+ " WHERE d.isactive = 1 AND d.isdelete = 0 "
+ " AND d.ward = ? "
+ " GROUP BY drain_name, d.drain_id "
+ ") t "
+ "ORDER BY t.drain_name";
String sql = "SELECT " +
" t.drain_name AS drain, " +
" t.total_manhole, " +
" t.completed_manhole AS manhole_completed, " +
" (t.total_manhole - t.completed_manhole) AS manhole_pending, " +
" ROUND( " +
" t.completed_manhole * 100.0 / NULLIF(t.total_manhole, 0), " +
" 2 " +
" ) AS completed_percentage, " +
" ROUND( " +
" (t.total_manhole - t.completed_manhole) * 100.0 " +
" / NULLIF(t.total_manhole, 0), " +
" 2 " +
" ) AS pending_percentage " +
"FROM ( " +
" SELECT " +
" CONCAT(d.street_name, '-', d.drain_side) AS drain_name, " +
" d.drain_id, " +
" MAX(d.manhole_count) AS total_manhole, " +
" COUNT( " +
" DISTINCT CASE " +
" WHEN ba.activity_id IS NOT NULL " +
" AND aa.activity_id IS NOT NULL " +
" THEN m.manhole_id " +
" END " +
" ) AS completed_manhole " +
" FROM drain_master d " +
" LEFT JOIN manhole_master m " +
" ON d.drain_id = m.drain_id " +
" AND m.isactive = 1 " +
" AND m.isdelete = 0 " +
" LEFT JOIN before_activity ba " +
" ON m.manhole_id = ba.manhole_id " +
" AND ba.isactive = 1 " +
" AND ba.isdelete = 0 " +
" LEFT JOIN after_activity aa " +
" ON m.manhole_id = aa.manhole_id " +
" AND aa.isactive = 1 " +
" AND aa.isdelete = 0 " +
" WHERE " +
" d.isactive = 1 " +
" AND d.isdelete = 0 " +
" AND d.ward = ? " +
" GROUP BY " +
" d.street_name, " +
" d.drain_side, " +
" d.drain_id " +
") t " +
"ORDER BY t.drain_name;";
return jdbcManHoleTemplate.queryForList(sql, ward);
}

16
src/main/java/in/gov/chennaicorporation/mobileservice/penalty/controller/APIPenaltyControllerPOS.java

@ -23,8 +23,7 @@ public class APIPenaltyControllerPOS {
@GetMapping(value = "/getPenaltyDepartment")
public List<Map<String, Object>> getPenaltyDepartment(
@RequestParam(value = "loginId", required = false) String loginId
) {
@RequestParam(value = "loginId", required = false) String loginId) {
return penaltyServicePOS.getPenaltyDepartment();
}
@ -39,8 +38,7 @@ public class APIPenaltyControllerPOS {
public List<Map<String, Object>> getPenaltyAmount(
@RequestParam(value = "categoryId", required = false) String categoryId,
@RequestParam(value = "ton", required = false) String ton,
@RequestParam(value = "loginId", required = false) String loginId
) {
@RequestParam(value = "loginId", required = false) String loginId) {
return penaltyServicePOS.getPenaltyAmount(categoryId, ton);
}
@ -70,8 +68,7 @@ public class APIPenaltyControllerPOS {
@RequestParam(value = "tid", required = false) String tid,
@RequestParam(value = "mid", required = false) String mid,
@RequestParam(value = "serialNumber", required = false) String serialNumber,
@RequestParam(value = "file", required = false) MultipartFile file
) {
@RequestParam(value = "file", required = false) MultipartFile file) {
return penaltyServicePOS.generateChallanPOS(formData, categoryId, latitude, longitude, zone, ward,
loginId, violatorName, violatorPhone, violatorCompany, ton, amount, tid, mid, serialNumber, file);
}
@ -99,8 +96,9 @@ public class APIPenaltyControllerPOS {
@RequestParam(value = "extraInfo3", required = false) String extraInfo3,
@RequestParam(value = "txnMode", required = false) String txnMode,
@RequestParam(value = "txnId", required = false) String txnId,
@RequestParam(value = "file", required = false) MultipartFile file
) {
return penaltyServicePOS.storeOfflineTransaction(formData, transactionResponseStatus, bankName, transactionAmount, txnDate, txnTime,branchname,extraInfo,extraInfo2,extraInfo3,txnMode,txnId,file);
@RequestParam(value = "file", required = false) MultipartFile file) {
return penaltyServicePOS.storeOfflineTransaction(formData, transactionResponseStatus, bankName,
transactionAmount, txnDate, txnTime, branchname, extraInfo, extraInfo2, extraInfo3, txnMode, txnId,
file);
}
}
Loading…
Cancel
Save