Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
datacollector
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
chenweisong
datacollector
Commits
8d92466c
Commit
8d92466c
authored
Mar 26, 2020
by
chenweisong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新
parent
f505809d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
38 deletions
+38
-38
ExceptionHandlerConfig.java
...om/keymobile/rest/common/conf/ExceptionHandlerConfig.java
+2
-2
CommonException.java
.../com/keymobile/rest/common/exception/CommonException.java
+2
-2
CommonValidator.java
.../com/keymobile/rest/common/validator/CommonValidator.java
+15
-15
TaskController.java
...in/java/com/keymobile/rest/controller/TaskController.java
+15
-15
UserController.java
...in/java/com/keymobile/rest/controller/UserController.java
+4
-4
No files found.
src/main/java/com/keymobile/rest/common/conf/ExceptionHandlerConfig.java
View file @
8d92466c
...
...
@@ -2,7 +2,7 @@ package com.keymobile.rest.common.conf;
import
com.keymobile.rest.common.bean.ApiResponse
;
import
com.keymobile.rest.common.constant.ApiConstant
;
import
com.keymobile.rest.common.exception.
Twinkle
Exception
;
import
com.keymobile.rest.common.exception.
Common
Exception
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
...
...
@@ -27,7 +27,7 @@ public class ExceptionHandlerConfig {
*/
@ExceptionHandler
(
Exception
.
class
)
public
ApiResponse
globalException
(
Throwable
ex
)
{
if
(
ex
instanceof
Twinkle
Exception
)
{
if
(
ex
instanceof
Common
Exception
)
{
logger
.
warn
(
"访问出错:"
+
ex
.
getMessage
());
return
ApiResponse
.
fail
(
ApiConstant
.
FAILED_CODE
,
ex
.
getMessage
());
}
...
...
src/main/java/com/keymobile/rest/common/exception/
Twinkle
Exception.java
→
src/main/java/com/keymobile/rest/common/exception/
Common
Exception.java
View file @
8d92466c
...
...
@@ -9,10 +9,10 @@ import lombok.Data;
* @date :2019/1/12 23:28
*/
@Data
public
class
Twinkle
Exception
extends
RuntimeException
{
public
class
Common
Exception
extends
RuntimeException
{
private
static
final
long
serialVersionUID
=
3455708526465670030L
;
public
Twinkle
Exception
(
String
msg
)
{
public
Common
Exception
(
String
msg
)
{
super
(
msg
);
}
}
src/main/java/com/keymobile/rest/common/validator/
Twinkle
Validator.java
→
src/main/java/com/keymobile/rest/common/validator/
Common
Validator.java
View file @
8d92466c
package
com
.
keymobile
.
rest
.
common
.
validator
;
import
com.keymobile.rest.common.exception.
Twinkle
Exception
;
import
com.keymobile.rest.common.exception.
Common
Exception
;
import
java.util.Collection
;
import
java.util.Map
;
...
...
@@ -12,37 +12,37 @@ import java.util.regex.Pattern;
* @author :chenws
* @date :2019/1/12 23:28
*/
public
final
class
Twinkle
Validator
extends
AbstractValidator
{
public
final
class
Common
Validator
extends
AbstractValidator
{
public
static
void
isTrue
(
boolean
flag
,
String
message
)
{
if
(!
flag
)
{
throw
new
Twinkle
Exception
(
message
);
throw
new
Common
Exception
(
message
);
}
}
public
static
void
isFalse
(
boolean
flag
,
String
message
)
{
if
(
flag
)
{
throw
new
Twinkle
Exception
(
message
);
throw
new
Common
Exception
(
message
);
}
}
public
static
void
notLessThan
(
int
value
,
int
flag
,
String
message
)
{
if
(
value
<
flag
)
{
throw
new
Twinkle
Exception
(
message
);
throw
new
Common
Exception
(
message
);
}
}
public
static
void
notMessThan
(
int
value
,
int
flag
,
String
message
)
{
if
(
value
>
flag
)
{
throw
new
Twinkle
Exception
(
message
);
throw
new
Common
Exception
(
message
);
}
}
public
static
<
T
>
boolean
notNull
(
T
value
,
String
message
)
{
boolean
isValid
=
notNull
(
value
);
if
(!
isValid
)
{
throw
new
Twinkle
Exception
(
message
);
throw
new
Common
Exception
(
message
);
}
return
isValid
;
}
...
...
@@ -53,7 +53,7 @@ public final class TwinkleValidator extends AbstractValidator {
}
boolean
isValid
=
Pattern
.
matches
(
"^\\d+$"
,
input
);
if
(!
isValid
)
{
throw
new
Twinkle
Exception
(
message
);
throw
new
Common
Exception
(
message
);
}
return
isValid
;
}
...
...
@@ -61,7 +61,7 @@ public final class TwinkleValidator extends AbstractValidator {
public
static
<
T
extends
CharSequence
>
boolean
notEmpty
(
T
value
,
String
message
)
{
boolean
isValid
=
notEmpty
(
value
);
if
(!
isValid
)
{
throw
new
Twinkle
Exception
(
message
);
throw
new
Common
Exception
(
message
);
}
return
isValid
;
}
...
...
@@ -69,7 +69,7 @@ public final class TwinkleValidator extends AbstractValidator {
public
static
<
T
>
boolean
notEmpty
(
T
[]
value
,
String
message
)
{
boolean
isValid
=
notEmpty
(
value
);
if
(!
isValid
)
{
throw
new
Twinkle
Exception
(
message
);
throw
new
Common
Exception
(
message
);
}
return
isValid
;
}
...
...
@@ -77,7 +77,7 @@ public final class TwinkleValidator extends AbstractValidator {
public
static
<
T
extends
Collection
<?>>
boolean
notEmpty
(
T
value
,
String
message
)
{
boolean
isValid
=
notEmpty
(
value
);
if
(!
isValid
)
{
throw
new
Twinkle
Exception
(
message
);
throw
new
Common
Exception
(
message
);
}
return
isValid
;
}
...
...
@@ -85,7 +85,7 @@ public final class TwinkleValidator extends AbstractValidator {
public
static
<
T
extends
Map
<?,
?>>
boolean
notEmpty
(
T
value
,
String
message
)
{
boolean
isValid
=
notEmpty
(
value
);
if
(!
isValid
)
{
throw
new
Twinkle
Exception
(
message
);
throw
new
Common
Exception
(
message
);
}
return
isValid
;
}
...
...
@@ -93,7 +93,7 @@ public final class TwinkleValidator extends AbstractValidator {
public
static
boolean
maxLength
(
String
value
,
int
maxLength
,
String
message
)
{
boolean
isValid
=
maxLength
(
value
,
maxLength
);
if
(!
isValid
)
{
throw
new
Twinkle
Exception
(
message
);
throw
new
Common
Exception
(
message
);
}
return
isValid
;
}
...
...
@@ -101,7 +101,7 @@ public final class TwinkleValidator extends AbstractValidator {
public
static
boolean
range
(
String
value
,
int
minLength
,
int
maxLength
,
String
message
)
{
boolean
isValid
=
range
(
value
,
minLength
,
maxLength
);
if
(!
isValid
)
{
throw
new
Twinkle
Exception
(
message
);
throw
new
Common
Exception
(
message
);
}
return
isValid
;
}
...
...
@@ -109,7 +109,7 @@ public final class TwinkleValidator extends AbstractValidator {
public
static
boolean
range
(
Integer
value
,
int
min
,
int
max
,
String
message
)
{
boolean
isValid
=
range
(
value
,
min
,
max
);
if
(!
isValid
)
{
throw
new
Twinkle
Exception
(
message
);
throw
new
Common
Exception
(
message
);
}
return
isValid
;
}
...
...
src/main/java/com/keymobile/rest/controller/TaskController.java
View file @
8d92466c
...
...
@@ -4,7 +4,7 @@ import com.google.common.collect.ImmutableMap;
import
com.keymobile.rest.common.bean.ApiResponse
;
import
com.keymobile.rest.common.utils.BeanUtils
;
import
com.keymobile.rest.common.utils.DateUtil
;
import
com.keymobile.rest.common.validator.
Twinkle
Validator
;
import
com.keymobile.rest.common.validator.
Common
Validator
;
import
com.keymobile.rest.model.*
;
import
com.keymobile.rest.model.Process
;
import
com.keymobile.rest.service.*
;
...
...
@@ -84,7 +84,7 @@ public class TaskController {
@PostMapping
(
value
=
"/get"
)
public
ApiResponse
get
(
long
taskId
)
{
Activity
activity
=
activityService
.
get
(
taskId
);
Twinkle
Validator
.
notNull
(
activity
,
"活动不存在"
);
Common
Validator
.
notNull
(
activity
,
"活动不存在"
);
return
ApiResponse
.
ok
(
activity
);
}
...
...
@@ -134,10 +134,10 @@ public class TaskController {
@ApiOperation
(
value
=
"新建活动"
)
@PostMapping
(
value
=
"/create"
)
public
ApiResponse
createTask
(
@RequestBody
TaskForm
form
)
{
Twinkle
Validator
.
notEmpty
(
form
.
getName
(),
"名称不能为空"
);
Twinkle
Validator
.
notNull
(
form
.
getType
(),
"类型不能为空"
);
Common
Validator
.
notEmpty
(
form
.
getName
(),
"名称不能为空"
);
Common
Validator
.
notNull
(
form
.
getType
(),
"类型不能为空"
);
Twinkle
Validator
.
isTrue
(
form
.
getExcels
()
!=
null
&&
form
.
getExcels
().
size
()
!=
0
,
"补录模板不能为空"
);
Common
Validator
.
isTrue
(
form
.
getExcels
()
!=
null
&&
form
.
getExcels
().
size
()
!=
0
,
"补录模板不能为空"
);
// 创建人 为 manager
User
admin
=
getAdmin
();
form
.
setUser
(
admin
);
...
...
@@ -151,15 +151,15 @@ public class TaskController {
// 新建excel实例
List
<
ExcelForm
>
excelFormList
=
form
.
getExcels
();
excelFormList
.
forEach
(
excelForm
->
{
Twinkle
Validator
.
isTrue
(
excelForm
.
getName
()
!=
null
,
"模板名称不能为空"
);
Twinkle
Validator
.
isTrue
(
excelForm
.
getConfig
()
!=
null
,
"模板配置config不能为空"
);
Twinkle
Validator
.
isTrue
(
excelForm
.
getScopeId
()
!=
null
&&
excelForm
.
getScopeId
()
!=
0
,
"模板scopeId不能为空"
);
Twinkle
Validator
.
isTrue
(
excelForm
.
getNeedAudit
()
!=
null
&&
excelForm
.
getNeedAudit
()
!=
0
,
"模板needAudit不能为空"
);
Twinkle
Validator
.
isTrue
(
excelForm
.
getNeedConfirm
()
!=
null
&&
excelForm
.
getNeedConfirm
()
!=
0
,
"模板needConfirm不能为空"
);
Common
Validator
.
isTrue
(
excelForm
.
getName
()
!=
null
,
"模板名称不能为空"
);
Common
Validator
.
isTrue
(
excelForm
.
getConfig
()
!=
null
,
"模板配置config不能为空"
);
Common
Validator
.
isTrue
(
excelForm
.
getScopeId
()
!=
null
&&
excelForm
.
getScopeId
()
!=
0
,
"模板scopeId不能为空"
);
Common
Validator
.
isTrue
(
excelForm
.
getNeedAudit
()
!=
null
&&
excelForm
.
getNeedAudit
()
!=
0
,
"模板needAudit不能为空"
);
Common
Validator
.
isTrue
(
excelForm
.
getNeedConfirm
()
!=
null
&&
excelForm
.
getNeedConfirm
()
!=
0
,
"模板needConfirm不能为空"
);
RecordScope
scope
=
recordScopeService
.
findById
(
excelForm
.
getScopeId
());
Twinkle
Validator
.
isTrue
(
scope
!=
null
,
"补录范围不能为空"
);
Twinkle
Validator
.
isFalse
((
StringUtils
.
isEmpty
(
excelForm
.
getUpStreamAddr
())
&&
StringUtils
.
isNotEmpty
(
excelForm
.
getBackStreamAddr
())
Common
Validator
.
isTrue
(
scope
!=
null
,
"补录范围不能为空"
);
Common
Validator
.
isFalse
((
StringUtils
.
isEmpty
(
excelForm
.
getUpStreamAddr
())
&&
StringUtils
.
isNotEmpty
(
excelForm
.
getBackStreamAddr
())
||
(
StringUtils
.
isNotEmpty
(
excelForm
.
getUpStreamAddr
())
&&
StringUtils
.
isEmpty
(
excelForm
.
getBackStreamAddr
()))),
"上游地址和回流地址需同时填写或者同时为空"
);
excelForm
.
setActivity
(
finalActivity
);
...
...
@@ -169,7 +169,7 @@ public class TaskController {
// 查找当前补录范围所有的用户
List
<
User
>
userList
=
scope
.
getUserList
();
Twinkle
Validator
.
notLessThan
(
userList
.
size
(),
1
,
"补录人员不存在,所选补录范围需要先绑定用户"
);
Common
Validator
.
notLessThan
(
userList
.
size
(),
1
,
"补录人员不存在,所选补录范围需要先绑定用户"
);
userList
.
forEach
(
user
->
{
// 创建了一些空白任务
...
...
@@ -192,10 +192,10 @@ public class TaskController {
@PostMapping
(
value
=
"/start"
)
public
ApiResponse
startTask
(
long
taskId
)
{
Activity
activity
=
activityService
.
get
(
taskId
);
Twinkle
Validator
.
notNull
(
activity
,
"活动不存在"
);
Common
Validator
.
notNull
(
activity
,
"活动不存在"
);
// 根据活动查找需要填写的人 目前只支持一人
List
<
Template
>
templateList
=
activity
.
getExcelList
();
Twinkle
Validator
.
notLessThan
(
templateList
.
size
(),
1
,
"补录模板不存在"
);
Common
Validator
.
notLessThan
(
templateList
.
size
(),
1
,
"补录模板不存在"
);
// 部署补录流程
Deployment
deploy
=
repositoryService
...
...
src/main/java/com/keymobile/rest/controller/UserController.java
View file @
8d92466c
package
com
.
keymobile
.
rest
.
controller
;
import
com.keymobile.rest.common.bean.ApiResponse
;
import
com.keymobile.rest.common.validator.
Twinkle
Validator
;
import
com.keymobile.rest.common.validator.
Common
Validator
;
import
com.keymobile.rest.model.*
;
import
com.keymobile.rest.service.*
;
import
io.swagger.annotations.Api
;
...
...
@@ -73,10 +73,10 @@ public class UserController {
@PostMapping
(
value
=
"/scope/bindUser"
)
public
ApiResponse
bindUser
(
long
scopeId
,
long
userId
)
{
RecordScope
scope
=
recordScopeService
.
findById
(
scopeId
);
Twinkle
Validator
.
notNull
(
scope
,
"所选范围不存在"
);
Common
Validator
.
notNull
(
scope
,
"所选范围不存在"
);
User
user
=
userService
.
findById
(
userId
);
Twinkle
Validator
.
notNull
(
user
,
"所选用户不存在"
);
Twinkle
Validator
.
isTrue
(
scope
.
getGroup
().
getId
()
==
user
.
getGroup
().
getId
(),
"所选用户与所选范围不属于同一机构"
);
Common
Validator
.
notNull
(
user
,
"所选用户不存在"
);
Common
Validator
.
isTrue
(
scope
.
getGroup
().
getId
()
==
user
.
getGroup
().
getId
(),
"所选用户与所选范围不属于同一机构"
);
List
<
User
>
userList
=
scope
.
getUserList
();
if
(!
userList
.
contains
(
user
))
{
userList
.
add
(
user
);
...
...
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