11 changed files with 506 additions and 34 deletions
-
3src/main/java/com/bw/translate/cache/ConfigCache.java
-
37src/main/java/com/bw/translate/controller/DocumentTranslateController.java
-
14src/main/java/com/bw/translate/entity/Constants.java
-
90src/main/java/com/bw/translate/handler/MainHandler.java
-
17src/main/java/com/bw/translate/service/DocumentTranslateService.java
-
10src/main/java/com/bw/translate/service/ExecTranslateService.java
-
55src/main/java/com/bw/translate/service/impl/DocumentTranslateServiceImpl.java
-
200src/main/java/com/bw/translate/service/impl/ExecTranslateServiceImpl.java
-
87src/main/java/com/bw/translate/utils/DownLoadUtil.java
-
17src/main/java/com/bw/translate/utils/FileUtil.java
-
10src/main/resources/application.yml
@ -0,0 +1,37 @@ |
|||||
|
package com.bw.translate.controller; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import org.springframework.stereotype.Controller; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestMethod; |
||||
|
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
import com.bw.translate.service.DocumentTranslateService; |
||||
|
|
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
|
||||
|
/** |
||||
|
* 文本翻译任务控制层 |
||||
|
* @author jian.mao |
||||
|
* @date 2025年1月16日 |
||||
|
* @description |
||||
|
*/ |
||||
|
@Controller |
||||
|
@RequestMapping("/document") |
||||
|
@Slf4j |
||||
|
public class DocumentTranslateController { |
||||
|
|
||||
|
@Resource |
||||
|
public DocumentTranslateService documentTranslateService; |
||||
|
@PostMapping("/put") |
||||
|
@ResponseBody |
||||
|
public String put(@RequestBody String dataJson) { |
||||
|
return documentTranslateService.put(dataJson); |
||||
|
} |
||||
|
@RequestMapping(value = "/hello", method = RequestMethod.GET) |
||||
|
@ResponseBody |
||||
|
public String hello(String param, String token) { |
||||
|
return "123"; |
||||
|
} |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
package com.bw.translate.service; |
||||
|
|
||||
|
/** |
||||
|
* 文档翻译任务接口 |
||||
|
* @author jian.mao |
||||
|
* @date 2025年2月13日 |
||||
|
* @description |
||||
|
*/ |
||||
|
public interface DocumentTranslateService { |
||||
|
|
||||
|
/** |
||||
|
* 任务插入排队 |
||||
|
* @param dataJson |
||||
|
* @return |
||||
|
*/ |
||||
|
public String put(String dataJson); |
||||
|
} |
@ -0,0 +1,55 @@ |
|||||
|
package com.bw.translate.service.impl; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.bw.translate.cache.ConfigCache; |
||||
|
import com.bw.translate.entity.Constants; |
||||
|
import com.bw.translate.service.DocumentTranslateService; |
||||
|
|
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
|
||||
|
/** |
||||
|
* 文档翻译任务接口实现类 |
||||
|
* @author jian.mao |
||||
|
* @date 2025年2月13日 |
||||
|
* @description |
||||
|
*/ |
||||
|
@Service |
||||
|
@Slf4j |
||||
|
public class DocumentTranslateServiceImpl implements DocumentTranslateService { |
||||
|
|
||||
|
@Override |
||||
|
public String put(String dataJson) { |
||||
|
Map<String, Object> response = new HashMap<>(16); |
||||
|
int code = 200; |
||||
|
String message = "success"; |
||||
|
Map<String, Object> task = null; |
||||
|
try { |
||||
|
task = JSONObject.parseObject(dataJson); |
||||
|
} catch (Exception e) { |
||||
|
log.error("参数结构不合法,", e); |
||||
|
code = 100010; |
||||
|
message = "参数不合法"; |
||||
|
} |
||||
|
// 写入队列 |
||||
|
try { |
||||
|
if(task.containsKey(Constants.TRACE) && (boolean)task.get(Constants.TRACE)){ |
||||
|
ConfigCache.createDocumentTaskQueue.putFirst(task); |
||||
|
}else{ |
||||
|
ConfigCache.createDocumentTaskQueue.put(task); |
||||
|
} |
||||
|
} catch (InterruptedException e) { |
||||
|
log.error("文档任务写入队列异常,", e); |
||||
|
code = 100011; |
||||
|
message = "任务写入队列失败"; |
||||
|
} |
||||
|
response.put(Constants.CODE, code); |
||||
|
response.put(Constants.MESSAGE, message); |
||||
|
return JSONObject.toJSONString(response); |
||||
|
} |
||||
|
|
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue