资金日表取数逻辑更新

This commit is contained in:
zengweihai 2024-08-09 11:22:39 +08:00
parent 61dbe850d2
commit dc644ca975
2 changed files with 225 additions and 156 deletions

View File

@ -9,6 +9,7 @@ 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.ORM;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
@ -33,32 +34,169 @@ public class CapitalDayListDataPlugin extends AbstractReportListDataPlugin imple
@Override
public DataSet query(ReportQueryParam reportQueryParam, Object o) throws Throwable {
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};//字段类型数组
//获取过滤条件集合
Map<String, Object> paramMap = this.transQueryParam(reportQueryParam);
DynamicObjectCollection companys = (DynamicObjectCollection)paramMap.get("shkd_filter_company");//使用组织集合
DynamicObjectCollection groups = (DynamicObjectCollection)paramMap.get("shkd_filter_group");//使用组织集合
String shkd_queryorgtype = paramMap.get("shkd_queryorgtype").toString();//使用组织集合
ArrayList<Long> longs = new ArrayList<>();
String groupName = null;
//如果查询是查的集团然后想要查询需查询下级及下级所有公司的id
if("group".equals(shkd_queryorgtype)){
ArrayList<Long> grouplongs = new ArrayList<>();
for (DynamicObject group : groups) {
groupName = group.getString("name");
grouplongs.add(group.getLong("id"));
}
List<Long> allSubordinateOrgs = OrgUnitServiceHelper.getAllSubordinateOrgs(8L, grouplongs, true);
longs.addAll(allSubordinateOrgs);
}else{
for (DynamicObject company : companys) {
longs.add(company.getLong("id"));
}
}
Collection<Object[]> firmParams = null ;
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");
ArrayList<Long> longs = new ArrayList<>();
String groupName = null;
//如果查询是查的集团然后想要查询需查询下级及下级所有公司的id
if("group".equals(shkd_queryorgtype)){
for (DynamicObject group : groups) {
longs.clear();//清除数据
ArrayList<Long> grouplongs = new ArrayList<>();
groupName = group.getString("name");
grouplongs.add(group.getLong("id"));
List<Long> allSubordinateOrgs = OrgUnitServiceHelper.getAllSubordinateOrgs(8L, grouplongs, true);
String shkd_iscontainyy = paramMap.get("shkd_iscontainyy").toString();//是否包含榆叶
if ("0".equals(shkd_iscontainyy)){
for (Long allSubordinateOrg : allSubordinateOrgs) {
DynamicObject bos_org = BusinessDataServiceHelper.loadSingle(allSubordinateOrg, "bos_org");
String shkd_affiliation = bos_org.getString("shkd_affiliation");
if ("1".equals(shkd_affiliation)){
longs.add(allSubordinateOrg);
}
}
firmParams = this.addFirmParams(shkd_queryorgtype,firmParams,groupName,longs,firstDate,endDate,orgcurrency,exratetable);
}else {
longs.addAll(allSubordinateOrgs);
firmParams = this.addFirmParams(shkd_queryorgtype,firmParams,groupName,longs,firstDate,endDate,orgcurrency,exratetable);
}
}
}else{
for (DynamicObject company : companys) {
longs.add(company.getLong("id"));
}
firmParams = this.addFirmParams(shkd_queryorgtype,firmParams,null,longs,firstDate,endDate,orgcurrency,exratetable);
}
int i = 0;
if(firmParams != null && firmParams.size() > 0){
for (Object[] firmParam : firmParams) {
firmParam[0] = i+1;
i++;
}
}
RowMeta row = RowMetaFactory.createRowMeta(fileNames, dataTypes);
CollectionInput inputs = new CollectionInput(row, firmParams);
DataSet resultDataSet = Algo.create(this.getClass().getName()).createDataSet(inputs);
return resultDataSet;
}
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;
}
//内部往来收款单组装
public BigDecimal getTransactions(DynamicObject[] per_cas_recbills){
BigDecimal recAmountTotal = BigDecimal.ZERO;
for (DynamicObject per_cas_recbill : per_cas_recbills) {
//查询收款单为内部往来的公司
String payertype = per_cas_recbill.getString("payertype");//付款人类型
if("bd_customer".equals(payertype)||"bd_supplier".equals(payertype)||"bos_org".equals(payertype)){
if("bd_supplier".equals(payertype)){
DynamicObject f7_payer = per_cas_recbill.getDynamicObject("f7_payer");//供应商
long id = f7_payer.getLong("id");
QFilter per_recQF = new QFilter("billstatus", QCP.equals, "D");
per_recQF.and("org.id",QCP.equals,id);
DynamicObject bd_supplier = BusinessDataServiceHelper.loadSingle("bd_supplier", "id,number,internal_company", per_recQF.toArray());
DynamicObject internal_company = bd_supplier.getDynamicObject("internal_company");
if(internal_company==null){
continue;
}
} else if ("bd_customer".equals(payertype)) {
DynamicObject customerf7 = per_cas_recbill.getDynamicObject("customerf7");//供应商
long id = customerf7.getLong("id");
QFilter per_recQF = new QFilter("billstatus", QCP.equals, "D");
per_recQF.and("org.id",QCP.equals,id);
DynamicObject bd_supplier = BusinessDataServiceHelper.loadSingle("bd_supplier", "id,number,internal_company", per_recQF.toArray());
DynamicObject internal_company = bd_supplier.getDynamicObject("internal_company");
if(internal_company==null){
continue;
}
}
BigDecimal actrecamt = per_cas_recbill.getBigDecimal("actrecamt");
recAmountTotal = recAmountTotal.add(actrecamt);//添加收入金额
}
}
return recAmountTotal;
}
//内部往来付款合计
public BigDecimal getTransactionsByfk(DynamicObject[] per_cas_paybills){
BigDecimal perPayAmountTotal = BigDecimal.ZERO;
for (DynamicObject per_cas_paybill : per_cas_paybills) {
//查询收款单为内部往来的公司
String payertype = per_cas_paybill.getString("payeetype");//收款人款人类型
Long payerid = per_cas_paybill.getLong("payee");//供应商
if("bd_customer".equals(payertype)||"bd_supplier".equals(payertype)||"bos_org".equals(payertype)){
if("bd_supplier".equals(payertype)){
QFilter per_recQF = new QFilter("id",QCP.equals,payerid);
DynamicObject bd_supplier = BusinessDataServiceHelper.loadSingle("bd_supplier", "id,number,internal_company", per_recQF.toArray());
DynamicObject internal_company = bd_supplier.getDynamicObject("internal_company");
if(internal_company==null){
continue;
}
} else if ("bd_customer".equals(payertype)) {
QFilter per_recQF = new QFilter("org.id",QCP.equals,payerid);
DynamicObject bd_supplier = BusinessDataServiceHelper.loadSingle("bd_supplier", "id,number,internal_company", per_recQF.toArray());
DynamicObject internal_company = bd_supplier.getDynamicObject("internal_company");
if(internal_company==null){
continue;
}
}
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)){//当付款编码同收款编码时
perPayAmountTotal = perPayAmountTotal.add(actpayamt);//补充收款数据
}
}
}
return perPayAmountTotal;
}
public Collection<Object[]> addFirmParams(String shkd_queryorgtype, Collection<Object[]> firmParams, String groupName, List<Long> longs, Date firstDate,Date endDate,DynamicObject orgcurrency, DynamicObject exratetable){
Long orgcurrencyId = null;
Long exratetableId = null;
if (orgcurrency != null){
@ -69,18 +207,12 @@ public class CapitalDayListDataPlugin extends AbstractReportListDataPlugin imple
}
// 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);//多公司数据集合
BigDecimal payTotal = BigDecimal.ZERO; //总计 期间支出合计
@ -89,14 +221,14 @@ public class CapitalDayListDataPlugin extends AbstractReportListDataPlugin imple
BigDecimal recLB = BigDecimal.ZERO; //内部往来 期间收入合计
BigDecimal payNet = BigDecimal.ZERO;//支出净额
BigDecimal recNet = BigDecimal.ZERO;//收入净额
for (int i = 0; i < cas_cashmgtinits.length; i++) {
//若是集团需要在第一行拼接第一行的数据
if("group".equals(shkd_queryorgtype)&&i == 0){
if("group".equals(shkd_queryorgtype)&& cas_cashmgtinits.length > 0){
Object[] firmParam = new Object[7];//存放公司数据
firmParam[0] = i;//存放序号
firmParam[1] = groupName;//存放集团名称,先优先考虑单集团的凭借
firmParams.add(firmParam);
}
for (int i = 0; i < cas_cashmgtinits.length; i++) {
DynamicObject startperiod = cas_cashmgtinits[i].getDynamicObject("startperiod");
if (startperiod != null){
Object pkValue = startperiod.getPkValue();
@ -107,7 +239,6 @@ public class CapitalDayListDataPlugin extends AbstractReportListDataPlugin imple
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");
@ -229,6 +360,7 @@ public class CapitalDayListDataPlugin extends AbstractReportListDataPlugin imple
}
}
if ("group".equals(shkd_queryorgtype)&& cas_cashmgtinits.length > 0){
//总计行的组装
Object[] firmParam = new Object[7];//存放公司数据
firmParam[1] = "总计";
@ -244,118 +376,15 @@ public class CapitalDayListDataPlugin extends AbstractReportListDataPlugin imple
//内部收支净额的组装
Object[] firmParam3 = new Object[7];//存放内部往来数据
firmParam3[1] = "收支净额";
firmParam3[3] = recTotal.subtract(recLB); //收入内部往来合计
firmParam3[4] = payTotal.subtract(payLB); //支出内部往来合计
recNet = recTotal.subtract(recLB);//收入净额
payNet = payTotal.subtract(payLB);//支出净额
firmParam3[3] = recNet; //收入内部往来合计
firmParam3[4] = payNet; //支出内部往来合计
firmParams.add(firmParam3);
}
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 firmParams;
}
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;
}
//内部往来收款单组装
public BigDecimal getTransactions(DynamicObject[] per_cas_recbills){
BigDecimal recAmountTotal = BigDecimal.ZERO;
for (DynamicObject per_cas_recbill : per_cas_recbills) {
//查询收款单为内部往来的公司
String payertype = per_cas_recbill.getString("payertype");//付款人类型
if("bd_customer".equals(payertype)||"bd_supplier".equals(payertype)||"bos_org".equals(payertype)){
if("bd_supplier".equals(payertype)){
DynamicObject f7_payer = per_cas_recbill.getDynamicObject("f7_payer");//供应商
long id = f7_payer.getLong("id");
QFilter per_recQF = new QFilter("billstatus", QCP.equals, "D");
per_recQF.and("org.id",QCP.equals,id);
DynamicObject bd_supplier = BusinessDataServiceHelper.loadSingle("bd_supplier", "id,number,internal_company", per_recQF.toArray());
DynamicObject internal_company = bd_supplier.getDynamicObject("internal_company");
if(internal_company==null){
continue;
}
} else if ("bd_customer".equals(payertype)) {
DynamicObject customerf7 = per_cas_recbill.getDynamicObject("customerf7");//供应商
long id = customerf7.getLong("id");
QFilter per_recQF = new QFilter("billstatus", QCP.equals, "D");
per_recQF.and("org.id",QCP.equals,id);
DynamicObject bd_supplier = BusinessDataServiceHelper.loadSingle("bd_supplier", "id,number,internal_company", per_recQF.toArray());
DynamicObject internal_company = bd_supplier.getDynamicObject("internal_company");
if(internal_company==null){
continue;
}
}
BigDecimal actrecamt = per_cas_recbill.getBigDecimal("actrecamt");
recAmountTotal = recAmountTotal.add(actrecamt);//添加收入金额
}
}
return recAmountTotal;
}
//内部往来付款合计
public BigDecimal getTransactionsByfk(DynamicObject[] per_cas_paybills){
BigDecimal perPayAmountTotal = BigDecimal.ZERO;
for (DynamicObject per_cas_paybill : per_cas_paybills) {
//查询收款单为内部往来的公司
String payertype = per_cas_paybill.getString("payeetype");//收款人款人类型
Long payerid = per_cas_paybill.getLong("payee");//供应商
if("bd_customer".equals(payertype)||"bd_supplier".equals(payertype)||"bos_org".equals(payertype)){
if("bd_supplier".equals(payertype)){
QFilter per_recQF = new QFilter("id",QCP.equals,payerid);
DynamicObject bd_supplier = BusinessDataServiceHelper.loadSingle("bd_supplier", "id,number,internal_company", per_recQF.toArray());
DynamicObject internal_company = bd_supplier.getDynamicObject("internal_company");
if(internal_company==null){
continue;
}
} else if ("bd_customer".equals(payertype)) {
QFilter per_recQF = new QFilter("org.id",QCP.equals,payerid);
DynamicObject bd_supplier = BusinessDataServiceHelper.loadSingle("bd_supplier", "id,number,internal_company", per_recQF.toArray());
DynamicObject internal_company = bd_supplier.getDynamicObject("internal_company");
if(internal_company==null){
continue;
}
}
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)){//当付款编码同收款编码时
perPayAmountTotal = perPayAmountTotal.add(actpayamt);//补充收款数据
}
}
}
return perPayAmountTotal;
}
}

View File

@ -1,8 +1,11 @@
package shkd.fi.cas.report.form;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.resource.ResManager;
import kd.bos.entity.datamodel.events.ChangeData;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.entity.report.FilterInfo;
import kd.bos.entity.report.ReportQueryParam;
import kd.bos.filter.FilterColumn;
import kd.bos.form.control.events.FilterContainerInitEvent;
@ -52,6 +55,7 @@ public class CapitalDayFormListPlugin extends AbstractReportFormPlugin implement
String shkd_queryorgtype = (String) this.getModel().getValue("shkd_queryorgtype");
if ("company".equals(shkd_queryorgtype)){
this.getView().setVisible(false,"shkd_filter_group");
this.getView().setVisible(false,"shkd_iscontainyy");
}else if ("group".equals(shkd_queryorgtype)){
this.getView().setVisible(false,"shkd_filter_company");
}
@ -89,12 +93,48 @@ public class CapitalDayFormListPlugin extends AbstractReportFormPlugin implement
if ("company".equals(newValue)){
this.getModel().setValue("shkd_filter_group",null);
this.getView().setVisible(false,"shkd_filter_group");
this.getView().setVisible(false,"shkd_iscontainyy");
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");
this.getView().setVisible(true,"shkd_iscontainyy");
}
}
}
/**
* 校验过滤条件
* @param queryParam
* @return
*/
@Override
public boolean verifyQuery(ReportQueryParam queryParam) {
FilterInfo filterInfo = queryParam.getFilter();
String shkd_queryorgtype = (String)this.getModel().getValue("shkd_queryorgtype");
if (filterInfo != null) {
// 判断集团或公司是否为空
if("company".equals(shkd_queryorgtype)){//当类型为公司时校验使用公司不为空
DynamicObjectCollection company = (DynamicObjectCollection)filterInfo.getValue("shkd_filter_company");
if (company == null || company.isEmpty()){
this.getView().showTipNotification("使用公司条件不能为空!");
return false;
}
}else if ("group".equals(shkd_queryorgtype)){//当类型为集团时校验使用集团不为空
DynamicObjectCollection group = (DynamicObjectCollection)filterInfo.getValue("shkd_filter_group");
if (group == null || group.isEmpty()){
this.getView().showTipNotification("使用集团条件不能为空!");
return false;
}
}
//判断币别不为空
// DynamicObject shkd_orgcurrency = (DynamicObject)filterInfo.getValue("shkd_orgcurrency");
// if (shkd_orgcurrency == null) {
// this.getView().showTipNotification("币别不能为空!");
// return false;
// }
}
return super.verifyQuery(queryParam);
}
}