8 changed files with 386 additions and 2 deletions
-
50src/main/java/com/gcc/erppostdata/common/MySchduler.java
-
13src/main/java/com/gcc/erppostdata/config/AppConfig.java
-
14src/main/java/com/gcc/erppostdata/config/DatabaseConfig.java
-
182src/main/java/com/gcc/erppostdata/penalty_pos/PenaltyPosPostData.java
-
55src/main/java/com/gcc/erppostdata/penalty_pos/PenaltyPosQueryBank.java
-
66src/main/java/com/gcc/erppostdata/repo/PenaltyPosLogRepo.java
-
4src/main/resources/application-dev.properties
-
2src/main/resources/application-prod.properties
@ -0,0 +1,182 @@ |
|||
package com.gcc.erppostdata.penalty_pos; |
|||
|
|||
import java.io.BufferedReader; |
|||
import java.io.InputStreamReader; |
|||
import java.net.HttpURLConnection; |
|||
import java.net.URL; |
|||
import java.net.URLEncoder; |
|||
import java.time.LocalDate; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.TreeMap; |
|||
|
|||
import javax.sql.DataSource; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Qualifier; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import com.fasterxml.jackson.core.JsonProcessingException; |
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import com.gcc.erppostdata.config.AppConfig; |
|||
import com.gcc.erppostdata.repo.PenaltyPosLogRepo; |
|||
|
|||
@Component |
|||
public class PenaltyPosPostData { |
|||
|
|||
@Autowired |
|||
private AppConfig appConfig; |
|||
|
|||
@Autowired |
|||
private PenaltyPosLogRepo penaltyPosLogRepo; |
|||
|
|||
private JdbcTemplate jdbcTemplate; |
|||
|
|||
@Autowired |
|||
public void setDataSource(@Qualifier("mysqlPenaltyPosDataSource") DataSource dataSource) { |
|||
this.jdbcTemplate = new JdbcTemplate(dataSource); |
|||
} |
|||
|
|||
public void fetchpenaltyposData(String sql, String id) { |
|||
System.out.println("SQL: " + sql); |
|||
|
|||
List<Map<String, Object>> results = jdbcTemplate.queryForList(sql); |
|||
List<Map<String, Object>> swimDataList = new ArrayList<>(); |
|||
|
|||
System.out.println("Records fetched for penalty pos: " + results.size()); |
|||
|
|||
for (Map<String, Object> row : results) { |
|||
try { |
|||
Map<String, Object> data = new TreeMap<>(); |
|||
|
|||
// Safe value extraction |
|||
String bookingId = row.get("id") != null ? row.get("id").toString() : ""; |
|||
String paymentId = row.get("txnRefNo") != null ? row.get("txnRefNo").toString() : ""; |
|||
String paymentDate = row.get("txnDate") != null ? row.get("txnDate").toString() : ""; |
|||
String name = row.get("violator_name") != null ? row.get("violator_name").toString() : ""; |
|||
String mobile = row.get("violator_phone") != null ? row.get("violator_phone").toString() : ""; |
|||
String amountStr = row.get("fine_amount") != null ? row.get("fine_amount").toString() : "0"; |
|||
String orderid = row.get("orderid") != null ? row.get("orderid").toString() : ""; |
|||
|
|||
String categoryId = row.get("category_id") != null ? row.get("category_id").toString(): "0"; |
|||
|
|||
String categoryErpcode=row.get("category_erpcode") != null ? row.get("category_erpcode").toString(): "0"; |
|||
|
|||
double amount = 0; |
|||
try { |
|||
amount = Double.parseDouble(amountStr); |
|||
} catch (NumberFormatException e) { |
|||
System.err.println("Invalid amount for Id: " + bookingId); |
|||
} |
|||
|
|||
String assessmentNo = LocalDate.now().getYear()+"/"+categoryId + "/PTYPOS/"+categoryErpcode+"/" + bookingId; |
|||
|
|||
data.put("serviceId", "getOtherCollection"); |
|||
data.put("COLLECTION_TYPE", "Fine Collection"); |
|||
data.put("TOTALTRANSACTIONCODE", "450320225"); // 450320225 |
|||
data.put("ASSESSMENTNO", assessmentNo); |
|||
data.put("UNIQUERECEIPTID", bookingId); |
|||
data.put("TRANSACTIONNO", orderid); |
|||
data.put("TRANSACTIONREFNO", paymentId); |
|||
data.put("TRANSACTIONDATE", paymentDate); |
|||
data.put("TOTALTRANSACTIONAMOUNT", amount); |
|||
data.put("MSTRCODEONE", categoryErpcode); |
|||
data.put("SPLITAMOUNTONE", amountStr); |
|||
data.put("PARTYNAME", name); |
|||
data.put("PARTYMOBILE", mobile); |
|||
data.put("PARTYADDRESS", "NA"); |
|||
data.put("bookingId", bookingId); |
|||
|
|||
postDataToERP(data, id); |
|||
|
|||
} catch (Exception e) { |
|||
System.err.println("Error processing row: " + row); |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private void postDataToERP(Map<String, Object> data, String id) { |
|||
try { |
|||
StringBuilder encodedUrl = new StringBuilder(appConfig.getErpUrl()); |
|||
boolean firstParam = true; |
|||
|
|||
for (Map.Entry<String, Object> entry : data.entrySet()) { |
|||
if (!firstParam) encodedUrl.append("&"); |
|||
firstParam = false; |
|||
String key = URLEncoder.encode(entry.getKey(), "UTF-8"); |
|||
String value = URLEncoder.encode(String.valueOf(entry.getValue()), "UTF-8"); |
|||
encodedUrl.append(key).append("=").append(value); |
|||
} |
|||
|
|||
String finalUrl = encodedUrl.toString(); |
|||
System.out.println("Final Encoded URL: " + finalUrl); |
|||
|
|||
HttpURLConnection connection = (HttpURLConnection) new URL(finalUrl).openConnection(); |
|||
connection.setRequestMethod("GET"); |
|||
int responseCode = connection.getResponseCode(); |
|||
System.out.println("Response Code: " + responseCode); |
|||
|
|||
StringBuilder response = new StringBuilder(); |
|||
BufferedReader in = new BufferedReader(new InputStreamReader( |
|||
responseCode == 200 ? connection.getInputStream() : connection.getErrorStream() |
|||
)); |
|||
String inputLine; |
|||
while ((inputLine = in.readLine()) != null) response.append(inputLine); |
|||
in.close(); |
|||
|
|||
System.out.println("ERP Response: " + response); |
|||
|
|||
if (id != null) { |
|||
updateLog(data, response, id); |
|||
} else { |
|||
saveLog(data, response); |
|||
} |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
private void saveLog(Map<String, Object> map, StringBuilder response) throws JsonProcessingException { |
|||
logToRepo(map, response); |
|||
} |
|||
|
|||
private void updateLog(Map<String, Object> map, StringBuilder response, String id) throws JsonProcessingException { |
|||
logToRepo(map, response, id); |
|||
} |
|||
|
|||
private void logToRepo(Map<String, Object> map, StringBuilder response) throws JsonProcessingException { |
|||
logToRepo(map, response, null); |
|||
} |
|||
|
|||
private void logToRepo(Map<String, Object> map, StringBuilder response, String id) throws JsonProcessingException { |
|||
String statusCode = "0"; |
|||
if (response != null) { |
|||
ObjectMapper objectMapper = new ObjectMapper(); |
|||
Map<String, Object> res = objectMapper.readValue(response.toString(), Map.class); |
|||
String msg = String.valueOf(res.get("Message")); |
|||
String status = String.valueOf(res.getOrDefault("ResultStatus", "")); |
|||
|
|||
if ("Connection Failure".equals(msg)) { |
|||
statusCode = "2"; |
|||
} else if ("Already Updated this collection".equals(msg) && "false".equals(status)) { |
|||
statusCode = "1"; |
|||
} else if ("Failure".equals(msg) && "false".equals(status)) { |
|||
statusCode = "2"; |
|||
} else if ("true".equals(status)) { |
|||
statusCode = "1"; |
|||
} |
|||
} |
|||
|
|||
map.put("status", statusCode); |
|||
map.put("response", response.toString()); |
|||
|
|||
if (id != null) { |
|||
penaltyPosLogRepo.updateLog(statusCode, response.toString(), id); |
|||
} else { |
|||
penaltyPosLogRepo.insert(map); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
package com.gcc.erppostdata.penalty_pos; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
@Service |
|||
public class PenaltyPosQueryBank { |
|||
|
|||
@Autowired |
|||
private PenaltyPosPostData PenaltyPosPostData; |
|||
|
|||
public void PushAllData() { |
|||
String sql = "SELECT pc.id, pc.category_id, pcat.name AS category_name, pcat.erpcode AS category_erpcode," |
|||
+ " pcat.isactive AS cat_isactive, pc.challan_by, pc.challan_date, pc.status, pc.violator_name," |
|||
+ " pc.violator_phone, pc.violator_company, pc.fine_amount, pc.orderid, bt.txnid, DATE_FORMAT(bt.txnDate, '%d/%m/%Y') AS txnDate, bt.txnRefNo " |
|||
+ " FROM penalty_challan pc " |
|||
+ " INNER JOIN bank_transactions bt ON pc.orderid COLLATE utf8mb4_general_ci = bt.txnid COLLATE utf8mb4_general_ci" |
|||
+ " LEFT JOIN penalty_category pcat ON pc.category_id = pcat.id WHERE pc.status = 'Transaction success' AND pc.challan_date >= '2026-04-01' AND bt.txnRefNo IS NOT NULL AND TRIM(bt.txnRefNo) <> '' AND pcat.erpcode<>000" |
|||
+ " ORDER BY pc.id ASC"; |
|||
|
|||
PenaltyPosPostData.fetchpenaltyposData(sql, null); |
|||
} |
|||
|
|||
public void hourlyPushData(int lastId) { |
|||
|
|||
String sql = "SELECT pc.id, pc.category_id, pcat.name AS category_name, pcat.erpcode AS category_erpcode," |
|||
+ " pcat.isactive AS cat_isactive, pc.challan_by, pc.challan_date, pc.status, pc.violator_name," |
|||
+ " pc.violator_phone, pc.violator_company, pc.fine_amount, pc.orderid, bt.txnid,DATE_FORMAT(bt.txnDate, '%d/%m/%Y') AS txnDate, bt.txnRefNo " |
|||
+ " FROM penalty_challan pc " |
|||
+ " INNER JOIN bank_transactions bt ON pc.orderid COLLATE utf8mb4_general_ci = bt.txnid COLLATE utf8mb4_general_ci" |
|||
+ " LEFT JOIN penalty_category pcat ON pc.category_id = pcat.id WHERE pc.id > "+ lastId +" AND pc.status = 'Transaction success' AND pc.challan_date >= '2026-04-01' " |
|||
+ " AND bt.txnRefNo IS NOT NULL AND TRIM(bt.txnRefNo) <> '' AND pcat.erpcode<>000" |
|||
+ " ORDER BY pc.id ASC LIMIT 1000 "; |
|||
|
|||
PenaltyPosPostData.fetchpenaltyposData(sql, null); |
|||
|
|||
} |
|||
|
|||
public void resendPushData(String uniqueId, String id) { |
|||
|
|||
String sql = "SELECT pc.id, pc.category_id, pcat.name AS category_name, pcat.erpcode AS category_erpcode," |
|||
+ " pcat.isactive AS cat_isactive, pc.challan_by, pc.challan_date, pc.status, pc.violator_name," |
|||
+ " pc.violator_phone, pc.violator_company, pc.fine_amount, pc.orderid, bt.txnid, DATE_FORMAT(bt.txnDate, '%d/%m/%Y') AS txnDate, bt.txnRefNo " |
|||
+ " FROM penalty_challan pc " |
|||
+ " INNER JOIN bank_transactions bt ON pc.orderid COLLATE utf8mb4_general_ci = bt.txnid COLLATE utf8mb4_general_ci" |
|||
+ " LEFT JOIN penalty_category pcat ON pc.category_id = pcat.id" |
|||
+ " WHERE pc.id="+uniqueId+" AND pc.status = 'Transaction success' AND pc.challan_date >= '2026-04-01' AND bt.txnRefNo IS NOT NULL AND TRIM(bt.txnRefNo) <> '' AND pcat.erpcode<>000 " |
|||
+ " ORDER BY pc.id ASC"; |
|||
|
|||
|
|||
PenaltyPosPostData.fetchpenaltyposData(sql, id); |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,66 @@ |
|||
package com.gcc.erppostdata.repo; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
import javax.sql.DataSource; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Qualifier; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
import org.springframework.stereotype.Repository; |
|||
|
|||
@Repository |
|||
public class PenaltyPosLogRepo { |
|||
|
|||
@Autowired |
|||
private JdbcTemplate jdbcTemplate; |
|||
|
|||
@Autowired |
|||
public void setDataSource(@Qualifier("mysqlerpPostData") DataSource dataSource) { |
|||
this.jdbcTemplate = new JdbcTemplate(dataSource); |
|||
} |
|||
|
|||
public int insert(Map<String, Object> data) { |
|||
String sql = "INSERT INTO pos_penalty_post_data (" + |
|||
"mobile, assessment_no, collection_type, mstr_code_one, split_amount_one, " + |
|||
"total_transaction_amount, total_transaction_code, transaction_date, " + |
|||
"transaction_no, transaction_ref_no, unique_receipt_id, booking_id, " + |
|||
"user_name, status, response) " + |
|||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; |
|||
|
|||
return jdbcTemplate.update(sql, |
|||
data.get("PARTYMOBILE"), |
|||
data.get("ASSESSMENTNO"), |
|||
data.get("COLLECTION_TYPE"), |
|||
data.get("MSTRCODEONE"), |
|||
data.get("SPLITAMOUNTONE"), |
|||
data.get("TOTALTRANSACTIONAMOUNT"), |
|||
data.get("TOTALTRANSACTIONCODE"), |
|||
data.get("TRANSACTIONDATE"), |
|||
data.get("TRANSACTIONNO"), |
|||
data.get("TRANSACTIONREFNO"), |
|||
data.get("UNIQUERECEIPTID"), |
|||
data.get("UNIQUERECEIPTID"), |
|||
data.get("PARTYNAME"), |
|||
data.get("status"), |
|||
data.get("response") |
|||
); |
|||
} |
|||
|
|||
|
|||
public int updateLog(String status, String response, String id) { |
|||
String sql = "UPDATE pos_penalty_post_data SET status = ?, response = ? WHERE id = ?"; |
|||
return jdbcTemplate.update(sql, status, response, id); |
|||
} |
|||
|
|||
public List<Map<String, Object>> getDataByStatus() { |
|||
String sql = "SELECT * FROM pos_penalty_post_data WHERE status in (0,2) LIMIT 1000"; |
|||
return jdbcTemplate.queryForList(sql); |
|||
} |
|||
|
|||
public int getLastBookingIdInserted() { |
|||
String sql = "SELECT unique_receipt_id FROM pos_penalty_post_data ORDER BY unique_receipt_id DESC LIMIT 1"; |
|||
return jdbcTemplate.queryForObject(sql, Integer.class); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue