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 @@
...
@@ -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>
...
...
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;
...
@@ -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
=
tru
e
,
value
=
"要查询文档树的根[最上层]目录"
)
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"sTopLink"
,
dataType
=
"string"
,
required
=
fals
e
,
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,15 +278,17 @@ public class LanguageController {
...
@@ -284,15 +278,17 @@ 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
>>();
if
(
sDocuments
!=
null
)
{
for
(
String
doc
:
sDocuments
)
{
for
(
String
doc
:
sDocuments
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"sText"
,
doc
);
map
.
put
(
"sText"
,
doc
);
tmp
.
add
(
map
);
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"
);
...
@@ -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
(
"
c
aption"
,
caption
);
result
.
put
(
"
C
aption"
,
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
translate
ByJson
(
@RequestBody
ContentArgs
content
)
{
return
this
.
translate
(
content
.
getsLink
(),
content
.
getsDocuments
(),
content
.
getsCaption
());
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