Commit 9d26381dcc36545138504b64f39d40956c9dd821
1 parent
9bb231eb
【代码优化】增强 JDK17、JDK8 之间的兼容性
Showing
8 changed files
with
20 additions
and
12 deletions
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/deepseek/DeepSeekChatModel.java
| 1 | package cn.iocoder.yudao.framework.ai.core.model.deepseek; | 1 | package cn.iocoder.yudao.framework.ai.core.model.deepseek; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.ListUtil; | ||
| 3 | import cn.hutool.core.lang.Assert; | 4 | import cn.hutool.core.lang.Assert; |
| 4 | import lombok.extern.slf4j.Slf4j; | 5 | import lombok.extern.slf4j.Slf4j; |
| 5 | import org.springframework.ai.chat.metadata.ChatGenerationMetadata; | 6 | import org.springframework.ai.chat.metadata.ChatGenerationMetadata; |
| @@ -70,12 +71,12 @@ public class DeepSeekChatModel implements ChatModel { | @@ -70,12 +71,12 @@ public class DeepSeekChatModel implements ChatModel { | ||
| 70 | OpenAiApi.ChatCompletion chatCompletion = completionEntity.getBody(); | 71 | OpenAiApi.ChatCompletion chatCompletion = completionEntity.getBody(); |
| 71 | if (chatCompletion == null) { | 72 | if (chatCompletion == null) { |
| 72 | log.warn("No chat completion returned for prompt: {}", prompt); | 73 | log.warn("No chat completion returned for prompt: {}", prompt); |
| 73 | - return new ChatResponse(List.of()); | 74 | + return new ChatResponse(ListUtil.of()); |
| 74 | } | 75 | } |
| 75 | List<OpenAiApi.ChatCompletion.Choice> choices = chatCompletion.choices(); | 76 | List<OpenAiApi.ChatCompletion.Choice> choices = chatCompletion.choices(); |
| 76 | if (choices == null) { | 77 | if (choices == null) { |
| 77 | log.warn("No choices returned for prompt: {}", prompt); | 78 | log.warn("No choices returned for prompt: {}", prompt); |
| 78 | - return new ChatResponse(List.of()); | 79 | + return new ChatResponse(ListUtil.of()); |
| 79 | } | 80 | } |
| 80 | 81 | ||
| 81 | // 2. 转换 ChatResponse 返回 | 82 | // 2. 转换 ChatResponse 返回 |
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/xinghuo/XingHuoChatModel.java
| 1 | package cn.iocoder.yudao.framework.ai.core.model.xinghuo; | 1 | package cn.iocoder.yudao.framework.ai.core.model.xinghuo; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.ListUtil; | ||
| 3 | import cn.hutool.core.lang.Assert; | 4 | import cn.hutool.core.lang.Assert; |
| 4 | import lombok.extern.slf4j.Slf4j; | 5 | import lombok.extern.slf4j.Slf4j; |
| 5 | import org.springframework.ai.chat.metadata.ChatGenerationMetadata; | 6 | import org.springframework.ai.chat.metadata.ChatGenerationMetadata; |
| @@ -72,12 +73,12 @@ public class XingHuoChatModel implements ChatModel { | @@ -72,12 +73,12 @@ public class XingHuoChatModel implements ChatModel { | ||
| 72 | OpenAiApi.ChatCompletion chatCompletion = completionEntity.getBody(); | 73 | OpenAiApi.ChatCompletion chatCompletion = completionEntity.getBody(); |
| 73 | if (chatCompletion == null) { | 74 | if (chatCompletion == null) { |
| 74 | log.warn("No chat completion returned for prompt: {}", prompt); | 75 | log.warn("No chat completion returned for prompt: {}", prompt); |
| 75 | - return new ChatResponse(List.of()); | 76 | + return new ChatResponse(ListUtil.of()); |
| 76 | } | 77 | } |
| 77 | List<OpenAiApi.ChatCompletion.Choice> choices = chatCompletion.choices(); | 78 | List<OpenAiApi.ChatCompletion.Choice> choices = chatCompletion.choices(); |
| 78 | if (choices == null) { | 79 | if (choices == null) { |
| 79 | log.warn("No choices returned for prompt: {}", prompt); | 80 | log.warn("No choices returned for prompt: {}", prompt); |
| 80 | - return new ChatResponse(List.of()); | 81 | + return new ChatResponse(ListUtil.of()); |
| 81 | } | 82 | } |
| 82 | 83 | ||
| 83 | // 2. 转换 ChatResponse 返回 | 84 | // 2. 转换 ChatResponse 返回 |
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/com/alibaba/cloud/ai/tongyi/audio/transcription/TongYiAudioTranscriptionModel.java
| @@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
| 16 | 16 | ||
| 17 | package com.alibaba.cloud.ai.tongyi.audio.transcription; | 17 | package com.alibaba.cloud.ai.tongyi.audio.transcription; |
| 18 | 18 | ||
| 19 | +import cn.hutool.core.collection.ListUtil; | ||
| 19 | import com.alibaba.cloud.ai.tongyi.audio.AudioTranscriptionModels; | 20 | import com.alibaba.cloud.ai.tongyi.audio.AudioTranscriptionModels; |
| 20 | import com.alibaba.cloud.ai.tongyi.audio.transcription.api.AudioTranscriptionPrompt; | 21 | import com.alibaba.cloud.ai.tongyi.audio.transcription.api.AudioTranscriptionPrompt; |
| 21 | import com.alibaba.cloud.ai.tongyi.audio.transcription.api.AudioTranscriptionResponse; | 22 | import com.alibaba.cloud.ai.tongyi.audio.transcription.api.AudioTranscriptionResponse; |
| @@ -82,7 +83,7 @@ public class TongYiAudioTranscriptionModel | @@ -82,7 +83,7 @@ public class TongYiAudioTranscriptionModel | ||
| 82 | try { | 83 | try { |
| 83 | transcriptionParam = TranscriptionParam.builder() | 84 | transcriptionParam = TranscriptionParam.builder() |
| 84 | .model(AudioTranscriptionModels.Paraformer_V1) | 85 | .model(AudioTranscriptionModels.Paraformer_V1) |
| 85 | - .fileUrls(List.of(String.valueOf(instructions.getURL()))) | 86 | + .fileUrls(ListUtil.of(String.valueOf(instructions.getURL()))) |
| 86 | .build(); | 87 | .build(); |
| 87 | } | 88 | } |
| 88 | catch (IOException e) { | 89 | catch (IOException e) { |
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/com/alibaba/cloud/ai/tongyi/chat/TongYiChatModel.java
| @@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
| 16 | 16 | ||
| 17 | package com.alibaba.cloud.ai.tongyi.chat; | 17 | package com.alibaba.cloud.ai.tongyi.chat; |
| 18 | 18 | ||
| 19 | +import cn.hutool.core.collection.ListUtil; | ||
| 19 | import com.alibaba.cloud.ai.tongyi.common.exception.TongYiException; | 20 | import com.alibaba.cloud.ai.tongyi.common.exception.TongYiException; |
| 20 | import com.alibaba.dashscope.aigc.conversation.ConversationParam; | 21 | import com.alibaba.dashscope.aigc.conversation.ConversationParam; |
| 21 | import com.alibaba.dashscope.aigc.generation.Generation; | 22 | import com.alibaba.dashscope.aigc.generation.Generation; |
| @@ -207,7 +208,7 @@ public class TongYiChatModel extends | @@ -207,7 +208,7 @@ public class TongYiChatModel extends | ||
| 207 | .getChoices() | 208 | .getChoices() |
| 208 | .get(0) | 209 | .get(0) |
| 209 | )); | 210 | )); |
| 210 | - return new ChatResponse(List.of(gen)); | 211 | + return new ChatResponse(ListUtil.of(gen)); |
| 211 | }) | 212 | }) |
| 212 | ) | 213 | ) |
| 213 | .publishOn(Schedulers.parallel()); | 214 | .publishOn(Schedulers.parallel()); |
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/com/alibaba/cloud/ai/tongyi/embedding/TongYiTextEmbeddingModel.java
| @@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
| 16 | 16 | ||
| 17 | package com.alibaba.cloud.ai.tongyi.embedding; | 17 | package com.alibaba.cloud.ai.tongyi.embedding; |
| 18 | 18 | ||
| 19 | +import cn.hutool.core.collection.ListUtil; | ||
| 19 | import com.alibaba.cloud.ai.tongyi.common.exception.TongYiException; | 20 | import com.alibaba.cloud.ai.tongyi.common.exception.TongYiException; |
| 20 | import com.alibaba.cloud.ai.tongyi.metadata.TongYiTextEmbeddingResponseMetadata; | 21 | import com.alibaba.cloud.ai.tongyi.metadata.TongYiTextEmbeddingResponseMetadata; |
| 21 | import com.alibaba.dashscope.embeddings.TextEmbedding; | 22 | import com.alibaba.dashscope.embeddings.TextEmbedding; |
| @@ -100,7 +101,7 @@ public class TongYiTextEmbeddingModel extends AbstractEmbeddingModel { | @@ -100,7 +101,7 @@ public class TongYiTextEmbeddingModel extends AbstractEmbeddingModel { | ||
| 100 | 101 | ||
| 101 | return this.call( | 102 | return this.call( |
| 102 | new EmbeddingRequest( | 103 | new EmbeddingRequest( |
| 103 | - List.of(document.getFormattedContent(this.metadataMode)), | 104 | + ListUtil.of(document.getFormattedContent(this.metadataMode)), |
| 104 | null) | 105 | null) |
| 105 | ).getResults().stream() | 106 | ).getResults().stream() |
| 106 | .map(Embedding::getOutput) | 107 | .map(Embedding::getOutput) |
yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/music/SunoApiTests.java
| 1 | package cn.iocoder.yudao.framework.ai.music; | 1 | package cn.iocoder.yudao.framework.ai.music; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.ListUtil; | ||
| 3 | import cn.iocoder.yudao.framework.ai.core.model.suno.api.SunoApi; | 4 | import cn.iocoder.yudao.framework.ai.core.model.suno.api.SunoApi; |
| 4 | import org.junit.jupiter.api.Disabled; | 5 | import org.junit.jupiter.api.Disabled; |
| 5 | import org.junit.jupiter.api.Test; | 6 | import org.junit.jupiter.api.Test; |
| @@ -66,7 +67,7 @@ public class SunoApiTests { | @@ -66,7 +67,7 @@ public class SunoApiTests { | ||
| 66 | String id = "584729e5-0fe9-4157-86da-1b4803ff42bf"; | 67 | String id = "584729e5-0fe9-4157-86da-1b4803ff42bf"; |
| 67 | 68 | ||
| 68 | // 调用方法 | 69 | // 调用方法 |
| 69 | - List<SunoApi.MusicData> musicList = sunoApi.getMusicList(List.of(id)); | 70 | + List<SunoApi.MusicData> musicList = sunoApi.getMusicList(ListUtil.of(id)); |
| 70 | // 打印结果 | 71 | // 打印结果 |
| 71 | System.out.println(musicList); | 72 | System.out.println(musicList); |
| 72 | } | 73 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/statistics/CrmStatisticsPerformanceServiceImpl.java
| 1 | package cn.iocoder.yudao.module.crm.service.statistics; | 1 | package cn.iocoder.yudao.module.crm.service.statistics; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.hutool.core.collection.ListUtil; | ||
| 4 | import cn.hutool.core.util.ObjUtil; | 5 | import cn.hutool.core.util.ObjUtil; |
| 5 | import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO; | 6 | import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceReqVO; |
| 6 | import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO; | 7 | import cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.performance.CrmStatisticsPerformanceRespVO; |
| @@ -106,7 +107,7 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform | @@ -106,7 +107,7 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform | ||
| 106 | private List<Long> getUserIds(CrmStatisticsPerformanceReqVO reqVO) { | 107 | private List<Long> getUserIds(CrmStatisticsPerformanceReqVO reqVO) { |
| 107 | // 情况一:选中某个用户 | 108 | // 情况一:选中某个用户 |
| 108 | if (ObjUtil.isNotNull(reqVO.getUserId())) { | 109 | if (ObjUtil.isNotNull(reqVO.getUserId())) { |
| 109 | - return List.of(reqVO.getUserId()); | 110 | + return ListUtil.of(reqVO.getUserId()); |
| 110 | } | 111 | } |
| 111 | // 情况二:选中某个部门 | 112 | // 情况二:选中某个部门 |
| 112 | // 2.1 获得部门列表 | 113 | // 2.1 获得部门列表 |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/framework/sms/core/client/impl/SmsClientTests.java
| 1 | package cn.iocoder.yudao.module.system.framework.sms.core.client.impl; | 1 | package cn.iocoder.yudao.module.system.framework.sms.core.client.impl; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.ListUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.core.KeyValue; | 4 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 4 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO; | 5 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO; |
| 5 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO; | 6 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO; |
| @@ -47,7 +48,7 @@ public class SmsClientTests { | @@ -47,7 +48,7 @@ public class SmsClientTests { | ||
| 47 | String mobile = "15601691323"; | 48 | String mobile = "15601691323"; |
| 48 | String apiTemplateId = "SMS_207945135"; | 49 | String apiTemplateId = "SMS_207945135"; |
| 49 | // 调用 | 50 | // 调用 |
| 50 | - SmsSendRespDTO sendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, List.of(new KeyValue<>("code", "1024"))); | 51 | + SmsSendRespDTO sendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, ListUtil.of(new KeyValue<>("code", "1024"))); |
| 51 | // 打印结果 | 52 | // 打印结果 |
| 52 | System.out.println(sendRespDTO); | 53 | System.out.println(sendRespDTO); |
| 53 | } | 54 | } |
| @@ -96,7 +97,7 @@ public class SmsClientTests { | @@ -96,7 +97,7 @@ public class SmsClientTests { | ||
| 96 | String mobile = "15601691323"; | 97 | String mobile = "15601691323"; |
| 97 | String apiTemplateId = "2136358"; | 98 | String apiTemplateId = "2136358"; |
| 98 | // 调用 | 99 | // 调用 |
| 99 | - SmsSendRespDTO sendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, List.of(new KeyValue<>("code", "1024"))); | 100 | + SmsSendRespDTO sendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, ListUtil.of(new KeyValue<>("code", "1024"))); |
| 100 | // 打印结果 | 101 | // 打印结果 |
| 101 | System.out.println(sendRespDTO); | 102 | System.out.println(sendRespDTO); |
| 102 | } | 103 | } |
| @@ -131,7 +132,7 @@ public class SmsClientTests { | @@ -131,7 +132,7 @@ public class SmsClientTests { | ||
| 131 | Long sendLogId = System.currentTimeMillis(); | 132 | Long sendLogId = System.currentTimeMillis(); |
| 132 | String mobile = "15601691323"; | 133 | String mobile = "15601691323"; |
| 133 | String apiTemplateId = "xx test01"; | 134 | String apiTemplateId = "xx test01"; |
| 134 | - List<KeyValue<String, Object>> templateParams = List.of(new KeyValue<>("code", "1024")); | 135 | + List<KeyValue<String, Object>> templateParams = ListUtil.of(new KeyValue<>("code", "1024")); |
| 135 | // 调用 | 136 | // 调用 |
| 136 | SmsSendRespDTO smsSendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, templateParams); | 137 | SmsSendRespDTO smsSendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, templateParams); |
| 137 | // 打印结果 | 138 | // 打印结果 |