计提报表本年本月收益优化
This commit is contained in:
parent
68dd80d891
commit
a4ab06b57d
|
|
@ -22,6 +22,7 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi
|
||||||
"shjh_depositstartdate", "shjh_depositstopdate", "shjh_term", "shjh_interestrate",
|
"shjh_depositstartdate", "shjh_depositstopdate", "shjh_term", "shjh_interestrate",
|
||||||
"shjh_frequency", "shjh_amount", "shjh_accrualdate", "shjh_accrualdays",
|
"shjh_frequency", "shjh_amount", "shjh_accrualdate", "shjh_accrualdays",
|
||||||
"shjh_accrualinterest", "shjh_monthearnings", "shjh_yearearnings", "shjh_depositmodel", "shjh_basis"};
|
"shjh_accrualinterest", "shjh_monthearnings", "shjh_yearearnings", "shjh_depositmodel", "shjh_basis"};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processRowData(String gridPK, DynamicObjectCollection rowData, ReportQueryParam queryParam) {
|
public void processRowData(String gridPK, DynamicObjectCollection rowData, ReportQueryParam queryParam) {
|
||||||
super.processRowData(gridPK, rowData, queryParam);
|
super.processRowData(gridPK, rowData, queryParam);
|
||||||
|
|
@ -73,10 +74,10 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi
|
||||||
// 检查计提日期是否在有效区间(存款起期 <= 计提日期 <= 存款止期)
|
// 检查计提日期是否在有效区间(存款起期 <= 计提日期 <= 存款止期)
|
||||||
boolean isValidPeriod = !filterDate.before(depositStartDate) &&
|
boolean isValidPeriod = !filterDate.before(depositStartDate) &&
|
||||||
!filterDate.after(depositEndDate);
|
!filterDate.after(depositEndDate);
|
||||||
|
|
||||||
if (isValidPeriod) {
|
if (isValidPeriod) {
|
||||||
//计提天数
|
//计提天数
|
||||||
dayDiff = this.calculationDays(row, filterDate, depositStartDate);
|
dayDiff = this.calculationDays(row, filterDate, depositStartDate);
|
||||||
|
|
||||||
/* 计提利息 = (金额 × 天利率 × 计提天数) */
|
/* 计提利息 = (金额 × 天利率 × 计提天数) */
|
||||||
accruedInterest = amount.multiply(rate)
|
accruedInterest = amount.multiply(rate)
|
||||||
.multiply(new BigDecimal(dayDiff))
|
.multiply(new BigDecimal(dayDiff))
|
||||||
|
|
@ -84,29 +85,10 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi
|
||||||
.setScale(2, RoundingMode.HALF_UP);
|
.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
|
||||||
/* 计算本月收益 = 金额 × 天利率 × 当月有效天数 */
|
/* 计算本月收益 = 金额 × 天利率 × 当月有效天数 */
|
||||||
Calendar cal = Calendar.getInstance();
|
monthlyIncome = this.calculationMonthAmount(filterDate, depositStartDate, amount, rate, basisDay);
|
||||||
cal.setTime(filterDate);
|
|
||||||
|
|
||||||
// 当月第一天
|
|
||||||
cal.set(Calendar.DAY_OF_MONTH, 1);
|
|
||||||
Date monthStart = cal.getTime();
|
|
||||||
|
|
||||||
// 当月有效天数(存款起期与当月首日的较晚者)
|
|
||||||
Date validMonthStart = depositStartDate.after(monthStart) ?
|
|
||||||
depositStartDate : monthStart;
|
|
||||||
|
|
||||||
long monthDays = TimeUnit.DAYS.convert(
|
|
||||||
filterDate.getTime() - validMonthStart.getTime(),
|
|
||||||
TimeUnit.MILLISECONDS);
|
|
||||||
|
|
||||||
monthlyIncome = amount.multiply(rate)
|
|
||||||
.multiply(new BigDecimal(monthDays))
|
|
||||||
.divide(basisDay,10, RoundingMode.HALF_UP)
|
|
||||||
.setScale(2, RoundingMode.HALF_UP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 计算本年累计收益 = 金额 × 利率 × 当年有效天数 */
|
/* 计算本年累计收益 = 金额 × 利率 × 当年有效天数 */
|
||||||
//Date currentDate = new Date(); // 当前日期
|
|
||||||
Date validYearEnd = null; // 有效结束日期
|
Date validYearEnd = null; // 有效结束日期
|
||||||
|
|
||||||
if (filterDate.before(depositStartDate)) {
|
if (filterDate.before(depositStartDate)) {
|
||||||
|
|
@ -115,11 +97,11 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi
|
||||||
} else if (filterDate.after(depositEndDate)) {
|
} else if (filterDate.after(depositEndDate)) {
|
||||||
// 当日期晚于存款到期日,计算到 depositEndDate 的累计收益
|
// 当日期晚于存款到期日,计算到 depositEndDate 的累计收益
|
||||||
validYearEnd = depositEndDate;
|
validYearEnd = depositEndDate;
|
||||||
yearlyIncome = this.calculationYearAmount(validYearEnd, depositStartDate, amount, rate, basisDay);
|
yearlyIncome = this.calculationYearAmount(filterDate,validYearEnd, depositStartDate, amount, rate, basisDay);
|
||||||
} else {
|
} else {
|
||||||
// 当前日期在有效期内,计算到当前日期的累计收益
|
// 当前日期在有效期内,计算到当前日期的累计收益
|
||||||
validYearEnd = filterDate;
|
validYearEnd = filterDate;
|
||||||
yearlyIncome = this.calculationYearAmount(validYearEnd, depositStartDate, amount, rate, basisDay);
|
yearlyIncome = this.calculationYearAmount(filterDate,validYearEnd, depositStartDate, amount, rate, basisDay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,6 +137,7 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对小计行处理
|
* 对小计行处理
|
||||||
|
*
|
||||||
* @param rowData
|
* @param rowData
|
||||||
*/
|
*/
|
||||||
private void changeRowData(DynamicObjectCollection rowData) {
|
private void changeRowData(DynamicObjectCollection rowData) {
|
||||||
|
|
@ -204,6 +187,7 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 尾行固定添加合计行
|
* 尾行固定添加合计行
|
||||||
|
*
|
||||||
* @param rowData
|
* @param rowData
|
||||||
*/
|
*/
|
||||||
private void addTotalRowData(DynamicObjectCollection rowData) {
|
private void addTotalRowData(DynamicObjectCollection rowData) {
|
||||||
|
|
@ -236,6 +220,7 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算计提天数
|
* 计算计提天数
|
||||||
|
*
|
||||||
* @param row
|
* @param row
|
||||||
* @param filterDate 计提日期
|
* @param filterDate 计提日期
|
||||||
* @param depositStartDate 启始日期
|
* @param depositStartDate 启始日期
|
||||||
|
|
@ -271,7 +256,61 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi
|
||||||
return dayDiff;
|
return dayDiff;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BigDecimal calculationYearAmount(Date validYearEnd,Date depositStartDate, BigDecimal amount,BigDecimal rate,BigDecimal basisDay){
|
/**
|
||||||
|
* 计算本月累计收益
|
||||||
|
* @param filterDate 计提日期
|
||||||
|
* @param depositStartDate 起始日期
|
||||||
|
* @param amount 金额
|
||||||
|
* @param rate 利率
|
||||||
|
* @param basisDay 计息基准
|
||||||
|
* @return 本年累计收益
|
||||||
|
*/
|
||||||
|
private BigDecimal calculationMonthAmount(Date filterDate, Date depositStartDate, BigDecimal amount, BigDecimal rate, BigDecimal basisDay) {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(filterDate);
|
||||||
|
|
||||||
|
// 当月第一天
|
||||||
|
cal.set(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
Date monthStart = cal.getTime();
|
||||||
|
|
||||||
|
// 当月有效天数(存款起期与当月首日的较晚者)
|
||||||
|
Date validMonthStart = depositStartDate.after(monthStart) ? depositStartDate : monthStart;
|
||||||
|
|
||||||
|
long monthDays = TimeUnit.DAYS.convert(
|
||||||
|
filterDate.getTime() - validMonthStart.getTime(),
|
||||||
|
TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
|
// 检查filterDate和depositStartDate是否在同年同月
|
||||||
|
Calendar filterCal = Calendar.getInstance();
|
||||||
|
filterCal.setTime(filterDate);
|
||||||
|
Calendar depositCal = Calendar.getInstance();
|
||||||
|
depositCal.setTime(depositStartDate);
|
||||||
|
|
||||||
|
boolean sameYearMonth = filterCal.get(Calendar.YEAR) == depositCal.get(Calendar.YEAR)
|
||||||
|
&& filterCal.get(Calendar.MONTH) == depositCal.get(Calendar.MONTH);
|
||||||
|
|
||||||
|
// 如果是同年同月,天数加1
|
||||||
|
if (sameYearMonth) {
|
||||||
|
monthDays += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return amount.multiply(rate)
|
||||||
|
.multiply(new BigDecimal(monthDays))
|
||||||
|
.divide(basisDay, 10, RoundingMode.HALF_UP)
|
||||||
|
.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算本年累计收益
|
||||||
|
* @param filterDate 计提日期
|
||||||
|
* @param validYearEnd 结束有效日期
|
||||||
|
* @param depositStartDate 起始日期
|
||||||
|
* @param amount 金额
|
||||||
|
* @param rate 利率
|
||||||
|
* @param basisDay 计息基准
|
||||||
|
* @return 本年累计收益
|
||||||
|
*/
|
||||||
|
private BigDecimal calculationYearAmount(Date filterDate,Date validYearEnd, Date depositStartDate, BigDecimal amount, BigDecimal rate, BigDecimal basisDay) {
|
||||||
// 计算当年第一天(1月1日)
|
// 计算当年第一天(1月1日)
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
cal.setTime(validYearEnd);
|
cal.setTime(validYearEnd);
|
||||||
|
|
@ -289,6 +328,19 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi
|
||||||
TimeUnit.MILLISECONDS
|
TimeUnit.MILLISECONDS
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 检查filterDate和depositStartDate是否在同年
|
||||||
|
Calendar filterCal = Calendar.getInstance();
|
||||||
|
filterCal.setTime(filterDate);
|
||||||
|
Calendar depositCal = Calendar.getInstance();
|
||||||
|
depositCal.setTime(depositStartDate);
|
||||||
|
|
||||||
|
boolean sameYear = filterCal.get(Calendar.YEAR) == depositCal.get(Calendar.YEAR);
|
||||||
|
|
||||||
|
// 如果是同年,天数加1
|
||||||
|
if (sameYear) {
|
||||||
|
yearDays += 1;
|
||||||
|
}
|
||||||
|
|
||||||
return amount.multiply(rate)
|
return amount.multiply(rate)
|
||||||
.multiply(new BigDecimal(yearDays))
|
.multiply(new BigDecimal(yearDays))
|
||||||
.divide(basisDay, 10, RoundingMode.HALF_UP)
|
.divide(basisDay, 10, RoundingMode.HALF_UP)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue