From c1bdbdfab06deda9aee964e3000ae34ef07069d1 Mon Sep 17 00:00:00 2001 From: dongqin <123456> Date: Thu, 1 Aug 2019 14:17:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/BabyEvaluationCriterionServiceImpl.java | 74 ++++++++++++++-------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BabyEvaluationCriterionServiceImpl.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BabyEvaluationCriterionServiceImpl.java index 6dc151a..3135b26 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BabyEvaluationCriterionServiceImpl.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BabyEvaluationCriterionServiceImpl.java @@ -17,6 +17,10 @@ import com.lyms.platform.pojo.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.aggregation.Aggregation; +import org.springframework.data.mongodb.core.aggregation.AggregationResults; +import org.springframework.data.mongodb.core.aggregation.GroupOperation; +import org.springframework.data.mongodb.core.aggregation.MatchOperation; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Update; @@ -60,46 +64,46 @@ public class BabyEvaluationCriterionServiceImpl implements BabyEvaluationCriteri if (month > 84) { return new BaseResponse().setErrorcode(ErrorCodeConstants.PARAMETER_ERROR).setErrormsg("操作失败,当前儿童年龄大于7岁"); } - int month3 = getCurrentMonth(month, 3); + int month3 = getCurrentMonth(month, 3, 3); if (month3 >= 3 && month3 <= 72) { // 大于等于3月龄 小于等于72月龄 - int month2 = getCurrentMonth(month3, 2); - int month1 = getCurrentMonth(month2, 2); - int month4 = getCurrentMonth(month3, 4); - int month5 = getCurrentMonth(month4, 4); + int month2 = getCurrentMonth(month3, 2, 3); + int month1 = getCurrentMonth(month2, 2, 3); + int month4 = getCurrentMonth(month3, 4, 3); + int month5 = getCurrentMonth(month4, 4, 3); months = new int[]{month1, month2, month3, month4, month5}; }else if (month3 < 3) { if (month3 == 1) { // 等于1月龄 - int month4 = getCurrentMonth(month3, 4); - int month5 = getCurrentMonth(month4, 4); + int month4 = getCurrentMonth(month3, 4, 3); + int month5 = getCurrentMonth(month4, 4, 3); months = new int[] {month3, month4, month5}; }else if (month3 == 2) { // 等于2月龄 - int month2 = getCurrentMonth(month3, 2); - int month4 = getCurrentMonth(month3, 4); - int month5 = getCurrentMonth(month4, 4); + int month2 = getCurrentMonth(month3, 2, 3); + int month4 = getCurrentMonth(month3, 4, 3); + int month5 = getCurrentMonth(month4, 4, 3); months = new int[] {month2, month3, month4, month5}; } } else if (month3 > 72 && month3 <= 84) { if (month3 == 78) { // 等于78月龄 - int month2 = getCurrentMonth(month3, 2); - int month1 = getCurrentMonth(month2, 2); - int month4 = getCurrentMonth(month3, 4); + int month2 = getCurrentMonth(month3, 2, 3); + int month1 = getCurrentMonth(month2, 2, 3); + int month4 = getCurrentMonth(month3, 4, 3); months = new int[]{month1, month2, month3, month4}; }else if (month3 == 84) { // 等于84月龄 - int month2 = getCurrentMonth(month3, 2); - int month1 = getCurrentMonth(month2, 2); + int month2 = getCurrentMonth(month3, 2, 3); + int month1 = getCurrentMonth(month2, 2, 3); months = new int[]{month1, month2, month3}; } } @@ -118,16 +122,16 @@ public class BabyEvaluationCriterionServiceImpl implements BabyEvaluationCriteri * @param index 表示下标位置 * @return */ - private Integer getCurrentMonth(Integer month, Integer index){ + private Integer getCurrentMonth(Integer month, Integer index, Integer type){ Query query = new Query(); if (2 == index){ - query.addCriteria(Criteria.where("month").lt(month).and("yn").is(YnEnums.YES.getId())); + query.addCriteria(Criteria.where("month").lt(month).and("yn").is(YnEnums.YES.getId()).and("type").is(type)); query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "month"))); } else if (3 == index) { - query.addCriteria(Criteria.where("month").lte(month).and("yn").is(YnEnums.YES.getId())); + query.addCriteria(Criteria.where("month").lte(month).and("yn").is(YnEnums.YES.getId()).and("type").is(type)); query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "month"))); } else if (4 == index) { - query.addCriteria(Criteria.where("month").gt(month).and("yn").is(YnEnums.YES.getId())); + query.addCriteria(Criteria.where("month").gt(month).and("yn").is(YnEnums.YES.getId()).and("type").is(type)); query.with(new Sort(new Sort.Order(Sort.Direction.ASC, "month"))); } @@ -222,6 +226,15 @@ public class BabyEvaluationCriterionServiceImpl implements BabyEvaluationCriteri mapList.add(objectMap); } + BigDecimal defOldVal = BigDecimal.ZERO; + if (checkMonth - 2 > 1) { + /*MatchOperation match = Aggregation.match(Criteria.where("")); + GroupOperation group = Aggregation.group(); + Aggregation aggregation = Aggregation.newAggregation(match, group); + AggregationResults aggregate = mongoTemplate.aggregate(aggregation, Map.class); + List mappedResults = aggregate.getMappedResults();*/ + //mongoTemplate.find(Query.query(Criteria.where().)) + } int developmentQuotient = 0; if (currentProjectVal > 0) { mentalAge = new BigDecimal(currentProjectVal).divide(new BigDecimal(5), 0, BigDecimal.ROUND_HALF_UP).intValue(); @@ -663,10 +676,10 @@ public class BabyEvaluationCriterionServiceImpl implements BabyEvaluationCriteri String babyId = param.getBabyId(); boolean isPass = paramValid(param); ExerciseAppraisalModel model = param; - model.setCheckTime(new Date()); if (!isPass) { return new BaseResponse().setErrorcode(ErrorCodeConstants.PARAMETER_ERROR).setErrormsg("参数缺失"); } + model.setCheckTime(new Date(model.getCheckTime().getTime() - 28800000)); String id = param.getId(); if (StringUtils.isEmpty(id)) { // 新增运动测评 @@ -675,6 +688,7 @@ public class BabyEvaluationCriterionServiceImpl implements BabyEvaluationCriteri return new BaseResponse().setErrorcode(ErrorCodeConstants.NO_DATA).setErrormsg("未查到该儿童的建档数据"); } Integer month = DateUtil.getBabyAgeMonth(babyModel.getBirth(), new Date()); + Integer currentMonth = getCurrentMonth(month, 3, 1); model.setBirth(babyModel.getBirth()); model.setCardNo(babyModel.getCardNo()); model.setVcCardNo(babyModel.getVcCardNo()); @@ -689,14 +703,15 @@ public class BabyEvaluationCriterionServiceImpl implements BabyEvaluationCriteri // 总分 model.setTotalScore(model.getStandingComponent() + model.getSeatComponent() + model.getSupineComponent() + model.getLieProstratComponent()); // 百分位 - BabyEvaluationCriterionModel babyEvaluationCriterionModel = getBabyEvaluationCriterionModel(model, month); + BabyEvaluationCriterionModel babyEvaluationCriterionModel = getBabyEvaluationCriterionModel(model, currentMonth); model.setPercentileScore(babyEvaluationCriterionModel.getPercent()); mongoTemplate.insert(model); } if (StringUtils.isNotEmpty(id)) { - Integer month = DateUtil.getBabyAgeMonth(model.getBirth(), new Date()); - model.setCheckTime(null); + Integer month = DateUtil.getBabyAgeMonth(model.getBirth(), + mongoTemplate.findOne(Query.query(Criteria.where("_id").is(id)), ExerciseAppraisalModel.class).getCreateTime()); + Integer currentMonth = getCurrentMonth(month, 3, 1); model.setCreateUser(null); model.setCreateTime(null); model.setBirth(null); @@ -713,7 +728,7 @@ public class BabyEvaluationCriterionServiceImpl implements BabyEvaluationCriteri // 总分 model.setTotalScore(model.getStandingComponent() + model.getSeatComponent() + model.getSupineComponent() + model.getLieProstratComponent()); // 百分位 - BabyEvaluationCriterionModel babyEvaluationCriterionModel = getBabyEvaluationCriterionModel(model, month); + BabyEvaluationCriterionModel babyEvaluationCriterionModel = getBabyEvaluationCriterionModel(model, currentMonth); model.setPercentileScore(babyEvaluationCriterionModel.getPercent()); Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(model)); mongoTemplate.updateFirst(Query.query(Criteria.where("_id").is(id)), update, ExerciseAppraisalModel.class); @@ -755,6 +770,10 @@ public class BabyEvaluationCriterionServiceImpl implements BabyEvaluationCriteri if (CollectionUtils.isNotEmpty(models)) { for (ExerciseAppraisalModel model : models) { Map map = BeanUtils.objectToStringMap(model); + Date checkTime = model.getCheckTime(); + map.put("checkTimeStr", DateUtil.getyyyy_MM_dd(checkTime)); + map.put("checkMonthStr", DateUtil.getBabyMonthAge(model.getBirth(), checkTime)); + map.put("checkDoctorStr", usersMapper.getUsers(Integer.parseInt(model.getCheckDoctor())).getName()); add(map); } } @@ -807,7 +826,7 @@ public class BabyEvaluationCriterionServiceImpl implements BabyEvaluationCriteri long count = mongoTemplate.count(query, ExerciseAppraisalModel.class); param.mysqlBuild((int) count); - query.skip(param.getLimit()).limit(param.getLimit()); + query.skip(param.getOffset()).limit(param.getLimit()); query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "createTime"))); List models = mongoTemplate.find(query, ExerciseAppraisalModel.class); @@ -816,7 +835,8 @@ public class BabyEvaluationCriterionServiceImpl implements BabyEvaluationCriteri Map map = BeanUtils.objectToStringMap(model); map.put("age", DateUtil.getBabyMonthAge(model.getBirth(), new Date())); map.put("checkTimeStr", DateUtil.gety_m_dhm(model.getCheckTime())); - map.put("checkDoctorStr", usersMapper.getUsers(Integer.parseInt(model.getCheckDoctor())).getName()); + Users users = usersMapper.getUsers(Integer.parseInt(model.getCheckDoctor())); + map.put("checkDoctorStr",users == null ? "" : users.getName()); maps.add(map); } BaseListResponse baseListResponse = new BaseListResponse(); @@ -841,7 +861,7 @@ public class BabyEvaluationCriterionServiceImpl implements BabyEvaluationCriteri || param.getSeatOutsideIndexs() == null || param.getStandingComponent() == null || param.getStandingInside() == null || param.getStandingOutside() == null || param.getStandingInsideIndexs() == null - || param.getStandingOutsideIndexs() == null) { + || param.getStandingOutsideIndexs() == null || param.getCheckTime() == null) { return false; } return true; -- 1.8.3.1