refactor: 澳洲分行查询

master
zhangtao 4 years ago
parent ad10c558d1
commit d06cb3afa6

@ -0,0 +1,73 @@
package au.com.royalpay.payment.manage.merchants.core.bank;
import cn.yixblog.platform.http.HttpRequestGenerator;
import cn.yixblog.platform.http.HttpRequestResult;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMethod;
import java.io.IOException;
/**
* @Description
* @title:
* @Date 2020/11/12 14:24
* @author: zhangTao
*/
public class AustraliaBank {
private static Logger logger = LoggerFactory.getLogger(AustraliaBank.class);
private static final String AUSTRALIA_BSB_NUMBERS_API = "https://bankcodesapi.com/au-bsb/json";
private static final String API_KEY = "ab9379cfdab559509bbdcdd11923489f";
public static AustraliaBankInfo getBankInfo(String bsbNo) {
logger.info("<------------------>Start submitting branch bsb Numbers<--------------------->");
try {
HttpRequestResult result =
new HttpRequestGenerator(new URL(AUSTRALIA_BSB_NUMBERS_API, API_KEY, bsbNo).toString(), RequestMethod.GET)
.execute();
if (result.isSuccess()) {
JSONObject res = result.getResponseContentJSONObj();
logger.info("Success submitted branch bsb Numbers message ------> {}", res);
return AustraliaBankInfo.instance(res);
}
} catch (IOException e) {
logger.error("fail to submitting branch bsb Numbers, error ---> {}", e.getMessage());
}
return AustraliaBankInfo.noneInstance();
}
private static class URL {
private static String URL_TEMPLATE = "{url}/{apiKey}/{bsbNo}/";
private String url;
private String apiKey;
private String bsbNo;
public URL(String url, String apiKey, String bsbNo) {
this.url = url;
this.apiKey = apiKey;
this.bsbNo = bsbNo;
}
public String toString() {
return URL_TEMPLATE.replace("{url}", this.url)
.replace("{apiKey}", apiKey)
.replace("{bsbNo}", bsbNo);
}
}
}

@ -0,0 +1,14 @@
package au.com.royalpay.payment.manage.merchants.core.bank;
/**
* @Description
* @title:
* @Date 2020/11/12 16:07
* @author: zhangTao
*/
public class AustraliaBankClientNullException extends RuntimeException{
public AustraliaBankClientNullException() {
}
}

@ -0,0 +1,50 @@
package au.com.royalpay.payment.manage.merchants.core.bank;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import java.awt.*;
/**
* @Description
* @title:
* @Date 2020/11/12 15:56
* @author: zhangTao
*/
@Getter
public class AustraliaBankInfo {
private String bsb;
private String valid;
private String bank;
private String address;
private String system;
private String city;
private String postcode;
private String state;
private String branch;
public boolean isNone() {
return StringUtils.isBlank(this.bsb);
}
static AustraliaBankInfo instance(JSONObject australiaBankInfo){
AustraliaBankInfo bankInfo = new AustraliaBankInfo();
bankInfo.bsb = australiaBankInfo.getString("bsb");
bankInfo.valid = australiaBankInfo.getString("valid");
bankInfo.bank = australiaBankInfo.getString("bank");
bankInfo.address = australiaBankInfo.getString("address");
bankInfo.system = australiaBankInfo.getString("system");
bankInfo.city = australiaBankInfo.getString("city");
bankInfo.postcode = australiaBankInfo.getString("postcode");
bankInfo.state = australiaBankInfo.getString("state");
bankInfo.branch = australiaBankInfo.getString("branch");
return bankInfo;
}
static AustraliaBankInfo noneInstance() {
return new AustraliaBankInfo();
}
}

@ -47,6 +47,9 @@ import au.com.royalpay.payment.manage.merchants.core.ClientConfigService;
import au.com.royalpay.payment.manage.merchants.core.ClientInfoCacheSupport; import au.com.royalpay.payment.manage.merchants.core.ClientInfoCacheSupport;
import au.com.royalpay.payment.manage.merchants.core.ClientManager; import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.manage.merchants.core.ClientModifySupport; import au.com.royalpay.payment.manage.merchants.core.ClientModifySupport;
import au.com.royalpay.payment.manage.merchants.core.bank.AustraliaBank;
import au.com.royalpay.payment.manage.merchants.core.bank.AustraliaBankClientNullException;
import au.com.royalpay.payment.manage.merchants.core.bank.AustraliaBankInfo;
import au.com.royalpay.payment.manage.merchants.entity.impls.*; import au.com.royalpay.payment.manage.merchants.entity.impls.*;
import au.com.royalpay.payment.manage.merchants.enums.UPayAuthFileEnum; import au.com.royalpay.payment.manage.merchants.enums.UPayAuthFileEnum;
import au.com.royalpay.payment.manage.notice.core.MailService; import au.com.royalpay.payment.manage.notice.core.MailService;
@ -98,7 +101,6 @@ import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.Order; import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds; import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList; import com.github.miemiedev.mybatis.paginator.domain.PageList;
import io.jsonwebtoken.lang.Assert;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
@ -2746,24 +2748,33 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
@Override @Override
public JSONObject getBankInfo(JSONObject manager, String clientMoniker, String bsbNo) { public JSONObject getBankInfo(JSONObject manager, String clientMoniker, String bsbNo) {
JSONObject client = getClientInfoByMoniker(clientMoniker); Optional<JSONObject> clientOptional = Optional.ofNullable(getClientInfoByMoniker(clientMoniker));
if (client == null) {
throw new InvalidShortIdException(); if (!clientOptional.isPresent()) {
throw new AustraliaBankClientNullException();
} }
checkOrgPermission(manager, client);
// bd451cc3e3ad66c75165dc852507e8f0 checkOrgPermission(manager, clientOptional.get());
// 收费 ab9379cfdab559509bbdcdd11923489f
String url = "https://api.bank.codes/au-bsb/json/ab9379cfdab559509bbdcdd11923489f/" + bsbNo; AustraliaBankInfo bankInfo = AustraliaBank.getBankInfo(bsbNo);
JSONObject res = new JSONObject();
try { if (bankInfo.isNone()) {
HttpRequestResult result = new HttpRequestGenerator(url, RequestMethod.GET).execute(); return new JSONObject();
if (result.isSuccess()) {
res = result.getResponseContentJSONObj();
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
} }
return res;
return new JSONObject() {
{
put("bsb", bankInfo.getBsb());
put("valid", bankInfo.getValid());
put("bank", bankInfo.getBank());
put("address", bankInfo.getAddress());
put("system", bankInfo.getSystem());
put("city", bankInfo.getCity());
put("postcode", bankInfo.getPostcode());
put("state", bankInfo.getState());
put("branch", bankInfo.getBranch());
}
};
} }
@Override @Override

@ -1,9 +1,11 @@
package au.com.royalpay.payment.manage.merchants.web; package au.com.royalpay.payment.manage.merchants.web;
import au.com.royalpay.payment.channels.rpaypaymentsvc.runtime.request.entities.RPayMerchantEntity; import au.com.royalpay.payment.channels.rpaypaymentsvc.runtime.request.entities.RPayMerchantEntity;
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
import au.com.royalpay.payment.manage.dev.core.MerchantLocationService; import au.com.royalpay.payment.manage.dev.core.MerchantLocationService;
import au.com.royalpay.payment.manage.merchants.beans.*; import au.com.royalpay.payment.manage.merchants.beans.*;
import au.com.royalpay.payment.manage.merchants.core.ClientManager; import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.manage.merchants.core.bank.AustraliaBankClientNullException;
import au.com.royalpay.payment.manage.permission.manager.ManagerMapping; import au.com.royalpay.payment.manage.permission.manager.ManagerMapping;
import au.com.royalpay.payment.manage.permission.manager.RequireManager; import au.com.royalpay.payment.manage.permission.manager.RequireManager;
import au.com.royalpay.payment.manage.pos.datasource.ReadOnlyConnection; import au.com.royalpay.payment.manage.pos.datasource.ReadOnlyConnection;
@ -435,9 +437,13 @@ public class PartnerManageController {
} }
@GetMapping("/{clientMoniker}/bank_account/bank_info/{bsb_no}") @GetMapping("/{clientMoniker}/bank_account/bank_info/{bsb_no}")
public JSONObject getBankInfo(@PathVariable String clientMoniker, @PathVariable String bsb_no, public JSONObject getBankInfo(@PathVariable String clientMoniker, @PathVariable("bsb_no") String bsbNo,
@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) {
return clientManager.getBankInfo(manager, clientMoniker, bsb_no); try {
return clientManager.getBankInfo(manager, clientMoniker, bsbNo);
}catch (AustraliaBankClientNullException e){
throw new InvalidShortIdException();
}
} }
@ManagerMapping(value = "/{clientMoniker}/bank_account", method = RequestMethod.PUT, role = {ManagerRole.OPERATOR, ManagerRole.BD_USER, ManagerRole.FINANCIAL_STAFF}) @ManagerMapping(value = "/{clientMoniker}/bank_account", method = RequestMethod.PUT, role = {ManagerRole.OPERATOR, ManagerRole.BD_USER, ManagerRole.FINANCIAL_STAFF})

Loading…
Cancel
Save