Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Fedex
/
iClear-Connect-Pre-Clearance
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
tao.mo
2024-11-12 15:07:44 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8af3aaeff4a3ae25be084a4f4d5279bcf990ce8c
8af3aaef
1 parent
38735c40
biz-customer | 修改 | 信息校验
mt 2024年11月12日15:07:37
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
57 additions
and
22 deletions
server/biz-customer/src/main/java/com/fedex/connect/customer/data/bo/ConsignmentBo.java
server/biz-customer/src/main/java/com/fedex/connect/customer/enums/ResponseCode.java
server/biz-customer/src/main/java/com/fedex/connect/customer/validate/controller/biz/ConsignmentInfoValidate.java
server/biz-customer/src/main/java/com/fedex/connect/customer/validate/controller/biz/ConsignmentValidate.java
server/biz-customer/src/main/resources/message_en_US.properties
server/biz-customer/src/main/resources/message_zh_CN.properties
server/common-dependencies/src/main/java/com/fedex/connect/common/dependencies/annotation/BaseNotBlank.java
server/common-dependencies/src/main/java/com/fedex/connect/common/dependencies/util/BaseValidateUtils.java
server/common-dependencies/src/main/java/com/fedex/connect/common/dependencies/util/ResponseUtils.java
server/biz-customer/src/main/java/com/fedex/connect/customer/data/bo/ConsignmentBo.java
View file @
8af3aae
...
...
@@ -10,24 +10,24 @@ public class ConsignmentBo {
//运单id
private
Integer
id
;
//运单号
@BaseNotBlank
@BaseNotBlank
(
describe
=
"business_field_31003"
)
private
String
consignmentCode
;
//
用户录入shipperAccount
@BaseNotBlank
//
发货人计费账号
@BaseNotBlank
(
describe
=
"business_field_31001"
)
private
String
shipperAccount
;
//原产国code
@BaseNotBlank
@BaseNotBlank
(
describe
=
"business_field_31004"
)
private
String
originCountryCode
;
//原产国全
程
@BaseNotBlank
//原产国全
称
@BaseNotBlank
(
describe
=
"business_field_31005"
)
private
String
originCountry
;
//目的国code
@BaseNotBlank
@BaseNotBlank
(
describe
=
"business_field_31006"
)
private
String
destinationCountryCode
;
//目的国全称
@BaseNotBlank
@BaseNotBlank
(
describe
=
"business_field_31007"
)
private
String
destinationCountry
;
//文件业务类型AWB,INV,PKL,OTH(分运单,发票,箱单和其它这四种类型)
@BaseNotBlank
@BaseNotBlank
(
describe
=
"business_field_31008"
)
private
List
<
String
>
fileBizType
;
}
...
...
server/biz-customer/src/main/java/com/fedex/connect/customer/enums/ResponseCode.java
View file @
8af3aae
...
...
@@ -9,6 +9,13 @@ public enum ResponseCode {
//********************biz_customer模块
//#*********用于字段描述使用,不单独使用**********
MESSAGE_CODE_31001
(
31001
,
"business_field_31001"
),
MESSAGE_CODE_31002
(
31002
,
"business_field_31002"
),
MESSAGE_CODE_31003
(
31003
,
"business_field_31003"
),
MESSAGE_CODE_31004
(
31004
,
"business_field_31004"
),
MESSAGE_CODE_31005
(
31005
,
"business_field_31005"
),
MESSAGE_CODE_31006
(
31006
,
"business_field_31006"
),
MESSAGE_CODE_31007
(
31007
,
"business_field_31007"
),
MESSAGE_CODE_31008
(
31008
,
"business_field_31008"
),
//#*********具体响应到前端**********
MESSAGE_CODE_30001
(
30001
,
"business_exception_30001"
),
...
...
server/biz-customer/src/main/java/com/fedex/connect/customer/validate/controller/biz/ConsignmentInfoValidate.java
View file @
8af3aae
...
...
@@ -27,7 +27,7 @@ public class ConsignmentInfoValidate {
*/
public
void
validateConsignmentId
(
Long
consignmentId
){
if
(
Objects
.
isNull
(
consignmentId
)){
responseUtils
.
fail
(
ResponseCode
.
MESSAGE_CODE_30001
);
responseUtils
.
fail
(
ResponseCode
.
MESSAGE_CODE_30001
,
ResponseCode
.
MESSAGE_CODE_31002
.
getMsg
()
);
}
}
}
...
...
server/biz-customer/src/main/java/com/fedex/connect/customer/validate/controller/biz/ConsignmentValidate.java
View file @
8af3aae
...
...
@@ -45,14 +45,9 @@ public class ConsignmentValidate {
* @return void
*/
public
void
validateConsignmentSubmit
(
ConsignmentBo
consignmentBo
){
Integer
code
=
ResponseCode
.
MESSAGE_CODE_30001
.
getCode
();
String
msg
=
ResponseCode
.
MESSAGE_CODE_30001
.
getMsg
();
if
(
Objects
.
isNull
(
consignmentBo
)){
responseUtils
.
fail
(
ResponseCode
.
MESSAGE_CODE_30001
);
}
/**
* 非空字段校验
*/
baseValidateUtils
.
notBlankValidate
(
consignmentBo
,
code
,
msg
);
baseValidateUtils
.
notBlankValidate
(
consignmentBo
,
ResponseCode
.
MESSAGE_CODE_30001
);
}
}
...
...
server/biz-customer/src/main/resources/message_en_US.properties
View file @
8af3aae
...
...
@@ -21,6 +21,12 @@ system_exception_10006=登录已过期,请重新登录
business_field_31001
=
发货人计费账号
business_field_31002
=
运单ID
business_field_31003
=
运单号
business_field_31004
=
原产国编码
business_field_31005
=
原产国名称
business_field_31006
=
目的国编码
business_field_31007
=
目的国全称
business_field_31008
=
文件业务类型
#*********具体响应到前端**********
business_exception_30001
=
${0}必填字段未填写
business_exception_30002
=
单次最多可查询1000个运单号码
...
...
server/biz-customer/src/main/resources/message_zh_CN.properties
View file @
8af3aae
...
...
@@ -21,6 +21,12 @@ system_exception_10006=登录已过期,请重新登录
business_field_31001
=
发货人计费账号
business_field_31002
=
运单ID
business_field_31003
=
运单号
business_field_31004
=
原产国编码
business_field_31005
=
原产国名称
business_field_31006
=
目的国编码
business_field_31007
=
目的国全称
business_field_31008
=
文件业务类型
#*********具体响应到前端**********
business_exception_30001
=
${0}必填字段未填写
business_exception_30002
=
单次最多可查询1000个运单号码
...
...
server/common-dependencies/src/main/java/com/fedex/connect/common/dependencies/annotation/BaseNotBlank.java
View file @
8af3aae
package
com
.
fedex
.
connect
.
common
.
dependencies
.
annotation
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* 字段非空注解
*/
@Target
(
ElementType
.
FIELD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
BaseNotBlank
{
//操作描述,使用国际化文件中编码
String
describe
();
}
...
...
server/common-dependencies/src/main/java/com/fedex/connect/common/dependencies/util/BaseValidateUtils.java
View file @
8af3aae
...
...
@@ -2,10 +2,13 @@ package com.fedex.connect.common.dependencies.util;
import
com.fedex.connect.common.dependencies.annotation.BaseNotBlank
;
import
com.fedex.connect.common.dependencies.exception.OpErrorException
;
import
com.fedex.connect.common.dependencies.i18n.LocaleMessageUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.StringUtils
;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Objects
;
/**
...
...
@@ -15,32 +18,44 @@ import java.util.Objects;
*/
@Component
public
class
BaseValidateUtils
{
@Autowired
ResponseUtils
responseUtils
;
@Autowired
LocaleMessageUtil
localeMessageUtil
;
/**
* 字段非空校验,仅对有BaseNotBlank注解字段进行非空校验,字段类型如果为字符串,空字符串也算空
* @param obj
*/
public
void
notBlankValidate
(
Object
obj
,
Integer
code
,
String
msg
){
public
void
notBlankValidate
(
Object
obj
,
Object
codeEnum
){
Class
cls
=
obj
.
getClass
();
Field
[]
fields
=
cls
.
getDeclaredFields
();
try
{
List
<
String
>
errorList
=
new
ArrayList
<>();
for
(
Field
field
:
fields
)
{
Annotation
annotation
=
field
.
getAnnotation
(
BaseNotBlank
.
class
);
BaseNotBlank
annotation
=
field
.
getAnnotation
(
BaseNotBlank
.
class
);
if
(
Objects
.
nonNull
(
annotation
))
{
Object
value
=
AssignmentFieldUtils
.
getFieldValue
(
obj
,
field
.
getName
());
if
(
value
instanceof
String
){
String
str
=
String
.
valueOf
(
value
);
if
(!
StringUtils
.
hasText
(
str
)){
throw
new
OpErrorException
(
code
,
msg
);
String
fieldName
=
localeMessageUtil
.
getMessage
(
annotation
.
describe
());
errorList
.
add
(
fieldName
);
}
}
else
{
if
(
Objects
.
isNull
(
value
)){
throw
new
OpErrorException
(
code
,
msg
);
String
fieldName
=
localeMessageUtil
.
getMessage
(
annotation
.
describe
());
errorList
.
add
(
fieldName
);
}
}
}
}
//存在非空字段为空的情况
if
(
errorList
.
size
()
>
0
){
responseUtils
.
fail
(
codeEnum
,
errorList
);
}
}
catch
(
Exception
ex
){
throw
new
OpErrorException
(
code
,
msg
);
responseUtils
.
fail
(
codeEnum
);
}
}
}
\ No newline at end of file
...
...
server/common-dependencies/src/main/java/com/fedex/connect/common/dependencies/util/ResponseUtils.java
View file @
8af3aae
...
...
@@ -50,6 +50,7 @@ public class ResponseUtils {
*/
public
void
fail
(
Object
codeEnum
,
Object
...
objects
)
{
ResponseCodeBo
responseCodeBo
=
this
.
ref
(
codeEnum
,
objects
);
log
.
error
(
responseCodeBo
.
getErrMsg
());
throw
new
OpErrorException
(
responseCodeBo
.
getCode
(),
responseCodeBo
.
getErrMsg
());
}
...
...
Please
register
or
login
to post a comment