feat:流水错误修改
This commit is contained in:
1 parent
3ae6fdbfb4
commit
c0285edd4c
29 files changed
+2631
-1111
No files matched your search
+12
-12
@@ -242,7 +242,7 @@ public class ThirdPayApiServiceImpl implements ThirdPayApiService {
|
||||
long startTime = System.currentTimeMillis();
|
||||
ThirdPayLogEntity logObj = ThirdPayLogEntity.builder().apiUrl("/third/third-pay-api/water").bizType(ThirdPayApiBizTypeEnum.WATER.getType()).req(json).header(JSONUtil.toJsonStr(headers)).paySourceType(getPaySourceType(headers)).build();
|
||||
// 开始处理
|
||||
PayBaseVo baseVo = new PayBaseVo<PayWalletInfoVo>();
|
||||
PayBaseVo<List<PayWaterVo>> baseVo = new PayBaseVo<>();
|
||||
ThirdKeyManageEntity keySetting = keyManageService.checkSignAndReturnConfig(json, headers);
|
||||
if (ObjectUtil.isEmpty(keySetting)) {
|
||||
baseVo.set(ThirdPayVoStatusEnum.SIGN_ERROR);
|
||||
@@ -259,18 +259,18 @@ public class ThirdPayApiServiceImpl implements ThirdPayApiService {
|
||||
if (dto.getSize() > 200L) dto.setSize(200L);
|
||||
try {
|
||||
PayBaseVo<List<PayWaterVo>> pageList = hardThirdPayService.waterList(dto, ThirdPaySoureBizTypeEnum.valueOfByType(keySetting.getBizType()));
|
||||
if (ObjectUtil.isEmpty(pageList.getData())) {
|
||||
baseVo.set(ThirdPayVoStatusEnum.UNKNOWN_ERROR);
|
||||
baseVo.setData(pageList.getData());
|
||||
// 日志
|
||||
logObj.setRes(JSONUtil.toJsonStr(baseVo));
|
||||
logObj.setTimeConsuming(Long.toString(System.currentTimeMillis() - startTime));
|
||||
payLogService.save(logObj);
|
||||
return baseVo;
|
||||
if (ObjectUtil.isEmpty(pageList)) {
|
||||
throw new RuntimeException("流水查询失败");
|
||||
}
|
||||
// 加密一下手机号
|
||||
for (PayWaterVo item : pageList.getData()) {
|
||||
item.setSignPhone(LbRetailSignUtils.sm4Encrypt(item.getSignPhone(), keySetting.getFieldKey()));
|
||||
if (ObjectUtil.equal(pageList.getCode(), ThirdPayVoStatusEnum.SUCCESS.getType())) {
|
||||
// 查询成功但没有流水时,统一返回空数组。
|
||||
if (ObjectUtil.isEmpty(pageList.getData())) {
|
||||
pageList.setData(List.of());
|
||||
}
|
||||
// 加密一下手机号
|
||||
for (PayWaterVo item : pageList.getData()) {
|
||||
item.setSignPhone(LbRetailSignUtils.sm4Encrypt(item.getSignPhone(), keySetting.getFieldKey()));
|
||||
}
|
||||
}
|
||||
// 日志
|
||||
logObj.setRes(JSONUtil.toJsonStr(pageList));
|
||||
|
||||
+62
@@ -1,5 +1,6 @@
|
||||
package com.bsd.pjcloud.thirdparty.service.impl.pay;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.bsd.pjcloud.hard.api.feign.RemoteHardThirdPayService;
|
||||
import com.bsd.pjcloud.thirdparty.constant.ThirdKeyTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPaySoureBizTypeEnum;
|
||||
@@ -13,6 +14,7 @@ import com.bsd.pjcloud.thirdparty.vo.pay.PayWaterVo;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.junit.jupiter.params.provider.EmptySource;
|
||||
import org.junit.jupiter.params.provider.NullSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
@@ -69,6 +71,66 @@ class ThirdPayWaterSourceTest {
|
||||
verify(fixture.logs).save(any(ThirdPayLogEntity.class));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@NullSource
|
||||
@EmptySource
|
||||
void successfulQueryWithoutOrdersReturnsAnEmptyArray(List<PayWaterVo> data) {
|
||||
Fixture fixture = new Fixture(ThirdPaySoureBizTypeEnum.LB);
|
||||
PayBaseVo<List<PayWaterVo>> response = new PayBaseVo<>();
|
||||
response.setCode(200);
|
||||
response.setMessage("成功");
|
||||
response.setData(data);
|
||||
when(fixture.hardware.waterList(any(), eq(ThirdPaySoureBizTypeEnum.LB))).thenReturn(response);
|
||||
Map<String, String> headers = fixture.headers();
|
||||
headers.put("BIZ-TYPE", "10");
|
||||
|
||||
PayBaseVo<List<PayWaterVo>> result = fixture.service.water(JSON, headers);
|
||||
|
||||
assertEquals(200, result.getCode());
|
||||
assertNotNull(result.getData());
|
||||
assertTrue(result.getData().isEmpty());
|
||||
ArgumentCaptor<ThirdPayLogEntity> log = ArgumentCaptor.forClass(ThirdPayLogEntity.class);
|
||||
verify(fixture.logs).save(log.capture());
|
||||
assertEquals(JSONUtil.toJsonStr(result), log.getValue().getRes());
|
||||
assertTrue(JSONUtil.parseObj(log.getValue().getRes()).getJSONArray("data").isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {500, 503, 599})
|
||||
void downstreamBusinessErrorsKeepTheirOriginalCode(int code) {
|
||||
Fixture fixture = new Fixture(ThirdPaySoureBizTypeEnum.LB);
|
||||
PayBaseVo<List<PayWaterVo>> response = new PayBaseVo<>();
|
||||
response.setCode(code);
|
||||
response.setMessage("业务错误");
|
||||
when(fixture.hardware.waterList(any(), eq(ThirdPaySoureBizTypeEnum.LB))).thenReturn(response);
|
||||
Map<String, String> headers = fixture.headers();
|
||||
headers.put("BIZ-TYPE", "10");
|
||||
|
||||
PayBaseVo<List<PayWaterVo>> result = fixture.service.water(JSON, headers);
|
||||
|
||||
assertSame(response, result);
|
||||
assertEquals(code, result.getCode());
|
||||
assertEquals("业务错误", result.getMessage());
|
||||
verify(fixture.logs).save(any(ThirdPayLogEntity.class));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {false, true})
|
||||
void failedRemoteCallsStillReturnAnError(boolean throwsException) {
|
||||
Fixture fixture = new Fixture(ThirdPaySoureBizTypeEnum.LB);
|
||||
if (throwsException) {
|
||||
when(fixture.hardware.waterList(any(), eq(ThirdPaySoureBizTypeEnum.LB)))
|
||||
.thenThrow(new IllegalStateException("模拟调用失败"));
|
||||
} else {
|
||||
when(fixture.hardware.waterList(any(), eq(ThirdPaySoureBizTypeEnum.LB))).thenReturn(null);
|
||||
}
|
||||
Map<String, String> headers = fixture.headers();
|
||||
headers.put("BIZ-TYPE", "10");
|
||||
|
||||
assertEquals(599, fixture.service.water(JSON, headers).getCode());
|
||||
verify(fixture.logs).save(any(ThirdPayLogEntity.class));
|
||||
}
|
||||
|
||||
private static class Fixture {
|
||||
final ThirdKeyManageEntity config = new ThirdKeyManageEntity();
|
||||
final RemoteHardThirdPayService hardware = mock(RemoteHardThirdPayService.class);
|
||||
|
||||
Reference in new issue
Block a user