Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yifu-mvp
Project
Project
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
fangxinjiang
yifu-mvp
Commits
eed3ae1a
Commit
eed3ae1a
authored
Jul 07, 2022
by
fangxinjiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
最大值注解调整
parent
070e0679
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
274 additions
and
13 deletions
+274
-13
TEmpBadRecord.java
...ifu/cloud/plus/v1/yifu/archives/entity/TEmpBadRecord.java
+1
-1
EmpBadRecordVo.java
...m/yifu/cloud/plus/v1/yifu/archives/vo/EmpBadRecordVo.java
+2
-2
pom.xml
yifu-common/yifu-common-core/pom.xml
+6
-0
ExcelAttribute.java
...oud.plus.v1/yifu/common/core/constant/ExcelAttribute.java
+1
-1
ExcelUtil.java
...m/yifu.cloud.plus.v1/yifu/common/core/util/ExcelUtil.java
+8
-9
BigDecimalUtils.java
.../cloud/plus/v1/yifu/common/core/util/BigDecimalUtils.java
+256
-0
No files found.
yifu-archives/yifu-archives-api/src/main/java/com/yifu/cloud/plus/v1/yifu/archives/entity/TEmpBadRecord.java
View file @
eed3ae1a
...
...
@@ -113,7 +113,7 @@ public class TEmpBadRecord extends BaseEntity {
/**
* 费用损失 (费用损失与其他费用损失其一必填)
*/
@ExcelAttribute
(
name
=
"费用损失"
,
isFloat
=
true
,
max
=
(
float
)
999999999.99
)
@ExcelAttribute
(
name
=
"费用损失"
,
isFloat
=
true
,
max
=
"999999999.99"
)
@Schema
(
description
=
"费用损失 (费用损失与其他费用损失其一必填)"
)
@DecimalMax
(
value
=
"999999999.99"
,
message
=
"费用损失不可大于999999999.99"
)
@ExcelProperty
(
"费用损失"
)
...
...
yifu-archives/yifu-archives-api/src/main/java/com/yifu/cloud/plus/v1/yifu/archives/vo/EmpBadRecordVo.java
View file @
eed3ae1a
...
...
@@ -68,7 +68,7 @@ public class EmpBadRecordVo extends RowIndex implements Serializable {
/**
* 费用损失 (费用损失与其他费用损失其一必填)
*/
@ExcelAttribute
(
name
=
"费用损失"
,
isFloat
=
true
,
max
=
(
float
)
999999999.99
)
@ExcelAttribute
(
name
=
"费用损失"
,
isFloat
=
true
,
max
=
"999999999.99"
)
@Schema
(
description
=
"费用损失 (费用损失与其他费用损失其一必填)"
)
@ExcelProperty
(
"费用损失"
)
private
BigDecimal
loseFee
;
...
...
@@ -76,7 +76,7 @@ public class EmpBadRecordVo extends RowIndex implements Serializable {
/**
* 其他损失 (费用损失与其他费用损失其一必填)
*/
@ExcelAttribute
(
name
=
"其他损失"
,
isFloat
=
true
,
max
=
(
float
)
999999999.99
)
@ExcelAttribute
(
name
=
"其他损失"
,
isFloat
=
true
,
max
=
"999999999.99"
)
@Schema
(
description
=
"其他损失 (费用损失与其他费用损失其一必填)"
)
@ExcelProperty
(
"其他损失"
)
private
BigDecimal
loseFeeOther
;
...
...
yifu-common/yifu-common-core/pom.xml
View file @
eed3ae1a
...
...
@@ -88,5 +88,11 @@
<artifactId>
equator
</artifactId>
<version>
1.0.4
</version>
</dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
30.1-jre
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
</project>
yifu-common/yifu-common-core/src/main/java/com/yifu.cloud.plus.v1/yifu/common/core/constant/ExcelAttribute.java
View file @
eed3ae1a
...
...
@@ -40,7 +40,7 @@ public @interface ExcelAttribute {
* 最大值
* @return
*/
public
abstract
float
max
()
default
0
;
public
abstract
String
max
()
default
"0"
;
/**
* 最小值
...
...
yifu-common/yifu-common-core/src/main/java/com/yifu.cloud.plus.v1/yifu/common/core/util/ExcelUtil.java
View file @
eed3ae1a
...
...
@@ -658,16 +658,15 @@ public class ExcelUtil <T> implements Serializable {
return
errorInfo
(
attr
,
"_超出最大长度"
,
i
);
}
//最大值校验
if
(
attr
.
max
()
>
0
)
{
if
(
Common
.
isNotNull
(
attr
.
max
())
&&
!
CommonConstants
.
ZERO_STRING
.
equals
(
attr
.
max
())
)
{
if
(
Common
.
isNumber
(
c
))
{
if
(
attr
.
isDouble
()){
if
(
Double
.
doubleToLongBits
(
Double
.
valueOf
(
c
).
doubleValue
())
>
Double
.
doubleToLongBits
(
attr
.
max
()))
{
return
errorInfo
(
attr
,
"_超出最大值"
,
i
);
}
}
else
if
(
attr
.
isFloat
()
&&
Float
.
compare
(
Float
.
valueOf
(
c
),
attr
.
max
())
>
0
){
if
(
attr
.
isDouble
()
&&
Double
.
doubleToLongBits
(
Double
.
valueOf
(
c
).
doubleValue
())
>
Double
.
valueOf
(
attr
.
max
()).
doubleValue
()){
return
errorInfo
(
attr
,
"_超出最大值"
,
i
);
}
else
if
(
attr
.
isFloat
()
&&
BigDecimalUtils
.
strToBigdecimal
(
c
).
compareTo
(
BigDecimalUtils
.
strToBigdecimal
(
attr
.
max
()))
>
0
){
return
errorInfo
(
attr
,
"_超出最大值"
,
i
);
}
else
{
if
(
Float
.
valueOf
(
c
).
intValue
()
>
attr
.
max
())
{
if
(
Float
.
valueOf
(
c
).
intValue
()
>
Float
.
valueOf
(
attr
.
max
()).
intValue
())
{
return
errorInfo
(
attr
,
"_超出最大值"
,
i
);
}
}
...
...
@@ -679,8 +678,8 @@ public class ExcelUtil <T> implements Serializable {
if
(
attr
.
min
()
>
0
)
{
if
(
Common
.
isNumber
(
c
))
{
if
(
attr
.
isFloat
()){
if
(
Float
.
valueOf
(
c
).
compareTo
(
attr
.
m
ax
())
>
CommonConstants
.
ZERO_INT
)
{
return
errorInfo
(
attr
,
"_
超出最大
值"
,
i
);
if
(
Float
.
valueOf
(
c
).
compareTo
(
attr
.
m
in
())
<
CommonConstants
.
ZERO_INT
)
{
return
errorInfo
(
attr
,
"_
小于最小
值"
,
i
);
}
}
else
{
if
(
Float
.
valueOf
(
c
).
intValue
()
<
attr
.
min
())
{
...
...
yifu-common/yifu-common-core/src/main/java/com/yifu/cloud/plus/v1/yifu/common/core/util/BigDecimalUtils.java
0 → 100644
View file @
eed3ae1a
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
core
.
util
;
import
com.google.common.base.Optional
;
import
java.math.BigDecimal
;
/**
* BigDecimal 工具类
* @Author fxj
* @Date 2019-09-25
* @Description 提供精确的浮点数运算(包括加、减、乘、除、四舍五入)工具类
**/
public
class
BigDecimalUtils
{
/**
* BigDecimal的加法运算封装
* @author : shijing
* 2017年3月23日下午4:53:21
* @param b1
* @param bn
* @return
*/
public
static
BigDecimal
safeAdd
(
BigDecimal
b1
,
BigDecimal
...
bn
)
{
if
(
null
==
b1
)
{
b1
=
BigDecimal
.
ZERO
;
}
if
(
null
!=
bn
)
{
for
(
BigDecimal
b
:
bn
)
{
b1
=
b1
.
add
(
null
==
b
?
BigDecimal
.
ZERO
:
b
);
}
}
return
b1
;
}
/**
* Integer加法运算的封装
* @author : shijing
* 2017年3月23日下午4:54:08
* @param b1 第一个数
* @param bn 需要加的加法数组
* @注 : Optional 是属于com.google.common.base.Optional<T> 下面的class
* @return
*/
public
static
Integer
safeAdd
(
Integer
b1
,
Integer
...
bn
)
{
if
(
null
==
b1
)
{
b1
=
0
;
}
Integer
r
=
b1
;
if
(
null
!=
bn
)
{
for
(
Integer
b
:
bn
)
{
r
+=
Optional
.
fromNullable
(
b
).
or
(
0
);
}
}
return
r
>
0
?
r
:
0
;
}
/**
* 计算金额方法
* @author : shijing
* 2017年3月23日下午4:53:00
* @param b1
* @param bn
* @return
*/
public
static
BigDecimal
safeSubtract
(
BigDecimal
b1
,
BigDecimal
...
bn
)
{
return
safeSubtract
(
true
,
b1
,
bn
);
}
/**
* BigDecimal的安全减法运算
* @author : shijing
* 2017年3月23日下午4:50:45
* @param isZero 减法结果为负数时是否返回0,true是返回0(金额计算时使用),false是返回负数结果
* @param b1 被减数
* @param bn 需要减的减数数组
* @return
*/
public
static
BigDecimal
safeSubtract
(
Boolean
isZero
,
BigDecimal
b1
,
BigDecimal
...
bn
)
{
if
(
null
==
b1
)
{
b1
=
BigDecimal
.
ZERO
;
}
BigDecimal
r
=
b1
;
if
(
null
!=
bn
)
{
for
(
BigDecimal
b
:
bn
)
{
r
=
r
.
subtract
((
null
==
b
?
BigDecimal
.
ZERO
:
b
));
}
}
return
isZero
?
(
r
.
compareTo
(
BigDecimal
.
ZERO
)
==
-
1
?
BigDecimal
.
ZERO
:
r
)
:
r
;
}
/**
* 整型的减法运算,小于0时返回0
* @author : shijing
* 2017年3月23日下午4:58:16
* @param b1
* @param bn
* @return
*/
public
static
Integer
safeSubtract
(
Integer
b1
,
Integer
...
bn
)
{
if
(
null
==
b1
)
{
b1
=
0
;
}
Integer
r
=
b1
;
if
(
null
!=
bn
)
{
for
(
Integer
b
:
bn
)
{
r
-=
Optional
.
fromNullable
(
b
).
or
(
0
);
}
}
return
null
!=
r
&&
r
>
0
?
r
:
0
;
}
/**
* 金额除法计算,返回2位小数(具体的返回多少位大家自己看着改吧)
* @author : shijing
* 2017年3月23日下午5:02:17
* @param b1
* @param b2
* @return
*/
public
static
<
T
extends
Number
>
BigDecimal
safeDivide
(
T
b1
,
T
b2
){
return
safeDivide
(
b1
,
b2
,
BigDecimal
.
ZERO
);
}
/**
* @description:
* @param b1
* @param b2
* @return: java.math.BigDecimal
* @author: wangweiguo
* @date: 2021/8/5
*/
public
static
<
T
extends
Number
>
BigDecimal
safeDivide
(
T
b1
,
T
b2
,
int
scale
){
return
safeDivide
(
b1
,
b2
,
BigDecimal
.
ZERO
,
scale
);
}
/**
* BigDecimal的除法运算封装,如果除数或者被除数为0,返回默认值
* 默认返回小数位后2位,用于金额计算
* @author : shijing
* 2017年3月23日下午4:59:29
* @param b1
* @param b2
* @param defaultValue
* @return
*/
public
static
<
T
extends
Number
>
BigDecimal
safeDivide
(
T
b1
,
T
b2
,
BigDecimal
defaultValue
)
{
if
(
null
==
b1
||
null
==
b2
)
{
return
defaultValue
;
}
try
{
return
BigDecimal
.
valueOf
(
b1
.
doubleValue
()).
divide
(
BigDecimal
.
valueOf
(
b2
.
doubleValue
()),
2
,
BigDecimal
.
ROUND_HALF_UP
);
}
catch
(
Exception
e
)
{
return
defaultValue
;
}
}
/**
* @description:
* @param b1
* @param b2
* @param defaultValue
* @param scale
* @return: java.math.BigDecimal
* @author: wangweiguo
* @date: 2021/8/5
*/
public
static
<
T
extends
Number
>
BigDecimal
safeDivide
(
T
b1
,
T
b2
,
BigDecimal
defaultValue
,
int
scale
)
{
if
(
null
==
b1
||
null
==
b2
)
{
return
defaultValue
;
}
try
{
return
BigDecimal
.
valueOf
(
b1
.
doubleValue
()).
divide
(
BigDecimal
.
valueOf
(
b2
.
doubleValue
()),
scale
,
BigDecimal
.
ROUND_HALF_UP
);
}
catch
(
Exception
e
)
{
return
defaultValue
;
}
}
/**
* BigDecimal的乘法运算封装
* @author : shijing
* 2017年3月23日下午5:01:57
* @param b1
* @param b2
* @return
*/
public
static
<
T
extends
Number
>
BigDecimal
safeMultiply
(
T
b1
,
T
b2
)
{
if
(
null
==
b1
||
null
==
b2
)
{
return
BigDecimal
.
ZERO
;
}
return
BigDecimal
.
valueOf
(
b1
.
doubleValue
()).
multiply
(
BigDecimal
.
valueOf
(
b2
.
doubleValue
())).
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
);
}
public
static
<
T
extends
Number
>
BigDecimal
safeMultiply
(
T
b1
,
T
b2
,
T
b3
)
{
if
(
null
==
b1
||
null
==
b2
||
null
==
b3
)
{
return
BigDecimal
.
ZERO
;
}
return
BigDecimal
.
valueOf
(
b1
.
doubleValue
()).
multiply
(
BigDecimal
.
valueOf
(
b2
.
doubleValue
())).
multiply
(
BigDecimal
.
valueOf
(
b3
.
doubleValue
())).
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
);
}
/**
* BigDecimal的乘法运算封装
* @author : shijing
* 2017年3月23日下午5:01:57
* @param b1
* @param b2
* @return
*/
public
static
<
T
extends
Number
>
BigDecimal
safeMultiply
(
T
b1
,
T
b2
,
int
scale
)
{
if
(
null
==
b1
||
null
==
b2
)
{
return
BigDecimal
.
ZERO
;
}
return
BigDecimal
.
valueOf
(
b1
.
doubleValue
()).
multiply
(
BigDecimal
.
valueOf
(
b2
.
doubleValue
())).
setScale
(
scale
,
BigDecimal
.
ROUND_HALF_UP
);
}
public
static
<
T
extends
Number
>
BigDecimal
safeMultiply
(
T
b1
,
T
b2
,
T
b3
,
int
scale
)
{
if
(
null
==
b1
||
null
==
b2
||
null
==
b3
)
{
return
BigDecimal
.
ZERO
;
}
return
BigDecimal
.
valueOf
(
b1
.
doubleValue
()).
multiply
(
BigDecimal
.
valueOf
(
b2
.
doubleValue
())).
multiply
(
BigDecimal
.
valueOf
(
b3
.
doubleValue
())).
setScale
(
scale
,
BigDecimal
.
ROUND_HALF_UP
);
}
public
static
<
T
extends
Number
>
BigDecimal
safeMultiply
(
T
b1
,
T
b2
,
T
b3
,
T
b4
,
int
scale
)
{
if
(
null
==
b1
||
null
==
b2
||
null
==
b3
)
{
return
BigDecimal
.
ZERO
;
}
return
BigDecimal
.
valueOf
(
b1
.
doubleValue
()).
multiply
(
BigDecimal
.
valueOf
(
b2
.
doubleValue
())).
multiply
(
BigDecimal
.
valueOf
(
b3
.
doubleValue
())).
multiply
(
BigDecimal
.
valueOf
(
b4
.
doubleValue
())).
setScale
(
scale
,
BigDecimal
.
ROUND_HALF_UP
);
}
/**
* null 默认 为 0
* @Author fxj
* @Date 2019-09-25
* @param bigDecimal
* @return
**/
public
static
BigDecimal
isNullToZero
(
BigDecimal
bigDecimal
){
if
(
null
==
bigDecimal
){
return
BigDecimal
.
ZERO
;
}
return
bigDecimal
;
}
/**
* 对象转为BigDecimal 数据 并四舍五入保留两位小数
* @Author fxj
* @Date 2019-10-14
* @param b1
* @return
**/
public
static
BigDecimal
objectToBigDecimal
(
Double
b1
)
{
if
(
null
==
b1
)
{
return
BigDecimal
.
ZERO
;
}
return
BigDecimal
.
valueOf
(
b1
.
doubleValue
()).
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
);
}
public
static
BigDecimal
strToBigdecimal
(
String
c
)
{
if
(
Common
.
isEmpty
(
c
)){
return
BigDecimal
.
ZERO
;
}
return
new
BigDecimal
(
c
);
}
}
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