mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
sonarqube质量修复
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
package com.cf.imes.framework.common.core;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Key Value 的键值对
|
||||
*
|
||||
* @author 晨丰科技
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class KeyValue<K, V> implements Serializable {
|
||||
|
||||
private K key;
|
||||
private V value;
|
||||
|
||||
}
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package com.cf.imes.framework.common.util.collection;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.cf.imes.framework.common.core.KeyValue;
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
@@ -56,7 +56,7 @@ public class MapUtils {
|
||||
consumer.accept(value);
|
||||
}
|
||||
|
||||
public static <K, V> Map<K, V> convertMap(List<KeyValue<K, V>> keyValues) {
|
||||
public static <K, V> Map<K, V> convertMap(List<Pair<K, V>> keyValues) {
|
||||
Map<K, V> map = Maps.newLinkedHashMapWithExpectedSize(keyValues.size());
|
||||
keyValues.forEach(keyValue -> map.put(keyValue.getKey(), keyValue.getValue()));
|
||||
return map;
|
||||
|
||||
+10
-10
@@ -1,7 +1,7 @@
|
||||
package com.cf.imes.framework.dict.core.util;
|
||||
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.cf.imes.framework.common.core.KeyValue;
|
||||
import com.cf.imes.framework.common.util.cache.CacheUtils;
|
||||
import com.cf.imes.module.system.api.dict.DictDataApi;
|
||||
import com.cf.imes.module.system.api.dict.dto.DictDataRespDTO;
|
||||
@@ -27,12 +27,12 @@ public class DictFrameworkUtils {
|
||||
/**
|
||||
* 针对 {@link #getDictDataLabel(String, String)} 的缓存
|
||||
*/
|
||||
private static final LoadingCache<KeyValue<String, String>, DictDataRespDTO> GET_DICT_DATA_CACHE = CacheUtils.buildAsyncReloadingCache(
|
||||
private static final LoadingCache<Pair<String, String>, DictDataRespDTO> GET_DICT_DATA_CACHE = CacheUtils.buildAsyncReloadingCache(
|
||||
Duration.ofMinutes(1L), // 过期时间 1 分钟
|
||||
new CacheLoader<KeyValue<String, String>, DictDataRespDTO>() {
|
||||
new CacheLoader<>() {
|
||||
|
||||
@Override
|
||||
public DictDataRespDTO load(KeyValue<String, String> key) {
|
||||
public DictDataRespDTO load(Pair<String, String> key) {
|
||||
return ObjectUtil.defaultIfNull(dictDataApi.getDictData(key.getKey(), key.getValue()).getCheckedData(),
|
||||
DICT_DATA_NULL);
|
||||
}
|
||||
@@ -42,12 +42,12 @@ public class DictFrameworkUtils {
|
||||
/**
|
||||
* 针对 {@link #parseDictDataValue(String, String)} 的缓存
|
||||
*/
|
||||
private static final LoadingCache<KeyValue<String, String>, DictDataRespDTO> PARSE_DICT_DATA_CACHE = CacheUtils.buildAsyncReloadingCache(
|
||||
private static final LoadingCache<Pair<String, String>, DictDataRespDTO> PARSE_DICT_DATA_CACHE = CacheUtils.buildAsyncReloadingCache(
|
||||
Duration.ofMinutes(1L), // 过期时间 1 分钟
|
||||
new CacheLoader<KeyValue<String, String>, DictDataRespDTO>() {
|
||||
new CacheLoader<>() {
|
||||
|
||||
@Override
|
||||
public DictDataRespDTO load(KeyValue<String, String> key) {
|
||||
public DictDataRespDTO load(Pair<String, String> key) {
|
||||
return ObjectUtil.defaultIfNull(dictDataApi.parseDictData(key.getKey(), key.getValue()).getCheckedData(),
|
||||
DICT_DATA_NULL);
|
||||
}
|
||||
@@ -61,17 +61,17 @@ public class DictFrameworkUtils {
|
||||
|
||||
@SneakyThrows
|
||||
public static String getDictDataLabel(String dictType, Integer value) {
|
||||
return GET_DICT_DATA_CACHE.get(new KeyValue<>(dictType, String.valueOf(value))).getLabel();
|
||||
return GET_DICT_DATA_CACHE.get(new Pair<>(dictType, String.valueOf(value))).getLabel();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static String getDictDataLabel(String dictType, String value) {
|
||||
return GET_DICT_DATA_CACHE.get(new KeyValue<>(dictType, value)).getLabel();
|
||||
return GET_DICT_DATA_CACHE.get(new Pair<>(dictType, value)).getLabel();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static String parseDictDataValue(String dictType, String label) {
|
||||
return PARSE_DICT_DATA_CACHE.get(new KeyValue<>(dictType, label)).getValue();
|
||||
return PARSE_DICT_DATA_CACHE.get(new Pair<>(dictType, label)).getValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
@@ -16,6 +16,8 @@ import org.junit.jupiter.api.Test;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* {@link PayClientFactoryImpl} 的集成测试
|
||||
*
|
||||
@@ -43,6 +45,7 @@ public class PayClientFactoryImplIntegrationTest {
|
||||
Long channelId = RandomUtil.randomLong();
|
||||
payClientFactory.createOrUpdatePayClient(channelId, PayChannelEnum.WX_PUB.getCode(), config);
|
||||
PayClient client = payClientFactory.getPayClient(channelId);
|
||||
assertNotNull(client);
|
||||
// 发起支付
|
||||
PayOrderUnifiedReqDTO reqDTO = buildPayOrderUnifiedReqDTO();
|
||||
// CommonResult<?> result = client.unifiedOrder(reqDTO);
|
||||
@@ -66,6 +69,7 @@ public class PayClientFactoryImplIntegrationTest {
|
||||
Long channelId = RandomUtil.randomLong();
|
||||
payClientFactory.createOrUpdatePayClient(channelId, PayChannelEnum.WX_PUB.getCode(), config);
|
||||
PayClient client = payClientFactory.getPayClient(channelId);
|
||||
assertNotNull(client);
|
||||
// 发起支付
|
||||
PayOrderUnifiedReqDTO reqDTO = buildPayOrderUnifiedReqDTO();
|
||||
// CommonResult<?> result = client.unifiedOrder(reqDTO);
|
||||
@@ -89,6 +93,7 @@ public class PayClientFactoryImplIntegrationTest {
|
||||
Long channelId = RandomUtil.randomLong();
|
||||
payClientFactory.createOrUpdatePayClient(channelId, PayChannelEnum.ALIPAY_QR.getCode(), config);
|
||||
PayClient client = payClientFactory.getPayClient(channelId);
|
||||
assertNotNull(client);
|
||||
// 发起支付
|
||||
PayOrderUnifiedReqDTO reqDTO = buildPayOrderUnifiedReqDTO();
|
||||
reqDTO.setNotifyUrl("http://yunai.natapp1.cc/admin-api/pay/notify/callback/18"); // TODO @tina: 这里改成你的 natapp 回调地址
|
||||
@@ -113,6 +118,7 @@ public class PayClientFactoryImplIntegrationTest {
|
||||
Long channelId = RandomUtil.randomLong();
|
||||
payClientFactory.createOrUpdatePayClient(channelId, PayChannelEnum.ALIPAY_WAP.getCode(), config);
|
||||
PayClient client = payClientFactory.getPayClient(channelId);
|
||||
assertNotNull(client);
|
||||
// 发起支付
|
||||
PayOrderUnifiedReqDTO reqDTO = buildPayOrderUnifiedReqDTO();
|
||||
// CommonResult<?> result = client.unifiedOrder(reqDTO);
|
||||
|
||||
+7
@@ -18,6 +18,8 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* {@link WxBarPayClient} 的集成测试,用于快速调试微信条码支付
|
||||
*
|
||||
@@ -48,6 +50,8 @@ public class WxBarPayClientIntegrationTest {
|
||||
System.out.println(JsonUtils.toJsonPrettyString(request));
|
||||
WxPayMicropayResult response = client.micropay(request);
|
||||
System.out.println("========= response ==========");
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getTransactionId());
|
||||
System.out.println(JsonUtils.toJsonPrettyString(response));
|
||||
}
|
||||
|
||||
@@ -62,6 +66,7 @@ public class WxBarPayClientIntegrationTest {
|
||||
// 执行解析
|
||||
String xml = "<xml><return_code>SUCCESS</return_code><appid><![CDATA[wx62056c0d5e8db250]]></appid><mch_id><![CDATA[1545083881]]></mch_id><nonce_str><![CDATA[ed8f02c21d15635cede114a42d0525a0]]></nonce_str><req_info><![CDATA[bGp+wB9DAHjoOO9Nw1iSmmIFdN2zZDhsoRWZBYdf/8bcpjowr4T8i2qjLsbMtvKQeVC5kBZOL/Agal3be6UPwnoantil+L+ojZgvLch7dXFKs/AcoxIYcVYyGka+wmnRJfUmuFRBgzt++8HOFsmJz6e2brYv1EAz+93fP2AsJtRuw1FEzodcg8eXm52hbE0KhLNqC2OyNVkn8AbOOrwIxSYobg2jVbuJ4JllYbEGIQ/6kWzNbVmMKhGJGYBy/NbUGKoQsoe4QeTQqcqQqVp08muxaOfJGThaN3B9EEMFSrog/3yT7ykVV6WQ5+Ygt89LplOf5ucWa4Ird7VJhHWtzI92ZePj4Omy1XkT1TRlwtDegA0S5MeQpM4WZ1taMrhxgmNkTUJ0JXFncx5e2KLQvbvD/HOcccx48Xv1c16JBz6G3501k8E++LWXgZ2TeNXwGsk6FyRZb0ApLyQHIx5ZtPo/UET9z3AmJCPXkrUsZ4WK46fDtbzxVPU2r8nTOcGCPbO0LUsGT6wpsuQVC4CisXDJwoZmL6kKwHfKs6mmUL2YZYzNfgoB/KgpJYSpC96kcpQyFvw+xuwqK2SXGZbAl9lADT+a83z04feQHSSIG3PCrX4QEWzpCZZ4+ySEz1Y34aoU20X9GtX+1LSwUjmQgwHrMBSvFm3/B7+IFM8OUqDB+Uvkr9Uvy7P2/KDvfy3Ih7GFcGd0C5NXpSvVTTfu1IlK/T3/t6MR/8iq78pp/2ZTYvO6eNDRJWaXYU+x6sl2dTs9n+2Z4W4AfYTvEyuxlx+aI19SqCJh7WmaFcAxidFl/9iqDjWiplb9+C6ijZv2hJtVjSCuoptIWpGDYItH7RAqlKHrx6flJD+M/5BceMHBv2w4OWCD9vPRLo8gl9o06ip0iflzO1dixhOAgLFjsQmQHNGFtR3EvCID+iS4FUlilwK+hcKNxrr0wp9Btkl9W1R9aTo289CUiIxx45skfCYzHwb+7Hqj3uTiXnep6zhCKZBAnPsDOvISXfBgXKufcFsTNtts09jX8H5/uMc9wyJ179H1cp+At1mIK2duwfo4Q9asfEoffl6Zn1olGdtEruxHGeVU0NwJ8V7RflC/Cx5RXtJ3sPJ/sHmVnBlVyR0=]]></req_info></xml>";
|
||||
WxPayRefundNotifyResult response = client.parseRefundNotifyResult(xml);
|
||||
assertNotNull(response.getReqInfo().getTransactionId());
|
||||
System.out.println(response.getReqInfo());
|
||||
}
|
||||
|
||||
@@ -84,6 +89,7 @@ public class WxBarPayClientIntegrationTest {
|
||||
System.out.println(JsonUtils.toJsonPrettyString(request));
|
||||
WxPayRefundResult response = client.refund(request);
|
||||
System.out.println("========= response ==========");
|
||||
assertNotNull(response.getTransactionId());
|
||||
System.out.println(JsonUtils.toJsonPrettyString(response));
|
||||
}
|
||||
|
||||
@@ -105,6 +111,7 @@ public class WxBarPayClientIntegrationTest {
|
||||
System.out.println(JsonUtils.toJsonPrettyString(request));
|
||||
WxPayRefundV3Result response = client.refundV3(request);
|
||||
System.out.println("========= response ==========");
|
||||
assertNotNull(response.getTransactionId());
|
||||
System.out.println(JsonUtils.toJsonPrettyString(response));
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -15,6 +15,8 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* {@link WxNativePayClient} 的集成测试,用于快速调试微信扫码支付
|
||||
*
|
||||
@@ -43,6 +45,7 @@ public class WxNativePayClientIntegrationTest {
|
||||
System.out.println(JsonUtils.toJsonPrettyString(request));
|
||||
String response = client.createOrderV3(TradeTypeEnum.NATIVE, request);
|
||||
System.out.println("========= response ==========");
|
||||
assertNotNull(response);
|
||||
System.out.println(JsonUtils.toJsonPrettyString(response));
|
||||
}
|
||||
|
||||
@@ -64,6 +67,7 @@ public class WxNativePayClientIntegrationTest {
|
||||
System.out.println(JsonUtils.toJsonPrettyString(request));
|
||||
WxPayRefundV3Result response = client.refundV3(request);
|
||||
System.out.println("========= response ==========");
|
||||
assertNotNull(response.getTransactionId());
|
||||
System.out.println(JsonUtils.toJsonPrettyString(response));
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.cf.imes.framework.sms.core.client;
|
||||
|
||||
import com.cf.imes.framework.common.core.KeyValue;
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import com.cf.imes.framework.sms.core.client.dto.SmsReceiveRespDTO;
|
||||
import com.cf.imes.framework.sms.core.client.dto.SmsSendRespDTO;
|
||||
import com.cf.imes.framework.sms.core.client.dto.SmsTemplateRespDTO;
|
||||
@@ -24,7 +24,7 @@ public interface SmsClient {
|
||||
* @return 短信发送结果
|
||||
*/
|
||||
SmsSendRespDTO sendSms(Long logId, String mobile, String apiTemplateId,
|
||||
List<KeyValue<String, Object>> templateParams) throws Throwable;
|
||||
List<Pair<String, Object>> templateParams) throws Throwable;
|
||||
|
||||
/**
|
||||
* 解析接收短信的接收结果
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package com.cf.imes.framework.sms.core.client.impl.aliyun;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.aliyuncs.auth.Credential;
|
||||
import com.cf.imes.framework.common.core.KeyValue;
|
||||
import com.cf.imes.framework.common.util.collection.MapUtils;
|
||||
import com.cf.imes.framework.common.util.json.JsonUtils;
|
||||
import com.cf.imes.framework.sms.core.client.dto.SmsReceiveRespDTO;
|
||||
@@ -89,7 +89,7 @@ public class AliyunSmsClient extends AbstractSmsClient {
|
||||
|
||||
@Override
|
||||
public SmsSendRespDTO sendSms(Long sendLogId, String mobile, String apiTemplateId,
|
||||
List<KeyValue<String, Object>> templateParams) throws Throwable {
|
||||
List<Pair<String, Object>> templateParams) throws Throwable {
|
||||
// 构建请求
|
||||
SendSmsRequest request = new SendSmsRequest();
|
||||
request.setPhoneNumbers(mobile);
|
||||
|
||||
+2
-2
@@ -2,13 +2,13 @@ package com.cf.imes.framework.sms.core.client.impl.debug;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import cn.hutool.crypto.digest.HmacAlgorithm;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.cf.imes.framework.common.core.KeyValue;
|
||||
import com.cf.imes.framework.common.util.collection.MapUtils;
|
||||
import com.cf.imes.framework.common.util.json.JsonUtils;
|
||||
import com.cf.imes.framework.sms.core.client.dto.SmsReceiveRespDTO;
|
||||
@@ -50,7 +50,7 @@ public class DebugDingTalkSmsClient extends AbstractSmsClient {
|
||||
|
||||
@Override
|
||||
public SmsSendRespDTO sendSms(Long sendLogId, String mobile,
|
||||
String apiTemplateId, List<KeyValue<String, Object>> templateParams) throws Throwable {
|
||||
String apiTemplateId, List<Pair<String, Object>> templateParams) throws Throwable {
|
||||
// 构建请求
|
||||
String url = buildUrl("robot/send");
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
|
||||
+5
-5
@@ -1,8 +1,8 @@
|
||||
package com.cf.imes.framework.sms.core.client.impl.tencent;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.cf.imes.framework.common.core.KeyValue;
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import com.cf.imes.framework.common.util.collection.ArrayUtils;
|
||||
import com.cf.imes.framework.common.util.json.JsonUtils;
|
||||
import com.cf.imes.framework.sms.core.client.dto.SmsReceiveRespDTO;
|
||||
@@ -91,16 +91,16 @@ public class TencentSmsClient extends AbstractSmsClient {
|
||||
}
|
||||
|
||||
private String getSdkAppId() {
|
||||
return StrUtil.subAfter(properties.getApiKey(), " ", true);
|
||||
return CharSequenceUtil.subAfter(properties.getApiKey(), " ", true);
|
||||
}
|
||||
|
||||
private String getApiKey() {
|
||||
return StrUtil.subBefore(properties.getApiKey(), " ", true);
|
||||
return CharSequenceUtil.subBefore(properties.getApiKey(), " ", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SmsSendRespDTO sendSms(Long sendLogId, String mobile,
|
||||
String apiTemplateId, List<KeyValue<String, Object>> templateParams) throws Throwable {
|
||||
String apiTemplateId, List<Pair<String, Object>> templateParams) throws Throwable {
|
||||
// 构建请求
|
||||
SendSmsRequest request = new SendSmsRequest();
|
||||
request.setSmsSdkAppId(getSdkAppId());
|
||||
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
package com.cf.imes.framework.sms.core.client.impl.aliyun;
|
||||
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import com.cf.imes.framework.common.core.KeyValue;
|
||||
import com.cf.imes.framework.common.util.collection.MapUtils;
|
||||
import com.cf.imes.framework.sms.core.client.dto.SmsReceiveRespDTO;
|
||||
import com.cf.imes.framework.sms.core.client.dto.SmsSendRespDTO;
|
||||
@@ -65,8 +65,8 @@ public class AliyunSmsClientTest extends BaseMockitoUnitTest {
|
||||
Long sendLogId = randomLongId();
|
||||
String mobile = randomString();
|
||||
String apiTemplateId = randomString();
|
||||
List<KeyValue<String, Object>> templateParams = Lists.newArrayList(
|
||||
new KeyValue<>("code", 1234), new KeyValue<>("op", "login"));
|
||||
List<Pair<String, Object>> templateParams = Lists.newArrayList(
|
||||
new Pair<>("code", 1234), new Pair<>("op", "login"));
|
||||
// mock 方法
|
||||
SendSmsResponse response = randomPojo(SendSmsResponse.class, o -> o.setCode("OK"));
|
||||
when(client.getAcsResponse(argThat((ArgumentMatcher<SendSmsRequest>) acsRequest -> {
|
||||
@@ -95,8 +95,8 @@ public class AliyunSmsClientTest extends BaseMockitoUnitTest {
|
||||
Long sendLogId = randomLongId();
|
||||
String mobile = randomString();
|
||||
String apiTemplateId = randomString();
|
||||
List<KeyValue<String, Object>> templateParams = Lists.newArrayList(
|
||||
new KeyValue<>("code", 1234), new KeyValue<>("op", "login"));
|
||||
List<Pair<String, Object>> templateParams = Lists.newArrayList(
|
||||
new Pair<>("code", 1234), new Pair<>("op", "login"));
|
||||
// mock 方法
|
||||
SendSmsResponse response = randomPojo(SendSmsResponse.class, o -> o.setCode("ERROR"));
|
||||
when(client.getAcsResponse(argThat((ArgumentMatcher<SendSmsRequest>) acsRequest -> {
|
||||
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
package com.cf.imes.framework.sms.core.client.impl.tencent;
|
||||
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import com.cf.imes.framework.common.core.KeyValue;
|
||||
import com.cf.imes.framework.common.util.collection.ArrayUtils;
|
||||
import com.cf.imes.framework.common.util.collection.MapUtils;
|
||||
import com.cf.imes.framework.common.util.json.JsonUtils;
|
||||
@@ -80,8 +80,8 @@ public class TencentSmsClientTest extends BaseMockitoUnitTest {
|
||||
Long sendLogId = randomLongId();
|
||||
String mobile = randomString();
|
||||
String apiTemplateId = randomString();
|
||||
List<KeyValue<String, Object>> templateParams = Lists.newArrayList(
|
||||
new KeyValue<>("1", 1234), new KeyValue<>("2", "login"));
|
||||
List<Pair<String, Object>> templateParams = Lists.newArrayList(
|
||||
new Pair<>("1", 1234), new Pair<>("2", "login"));
|
||||
String requestId = randomString();
|
||||
String serialNo = randomString();
|
||||
// mock 方法
|
||||
@@ -121,8 +121,8 @@ public class TencentSmsClientTest extends BaseMockitoUnitTest {
|
||||
Long sendLogId = randomLongId();
|
||||
String mobile = randomString();
|
||||
String apiTemplateId = randomString();
|
||||
List<KeyValue<String, Object>> templateParams = Lists.newArrayList(
|
||||
new KeyValue<>("1", 1234), new KeyValue<>("2", "login"));
|
||||
List<Pair<String, Object>> templateParams = Lists.newArrayList(
|
||||
new Pair<>("1", 1234), new Pair<>("2", "login"));
|
||||
String requestId = randomString();
|
||||
String serialNo = randomString();
|
||||
// mock 方法
|
||||
|
||||
+4
@@ -6,6 +6,8 @@ import cn.hutool.extra.ftp.FtpMode;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class FtpFileClientTest {
|
||||
|
||||
@Test
|
||||
@@ -21,11 +23,13 @@ public class FtpFileClientTest {
|
||||
config.setPassword("");
|
||||
config.setMode(FtpMode.Passive.name());
|
||||
FtpFileClient client = new FtpFileClient(0L, config);
|
||||
assertNotNull(client);
|
||||
client.init();
|
||||
// 上传文件
|
||||
String path = IdUtil.fastSimpleUUID() + ".jpg";
|
||||
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
|
||||
String fullPath = client.upload(content, path, "image/jpeg");
|
||||
assertNotNull(fullPath);
|
||||
System.out.println("访问地址:" + fullPath);
|
||||
if (false) {
|
||||
byte[] bytes = client.getContent(path);
|
||||
|
||||
+4
@@ -5,6 +5,8 @@ import cn.hutool.core.util.IdUtil;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class LocalFileClientTest {
|
||||
|
||||
@Test
|
||||
@@ -15,11 +17,13 @@ public class LocalFileClientTest {
|
||||
config.setDomain("http://127.0.0.1:48080");
|
||||
config.setBasePath("/Users/yunai/file_test");
|
||||
LocalFileClient client = new LocalFileClient(0L, config);
|
||||
assertNotNull(client);
|
||||
client.init();
|
||||
// 上传文件
|
||||
String path = IdUtil.fastSimpleUUID() + ".jpg";
|
||||
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
|
||||
String fullPath = client.upload(content, path, "image/jpeg");
|
||||
assertNotNull(fullPath);
|
||||
System.out.println("访问地址:" + fullPath);
|
||||
client.delete(path);
|
||||
}
|
||||
|
||||
+4
@@ -5,6 +5,8 @@ import cn.hutool.core.util.IdUtil;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class SftpFileClientTest {
|
||||
|
||||
@Test
|
||||
@@ -19,11 +21,13 @@ public class SftpFileClientTest {
|
||||
config.setUsername("");
|
||||
config.setPassword("");
|
||||
SftpFileClient client = new SftpFileClient(0L, config);
|
||||
assertNotNull(client);
|
||||
client.init();
|
||||
// 上传文件
|
||||
String path = IdUtil.fastSimpleUUID() + ".jpg";
|
||||
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
|
||||
String fullPath = client.upload(content, path, "image/jpeg");
|
||||
assertNotNull(fullPath);
|
||||
System.out.println("访问地址:" + fullPath);
|
||||
if (false) {
|
||||
byte[] bytes = client.getContent(path);
|
||||
|
||||
+10
-10
@@ -1,7 +1,7 @@
|
||||
package com.cf.imes.framework.security.core.service;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.cf.imes.framework.common.core.KeyValue;
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import com.cf.imes.framework.common.util.cache.CacheUtils;
|
||||
import com.cf.imes.framework.security.core.LoginUser;
|
||||
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
||||
@@ -28,12 +28,12 @@ public class SecurityFrameworkServiceImpl implements SecurityFrameworkService {
|
||||
/**
|
||||
* 针对 {@link #hasAnyRoles(String...)} 的缓存
|
||||
*/
|
||||
private final LoadingCache<KeyValue<Long, List<String>>, Boolean> hasAnyRolesCache = CacheUtils.buildCache(
|
||||
private final LoadingCache<Pair<Long, List<String>>, Boolean> hasAnyRolesCache = CacheUtils.buildCache(
|
||||
Duration.ofMinutes(1L), // 过期时间 1 分钟
|
||||
new CacheLoader<KeyValue<Long, List<String>>, Boolean>() {
|
||||
new CacheLoader<>() {
|
||||
|
||||
@Override
|
||||
public Boolean load(KeyValue<Long, List<String>> key) {
|
||||
public Boolean load(Pair<Long, List<String>> key) {
|
||||
return permissionApi.hasAnyRoles(key.getKey(), key.getValue().toArray(new String[0])).getCheckedData();
|
||||
}
|
||||
|
||||
@@ -42,12 +42,12 @@ public class SecurityFrameworkServiceImpl implements SecurityFrameworkService {
|
||||
/**
|
||||
* 针对 {@link #hasAnyPermissions(String...)} 的缓存
|
||||
*/
|
||||
private final LoadingCache<KeyValue<Long, List<String>>, Boolean> hasAnyPermissionsCache = CacheUtils.buildCache(
|
||||
private final LoadingCache<Pair<Long, List<String>>, Boolean> hasAnyPermissionsCache = CacheUtils.buildCache(
|
||||
Duration.ofMinutes(1L), // 过期时间 1 分钟
|
||||
new CacheLoader<KeyValue<Long, List<String>>, Boolean>() {
|
||||
new CacheLoader<>() {
|
||||
|
||||
@Override
|
||||
public Boolean load(KeyValue<Long, List<String>> key) {
|
||||
public Boolean load(Pair<Long, List<String>> key) {
|
||||
Boolean checkedData = permissionApi.hasAnyPermissions(key.getKey(), key.getValue().toArray(new String[0])).getCheckedData();
|
||||
return checkedData;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class SecurityFrameworkServiceImpl implements SecurityFrameworkService {
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public boolean hasAnyPermissions(String... permissions) {
|
||||
return hasAnyPermissionsCache.get(new KeyValue<>(SecurityFrameworkUtils.getLoginUserId(), Arrays.asList(permissions)));
|
||||
return hasAnyPermissionsCache.get(new Pair<>(SecurityFrameworkUtils.getLoginUserId(), Arrays.asList(permissions)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,13 +78,13 @@ public class SecurityFrameworkServiceImpl implements SecurityFrameworkService {
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public boolean hasAnyRoles(String... roles) {
|
||||
return hasAnyRolesCache.get(new KeyValue<>(SecurityFrameworkUtils.getLoginUserId(), Arrays.asList(roles)));
|
||||
return hasAnyRolesCache.get(new Pair<>(SecurityFrameworkUtils.getLoginUserId(), Arrays.asList(roles)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public boolean hasAnyRoles(Long userId, String... roles) {
|
||||
return hasAnyRolesCache.get(new KeyValue<>(userId, Arrays.asList(roles)));
|
||||
return hasAnyRolesCache.get(new Pair<>(userId, Arrays.asList(roles)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-3
@@ -2,9 +2,9 @@ package com.cf.imes.framework.jackson.config;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.cf.imes.framework.common.util.json.JsonUtils;
|
||||
import com.cf.imes.framework.jackson.core.databind.CustomNumberSerializer;
|
||||
import com.cf.imes.framework.jackson.core.databind.LocalDateTimeDeserializer;
|
||||
import com.cf.imes.framework.jackson.core.databind.LocalDateTimeSerializer;
|
||||
import com.cf.imes.framework.jackson.core.databind.NumberSerializer;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
@@ -31,8 +31,8 @@ public class ChenfengJacksonAutoConfiguration {
|
||||
SimpleModule simpleModule = new SimpleModule();
|
||||
simpleModule
|
||||
// 新增 Long 类型序列化规则,数值超过 2^53-1,在 JS 会出现精度丢失问题,因此 Long 自动序列化为字符串类型
|
||||
.addSerializer(Long.class, NumberSerializer.INSTANCE)
|
||||
.addSerializer(Long.TYPE, NumberSerializer.INSTANCE)
|
||||
.addSerializer(Long.class, CustomNumberSerializer.CUSTOM_INSTANCE)
|
||||
.addSerializer(Long.TYPE, CustomNumberSerializer.CUSTOM_INSTANCE)
|
||||
.addSerializer(LocalDate.class, LocalDateSerializer.INSTANCE)
|
||||
.addDeserializer(LocalDate.class, LocalDateDeserializer.INSTANCE)
|
||||
.addSerializer(LocalTime.class, LocalTimeSerializer.INSTANCE)
|
||||
|
||||
+3
-3
@@ -14,14 +14,14 @@ import java.io.IOException;
|
||||
* @author 星语
|
||||
*/
|
||||
@JacksonStdImpl
|
||||
public class NumberSerializer extends com.fasterxml.jackson.databind.ser.std.NumberSerializer {
|
||||
public class CustomNumberSerializer extends com.fasterxml.jackson.databind.ser.std.NumberSerializer {
|
||||
|
||||
private static final long MAX_SAFE_INTEGER = 9007199254740991L;
|
||||
private static final long MIN_SAFE_INTEGER = -9007199254740991L;
|
||||
|
||||
public static final NumberSerializer INSTANCE = new NumberSerializer(Number.class);
|
||||
public static final CustomNumberSerializer CUSTOM_INSTANCE = new CustomNumberSerializer(Number.class);
|
||||
|
||||
public NumberSerializer(Class<? extends Number> rawType) {
|
||||
public CustomNumberSerializer(Class<? extends Number> rawType) {
|
||||
super(rawType);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user