定期利息计提报表
This commit is contained in:
parent
984942b5ae
commit
f1fa766615
|
|
@ -0,0 +1,142 @@
|
||||||
|
package shjh.jhzj7.fi.fi.plugin.report;
|
||||||
|
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.dataentity.utils.StringUtils;
|
||||||
|
import kd.bos.entity.report.ReportQueryParam;
|
||||||
|
import kd.bos.report.plugin.AbstractReportFormPlugin;
|
||||||
|
import kd.sdk.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Iterator;
|
||||||
|
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"};
|
||||||
|
@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;
|
||||||
|
Iterator<DynamicObject> iterator = rowData.iterator();
|
||||||
|
while (iterator.hasNext()){
|
||||||
|
DynamicObject row = iterator.next();
|
||||||
|
try {
|
||||||
|
// 获取公司名称
|
||||||
|
String companyName = row.getString(FIELDS[0]);
|
||||||
|
// 获取日期
|
||||||
|
Date filterDate =queryParam.getFilter().getDate("shjh_filterdate");
|
||||||
|
Date depositStartDate = row.getDate(FIELDS[4]);
|
||||||
|
Date depositEndDate = row.getDate(FIELDS[5]); // 存款到期日(保证有值)
|
||||||
|
|
||||||
|
// 初始化计算结果
|
||||||
|
BigDecimal accruedInterest = BigDecimal.ZERO;
|
||||||
|
BigDecimal monthlyIncome = BigDecimal.ZERO;
|
||||||
|
BigDecimal yearlyIncome = BigDecimal.ZERO;
|
||||||
|
long dayDiff = 0;
|
||||||
|
|
||||||
|
if (filterDate != null && depositStartDate != null && depositEndDate != null) {
|
||||||
|
// 检查计提日期是否在有效区间(存款起期 <= 计提日期 <= 存款止期)
|
||||||
|
boolean isValidPeriod = !filterDate.before(depositStartDate) &&
|
||||||
|
!filterDate.after(depositEndDate);
|
||||||
|
|
||||||
|
// 计算天数差(只在有效区间计算)
|
||||||
|
if (isValidPeriod) {
|
||||||
|
dayDiff = TimeUnit.DAYS.convert(
|
||||||
|
filterDate.getTime() - depositStartDate.getTime(),
|
||||||
|
TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
|
// 获取金额和利率(利率需要除以100)
|
||||||
|
BigDecimal amount = row.getBigDecimal(FIELDS[9]);
|
||||||
|
BigDecimal rate = new BigDecimal(row.getLong(FIELDS[7]))
|
||||||
|
.divide(new BigDecimal(100), 10, RoundingMode.HALF_UP);
|
||||||
|
|
||||||
|
if (amount != null && amount.compareTo(BigDecimal.ZERO) != 0 &&
|
||||||
|
rate.compareTo(BigDecimal.ZERO) != 0 && dayDiff > 0) {
|
||||||
|
|
||||||
|
/* 计提利息 = (金额 × 利率 × 计提天数) / 365 */
|
||||||
|
accruedInterest = amount.multiply(rate)
|
||||||
|
.multiply(new BigDecimal(dayDiff))
|
||||||
|
.divide(new BigDecimal(365), 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))
|
||||||
|
.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
|
||||||
|
/* 计算本年累计收益 = 金额 × 利率 × 当年有效天数 */
|
||||||
|
// 当年第一天
|
||||||
|
cal.set(Calendar.MONTH, Calendar.JANUARY);
|
||||||
|
cal.set(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
Date yearStart = cal.getTime();
|
||||||
|
|
||||||
|
// 当年有效天数(存款起期与年初的较晚者,到期日与计提日的较早者)
|
||||||
|
Date validYearStart = depositStartDate.after(yearStart) ?
|
||||||
|
depositStartDate : yearStart;
|
||||||
|
Date validYearEnd = filterDate.before(depositEndDate) ?
|
||||||
|
filterDate : depositEndDate;
|
||||||
|
|
||||||
|
long yearDays = TimeUnit.DAYS.convert(
|
||||||
|
validYearEnd.getTime() - validYearStart.getTime(),
|
||||||
|
TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
|
yearlyIncome = amount.multiply(rate)
|
||||||
|
.multiply(new BigDecimal(yearDays))
|
||||||
|
.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
// 设置结果
|
||||||
|
row.set(FIELDS[11], String.valueOf(dayDiff)); // 计提天数
|
||||||
|
row.set(FIELDS[12], accruedInterest); // 计提利息(按/365计算)
|
||||||
|
row.set(FIELDS[13], monthlyIncome); // 本月收益(金额×利率×有效天数)
|
||||||
|
row.set(FIELDS[14], yearlyIncome); // 本年累计收益(金额×利率×有效天数)
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,127 @@
|
||||||
|
package shjh.jhzj7.fi.fi.plugin.report;
|
||||||
|
|
||||||
|
import kd.bos.algo.DataSet;
|
||||||
|
import kd.bos.algo.DataType;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.dataentity.utils.StringUtils;
|
||||||
|
import kd.bos.entity.report.AbstractReportListDataPlugin;
|
||||||
|
import kd.bos.entity.report.FilterItemInfo;
|
||||||
|
import kd.bos.entity.report.ReportQueryParam;
|
||||||
|
import kd.bos.logging.Log;
|
||||||
|
import kd.bos.logging.LogFactory;
|
||||||
|
import kd.bos.orm.query.QCP;
|
||||||
|
import kd.bos.orm.query.QFilter;
|
||||||
|
import kd.bos.servicehelper.QueryServiceHelper;
|
||||||
|
import kd.sdk.plugin.Plugin;
|
||||||
|
import shjh.jhzj7.fi.fi.plugin.operate.LoanPushSapOperation;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表取数插件
|
||||||
|
* 定期利息计提报表取数插件
|
||||||
|
*/
|
||||||
|
public class RegularListReport extends AbstractReportListDataPlugin implements Plugin {
|
||||||
|
|
||||||
|
private final static Log logger = LogFactory.getLog(RegularListReport.class);
|
||||||
|
|
||||||
|
//定期存款处理表字段
|
||||||
|
private static String[] DEPOSIT={"org","finorginfo","finaccount","currency",
|
||||||
|
"intdate","expiredate","term","interestrate","revenueproject","amount"};
|
||||||
|
|
||||||
|
//定期利息计提报表字段
|
||||||
|
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"};
|
||||||
|
|
||||||
|
private static final DataType[] DATATYPE={DataType.LongType,DataType.LongType,DataType.StringType,DataType.LongType,
|
||||||
|
DataType.DateType, DataType.DateType,DataType.StringType,DataType.LongType,
|
||||||
|
DataType.LongType,DataType.BigDecimalType,DataType.DateType,DataType.StringType,
|
||||||
|
DataType.BigDecimalType,DataType.BigDecimalType,DataType.BigDecimalType};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataSet query(ReportQueryParam param, Object obj) throws Throwable {
|
||||||
|
List<FilterItemInfo> filterItems = param.getFilter().getFilterItems();
|
||||||
|
Long orgId=null;
|
||||||
|
String accrualDate=null;
|
||||||
|
for (FilterItemInfo filterItem : filterItems) {
|
||||||
|
switch (filterItem.getPropName()){
|
||||||
|
case "shjh_filterorgname":
|
||||||
|
orgId=(filterItem.getValue()==null) ? null: (Long) ((DynamicObject)filterItem.getValue()).getPkValue();
|
||||||
|
break;
|
||||||
|
case "shjh_filterdate":
|
||||||
|
accrualDate=(filterItem.getDate()==null) ? null:new SimpleDateFormat("yyyy-MM-dd").format(filterItem.getDate());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StringBuilder selectFields = new StringBuilder();
|
||||||
|
selectFields.append(DEPOSIT[0]).append(".name").append(" as ").append(FIELDS[0]).append(",")
|
||||||
|
.append(DEPOSIT[1]).append(" as ").append(FIELDS[1]).append(",")
|
||||||
|
.append(DEPOSIT[2]).append(" as ").append(FIELDS[2]).append(",")
|
||||||
|
.append(DEPOSIT[3]).append(" as ").append(FIELDS[3]).append(",")
|
||||||
|
.append(DEPOSIT[4]).append(" as ").append(FIELDS[4]).append(",")
|
||||||
|
.append(DEPOSIT[5]).append(" as ").append(FIELDS[5]).append(",")
|
||||||
|
.append(DEPOSIT[6]).append(" as ").append(FIELDS[6]).append(",")
|
||||||
|
.append(DEPOSIT[7]).append(" as ").append(FIELDS[7]).append(",")
|
||||||
|
.append(DEPOSIT[8]).append(" as ").append(FIELDS[8]).append(",")
|
||||||
|
.append(DEPOSIT[9]).append(" as ").append(FIELDS[9]).append(",")
|
||||||
|
.append("'").append(accrualDate).append("'").append(FIELDS[10]);
|
||||||
|
// 逻辑字段
|
||||||
|
|
||||||
|
|
||||||
|
List<QFilter> qFilters=new ArrayList<>();
|
||||||
|
if (orgId!=null){
|
||||||
|
qFilters.add(new QFilter("org", QCP.equals,orgId));
|
||||||
|
|
||||||
|
}
|
||||||
|
DataSet dataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "cim_deposit", selectFields.toString(), qFilters.toArray(new QFilter[]{}), null);
|
||||||
|
|
||||||
|
|
||||||
|
//分组小计
|
||||||
|
DataSet groupDataSet = dataSet.groupBy(new String[]{FIELDS[0]}).sum(FIELDS[9]).finish();
|
||||||
|
// 由于分组计算之后,Dataset的字段少了一个,需要通过addField加回来,为之后union做准备
|
||||||
|
groupDataSet = groupDataSet
|
||||||
|
.addField("0L", FIELDS[1])//银行名称-id
|
||||||
|
.addField("'-'",FIELDS[2])//银行账户
|
||||||
|
.addField("0L",FIELDS[3])//币种
|
||||||
|
.addField("NULL",FIELDS[4])//起款日期
|
||||||
|
.addField("NULL",FIELDS[5])//存款止期
|
||||||
|
.addField("'-'",FIELDS[6])//存期
|
||||||
|
.addField("0",FIELDS[7])//利率
|
||||||
|
.addField("0L",FIELDS[8])//频率
|
||||||
|
.addField("NULL",FIELDS[10]);//计提日期
|
||||||
|
|
||||||
|
|
||||||
|
StringBuilder selectExpression = new StringBuilder();
|
||||||
|
selectExpression.append(FIELDS[0]);
|
||||||
|
|
||||||
|
// 添加其他字段(直接使用原字段名)
|
||||||
|
for (int i = 1; i < FIELDS.length; i++) {
|
||||||
|
if (i==11){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
selectExpression.append(", ").append(FIELDS[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 应用SELECT转换
|
||||||
|
groupDataSet = groupDataSet.select("concat(shjh_orgname+'-小计') as "+ selectExpression);
|
||||||
|
|
||||||
|
// union前,需要保证两个dataSet的字段序列一致,因此这里对sumDataSet对象重新排列字段序列
|
||||||
|
groupDataSet = groupDataSet.select(String.valueOf(selectExpression));
|
||||||
|
// union,此时groupDataSet会续在dataSet的底部
|
||||||
|
DataSet unionDataSet = dataSet.union(groupDataSet);
|
||||||
|
// 按组织名称排序,这样,底部的合计数据,就会与上面的组织名称排在一起
|
||||||
|
DataSet orderByDataSet = unionDataSet.orderBy(new String[]{FIELDS[0]});
|
||||||
|
|
||||||
|
return orderByDataSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue