先展示效果
根据数据中已有的年份动态扩展,假如有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);
}
}