Commit 242bd7fd1d5b17251315bb4dcfc8806e2186a217
1 parent
df9150685b
Exists in
master
and in
1 other branch
watermark test
Showing 5 changed files with 65 additions and 20 deletions
- platform-biz-patient-service/src/main/java/com/lyms/platform/biz/BasicConfigServiceTest.java
- platform-biz-patient-service/src/main/java/com/lyms/platform/biz/service/MongoSyncService.java
- platform-common/src/main/java/com/lyms/platform/common/dao/BaseMongoDAOImpl.java
- platform-common/src/main/java/com/lyms/platform/common/pojo/SyncDataModel.java
- platform-common/src/main/java/com/lyms/platform/common/pojo/UpdateMultiData.java
platform-biz-patient-service/src/main/java/com/lyms/platform/biz/BasicConfigServiceTest.java
View file @
242bd7f
| ... | ... | @@ -31,6 +31,7 @@ |
| 31 | 31 | import org.springframework.context.support.ClassPathXmlApplicationContext; |
| 32 | 32 | |
| 33 | 33 | import org.springframework.data.mongodb.core.MongoTemplate; |
| 34 | +import org.springframework.data.mongodb.core.query.Criteria; | |
| 34 | 35 | import org.springframework.data.mongodb.core.query.Query; |
| 35 | 36 | import org.springframework.data.mongodb.core.query.Update; |
| 36 | 37 | |
| ... | ... | @@ -43,7 +44,31 @@ |
| 43 | 44 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| 44 | 45 | ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/spring/applicationContext_biz_patient1.xml"); |
| 45 | 46 | // queryRisk(applicationContext); |
| 46 | - changeLong2Time(applicationContext); | |
| 47 | + removeDoubleBaby(applicationContext); | |
| 48 | + } | |
| 49 | + | |
| 50 | + public static void removeDoubleBaby(ApplicationContext applicationContext) { | |
| 51 | + MongoTemplate mongoTemplate | |
| 52 | + =(MongoTemplate)applicationContext.getBean("mongoTemplate"); | |
| 53 | + mongoTemplate.getDb().slaveOk(); | |
| 54 | + mongoTemplate.getDb().authenticate("platform", "platform123".toCharArray()); | |
| 55 | + List<BabyModel> list = mongoTemplate.find(new Query(new Criteria()), BabyModel.class); | |
| 56 | + Map<String, BabyModel> localMap = new HashMap<>(); | |
| 57 | + Map<String, BabyModel> remoteMap = new HashMap<>(); | |
| 58 | + for (BabyModel model:list) { | |
| 59 | + if (model.getId().length() == 24) { | |
| 60 | + localMap.put(model.getMphone(),model); | |
| 61 | + } else if (model.getId().length() == 32) { | |
| 62 | + remoteMap.put(model.getMphone(),model); | |
| 63 | + } else { | |
| 64 | + System.out.println("other:"+JsonUtil.obj2JsonString(model)); | |
| 65 | + } | |
| 66 | + } | |
| 67 | + for (String phone:remoteMap.keySet()) { | |
| 68 | + if (localMap.containsKey(phone)) { | |
| 69 | + System.out.println("double:"+JsonUtil.obj2JsonString(remoteMap.get(phone))); | |
| 70 | + } | |
| 71 | + } | |
| 47 | 72 | } |
| 48 | 73 | |
| 49 | 74 | public static void changeLong2Time(ApplicationContext applicationContext) { |
platform-biz-patient-service/src/main/java/com/lyms/platform/biz/service/MongoSyncService.java
View file @
242bd7f
| ... | ... | @@ -11,6 +11,7 @@ |
| 11 | 11 | import org.apache.commons.lang.StringUtils; |
| 12 | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| 13 | 13 | import org.springframework.data.mongodb.core.MongoTemplate; |
| 14 | +import org.springframework.data.mongodb.core.query.Criteria; | |
| 14 | 15 | import org.springframework.data.mongodb.core.query.Query; |
| 15 | 16 | import org.springframework.data.mongodb.core.query.Update; |
| 16 | 17 | import org.springframework.stereotype.Service; |
| ... | ... | @@ -58,8 +59,14 @@ |
| 58 | 59 | } |
| 59 | 60 | if (obj instanceof UpdateMultiData) { |
| 60 | 61 | UpdateMultiData data = (UpdateMultiData) obj; |
| 61 | - if (data.getMongoQuery() != null && data.getMongoUpdate() != null) { | |
| 62 | - mongoTemplate.updateMulti(data.getMongoQuery(), data.getMongoUpdate(), updateClass); | |
| 62 | + if (data.getQuery() != null && data.getUpdate() != null) { | |
| 63 | + Update update = MongoConvertHelper | |
| 64 | + .convertToNativeUpdate(data.getUpdate()); | |
| 65 | + MongoCondition condition = new MongoCondition(); | |
| 66 | + for (String key:data.getQuery().keySet()) { | |
| 67 | + condition = condition.and(key,data.getQuery().get(key),MongoOper.IS); | |
| 68 | + } | |
| 69 | + mongoTemplate.updateMulti(condition.toMongoQuery().convertToMongoQuery(), update, updateClass); | |
| 63 | 70 | return true; |
| 64 | 71 | } else if (data.getQuery() != null && data.getUpdate() != null) { |
| 65 | 72 | MongoCondition c = null; |
platform-common/src/main/java/com/lyms/platform/common/dao/BaseMongoDAOImpl.java
View file @
242bd7f
| 1 | 1 | package com.lyms.platform.common.dao; |
| 2 | 2 | |
| 3 | +import com.lyms.platform.common.dao.operator.MongoCondition; | |
| 4 | +import com.lyms.platform.common.dao.operator.MongoOper; | |
| 5 | +import com.lyms.platform.common.dao.operator.MongoQuery; | |
| 3 | 6 | import com.lyms.platform.common.dao.operator.Page; |
| 4 | 7 | import com.lyms.platform.common.pojo.SyncDataModel; |
| 5 | 8 | import com.lyms.platform.common.pojo.UpdateMultiData; |
| ... | ... | @@ -8,6 +11,7 @@ |
| 8 | 11 | import org.apache.commons.collections.CollectionUtils; |
| 9 | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | 13 | import org.springframework.data.mongodb.core.MongoTemplate; |
| 14 | +import org.springframework.data.mongodb.core.query.Criteria; | |
| 11 | 15 | import org.springframework.data.mongodb.core.query.Query; |
| 12 | 16 | import org.springframework.data.mongodb.core.query.Update; |
| 13 | 17 | import org.springframework.util.Assert; |
| ... | ... | @@ -144,7 +148,6 @@ |
| 144 | 148 | // 数据上传 |
| 145 | 149 | UpdateMultiData data = new UpdateMultiData(); |
| 146 | 150 | data.setMongoQuery(query); |
| 147 | - data.setMongoUpdate(update); | |
| 148 | 151 | data.setUpdate(ReflectionUtils.getUpdateField(obj)); |
| 149 | 152 | // 批量修改的情况下,ID字段是要修改的CLASS |
| 150 | 153 | addSyncData("UPDATEMULTI", data, obj.getClass().getName()); |
platform-common/src/main/java/com/lyms/platform/common/pojo/SyncDataModel.java
View file @
242bd7f
| 1 | 1 | package com.lyms.platform.common.pojo; |
| 2 | 2 | |
| 3 | +import com.lyms.platform.common.dao.operator.MongoCondition; | |
| 4 | +import com.lyms.platform.common.dao.operator.MongoOper; | |
| 5 | +import com.lyms.platform.common.dao.operator.MongoQuery; | |
| 3 | 6 | import com.lyms.platform.common.result.BaseModel; |
| 7 | +import com.lyms.platform.common.utils.MongoConvertHelper; | |
| 8 | +import com.lyms.platform.common.utils.ReflectionUtils; | |
| 9 | +import com.lyms.platform.common.utils.SerializUtils; | |
| 10 | +import org.apache.commons.codec.binary.Base64; | |
| 4 | 11 | import org.springframework.data.mongodb.core.mapping.Document; |
| 12 | +import org.springframework.data.mongodb.core.query.Query; | |
| 13 | +import org.springframework.data.mongodb.core.query.Update; | |
| 14 | +import org.springframework.util.Assert; | |
| 5 | 15 | |
| 16 | +import java.io.Serializable; | |
| 6 | 17 | import java.util.Date; |
| 7 | 18 | |
| 8 | 19 | /** |
| ... | ... | @@ -10,6 +21,21 @@ |
| 10 | 21 | */ |
| 11 | 22 | @Document(collection = "lyms_sync_data") |
| 12 | 23 | public class SyncDataModel extends BaseModel { |
| 24 | + | |
| 25 | + public static void main(String[] a) { | |
| 26 | + Query query = new MongoQuery(new MongoCondition("yn", 1, MongoOper.IS)).convertToMongoQuery(); | |
| 27 | + SyncDataModel model = new SyncDataModel(); | |
| 28 | + model.setDataId("fuck"); | |
| 29 | + Assert.notNull(model, "execute findAndModify method must not null."); | |
| 30 | + Update update = MongoConvertHelper | |
| 31 | + .convertToNativeUpdate(ReflectionUtils.getUpdateField(model)); | |
| 32 | + Assert.notNull(update, "execute findAndModify method must not null.update:" + update); | |
| 33 | + // 数据上传 | |
| 34 | + UpdateMultiData data = new UpdateMultiData(); | |
| 35 | + data.setMongoQuery(query); | |
| 36 | + data.setUpdate(ReflectionUtils.getUpdateField(model)); | |
| 37 | + System.out.println(Base64.encodeBase64String(SerializUtils.objToByte((Serializable) data))); | |
| 38 | + } | |
| 13 | 39 | |
| 14 | 40 | private static final long serialVersionUID = 97531300010L; |
| 15 | 41 |
platform-common/src/main/java/com/lyms/platform/common/pojo/UpdateMultiData.java
View file @
242bd7f
| ... | ... | @@ -21,21 +21,6 @@ |
| 21 | 21 | private Map<String, Object> query; |
| 22 | 22 | private Map<String, Object> update; |
| 23 | 23 | |
| 24 | - private Query mongoQuery; | |
| 25 | - private Update mongoUpdate; | |
| 26 | - | |
| 27 | - public Update getMongoUpdate() { | |
| 28 | - return mongoUpdate; | |
| 29 | - } | |
| 30 | - | |
| 31 | - public void setMongoUpdate(Update mongoUpdate) { | |
| 32 | - this.mongoUpdate = mongoUpdate; | |
| 33 | - } | |
| 34 | - | |
| 35 | - public Query getMongoQuery() { | |
| 36 | - return mongoQuery; | |
| 37 | - } | |
| 38 | - | |
| 39 | 24 | public void setQuery(Map<String, Object> query) { |
| 40 | 25 | this.query = query; |
| 41 | 26 | } |
| ... | ... | @@ -45,7 +30,6 @@ |
| 45 | 30 | } |
| 46 | 31 | |
| 47 | 32 | public void setMongoQuery(Query query) { |
| 48 | - this.mongoQuery = query; | |
| 49 | 33 | DBObject dbObject = query.getQueryObject(); |
| 50 | 34 | this.query = new HashMap<>(); |
| 51 | 35 | for (String key:dbObject.keySet()) { |