Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
smf-core
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit cc0203f6
由
zshaohui
编写于
2025-10-29 14:24:51 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1.设备互联,按设备名称排序
1 个父辈
935885b8
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
51 行增加
和
1 行删除
src/main/java/com/neotel/smfcore/core/kanban/rest/BoxKanbanController.java
src/main/java/com/neotel/smfcore/core/kanban/rest/utils/NaturalOrderComparator.java
src/main/java/com/neotel/smfcore/core/kanban/rest/BoxKanbanController.java
查看文件 @
cc0203f
...
@@ -17,6 +17,7 @@ import com.neotel.smfcore.core.device.util.DataCache;
...
@@ -17,6 +17,7 @@ import com.neotel.smfcore.core.device.util.DataCache;
import
com.neotel.smfcore.core.kanban.rest.bean.dto.*
;
import
com.neotel.smfcore.core.kanban.rest.bean.dto.*
;
import
com.neotel.smfcore.core.kanban.rest.bean.mapstruct.BoxTaskMapper
;
import
com.neotel.smfcore.core.kanban.rest.bean.mapstruct.BoxTaskMapper
;
import
com.neotel.smfcore.core.kanban.rest.bean.query.BoxTaskQueryCriter
;
import
com.neotel.smfcore.core.kanban.rest.bean.query.BoxTaskQueryCriter
;
import
com.neotel.smfcore.core.kanban.rest.utils.NaturalOrderComparator
;
import
com.neotel.smfcore.core.message.util.DeviceMessageUtil
;
import
com.neotel.smfcore.core.message.util.DeviceMessageUtil
;
import
com.neotel.smfcore.core.msd.bean.MSDSettiings
;
import
com.neotel.smfcore.core.msd.bean.MSDSettiings
;
import
com.neotel.smfcore.core.solder.util.SolderBoxCache
;
import
com.neotel.smfcore.core.solder.util.SolderBoxCache
;
...
@@ -107,7 +108,7 @@ public class BoxKanbanController {
...
@@ -107,7 +108,7 @@ public class BoxKanbanController {
}
}
}
}
if
(
boxStatusDtos
.
size
()>
0
){
if
(
boxStatusDtos
.
size
()>
0
){
boxStatusDtos
=
boxStatusDtos
.
stream
().
sorted
(
Comparator
.
comparing
(
BoxStatusDto
::
getName
)).
collect
(
Collectors
.
toList
());
boxStatusDtos
=
boxStatusDtos
.
stream
().
sorted
(
Comparator
.
comparing
(
BoxStatusDto
::
getName
,
new
NaturalOrderComparator
()
)).
collect
(
Collectors
.
toList
());
GroupStatusDto
groupStatusDto
=
new
GroupStatusDto
(
group
.
getId
(),
group
.
getGroupName
(),
boxStatusDtos
,
groupType
);
GroupStatusDto
groupStatusDto
=
new
GroupStatusDto
(
group
.
getId
(),
group
.
getGroupName
(),
boxStatusDtos
,
groupType
);
groupStatusDtos
.
add
(
groupStatusDto
);
groupStatusDtos
.
add
(
groupStatusDto
);
}
}
...
...
src/main/java/com/neotel/smfcore/core/kanban/rest/utils/NaturalOrderComparator.java
0 → 100644
查看文件 @
cc0203f
package
com
.
neotel
.
smfcore
.
core
.
kanban
.
rest
.
utils
;
import
java.util.Comparator
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* 自然排序比较器:字母按字典序,数字按数值大小排序
*/
public
class
NaturalOrderComparator
implements
Comparator
<
String
>
{
// 正则表达式:拆分字符串为"非数字"和"数字"交替的部分
private
static
final
Pattern
PATTERN
=
Pattern
.
compile
(
"(\\D+)|(\\d+)"
);
@Override
public
int
compare
(
String
s1
,
String
s2
)
{
if
(
s1
==
null
&&
s2
==
null
)
return
0
;
if
(
s1
==
null
)
return
-
1
;
// null放前面
if
(
s2
==
null
)
return
1
;
Matcher
m1
=
PATTERN
.
matcher
(
s1
);
Matcher
m2
=
PATTERN
.
matcher
(
s2
);
// 逐个匹配"非数字/数字"片段并比较
while
(
m1
.
find
()
&&
m2
.
find
())
{
String
group1
=
m1
.
group
();
String
group2
=
m2
.
group
();
// 判断当前片段是数字还是非数字
if
(
group1
.
matches
(
"\\d+"
)
&&
group2
.
matches
(
"\\d+"
))
{
// 数字片段:按数值大小比较(避免"10" < "2"的字符串排序问题)
Long
num1
=
Long
.
parseLong
(
group1
);
Long
num2
=
Long
.
parseLong
(
group2
);
int
numCompare
=
num1
.
compareTo
(
num2
);
if
(
numCompare
!=
0
)
{
return
numCompare
;
}
}
else
{
// 非数字片段:按字典序比较
int
strCompare
=
group1
.
compareTo
(
group2
);
if
(
strCompare
!=
0
)
{
return
strCompare
;
}
}
}
// 一个字符串是另一个的前缀,短的放前面
return
Integer
.
compare
(
s1
.
length
(),
s2
.
length
());
}
}
\ No newline at end of file
\ No newline at end of file
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论