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

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

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