理财收益计提报表-合计小计优化
This commit is contained in:
parent
986d9ac682
commit
c1ebd242c6
|
|
@ -153,9 +153,7 @@ public class RecBillChangeListExtendPlugin extends AbstractListPlugin implements
|
|||
// 是否存在付款申请
|
||||
QFilter[] filters = new QFilter[]{
|
||||
new QFilter("org.number", QCP.equals, companyCode),
|
||||
new QFilter("shjh_vouchernum", QCP.equals, voucherNum),
|
||||
new QFilter("shjh_sapfiscalyear", QCP.equals, sapFiscalYear),
|
||||
new QFilter("shjh_sapline", QCP.equals, sapLineNumber)
|
||||
new QFilter("shjh_vouchernum", QCP.equals, voucherNum)
|
||||
};
|
||||
DynamicObject payApply = BusinessDataServiceHelper.loadSingle("ap_payapply", filters);
|
||||
if (payApply != null) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package shjh.jhzj7.fi.fi.plugin.report;
|
|||
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.entity.report.FilterItemInfo;
|
||||
import kd.bos.entity.report.ReportColumn;
|
||||
import kd.bos.entity.report.ReportQueryParam;
|
||||
import kd.bos.logging.Log;
|
||||
|
|
@ -14,10 +13,7 @@ import shjh.jhzj7.fi.fi.plugin.report.util.ReportUtils;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 报表界面插件
|
||||
|
|
@ -64,12 +60,14 @@ public class FinancialFormReport extends AbstractReportFormPlugin implements Plu
|
|||
|
||||
// 遍历每一行数据
|
||||
Iterator<DynamicObject> iterator = rowData.iterator();
|
||||
//小计行合计项
|
||||
BigDecimal sumProjectedEarnings =BigDecimal.ZERO;//预计收益汇总
|
||||
BigDecimal sumProvisionEarnings =BigDecimal.ZERO;//收益计提汇总
|
||||
BigDecimal sumMonthEarnings =BigDecimal.ZERO;//本月收益汇总
|
||||
BigDecimal sumYearEarnings =BigDecimal.ZERO;//本年收益汇总
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
DynamicObject row = iterator.next();
|
||||
//跳过小计行
|
||||
if (row.getString(REPORT_FIELDS[0]).contains("-小计")){
|
||||
continue;
|
||||
}
|
||||
// 基础字段获取(添加null检查)
|
||||
BigDecimal amount = ReportUtils.getBigDecimalValue(row, REPORT_FIELDS[4]); // 原始金额(元)
|
||||
row.set(REPORT_FIELDS[4],amount.divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP));
|
||||
|
|
@ -90,16 +88,50 @@ public class FinancialFormReport extends AbstractReportFormPlugin implements Plu
|
|||
String day = countProductTerm(buyDate, expireDate, accrualDate, row);
|
||||
// 4. 预计收益 = 产品期限 * 金额(千元) * 预计业绩比较基准 / 365
|
||||
BigDecimal proRevenue = countProRevenue(expectedRate, day, amount, row);
|
||||
sumProjectedEarnings=sumProjectedEarnings.add(proRevenue);
|
||||
// 5. 收益计提 = 持有份额 * (月末单位净值 - 购买时单位净值) / 1000
|
||||
BigDecimal revenueAmt = countRevenueAmt(buyCopies, monthNetWorth, netWorth, row);
|
||||
sumProvisionEarnings=sumProvisionEarnings.add(revenueAmt);
|
||||
// 6. 本月收益计算(严格按生效期间计算)
|
||||
BigDecimal monthRevenue = countMonthRevenue(monthNetWorth, netWorth, buyCopies, valueDate, accrualDate, expireDate, row);
|
||||
sumMonthEarnings=sumMonthEarnings.add(monthRevenue);
|
||||
// 7. 当月收益率 = 本月收益 / 金额(千元) * 100 * 12
|
||||
countMonthRate(amount,monthRevenue,row);
|
||||
// 8. 本年累计收益 = 当年各月收益之和(按实际持有天数比例计算)
|
||||
BigDecimal yearRevenue = countYearRevenue(monthNetWorth, netWorth, buyCopies, valueDate, accrualDate, expireDate, row);
|
||||
sumYearEarnings=sumYearEarnings.add(yearRevenue);
|
||||
|
||||
//小计行合计
|
||||
if (row.getString(REPORT_FIELDS[0]).contains("-小计")){
|
||||
row.set(DYNAMICS_FIELDS[0],sumProjectedEarnings);
|
||||
row.set(DYNAMICS_FIELDS[3],sumProvisionEarnings);
|
||||
row.set(DYNAMICS_FIELDS[4],sumMonthEarnings);
|
||||
row.set(DYNAMICS_FIELDS[6],sumYearEarnings);
|
||||
//赋值后归0,重新参与合计
|
||||
sumProjectedEarnings=BigDecimal.ZERO;
|
||||
sumProvisionEarnings=BigDecimal.ZERO;
|
||||
sumMonthEarnings=BigDecimal.ZERO;
|
||||
sumYearEarnings=BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//小计行处理
|
||||
ReportUtils.changeRowData(rowData,REPORT_FIELDS[0]);
|
||||
//添加合计
|
||||
// 需要配置求和的字段映射(目标字段,来源字段)
|
||||
List<String[]> sumConfig = new ArrayList<>();
|
||||
// 处理REPORT_FIELDS中的金额字段
|
||||
sumConfig.add(new String[]{REPORT_FIELDS[4], REPORT_FIELDS[4]}); // shjh_amount
|
||||
// 处理DYNAMICS_FIELDS中的收益字段
|
||||
sumConfig.add(new String[]{DYNAMICS_FIELDS[0], DYNAMICS_FIELDS[0]}); // shjh_projectrevenueamt
|
||||
sumConfig.add(new String[]{DYNAMICS_FIELDS[3], DYNAMICS_FIELDS[3]}); // shjh_revenueamt
|
||||
sumConfig.add(new String[]{DYNAMICS_FIELDS[4], DYNAMICS_FIELDS[4]}); // shjh_monthrevenueamt
|
||||
sumConfig.add(new String[]{DYNAMICS_FIELDS[6], DYNAMICS_FIELDS[6]}); // shjh_yearrevenueamt
|
||||
|
||||
ReportUtils.addTotalRowData(rowData,REPORT_FIELDS[0],"小计","合计",sumConfig);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ public class RegularFormReport extends AbstractReportFormPlugin implements Plugi
|
|||
rowData.removeAll(rowsToRemove);
|
||||
}
|
||||
|
||||
// 如果只有一类公司,移除所有小计行(根据你的TODO注释)
|
||||
// 如果只有一类公司,移除所有小计行
|
||||
if (currentCompanyName != null && rowData.stream()
|
||||
.filter(r -> !r.getString(FIELDS[0]).contains("小计"))
|
||||
.map(r -> r.getString(FIELDS[0]))
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
package shjh.jhzj7.fi.fi.plugin.report.util;
|
||||
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.dataentity.entity.LocaleString;
|
||||
import kd.bos.entity.report.ReportColumn;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class ReportUtils {
|
||||
|
||||
|
|
@ -31,6 +34,94 @@ public class ReportUtils {
|
|||
return reportColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加合计行通用工具方法
|
||||
* @param rowData 数据集合
|
||||
* @param summaryField 用于识别小计行的字段名(如"projectName")
|
||||
* @param summaryKeyword 小计行标识关键字(如"小计")-跳过该行数据
|
||||
* @param totalRowLabel 合计行显示文本(如"合计")
|
||||
* @param sumFields 需要求和的字段配置(二维数组,格式:[目标字段, 来源字段])
|
||||
*/
|
||||
public static void addTotalRowData(DynamicObjectCollection rowData,
|
||||
String summaryField,
|
||||
String summaryKeyword,
|
||||
String totalRowLabel,
|
||||
List<String[]> sumFields) {
|
||||
// 初始化合计值容器
|
||||
BigDecimal[] totals = new BigDecimal[sumFields.size()];
|
||||
for(int i=0; i<totals.length; i++){
|
||||
totals[i] = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
// 遍历数据行
|
||||
for (DynamicObject row : rowData) {
|
||||
if (!row.getString(summaryField).contains(summaryKeyword)) {
|
||||
// 累加所有需要合计的字段
|
||||
for(int i=0; i<sumFields.size(); i++){
|
||||
String sourceField = sumFields.get(i)[1];
|
||||
BigDecimal value = row.getBigDecimal(sourceField);
|
||||
if(value != null){
|
||||
totals[i] = totals[i].add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 创建合计行
|
||||
DynamicObject totalRow = new DynamicObject(rowData.getDynamicObjectType());
|
||||
totalRow.set(summaryField, totalRowLabel);
|
||||
|
||||
// 设置合计值
|
||||
for(int i=0; i<sumFields.size(); i++){
|
||||
String targetField = sumFields.get(i)[0];
|
||||
totalRow.set(targetField, totals[i]);
|
||||
}
|
||||
|
||||
rowData.add(totalRow);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对小计行处理
|
||||
* @param rowData 数据集合
|
||||
* @param keyWord 需要处理的单元格标识
|
||||
*/
|
||||
public static void changeRowData(DynamicObjectCollection rowData,String keyWord) {
|
||||
// 用于记录当前处理的"公司名称-小计"行
|
||||
String currentName = null;
|
||||
List<DynamicObject> rowsToRemove = new ArrayList<>();
|
||||
|
||||
for (DynamicObject row : rowData) {
|
||||
String name = row.getString(keyWord);
|
||||
|
||||
// 如果是"公司名称-小计"格式的行
|
||||
if (name != null && name.contains("-小计")) {
|
||||
// 如果是第一次遇到该公司的小计行
|
||||
if (currentName == null || !name.startsWith(currentName)) {
|
||||
currentName = name.substring(0, name.indexOf("-小计"));
|
||||
// 修改为公司名称简化为"小计"
|
||||
row.set(keyWord, "小计");
|
||||
} else {
|
||||
// 如果是同一公司的重复小计行,标记为需要移除
|
||||
rowsToRemove.add(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 移除重复的小计行
|
||||
if (!rowsToRemove.isEmpty()) {
|
||||
rowData.removeAll(rowsToRemove);
|
||||
}
|
||||
|
||||
// 如果只有一类公司,移除所有小计行
|
||||
if (currentName != null && rowData.stream()
|
||||
.filter(r -> !r.getString(keyWord).contains("小计"))
|
||||
.map(r -> r.getString(keyWord))
|
||||
.distinct()
|
||||
.count() == 1) {
|
||||
rowData.removeIf(r -> r.getString(keyWord).contains("小计"));
|
||||
}
|
||||
}
|
||||
|
||||
// 辅助方法:获取某个月的第一天
|
||||
public static Date getFirstDayOfMonth(Date date) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
|
|
|||
Loading…
Reference in New Issue