Commit d879a9f9b573612fbfc491d23890fdd7814af11e

Authored by baohanddd
1 parent a2bf846944

add statistics(map) common index

Showing 1 changed file with 86 additions and 1 deletions

platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/StatisticsController.java View file @ d879a9f
... ... @@ -10,6 +10,7 @@
10 10 import com.lymsh.platform.reportdata.model.echarts.*;
11 11 import com.lymsh.platform.reportdata.service.StatisticsService;
12 12 import org.apache.commons.lang.StringUtils;
  13 +import org.joda.time.DateTime;
13 14 import org.springframework.beans.factory.annotation.Autowired;
14 15 import org.springframework.stereotype.Controller;
15 16 import org.springframework.web.bind.annotation.PathVariable;
... ... @@ -175,7 +176,6 @@
175 176 } else {
176 177 return 1;
177 178 }
178   -
179 179 }
180 180 });
181 181  
182 182  
183 183  
... ... @@ -196,12 +196,31 @@
196 196 groupRiskOption.setSeries(groupRiskSeriesList);
197 197  
198 198  
  199 + // 4. 按省或市或地区查询区域内近12个自然月每月建档人数
  200 + List<AreaData> patientMonthList = statisticsService.queryMonthPatients(new AreaDataQuery());
  201 + Map<String, Map<String, Integer>> patientMonthMap = new HashMap<>();
  202 + for (AreaData areaData:patientMonthList) {
  203 + String regino = areaData.getProvinceName();
  204 + Map<String, Integer> subMap = null;
  205 + if (patientMonthMap.containsKey(regino)) {
  206 + subMap = patientMonthMap.get(regino);
  207 + } else {
  208 + subMap = new HashMap<>();
  209 + patientMonthMap.put(regino, subMap);
  210 + }
  211 + String month = buildMonth(areaData.getYear());
  212 + subMap.put(month, areaData.getVal());
  213 + }
  214 + Option patientMonthOption = buildLineOption("建档人数", null, patientMonthMap, buildDefaultMonth(12));
199 215  
  216 +
  217 +
200 218 result.put("type", 1);
201 219 result.put("kvData", kvData);
202 220 result.put("mapsOption", option);
203 221 result.put("areaBarOption", areaBarOption);
204 222 result.put("riskOption", groupRiskOption);
  223 + result.put("patientMonthOption", patientMonthOption);
205 224 ResultUtils.buildSuccessResultAndWrite(response, result);
206 225 }
207 226  
... ... @@ -210,6 +229,72 @@
210 229  
211 230  
212 231  
  232 +
  233 + private String buildMonth(String year) {
  234 + return year.substring(0,4) + "-" + year.substring(4);
  235 + }
  236 +
  237 + private List<Object> buildDefaultMonth(Integer count) {
  238 + List<Object> list = new ArrayList<>();
  239 + DateTime dt = new DateTime();
  240 + for (count--;count>=0;count--) {
  241 + DateTime temp = dt.minusMonths(count);
  242 + list.add(temp.toString("yyyy-MM"));
  243 + }
  244 + return list;
  245 + }
  246 +
  247 + private Option buildLineOption(String titleText, String subTitle, Map<String, Map<String, Integer>> map, List<Object> xData) {
  248 + Option option = new Option();
  249 + Title title = new Title();
  250 + title.setText(titleText);
  251 + title.setSubtext(subTitle);
  252 + option.setTitle(title);
  253 + Tooltip tooltip = new Tooltip();
  254 + tooltip.setTrigger("axis");
  255 + tooltip.setShow(true);
  256 + option.setTooltip(tooltip);
  257 + List<Object> legendData = new ArrayList<>();
  258 + Legend legend = new Legend();
  259 + legend.setTop("50px");
  260 + legend.setLeft("center");
  261 + legend.setData(legendData);
  262 + option.setLegend(legend);
  263 + Grid grid = new Grid();
  264 + grid.setContainLabel(true);
  265 + grid.setTop("80px");
  266 + grid.setLeft("3%");
  267 + grid.setRight("3%");
  268 + grid.setBottom("3%");
  269 + option.setGrid(grid);
  270 + AxisPointer x = new AxisPointer();
  271 + x.setType("category");
  272 + x.setData(xData);
  273 + option.setxAxis(x);
  274 + AxisPointer y = new AxisPointer();
  275 + y.setType("value");
  276 + option.setyAxis(y);
  277 + List<Object> seriesList = new ArrayList<>();
  278 + option.setSeries(seriesList);
  279 + for (String regino:map.keySet()) {
  280 + legendData.add(regino);
  281 + Map<String, Integer> sub = map.get(regino);
  282 + Series series = new Series();
  283 + series.setName(regino);
  284 + series.setType("line");
  285 + List<Object> list = new ArrayList<>();
  286 + series.setData(list);
  287 + for (Object o:xData) {
  288 + if (sub.get(o) == null) {
  289 + list.add(0);
  290 + } else {
  291 + list.add(sub.get(o));
  292 + }
  293 + }
  294 + seriesList.add(series);
  295 + }
  296 + return option;
  297 + }
213 298  
214 299 private Option buildMapOption(String titleText, String subTitle) {
215 300 Option option = new Option();