Commit a95f2d0d authored by 曲欣亮's avatar 曲欣亮

导入演示数据,抽离签名逻辑

parent 7d47b305
...@@ -63,14 +63,6 @@ ...@@ -63,14 +63,6 @@
<artifactId>activation</artifactId> <artifactId>activation</artifactId>
<version>1.1</version> <version>1.1</version>
</dependency> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
......
package com.egolm.lang;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.egolm.common.FileUtil;
import com.egolm.common.GsonUtil;
import com.egolm.common.HttpUtil;
import com.egolm.lang.config.interceptor.SigUtil;
public class ImportJson {
public static void main(String[] args) throws UnsupportedEncodingException {
String json = new String(FileUtil.fileToBytes(new File("/home/quxl/Desktop/APOS.Language.900.json")), "GBK");
Map<String, Object> map = GsonUtil.toMap(json);
for(String key : map.keySet()) {
Map<?, ?> cmap = (Map<?, ?>)map.get(key);
String Caption = (String)cmap.get("Caption");
cmap.remove("Caption");
Map<String, Object> tmp = new HashMap<String, Object>();
tmp.put("sCaption", Caption);
List<Object> ary = new ArrayList<Object>();
for(Object ckey : cmap.keySet()) {
String sText = (String)ckey;
String sTarget = null;
if(cmap.get(ckey) instanceof String) {
sTarget = (String)cmap.get(ckey);
} else {
sTarget = (String)((Map<?, ?>)cmap.get(ckey)).get("");
}
Map<String, String> doc = new HashMap<String, String>();
doc.put("sText", sText);
doc.put("sTarget", sTarget);
ary.add(doc);
}
tmp.put("sDocuments", ary);
String sContentText = GsonUtil.toJson(tmp);
String sLink = "APOS";
String appid = "44EB5B79174D45F48BF32C09E6F0C4AA";
String secret = "4117B10F6D48494595EE5D567333BB32";
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("sLink", sLink + "/" + key);
parameters.put("appid", appid);
parameters.put("sContentText", sContentText);
String sig = SigUtil.sig(parameters, secret);
parameters.put("sig", sig);
// String result = HttpUtil.post("http://localhost:8090/lang/api/update", parameters);
// System.out.println(result);
System.out.println();
}
}
}
...@@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -17,6 +17,7 @@ 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;
import com.alibaba.fastjson.JSON;
import com.egolm.common.GsonUtil; 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;
...@@ -24,8 +25,6 @@ import com.egolm.lang.config.XException; ...@@ -24,8 +25,6 @@ import com.egolm.lang.config.XException;
import com.egolm.lang.model.ContentArgs; 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.databind.ObjectMapper;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
...@@ -45,7 +44,7 @@ public class LanguageController { ...@@ -45,7 +44,7 @@ public class LanguageController {
@ResponseBody @ResponseBody
@PostMapping("menus") @PostMapping("menus")
@ApiOperation("查询翻译树") @ApiOperation("查询菜单树")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"), @ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"), @ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
...@@ -152,7 +151,7 @@ public class LanguageController { ...@@ -152,7 +151,7 @@ public class LanguageController {
@ApiImplicitParam(paramType = "header", 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, true);
Map<String, Object> contentMap = GsonUtil.toMap(sContentText); Map<String, Object> contentMap = GsonUtil.toMap(sContentText);
Map<String, Object> tmp = new HashMap<String, Object>(); Map<String, Object> tmp = new HashMap<String, Object>();
String sCaption = (String)contentMap.get("sCaption"); String sCaption = (String)contentMap.get("sCaption");
...@@ -178,12 +177,7 @@ public class LanguageController { ...@@ -178,12 +177,7 @@ public class LanguageController {
if(StringUtil.isNotBlank(sCaption)) { if(StringUtil.isNotBlank(sCaption)) {
tmp.put("sCaption", sCaption); tmp.put("sCaption", sCaption);
} }
ObjectMapper mapper = new ObjectMapper(); service.update(sNodeID, JSON.toJSONString(tmp, true));
try {
service.update(sNodeID, mapper.writerWithDefaultPrettyPrinter().writeValueAsString(tmp));
} catch (JsonProcessingException e) {
throw new XException("JSON格式错误", e);
}
return Rjx.jsonOk(); return Rjx.jsonOk();
} }
...@@ -235,7 +229,7 @@ public class LanguageController { ...@@ -235,7 +229,7 @@ public class LanguageController {
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"), @ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "header", 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 = false, value = "要查询文档树的根[最上层]目录")
}) })
public Object getTreeByLink(String sTopLink) { public Object getTreeByLink(String sTopLink) {
String sTopID = service.getNodeIDByLink(sTopLink); String sTopID = service.getNodeIDByLink(sTopLink);
...@@ -245,7 +239,7 @@ public class LanguageController { ...@@ -245,7 +239,7 @@ public class LanguageController {
} else { } else {
list = service.getListByTopID(sTopID); list = service.getListByTopID(sTopID);
} }
return Rjx.jsonOk().setData(this.toDoc(list, sTopID)); return Rjx.jsonOk().setData(this.toDoc(list, null));
} }
private Map<String, Object> toDoc(List<Map<String, Object>> list, String sParentID) { private Map<String, Object> toDoc(List<Map<String, Object>> list, String sParentID) {
...@@ -284,14 +278,16 @@ public class LanguageController { ...@@ -284,14 +278,16 @@ public class LanguageController {
@ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"), @ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "header", 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 = "sLink"), @ApiImplicitParam(paramType = "query", name = "sLink", dataType = "string", required = true, value = "sLink"),
@ApiImplicitParam(paramType = "query", name = "sDocuments", dataType = "string", required = true, value = "翻译文档数组", allowMultiple=true) @ApiImplicitParam(paramType = "query", name = "sDocuments", dataType = "string", value = "翻译文档数组", allowMultiple=true)
}) })
public Object translate(String sLink, String[] sDocuments, String sCaption) { public Object translate(String sLink, String[] sDocuments, String sCaption) {
List<Map<String, String>> tmp = new ArrayList<Map<String, String>>(); List<Map<String, String>> tmp = new ArrayList<Map<String, String>>();
for(String doc : sDocuments) { if(sDocuments != null) {
Map<String, String> map = new HashMap<String, String>(); for(String doc : sDocuments) {
map.put("sText", doc); Map<String, String> map = new HashMap<String, String>();
tmp.add(map); 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);
...@@ -327,15 +323,10 @@ public class LanguageController { ...@@ -327,15 +323,10 @@ public class LanguageController {
map.put("sCaption", caption); map.put("sCaption", caption);
map.put("sDocuments", tmp); map.put("sDocuments", tmp);
if(isUpdate) { if(isUpdate) {
ObjectMapper mapper = new ObjectMapper(); service.update(sNodeID, JSON.toJSONString(map, true));
try {
service.update(sNodeID, mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map));
} catch (JsonProcessingException e) {
throw new XException("JSON格式错误", e);
}
} }
Map<String, String> result = new HashMap<String, String>(); Map<String, String> result = new HashMap<String, String>();
result.put("caption", caption); result.put("Caption", caption);
for(Map<String, String> m : tmp) { for(Map<String, String> m : tmp) {
result.put(m.get("sText"), m.get("sTarget")); result.put(m.get("sText"), m.get("sTarget"));
} }
...@@ -349,7 +340,7 @@ public class LanguageController { ...@@ -349,7 +340,7 @@ public class LanguageController {
@ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"), @ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig") @ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig")
}) })
public Object translate(@RequestBody ContentArgs content) { public Object translateByJson(@RequestBody ContentArgs content) {
return this.translate(content.getsLink(), content.getsDocuments(), content.getsCaption()); return this.translate(content.getsLink(), content.getsDocuments(), content.getsCaption());
} }
......
package com.egolm.lang.config.interceptor;
import java.util.Map;
import java.util.TreeMap;
import com.egolm.common.HttpUtil;
import com.egolm.common.StringUtil;
public class SigUtil {
public static String sig(Map<String, Object> parameters, String secret) {
Map<String, Object> parameterMap = new TreeMap<String, Object>(parameters);
parameterMap.remove("sig");
String queryString = HttpUtil.formatToQueryString(parameterMap);
String vsig = StringUtil.toSHA1String(queryString + secret);
return vsig;
}
}
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