Browse Source

Penalty Module update

main
Balaji 2 years ago
parent
commit
8b23aad328
  1. 33
      mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/configuration/DataSourceConfig.java
  2. 11
      mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/controller/APIOfficialController.java
  3. 7
      mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/controller/APIActivityController.java
  4. 57
      mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/service/Activity.java
  5. 5
      mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/service/DateTimeUtil.java
  6. 74
      mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/controller/APINULMOfficerController.java
  7. 1
      mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/controller/package-info.java
  8. 1
      mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/package-info.java
  9. 350
      mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/service/NULMOfficerActivity.java
  10. 1
      mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/service/package-info.java
  11. 97
      mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/penalty/controller/APIPenaltyController.java
  12. 601
      mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/penalty/service/PenaltyService.java
  13. 85
      mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/service/OfficialAPIService.java
  14. 1
      mobileservice/src/main/resources/application.properties

33
mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/configuration/DataSourceConfig.java

@ -20,8 +20,14 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableTransactionManagement @EnableTransactionManagement
public class DataSourceConfig { public class DataSourceConfig {
//private static String dbpassword = "gccroot";
private static String dbpassword = "";
private static String host = "localhost:3306";
private static String dbpassword = "gccroot";
//private static String dbpassword = "";
// AWS
//private static String host = "gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306";
//private static String dbpassword = "gcc-facial";
//////////////////////////////(For GCC APP) //////////////////////// //////////////////////////////(For GCC APP) ////////////////////////
@Configuration @Configuration
@ -37,7 +43,7 @@ public class DataSourceConfig {
public DataSource mysqlAppDataSource() { public DataSource mysqlAppDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource(); DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/gcc_apps");
dataSource.setUrl("jdbc:mysql://"+host+"/gcc_apps");
dataSource.setUsername("root"); dataSource.setUsername("root");
dataSource.setPassword(dbpassword); dataSource.setPassword(dbpassword);
return dataSource; return dataSource;
@ -70,7 +76,7 @@ public class DataSourceConfig {
public DataSource mysqlActivityDataSource() { public DataSource mysqlActivityDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource(); DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/gcc_activity");
dataSource.setUrl("jdbc:mysql://"+host+"/gcc_activity");
dataSource.setUsername("root"); dataSource.setUsername("root");
dataSource.setPassword(dbpassword); dataSource.setPassword(dbpassword);
return dataSource; return dataSource;
@ -81,7 +87,7 @@ public class DataSourceConfig {
public DataSource mysqlPenaltyDataSource() { public DataSource mysqlPenaltyDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource(); DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/gcc_penalty");
dataSource.setUrl("jdbc:mysql://"+host+"/gcc_penalty");
dataSource.setUsername("root"); dataSource.setUsername("root");
dataSource.setPassword(dbpassword); dataSource.setPassword(dbpassword);
return dataSource; return dataSource;
@ -92,7 +98,7 @@ public class DataSourceConfig {
public DataSource mysqlPGRMasterDataSource() { public DataSource mysqlPGRMasterDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource(); DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/erp_pgr");
dataSource.setUrl("jdbc:mysql://"+host+"/erp_pgr");
dataSource.setUsername("root"); dataSource.setUsername("root");
dataSource.setPassword(dbpassword); dataSource.setPassword(dbpassword);
return dataSource; return dataSource;
@ -103,7 +109,7 @@ public class DataSourceConfig {
public DataSource mysqlGCCUserDataSource() { public DataSource mysqlGCCUserDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource(); DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/gcc_users");
dataSource.setUrl("jdbc:mysql://"+host+"/gcc_users");
dataSource.setUsername("root"); dataSource.setUsername("root");
dataSource.setPassword(dbpassword); dataSource.setPassword(dbpassword);
return dataSource; return dataSource;
@ -115,7 +121,18 @@ public class DataSourceConfig {
public DataSource mysqlGccSOSDataSource() { public DataSource mysqlGccSOSDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource(); DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/gcc_sos");
dataSource.setUrl("jdbc:mysql://"+host+"/gcc_sos");
dataSource.setUsername("root");
dataSource.setPassword(dbpassword);
return dataSource;
}
//////////////////////////////(For NULM Staff) ////////////////////////
@Bean(name = "mysqlNulmDataSource")
public DataSource mysqlNulmDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://"+host+"/gcc_nulm");
dataSource.setUsername("root"); dataSource.setUsername("root");
dataSource.setPassword(dbpassword); dataSource.setPassword(dbpassword);
return dataSource; return dataSource;

11
mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/controller/APIOfficialController.java

@ -83,9 +83,16 @@ public class APIOfficialController {
} }
// For Menu //////////////////////////////////////// // For Menu ////////////////////////////////////////
@GetMapping(value="/getMainMenu")
public List getMainMenu(@RequestParam String loginId){
return officialAPIService.getMainMenu(loginId);
}
@GetMapping(value="/getMenu") @GetMapping(value="/getMenu")
public List getMenu(@RequestParam String loginId){
return officialAPIService.getMenu(loginId);
public List getMenu(
@RequestParam String loginId,
@RequestParam(value = "departmentId", required = false) String departmentId){
return officialAPIService.getMenu(loginId,departmentId);
} }
@GetMapping(value="/getSubMenu") @GetMapping(value="/getSubMenu")

7
mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/controller/APIActivityController.java

@ -21,8 +21,8 @@ public class APIActivityController {
private Activity activity; private Activity activity;
@GetMapping(value="/asset/getActivityCategory") @GetMapping(value="/asset/getActivityCategory")
public List<?> getActivityCategory(){
return activity.getActivityCategory();
public List<?> getActivityCategory(@RequestParam(value = "departmentId", required = false) String departmentId){
return activity.getActivityCategory(departmentId);
} }
@PostMapping(value="/asset/save") @PostMapping(value="/asset/save")
@ -35,9 +35,10 @@ public class APIActivityController {
@RequestParam("streeId") String streeId, @RequestParam("streeId") String streeId,
@RequestParam("streetName") String streetName, @RequestParam("streetName") String streetName,
@RequestParam("loginId") String loginId, @RequestParam("loginId") String loginId,
@RequestParam(value = "name", required = false) String name,
@RequestParam(value = "file", required = false) MultipartFile file @RequestParam(value = "file", required = false) MultipartFile file
) { ) {
return activity.saveAsset(formData, assetTypeId, latitude, longitude, zone, ward, streeId, streetName, loginId, file);
return activity.saveAsset(formData, assetTypeId, latitude, longitude, zone, ward, streeId, streetName, loginId, name, file);
} }
@GetMapping(value="/asset/loadAssetlistbyStreetId") @GetMapping(value="/asset/loadAssetlistbyStreetId")

57
mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/service/Activity.java

@ -14,6 +14,7 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -80,8 +81,13 @@ public class Activity {
} }
@Transactional @Transactional
public List<Map<String, Object>> getActivityCategory(){
String sqlQuery = "SELECT * FROM `activity_category` WHERE (`isactive`=1 AND `isdelete`=0) ORDER BY `display_order` ASC";
public List<Map<String, Object>> getActivityCategory(String departmentId){
String sqlQuery = "SELECT * FROM `activity_category` WHERE (`isactive`=1 AND `isdelete`=0) ";
if(departmentId!=null && !departmentId.isEmpty() && !departmentId.isBlank()) {
sqlQuery= sqlQuery +" AND `mappingid`='"+departmentId+"'";
}
sqlQuery = sqlQuery + " ORDER BY `display_order`, `name` ASC";
List<Map<String, Object>> result = jdbcActivityTemplate.queryForList(sqlQuery); List<Map<String, Object>> result = jdbcActivityTemplate.queryForList(sqlQuery);
return result; return result;
@ -98,6 +104,7 @@ public class Activity {
String streeId, String streeId,
String streetName, String streetName,
String loginId, String loginId,
String name,
MultipartFile file) { MultipartFile file) {
List<Map<String, Object>> result=null; List<Map<String, Object>> result=null;
Map<String, Object> response = new HashMap<>(); Map<String, Object> response = new HashMap<>();
@ -105,8 +112,8 @@ public class Activity {
String image = assetFileUpload(assetType,file); String image = assetFileUpload(assetType,file);
String sqlQuery = "INSERT INTO `asset_list`(`category_id`, `image`, `latitude`, `longitude`, `zone`, `ward`, `streetid`, `streetname`, `cby`) "
+ "VALUES (?,?,?,?,?,?,?,?,?)";
String sqlQuery = "INSERT INTO `asset_list`(`category_id`, `image`, `latitude`, `longitude`, `zone`, `ward`, `streetid`, `streetname`, `cby`, `name`) "
+ "VALUES (?,?,?,?,?,?,?,?,?,?)";
KeyHolder keyHolder = new GeneratedKeyHolder(); KeyHolder keyHolder = new GeneratedKeyHolder();
@ -124,6 +131,7 @@ public class Activity {
ps.setString(7, streeId); ps.setString(7, streeId);
ps.setString(8, streetName); ps.setString(8, streetName);
ps.setString(9, loginId); ps.setString(9, loginId);
ps.setString(10, name);
return ps; return ps;
} }
}, keyHolder); }, keyHolder);
@ -905,21 +913,34 @@ public String assetFileUpload(String catId, MultipartFile file) {
*/ */
// Function to convert date string from dd-MM-yyyy to yyyy-MM-dd // Function to convert date string from dd-MM-yyyy to yyyy-MM-dd
public static String convertDateFormat(String inputDate, int add) {
// Define the input and output date formats
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// Parse the input date string to LocalDate
LocalDate date = LocalDate.parse(inputDate, inputFormatter);
if(add>0) {
// Add one day to the date
date = date.plusDays(1);
}
public static String convertDateFormat(String inputDate, int add) {
// Check if the inputDate is not null or blank
if (inputDate != null && !inputDate.isBlank()) {
try {
// Define the input and output date formats
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// Parse the input date string to LocalDate
LocalDate date = LocalDate.parse(inputDate, inputFormatter);
// Add the specified number of days to the date if 'add' is greater than 0
if (add > 0) {
date = date.plusDays(add);
}
// Format the date to the new format
return date.format(outputFormatter);
}
// Format the date to the new format
return date.format(outputFormatter);
} catch (DateTimeParseException e) {
// Handle the case where the input date is invalid
System.out.println("Invalid date format: " + inputDate);
return "";
}
} else {
return "";
}
}
public String getApiResponse() { public String getApiResponse() {
//String url="https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=9176617754&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Welcome+to+GCC%21+%0A%0AYour+OTP+for+GCC+Community+Centre+is+36837+."; //String url="https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=9176617754&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Welcome+to+GCC%21+%0A%0AYour+OTP+for+GCC+Community+Centre+is+36837+.";

5
mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/service/DateTimeUtil.java

@ -26,4 +26,9 @@ public class DateTimeUtil {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
return now.format(formatter); return now.format(formatter);
} }
public static String getCurrentDateTimeMysql() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
return now.format(formatter);
}
} }

74
mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/controller/APINULMOfficerController.java

@ -0,0 +1,74 @@
package in.gov.chennaicorporation.mobileservice.nulm.controller;
import java.util.List;
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.nulm.service.NULMOfficerActivity;
@RequestMapping("/gccofficialapp/api/nulm/officer/")
@RestController("gccofficialappOffcierNULMRest")
public class APINULMOfficerController {
@Autowired
private NULMOfficerActivity nulmOfficerActivity;
@GetMapping(value="/getAllRequest") // Template
public List<?> getAllRequest(
@RequestParam(value="zone", required = false) String zone,
@RequestParam(value="ward", required = false) String ward,
@RequestParam(value="streetid", required = false) String streetid,
@RequestParam(value="fromdate", required = false) String fromdate,
@RequestParam(value="todate", required = false) String todate,
@RequestParam(value="request_type", required = false) String request_type,
@RequestParam(value="loginId", required = false) String loginId,
@RequestParam(value="status", required = false) String status
){
return nulmOfficerActivity.getAllRequest(request_type, zone, ward, streetid, fromdate, todate, loginId,status);
}
@GetMapping(value="/getStaffListToRegister") // Template
public List<?> getStaffListToRegister(
@RequestParam(value="reporterId", required = false) String reporterId
){
return nulmOfficerActivity.getStaffListToRegister(reporterId);
}
@GetMapping(value="/updateStaffFaceRegister") // Template
public List<?> updateStaffFaceRegister(
@RequestParam(value="reporterId", required = false) String reporterId,
@RequestParam(value="enrollId", required = false) String enrollId,
@RequestParam(value="status", required = false) String status
){
return nulmOfficerActivity.updateStaffFaceRegister(reporterId, enrollId, status);
}
@GetMapping(value="/getStaffListForAttendance") // Template
public List<?> getStaffListForAttendance(
@RequestParam(value="reporterId", required = false) String reporterId
){
return nulmOfficerActivity.getStaffListForAttendance(reporterId);
}
@GetMapping(value="/markAttendance") // Template
public List<?> markAttendance(
@RequestParam(value="reporterId", required = false) String reporterId,
@RequestParam(value="enrollId", required = false) String enrollId,
@RequestParam(value="action", required = false) String status,
@RequestParam(value="photourl", required = false) String photourl
){
return nulmOfficerActivity.markAttendance(reporterId, enrollId, status, photourl);
}
@GetMapping(value="/getStaffAttendanceListByDate") // Template
public List<?> getStaffAttendanceListByDate(
@RequestParam(value="reporterId", required = false) String reporterId,
@RequestParam(value="specificDate", required = false) String specificDate
){
return nulmOfficerActivity.getStaffAttendanceListByDate(reporterId,specificDate);
}
}

1
mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/controller/package-info.java

@ -0,0 +1 @@
package in.gov.chennaicorporation.mobileservice.nulm.controller;

1
mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/package-info.java

@ -0,0 +1 @@
package in.gov.chennaicorporation.mobileservice.nulm;

350
mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/service/NULMOfficerActivity.java

@ -0,0 +1,350 @@
package in.gov.chennaicorporation.mobileservice.nulm.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.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.web.multipart.MultipartFile;
import in.gov.chennaicorporation.mobileservice.gccactivity.service.DateTimeUtil;
@Service
public class NULMOfficerActivity {
private JdbcTemplate jdbcNULMTemplate;
private final Environment environment;
@Autowired
public void setDataSource(@Qualifier("mysqlNulmDataSource") DataSource sosDataSource) {
this.jdbcNULMTemplate = new JdbcTemplate(sosDataSource);
}
@Autowired
public NULMOfficerActivity(Environment environment) {
this.environment = environment;
}
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 List<Map<String, Object>> Template(
String loginId,
String request_type,
String status,
String zone,
String ward
){
String sqlQuery = "SELECT * FROM `rescue` WHERE `isactive`=1 ";
System.out.println(sqlQuery);
List<Map<String, Object>> result = jdbcNULMTemplate.queryForList(sqlQuery);
Map<String, Object> response = new HashMap<>();
response.put("status", "Success");
response.put("message", "Request List");
response.put("ward", result);
return Collections.singletonList(response);
}
public List<Map<String, Object>> getAllRequest(
String request_type,
String zone,
String ward,
String streetid,
String fromdate,
String todate,
String loginId,
String status){
String sqlQuery = "SELECT * FROM `rescue` WHERE `isactive`=1 ";
System.out.println(sqlQuery);
List<Map<String, Object>> result = jdbcNULMTemplate.queryForList(sqlQuery);
Map<String, Object> response = new HashMap<>();
response.put("status", "Success");
response.put("message", "Request List");
response.put("ward", result);
return Collections.singletonList(response);
}
public List<Map<String, Object>> getStaffListToRegister(
String reporterId
){
String sqlQuery = "SELECT * FROM `enrollment_table` WHERE (`isactive`=1 AND `appointed`=1 AND `facial_attendance`=0)"
+ " AND `incharge_id`='"+reporterId+"'";
System.out.println(sqlQuery);
List<Map<String, Object>> result = jdbcNULMTemplate.queryForList(sqlQuery);
Map<String, Object> response = new HashMap<>();
response.put("status", "Success");
response.put("message", "Request List");
response.put("Data", result);
return Collections.singletonList(response);
}
public List<Map<String, Object>> updateStaffFaceRegister(
String reporterId,
String enrollId,
String status
){
Map<String, Object> response = new HashMap<>();
if((reporterId!=null && !reporterId.isBlank() && !reporterId.isEmpty())
&& (enrollId!=null && !enrollId.isEmpty() && !enrollId.isBlank()))
{
String sqlQuery = "UPDATE `enrollment_table` SET `facial_attendance`=1 WHERE `enrollment_id`='"+enrollId+"'"
+ " AND `incharge_id`='"+reporterId+"'";
System.out.println(sqlQuery);
Integer updateResult=jdbcNULMTemplate.update(sqlQuery);
sqlQuery = "SELECT * FROM `enrollment_table` WHERE (`isactive`=1 AND `appointed`=1 AND `facial_attendance`=1)"
+ " AND `enrollment_id`='"+enrollId+"'";
List<Map<String, Object>> result = jdbcNULMTemplate.queryForList(sqlQuery);
response.put("status", "Success");
response.put("message", "Facial register successfully!");
response.put("Data", result);
}
else {
response.put("status", "Failed");
response.put("message", "Invalid Data");
}
return Collections.singletonList(response);
}
public List<Map<String, Object>> getStaffListForAttendance(
String reporterId
){
String sqlQuery = "SELECT e.*, "
+ " IFNULL(DATE_FORMAT(a.indatetime, '%d-%m-%Y %l:%i %p'), '') AS indatetime, "
+ " IFNULL(DATE_FORMAT(a.outdatetime, '%d-%m-%Y %l:%i %p'), '') AS outdatetime, "
+ " a.inby, "
+ " a.outby, "
+ " a.inphoto, "
+ " a.outphoto "
+ "FROM enrollment_table e "
+ "LEFT JOIN attendance a ON e.enrollment_id = a.enrollment_id"
+ " AND a.indatetime = ("
+ " SELECT MAX(a2.indatetime) "
+ " FROM attendance a2 "
+ " WHERE a2.enrollment_id = e.enrollment_id"
+ " )"
+ "WHERE e.isactive = 1 "
+ " AND e.appointed = 1 "
+ " AND e.facial_attendance = 1 "
+ " AND e.incharge_id = '"+reporterId+"'";
System.out.println(sqlQuery);
List<Map<String, Object>> result = jdbcNULMTemplate.queryForList(sqlQuery);
Map<String, Object> response = new HashMap<>();
response.put("status", "Success");
response.put("message", "Request List");
response.put("Data", result);
return Collections.singletonList(response);
}
@Transactional
public List<Map<String, Object>> markAttendance(
String reporterId,
String enrollId,
String action, // "in" for check-in, "out" for check-out
String photourl
) {
Map<String, Object> response = new HashMap<>();
int lastQueryId = 0;
String datetimetxt = DateTimeUtil.getCurrentDateTimeMysql(); // Current timestamp
try {
if ("in".equalsIgnoreCase(action)) {
// Insert a new attendance record for check-in
String sqlQuery = "INSERT INTO attendance (indatetime, inby, inphoto, enrollment_id) "
+ "VALUES (?, ?, ?, ?)";
KeyHolder keyHolder = new GeneratedKeyHolder();
int affectedRows = jdbcNULMTemplate.update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement(sqlQuery, new String[]{"id"});
ps.setString(1, datetimetxt); // Check-in time
ps.setString(2, reporterId); // Mark By
ps.setString(3, photourl); // Photo URL for check-in
ps.setString(4, enrollId); // Employee ID (enrollId)
return ps;
}
}, keyHolder);
if (affectedRows > 0) {
Number generatedId = keyHolder.getKey();
lastQueryId = (generatedId != null) ? generatedId.intValue() : 0;
response.put("Id", lastQueryId);
response.put("status", "success");
response.put("message", "Check-in was recorded successfully!");
System.out.println("Check-in was recorded successfully! Attendance ID: " + generatedId);
} else {
response.put("status", "error");
response.put("message", "Failed to record check-in.");
}
} else if ("out".equalsIgnoreCase(action)) {
// Update the existing attendance record for check-out
String sqlQuery = "UPDATE attendance SET outdatetime = ?, outby = ?, outphoto = ? "
+ "WHERE enrollment_id = ? AND outdatetime IS NULL "
+ "ORDER BY indatetime DESC LIMIT 1";
int affectedRows = jdbcNULMTemplate.update(sqlQuery, datetimetxt, reporterId, photourl, enrollId);
if (affectedRows > 0) {
response.put("status", "success");
response.put("message", "Check-out was recorded successfully!");
System.out.println("Check-out was recorded successfully!");
} else {
response.put("status", "error");
response.put("message", "Failed to record check-out. No pending check-in found.");
}
} else if ("od".equalsIgnoreCase(action)) {
// Mark On Duty (OD) even if no check-in
String sqlQuery = "INSERT INTO attendance (oddatetime, odby, enrollment_id) "
+ "VALUES (?, ?, ?)";
int affectedRows = jdbcNULMTemplate.update(sqlQuery, datetimetxt, reporterId, enrollId);
if (affectedRows > 0) {
response.put("status", "success");
response.put("message", "On Duty was recorded successfully!");
System.out.println("On Duty was recorded successfully!");
} else {
response.put("status", "error");
response.put("message", "Failed to record On Duty.");
}
} else if ("leave".equalsIgnoreCase(action)) {
// Mark Leave even if no check-in
String sqlQuery = "INSERT INTO attendance (leavedatetime, leaveby, enrollment_id) "
+ "VALUES (?, ?, ?)";
int affectedRows = jdbcNULMTemplate.update(sqlQuery, datetimetxt, reporterId, enrollId);
if (affectedRows > 0) {
response.put("status", "success");
response.put("message", "Leave was recorded successfully!");
System.out.println("Leave was recorded successfully!");
} else {
response.put("status", "error");
response.put("message", "Failed to record Leave.");
}
} else {
response.put("status", "error");
response.put("message", "Invalid action. Use 'in' for check-in, 'out' for check-out, 'od' for On Duty, or 'leave' for Leave.");
}
} 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());
}
}
return Collections.singletonList(response);
}
public List<Map<String, Object>> getStaffAttendanceListByDate(
String reporterId,
String specificDate // Pass the specific date as an argument
){
String sqlQuery = "SELECT e.*, " +
" IFNULL(DATE_FORMAT(a.indatetime, '%d-%m-%Y %l:%i %p'), '') AS indatetime, " +
" IFNULL(DATE_FORMAT(a.outdatetime, '%d-%m-%Y %l:%i %p'), '') AS outdatetime, " +
" a.inby, " +
" a.outby, " +
" a.inphoto, " +
" a.outphoto, " +
" IFNULL(TIMEDIFF(a.outdatetime, a.indatetime), '') AS total_working_hours " +
"FROM enrollment_table e " +
"LEFT JOIN attendance a ON e.enrollment_id = a.enrollment_id " +
" AND DATE_FORMAT(a.indatetime, '%d-%m-%Y') = '"+specificDate+"' " + // Ensure the date matches the specific date
"WHERE e.isactive = 1 " +
" AND e.appointed = 1 " +
" AND e.facial_attendance = 1 " +
" AND e.incharge_id = '"+reporterId+"'";
System.out.println(sqlQuery);
// Execute the query with specificDate and reporterId as parameters
List<Map<String, Object>> result = jdbcNULMTemplate.queryForList(sqlQuery);
// Prepare the response
Map<String, Object> response = new HashMap<>();
response.put("status", "Success");
response.put("message", "Request List");
response.put("Data", result);
return Collections.singletonList(response);
}
}

1
mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/service/package-info.java

@ -0,0 +1 @@
package in.gov.chennaicorporation.mobileservice.nulm.service;

97
mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/penalty/controller/APIPenaltyController.java

@ -4,14 +4,17 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; 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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import in.gov.chennaicorporation.mobileservice.penalty.service.PenaltyService; import in.gov.chennaicorporation.mobileservice.penalty.service.PenaltyService;
@RequestMapping("/gccofficialapp/penalty/api")
@RequestMapping("/gccofficialapp/api/penalty")
@RestController("apiPenaltyRest") @RestController("apiPenaltyRest")
public class APIPenaltyController { public class APIPenaltyController {
@Autowired @Autowired
@ -21,4 +24,96 @@ public class APIPenaltyController {
public List<Map<String, Object>> getPenaltyTypes() { public List<Map<String, Object>> getPenaltyTypes() {
return penaltyService.getPenaltyTypeList(); return penaltyService.getPenaltyTypeList();
} }
@PostMapping(value="/generateChallan")
public List<?> generateChallan(@RequestParam MultiValueMap<String, String> formData,
@RequestParam(value = "categoryId", required = false) String categoryId,
@RequestParam(value = "latitude", required = false) String latitude,
@RequestParam(value = "longitude", required = false) String longitude,
@RequestParam(value = "zone", required = false) String zone,
@RequestParam(value = "ward", required = false) String ward,
@RequestParam(value = "streeId", required = false) String streeId,
@RequestParam(value = "streetName", required = false) String streetName,
@RequestParam(value = "loginId", required = false) String loginId,
@RequestParam(value = "remarks", required = false) String remarks,
@RequestParam(value = "isviolatorAvailable", required = false) String isviolatorAvailable,
@RequestParam(value = "violatorName", required = false) String violatorName,
@RequestParam(value = "violatorPhone", required = false) String violatorPhone,
@RequestParam(value = "ton", required = false) String ton,
@RequestParam(value = "file", required = false) MultipartFile file
) {
return penaltyService.generateChallan(formData, categoryId, latitude, longitude, zone, ward, streeId,
streetName, loginId,remarks,isviolatorAvailable,violatorName,violatorPhone,ton,file);
}
@PostMapping(value="/updateViolateInfo")
public List<?> updateViolateInfo(@RequestParam MultiValueMap<String, String> formData,
@RequestParam(value = "challanId", required = false) String challanId,
@RequestParam(value = "categoryId", required = false) String categoryId,
@RequestParam(value = "latitude", required = false) String latitude,
@RequestParam(value = "longitude", required = false) String longitude,
@RequestParam(value = "zone", required = false) String zone,
@RequestParam(value = "ward", required = false) String ward,
@RequestParam(value = "streeId", required = false) String streeId,
@RequestParam(value = "streetName", required = false) String streetName,
@RequestParam(value = "loginId", required = false) String loginId,
@RequestParam(value = "remarks", required = false) String remarks,
@RequestParam(value = "isviolatorAvailable", required = false) String isviolatorAvailable,
@RequestParam(value = "violatorName", required = false) String violatorName,
@RequestParam(value = "violatorPhone", required = false) String violatorPhone,
@RequestParam(value = "ton", required = false) String ton,
@RequestParam(value = "file", required = false) MultipartFile file
) {
return penaltyService.updateViolateInfo(formData, challanId, categoryId, latitude, longitude, zone, ward, streeId,
streetName, loginId,remarks,isviolatorAvailable,violatorName,violatorPhone,ton,file);
}
@GetMapping(value = "/getOfficerChallanList")
public List<Map<String, Object>> getOfficerChallanList(
@RequestParam(value = "categoryId", required = false) String categoryId,
@RequestParam(value = "fromDate", required = false) String fromDate,
@RequestParam(value = "toDate", required = false) String toDate,
@RequestParam(value = "zone", required = false) String zone,
@RequestParam(value = "ward", required = false) String ward,
@RequestParam(value = "streetid", required = false) String streetid,
@RequestParam(value = "status", required = false) String status,
@RequestParam(value = "isviolatorAvailable", required = false) String isviolatorAvailable,
@RequestParam(value = "loginId", required = false) String loginId
){
return penaltyService.getOfficerChallanList(categoryId, fromDate, toDate, zone, ward, streetid, status, loginId,isviolatorAvailable);
}
@PostMapping(value="/issueFine")
public List<?> issueFine(@RequestParam MultiValueMap<String, String> formData,
@RequestParam(value = "challanId", required = false) String challanId,
@RequestParam(value = "tonOnFine", required = false) String tonOnFine,
@RequestParam(value = "fineAmount", required = false) String fineAmount,
@RequestParam(value = "latitude", required = false) String latitude,
@RequestParam(value = "longitude", required = false) String longitude,
@RequestParam(value = "zone", required = false) String zone,
@RequestParam(value = "ward", required = false) String ward,
@RequestParam(value = "streeId", required = false) String streeId,
@RequestParam(value = "streetName", required = false) String streetName,
@RequestParam(value = "loginId", required = false) String loginId,
@RequestParam(value = "remarks", required = false) String remarks,
@RequestParam(value = "file", required = false) MultipartFile file
) {
return penaltyService.issueFine(formData, challanId, tonOnFine, fineAmount, latitude, longitude, zone, ward, streeId, streetName, loginId,remarks,file);
}
@PostMapping(value="/closeChallan")
public List<?> closeChallan(@RequestParam MultiValueMap<String, String> formData,
@RequestParam(value = "challanId", required = false) String challanId,
@RequestParam(value = "latitude", required = false) String latitude,
@RequestParam(value = "longitude", required = false) String longitude,
@RequestParam(value = "zone", required = false) String zone,
@RequestParam(value = "ward", required = false) String ward,
@RequestParam(value = "streeId", required = false) String streeId,
@RequestParam(value = "streetName", required = false) String streetName,
@RequestParam(value = "loginId", required = false) String loginId,
@RequestParam(value = "remarks", required = false) String remarks,
@RequestParam(value = "file", required = false) MultipartFile file
) {
return penaltyService.closeChallan(formData, challanId, latitude, longitude, zone, ward, streeId, streetName, loginId,remarks,file);
}
} }

601
mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/penalty/service/PenaltyService.java

@ -1,29 +1,624 @@
package in.gov.chennaicorporation.mobileservice.penalty.service; package in.gov.chennaicorporation.mobileservice.penalty.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.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.env.Environment;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate; 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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.MultiValueMap;
import org.springframework.web.multipart.MultipartFile;
import in.gov.chennaicorporation.mobileservice.gccactivity.service.DateTimeUtil;
@Service @Service
public class PenaltyService { public class PenaltyService {
private JdbcTemplate jdbcPenaltyTemplate; private JdbcTemplate jdbcPenaltyTemplate;
private final Environment environment;
@Autowired @Autowired
public void setDataSource(@Qualifier("mysqlPenaltyDataSource") DataSource penaltyDataSource) {
public void setDataSource(@Qualifier("mysqlActivityDataSource") DataSource penaltyDataSource) {
this.jdbcPenaltyTemplate = new JdbcTemplate(penaltyDataSource); this.jdbcPenaltyTemplate = new JdbcTemplate(penaltyDataSource);
} }
@Autowired
public PenaltyService(Environment environment) {
this.environment = environment;
}
// Function to convert date string from dd-MM-yyyy to yyyy-MM-dd
public static String convertDateFormat(String inputDate, int add) {
// Check if the inputDate is not null or blank
if (inputDate != null && !inputDate.isBlank()) {
try {
// Define the input and output date formats
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// Parse the input date string to LocalDate
LocalDate date = LocalDate.parse(inputDate, inputFormatter);
// Add the specified number of days to the date if 'add' is greater than 0
if (add > 0) {
date = date.plusDays(add);
}
// Format the date to the new format
return date.format(outputFormatter);
} catch (DateTimeParseException e) {
// Handle the case where the input date is invalid
System.out.println("Invalid date format: " + inputDate);
return "";
}
} else {
return "";
}
}
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("penalty_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
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+"/"+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();
}
}
@Transactional @Transactional
public List<Map<String, Object>> getPenaltyTypeList() { public List<Map<String, Object>> getPenaltyTypeList() {
String SqlQuery = "SELECT `id`, `name`, `display_name` FROM `penalty_types` WHERE `isdelete`=0 AND `isactive`=1";
List<Map<String, Object>> result = jdbcPenaltyTemplate.queryForList(SqlQuery);
String sqlQuery = "SELECT `id`, `name`,`iconurl` FROM `penalty_category` WHERE `isdelete`=0 AND `isactive`=1 ORDER BY `name`";
List<Map<String, Object>> result = jdbcPenaltyTemplate.queryForList(sqlQuery);
return result;
}
@Transactional
public List<Map<String, Object>> generateChallan(
MultiValueMap<String, String> formData,
String category_id,
String latitude,
String longitude,
String zone,
String ward,
String streeId,
String streetName,
String loginId,
String remarks,
String isviolatorAvailable,
String violatorName,
String violatorPhone,
String ton,
MultipartFile file) {
Map<String, Object> response = new HashMap<>();
int lastInsertId = 0;
String image = fileUpload("challan",category_id,file);
String sqlQuery = "INSERT INTO `penalty_challan`(`category_id`, `image`, `latitude`, `longitude`, "
+ "`zone`, `ward`, `streetid`, `streetname`, `challan_by`,`remarks`,"
+ "`violator_info`, `violator_name`, `violator_phone`, `ton`) "
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
KeyHolder keyHolder = new GeneratedKeyHolder();
try {
int affectedRows = jdbcPenaltyTemplate.update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement(sqlQuery, new String[]{"id"});
ps.setString(1, category_id);
ps.setString(2, image);
ps.setString(3, latitude);
ps.setString(4, longitude);
ps.setString(5, zone);
ps.setString(6, ward);
ps.setString(7, streeId);
ps.setString(8, streetName);
ps.setString(9, loginId);
ps.setString(10, remarks);
ps.setString(11, isviolatorAvailable);
ps.setString(12, violatorName);
ps.setString(13, violatorPhone);
ps.setString(14, ton);
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 new Penalty (Chellan) was generated successfully!");
System.out.println("A new Penalty (Chellan) was generated successfully! Insert ID: " + generatedId);
} else {
response.put("status", "error");
response.put("message", "Failed to insert a new Penalty (Chellan).");
}
} 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());
}
}
return Collections.singletonList(response);
}
@Transactional
public List<Map<String, Object>> updateViolateInfo(
MultiValueMap<String, String> formData,
String challanId,
String category_id,
String latitude,
String longitude,
String zone,
String ward,
String streeId,
String streetName,
String loginId,
String remarks,
String isviolatorAvailable,
String violatorName,
String violatorPhone,
String ton,
MultipartFile file) {
Map<String, Object> response = new HashMap<>();
int lastInsertId = 0;
String image = fileUpload("challan",category_id,file);
String sqlQuery = "UPDATE `penalty_challan` SET `category_id`=? , `image`=?, `latitude`=?, `longitude`=?, "
+ "`zone`=?, `ward`=?, `streetid`=?, `streetname`=?, `challan_by`=?,`remarks`=?,"
+ "`violator_info`=?, `violator_name`=?, `violator_phone`=?, `ton`=? "
+ " WHERE `id`=? LIMIT 1";
KeyHolder keyHolder = new GeneratedKeyHolder();
try {
int affectedRows = jdbcPenaltyTemplate.update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement(sqlQuery, new String[]{"id"});
ps.setString(1, category_id);
ps.setString(2, image);
ps.setString(3, latitude);
ps.setString(4, longitude);
ps.setString(5, zone);
ps.setString(6, ward);
ps.setString(7, streeId);
ps.setString(8, streetName);
ps.setString(9, loginId);
ps.setString(10, remarks);
ps.setString(11, isviolatorAvailable);
ps.setString(12, violatorName);
ps.setString(13, violatorPhone);
ps.setString(14, ton);
ps.setString(15, challanId);
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 new Penalty (Chellan) was generated successfully!");
System.out.println("A new Penalty (Chellan) was generated successfully! Insert ID: " + generatedId);
} else {
response.put("status", "error");
response.put("message", "Failed to insert a new Penalty (Chellan).");
}
} 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());
}
}
return Collections.singletonList(response);
}
@Transactional
public List<Map<String, Object>> getChallanList() {
String sqlQuery = "SELECT *, "
+ "DATE_FORMAT(challan_date, '%d-%m-%Y %r') AS formatted_challan_datetime, "
+ "DATE_FORMAT(challan_date, '%d-%m-%Y') AS formatted_challan_date, "
+ "DATE_FORMAT(challan_date, '%r') AS formatted_challan_time, "
+ "CONCAT('https://gccservices.chennaicorporation.gov.in/gccofficialapp/files', image) AS imageUrl, "
+ "CASE "
+ " WHEN status = 1 THEN 'Generated'"
+ " WHEN status = 2 THEN 'User Action Takened'"
+ " WHEN status = 3 THEN 'Fine Generated(Unpaid)'"
+ " WHEN status = 4 THEN 'Fine Generated(Paid)'"
+ " WHEN status = 5 THEN 'Action Taken By GCC'"
+ " WHEN status = 6 THEN 'Completed'"
+ " ELSE 'unknown'"
+ " END AS status_name, "
+ "DATE_FORMAT(challan_date, '%d-%m-%Y %H:%i:%s') AS challan_date "
+ "FROM penalty_category "
+ "WHERE isdelete=0 AND isactive=1 "
+ "ORDER BY name";
System.out.println("SQL : " + sqlQuery);
List<Map<String, Object>> result = jdbcPenaltyTemplate.queryForList(sqlQuery);
return result;
}
@Transactional
public List<Map<String, Object>> getOfficerChallanList(
String category_id,
String fromDate,
String toDate,
String zone,
String ward,
String streetid,
String status,
String loginId,
String isviolatorAvailable
) {
StringBuilder sqlQuery = new StringBuilder("SELECT pc.*, "
+ "DATE_FORMAT(pc.challan_date, '%d-%m-%Y %r') AS formatted_challan_datetime, "
+ "DATE_FORMAT(pc.challan_date, '%d-%m-%Y') AS formatted_challan_date, "
+ "DATE_FORMAT(pc.challan_date, '%r') AS formatted_challan_time, "
+ "CONCAT('https://gccservices.chennaicorporation.gov.in/gccofficialapp/files', pc.image) AS imageUrl, "
// Conditional formatting for fineissued_date fields
+ "CASE WHEN pc.fineissued = 1 THEN DATE_FORMAT(pc.fineissued_date, '%d-%m-%Y %r') ELSE '-' END AS formatted_fineissue_datetime, "
+ "CASE WHEN pc.fineissued = 1 THEN DATE_FORMAT(pc.fineissued_date, '%d-%m-%Y') ELSE '-' END AS formatted_fineissue_date, "
+ "CASE WHEN pc.fineissued = 1 THEN DATE_FORMAT(pc.fineissued_date, '%r') ELSE '-' END AS formatted_fineissue_time, "
// Status name mapping
+ "CASE "
+ " WHEN pc.status = 1 THEN 'Generated' "
+ " WHEN pc.status = 2 THEN 'User Action Taken' "
+ " WHEN pc.status = 3 THEN 'Fine Generated (Unpaid)' "
+ " WHEN pc.status = 4 THEN 'Fine Generated (Paid)' "
+ " WHEN pc.status = 5 THEN 'Action Taken By GCC' "
+ " WHEN pc.status = 6 THEN 'Completed' "
+ " ELSE 'Unknown' "
+ "END AS status_name, "
+ "DATE_FORMAT(pc.challan_date, '%d-%m-%Y %H:%i:%s') AS challan_date, "
+ "penalty_category.name AS penalty_category_name "
+ "FROM penalty_challan pc "
+ "JOIN penalty_category ON pc.category_id = penalty_category.id "
+ "WHERE (pc.isdelete = 0 AND pc.isactive = 1) AND pc.challan_by = '" + loginId + "' ");
// Add additional filters if provided
if (zone != null && !zone.isEmpty() && !zone.isBlank()) {
sqlQuery.append(" AND pc.zone = '" + zone + "'");
}
if (ward != null && !ward.isEmpty() && !ward.isBlank()) {
sqlQuery.append(" AND pc.ward = '" + ward + "'");
}
if (streetid != null && !streetid.isEmpty() && !streetid.isBlank()) {
sqlQuery.append(" AND pc.streetid = '" + streetid + "'");
}
if (category_id != null && !category_id.isEmpty() && !category_id.isBlank()) {
sqlQuery.append(" AND pc.category_id = '" + category_id + "'");
}
if (isviolatorAvailable != null && !isviolatorAvailable.isEmpty() && !isviolatorAvailable.isBlank()) {
sqlQuery.append(" AND pc.violator_info = '" + isviolatorAvailable + "'");
}
if (status != null && !status.isEmpty() && !status.isBlank()) {
sqlQuery.append(" AND pc.status = '" + status + "'");
}
// Date filters
if (fromDate != null && toDate != null) {
fromDate = convertDateFormat(fromDate, 0);
toDate = convertDateFormat(toDate, 1);
sqlQuery.append(" AND pc.challan_date BETWEEN '" + fromDate + "' AND '" + toDate + "'");
}
sqlQuery.append(" ORDER BY pc.challan_date DESC");
System.out.println("SQL OF getOfficerChallanList");
System.out.println("SQL : " + sqlQuery);
List<Map<String, Object>> result = jdbcPenaltyTemplate.queryForList(sqlQuery.toString());
return result;
}
@Transactional
public List<Map<String, Object>> issueFine(
MultiValueMap<String, String> formData,
String challanId,
String tonOnFine,
String fineAmount,
String latitude,
String longitude,
String zone,
String ward,
String streeId,
String streetName,
String loginId,
String remarks,
MultipartFile file) {
Map<String, Object> response = new HashMap<>();
int lastInsertId = 0;
String image = fileUpload("fine",challanId,file);
String sqlQuery = "INSERT INTO `penalty_fine_info`(`challan_id`, `image`, `latitude`, `longitude`, `zone`, `ward`, `streetid`, `streetname`, `fineissued_by`,`remarks`,`ton_on_fine`,`fine_amount`) "
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
KeyHolder keyHolder = new GeneratedKeyHolder();
try {
int affectedRows = jdbcPenaltyTemplate.update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement(sqlQuery, new String[]{"id"});
ps.setString(1, challanId);
ps.setString(2, image);
ps.setString(3, latitude);
ps.setString(4, longitude);
ps.setString(5, zone);
ps.setString(6, ward);
ps.setString(7, streeId);
ps.setString(8, streetName);
ps.setString(9, loginId);
ps.setString(10, remarks);
ps.setString(11, tonOnFine);
ps.setString(12, fineAmount);
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 new fine was generated successfully!");
System.out.println("A new fine was generated successfully! Insert ID: " + generatedId);
//Fine Generated(Unpaid) id 3
String sqlQuery_u = "UPDATE `penalty_challan` SET `status`=3, fineissued=1 WHERE `id`='"+challanId+"'";
jdbcPenaltyTemplate.update(sqlQuery_u);
System.out.println(sqlQuery_u);
System.out.println("Challan Updated as fine successfully! Challan ID: " + challanId);
} else {
response.put("status", "error");
response.put("message", "Failed to insert a new fine.");
}
} 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());
}
}
return Collections.singletonList(response);
}
@Transactional
public List<Map<String, Object>> closeChallan(
MultiValueMap<String, String> formData,
String challanId,
String latitude,
String longitude,
String zone,
String ward,
String streeId,
String streetName,
String loginId,
String remarks,
MultipartFile file) {
Map<String, Object> response = new HashMap<>();
int lastInsertId = 0;
String image = fileUpload("close",challanId,file);
String sqlQuery = "INSERT INTO `penalty_close_info`(`challan_id`, `image`, `latitude`, `longitude`, `zone`, `ward`, `streetid`, `streetname`, `fineclose_by`,`remarks`) "
+ "VALUES (?,?,?,?,?,?,?,?,?,?)";
KeyHolder keyHolder = new GeneratedKeyHolder();
try {
int affectedRows = jdbcPenaltyTemplate.update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement(sqlQuery, new String[]{"id"});
ps.setString(1, challanId);
ps.setString(2, image);
ps.setString(3, latitude);
ps.setString(4, longitude);
ps.setString(5, zone);
ps.setString(6, ward);
ps.setString(7, streeId);
ps.setString(8, streetName);
ps.setString(9, loginId);
ps.setString(10, remarks);
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 Challan Close log was generated successfully!");
System.out.println("A Challan Close log was generated successfully! Insert ID: " + generatedId);
//Fine Generated(Unpaid) id 3
String sqlQuery_u = "UPDATE `penalty_challan` SET `status`=6 WHERE `id`='"+challanId+"'";
jdbcPenaltyTemplate.update(sqlQuery_u);
System.out.println(sqlQuery_u);
System.out.println("Challan Updated as closed successfully! Challan ID: " + challanId);
} else {
response.put("status", "error");
response.put("message", "Failed to close the challan.");
}
} 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());
}
}
return Collections.singletonList(response);
}
@Transactional
public List<Map<String, Object>> getTaskListByZone(
String zone,
String loginId){
String sqlQuery = "SELECT *,CASE "
+ " WHEN status = 1 THEN 'Open'"
+ " WHEN status = 2 THEN 'In-Progress'"
+ " WHEN status = 3 THEN 'Pending'"
+ " WHEN status = 4 THEN 'Completed'"
+ " ELSE 'unknown'"
+ " END AS status_name FROM "
+ "`brr_task` WHERE `zone`=? AND (`isactive`=1 AND `isdelete`=0) ORDER BY `id` DESC";
List<Map<String, Object>> result = jdbcPenaltyTemplate.queryForList(sqlQuery, zone);
return result; return result;
} }
} }

85
mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/service/OfficialAPIService.java

@ -89,16 +89,16 @@ public class OfficialAPIService {
switch (usertype) { switch (usertype) {
case "erp": case "erp":
//sqlQuery = "SELECT * FROM `EG_USER` WHERE `ISPORTALUSER` <> 1 AND `ISACTIVE` = 1 AND `EXTRAFIELD2` = ? AND `PIN` = ? LIMIT 1"; //sqlQuery = "SELECT * FROM `EG_USER` WHERE `ISPORTALUSER` <> 1 AND `ISACTIVE` = 1 AND `EXTRAFIELD2` = ? AND `PIN` = ? LIMIT 1";
sqlQuery = "SELECT * FROM `EG_USER` WHERE `EXTRAFIELD2` = ? AND `PIN` = ? LIMIT 1";
sqlQuery = "SELECT * FROM `EG_USER` WHERE `EXTRAFIELD2` = ? AND `PIN` = ? AND `ISACTIVE`=1 LIMIT 1";
result = jdbcOfficalTemplate.queryForList(sqlQuery, username, password); result = jdbcOfficalTemplate.queryForList(sqlQuery, username, password);
break; break;
case "nonerp": case "nonerp":
sqlQuery = "SELECT * FROM `EG_USER` WHERE `EXTRAFIELD2` = ? AND `PIN` = ? LIMIT 1";
sqlQuery = "SELECT * FROM `EG_USER` WHERE `EXTRAFIELD2` = ? AND `PIN` = ? AND `ISACTIVE`=1 LIMIT 1";
result = jdbcOfficalTemplate.queryForList(sqlQuery, username, password); result = jdbcOfficalTemplate.queryForList(sqlQuery, username, password);
break; break;
// additional cases can be added here // additional cases can be added here
default: default:
sqlQuery = "SELECT * FROM `EG_USER` WHERE `EXTRAFIELD2` = ? AND `PIN` = ? LIMIT 1";
sqlQuery = "SELECT * FROM `EG_USER` WHERE `EXTRAFIELD2` = ? AND `PIN` = ? AND `ISACTIVE`=1 LIMIT 1";
result = jdbcOfficalTemplate.queryForList(sqlQuery, username, password); result = jdbcOfficalTemplate.queryForList(sqlQuery, username, password);
//result = Collections.emptyList(); //result = Collections.emptyList();
break; break;
@ -202,6 +202,40 @@ public class OfficialAPIService {
return result; return result;
} }
@Transactional
public List<Map<String, Object>> getUserMainMenu(String loginId) {
String SqlQuery = "";
String groups ="0";
List<Map<String, Object>> groupids=getUserGroups(loginId);
// Check if the list is not empty
if (groupids != null && !groupids.isEmpty()) {
// Retrieve the first map in the list
Map<String, Object> firstEntry = groupids.get(0);
// Check if the map contains the "groups" key
if (firstEntry.containsKey("groups")) {
// Get the "groups" value
groups = (String) firstEntry.get("groups");
// Do something with the groups value
System.out.println("Groups: " + groups);
} else {
System.out.println("The 'groups' key is not present.");
}
} else {
System.out.println("No data found in groupids.");
}
//SqlQuery="SELECT GROUP_CONCAT(`module_id`) AS module_ids FROM `user_group_module_access` WHERE `group_id` IN ("+groups+") GROUP by `group_id`";
SqlQuery="SELECT GROUP_CONCAT(DISTINCT `department_id` ORDER BY `department_id` ASC) AS department_ids "
+ "FROM `user_group_department_access` "
+ "WHERE `group_id` IN ("+groups+")";
List<Map<String, Object>> result = jdbcUserTemplate.queryForList(SqlQuery);
return result;
}
@Transactional @Transactional
public List<Map<String, Object>> getUserModules(String loginId) { public List<Map<String, Object>> getUserModules(String loginId) {
@ -236,6 +270,7 @@ public class OfficialAPIService {
return result; return result;
} }
@Transactional @Transactional
public List<Map<String, Object>> getUserMenuItem(String loginId) { public List<Map<String, Object>> getUserMenuItem(String loginId) {
@ -270,9 +305,45 @@ public class OfficialAPIService {
} }
@Transactional @Transactional
public List<Map<String, Object>> getMenu(String loginId) {
public List<Map<String, Object>> getMainMenu(String loginId) {
System.out.println("getMenu LoginID: " + loginId); System.out.println("getMenu LoginID: " + loginId);
String SqlQuery = ""; String SqlQuery = "";
String mainmenus ="0";
if(loginId.isBlank() || loginId.isEmpty() || loginId==null || loginId.equals(null) || loginId.equals("null")) {
loginId="11342";
}
List<Map<String, Object>> mainModuleids=getUserMainMenu(loginId);
// Check if the list is not empty
if (mainModuleids != null && !mainModuleids.isEmpty()) {
// Retrieve the first map in the list
Map<String, Object> firstEntry = mainModuleids.get(0);
// Check if the map contains the "groups" key
if (firstEntry.containsKey("department_ids")) {
// Get the "groups" value
mainmenus = (String) firstEntry.get("department_ids");
// Do something with the groups value
System.out.println("MainMenus: " + mainmenus);
} else {
System.out.println("The 'department_ids' key is not present.");
}
} else {
System.out.println("No data found in moduleids.");
}
SqlQuery="SELECT *,CONCAT('https://gccservices.chennaicorporation.gov.in/gccofficialapp/files/app_icon/menu/', icon_url) "
+ "AS iconUrl FROM `department` WHERE `ISACTIVE`=1 AND `id` IN ("+mainmenus+") ORDER BY `orderby`, `name` ASC";
List<Map<String, Object>> result = jdbcActivityTemplate.queryForList(SqlQuery);
return result;
}
@Transactional
public List<Map<String, Object>> getMenu(String loginId, String departmentId) {
System.out.println("getMenu LoginID: " + loginId);
System.out.println("getMenu DepartmentID: " + departmentId);
String SqlQuery = "";
String menus ="0"; String menus ="0";
if(loginId.isBlank() || loginId.isEmpty() || loginId==null || loginId.equals(null) || loginId.equals("null")) { if(loginId.isBlank() || loginId.isEmpty() || loginId==null || loginId.equals(null) || loginId.equals("null")) {
loginId="11342"; loginId="11342";
@ -299,7 +370,10 @@ public class OfficialAPIService {
} }
SqlQuery="SELECT *,CONCAT('https://gccservices.chennaicorporation.gov.in/gccofficialapp/files/app_icon/menu/', icon_url) " SqlQuery="SELECT *,CONCAT('https://gccservices.chennaicorporation.gov.in/gccofficialapp/files/app_icon/menu/', icon_url) "
+ "AS iconUrl FROM `modules` WHERE `ISACTIVE`=1 AND `id` IN ("+menus+")";
+ "AS iconUrl FROM `modules` WHERE `ISACTIVE`=1 AND `id` IN ("+menus+") ";
if(departmentId!=null && !departmentId.isEmpty() && !departmentId.isBlank()) {
SqlQuery=SqlQuery+" AND `departmentId_id`='"+departmentId+"'";
}
List<Map<String, Object>> result = jdbcActivityTemplate.queryForList(SqlQuery); List<Map<String, Object>> result = jdbcActivityTemplate.queryForList(SqlQuery);
return result; return result;
} }
@ -338,6 +412,7 @@ public class OfficialAPIService {
SqlQuery="SELECT *,CONCAT('https://gccservices.chennaicorporation.gov.in/gccofficialapp/files/app_icon/menu/', icon_url) " SqlQuery="SELECT *,CONCAT('https://gccservices.chennaicorporation.gov.in/gccofficialapp/files/app_icon/menu/', icon_url) "
+ "AS iconUrl FROM `menuitem` WHERE `ISACTIVE`=1 AND `module_id`=? AND `id` IN ("+menuitem+")"; + "AS iconUrl FROM `menuitem` WHERE `ISACTIVE`=1 AND `module_id`=? AND `id` IN ("+menuitem+")";
System.out.println(SqlQuery);
List<Map<String, Object>> result = jdbcActivityTemplate.queryForList(SqlQuery,menuId); List<Map<String, Object>> result = jdbcActivityTemplate.queryForList(SqlQuery,menuId);
return result; return result;
} }

1
mobileservice/src/main/resources/application.properties

@ -32,3 +32,4 @@ activity_foldername = asset_activity/
activity_new_asset_foldername = asset_images/ activity_new_asset_foldername = asset_images/
brr_activity_foldername= brr_activity_images/ brr_activity_foldername= brr_activity_images/
sos_activity_foldername= sos_rescue_activity_images/ sos_activity_foldername= sos_rescue_activity_images/
penalty_foldername=penalty_activity/
Loading…
Cancel
Save