Commit 103b9065f9207b96ec0f327ecdbddee864fff2c2
1 parent
91fc2f2476
Exists in
master
and in
6 other branches
血糖
Showing 1 changed file with 102 additions and 70 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodSugarServiceImpl.java
View file @
103b906
... | ... | @@ -357,82 +357,114 @@ |
357 | 357 | } |
358 | 358 | |
359 | 359 | |
360 | - // 周平均 | |
361 | - Date date = new Date(); | |
362 | - List<Map<String, Object>> weekAvgMap = new ArrayList<>(); | |
363 | - Map<Integer, Map<String, Object>> weekAvgMapTemp = new LinkedHashMap<>(); | |
364 | - Date weekStart = DateUtil.getYmdDate(DateUtil.addDay(DateUtil.addWeek(date, -1), 1)); | |
365 | - List<BloodSugar> bloodSugarsWeek = mongoTemplate.find(Query.query(Criteria.where("pid").is(pid).and("created").gte(weekStart)).with(new Sort(Sort.Direction.DESC, "created")), BloodSugar.class); | |
366 | - for (BloodSugar bloodSugar : bloodSugarsWeek) { | |
367 | - if(weekAvgMapTemp.containsKey(bloodSugar.getBloodSugarType())) { | |
368 | - Map<String, Object> temp = weekAvgMapTemp.get(bloodSugar.getBloodSugarType()); | |
369 | - temp.put("dayCount", Integer.parseInt(temp.get("dayCount") + "") + 1); // 总共有记录的天数 | |
370 | - temp.put("sugarCount", Double.parseDouble(temp.get("sugarCount") + "") + Double.parseDouble(bloodSugar.getBloodSugar())); // 总共所有记录的和 | |
371 | - weekAvgMapTemp.put(bloodSugar.getBloodSugarType(), temp); | |
372 | - } else { | |
373 | - Map<String, Object> temp = new HashMap<>(); | |
374 | - temp.put("dayCount", 1); // 总共有记录的天数 | |
375 | - temp.put("sugarCount", Double.parseDouble(bloodSugar.getBloodSugar())); // 总共所有记录的和 | |
376 | - weekAvgMapTemp.put(bloodSugar.getBloodSugarType(), temp); | |
377 | - } | |
378 | - } | |
379 | - for (BloodSugarEnums bloodSugarEnums : BloodSugarEnums.values()) { | |
380 | - Map<String, Object> weekMap = new HashMap<>(); | |
381 | - weekMap.put("name", bloodSugarEnums.getName()); | |
382 | - boolean flag = true; | |
383 | - for (Map.Entry<Integer, Map<String, Object>> entry : weekAvgMapTemp.entrySet()) { | |
384 | - if(entry.getKey() == bloodSugarEnums.getId()) { | |
385 | - Map<String, Object> map = entry.getValue(); | |
386 | - Integer dayCount = (Integer) map.get("dayCount"); | |
387 | - Double sugarCount = (Double) map.get("sugarCount"); | |
388 | - weekMap.put("value", MathUtil.doubleFormat2(sugarCount / dayCount)); | |
389 | - flag = false; | |
390 | - } | |
391 | - } | |
392 | - if(flag) { | |
393 | - weekMap.put("value", ""); | |
394 | - } | |
395 | - weekAvgMap.add(weekMap); | |
396 | - } | |
360 | +// // 周平均 | |
361 | +// Date date = new Date(); | |
362 | +// List<Map<String, Object>> weekAvgMap = new ArrayList<>(); | |
363 | +// Map<Integer, Map<String, Object>> weekAvgMapTemp = new LinkedHashMap<>(); | |
364 | +// Date weekStart = DateUtil.getYmdDate(DateUtil.addDay(DateUtil.addWeek(date, -1), 1)); | |
365 | +// List<BloodSugar> bloodSugarsWeek = mongoTemplate.find(Query.query(Criteria.where("pid").is(pid).and("created").gte(weekStart)).with(new Sort(Sort.Direction.DESC, "created")), BloodSugar.class); | |
366 | +// for (BloodSugar bloodSugar : bloodSugarsWeek) { | |
367 | +// if(weekAvgMapTemp.containsKey(bloodSugar.getBloodSugarType())) { | |
368 | +// Map<String, Object> temp = weekAvgMapTemp.get(bloodSugar.getBloodSugarType()); | |
369 | +// temp.put("dayCount", Integer.parseInt(temp.get("dayCount") + "") + 1); // 总共有记录的天数 | |
370 | +// temp.put("sugarCount", Double.parseDouble(temp.get("sugarCount") + "") + Double.parseDouble(bloodSugar.getBloodSugar())); // 总共所有记录的和 | |
371 | +// weekAvgMapTemp.put(bloodSugar.getBloodSugarType(), temp); | |
372 | +// } else { | |
373 | +// Map<String, Object> temp = new HashMap<>(); | |
374 | +// temp.put("dayCount", 1); // 总共有记录的天数 | |
375 | +// temp.put("sugarCount", Double.parseDouble(bloodSugar.getBloodSugar())); // 总共所有记录的和 | |
376 | +// weekAvgMapTemp.put(bloodSugar.getBloodSugarType(), temp); | |
377 | +// } | |
378 | +// } | |
379 | +// for (BloodSugarEnums bloodSugarEnums : BloodSugarEnums.values()) { | |
380 | +// Map<String, Object> weekMap = new HashMap<>(); | |
381 | +// weekMap.put("name", bloodSugarEnums.getName()); | |
382 | +// boolean flag = true; | |
383 | +// for (Map.Entry<Integer, Map<String, Object>> entry : weekAvgMapTemp.entrySet()) { | |
384 | +// if(entry.getKey() == bloodSugarEnums.getId()) { | |
385 | +// Map<String, Object> map = entry.getValue(); | |
386 | +// Integer dayCount = (Integer) map.get("dayCount"); | |
387 | +// Double sugarCount = (Double) map.get("sugarCount"); | |
388 | +// weekMap.put("value", MathUtil.doubleFormat2(sugarCount / dayCount)); | |
389 | +// flag = false; | |
390 | +// } | |
391 | +// } | |
392 | +// if(flag) { | |
393 | +// weekMap.put("value", ""); | |
394 | +// } | |
395 | +// weekAvgMap.add(weekMap); | |
396 | +// } | |
397 | 397 | |
398 | - // 月平均 | |
398 | +// // 月平均 | |
399 | +// List<Map<String, Object>> monthAvgMap = new ArrayList<>(); | |
400 | +// Map<Integer, Map<String, Object>> monthAvgTemp = new LinkedHashMap<>(); | |
401 | +//// Date monthStart = DateUtil.addMonth(date, -1); | |
402 | +// Date monthStart = DateUtil.getYmdDate(DateUtil.addDay(DateUtil.addMonth(date, -1), 1)); | |
403 | +// List<BloodSugar> bloodSugarsMonth = mongoTemplate.find(Query.query(Criteria.where("pid").is(pid).and("created").gte(monthStart)).with(new Sort(Sort.Direction.DESC, "created")), BloodSugar.class); | |
404 | +// for (BloodSugar bloodSugar : bloodSugarsMonth) { | |
405 | +// if(monthAvgTemp.containsKey(bloodSugar.getBloodSugarType())) { | |
406 | +// Map<String, Object> temp = monthAvgTemp.get(bloodSugar.getBloodSugarType()); | |
407 | +// temp.put("dayCount", Integer.parseInt(temp.get("dayCount") + "") + 1); // 总共有记录的天数 | |
408 | +// temp.put("sugarCount", Double.parseDouble(temp.get("sugarCount") + "") + Double.parseDouble(bloodSugar.getBloodSugar())); // 总共所有记录的和 | |
409 | +// monthAvgTemp.put(bloodSugar.getBloodSugarType(), temp); | |
410 | +// } else { | |
411 | +// Map<String, Object> temp = new HashMap<>(); | |
412 | +// temp.put("dayCount", 1); // 总共有记录的天数 | |
413 | +// temp.put("sugarCount", Double.parseDouble(bloodSugar.getBloodSugar())); // 总共所有记录的和 | |
414 | +// monthAvgTemp.put(bloodSugar.getBloodSugarType(), temp); | |
415 | +// } | |
416 | +// } | |
417 | +// for (BloodSugarEnums bloodSugarEnums : BloodSugarEnums.values()) { | |
418 | +// Map<String, Object> monthMap = new HashMap<>(); | |
419 | +// monthMap.put("name", bloodSugarEnums.getName()); | |
420 | +// boolean flag = true; | |
421 | +// for (Map.Entry<Integer, Map<String, Object>> entry : monthAvgTemp.entrySet()) { | |
422 | +// monthMap.put("name", bloodSugarEnums.getName()); | |
423 | +// if(entry.getKey() == bloodSugarEnums.getId()) { | |
424 | +// Map<String, Object> map = entry.getValue(); | |
425 | +// Integer dayCount = (Integer) map.get("dayCount"); | |
426 | +// Double sugarCount = (Double) map.get("sugarCount"); | |
427 | +// monthMap.put("value", MathUtil.doubleFormat2(sugarCount / dayCount)); | |
428 | +// flag = false; | |
429 | +// } | |
430 | +// } | |
431 | +// if(flag) { | |
432 | +// monthMap.put("value", ""); | |
433 | +// } | |
434 | +// monthAvgMap.add(monthMap); | |
435 | +// } | |
436 | + | |
437 | + | |
399 | 438 | List<Map<String, Object>> monthAvgMap = new ArrayList<>(); |
400 | - Map<Integer, Map<String, Object>> monthAvgTemp = new LinkedHashMap<>(); | |
401 | -// Date monthStart = DateUtil.addMonth(date, -1); | |
402 | - Date monthStart = DateUtil.getYmdDate(DateUtil.addDay(DateUtil.addMonth(date, -1), 1)); | |
403 | - List<BloodSugar> bloodSugarsMonth = mongoTemplate.find(Query.query(Criteria.where("pid").is(pid).and("created").gte(monthStart)).with(new Sort(Sort.Direction.DESC, "created")), BloodSugar.class); | |
404 | - for (BloodSugar bloodSugar : bloodSugarsMonth) { | |
405 | - if(monthAvgTemp.containsKey(bloodSugar.getBloodSugarType())) { | |
406 | - Map<String, Object> temp = monthAvgTemp.get(bloodSugar.getBloodSugarType()); | |
407 | - temp.put("dayCount", Integer.parseInt(temp.get("dayCount") + "") + 1); // 总共有记录的天数 | |
408 | - temp.put("sugarCount", Double.parseDouble(temp.get("sugarCount") + "") + Double.parseDouble(bloodSugar.getBloodSugar())); // 总共所有记录的和 | |
409 | - monthAvgTemp.put(bloodSugar.getBloodSugarType(), temp); | |
410 | - } else { | |
411 | - Map<String, Object> temp = new HashMap<>(); | |
412 | - temp.put("dayCount", 1); // 总共有记录的天数 | |
413 | - temp.put("sugarCount", Double.parseDouble(bloodSugar.getBloodSugar())); // 总共所有记录的和 | |
414 | - monthAvgTemp.put(bloodSugar.getBloodSugarType(), temp); | |
415 | - } | |
416 | - } | |
417 | - for (BloodSugarEnums bloodSugarEnums : BloodSugarEnums.values()) { | |
418 | - Map<String, Object> monthMap = new HashMap<>(); | |
419 | - monthMap.put("name", bloodSugarEnums.getName()); | |
420 | - boolean flag = true; | |
421 | - for (Map.Entry<Integer, Map<String, Object>> entry : monthAvgTemp.entrySet()) { | |
439 | + List<Map<String, Object>> weekAvgMap = new ArrayList<>(); | |
440 | + Date monthStart = new Date(); | |
441 | + DateUtil.formatYmd(monthStart); | |
442 | + List<BloodSugar> bss = mongoTemplate.find(Query.query(Criteria.where("pid").is(pid).and("created").gte(monthStart)).with(new Sort(Sort.Direction.DESC, "created")), BloodSugar.class); | |
443 | + if (CollectionUtils.isNotEmpty(bss)) | |
444 | + { | |
445 | + for (BloodSugarEnums bloodSugarEnums : BloodSugarEnums.values()) { | |
446 | + Map<String, Object> monthMap = new HashMap<>(); | |
422 | 447 | monthMap.put("name", bloodSugarEnums.getName()); |
423 | - if(entry.getKey() == bloodSugarEnums.getId()) { | |
424 | - Map<String, Object> map = entry.getValue(); | |
425 | - Integer dayCount = (Integer) map.get("dayCount"); | |
426 | - Double sugarCount = (Double) map.get("sugarCount"); | |
427 | - monthMap.put("value", MathUtil.doubleFormat2(sugarCount / dayCount)); | |
428 | - flag = false; | |
448 | + boolean flag = true; | |
449 | + for (BloodSugar bs : bss) { | |
450 | + monthMap.put("name",bloodSugarEnums.getName()); | |
451 | + if (bs.getBloodSugarType() == bloodSugarEnums.getId()) | |
452 | + { | |
453 | + monthMap.put("value", bs.getBloodSugar()); | |
454 | + | |
455 | + flag = false; | |
456 | + } | |
429 | 457 | } |
458 | + if(flag) { | |
459 | + monthMap.put("value", ""); | |
460 | + } | |
461 | + monthAvgMap.add(monthMap); | |
462 | + weekAvgMap.add(monthMap); | |
430 | 463 | } |
431 | - if(flag) { | |
432 | - monthMap.put("value", ""); | |
433 | - } | |
434 | - monthAvgMap.add(monthMap); | |
464 | + | |
465 | + | |
435 | 466 | } |
467 | + | |
436 | 468 | |
437 | 469 | CollectionUtils.sortListByMapKeyWithDate(restList, "craeted"); |
438 | 470 | List<String> monthCountSet3 = new ArrayList<>(); |