Commit 7781b19b2d80122bf798bb213ee159a4e5e4ad57
Exists in
master
and in
3 other branches
Merge remote-tracking branch 'origin/master'
Showing 3 changed files
platform-biz-patient-service/src/main/java/com/lyms/platform/biz/BasicConfigServiceTest.java
View file @
7781b19
| ... | ... | @@ -5,6 +5,7 @@ |
| 5 | 5 | import java.text.SimpleDateFormat; |
| 6 | 6 | import java.util.*; |
| 7 | 7 | |
| 8 | +import com.lyms.platform.biz.dal.impl.YunBookbuildingDaoImpl; | |
| 8 | 9 | import com.lyms.platform.biz.service.GuidelinesService; |
| 9 | 10 | import com.lyms.platform.common.enums.YnEnums; |
| 10 | 11 | import com.lyms.platform.common.utils.JsonUtil; |
| ... | ... | @@ -26,6 +27,8 @@ |
| 26 | 27 | public static void main(String[] args) throws Exception { |
| 27 | 28 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| 28 | 29 | ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/spring/applicationContext_biz_patient1.xml"); |
| 30 | + | |
| 31 | + | |
| 29 | 32 | // PuerperaService basicConfigService = (PuerperaService) applicationContext.getBean(PuerperaService.class); |
| 30 | 33 | /* PuerperaModel obj = new PuerperaModel(); |
| 31 | 34 | obj.setAddress("成都市高新区天府2街"); |
| ... | ... | @@ -82,7 +85,7 @@ |
| 82 | 85 | // addaw(applicationContext, "0-83月龄体重标准差数值表(男、女).csv", 0); |
| 83 | 86 | // addZhenduan(applicationContext); |
| 84 | 87 | |
| 85 | - addHealthConfig(applicationContext); | |
| 88 | +// addHealthConfig(applicationContext); | |
| 86 | 89 | } |
| 87 | 90 | |
| 88 | 91 | public static void addZhenduan(ApplicationContext applicationContext) { |
platform-biz-patient-service/src/main/java/com/lyms/platform/biz/service/MongoSyncService.java
View file @
7781b19
| ... | ... | @@ -4,12 +4,20 @@ |
| 4 | 4 | import com.lyms.platform.common.dao.operator.MongoOper; |
| 5 | 5 | import com.lyms.platform.common.dao.operator.MongoQuery; |
| 6 | 6 | import com.lyms.platform.common.utils.*; |
| 7 | +import com.lyms.platform.pojo.*; | |
| 8 | +import com.mongodb.Mongo; | |
| 9 | +import org.apache.commons.lang.*; | |
| 10 | +import org.apache.commons.lang.StringUtils; | |
| 7 | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 8 | 12 | import org.springframework.data.mongodb.core.MongoTemplate; |
| 13 | +import org.springframework.data.mongodb.core.query.Query; | |
| 9 | 14 | import org.springframework.data.mongodb.core.query.Update; |
| 10 | 15 | import org.springframework.stereotype.Service; |
| 11 | 16 | import org.springframework.util.Assert; |
| 12 | 17 | |
| 18 | +import java.util.ArrayList; | |
| 19 | +import java.util.List; | |
| 20 | + | |
| 13 | 21 | /** |
| 14 | 22 | * Created by Administrator on 2016/9/13 0013. |
| 15 | 23 | */ |
| ... | ... | @@ -52,6 +60,116 @@ |
| 52 | 60 | } catch (Exception e) { |
| 53 | 61 | e.printStackTrace(); |
| 54 | 62 | return false; |
| 63 | + } | |
| 64 | + } | |
| 65 | + | |
| 66 | + public String syncByHospitalId(String hospitalId) { | |
| 67 | + if (org.apache.commons.lang.StringUtils.isBlank(hospitalId)) { | |
| 68 | + return "hospitalId is null"; | |
| 69 | + } | |
| 70 | + StringBuffer sb = new StringBuffer(); | |
| 71 | + List<Class> classList = new ArrayList<>(); | |
| 72 | + classList.add(AntenatalExaminationModel.class); | |
| 73 | + classList.add(AntExChuModel.class); | |
| 74 | + classList.add(BabyModel.class); | |
| 75 | + classList.add(BabyCheckModel.class); | |
| 76 | + classList.add(MaternalDeliverModel.class); | |
| 77 | + classList.add(Patients.class); | |
| 78 | + classList.add(PersonModel.class); | |
| 79 | + classList.add(PostReviewModel.class); | |
| 80 | + classList.add(PuerperaModel.class); | |
| 81 | + classList.add(ReferralApplyOrderModel.class); | |
| 82 | + classList.add(ReferValue.class); | |
| 83 | + classList.add(SieveModel.class); | |
| 84 | + classList.add(SieveApplyOrderModel.class); | |
| 85 | + classList.add(SieveResultModel.class); | |
| 86 | + classList.add(StopPregModel.class); | |
| 87 | + try { | |
| 88 | + Mongo mongo = new Mongo("119.90.43.68", 27018); | |
| 89 | + MongoTemplate template = new MongoTemplate(mongo, "platform"); | |
| 90 | + template.getDb().authenticate("platform", "platform123".toCharArray()); | |
| 91 | + Query query = new MongoQuery(new MongoCondition("hospitalId", hospitalId, MongoOper.IS)).convertToMongoQuery(); | |
| 92 | + for (Class cla:classList) { | |
| 93 | + sb.append("sync start... "); | |
| 94 | + sb.append(cla.getName()); | |
| 95 | + sb.append(" query size:"); | |
| 96 | + List list = mongoTemplate.find(query, cla); | |
| 97 | + sb.append(list.size()); | |
| 98 | + int insert = 0; | |
| 99 | + int modified = 0; | |
| 100 | + for (Object obj:list) { | |
| 101 | + String id = cla.getMethod("getId").invoke(obj).toString(); | |
| 102 | + if (StringUtils.isNotBlank(id)) { | |
| 103 | + Object temp = template.findById(id, cla); | |
| 104 | + if (temp == null) { | |
| 105 | + template.insert(obj); | |
| 106 | + insert++; | |
| 107 | + } else { | |
| 108 | + Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(obj)); | |
| 109 | + template.updateMulti(new MongoQuery(new MongoCondition("id", id, MongoOper.IS)).convertToMongoQuery(), update, cla); | |
| 110 | + modified++; | |
| 111 | + } | |
| 112 | + } | |
| 113 | + } | |
| 114 | + sb.append(" insert:"); | |
| 115 | + sb.append(insert); | |
| 116 | + sb.append(" modified:"); | |
| 117 | + sb.append(modified); | |
| 118 | + sb.append("\r\n<br>"); | |
| 119 | + } | |
| 120 | + return sb.toString(); | |
| 121 | + } catch (Exception e) { | |
| 122 | + e.printStackTrace(); | |
| 123 | + sb.append(e.getMessage()); | |
| 124 | + return sb.toString(); | |
| 125 | + } | |
| 126 | + } | |
| 127 | + | |
| 128 | + public String downloadByHospitalId(String hospitalId) { | |
| 129 | + if (org.apache.commons.lang.StringUtils.isBlank(hospitalId)) { | |
| 130 | + return "hospitalId is null"; | |
| 131 | + } | |
| 132 | + StringBuffer sb = new StringBuffer(); | |
| 133 | + List<Class> classList = new ArrayList<>(); | |
| 134 | + classList.add(SmsTemplateModel.class); | |
| 135 | + try { | |
| 136 | + Mongo mongo = new Mongo("119.90.43.68", 27018); | |
| 137 | + MongoTemplate template = new MongoTemplate(mongo, "platform"); | |
| 138 | + template.getDb().authenticate("platform", "platform123".toCharArray()); | |
| 139 | + Query query = new MongoQuery(new MongoCondition("hospitalId", hospitalId, MongoOper.IS)).convertToMongoQuery(); | |
| 140 | + for (Class cla:classList) { | |
| 141 | + sb.append("download start... "); | |
| 142 | + sb.append(cla.getName()); | |
| 143 | + sb.append(" query size:"); | |
| 144 | + List list = template.find(query, cla); | |
| 145 | + sb.append(list.size()); | |
| 146 | + int insert = 0; | |
| 147 | + int modified = 0; | |
| 148 | + for (Object obj:list) { | |
| 149 | + String id = cla.getMethod("getId").invoke(obj).toString(); | |
| 150 | + if (StringUtils.isNotBlank(id)) { | |
| 151 | + Object temp = mongoTemplate.findById(id, cla); | |
| 152 | + if (temp == null) { | |
| 153 | + mongoTemplate.insert(obj); | |
| 154 | + insert++; | |
| 155 | + } else { | |
| 156 | + Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(obj)); | |
| 157 | + mongoTemplate.updateMulti(new MongoQuery(new MongoCondition("id", id, MongoOper.IS)).convertToMongoQuery(), update, cla); | |
| 158 | + modified++; | |
| 159 | + } | |
| 160 | + } | |
| 161 | + } | |
| 162 | + sb.append(" insert:"); | |
| 163 | + sb.append(insert); | |
| 164 | + sb.append(" modified:"); | |
| 165 | + sb.append(modified); | |
| 166 | + sb.append("\r\n<br>"); | |
| 167 | + } | |
| 168 | + return sb.toString(); | |
| 169 | + } catch (Exception e) { | |
| 170 | + e.printStackTrace(); | |
| 171 | + sb.append(e.getMessage()); | |
| 172 | + return sb.toString(); | |
| 55 | 173 | } |
| 56 | 174 | } |
| 57 | 175 |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/MongoSyncController.java
View file @
7781b19
| ... | ... | @@ -34,5 +34,17 @@ |
| 34 | 34 | return "token vaild"; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | + @ResponseBody | |
| 38 | + @RequestMapping(method = RequestMethod.POST,value = "/initByHospitalId") | |
| 39 | + public String initByHospitalId(String hospitalId){ | |
| 40 | + return mongoSyncService.syncByHospitalId(hospitalId); | |
| 41 | + } | |
| 42 | + | |
| 43 | + @ResponseBody | |
| 44 | + @RequestMapping(method = RequestMethod.GET,value = "/downloadByHospitalId") | |
| 45 | + public String downloadByHospitalId(String hospitalId){ | |
| 46 | + return mongoSyncService.downloadByHospitalId(hospitalId); | |
| 47 | + } | |
| 48 | + | |
| 37 | 49 | } |