Merge branch 'feature/gongfu-20260126' into develop
This commit is contained in:
commit
34df03ebd9
|
|
@ -1,14 +1,22 @@
|
||||||
package com.nflg.mobilebroken.admin.controller;
|
package com.nflg.mobilebroken.admin.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
||||||
import com.nflg.mobilebroken.common.pojo.request.TranslateWordRequest;
|
import com.nflg.mobilebroken.common.pojo.request.TranslateWordRequest;
|
||||||
import com.nflg.mobilebroken.common.util.AdminUserUtil;
|
import com.nflg.mobilebroken.common.util.AdminUserUtil;
|
||||||
|
import com.nflg.mobilebroken.common.util.VUtils;
|
||||||
|
import com.nflg.mobilebroken.repository.entity.Language;
|
||||||
|
import com.nflg.mobilebroken.repository.service.IDictionaryItemService;
|
||||||
|
import com.nflg.mobilebroken.repository.service.ILanguageService;
|
||||||
import com.nflg.mobilebroken.starter.service.ITranslate;
|
import com.nflg.mobilebroken.starter.service.ITranslate;
|
||||||
import com.nflg.mobilebroken.starter.service.impl.DeepSeekTranslate;
|
import com.nflg.mobilebroken.starter.service.impl.DeepSeekTranslate;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 翻译相关
|
* 翻译相关
|
||||||
|
|
@ -23,6 +31,9 @@ public class TranslateController extends ControllerBase{
|
||||||
@Resource
|
@Resource
|
||||||
private DeepSeekTranslate deepSeekTranslate;
|
private DeepSeekTranslate deepSeekTranslate;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ILanguageService languageService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文字翻译
|
* 文字翻译
|
||||||
* @param request 请求参数
|
* @param request 请求参数
|
||||||
|
|
@ -39,8 +50,16 @@ public class TranslateController extends ControllerBase{
|
||||||
* @return 翻译结果
|
* @return 翻译结果
|
||||||
*/
|
*/
|
||||||
@PostMapping("deepseek")
|
@PostMapping("deepseek")
|
||||||
public ApiResult<String> deepseek(@RequestParam String text) {
|
public ApiResult<String> deepseek(HttpServletRequest request, @RequestParam String text) {
|
||||||
|
String languageCode = request.getHeader("language");
|
||||||
|
if (StrUtil.isBlank(languageCode)) {
|
||||||
|
return ApiResult.success("");
|
||||||
|
}
|
||||||
|
Language language = languageService.lambdaQuery().eq(Language::getCode, languageCode).one();
|
||||||
|
if (Objects.isNull(language)) {
|
||||||
|
return ApiResult.success("");
|
||||||
|
}
|
||||||
text = text.replaceAll("<br>", ",");
|
text = text.replaceAll("<br>", ",");
|
||||||
return ApiResult.success(deepSeekTranslate.translateWord(text, "auto", AdminUserUtil.getLanguageName(), "text"));
|
return ApiResult.success(deepSeekTranslate.translateWord(text, "auto", language.getName(), "text"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
package com.nflg.mobilebroken.cfs.controller;
|
package com.nflg.mobilebroken.cfs.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
||||||
import com.nflg.mobilebroken.common.util.AppUserUtil;
|
import com.nflg.mobilebroken.common.util.AppUserUtil;
|
||||||
|
import com.nflg.mobilebroken.repository.entity.Language;
|
||||||
|
import com.nflg.mobilebroken.repository.service.ILanguageService;
|
||||||
import com.nflg.mobilebroken.starter.service.impl.DeepSeekTranslate;
|
import com.nflg.mobilebroken.starter.service.impl.DeepSeekTranslate;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
@ -9,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 翻译相关
|
* 翻译相关
|
||||||
|
|
@ -20,13 +25,24 @@ public class TranslateController extends ControllerBase {
|
||||||
@Resource
|
@Resource
|
||||||
private DeepSeekTranslate deepSeekTranslate;
|
private DeepSeekTranslate deepSeekTranslate;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ILanguageService languageService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* deepseek翻译
|
* deepseek翻译
|
||||||
* @param text 要翻译的文本
|
* @param text 要翻译的文本
|
||||||
* @return 翻译结果
|
* @return 翻译结果
|
||||||
*/
|
*/
|
||||||
@PostMapping("deepseek")
|
@PostMapping("deepseek")
|
||||||
public ApiResult<String> deepseek(@RequestParam String text) {
|
public ApiResult<String> deepseek(HttpServletRequest request, @RequestParam String text) {
|
||||||
return ApiResult.success(deepSeekTranslate.translateWord(text, "auto", AppUserUtil.getLanguageName(), "text"));
|
String languageCode = request.getHeader("language");
|
||||||
|
if (StrUtil.isBlank(languageCode)) {
|
||||||
|
return ApiResult.success("");
|
||||||
|
}
|
||||||
|
Language language = languageService.lambdaQuery().eq(Language::getCode, languageCode).one();
|
||||||
|
if (Objects.isNull(language)) {
|
||||||
|
return ApiResult.success("");
|
||||||
|
}
|
||||||
|
return ApiResult.success(deepSeekTranslate.translateWord(text, "auto", language.getName(), "text"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue