From 8b23aad328741ce82c70c26207f7b51d11f6da12 Mon Sep 17 00:00:00 2001 From: Balaji <104271023+tbalaji0001@users.noreply.github.com> Date: Mon, 9 Sep 2024 11:15:14 +0530 Subject: [PATCH] Penalty Module update --- .../configuration/DataSourceConfig.java | 37 +- .../controller/APIOfficialController.java | 11 +- .../controller/APIActivityController.java | 7 +- .../gccactivity/service/Activity.java | 57 +- .../gccactivity/service/DateTimeUtil.java | 5 + .../controller/APINULMOfficerController.java | 74 +++ .../nulm/controller/package-info.java | 1 + .../mobileservice/nulm/package-info.java | 1 + .../nulm/service/NULMOfficerActivity.java | 350 ++++++++++ .../nulm/service/package-info.java | 1 + .../controller/APIPenaltyController.java | 97 ++- .../penalty/service/CattleCatchService.java | 2 +- .../penalty/service/PenaltyService.java | 601 +++++++++++++++++- .../service/OfficialAPIService.java | 85 ++- .../src/main/resources/application.properties | 3 +- 15 files changed, 1288 insertions(+), 44 deletions(-) create mode 100644 mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/controller/APINULMOfficerController.java create mode 100644 mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/controller/package-info.java create mode 100644 mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/package-info.java create mode 100644 mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/service/NULMOfficerActivity.java create mode 100644 mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/service/package-info.java diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/configuration/DataSourceConfig.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/configuration/DataSourceConfig.java index 7d9c196..7a669b1 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/configuration/DataSourceConfig.java +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/configuration/DataSourceConfig.java @@ -20,9 +20,15 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @EnableTransactionManagement 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) //////////////////////// @Configuration @EnableTransactionManagement @@ -37,7 +43,7 @@ public class DataSourceConfig { public DataSource mysqlAppDataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); 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.setPassword(dbpassword); return dataSource; @@ -70,7 +76,7 @@ public class DataSourceConfig { public DataSource mysqlActivityDataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); 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.setPassword(dbpassword); return dataSource; @@ -81,7 +87,7 @@ public class DataSourceConfig { public DataSource mysqlPenaltyDataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); 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.setPassword(dbpassword); return dataSource; @@ -92,7 +98,7 @@ public class DataSourceConfig { public DataSource mysqlPGRMasterDataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); 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.setPassword(dbpassword); return dataSource; @@ -103,7 +109,7 @@ public class DataSourceConfig { public DataSource mysqlGCCUserDataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); 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.setPassword(dbpassword); return dataSource; @@ -115,12 +121,23 @@ public class DataSourceConfig { public DataSource mysqlGccSOSDataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); 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.setPassword(dbpassword); + return dataSource; + } + ////////////////////////////// ORACLE //////////////////////// @Bean(name = "oracleERPDataSource") public DataSource oracleERPDataSource() { diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/controller/APIOfficialController.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/controller/APIOfficialController.java index 4d7cd5a..b1601e8 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/controller/APIOfficialController.java +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/controller/APIOfficialController.java @@ -83,9 +83,16 @@ public class APIOfficialController { } // For Menu //////////////////////////////////////// + @GetMapping(value="/getMainMenu") + public List getMainMenu(@RequestParam String loginId){ + return officialAPIService.getMainMenu(loginId); + } + @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") diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/controller/APIActivityController.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/controller/APIActivityController.java index 3da102a..da89e7d 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/controller/APIActivityController.java +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/controller/APIActivityController.java @@ -21,8 +21,8 @@ public class APIActivityController { private Activity activity; @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") @@ -35,9 +35,10 @@ public class APIActivityController { @RequestParam("streeId") String streeId, @RequestParam("streetName") String streetName, @RequestParam("loginId") String loginId, + @RequestParam(value = "name", required = false) String name, @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") diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/service/Activity.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/service/Activity.java index 13a69e0..71204fa 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/service/Activity.java +++ b/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.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -80,8 +81,13 @@ public class Activity { } @Transactional - public List> getActivityCategory(){ - String sqlQuery = "SELECT * FROM `activity_category` WHERE (`isactive`=1 AND `isdelete`=0) ORDER BY `display_order` ASC"; + public List> 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> result = jdbcActivityTemplate.queryForList(sqlQuery); return result; @@ -98,6 +104,7 @@ public class Activity { String streeId, String streetName, String loginId, + String name, MultipartFile file) { List> result=null; Map response = new HashMap<>(); @@ -105,8 +112,8 @@ public class Activity { 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(); @@ -124,6 +131,7 @@ public class Activity { ps.setString(7, streeId); ps.setString(8, streetName); ps.setString(9, loginId); + ps.setString(10, name); return ps; } }, 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 - 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"); + 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); - if(add>0) { - // Add one day to the date - date = date.plusDays(1); - } - - // Format the date to the new format - return date.format(outputFormatter); - } + // 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 ""; + } + } 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+."; diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/service/DateTimeUtil.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/service/DateTimeUtil.java index 8fd35af..47ed74d 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/service/DateTimeUtil.java +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/gccactivity/service/DateTimeUtil.java @@ -26,4 +26,9 @@ public class DateTimeUtil { LocalDateTime now = LocalDateTime.now(); 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); + } } diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/controller/APINULMOfficerController.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/controller/APINULMOfficerController.java new file mode 100644 index 0000000..21c5563 --- /dev/null +++ b/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); + } + +} diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/controller/package-info.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/controller/package-info.java new file mode 100644 index 0000000..26f15f6 --- /dev/null +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/controller/package-info.java @@ -0,0 +1 @@ +package in.gov.chennaicorporation.mobileservice.nulm.controller; \ No newline at end of file diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/package-info.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/package-info.java new file mode 100644 index 0000000..ac62699 --- /dev/null +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/package-info.java @@ -0,0 +1 @@ +package in.gov.chennaicorporation.mobileservice.nulm; \ No newline at end of file diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/service/NULMOfficerActivity.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/service/NULMOfficerActivity.java new file mode 100644 index 0000000..24ba636 --- /dev/null +++ b/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> 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> result = jdbcNULMTemplate.queryForList(sqlQuery); + Map response = new HashMap<>(); + response.put("status", "Success"); + response.put("message", "Request List"); + response.put("ward", result); + + return Collections.singletonList(response); + } + + public List> 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> result = jdbcNULMTemplate.queryForList(sqlQuery); + Map response = new HashMap<>(); + response.put("status", "Success"); + response.put("message", "Request List"); + response.put("ward", result); + + return Collections.singletonList(response); + } + + public List> 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> result = jdbcNULMTemplate.queryForList(sqlQuery); + Map response = new HashMap<>(); + response.put("status", "Success"); + response.put("message", "Request List"); + response.put("Data", result); + + return Collections.singletonList(response); + } + + public List> updateStaffFaceRegister( + String reporterId, + String enrollId, + String status + ){ + Map 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> 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> 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> result = jdbcNULMTemplate.queryForList(sqlQuery); + Map response = new HashMap<>(); + response.put("status", "Success"); + response.put("message", "Request List"); + response.put("Data", result); + + return Collections.singletonList(response); + } + + @Transactional + public List> markAttendance( + String reporterId, + String enrollId, + String action, // "in" for check-in, "out" for check-out + String photourl + ) { + + Map 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> 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> result = jdbcNULMTemplate.queryForList(sqlQuery); + + // Prepare the response + Map response = new HashMap<>(); + response.put("status", "Success"); + response.put("message", "Request List"); + response.put("Data", result); + + return Collections.singletonList(response); + } +} diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/service/package-info.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/service/package-info.java new file mode 100644 index 0000000..b04aaea --- /dev/null +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/service/package-info.java @@ -0,0 +1 @@ +package in.gov.chennaicorporation.mobileservice.nulm.service; \ No newline at end of file diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/penalty/controller/APIPenaltyController.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/penalty/controller/APIPenaltyController.java index 0da375e..55d6f4f 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/penalty/controller/APIPenaltyController.java +++ b/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 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.penalty.service.PenaltyService; -@RequestMapping("/gccofficialapp/penalty/api") +@RequestMapping("/gccofficialapp/api/penalty") @RestController("apiPenaltyRest") public class APIPenaltyController { @Autowired @@ -21,4 +24,96 @@ public class APIPenaltyController { public List> getPenaltyTypes() { return penaltyService.getPenaltyTypeList(); } + + @PostMapping(value="/generateChallan") + public List generateChallan(@RequestParam MultiValueMap 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 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> 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 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 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); + } } diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/penalty/service/CattleCatchService.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/penalty/service/CattleCatchService.java index fe4686c..8542561 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/penalty/service/CattleCatchService.java +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/penalty/service/CattleCatchService.java @@ -24,6 +24,6 @@ public class CattleCatchService { public List> getPenaltyTypeList() { String SqlQuery = "SELECT `id`, `name`, `display_name` FROM `penalty_types` WHERE `isdelete`=0 AND `isactive`=1"; List> result = jdbcPenaltyTemplate.queryForList(SqlQuery); - return result; + return result; } } diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/penalty/service/PenaltyService.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/penalty/service/PenaltyService.java index 8356e5e..51e403c 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/penalty/service/PenaltyService.java +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/penalty/service/PenaltyService.java @@ -1,29 +1,624 @@ 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.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.util.MultiValueMap; +import org.springframework.web.multipart.MultipartFile; + +import in.gov.chennaicorporation.mobileservice.gccactivity.service.DateTimeUtil; @Service public class PenaltyService { private JdbcTemplate jdbcPenaltyTemplate; + private final Environment environment; @Autowired - public void setDataSource(@Qualifier("mysqlPenaltyDataSource") DataSource penaltyDataSource) { + public void setDataSource(@Qualifier("mysqlActivityDataSource") DataSource 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 public List> getPenaltyTypeList() { - String SqlQuery = "SELECT `id`, `name`, `display_name` FROM `penalty_types` WHERE `isdelete`=0 AND `isactive`=1"; - List> result = jdbcPenaltyTemplate.queryForList(SqlQuery); + String sqlQuery = "SELECT `id`, `name`,`iconurl` FROM `penalty_category` WHERE `isdelete`=0 AND `isactive`=1 ORDER BY `name`"; + List> result = jdbcPenaltyTemplate.queryForList(sqlQuery); + return result; + } + + @Transactional + public List> generateChallan( + MultiValueMap 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 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> updateViolateInfo( + MultiValueMap 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 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> 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> result = jdbcPenaltyTemplate.queryForList(sqlQuery); + return result; + } + + @Transactional + public List> 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> result = jdbcPenaltyTemplate.queryForList(sqlQuery.toString()); + + return result; + } + + @Transactional + public List> issueFine( + MultiValueMap 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 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> closeChallan( + MultiValueMap formData, + String challanId, + String latitude, + String longitude, + String zone, + String ward, + String streeId, + String streetName, + String loginId, + String remarks, + MultipartFile file) { + + Map 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> 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> result = jdbcPenaltyTemplate.queryForList(sqlQuery, zone); + return result; } } diff --git a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/service/OfficialAPIService.java b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/service/OfficialAPIService.java index cb91472..139ae62 100644 --- a/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/service/OfficialAPIService.java +++ b/mobileservice/src/main/java/in/gov/chennaicorporation/mobileservice/service/OfficialAPIService.java @@ -89,16 +89,16 @@ public class OfficialAPIService { switch (usertype) { 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 `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); break; 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); break; // additional cases can be added here 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 = Collections.emptyList(); break; @@ -202,6 +202,40 @@ public class OfficialAPIService { return result; } + @Transactional + public List> getUserMainMenu(String loginId) { + + String SqlQuery = ""; + String groups ="0"; + List> groupids=getUserGroups(loginId); + + // Check if the list is not empty + if (groupids != null && !groupids.isEmpty()) { + // Retrieve the first map in the list + Map 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> result = jdbcUserTemplate.queryForList(SqlQuery); + return result; + } + @Transactional public List> getUserModules(String loginId) { @@ -236,6 +270,7 @@ public class OfficialAPIService { return result; } + @Transactional public List> getUserMenuItem(String loginId) { @@ -270,9 +305,45 @@ public class OfficialAPIService { } @Transactional - public List> getMenu(String loginId) { + public List> getMainMenu(String loginId) { System.out.println("getMenu LoginID: " + loginId); String SqlQuery = ""; + String mainmenus ="0"; + if(loginId.isBlank() || loginId.isEmpty() || loginId==null || loginId.equals(null) || loginId.equals("null")) { + loginId="11342"; + } + List> mainModuleids=getUserMainMenu(loginId); + + // Check if the list is not empty + if (mainModuleids != null && !mainModuleids.isEmpty()) { + // Retrieve the first map in the list + Map 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> result = jdbcActivityTemplate.queryForList(SqlQuery); + return result; + } + + @Transactional + public List> getMenu(String loginId, String departmentId) { + System.out.println("getMenu LoginID: " + loginId); + System.out.println("getMenu DepartmentID: " + departmentId); + String SqlQuery = ""; String menus ="0"; if(loginId.isBlank() || loginId.isEmpty() || loginId==null || loginId.equals(null) || loginId.equals("null")) { loginId="11342"; @@ -299,7 +370,10 @@ public class OfficialAPIService { } 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> result = jdbcActivityTemplate.queryForList(SqlQuery); return result; } @@ -338,6 +412,7 @@ public class OfficialAPIService { 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+")"; + System.out.println(SqlQuery); List> result = jdbcActivityTemplate.queryForList(SqlQuery,menuId); return result; } diff --git a/mobileservice/src/main/resources/application.properties b/mobileservice/src/main/resources/application.properties index ab1fcb7..0e493c4 100644 --- a/mobileservice/src/main/resources/application.properties +++ b/mobileservice/src/main/resources/application.properties @@ -31,4 +31,5 @@ file.upload.directory=${user.dir}/gcc_mobile_service_uploads/ activity_foldername = asset_activity/ activity_new_asset_foldername = asset_images/ brr_activity_foldername= brr_activity_images/ -sos_activity_foldername= sos_rescue_activity_images/ \ No newline at end of file +sos_activity_foldername= sos_rescue_activity_images/ +penalty_foldername=penalty_activity/ \ No newline at end of file