| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- package id.co.hanoman.service.as400;
- import java.math.BigDecimal;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.LinkedList;
- import java.util.List;
- import javax.naming.InitialContext;
- import javax.sql.DataSource;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import id.co.hanoman.service.PersistanceServiceInterface;
- import id.co.hanoman.service.ServiceUtil;
- import id.co.hanoman.service.ePayment.AppSetting;
- import id.co.hanoman.service.mwapp.SysParam;
- public class AS400ServiceInterface {
- protected Log log = LogFactory.getLog(this.getClass());
- public Branch[] getBranchList(String mwappDs, String branchCode) {
- return new Branch[] {};
- }
-
- public Branch[] getBranchList(String mwappDs, BigDecimal branchCodeStart, BigDecimal branchCodeEnd) {
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- Branch[] result = null;
- try {
- System.out.println("before connect");
- conn = initialAS400Connection();
- System.out.println("after connect");
- String as400Schema = getAppSettingValue(mwappDs, "EPAYMENT_AS400_SCHEMA", "I");
- String sql = "SELECT JHDATA.JDBR, JHDATA.JDNAME FROM PAR" + as400Schema + "SIBS.JHDATA JHDATA WHERE JHDATA.JDBR >= ? AND JHDATA.JDBR <= ?";
- ps = conn.prepareStatement(sql);
- ps.setBigDecimal(1, branchCodeStart);
- ps.setBigDecimal(2, branchCodeEnd);
- rs = ps.executeQuery();
- System.out.println("BRANCH");
- List<Branch> list = new ArrayList<Branch>();
- while (rs.next()) {
- String code = rs.getString(1);
- String name = rs.getString(2);
- Branch branch = new Branch();
- branch.setCode(code);
- branch.setName(name);
- list.add(branch);
- }
-
- result = new Branch[list.size()];
- result = list.toArray(result);
- }catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (rs != null) {
- try {
- rs.close();
- } catch (Exception e) {
- }
- }
- if (ps != null) {
- try {
- ps.close();
- } catch (Exception e) {
- }
- }
- if (conn != null) {
- try {
- System.out.println("-------------- Closing Connection AS400 ---------------");
- conn.close();
- } catch (Exception e) {
- }
- }
- }
-
- return result;
- }
- public KeperluanBayar[] getKeperluanBayar(String mwappDs, String univCode) {
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- KeperluanBayar[] result = null;
- try {
- System.out.println("before connect");
- conn = initialAS400Connection();
- System.out.println("after connect");
- String as400Schema = getAppSettingValue(mwappDs, "EPAYMENT_AS400_SCHEMA", "I");
- String sql = "SELECT UPLPAR.UNPYTP, UPLPAR.UNPYDS FROM BW" + as400Schema + "DAT.UPLPAR AS UPLPAR WHERE UPLPAR.UNVCOD = ?";
- ps = conn.prepareStatement(sql);
- ps.setString(1, univCode);
- rs = ps.executeQuery();
- List<KeperluanBayar> list = new ArrayList<KeperluanBayar>();
- while (rs.next()) {
- String code = rs.getString(1);
- String name = rs.getString(2);
- KeperluanBayar keperluanBayar = new KeperluanBayar();
- keperluanBayar.setCode(code);
- keperluanBayar.setName(name);
- list.add(keperluanBayar);
- }
-
- result = new KeperluanBayar[list.size()];
- result = list.toArray(result);
- }catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (rs != null) {
- try {
- rs.close();
- } catch (Exception e) {
- }
- }
- if (ps != null) {
- try {
- ps.close();
- } catch (Exception e) {
- }
- }
- if (conn != null) {
- try {
- System.out.println("-------------- Closing Connection AS400 ---------------");
- conn.close();
- } catch (Exception e) {
- }
- }
- }
- return result;
- }
-
- public Teller getTellerByGroupAndId(String mwappDs, String group, String telId) {
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- Teller teller = null;
- try {
- System.out.println("before connect");
- conn = initialAS400Connection();
- System.out.println("after connect");
-
- String as400Schema = getParamValue(mwappDs, "MDW_AS400_SCHEMA");
- String sql = "SELECT TLTEL.TLNUM, TLTEL.TLNAME, TLCTLU.TLCTL FROM SET" + as400Schema + "ENV.TLTEL AS TLTEL JOIN SET" + as400Schema + "ENV.TLCTLU AS TLCTLU ON TLTEL.TLTBRN = TLCTLU.TLBRN# WHERE TLTEL.TLTTYP = ? AND TLTEL.TLNUM = ?";
-
- ps = conn.prepareStatement(sql);
- ps.setString(1, group);
- ps.setString(2, telId);
- rs = ps.executeQuery();
- List<Teller> list = new ArrayList<Teller>();
- if (rs.next()) {
- teller = new Teller();
- String tellerId = rs.getString(1);
- String tellerName = rs.getString(2);
- String ctrlUnitId = rs.getString(3);
- teller.setTellerName(tellerName);
- teller.setTellerId(tellerId);
- teller.setCtrlUnitId(ctrlUnitId);
- teller.setGroup(group);
- }
-
- }catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (rs != null) {
- try {
- rs.close();
- } catch (Exception e) {
- }
- }
- if (ps != null) {
- try {
- ps.close();
- } catch (Exception e) {
- }
- }
- if (conn != null) {
- try {
- System.out.println("-------------- Closing Connection AS400 ---------------");
- conn.close();
- } catch (Exception e) {
- }
- }
- }
- return teller;
- }
- public Teller[] getTellerList(String mwappDs, String group) {
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- Teller[] result = null;
- try {
- System.out.println("before connect");
- conn = initialAS400Connection();
- System.out.println("after connect");
- String as400Schema = getParamValue(mwappDs, "MDW_AS400_SCHEMA");
-
- String sql = "SELECT TLTEL.TLNUM, TLTEL.TLNAME, TLCTLU.TLCTL FROM SET" + as400Schema + "ENV.TLTEL AS TLTEL JOIN SET" + as400Schema + "ENV.TLCTLU AS TLCTLU ON TLTEL.TLTBRN = TLCTLU.TLBRN# WHERE TLTEL.TLTTYP = ? ORDER BY TLTEL.TLNUM";
- ps = conn.prepareStatement(sql);
- ps.setString(1, group);
- rs = ps.executeQuery();
- List<Teller> list = new ArrayList<Teller>();
- while (rs.next()) {
- String tellerId = rs.getString(1);
- String tellerName = rs.getString(2);
- String ctrlUnitId = rs.getString(3);
- Teller teller = new Teller();
- teller.setTellerName(tellerName);
- teller.setTellerId(tellerId);
- teller.setCtrlUnitId(ctrlUnitId);
- teller.setGroup(group);
- list.add(teller);
- }
-
- result = new Teller[list.size()];
- result = list.toArray(result);
- }catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (rs != null) {
- try {
- rs.close();
- } catch (Exception e) {
- }
- }
- if (ps != null) {
- try {
- ps.close();
- } catch (Exception e) {
- }
- }
- if (conn != null) {
- try {
- System.out.println("-------------- Closing Connection AS400 ---------------");
- conn.close();
- } catch (Exception e) {
- }
- }
- }
- return result;
- }
- public BillerQuery[] queryBiller(String mwappDs, String filter) {
- Connection xconn = null;
- Statement stmtg = null;
- ResultSet rsg = null;
- BillerQuery[] rs = null;
-
- try {
- System.out.println("before connect");
- xconn = initialAS400Connection();
- System.out.println("after connect");
- String as400Schema = getAppSettingValue(mwappDs, "EPAYMENT_AS400_SCHEMA", "I");
- stmtg = xconn.createStatement();
- if(filter == null) filter = new String();
- String sql = "SELECT UNCODE, UNNAME FROM BW" + as400Schema + "DAT.unlist WHERE 1=1 " + filter;
- rsg = stmtg.executeQuery(sql);
- List<BillerQuery> list = new ArrayList<BillerQuery>();
-
- while (rsg.next()) {
- String code = rsg.getString(1).trim();
- String name = rsg.getString(2).trim();
- BillerQuery billerQuery = new BillerQuery();
- billerQuery.setCode(code);
- billerQuery.setName(name);
- list.add(billerQuery);
- }
-
- rs = new BillerQuery[list.size()];
- rs = list.toArray(rs);
- System.out.println("Total Biller Query ::::: "+rs.length);
-
- }catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (rsg != null) {
- try {
- rsg.close();
- } catch (Exception e) {
- }
- }
- if (stmtg != null) {
- try {
- stmtg.close();
- } catch (Exception e) {
- }
- }
- if (xconn != null) {
- try {
- System.out.println("------------------------- Closing Connection AS400 -------------------------");
- xconn.close();
- } catch (Exception e) {
- }
- }
- }
- return rs;
- }
-
-
- private Connection initialAS400Connection() {
- Connection conn = null;
- try {
-
- // ----------------- jdbc -----------------------
- // System.out.println("connecting as400 jdbc");
- // Class.forName("com.ibm.as400.access.AS400JDBCDriver");
- // conn = DriverManager.getConnection("jdbc:as400://172.18.30.104/BWIDAT", "BTNSOA", "BTNSOA");
-
- // ----------------- jndi -----------------------
- System.out.println("connecting as400 datasource");
- InitialContext ctx = new InitialContext();
- DataSource ds = (DataSource) ctx.lookup("jdbc/as400/btn_ds");
- conn = ds.getConnection();
-
- System.out.println("connected as400");
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e.getMessage(), e);
- }
- return conn;
- }
-
- private String getAppSettingValue(String ds, String code, String defaultValue) throws Exception {
- String settingValue = defaultValue;
- try {
- if (code == null || "".equals(code)) {
- } else {
- PersistanceServiceInterface psiEpay = ServiceUtil.getDaoClient(null);
- AppSetting appSetting = (AppSetting) psiEpay.queryById(ds, "AppSetting", code, null);
- if (appSetting != null) {
- settingValue = appSetting.getSettingValue();
- if (log.isDebugEnabled())
- log.debug("settingValue[" + code + "] :: " + settingValue);
- if (settingValue == null || "".equals(settingValue))
- settingValue = defaultValue;
- }
- }
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- throw new RuntimeException(e.getMessage(), e);
- }
- return settingValue;
- }
-
- private String getParamValue(String ds, String code) throws Exception {
- String paramValue = null;
- try {
- if (code == null || "".equals(code)) {
- } else {
- PersistanceServiceInterface psiEpay = ServiceUtil.getDaoClient(null);
- SysParam sysParam = (SysParam) psiEpay.queryById(ds, "SysParam", code, null);
- if (sysParam != null) {
- paramValue = sysParam.getParamValue();
- if (log.isDebugEnabled())
- log.debug("paramValue[" + code + "] :: " + paramValue);
- if (paramValue == null || "".equals(paramValue))
- paramValue = null;
- }
-
- }
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- throw new RuntimeException(e.getMessage(), e);
- }
- return paramValue;
-
- }
- }
|