added Purulia and Mughberia Bank codes in Nabard List
This commit is contained in:
@@ -24,261 +24,259 @@ import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class RequestResponse {
|
||||
static Connection connection = null;
|
||||
static ResultSet rs = null;
|
||||
static Statement statement = null;
|
||||
static Connection connection = null;
|
||||
static ResultSet rs = null;
|
||||
static Statement statement = null;
|
||||
|
||||
public static ArrayList<DataBean> get_response(String jsonInputString, String date)
|
||||
throws IOException {
|
||||
// String urlFromDatabase = "https://IPKS.cedgenetbanking.in/IPKSTRAN";
|
||||
String urlFromDatabase = "";
|
||||
String bc = new JSONObject(jsonInputString).getString("bankcode");
|
||||
if(bc.equals("0005") || bc.equals("0021")) {
|
||||
urlFromDatabase = "https://NABARDIPKS.cedgeapiservices.in/IPKSTRAN";
|
||||
} else {
|
||||
urlFromDatabase = "https://UCBIPKS.cedgeapiservices.in/IPKSTRAN";
|
||||
}
|
||||
System.out.println(urlFromDatabase);
|
||||
ArrayList<DataBean> data = new ArrayList<>();
|
||||
URL url = null;
|
||||
public static ArrayList<DataBean> get_response(String jsonInputString, String date)
|
||||
throws IOException {
|
||||
// String urlFromDatabase = "https://IPKS.cedgenetbanking.in/IPKSTRAN";
|
||||
String urlFromDatabase = "";
|
||||
String bc = new JSONObject(jsonInputString).getString("bankcode");
|
||||
if (bc.equals("0005") || bc.equals("0021") || bc.equals("0016") || bc.equals("0018")) {
|
||||
urlFromDatabase = "https://NABARDIPKS.cedgeapiservices.in/IPKSTRAN";
|
||||
} else {
|
||||
urlFromDatabase = "https://UCBIPKS.cedgeapiservices.in/IPKSTRAN";
|
||||
}
|
||||
System.out.println(urlFromDatabase);
|
||||
ArrayList<DataBean> data = new ArrayList<>();
|
||||
URL url = null;
|
||||
|
||||
try {
|
||||
url = new URL(urlFromDatabase);
|
||||
} catch (MalformedURLException e1) {
|
||||
try {
|
||||
url = new URL(urlFromDatabase);
|
||||
} catch (MalformedURLException e1) {
|
||||
|
||||
e1.printStackTrace();
|
||||
}
|
||||
HttpURLConnection con = null;
|
||||
try {
|
||||
con = (HttpURLConnection) url.openConnection();
|
||||
con.setRequestMethod("POST");
|
||||
con.setRequestProperty("Content-Type", "application/json; utf-8");
|
||||
con.setRequestProperty("Accept", "application/json");
|
||||
con.setDoOutput(true);
|
||||
e1.printStackTrace();
|
||||
}
|
||||
HttpURLConnection con = null;
|
||||
try {
|
||||
con = (HttpURLConnection) url.openConnection();
|
||||
con.setRequestMethod("POST");
|
||||
con.setRequestProperty("Content-Type", "application/json; utf-8");
|
||||
con.setRequestProperty("Accept", "application/json");
|
||||
con.setDoOutput(true);
|
||||
|
||||
} catch (IOException e2) {
|
||||
} catch (IOException e2) {
|
||||
|
||||
e2.printStackTrace();
|
||||
}
|
||||
|
||||
try (OutputStream os = con.getOutputStream()) {
|
||||
byte[] input = jsonInputString.getBytes("utf-8");
|
||||
os.write(input, 0, input.length);
|
||||
}
|
||||
|
||||
int responseCode = 0;
|
||||
try {
|
||||
responseCode = con.getResponseCode();
|
||||
} catch (IOException e1) {
|
||||
|
||||
e1.printStackTrace();
|
||||
}
|
||||
System.out.println("Response Code : " + responseCode);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||
|
||||
StringBuffer response = new StringBuffer();
|
||||
response.append("{\"result\":");
|
||||
try {
|
||||
String inputLine;
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
|
||||
e1.printStackTrace();
|
||||
}
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e1) {
|
||||
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
response.append("}");
|
||||
|
||||
if (response.toString().contains("No data found")) {
|
||||
System.out.println("No Transactions found");
|
||||
} else {
|
||||
|
||||
JSONObject json = new JSONObject(response.toString());
|
||||
JSONArray dataArray = new JSONArray(json.get("result").toString());
|
||||
|
||||
for (int i = 0; i < dataArray.length(); i++) {
|
||||
String JSonData = dataArray.get(i).toString();
|
||||
DataBean databean = new DataBean();
|
||||
|
||||
JSONObject dataD = new JSONObject(JSonData);
|
||||
|
||||
databean.setAcctNo(dataD.get("acctno").toString());
|
||||
databean.setBankcode(dataD.get("bankcode").toString());
|
||||
databean.setTxnCode(dataD.get("trancode").toString());
|
||||
databean.setTxnAmt(dataD.get("trnamt").toString());
|
||||
databean.setNarration(dataD.get("narration").toString());
|
||||
databean.setJrnlId(dataD.get("jrnl").toString());
|
||||
databean.setTimestamp(date);
|
||||
|
||||
if (Double.parseDouble(dataD.get("trnamt").toString()) > 0.0D) {
|
||||
databean.setTxnInd("CR");
|
||||
} else if (Double.parseDouble(dataD.get("trnamt").toString()) < 0.0D) {
|
||||
databean.setTxnInd("DR");
|
||||
} else {
|
||||
databean.setTxnInd("NA");
|
||||
}
|
||||
data.add(databean);
|
||||
e2.printStackTrace();
|
||||
}
|
||||
|
||||
setDatainDatabase(data, date);
|
||||
}
|
||||
|
||||
} catch (Exception e3) {
|
||||
|
||||
e3.printStackTrace();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public static ArrayList<String> getUrl() {
|
||||
DateFormat sdf = new SimpleDateFormat("ddMMyyyy");
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(new Date());
|
||||
cal.add(6, -1);
|
||||
|
||||
String dateToday = sdf.format(cal.getTime());
|
||||
|
||||
System.out.println("Date :" + dateToday);
|
||||
String url = null;
|
||||
String bankCode = null;
|
||||
ArrayList<String> finalUrl = new ArrayList<>();
|
||||
try {
|
||||
connection = Util.getDBConnection();
|
||||
|
||||
statement = connection.createStatement();
|
||||
rs =
|
||||
statement.executeQuery(
|
||||
"select * from rupay_kcc_api_map where status='Y' and API_TYPE='TXN'");
|
||||
while (rs.next()) {
|
||||
url = rs.getString(7);
|
||||
bankCode = rs.getString(6);
|
||||
String finUrl = url.replaceAll("dt", dateToday);
|
||||
finUrl = finUrl.replaceAll("bcode", bankCode);
|
||||
finalUrl.add(finUrl);
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
|
||||
try {
|
||||
if (connection != null) connection.close();
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
return finalUrl;
|
||||
}
|
||||
|
||||
public static void setDatainDatabase(ArrayList<DataBean> data, String date) {
|
||||
Connection connection = null;
|
||||
ResultSet rs = null;
|
||||
Statement st = null;
|
||||
String query = null;
|
||||
PreparedStatement statement = null;
|
||||
|
||||
ArrayList<String> combination = new ArrayList<>();
|
||||
|
||||
try {
|
||||
try {
|
||||
connection = Util.getDBConnection();
|
||||
st = connection.createStatement();
|
||||
rs =
|
||||
st.executeQuery(
|
||||
"select l.bankcode,l.jrnl_id,l.txn_date from sweep_api_log l where l.txn_date='"
|
||||
+ date
|
||||
+ "'");
|
||||
while (rs.next()) {
|
||||
String comb = rs.getString(1) + "|" + rs.getString(2) + "|" + rs.getString(3);
|
||||
|
||||
combination.add(comb);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out.println("No record found");
|
||||
}
|
||||
|
||||
Iterator<DataBean> iter = data.iterator();
|
||||
Statement st2 = connection.createStatement();
|
||||
while (iter.hasNext()) {
|
||||
DataBean d = iter.next();
|
||||
|
||||
if (d.getTxnCode().equalsIgnoreCase("001057")) {
|
||||
|
||||
if (combination.contains(d.getBankcode() + "|" + d.getJrnlId() + "|" + d.getTimestamp())
|
||||
|| d.getJrnlId() == null
|
||||
|| d.getJrnlId().equalsIgnoreCase("")) {
|
||||
System.out.println(
|
||||
"RECORD ALREADY PRESENT FOR "
|
||||
+ d.getBankcode()
|
||||
+ "|"
|
||||
+ d.getJrnlId()
|
||||
+ "|"
|
||||
+ d.getTimestamp());
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
query =
|
||||
"insert into sweep_api_log (bankcode, cbsacctno, txncode, txnamt, txnind, narration,"
|
||||
+ " jrnl_id, txn_date, post_flag, success_flag, errorlog) values ('"
|
||||
+ d.getBankcode()
|
||||
+ "','"
|
||||
+ d.getAcctNo()
|
||||
+ "','"
|
||||
+ d.getTxnCode()
|
||||
+ "',abs("
|
||||
+ d.getTxnAmt()
|
||||
+ "),'";
|
||||
query =
|
||||
query
|
||||
+ d.getTxnInd()
|
||||
+ "','"
|
||||
+ d.getNarration()
|
||||
+ "','"
|
||||
+ d.getJrnlId()
|
||||
+ "','"
|
||||
+ d.getTimestamp()
|
||||
+ "','N','N',"
|
||||
+ null
|
||||
+ ")";
|
||||
System.out.println("SQL Statement :" + query);
|
||||
|
||||
st2.addBatch(query);
|
||||
System.out.println("Added to DB Insert Batch");
|
||||
|
||||
continue;
|
||||
try (OutputStream os = con.getOutputStream()) {
|
||||
byte[] input = jsonInputString.getBytes("utf-8");
|
||||
os.write(input, 0, input.length);
|
||||
}
|
||||
|
||||
System.out.println("Txncode:" + d.getTxnCode());
|
||||
}
|
||||
int responseCode = 0;
|
||||
try {
|
||||
responseCode = con.getResponseCode();
|
||||
} catch (IOException e1) {
|
||||
|
||||
st2.executeBatch();
|
||||
System.out.println("Insert to DB Completed");
|
||||
System.out.println("Posting Txns in IPKS");
|
||||
e1.printStackTrace();
|
||||
}
|
||||
System.out.println("Response Code : " + responseCode);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||
|
||||
CallableStatement cs = connection.prepareCall("{call sweep_api_txn_post}");
|
||||
cs.execute();
|
||||
System.out.println("Posting Completed, Check log.");
|
||||
StringBuffer response = new StringBuffer();
|
||||
response.append("{\"result\":");
|
||||
try {
|
||||
String inputLine;
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e1) {
|
||||
|
||||
try {
|
||||
if (connection != null) connection.close();
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
response.append("}");
|
||||
|
||||
if (response.toString().contains("No data found")) {
|
||||
System.out.println("No Transactions found");
|
||||
} else {
|
||||
|
||||
JSONObject json = new JSONObject(response.toString());
|
||||
JSONArray dataArray = new JSONArray(json.get("result").toString());
|
||||
|
||||
for (int i = 0; i < dataArray.length(); i++) {
|
||||
String JSonData = dataArray.get(i).toString();
|
||||
DataBean databean = new DataBean();
|
||||
|
||||
JSONObject dataD = new JSONObject(JSonData);
|
||||
|
||||
databean.setAcctNo(dataD.get("acctno").toString());
|
||||
databean.setBankcode(dataD.get("bankcode").toString());
|
||||
databean.setTxnCode(dataD.get("trancode").toString());
|
||||
databean.setTxnAmt(dataD.get("trnamt").toString());
|
||||
databean.setNarration(dataD.get("narration").toString());
|
||||
databean.setJrnlId(dataD.get("jrnl").toString());
|
||||
databean.setTimestamp(date);
|
||||
|
||||
if (Double.parseDouble(dataD.get("trnamt").toString()) > 0.0D) {
|
||||
databean.setTxnInd("CR");
|
||||
} else if (Double.parseDouble(dataD.get("trnamt").toString()) < 0.0D) {
|
||||
databean.setTxnInd("DR");
|
||||
} else {
|
||||
databean.setTxnInd("NA");
|
||||
}
|
||||
data.add(databean);
|
||||
}
|
||||
|
||||
setDatainDatabase(data, date);
|
||||
}
|
||||
|
||||
} catch (Exception e3) {
|
||||
|
||||
e3.printStackTrace();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public static ArrayList<String> getUrl() {
|
||||
DateFormat sdf = new SimpleDateFormat("ddMMyyyy");
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(new Date());
|
||||
cal.add(6, -1);
|
||||
|
||||
String dateToday = sdf.format(cal.getTime());
|
||||
|
||||
System.out.println("Date :" + dateToday);
|
||||
String url = null;
|
||||
String bankCode = null;
|
||||
ArrayList<String> finalUrl = new ArrayList<>();
|
||||
try {
|
||||
connection = Util.getDBConnection();
|
||||
|
||||
statement = connection.createStatement();
|
||||
rs = statement.executeQuery(
|
||||
"select * from rupay_kcc_api_map where status='Y' and API_TYPE='TXN'");
|
||||
while (rs.next()) {
|
||||
url = rs.getString(7);
|
||||
bankCode = rs.getString(6);
|
||||
String finUrl = url.replaceAll("dt", dateToday);
|
||||
finUrl = finUrl.replaceAll("bcode", bankCode);
|
||||
finalUrl.add(finUrl);
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
|
||||
try {
|
||||
if (connection != null)
|
||||
connection.close();
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
return finalUrl;
|
||||
}
|
||||
|
||||
public static void setDatainDatabase(ArrayList<DataBean> data, String date) {
|
||||
Connection connection = null;
|
||||
ResultSet rs = null;
|
||||
Statement st = null;
|
||||
String query = null;
|
||||
PreparedStatement statement = null;
|
||||
|
||||
ArrayList<String> combination = new ArrayList<>();
|
||||
|
||||
try {
|
||||
try {
|
||||
connection = Util.getDBConnection();
|
||||
st = connection.createStatement();
|
||||
rs = st.executeQuery(
|
||||
"select l.bankcode,l.jrnl_id,l.txn_date from sweep_api_log l where l.txn_date='"
|
||||
+ date
|
||||
+ "'");
|
||||
while (rs.next()) {
|
||||
String comb = rs.getString(1) + "|" + rs.getString(2) + "|" + rs.getString(3);
|
||||
|
||||
combination.add(comb);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out.println("No record found");
|
||||
}
|
||||
|
||||
Iterator<DataBean> iter = data.iterator();
|
||||
Statement st2 = connection.createStatement();
|
||||
while (iter.hasNext()) {
|
||||
DataBean d = iter.next();
|
||||
|
||||
if (d.getTxnCode().equalsIgnoreCase("001057")) {
|
||||
|
||||
if (combination.contains(d.getBankcode() + "|" + d.getJrnlId() + "|" + d.getTimestamp())
|
||||
|| d.getJrnlId() == null
|
||||
|| d.getJrnlId().equalsIgnoreCase("")) {
|
||||
System.out.println(
|
||||
"RECORD ALREADY PRESENT FOR "
|
||||
+ d.getBankcode()
|
||||
+ "|"
|
||||
+ d.getJrnlId()
|
||||
+ "|"
|
||||
+ d.getTimestamp());
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
query = "insert into sweep_api_log (bankcode, cbsacctno, txncode, txnamt, txnind, narration,"
|
||||
+ " jrnl_id, txn_date, post_flag, success_flag, errorlog) values ('"
|
||||
+ d.getBankcode()
|
||||
+ "','"
|
||||
+ d.getAcctNo()
|
||||
+ "','"
|
||||
+ d.getTxnCode()
|
||||
+ "',abs("
|
||||
+ d.getTxnAmt()
|
||||
+ "),'";
|
||||
query = query
|
||||
+ d.getTxnInd()
|
||||
+ "','"
|
||||
+ d.getNarration()
|
||||
+ "','"
|
||||
+ d.getJrnlId()
|
||||
+ "','"
|
||||
+ d.getTimestamp()
|
||||
+ "','N','N',"
|
||||
+ null
|
||||
+ ")";
|
||||
System.out.println("SQL Statement :" + query);
|
||||
|
||||
st2.addBatch(query);
|
||||
System.out.println("Added to DB Insert Batch");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
System.out.println("Txncode:" + d.getTxnCode());
|
||||
}
|
||||
|
||||
st2.executeBatch();
|
||||
System.out.println("Insert to DB Completed");
|
||||
System.out.println("Posting Txns in IPKS");
|
||||
|
||||
CallableStatement cs = connection.prepareCall("{call sweep_api_txn_post}");
|
||||
cs.execute();
|
||||
System.out.println("Posting Completed, Check log.");
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
|
||||
try {
|
||||
if (connection != null)
|
||||
connection.close();
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user