查询一年12个月的数据

    /**
     * 知识累计量
     * @param vo
     * @return
     */
    public List<Integer> getCumulations(KnowledgeSearchVo vo){
        Map<String,Object> map = new HashMap<String,Object>();
        List<Integer> addList=new ArrayList<Integer>();
        String sql="select sum(case when  datepart(month,createdate)=1 then 1 else 0 end) as '1月',\n" +
                "        sum(case when  datepart(month,createdate)=2 then 1 else 0 end) as '2月',\n" +
                "        sum(case when  datepart(month,createdate)=3 then 1 else 0 end) as '3月',\n" +
                "        sum(case when  datepart(month,createdate)=4 then 1 else 0 end) as '4月',\n" +
                "        sum(case when  datepart(month,createdate)=5 then 1 else 0 end) as '5月',\n" +
                "        sum(case when  datepart(month,createdate)=6 then 1 else 0 end) as '6月',\n" +
                "        sum(case when  datepart(month,createdate)=7 then 1 else 0 end) as '7月',\n" +
                "        sum(case when  datepart(month,createdate)=8 then 1 else 0 end) as '8月',\n" +
                "        sum(case when  datepart(month,createdate)=9 then 1 else 0 end) as '9月',\n" +
                "        sum(case when  datepart(month,createdate)=10 then 1 else 0 end) as '10月',\n" +
                "        sum(case when  datepart(month,createdate)=11 then 1 else 0 end) as '11月',\n" +
                "        sum(case when  datepart(month,createdate)=12 then 1 else 0 end) as '12月'\n" +
                "    from docbase\n" +
                "    where isdelete=0 and docstatus=1";
        if(vo!=null&&StringUtils.isNotEmpty(vo.getYear())){
            sql+=" and datepart(year,createdate)=?";
            map = dataService.getMap(sql,vo.getYear());
        }else {
            map = dataService.getMap(sql);
        }
        List<Map.Entry<String,Object>> list = new ArrayList<Map.Entry<String,Object>>(map.entrySet());
        Collections.sort(list, new Comparator<Map.Entry<String, Object>>() {
            @Override
            public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) {
                return NumberHelper.string2Int(o1.getKey().replace("月",""),0)-
                        NumberHelper.string2Int(o2.getKey().replace("月",""),0);
            }
        });
        List<Integer> lists=new ArrayList<>();
        int sum=0;

            for(Map.Entry<String,Object> m: list){
                addList.add(NumberHelper.string2Int(map.get(m.getKey()),0));
            }
            for (Integer i:addList){
                sum=sum+i.intValue();
                lists.add(sum);
            }
            return lists;


    }

 

上一篇:js连续使用三原运算符


下一篇:C# EF SQL Server 字段类型【Time(7)】 转字符串