Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
pipeline-network
Commits
a862e4a6
Commit
a862e4a6
authored
Nov 04, 2026
by
wujipeng
Browse files
管径优化
parent
cedc7ea3
Changes
1
Show whitespace changes
Inline
Side-by-side
src/main/java/com/example/pipelinenetwork/service/impl/BasicServiceImpl.java
View file @
a862e4a6
...
@@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
...
@@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -60,10 +61,16 @@ public class BasicServiceImpl extends ServiceImpl<BasicMapper, BasicEntity> impl
...
@@ -60,10 +61,16 @@ public class BasicServiceImpl extends ServiceImpl<BasicMapper, BasicEntity> impl
@Override
@Override
public
Map
<
String
,
Integer
>
roadSummary
(
String
type
,
String
region
)
{
public
Map
<
String
,
Integer
>
roadSummary
(
String
type
,
String
region
)
{
Map
<
String
,
Integer
>
result
=
new
HashMap
<>();
/*
//获取基础信息
* LinkedHashMap 可以保留道路的处理顺序。后续遇到拆分后的重复道路名时,
List
<
BasicEntity
>
basicList
=
list
(
new
LambdaQueryWrapper
<>(
BasicEntity
.
class
).
eq
(
BasicEntity:
:
getRegion
,
region
));
* 通过写入前检查 key 是否存在,只保留第一次写入的数量,避免后续记录覆盖它。
Map
<
String
,
String
>
basicMap
=
new
HashMap
<>();
*/
Map
<
String
,
Integer
>
result
=
new
LinkedHashMap
<>();
// 按主键升序获取基础信息,使“第一次出现”的判定结果稳定可预期。
List
<
BasicEntity
>
basicList
=
list
(
new
LambdaQueryWrapper
<>(
BasicEntity
.
class
)
.
eq
(
BasicEntity:
:
getRegion
,
region
)
.
orderByAsc
(
BasicEntity:
:
getId
));
Map
<
String
,
String
>
basicMap
=
new
LinkedHashMap
<>();
for
(
BasicEntity
basicEntity
:
basicList
)
{
for
(
BasicEntity
basicEntity
:
basicList
)
{
/*
/*
* roadName 在后续会被作为返回结果 Map 的 key,即 JSON 对象的字段名。
* roadName 在后续会被作为返回结果 Map 的 key,即 JSON 对象的字段名。
...
@@ -88,9 +95,9 @@ public class BasicServiceImpl extends ServiceImpl<BasicMapper, BasicEntity> impl
...
@@ -88,9 +95,9 @@ public class BasicServiceImpl extends ServiceImpl<BasicMapper, BasicEntity> impl
basicMap
.
forEach
((
key
,
value
)
->
{
basicMap
.
forEach
((
key
,
value
)
->
{
if
(
defectMap
.
containsKey
(
key
))
{
if
(
defectMap
.
containsKey
(
key
))
{
Integer
i
=
defectMap
.
get
(
key
);
Integer
i
=
defectMap
.
get
(
key
);
result
.
put
(
value
,
i
);
putSplitRoadNames
(
result
,
value
,
i
);
}
else
{
}
else
{
result
.
put
(
value
,
0
);
putSplitRoadNames
(
result
,
value
,
0
);
}
}
});
});
}
else
if
(
"修复"
.
equals
(
type
))
{
}
else
if
(
"修复"
.
equals
(
type
))
{
...
@@ -106,12 +113,33 @@ public class BasicServiceImpl extends ServiceImpl<BasicMapper, BasicEntity> impl
...
@@ -106,12 +113,33 @@ public class BasicServiceImpl extends ServiceImpl<BasicMapper, BasicEntity> impl
basicMap
.
forEach
((
key
,
value
)
->
{
basicMap
.
forEach
((
key
,
value
)
->
{
if
(
repairMap
.
containsKey
(
key
))
{
if
(
repairMap
.
containsKey
(
key
))
{
Integer
i
=
repairMap
.
get
(
key
);
Integer
i
=
repairMap
.
get
(
key
);
result
.
put
(
value
,
i
);
putSplitRoadNames
(
result
,
value
,
i
);
}
else
{
}
else
{
result
.
put
(
value
,
0
);
putSplitRoadNames
(
result
,
value
,
0
);
}
}
});
});
}
}
return
result
;
return
result
;
}
}
/**
* 将可能由中文顿号连接的组合道路名拆分后写入汇总结果。
* <p>
* 例如:“道路A、道路B”且数量为 4,会分别写入“道路A=4”和“道路B=4”。
* 如果拆分后的道路名已经存在,则保留第一次写入的数量;同时忽略空白片段,
* 避免返回空字符串 key。
*
* @param result 接口最终返回的道路数量映射
* @param roadName 数据库中的道路名,可能包含多个以“、”分隔的名称
* @param count 原组合道路对应的数量,拆分后每个道路都使用该数量
*/
private
void
putSplitRoadNames
(
Map
<
String
,
Integer
>
result
,
String
roadName
,
Integer
count
)
{
String
[]
roadNames
=
roadName
.
split
(
"、"
);
for
(
String
name
:
roadNames
)
{
String
normalizedName
=
name
.
trim
();
if
(!
normalizedName
.
isEmpty
()
&&
!
result
.
containsKey
(
normalizedName
))
{
result
.
put
(
normalizedName
,
count
);
}
}
}
}
}
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