Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cnooc_zydeepen-cggl_expert-manage-miniapp
Overview
Overview
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
孙德龙
cnooc_zydeepen-cggl_expert-manage-miniapp
Commits
0b164889
Commit
0b164889
authored
Nov 12, 2025
by
kenzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update apiResult
parent
517de7c9
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
113 additions
and
62 deletions
+113
-62
pom.xml
+5
-0
src/main/java/com/cnooc/expert/Ping.java
+7
-1
src/main/java/com/cnooc/expert/common/exception/ErrorCode.java
+2
-2
src/main/java/com/cnooc/expert/common/exception/GlobalErrorCodeConstants.java
+30
-30
src/main/java/com/cnooc/expert/common/exception/GlobalExceptionHandler.java
+3
-3
src/main/java/com/cnooc/expert/common/response/ApiResult.java
+14
-12
src/main/java/com/cnooc/expert/controller/auth/AuthController.java
+11
-0
src/main/java/com/cnooc/expert/controller/auth/LoginController.java
+5
-0
src/main/java/com/cnooc/expert/controller/person/PersonController.java
+3
-7
src/main/java/com/cnooc/expert/external/expert/api/ExpertServiceApi.java
+0
-1
src/main/java/com/cnooc/expert/service/PersonService.java
+6
-6
src/main/resources/application.yml
+27
-0
No files found.
pom.xml
View file @
0b164889
...
...
@@ -30,6 +30,11 @@
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<optional>
true
</optional>
...
...
src/main/java/com/cnooc/expert/Ping.java
View file @
0b164889
package
com
.
cnooc
.
expert
;
import
com.cnooc.expert.common.response.ApiResult
;
import
lombok.AllArgsConstructor
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@AllArgsConstructor
@RestController
public
class
Ping
{
private
final
StringRedisTemplate
redisTemplate
;
@GetMapping
(
"/ping"
)
public
ApiResult
<
String
>
ping
()
{
return
ApiResult
.
successWithData
(
"Pong"
);
redisTemplate
.
opsForValue
().
set
(
"ping"
,
"Pong"
);
return
ApiResult
.
successWithResult
(
"Pong"
);
}
}
src/main/java/com/cnooc/expert/common/exception/ErrorCode.java
View file @
0b164889
...
...
@@ -8,14 +8,14 @@ public class ErrorCode {
/**
* 错误码
*/
private
final
String
code
;
private
final
Integer
code
;
/**
* 错误提示
*/
private
final
String
msg
;
public
ErrorCode
(
String
code
,
String
msg
)
{
public
ErrorCode
(
int
code
,
String
msg
)
{
this
.
code
=
code
;
this
.
msg
=
msg
;
}
...
...
src/main/java/com/cnooc/expert/common/exception/GlobalErrorCodeConstants.java
View file @
0b164889
...
...
@@ -2,45 +2,45 @@ package com.cnooc.expert.common.exception;
public
interface
GlobalErrorCodeConstants
{
ErrorCode
SUCCESS
=
new
ErrorCode
(
"200"
,
"
成功"
);
ErrorCode
SUCCESS
=
new
ErrorCode
(
100200
,
"操作
成功"
);
// ========== 系统级别错误 (1000-1999) ==========
ErrorCode
BAD_REQUEST
=
new
ErrorCode
(
"1001"
,
"请求参数不正确"
);
ErrorCode
UNAUTHORIZED
=
new
ErrorCode
(
"1002"
,
"账号未登录"
);
ErrorCode
FORBIDDEN
=
new
ErrorCode
(
"1003"
,
"没有该操作权限"
);
ErrorCode
NOT_FOUND
=
new
ErrorCode
(
"1004"
,
"请求未找到"
);
ErrorCode
METHOD_NOT_ALLOWED
=
new
ErrorCode
(
"1005"
,
"请求方法不正确"
);
ErrorCode
LOCKED
=
new
ErrorCode
(
"1006"
,
"请求失败,请稍后重试"
);
ErrorCode
TOO_MANY_REQUESTS
=
new
ErrorCode
(
"1007"
,
"请求过于频繁,请稍后重试"
);
ErrorCode
INTERNAL_SERVER_ERROR
=
new
ErrorCode
(
"1008"
,
"系统异常"
);
ErrorCode
NOT_IMPLEMENTED
=
new
ErrorCode
(
"1009"
,
"功能未实现/未开启"
);
ErrorCode
ERROR_CONFIGURATION
=
new
ErrorCode
(
"1010"
,
"错误的配置项"
);
ErrorCode
CAPTCHA_EXPIRED
=
new
ErrorCode
(
"1011"
,
"验证码错误"
);
ErrorCode
CODE_REDIS_KEY
=
new
ErrorCode
(
"1011"
,
"验证码已过期"
);
ErrorCode
SYSTEM_ERROR
=
new
ErrorCode
(
"1012"
,
"系统内部异常"
);
ErrorCode
BAD_REQUEST
=
new
ErrorCode
(
1001
,
"请求参数不正确"
);
ErrorCode
UNAUTHORIZED
=
new
ErrorCode
(
1002
,
"账号未登录"
);
ErrorCode
FORBIDDEN
=
new
ErrorCode
(
1003
,
"没有该操作权限"
);
ErrorCode
NOT_FOUND
=
new
ErrorCode
(
1004
,
"请求未找到"
);
ErrorCode
METHOD_NOT_ALLOWED
=
new
ErrorCode
(
1005
,
"请求方法不正确"
);
ErrorCode
LOCKED
=
new
ErrorCode
(
1006
,
"请求失败,请稍后重试"
);
ErrorCode
TOO_MANY_REQUESTS
=
new
ErrorCode
(
1007
,
"请求过于频繁,请稍后重试"
);
ErrorCode
INTERNAL_SERVER_ERROR
=
new
ErrorCode
(
1008
,
"系统异常"
);
ErrorCode
NOT_IMPLEMENTED
=
new
ErrorCode
(
1009
,
"功能未实现/未开启"
);
ErrorCode
ERROR_CONFIGURATION
=
new
ErrorCode
(
1010
,
"错误的配置项"
);
ErrorCode
CAPTCHA_EXPIRED
=
new
ErrorCode
(
1011
,
"验证码错误"
);
ErrorCode
CODE_REDIS_KEY
=
new
ErrorCode
(
1011
,
"验证码已过期"
);
ErrorCode
SYSTEM_ERROR
=
new
ErrorCode
(
1012
,
"系统内部异常"
);
// ========== 用户认证相关错误 (2000-2999) ==========
ErrorCode
LOGIN_EXPIRED
=
new
ErrorCode
(
"2001"
,
"请先登录"
);
ErrorCode
USER_NOT_EXISTS
=
new
ErrorCode
(
"2002"
,
"用户不存在"
);
ErrorCode
PASSWORD_ERROR
=
new
ErrorCode
(
"2003"
,
"密码错误"
);
ErrorCode
USER_DISABLED
=
new
ErrorCode
(
"2004"
,
"用户已被禁用"
);
ErrorCode
LOGIN_EXPIRED
=
new
ErrorCode
(
2001
,
"请先登录"
);
ErrorCode
USER_NOT_EXISTS
=
new
ErrorCode
(
2002
,
"用户不存在"
);
ErrorCode
PASSWORD_ERROR
=
new
ErrorCode
(
2003
,
"密码错误"
);
ErrorCode
USER_DISABLED
=
new
ErrorCode
(
2004
,
"用户已被禁用"
);
// ========== 参数校验错误 (3000-3999) ==========
ErrorCode
PARAM_REQUIRED
=
new
ErrorCode
(
"3001"
,
"必填字段不能为空"
);
ErrorCode
PARAM_FORMAT_ERROR
=
new
ErrorCode
(
"3002"
,
"参数格式不正确"
);
ErrorCode
PARAM_RANGE_ERROR
=
new
ErrorCode
(
"3003"
,
"参数超出范围"
);
ErrorCode
PARAM_REQUIRED
=
new
ErrorCode
(
3001
,
"必填字段不能为空"
);
ErrorCode
PARAM_FORMAT_ERROR
=
new
ErrorCode
(
3002
,
"参数格式不正确"
);
ErrorCode
PARAM_RANGE_ERROR
=
new
ErrorCode
(
3003
,
"参数超出范围"
);
// ========== 业务逻辑错误 (4000-4999) ==========
ErrorCode
OPERATION_TOO_FREQUENT
=
new
ErrorCode
(
"4001"
,
"操作太频繁,请稍后再试"
);
ErrorCode
DATA_ALREADY_EXISTS
=
new
ErrorCode
(
"4002"
,
"数据已存在"
);
ErrorCode
DATA_NOT_EXISTS
=
new
ErrorCode
(
"4003"
,
"数据不存在"
);
ErrorCode
BUSINESS_FAILED
=
new
ErrorCode
(
"4004"
,
"业务处理失败"
);
ErrorCode
OPERATION_TOO_FREQUENT
=
new
ErrorCode
(
4001
,
"操作太频繁,请稍后再试"
);
ErrorCode
DATA_ALREADY_EXISTS
=
new
ErrorCode
(
4002
,
"数据已存在"
);
ErrorCode
DATA_NOT_EXISTS
=
new
ErrorCode
(
4003
,
"数据不存在"
);
ErrorCode
BUSINESS_FAILED
=
new
ErrorCode
(
4004
,
"业务处理失败"
);
// ========== 数据访问错误 (5000-5999) ==========
ErrorCode
DATABASE_CONNECTION_ERROR
=
new
ErrorCode
(
"5001"
,
"数据库连接失败"
);
ErrorCode
QUERY_DATA_ERROR
=
new
ErrorCode
(
"5002"
,
"查询数据出错"
);
ErrorCode
INSERT_DATA_ERROR
=
new
ErrorCode
(
"5003"
,
"插入数据出错"
);
ErrorCode
UPDATE_DATA_ERROR
=
new
ErrorCode
(
"5004"
,
"更新数据出错"
);
ErrorCode
DELETE_DATA_ERROR
=
new
ErrorCode
(
"5005"
,
"删除数据出错"
);
ErrorCode
DATABASE_CONNECTION_ERROR
=
new
ErrorCode
(
5001
,
"数据库连接失败"
);
ErrorCode
QUERY_DATA_ERROR
=
new
ErrorCode
(
5002
,
"查询数据出错"
);
ErrorCode
INSERT_DATA_ERROR
=
new
ErrorCode
(
5003
,
"插入数据出错"
);
ErrorCode
UPDATE_DATA_ERROR
=
new
ErrorCode
(
5004
,
"更新数据出错"
);
ErrorCode
DELETE_DATA_ERROR
=
new
ErrorCode
(
5005
,
"删除数据出错"
);
}
src/main/java/com/cnooc/expert/common/exception/GlobalExceptionHandler.java
View file @
0b164889
...
...
@@ -48,18 +48,18 @@ public class GlobalExceptionHandler {
@ExceptionHandler
(
Exception
.
class
)
public
ApiResult
<
String
>
handleException
(
Exception
e
,
HttpServletRequest
request
)
{
log
.
error
(
"系统异常: {},请求URL: {}"
,
e
.
getMessage
(),
request
.
getRequestURI
(),
e
);
return
ApiResult
.
error
(
String
.
valueOf
(
HttpStatus
.
INTERNAL_SERVER_ERROR
.
value
()
),
GlobalErrorCodeConstants
.
SYSTEM_ERROR
.
getMsg
());
return
ApiResult
.
error
(
HttpStatus
.
INTERNAL_SERVER_ERROR
.
value
(
),
GlobalErrorCodeConstants
.
SYSTEM_ERROR
.
getMsg
());
}
@ExceptionHandler
(
BusinessException
.
class
)
public
ApiResult
<
String
>
handleBusinessException
(
BusinessException
e
,
HttpServletRequest
request
)
{
log
.
error
(
"业务异常: {},请求URL: {}"
,
e
.
getMessage
(),
request
.
getRequestURI
(),
e
);
return
ApiResult
.
error
(
e
.
get
Messag
e
(),
e
.
getMessage
());
return
ApiResult
.
error
(
e
.
get
ErrorCode
().
getCod
e
(),
e
.
getMessage
());
}
@ExceptionHandler
(
NullPointerException
.
class
)
public
ApiResult
<
String
>
handleNullPointerException
(
NullPointerException
e
,
HttpServletRequest
request
)
{
log
.
error
(
"空指针异常: {},请求URL: {}"
,
e
.
getMessage
(),
request
.
getRequestURI
(),
e
);
return
ApiResult
.
error
(
String
.
valueOf
(
HttpStatus
.
INTERNAL_SERVER_ERROR
.
value
()
),
GlobalErrorCodeConstants
.
SYSTEM_ERROR
.
getMsg
());
return
ApiResult
.
error
(
GlobalErrorCodeConstants
.
SYSTEM_ERROR
.
getCode
(
),
GlobalErrorCodeConstants
.
SYSTEM_ERROR
.
getMsg
());
}
}
src/main/java/com/cnooc/expert/common/response/ApiResult.java
View file @
0b164889
package
com
.
cnooc
.
expert
.
common
.
response
;
import
com.cnooc.expert.common.exception.ErrorCode
;
import
com.cnooc.expert.common.exception.GlobalErrorCodeConstants
;
import
lombok.Getter
;
import
lombok.Setter
;
...
...
@@ -14,7 +16,7 @@ public class ApiResult<T> implements Serializable {
/**
* 响应码
*/
private
String
c
ode
;
private
Integer
httpC
ode
;
/**
* 响应消息
...
...
@@ -24,45 +26,45 @@ public class ApiResult<T> implements Serializable {
/**
* 响应数据
*/
private
T
data
;
private
T
result
;
public
ApiResult
(
String
code
,
String
message
,
T
data
)
{
this
.
code
=
c
ode
;
public
ApiResult
(
int
httpCode
,
String
message
,
T
result
)
{
this
.
httpCode
=
httpC
ode
;
this
.
message
=
message
;
this
.
data
=
data
;
this
.
result
=
result
;
}
/**
* 成功返回结果
*/
public
static
<
T
>
ApiResult
<
T
>
successWith
Data
(
T
data
)
{
return
new
ApiResult
<>(
"200"
,
"操作成功"
,
data
);
public
static
<
T
>
ApiResult
<
T
>
successWith
Result
(
T
result
)
{
return
new
ApiResult
<>(
GlobalErrorCodeConstants
.
SUCCESS
.
getCode
(),
GlobalErrorCodeConstants
.
SUCCESS
.
getMsg
(),
result
);
}
/**
* 成功返回结果
*/
public
static
<
T
>
ApiResult
<
T
>
success
()
{
return
new
ApiResult
<>(
"200"
,
"操作成功"
,
null
);
return
new
ApiResult
<>(
GlobalErrorCodeConstants
.
SUCCESS
.
getCode
(),
GlobalErrorCodeConstants
.
SUCCESS
.
getMsg
()
,
null
);
}
public
static
<
T
>
ApiResult
<
T
>
success
(
String
message
)
{
return
new
ApiResult
<>(
"200"
,
message
,
null
);
return
new
ApiResult
<>(
GlobalErrorCodeConstants
.
SUCCESS
.
getCode
()
,
message
,
null
);
}
/**
* 失败返回结果
*/
public
static
<
T
>
ApiResult
<
T
>
error
(
String
message
)
{
return
new
ApiResult
<>(
"500"
,
message
,
null
);
return
new
ApiResult
<>(
GlobalErrorCodeConstants
.
SYSTEM_ERROR
.
getCode
()
,
message
,
null
);
}
/**
* 失败返回结果
*/
public
static
<
T
>
ApiResult
<
T
>
error
(
String
c
ode
,
String
message
)
{
return
new
ApiResult
<>(
c
ode
,
message
,
null
);
public
static
<
T
>
ApiResult
<
T
>
error
(
int
httpC
ode
,
String
message
)
{
return
new
ApiResult
<>(
httpC
ode
,
message
,
null
);
}
// Getters and Setters
...
...
src/main/java/com/cnooc/expert/controller/auth/AuthController.java
0 → 100644
View file @
0b164889
package
com
.
cnooc
.
expert
.
controller
.
auth
;
import
lombok.AllArgsConstructor
;
import
org.springframework.web.bind.annotation.RestController
;
@AllArgsConstructor
@RestController
public
class
AuthController
{
}
src/main/java/com/cnooc/expert/controller/auth/LoginController.java
0 → 100644
View file @
0b164889
package
com
.
cnooc
.
expert
.
controller
.
auth
;
public
class
LoginController
{
}
src/main/java/com/cnooc/expert/controller/person/PersonController.java
View file @
0b164889
package
com
.
cnooc
.
expert
.
controller
.
person
;
import
com.cnooc.expert.common.response.ApiResult
;
import
com.cnooc.expert.controller.person.model.request.PersonGetReq
;
import
com.cnooc.expert.service.PersonService
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
lombok.AllArgsConstructor
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -18,9 +15,8 @@ public class PersonController {
private
final
PersonService
personService
;
@GetMapping
(
"/get"
)
// public ApiResult<String> personGet(@RequestBody @Validated PersonGetReq req) {
public
ApiResult
<
String
>
personGet
()
{
return
ApiResult
.
successWithData
(
personService
.
getExpertDetail
(
1
));
public
String
personGet
()
throws
JsonProcessingException
{
return
personService
.
getExpertDetail
(
1
);
}
}
src/main/java/com/cnooc/expert/external/expert/api/ExpertServiceApi.java
View file @
0b164889
...
...
@@ -12,7 +12,6 @@ import java.util.Map;
public
interface
ExpertServiceApi
{
// GET请求
@GET
(
"/api"
)
Call
<
ExpertInfoGetResp
>
expertDetailGet
(
@HeaderMap
Map
<
String
,
Object
>
headers
);
...
...
src/main/java/com/cnooc/expert/service/PersonService.java
View file @
0b164889
package
com
.
cnooc
.
expert
.
service
;
import
com.cnooc.expert.controller.person.model.request.PersonGetReq
;
import
com.cnooc.expert.external.expert.model.response.ExpertInfoGetResp
;
import
com.cnooc.expert.external.expert.service.ExpertService
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.AllArgsConstructor
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
@AllArgsConstructor
@Service
public
class
PersonService
{
private
ObjectMapper
objectMapper
;
private
final
ExpertService
expertService
;
public
String
getExpertDetail
(
int
id
)
{
public
String
getExpertDetail
(
int
id
)
throws
JsonProcessingException
{
ExpertInfoGetResp
expertInfo
=
expertService
.
getExpertInfo
(
id
);
return
StringUtils
.
defaultIfBlank
(
expertInfo
.
getInfo
().
getSeed
(),
""
)
;
return
objectMapper
.
writeValueAsString
(
expertService
.
getExpertInfo
(
id
));
}
}
src/main/resources/application.yml
View file @
0b164889
spring
:
redis
:
host
:
39.105.210.213
port
:
6379
database
:
6
password
:
'
WSzs*aA^U2nH$u!K'
lettuce
:
cluster
:
refresh
:
adaptive
:
true
period
:
30000
pool
:
max-wait
:
10000
max-idle
:
10
min-idle
:
10
max-active
:
20
jackson
:
date-format
:
yyyy-MM-dd HH:mm:ss
time-zone
:
GMT+8
serialization
:
indent-output
:
true
deserialization
:
fail-on-unknown-properties
:
false
default-property-inclusion
:
non_null
server
:
port
:
9090
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