Browse Source

pet API updated

master
Thaqi2021 2 years ago
parent
commit
7e31f0d451
  1. 114
      src/main/java/com/gcc/erppostdata/petregistration/PRPostData.java
  2. 6
      src/main/java/com/gcc/erppostdata/petregistration/PetQueryBank.java
  3. 2
      src/main/java/com/gcc/erppostdata/repo/CommunityHallLogRepo.java
  4. 2
      src/main/java/com/gcc/erppostdata/repo/PetLogRepo.java

114
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<Map<String, Object>> petlist) {
public void postDataToERP(List<Map<String, Object>> petlist,String id) {
for (Map<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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";

6
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);
}

2
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);
}
}

2
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);
}
}
Loading…
Cancel
Save