Commit a1ff200109be78a2b470c710e0c83dfc53fa5817
1 parent
1c05143c5f
Exists in
master
and in
1 other branch
rebuild sync data controller
Showing 8 changed files with 207 additions and 15 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/utils/CompressEncodeingUtil.java
- platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java
- platform-common/src/main/java/com/lyms/platform/common/utils/SerializUtils.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/InitDataController.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/UsersController.java
- platform-operate-api/src/main/resources/config.properties
platform-biz-patient-service/src/main/java/com/lyms/platform/biz/BasicConfigServiceTest.java
View file @
a1ff200
| ... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 | import java.io.IOException; |
| 5 | 5 | import java.text.SimpleDateFormat; |
| 6 | 6 | import java.util.*; |
| 7 | +import java.util.Date; | |
| 7 | 8 | |
| 8 | 9 | import com.lyms.platform.biz.dal.impl.YunBookbuildingDaoImpl; |
| 9 | 10 | import com.lyms.platform.biz.param.AssayConfigQuery; |
| 10 | 11 | |
| 11 | 12 | |
| ... | ... | @@ -31,13 +32,87 @@ |
| 31 | 32 | |
| 32 | 33 | import org.springframework.data.mongodb.core.MongoTemplate; |
| 33 | 34 | import org.springframework.data.mongodb.core.query.Query; |
| 35 | +import org.springframework.data.mongodb.core.query.Update; | |
| 34 | 36 | |
| 35 | 37 | public class BasicConfigServiceTest { |
| 38 | + | |
| 39 | + public static SimpleDateFormat y_m_d= new SimpleDateFormat("yyyy-MM-dd"); | |
| 40 | + public static SimpleDateFormat h_m_s = new SimpleDateFormat("HH:mm:ss"); | |
| 41 | + | |
| 36 | 42 | public static void main(String[] args) throws Exception { |
| 37 | 43 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| 38 | 44 | ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/spring/applicationContext_biz_patient1.xml"); |
| 39 | 45 | // queryRisk(applicationContext); |
| 40 | - dataptest(applicationContext); | |
| 46 | + changeLong2Time(applicationContext); | |
| 47 | + } | |
| 48 | + | |
| 49 | + public static void changeLong2Time(ApplicationContext applicationContext) { | |
| 50 | + MongoTemplate mongoTemplate | |
| 51 | + =(MongoTemplate)applicationContext.getBean("mongoTemplate"); | |
| 52 | + mongoTemplate.getDb().slaveOk(); | |
| 53 | + mongoTemplate.getDb().authenticate("platform", "platform123".toCharArray()); | |
| 54 | + y_m_d.setTimeZone(TimeZone.getTimeZone("GMT+0")); | |
| 55 | + h_m_s.setTimeZone(TimeZone.getTimeZone("GMT+0")); | |
| 56 | + try { | |
| 57 | + MongoCondition coniticon = new MongoCondition(); | |
| 58 | + MongoQuery mongoQuery = new MongoQuery(coniticon); | |
| 59 | + List<AntExChuModelTemp> list = mongoTemplate.find(mongoQuery.convertToMongoQuery(),AntExChuModelTemp.class); | |
| 60 | + for (AntExChuModelTemp model:list) { | |
| 61 | + boolean boo = false; | |
| 62 | + AntExChuModel db = new AntExChuModel(); | |
| 63 | + db.setId(model.getId()); | |
| 64 | + if (model.getCreated() != null && model.getCreated() instanceof Long) { | |
| 65 | + boo = true; | |
| 66 | + db.setCreated(new Date(((Long) model.getCreated()).longValue())); | |
| 67 | + System.out.println("db.getCollection('lyms_antexc').update( { \"_id\" : ObjectId(\""+model.getId()+"\")},{ $set : { \"created\" : ISODate('"+y_m_d.format(model.getCreated())+"T"+h_m_s.format(model.getCreated())+".000Z')} } );"); | |
| 68 | + } | |
| 69 | + if (model.getModified() != null && model.getModified() instanceof Long) { | |
| 70 | + boo = true; | |
| 71 | + db.setModified(new Date(((Long) model.getModified()).longValue())); | |
| 72 | + System.out.println("db.getCollection('lyms_antexc').update( { \"_id\" : ObjectId(\""+model.getId()+"\")},{ $set : { \"modified\" : ISODate('"+y_m_d.format(model.getModified())+"T"+h_m_s.format(model.getModified())+".000Z')} } );"); | |
| 73 | + | |
| 74 | + } | |
| 75 | + | |
| 76 | + if (model.getNextCheckTime() != null && model.getNextCheckTime() instanceof Long) { | |
| 77 | + boo = true; | |
| 78 | + db.setNextCheckTime(new Date(((Long) model.getNextCheckTime()).longValue())); | |
| 79 | + System.out.println("db.getCollection('lyms_antexc').update( { \"_id\" : ObjectId(\""+model.getId()+"\")},{ $set : { \"nextCheckTime\" : ISODate('"+y_m_d.format(model.getNextCheckTime())+"T"+h_m_s.format(model.getNextCheckTime())+".000Z')} } );"); | |
| 80 | + | |
| 81 | + } | |
| 82 | + if (model.getCheckTime() != null && model.getCheckTime() instanceof Long) { | |
| 83 | + boo = true; | |
| 84 | + db.setCheckTime(new Date(((Long) model.getCheckTime()).longValue())); | |
| 85 | + System.out.println("db.getCollection('lyms_antexc').update( { \"_id\" : ObjectId(\""+model.getId()+"\")},{ $set : { \"checkTime\" : ISODate('"+y_m_d.format(model.getCheckTime())+"T"+h_m_s.format(model.getCheckTime())+".000Z')} } );"); | |
| 86 | + | |
| 87 | + } | |
| 88 | + if (model.getDueDate() != null && model.getDueDate() instanceof Long) { | |
| 89 | + boo = true; | |
| 90 | + db.setDueDate(new Date(((Long) model.getDueDate()).longValue())); | |
| 91 | + System.out.println("db.getCollection('lyms_antexc').update( { \"_id\" : ObjectId(\""+model.getId()+"\")},{ $set : { \"dueDate\" : ISODate('"+y_m_d.format(model.getDueDate())+"T"+h_m_s.format(model.getDueDate())+".000Z')} } );"); | |
| 92 | + | |
| 93 | + } | |
| 94 | + if (model.getLastMenses() != null && model.getLastMenses() instanceof Long) { | |
| 95 | + boo = true; | |
| 96 | + db.setLastMenses(new Date(((Long) model.getLastMenses()).longValue())); | |
| 97 | + System.out.println("db.getCollection('lyms_antexc').update( { \"_id\" : ObjectId(\""+model.getId()+"\")},{ $set : { \"lastMenses\" : ISODate('"+y_m_d.format(model.getLastMenses())+"T"+h_m_s.format(model.getLastMenses())+".000Z')} } );"); | |
| 98 | + | |
| 99 | + } | |
| 100 | + | |
| 101 | + | |
| 102 | + if (boo) { | |
| 103 | + | |
| 104 | +// System.out.println(JsonUtil.obj2Str(db)); | |
| 105 | +// MongoCondition coniticon1 = new MongoCondition(); | |
| 106 | +// coniticon1.and("_id", db.getId(), MongoOper.IS); | |
| 107 | +// MongoQuery mongoQuery1 = new MongoQuery(coniticon1); | |
| 108 | +// Update update = MongoConvertHelper | |
| 109 | +// .convertToNativeUpdate(ReflectionUtils.getUpdateField(db)); | |
| 110 | +// mongoTemplate.updateMulti(mongoQuery1.convertToMongoQuery(), update, AntExChuModel.class); | |
| 111 | + } | |
| 112 | + } | |
| 113 | + } catch (Exception e) { | |
| 114 | + e.printStackTrace(); | |
| 115 | + } | |
| 41 | 116 | } |
| 42 | 117 | |
| 43 | 118 | public static void dataptest(ApplicationContext applicationContext) { |
platform-biz-patient-service/src/main/java/com/lyms/platform/biz/service/MongoSyncService.java
View file @
a1ff200
| ... | ... | @@ -44,7 +44,10 @@ |
| 44 | 44 | public static String mongo_crypto_key = Config.getItem("mongo_crypto_key", "0"); |
| 45 | 45 | |
| 46 | 46 | public static void main(String[] a) { |
| 47 | - | |
| 47 | + | |
| 48 | + String s = "rO0ABXNyACJjb20ubHltcy5wbGF0Zm9ybS5wb2pvLkFyY2hpdmVEYXRhYLiAY6y7JRwCAAdMAAdjYXJkTnVtdAASTGphdmEvbGFuZy9TdHJpbmc7TAAKaG9zcGl0YWxJZHEAfgABTAACaWRxAH4AAUwABmlkQ2FyZHEAfgABTAAIanNvbkRhdGFxAH4AAUwABG5hbWVxAH4AAUwABXBob25lcQB+AAF4cHQAHG9jQ1Fkc3psN3FCZGotXzNHZlhRX3FxNWVXWjR0AAMyMTZ0ABYyMTY6MTMwMzAyMTk4NzA4MjUzNTI3dAASMTMwMzAyMTk4NzA4MjUzNTI3dAPAeyJwaG9uZSI6IjE1NjAzMzY0MjQ2IiwiZXJyb3Jtc2ciOiLmiJDlip8iLCJodXNFZHVjYX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wiaG9zcGl0YWxOYW1lIjoi56em55qH5bKb5biC5aaH5bm85L+d5YGl6ZmiIiwiYWNjb3VudFR5cGUiOiLpnZ7lhpzkuJrmiLflj6MiLCJlcnJvcmNvZGUiOjAsImh1c0lkQ2FyZCI6IiJ9dAAG546L5LmQdAALMTU2MDMzNjQyNDY="; | |
| 49 | + Object obj = SerializUtils.byteToObj(Base64.decodeBase64(s)); | |
| 50 | + System.out.println(obj); | |
| 48 | 51 | } |
| 49 | 52 | |
| 50 | 53 | public boolean syncData(String action, String id, String className, String json) { |
platform-common/src/main/java/com/lyms/platform/common/utils/CompressEncodeingUtil.java
View file @
a1ff200
| 1 | +package com.lyms.platform.common.utils; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Created by riecard on 2016/12/8. | |
| 5 | + */ | |
| 6 | +public class CompressEncodeingUtil { | |
| 7 | + | |
| 8 | + final static char[] digits = { | |
| 9 | + '0' , '1' , '2' , '3' , '4' , '5' , | |
| 10 | + '6' , '7' , '8' , '9' , 'a' , 'b' , | |
| 11 | + 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , | |
| 12 | + 'i' , 'j' , 'k' , 'l' , 'm' , 'n' , | |
| 13 | + 'o' , 'p' , 'q' , 'r' , 's' , 't' , | |
| 14 | + 'u' , 'v' , 'w' , 'x' , 'y' , 'z' , | |
| 15 | + 'A' , 'B' , 'C' , 'D' , 'E' , 'F' , | |
| 16 | + 'G' , 'H' , 'I' , 'J' , 'K' , 'L' , | |
| 17 | + 'M' , 'N' , 'O' , 'P' , 'Q' , 'R' , | |
| 18 | + 'S' , 'T' , 'U' , 'V' , 'W' , 'X' , | |
| 19 | + 'Y' , 'Z' , '$' , '!' , | |
| 20 | + }; | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * 把10进制的数字转换成64进制 | |
| 24 | + * @param number | |
| 25 | + * @return | |
| 26 | + */ | |
| 27 | + public static String compressNumber(String number) { | |
| 28 | + return compressNumber(Long.valueOf(number)); | |
| 29 | + } | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * 把10进制的数字转换成64进制 | |
| 33 | + * @param number | |
| 34 | + * @return | |
| 35 | + */ | |
| 36 | + public static String compressNumber(long number) { | |
| 37 | + System.out.println(number); | |
| 38 | + char[] buf = new char[64]; | |
| 39 | + int charPos = 64; | |
| 40 | + int radix = 1 << 6; | |
| 41 | + long mask = radix - 1; | |
| 42 | + do { | |
| 43 | + buf[--charPos] = digits[(int)(number & mask)]; | |
| 44 | + number >>>= 6; | |
| 45 | + } while (number != 0); | |
| 46 | + return new String(buf, charPos, (64 - charPos)); | |
| 47 | + } | |
| 48 | + /** | |
| 49 | + * 把64进制的字符串转换成10进制 | |
| 50 | + * @param decompStr | |
| 51 | + * @return | |
| 52 | + */ | |
| 53 | + public static long unCompressNumber(String decompStr) | |
| 54 | + { | |
| 55 | + long result=0; | |
| 56 | + for (int i = decompStr.length()-1; i >=0; i--) { | |
| 57 | + if(i==decompStr.length()) | |
| 58 | + { | |
| 59 | + result+=getCharIndexNum(decompStr.charAt(i)); | |
| 60 | + continue; | |
| 61 | + } | |
| 62 | + for (int j = 0; j < digits.length; j++) { | |
| 63 | + if(decompStr.charAt(i)==digits[j]) | |
| 64 | + { | |
| 65 | + result+=((long)j)<<6*(decompStr.length()-1-i); | |
| 66 | + } | |
| 67 | + } | |
| 68 | + } | |
| 69 | + return result; | |
| 70 | + } | |
| 71 | + /** | |
| 72 | + * | |
| 73 | + * @param ch | |
| 74 | + * @return | |
| 75 | + */ | |
| 76 | + private static long getCharIndexNum(char ch) | |
| 77 | + { | |
| 78 | + int num=((int)ch); | |
| 79 | + if(num>=48&&num<=57) | |
| 80 | + { | |
| 81 | + return num-48; | |
| 82 | + } | |
| 83 | + else if(num>=97&&num<=122) | |
| 84 | + { | |
| 85 | + return num-87; | |
| 86 | + }else if(num>=65&&num<=90) | |
| 87 | + { | |
| 88 | + return num-29; | |
| 89 | + }else if(num==43) | |
| 90 | + { | |
| 91 | + return 62; | |
| 92 | + } | |
| 93 | + else if (num == 47) | |
| 94 | + { | |
| 95 | + return 63; | |
| 96 | + } | |
| 97 | + return 0; | |
| 98 | + } | |
| 99 | + | |
| 100 | +} |
platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java
View file @
a1ff200
platform-common/src/main/java/com/lyms/platform/common/utils/SerializUtils.java
View file @
a1ff200
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/InitDataController.java
View file @
a1ff200
| ... | ... | @@ -13,6 +13,7 @@ |
| 13 | 13 | import org.apache.commons.httpclient.HttpClient; |
| 14 | 14 | import org.apache.commons.httpclient.NameValuePair; |
| 15 | 15 | import org.apache.commons.httpclient.methods.PostMethod; |
| 16 | +import org.apache.commons.io.FileUtils; | |
| 16 | 17 | import org.springframework.beans.factory.annotation.Autowired; |
| 17 | 18 | import org.springframework.data.mongodb.core.MongoTemplate; |
| 18 | 19 | import org.springframework.data.mongodb.core.query.Query; |
| ... | ... | @@ -34,6 +35,8 @@ |
| 34 | 35 | @RequestMapping("/initdata") |
| 35 | 36 | public class InitDataController extends BaseController { |
| 36 | 37 | |
| 38 | + public static final String postser_url = PropertiesUtils.getPropertyValue("postser_url"); | |
| 39 | + | |
| 37 | 40 | @Autowired |
| 38 | 41 | protected MongoTemplate mongoTemplate; |
| 39 | 42 | |
| ... | ... | @@ -104,7 +107,7 @@ |
| 104 | 107 | HttpClient client = new HttpClient(); |
| 105 | 108 | client.getHttpConnectionManager().getParams().setConnectionTimeout(30000); |
| 106 | 109 | client.getHttpConnectionManager().getParams().setSoTimeout(30000); |
| 107 | - PostMethod post = new MessageUtil.UTF8PostMethod("http://api.meishengbb.com/initdata/reser"); | |
| 110 | + PostMethod post = new MessageUtil.UTF8PostMethod(postser_url); | |
| 108 | 111 | NameValuePair[] pairs = { |
| 109 | 112 | new NameValuePair("className", claName), |
| 110 | 113 | new NameValuePair("json", JsonUtil.array2JsonString(synclist)), |
| 111 | 114 | |
| ... | ... | @@ -136,19 +139,22 @@ |
| 136 | 139 | Class cla = Class.forName(className); |
| 137 | 140 | List<String> synclist = JsonUtil.toList(json, String.class); |
| 138 | 141 | for (String s:synclist) { |
| 139 | - System.out.println(className); | |
| 140 | - System.out.println(s); | |
| 141 | - Object obj = SerializUtils.byteToObj(Base64.decodeBase64(s)); | |
| 142 | - String id = cla.getMethod("getId").invoke(obj).toString(); | |
| 143 | - if (StringUtils.isNotEmpty(id)) { | |
| 144 | - if (mongoTemplate.findById(id, cla) == null) { | |
| 145 | - mongoTemplate.insert(obj); | |
| 146 | - } else { | |
| 147 | - Query query = new MongoQuery(new MongoCondition("id", id, MongoOper.IS)).convertToMongoQuery(); | |
| 148 | - Update update = MongoConvertHelper | |
| 149 | - .convertToNativeUpdate(ReflectionUtils.getUpdateField(obj)); | |
| 150 | - mongoTemplate.updateMulti(query, update, cla); | |
| 142 | + try { | |
| 143 | + Object obj = SerializUtils.byteToObj(Base64.decodeBase64(s)); | |
| 144 | + String id = cla.getMethod("getId").invoke(obj).toString(); | |
| 145 | + if (StringUtils.isNotEmpty(id)) { | |
| 146 | + if (mongoTemplate.findById(id, cla) == null) { | |
| 147 | + mongoTemplate.insert(obj); | |
| 148 | + } else { | |
| 149 | + Query query = new MongoQuery(new MongoCondition("id", id, MongoOper.IS)).convertToMongoQuery(); | |
| 150 | + Update update = MongoConvertHelper | |
| 151 | + .convertToNativeUpdate(ReflectionUtils.getUpdateField(obj)); | |
| 152 | + mongoTemplate.updateMulti(query, update, cla); | |
| 153 | + } | |
| 151 | 154 | } |
| 155 | + } catch (Exception e) { | |
| 156 | + System.out.println(className); | |
| 157 | + System.out.println(s); | |
| 152 | 158 | } |
| 153 | 159 | } |
| 154 | 160 | return "success"; |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/UsersController.java
View file @
a1ff200
| ... | ... | @@ -498,6 +498,7 @@ |
| 498 | 498 | |
| 499 | 499 | Map<String, Object> map = new HashMap<>(); |
| 500 | 500 | map.put("user", users); |
| 501 | + map.put("watermark", CompressEncodeingUtil.compressNumber(users.getId().toString()+DateUtil.getymd6())); | |
| 501 | 502 | map.put("roles", roles); |
| 502 | 503 | map.put("permissions", permissions); |
| 503 | 504 |