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

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

parent 7d47b305
......@@ -63,14 +63,6 @@
<artifactId>activation</artifactId>
<version>1.1</version>
</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>
<build>
<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;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import com.egolm.common.GsonUtil;
import com.egolm.common.StringUtil;
import com.egolm.common.bean.Rjx;
......@@ -24,8 +25,6 @@ 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;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
......@@ -45,7 +44,7 @@ public class LanguageController {
@ResponseBody
@PostMapping("menus")
@ApiOperation("查询翻译树")
@ApiOperation("查询菜单树")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "header", name = "appid", dataType = "string", required = false, value = "appid"),
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
......@@ -152,7 +151,7 @@ public class LanguageController {
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
})
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> tmp = new HashMap<String, Object>();
String sCaption = (String)contentMap.get("sCaption");
......@@ -178,12 +177,7 @@ public class LanguageController {
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);
}
service.update(sNodeID, JSON.toJSONString(tmp, true));
return Rjx.jsonOk();
}
......@@ -235,7 +229,7 @@ public class LanguageController {
@ApiImplicitParams({
@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 = "要查询文档树的根[最上层]目录")
@ApiImplicitParam(paramType = "query", name = "sTopLink", dataType = "string", required = false, value = "要查询文档树的根[最上层]目录")
})
public Object getTreeByLink(String sTopLink) {
String sTopID = service.getNodeIDByLink(sTopLink);
......@@ -245,7 +239,7 @@ public class LanguageController {
} else {
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) {
......@@ -284,15 +278,17 @@ public class LanguageController {
@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)
@ApiImplicitParam(paramType = "query", name = "sDocuments", dataType = "string", value = "翻译文档数组", allowMultiple=true)
})
public Object translate(String sLink, String[] sDocuments, String sCaption) {
List<Map<String, String>> tmp = new ArrayList<Map<String, String>>();
if(sDocuments != null) {
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");
......@@ -327,15 +323,10 @@ public class LanguageController {
map.put("sCaption", caption);
map.put("sDocuments", tmp);
if(isUpdate) {
ObjectMapper mapper = new ObjectMapper();
try {
service.update(sNodeID, mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map));
} catch (JsonProcessingException e) {
throw new XException("JSON格式错误", e);
}
service.update(sNodeID, JSON.toJSONString(map, true));
}
Map<String, String> result = new HashMap<String, String>();
result.put("caption", caption);
result.put("Caption", caption);
for(Map<String, String> m : tmp) {
result.put(m.get("sText"), m.get("sTarget"));
}
......@@ -349,7 +340,7 @@ public class LanguageController {
@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) {
public Object translateByJson(@RequestBody ContentArgs content) {
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