diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/report/BankBalanceSummaryFormPlugin.java b/main/java/shjh/jhzj7/fi/fi/plugin/report/BankBalanceSummaryFormPlugin.java new file mode 100644 index 0000000..d938723 --- /dev/null +++ b/main/java/shjh/jhzj7/fi/fi/plugin/report/BankBalanceSummaryFormPlugin.java @@ -0,0 +1,331 @@ +package shjh.jhzj7.fi.fi.plugin.report; + +import kd.bos.algo.DataSet; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +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.report.plugin.AbstractReportFormPlugin; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.QueryServiceHelper; +import kd.sdk.plugin.Plugin; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.*; + +import static shjh.jhzj7.fi.fi.plugin.report.StrongSharingQueryPlugin.BEI_INTELPAY; + + +/** + * 报表界面插件 + * 银行余额汇总报表界面插件 + */ +public class BankBalanceSummaryFormPlugin extends AbstractReportFormPlugin implements Plugin { + + public static final String CIM_FINSUBSCRIBE = "cim_finsubscribe";//理财申购单 + public static final String CIM_INTBILL_BATCH = "cim_intbill_batch";//理财收益批量预提 + public static final String CIM_DEPOSIT = "cim_deposit";//定期存款处理 + private static final String[] FIELDS = {"1: 运营资金", "1.1 强共享公司", "1.2 弱共享公司", "2: 理财", "3: 定期", "合计"}; + private static final Log log = LogFactory.getLog(BankBalanceSummaryFormPlugin.class); + + @Override + public void processRowData(String gridPK, DynamicObjectCollection rowData, ReportQueryParam queryParam) { + super.processRowData(gridPK, rowData, queryParam); + //千元 + rowData.clear(); + + // 获取过滤条件 1.基准日期 2.同年比较日期 3.上年比较日期 + Date shjh_benchmarka =queryParam.getFilter().getDate("shjh_benchmarka"); + Date shjh_sameyeara =queryParam.getFilter().getDate("shjh_sameyeara"); + Date shjh_previousyear =queryParam.getFilter().getDate("shjh_previousyear"); + + // 组装默认数据 + for (int i = 0; i <= 5 ; i++) { + DynamicObject dynamicObject = new DynamicObject(rowData.getDynamicObjectType()); + dynamicObject.set("shjh_bankbalance", FIELDS[i]);//银行余额 + rowData.add(dynamicObject); + } + + QFilter q1 = new QFilter("bizdate", QCP.equals, shjh_benchmarka);//交易日期(基准日期) + QFilter q2 = new QFilter("company.shjh_isshare", QCP.equals, "1");//公司属性为强共享 + QFilter q3 = new QFilter("company.shjh_isshare", QCP.equals, "0");//公司属性为弱共享 + QFilter q4 = new QFilter("bizdate", QCP.equals, shjh_sameyeara);//交易日期(同年比较日期) + QFilter q5 = new QFilter("bizdate", QCP.equals, shjh_previousyear);//交易日期(上年比较日期) + // 强弱共享 + setBenchmarkamount(q1.and(q2),rowData,true,"基准日期");//设置基准日期,强共享,按账号id分组,取最大日期的余额合计 + setBenchmarkamount(q1.and(q3),rowData,false,"基准日期");//设置基准日期,弱共享,按账号id分组,取最大日期的余额合计 + setBenchmarkamount(q4.and(q2),rowData,true,"同年比较日期");//设置同年比较日期,强共享,按账号id分组,取最大日期的余额合计 + setBenchmarkamount(q4.and(q3),rowData,false,"同年比较日期");//设置同年比较日期,弱共享,按账号id分组,取最大日期的余额合计 + setBenchmarkamount(q5.and(q2),rowData,true,"上年比较日期");//设置上年比较日期,强共享,按账号id分组,取最大日期的余额合计 + setBenchmarkamount(q5.and(q3),rowData,false,"上年比较日期");//设置上年比较日期,弱共享,按账号id分组,取最大日期的余额合计 + // 理财 + setLcAmount(shjh_benchmarka,rowData,"基准日期"); + setLcAmount(shjh_sameyeara,rowData,"同年比较日期"); + setLcAmount(shjh_previousyear,rowData,"上年比较日期"); + // 定期 + setDqAmount(shjh_benchmarka,rowData,"基准日期"); + setDqAmount(shjh_sameyeara,rowData,"同年比较日期"); + setDqAmount(shjh_previousyear,rowData,"上年比较日期"); + //设置运营资金金额(首行) + setAmount(rowData); + //设置合计金额(尾行) + setTotal(rowData); + + //环比:基准日期下的余额减去同年比较日期下的余额 + for (DynamicObject rowDatum : rowData) { + rowDatum.set("shjh_monthonmonthrate", rowDatum.getBigDecimal("shjh_benchmarkamount").subtract(rowDatum.getBigDecimal("shjh_sameyearamount"))); + } + + //同比:基准日期下的余额减去上年比较日期下的余额 + for (DynamicObject rowDatum : rowData) { + rowDatum.set("shjh_yearonyear", rowDatum.getBigDecimal("shjh_benchmarkamount").subtract(rowDatum.getBigDecimal("shjh_previousyearamount"))); + } + } + + /** + * 设置基准日期/同年比较日期/上年比较日期,强/弱共享,按账号id分组,取最大日期的余额合计 + * @param qFilter 过滤条件 + * @param rowData 行数据 + * @param isShare 是否为强共享 + * @param type 日期类型 + */ + private void setBenchmarkamount(QFilter qFilter,DynamicObjectCollection rowData,Boolean isShare,String type){ + // 被动付款入账_(交易日期,余额,账号id,公司属性) + DynamicObject[] bei_intelpay1 = BusinessDataServiceHelper.load(BEI_INTELPAY,"biztime," + + "transbalance,accountbank,company.shjh_isshare", new QFilter[]{qFilter}, null); + + // 按银行账户id分组 + Map> map = new HashMap<>(); + for (DynamicObject bei_intelpay : bei_intelpay1) { + DynamicObject accountbank = bei_intelpay.getDynamicObject("accountbank"); + //银行账户id为空 + if (null == accountbank) { + continue; + } + // 避免重复 key + boolean keyExists = false; + for (Long existingKey : map.keySet()) { + if (existingKey.toString().contentEquals(String.valueOf(accountbank.getLong("id")))) { + keyExists = true; + map.get(existingKey).add(bei_intelpay);//若map里面有 + break; + } + } + if (!keyExists) { + map.computeIfAbsent(accountbank.getLong("id"), k -> new ArrayList<>()).add(bei_intelpay); + } + } + //取最大日期的集合 + Map newMap = new HashMap<>(); + for (Map.Entry> entry : map.entrySet()) { + Long key = entry.getKey(); + List list = entry.getValue(); + DynamicObject maxDateObject = null; + Date maxDate = null; + for (DynamicObject dynamicObject : list) { + Date biztime = dynamicObject.getDate("biztime"); + if (maxDate == null || biztime.after(maxDate)) { + maxDate = biztime; + maxDateObject = dynamicObject; + } + } + if (maxDateObject != null) { + newMap.put(key, maxDateObject); + } + } + + // 求和余额 千元 + BigDecimal total = new BigDecimal("0");//合计_基准日期-余额 + for (Map.Entry entry : newMap.entrySet()) { + DynamicObject value = entry.getValue(); + if (null != value) { + BigDecimal transbalance = value.getBigDecimal("transbalance"); + if (transbalance != null) { + total = total.add(transbalance); + } + } + } + + BigDecimal divisor = new BigDecimal("1000");//转换为千元 + // 进行除法运算并保留两位小数 + total = total.divide(divisor, 2, RoundingMode.HALF_UP); + + // 根据条件设置值 + Map fieldMap = new HashMap<>(); + fieldMap.put("基准日期", "shjh_benchmarkamount"); + fieldMap.put("同年比较日期", "shjh_sameyearamount"); + fieldMap.put("上年比较日期", "shjh_previousyearamount"); + + String field = fieldMap.get(type); + if (field != null) { + int index = isShare ? 1 : 2; + DynamicObject row1 = rowData.get(index); + row1.set(field, total); + } + } + + /** + * 理财:理财申购单的本金+计提收益(只考虑起始日期<=基准等日期) + * @param date 基准等日期 + * @param rowData 行数据 + * @param type 日期类型 + */ + private void setLcAmount(Date date,DynamicObjectCollection rowData,String type){ + + //理财申购单的本金: 汇总理财金额 (理财申购本金) + //计提收益:持有份额*(月末单位净值-购买时单位净值)/1000 + //理财申购单中购买份数*(<理财收益批量预提单根据理财申购单号+收益日期区间+需要生成凭证为过滤条件,若结果多个,取创建时间降序取第一个> - 理财申购单中理财金额)) + + QFilter qFilter = new QFilter("valuedate", QCP.less_equals, date); //起始日期 <= 基准日期 + + BigDecimal bjtotal = new BigDecimal("0");//理财申购单的本金 + BigDecimal jttotal = new BigDecimal("0");//计提收益 + + // 理财申购单(理财起始日,购买份数,理财金额,单据编号) + DynamicObject[] finsubscribes = BusinessDataServiceHelper.load(CIM_FINSUBSCRIBE, "valuedate,buycopies," + + "amount,billno", qFilter.toArray()); + for (DynamicObject finsubscribe : finsubscribes) { + //1.本金 + BigDecimal amounts = finsubscribe.getBigDecimal("amount"); + if (amounts != null) { + bjtotal = bjtotal.add(amounts); + } + + //2.计提收益 + //购买份数 + BigDecimal buycopies = finsubscribe.getBigDecimal("buycopies"); + //月末单位净值 + QFilter Q1 = new QFilter("entry.finbillno", QCP.equals, finsubscribe.getString("billno"));//理财收益批量预提单根据理财申购单号 + QFilter Q2 = new QFilter("entry.startdate", QCP.less_equals, date);//收益计算开始日 <= 基准等日期 + QFilter Q3 = new QFilter("entry.enddate", QCP.large_equals, date); //收益计算开始日 >= 基准等日期 + QFilter Q4 = new QFilter("shjh_needvoucher", QCP.equals, true); //需要生成凭证 + //理财收益批量预提单(预提收益信息分录,理财申购单号,收益计算开始日,收益计算结束日,需要生成凭证,现值) + BigDecimal ymtotal = new BigDecimal("0");//月末单位净值 + DynamicObject[] intbillBatchs = BusinessDataServiceHelper.load(CIM_INTBILL_BATCH, + "entry,entry.finbillno,entry.startdate,entry.enddate,shjh_needvoucher,entry.shjh_nowamount", new QFilter[]{Q1, Q2, Q3, Q4},"createtime desc"); + if (intbillBatchs.length > 0) { + DynamicObject intbillBatch = intbillBatchs[0]; + if (null != intbillBatch) { + DynamicObjectCollection entrys = intbillBatch.getDynamicObjectCollection("entry"); + for (DynamicObject entry : entrys) { + BigDecimal shjh_nowamount = entry.getBigDecimal("shjh_nowamount"); + if (shjh_nowamount != null) { + ymtotal = ymtotal.add(shjh_nowamount); + } + } + } + //购买时单位净值 + BigDecimal amount = finsubscribe.getBigDecimal("amount"); + // 计算计提收益 + jttotal = jttotal.add(buycopies.multiply(ymtotal.subtract(amount)).divide(new BigDecimal("1000"), 2, RoundingMode.HALF_UP)); + + } + } + // 根据条件设置值 + Map fieldMap = new HashMap<>(); + fieldMap.put("基准日期", "shjh_benchmarkamount"); + fieldMap.put("同年比较日期", "shjh_sameyearamount"); + fieldMap.put("上年比较日期", "shjh_previousyearamount"); + + //千元 + BigDecimal total = bjtotal.add(jttotal); + BigDecimal divisor = new BigDecimal("1000");//转换为千元 + // 进行除法运算并保留两位小数 + total = total.divide(divisor, 2, RoundingMode.HALF_UP); + + String field = fieldMap.get(type); + if (field != null) { + DynamicObject row3 = rowData.get(3);//理财 + row3.set(field, total);//理财申购单的本金+计提收益 + } + } + + + /** + * 定期:定期存款处理单的本金+计提利息(只考虑存款起息日<=基准等日期) + * @param date 基准等日期 + * @param rowData 行数据 + * @param type 日期类型 + */ + private void setDqAmount(Date date,DynamicObjectCollection rowData,String type){ + + //只考虑存款起息日<=基准等日期 + QFilter qFilter = new QFilter("intdate", QCP.less_equals, date); //存款起息日 <= 基准等日期 + + BigDecimal bjtotal = new BigDecimal("0");//定期存款处理单中本金总和 + BigDecimal jttotal = new BigDecimal("0");//计提收益 + // 定期存款处理单(存款起息日,存款金额,存款利率(%)) + DynamicObject[] finsubscribes = BusinessDataServiceHelper.load(CIM_DEPOSIT, "intdate,amount,interestrate", qFilter.toArray()); + for (DynamicObject finsubscribe : finsubscribes) { + + //1.本金: 汇总存款金额 (定期存款单本金) + BigDecimal amounts = finsubscribe.getBigDecimal("amount"); + if (amounts != null) { + bjtotal = bjtotal.add(amounts); + } + + //2.计提利息:(金额*定存利率*计提天数)/365 + BigDecimal amount = finsubscribe.getBigDecimal("amount"); + BigDecimal interestrate = finsubscribe.getBigDecimal("interestrate"); + if (amount != null && interestrate != null) { + Date intdate = finsubscribe.getDate("intdate"); + int days = (int) ((date.getTime() - intdate.getTime()) / (24 * 60 * 60 * 1000));//计提天数 + BigDecimal interest = amount.multiply(interestrate).multiply(BigDecimal.valueOf(days)) + .divide(BigDecimal.valueOf(365), 2, RoundingMode.HALF_UP); + jttotal = jttotal.add(interest);//汇总计提 + } + + } + + // 根据条件设置值 + Map fieldMap = new HashMap<>(); + fieldMap.put("基准日期", "shjh_benchmarkamount"); + fieldMap.put("同年比较日期", "shjh_sameyearamount"); + fieldMap.put("上年比较日期", "shjh_previousyearamount"); + + //千元 + BigDecimal total = bjtotal.add(jttotal); + BigDecimal divisor = new BigDecimal("1000");//转换为千元 + // 进行除法运算并保留两位小数 + total = total.divide(divisor, 2, RoundingMode.HALF_UP); + + String field = fieldMap.get(type); + if (field != null) { + DynamicObject row3 = rowData.get(4);//理财 + row3.set(field, total);//理财申购单的本金+计提收益 + } + } + /** + * 设置运营资金金额数据: 强共享 + 弱共享 + */ + private void setAmount(DynamicObjectCollection rowData) { + DynamicObject row0 = rowData.get(0);//运营资金 + DynamicObject row1 = rowData.get(1);//强共享 + DynamicObject row2 = rowData.get(2);//弱共享 + row0.set("shjh_benchmarkamount", row1.getBigDecimal("shjh_benchmarkamount").add(row2.getBigDecimal("shjh_benchmarkamount")));//基准日期(余额) + row0.set("shjh_sameyearamount", row1.getBigDecimal("shjh_sameyearamount").add(row2.getBigDecimal("shjh_sameyearamount")));//同年比较日期(余额) + row0.set("shjh_monthonmonthrate", row1.getBigDecimal("shjh_monthonmonthrate").add(row2.getBigDecimal("shjh_monthonmonthrate")));//环比 + row0.set("shjh_previousyearamount", row1.getBigDecimal("shjh_previousyearamount").add(row2.getBigDecimal("shjh_previousyearamount")));//上年比较日期(余额) + row0.set("shjh_yearonyear", row1.getBigDecimal("shjh_yearonyear").add(row2.getBigDecimal("shjh_yearonyear")));//同比 + } + + /** + * 设置合计数据:运营资金 + 理财 + 定期 + */ + private void setTotal(DynamicObjectCollection rowData) { + DynamicObject row5 = rowData.get(5);//合计 + DynamicObject row0 = rowData.get(0);//运营资金 + DynamicObject row3 = rowData.get(3);//2: 理财 + DynamicObject row4 = rowData.get(4);//3: 定期 + row5.set("shjh_benchmarkamount", row0.getBigDecimal("shjh_benchmarkamount").add(row3.getBigDecimal("shjh_benchmarkamount")).add(row4.getBigDecimal("shjh_benchmarkamount")));//基准日期(余额) + row5.set("shjh_sameyearamount", row0.getBigDecimal("shjh_sameyearamount").add(row3.getBigDecimal("shjh_sameyearamount")).add(row4.getBigDecimal("shjh_sameyearamount")));//同年比较日期(余额) + row5.set("shjh_monthonmonthrate", row0.getBigDecimal("shjh_monthonmonthrate").add(row3.getBigDecimal("shjh_monthonmonthrate")).add(row4.getBigDecimal("shjh_monthonmonthrate")));//环比 + row5.set("shjh_previousyearamount", row0.getBigDecimal("shjh_previousyearamount").add(row3.getBigDecimal("shjh_previousyearamount")).add(row4.getBigDecimal("shjh_previousyearamount")));//上年比较日期(余额) + row5.set("shjh_yearonyear", row0.getBigDecimal("shjh_yearonyear").add(row3.getBigDecimal("shjh_yearonyear")).add(row4.getBigDecimal("shjh_yearonyear")));//同比 + + } +} diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/report/BankBalanceSummaryQueryPlugin.java b/main/java/shjh/jhzj7/fi/fi/plugin/report/BankBalanceSummaryQueryPlugin.java new file mode 100644 index 0000000..4424905 --- /dev/null +++ b/main/java/shjh/jhzj7/fi/fi/plugin/report/BankBalanceSummaryQueryPlugin.java @@ -0,0 +1,33 @@ +package shjh.jhzj7.fi.fi.plugin.report; + +import kd.bos.algo.DataSet; +import kd.bos.entity.report.AbstractReportListDataPlugin; +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 java.util.ArrayList; +import java.util.List; + +/** + * 银行余额汇总报表 + * shjh_bankbalancesummary + */ +public class BankBalanceSummaryQueryPlugin extends AbstractReportListDataPlugin { + private static final Log log = LogFactory.getLog(BankBalanceSummaryQueryPlugin.class); + @Override + public DataSet query(ReportQueryParam reportQueryParam, Object o) throws Throwable { + List acctIds = new ArrayList(); + acctIds.add("CNY"); + acctIds.add("HKD"); + acctIds.add("JPY"); + acctIds.add("USD"); + acctIds.add("EUR"); + acctIds.add("GBP"); + QFilter qFilter = new QFilter("number", QCP.in, acctIds); + return QueryServiceHelper.queryDataSet(this.getClass().getName(), "bd_currency", null, qFilter.toArray(), null); + } +} diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/report/StrongSharingFormPlugin.java b/main/java/shjh/jhzj7/fi/fi/plugin/report/StrongSharingFormPlugin.java index 8be3f53..44cba06 100644 --- a/main/java/shjh/jhzj7/fi/fi/plugin/report/StrongSharingFormPlugin.java +++ b/main/java/shjh/jhzj7/fi/fi/plugin/report/StrongSharingFormPlugin.java @@ -3,15 +3,12 @@ package shjh.jhzj7.fi.fi.plugin.report; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.entity.report.ReportQueryParam; +import kd.bos.logging.Log; +import kd.bos.logging.LogFactory; 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; /** * 报表界面插件 @@ -19,6 +16,8 @@ import java.util.concurrent.TimeUnit; */ public class StrongSharingFormPlugin extends AbstractReportFormPlugin implements Plugin { + private static final Log log = LogFactory.getLog(StrongSharingFormPlugin.class); + @Override public void processRowData(String gridPK, DynamicObjectCollection rowData, ReportQueryParam queryParam) { super.processRowData(gridPK, rowData, queryParam); @@ -30,9 +29,14 @@ public class StrongSharingFormPlugin extends AbstractReportFormPlugin implements //银行名称(shjh_bankname)包含小计 汇总 (1.基准日期-余额(shjh_amountjz) 2.同年比较日期-余额(shjh_amounttn)) if (rowDatum.getString("shjh_bankname").contains("小计")) { BigDecimal amountjz = rowDatum.getBigDecimal("shjh_amountjz"); - shjh_amountjz = shjh_amountjz.add(amountjz);//基准日期-余额 + if (null != amountjz) { + shjh_amountjz = shjh_amountjz.add(amountjz);//基准日期-余额 + } BigDecimal amounttn = rowDatum.getBigDecimal("shjh_amounttn"); - shjh_amounttn = shjh_amounttn.add(amounttn);//同年比较日期-余额 + if (null != amounttn) { + shjh_amounttn = shjh_amounttn.add(amounttn);//同年比较日期-余额 + + } } } DynamicObject dynamicObject = new DynamicObject(rowData.getDynamicObjectType()); diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/report/StrongSharingQueryPlugin.java b/main/java/shjh/jhzj7/fi/fi/plugin/report/StrongSharingQueryPlugin.java index b103e60..c3a9a83 100644 --- a/main/java/shjh/jhzj7/fi/fi/plugin/report/StrongSharingQueryPlugin.java +++ b/main/java/shjh/jhzj7/fi/fi/plugin/report/StrongSharingQueryPlugin.java @@ -1,9 +1,6 @@ package shjh.jhzj7.fi.fi.plugin.report; import kd.bos.algo.DataSet; -import kd.bos.algo.GroupbyDataSet; -import kd.bos.cache.database.DataType; -import kd.bos.dataentity.entity.DynamicObject; import kd.bos.entity.report.AbstractReportListDataPlugin; import kd.bos.entity.report.FilterInfo; import kd.bos.entity.report.ReportQueryParam; @@ -11,7 +8,6 @@ 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.BusinessDataServiceHelper; import kd.bos.servicehelper.QueryServiceHelper; import kd.sdk.plugin.Plugin; @@ -24,10 +20,10 @@ import java.util.Date; public class StrongSharingQueryPlugin extends AbstractReportListDataPlugin implements Plugin { // 交易明细单据编码 - private static String BEI_INTELPAY = "bei_intelpay"; + public static final String BEI_INTELPAY = "bei_intelpay"; //合作金融机构 - private static String BD_FINORGINFO = "bd_finorginfo"; - private static Log log = LogFactory.getLog(StrongSharingQueryPlugin.class); + private static final String BD_FINORGINFO = "bd_finorginfo"; + private static final Log log = LogFactory.getLog(StrongSharingQueryPlugin.class); @Override public DataSet query(ReportQueryParam reportQueryParam, Object o) throws Throwable {