报表表单和取数插件提交

This commit is contained in:
zengweihai 2024-08-02 19:38:33 +08:00
parent a50bafde7e
commit 48f4a4ccae
2 changed files with 379 additions and 0 deletions

View File

@ -0,0 +1,279 @@
package shkd.fi.cas.report.data;
import kd.bos.algo.*;
import kd.bos.algo.input.CollectionInput;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
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.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.*;
/**
* 报表取数插件
*/
public class CapitalDayListDataPlugin extends AbstractReportListDataPlugin implements Plugin {
private static final Log logger = LogFactory.getLog(CapitalDayDataListShkdPlugin.class);
@Override
public DataSet query(ReportQueryParam reportQueryParam, Object o) throws Throwable {
//获取过滤条件集合
Map<String, Object> paramMap = this.transQueryParam(reportQueryParam);
DynamicObjectCollection companys = (DynamicObjectCollection)paramMap.get("shkd_filter_company");//使用组织集合
ArrayList<Long> longs = new ArrayList<>();
for (DynamicObject company : companys) {
longs.add(company.getLong("id"));
}
Date firstDate = (Date)paramMap.get("shkd_firstdate");//开始时间
Date endDate = (Date)paramMap.get("shkd_enddate");//结束时间
DynamicObject orgcurrency = (DynamicObject) paramMap.get("shkd_orgcurrency");
DynamicObject exratetable = (DynamicObject) paramMap.get("shkd_exratetable");
Long orgcurrencyId = null;
Long exratetableId = null;
if (orgcurrency != null){
orgcurrencyId = orgcurrency.getLong("id");
}
if (exratetable != null){
exratetableId = exratetable.getLong("id");
}
// Long currency = ((DynamicObject)paramMap.get("orgcurrency")).getLong("id");//币别
// Long exchangeRateTableId = ((DynamicObject)paramMap.get("exratetable")).getLong("id");//汇率表
String[] fileNames = {"shkd_ordinal","shkd_company","shkd_init_original","shkd_income_original","shkd_expend_original",
"shkd_period_original","shkd_currencyfield"};//字段标识数组
DataType[] dataTypes = {DataType.StringType,DataType.StringType,DataType.BigDecimalType,DataType.BigDecimalType,DataType.BigDecimalType,
DataType.BigDecimalType,DataType.LongType};//字段类型数组
//查询已出纳初始化的公司
QFilter accQF = new QFilter("isfinishinit", QCP.equals, "1");//过滤为启用的公司账户
accQF.and("org.id",QCP.in,longs);
// accQF.and("org.name",QCP.equals,"上海挚新私募基金管理有限公司");
DynamicObject[] cas_cashmgtinits = BusinessDataServiceHelper.load("cas_cashmgtinit", "id,org,isfinishinit,startperiod,standardcurrency,exratetable," +
"entrybank.bank_accountbank,entrybank.bank_journalbalance,entrybank.bank_journalsumbalanceadj", accQF.toArray());
Collection<Object[]> firmParams = null;
if (cas_cashmgtinits != null){
firmParams = new ArrayList<Object[]>(cas_cashmgtinits.length);//多公司数据集合
for (int i = 0; i < cas_cashmgtinits.length; i++) {
DynamicObject startperiod = cas_cashmgtinits[i].getDynamicObject("startperiod");
if (startperiod != null){
Object pkValue = startperiod.getPkValue();
DynamicObject bd_period = BusinessDataServiceHelper.loadSingle(pkValue, "bd_period");
Date begindate = bd_period.getDate("begindate");//获取期初时间
DynamicObject org = cas_cashmgtinits[i].getDynamicObject("org");
if (org != null){//当前组织不为空时,查询对应付款单和收款单计算收入
Object[] firmParam = new Object[7];//存放公司数据
String name = org.getString("name");
Object orgPkValue = org.getPkValue();
firmParam[0] = i+1;//存放序号
firmParam[1] = name;//存放公司名称
//获取初始金额之和及日记账余额之和
DynamicObjectCollection entrybank = cas_cashmgtinits[i].getDynamicObjectCollection("entrybank");
BigDecimal journalbalance_total = BigDecimal.ZERO;//日记账初始余额之和
for (DynamicObject dynamicObject : entrybank) {//计算各银行账号金额之和
BigDecimal bank_journalbalance = dynamicObject.getBigDecimal("bank_journalbalance");
journalbalance_total = journalbalance_total.add(bank_journalbalance);//日记账初始余额之和
}
BigDecimal payAmountTotal = BigDecimal.ZERO;
BigDecimal recAmountTotal = BigDecimal.ZERO;
//逻辑1查询该公司到查询时间的所有付款单
QFilter bef_payQF = new QFilter("billstatus", QCP.equals, "D");
bef_payQF.and("org.id",QCP.equals,orgPkValue);
bef_payQF.and("paydate",QCP.large_equals,begindate);
if (firstDate == null){//没有设置时间则查询今日记账,即查询期间开始到今日之前的所有付款单据
firstDate = new Date();
}
if (exratetable != null){
bef_payQF.and("exratetable.id",QCP.equals,exratetableId);
}
if (orgcurrency != null){
bef_payQF.and("currency.id",QCP.equals,orgcurrencyId);
}
Date startDate = this.getStartDate(firstDate);//过滤条件-开始日期
bef_payQF.and("paydate","<",startDate);
DynamicObject[] bef_cas_paybills = BusinessDataServiceHelper.load("cas_paybill", "id,org,org.id,org.number,payeenumber,actpayamt,currency", bef_payQF.toArray());
for (DynamicObject bef_cas_paybill : bef_cas_paybills) {
String payNumber = bef_cas_paybill.getDynamicObject("org").getString("number");
String recNumber = bef_cas_paybill.getString("payeenumber");
logger.info("付款方编码为:"+payNumber+",收款方编码为:"+recNumber);
BigDecimal actpayamt = bef_cas_paybill.getBigDecimal("actpayamt");
if (!payNumber.equals(recNumber)){//付款编码同收款编码的忽略相互抵消
payAmountTotal = payAmountTotal.add(actpayamt);
}
}
//逻辑2查询该公司到查询时间的所有收款单
QFilter bef_recQF = new QFilter("billstatus", QCP.equals, "D");
if (exratetable != null){
bef_recQF.and("exratetable.id",QCP.equals,exratetableId);
}
if (orgcurrency != null){
bef_recQF.and("currency.id",QCP.equals,orgcurrencyId);
}
bef_recQF.and("org.id",QCP.equals,orgPkValue);
bef_recQF.and("payeedate",QCP.large_equals,begindate);
bef_recQF.and("payeedate","<",startDate);
DynamicObject[] cas_recbills = BusinessDataServiceHelper.load("cas_recbill", "id,org,org.id,org.number,actrecamt,currency", bef_recQF.toArray());
for (DynamicObject cas_recbill : cas_recbills) {
BigDecimal actrecamt = cas_recbill.getBigDecimal("actrecamt");
recAmountTotal = recAmountTotal.add(actrecamt);
}
//期初余额 = 初始余额 + 期初前收入 - 期初前支出
BigDecimal startAmount = journalbalance_total.add(recAmountTotal).subtract(payAmountTotal);
firmParam[2] = startAmount;
if (endDate == null){
endDate = new Date();//赋值结束时间
}
Date overDate = this.getEndDate(endDate);//取到当天结束日期
BigDecimal perPayAmountTotal = BigDecimal.ZERO;//期间总支出
BigDecimal perRecAmountTotal = BigDecimal.ZERO;//期间总收入
//逻辑3查询该公司期间总收入
QFilter per_recQF = new QFilter("billstatus", QCP.equals, "D");
per_recQF.and("org.id",QCP.equals,orgPkValue);
if (exratetable != null){
per_recQF.and("exratetable.id",QCP.equals,exratetableId);
}
if (orgcurrency != null){
per_recQF.and("currency.id",QCP.equals,orgcurrencyId);
}
per_recQF.and("payeedate",QCP.large_equals,startDate);
per_recQF.and("payeedate",QCP.less_equals,overDate);
DynamicObject[] per_cas_recbills = BusinessDataServiceHelper.load("cas_recbill", "id,org,org.id,org.number,actrecamt,currency", per_recQF.toArray());
for (DynamicObject per_cas_recbill : per_cas_recbills) {
BigDecimal actrecamt = per_cas_recbill.getBigDecimal("actrecamt");
perRecAmountTotal = perRecAmountTotal.add(actrecamt);//添加收入金额
}
firmParam[3] = perRecAmountTotal;
//逻辑4查询该公司期间总支出
QFilter per_payQF = new QFilter("billstatus", QCP.equals, "D");
if (exratetable != null){
per_payQF.and("exratetable.id",QCP.equals,exratetableId);
}
if (orgcurrency != null){
per_payQF.and("currency.id",QCP.equals,orgcurrencyId);
}
per_payQF.and("org.id",QCP.equals,orgPkValue);
per_payQF.and("paydate",QCP.large_equals,startDate);
per_payQF.and("paydate",QCP.less_equals,overDate);
DynamicObject[] per_cas_paybills = BusinessDataServiceHelper.load("cas_paybill", "id,org,org.id,org.number,payeenumber,actpayamt,currency", per_payQF.toArray());
for (DynamicObject per_cas_paybill : per_cas_paybills) {
String payNumber = per_cas_paybill.getDynamicObject("org").getString("number");
String recNumber = per_cas_paybill.getString("payeenumber");
BigDecimal actpayamt = per_cas_paybill.getBigDecimal("actpayamt");
perPayAmountTotal = perPayAmountTotal.add(actpayamt);
if (payNumber.equals(recNumber)){//当付款编码同收款编码时
perRecAmountTotal = perRecAmountTotal.add(actpayamt);//补充收款数据
}
}
firmParam[4] = perPayAmountTotal;
//期间余额 = 期初余额 +期间收入 -期间支出
BigDecimal endAmount = startAmount.add(perRecAmountTotal).subtract(perPayAmountTotal);
firmParam[5] = endAmount;
firmParams.add(firmParam);
}
}
}
}
// Map<String, List<Map<String,Object>>> firm_accMap = new HashMap<String, List<Map<String, Object>>>(cas_cashmgtinits.length);//总体公司银行账户集合数据
// for (DynamicObject cas_cashmgtinit : cas_cashmgtinits) {
// DynamicObject org = cas_cashmgtinit.getDynamicObject("org");
// String name = org.getString("name");
// List<Map<String,Object>> firm_banks = new ArrayList<Map<String, Object>>();//银行账户集合
// DynamicObjectCollection entrybank = cas_cashmgtinit.getDynamicObjectCollection("entrybank");
// for (DynamicObject dynamicObject : entrybank) {
// Map<String,Object> bankInfo = new HashMap<String,Object>();//单个银行数据信息
// bankInfo.put("bank_accountbank_id",dynamicObject.getDynamicObject("bank_accountbank").getLong("id"));
// bankInfo.put("bank_journalbalance",dynamicObject.getBigDecimal("bank_journalbalance"));
// bankInfo.put("bank_journalsumbalanceadj",dynamicObject.getBigDecimal("bank_journalsumbalanceadj"));
// firm_banks.add(bankInfo);
// }
// firm_accMap.put(name,firm_banks);
// }
//2查询所有收款处理单据数据cas_recbill org收款人公司 accountbank银行账号 actrecamt收款金额
//3查询所有付款处理单据数据 org付款人公司 payeracctbank银行账号 payeename收款人名称 payeebanknum收款账号 actpayamt付款金额
// QFilter payQF = new QFilter();
// BusinessDataServiceHelper.load("cas_paybill",)
// Collection<Object[]> coll= new ArrayList<Object[]>();
// for (int i = 0;i < 3 ;i++ ){
// Object[] values = new Object[fileNames.length];
// values[0] = i+1;
// values[1] = "公司"+i;
// values[2] = 10+(int)Math.floor(Math.random()*100);
// values[3] = 10+(int)Math.floor(Math.random()*100);
// values[4] = 10+(int)Math.floor(Math.random()*100);
// values[5] = 10+(int)Math.floor(Math.random()*100);
// coll.add(values);
// }
// BigDecimal sum1 = BigDecimal.ZERO;
// BigDecimal sum2 = BigDecimal.ZERO;
// for (Object[] objects : coll) {
// sum1 = sum1.add(new BigDecimal(objects[3].toString()));
// sum2 = sum2.add(new BigDecimal(objects[4].toString()));
// }
// Object[] obj = new Object[fileNames.length];
// obj[1] = "期间汇总";
// obj[3] = sum1;
// obj[4] = sum2;
// coll.add(obj);
if (firmParams != null){
RowMeta row = RowMetaFactory.createRowMeta(fileNames, dataTypes);
CollectionInput inputs = new CollectionInput(row, firmParams);
DataSet resultDataSet = Algo.create(this.getClass().getName()).createDataSet(inputs);
return resultDataSet;
}
return null;
}
protected Map<String, Object> transQueryParam(ReportQueryParam param) {
Map<String, Object> paramMap = new HashMap(param.getFilter().getFilterItems().size());
Iterator var3 = param.getFilter().getFilterItems().iterator();
while(var3.hasNext()) {
FilterItemInfo filterItem = (FilterItemInfo)var3.next();
paramMap.put(filterItem.getPropName(), filterItem.getValue());
}
return paramMap;
}
public Date getStartDate (Date date){
LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDateTime startOfDay = LocalDateTime.of(localDate, LocalTime.MIN);
Date startDate = Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
return startDate;
}
public Date getEndDate (Date date){
LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDateTime startOfDay = LocalDateTime.of(localDate, LocalTime.MAX);
Date endOfDay = Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
return endOfDay;
}
}

View File

@ -0,0 +1,100 @@
package shkd.fi.cas.report.form;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.events.ChangeData;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.entity.report.ReportQueryParam;
import kd.bos.filter.FilterColumn;
import kd.bos.form.control.events.FilterContainerInitEvent;
import kd.bos.form.field.BasedataEdit;
import kd.bos.form.field.MulBasedataEdit;
import kd.bos.form.field.events.BeforeF7SelectEvent;
import kd.bos.form.field.events.BeforeF7SelectListener;
import kd.bos.form.field.events.BeforeFilterF7SelectEvent;
import kd.bos.list.ListShowParameter;
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.sdk.plugin.Plugin;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.EventObject;
/**
* 报表界面插件
*/
public class CapitalDayFormListPlugin extends AbstractReportFormPlugin implements BeforeF7SelectListener, Plugin {
@Override
public void registerListener(EventObject e) {
super.registerListener(e);
MulBasedataEdit edit = this.getView().getControl("shkd_filter_company");
MulBasedataEdit edit1 = this.getView().getControl("shkd_filter_group");
edit.addBeforeF7SelectListener(this);
edit1.addBeforeF7SelectListener(this);
}
/**
* 设置日期初始值及初始化公司集团字段显影控制
* @param e
*/
@Override
public void afterCreateNewData(EventObject e) {
super.afterCreateNewData(e);
//设置日期范围初始值
this.getModel().setValue("shkd_firstdate",new Date());
this.getModel().setValue("shkd_enddate",new Date());
//始化公司集团字段显影控制
String shkd_queryorgtype = (String) this.getModel().getValue("shkd_queryorgtype");
if ("company".equals(shkd_queryorgtype)){
this.getView().setVisible(false,"shkd_filter_group");
}else if ("group".equals(shkd_queryorgtype)){
this.getView().setVisible(false,"shkd_filter_company");
}
}
@Override
public void beforeF7Select(BeforeF7SelectEvent beforeF7SelectEvent) {
String name = beforeF7SelectEvent.getProperty().getName();
if ("shkd_filter_company".equals(name)){
QFilter accQF = new QFilter("isfinishinit", QCP.equals, "1");//过滤为启用的公司账户
DynamicObject[] cas_cashmgtinits = BusinessDataServiceHelper.load("cas_cashmgtinit", "id,org,isfinishinit,startperiod,standardcurrency,exratetable," +
"entrybank.bank_accountbank,entrybank.bank_journalbalance,entrybank.bank_journalsumbalanceadj", accQF.toArray());
ArrayList<Long> orgIds = new ArrayList<>();
for (DynamicObject cas_cashmgtinit : cas_cashmgtinits) {
orgIds.add( cas_cashmgtinit.getLong("org.id"));
}
ListShowParameter formShowParameter = (ListShowParameter) beforeF7SelectEvent.getFormShowParameter();
QFilter payment_qf= new QFilter("id",QCP.in,orgIds);
formShowParameter.getListFilterParameter().setFilter(payment_qf);
}else if ("shkd_filter_group".equals(name)){
QFilter orgpattern_qf= new QFilter("orgpattern.number",QCP.equals, "Orgform01");
ListShowParameter formShowParameter = (ListShowParameter) beforeF7SelectEvent.getFormShowParameter();
formShowParameter.getListFilterParameter().setFilter(orgpattern_qf);
}
}
@Override
public void propertyChanged(PropertyChangedArgs e) {
super.propertyChanged(e);
String name = e.getProperty().getName();
if ("shkd_queryorgtype".equals(name)){
ChangeData[] changeSet = e.getChangeSet();
Object newValue = changeSet[0].getNewValue();
if ("company".equals(newValue)){
this.getModel().setValue("shkd_filter_group",null);
this.getView().setVisible(false,"shkd_filter_group");
this.getView().setVisible(true,"shkd_filter_company");
}else if ("group".equals(newValue)){
this.getModel().setValue("shkd_filter_company",null);
this.getView().setVisible(false,"shkd_filter_company");
this.getView().setVisible(true,"shkd_filter_group");
}
}
}
}