diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/PatientWeightServiceImpl.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/PatientWeightServiceImpl.java index ef2f41b..8e0e10c 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/PatientWeightServiceImpl.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/PatientWeightServiceImpl.java @@ -89,21 +89,20 @@ public class PatientWeightServiceImpl extends BaseServiceImpl implements Patient public BaseResponse addOrUpdate(Integer userId, PatientWeight patientWeight) { String hospitalId = autoMatchFacade.getHospitalId(userId); String nowWeight = patientWeight.getNowWeight(); - PatientWeight weight = mongoTemplate.findOne(Query.query(Criteria.where("patientId").is(patientWeight.getPatientId()).and("hospitalId").is(hospitalId)), PatientWeight.class); + PatientWeight pw = mongoTemplate.findOne(Query.query(Criteria.where("patientId").is(patientWeight.getPatientId()).and("hospitalId").is(hospitalId)), PatientWeight.class); Map weights = new HashMap<>(); - if(weight != null && MapUtils.isNotEmpty(weight.getWeights())) { - weights = weight.getWeights(); + if(pw != null) { + if(MapUtils.isNotEmpty(pw.getWeights())) { + weights = pw.getWeights(); + } + weights.put(DateUtil.getWeek(pw.getLastMenses(), new Date()), nowWeight); + pw.setWeights(weights); + Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(pw)); + mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(pw.getId())), update, PatientWeight.class); + return RespBuilder.buildSuccess(pw.getId()); } - weights.put(DateUtil.getWeek(weight.getLastMenses(), new Date()), nowWeight); - weight.setWeights(weights); - patientWeight.setWeights(weights); if(StringUtils.isEmpty(patientWeight.getId())) { - if(weight != null) { - Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(weight)); - mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(weight.getId())), update, PatientWeight.class); - return RespBuilder.buildSuccess(patientWeight.getId()); - } patientWeight.setHospitalId(hospitalId); patientWeight.setOperaterId(userId.toString()); patientWeight.setCreated(new Date()); @@ -115,6 +114,8 @@ public class PatientWeightServiceImpl extends BaseServiceImpl implements Patient patientWeight.setBirth(patients.getBirth()); patientWeight.setUsername(patients.getUsername()); patientWeight.setPhone(patients.getPhone()); + weights.put(DateUtil.getWeek(patients.getLastMenses(), new Date()), nowWeight); + patientWeight.setWeights(weights); } if(StringUtils.isNotBlank(patientWeight.getNowWeight()) && patientWeight.getBeforeHeight() != null) { patientWeight.setBmi(getBmi(patientWeight.getNowWeight(), patientWeight.getBeforeHeight()));