Commit 03a1edd7331d74381d491c82ea57ea463b23956b

Authored by litao
1 parent 24b25b1052

产检次数报表

Showing 8 changed files with 149 additions and 14 deletions

platform-common/pom.xml View file @ 03a1edd
... ... @@ -34,6 +34,11 @@
34 34 <version>2.6.12</version>
35 35 </dependency>
36 36 <!-- end Execl -->
  37 + <dependency>
  38 + <groupId>org.apache.commons</groupId>
  39 + <artifactId>commons-lang3</artifactId>
  40 + <version>3.4</version>
  41 + </dependency>
37 42 </dependencies>
38 43 <build>
39 44 <plugins>
platform-common/src/main/java/com/lyms/platform/common/base/BaseController.java View file @ 03a1edd
1 1 package com.lyms.platform.common.base;
2 2  
3 3  
  4 +import com.lyms.platform.common.utils.DateUtil;
  5 +import org.springframework.web.bind.WebDataBinder;
  6 +import org.springframework.web.bind.annotation.InitBinder;
  7 +
4 8 import javax.servlet.http.HttpServletRequest;
5 9 import javax.servlet.http.HttpServletResponse;
  10 +import java.beans.PropertyEditorSupport;
6 11 import java.io.IOException;
7 12 import java.io.PrintWriter;
  13 +import java.sql.Timestamp;
  14 +import java.util.Date;
8 15 import java.util.HashMap;
9 16 import java.util.Map;
10 17  
... ... @@ -81,6 +88,28 @@
81 88 ip = request.getRemoteAddr();
82 89 }
83 90 return ip;
  91 + }
  92 +
  93 + @InitBinder
  94 + public void initBinder(WebDataBinder binder) {
  95 + // Date 类型转换
  96 + binder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
  97 +
  98 + @Override
  99 + public void setAsText(String text) {
  100 + setValue(DateUtil.parseDate(text));
  101 + }
  102 + });
  103 +
  104 + // Timestamp 类型转换
  105 + binder.registerCustomEditor(Timestamp.class, new PropertyEditorSupport() {
  106 +
  107 + @Override
  108 + public void setAsText(String text) {
  109 + Date date = DateUtil.parseDate(text);
  110 + setValue(date == null ? null : new Timestamp(date.getTime()));
  111 + }
  112 + });
84 113 }
85 114 }
platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java View file @ 03a1edd
... ... @@ -19,6 +19,8 @@
19 19 public static SimpleDateFormat m_d = new SimpleDateFormat("MM/dd");
20 20 public static SimpleDateFormat y_m_d_h_m_s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
21 21 public static SimpleDateFormat y_m_d_h_m1 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
  22 + public static String[] parsePatterns = { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss",
  23 + "yyyy/MM/dd HH:mm" };
22 24  
23 25 public static SimpleDateFormat y_m_d_h_m = new SimpleDateFormat("yyyyMMddHHmm");
24 26 public static SimpleDateFormat yyyyMMddHHmmssSSS = new SimpleDateFormat("yyyyMMddHHmmssSSS");
... ... @@ -819,5 +821,20 @@
819 821 return new Date[]{parseYMD(snDateString.substring(0, 10)), parseYMDEnd(snDateString.substring(13, 23))};
820 822 }
821 823  
  824 + /**
  825 + * 日期型字符串转化为日期 格式
  826 + * { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm",
  827 + * "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm" }
  828 + */
  829 + public static Date parseDate(Object str) {
  830 + if (str == null) {
  831 + return null;
  832 + }
  833 + try {
  834 + return org.apache.commons.lang3.time.DateUtils.parseDate(str.toString(), parsePatterns);
  835 + } catch (ParseException e) {
  836 + return null;
  837 + }
  838 + }
822 839 }
platform-operate-api/pom.xml View file @ 03a1edd
... ... @@ -71,6 +71,17 @@
71 71 <artifactId>activemq-pool</artifactId>
72 72 <version>${org.activemq.version}</version>
73 73 </dependency>
  74 + <dependency>
  75 + <groupId>org.apache.commons</groupId>
  76 + <artifactId>commons-lang3</artifactId>
  77 + <version>3.4</version>
  78 + </dependency>
  79 + <dependency>
  80 + <groupId>org.eclipse.jetty</groupId>
  81 + <artifactId>jetty-servlets</artifactId>
  82 + <version>9.3.8.v20160314</version>
  83 + </dependency>
  84 +
74 85 </dependencies>
75 86 <build>
76 87 <resources>
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java View file @ 03a1edd
... ... @@ -34,9 +34,21 @@
34 34 */
35 35 @RequestMapping(method = RequestMethod.GET,value = "/getCheckStatistics")
36 36 @ResponseBody
37   - public BaseObjectResponse getCheckStatistics(Date startDate, Date endDate,
  37 + public BaseObjectResponse getCheckStatistics(String startDate, String endDate,
38 38 Integer startWeek, Integer endWeek, Integer childBirth) {
39 39 return reportService.areaCountFacade(startDate, endDate, startWeek, endWeek, childBirth);
40 40 }
  41 +
  42 + @RequestMapping(method = RequestMethod.GET,value = "/date")
  43 + @ResponseBody
  44 + public BaseObjectResponse testDate(Date startDate) {
  45 + if(startDate != null) {
  46 + System.out.println("startDate = [" + startDate.toLocaleString() + "]");
  47 + }
  48 + BaseObjectResponse obj = new BaseObjectResponse();
  49 + obj.setData(startDate);
  50 + return obj;
  51 + }
  52 +
41 53 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/dao/impl/BaseDaoImpl.java View file @ 03a1edd
... ... @@ -39,8 +39,8 @@
39 39 return qr.query(sql, new MapListHandler(), params.toArray());
40 40 } catch (SQLException e) {
41 41 logger.error("查询出错: sql: {}, params: {}", sql, params);
  42 + throw new RuntimeException();
42 43 }
43   - return null;
44 44 }
45 45 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/IReportService.java View file @ 03a1edd
... ... @@ -2,8 +2,6 @@
2 2  
3 3 import com.lyms.platform.common.result.BaseObjectResponse;
4 4  
5   -import java.util.Date;
6   -
7 5 /**
8 6 * 报表service
9 7 * @Author: litao
... ... @@ -21,6 +19,6 @@
21 19 * @param childBirth
22 20 * @return
23 21 */
24   - BaseObjectResponse areaCountFacade(Date startDate, Date endDate, Integer startWeek, Integer endWeek, Integer childBirth);
  22 + BaseObjectResponse areaCountFacade(String startDate, String endDate, Integer startWeek, Integer endWeek, Integer childBirth);
25 23 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java View file @ 03a1edd
... ... @@ -3,14 +3,13 @@
3 3 import com.lyms.platform.common.result.BaseObjectResponse;
4 4 import com.lyms.platform.operate.web.dao.IReportDao;
5 5 import com.lyms.platform.operate.web.service.IReportService;
  6 +import com.lyms.platform.operate.web.utils.MathUtil;
  7 +import org.apache.commons.lang.StringUtils;
6 8 import org.springframework.beans.factory.annotation.Autowired;
7 9 import org.springframework.stereotype.Service;
8 10 import scala.collection.mutable.StringBuilder;
9 11  
10   -import java.util.ArrayList;
11   -import java.util.Date;
12   -import java.util.List;
13   -import java.util.Map;
  12 +import java.util.*;
14 13  
15 14 /**
16 15 * @Author: litao
17 16  
18 17  
19 18  
... ... @@ -24,15 +23,77 @@
24 23 private IReportDao reportDao;
25 24  
26 25 @Override
27   - public BaseObjectResponse areaCountFacade(Date startDate, Date endDate, Integer startWeek, Integer endWeek, Integer childBirth) {
  26 + public BaseObjectResponse areaCountFacade(String startDate, String endDate, Integer startWeek, Integer endWeek, Integer childBirth) {
28 27 BaseObjectResponse rest = new BaseObjectResponse();
  28 + Map<String, Object> restMap = new HashMap<>();
29 29 List<Object> params = new ArrayList<>();
30 30 List<Map<String, Object>> mapList = reportDao.findList(getAreaCountFacadeSql(startDate, endDate, startWeek, endWeek, childBirth, params), params);
31   - rest.setData(mapList);
  31 +
  32 + List<Map<String, Object>> calcData = calcData(mapList);/** 计算报表数据 */
  33 +
  34 + restMap.put("reportData", calcData); /** 报表数据*/
  35 + restMap.put("xAxis", Arrays.asList("1次", "2次", "3次", "4次", "5次", "6次", "7次", "8次", "9次", "10次", "11次", "12次", "≥13次")); /** x轴数据 */
  36 + restMap.put("yAxis", createYData(calcData));
  37 +
  38 + if(StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)) {
  39 + restMap.put("recordDate", startDate.replace("-", "/") + " - " + endDate.replace("-", "/"));
  40 + }
  41 +
  42 + rest.setData(restMap);
32 43 return rest;
33 44 }
34 45  
35   - private String getAreaCountFacadeSql(Date startDate, Date endDate, Integer startWeek, Integer endWeek, Integer childBirth, List<Object> params) {
  46 + private List<Object> createYData(List<Map<String, Object>> calcData) {
  47 + List<Object> yData = new ArrayList<>();
  48 + for (Map<String, Object> map : calcData) {
  49 + yData.add(map.get("people"));
  50 + }
  51 + return yData;
  52 + }
  53 +
  54 + private List<Map<String, Object>> calcData(List<Map<String, Object>> mapList) {
  55 + List<Map<String, Object>> restMap = new ArrayList<>();
  56 + int countPeople = 0; /** 体检所有人数 */
  57 + int otherPeople = 0; /** 存储 >= 13次的 所有人数 */
  58 + double residualRatio = 1; /** 所剩比率 */
  59 + for (Map<String, Object> map : mapList) {
  60 + countPeople += Integer.parseInt(map.get("EXAMINE_CNT").toString());
  61 + }
  62 +
  63 + for (Map<String, Object> map : mapList) {
  64 + String number = map.get("EXAMINE_HISTORY_NUM").toString(); /** 次数 */
  65 + String people = map.get("EXAMINE_CNT").toString(); /** 人数 */
  66 + if(StringUtils.isNotBlank(number) && StringUtils.isNotBlank(people)) {
  67 + Integer count = Integer.valueOf(number);
  68 + if(count >= 13) {
  69 + otherPeople += Integer.valueOf(people);
  70 + } else {
  71 + String proportion = MathUtil.division(Integer.valueOf(people), countPeople);
  72 + residualRatio -= Double.valueOf(proportion);
  73 + Map<String, Object> m = new HashMap<>();
  74 + m.put("number", number);
  75 + m.put("people", people);
  76 + m.put("proportion", MathUtil.doubleFormat(Double.valueOf(proportion) * 100) + "%");
  77 + restMap.add(m);
  78 + }
  79 + }
  80 + }
  81 +
  82 + /** 处理13次以上的 */
  83 + Map<String, Object> m = new HashMap<>();
  84 + m.put("number", 13);
  85 + m.put("people", otherPeople);
  86 + m.put("proportion", MathUtil.doubleFormat(Double.valueOf(residualRatio) * 100) + "%");
  87 + restMap.add(m);
  88 +
  89 + /** 处理总数 */
  90 + m.put("people", countPeople);
  91 + m.put("proportion", "100%");
  92 + restMap.add(m);
  93 + return restMap;
  94 + }
  95 +
  96 + private String getAreaCountFacadeSql(String startDate, String endDate, Integer startWeek, Integer endWeek, Integer childBirth, List<Object> params) {
36 97 StringBuilder sql = new StringBuilder();
37 98 sql.append("SELECT B.EXAMINE_HISTORY_NUM, ")
38 99 .append("COUNT(B.EXAMINE_ID) AS EXAMINE_CNT ")
... ... @@ -49,7 +110,7 @@
49 110 }
50 111  
51 112 if(startDate != null && endDate != null) {
52   - sql.append("AND A.CREATE_DATE BETWEEN ? AND ? ");
  113 + sql.append("AND A.CREATE_DATE BETWEEN to_date(?,'yyyy-mm-dd') AND to_date(?,'yyyy-mm-dd') ");
53 114 params.add(startDate);
54 115 params.add(endDate);
55 116 }
56 117  
... ... @@ -60,9 +121,11 @@
60 121 params.add(endWeek);
61 122 }
62 123  
63   - sql.append("GROUP BY B.EXAMINE_HISTORY_NUM");
  124 + sql.append("GROUP BY B.EXAMINE_HISTORY_NUM ")
  125 + .append("ORDER BY EXAMINE_HISTORY_NUM");
64 126  
65 127 return sql.toString();
66 128 }
  129 +
67 130 }