easy poi动态生成数据 动态导出excel数据(工作记录)

本文介绍了如何使用Java动态生成Excel数据,根据已有年份扩展账期,详细阐述了数据处理过程,包括账期去重、按条件分组、计算合计等步骤。同时讲解了动态导出Excel的实现,以及前端展示和延缓加载的配置细节。
摘要由CSDN通过智能技术生成

先展示效果
在这里插入图片描述
根据数据中已有的年份动态扩展,假如有2023年的数据,会动态扩展到2022年后面。
下面 来看下代码如何实现

public Map<String, Object> getRevenueNoRecognitionByDynamicGeneration(RevenueSearchConData revenueSearchConData) throws Exception {
   
		List<RevenueNoRecognitionData> list = revenueRecognitionMapper.queryReasonForClassificationRevenueFromList(revenueSearchConData);
		List<HashMap<String, Object>> hashMaps = this.dataProcessing(list);
		hashMaps.sort(new dataSort());//根据归类原因前面的序号排序
		List<String> zqList=new ArrayList<>();
		zqList.add("hj");
		zqList.add("xj");
		//根据账期归类原因分组后,去掉重复账期
		List<String> collect = list.stream().map(RevenueNoRecognitionData::getZq).distinct().collect(Collectors.toList());
		collect.removeIf(Objects::isNull);//剔除null数据
		zqList.addAll(collect);//将去重后的账期加入到zqList
		List<HashMap<String, Object>> colMap = this.generateField(zqList);
		Map<String,Object> resultMap=new HashMap<>();
		resultMap.put("col", colMap);//表头标题
		resultMap.put("zqSize", zqList.size());//每列要跨的长度
		resultMap.put("retdata", hashMaps);//数据
		return resultMap;
	}

这里主要将数据查出来,交给dataProcessing处理,

List<HashMap<String, Object>> dataProcessing(List<RevenueNoRecognitionData> list) throws Exception {
   
		RevenueSearchConData revenueSearchConData = new RevenueSearchConData();
		revenueSearchConData.setQueryType("1");
		List<GlyyData> glyyDataList = revenueRecognitionMapper.queryGlyyList(revenueSearchConData);
		List<HashMap<String, Object>> newList = new ArrayList<>();
		//去掉重复数据并获取账期
		List<String> zqList = list.stream().map(RevenueNoRecognitionData::getZq).distinct().collect(Collectors.toList());
		zqList.removeIf(Objects::isNull);//剔除null数据
		String maxZq = Collections.max(zqList);//获取当前最大账期
		if (CollectionUtil.isNotEmpty(list)) {
   
			//将所有归类原因与已有的归类原因比较 没有的添加上去
			for (GlyyData glyyData : glyyDataList) {
   
				RevenueNoRecognitionData revenueNoRecognitionData = new RevenueNoRecognitionData();
				for (RevenueNoRecognitionData revenue : list) {
   
					if (!glyyData.getGlyy().equals(revenue.getGlyy())) {
   
						revenueNoRecognitionData.setGlyy(glyyData.getGlyy() == null ? "" : glyyData.getGlyy());
						revenueNoRecognitionData.setZrbm(glyyData.getZrbm() == null ? "" : glyyData.getZrbm());
						revenueNoRecognitionData.setWtgs(glyyData.getWtgs() == null ? "" : glyyData.getWtgs());
					}
				}
				list.add(revenueNoRecognitionData);
			}
			Map<String, List<RevenueNoRecognitionData>> map = new HashMap<>();
			//按照问题归类拼接上责任部门拼接上归类原因分组
			for (RevenueNoRecognitionData revenue : list) {
   
				if (CollectionUtil.isNotEmpty(map.get(revenue.getWtgs() + "-" + revenue.getZrbm() + "-" + revenue.getGlyy()))) {
   
					map.get(revenue.getWtgs() + "-" + revenue.getZrbm() + "-" + revenue.getGlyy()).add(revenue);
				} else {
   
					List<RevenueNoRecognitionData> revenueList = new ArrayList<>();
					revenueList.add(revenue);
					map.put(revenue.getWtgs() + "-" + revenue.getZrbm() + "-" + revenue.getGlyy(), revenueList);
				}
			}
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值