11 changed files with 461 additions and 99 deletions
-
57src/main/java/com/gcc/erppostdata/common/MySchduler.java
-
35src/main/java/com/gcc/erppostdata/communityhall/CHPostData.java
-
6src/main/java/com/gcc/erppostdata/communityhall/CmhQueryBank.java
-
8src/main/java/com/gcc/erppostdata/config/DatabaseConfig.java
-
229src/main/java/com/gcc/erppostdata/mudhalvarpadaipagam/CWPostData.java
-
40src/main/java/com/gcc/erppostdata/mudhalvarpadaipagam/CoworkQueryBank.java
-
21src/main/java/com/gcc/erppostdata/mudhalvarpadaipagam/MPPostData.java
-
73src/main/java/com/gcc/erppostdata/petregistration/PRPostData.java
-
12src/main/java/com/gcc/erppostdata/petregistration/PetQueryBank.java
-
77src/main/java/com/gcc/erppostdata/repo/CoworkLogRepo.java
-
2src/main/resources/application.properties
@ -0,0 +1,229 @@ |
|||||
|
package com.gcc.erppostdata.mudhalvarpadaipagam; |
||||
|
|
||||
|
import com.fasterxml.jackson.core.JsonProcessingException; |
||||
|
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
|
import com.gcc.erppostdata.config.AppConfig; |
||||
|
import com.gcc.erppostdata.repo.CoworkLogRepo; |
||||
|
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 javax.sql.DataSource; |
||||
|
import java.io.BufferedReader; |
||||
|
import java.io.InputStreamReader; |
||||
|
import java.net.HttpURLConnection; |
||||
|
import java.net.URL; |
||||
|
import java.net.URLEncoder; |
||||
|
import java.text.SimpleDateFormat; |
||||
|
import java.time.LocalDate; |
||||
|
import java.util.*; |
||||
|
|
||||
|
@Component |
||||
|
public class CWPostData { |
||||
|
|
||||
|
@Autowired |
||||
|
private JdbcTemplate jdbcTemplate; |
||||
|
|
||||
|
@Autowired |
||||
|
private AppConfig appConfig; |
||||
|
|
||||
|
@Autowired |
||||
|
private CoworkLogRepo coworkLogRepo; |
||||
|
|
||||
|
private List<Map<String, Object>> coworkDataList; |
||||
|
|
||||
|
// @PersistenceContext(unitName = "coworkspace") |
||||
|
// private EntityManager entityManager; |
||||
|
|
||||
|
|
||||
|
// @Autowired |
||||
|
// @Qualifier("mysqlmudhalvarpadaipagamDataSource") |
||||
|
// private EntityManager entityManager; |
||||
|
|
||||
|
@Autowired |
||||
|
public void setDataSource(@Qualifier("mysqlmudhalvarpadaipagamDataSource") DataSource dataSource) { |
||||
|
this.jdbcTemplate = new JdbcTemplate(dataSource); |
||||
|
} |
||||
|
|
||||
|
public void fetchCoworkData(String sql, String id) { |
||||
|
System.out.println("SQL: " + sql); |
||||
|
|
||||
|
coworkDataList = new ArrayList<>(); |
||||
|
|
||||
|
List<Map<String, Object>> results = jdbcTemplate.queryForList(sql); |
||||
|
|
||||
|
for (Map<String, Object> row : results) { |
||||
|
Map<String, Object> data = new TreeMap<>(); |
||||
|
|
||||
|
String assessmentNo = LocalDate.now().getYear() + "/MUTHAPADAI/" + row.get("booking_id").toString(); |
||||
|
|
||||
|
// Static mandatory input |
||||
|
data.put("serviceId", "getOtherCollection"); |
||||
|
data.put("COLLECTION_TYPE", "Muthalvar Padaippagam"); |
||||
|
data.put("TOTALTRANSACTIONCODE", "450310000"); |
||||
|
|
||||
|
// Unique data |
||||
|
data.put("ASSESSMENTNO", assessmentNo); |
||||
|
data.put("UNIQUERECEIPTID", row.get("booking_id").toString()); |
||||
|
data.put("TRANSACTIONNO", row.get("order_id").toString()); |
||||
|
data.put("TRANSACTIONREFNO", row.get("payment_id").toString()); |
||||
|
data.put("TRANSACTIONDATE", row.get("paymentdate").toString()); |
||||
|
data.put("TOTALTRANSACTIONAMOUNT", Double.parseDouble(row.get("amount").toString())); |
||||
|
|
||||
|
// Amount breakdown |
||||
|
data.put("MSTRCODEONE", "019"); |
||||
|
data.put("SPLITAMOUNTONE", row.get("amount").toString()); |
||||
|
|
||||
|
// Party details |
||||
|
data.put("PARTYNAME", row.get("user_name").toString()); |
||||
|
data.put("PARTYMOBILE", row.get("mobile").toString()); |
||||
|
data.put("PARTYADDRESS", "NA");// For internal tracking |
||||
|
|
||||
|
coworkDataList.add(data); |
||||
|
} |
||||
|
|
||||
|
postDataToERP(coworkDataList, id); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void postDataToERP(List<Map<String, Object>> coworkList, String id) { |
||||
|
for (Map<String, Object> data : coworkList) { |
||||
|
StringBuilder response = new StringBuilder(); |
||||
|
System.out.println("Sending Data: " + data); |
||||
|
StringBuilder encodedUrl = new StringBuilder(appConfig.getErpUrl()); |
||||
|
|
||||
|
try { |
||||
|
boolean firstParam = true; |
||||
|
// SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); |
||||
|
// |
||||
|
// SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); |
||||
|
// |
||||
|
// outputFormat.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata")); |
||||
|
|
||||
|
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) { |
||||
|
value = ""; |
||||
|
} else { |
||||
|
value = entry.getValue().toString(); |
||||
|
// 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")); |
||||
|
} |
||||
|
|
||||
|
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); |
||||
|
|
||||
|
if (responseCode == HttpURLConnection.HTTP_OK) { |
||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); |
||||
|
String inputLine; |
||||
|
while ((inputLine = in.readLine()) != null) { |
||||
|
response.append(inputLine); |
||||
|
} |
||||
|
in.close(); |
||||
|
} else { |
||||
|
System.out.println("GET request failed."); |
||||
|
} |
||||
|
|
||||
|
if (id != null) { |
||||
|
updateTheLog(data, response, id); |
||||
|
} else { |
||||
|
saveTheLog(data, response); |
||||
|
} |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
try { |
||||
|
if (id != null) { |
||||
|
updateTheLog(data, response, id); |
||||
|
} else { |
||||
|
saveTheLog(data, response); |
||||
|
} |
||||
|
} catch (Exception ex) { |
||||
|
ex.printStackTrace(); |
||||
|
} |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void saveTheLog(Map<String, Object> map, StringBuilder response) throws JsonProcessingException { |
||||
|
String status = "", msgStatus = ""; |
||||
|
if (response != null) { |
||||
|
ObjectMapper objectMapper = new ObjectMapper(); |
||||
|
Map<String, Object> res = objectMapper.readValue(response.toString(), Map.class); |
||||
|
msgStatus = String.valueOf(res.get("Message")); |
||||
|
if (res.get("ResultStatus") != null) { |
||||
|
status = String.valueOf(res.get("ResultStatus")); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
System.out.println("ResultStatus: " + status + " msgStatus: " + msgStatus); |
||||
|
|
||||
|
String statusCode = "0"; |
||||
|
if ("Connection Failure".equals(msgStatus)) { |
||||
|
statusCode = "2"; |
||||
|
} else if ("Already Updated this collection".equals(msgStatus) && "false".equals(status)) { |
||||
|
statusCode = "1"; |
||||
|
} else if ("Failure".equals(msgStatus) && "false".equals(status)) { |
||||
|
statusCode = "2"; |
||||
|
} else if ("true".equals(status)) { |
||||
|
statusCode = "1"; |
||||
|
} |
||||
|
|
||||
|
map.put("status", statusCode); |
||||
|
map.put("response", response.toString()); |
||||
|
coworkLogRepo.insert(map); |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
public void updateTheLog(Map<String, Object> map, StringBuilder response, String id) throws JsonProcessingException { |
||||
|
String status = "", msgStatus = ""; |
||||
|
if (response != null) { |
||||
|
ObjectMapper objectMapper = new ObjectMapper(); |
||||
|
Map<String, Object> res = objectMapper.readValue(response.toString(), Map.class); |
||||
|
msgStatus = String.valueOf(res.get("Message")); |
||||
|
if (res.get("ResultStatus") != null) { |
||||
|
status = String.valueOf(res.get("ResultStatus")); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
System.out.println("ResultStatus: " + status + " msgStatus: " + msgStatus); |
||||
|
|
||||
|
String statusCode = "0"; |
||||
|
if ("Connection Failure".equals(msgStatus)) { |
||||
|
statusCode = "2"; |
||||
|
} else if ("Already Updated this collection".equals(msgStatus) && "false".equals(status)) { |
||||
|
statusCode = "1"; |
||||
|
} else if ("Failure".equals(msgStatus) && "false".equals(status)) { |
||||
|
statusCode = "2"; |
||||
|
} else if ("true".equals(status)) { |
||||
|
statusCode = "1"; |
||||
|
} |
||||
|
|
||||
|
coworkLogRepo.updateLog(statusCode, response.toString(), id); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
package com.gcc.erppostdata.mudhalvarpadaipagam; |
||||
|
|
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
@Service |
||||
|
public class CoworkQueryBank { |
||||
|
|
||||
|
@Autowired |
||||
|
private CWPostData cwPostData; |
||||
|
|
||||
|
|
||||
|
public void PushAllData() { |
||||
|
String sql = "SELECT b.user_name, b.mobile, p.amount, p.payment_status, " + |
||||
|
" DATE_FORMAT(p.paymentdate,'%d/%m/%Y') as paymentdate, p.payment_id, " + |
||||
|
"b.booking_id, b.booking_status,p.order_id FROM booking b " + |
||||
|
"JOIN payment p ON b.booking_id = p.booking_id " + |
||||
|
"WHERE b.booking_status = 'success' order by b.booking_id"; |
||||
|
cwPostData.fetchCoworkData(sql, null); |
||||
|
} |
||||
|
|
||||
|
public void hourlyPushData(int bookingId) { |
||||
|
String sql = "SELECT b.user_name, b.mobile, p.amount, p.payment_status, " + |
||||
|
"DATE_FORMAT(p.paymentdate,'%d/%m/%Y') as paymentdate, p.payment_id, " + |
||||
|
"b.booking_id, b.booking_status,p.order_id FROM booking b " + |
||||
|
"JOIN payment p ON b.booking_id = p.booking_id " + |
||||
|
"WHERE b.booking_status = 'success' AND p.paymentdate <= NOW() - INTERVAL 1 HOUR " + |
||||
|
"AND b.booking_id > '" + bookingId + "' order by b.booking_id LIMIT 1000"; |
||||
|
cwPostData.fetchCoworkData(sql, null); |
||||
|
} |
||||
|
|
||||
|
public void resendPushData(String bookingId, String id) { |
||||
|
String sql = "SELECT b.user_name, b.mobile, p.amount, p.payment_status, " + |
||||
|
"DATE_FORMAT(p.paymentdate,'%d/%m/%Y') as paymentdate, p.payment_id, " + |
||||
|
"b.booking_id, b.booking_status,p.order_id FROM booking b " + |
||||
|
"JOIN payment p ON b.booking_id = p.booking_id " + |
||||
|
"WHERE b.booking_status = 'success' AND b.booking_id = '" + bookingId + "' order by b.booking_id"; |
||||
|
cwPostData.fetchCoworkData(sql, id); |
||||
|
} |
||||
|
} |
||||
@ -1,21 +0,0 @@ |
|||||
package com.gcc.erppostdata.mudhalvarpadaipagam; |
|
||||
|
|
||||
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 javax.sql.DataSource; |
|
||||
|
|
||||
@Component |
|
||||
public class MPPostData { |
|
||||
|
|
||||
@Autowired |
|
||||
private JdbcTemplate jdbcTemplate; |
|
||||
|
|
||||
@Autowired |
|
||||
public void setDataSource (@Qualifier("mysqlmudhalvarpadaipagamDataSource") DataSource dataSource){ |
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -0,0 +1,77 @@ |
|||||
|
package com.gcc.erppostdata.repo; |
||||
|
|
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.beans.factory.annotation.Qualifier; |
||||
|
import org.springframework.jdbc.core.JdbcTemplate; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import javax.sql.DataSource; |
||||
|
import java.sql.Timestamp; |
||||
|
import java.text.SimpleDateFormat; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@Service |
||||
|
public class CoworkLogRepo { |
||||
|
|
||||
|
@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 cowork_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"), // ✅ Now will correctly insert DATETIME |
||||
|
data.get("TRANSACTIONNO"), |
||||
|
data.get("TRANSACTIONREFNO"), |
||||
|
data.get("UNIQUERECEIPTID"), |
||||
|
data.get("bookingId"), |
||||
|
data.get("PARTYNAME"), |
||||
|
data.get("status"), |
||||
|
data.get("response") |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
public List<Map<String,Object>> getDataByStatus(String status) { |
||||
|
String sql = "SELECT * FROM cowork_post_data WHERE status = ?"; |
||||
|
return jdbcTemplate.queryForList(sql, status); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public int updateLog(String status, String response, String id) { |
||||
|
String sql = "UPDATE cowork_post_data SET status = ?, response = ? WHERE id = ?"; |
||||
|
return jdbcTemplate.update(sql, status, response, id); |
||||
|
} |
||||
|
|
||||
|
public int getLastBookingIdInserted() { |
||||
|
String sql = "SELECT uniqueId FROM cowork_post_data ORDER BY uniqueId DESC LIMIT 1"; |
||||
|
return jdbcTemplate.queryForObject(sql, Integer.class); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue