【代码优化】增强 JDK17、JDK8 之间的兼容性

pull/135/head
YunaiV 2024-08-26 12:38:00 +08:00
parent 87955a9751
commit 51a37f885b
8 changed files with 20 additions and 12 deletions

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.framework.ai.core.model.deepseek; package cn.iocoder.yudao.framework.ai.core.model.deepseek;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.metadata.ChatGenerationMetadata; import org.springframework.ai.chat.metadata.ChatGenerationMetadata;
@ -70,12 +71,12 @@ public class DeepSeekChatModel implements ChatModel {
OpenAiApi.ChatCompletion chatCompletion = completionEntity.getBody(); OpenAiApi.ChatCompletion chatCompletion = completionEntity.getBody();
if (chatCompletion == null) { if (chatCompletion == null) {
log.warn("No chat completion returned for prompt: {}", prompt); log.warn("No chat completion returned for prompt: {}", prompt);
return new ChatResponse(List.of()); return new ChatResponse(ListUtil.of());
} }
List<OpenAiApi.ChatCompletion.Choice> choices = chatCompletion.choices(); List<OpenAiApi.ChatCompletion.Choice> choices = chatCompletion.choices();
if (choices == null) { if (choices == null) {
log.warn("No choices returned for prompt: {}", prompt); log.warn("No choices returned for prompt: {}", prompt);
return new ChatResponse(List.of()); return new ChatResponse(ListUtil.of());
} }
// 2. 转换 ChatResponse 返回 // 2. 转换 ChatResponse 返回

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.framework.ai.core.model.xinghuo; package cn.iocoder.yudao.framework.ai.core.model.xinghuo;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.metadata.ChatGenerationMetadata; import org.springframework.ai.chat.metadata.ChatGenerationMetadata;
@ -72,12 +73,12 @@ public class XingHuoChatModel implements ChatModel {
OpenAiApi.ChatCompletion chatCompletion = completionEntity.getBody(); OpenAiApi.ChatCompletion chatCompletion = completionEntity.getBody();
if (chatCompletion == null) { if (chatCompletion == null) {
log.warn("No chat completion returned for prompt: {}", prompt); log.warn("No chat completion returned for prompt: {}", prompt);
return new ChatResponse(List.of()); return new ChatResponse(ListUtil.of());
} }
List<OpenAiApi.ChatCompletion.Choice> choices = chatCompletion.choices(); List<OpenAiApi.ChatCompletion.Choice> choices = chatCompletion.choices();
if (choices == null) { if (choices == null) {
log.warn("No choices returned for prompt: {}", prompt); log.warn("No choices returned for prompt: {}", prompt);
return new ChatResponse(List.of()); return new ChatResponse(ListUtil.of());
} }
// 2. 转换 ChatResponse 返回 // 2. 转换 ChatResponse 返回

View File

@ -16,6 +16,7 @@
package com.alibaba.cloud.ai.tongyi.audio.transcription; package com.alibaba.cloud.ai.tongyi.audio.transcription;
import cn.hutool.core.collection.ListUtil;
import com.alibaba.cloud.ai.tongyi.audio.AudioTranscriptionModels; import com.alibaba.cloud.ai.tongyi.audio.AudioTranscriptionModels;
import com.alibaba.cloud.ai.tongyi.audio.transcription.api.AudioTranscriptionPrompt; import com.alibaba.cloud.ai.tongyi.audio.transcription.api.AudioTranscriptionPrompt;
import com.alibaba.cloud.ai.tongyi.audio.transcription.api.AudioTranscriptionResponse; import com.alibaba.cloud.ai.tongyi.audio.transcription.api.AudioTranscriptionResponse;
@ -82,7 +83,7 @@ public class TongYiAudioTranscriptionModel
try { try {
transcriptionParam = TranscriptionParam.builder() transcriptionParam = TranscriptionParam.builder()
.model(AudioTranscriptionModels.Paraformer_V1) .model(AudioTranscriptionModels.Paraformer_V1)
.fileUrls(List.of(String.valueOf(instructions.getURL()))) .fileUrls(ListUtil.of(String.valueOf(instructions.getURL())))
.build(); .build();
} }
catch (IOException e) { catch (IOException e) {

View File

@ -16,6 +16,7 @@
package com.alibaba.cloud.ai.tongyi.chat; package com.alibaba.cloud.ai.tongyi.chat;
import cn.hutool.core.collection.ListUtil;
import com.alibaba.cloud.ai.tongyi.common.exception.TongYiException; import com.alibaba.cloud.ai.tongyi.common.exception.TongYiException;
import com.alibaba.dashscope.aigc.conversation.ConversationParam; import com.alibaba.dashscope.aigc.conversation.ConversationParam;
import com.alibaba.dashscope.aigc.generation.Generation; import com.alibaba.dashscope.aigc.generation.Generation;
@ -207,7 +208,7 @@ public class TongYiChatModel extends
.getChoices() .getChoices()
.get(0) .get(0)
)); ));
return new ChatResponse(List.of(gen)); return new ChatResponse(ListUtil.of(gen));
}) })
) )
.publishOn(Schedulers.parallel()); .publishOn(Schedulers.parallel());

View File

@ -16,6 +16,7 @@
package com.alibaba.cloud.ai.tongyi.embedding; package com.alibaba.cloud.ai.tongyi.embedding;
import cn.hutool.core.collection.ListUtil;
import com.alibaba.cloud.ai.tongyi.common.exception.TongYiException; import com.alibaba.cloud.ai.tongyi.common.exception.TongYiException;
import com.alibaba.cloud.ai.tongyi.metadata.TongYiTextEmbeddingResponseMetadata; import com.alibaba.cloud.ai.tongyi.metadata.TongYiTextEmbeddingResponseMetadata;
import com.alibaba.dashscope.embeddings.TextEmbedding; import com.alibaba.dashscope.embeddings.TextEmbedding;
@ -100,7 +101,7 @@ public class TongYiTextEmbeddingModel extends AbstractEmbeddingModel {
return this.call( return this.call(
new EmbeddingRequest( new EmbeddingRequest(
List.of(document.getFormattedContent(this.metadataMode)), ListUtil.of(document.getFormattedContent(this.metadataMode)),
null) null)
).getResults().stream() ).getResults().stream()
.map(Embedding::getOutput) .map(Embedding::getOutput)

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.framework.ai.music; package cn.iocoder.yudao.framework.ai.music;
import cn.hutool.core.collection.ListUtil;
import cn.iocoder.yudao.framework.ai.core.model.suno.api.SunoApi; import cn.iocoder.yudao.framework.ai.core.model.suno.api.SunoApi;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -66,7 +67,7 @@ public class SunoApiTests {
String id = "584729e5-0fe9-4157-86da-1b4803ff42bf"; String id = "584729e5-0fe9-4157-86da-1b4803ff42bf";
// 调用方法 // 调用方法
List<SunoApi.MusicData> musicList = sunoApi.getMusicList(List.of(id)); List<SunoApi.MusicData> musicList = sunoApi.getMusicList(ListUtil.of(id));
// 打印结果 // 打印结果
System.out.println(musicList); System.out.println(musicList);
} }

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.crm.service.statistics; package cn.iocoder.yudao.module.crm.service.statistics;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjUtil;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO; import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO; import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO;
@ -105,7 +106,7 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform
private List<Long> getUserIds(CrmStatisticsPerformanceReqVO reqVO) { private List<Long> getUserIds(CrmStatisticsPerformanceReqVO reqVO) {
// 情况一:选中某个用户 // 情况一:选中某个用户
if (ObjUtil.isNotNull(reqVO.getUserId())) { if (ObjUtil.isNotNull(reqVO.getUserId())) {
return List.of(reqVO.getUserId()); return ListUtil.of(reqVO.getUserId());
} }
// 情况二:选中某个部门 // 情况二:选中某个部门
// 2.1 获得部门列表 // 2.1 获得部门列表

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.system.framework.sms.core.client.impl; package cn.iocoder.yudao.module.system.framework.sms.core.client.impl;
import cn.hutool.core.collection.ListUtil;
import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.core.KeyValue;
import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO; import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO;
import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO; import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO;
@ -47,7 +48,7 @@ public class SmsClientTests {
String mobile = "15601691323"; String mobile = "15601691323";
String apiTemplateId = "SMS_207945135"; String apiTemplateId = "SMS_207945135";
// 调用 // 调用
SmsSendRespDTO sendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, List.of(new KeyValue<>("code", "1024"))); SmsSendRespDTO sendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, ListUtil.of(new KeyValue<>("code", "1024")));
// 打印结果 // 打印结果
System.out.println(sendRespDTO); System.out.println(sendRespDTO);
} }
@ -96,7 +97,7 @@ public class SmsClientTests {
String mobile = "15601691323"; String mobile = "15601691323";
String apiTemplateId = "2136358"; String apiTemplateId = "2136358";
// 调用 // 调用
SmsSendRespDTO sendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, List.of(new KeyValue<>("code", "1024"))); SmsSendRespDTO sendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, ListUtil.of(new KeyValue<>("code", "1024")));
// 打印结果 // 打印结果
System.out.println(sendRespDTO); System.out.println(sendRespDTO);
} }
@ -131,7 +132,7 @@ public class SmsClientTests {
Long sendLogId = System.currentTimeMillis(); Long sendLogId = System.currentTimeMillis();
String mobile = "15601691323"; String mobile = "15601691323";
String apiTemplateId = "xx test01"; String apiTemplateId = "xx test01";
List<KeyValue<String, Object>> templateParams = List.of(new KeyValue<>("code", "1024")); List<KeyValue<String, Object>> templateParams = ListUtil.of(new KeyValue<>("code", "1024"));
// 调用 // 调用
SmsSendRespDTO smsSendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, templateParams); SmsSendRespDTO smsSendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, templateParams);
// 打印结果 // 打印结果