parent
							
								
									da1cff7235
								
							
						
					
					
						commit
						191ecc255f
					
				|  | @ -382,9 +382,9 @@ public class FinanceReportFormPlugin extends AbstractReportFormPlugin  implement | ||||||
|         BigDecimal shkd_jtnbjkrzcb=new BigDecimal(0);//⑩集团内部借款融资成本(%) |         BigDecimal shkd_jtnbjkrzcb=new BigDecimal(0);//⑩集团内部借款融资成本(%) | ||||||
|         BigDecimal shkd_jtnbjkqx=new BigDecimal(0);//⑩集团内部借款期限 |         BigDecimal shkd_jtnbjkqx=new BigDecimal(0);//⑩集团内部借款期限 | ||||||
|         for (DynamicObject rowDatum : rowData) { |         for (DynamicObject rowDatum : rowData) { | ||||||
|             shkd_jtnbjkamount.subtract(rowDatum.getBigDecimal("shkd_jtnbjkamount")); |             shkd_jtnbjkamount=shkd_jtnbjkamount.subtract(rowDatum.getBigDecimal("shkd_jtnbjkamount")); | ||||||
|             shkd_jtnbjkrzcb.subtract(rowDatum.getBigDecimal("shkd_jtnbjkrzcb")); |             shkd_jtnbjkrzcb=shkd_jtnbjkrzcb.subtract(rowDatum.getBigDecimal("shkd_jtnbjkrzcb")); | ||||||
|             shkd_jtnbjkqx.subtract(rowDatum.getBigDecimal("shkd_jtnbjkqx")); |             shkd_jtnbjkqx=shkd_jtnbjkqx.subtract(rowDatum.getBigDecimal("shkd_jtnbjkqx")); | ||||||
|         } |         } | ||||||
|         DynamicObject dynamicObject = new DynamicObject(rowData.getDynamicObjectType()); |         DynamicObject dynamicObject = new DynamicObject(rowData.getDynamicObjectType()); | ||||||
|         dynamicObject.set("shkd_org","合并抵消"); |         dynamicObject.set("shkd_org","合并抵消"); | ||||||
|  |  | ||||||
|  | @ -0,0 +1,334 @@ | ||||||
|  | package shkd.sys.sys.plugin.report; | ||||||
|  | 
 | ||||||
|  | import kd.bos.context.RequestContext; | ||||||
|  | import kd.bos.dataentity.entity.DynamicObject; | ||||||
|  | import kd.bos.dataentity.entity.DynamicObjectCollection; | ||||||
|  | import kd.bos.dataentity.entity.LocaleString; | ||||||
|  | import kd.bos.entity.datamodel.events.PackageDataEvent; | ||||||
|  | import kd.bos.entity.report.*; | ||||||
|  | import kd.bos.form.events.HyperLinkClickEvent; | ||||||
|  | import kd.bos.form.events.HyperLinkClickListener; | ||||||
|  | import kd.bos.orm.query.QCP; | ||||||
|  | import kd.bos.orm.query.QFilter; | ||||||
|  | import kd.bos.permission.api.HasPermOrgResult; | ||||||
|  | import kd.bos.report.ReportList; | ||||||
|  | import kd.bos.report.ReportShowParameter; | ||||||
|  | import kd.bos.report.events.CreateColumnEvent; | ||||||
|  | import kd.bos.report.filter.ReportFilter; | ||||||
|  | import kd.bos.report.plugin.AbstractReportFormPlugin; | ||||||
|  | import kd.bos.servicehelper.BusinessDataServiceHelper; | ||||||
|  | import kd.bos.servicehelper.QueryServiceHelper; | ||||||
|  | import kd.bos.servicehelper.org.OrgUnitServiceHelper; | ||||||
|  | import kd.bos.servicehelper.org.OrgViewType; | ||||||
|  | import kd.bos.servicehelper.permission.PermissionServiceHelper; | ||||||
|  | import shkd.sys.sys.plugin.report.domain.FinanceVarietyEnum; | ||||||
|  | 
 | ||||||
|  | import java.math.BigDecimal; | ||||||
|  | import java.util.*; | ||||||
|  | 
 | ||||||
|  | public class FinanceReportfordateFormPlugin  extends AbstractReportFormPlugin implements HyperLinkClickListener { | ||||||
|  |     @Override | ||||||
|  |     public void hyperLinkClick(HyperLinkClickEvent hyperLinkClickEvent) { | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void packageData(PackageDataEvent evt) { | ||||||
|  | 
 | ||||||
|  |         if ("shkd_org".equals(((ReportColumn)evt.getSource()).getFieldKey())){ | ||||||
|  |             String formatValue = (String)evt.getFormatValue(); | ||||||
|  |             DynamicObject selorg = QueryServiceHelper.queryOne("bos_org", "id,name,number", (new QFilter("name", QCP.equals, formatValue)).toArray()); | ||||||
|  |             if (selorg==null){ | ||||||
|  |                 evt.getNoLinkKey().add(((ReportColumn)evt.getSource()).getFieldKey()); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |             Long pkValue = selorg.getLong("id"); | ||||||
|  |             List<Long> orgIds = new ArrayList<>(1); | ||||||
|  |             orgIds.add(pkValue); | ||||||
|  |             List<Long> allSubordinateOrgs = OrgUnitServiceHelper.getAllSubordinateOrgs(OrgViewType.OrgUnit, orgIds, false);//不包括自己 | ||||||
|  |             if (allSubordinateOrgs.size()==0){ | ||||||
|  |                 evt.getNoLinkKey().add(((ReportColumn)evt.getSource()).getFieldKey()); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void registerListener(EventObject e) { | ||||||
|  |         super.registerListener(e); | ||||||
|  |         this.addItemClickListeners("toolbarap"); | ||||||
|  |         ReportList reportlistap = this.getView().getControl("reportlistap"); | ||||||
|  |         reportlistap.addHyperClickListener(this::hyperLinkClick); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void initDefaultQueryParam(ReportQueryParam queryParam) { | ||||||
|  |         super.initDefaultQueryParam(queryParam); | ||||||
|  |         Boolean shkd_isone = (Boolean) this.getModel().getValue("shkd_isone");//是否在第一层 | ||||||
|  |         if (!shkd_isone){ | ||||||
|  |             ReportFilter filter = this.getView().getControl("reportfilterap");//调用页面的自动查询 | ||||||
|  |             queryParam.setFilter(filter.getReportQueryParam().getFilter()); | ||||||
|  |         } | ||||||
|  |         HasPermOrgResult userHasPermOrgs = PermissionServiceHelper.getUserHasPermOrgs(Long.parseLong(RequestContext.get().getUserId())); | ||||||
|  |         //有权的组织 | ||||||
|  |         List<Long> hasPermOrgs = userHasPermOrgs.getHasPermOrgs(); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |         if (hasPermOrgs.size()==0){ | ||||||
|  |             this.getModel().setValue("shkd_seluserpower", null); | ||||||
|  |         }else if (hasPermOrgs.size()!=0&&shkd_isone){//有组织权限隔离且在首层 | ||||||
|  |             //获取有权组织里级别高的根节点组织 | ||||||
|  |             List<Long> res=getSuperOrg(hasPermOrgs); | ||||||
|  |             Object[] longs = res.toArray(new Long[0]); | ||||||
|  |             this.getModel().setValue("shkd_seluserpower", longs); | ||||||
|  |         }else if (hasPermOrgs.size()!=0&&!shkd_isone){//有组织权限隔离但不在首层 | ||||||
|  |             this.getModel().setValue("shkd_seluserpower", null); | ||||||
|  |         } | ||||||
|  |         //是否全部组织有权 | ||||||
|  |         boolean hasallOrg = userHasPermOrgs.hasAllOrgPerm(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void afterBindData(EventObject e) { | ||||||
|  |         super.afterBindData(e); | ||||||
|  |         ReportShowParameter formShowParameter = (ReportShowParameter) this.getView().getFormShowParameter(); | ||||||
|  |         Object shkd_selorg = formShowParameter.getCustomParam("shkd_selorg"); | ||||||
|  |         Object shkd_seldate = formShowParameter.getCustomParam("shkd_seldate"); | ||||||
|  |         Object shkd_selmoney = formShowParameter.getCustomParam("shkd_selmoney"); | ||||||
|  |         if (shkd_selorg != null) { | ||||||
|  |             DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle((Long) shkd_selorg, "bos_org"); | ||||||
|  |             this.getView().getModel().setValue("shkd_selorg", dynamicObject); | ||||||
|  |             this.getView().getModel().setValue("shkd_seldate", shkd_seldate); | ||||||
|  |             this.getView().getModel().setValue("shkd_selmoney", shkd_selmoney); | ||||||
|  |             this.getView().getModel().setValue("shkd_isone", false); | ||||||
|  |             this.getView().getModel().setValue("shkd_seluserpower", null); | ||||||
|  |             ReportFilter filter = this.getView().getControl("reportfilterap");//调用页面的自动查询 | ||||||
|  |             filter.search(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void afterCreateColumn(CreateColumnEvent event) { | ||||||
|  |         super.afterCreateColumn(event); | ||||||
|  |         ReportQueryParam queryParam = event.getQueryParam(); | ||||||
|  |         FilterInfo filter = queryParam.getFilter(); | ||||||
|  |         String shkd_money = filter.getString("shkd_selmoney"); | ||||||
|  |         List<AbstractReportColumn> columns = event.getColumns(); | ||||||
|  |         getColumns( columns,shkd_money); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public List getColumns(List columns,String shkd_money) { | ||||||
|  |         //集团外债务融资 | ||||||
|  |         List<AbstractReportColumn> jtwzwrz = ((ReportColumnGroup) columns.get(3)).getChildren(); | ||||||
|  |         for (AbstractReportColumn child : jtwzwrz) { | ||||||
|  |             ReportColumnGroup reportColumnGroup= null; | ||||||
|  |             try { | ||||||
|  |                 reportColumnGroup = (ReportColumnGroup) child; | ||||||
|  |             } catch (Exception e) { | ||||||
|  |                 String localeValue_zh_cn = child.getCaption().getLocaleValue_zh_CN(); | ||||||
|  |                 if (localeValue_zh_cn.contains("金额")){ | ||||||
|  |                     LocaleString l = new LocaleString(); | ||||||
|  |                     l.put("zh_CN",localeValue_zh_cn+"("+ FinanceVarietyEnum.getshkd_selmoney(shkd_money)+")"); | ||||||
|  |                     child.setCaption(l); | ||||||
|  |                 } | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |             List<AbstractReportColumn> children = reportColumnGroup.getChildren(); | ||||||
|  |             for (AbstractReportColumn abstractReportColumn : children) { | ||||||
|  |                 String localeValue_zh_cn = abstractReportColumn.getCaption().getLocaleValue_zh_CN(); | ||||||
|  |                 if ("金额".contains(localeValue_zh_cn)){ | ||||||
|  |                     LocaleString l = new LocaleString(); | ||||||
|  |                     l.put("zh_CN",localeValue_zh_cn+"("+ FinanceVarietyEnum.getshkd_selmoney(shkd_money)+")"); | ||||||
|  |                     abstractReportColumn.setCaption(l); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         //集团内债务融资 | ||||||
|  |         List<AbstractReportColumn> jtnzwrz = ((ReportColumnGroup) columns.get(4)).getChildren(); | ||||||
|  |         for (AbstractReportColumn child : jtnzwrz) { | ||||||
|  |             ReportColumnGroup reportColumnGroup= null; | ||||||
|  |             try { | ||||||
|  |                 reportColumnGroup = (ReportColumnGroup) child; | ||||||
|  |             } catch (Exception e) { | ||||||
|  |                 String localeValue_zh_cn = child.getCaption().getLocaleValue_zh_CN(); | ||||||
|  |                 if (localeValue_zh_cn.contains("金额")){ | ||||||
|  |                     LocaleString l = new LocaleString(); | ||||||
|  |                     l.put("zh_CN",localeValue_zh_cn+"("+ FinanceVarietyEnum.getshkd_selmoney(shkd_money)+")"); | ||||||
|  |                     child.setCaption(l); | ||||||
|  |                 } | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |             List<AbstractReportColumn> children = reportColumnGroup.getChildren(); | ||||||
|  |             for (AbstractReportColumn abstractReportColumn : children) { | ||||||
|  |                 String localeValue_zh_cn = abstractReportColumn.getCaption().getLocaleValue_zh_CN(); | ||||||
|  |                 if ("金额".contains(localeValue_zh_cn)){ | ||||||
|  |                     LocaleString l = new LocaleString(); | ||||||
|  |                     l.put("zh_CN",localeValue_zh_cn+"("+ FinanceVarietyEnum.getshkd_selmoney(shkd_money)+")"); | ||||||
|  |                     abstractReportColumn.setCaption(l); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         //债务融资 | ||||||
|  |         List<AbstractReportColumn> zwrz = ((ReportColumnGroup) columns.get(5)).getChildren(); | ||||||
|  |         for (AbstractReportColumn child : zwrz) { | ||||||
|  |             ReportColumnGroup reportColumnGroup= null; | ||||||
|  |             try { | ||||||
|  |                 reportColumnGroup = (ReportColumnGroup) child; | ||||||
|  |             } catch (Exception e) { | ||||||
|  |                 String localeValue_zh_cn = child.getCaption().getLocaleValue_zh_CN(); | ||||||
|  |                 if (localeValue_zh_cn.contains("金额")){ | ||||||
|  |                     LocaleString l = new LocaleString(); | ||||||
|  |                     l.put("zh_CN",localeValue_zh_cn+"("+ FinanceVarietyEnum.getshkd_selmoney(shkd_money)+")"); | ||||||
|  |                     child.setCaption(l); | ||||||
|  |                 } | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |             List<AbstractReportColumn> children = reportColumnGroup.getChildren(); | ||||||
|  |             for (AbstractReportColumn abstractReportColumn : children) { | ||||||
|  |                 String localeValue_zh_cn = abstractReportColumn.getCaption().getLocaleValue_zh_CN(); | ||||||
|  |                 if ("金额".contains(localeValue_zh_cn)){ | ||||||
|  |                     LocaleString l = new LocaleString(); | ||||||
|  |                     l.put("zh_CN",localeValue_zh_cn+"("+ FinanceVarietyEnum.getshkd_selmoney(shkd_money)+")"); | ||||||
|  |                     abstractReportColumn.setCaption(l); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         //权益融资 | ||||||
|  |         List<AbstractReportColumn> qyrz = ((ReportColumnGroup) columns.get(6)).getChildren(); | ||||||
|  |         for (AbstractReportColumn child : qyrz) { | ||||||
|  |             ReportColumnGroup reportColumnGroup= null; | ||||||
|  |             try { | ||||||
|  |                 reportColumnGroup = (ReportColumnGroup) child; | ||||||
|  |             } catch (Exception e) { | ||||||
|  |                 String localeValue_zh_cn = child.getCaption().getLocaleValue_zh_CN(); | ||||||
|  |                 if (localeValue_zh_cn.contains("金额")){ | ||||||
|  |                     LocaleString l = new LocaleString(); | ||||||
|  |                     l.put("zh_CN",localeValue_zh_cn+"("+ FinanceVarietyEnum.getshkd_selmoney(shkd_money)+")"); | ||||||
|  |                     child.setCaption(l); | ||||||
|  |                 } | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |             List<AbstractReportColumn> children = reportColumnGroup.getChildren(); | ||||||
|  |             for (AbstractReportColumn abstractReportColumn : children) { | ||||||
|  |                 String localeValue_zh_cn = abstractReportColumn.getCaption().getLocaleValue_zh_CN(); | ||||||
|  |                 if ("金额".contains(localeValue_zh_cn)){ | ||||||
|  |                     LocaleString l = new LocaleString(); | ||||||
|  |                     l.put("zh_CN",localeValue_zh_cn+"("+ FinanceVarietyEnum.getshkd_selmoney(shkd_money)+")"); | ||||||
|  |                     abstractReportColumn.setCaption(l); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         //融资(含权益) | ||||||
|  |         List<AbstractReportColumn> rz = ((ReportColumnGroup) columns.get(7)).getChildren(); | ||||||
|  |         for (AbstractReportColumn child : rz) { | ||||||
|  |             ReportColumnGroup reportColumnGroup= null; | ||||||
|  |             try { | ||||||
|  |                 reportColumnGroup = (ReportColumnGroup) child; | ||||||
|  |             } catch (Exception e) { | ||||||
|  |                 String localeValue_zh_cn = child.getCaption().getLocaleValue_zh_CN(); | ||||||
|  |                 if (localeValue_zh_cn.contains("金额")){ | ||||||
|  |                     LocaleString l = new LocaleString(); | ||||||
|  |                     l.put("zh_CN",localeValue_zh_cn+"("+ FinanceVarietyEnum.getshkd_selmoney(shkd_money)+")"); | ||||||
|  |                     child.setCaption(l); | ||||||
|  |                 } | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |             List<AbstractReportColumn> children = reportColumnGroup.getChildren(); | ||||||
|  |             for (AbstractReportColumn abstractReportColumn : children) { | ||||||
|  |                 String localeValue_zh_cn = abstractReportColumn.getCaption().getLocaleValue_zh_CN(); | ||||||
|  |                 if ("金额".contains(localeValue_zh_cn)){ | ||||||
|  |                     LocaleString l = new LocaleString(); | ||||||
|  |                     l.put("zh_CN",localeValue_zh_cn+"("+ FinanceVarietyEnum.getshkd_selmoney(shkd_money)+")"); | ||||||
|  |                     abstractReportColumn.setCaption(l); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return columns; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void processRowData(String gridPK, DynamicObjectCollection rowData, ReportQueryParam queryParam) { | ||||||
|  |         super.processRowData(gridPK, rowData, queryParam); | ||||||
|  | 
 | ||||||
|  |         if (rowData.size()==0){ | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         //获取排序配置 | ||||||
|  |         DynamicObject shkd_selorg = (DynamicObject) this.getModel().getValue("shkd_selorg"); | ||||||
|  |         long id = shkd_selorg.getLong("id"); | ||||||
|  |         QFilter filter = new QFilter("shkd_org", QCP.equals, id); | ||||||
|  |         DynamicObject paixu = BusinessDataServiceHelper.loadSingle("shkd_orgorderby", filter.toArray()); | ||||||
|  |         if (paixu==null){ | ||||||
|  |             //添加“集团内债务融资未抵消“合计行 | ||||||
|  |             addheji(rowData); | ||||||
|  |         }else { | ||||||
|  |             DynamicObjectCollection shkd_entryentity = paixu.getDynamicObjectCollection("shkd_entryentity"); | ||||||
|  |             // 创建一个HashMap来存储转换后的结果 | ||||||
|  |             Map<String, Integer> map = new HashMap<>(); | ||||||
|  |             int s=0; | ||||||
|  |             // 假设你可以通过遍历DynamicObjectCollection,来获取其中的元素 | ||||||
|  |             for (DynamicObject obj : shkd_entryentity) { | ||||||
|  |                 DynamicObject key = obj.getDynamicObject("shkd_ywdy"); | ||||||
|  |                 int value = s++; | ||||||
|  |                 map.put(key.getString("number"), value);  // 将键值对放入HashMap | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             //按字段 组织配置 排序 | ||||||
|  | 
 | ||||||
|  |             Collections.sort(rowData , new Comparator<DynamicObject>(){ | ||||||
|  |                 @Override | ||||||
|  |                 public int compare(DynamicObject dynamicObject1, DynamicObject dynamicObject2) { | ||||||
|  |                     return (map.get(dynamicObject1.getString("shkd_orgnumber"))==null?100:map.get(dynamicObject1.getString("shkd_orgnumber")))-(map.get(dynamicObject2.getString("shkd_orgnumber"))==null?100:map.get(dynamicObject2.getString("shkd_orgnumber"))); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |             }); | ||||||
|  |             //添加“集团内债务融资未抵消“合计行 | ||||||
|  |             addheji(rowData); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void addheji(DynamicObjectCollection rowData){ | ||||||
|  |         BigDecimal shkd_jtnbjkamount=new BigDecimal(0);//⑩集团内部借款金额 | ||||||
|  |         BigDecimal shkd_jtnbjkrzcb=new BigDecimal(0);//⑩集团内部借款融资成本(%) | ||||||
|  |         BigDecimal shkd_jtnbjkqx=new BigDecimal(0);//⑩集团内部借款期限 | ||||||
|  |         for (DynamicObject rowDatum : rowData) { | ||||||
|  |             shkd_jtnbjkamount.subtract(rowDatum.getBigDecimal("shkd_jtnbjkamount")); | ||||||
|  |             shkd_jtnbjkrzcb.subtract(rowDatum.getBigDecimal("shkd_jtnbjkrzcb")); | ||||||
|  |             shkd_jtnbjkqx.subtract(rowDatum.getBigDecimal("shkd_jtnbjkqx")); | ||||||
|  |         } | ||||||
|  |         DynamicObject dynamicObject = new DynamicObject(rowData.getDynamicObjectType()); | ||||||
|  |         dynamicObject.set("shkd_org","合并抵消"); | ||||||
|  |         dynamicObject.set("shkd_jtnbjkamount",shkd_jtnbjkamount); | ||||||
|  |         dynamicObject.set("shkd_jtnbjkrzcb",shkd_jtnbjkrzcb); | ||||||
|  |         dynamicObject.set("shkd_jtnbjkqx",shkd_jtnbjkqx); | ||||||
|  |         rowData.add(dynamicObject); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private List<Long> getSuperOrg(List<Long> org){ | ||||||
|  |         //组织和其对应直接上级 | ||||||
|  |         Map<Long, Long> map = new HashMap(); | ||||||
|  |         map=OrgUnitServiceHelper.getDirectSuperiorOrg(OrgViewType.OrgUnit, org); | ||||||
|  | 
 | ||||||
|  |         Set<Long> existingOrgs = new HashSet<>(map.keySet()); | ||||||
|  | 
 | ||||||
|  |         // 2. 遍历 map,检查每个组织 a 的上级是否存在于 existingOrgs 中 | ||||||
|  |         List<Long> result = new ArrayList<>(); | ||||||
|  |         for (Long orgId : map.keySet()) { | ||||||
|  |             Long superior = map.get(orgId); // 获取当前组织的上级 | ||||||
|  |             if (superior == null || !existingOrgs.contains(superior)) { | ||||||
|  |                 // 如果上级不存在(或为 null),则保留当前组织 | ||||||
|  |                 result.add(orgId); | ||||||
|  |             } | ||||||
|  |             // 否则(上级存在),不加入 result(相当于删除) | ||||||
|  |         } | ||||||
|  |         List<Long> longs = new ArrayList<>(result); | ||||||
|  |         return longs; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,280 @@ | ||||||
|  | package shkd.sys.sys.plugin.report; | ||||||
|  | 
 | ||||||
|  | import kd.bos.algo.DataSet; | ||||||
|  | import kd.bos.algo.JoinDataSet; | ||||||
|  | import kd.bos.algo.JoinType; | ||||||
|  | import kd.bos.dataentity.entity.DynamicObject; | ||||||
|  | import kd.bos.dataentity.entity.DynamicObjectCollection; | ||||||
|  | import kd.bos.db.DB; | ||||||
|  | import kd.bos.db.DBRoute; | ||||||
|  | import kd.bos.entity.report.AbstractReportListDataPlugin; | ||||||
|  | import kd.bos.entity.report.FastFilter; | ||||||
|  | import kd.bos.entity.report.FilterItemInfo; | ||||||
|  | import kd.bos.entity.report.ReportQueryParam; | ||||||
|  | import kd.bos.entity.tree.TreeNode; | ||||||
|  | import kd.bos.logging.Log; | ||||||
|  | import kd.bos.logging.LogFactory; | ||||||
|  | import kd.bos.org.model.OrgTreeBuildType; | ||||||
|  | import kd.bos.org.model.OrgTreeParam; | ||||||
|  | import kd.bos.orm.query.QCP; | ||||||
|  | import kd.bos.orm.query.QFilter; | ||||||
|  | import kd.bos.servicehelper.BusinessDataServiceHelper; | ||||||
|  | import kd.bos.servicehelper.QueryServiceHelper; | ||||||
|  | import kd.bos.servicehelper.org.OrgUnitServiceHelper; | ||||||
|  | import kd.bos.servicehelper.org.OrgViewType; | ||||||
|  | import kd.bos.util.CollectionUtils; | ||||||
|  | import shkd.sys.sys.plugin.report.domain.FinanceVarietyEnum; | ||||||
|  | 
 | ||||||
|  | import java.text.SimpleDateFormat; | ||||||
|  | import java.util.*; | ||||||
|  | import java.util.stream.Collectors; | ||||||
|  | 
 | ||||||
|  | public class FinanceReportfordatePlugin extends AbstractReportListDataPlugin { | ||||||
|  | 
 | ||||||
|  |     private static final Log logger = LogFactory.getLog(FinanceReportfordatePlugin.class); | ||||||
|  | 
 | ||||||
|  |     public List<QFilter> getListQFilter(ReportQueryParam reportQueryParam) { | ||||||
|  |         //过滤条件数组 | ||||||
|  |         ArrayList<QFilter> filters = new ArrayList<>(); | ||||||
|  |         //初始化过滤数据 | ||||||
|  |         List<FilterItemInfo> initFilter = reportQueryParam.getFilter().getFilterItems(); | ||||||
|  |         if (CollectionUtils.isNotEmpty(initFilter)) { | ||||||
|  |             for (FilterItemInfo filterItemInfo : initFilter) { | ||||||
|  | //                QFilter filter = new QFilter(filterItemInfo.getPropName(), filterItemInfo.getCompareType(), filterItemInfo.getValue()); | ||||||
|  |                 QFilter filter = new QFilter(filterItemInfo.getPropName(), QCP.equals, filterItemInfo.getValue()); | ||||||
|  |                 filters.add(filter); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         //快速过滤 | ||||||
|  |         FastFilter fastFilter = reportQueryParam.getFilter().getFastFilter(); | ||||||
|  |         if (fastFilter != null) { | ||||||
|  |             List<QFilter> fastFilterList = reportQueryParam.getFilter().getFastFilter().getQFilters(); | ||||||
|  |             //添加过滤条件 | ||||||
|  |             if (CollectionUtils.isNotEmpty(fastFilterList)) { | ||||||
|  |                 filters.addAll(fastFilterList); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         return filters; | ||||||
|  |     } | ||||||
|  |     @Override | ||||||
|  |     public DataSet query(ReportQueryParam reportQueryParam, Object o) throws Throwable { | ||||||
|  |         //获取筛选器的值 | ||||||
|  |         List<QFilter> listQFilter = getListQFilter(reportQueryParam); | ||||||
|  |         String shkd_selstartdate=""; | ||||||
|  |         String shkd_selenddate=""; | ||||||
|  |         List<String> dateList = new ArrayList<>(); | ||||||
|  |         DynamicObject selorgDy = null; | ||||||
|  |         Double shkd_selmoney=0.0; | ||||||
|  |         DynamicObjectCollection shkd_seluserpower=null; | ||||||
|  |         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | ||||||
|  |         for (QFilter filter : listQFilter) { | ||||||
|  |             if (filter.getProperty().contains("shkd_selorg")) { | ||||||
|  |                 selorgDy= (DynamicObject) filter.getValue(); | ||||||
|  |             } else if (filter.getProperty().contains("shkd_selstartdate")) { | ||||||
|  |                 shkd_selstartdate=sdf.format(filter.getValue()); | ||||||
|  |             } else if (filter.getProperty().contains("shkd_selenddate")) { | ||||||
|  |                 shkd_selenddate=sdf.format(filter.getValue()); | ||||||
|  |             }else if (filter.getProperty().contains("shkd_selmoney")) { | ||||||
|  |                 shkd_selmoney= Double.parseDouble((String) filter.getValue()); | ||||||
|  |             }else if  (filter.getProperty().contains("shkd_seluserpower")){ | ||||||
|  |                 shkd_seluserpower=(DynamicObjectCollection) filter.getValue(); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         HashMap<Long, List<Long>> map = new HashMap<>();//组织层级关系 | ||||||
|  |         //如果有组织则单独处理,没有则走getOrgrelate方法 | ||||||
|  |         if (shkd_seluserpower==null){ | ||||||
|  |             getOrgrelate(map, selorgDy); | ||||||
|  |         }else { | ||||||
|  |             for (DynamicObject dynamicObject : shkd_seluserpower) { | ||||||
|  |                 Long id = dynamicObject.getLong("id");//业务单元id | ||||||
|  |                 List<Long> orgIds = new ArrayList<>(1); | ||||||
|  |                 orgIds.add(id); | ||||||
|  |                 //获取该组织的全部下级业务单元 | ||||||
|  |                 List<Long> allSubordinateOrgs = OrgUnitServiceHelper.getAllSubordinateOrgs(OrgViewType.OrgUnit, orgIds, true);//包括自己 | ||||||
|  |                 map.put(id,allSubordinateOrgs); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         //根据组织关系配置sql | ||||||
|  |         StringBuilder sqlBuilder = new StringBuilder("/*dialect*/ "); | ||||||
|  |         getSQlBuilder(shkd_selstartdate,shkd_selenddate,map,sqlBuilder); | ||||||
|  | 
 | ||||||
|  |         logger.info("sqlBuilder信息:{}", sqlBuilder); | ||||||
|  |         DataSet res = DB.queryDataSet(this.getClass().getSimpleName(), DBRoute.of("fi"), sqlBuilder.toString());//财务云 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |         //业务单元数据集 | ||||||
|  |         DataSet balanceDataSet = QueryServiceHelper.queryDataSet(this.getClass().getSimpleName(),"bos_org","id,number as shkd_orgnumber,name as shkd_org", null, null); | ||||||
|  | 
 | ||||||
|  |         JoinDataSet join = res.join(balanceDataSet, JoinType.INNER);//连接组织 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public StringBuilder getSQlBuilder(String shkd_selstartdate,String shkd_selenddate,HashMap<Long, List<Long>> map,StringBuilder sqlBuilder){ | ||||||
|  |         //组装组织分类 | ||||||
|  |         StringBuilder orgclass=new StringBuilder(" case \n"); | ||||||
|  |         StringBuilder orgclass1=new StringBuilder(" case \n"); | ||||||
|  |         for (Map.Entry<Long, List<Long>> entry : map.entrySet()) { | ||||||
|  |             Long key = entry.getKey(); | ||||||
|  |             List<Long> valueList = entry.getValue(); | ||||||
|  |             String result = valueList.toString(); | ||||||
|  |             result = result.substring(1, result.length() - 1); | ||||||
|  |             orgclass.append(" WHEN e.forgid IN ( "+result+" ) THEN "+key+" \n"); | ||||||
|  |             orgclass1.append(" WHEN t5.fcompanyid IN ( "+result+" ) THEN "+key+" \n"); | ||||||
|  |         } | ||||||
|  |         orgclass.append(" ELSE NULL \n"); | ||||||
|  |         orgclass.append(" END AS zz \n"); | ||||||
|  |         orgclass1.append(" ELSE NULL \n"); | ||||||
|  |         orgclass1.append(" END AS zz \n"); | ||||||
|  | 
 | ||||||
|  |         String zqrz = getrzpzId(FinanceVarietyEnum.zqrz, "cfm_financingvarieties");//获取债券融资的融资品种 | ||||||
|  |         String dqjk = getrzpzId(FinanceVarietyEnum.dqjk, "cfm_financingvarieties");//获取短期借款的融资品种 | ||||||
|  |         String zcqld = getrzpzId(FinanceVarietyEnum.zcqld, "cfm_financingvarieties");//获取中长期流贷的融资品种 | ||||||
|  |         String xmdk = getrzpzId(FinanceVarietyEnum.xmdk, "cfm_financingvarieties");//获取项目贷款的融资品种 | ||||||
|  |         String bxzjrz = getrzpzId(FinanceVarietyEnum.bxzjrz, "cfm_financingvarieties");//获取保险资金融资的融资品种 | ||||||
|  |         String fjrqyjk = getrzpzId(FinanceVarietyEnum.fjrqyjk, "cfm_financingvarieties");//获取非金融企业借款的融资品种 | ||||||
|  |         Map<String, String> qtzwrz = getrzpzIdmap(FinanceVarietyEnum.qtzwrz, "cfm_financingvarieties");//获取其他债务融资的融资品种 | ||||||
|  |         String jtnbjk = getrzpzId(FinanceVarietyEnum.jtnbjk, "cfm_financingvarieties");//获取集团内部借款的融资品种 | ||||||
|  |         String yxd = getrzpzId(FinanceVarietyEnum.yxd, "cfm_financingvarieties");//获取永续债的融资品种 | ||||||
|  |         String yxxt = getrzpzId(FinanceVarietyEnum.yxxt, "cfm_financingvarieties");//获取永续信托的融资品种 | ||||||
|  |         Map<String, String> qtqyrz = getrzpzIdmap(FinanceVarietyEnum.qtqyrz, "cfm_financingvarieties");//获取其他权益融资的融资品种 | ||||||
|  | 
 | ||||||
|  |         //开始拼接 | ||||||
|  |         sqlBuilder.append("SELECT \n"); | ||||||
|  |         sqlBuilder.append("SUM(CASE WHEN djlx='债券发行' AND rzpz in ("+zqrz+") AND starttime <= '"+shkd_selstartdate+"' AND endtime > '"+shkd_selstartdate+"' THEN je ELSE 0 END ) AS shkd_zqrzqcye,\n" + | ||||||
|  |                 "    SUM(CASE WHEN djlx='债券发行' AND rzpz in ("+zqrz+") AND starttime > '"+shkd_selstartdate+"' AND starttime <= '"+shkd_selenddate+"' THEN je ELSE 0 END ) AS shkd_zqrzxzrze,\n" + | ||||||
|  |                 "    SUM(CASE WHEN djlx='债券发行' AND rzpz in ("+zqrz+") AND endtime > '"+shkd_selstartdate+"' AND endtime <= '"+shkd_selenddate+"' THEN je ELSE 0 END ) AS shkd_zqrzxzhke,\n" + | ||||||
|  |                 "    SUM(CASE WHEN djlx='债券发行' AND rzpz in ("+zqrz+") AND starttime <= '"+shkd_selenddate+"' AND endtime > '"+shkd_selenddate+"' THEN je ELSE 0 END ) AS shkd_zqrzqmye, \n");//①债券融资 | ||||||
|  | 
 | ||||||
|  |         sqlBuilder.append("SUM(CASE WHEN djlx='银行借款合同' AND rzpz in ("+dqjk+") AND starttime <= '"+shkd_selstartdate+" AND endtime > '"+shkd_selstartdate+"' THEN je ELSE 0 END ) AS ②短期借款期初余额,\n" + | ||||||
|  |                 "    SUM(CASE WHEN djlx='银行借款合同' AND rzpz in ("+dqjk+") AND starttime > '"+shkd_selstartdate+"' AND starttime <= '"+shkd_selenddate+"' THEN je ELSE 0 END ) AS ②短期借款新增融资额,\n" + | ||||||
|  |                 "    SUM(CASE WHEN djlx='银行借款合同' AND rzpz in ("+dqjk+") AND endtime > '"+shkd_selstartdate+"' AND endtime <= '"+shkd_selenddate+"' THEN je ELSE 0 END ) AS ②短期借款新增还款额,\n" + | ||||||
|  |                 "    SUM(CASE WHEN djlx='银行借款合同' AND rzpz in ("+dqjk+") AND starttime <= '"+shkd_selenddate+"' AND endtime > '"+shkd_selenddate+"' THEN je ELSE 0 END ) AS ②短期借款期末余额,");//②短期借款 | ||||||
|  | 
 | ||||||
|  |         sqlBuilder.append("zz \n"); | ||||||
|  | 
 | ||||||
|  |         sqlBuilder.append("FROM\n" + | ||||||
|  |                 "(\n" + | ||||||
|  |                 "SELECT\n" + | ||||||
|  |                 "t1.fbillno,t1.ffinproductid as rzpz,rpentry.fexdrawamount as je,'债券发行' AS djlx,'' AS zqrlx,\n" + | ||||||
|  |                 "t1.fbizdate AS starttime,\n" + | ||||||
|  |                 "rpentry.fexrepaymentdate AS endtime,\n" + | ||||||
|  |                 orgclass + | ||||||
|  |                 "FROM\n" + | ||||||
|  |                 "  t_cfm_loanbill t1 --  债券发行\n" + | ||||||
|  |                 "  INNER JOIN t_cfm_loanbill_e e ON e.fid = t1.fid -- 内连接组织拆分表\n" + | ||||||
|  |                 "  INNER JOIN t_cfm_loanbill_rp_entry rpentry ON rpentry.fid = t1.fid -- 债券发行明细表\n" + | ||||||
|  |                 "WHERE\n" + | ||||||
|  |                 "        t1.fbillstatus='C'\n" + | ||||||
|  |                 "    UNION ALL\n" + | ||||||
|  |                 "SELECT \n" + | ||||||
|  |                 "   t2.fbillno as fbillno,COALESCE( NULLIF ( t2.fk_shkd_basedatafield, 0 ), t2.ffinproductid ) AS rzpz,rpentry.fexdrawamount as je,'银行借款合同' AS djlx,'' AS zqrlx,\n" + | ||||||
|  |                 "   t3.fbizdate AS starttime,\n" + | ||||||
|  |                 "   rpentry.fexrepaymentdate AS endtime,\n" + | ||||||
|  |                 orgclass+ | ||||||
|  |                 "FROM\n" + | ||||||
|  |                 "  t_cfm_loancontractbill t2 --银行借款合同\n" + | ||||||
|  |                 "    INNER JOIN t_cfm_loancontractbill_e e ON e.fid = t2.fid -- 内连接组织拆分表\n" + | ||||||
|  |                 "    INNER JOIN t_cfm_loanbill_e e1 ON e1.floancontractbillid = t2.fid -- 内连接合同拆分表\n" + | ||||||
|  |                 "    INNER JOIN t_cfm_loanbill t3 ON t3.fid = e1.fid -- 银行提款处理表\n" + | ||||||
|  |                 "    INNER JOIN t_cfm_loanbill_rp_entry rpentry ON rpentry.fid = t3.fid -- 银行提款处理明细表\n" + | ||||||
|  |                 "WHERE\n" + | ||||||
|  |                 "    t2.fbillstatus='C' AND e.floantype IN ('loan','sl')\n" + | ||||||
|  |                 "    AND t3.fbillstatus='C'\n" + | ||||||
|  |                 "    UNION ALL\n" + | ||||||
|  |                 "SELECT\n" + | ||||||
|  |                 "t4.fbillno,t4.ffinproductid as rzpz,planmx.frentamt as je,'融资租赁合同' AS djlx,'' AS zqrlx,\n" + | ||||||
|  |                 "t4.fstartdate AS starttime,\n" + | ||||||
|  |                 "planmx.fpaydate AS endtime,\n" + | ||||||
|  |                 orgclass+ | ||||||
|  |                 "FROM\n" + | ||||||
|  |                 "t_cfm_loancontractbill t4 --  融资租赁合同\n" + | ||||||
|  |                 "INNER JOIN t_cfm_loancontractbill_e e ON e.fid = t4.fid -- 内连接组织拆分表\n" + | ||||||
|  |                 "INNER JOIN t_cfm_contractbill_plan planmx ON planmx.fid = t4.fid -- 融资租赁合同明细表\n" + | ||||||
|  |                 "WHERE\n" + | ||||||
|  |                 "        t4.fbillstatus='C' AND e.floantype='finlease'\n" + | ||||||
|  |                 "        UNION ALL\n" + | ||||||
|  |                 "    SELECT\n" + | ||||||
|  |                 "t5.fbillno, 6666666666666666666 as rzpz,t5.famount as je,'开票登记' AS djlx,'' AS zqrlx,\n" + | ||||||
|  |                 "t5.fissuedate AS starttime,\n" + | ||||||
|  |                 "t5.fdraftbillexpiredate AS endtime,\n" + | ||||||
|  |                 orgclass1+ | ||||||
|  |                 "FROM\n" + | ||||||
|  |                 "t_cdm_draftbill t5 --  开票登记\n" + | ||||||
|  |                 "WHERE\n" + | ||||||
|  |                 "        t5.fbillstatus='C'\n" + | ||||||
|  |                 "        UNION ALL\n" + | ||||||
|  |                 "    SELECT \n" + | ||||||
|  |                 "   t2.fbillno as fbillno,COALESCE( NULLIF ( t2.fk_shkd_basedatafield, 0 ), t2.ffinproductid ) AS rzpz,rpentry.fexdrawamount as je,'企业借款合同' AS djlx,e.fcreditortype AS zqrlx,\n" + | ||||||
|  |                 "   t3.fbizdate AS starttime,\n" + | ||||||
|  |                 "rpentry.fexrepaymentdate AS endtime,\n" + | ||||||
|  |                 orgclass+ | ||||||
|  |                 "FROM\n" + | ||||||
|  |                 "  t_cfm_loancontractbill t2 --企业借款合同\n" + | ||||||
|  |                 "    INNER JOIN t_cfm_loancontractbill_e e ON e.fid = t2.fid -- 内连接组织拆分表\n" + | ||||||
|  |                 "    INNER JOIN t_cfm_loanbill_e e1 ON e1.floancontractbillid = t2.fid -- 内连接合同拆分表\n" + | ||||||
|  |                 "    INNER JOIN t_cfm_loanbill t3 ON t3.fid = e1.fid -- 银行提款处理表\n" + | ||||||
|  |                 "    INNER JOIN t_cfm_loanbill_rp_entry rpentry ON rpentry.fid = t3.fid -- 银行提款处理明细表\n" + | ||||||
|  |                 "WHERE\n" + | ||||||
|  |                 "    t2.fbillstatus='C' AND e.floantype IN ('ec','entrust')\n" + | ||||||
|  |                 "    AND t3.fbillstatus='C'\n" + | ||||||
|  |                 "    ) AS hbb\n" + | ||||||
|  |                 "     GROUP BY zz"); | ||||||
|  | 
 | ||||||
|  |         return sqlBuilder; | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public HashMap<Long, List<Long>> getOrgrelate(HashMap<Long, List<Long>> map,DynamicObject selorgDy){ | ||||||
|  |         // 查询该组织的直接下级业务单元 | ||||||
|  |         OrgTreeParam orgTreeParam=new OrgTreeParam(); | ||||||
|  |         orgTreeParam.setId(selorgDy.getLong("id")); | ||||||
|  |         orgTreeParam.setOrgViewType(OrgViewType.OrgUnit);//设置视图方案为业务单元的 | ||||||
|  |         orgTreeParam.setTreeBuildType(OrgTreeBuildType.FILL_HIDDEN_PARENT_DIRECT); | ||||||
|  |         List<TreeNode> treeNodes=OrgUnitServiceHelper.getTreeChildren(orgTreeParam); | ||||||
|  | 
 | ||||||
|  |         for (TreeNode treeNode : treeNodes) { | ||||||
|  |             Long id = Long.valueOf(treeNode.getId());//业务单元id | ||||||
|  |             List<Long> orgIds = new ArrayList<>(1); | ||||||
|  |             orgIds.add(id); | ||||||
|  |             //获取该组织的全部下级业务单元 | ||||||
|  |             List<Long> allSubordinateOrgs = OrgUnitServiceHelper.getAllSubordinateOrgs(OrgViewType.OrgUnit, orgIds, true);//包括自己 | ||||||
|  |             map.put(id,allSubordinateOrgs); | ||||||
|  |         } | ||||||
|  |         return map; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public String getrzpzId(List<String> rzpz,String entity){ | ||||||
|  |         QFilter qFilter = new QFilter("name", QCP.in, rzpz); | ||||||
|  |         DynamicObject[] ids = BusinessDataServiceHelper.load(entity, "id", qFilter.toArray()); | ||||||
|  |         // 使用 Stream 来将 ids 数组转为逗号分隔的字符串 | ||||||
|  |         String result = Arrays.stream(ids) | ||||||
|  |                 .map(id -> id.getString("id"))  // 假设 getId() 返回 id 的值 | ||||||
|  |                 .collect(Collectors.joining(",")); | ||||||
|  |         return result; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     public Map<String, String> getrzpzIdmap(Map<String, List<String>> map , String entity){ | ||||||
|  |         Map<String, String> resmap = new HashMap<>(); | ||||||
|  |         for (Map.Entry<String, List<String>> entry : map.entrySet()){ | ||||||
|  |             String key = entry.getKey(); | ||||||
|  |             List<String> values = entry.getValue(); | ||||||
|  |             QFilter qFilter = new QFilter("name", QCP.in, values); | ||||||
|  |             DynamicObject[] ids = BusinessDataServiceHelper.load(entity, "id", qFilter.toArray()); | ||||||
|  |             // 使用 Stream 来将 ids 数组转为逗号分隔的字符串 | ||||||
|  |             String result = Arrays.stream(ids) | ||||||
|  |                     .map(id -> id.getString("id"))  // 假设 getId() 返回 id 的值 | ||||||
|  |                     .collect(Collectors.joining(",")); | ||||||
|  |             resmap.put(key,result); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return resmap; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue