Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
member-api
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
member-api
Commits
a95f2d0d
Commit
a95f2d0d
authored
Aug 28, 2018
by
曲欣亮
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
导入演示数据,抽离签名逻辑
parent
7d47b305
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
33 deletions
+97
-33
pom.xml
pom.xml
+0
-8
ImportJson.java
src/main/java/com/egolm/lang/ImportJson.java
+62
-0
LanguageController.java
src/main/java/com/egolm/lang/LanguageController.java
+16
-25
SigUtil.java
src/main/java/com/egolm/lang/config/interceptor/SigUtil.java
+19
-0
No files found.
pom.xml
View file @
a95f2d0d
...
...
@@ -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>
...
...
src/main/java/com/egolm/lang/ImportJson.java
0 → 100644
View file @
a95f2d0d
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
();
}
}
}
src/main/java/com/egolm/lang/LanguageController.java
View file @
a95f2d0d
...
...
@@ -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
=
tru
e
,
value
=
"要查询文档树的根[最上层]目录"
)
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"sTopLink"
,
dataType
=
"string"
,
required
=
fals
e
,
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
(
"
c
aption"
,
caption
);
result
.
put
(
"
C
aption"
,
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
translate
ByJson
(
@RequestBody
ContentArgs
content
)
{
return
this
.
translate
(
content
.
getsLink
(),
content
.
getsDocuments
(),
content
.
getsCaption
());
}
...
...
src/main/java/com/egolm/lang/config/interceptor/SigUtil.java
0 → 100644
View file @
a95f2d0d
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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment