Commit c1bdbdfab06deda9aee964e3000ae34ef07069d1

Authored by dongqin
1 parent 20ca66481e

修复bug

Showing 1 changed file with 47 additions and 27 deletions

platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BabyEvaluationCriterionServiceImpl.java View file @ c1bdbdf
... ... @@ -17,6 +17,10 @@
17 17 import org.springframework.beans.factory.annotation.Autowired;
18 18 import org.springframework.data.domain.Sort;
19 19 import org.springframework.data.mongodb.core.MongoTemplate;
  20 +import org.springframework.data.mongodb.core.aggregation.Aggregation;
  21 +import org.springframework.data.mongodb.core.aggregation.AggregationResults;
  22 +import org.springframework.data.mongodb.core.aggregation.GroupOperation;
  23 +import org.springframework.data.mongodb.core.aggregation.MatchOperation;
20 24 import org.springframework.data.mongodb.core.query.Criteria;
21 25 import org.springframework.data.mongodb.core.query.Query;
22 26 import org.springframework.data.mongodb.core.query.Update;
23 27  
24 28  
25 29  
26 30  
27 31  
... ... @@ -60,46 +64,46 @@
60 64 if (month > 84) {
61 65 return new BaseResponse().setErrorcode(ErrorCodeConstants.PARAMETER_ERROR).setErrormsg("操作失败,当前儿童年龄大于7岁");
62 66 }
63   - int month3 = getCurrentMonth(month, 3);
  67 + int month3 = getCurrentMonth(month, 3, 3);
64 68 if (month3 >= 3 && month3 <= 72) {
65 69  
66 70 // 大于等于3月龄 小于等于72月龄
67   - int month2 = getCurrentMonth(month3, 2);
68   - int month1 = getCurrentMonth(month2, 2);
69   - int month4 = getCurrentMonth(month3, 4);
70   - int month5 = getCurrentMonth(month4, 4);
  71 + int month2 = getCurrentMonth(month3, 2, 3);
  72 + int month1 = getCurrentMonth(month2, 2, 3);
  73 + int month4 = getCurrentMonth(month3, 4, 3);
  74 + int month5 = getCurrentMonth(month4, 4, 3);
71 75 months = new int[]{month1, month2, month3, month4, month5};
72 76  
73 77 }else if (month3 < 3) {
74 78 if (month3 == 1) {
75 79  
76 80 // 等于1月龄
77   - int month4 = getCurrentMonth(month3, 4);
78   - int month5 = getCurrentMonth(month4, 4);
  81 + int month4 = getCurrentMonth(month3, 4, 3);
  82 + int month5 = getCurrentMonth(month4, 4, 3);
79 83 months = new int[] {month3, month4, month5};
80 84  
81 85 }else if (month3 == 2) {
82 86  
83 87 // 等于2月龄
84   - int month2 = getCurrentMonth(month3, 2);
85   - int month4 = getCurrentMonth(month3, 4);
86   - int month5 = getCurrentMonth(month4, 4);
  88 + int month2 = getCurrentMonth(month3, 2, 3);
  89 + int month4 = getCurrentMonth(month3, 4, 3);
  90 + int month5 = getCurrentMonth(month4, 4, 3);
87 91 months = new int[] {month2, month3, month4, month5};
88 92 }
89 93 } else if (month3 > 72 && month3 <= 84) {
90 94 if (month3 == 78) {
91 95  
92 96 // 等于78月龄
93   - int month2 = getCurrentMonth(month3, 2);
94   - int month1 = getCurrentMonth(month2, 2);
95   - int month4 = getCurrentMonth(month3, 4);
  97 + int month2 = getCurrentMonth(month3, 2, 3);
  98 + int month1 = getCurrentMonth(month2, 2, 3);
  99 + int month4 = getCurrentMonth(month3, 4, 3);
96 100 months = new int[]{month1, month2, month3, month4};
97 101  
98 102 }else if (month3 == 84) {
99 103  
100 104 // 等于84月龄
101   - int month2 = getCurrentMonth(month3, 2);
102   - int month1 = getCurrentMonth(month2, 2);
  105 + int month2 = getCurrentMonth(month3, 2, 3);
  106 + int month1 = getCurrentMonth(month2, 2, 3);
103 107 months = new int[]{month1, month2, month3};
104 108 }
105 109 }
106 110  
107 111  
108 112  
... ... @@ -118,16 +122,16 @@
118 122 * @param index 表示下标位置
119 123 * @return
120 124 */
121   - private Integer getCurrentMonth(Integer month, Integer index){
  125 + private Integer getCurrentMonth(Integer month, Integer index, Integer type){
122 126 Query query = new Query();
123 127 if (2 == index){
124   - query.addCriteria(Criteria.where("month").lt(month).and("yn").is(YnEnums.YES.getId()));
  128 + query.addCriteria(Criteria.where("month").lt(month).and("yn").is(YnEnums.YES.getId()).and("type").is(type));
125 129 query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "month")));
126 130 } else if (3 == index) {
127   - query.addCriteria(Criteria.where("month").lte(month).and("yn").is(YnEnums.YES.getId()));
  131 + query.addCriteria(Criteria.where("month").lte(month).and("yn").is(YnEnums.YES.getId()).and("type").is(type));
128 132 query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "month")));
129 133 } else if (4 == index) {
130   - query.addCriteria(Criteria.where("month").gt(month).and("yn").is(YnEnums.YES.getId()));
  134 + query.addCriteria(Criteria.where("month").gt(month).and("yn").is(YnEnums.YES.getId()).and("type").is(type));
131 135 query.with(new Sort(new Sort.Order(Sort.Direction.ASC, "month")));
132 136 }
133 137  
... ... @@ -222,6 +226,15 @@
222 226  
223 227 mapList.add(objectMap);
224 228 }
  229 + BigDecimal defOldVal = BigDecimal.ZERO;
  230 + if (checkMonth - 2 > 1) {
  231 + /*MatchOperation match = Aggregation.match(Criteria.where(""));
  232 + GroupOperation group = Aggregation.group();
  233 + Aggregation aggregation = Aggregation.newAggregation(match, group);
  234 + AggregationResults<Map> aggregate = mongoTemplate.aggregate(aggregation, Map.class);
  235 + List<Map> mappedResults = aggregate.getMappedResults();*/
  236 + //mongoTemplate.find(Query.query(Criteria.where().))
  237 + }
225 238 int developmentQuotient = 0;
226 239 if (currentProjectVal > 0) {
227 240 mentalAge = new BigDecimal(currentProjectVal).divide(new BigDecimal(5), 0, BigDecimal.ROUND_HALF_UP).intValue();
228 241  
... ... @@ -663,10 +676,10 @@
663 676 String babyId = param.getBabyId();
664 677 boolean isPass = paramValid(param);
665 678 ExerciseAppraisalModel model = param;
666   - model.setCheckTime(new Date());
667 679 if (!isPass) {
668 680 return new BaseResponse().setErrorcode(ErrorCodeConstants.PARAMETER_ERROR).setErrormsg("参数缺失");
669 681 }
  682 + model.setCheckTime(new Date(model.getCheckTime().getTime() - 28800000));
670 683 String id = param.getId();
671 684 if (StringUtils.isEmpty(id)) {
672 685 // 新增运动测评
... ... @@ -675,6 +688,7 @@
675 688 return new BaseResponse().setErrorcode(ErrorCodeConstants.NO_DATA).setErrormsg("未查到该儿童的建档数据");
676 689 }
677 690 Integer month = DateUtil.getBabyAgeMonth(babyModel.getBirth(), new Date());
  691 + Integer currentMonth = getCurrentMonth(month, 3, 1);
678 692 model.setBirth(babyModel.getBirth());
679 693 model.setCardNo(babyModel.getCardNo());
680 694 model.setVcCardNo(babyModel.getVcCardNo());
681 695  
... ... @@ -689,14 +703,15 @@
689 703 // 总分
690 704 model.setTotalScore(model.getStandingComponent() + model.getSeatComponent() + model.getSupineComponent() + model.getLieProstratComponent());
691 705 // 百分位
692   - BabyEvaluationCriterionModel babyEvaluationCriterionModel = getBabyEvaluationCriterionModel(model, month);
  706 + BabyEvaluationCriterionModel babyEvaluationCriterionModel = getBabyEvaluationCriterionModel(model, currentMonth);
693 707 model.setPercentileScore(babyEvaluationCriterionModel.getPercent());
694 708 mongoTemplate.insert(model);
695 709 }
696 710  
697 711 if (StringUtils.isNotEmpty(id)) {
698   - Integer month = DateUtil.getBabyAgeMonth(model.getBirth(), new Date());
699   - model.setCheckTime(null);
  712 + Integer month = DateUtil.getBabyAgeMonth(model.getBirth(),
  713 + mongoTemplate.findOne(Query.query(Criteria.where("_id").is(id)), ExerciseAppraisalModel.class).getCreateTime());
  714 + Integer currentMonth = getCurrentMonth(month, 3, 1);
700 715 model.setCreateUser(null);
701 716 model.setCreateTime(null);
702 717 model.setBirth(null);
... ... @@ -713,7 +728,7 @@
713 728 // 总分
714 729 model.setTotalScore(model.getStandingComponent() + model.getSeatComponent() + model.getSupineComponent() + model.getLieProstratComponent());
715 730 // 百分位
716   - BabyEvaluationCriterionModel babyEvaluationCriterionModel = getBabyEvaluationCriterionModel(model, month);
  731 + BabyEvaluationCriterionModel babyEvaluationCriterionModel = getBabyEvaluationCriterionModel(model, currentMonth);
717 732 model.setPercentileScore(babyEvaluationCriterionModel.getPercent());
718 733 Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(model));
719 734 mongoTemplate.updateFirst(Query.query(Criteria.where("_id").is(id)), update, ExerciseAppraisalModel.class);
... ... @@ -755,6 +770,10 @@
755 770 if (CollectionUtils.isNotEmpty(models)) {
756 771 for (ExerciseAppraisalModel model : models) {
757 772 Map<String, String> map = BeanUtils.objectToStringMap(model);
  773 + Date checkTime = model.getCheckTime();
  774 + map.put("checkTimeStr", DateUtil.getyyyy_MM_dd(checkTime));
  775 + map.put("checkMonthStr", DateUtil.getBabyMonthAge(model.getBirth(), checkTime));
  776 + map.put("checkDoctorStr", usersMapper.getUsers(Integer.parseInt(model.getCheckDoctor())).getName());
758 777 add(map);
759 778 }
760 779 }
... ... @@ -807,7 +826,7 @@
807 826  
808 827 long count = mongoTemplate.count(query, ExerciseAppraisalModel.class);
809 828 param.mysqlBuild((int) count);
810   - query.skip(param.getLimit()).limit(param.getLimit());
  829 + query.skip(param.getOffset()).limit(param.getLimit());
811 830 query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "createTime")));
812 831  
813 832 List<ExerciseAppraisalModel> models = mongoTemplate.find(query, ExerciseAppraisalModel.class);
... ... @@ -816,7 +835,8 @@
816 835 Map<String, String> map = BeanUtils.objectToStringMap(model);
817 836 map.put("age", DateUtil.getBabyMonthAge(model.getBirth(), new Date()));
818 837 map.put("checkTimeStr", DateUtil.gety_m_dhm(model.getCheckTime()));
819   - map.put("checkDoctorStr", usersMapper.getUsers(Integer.parseInt(model.getCheckDoctor())).getName());
  838 + Users users = usersMapper.getUsers(Integer.parseInt(model.getCheckDoctor()));
  839 + map.put("checkDoctorStr",users == null ? "" : users.getName());
820 840 maps.add(map);
821 841 }
822 842 BaseListResponse baseListResponse = new BaseListResponse();
... ... @@ -841,7 +861,7 @@
841 861 || param.getSeatOutsideIndexs() == null
842 862 || param.getStandingComponent() == null || param.getStandingInside() == null
843 863 || param.getStandingOutside() == null || param.getStandingInsideIndexs() == null
844   - || param.getStandingOutsideIndexs() == null) {
  864 + || param.getStandingOutsideIndexs() == null || param.getCheckTime() == null) {
845 865 return false;
846 866 }
847 867 return true;