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
e72ab383
Commit
e72ab383
authored
Jul 23, 2026
by
wujipeng
Browse files
道路详情优化
parent
9c5d4443
Changes
5
Show whitespace changes
Inline
Side-by-side
pom.xml
View file @
e72ab383
...
@@ -69,11 +69,6 @@
...
@@ -69,11 +69,6 @@
<artifactId>
jjwt
</artifactId>
<artifactId>
jjwt
</artifactId>
<version>
0.9.1
</version>
<version>
0.9.1
</version>
</dependency>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-security
</artifactId>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
src/main/java/com/example/pipelinenetwork/config/FilterConfig.java
0 → 100644
View file @
e72ab383
package
com.example.pipelinenetwork.config
;
import
com.example.pipelinenetwork.filter.JwtAuthenticationFilter
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
javax.annotation.Resource
;
@Configuration
public
class
FilterConfig
{
@Resource
private
JwtAuthenticationFilter
jwtAuthenticationFilter
;
@Bean
public
FilterRegistrationBean
<
JwtAuthenticationFilter
>
jwtFilterRegistration
()
{
FilterRegistrationBean
<
JwtAuthenticationFilter
>
registration
=
new
FilterRegistrationBean
<>();
registration
.
setFilter
(
jwtAuthenticationFilter
);
// 拦截所有请求
registration
.
addUrlPatterns
(
"/*"
);
// 设置优先级,数值越小优先级越高
registration
.
setOrder
(
1
);
return
registration
;
}
}
\ No newline at end of file
src/main/java/com/example/pipelinenetwork/config/SecurityConfig.java
deleted
100644 → 0
View file @
9c5d4443
package
com.example.pipelinenetwork.config
;
import
com.example.pipelinenetwork.filter.JwtAuthenticationFilter
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
import
org.springframework.security.config.http.SessionCreationPolicy
;
import
org.springframework.security.web.SecurityFilterChain
;
import
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
;
import
javax.servlet.http.HttpServletResponse
;
@Configuration
@EnableWebSecurity
public
class
SecurityConfig
{
private
final
JwtAuthenticationFilter
jwtAuthenticationFilter
;
public
SecurityConfig
(
JwtAuthenticationFilter
jwtAuthenticationFilter
)
{
this
.
jwtAuthenticationFilter
=
jwtAuthenticationFilter
;
}
@Bean
public
SecurityFilterChain
securityFilterChain
(
HttpSecurity
http
)
throws
Exception
{
http
.
csrf
().
disable
()
.
sessionManagement
().
sessionCreationPolicy
(
SessionCreationPolicy
.
STATELESS
)
.
and
()
.
exceptionHandling
()
.
authenticationEntryPoint
((
request
,
response
,
authException
)
->
{
response
.
setStatus
(
HttpServletResponse
.
SC_UNAUTHORIZED
);
response
.
setContentType
(
"application/json;charset=UTF-8"
);
response
.
getWriter
().
write
(
"{\"code\":401,\"message\":\"未登录或Token已过期\"}"
);
})
.
accessDeniedHandler
((
request
,
response
,
accessDeniedException
)
->
{
response
.
setStatus
(
HttpServletResponse
.
SC_FORBIDDEN
);
response
.
setContentType
(
"application/json;charset=UTF-8"
);
response
.
getWriter
().
write
(
"{\"code\":403,\"message\":\"没有访问权限\"}"
);
})
.
and
()
.
authorizeRequests
()
.
antMatchers
(
"/login/in"
).
permitAll
()
.
anyRequest
().
authenticated
()
.
and
()
.
addFilterBefore
(
jwtAuthenticationFilter
,
UsernamePasswordAuthenticationFilter
.
class
);
return
http
.
build
();
}
}
\ No newline at end of file
src/main/java/com/example/pipelinenetwork/filter/JwtAuthenticationFilter.java
View file @
e72ab383
package
com.example.pipelinenetwork.filter
;
package
com.example.pipelinenetwork.filter
;
import
com.example.pipelinenetwork.util.JwtUtil
;
import
com.example.pipelinenetwork.util.JwtUtil
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.
web.filter.OncePerRequestFilter
;
import
org.springframework.
util.StringUtils
;
import
javax.servlet.FilterChain
;
import
javax.annotation.Resource
;
import
javax.servlet.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
@Component
@Component
public
class
JwtAuthenticationFilter
ext
en
d
s
OncePerRequest
Filter
{
public
class
JwtAuthenticationFilter
implem
en
t
s
Filter
{
private
final
JwtUtil
jwtUtil
;
@Resource
private
JwtUtil
jwtUtil
;
public
JwtAuthenticationFilter
(
JwtUtil
jwtUtil
)
{
// 需要放行的路径
this
.
jwtUtil
=
jwtUtil
;
private
static
final
String
LOGIN_PATH
=
"/login/in"
;
}
@Override
@Override
p
rotected
void
doFilter
Internal
(
HttpServletRequest
request
,
p
ublic
void
doFilter
(
ServletRequest
servletRequest
,
ServletResponse
servletResponse
,
FilterChain
filterChain
)
HttpServletResponse
response
,
throws
IOException
,
ServletException
{
FilterChain
filterChain
)
throws
IOException
{
HttpServletRequest
request
=
(
HttpServletRequest
)
servletRequest
;
try
{
HttpServletResponse
response
=
(
HttpServletResponse
)
servletResponse
;
String
authHeader
=
request
.
getHeader
(
"Authorization"
);
if
(
authHeader
!=
null
&&
authHeader
.
startsWith
(
"Bearer "
))
{
// 设置字符编码和响应类型
String
token
=
authHeader
.
substring
(
7
);
request
.
setCharacterEncoding
(
"UTF-8"
);
if
(
jwtUtil
.
va
li
d
at
eToken
(
token
))
{
response
.
setContentType
(
"app
li
c
at
ion/json;charset=UTF-8"
);
String
username
=
jwtUtil
.
getUsernameFromToken
(
token
);
UsernamePasswordAuthenticationToken
authentication
=
// 获取请求路径
new
UsernamePasswordAuthenticationToken
(
String
requestURI
=
request
.
getRequestURI
();
username
,
null
,
new
ArrayList
<>());
SecurityContextHolder
.
getContext
().
setAuthentication
(
authentication
);
// 放行登录接口
}
else
{
if
(
LOGIN_PATH
.
equals
(
requestURI
))
{
sendErrorResponse
(
response
,
HttpServletResponse
.
SC_UNAUTHORIZED
,
"Token无效"
);
filterChain
.
doFilter
(
request
,
response
);
return
;
return
;
}
}
// 从请求头中获取 Token
String
token
=
request
.
getHeader
(
"Authorization"
);
// 检查 Token 是否存在且以 "Bearer " 开头
if
(!
StringUtils
.
hasText
(
token
)
||
!
token
.
startsWith
(
"Bearer "
))
{
response
.
setStatus
(
HttpServletResponse
.
SC_UNAUTHORIZED
);
response
.
getWriter
().
write
(
"{\"code\":401,\"message\":\"未提供有效的Token\"}"
);
return
;
}
}
filterChain
.
doFilter
(
request
,
response
);
}
catch
(
Exception
e
)
{
// 去掉 "Bearer " 前缀,获取实际的 Token
sendErrorResponse
(
response
,
HttpServletResponse
.
SC_INTERNAL_SERVER_ERROR
,
token
=
token
.
substring
(
7
);
"Authentication failed: "
+
e
.
getMessage
());
}
// 验证 Token 是否有效
if
(!
jwtUtil
.
validateToken
(
token
))
{
response
.
setStatus
(
HttpServletResponse
.
SC_UNAUTHORIZED
);
response
.
getWriter
().
write
(
"{\"code\":401,\"message\":\"Token无效或已过期\"}"
);
return
;
}
}
private
void
sendErrorResponse
(
HttpServletResponse
response
,
int
status
,
String
message
)
throws
IOException
{
// 将用户名存入请求属性中,方便后续使用
response
.
setStatus
(
status
);
String
username
=
jwtUtil
.
getUsernameFromToken
(
token
);
response
.
setContentType
(
"application/json;charset=UTF-8"
);
request
.
setAttribute
(
"username"
,
username
);
response
.
getWriter
().
write
(
String
.
format
(
"{\"code\": %d, \"message\": \"%s\"}"
,
status
,
message
));
// 放行请求
filterChain
.
doFilter
(
request
,
response
);
}
}
}
}
\ No newline at end of file
src/main/java/com/example/pipelinenetwork/service/impl/RoadServiceImpl.java
View file @
e72ab383
...
@@ -13,6 +13,7 @@ import com.example.pipelinenetwork.service.BasicService;
...
@@ -13,6 +13,7 @@ import com.example.pipelinenetwork.service.BasicService;
import
com.example.pipelinenetwork.service.DefectService
;
import
com.example.pipelinenetwork.service.DefectService
;
import
com.example.pipelinenetwork.service.RoadService
;
import
com.example.pipelinenetwork.service.RoadService
;
import
com.example.pipelinenetwork.util.LinestringUtil
;
import
com.example.pipelinenetwork.util.LinestringUtil
;
import
com.example.pipelinenetwork.util.NumberUtils
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.apache.poi.ss.usermodel.Workbook
;
...
@@ -77,9 +78,13 @@ public class RoadServiceImpl extends ServiceImpl<RoadMapper, RoadEntity> impleme
...
@@ -77,9 +78,13 @@ public class RoadServiceImpl extends ServiceImpl<RoadMapper, RoadEntity> impleme
List
<
String
>
relIds
=
new
ArrayList
<>();
List
<
String
>
relIds
=
new
ArrayList
<>();
for
(
BasicEntity
basicEntity
:
list
)
{
for
(
BasicEntity
basicEntity
:
list
)
{
relIds
.
add
(
basicEntity
.
getRelId
());
relIds
.
add
(
basicEntity
.
getRelId
());
if
(
basicEntity
.
getPipeNum
()
!=
null
){
pipeNum
+=
basicEntity
.
getPipeNum
();
pipeNum
+=
basicEntity
.
getPipeNum
();
}
if
(
basicEntity
.
getDetectionLength
()
!=
null
){
length
+=
basicEntity
.
getDetectionLength
();
length
+=
basicEntity
.
getDetectionLength
();
}
}
}
if
(
relIds
.
isEmpty
())
{
if
(
relIds
.
isEmpty
())
{
return
Result
.
error
(
"未找到该名称的路段"
);
return
Result
.
error
(
"未找到该名称的路段"
);
}
}
...
...
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