diff --git a/src/main/java/in/gov/chennaicorporation/mobileservice/configuration/DataSourceConfig.java b/src/main/java/in/gov/chennaicorporation/mobileservice/configuration/DataSourceConfig.java index c25849fa..a9ea1a1a 100644 --- a/src/main/java/in/gov/chennaicorporation/mobileservice/configuration/DataSourceConfig.java +++ b/src/main/java/in/gov/chennaicorporation/mobileservice/configuration/DataSourceConfig.java @@ -20,13 +20,13 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @EnableTransactionManagement public class DataSourceConfig { -// private static String host = "localhost:3306"; -// private static String dbpassword = "root"; + private static String host = "localhost:3306"; + private static String dbpassword = "root"; // private static String dbpassword = "gccroot"; // AWS - private static String host = "gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306"; - private static String dbpassword = "gcc-facial-password"; +// private static String host = "gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306"; +// private static String dbpassword = "gcc-facial-password"; ////////////////////////////// (For GCC APP) //////////////////////// @Configuration diff --git a/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/service/NULMOfficerActivity.java b/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/service/NULMOfficerActivity.java index 776cc45a..d2ba6501 100644 --- a/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/service/NULMOfficerActivity.java +++ b/src/main/java/in/gov/chennaicorporation/mobileservice/nulm/service/NULMOfficerActivity.java @@ -163,31 +163,32 @@ public class NULMOfficerActivity { 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 " - // + " CASE " + - // " WHEN DATE(a.indatetime) = CURDATE() THEN 'Present' " + - // " WHEN DATE(a.oddatetime) = CURDATE() THEN 'OD Marked' " + - // " WHEN DATE(a.leavedatetime) = CURDATE() THEN 'Leave Marked' " + - // " ELSE '' " + - // " END AS attendance_status " - + "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 + "'"; - // + " AND FIND_IN_SET(e.incharge_id, '"+reporterId+"') > 0 "; + String sqlQuery = "SELECT " + + " e.*, " + + " IFNULL(DATE_FORMAT(a.indatetime, '%d-%m-%Y %h:%i %p'), '') AS indatetime, " + + " IFNULL(DATE_FORMAT(a.outdatetime, '%d-%m-%Y %h:%i %p'), '') AS outdatetime, " + + " a.inby, " + + " a.outby, " + + " a.inphoto, " + + " a.outphoto, " + + " CASE " + + " WHEN a.indatetime IS NOT NULL THEN 'Present' " + + " WHEN a.oddatetime IS NOT NULL THEN 'OD Marked' " + + " WHEN a.leavedatetime IS NOT NULL THEN 'Leave Marked' " + + " ELSE '' " + + " END AS attendance_status " + + " FROM enrollment_table e " + + " LEFT JOIN attendance a " + + " ON a.enrollment_id = e.enrollment_id " + + " AND ( " + + " DATE(a.indatetime) = CURDATE() " + + " OR DATE(a.oddatetime) = CURDATE() " + + " OR DATE(a.leavedatetime) = CURDATE() " + + " ) " + + " 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); @@ -208,16 +209,16 @@ public class NULMOfficerActivity { + " a.inby, " + " a.outby, " + " a.inphoto, " - + " a.outphoto " - // + " CASE " - // + " WHEN DATE(a.oddatetime) = CURDATE() THEN 'OD Marked' " - // + " WHEN DATE(a.leavedatetime) = CURDATE() THEN 'Leave Marked' " - // + " ELSE '' " - // + " END AS attendance_status " + + " a.outphoto, " + + " CASE " + + " WHEN DATE(a.oddatetime) = CURDATE() THEN 'OD Marked' " + + " WHEN DATE(a.leavedatetime) = CURDATE() THEN 'Leave Marked' " + + " ELSE '' " + + " END AS attendance_status " + " FROM enrollment_table e " - + " LEFT JOIN attendance a ON e.enrollment_id = a.enrollment_id" - + " AND a.indatetime = (" - + " SELECT MAX(a2.indatetime) " + + " LEFT JOIN attendance a " + + " ON a.id = (" + + " SELECT MAX(a2.id) " + " FROM attendance a2 " + " WHERE a2.enrollment_id = e.enrollment_id" + " )" @@ -247,20 +248,20 @@ public class NULMOfficerActivity { + " a.inby, " + " a.outby, " + " a.inphoto, " - + " a.outphoto " - // + " CASE " - // + " WHEN DATE(a.oddatetime) = CURDATE() THEN 'OD Marked' " - // + " WHEN DATE(a.leavedatetime) = CURDATE() THEN 'Leave Marked' " - // + " ELSE '' " - // + " END AS attendance_status " - + " FROM enrollment_table e " - + " LEFT JOIN attendance a ON e.enrollment_id = a.enrollment_id" - + " AND a.indatetime = (" - + " SELECT MAX(a2.indatetime) " + + " a.outphoto, " + + " CASE " + + " WHEN DATE(a.oddatetime) = CURDATE() THEN 'OD Marked' " + + " WHEN DATE(a.leavedatetime) = CURDATE() THEN 'Leave Marked' " + + " ELSE '' " + + " END AS attendance_status " + + " FROM enrollment_table e " + + " LEFT JOIN attendance a " + + " ON a.id = (" + + " SELECT MAX(a2.id) " + " FROM attendance a2 " + " WHERE a2.enrollment_id = e.enrollment_id" + " )" - + " WHERE e.isactive = 1 " + + " WHERE e.isactive = 1 " + " AND e.appointed = 1 " + " AND e.facial_attendance = 1 " + " AND e.emp_type = 'Park' " @@ -581,10 +582,9 @@ public class NULMOfficerActivity { } else if ("out".equalsIgnoreCase(action)) { // Update the existing attendance record for check-out - // String sqlQuery = "UPDATE attendance SET outdatetime = ?, outby = ?, outphoto - // = ?, location = ?, appversion = ?, apptype = ? " - // + "WHERE enrollment_id = ? AND outdatetime IS NULL " - // + "ORDER BY indatetime DESC LIMIT 1"; +// String sqlQuery = "UPDATE attendance SET outdatetime = ?, outby = ?, outphoto= ?, location = ?, appversion = ?, apptype = ? " +// + "WHERE enrollment_id = ? AND outdatetime IS NULL " +// + "ORDER BY indatetime DESC LIMIT 1"; String sqlQuery = "UPDATE attendance " + "SET outdatetime = ?, outby = ?, outphoto = ?, location = ?, appversion = ?, apptype = ? " + "WHERE enrollment_id = ? " + @@ -607,16 +607,16 @@ public class NULMOfficerActivity { 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 + // Mark On Duty (OD) even if no check-in - // String updateSql = "UPDATE attendance " + - // "SET outdatetime = DATE_ADD(indatetime, INTERVAL 8 HOUR) " + - // "WHERE enrollment_id = ? " + - // "AND outdatetime IS NULL " + - // "ORDER BY indatetime DESC " + - // "LIMIT 1"; + String updateSql = "UPDATE attendance " + + "SET outdatetime = DATE_ADD(indatetime, INTERVAL 8 HOUR) " + + "WHERE enrollment_id = ? " + + "AND outdatetime IS NULL " + + "ORDER BY indatetime DESC " + + "LIMIT 1"; - // int rows = jdbcNULMTemplate.update(updateSql, enrollId); + int rows = jdbcNULMTemplate.update(updateSql, enrollId); String sqlQuery = "INSERT INTO attendance (oddatetime, odby, enrollment_id, location, appversion, apptype) " + "VALUES (?, ?, ?, ?, ?, ?)"; @@ -636,14 +636,14 @@ public class NULMOfficerActivity { } else if ("leave".equalsIgnoreCase(action)) { // Mark Leave even if no check-in - // String updateSql = "UPDATE attendance " + - // "SET outdatetime = DATE_ADD(indatetime, INTERVAL 8 HOUR) " + - // "WHERE enrollment_id = ? " + - // "AND outdatetime IS NULL " + - // "ORDER BY indatetime DESC " + - // "LIMIT 1"; + String updateSql = "UPDATE attendance " + + "SET outdatetime = DATE_ADD(indatetime, INTERVAL 8 HOUR) " + + "WHERE enrollment_id = ? " + + "AND outdatetime IS NULL " + + "ORDER BY indatetime DESC " + + "LIMIT 1"; - // int rows = jdbcNULMTemplate.update(updateSql, enrollId); + int rows = jdbcNULMTemplate.update(updateSql, enrollId); String sqlQuery = "INSERT INTO attendance (leavedatetime, leaveby, enrollment_id, location, appversion, apptype) " + "VALUES (?, ?, ?, ?, ?, ?)";