Commit 52469eb6fdbf39787d734c8f05d330e0974bafd1

Authored by yangfei

Merge remote-tracking branch 'origin/master'

Showing 4 changed files

platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java View file @ 52469eb
... ... @@ -42,7 +42,7 @@
42 42 @ResponseBody
43 43 @TokenRequired
44 44 @RequestMapping(value = "/patients", method = RequestMethod.GET)
45   - public BaseObjectResponse patients(String provinceId, String cityId, String areaId, String streetId, Integer statistType, Integer statistVal,
  45 + public BaseObjectResponse patients(@RequestParam String provinceId, String cityId, String areaId, String streetId, @RequestParam Integer statistType, Integer statistVal,
46 46 Integer ageType, Integer patientType, Date startDate, Date endDate, HttpServletRequest request) {
47 47 return reportService.patients(provinceId, cityId, areaId, streetId, statistType, statistVal, ageType, patientType, startDate, endDate, getUserId(request));
48 48 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/ViewFacade.java View file @ 52469eb
... ... @@ -1488,7 +1488,7 @@
1488 1488 if (antExcAddOther.getFitness() != null) {
1489 1489 String fitness = FitnessEnums.getTitle(Integer.parseInt(antExcAddOther.getFitness().toString()));
1490 1490 if (antExcAddOther.getFitnessRemark() != null) {
1491   - mapData.put("fitness", fitness + "(" + antExcAddOther.getFitnessRemark() + ")");
  1491 + mapData.put("fitness", fitness + "(" + antExcAddOther.getFitnessRemark() + ")");
1492 1492 } else {
1493 1493 mapData.put("fitness", fitness);
1494 1494 }
... ... @@ -1515,7 +1515,7 @@
1515 1515 if (otherMap.containsKey("fmType")) {
1516 1516 String fmType = CZFmTypeEnums.getTitle(Integer.parseInt(otherMap.get("fmType").toString()));
1517 1517 if (otherMap.get("fmTypeRemark") != null) {
1518   - mapData.put("fmType", fmType + "," + otherMap.get("fmTypeRemark"));
  1518 + mapData.put("fmType", fmType + "(" + otherMap.get("fmTypeRemark") + ")");
1519 1519 } else {
1520 1520 mapData.put("fmType", fmType);
1521 1521 }
... ... @@ -1525,7 +1525,7 @@
1525 1525 if (otherMap.containsKey("fitness")) {
1526 1526 String fitness = FitnessEnums.getTitle(Integer.parseInt(otherMap.get("fitness").toString()));
1527 1527 if (otherMap.get("fitnessRemark") != null) {
1528   - mapData.put("fitness", fitness + "," + otherMap.get("fitnessRemark"));
  1528 + mapData.put("fitness", fitness + "(" + otherMap.get("fitnessRemark") + ")");
1529 1529 } else {
1530 1530 mapData.put("fitness", fitness);
1531 1531 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java View file @ 52469eb
... ... @@ -184,7 +184,7 @@
184 184  
185 185 /**
186 186 * 建档统计
187   - * @param statistType 统计环比 1=周 2=月 3=季度 4=半年 5=年
  187 + * @param statistType 1=占比 2=环比
188 188 * @param ageType 1=全部年龄 2=20岁以下 3=20-30岁 4=30-40岁 5=40岁以上
189 189 * @param patientType 建档孕周 1=孕早期 2=孕中期 3=孕晚期
190 190 * @return
... ... @@ -203,6 +203,7 @@
203 203 List<Object> line = new ArrayList<>();
204 204 Map<String, Object> barMap = new HashMap<>();
205 205 Map<String, Object> lineMap = new HashMap<>();
  206 + List<Map<String, Date>> range = DateUtil.getRange(startDate, endDate);
206 207  
207 208 if(StringUtils.isNotEmpty(aredId)) { // 按照医院统计
208 209 List<String> patientIds = new ArrayList<>();
... ... @@ -217,6 +218,47 @@
217 218 xDatas.add(couponMapper.findHospitalNameById((String) mappedResult.get("_id")));
218 219 bar.add((Integer) mappedResult.get("count"));
219 220 }
  221 +
  222 + // 拼装tab数据
  223 + titleList.add("医院名称");
  224 + titleList.add("统计指标(人)");
  225 + for (Map<String, Date> map : range) {
  226 + titleList.add(DateUtil.getyyyy_mm(map.get("cname")));
  227 + }
  228 + Map<String, Map<String, Integer>> tempMap = new HashMap<>();
  229 + for (Patients patient : patients) {
  230 + if(tempMap.containsKey(patient.getHospitalId())) {
  231 + Map<String, Integer> map = tempMap.get(patient.getHospitalId());
  232 + for (Map<String, Date> dateMap : range) {
  233 + String cname = DateUtil.getyyyy_mm(dateMap.get("cname"));
  234 + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime()
  235 + && patient.getBookbuildingDate().getTime() < dateMap.get("end").getTime()) {
  236 + map.put(cname, map.containsKey(cname) ? map.get(cname) + 1 : 1);
  237 + break;
  238 + }
  239 + }
  240 + } else {
  241 + Map<String, Integer> temp = new HashMap<>();
  242 + for (Map<String, Date> dateMap : range) {
  243 + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime()
  244 + && patient.getBookbuildingDate().getTime() < dateMap.get("end").getTime()) {
  245 + temp.put(DateUtil.getyyyy_mm(dateMap.get("cname")), 1);
  246 + break;
  247 + }
  248 + }
  249 + tempMap.put(patient.getHospitalId(), temp);
  250 + }
  251 + }
  252 + for (Map.Entry<String, Map<String, Integer>> entry : tempMap.entrySet()) {
  253 + List<String> tempList = new ArrayList<>();
  254 + tempList.add(couponMapper.findHospitalNameById(entry.getKey()));
  255 + tempList.add("建档人数");
  256 + for (Map<String, Date> map : range) {
  257 + tempList.add(entry.getValue().containsKey(DateUtil.getyyyy_mm(map.get("cname"))) ?
  258 + entry.getValue().get(DateUtil.getyyyy_mm(map.get("cname"))) + "" : "0");
  259 + }
  260 + tabList.add(tempList);
  261 + }
220 262 } else {
221 263 Map<Integer, Integer> areaCountMap = new HashMap<>();
222 264 String groupKey = StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId"; // 按照区县或者市统计
223 265  
224 266  
225 267  
226 268  
227 269  
228 270  
229 271  
230 272  
231 273  
... ... @@ -242,94 +284,89 @@
242 284 }
243 285  
244 286 // 拼装tab数据
245   - List<Map<String, Date>> range = DateUtil.getRange(startDate, endDate);
246   - if(StringUtils.isNotEmpty(cityId)) { // 按照区县来
247   - titleList.add("");
248   - titleList.add("");
249   - titleList.add("");
250   - for (Map<String, Date> map : range) {
251   - titleList.add(DateUtil.getyyyy_mm(map.get("cname")));
252   - }
253   - } else { // 按照城市来
254   - titleList.add("城市名称");
255   - titleList.add("机构数");
256   - titleList.add("统计指标(人)");
257   - for (Map<String, Date> map : range) {
258   - titleList.add(DateUtil.getyyyy_mm(map.get("cname")));
259   - }
260   - tabList.add(titleList);
261   - List<Map<String, Object>> infos = new ArrayList<>();
262   - for (Patients patient : patients) {
263   - for (Map<String, Object> map : hospitals) {
264   - if(patient.getHospitalId().equals(map.get("id").toString())) {
265   - boolean flag = true;
266   - for (Map<String, Object> info : infos) {
267   - if(map.get("cityId").equals(info.get("id"))) {
268   - Set<String> hids = (Set<String>) info.get("hids");
269   - hids.add(patient.getHospitalId());
270   - for (Map<String, Date> dateMap : range) {
271   - if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime()
272   - && patient.getBookbuildingDate().getTime() < dateMap.get("end").getTime()) {
273   - String monthKey = DateUtil.getyyyy_mm(dateMap.get("cname"));
274   - if(info.containsKey(monthKey)) {
275   - info.put(monthKey, (Integer) info.get(monthKey) + 1);
276   - flag = false;
277   - } else {
278   - info.put(monthKey, 1);
279   - flag = false;
280   - }
281   - }
282   - }
283   - }
284   - }
285   - if(flag) {
  287 + titleList.add((StringUtils.isNotEmpty(cityId) ? "区县" : "城市") + "名称");
  288 + titleList.add("机构数");
  289 + titleList.add("统计指标(人)");
  290 + for (Map<String, Date> map : range) {
  291 + titleList.add(DateUtil.getyyyy_mm(map.get("cname")));
  292 + }
  293 +
  294 + List<Map<String, Object>> infos = new ArrayList<>();
  295 + for (Patients patient : patients) {
  296 + for (Map<String, Object> map : hospitals) {
  297 + if(patient.getHospitalId().equals(map.get("id").toString())) {
  298 + boolean flag = true;
  299 + for (Map<String, Object> info : infos) {
  300 + if(map.get((StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId")).equals(info.get("id"))) {
  301 + Set<String> hids = (Set<String>) info.get("hids");
  302 + hids.add(patient.getHospitalId());
286 303 for (Map<String, Date> dateMap : range) {
287 304 if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime()
288 305 && patient.getBookbuildingDate().getTime() < dateMap.get("end").getTime()) {
289 306 String monthKey = DateUtil.getyyyy_mm(dateMap.get("cname"));
290   - Map<String, Object> info = new HashMap<>();
291   - Set<String> hids = new HashSet<>();
292   - hids.add(patient.getHospitalId());
293   - info.put(monthKey, 1);
294   - info.put("id", map.get("cityId"));
295   - info.put("hids", hids);
296   - infos.add(info);
  307 + if(info.containsKey(monthKey)) {
  308 + info.put(monthKey, (Integer) info.get(monthKey) + 1);
  309 + flag = false;
  310 + } else {
  311 + info.put(monthKey, 1);
  312 + flag = false;
  313 + }
297 314 }
298 315 }
299 316 }
300 317 }
  318 + if(flag) {
  319 + for (Map<String, Date> dateMap : range) {
  320 + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime()
  321 + && patient.getBookbuildingDate().getTime() < dateMap.get("end").getTime()) {
  322 + String monthKey = DateUtil.getyyyy_mm(dateMap.get("cname"));
  323 + Map<String, Object> info = new HashMap<>();
  324 + Set<String> hids = new HashSet<>();
  325 + hids.add(patient.getHospitalId());
  326 + info.put(monthKey, 1);
  327 + info.put("id", map.get((StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId")));
  328 + info.put("hids", hids);
  329 + infos.add(info);
  330 + }
  331 + }
  332 + }
301 333 }
302 334 }
  335 + }
303 336  
304   - for (Map<String, Object> info : infos) {
305   - List<String> tempList = new ArrayList<>();
306   - tempList.add(findName(info.get("id")));
307   - tempList.add(((Set<String>) info.get("hids")).size() + "");
308   - tempList.add("建档总数");
309   - for (Map<String, Date> map : range) {
310   - tempList.add(info.containsKey(DateUtil.getyyyy_mm(map.get("cname"))) ?
311   - info.get(DateUtil.getyyyy_mm(map.get("cname"))) + "" : "0");
312   - }
313   - tabList.add(tempList);
  337 + for (Map<String, Object> info : infos) {
  338 + List<String> tempList = new ArrayList<>();
  339 + tempList.add(findName(info.get("id")));
  340 + tempList.add(((Set<String>) info.get("hids")).size() + "");
  341 + tempList.add("建档总数");
  342 + for (Map<String, Date> map : range) {
  343 + tempList.add(info.containsKey(DateUtil.getyyyy_mm(map.get("cname"))) ?
  344 + info.get(DateUtil.getyyyy_mm(map.get("cname"))) + "" : "0");
314 345 }
315   - System.out.println(tabList);
316   - }
  346 + tabList.add(tempList);
317 347 }
  348 + System.out.println(tabList);
  349 + }
318 350  
319   - setTabListInfo(tabList);
  351 + tabList.add(0, titleList);
  352 + setTabListInfo(tabList, StringUtils.isNotEmpty(aredId) ? 2 : 3);
320 353  
321 354 barMap.put("data", bar);
322 355 barMap.put("type", "bar");
323 356 barMap.put("name", "建档总数");
324 357 series.add(barMap);
325 358  
326   - Integer count = 0;
327   - for (Integer num : bar) {
328   - count += num;
  359 + if(statistType == 1) {
  360 + Integer count = 0;
  361 + for (Integer num : bar) {
  362 + count += num;
  363 + }
  364 + for (Integer num : bar) {
  365 + line.add(MathUtil.getProportion(num, count));
  366 + }
  367 + } else if(statistType == 2) {
  368 +
329 369 }
330   - for (Integer num : bar) {
331   - line.add(MathUtil.getProportion(num, count));
332   - }
333 370 lineMap.put("data", line);
334 371 lineMap.put("type", "line");
335 372 lineMap.put("name", "建档总数");
... ... @@ -344,7 +381,7 @@
344 381 return RespBuilder.buildSuccess(restMap);
345 382 }
346 383  
347   - private void setTabListInfo(List<List<String>> tabList) {
  384 + private void setTabListInfo(List<List<String>> tabList, int index) {
348 385 if(CollectionUtils.isNotEmpty(tabList)) {
349 386 for (int i = 0; i < tabList.size(); i++) {
350 387 List<String> list = tabList.get(i);
... ... @@ -354,7 +391,7 @@
354 391 list.add("合计");
355 392 } else {
356 393 int count = 0;
357   - for (int j = 3; j < list.size(); j++) {
  394 + for (int j = index; j < list.size(); j++) {
358 395 count += Integer.parseInt(list.get(j));
359 396 }
360 397 list.add(0, ++seq + "");
361 398  
... ... @@ -464,12 +501,21 @@
464 501 return patients;
465 502 }
466 503  
467   - // 建档孕周 1=孕早期 2=孕中期 3=孕晚期
  504 + // 建档孕周 1=孕早期(0~12周) 2=孕中期(13-27) 3=孕晚期(28~42)
468 505 private void doFilter(List<Patients> patients, Integer ageType, Integer patientType) {
469 506 if(patientType != null) {
470 507 Iterator<Patients> iterator = patients.iterator();
471 508 while (iterator.hasNext()) {
472   -
  509 + Integer week = DateUtil.getWeek(iterator.next().getLastMenses(), new Date());
  510 + if(week != null) {
  511 + if(patientType == 1 && week > 12) {
  512 + iterator.remove();
  513 + } else if(patientType == 2 && (week < 13 || week > 27)) {
  514 + iterator.remove();
  515 + } else if(patientType == 3 && week < 28) {
  516 + iterator.remove();
  517 + }
  518 + }
473 519 }
474 520 }
475 521 if (ageType != null) {
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/MathUtil.java View file @ 52469eb
... ... @@ -77,6 +77,24 @@
77 77 return "0.00%";
78 78 }
79 79  
  80 + public static String getProportion(Integer num, Integer count) {
  81 + if(num != null && StringUtils.isNumeric(num.toString()) && count != null && count != 0) {
  82 + Double division = Double.parseDouble(division(Integer.parseInt(num.toString()), count)) * 100;
  83 + String s = doubleFormat(division);
  84 + s = removeZero(s);
  85 + return s;
  86 + }
  87 + return "0";
  88 + }
  89 +
  90 + public static String removeZero(String s) {
  91 + if(StringUtils.isNotEmpty(s) && ((s.endsWith("0") && s.contains(".")) || s.endsWith("."))) {
  92 + s = s.substring(0, s.length() - 1);
  93 + return removeZero(s);
  94 + }
  95 + return s;
  96 + }
  97 +
80 98 public static String getProportion(Object obj, Object count) {
81 99 if(StringUtils.isNotBlank("count") && StringUtils.isNumeric(count.toString()))
82 100 return getProportion(obj, Integer.parseInt(count.toString()));
... ... @@ -92,6 +110,10 @@
92 110 */
93 111 public static Double division(Double a, Double b, Integer digit) {
94 112 return new BigDecimal(a / b).setScale(digit, BigDecimal.ROUND_HALF_UP).doubleValue();
  113 + }
  114 +
  115 + public static void main(String[] args) {
  116 + System.out.println(getProportion(30, 100));
95 117 }
96 118  
97 119