计算同比和环比增长率

      今天做的项目中,遇到一个计算同期环比和上期环比的计算并显示出来。这是用ssm框架

  代码示例:

  

@RequiresPermissions"analysis:analysis:smartSearch")
    @RequestMappingvalue = "/analysis/analysis/smartSearch")
    public String smartSearch)
    {
        Page<ElectronicTax> page = new Page<ElectronicTax>request, response);
        //page.setPageSize 25 );
        
        if  POST )
        {
            if  !"".equalsrequest.getParameter"pageSize")) )
            {
                el.setPagepage);
            }
            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).getSmartSearchel);
            
            
            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".equalskey) || "accounting".equalskey) && el.getIsTime) == null )) continue;
                        
                        if  keyOne.getkey) == null )
                        {
                            if  munehisa == null )
                            {
                                munehisa = key;
                            }
                            else
                            {
                                transverse = key;
                            }
                            keyOne.putkey, new ArrayList<String>));
                        }
                        
                        if  !keyOne.getkey).contains value ) )
                        {
                            keyOne.getkey).addvalue);
                        }
                    }
                }
            }
            //横向为空,则只选择了一个字段,那么横向TITLE为金额
            if  transverse == null )
            {
                //transverse = "amount";
                keyOne.puttransverse, new ArrayList<String>));
                keyOne.gettransverse).add"金额");
                System.out.printlnkeyOne.gettransverse));
            }
            else
            {
                if  keyOne.gettransverse).size) > keyOne.getmunehisa).size))
                {//纵横向互换
                    String s = transverse;
                    transverse = munehisa;
                    munehisa = s;
                }
                
                model.addAttribute"transverse_param", getParamtransverse));
            }
            
            model.addAttribute"munehisa_param", getParammunehisa));
            Double currentsAmounts = null;
            Double LastsAmounts = null;
                    
            for Map<String, Object> m : list )
            {
                if  dataList.get m.getmunehisa) ) == 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.getmunehisa).equals mm.getmunehisa) ) )
                        {
                            if  transverse == null )
                            {
                                twelveMap.put"金额", mm.get"amount"));
                            }
                            else
                                twelveMap.putmm.gettransverse).toString), mm.get"amount"));
                        }
                    }
                    
                    for String ym : keyOne.gettransverse) )
                    {
                        Map<String, Object> map = new HashMap<String, Object>);
                        
                        Double currentAmount;
                        map.puttransverse, ym);
                        if  twelveMap.getym) == null )
                        {
                            currentAmount = 0.0;

                        }
                        else
                        {
                            currentAmount = Double.parseDouble twelveMap.getym).toString) );
                        }
                        map.put"amount", currentAmount);
                        
                        //对比计算
                        if  el.getIdenticalCompare) != null )
                        {
//                            System.out.printlnm.gettransverse).toString));
//                            System.out.printlnm.getmunehisa).toString));
//                            System.out.printlnmunehisa);
//                            Double amount = companyService.getLastYearCountm.gettransverse).toString), m.getmunehisa).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.getLastMonthCountm.gettransverse).toString), m.getmunehisa).toString), munehisa);
                            if  amount > 0  )
                            {    
                                map.put"ring", currentAmount - amount)/amount);
                            }
                            else map.put"ring", 100);
                        }
                        
                        if  el.getCumulativeCompare) != null )
                        {
                            Double currentAmounts = companyService.getCumulativeComparem.gettransverse).toString), m.getmunehisa).toString), munehisa, "current");
                            Double LastAmounts = companyService.getCumulativeComparem.gettransverse).toString), m.getmunehisa).toString), munehisa, "");
                            //所有行业同比增量
                            if  currentsAmounts == null )
                            {
                                currentsAmounts = companyService.getCumulativeComparem.gettransverse).toString),"", munehisa, "current");
                                LastsAmounts = companyService.getCumulativeComparem.gettransverse).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.putm.getmunehisa).toString), tmpList);
                }
            }
            
            model.addAttribute"dataList", dataList);
            model.addAttribute"transverse", keyOne.gettransverse));
        }
        
        if  !"".equalsrequest.getParameter"pageSize")) )
        {
            model.addAttribute"page", page);
        }
        model.addAttribute"yearMonthList", companyService.getYearMonth));
        
        return "addons/analysis/analysis/smartSearch";
    }

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注