From 11430810eb8f96867c210f605e2ef82ca63c40d9 Mon Sep 17 00:00:00 2001 From: Yixian Date: Mon, 28 Mar 2022 18:06:28 +0800 Subject: [PATCH] feature: new customized settle api --- .../manage/dev/web/TestController.java | 36 +++++------ .../beans/CustomizedSettleRequest.java | 61 +++++++++++++++++++ .../clearing/core/SettleTasksService.java | 3 + .../core/impl/SettleTaskServiceImpl.java | 33 ++++++++++ 4 files changed, 116 insertions(+), 17 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/management/clearing/beans/CustomizedSettleRequest.java diff --git a/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java b/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java index 4d7101b2e..f3c7ee7b0 100644 --- a/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java +++ b/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java @@ -1,18 +1,12 @@ package au.com.royalpay.payment.manage.dev.web; -import au.com.royalpay.payment.channels.alipay.config.AlipayConfig; -import au.com.royalpay.payment.channels.alipay.config.AlipayEnvironment; -import au.com.royalpay.payment.channels.alipay.runtime.AlipayOnlineApi; -import au.com.royalpay.payment.channels.alipay.runtime.AlipayRetailApi; import au.com.royalpay.payment.channels.wechat.runtime.beans.SubMerchantInfoInheritance; import au.com.royalpay.payment.channels.wechat.runtime.impls.WxPayMerchantRegister; import au.com.royalpay.payment.channels.wechat.runtime.mappers.PaymentChannelMccGoodMapper; import au.com.royalpay.payment.core.PaymentApi; import au.com.royalpay.payment.core.PaymentDevHelper; -import au.com.royalpay.payment.core.beans.EmptyMerchantApplication; import au.com.royalpay.payment.core.exceptions.InvalidShortIdException; import au.com.royalpay.payment.core.impls.MerchantChannelApplicationManager; -import au.com.royalpay.payment.core.mappers.PmtCustomReportMapper; import au.com.royalpay.payment.manage.analysis.core.ATOReportService; import au.com.royalpay.payment.manage.analysis.core.DashboardService; import au.com.royalpay.payment.manage.analysis.core.PlatformClearService; @@ -23,6 +17,8 @@ import au.com.royalpay.payment.manage.dev.bean.SendWechatMessage; import au.com.royalpay.payment.manage.dev.core.AliforexcelService; import au.com.royalpay.payment.manage.dev.core.AlipayRegisterService; import au.com.royalpay.payment.manage.dev.core.WechatMessageService; +import au.com.royalpay.payment.manage.management.clearing.beans.CustomizedSettleRequest; +import au.com.royalpay.payment.manage.management.clearing.core.SettleTasksService; import au.com.royalpay.payment.manage.mappers.payment.OrderMapper; import au.com.royalpay.payment.manage.mappers.payment.RefundMapper; import au.com.royalpay.payment.manage.mappers.system.*; @@ -69,12 +65,13 @@ import javax.validation.Valid; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.math.BigDecimal; import java.math.RoundingMode; -import java.security.InvalidParameterException; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Optional; /** * Created by yixian on 2016-07-06. @@ -106,6 +103,8 @@ public class TestController { @Resource private PaymentApi paymentApi; @Resource + private SettleTasksService settleTasksService; + @Resource private TradeLogService tradeLogService; @Resource private RetailAppService retailAppService; @@ -127,8 +126,6 @@ public class TestController { @Resource private PaymentDevHelper paymentDevHelper; @Resource - private PmtCustomReportMapper pmtCustomReportsMapper; - @Resource private SysWxMerchantApplyMapper sysWxMerchantApplyMapper; @Resource private PaymentChannelMccGoodMapper paymentChannelMccGoodMapper; @@ -259,13 +256,13 @@ public class TestController { } JSONObject alipayApsCashierRate = merchantInfoProvider.clientCurrentRate(client.getIntValue("client_id"), new Date(), PayChannel.ALIPAY_APS_CASHIER.getChannelCode()); if (alipayApsCashierRate != null) { - client.put("aps_cashier_rate", alipayApsCashierRate.getBigDecimal("rate_value").setScale(2, RoundingMode.DOWN)+"%"); - client.put("aps_cashier_service_rate", alipayApsCashierRate.getBigDecimal("transaction_fee").multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.DOWN)+"%"); + client.put("aps_cashier_rate", alipayApsCashierRate.getBigDecimal("rate_value").setScale(2, RoundingMode.DOWN) + "%"); + client.put("aps_cashier_service_rate", alipayApsCashierRate.getBigDecimal("transaction_fee").multiply(CommonConsts.HUNDRED).setScale(2, RoundingMode.DOWN) + "%"); } JSONObject alipayApsInstoreRate = merchantInfoProvider.clientCurrentRate(client.getIntValue("client_id"), new Date(), PayChannel.ALIPAY_APS_IN_STORE.getChannelCode()); if (alipayApsInstoreRate != null) { - client.put("aps_instore_rate", alipayApsInstoreRate.getBigDecimal("rate_value").setScale(2, RoundingMode.DOWN)+"%"); - client.put("aps_instore_service_rate",alipayApsInstoreRate.getBigDecimal("transaction_fee").multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.DOWN)+"%"); + client.put("aps_instore_rate", alipayApsInstoreRate.getBigDecimal("rate_value").setScale(2, RoundingMode.DOWN) + "%"); + client.put("aps_instore_service_rate", alipayApsInstoreRate.getBigDecimal("transaction_fee").multiply(CommonConsts.HUNDRED).setScale(2, RoundingMode.DOWN) + "%"); client.put("alipayplus_clean", alipayApsInstoreRate.getString("clean_days")); } } catch (Exception ignored) { @@ -436,6 +433,11 @@ public class TestController { aliforexcelService.registerRangeAlipayOnlineMerchant(start, end); } + @ManagerMapping(value = "/customized_settle", method = RequestMethod.POST, role = ManagerRole.DEVELOPER) + public JSONObject sendCustomizedSettle(@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager, @RequestBody CustomizedSettleRequest req) { + return settleTasksService.submitCustomizedSettle(req, manager); + } + @GetMapping(value = "/register/alipayGms") public void registerAlipayMerchant() { aliforexcelService.registerAlipayMerchant(); @@ -824,14 +826,14 @@ public class TestController { } - int st=0; + int st = 0; /** * 批量更新支付宝子商户号报备 */ @GetMapping(value = "/batch_update_alipayapply") public void batchUpdateAlipayApply() { - if(st>0){ + if (st > 0) { return; } st++; diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/beans/CustomizedSettleRequest.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/beans/CustomizedSettleRequest.java new file mode 100644 index 000000000..f45100ae2 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/beans/CustomizedSettleRequest.java @@ -0,0 +1,61 @@ +package au.com.royalpay.payment.manage.management.clearing.beans; + +import au.com.royalpay.payment.tools.merchants.beans.BalanceGroup; +import com.alibaba.fastjson.PropertyNamingStrategy; +import com.alibaba.fastjson.annotation.JSONType; + +import java.math.BigDecimal; + +@JSONType(naming = PropertyNamingStrategy.SnakeCase) +public class CustomizedSettleRequest { + private String clientMoniker; + private BigDecimal amount; + private int clearingStatus = 0; + private BalanceGroup balanceGroup = BalanceGroup.NORMAL_CROSS_BORDER; + private boolean forceSettle = false; + + public String getClientMoniker() { + return clientMoniker; + } + + public CustomizedSettleRequest setClientMoniker(String clientMoniker) { + this.clientMoniker = clientMoniker; + return this; + } + + public BigDecimal getAmount() { + return amount; + } + + public CustomizedSettleRequest setAmount(BigDecimal amount) { + this.amount = amount; + return this; + } + + public int getClearingStatus() { + return clearingStatus; + } + + public CustomizedSettleRequest setClearingStatus(int clearingStatus) { + this.clearingStatus = clearingStatus; + return this; + } + + public BalanceGroup getBalanceGroup() { + return balanceGroup; + } + + public CustomizedSettleRequest setBalanceGroup(BalanceGroup balanceGroup) { + this.balanceGroup = balanceGroup; + return this; + } + + public boolean isForceSettle() { + return forceSettle; + } + + public CustomizedSettleRequest setForceSettle(boolean forceSettle) { + this.forceSettle = forceSettle; + return this; + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/SettleTasksService.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/SettleTasksService.java index 141f7ae3e..15e7ee7cf 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/SettleTasksService.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/SettleTasksService.java @@ -1,5 +1,6 @@ package au.com.royalpay.payment.manage.management.clearing.core; +import au.com.royalpay.payment.manage.management.clearing.beans.CustomizedSettleRequest; import au.com.royalpay.payment.manage.management.clearing.web.ManualSettleTask; import com.alibaba.fastjson.JSONObject; @@ -14,6 +15,8 @@ public interface SettleTasksService { void submitTasks(List tasks); + JSONObject submitCustomizedSettle(CustomizedSettleRequest settleRequest, JSONObject manager); + List analysisYesterdayTransaction(); } diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/SettleTaskServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/SettleTaskServiceImpl.java index 4c391876b..29c8fad34 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/SettleTaskServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/SettleTaskServiceImpl.java @@ -1,6 +1,7 @@ package au.com.royalpay.payment.manage.management.clearing.core.impl; import au.com.royalpay.payment.core.PaymentApi; +import au.com.royalpay.payment.manage.management.clearing.beans.CustomizedSettleRequest; import au.com.royalpay.payment.manage.management.clearing.core.SettleTasksService; import au.com.royalpay.payment.manage.management.clearing.web.ManualSettleTask; import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper; @@ -22,6 +23,7 @@ import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.http.MediaType; import org.springframework.http.RequestEntity; +import org.springframework.http.ResponseEntity; import org.springframework.http.converter.ByteArrayHttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.stereotype.Service; @@ -51,6 +53,7 @@ public class SettleTaskServiceImpl implements SettleTasksService { private final String transactionHost; private final AppLiveCheck appLiveCheck; private static final String SETTLE_TASK_URI = "/dev/manual/settle_tasks"; + private static final String CUSTOMIZED_SETTLE_URI = "/dev/manual/customized_settle"; public SettleTaskServiceImpl(SysSettlePlanMapper planMapper, StringRedisTemplate redisTemplate, MerchantInfoProvider mchInfoProvider, PaymentApi paymentApi, TransactionMapper transactionMapper, @Value("${app.redis.prefix}") String prefix, @@ -124,6 +127,36 @@ public class SettleTaskServiceImpl implements SettleTasksService { } } + @Override + public JSONObject submitCustomizedSettle(CustomizedSettleRequest settleRequest, JSONObject manager) { + URI uri = UriComponentsBuilder.fromHttpUrl(transactionHost).replacePath(CUSTOMIZED_SETTLE_URI) + .build().toUri(); + try { + JSONObject req = new JSONObject(); + req.put("client_moniker", settleRequest.getClientMoniker()); + req.put("amount", settleRequest.getAmount()); + req.put("clearing_status", settleRequest.getClearingStatus()); + req.put("balance_group", settleRequest.getBalanceGroup().name()); + req.put("operator", manager.getString("manager_id")); + req.put("force_settle", settleRequest.isForceSettle()); + String taskStr = JSON.toJSONString(req); + logger.info("submitting customized settlement task:{}--------->{}", uri, taskStr); + ResponseEntity result = restTemplate.exchange(RequestEntity.post(uri).contentType(MediaType.APPLICATION_JSON) + .body(taskStr.getBytes(StandardCharsets.UTF_8)), String.class); + return JSON.parseObject(result.getBody()); + } catch (RestClientResponseException e) { + String resp = e.getResponseBodyAsString(); + try { + JSONObject respJson = JSON.parseObject(resp); + throw new ServerErrorException(respJson.getString("message")); + } catch (JSONException e1) { + throw new ServerErrorException(resp); + } + } catch (RestClientException e) { + throw new ServerErrorException(e.getMessage()); + } + } + @Override public List analysisYesterdayTransaction() { Date from = DateTime.now().withMillisOfDay(0).withZoneRetainFields(DateTimeZone.forTimeZone(TimeZone.getTimeZone("Asia/Shanghai")))