Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
platform
/
platform-process-server
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 671e5353
authored
Oct 09, 2023
by
zhouhaibao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]新增异常处理
1 parent
d7c8078c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
136 additions
and
7 deletions
platform-process/src/main/java/cn/com/glsx/process/common/sysenum/ResultEnum.java
platform-process/src/main/java/cn/com/glsx/process/exception/AdminException.java
platform-process/src/main/java/cn/com/glsx/process/exception/AdminExceptionHandler.java
platform-process/src/main/java/cn/com/glsx/process/modules/controller/TestXXLJobController.java
platform-process/src/main/java/cn/com/glsx/process/common/sysenum/ResultEnum.java
0 → 100644
View file @
671e535
package
cn
.
com
.
glsx
.
process
.
common
.
sysenum
;
import
com.glsx.plat.exception.SystemMessage
;
/**
* 试驾服务错误码
*
* @author zhouhaibao
*/
public
enum
ResultEnum
{
PARAM_ERROR
(
1001
,
"参数错误"
);
private
final
Integer
code
;
private
final
String
message
;
ResultEnum
(
Integer
code
,
String
message
)
{
this
.
code
=
code
;
this
.
message
=
message
;
}
ResultEnum
(
SystemMessage
systemMessage
)
{
this
.
code
=
systemMessage
.
getCode
();
this
.
message
=
systemMessage
.
getMsg
();
}
public
Integer
getCode
()
{
return
code
;
}
public
String
getMessage
()
{
return
message
;
}
}
platform-process/src/main/java/cn/com/glsx/process/exception/AdminException.java
0 → 100644
View file @
671e535
package
cn
.
com
.
glsx
.
process
.
exception
;
import
cn.com.glsx.process.common.sysenum.ResultEnum
;
import
com.glsx.plat.exception.SystemMessage
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
* @author payu
*/
@Setter
@Getter
public
class
AdminException
extends
RuntimeException
{
private
int
errorCode
;
private
String
message
;
public
AdminException
()
{
}
public
AdminException
(
String
message
)
{
super
(
message
);
this
.
errorCode
=
SystemMessage
.
FAILURE
.
getCode
();
this
.
message
=
message
;
}
public
AdminException
(
int
errorCode
,
String
message
)
{
super
(
message
);
this
.
errorCode
=
errorCode
;
this
.
message
=
message
;
}
public
AdminException
(
ResultEnum
resultEnum
)
{
this
.
errorCode
=
resultEnum
.
getCode
();
this
.
message
=
resultEnum
.
getMessage
();
}
public
AdminException
(
Throwable
cause
)
{
super
(
cause
);
}
public
AdminException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
}
platform-process/src/main/java/cn/com/glsx/process/exception/AdminExceptionHandler.java
0 → 100644
View file @
671e535
package
cn
.
com
.
glsx
.
process
.
exception
;
import
com.alibaba.excel.exception.ExcelDataConvertException
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.plat.exception.ExceptionLevel
;
import
com.glsx.plat.exception.GlobalRExceptionHandler
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.ibatis.binding.BindingException
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
/**
* 全局异常处理
*
* @author payu
*/
@Slf4j
@RestControllerAdvice
public
class
AdminExceptionHandler
extends
GlobalRExceptionHandler
{
@ExceptionHandler
(
AdminException
.
class
)
public
R
handleAdminException
(
AdminException
e
)
{
return
R
.
error
(
e
.
getErrorCode
(),
e
.
getMessage
());
}
/**
* Mybatis BindingException
*
* @param e
* @return
*/
@ExceptionHandler
(
BindingException
.
class
)
public
R
handleBindingException
(
BindingException
e
)
{
return
R
.
error
(
e
.
getMessage
());
}
@ExceptionHandler
(
ExcelDataConvertException
.
class
)
public
R
handleExcelDataConvertException
(
ExcelDataConvertException
e
)
{
return
R
.
error
(
e
.
getMessage
());
}
@Override
protected
void
saveException
(
Exception
e
,
ExceptionLevel
level
)
{
super
.
saveException
(
e
,
level
);
}
}
platform-process/src/main/java/cn/com/glsx/process/modules/controller/TestXXLJobController.java
View file @
671e535
package
cn
.
com
.
glsx
.
process
.
modules
.
controller
;
import
cn.com.glsx.process.common.sysenum.ResultEnum
;
import
cn.com.glsx.process.exception.AdminException
;
import
com.glsx.plat.exception.BusinessException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
...
@@ -29,8 +32,7 @@ public class TestXXLJobController {
@GetMapping
(
"/jobtest"
)
@Operation
(
summary
=
"动态任务添加"
,
description
=
"动态任务添加"
)
public
void
addtest
(
@RequestParam
(
"cron"
)
String
cron
,
@RequestParam
(
"jobName"
)
String
jobName
,
@RequestParam
(
"param"
)
String
param
,
@RequestParam
(
"executorHandler"
)
String
executorHandler
,
@RequestParam
(
"busKey"
)
String
busKey
)
{
public
void
addtest
(
@RequestParam
(
"cron"
)
String
cron
,
@RequestParam
(
"jobName"
)
String
jobName
,
@RequestParam
(
"param"
)
String
param
,
@RequestParam
(
"executorHandler"
)
String
executorHandler
,
@RequestParam
(
"busKey"
)
String
busKey
)
{
// cron表达式
XxlJobInfo
jobInfo
=
new
XxlJobInfo
();
jobInfo
.
setExecutorParam
(
param
);
...
...
@@ -44,11 +46,7 @@ public class TestXXLJobController {
@PostMapping
(
"/jobtestupdate"
)
@Operation
(
summary
=
"动态任务更新"
,
description
=
"动态任务更新"
)
public
void
updatetest
(
@RequestParam
(
value
=
"cron"
,
required
=
false
)
String
cron
,
@RequestParam
(
"id"
)
String
id
,
@RequestParam
(
value
=
"executorParam"
,
required
=
false
)
String
executorParam
,
@RequestParam
(
value
=
"jobDesc"
,
required
=
false
)
String
jobDesc
,
@RequestParam
(
value
=
"triggerStatus"
,
required
=
false
)
Integer
triggerStatus
)
{
public
void
updatetest
(
@RequestParam
(
value
=
"cron"
,
required
=
false
)
String
cron
,
@RequestParam
(
"id"
)
String
id
,
@RequestParam
(
value
=
"executorParam"
,
required
=
false
)
String
executorParam
,
@RequestParam
(
value
=
"jobDesc"
,
required
=
false
)
String
jobDesc
,
@RequestParam
(
value
=
"triggerStatus"
,
required
=
false
)
Integer
triggerStatus
)
{
XxlJobInfo
jobInfo
=
new
XxlJobInfo
();
jobInfo
.
setBusKey
(
id
);
jobInfo
.
setScheduleConf
(
cron
);
...
...
@@ -91,6 +89,9 @@ public class TestXXLJobController {
@PostMapping
(
"/testJava"
)
@Operation
(
summary
=
"测试java"
,
description
=
"动态任务触发"
)
public
R
testJava
(
@RequestParam
(
"busKey"
)
String
busKey
)
throws
Exception
{
if
(
true
)
{
throw
new
AdminException
(
ResultEnum
.
PARAM_ERROR
);
}
return
R
.
ok
().
data
(
userDemoService
.
testJava
(
busKey
));
}
}
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