@ -4,7 +4,8 @@ import java.time.LocalDateTime;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
import java.time.LocalDate ;
import java.util.HashMap ;
import javax.sql.DataSource ;
import javax.sql.DataSource ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
@ -26,7 +27,7 @@ public class SocialMediaService {
}
}
@Transactional
@Transactional
public int uploadComplaintDetailsInLogs ( Map < String , Object > details , String action , String remarks , int updated_agent ) {
public int uploadComplaintDetailsInLogs ( Map < String , Object > details , String action , String remarks , int updated_agent , String remainderDate ) {
/ / System . out . println ( "Complaint Details: " + details ) ;
/ / System . out . println ( "Complaint Details: " + details ) ;
/ / Extract other field values from complaintDetails
/ / Extract other field values from complaintDetails
String complaintNumber = details . get ( "complaintid" ) . toString ( ) ;
String complaintNumber = details . get ( "complaintid" ) . toString ( ) ;
@ -42,16 +43,22 @@ public class SocialMediaService {
String remarksfield = remarks ;
String remarksfield = remarks ;
String zone = details . get ( "Zone" ) . toString ( ) ;
String zone = details . get ( "Zone" ) . toString ( ) ;
int updated_by = updated_agent ;
int updated_by = updated_agent ;
String cur_status = details . get ( "currentStatus" ) . toString ( ) ;
String finalremainderDate = null ;
if ( ! remainderDate . isEmpty ( ) ) {
finalremainderDate = remainderDate ;
}
LocalDateTime currentDate = LocalDateTime . now ( ) ;
LocalDateTime currentDate = LocalDateTime . now ( ) ;
String query = "INSERT INTO gcc_1913_qaqc.social_media_completed (complaint_number,zone,complaint_date, complaint_person_name,remarks, "
String query = "INSERT INTO gcc_1913_qaqc.social_media_completed (complaint_number,zone,complaint_date, complaint_person_name,remarks, "
+ "complaint_mobilenumber, complaint_type, complaint_mode, department, official_name,official_mobilenum, call_status,created_date,updated_by) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)" ;
+ "complaint_mobilenumber, complaint_type, complaint_mode, department, official_name,official_mobilenum, call_status,created_date,updated_by,cur_status,remainder_date ) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?,?,? )" ;
int rowsAffected = jdbcTemplate . update ( query , complaintNumber , zone , complaintDate , personName , remarksfield ,
int rowsAffected = jdbcTemplate . update ( query , complaintNumber , zone , complaintDate , personName , remarksfield ,
personMobNo , cType , cMode , department , officialName , officialMobileNum , callStatus ,
personMobNo , cType , cMode , department , officialName , officialMobileNum , callStatus ,
currentDate , updated_by ) ;
currentDate , updated_by , cur_status , finalremainderDate ) ;
/ / System . out . println ( "Rows Inserted in table : " + rowsAffected ) ;
/ / System . out . println ( "Rows Inserted in table : " + rowsAffected ) ;
return rowsAffected ;
return rowsAffected ;
@ -59,7 +66,7 @@ public class SocialMediaService {
}
}
public List < Map < String , Object > > getdetails ( String formattedFromDate , String formattedToDate , String status , String zone ) {
public List < Map < String , Object > > getdetails ( String formattedFromDate , String formattedToDate , String status , String zone ) {
StringBuilder query = new StringBuilder ( "SELECT * FROM gcc_1913_qaqc.social_media_completed WHERE DATE(created_date) BETWEEN ? AND ? " ) ;
StringBuilder query = new StringBuilder ( "SELECT *,DATE_FORMAT(remainder_date, '%d/%m/%Y') as formatted_fdate FROM gcc_1913_qaqc.social_media_completed WHERE DATE(created_date) BETWEEN ? AND ? " ) ;
List < Object > params = new ArrayList < > ( ) ;
List < Object > params = new ArrayList < > ( ) ;
params . add ( formattedFromDate ) ;
params . add ( formattedFromDate ) ;
params . add ( formattedToDate ) ;
params . add ( formattedToDate ) ;
@ -74,15 +81,9 @@ public class SocialMediaService {
params . add ( status ) ;
params . add ( status ) ;
}
}
/ / Log the query and parameters for debugging
/ / System . out . println ( "Executing query: " + query . toString ( ) ) ;
/ / System . out . println ( "With parameters: " + params ) ;
/ / Execute the query
/ / Execute the query
List < Map < String , Object > > results = jdbcTemplate . queryForList ( query . toString ( ) , params . toArray ( ) ) ;
List < Map < String , Object > > results = jdbcTemplate . queryForList ( query . toString ( ) , params . toArray ( ) ) ;
/ / Log the results for debugging
/ / System . out . println ( "Query results: " + results ) ;
return results . isEmpty ( ) ? null : results ;
return results . isEmpty ( ) ? null : results ;
}
}
@ -100,6 +101,100 @@ public class SocialMediaService {
return erpUsername ;
return erpUsername ;
}
}
public List < Map < String , Object > > getA1dropdowns ( ) {
String sql = "SELECT * FROM call_status WHERE isactive=1 AND isdelete=0 AND call_category_id=5" ;
try {
return jdbcTemplate . queryForList ( sql ) ;
} catch ( Exception ex ) {
ex . printStackTrace ( ) ;
return new ArrayList < > ( ) ; / / return empty list on error
}
}
public List < Map < String , Object > > getA2dropdowns ( ) {
String sql = "SELECT * FROM call_status WHERE isactive=1 AND isdelete=0 AND call_category_id=6" ;
try {
return jdbcTemplate . queryForList ( sql ) ;
} catch ( Exception ex ) {
ex . printStackTrace ( ) ;
return new ArrayList < > ( ) ; / / return empty list on error
}
}
public List < Map < String , Object > > getfiltreddetails ( List < Map < String , Object > > details ) {
List < Map < String , Object > > followupData = getFollowupData ( ) ;
if ( followupData = = null | | followupData . isEmpty ( ) ) {
return details ;
}
LocalDate currentDate = LocalDate . now ( ) ;
/ / Store complaint_number - > followup row
Map < String , Map < String , Object > > followupMap = new HashMap < > ( ) ;
for ( Map < String , Object > followup : followupData ) {
String complaintNumber = String . valueOf ( followup . get ( "complaint_number" ) ) ;
followupMap . put ( complaintNumber , followup ) ;
}
List < Map < String , Object > > filteredDetails = new ArrayList < > ( ) ;
for ( Map < String , Object > detail : details ) {
String complaintNumber = String . valueOf ( detail . get ( "Complaint Number" ) ) ;
/ / If complaint not in followup table
if ( ! followupMap . containsKey ( complaintNumber ) ) {
filteredDetails . add ( detail ) ;
continue ;
}
Map < String , Object > followupRow = followupMap . get ( complaintNumber ) ;
String remainderDateStr = String . valueOf ( followupRow . get ( "remainder_date" ) ) ;
LocalDate remainderDate = LocalDate . parse ( remainderDateStr ) ;
/ / remainder_date < = current date
if ( ! remainderDate . isAfter ( currentDate ) ) {
/ / UPDATE is_processed = 0
Integer id = ( Integer ) followupRow . get ( "id" ) ;
updateFollowupProcessed ( id ) ;
filteredDetails . add ( detail ) ;
}
/ / ELSE :
/ / remainder_date > currentDate
/ / skip / eliminate from frontend
}
return filteredDetails ;
}
private void updateFollowupProcessed ( Integer id ) {
String sql =
"UPDATE social_media_completed " +
"SET is_processed = 0 " +
"WHERE id = ?" ;
jdbcTemplate . update ( sql , id ) ;
}
private List < Map < String , Object > > getFollowupData ( ) {
String sqlQuery = "select id, complaint_number,call_status, remainder_date from social_media_completed where is_processed=1 AND call_status='FOLLOWUP'" ;
return jdbcTemplate . queryForList ( sqlQuery ) ;
}
}
}