From 7e31f0d451430aafc44275ad436fdbf6f3b38bf4 Mon Sep 17 00:00:00 2001 From: Thaqi2021 Date: Mon, 10 Mar 2025 16:30:42 +0530 Subject: [PATCH] pet API updated --- .../petregistration/PRPostData.java | 114 +++++++++++------- .../petregistration/PetQueryBank.java | 6 +- .../repo/CommunityHallLogRepo.java | 2 +- .../com/gcc/erppostdata/repo/PetLogRepo.java | 2 +- 4 files changed, 75 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/gcc/erppostdata/petregistration/PRPostData.java b/src/main/java/com/gcc/erppostdata/petregistration/PRPostData.java index e3fb221..334aea4 100644 --- a/src/main/java/com/gcc/erppostdata/petregistration/PRPostData.java +++ b/src/main/java/com/gcc/erppostdata/petregistration/PRPostData.java @@ -27,6 +27,7 @@ public class PRPostData { @Autowired private JdbcTemplate jdbcTemplate; + @Autowired private AppConfig appConfig; @@ -45,7 +46,7 @@ public class PRPostData { this.jdbcTemplate = new JdbcTemplate(dataSource); } - public void fetpetData(String sql) { + public void fetpetData(String sql,String id) { System.out.println("sql:" + sql); @@ -65,7 +66,7 @@ public class PRPostData { // Unique data data.put("ASSESSMENTNO", row[10].toString()); - data.put("UNIQUERECEIPTID", row[1].toString()); // uniqueid + data.put("UNIQUERECEIPTID", row[0].toString()); // uniqueid data.put("TRANSACTIONNO", row[9].toString()); // order_id data.put("TRANSACTIONREFNO", row[6].toString()); // payment_id data.put("TRANSACTIONDATE", row[8].toString()); // paymentdate @@ -84,52 +85,52 @@ public class PRPostData { } // Call the method with the fetched data - postDataToERP(petDataList); + postDataToERP(petDataList,id); } - public void postDataToERP(List> petlist) { + public void postDataToERP(List> petlist,String id) { for (Map data : petlist) { System.out.println("Sending Data: " + data); System.out.println("ERP URL before request: " + appConfig.getErpUrl()); - String erpBaseUrl = "http://coc-staging.egovernments.org:9980/pgr/external/mobileservice?"; - StringBuilder encodedUrl = new StringBuilder(erpBaseUrl); +// String erpBaseUrl = "http://coc-staging.egovernments.org:9980/pgr/external/mobileservice?"; + StringBuilder encodedUrl = new StringBuilder(appConfig.getErpUrl()); + boolean firstParam = true; + SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); // Original format + SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); // Expected format + outputFormat.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata")); // Adjust timezone if needed - try { - boolean firstParam = true; - SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); // Original format - SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); // Expected format - outputFormat.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata")); // Adjust timezone if needed - for (Map.Entry entry : data.entrySet()) { - if (!firstParam) { - encodedUrl.append("&"); - } - firstParam = false; - - String key = URLEncoder.encode(entry.getKey(), "UTF-8"); - String value = ""; - - if (entry.getValue() == null) { - System.out.println("Missing value for key: " + key); - value = ""; // Ensure empty values are sent correctly - } else { - value = entry.getValue().toString(); - - // ✅ Fix Date Formatting - if (entry.getKey().equals("TRANSACTIONDATE")) { - try { - Date date = inputFormat.parse(value); - value = outputFormat.format(date); - } catch (Exception e) { - System.out.println(" Error parsing TRANSACTIONDATE: " + value); + try { + for (Map.Entry entry : data.entrySet()) { + if (!firstParam) { + encodedUrl.append("&"); + } + firstParam = false; + + String key = URLEncoder.encode(entry.getKey(), "UTF-8"); + String value = ""; + + if (entry.getValue() == null) { + System.out.println("Missing value for key: " + key); + value = ""; // Ensure empty values are sent correctly + } else { + value = entry.getValue().toString(); + + // ✅ Fix Date Formatting + if (entry.getKey().equals("TRANSACTIONDATE")) { + try { + Date date = inputFormat.parse(value); + value = outputFormat.format(date); + } catch (Exception e) { + System.out.println(" Error parsing TRANSACTIONDATE: " + value); + } } } - } - encodedUrl.append(key).append("=").append(URLEncoder.encode(value, "UTF-8")); - } + encodedUrl.append(key).append("=").append(URLEncoder.encode(value, "UTF-8")); + } String finalUrl = encodedUrl.toString(); System.out.println("Final Encoded URL: " + finalUrl); @@ -148,14 +149,34 @@ public class PRPostData { } in.close(); System.out.println("Response: " + response.toString()); - saveTheLog(data,response); + if(id != null){ + updateTheLog(data,response,id); + }else { + saveTheLog(data, response); + } } else { System.out.println("GET request failed."); - saveTheLog(data,null); + if(id != null){ + updateTheLog(data,null,id); + }else { + saveTheLog(data, null); + } } - } catch (Exception e) { - e.printStackTrace(); + } catch(Exception e){ + try { + if(id != null){ + updateTheLog(data,null,id); + }else { + saveTheLog(data, null); + } + } + catch (Exception e1) { + e1.printStackTrace(); + } + e.printStackTrace(); + } + } } @@ -167,15 +188,20 @@ public class PRPostData { if(response != null) { ObjectMapper objectMapper = new ObjectMapper(); Map res = objectMapper.readValue(response.toString(), Map.class); - status = res.get("ResultStatus").toString(); msgStatus = res.get("Message").toString(); + if(res.get("ResultStatus") != null) { + status = res.get("ResultStatus").toString(); + } + } System.out.println("ResultStatus: " + status); String msg = "Already Updated this collection"; - - - if(msg.equals(msgStatus) && status.equals("false")) { + String conFailure = "Connection Failure"; + if(conFailure.equals(msgStatus) ) { + statusCode="1"; + } + else if(msg.equals(msgStatus) && status.equals("false")) { statusCode="1"; } else if ("Failure".equals(msgStatus) && status.equals("false")) { statusCode="2"; diff --git a/src/main/java/com/gcc/erppostdata/petregistration/PetQueryBank.java b/src/main/java/com/gcc/erppostdata/petregistration/PetQueryBank.java index 2b26941..f9a53fe 100644 --- a/src/main/java/com/gcc/erppostdata/petregistration/PetQueryBank.java +++ b/src/main/java/com/gcc/erppostdata/petregistration/PetQueryBank.java @@ -29,7 +29,7 @@ public class PetQueryBank { "INNER JOIN pet_owner o ON p.mobilenum = o.phone " + "WHERE p.status = 2;"; - prPostData.fetpetData(sql); + prPostData.fetpetData(sql,null); } public void hourlyPushData(int uniqueId) { @@ -55,7 +55,7 @@ public class PetQueryBank { " AND p.uniqueid > '"+uniqueId+"' LIMIT 1000"; System.out.println(sql); - prPostData.fetpetData(sql); + prPostData.fetpetData(sql,null); } @@ -80,7 +80,7 @@ public class PetQueryBank { "INNER JOIN pet_owner o ON p.mobilenum = o.phone " + "WHERE p.status = 2 AND p.uniqueid = '" + uniqueId + "'"; - prPostData.fetpetData(sql); + prPostData.fetpetData(sql,id); } diff --git a/src/main/java/com/gcc/erppostdata/repo/CommunityHallLogRepo.java b/src/main/java/com/gcc/erppostdata/repo/CommunityHallLogRepo.java index e3d684e..b715345 100644 --- a/src/main/java/com/gcc/erppostdata/repo/CommunityHallLogRepo.java +++ b/src/main/java/com/gcc/erppostdata/repo/CommunityHallLogRepo.java @@ -39,7 +39,7 @@ public class CommunityHallLogRepo { } public int getLastBookingIdInserted() { - String sql = "SELECT bookingId FROM comm_post_data ORDER BY id DESC LIMIT 1"; + String sql = "SELECT bookingId FROM comm_post_data ORDER BY bookingId DESC LIMIT 1"; return jdbcTemplate.queryForObject(sql, Integer.class); } } diff --git a/src/main/java/com/gcc/erppostdata/repo/PetLogRepo.java b/src/main/java/com/gcc/erppostdata/repo/PetLogRepo.java index 88991c2..44e71c9 100644 --- a/src/main/java/com/gcc/erppostdata/repo/PetLogRepo.java +++ b/src/main/java/com/gcc/erppostdata/repo/PetLogRepo.java @@ -38,7 +38,7 @@ public class PetLogRepo { } public int getLastUniqueIdInserted() { - String sql = "SELECT uniqueId FROM pet_post_data ORDER BY id DESC LIMIT 1"; + String sql = "SELECT uniqueId FROM pet_post_data ORDER BY uniqueId DESC LIMIT 1"; return jdbcTemplate.queryForObject(sql, Integer.class); } }