diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/report/StrongOperateFormPlugin.java b/main/java/shjh/jhzj7/fi/fi/plugin/report/StrongOperateFormPlugin.java new file mode 100644 index 0000000..0107719 --- /dev/null +++ b/main/java/shjh/jhzj7/fi/fi/plugin/report/StrongOperateFormPlugin.java @@ -0,0 +1,59 @@ +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; + +/** + * 报表界面插件 + * 强共享营运资金分布情况汇总表界面插件 + */ +public class StrongOperateFormPlugin extends AbstractReportFormPlugin implements Plugin { + + private static final Log log = LogFactory.getLog(StrongOperateFormPlugin.class); + + @Override + public void processRowData(String gridPK, DynamicObjectCollection rowData, ReportQueryParam queryParam) { + super.processRowData(gridPK, rowData, queryParam); + + //1.计算合计 + BigDecimal shjh_amountjz = new BigDecimal("0");//合计_基准日期-余额 + for (DynamicObject rowDatum : rowData) { + //合计资金合计(元) + BigDecimal amountjz = rowDatum.getBigDecimal("shjh_amountjz"); + if (null != amountjz) { + shjh_amountjz = shjh_amountjz.add(amountjz);//基准日期-余额 + } + } + DynamicObject dynamicObject = new DynamicObject(rowData.getDynamicObjectType()); + dynamicObject.set("shjh_bankname", "合计");//组织编码 + dynamicObject.set("shjh_amountjz", shjh_amountjz); + dynamicObject.set("shjh_percentage", null); + rowData.add(dynamicObject); + //2.计算每行 资金合计(元) 占比 + for (DynamicObject rowDatum : rowData) { + //合计资金合计(元) + BigDecimal amountjz = rowDatum.getBigDecimal("shjh_amountjz"); + if (null != amountjz) { + //资金合计(元)占比 + // 先乘 100 再相除并保留两位小数 + BigDecimal amountjz_zb = new BigDecimal("0"); + if (shjh_amountjz.compareTo(BigDecimal.ZERO) != 0) { + // 先乘 100 再相除并保留两位小数 + amountjz_zb = amountjz.multiply(new BigDecimal("100")).divide(shjh_amountjz, 2, RoundingMode.HALF_UP); + System.out.println("百分比结果: " + amountjz_zb + "%"); + } else { + System.out.println("除数不能为 0,无法进行计算。"); + } + rowDatum.set("shjh_percentage", amountjz_zb); + } + } + } +} diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/report/StrongOperateQueryPlugin.java b/main/java/shjh/jhzj7/fi/fi/plugin/report/StrongOperateQueryPlugin.java new file mode 100644 index 0000000..8f36e17 --- /dev/null +++ b/main/java/shjh/jhzj7/fi/fi/plugin/report/StrongOperateQueryPlugin.java @@ -0,0 +1,91 @@ +package shjh.jhzj7.fi.fi.plugin.report; + +import kd.bos.algo.DataSet; +import kd.bos.entity.report.AbstractReportListDataPlugin; +import kd.bos.entity.report.FilterInfo; +import kd.bos.entity.report.ReportQueryParam; +import kd.bos.orm.query.QCP; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.QueryServiceHelper; +import kd.sdk.plugin.Plugin; + +import java.util.Date; + +/** + * 强共享营运资金分布情况汇总表 + * shjh_strongoperatereport + */ +public class StrongOperateQueryPlugin extends AbstractReportListDataPlugin implements Plugin { + + // 交易明细单据编码 + public static final String BEI_INTELPAY = "bei_intelpay"; + + @Override + public DataSet query(ReportQueryParam reportQueryParam, Object o) throws Throwable { + + FilterInfo filter = reportQueryParam.getFilter(); + Date shjh_basedate = filter.getDate("shjh_basedate");//基准日期 + QFilter q1 = new QFilter("bizdate", QCP.equals, shjh_basedate);//交易日期 + QFilter q2 = new QFilter("company.shjh_isshare", QCP.equals, "1");//公司属性为强共享 + + DataSet result = null; + // 被动付款入账 + DataSet beiIntelpay1 = QueryServiceHelper.queryDataSet(this.getClass().getName(), BEI_INTELPAY, + "id,billno as shjh_billno,company.number as shjh_orgnumber,company.name as shjh_orgname," + + "bank.number as banknumber,biztime as shjh_biztime,transbalance as shjh_amountjz,accountbank.id as accountbankid," + + "company.shjh_isshare as shjh_companyisshare", + new QFilter[]{q1, q2}, null); + // 合作金融机构 bd_finorginfo + DataSet bdAccountbanks1 = QueryServiceHelper.queryDataSet(this.getClass().getName(), + "bd_finorginfo", "id,number as finorginfonumber,bank_cate.name as shjh_bankname", null, null); + + try { + // 去重处理 + DataSet distinctBeiIntelpay = beiIntelpay1.distinct(); + DataSet distinctBdAccountbanks = bdAccountbanks1.distinct(); + + // 根据被动付款入账 开户银行 银行类别(查所有满足日期的交易明细) + DataSet joinedDataSet = distinctBeiIntelpay.join(distinctBdAccountbanks) + .on("banknumber", "finorginfonumber") + .select(new String[]{"shjh_billno", "shjh_orgnumber", "shjh_orgname", "shjh_bankname", "banknumber", + "shjh_biztime", "shjh_amountjz", "accountbankid","shjh_companyisshare"}) + .finish(); + + // 按银行账户id分组,取最大日期的集合 + DataSet maxBizdate = joinedDataSet.groupBy(new String[]{"accountbankid"}) + .max("shjh_biztime") + .finish(); + + // 分组后和源集合联表:除账户id,日期的其他字段进行组合返回前台 + DataSet result1 = joinedDataSet.join(maxBizdate) + .on("accountbankid", "accountbankid") + .on("shjh_biztime", "shjh_biztime") + .select(new String[]{"shjh_billno", "shjh_orgnumber", "shjh_orgname", "shjh_bankname", "banknumber", + "shjh_biztime", "shjh_amountjz","accountbankid","shjh_companyisshare"}) + .finish(); + + // 再次根据银行编码分组 求和余额 + result = result1.groupBy(new String[]{"shjh_orgnumber", "shjh_orgname", "shjh_bankname","banknumber","shjh_companyisshare"}).sum("shjh_amountjz").finish(); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + // 确保在操作完成后关闭数据集 + if (beiIntelpay1 != null) { + try { + beiIntelpay1.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + if (bdAccountbanks1 != null) { + try { + bdAccountbanks1.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + return result; + } +}