Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-usercenter
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 9ec526bf
authored
Nov 07, 2022
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
登陆接口新增租户名大写字段
1 parent
86fc9965
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
0 deletions
pom.xml
src/main/java/cn/com/glsx/shield/modules/model/view/UserDTO.java
src/main/java/cn/com/glsx/shield/modules/service/UserService.java
src/main/java/cn/com/glsx/shield/modules/util/ChineseCharacterUtil.java
pom.xml
View file @
9ec526b
...
...
@@ -66,6 +66,12 @@
<artifactId>
kaptcha
</artifactId>
<version>
${kaptcha.version}
</version>
</dependency>
<!-- 提取汉字首字母拼音-->
<dependency>
<groupId>
com.belerweb
</groupId>
<artifactId>
pinyin4j
</artifactId>
<version>
2.5.1
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/cn/com/glsx/shield/modules/model/view/UserDTO.java
View file @
9ec526b
...
...
@@ -59,4 +59,8 @@ public class UserDTO {
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
createdDate
;
/**
* 租户首字母大写
*/
private
String
tenant
;
}
src/main/java/cn/com/glsx/shield/modules/service/UserService.java
View file @
9ec526b
...
...
@@ -16,6 +16,7 @@ import cn.com.glsx.shield.modules.model.param.UserSearch;
import
cn.com.glsx.shield.modules.model.view.SuperTreeModel
;
import
cn.com.glsx.shield.modules.model.view.UserDTO
;
import
cn.com.glsx.shield.modules.service.permissionStrategy.PermissionStrategy
;
import
cn.com.glsx.shield.modules.util.ChineseCharacterUtil
;
import
cn.com.glsx.usercenter.api.dto.request.FindUserRequest
;
import
cn.com.glsx.usercenter.api.dto.request.SimpleAddUser
;
import
cn.hutool.core.lang.UUID
;
...
...
@@ -180,6 +181,10 @@ public class UserService {
Long
superiorId
=
userDTO
.
getSuperiorId
();
User
superiorUser
=
userMapper
.
selectById
(
superiorId
);
userDTO
.
setSuperiorName
(
superiorUser
!=
null
?
superiorUser
.
getUsername
()
:
""
);
Tenant
tenant
=
tenantMapper
.
selectById
(
user
.
getTenantId
());
String
upperChar
=
ChineseCharacterUtil
.
convertHanzi2Pinyin
(
tenant
.
getTenantName
(),
false
);
userDTO
.
setTenant
(
upperChar
);
}
return
userDTO
;
}
...
...
src/main/java/cn/com/glsx/shield/modules/util/ChineseCharacterUtil.java
0 → 100644
View file @
9ec526b
package
cn
.
com
.
glsx
.
shield
.
modules
.
util
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
net.sourceforge.pinyin4j.PinyinHelper
;
import
net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat
;
import
net.sourceforge.pinyin4j.format.HanyuPinyinToneType
;
/***
* 汉字工具类
* @author wantao
* @since 2018.10.26
*
*/
public
class
ChineseCharacterUtil
{
/***
* 将汉字转成拼音(取首字母或全拼)
* @param hanzi
* @param full 是否全拼
* @return
*/
public
static
String
convertHanzi2Pinyin
(
String
hanzi
,
boolean
full
)
{
/***
* ^[\u2E80-\u9FFF]+$ 匹配所有东亚区的语言
* ^[\u4E00-\u9FFF]+$ 匹配简体和繁体
* ^[\u4E00-\u9FA5]+$ 匹配简体
*/
String
regExp
=
"^[\u4E00-\u9FFF]+$"
;
StringBuffer
sb
=
new
StringBuffer
();
if
(
hanzi
==
null
||
""
.
equals
(
hanzi
.
trim
()))
{
return
""
;
}
String
pinyin
=
""
;
for
(
int
i
=
0
;
i
<
hanzi
.
length
();
i
++)
{
char
unit
=
hanzi
.
charAt
(
i
);
if
(
match
(
String
.
valueOf
(
unit
),
regExp
))
//是汉字,则转拼音
{
pinyin
=
convertSingleHanzi2Pinyin
(
unit
);
if
(
full
)
{
sb
.
append
(
pinyin
);
}
else
{
sb
.
append
(
pinyin
.
toUpperCase
().
charAt
(
0
));
}
}
else
{
sb
.
append
(
unit
);
}
}
return
sb
.
toString
();
}
/***
* 将单个汉字转成拼音
* @param hanzi
* @return
*/
private
static
String
convertSingleHanzi2Pinyin
(
char
hanzi
)
{
HanyuPinyinOutputFormat
outputFormat
=
new
HanyuPinyinOutputFormat
();
outputFormat
.
setToneType
(
HanyuPinyinToneType
.
WITHOUT_TONE
);
String
[]
res
;
StringBuffer
sb
=
new
StringBuffer
();
try
{
res
=
PinyinHelper
.
toHanyuPinyinStringArray
(
hanzi
,
outputFormat
);
sb
.
append
(
res
[
0
]);
//对于多音字,只用第一个拼音
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
""
;
}
return
sb
.
toString
();
}
/***
* @param str 源字符串
* @param regex 正则表达式
* @return 是否匹配
*/
public
static
boolean
match
(
String
str
,
String
regex
)
{
Pattern
pattern
=
Pattern
.
compile
(
regex
);
Matcher
matcher
=
pattern
.
matcher
(
str
);
return
matcher
.
find
();
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
convertHanzi2Pinyin
(
"仲利国际"
,
false
));
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
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 post a comment