Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
manager
Project
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
reyun
manager
Commits
5b8e2f16
Commit
5b8e2f16
authored
Jul 03, 2020
by
kangxiaoshan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分摊调整金优化
parent
2182d277
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
201 additions
and
9 deletions
+201
-9
ShareIncomeServiceImpl.java
...main/java/common/service/impl/ShareIncomeServiceImpl.java
+201
-9
No files found.
src/main/java/common/service/impl/ShareIncomeServiceImpl.java
View file @
5b8e2f16
package
common
.
service
.
impl
;
import
com.amazonaws.services.dynamodbv2.xspec.B
;
import
common.model.*
;
import
common.repository.AuthRepository
;
import
common.repository.ContractBodyRepository
;
...
...
@@ -95,13 +94,211 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
for
(
Contract
contract
:
contracts
)
{
this
.
caculateShareIncome
(
contract
,
start
,
end
);
// this.caculateShareIncome(contract, start, end);
this
.
shareIncome4Contract
(
contract
,
start
,
end
);
contract
.
setMyBodyName
(
bodiesNameMap
.
get
(
contract
.
getMyBodyCode
()));
}
return
contracts
;
}
public
void
shareIncome4Contract
(
Contract
contract
,
DateTime
start
,
DateTime
end
)
{
DateTime
[]
selected
=
new
DateTime
[]{
start
,
end
};
DateTime
[]
contractPart
=
new
DateTime
[]{
new
DateTime
(
contract
.
getStartDate
()),
new
DateTime
(
contract
.
getEndDate
())};
//合同开始结束 时间
DateTime
[]
usePart
=
new
DateTime
[]{
selected
[
0
].
compareTo
(
contractPart
[
0
])
<=
0
?
contractPart
[
0
]
:
selected
[
0
],
selected
[
1
].
compareTo
(
contractPart
[
1
])
>=
0
?
contractPart
[
1
]
:
selected
[
1
]
};
contract
.
setIntervalUseDays
(
getDayRange
(
contractPart
[
0
],
usePart
[
1
])
+
1
);
Long
excludTax
=
contract
.
getMoney
()
*
94
;
//不含税收入*100
contract
.
setIncomeExcludingTax
(
excludTax
);
int
contractAllDay
=
getDayRange
(
contractPart
[
0
],
contractPart
[
1
])
+
1
;
//合同总天数
//处理精度
Long
dayShareIncome
=
new
BigDecimal
(
contract
.
getMoney
()
*
94
*
1.0
/
contractAllDay
)
.
setScale
(
0
,
BigDecimal
.
ROUND_HALF_UP
).
longValue
();
//每日分摊收入
//作废合同处理
Contract
cancleContract
=
this
.
cancledShare
(
contract
,
contractAllDay
,
dayShareIncome
,
contractPart
,
usePart
,
selected
);
if
(
cancleContract
!=
null
)
{
return
;
}
//中止合同处理
Contract
suspendContract
=
this
.
suspendShare
(
contract
,
contractAllDay
,
dayShareIncome
,
contractPart
,
usePart
,
selected
);
if
(
suspendContract
!=
null
)
{
return
;
}
//晚录合同处理
DateTime
create
=
new
DateTime
(
new
DateTime
(
contract
.
getCreateTime
()).
toString
(
"yyyy-MM-dd"
));
//录入时间点
DateTime
[]
creatPoints
=
new
DateTime
[]{
create
,
//录入日
create
.
dayOfMonth
().
withMinimumValue
()
//录入月1日
};
this
.
afterContract
(
contract
,
contractAllDay
,
dayShareIncome
,
contractPart
,
usePart
,
selected
,
creatPoints
);
}
private
void
afterContract
(
Contract
contract
,
int
contractAllDay
,
Long
dayShareIncome
,
DateTime
[]
contractPart
,
DateTime
[]
usePart
,
DateTime
[]
selected
,
DateTime
[]
creatPoints
)
{
int
aferDays
=
contractPart
[
0
].
monthOfYear
().
get
()
==
12
?
29
:
9
;
int
betweenMonth
=
creatPoints
[
0
].
getMonthOfYear
()
-
contractPart
[
0
].
getMonthOfYear
();
//时间范围内用于计算分摊金额的天数
int
daysIncom
=
getDayRange
(
usePart
[
0
],
usePart
[
1
])
+
1
;
//区间分摊总收入
contract
.
setIntervaIncomeShare
(
dayShareIncome
*
daysIncom
);
Long
adjustmentFund
=
0L
;
//调整金
if
(!
contractPart
[
0
].
dayOfMonth
().
withMaximumValue
().
plusDays
(
aferDays
).
isBefore
(
creatPoints
[
0
])
||
betweenMonth
<
1
)
{
//非合同晚录
contract
.
setAdjustmentFund
(
0L
);
contract
.
setIncomeShareAll
(
contract
.
getIntervaIncomeShare
());
}
else
if
(
selected
[
1
].
isBefore
(
creatPoints
[
1
].
plusDays
(
betweenMonth
>
1
?
-
1
:
0
)))
{
//录入月1号之前 调整金为 0
contract
.
setIntervaIncomeShare
(
0L
);
contract
.
setIncomeShareAll
(
contract
.
getIntervaIncomeShare
());
}
else
{
//合同晚录
//所选时间范围内的分摊收入(录入月1号开始计算)
DateTime
useStart
=
creatPoints
[
1
].
compareTo
(
selected
[
0
])
>=
0
?
creatPoints
[
1
]
:
selected
[
0
];
daysIncom
=
getDayRange
(
useStart
,
usePart
[
1
])
+
1
;
contract
.
setIntervaIncomeShare
(
dayShareIncome
*
daysIncom
);
//时间范围内分摊金
adjustmentFund
=
new
BigDecimal
(((
getDayRange
(
contractPart
[
0
],
creatPoints
[
1
].
plusDays
(-
1
))
+
1
)
*
contract
.
getIncomeExcludingTax
()
*
1.0
/
contractAllDay
))
.
setScale
(
0
,
BigDecimal
.
ROUND_HALF_UP
).
longValue
();
if
(
checkTwoTime
(
selected
[
0
],
creatPoints
[
1
])
&&
checkTwoTime
(
creatPoints
[
1
],
selected
[
1
]))
{
//所选时间范围包含 录入月 1 号 显示统计的调整金
contract
.
setAdjustmentFund
(
adjustmentFund
);
}
else
{
contract
.
setAdjustmentFund
(
0L
);
}
}
if
(
checkTwoTime
(
contractPart
[
1
],
selected
[
1
]))
{
//最后一日分摊金计算处理
Long
lastDay
=
contract
.
getIncomeExcludingTax
()
-
adjustmentFund
-
dayShareIncome
*
getDayRange
(
creatPoints
[
1
],
contractPart
[
1
]);
//最后一日 或 包含最后一日 时
contract
.
setIntervaIncomeShare
(
contract
.
getIntervaIncomeShare
()
-
dayShareIncome
+
lastDay
);
}
contract
.
setIncomeShareAll
(
contract
.
getIntervaIncomeShare
()
+
contract
.
getAdjustmentFund
());
}
private
Contract
suspendShare
(
Contract
contract
,
int
contractAllDay
,
Long
dayShareIncome
,
DateTime
[]
contractPart
,
DateTime
[]
usePart
,
DateTime
[]
selected
)
{
if
(!
ContractStatusEnum
.
SUSPEND
.
getKey
().
equals
(
contract
.
getStatus
()))
{
return
null
;
}
ContractChange
contractChange
=
contractChangeRepository
.
findByContentCode
(
ContractStatusEnum
.
SUSPEND
.
getValue
(),
contract
.
getContractCode
());
if
(
contractChange
==
null
)
{
contract
.
setAdjustmentFund
(
0L
);
contract
.
setIntervaIncomeShare
(
0L
);
contract
.
setIncomeShareAll
(
0L
);
return
contract
;
}
// 合同终止日 或 作废日
DateTime
cancelDate
=
new
DateTime
(
contractChange
.
getDs
());
//中止操作入库时间
DateTime
suspendDate
=
new
DateTime
(
new
DateTime
(
contractChange
.
getCreateTime
()).
toString
(
"yyyy-MM-dd"
));
Long
adjustmentFund
=
0L
;
if
(
checkTwoTime
(
suspendDate
,
cancelDate
))
{
adjustmentFund
=
0L
;
}
else
{
adjustmentFund
=
new
BigDecimal
((
getDayRange
(
cancelDate
,
suspendDate
)
+
1
)
*
contract
.
getIncomeExcludingTax
()
*
1.0
/
contractAllDay
)
.
setScale
(
0
,
BigDecimal
.
ROUND_HALF_UP
).
longValue
()
*
-
1
;
}
DateTime
usedEnd
=
usePart
[
1
].
compareTo
(
cancelDate
)
<=
0
?
usePart
[
1
]
:
cancelDate
;
int
daysIncom
=
Days
.
daysBetween
(
usePart
[
0
],
usedEnd
).
getDays
()
+
1
;
daysIncom
=
daysIncom
<
0
?
0
:
daysIncom
;
//区间分摊总收入
contract
.
setIntervaIncomeShare
(
dayShareIncome
*
daysIncom
);
if
(
checkTwoTime
(
selected
[
0
],
cancelDate
)
&&
checkTwoTime
(
cancelDate
,
selected
[
1
]))
{
contract
.
setAdjustmentFund
(
adjustmentFund
);
}
else
{
contract
.
setAdjustmentFund
(
0L
);
}
contract
.
setIncomeShareAll
(
contract
.
getIntervaIncomeShare
()
+
contract
.
getAdjustmentFund
());
return
contract
;
}
private
Contract
cancledShare
(
Contract
contract
,
int
contractAllDay
,
Long
dayShareIncome
,
DateTime
[]
contractPart
,
DateTime
[]
usePart
,
DateTime
[]
selected
)
{
if
(!
ContractStatusEnum
.
CANCEL
.
getKey
().
equals
(
contract
.
getStatus
()))
{
return
null
;
}
ContractChange
contractChange
=
contractChangeRepository
.
findByContentCode
(
ContractStatusEnum
.
CANCEL
.
getValue
(),
contract
.
getContractCode
());
if
(
contractChange
==
null
)
{
contract
.
setAdjustmentFund
(
0L
);
contract
.
setIntervaIncomeShare
(
0L
);
contract
.
setIncomeShareAll
(
0L
);
return
contract
;
}
// 合同终止日 或 作废日
DateTime
cancelDate
=
new
DateTime
(
contractChange
.
getDs
());
Long
adjustmentFund
=
new
BigDecimal
((
Days
.
daysBetween
(
contractPart
[
0
],
cancelDate
).
getDays
()
+
1
)
*
contract
.
getIncomeExcludingTax
()
*
1.0
/
contractAllDay
)
.
setScale
(
0
,
BigDecimal
.
ROUND_HALF_UP
).
longValue
()
*
-
1
;
DateTime
usedEnd
=
usePart
[
1
].
compareTo
(
cancelDate
)
<=
0
?
usePart
[
1
]
:
cancelDate
;
int
daysIncom
=
Days
.
daysBetween
(
usePart
[
0
],
usedEnd
).
getDays
()
+
1
;
daysIncom
=
daysIncom
<
0
?
0
:
daysIncom
;
//区间分摊总收入
contract
.
setIntervaIncomeShare
(
dayShareIncome
*
daysIncom
);
boolean
fullRange
=
getDayRange
(
selected
[
0
],
selected
[
1
])
>=
Days
.
daysBetween
(
contractPart
[
0
],
cancelDate
).
getDays
()
?
true
:
false
;
if
(
fullRange
)
{
contract
.
setAdjustmentFund
(-
1
*
contract
.
getIntervaIncomeShare
());
}
else
if
(
checkTwoTime
(
selected
[
0
],
cancelDate
)
&&
checkTwoTime
(
cancelDate
,
selected
[
1
]))
{
contract
.
setAdjustmentFund
(
adjustmentFund
);
}
else
{
contract
.
setAdjustmentFund
(
0L
);
}
contract
.
setIncomeShareAll
(
contract
.
getIntervaIncomeShare
()
+
contract
.
getAdjustmentFund
());
return
contract
;
}
private
int
getDayRange
(
DateTime
range1
,
DateTime
range2
)
{
return
Days
.
daysBetween
(
range1
,
range2
).
getDays
();
}
public
boolean
checkTwoTime
(
DateTime
dateTime1
,
DateTime
dateTime2
)
{
return
dateTime1
.
isBefore
(
dateTime2
)
||
dateTime1
.
isEqual
(
dateTime2
);
}
@Deprecated
private
void
caculateShareIncome
(
Contract
contract
,
DateTime
start
,
DateTime
end
)
{
DateTime
create
=
new
DateTime
(
new
DateTime
(
contract
.
getCreateTime
()).
toString
(
"yyyy-MM-dd"
));
...
...
@@ -119,7 +316,6 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
contract
.
setIntervalUseDays
(
Days
.
daysBetween
(
contractStart
,
usedEnd
).
getDays
()
+
1
);
//区间使用天数
int
allDay
=
Days
.
daysBetween
(
contractStart
,
contractEnd
).
getDays
()
+
1
;
Long
excludTax
=
contract
.
getMoney
()
*
94
;
//不含税收入*100 :contract.getMoney()*100 - contract.getMoney()*0.06*100 = contract.getMoney()*94
contract
.
setIncomeExcludingTax
(
excludTax
);
...
...
@@ -221,7 +417,7 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
//录入时间在次月10以后 或次月30日以后
if
(
betweenMonth
==
1
)
{
//相差一月
nextMonth
=
contractStart
.
dayOfMonth
().
withMaximumValue
().
plusDays
(
1
);
//合同开始次月1号 与调整金对应
nextMonth
=
contractStart
.
dayOfMonth
().
withMaximumValue
().
plusDays
(
1
);
//合同开始次月1号 与调整金对应
= 合同录入月1号
}
else
if
(
betweenMonth
>
1
)
{
//相差多月
nextMonth
=
creatMonth
;
//合同录入月1号 与调整金对应
...
...
@@ -302,17 +498,13 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
//包含最后一日 时
contract
.
setIntervaIncomeShare
(
contract
.
getIntervaIncomeShare
()
-
shareIncomDay
+
lastDay
);
contract
.
setIncomeShareAll
(
contract
.
getIntervaIncomeShare
());
}
else
{
}
else
{
contract
.
setIncomeShareAll
(
contract
.
getIntervaIncomeShare
());
}
}
public
boolean
checkTwoTime
(
DateTime
dateTime1
,
DateTime
dateTime2
)
{
return
dateTime1
.
isBefore
(
dateTime2
)
||
dateTime1
.
isEqual
(
dateTime2
);
}
public
static
void
main
(
String
[]
args
)
{
DateTime
contractStart
=
new
DateTime
(
"2020-05-15"
);
DateTime
create
=
new
DateTime
(
"2020-06-15"
);
...
...
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