浏览代码

优化报表接口

hsh 2 年之前
父节点
当前提交
3b1a792c55

+ 47 - 0
src/main/java/cn/hnthyy/thmz/Utils/ReportUsedUtil.java

@@ -3,7 +3,11 @@ package cn.hnthyy.thmz.Utils;
 import cn.hnthyy.thmz.vo.ReportVo;
 import org.apache.commons.lang3.StringUtils;
 
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Date;
+import java.util.List;
 
 /**
  * @Description: 报表开发工具类
@@ -169,4 +173,47 @@ public class ReportUsedUtil {
         return sql.toString();
     }
 
+    /**
+     * 获取两个日期之间的所有月份 (年月)
+     *
+     * @param startTime
+     * @param endTime
+     * @return:list
+     */
+    public static List<String> getMonthBetweenDate(String startTime, String endTime) {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
+        // 声明保存日期集合
+        List<String> list = new ArrayList<>();
+        try {
+            // 转化成日期类型
+            Date startDate = DateUtil.pase(startTime, "yyyy-MM");
+            Date endDate = DateUtil.pase(endTime, "yyyy-MM");
+
+            //用Calendar 进行日期比较判断
+            Calendar calendar = Calendar.getInstance();
+            while (true) {
+                assert startDate != null;
+                assert endDate != null;
+                if (!(startDate.getTime() <= endDate.getTime())) {
+                    break;
+                }
+
+                // 把日期添加到集合
+                list.add(sdf.format(startDate));
+
+                // 设置日期
+                calendar.setTime(startDate);
+
+                //把月数增加 1
+                calendar.add(Calendar.MONTH, 1);
+
+                // 获取增加后的日期
+                startDate = calendar.getTime();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return list;
+    }
+
 }

+ 14 - 10
src/main/java/cn/hnthyy/thmz/service/impl/his/bb/ReportStaticServiceImpl.java

@@ -50,12 +50,7 @@ public class ReportStaticServiceImpl implements ReportStaticService {
                     String gatherSql = info.getGatherSql() + " as value,  t." + vo.getGroupColumn() + " ";
                     String sql = ReportUsedUtil.callSqlFormat(vo, info.getBaseSql(), gatherSql, vo.getGroupColumn(), vo.getGroupColumn());
                     List<Map<String, Object>> l = reportStaticMapper.selectReportRegList(sql);
-                    List<Object> vl = new ArrayList<>();
-                    for (Map<String, Object> m : l) {
-                        vl.add(ReportUsedUtil.formatDataForUse(vo.getGroupColumn(), m.get(vo.getGroupColumn())));
-                    }
                     resultMap.put(info.getReportId(), l);
-                    resultMap.put(vo.getGroupColumn(), vl);
                 }
             }
         } else {
@@ -73,14 +68,23 @@ public class ReportStaticServiceImpl implements ReportStaticService {
                 String gatherSql = info.getGatherSql() + " as value,  t." + vo.getGroupColumn() + " ";
                 String sql = ReportUsedUtil.callSqlFormat(vo, info.getBaseSql(), gatherSql, vo.getGroupColumn(), vo.getGroupColumn());
                 List<Map<String, Object>> l = reportStaticMapper.selectReportRegList(sql);
-                List<Object> vl = new ArrayList<>();
-                for (Map<String, Object> m : l) {
-                    vl.add(ReportUsedUtil.formatDataForUse(vo.getGroupColumn(), m.get(vo.getGroupColumn())));
-                }
                 resultMap.put(info.getReportId(), l);
-                resultMap.put(vo.getGroupColumn(), vl);
             }
         }
+
+        // 计算分组单元
+        if("2".equals(type)){
+            List<String> vl = new ArrayList<>();
+            String s = vo.getStartTime();
+            String e = vo.getEndTime();
+            List<String> yfList = ReportUsedUtil.getMonthBetweenDate(s, e);
+            for (String yf: yfList) {
+                String c_fy = ReportUsedUtil.formatDataForUse(vo.getGroupColumn(), yf);
+                vl.add(c_fy);
+            }
+            resultMap.put(vo.getGroupColumn(), vl);
+        }
+
         return resultMap;
     }