diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientManager.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientManager.java index 5d8e10901..8130e20e7 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientManager.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientManager.java @@ -45,6 +45,8 @@ public interface ClientManager { String initMerchantCode(); + boolean getMerchantIsValid(String clientMoniker); + @Transactional JSONObject registerClient(String clientMoniker, ClientRegisterInfo registery, JSONObject manager); diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java index 1e74e9ae0..c0f5384ca 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java @@ -633,12 +633,20 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid @Override public String initMerchantCode() { String code = RandomStringUtils.randomAlphanumeric(4).toUpperCase(); - if (clientMapper.getPartnercode(code) > 0) { + if (!getMerchantIsValid(code)) { return initMerchantCode(); } return code; } + @Override + public boolean getMerchantIsValid(String clientMoniker) { + if (clientMapper.getPartnercode(clientMoniker) > 0) { + return false; + } + return true; + } + @Override @Transactional public JSONObject registerClient(String clientMoniker, ClientRegisterInfo registery, JSONObject manager) { diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/web/PartnerManageController.java b/src/main/java/au/com/royalpay/payment/manage/merchants/web/PartnerManageController.java index 3df2f98fc..8d7ddadfa 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/web/PartnerManageController.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/web/PartnerManageController.java @@ -54,6 +54,11 @@ public class PartnerManageController { return clientManager.initMerchantCode(); } + @RequestMapping(value = "/init/check_code_isvalid", method = RequestMethod.GET) + public boolean getMerchantIsValid(@RequestParam String clientMoniker) { + return clientManager.getMerchantIsValid(clientMoniker); + } + @RequestMapping(method = RequestMethod.POST) @RequireManager(role = {ManagerRole.ADMIN, ManagerRole.BD_USER, ManagerRole.OPERATOR}) public JSONObject registerPartner(@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager, @RequestBody @Valid ClientRegisterInfo registery, diff --git a/src/main/ui/static/payment/partner/partner-manage.js b/src/main/ui/static/payment/partner/partner-manage.js index fc9907856..1f2684509 100644 --- a/src/main/ui/static/payment/partner/partner-manage.js +++ b/src/main/ui/static/payment/partner/partner-manage.js @@ -371,6 +371,8 @@ define(['angular', 'decimal', 'static/commons/commons', 'uiBootstrap', 'uiRouter $scope.initMerchantCode = function () { $http.get('/sys/partners/init/merchant_code').then(function (response) { $scope.partner.client_moniker = response.data; + $scope.merchantCodeChecked = true; + $scope.merchantIsValid = true; }); }; $scope.initMerchantCode(); @@ -437,6 +439,8 @@ define(['angular', 'decimal', 'static/commons/commons', 'uiBootstrap', 'uiRouter $scope.clean_days = angular.copy(clean_days_map); $scope.bd_citys = angular.copy(bd_city_map); $scope.params = {textType: 'all', org_name: 'ALL'}; + $scope.merchantIsValid = false; + $scope.merchantCodeChecked = false; function remove(arr, val) { if (angular.isArray(arr)) { @@ -526,6 +530,17 @@ define(['angular', 'decimal', 'static/commons/commons', 'uiBootstrap', 'uiRouter // $scope.t2city_map = angular.copy(t2city_map); $scope.timezones = timezone.configs(); + $scope.checkMerchantCodeIsValid = function (code) { + if (code.length != 4) { + $scope.merchantCodeChecked = false; + $scope.merchantIsValid = false; + return; + } + $http.get('/sys/partners/init/check_code_isvalid',{params:{clientMoniker:code}}).then(function (response) { + $scope.merchantIsValid = response.data; + $scope.merchantCodeChecked = true; + }); + }; $scope.save = function (form) { if (form.$invalid) { angular.forEach(form, function (item, key) { diff --git a/src/main/ui/static/payment/partner/templates/add_partner.html b/src/main/ui/static/payment/partner/templates/add_partner.html index b371dd5c8..1e5dec61c 100644 --- a/src/main/ui/static/payment/partner/templates/add_partner.html +++ b/src/main/ui/static/payment/partner/templates/add_partner.html @@ -40,8 +40,12 @@ type="text" name="client_moniker" id="short-id-input" required maxlength="4" - ng-pattern="/^[a-zA-Z0-9]+$/" readonly> + ng-pattern="/^[a-zA-Z0-9]+$/" ng-change="checkMerchantCodeIsValid(partner.client_moniker)"> + + + +
No further changeable!