Commit cba367fe93cb78352e29421d41cdb0c3930b99c4

Authored by litao@lymsh.com
1 parent 280ede8cf1

体重管理相关代码

Showing 1 changed file with 12 additions and 11 deletions

platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/PatientWeightServiceImpl.java View file @ cba367f
... ... @@ -89,21 +89,20 @@
89 89 public BaseResponse addOrUpdate(Integer userId, PatientWeight patientWeight) {
90 90 String hospitalId = autoMatchFacade.getHospitalId(userId);
91 91 String nowWeight = patientWeight.getNowWeight();
92   - PatientWeight weight = mongoTemplate.findOne(Query.query(Criteria.where("patientId").is(patientWeight.getPatientId()).and("hospitalId").is(hospitalId)), PatientWeight.class);
  92 + PatientWeight pw = mongoTemplate.findOne(Query.query(Criteria.where("patientId").is(patientWeight.getPatientId()).and("hospitalId").is(hospitalId)), PatientWeight.class);
93 93 Map<Integer, String> weights = new HashMap<>();
94   - if(weight != null && MapUtils.isNotEmpty(weight.getWeights())) {
95   - weights = weight.getWeights();
  94 + if(pw != null) {
  95 + if(MapUtils.isNotEmpty(pw.getWeights())) {
  96 + weights = pw.getWeights();
  97 + }
  98 + weights.put(DateUtil.getWeek(pw.getLastMenses(), new Date()), nowWeight);
  99 + pw.setWeights(weights);
  100 + Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(pw));
  101 + mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(pw.getId())), update, PatientWeight.class);
  102 + return RespBuilder.buildSuccess(pw.getId());
96 103 }
97   - weights.put(DateUtil.getWeek(weight.getLastMenses(), new Date()), nowWeight);
98   - weight.setWeights(weights);
99   - patientWeight.setWeights(weights);
100 104  
101 105 if(StringUtils.isEmpty(patientWeight.getId())) {
102   - if(weight != null) {
103   - Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(weight));
104   - mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(weight.getId())), update, PatientWeight.class);
105   - return RespBuilder.buildSuccess(patientWeight.getId());
106   - }
107 106 patientWeight.setHospitalId(hospitalId);
108 107 patientWeight.setOperaterId(userId.toString());
109 108 patientWeight.setCreated(new Date());
... ... @@ -115,6 +114,8 @@
115 114 patientWeight.setBirth(patients.getBirth());
116 115 patientWeight.setUsername(patients.getUsername());
117 116 patientWeight.setPhone(patients.getPhone());
  117 + weights.put(DateUtil.getWeek(patients.getLastMenses(), new Date()), nowWeight);
  118 + patientWeight.setWeights(weights);
118 119 }
119 120 if(StringUtils.isNotBlank(patientWeight.getNowWeight()) && patientWeight.getBeforeHeight() != null) {
120 121 patientWeight.setBmi(getBmi(patientWeight.getNowWeight(), patientWeight.getBeforeHeight()));