Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gjjs-bd-common
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
s_guodong
gjjs-bd-common
Commits
152843b4
Commit
152843b4
authored
Aug 09, 2023
by
s_guodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持定制vo
parent
921b3994
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
165 additions
and
62 deletions
+165
-62
AbstractCommonResource.java
...om/ceb/gjjs/mda/resource/base/AbstractCommonResource.java
+92
-23
ValidatorUtil.java
...ss/src/main/java/com/ceb/gjjs/mda/util/ValidatorUtil.java
+12
-3
Need.java
...main/java/com/brilliance/mda/runtime/annotation/Need.java
+16
-0
BaseVO.java
.../main/java/com/brilliance/mda/runtime/request/BaseVO.java
+10
-9
ResponseSet.java
...java/com/brilliance/mda/runtime/response/ResponseSet.java
+35
-27
No files found.
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/resource/base/AbstractCommonResource.java
View file @
152843b4
...
...
@@ -3,12 +3,12 @@ package com.ceb.gjjs.mda.resource.base;
import
com.brilliance.mda.runtime.request.BaseVO
;
import
com.brilliance.mda.runtime.response.ResponseSet
;
import
com.brilliance.mda.support.service.ICommonService
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
java.util.Set
;
/**
* @author wangguangchao
...
...
@@ -18,88 +18,157 @@ public abstract class AbstractCommonResource<V extends BaseVO> {
protected
abstract
ICommonService
getCommonService
();
@Path
(
"/init"
)
@POST
public
ResponseSet
<
V
>
init
(
@RequestBody
V
req
)
{
return
getCommonService
().
init
(
req
);
String
checkResult
=
checkParam
(
req
);
if
(
StringUtils
.
isNotBlank
(
checkResult
))
{
return
new
ResponseSet
<>(
ResponseSet
.
CODE_FAILURE
,
checkResult
,
req
);
}
return
resetRespond
(
getCommonService
().
init
(
req
));
}
@Path
(
"/checkAll"
)
@POST
public
ResponseSet
checkAll
(
@RequestBody
V
req
)
{
return
getCommonService
().
checkAll
(
req
);
String
checkResult
=
checkParam
(
req
);
if
(
StringUtils
.
isNotBlank
(
checkResult
))
{
return
new
ResponseSet
<>(
ResponseSet
.
CODE_FAILURE
,
checkResult
,
req
);
}
return
resetRespond
(
getCommonService
().
checkAll
(
req
));
}
@Path
(
"/saveData"
)
@POST
public
ResponseSet
<
V
>
saveData
(
@RequestBody
V
req
)
{
return
getCommonService
().
saveData
(
req
);
String
checkResult
=
checkParam
(
req
);
if
(
StringUtils
.
isNotBlank
(
checkResult
))
{
return
new
ResponseSet
<>(
ResponseSet
.
CODE_FAILURE
,
checkResult
,
req
);
}
return
resetRespond
(
getCommonService
().
saveData
(
req
));
}
@Path
(
"/confirmData"
)
@POST
public
ResponseSet
<
V
>
confirmData
(
@RequestBody
V
req
)
{
return
getCommonService
().
confirmData
(
req
);
String
checkResult
=
checkParam
(
req
);
if
(
StringUtils
.
isNotBlank
(
checkResult
))
{
return
new
ResponseSet
<>(
ResponseSet
.
CODE_FAILURE
,
checkResult
,
req
);
}
return
resetRespond
(
getCommonService
().
confirmData
(
req
));
}
@Path
(
"/pending"
)
@POST
public
ResponseSet
<
V
>
pending
(
@RequestBody
V
req
)
{
return
getCommonService
().
pending
(
req
);
String
checkResult
=
checkParam
(
req
);
if
(
StringUtils
.
isNotBlank
(
checkResult
))
{
return
new
ResponseSet
<>(
ResponseSet
.
CODE_FAILURE
,
checkResult
,
req
);
}
return
resetRespond
(
getCommonService
().
pending
(
req
));
}
@Path
(
"/executeCheck/{rule}"
)
@POST
public
ResponseSet
<
V
>
executeCheck
(
@PathParam
(
"rule"
)
String
rule
,
@RequestBody
V
req
)
{
String
checkResult
=
checkParam
(
rule
,
req
);
if
(
StringUtils
.
isNotBlank
(
checkResult
))
{
return
new
ResponseSet
<>(
ResponseSet
.
CODE_FAILURE
,
checkResult
,
req
);
}
String
[]
ruleArr
=
rule
.
split
(
","
);
return
getCommonService
().
executeCheck
(
req
,
ruleArr
);
return
resetRespond
(
rule
,
getCommonService
().
executeCheck
(
req
,
ruleArr
)
);
}
@Path
(
"/executeRule/{rule}"
)
@POST
public
ResponseSet
<
V
>
executeRule
(
@PathParam
(
"rule"
)
String
rule
,
@RequestBody
V
req
)
{
String
checkResult
=
checkParam
(
rule
,
req
);
if
(
StringUtils
.
isNotBlank
(
checkResult
))
{
return
new
ResponseSet
<>(
ResponseSet
.
CODE_FAILURE
,
checkResult
,
req
);
}
String
[]
ruleArr
=
rule
.
split
(
","
);
ResponseSet
<
V
>
res
=
getCommonService
().
executeRule
(
req
,
ruleArr
);
return
res
;
return
res
etRespond
(
rule
,
res
)
;
}
@Path
(
"/executeDefault/{rule}"
)
@POST
public
ResponseSet
<
V
>
executeDefault
(
@PathParam
(
"rule"
)
String
rule
,
@RequestBody
V
req
)
{
String
checkResult
=
checkParam
(
rule
,
req
);
if
(
StringUtils
.
isNotBlank
(
checkResult
))
{
return
new
ResponseSet
<>(
ResponseSet
.
CODE_FAILURE
,
checkResult
,
req
);
}
String
[]
ruleArr
=
rule
.
split
(
","
);
return
getCommonService
().
executeDefault
(
req
,
ruleArr
);
return
resetRespond
(
rule
,
getCommonService
().
executeDefault
(
req
,
ruleArr
)
);
}
@Path
(
"/executeNotify"
)
@POST
public
ResponseSet
<
V
>
executeNotify
(
@RequestBody
V
req
)
{
return
getCommonService
().
executeNotify
(
req
);
String
checkResult
=
checkParam
(
req
);
if
(
StringUtils
.
isNotBlank
(
checkResult
))
{
return
new
ResponseSet
<>(
ResponseSet
.
CODE_FAILURE
,
checkResult
,
req
);
}
return
resetRespond
(
getCommonService
().
executeNotify
(
req
));
}
@Path
(
"/executeDocpan"
)
@POST
public
ResponseSet
<
V
>
executeDocpan
(
@RequestBody
V
req
)
{
return
getCommonService
().
executeDocpan
(
req
);
String
checkResult
=
checkParam
(
req
);
if
(
StringUtils
.
isNotBlank
(
checkResult
))
{
return
new
ResponseSet
<>(
ResponseSet
.
CODE_FAILURE
,
checkResult
,
req
);
}
return
resetRespond
(
getCommonService
().
executeDocpan
(
req
));
}
@Path
(
"/executeDocpanDetail"
)
@POST
public
ResponseSet
<
V
>
executeDocpanDetail
(
@RequestBody
V
req
)
{
return
getCommonService
().
executeDocpanDetail
(
req
);
String
checkResult
=
checkParam
(
req
);
if
(
StringUtils
.
isNotBlank
(
checkResult
))
{
return
new
ResponseSet
<>(
ResponseSet
.
CODE_FAILURE
,
checkResult
,
req
);
}
ResponseSet
responseSet
=
getCommonService
().
executeDocpanDetail
(
req
);
return
resetRespond
(
responseSet
);
}
private
void
setInitFlag
(
V
req
,
Set
<
String
>
needInitSet
,
String
[]
ruleArr
)
{
Class
<?
extends
AbstractCommonResource
>
aClass
=
this
.
getClass
();
Path
annotation
=
aClass
.
getAnnotation
(
Path
.
class
);
String
path
=
annotation
.
value
();
for
(
String
rule
:
ruleArr
)
{
if
(
needInitSet
.
contains
(
path
+
"@"
+
rule
))
{
req
.
setNeedInit
(
true
);
return
;
}
}
}
/**
* 检验参数
*
* @param rule
* @param req
* @return
*/
protected
abstract
String
checkParam
(
String
rule
,
V
req
);
/**
* 检验参数
*
* @param req
* @return
*/
protected
abstract
String
checkParam
(
V
req
);
/**
* 重新设置返回值
*
* @param rule
* @param responseSet
* @return
*/
protected
abstract
ResponseSet
<
V
>
resetRespond
(
String
rule
,
ResponseSet
<
V
>
responseSet
);
/**
* 重新设置返回值
*
* @param responseSet
* @return
*/
protected
abstract
ResponseSet
<
V
>
resetRespond
(
ResponseSet
<
V
>
responseSet
);
}
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/util/ValidatorUtil.java
View file @
152843b4
package
com
.
ceb
.
gjjs
.
mda
.
util
;
import
com.brilliance.mda.runtime.annotation.Need
;
import
org.apache.commons.lang3.StringUtils
;
import
org.hibernate.validator.constraints.Length
;
...
...
@@ -32,18 +33,26 @@ public class ValidatorUtil {
if
(
o
!=
null
)
{
String
stringValue
=
(
String
)
o
;
if
(
stringValue
.
length
()
>
max
||
stringValue
.
length
()
<
min
)
{
return
f
.
getName
()
+
":"
+
message
;
return
"参数校验错误["
+
f
.
getName
()
+
":"
+
message
+
"]"
;
}
}
}
if
(
f
.
isAnnotationPresent
(
NotEmpty
.
class
)
&&
type
.
isAssignableFrom
(
String
.
class
))
{
if
(
o
==
null
||
StringUtils
.
isBlank
((
String
)
o
))
{
return
f
.
getName
()
+
":不能为空
"
;
return
"参数校验错误["
+
f
.
getName
()
+
":不能为空]
"
;
}
}
if
(
f
.
isAnnotationPresent
(
NotNull
.
class
)
&&
!
type
.
isAssignableFrom
(
String
.
class
))
{
if
(
o
==
null
)
{
return
f
.
getName
()
+
":不能为null"
;
return
"参数校验错误["
+
f
.
getName
()
+
":不能为null]"
;
}
}
if
(
f
.
isAnnotationPresent
(
Need
.
class
))
{
if
(
o
==
null
)
{
return
"参数校验错误["
+
f
.
getName
()
+
":为必需参数]"
;
}
if
(
type
.
isAssignableFrom
(
String
.
class
)
&&
StringUtils
.
isBlank
((
String
)
o
))
{
return
"参数校验错误["
+
f
.
getName
()
+
":为必需参数,不能为空]"
;
}
}
}
...
...
gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/annotation/Need.java
0 → 100644
View file @
152843b4
package
com
.
brilliance
.
mda
.
runtime
.
annotation
;
import
java.lang.annotation.*
;
/**
* 是否需要执行初始化方法
*/
@Documented
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
(
ElementType
.
FIELD
)
public
@interface
Need
{
boolean
value
()
default
true
;
String
message
()
default
"不能为空"
;
}
gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/request/BaseVO.java
View file @
152843b4
...
...
@@ -5,9 +5,10 @@ import java.util.Map;
public
class
BaseVO
{
protected
String
src
;
protected
boolean
needInit
;
protected
String
pageId
;
protected
Map
<
String
,
Object
>
params
;
protected
Map
<
String
,
Object
>
special_vo
;
protected
List
<
Map
<
String
,
Object
>>
changes
;
...
...
@@ -55,14 +56,6 @@ public class BaseVO {
this
.
pageSize
=
pageSize
;
}
public
boolean
isNeedInit
()
{
return
needInit
;
}
public
void
setNeedInit
(
boolean
needInit
)
{
this
.
needInit
=
needInit
;
}
public
String
getSrc
()
{
return
src
;
}
...
...
@@ -70,4 +63,12 @@ public class BaseVO {
public
void
setSrc
(
String
src
)
{
this
.
src
=
src
;
}
public
Map
<
String
,
Object
>
getSpecial_vo
()
{
return
special_vo
;
}
public
void
setSpecial_vo
(
Map
<
String
,
Object
>
special_vo
)
{
this
.
special_vo
=
special_vo
;
}
}
gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/response/ResponseSet.java
View file @
152843b4
package
com
.
brilliance
.
mda
.
runtime
.
response
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
com.brilliance.mda.runtime.mda.IContext
;
import
com.brilliance.mda.runtime.mda.driver.MdaDriver
;
import
com.brilliance.mda.runtime.mda.driver.MdaEnv
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
ResponseSet
<
T
>
{
...
...
@@ -17,16 +17,17 @@ public class ResponseSet<T> {
/**
* 成功代码
*/
public
static
final
String
CODE_SUCCESS
=
"AAAAAA"
;
public
static
final
String
MSG_SUCESS
=
"操作成功!"
;
public
static
final
String
CODE_SUCCESS
=
"AAAAAA"
;
public
static
final
String
CODE_FAILURE
=
"BBBBBB"
;
public
static
final
String
MSG_SUCESS
=
"操作成功!"
;
private
String
respCode
;
private
String
respMsg
;
private
Map
<
String
,
String
>
fieldErrors
;
private
Map
<
String
,
String
>
fieldErrors
;
private
Map
<
String
,
List
<
String
>>
codeSet
;
private
Object
data
;
public
ResponseSet
(
IContext
ctx
,
Object
t
){
public
ResponseSet
(
IContext
ctx
,
Object
t
)
{
this
.
respCode
=
CODE_SUCCESS
;
this
.
respMsg
=
MSG_SUCESS
;
this
.
data
=
t
;
...
...
@@ -35,31 +36,32 @@ public class ResponseSet<T> {
ctx
.
visitValues
();
MdaDriver
.
setValueToVO
(
ctx
,
this
.
data
);
}
private
Map
<
String
,
List
<
String
>>
getValuesSet
(
IContext
ctx
){
private
Map
<
String
,
List
<
String
>>
getValuesSet
(
IContext
ctx
)
{
Map
<
String
,
List
<
String
>>
valuesSet
=
new
LinkedHashMap
<>();
ctx
.
getValuesSet
().
forEach
((
key
,
codeEntity
)
->
{
if
(!
codeEntity
.
visited
)
{
valuesSet
.
put
(
key
,
codeEntity
.
values
);
ctx
.
getValuesSet
().
forEach
((
key
,
codeEntity
)
->
{
if
(!
codeEntity
.
visited
)
{
valuesSet
.
put
(
key
,
codeEntity
.
values
);
}
});
return
valuesSet
;
}
private
Map
<
String
,
String
>
cloneFieldErrorsFromContext
(
IContext
ctx
)
{
if
(
ctx
==
null
)
{
private
Map
<
String
,
String
>
cloneFieldErrorsFromContext
(
IContext
ctx
)
{
if
(
ctx
==
null
)
{
return
null
;
}
Map
<
String
,
String
>
fieldErrors
=
ctx
.
getFieldErrors
();
Map
<
String
,
String
>
fieldErrorsClone
=
new
LinkedHashMap
<>();
Map
<
String
,
String
>
fieldErrors
=
ctx
.
getFieldErrors
();
Map
<
String
,
String
>
fieldErrorsClone
=
new
LinkedHashMap
<>();
fieldErrorsClone
.
putAll
(
fieldErrors
);
fieldErrors
.
clear
();
return
fieldErrorsClone
;
}
public
ResponseSet
(
Object
t
){
public
ResponseSet
(
Object
t
)
{
this
.
respCode
=
CODE_SUCCESS
;
this
.
respMsg
=
MSG_SUCESS
;
if
(
MdaEnv
.
getContext
()!=
null
)
{
if
(
MdaEnv
.
getContext
()
!=
null
)
{
fieldErrors
=
cloneFieldErrorsFromContext
(
MdaEnv
.
getContext
());
this
.
codeSet
=
getValuesSet
(
MdaEnv
.
getContext
());
MdaEnv
.
getContext
().
visitValues
();
...
...
@@ -67,10 +69,10 @@ public class ResponseSet<T> {
this
.
data
=
t
;
}
public
ResponseSet
(
String
errCode
,
String
errMsg
)
{
public
ResponseSet
(
String
errCode
,
String
errMsg
)
{
this
.
respCode
=
errCode
;
this
.
respMsg
=
errMsg
;
if
(
MdaEnv
.
getContext
()!=
null
)
{
if
(
MdaEnv
.
getContext
()
!=
null
)
{
fieldErrors
=
cloneFieldErrorsFromContext
(
MdaEnv
.
getContext
());
this
.
codeSet
=
getValuesSet
(
MdaEnv
.
getContext
());
MdaEnv
.
getContext
().
visitValues
();
...
...
@@ -81,16 +83,18 @@ public class ResponseSet<T> {
// this(errCode,errMsg);
// this.fieldErrors = fieldErrors;
// }
public
ResponseSet
(
String
errCode
,
String
errMsg
,
T
t
)
{
this
(
errCode
,
errMsg
);
public
ResponseSet
(
String
errCode
,
String
errMsg
,
T
t
)
{
this
(
errCode
,
errMsg
);
this
.
data
=
t
;
if
(
t
!=
null
)
{
if
(
t
!=
null
&&
MdaEnv
.
getContext
()
!=
null
)
{
MdaDriver
.
setValueToVO
(
MdaEnv
.
getContext
(),
this
.
data
);
}
}
public
Object
getData
()
{
return
data
;
}
public
void
setData
(
Object
data
)
{
this
.
data
=
data
;
}
...
...
@@ -127,18 +131,22 @@ public class ResponseSet<T> {
this
.
codeSet
=
codeSet
;
}
static
class
BooleanResult
{
static
class
BooleanResult
{
boolean
result
;
public
BooleanResult
(
boolean
result
){
public
BooleanResult
(
boolean
result
)
{
this
.
result
=
result
;
}
}
static
final
String
FAIL_CODE
=
"999999"
;
public
static
ResponseSet
fail
(
String
message
)
{
ResponseSet
responseSet
=
new
ResponseSet
(
FAIL_CODE
,
message
);
ResponseSet
responseSet
=
new
ResponseSet
(
FAIL_CODE
,
message
);
return
responseSet
;
}
public
static
ResponseSet
simpleSuccess
(
Object
data
){
public
static
ResponseSet
simpleSuccess
(
Object
data
)
{
return
new
ResponseSet
(
data
);
}
...
...
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