feature: new customized settle api

master
Yixian 3 years ago
parent da5db14d27
commit 11430810eb

@ -1,18 +1,12 @@
package au.com.royalpay.payment.manage.dev.web; 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.beans.SubMerchantInfoInheritance;
import au.com.royalpay.payment.channels.wechat.runtime.impls.WxPayMerchantRegister; 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.channels.wechat.runtime.mappers.PaymentChannelMccGoodMapper;
import au.com.royalpay.payment.core.PaymentApi; import au.com.royalpay.payment.core.PaymentApi;
import au.com.royalpay.payment.core.PaymentDevHelper; 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.exceptions.InvalidShortIdException;
import au.com.royalpay.payment.core.impls.MerchantChannelApplicationManager; 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.ATOReportService;
import au.com.royalpay.payment.manage.analysis.core.DashboardService; import au.com.royalpay.payment.manage.analysis.core.DashboardService;
import au.com.royalpay.payment.manage.analysis.core.PlatformClearService; 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.AliforexcelService;
import au.com.royalpay.payment.manage.dev.core.AlipayRegisterService; import au.com.royalpay.payment.manage.dev.core.AlipayRegisterService;
import au.com.royalpay.payment.manage.dev.core.WechatMessageService; 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.OrderMapper;
import au.com.royalpay.payment.manage.mappers.payment.RefundMapper; import au.com.royalpay.payment.manage.mappers.payment.RefundMapper;
import au.com.royalpay.payment.manage.mappers.system.*; import au.com.royalpay.payment.manage.mappers.system.*;
@ -69,12 +65,13 @@ import javax.validation.Valid;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.security.InvalidParameterException;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; 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. * Created by yixian on 2016-07-06.
@ -106,6 +103,8 @@ public class TestController {
@Resource @Resource
private PaymentApi paymentApi; private PaymentApi paymentApi;
@Resource @Resource
private SettleTasksService settleTasksService;
@Resource
private TradeLogService tradeLogService; private TradeLogService tradeLogService;
@Resource @Resource
private RetailAppService retailAppService; private RetailAppService retailAppService;
@ -127,8 +126,6 @@ public class TestController {
@Resource @Resource
private PaymentDevHelper paymentDevHelper; private PaymentDevHelper paymentDevHelper;
@Resource @Resource
private PmtCustomReportMapper pmtCustomReportsMapper;
@Resource
private SysWxMerchantApplyMapper sysWxMerchantApplyMapper; private SysWxMerchantApplyMapper sysWxMerchantApplyMapper;
@Resource @Resource
private PaymentChannelMccGoodMapper paymentChannelMccGoodMapper; private PaymentChannelMccGoodMapper paymentChannelMccGoodMapper;
@ -260,12 +257,12 @@ public class TestController {
JSONObject alipayApsCashierRate = merchantInfoProvider.clientCurrentRate(client.getIntValue("client_id"), new Date(), PayChannel.ALIPAY_APS_CASHIER.getChannelCode()); JSONObject alipayApsCashierRate = merchantInfoProvider.clientCurrentRate(client.getIntValue("client_id"), new Date(), PayChannel.ALIPAY_APS_CASHIER.getChannelCode());
if (alipayApsCashierRate != null) { if (alipayApsCashierRate != null) {
client.put("aps_cashier_rate", alipayApsCashierRate.getBigDecimal("rate_value").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(BigDecimal.valueOf(100)).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()); JSONObject alipayApsInstoreRate = merchantInfoProvider.clientCurrentRate(client.getIntValue("client_id"), new Date(), PayChannel.ALIPAY_APS_IN_STORE.getChannelCode());
if (alipayApsInstoreRate != null) { if (alipayApsInstoreRate != null) {
client.put("aps_instore_rate", alipayApsInstoreRate.getBigDecimal("rate_value").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(BigDecimal.valueOf(100)).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")); client.put("alipayplus_clean", alipayApsInstoreRate.getString("clean_days"));
} }
} catch (Exception ignored) { } catch (Exception ignored) {
@ -436,6 +433,11 @@ public class TestController {
aliforexcelService.registerRangeAlipayOnlineMerchant(start, end); 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") @GetMapping(value = "/register/alipayGms")
public void registerAlipayMerchant() { public void registerAlipayMerchant() {
aliforexcelService.registerAlipayMerchant(); aliforexcelService.registerAlipayMerchant();

@ -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;
}
}

@ -1,5 +1,6 @@
package au.com.royalpay.payment.manage.management.clearing.core; 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 au.com.royalpay.payment.manage.management.clearing.web.ManualSettleTask;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
@ -14,6 +15,8 @@ public interface SettleTasksService {
void submitTasks(List<ManualSettleTask> tasks); void submitTasks(List<ManualSettleTask> tasks);
JSONObject submitCustomizedSettle(CustomizedSettleRequest settleRequest, JSONObject manager);
List<JSONObject> analysisYesterdayTransaction(); List<JSONObject> analysisYesterdayTransaction();
} }

@ -1,6 +1,7 @@
package au.com.royalpay.payment.manage.management.clearing.core.impl; package au.com.royalpay.payment.manage.management.clearing.core.impl;
import au.com.royalpay.payment.core.PaymentApi; 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.core.SettleTasksService;
import au.com.royalpay.payment.manage.management.clearing.web.ManualSettleTask; import au.com.royalpay.payment.manage.management.clearing.web.ManualSettleTask;
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper; 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.data.redis.core.StringRedisTemplate;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity; import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.ByteArrayHttpMessageConverter; import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -51,6 +53,7 @@ public class SettleTaskServiceImpl implements SettleTasksService {
private final String transactionHost; private final String transactionHost;
private final AppLiveCheck appLiveCheck; private final AppLiveCheck appLiveCheck;
private static final String SETTLE_TASK_URI = "/dev/manual/settle_tasks"; 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, public SettleTaskServiceImpl(SysSettlePlanMapper planMapper, StringRedisTemplate redisTemplate,
MerchantInfoProvider mchInfoProvider, PaymentApi paymentApi, TransactionMapper transactionMapper, @Value("${app.redis.prefix}") String prefix, 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<String> 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 @Override
public List<JSONObject> analysisYesterdayTransaction() { public List<JSONObject> analysisYesterdayTransaction() {
Date from = DateTime.now().withMillisOfDay(0).withZoneRetainFields(DateTimeZone.forTimeZone(TimeZone.getTimeZone("Asia/Shanghai"))) Date from = DateTime.now().withMillisOfDay(0).withZoneRetainFields(DateTimeZone.forTimeZone(TimeZone.getTimeZone("Asia/Shanghai")))

Loading…
Cancel
Save