Commit 30ea291d49c8258a3521f7a49061e2e938a9c41d
1 parent
d936cb8d84
Exists in
master
and in
1 other branch
add sync data task
Showing 2 changed files with 33 additions and 10 deletions
platform-common/src/main/java/com/lyms/platform/common/utils/MongoSyncUtil.java
View file @
30ea291
| 1 | 1 | package com.lyms.platform.common.utils; |
| 2 | 2 | |
| 3 | -import com.lyms.platform.common.base.LoginContext; | |
| 4 | 3 | import com.lyms.platform.common.base.PageInfo; |
| 5 | -import com.lyms.platform.common.dao.operator.MongoCondition; | |
| 6 | -import com.lyms.platform.common.dao.operator.MongoOper; | |
| 7 | -import com.lyms.platform.common.dao.operator.MongoQuery; | |
| 8 | -import com.mchange.lang.LongUtils; | |
| 9 | 4 | import org.apache.commons.httpclient.HttpClient; |
| 10 | 5 | import org.apache.commons.httpclient.NameValuePair; |
| 11 | 6 | import org.apache.commons.httpclient.methods.PostMethod; |
| 12 | 7 | |
| 13 | -import java.util.HashMap; | |
| 14 | -import java.util.Map; | |
| 15 | - | |
| 16 | 8 | /** |
| 17 | 9 | * Created by Administrator on 2016/9/13 0013. |
| 18 | 10 | */ |
| 19 | 11 | |
| ... | ... | @@ -23,8 +15,39 @@ |
| 23 | 15 | public static String mongo_sync_token = Config.getItem("mongo_sync_token", "0"); |
| 24 | 16 | public static String mongo_crypto_key = Config.getItem("mongo_crypto_key", "0"); |
| 25 | 17 | |
| 18 | + public static boolean sync(String action, String jsonData, String id, String className) { | |
| 19 | + if ("1".equals(mongo_sync)) { | |
| 20 | + boolean boo = false; | |
| 21 | + try { | |
| 22 | + HttpClient client = new HttpClient(); | |
| 23 | + client.getHttpConnectionManager().getParams().setConnectionTimeout(3000); | |
| 24 | + client.getHttpConnectionManager().getParams().setSoTimeout(3000); | |
| 25 | + PostMethod post = new MessageUtil.UTF8PostMethod(mongo_sync_url); | |
| 26 | + NameValuePair[] pairs = { | |
| 27 | + new NameValuePair("action", action), | |
| 28 | + new NameValuePair("token", mongo_sync_token), | |
| 29 | + new NameValuePair("className", className), | |
| 30 | + new NameValuePair("jsonData", jsonData), | |
| 31 | + new NameValuePair("id", id), | |
| 32 | + }; | |
| 33 | + post.setRequestBody(pairs); | |
| 34 | + client.executeMethod(post); | |
| 35 | + int statusCode = post.getStatusCode(); | |
| 36 | + System.out.println(post.getResponseBodyAsString()); | |
| 37 | + post.releaseConnection(); | |
| 38 | + if (200 == statusCode) { | |
| 39 | + boo = true; | |
| 40 | + } | |
| 41 | + return boo; | |
| 42 | + } catch (Exception e) { | |
| 43 | + e.printStackTrace(); | |
| 44 | + return boo; | |
| 45 | + } | |
| 46 | + } | |
| 47 | + return true; | |
| 48 | + } | |
| 49 | + | |
| 26 | 50 | public static boolean sync(String action, Object data, String id) { |
| 27 | - System.out.println(mongo_sync +" :: "+id+" -- "+action); | |
| 28 | 51 | if ("1".equals(mongo_sync)) { |
| 29 | 52 | boolean boo = false; |
| 30 | 53 | try { |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/SyncDataTaskService.java
View file @
30ea291
| ... | ... | @@ -26,7 +26,7 @@ |
| 26 | 26 | query.setNeed("0"); |
| 27 | 27 | List<SyncDataModel> list = syncDataService.querySyncData(query); |
| 28 | 28 | for (SyncDataModel model:list) { |
| 29 | - if (MongoSyncUtil.sync(model.getAction(),model.getJsonData(),model.getDataId())) { | |
| 29 | + if (MongoSyncUtil.sync(model.getAction(),model.getJsonData(),model.getDataId(),model.getClassName())) { | |
| 30 | 30 | model.setStatus(0); |
| 31 | 31 | model.setModified(new Date()); |
| 32 | 32 | syncDataService.updateSyncData(model); |