@ -25,6 +25,18 @@ public class AppUserService {
this . jdbcManpowerTemplate = new JdbcTemplate ( manpowerDataSource ) ;
this . jdbcManpowerTemplate = new JdbcTemplate ( manpowerDataSource ) ;
}
}
@PostConstruct
public void init ( ) {
try {
jdbcManpowerTemplate
. execute ( "ALTER TABLE app_user CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci" ) ;
System . out . println (
"Collation mismatch auto-resolved: app_user converted to utf8mb4_0900_ai_ci successfully." ) ;
} catch ( Exception e ) {
System . err . println ( "Note: Could not alter app_user collation automatically: " + e . getMessage ( ) ) ;
}
}
public Map < String , Object > authenticate ( String username , String password ) {
public Map < String , Object > authenticate ( String username , String password ) {
Map < String , Object > result = new HashMap < > ( ) ;
Map < String , Object > result = new HashMap < > ( ) ;
@ -106,8 +118,11 @@ public class AppUserService {
" COALESCE(des.File_no, '-') AS File_no, " +
" COALESCE(des.File_no, '-') AS File_no, " +
" COALESCE(des.work_order_issue_date, '-') AS work_order_issue_date, " +
" COALESCE(des.work_order_issue_date, '-') AS work_order_issue_date, " +
" COALESCE(des.work_order_end_date, '-') AS work_order_end_date, " +
" COALESCE(des.work_order_end_date, '-') AS work_order_end_date, " +
" des.file_path " +
" des.file_path, " +
" des.updated_at, " +
" COALESCE(u.usr_name, des.updated_by) AS updated_by_name " +
"FROM employee_workorder_details des " +
"FROM employee_workorder_details des " +
"LEFT JOIN app_user u ON (des.updated_by = CAST(u.usr_id AS CHAR) OR des.updated_by = u.usr_name) " +
"WHERE des.vid = ? AND des.isactive = 1 AND des.isdelete = 0 " +
"WHERE des.vid = ? AND des.isactive = 1 AND des.isdelete = 0 " +
"ORDER BY des.orderby, des.designation" ;
"ORDER BY des.orderby, des.designation" ;
try {
try {
@ -140,6 +155,7 @@ public class AppUserService {
return new ArrayList < > ( ) ;
return new ArrayList < > ( ) ;
}
}
}
}
public int getOverallTenderCount ( ) {
public int getOverallTenderCount ( ) {
String sql = "SELECT SUM(total_employees) FROM vendor_details WHERE isactive = 1 AND isdelete = 0" ;
String sql = "SELECT SUM(total_employees) FROM vendor_details WHERE isactive = 1 AND isdelete = 0" ;
try {
try {
@ -179,7 +195,7 @@ public class AppUserService {
}
}
public List < Map < String , Object > > getActiveDesignations ( ) {
public List < Map < String , Object > > getActiveDesignations ( ) {
String sql = "SELECT id, designation, File_no FROM employee_workorder_details WHERE isactive = 1 AND isdelete = 0 ORDER BY orderby, designation" ;
String sql = "SELECT id, designation, File_no, file_path FROM employee_workorder_details WHERE isactive = 1 AND isdelete = 0 ORDER BY orderby, designation" ;
try {
try {
return jdbcManpowerTemplate . queryForList ( sql ) ;
return jdbcManpowerTemplate . queryForList ( sql ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
@ -222,6 +238,8 @@ public class AppUserService {
" e.isdelete, " +
" e.isdelete, " +
" e.joined_date, " +
" e.joined_date, " +
" e.cdate, " +
" e.cdate, " +
" e.updated_at, " +
" COALESCE(u.usr_name, e.updated_by) AS updated_by_name, " +
" COALESCE(v.vendor_name, e.vendor_id) AS vendor_name, " +
" COALESCE(v.vendor_name, e.vendor_id) AS vendor_name, " +
" COALESCE(ut.usertype, e.user_type) AS user_type, " +
" COALESCE(ut.usertype, e.user_type) AS user_type, " +
" COALESCE(des.designation, e.designation) AS designation, " +
" COALESCE(des.designation, e.designation) AS designation, " +
@ -236,6 +254,8 @@ public class AppUserService {
+
+
"LEFT JOIN employee_location_details loc ON (e.location = CAST(loc.id AS CHAR) OR e.location = loc.location_name) "
"LEFT JOIN employee_location_details loc ON (e.location = CAST(loc.id AS CHAR) OR e.location = loc.location_name) "
+
+
"LEFT JOIN app_user u ON (e.updated_by = CAST(u.usr_id AS CHAR) OR e.updated_by = u.usr_name) "
+
"WHERE (e.vendor_id = ? OR e.vendor_id = ?) AND e.isactive = 1 AND e.isdelete = 0 " +
"WHERE (e.vendor_id = ? OR e.vendor_id = ?) AND e.isactive = 1 AND e.isdelete = 0 " +
"ORDER BY e.name" ;
"ORDER BY e.name" ;
try {
try {
@ -258,13 +278,15 @@ public class AppUserService {
" e.isdelete, " +
" e.isdelete, " +
" e.joined_date, " +
" e.joined_date, " +
" e.cdate, " +
" e.cdate, " +
" e.updated_at, " +
" COALESCE(u.usr_name, e.updated_by) AS updated_by_name, " +
" COALESCE(v.vendor_name, e.vendor_id) AS vendor_name, " +
" COALESCE(v.vendor_name, e.vendor_id) AS vendor_name, " +
" COALESCE(ut.usertype, e.user_type) AS user_type, " +
" COALESCE(ut.usertype, e.user_type) AS user_type, " +
" COALESCE(des.designation, e.designation) AS designation, " +
" COALESCE(des.designation, e.designation) AS designation, " +
" COALESCE(loc.location_name, e.location) AS location, " +
" COALESCE(loc.location_name, e.location) AS location, " +
" COALESCE(des.File_no, '-') AS work_order, " +
" COALESCE(des.File_no, '-') AS work_order, " +
" COALESCE(des.work_order_issue_date, '-') AS issue_date, " +
" COALESCE(des.work_order_end_date, '-') AS end_date " +
" COALESCE(des.work_order_issue_date, '-') AS work_order_ issue_date, " +
" COALESCE(des.work_order_end_date, '-') AS work_order_ end_date " +
"FROM employee_details e " +
"FROM employee_details e " +
"LEFT JOIN vendor_details v ON (e.vendor_id = CAST(v.id AS CHAR) OR e.vendor_id = v.vendor_name) " +
"LEFT JOIN vendor_details v ON (e.vendor_id = CAST(v.id AS CHAR) OR e.vendor_id = v.vendor_name) " +
"LEFT JOIN user_type_details ut ON (e.user_type = CAST(ut.id AS CHAR) OR e.user_type = ut.usertype) " +
"LEFT JOIN user_type_details ut ON (e.user_type = CAST(ut.id AS CHAR) OR e.user_type = ut.usertype) " +
@ -272,6 +294,7 @@ public class AppUserService {
+
+
"LEFT JOIN employee_location_details loc ON (e.location = CAST(loc.id AS CHAR) OR e.location = loc.location_name) "
"LEFT JOIN employee_location_details loc ON (e.location = CAST(loc.id AS CHAR) OR e.location = loc.location_name) "
+
+
"LEFT JOIN app_user u ON (e.updated_by = CAST(u.usr_id AS CHAR) OR e.updated_by = u.usr_name) " +
"WHERE e.isactive = 1 AND e.isdelete = 0 " +
"WHERE e.isactive = 1 AND e.isdelete = 0 " +
"ORDER BY e.name" ;
"ORDER BY e.name" ;
try {
try {
@ -298,7 +321,7 @@ public class AppUserService {
return null ;
return null ;
}
}
public boolean addEmployee ( Map < String , Object > emp ) {
public boolean addEmployee ( Map < String , Object > emp , String updatedByUsername ) {
String checkSql = "SELECT COUNT(*) FROM employee_details WHERE emp_code = ? AND isdelete = 0" ;
String checkSql = "SELECT COUNT(*) FROM employee_details WHERE emp_code = ? AND isdelete = 0" ;
try {
try {
Integer count = jdbcManpowerTemplate . queryForObject ( checkSql , Integer . class , emp . get ( "emp_code" ) ) ;
Integer count = jdbcManpowerTemplate . queryForObject ( checkSql , Integer . class , emp . get ( "emp_code" ) ) ;
@ -350,9 +373,9 @@ public class AppUserService {
}
}
}
}
String sql = "INSERT INTO employee_details (emp_code, name, email, mobile, user_type, designation, location, vendor_id, joined_date, cdate, isactive, isdelete) "
String sql = "INSERT INTO employee_details (emp_code, name, email, mobile, user_type, designation, location, vendor_id, joined_date, cdate, updated_at, updated_by, isactive, isdelete) "
+
+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), 1, 0)" ;
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW(), ?, 1, 0)" ;
try {
try {
int updateRows = jdbcManpowerTemplate . update ( sql ,
int updateRows = jdbcManpowerTemplate . update ( sql ,
emp . get ( "emp_code" ) ,
emp . get ( "emp_code" ) ,
@ -363,7 +386,8 @@ public class AppUserService {
emp . get ( "designation" ) ,
emp . get ( "designation" ) ,
emp . get ( "location" ) ,
emp . get ( "location" ) ,
emp . get ( "vendor_id" ) ,
emp . get ( "vendor_id" ) ,
emp . get ( "joined_date" ) ) ;
emp . get ( "joined_date" ) ,
getUserIdByName ( updatedByUsername ) ) ;
if ( updateRows > 0 ) {
if ( updateRows > 0 ) {
recalculateDesignationManpower ( String . valueOf ( emp . get ( "designation" ) ) ,
recalculateDesignationManpower ( String . valueOf ( emp . get ( "designation" ) ) ,
String . valueOf ( emp . get ( "vendor_id" ) ) ) ;
String . valueOf ( emp . get ( "vendor_id" ) ) ) ;
@ -376,9 +400,9 @@ public class AppUserService {
}
}
}
}
public boolean updateEmployee ( Map < String , Object > emp ) {
public boolean updateEmployee ( Map < String , Object > emp , String updatedByUsername ) {
String empCode = ( String ) emp . get ( "emp_code" ) ;
String empCode = ( String ) emp . get ( "emp_code" ) ;
String selectSql = "SELECT emp_code, name, email, mobile, user_type, designation, location, vendor_id, isactive, isdelete "
String selectSql = "SELECT emp_code, name, email, mobile, user_type, designation, location, vendor_id, isactive, isdelete, updated_by, cdate "
+
+
"FROM employee_details WHERE emp_code = ? AND isdelete = 0" ;
"FROM employee_details WHERE emp_code = ? AND isdelete = 0" ;
List < Map < String , Object > > oldList ;
List < Map < String , Object > > oldList ;
@ -438,9 +462,9 @@ public class AppUserService {
}
}
}
}
String historySql = "INSERT INTO employee_details_update_history (emp_code, name, email, mobile, user_type, designation, location, vendor_id, updated_date, isactive, isdelete) "
String historySql = "INSERT INTO employee_details_update_history (emp_code, name, email, mobile, user_type, designation, location, vendor_id, updated_date, isactive, isdelete, updated_by, cdate ) "
+
+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?, ?)" ;
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?, ?, ?, ? )" ;
try {
try {
jdbcManpowerTemplate . update ( historySql ,
jdbcManpowerTemplate . update ( historySql ,
old . get ( "emp_code" ) ,
old . get ( "emp_code" ) ,
@ -452,13 +476,15 @@ public class AppUserService {
old . get ( "location" ) ,
old . get ( "location" ) ,
old . get ( "vendor_id" ) ,
old . get ( "vendor_id" ) ,
old . get ( "isactive" ) ,
old . get ( "isactive" ) ,
old . get ( "isdelete" ) ) ;
old . get ( "isdelete" ) ,
old . get ( "updated_by" ) ,
old . get ( "cdate" ) ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
System . err . println ( "Error inserting history record: " + e . getMessage ( ) ) ;
System . err . println ( "Error inserting history record: " + e . getMessage ( ) ) ;
return false ;
return false ;
}
}
String updateSql = "UPDATE employee_details SET name = ?, email = ?, mobile = ?, user_type = ?, designation = ?, location = ?, vendor_id = ?, joined_date = ? "
String updateSql = "UPDATE employee_details SET name = ?, email = ?, mobile = ?, user_type = ?, designation = ?, location = ?, vendor_id = ?, joined_date = ?, updated_at = NOW(), updated_by = ? "
+
+
"WHERE emp_code = ? AND isdelete = 0" ;
"WHERE emp_code = ? AND isdelete = 0" ;
try {
try {
@ -471,6 +497,7 @@ public class AppUserService {
emp . get ( "location" ) ,
emp . get ( "location" ) ,
emp . get ( "vendor_id" ) ,
emp . get ( "vendor_id" ) ,
emp . get ( "joined_date" ) ,
emp . get ( "joined_date" ) ,
getUserIdByName ( updatedByUsername ) ,
empCode ) ;
empCode ) ;
if ( rows > 0 ) {
if ( rows > 0 ) {
recalculateDesignationManpower ( String . valueOf ( old . get ( "designation" ) ) ,
recalculateDesignationManpower ( String . valueOf ( old . get ( "designation" ) ) ,
@ -500,8 +527,10 @@ public class AppUserService {
"FROM employee_details_update_history h " +
"FROM employee_details_update_history h " +
"LEFT JOIN vendor_details v ON (h.vendor_id = CAST(v.id AS CHAR) OR h.vendor_id = v.vendor_name) " +
"LEFT JOIN vendor_details v ON (h.vendor_id = CAST(v.id AS CHAR) OR h.vendor_id = v.vendor_name) " +
"LEFT JOIN user_type_details ut ON (h.user_type = CAST(ut.id AS CHAR) OR h.user_type = ut.usertype) " +
"LEFT JOIN user_type_details ut ON (h.user_type = CAST(ut.id AS CHAR) OR h.user_type = ut.usertype) " +
"LEFT JOIN employee_workorder_details des ON (h.designation = CAST(des.id AS CHAR) OR h.designation = des.designation) " +
"LEFT JOIN employee_location_details loc ON (h.location = CAST(loc.id AS CHAR) OR h.location = loc.location_name) " +
"LEFT JOIN employee_workorder_details des ON (h.designation = CAST(des.id AS CHAR) OR h.designation = des.designation) "
+
"LEFT JOIN employee_location_details loc ON (h.location = CAST(loc.id AS CHAR) OR h.location = loc.location_name) "
+
"WHERE h.emp_code = ? " +
"WHERE h.emp_code = ? " +
"ORDER BY h.updated_date DESC" ;
"ORDER BY h.updated_date DESC" ;
try {
try {
@ -566,7 +595,8 @@ public class AppUserService {
}
}
public boolean addVendorWorkOrder ( String vendorId , String description , String contractorName , String fileNo ,
public boolean addVendorWorkOrder ( String vendorId , String description , String contractorName , String fileNo ,
String subject , String issueDate , String endDate , String totalEmployees , Integer orderby ) {
String subject , String issueDate , String endDate , String totalEmployees , Integer orderby , String filePath ,
String updatedByUsername ) {
if ( orderby = = null ) {
if ( orderby = = null ) {
try {
try {
Integer maxOrder = jdbcManpowerTemplate
Integer maxOrder = jdbcManpowerTemplate
@ -576,9 +606,9 @@ public class AppUserService {
orderby = 1 ;
orderby = 1 ;
}
}
}
}
String sql = "INSERT INTO employee_workorder_details (designation, vid, tender_manpower_designation_wise, available_manpower, vacant_count, contract_name, File_no, subject, work_order_issue_date, work_order_end_date, orderby, cdate, isactive, isdelete) "
String sql = "INSERT INTO employee_workorder_details (designation, vid, tender_manpower_designation_wise, available_manpower, vacant_count, contract_name, File_no, subject, work_order_issue_date, work_order_end_date, orderby, cdate, updated_at, updated_by, isactive, isdelete, file_path ) "
+
+
"VALUES (?, ?, ?, '0', ?, ?, ?, ?, ?, ?, ?, NOW(), 1, 0)" ;
"VALUES (?, ?, ?, '0', ?, ?, ?, ?, ?, ?, ?, NOW(), NOW(), ?, 1, 0, ? )" ;
try {
try {
int rows = jdbcManpowerTemplate . update ( sql ,
int rows = jdbcManpowerTemplate . update ( sql ,
subject , / / designation
subject , / / designation
@ -590,7 +620,9 @@ public class AppUserService {
subject , / / subject
subject , / / subject
issueDate , / / work_order_issue_date
issueDate , / / work_order_issue_date
endDate , / / work_order_end_date
endDate , / / work_order_end_date
orderby / / orderby
orderby , / / orderby
getUserIdByName ( updatedByUsername ) , / / updated_by
filePath / / file_path
) ;
) ;
if ( rows > 0 ) {
if ( rows > 0 ) {
/ / Recalculate designation manpower ( handles available_manpower and
/ / Recalculate designation manpower ( handles available_manpower and
@ -682,7 +714,7 @@ public class AppUserService {
}
}
}
}
public boolean deleteEmployee ( String empCode ) {
public boolean deleteEmployee ( String empCode , String updatedByUsername ) {
String selectSql = "SELECT designation, vendor_id FROM employee_details WHERE emp_code = ? AND isdelete = 0" ;
String selectSql = "SELECT designation, vendor_id FROM employee_details WHERE emp_code = ? AND isdelete = 0" ;
try {
try {
List < Map < String , Object > > list = jdbcManpowerTemplate . queryForList ( selectSql , empCode ) ;
List < Map < String , Object > > list = jdbcManpowerTemplate . queryForList ( selectSql , empCode ) ;
@ -693,8 +725,8 @@ public class AppUserService {
String designation = String . valueOf ( emp . get ( "designation" ) ) ;
String designation = String . valueOf ( emp . get ( "designation" ) ) ;
String vendorId = String . valueOf ( emp . get ( "vendor_id" ) ) ;
String vendorId = String . valueOf ( emp . get ( "vendor_id" ) ) ;
String updateSql = "UPDATE employee_details SET isactive = 0, isdelete = 1 WHERE emp_code = ?" ;
int rows = jdbcManpowerTemplate . update ( updateSql , empCode ) ;
String updateSql = "UPDATE employee_details SET isactive = 0, isdelete = 1, updated_at = NOW(), updated_by = ? WHERE emp_code = ?" ;
int rows = jdbcManpowerTemplate . update ( updateSql , getUserIdByName ( updatedByUsername ) , empCode ) ;
if ( rows > 0 ) {
if ( rows > 0 ) {
recalculateDesignationManpower ( designation , vendorId ) ;
recalculateDesignationManpower ( designation , vendorId ) ;
return true ;
return true ;
@ -757,6 +789,8 @@ public class AppUserService {
" e.isdelete, " +
" e.isdelete, " +
" e.joined_date, " +
" e.joined_date, " +
" e.cdate, " +
" e.cdate, " +
" e.updated_at, " +
" COALESCE(u.usr_name, e.updated_by) AS updated_by_name, " +
" COALESCE(v.vendor_name, e.vendor_id) AS vendor_name, " +
" COALESCE(v.vendor_name, e.vendor_id) AS vendor_name, " +
" COALESCE(ut.usertype, e.user_type) AS user_type, " +
" COALESCE(ut.usertype, e.user_type) AS user_type, " +
" COALESCE(des.designation, e.designation) AS designation, " +
" COALESCE(des.designation, e.designation) AS designation, " +
@ -769,6 +803,8 @@ public class AppUserService {
+
+
"LEFT JOIN employee_location_details loc ON (e.location = CAST(loc.id AS CHAR) OR e.location = loc.location_name) "
"LEFT JOIN employee_location_details loc ON (e.location = CAST(loc.id AS CHAR) OR e.location = loc.location_name) "
+
+
"LEFT JOIN app_user u ON (e.updated_by = CAST(u.usr_id AS CHAR) OR e.updated_by = u.usr_name) "
+
"WHERE e.vendor_id = ? OR e.vendor_id = ? " +
"WHERE e.vendor_id = ? OR e.vendor_id = ? " +
"ORDER BY e.name" ;
"ORDER BY e.name" ;
try {
try {
@ -779,7 +815,7 @@ public class AppUserService {
}
}
}
}
public boolean restoreEmployee ( String empCode ) {
public boolean restoreEmployee ( String empCode , String updatedByUsername ) {
String selectSql = "SELECT designation, vendor_id FROM employee_details WHERE emp_code = ?" ;
String selectSql = "SELECT designation, vendor_id FROM employee_details WHERE emp_code = ?" ;
try {
try {
List < Map < String , Object > > list = jdbcManpowerTemplate . queryForList ( selectSql , empCode ) ;
List < Map < String , Object > > list = jdbcManpowerTemplate . queryForList ( selectSql , empCode ) ;
@ -790,8 +826,8 @@ public class AppUserService {
String designation = String . valueOf ( emp . get ( "designation" ) ) ;
String designation = String . valueOf ( emp . get ( "designation" ) ) ;
String vendorId = String . valueOf ( emp . get ( "vendor_id" ) ) ;
String vendorId = String . valueOf ( emp . get ( "vendor_id" ) ) ;
String updateSql = "UPDATE employee_details SET isactive = 1, isdelete = 0 WHERE emp_code = ?" ;
int rows = jdbcManpowerTemplate . update ( updateSql , empCode ) ;
String updateSql = "UPDATE employee_details SET isactive = 1, isdelete = 0, updated_at = NOW(), updated_by = ? WHERE emp_code = ?" ;
int rows = jdbcManpowerTemplate . update ( updateSql , getUserIdByName ( updatedByUsername ) , empCode ) ;
if ( rows > 0 ) {
if ( rows > 0 ) {
recalculateDesignationManpower ( designation , vendorId ) ;
recalculateDesignationManpower ( designation , vendorId ) ;
return true ;
return true ;
@ -814,6 +850,8 @@ public class AppUserService {
" e.isdelete, " +
" e.isdelete, " +
" e.joined_date, " +
" e.joined_date, " +
" e.cdate, " +
" e.cdate, " +
" e.updated_at, " +
" COALESCE(u.usr_name, e.updated_by) AS updated_by_name, " +
" COALESCE(v.vendor_name, e.vendor_id) AS vendor_name, " +
" COALESCE(v.vendor_name, e.vendor_id) AS vendor_name, " +
" COALESCE(ut.usertype, e.user_type) AS user_type, " +
" COALESCE(ut.usertype, e.user_type) AS user_type, " +
" COALESCE(des.designation, e.designation) AS designation, " +
" COALESCE(des.designation, e.designation) AS designation, " +
@ -826,6 +864,8 @@ public class AppUserService {
+
+
"LEFT JOIN employee_location_details loc ON (e.location = CAST(loc.id AS CHAR) OR e.location = loc.location_name) "
"LEFT JOIN employee_location_details loc ON (e.location = CAST(loc.id AS CHAR) OR e.location = loc.location_name) "
+
+
"LEFT JOIN app_user u ON (e.updated_by = CAST(u.usr_id AS CHAR) OR e.updated_by = u.usr_name) "
+
"ORDER BY e.name" ;
"ORDER BY e.name" ;
try {
try {
return jdbcManpowerTemplate . queryForList ( sql ) ;
return jdbcManpowerTemplate . queryForList ( sql ) ;
@ -834,4 +874,67 @@ public class AppUserService {
return new ArrayList < > ( ) ;
return new ArrayList < > ( ) ;
}
}
}
}
public String getUserIdByName ( String username ) {
if ( username = = null | | username . trim ( ) . isEmpty ( ) )
return null ;
try {
Integer id = jdbcManpowerTemplate . queryForObject (
"SELECT usr_id FROM app_user WHERE usr_name = ?" , Integer . class , username ) ;
return id ! = null ? String . valueOf ( id ) : null ;
} catch ( Exception e ) {
System . err . println ( "Error resolving user ID for name " + username + ": " + e . getMessage ( ) ) ;
return null ;
}
}
public boolean deleteWorkOrder ( String workOrderId , String updatedByUsername ) {
try {
/ / 1 . Get the details of the work order before deleting
String selectSql = "SELECT vid, tender_manpower_designation_wise, designation FROM employee_workorder_details WHERE id = ? AND isdelete = 0" ;
List < Map < String , Object > > list = jdbcManpowerTemplate . queryForList ( selectSql , workOrderId ) ;
if ( list = = null | | list . isEmpty ( ) ) {
return false ;
}
Map < String , Object > wo = list . get ( 0 ) ;
String vendorId = String . valueOf ( wo . get ( "vid" ) ) ;
String tenderStr = ( String ) wo . get ( "tender_manpower_designation_wise" ) ;
String designationName = ( String ) wo . get ( "designation" ) ;
String userId = getUserIdByName ( updatedByUsername ) ;
/ / 2 . Soft - delete the work order in employee_workorder_details , reset counts and
/ / record updater
String deleteSql = "UPDATE employee_workorder_details SET isactive = 0, isdelete = 1, available_manpower = '0', vacant_count = tender_manpower_designation_wise, updated_at = NOW(), updated_by = ? WHERE id = ?" ;
int rows = jdbcManpowerTemplate . update ( deleteSql , userId , workOrderId ) ;
if ( rows > 0 ) {
/ / 3 . Subtract its tender count from vendor ' s total_employees in vendor_details
int tenderCount = 0 ;
if ( tenderStr ! = null ) {
try {
tenderCount = Integer . parseInt ( tenderStr . trim ( ) ) ;
} catch ( NumberFormatException ignored ) {
}
}
if ( tenderCount > 0 ) {
updateVendorTotalEmployees ( vendorId , - tenderCount ) ;
}
/ / 4 . Soft - delete employees under this designation / work order for this vendor
/ / and record updater
String updateEmployeesSql = "UPDATE employee_details SET isactive = 0, isdelete = 1, updated_at = NOW(), updated_by = ? "
+
"WHERE (vendor_id = ? OR vendor_id = (SELECT vendor_name FROM vendor_details WHERE id = ?)) " +
" AND (designation = ? OR designation = ?)" ;
jdbcManpowerTemplate . update ( updateEmployeesSql , userId , vendorId , vendorId , workOrderId ,
designationName ) ;
return true ;
}
} catch ( Exception e ) {
System . err . println ( "Error deleting work order: " + e . getMessage ( ) ) ;
}
return false ;
}
}
}