Browse Source

mongo存储bug修复 PengDi@2021/1/21

pengdi@zoniot.com 4 years ago
parent
commit
42709f3821

+ 29 - 31
meter-reading-common/src/main/java/com/huaxu/zoniot/service/impl/MeterReadRecordServiceImpl.java

@@ -404,38 +404,36 @@ public class MeterReadRecordServiceImpl implements MeterReadRecordService {
                     mongoRecord = buildUnReadRecord(waterMeter,readDay);
                     meterReadRecordRepository.insert(mongoRecord);
                 }
-                else{
-                    if(!mongoRecord.getId().equals(record.getId())){
-                        log.info("record id in mysql is not equals in mongo ,{},{}",record.getId(),mongoRecord.getId());
-                    }
-                    // 更新Mongo中的抄表记录
-                    Query condition = new Query();
-                    condition.addCriteria(Criteria.where("readDate").is(readDay));
-                    condition.addCriteria(Criteria.where("deviceId").is(waterMeter.getDeviceId()));
-                    condition.addCriteria(Criteria.where("status").is(1));
-
-                    Update param = new Update();
-                    param.set("lastSendData",getMeasuringValueMap(measuringData));
-                    param.set("lastCost",todayCost);
-                    param.set("readData",currentReading);
-                    param.set("lastValid",currentReading);
-                    param.set("readStatus",Constants.READ);
-                    param.set("readTime",sendTime);
-                    param.set("dateUpdate",new Date());
-                    param.set("updateBy",Constants.SYS_FLAG);
-
-                    mongoTemplate.updateFirst(condition,param,MeterReadRecord.class);
-//                  如下写法也不知道为啥会有问题
-//                    mongoRecord.setLastSendData(getMeasuringValueMap(measuringData));
-//                    mongoRecord.setLastCost(todayCost);
-//                    mongoRecord.setReadData(currentReading);
-//                    mongoRecord.setLastValid(currentReading);
-//                    mongoRecord.setReadStatus(Constants.READ);
-//                    mongoRecord.setDateUpdate(new Date());
-//                    mongoRecord.setReadTime(sendTime);
-//                    mongoRecord.setUpdateBy(Constants.SYS_FLAG);
-//                    meterReadRecordRepository.save(mongoRecord);
+                if(!mongoRecord.getId().equals(record.getId())){
+                    log.info("record id in mysql is not equals in mongo ,{},{}",record.getId(),mongoRecord.getId());
                 }
+                // 更新Mongo中的抄表记录
+                Query condition = new Query();
+                condition.addCriteria(Criteria.where("readDate").is(readDay));
+                condition.addCriteria(Criteria.where("deviceId").is(waterMeter.getDeviceId()));
+                condition.addCriteria(Criteria.where("status").is(1));
+
+                Update param = new Update();
+                param.set("lastSendData",getMeasuringValueMap(measuringData));
+                param.set("lastCost",todayCost);
+                param.set("readData",currentReading);
+                param.set("lastValid",currentReading);
+                param.set("readStatus",Constants.READ);
+                param.set("readTime",sendTime);
+                param.set("dateUpdate",new Date());
+                param.set("updateBy",Constants.SYS_FLAG);
+
+                mongoTemplate.updateFirst(condition,param,MeterReadRecord.class);
+
+                /*mongoRecord.setLastSendData(getMeasuringValueMap(measuringData));
+                mongoRecord.setLastCost(todayCost);
+                mongoRecord.setReadData(currentReading);
+                mongoRecord.setLastValid(currentReading);
+                mongoRecord.setReadStatus(Constants.READ);
+                mongoRecord.setDateUpdate(new Date());
+                mongoRecord.setReadTime(sendTime);
+                mongoRecord.setUpdateBy(Constants.SYS_FLAG);
+                meterReadRecordRepository.save(mongoRecord);*/
             }catch (Exception e){
                 e.printStackTrace();
                 log.error("Update meter record to mongo failed!",e);