From a4ab06b57d6e8e770bdfc6c8233c6611adc55c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=B4=B5=E5=BC=BA?= Date: Fri, 23 May 2025 10:42:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E6=8F=90=E6=8A=A5=E8=A1=A8=E6=9C=AC?= =?UTF-8?q?=E5=B9=B4=E6=9C=AC=E6=9C=88=E6=94=B6=E7=9B=8A=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fi/plugin/report/RegularFormReport.java | 194 +++++++++++------- 1 file changed, 123 insertions(+), 71 deletions(-) diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/report/RegularFormReport.java b/main/java/shjh/jhzj7/fi/fi/plugin/report/RegularFormReport.java index 6c3022d..7f62450 100644 --- a/main/java/shjh/jhzj7/fi/fi/plugin/report/RegularFormReport.java +++ b/main/java/shjh/jhzj7/fi/fi/plugin/report/RegularFormReport.java @@ -18,25 +18,26 @@ import java.util.concurrent.TimeUnit; */ public class RegularFormReport extends AbstractReportFormPlugin implements Plugin { - private static final String[] FIELDS={"shjh_orgname","shjh_bankname","shjh_bankaccount","shjh_currency", - "shjh_depositstartdate","shjh_depositstopdate","shjh_term","shjh_interestrate", - "shjh_frequency","shjh_amount","shjh_accrualdate","shjh_accrualdays", - "shjh_accrualinterest","shjh_monthearnings","shjh_yearearnings","shjh_depositmodel","shjh_basis"}; + private static final String[] FIELDS = {"shjh_orgname", "shjh_bankname", "shjh_bankaccount", "shjh_currency", + "shjh_depositstartdate", "shjh_depositstopdate", "shjh_term", "shjh_interestrate", + "shjh_frequency", "shjh_amount", "shjh_accrualdate", "shjh_accrualdays", + "shjh_accrualinterest", "shjh_monthearnings", "shjh_yearearnings", "shjh_depositmodel", "shjh_basis"}; + @Override public void processRowData(String gridPK, DynamicObjectCollection rowData, ReportQueryParam queryParam) { super.processRowData(gridPK, rowData, queryParam); //小计金额 - BigDecimal subInterestAmt=BigDecimal.ZERO; - BigDecimal subMonthAmt=BigDecimal.ZERO; - BigDecimal subYearAmt=BigDecimal.ZERO; + BigDecimal subInterestAmt = BigDecimal.ZERO; + BigDecimal subMonthAmt = BigDecimal.ZERO; + BigDecimal subYearAmt = BigDecimal.ZERO; Iterator iterator = rowData.iterator(); - while (iterator.hasNext()){ + while (iterator.hasNext()) { DynamicObject row = iterator.next(); try { // 获取公司名称 String companyName = row.getString(FIELDS[0]); // 获取日期 - Date filterDate =queryParam.getFilter().getDate("shjh_filterdate"); + Date filterDate = queryParam.getFilter().getDate("shjh_filterdate"); Date depositStartDate = row.getDate(FIELDS[4]); Date depositEndDate = row.getDate(FIELDS[5]); // 存款到期日(保证有值) @@ -44,7 +45,7 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi BigDecimal accruedInterest = BigDecimal.ZERO; BigDecimal monthlyIncome = BigDecimal.ZERO; BigDecimal yearlyIncome = BigDecimal.ZERO; - long dayDiff=0; + long dayDiff = 0; if (filterDate != null && depositStartDate != null && depositEndDate != null) { @@ -54,14 +55,14 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi //计息基准 String basis = row.getString(FIELDS[16]); BigDecimal basisDay; - switch (basis){ + switch (basis) { case "Actual_365": default: - basisDay= BigDecimal.valueOf(365); + basisDay = BigDecimal.valueOf(365); break; case "Actual_360": case "DEP_30_360": - basisDay= BigDecimal.valueOf(360); + basisDay = BigDecimal.valueOf(360); break; } @@ -69,44 +70,25 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi BigDecimal rate = row.getBigDecimal(FIELDS[7]) .divide(new BigDecimal(100), 10, RoundingMode.HALF_UP); - if (amount != null && amount.compareTo(BigDecimal.ZERO) != 0 && rate.compareTo(BigDecimal.ZERO) != 0 ) { + if (amount != null && amount.compareTo(BigDecimal.ZERO) != 0 && rate.compareTo(BigDecimal.ZERO) != 0) { // 检查计提日期是否在有效区间(存款起期 <= 计提日期 <= 存款止期) boolean isValidPeriod = !filterDate.before(depositStartDate) && !filterDate.after(depositEndDate); + if (isValidPeriod) { + //计提天数 + dayDiff = this.calculationDays(row, filterDate, depositStartDate); - if (isValidPeriod) { - //计提天数 - dayDiff = this.calculationDays(row,filterDate,depositStartDate); /* 计提利息 = (金额 × 天利率 × 计提天数) */ accruedInterest = amount.multiply(rate) .multiply(new BigDecimal(dayDiff)) - .divide(basisDay,10, RoundingMode.HALF_UP) + .divide(basisDay, 10, RoundingMode.HALF_UP) .setScale(2, RoundingMode.HALF_UP); /* 计算本月收益 = 金额 × 天利率 × 当月有效天数 */ - 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); - - monthlyIncome = amount.multiply(rate) - .multiply(new BigDecimal(monthDays)) - .divide(basisDay,10, RoundingMode.HALF_UP) - .setScale(2, RoundingMode.HALF_UP); + monthlyIncome = this.calculationMonthAmount(filterDate, depositStartDate, amount, rate, basisDay); } /* 计算本年累计收益 = 金额 × 利率 × 当年有效天数 */ - //Date currentDate = new Date(); // 当前日期 Date validYearEnd = null; // 有效结束日期 if (filterDate.before(depositStartDate)) { @@ -115,30 +97,30 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi } else if (filterDate.after(depositEndDate)) { // 当日期晚于存款到期日,计算到 depositEndDate 的累计收益 validYearEnd = depositEndDate; - yearlyIncome = this.calculationYearAmount(validYearEnd, depositStartDate, amount, rate, basisDay); + yearlyIncome = this.calculationYearAmount(filterDate,validYearEnd, depositStartDate, amount, rate, basisDay); } else { // 当前日期在有效期内,计算到当前日期的累计收益 validYearEnd = filterDate; - yearlyIncome = this.calculationYearAmount(validYearEnd, depositStartDate, amount, rate, basisDay); + yearlyIncome = this.calculationYearAmount(filterDate,validYearEnd, depositStartDate, amount, rate, basisDay); } } } - if (companyName.contains("小计")){ + if (companyName.contains("小计")) { row.set(FIELDS[11], ""); // 计提天数 row.set(FIELDS[12], subInterestAmt); // 计提利息小计 row.set(FIELDS[13], subMonthAmt); // 本月收益小计 row.set(FIELDS[14], subYearAmt); // 本年累计收益小计 //金额清0 - subInterestAmt=BigDecimal.ZERO; - subMonthAmt=BigDecimal.ZERO; - subYearAmt=BigDecimal.ZERO; - }else { - subInterestAmt=subInterestAmt.add(accruedInterest); - subMonthAmt=subMonthAmt.add(monthlyIncome); - subYearAmt=subYearAmt.add(yearlyIncome); + subInterestAmt = BigDecimal.ZERO; + subMonthAmt = BigDecimal.ZERO; + subYearAmt = BigDecimal.ZERO; + } else { + subInterestAmt = subInterestAmt.add(accruedInterest); + subMonthAmt = subMonthAmt.add(monthlyIncome); + subYearAmt = subYearAmt.add(yearlyIncome); // 设置结果 - row.set(FIELDS[11], dayDiff==0 ? null:String.valueOf(dayDiff)); // 计提天数 + row.set(FIELDS[11], dayDiff == 0 ? null : String.valueOf(dayDiff)); // 计提天数 row.set(FIELDS[12], accruedInterest); // 计提利息(按/365计算) row.set(FIELDS[13], monthlyIncome); // 本月收益(金额×利率×有效天数) row.set(FIELDS[14], yearlyIncome); // 本年累计收益(金额×利率×有效天数) @@ -155,6 +137,7 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi /** * 对小计行处理 + * * @param rowData */ private void changeRowData(DynamicObjectCollection rowData) { @@ -177,13 +160,13 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi } } String term = row.getString(FIELDS[6]);//存期处理 - if (term !=null && !"-".equals(term)){ + if (term != null && !"-".equals(term)) { //term的格式:4y5m25d、4y30d,转换为4年5月25天格式 // term的格式:4y5m25d、4y30d,转换为4年5月25天格式 term = term.replaceAll("(\\d+)y", "$1年") // 替换y为年 .replaceAll("(\\d+)m", "$1月") // 替换m为月 .replaceAll("(\\d+)d", "$1天"); // 替换d为天 - row.set(FIELDS[6],term); + row.set(FIELDS[6], term); } } @@ -204,6 +187,7 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi /** * 尾行固定添加合计行 + * * @param rowData */ private void addTotalRowData(DynamicObjectCollection rowData) { @@ -214,42 +198,43 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi for (DynamicObject rowDatum : rowData) { //跳过小计行 - if (!rowDatum.getString(FIELDS[0]).contains("小计")){ + if (!rowDatum.getString(FIELDS[0]).contains("小计")) { BigDecimal amount = rowDatum.getBigDecimal(FIELDS[9]); - totalAmount=totalAmount.add(amount); + totalAmount = totalAmount.add(amount); BigDecimal interestAmt = rowDatum.getBigDecimal(FIELDS[12]); - totalInterestAmt=totalInterestAmt.add(interestAmt); + totalInterestAmt = totalInterestAmt.add(interestAmt); BigDecimal monthAmt = rowDatum.getBigDecimal(FIELDS[13]); - totalMonthAmt=totalMonthAmt.add(monthAmt); + totalMonthAmt = totalMonthAmt.add(monthAmt); BigDecimal yearAmt = rowDatum.getBigDecimal(FIELDS[14]); - totalYearAmt=totalYearAmt.add(yearAmt); + totalYearAmt = totalYearAmt.add(yearAmt); } } DynamicObject dynamicObject = new DynamicObject(rowData.getDynamicObjectType()); - dynamicObject.set(FIELDS[0],"合计"); - dynamicObject.set(FIELDS[9],totalAmount); - dynamicObject.set(FIELDS[12],totalInterestAmt); - dynamicObject.set(FIELDS[13],totalMonthAmt); - dynamicObject.set(FIELDS[14],totalYearAmt); + dynamicObject.set(FIELDS[0], "合计"); + dynamicObject.set(FIELDS[9], totalAmount); + dynamicObject.set(FIELDS[12], totalInterestAmt); + dynamicObject.set(FIELDS[13], totalMonthAmt); + dynamicObject.set(FIELDS[14], totalYearAmt); rowData.add(dynamicObject); } /** * 计算计提天数 + * * @param row - * @param filterDate 计提日期 + * @param filterDate 计提日期 * @param depositStartDate 启始日期 * @return */ - private long calculationDays(DynamicObject row,Date filterDate,Date depositStartDate){ + private long calculationDays(DynamicObject row, Date filterDate, Date depositStartDate) { long dayDiff = 0; //默认规则 - String calculationRule="headnotail"; - DynamicObject depositModel = row.getDynamicObject(FIELDS[15]); - if (depositModel!=null){ - calculationRule=depositModel.getString("intheadtailrule"); + String calculationRule = "headnotail"; + DynamicObject depositModel = row.getDynamicObject(FIELDS[15]); + if (depositModel != null) { + calculationRule = depositModel.getString("intheadtailrule"); } - switch (calculationRule){ + switch (calculationRule) { case "headnotail"://算头不算尾 case "noheadtail"://算尾不算头 default: @@ -271,7 +256,61 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi 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日) Calendar cal = Calendar.getInstance(); cal.setTime(validYearEnd); @@ -289,9 +328,22 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi TimeUnit.MILLISECONDS ); - return amount.multiply(rate) + // 检查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) .multiply(new BigDecimal(yearDays)) - .divide(basisDay,10, RoundingMode.HALF_UP) + .divide(basisDay, 10, RoundingMode.HALF_UP) .setScale(2, RoundingMode.HALF_UP); } } \ No newline at end of file