今天做的项目中,遇到一个计算同期环比和上期环比的计算并显示出来。这是用ssm框架
代码示例:
@RequiresPermissions("analysis:analysis:smartSearch") @RequestMapping(value = "/analysis/analysis/smartSearch") public String smartSearch() { Page<ElectronicTax> page = new Page<ElectronicTax>(request, response); //page.setPageSize( 25 ); if ( POST ) { if ( !"".equals(request.getParameter("pageSize")) ) { el.setPage(page); } Map<String, ArrayList<Map<String, Object>>> dataList = new HashMap<String, ArrayList<Map<String,Object>>>(); Map<String, List<String>> keyOne = new HashMap<String, List<String>>(); String transverse=null, munehisa=null; List<Map<String, Object>> list = companyService.getElectronicTaxDao().getSmartSearch(el); for( Map<String, Object> m : list ) { if ( m != null ) { Iterator<Entry<String, Object>> itr = m.entrySet().iterator(); while( itr.hasNext() ) { Entry<String, Object> ety = itr.next(); String key = ety.getKey(); String value = ety.getValue().toString(); if ( "amount".equals(key) || ("accounting".equals(key) && el.getIsTime() == null )) continue; if ( keyOne.get(key) == null ) { if ( munehisa == null ) { munehisa = key; } else { transverse = key; } keyOne.put(key, new ArrayList<String>()); } if ( !keyOne.get(key).contains( value ) ) { keyOne.get(key).add(value); } } } } //横向为空,则只选择了一个字段,那么横向TITLE为金额 if ( transverse == null ) { //transverse = "amount"; keyOne.put(transverse, new ArrayList<String>()); keyOne.get(transverse).add("金额"); System.out.println(keyOne.get(transverse)); } else { if ( keyOne.get(transverse).size() > keyOne.get(munehisa).size()) { //纵横向互换 String s = transverse; transverse = munehisa; munehisa = s; } model.addAttribute("transverse_param", getParam(transverse)); } model.addAttribute("munehisa_param", getParam(munehisa)); Double currentsAmounts = null; Double LastsAmounts = null; for( Map<String, Object> m : list ) { if ( dataList.get( m.get(munehisa) ) == null ) { ArrayList<Map<String, Object>> tmpList = new ArrayList<Map<String, Object>>(); Map<String, Object> twelveMap = new HashMap<String, Object>(); for( Map<String, Object> mm : list ) { if ( m.get(munehisa).equals( mm.get(munehisa) ) ) { if ( transverse == null ) { twelveMap.put("金额", mm.get("amount")); } else twelveMap.put(mm.get(transverse).toString(), mm.get("amount")); } } for( String ym : keyOne.get(transverse) ) { Map<String, Object> map = new HashMap<String, Object>(); Double currentAmount; map.put(transverse, ym); if ( twelveMap.get(ym) == null ) { currentAmount = 0.0; } else { currentAmount = Double.parseDouble( twelveMap.get(ym).toString() ); } map.put("amount", currentAmount); //对比计算 if ( el.getIdenticalCompare() != null ) { // System.out.println(m.get(transverse).toString()); // System.out.println(m.get(munehisa).toString()); // System.out.println(munehisa); // Double amount = companyService.getLastYearCount(m.get(transverse).toString(), m.get(munehisa).toString(), munehisa); // double amount=20; Double amount = 30d; amount.toString(); map.put("identical", currentAmount - amount); if ( amount > 0 ) { map.put("identicals", (currentAmount - amount)/amount); } else map.put("identicals", 100); } if ( el.getRingCompare() != null ) { Double amount = companyService.getLastMonthCount(m.get(transverse).toString(), m.get(munehisa).toString(), munehisa); if ( amount > 0 ) { map.put("ring", (currentAmount - amount)/amount); } else map.put("ring", 100); } if ( el.getCumulativeCompare() != null ) { Double currentAmounts = companyService.getCumulativeCompare(m.get(transverse).toString(), m.get(munehisa).toString(), munehisa, "current"); Double LastAmounts = companyService.getCumulativeCompare(m.get(transverse).toString(), m.get(munehisa).toString(), munehisa, ""); //所有行业同比增量 if ( currentsAmounts == null ) { currentsAmounts = companyService.getCumulativeCompare(m.get(transverse).toString(),"", munehisa, "current"); LastsAmounts = companyService.getCumulativeCompare(m.get(transverse).toString(), "", munehisa, ""); } map.put("cumulative", currentAmounts); map.put("cumulatives", currentAmounts-LastAmounts);//增量 if ( LastAmounts > 0 ) { map.put("cumulativess", (currentAmounts-LastAmounts)/LastAmounts);//增速 } else { map.put("cumulativess", 100);//增量 } if ( currentsAmounts > 0 || LastsAmounts > 0) { map.put("cumulativesss", (currentAmounts-LastAmounts)/(currentsAmounts-LastsAmounts));//增速 } else { map.put("cumulativesss", 100);//增量 } } tmpList.add( map ); } dataList.put(m.get(munehisa).toString(), tmpList); } } model.addAttribute("dataList", dataList); model.addAttribute("transverse", keyOne.get(transverse)); } if ( !"".equals(request.getParameter("pageSize")) ) { model.addAttribute("page", page); } model.addAttribute("yearMonthList", companyService.getYearMonth()); return "addons/analysis/analysis/smartSearch"; }
转载于:https://www.cnblogs.com/bwcx1375/p/7726208.html
今天的文章 计算同比和环比增长率分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ji-chu/82781.html