Commit 280ede8cf1d0313b43185b832770d6b0250492eb
1 parent
da1a343295
Exists in
master
and in
6 other branches
体重管理相关代码
Showing 1 changed file with 15 additions and 22 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/PatientWeightServiceImpl.java
View file @
280ede8
| ... | ... | @@ -87,22 +87,23 @@ |
| 87 | 87 | |
| 88 | 88 | @Override |
| 89 | 89 | public BaseResponse addOrUpdate(Integer userId, PatientWeight patientWeight) { |
| 90 | + String hospitalId = autoMatchFacade.getHospitalId(userId); | |
| 90 | 91 | String nowWeight = patientWeight.getNowWeight(); |
| 91 | - if(StringUtils.isEmpty(patientWeight.getId())) { | |
| 92 | - if(StringUtils.isNotBlank(nowWeight) && StringUtils.isNotBlank(patientWeight.getPatientId())) { | |
| 93 | - PatientWeight weight = mongoTemplate.findOne(Query.query(Criteria.where("patientId").is(patientWeight.getPatientId())), PatientWeight.class); | |
| 94 | - if(weight != null && MapUtils.isNotEmpty(weight.getWeights())) { | |
| 95 | - Map<Integer, String> weights = weight.getWeights(); | |
| 96 | - weights.put(DateUtil.getWeek(weight.getLastMenses(), new Date()), nowWeight); | |
| 97 | - weight.setWeights(weights); | |
| 98 | - Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(weight)); | |
| 99 | - mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(weight.getId())), update, PatientWeight.class); | |
| 100 | - return RespBuilder.buildSuccess(patientWeight.getId()); | |
| 101 | - } | |
| 92 | + PatientWeight weight = mongoTemplate.findOne(Query.query(Criteria.where("patientId").is(patientWeight.getPatientId()).and("hospitalId").is(hospitalId)), PatientWeight.class); | |
| 93 | + Map<Integer, String> weights = new HashMap<>(); | |
| 94 | + if(weight != null && MapUtils.isNotEmpty(weight.getWeights())) { | |
| 95 | + weights = weight.getWeights(); | |
| 96 | + } | |
| 97 | + weights.put(DateUtil.getWeek(weight.getLastMenses(), new Date()), nowWeight); | |
| 98 | + weight.setWeights(weights); | |
| 99 | + patientWeight.setWeights(weights); | |
| 102 | 100 | |
| 103 | - } | |
| 104 | - | |
| 105 | - String hospitalId = autoMatchFacade.getHospitalId(userId); | |
| 101 | + 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 | + } | |
| 106 | 107 | patientWeight.setHospitalId(hospitalId); |
| 107 | 108 | patientWeight.setOperaterId(userId.toString()); |
| 108 | 109 | patientWeight.setCreated(new Date()); |
| ... | ... | @@ -122,14 +123,6 @@ |
| 122 | 123 | mongoTemplate.save(patientWeight); |
| 123 | 124 | return RespBuilder.buildSuccess(patientWeight.getId()); |
| 124 | 125 | } else { |
| 125 | - if(StringUtils.isNotBlank(nowWeight)) { | |
| 126 | - PatientWeight pw = mongoTemplate.findById(patientWeight.getId(), PatientWeight.class); | |
| 127 | - if(pw != null) { | |
| 128 | - Map<Integer, String> weights = MapUtils.isEmpty(pw.getWeights()) ? new HashMap<Integer, String>() : pw.getWeights(); | |
| 129 | - weights.put(DateUtil.getWeek(new Date()), nowWeight); | |
| 130 | - patientWeight.setWeights(weights); | |
| 131 | - } | |
| 132 | - } | |
| 133 | 126 | patientWeight.setOperaterId(userId.toString()); |
| 134 | 127 | Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(patientWeight)); |
| 135 | 128 | mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(patientWeight.getId())), update, PatientWeight.class); |