Commit 7d47b305 authored by 曲欣亮's avatar 曲欣亮

项目基本完成,达到使用要求

parent a8d6fa2e
......@@ -13,6 +13,7 @@ import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
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.ResponseBody;
......@@ -20,6 +21,7 @@ import com.egolm.common.GsonUtil;
import com.egolm.common.StringUtil;
import com.egolm.common.bean.Rjx;
import com.egolm.lang.config.XException;
import com.egolm.lang.model.ContentArgs;
import com.egolm.lang.service.LanguageService;
import com.egolm.lang.service.TranslateService;
import com.fasterxml.jackson.core.JsonProcessingException;
......@@ -45,8 +47,8 @@ public class LanguageController {
@PostMapping("menus")
@ApiOperation("查询翻译树")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "query", name = "sig", dataType = "string", required = false, value = "sig"),
@ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
})
public Object menus(String sParentLink) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
......@@ -94,8 +96,8 @@ public class LanguageController {
@PostMapping("append")
@ApiOperation("增加一个翻译节点")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "query", name = "sig", dataType = "string", required = false, value = "sig"),
@ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
})
public Object append(String sLink) {
service.append(sLink);
......@@ -106,8 +108,8 @@ public class LanguageController {
@PostMapping("delete")
@ApiOperation("删除一个翻译节点")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "query", name = "sig", dataType = "string", required = false, value = "sig"),
@ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
})
public Object delete(String sLink) {
String sNodeID = service.getNodeIDByLink(sLink);
......@@ -119,8 +121,8 @@ public class LanguageController {
@PostMapping("move")
@ApiOperation("移动一个翻译节点")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "query", name = "sig", dataType = "string", required = false, value = "sig"),
@ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
})
public Object move(String sLink, String sParentLink) {
String sNodeID = service.getNodeIDByLink(sLink);
......@@ -133,8 +135,8 @@ public class LanguageController {
@PostMapping("rename")
@ApiOperation("重命名一个翻译节点")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "query", name = "sig", dataType = "string", required = false, value = "sig"),
@ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
})
public Object rename(String sLink, String sNodeNO) {
String sNodeID = service.getNodeIDByLink(sLink);
......@@ -146,14 +148,17 @@ public class LanguageController {
@PostMapping("update")
@ApiOperation("修改翻译节点文档")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "query", name = "sig", dataType = "string", required = false, value = "sig"),
@ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
})
public Object update(String sLink, String sContentText) {
String sNodeID = service.getNodeIDByLink(sLink);
List<?> list = GsonUtil.toList(sContentText);
if(list != null && list.size() > 0) {
List<Map<String, String>> ary = new ArrayList<Map<String, String>>();
Map<String, Object> contentMap = GsonUtil.toMap(sContentText);
Map<String, Object> tmp = new HashMap<String, Object>();
String sCaption = (String)contentMap.get("sCaption");
List<?> list = (List<?>)contentMap.get("sDocuments");
List<Map<String, String>> ary = new ArrayList<Map<String, String>>();
if(list != null) {
for(Object obj : list) {
Map<?, ?> docMap = (Map<?, ?>) obj;
String sText = (String)docMap.get("sText");
......@@ -168,24 +173,26 @@ public class LanguageController {
ary.add(map);
}
}
ObjectMapper mapper = new ObjectMapper();
try {
service.update(sNodeID, mapper.writerWithDefaultPrettyPrinter().writeValueAsString(ary));
} catch (JsonProcessingException e) {
throw new XException("JSON格式错误", e);
}
return Rjx.jsonOk();
} else {
return Rjx.jsonErr();
}
tmp.put("sDocuments", ary);
if(StringUtil.isNotBlank(sCaption)) {
tmp.put("sCaption", sCaption);
}
ObjectMapper mapper = new ObjectMapper();
try {
service.update(sNodeID, mapper.writerWithDefaultPrettyPrinter().writeValueAsString(tmp));
} catch (JsonProcessingException e) {
throw new XException("JSON格式错误", e);
}
return Rjx.jsonOk();
}
@ResponseBody
@PostMapping("queryDetail")
@ApiOperation("查询翻译文档详情")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "query", name = "sig", dataType = "string", required = false, value = "sig"),
@ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
})
public Object queryByLink(String sLink) {
String sNodeID = service.getNodeIDByLink(sLink);
......@@ -196,23 +203,38 @@ public class LanguageController {
@PostMapping("getDocumentsByLink")
@ApiOperation("查询翻译文档")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "query", name = "sig", dataType = "string", required = false, value = "sig"),
@ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
@ApiImplicitParam(paramType = "query", name = "sLink", dataType = "string", required = true, value = "要查询文档树的目录")
})
public Object getDocumentsByLink(String sLink) {
String sNodeID = service.getNodeIDByLink(sLink);
Map<String, Object> map = service.getNodeMapByID(sNodeID);
String sContentText = (String)map.get("sContentText");
return Rjx.jsonOk().setData(GsonUtil.toList(sContentText));
Map<String, Object> contentMap = GsonUtil.toMap(sContentText);
List<?> ary = (List<?>)contentMap.get("sDocuments");
Map<String, String> result = new HashMap<String, String>();
if(ary != null && ary.size() > 0) {
for(Object obj : ary) {
Map<?, ?> objMap = (Map<?, ?>) obj;
String sText = (String) objMap.get("sText");
String sTarget = (String) objMap.get("sTarget");
result.put(sText, sTarget);
}
}
String sCaption = (String)contentMap.get("sCaption");
if(StringUtil.isNotBlank(sCaption)) {
result.put("Caption", sCaption);
}
return Rjx.jsonOk().setData(result);
}
@ResponseBody
@PostMapping("getTreeByLink")
@ApiOperation("查询翻译文档树")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "query", name = "sig", dataType = "string", required = false, value = "sig"),
@ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
@ApiImplicitParam(paramType = "query", name = "sTopLink", dataType = "string", required = true, value = "要查询文档树的根[最上层]目录")
})
public Object getTreeByLink(String sTopLink) {
......@@ -233,8 +255,9 @@ public class LanguageController {
String sNodeID = (String)nodeMap.get("sNodeID");
String sNodeNO = (String)nodeMap.get("sNodeNO");
if((sParentID_ == null && sParentID == null) || (sParentID_ != null && sParentID != null && sParentID.equals(sParentID_))) {
String sContentText = (String)nodeMap.get("sContentText");
List<?> ary = GsonUtil.toList(sContentText);
String sContentText = (String)nodeMap.get("sContentText");
Map<String, Object> contentMap = GsonUtil.toMap(sContentText);
List<?> ary = (List<?>)contentMap.get("sDocuments");
Map<String, Object> cmap = this.toDoc(list, sNodeID);
if(ary != null && ary.size() > 0) {
for(Object obj : ary) {
......@@ -244,6 +267,10 @@ public class LanguageController {
cmap.put(sText, sTarget);
}
}
String sCaption = (String)contentMap.get("sCaption");
if(StringUtil.isNotBlank(sCaption)) {
cmap.put("Caption", sCaption);
}
node.put(sNodeNO, cmap);
}
}
......@@ -254,58 +281,77 @@ public class LanguageController {
@PostMapping("translate")
@ApiOperation("翻译文档")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "query", name = "sig", dataType = "string", required = false, value = "sig"),
@ApiImplicitParam(paramType = "query", name = "sDocument", dataType = "string", required = true, value = "翻译文档对象[JSON]结构")
@ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
@ApiImplicitParam(paramType = "query", name = "sLink", dataType = "string", required = true, value = "sLink"),
@ApiImplicitParam(paramType = "query", name = "sDocuments", dataType = "string", required = true, value = "翻译文档数组", allowMultiple=true)
})
public Object translate(String sLink, String sDocument) {
public Object translate(String sLink, String[] sDocuments, String sCaption) {
List<Map<String, String>> tmp = new ArrayList<Map<String, String>>();
for(String doc : sDocuments) {
Map<String, String> map = new HashMap<String, String>();
map.put("sText", doc);
tmp.add(map);
}
String sNodeID = service.getNodeIDByLink(sLink, true);
Map<String, Object> nodeMap = service.getNodeMapByID(sNodeID);
String sContentText = (String)nodeMap.get("sContentText");
List<?> list = GsonUtil.toList(sContentText);
String dst = null;
Map<String, Object> textMap = GsonUtil.toMap(sContentText);
String caption = (String)textMap.get("sCaption");
List<?> list = (List<?>)textMap.get("sDocuments");
if(list != null && list.size() > 0) {
for(Object obj : list) {
Map<?, ?> map = (Map<?, ?>) obj;
String sText = (String)map.get("sText");
String sTarget = (String)map.get("sTarget");
if(sDocument.equals(sText) && StringUtil.isNotBlank(sTarget)) {
dst = sTarget;
}
Map<?, ?> objMap = (Map<?, ?>) obj;
String sText = (String)objMap.get("sText");
String sTarget = (String)objMap.get("sTarget");
Map<String, String> map = new HashMap<String, String>();
map.put("sText", sText);
map.put("sTarget", sTarget);
tmp.add(map);
}
}
if(StringUtil.isBlank(dst)) {
dst = translate.st(sDocument, "auto", "en");
Map<String, Object> map = new HashMap<String, Object>();
map.put("sText", sDocument);
map.put("sTarget", dst);
List<Object> tmp = new ArrayList<Object>();
if(list != null) {
tmp.addAll(list);
boolean isUpdate = false;
for(Map<String, String> map : tmp) {
String sText = map.get("sText");
String sTarget = map.get("sTarget");
if(StringUtil.isBlank(sTarget)) {
isUpdate = true;
map.put("sTarget", translate.st(sText, "auto", "en"));
}
tmp.add(map);
}
if(StringUtil.isBlank(caption) && StringUtil.isNotBlank(sCaption)) {
isUpdate = true;
caption = sCaption;
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("sCaption", caption);
map.put("sDocuments", tmp);
if(isUpdate) {
ObjectMapper mapper = new ObjectMapper();
try {
service.update(sNodeID, mapper.writerWithDefaultPrettyPrinter().writeValueAsString(tmp));
service.update(sNodeID, mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map));
} catch (JsonProcessingException e) {
throw new XException("JSON格式错误", e);
}
}
return Rjx.jsonOk().setData(dst);
Map<String, String> result = new HashMap<String, String>();
result.put("caption", caption);
for(Map<String, String> m : tmp) {
result.put(m.get("sText"), m.get("sTarget"));
}
return Rjx.jsonOk().setData(result);
}
// @ResponseBody
// @PostMapping("translate")
// @ApiOperation("翻译文档")
// @ApiImplicitParams({
// @ApiImplicitParam(paramType = "query", name = "appid", dataType = "string", required = false, value = "appid"),
// @ApiImplicitParam(paramType = "query", name = "sig", dataType = "string", required = false, value = "sig"),
// })
// public Object translate(String sLink, String json) {
// String sNodeID = service.getNodeIDByLink(sLink, true);
//
// return Rjx.jsonOk();
// }
@ResponseBody
@PostMapping("translateByJson")
@ApiOperation("翻译文档")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig")
})
public Object translate(@RequestBody ContentArgs content) {
return this.translate(content.getsLink(), content.getsDocuments(), content.getsCaption());
}
public LanguageService getService() {
return service;
......
......@@ -3,8 +3,7 @@ package com.egolm.lang.config;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
......@@ -15,10 +14,11 @@ import com.egolm.common.bean.Rjx;
@Component
public class ExceptionHandler implements HandlerExceptionResolver {
private static final Log logger = LogFactory.getLog(ExceptionHandler.class);
private Logger logger = Logger.getLogger(ExceptionHandler.class);
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
logger.error("", ex);
ModelAndView mav = new ModelAndView(new MappingJackson2JsonView());
try {
response.setContentType("application/json");
......@@ -29,8 +29,6 @@ public class ExceptionHandler implements HandlerExceptionResolver {
}
} catch (Exception e) {
mav.addAllObjects(Rjx.jsonErr().setMessage("异常处理失败"));
} finally {
logger.error("", ex);
}
return mav;
}
......
package com.egolm.lang.model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ApiModel
public class ContentArgs {
@ApiModelProperty("翻译节点目录")
private String sLink;
@ApiModelProperty("sCaption")
private String sCaption;
@ApiModelProperty("要翻译的文档")
private String[] sDocuments;
public String getsLink() {
return sLink;
}
public String getsCaption() {
return sCaption;
}
public String[] getsDocuments() {
return sDocuments;
}
}
\ No newline at end of file
......@@ -48,8 +48,6 @@ $(document).ajaxSuccess(function(event, xhr, options) {
var message = xhr.responseJSON.message;
if(code == 300) {
window.location.href = "/lang/login.html";
} else if(code == 500 && message) {
alert(message);
}
}
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment