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