Commit ac03d920078c87d18d5fce3308179eb40ab63482
1 parent
95e075d7b4
Exists in
master
and in
6 other branches
数据同步模块
Showing 5 changed files with 219 additions and 20 deletions
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/PregnantBuildController.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/BookbuildingFacade.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/request/SyncV2HistoryRequest.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/request/SyncV2YunBookbuildingRequest.java
- platform-operate-api/src/main/resources/config.properties
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/PregnantBuildController.java
View file @
ac03d92
| 1 | 1 | package com.lyms.platform.operate.web.controller; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -import com.lyms.platform.biz.service.YunBookbuildingService; | |
| 5 | 4 | import com.lyms.platform.common.annotation.TokenRequired; |
| 6 | 5 | import com.lyms.platform.common.base.BaseController; |
| 7 | 6 | import com.lyms.platform.common.base.LoginContext; |
| 8 | 7 | |
| 9 | 8 | |
| 10 | 9 | |
| ... | ... | @@ -12,23 +11,16 @@ |
| 12 | 11 | import com.lyms.platform.common.utils.PropertiesUtils; |
| 13 | 12 | import com.lyms.platform.common.utils.StringUtils; |
| 14 | 13 | import com.lyms.platform.operate.web.facade.AntenatalExaminationFacade; |
| 15 | -import com.lyms.platform.operate.web.facade.AutoMatchFacade; | |
| 16 | 14 | import com.lyms.platform.operate.web.facade.BookbuildingFacade; |
| 17 | -import com.lyms.platform.operate.web.request.AntenatalExaminationQueryRequest; | |
| 18 | -import com.lyms.platform.operate.web.request.BookbuildingQueryRequest; | |
| 19 | -import com.lyms.platform.operate.web.request.ImgRequest; | |
| 20 | -import com.lyms.platform.operate.web.request.YunBookbuildingAddRequest; | |
| 21 | -import com.lyms.platform.permission.service.CouponService; | |
| 15 | +import com.lyms.platform.operate.web.request.*; | |
| 22 | 16 | import org.apache.commons.httpclient.HttpClient; |
| 23 | 17 | import org.springframework.beans.factory.annotation.Autowired; |
| 24 | -import org.springframework.data.mongodb.core.MongoTemplate; | |
| 25 | 18 | import org.springframework.stereotype.Controller; |
| 26 | 19 | import org.springframework.web.bind.annotation.*; |
| 27 | 20 | import org.springframework.web.multipart.MultipartFile; |
| 28 | 21 | |
| 29 | 22 | import javax.servlet.http.HttpServletRequest; |
| 30 | 23 | import javax.servlet.http.HttpServletResponse; |
| 31 | -import java.io.File; | |
| 32 | 24 | import java.io.IOException; |
| 33 | 25 | import java.io.UnsupportedEncodingException; |
| 34 | 26 | import java.net.URLEncoder; |
| 35 | 27 | |
| ... | ... | @@ -95,10 +87,10 @@ |
| 95 | 87 | |
| 96 | 88 | if (yunBookbuildingAddRequest != null && !StringUtils.isEmpty(yunBookbuildingAddRequest.getId()) ) |
| 97 | 89 | { |
| 98 | - return bookbuildingFacade.updatePregnantById(yunBookbuildingAddRequest.getId(), yunBookbuildingAddRequest,loginState.getId()); | |
| 90 | + return bookbuildingFacade.updatePregnantById(yunBookbuildingAddRequest.getId(), yunBookbuildingAddRequest,loginState.getId(), true); | |
| 99 | 91 | |
| 100 | 92 | } |
| 101 | - BaseObjectResponse p = bookbuildingFacade.addPregnantBookbuilding(yunBookbuildingAddRequest, loginState.getId()); | |
| 93 | + BaseObjectResponse p = bookbuildingFacade.addPregnantBookbuilding(yunBookbuildingAddRequest, loginState.getId(), true); | |
| 102 | 94 | return p; |
| 103 | 95 | } |
| 104 | 96 | |
| 105 | 97 | |
| 106 | 98 | |
| 107 | 99 | |
| ... | ... | @@ -114,14 +106,37 @@ |
| 114 | 106 | LoginContext loginState = (LoginContext) request.getAttribute("loginContext"); |
| 115 | 107 | if (yunBookbuildingAddRequest != null && !StringUtils.isEmpty(yunBookbuildingAddRequest.getId()) ) |
| 116 | 108 | { |
| 117 | - return bookbuildingFacade.updatePregnantById(yunBookbuildingAddRequest.getId(), yunBookbuildingAddRequest,loginState.getId()); | |
| 109 | + return bookbuildingFacade.updatePregnantById(yunBookbuildingAddRequest.getId(), yunBookbuildingAddRequest,loginState.getId(), true); | |
| 118 | 110 | |
| 119 | 111 | } |
| 120 | - BaseObjectResponse p = bookbuildingFacade.createOrUpdateYunBuild(yunBookbuildingAddRequest,loginState.getId()); | |
| 112 | + BaseObjectResponse p = bookbuildingFacade.createOrUpdateYunBuild(yunBookbuildingAddRequest,loginState.getId(), true); | |
| 121 | 113 | return p; |
| 122 | 114 | } |
| 123 | 115 | |
| 116 | + /** | |
| 117 | + * 将来源于v2.0的数据同步到当前版本中 | |
| 118 | + * | |
| 119 | + * @param param | |
| 120 | + */ | |
| 121 | + @RequestMapping(method = RequestMethod.POST, value = "/v2/saveOrUpdate") | |
| 122 | + @ResponseBody | |
| 123 | + public BaseResponse saveOrUpdateByV2(@RequestBody SyncV2YunBookbuildingRequest param) { | |
| 124 | + if (param != null && !StringUtils.isEmpty(param.getId()) ) { | |
| 125 | + return bookbuildingFacade.updatePregnantByIdV2(param.getId(), param, param.getUserId(), false); | |
| 126 | + } | |
| 127 | + return bookbuildingFacade.createOrUpdateYunBuildV2(param, param.getUserId(), false); | |
| 128 | + } | |
| 124 | 129 | |
| 130 | + /** | |
| 131 | + * 将v2.0的历史数据保存到当前库中 | |
| 132 | + * | |
| 133 | + * @param param | |
| 134 | + */ | |
| 135 | + @RequestMapping(method = RequestMethod.POST, value = "/v2/history/batchSave") | |
| 136 | + @ResponseBody | |
| 137 | + public BaseResponse saveByV2(@RequestBody SyncV2HistoryRequest param) { | |
| 138 | + return bookbuildingFacade.saveByV2(param); | |
| 139 | + } | |
| 125 | 140 | |
| 126 | 141 | /** |
| 127 | 142 | * 删除孕妇建档 |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/BookbuildingFacade.java
View file @
ac03d92
| 1 | 1 | package com.lyms.platform.operate.web.facade; |
| 2 | 2 | |
| 3 | +import com.alibaba.fastjson.JSONObject; | |
| 3 | 4 | import com.lyms.hospitalapi.Cdfy.CdfyHisService; |
| 4 | 5 | import com.lyms.hospitalapi.dzfy.DzfyHisService; |
| 5 | 6 | import com.lyms.hospitalapi.fnfy.FnfyHisService; |
| ... | ... | @@ -16,10 +17,7 @@ |
| 16 | 17 | import com.lyms.platform.common.result.BaseObjectResponse; |
| 17 | 18 | import com.lyms.platform.common.result.BaseResponse; |
| 18 | 19 | import com.lyms.platform.common.utils.*; |
| 19 | -import com.lyms.platform.operate.web.request.BookBuildManagerQueryRequest; | |
| 20 | -import com.lyms.platform.operate.web.request.BookbuildingQueryRequest; | |
| 21 | -import com.lyms.platform.operate.web.request.ImgRequest; | |
| 22 | -import com.lyms.platform.operate.web.request.YunBookbuildingAddRequest; | |
| 20 | +import com.lyms.platform.operate.web.request.*; | |
| 23 | 21 | import com.lyms.platform.operate.web.result.*; |
| 24 | 22 | import com.lyms.platform.operate.web.service.ITrackDownService; |
| 25 | 23 | import com.lyms.platform.operate.web.utils.JdbcUtil; |
| 26 | 24 | |
| ... | ... | @@ -42,8 +40,11 @@ |
| 42 | 40 | import org.springframework.data.mongodb.core.MongoTemplate; |
| 43 | 41 | import org.springframework.data.mongodb.core.query.Criteria; |
| 44 | 42 | import org.springframework.data.mongodb.core.query.Query; |
| 43 | +import org.springframework.http.HttpHeaders; | |
| 44 | +import org.springframework.http.MediaType; | |
| 45 | 45 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| 46 | 46 | import org.springframework.stereotype.Component; |
| 47 | +import org.springframework.web.client.RestTemplate; | |
| 47 | 48 | import org.springframework.web.multipart.MultipartFile; |
| 48 | 49 | |
| 49 | 50 | import javax.servlet.http.HttpServletResponse; |
| 50 | 51 | |
| ... | ... | @@ -169,7 +170,9 @@ |
| 169 | 170 | @Autowired |
| 170 | 171 | private CdfyHisService cdfyHisService; |
| 171 | 172 | |
| 173 | + public static final String syncToV2Url = PropertiesUtils.getPropertyValue("sync_to_v2_url"); | |
| 172 | 174 | |
| 175 | + | |
| 173 | 176 | /** |
| 174 | 177 | * 根据患者的建档ID,查询还未使用的免费产检查券 |
| 175 | 178 | * |
| ... | ... | @@ -188,7 +191,7 @@ |
| 188 | 191 | * @return |
| 189 | 192 | */ |
| 190 | 193 | public BaseObjectResponse addPregnantBookbuilding( |
| 191 | - YunBookbuildingAddRequest yunRequest, Integer userId) { | |
| 194 | + YunBookbuildingAddRequest yunRequest, Integer userId, boolean isSync) { | |
| 192 | 195 | |
| 193 | 196 | BaseObjectResponse br = new BaseObjectResponse(); |
| 194 | 197 | PatientsQuery patientsQuery = new PatientsQuery(); |
| ... | ... | @@ -445,6 +448,10 @@ |
| 445 | 448 | deleteImg(yunRequest); |
| 446 | 449 | } |
| 447 | 450 | |
| 451 | + if (isSync) { | |
| 452 | + syncDataToV2(p, null, userId); | |
| 453 | + } | |
| 454 | + | |
| 448 | 455 | br.setErrorcode(ErrorCodeConstants.SUCCESS); |
| 449 | 456 | br.setErrormsg("成功"); |
| 450 | 457 | br.setData(p.getId()); |
| ... | ... | @@ -507,7 +514,7 @@ |
| 507 | 514 | * @return |
| 508 | 515 | */ |
| 509 | 516 | public BaseObjectResponse createOrUpdateYunBuild( |
| 510 | - YunBookbuildingAddRequest yunRequest, Integer userId) { | |
| 517 | + YunBookbuildingAddRequest yunRequest, Integer userId, boolean isSync) { | |
| 511 | 518 | |
| 512 | 519 | BaseObjectResponse br = new BaseObjectResponse(); |
| 513 | 520 | PatientsQuery patientsQuery = new PatientsQuery(); |
| ... | ... | @@ -688,6 +695,11 @@ |
| 688 | 695 | } |
| 689 | 696 | } |
| 690 | 697 | |
| 698 | + if (isSync) { | |
| 699 | + syncDataToV2(p, null, userId); | |
| 700 | + } | |
| 701 | + | |
| 702 | + | |
| 691 | 703 | br.setErrorcode(ErrorCodeConstants.SUCCESS); |
| 692 | 704 | br.setErrormsg("成功"); |
| 693 | 705 | br.setData(p.getId()); |
| ... | ... | @@ -696,6 +708,50 @@ |
| 696 | 708 | } |
| 697 | 709 | |
| 698 | 710 | /** |
| 711 | + * 保存/更新数据成功后,将数据同步到2.0系统中 | |
| 712 | + * @param patients | |
| 713 | + * @param id 更新保存标识 | |
| 714 | + * @param userId userId | |
| 715 | + */ | |
| 716 | + private void syncDataToV2(final Patients patients, String id, Integer userId){ | |
| 717 | + try { | |
| 718 | + Thread syncThread = new Thread(new Runnable() { | |
| 719 | + //ExecutorService executor = Executors.newSingleThreadExecutor(); | |
| 720 | + //executor.execute(new Runnable() { | |
| 721 | + @Override | |
| 722 | + public void run() { | |
| 723 | + RestTemplate restTemplate = new RestTemplate(); | |
| 724 | + HttpHeaders headers = new HttpHeaders(); | |
| 725 | + headers.setContentType(MediaType.APPLICATION_JSON); | |
| 726 | + JSONObject jsonObject = getQueryParam(patients); | |
| 727 | + String result = restTemplate.postForObject(syncToV2Url + "/李晓东提供", jsonObject, String.class); | |
| 728 | + logger.info("建档数据同步到2.0系统,返回结果: {}", result); | |
| 729 | + } | |
| 730 | + }); | |
| 731 | + //executor.shutdown(); | |
| 732 | + syncThread.start(); | |
| 733 | + }catch (Exception e){ | |
| 734 | + e.printStackTrace(); | |
| 735 | + logger.error("建档数据同步到2.0系统失败",e); | |
| 736 | + } | |
| 737 | + } | |
| 738 | + | |
| 739 | + /** | |
| 740 | + * 组装请求2.0系统的请求参数 | |
| 741 | + * | |
| 742 | + * @param patients | |
| 743 | + * @return | |
| 744 | + */ | |
| 745 | + private JSONObject getQueryParam(Patients patients) { | |
| 746 | + JSONObject jsonObject = new JSONObject(64); | |
| 747 | + | |
| 748 | + // TODO 2019/6/5 13:21 dongqing 数据组装 | |
| 749 | + jsonObject.put("id", patients.getId()); | |
| 750 | + | |
| 751 | + return jsonObject; | |
| 752 | + } | |
| 753 | + | |
| 754 | + /** | |
| 699 | 755 | * 创建孕妇建档推送消息 |
| 700 | 756 | */ |
| 701 | 757 | private void createBuildMsg(Patients patient) { |
| ... | ... | @@ -795,7 +851,7 @@ |
| 795 | 851 | * @param id |
| 796 | 852 | * @param yunRequest |
| 797 | 853 | */ |
| 798 | - public BaseResponse updatePregnantById(String id, YunBookbuildingAddRequest yunRequest, Integer userId) { | |
| 854 | + public BaseResponse updatePregnantById(String id, YunBookbuildingAddRequest yunRequest, Integer userId, boolean isSync) { | |
| 799 | 855 | |
| 800 | 856 | BaseResponse br = new BaseResponse(); |
| 801 | 857 | PatientsQuery patientsQuery = new PatientsQuery(); |
| ... | ... | @@ -931,6 +987,10 @@ |
| 931 | 987 | deleteImg(yunRequest); |
| 932 | 988 | } |
| 933 | 989 | |
| 990 | + if (isSync) { | |
| 991 | + syncDataToV2(patients, id, userId); | |
| 992 | + } | |
| 993 | + | |
| 934 | 994 | return new BaseResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功"); |
| 935 | 995 | } |
| 936 | 996 | |
| ... | ... | @@ -2195,6 +2255,56 @@ |
| 2195 | 2255 | objectResponse.setErrormsg(ErrorCodeConstants.SYSTEM_ERROR_DESCRIPTION); |
| 2196 | 2256 | return objectResponse; |
| 2197 | 2257 | } |
| 2258 | + } | |
| 2259 | + | |
| 2260 | + /** | |
| 2261 | + * 更新v2.0的数据 | |
| 2262 | + * | |
| 2263 | + * @param id 主键 | |
| 2264 | + * @param param 请求参数 | |
| 2265 | + * @param userId 用户ID | |
| 2266 | + * @param b 是否同步数据 | |
| 2267 | + * @return BaseResponse | |
| 2268 | + */ | |
| 2269 | + public BaseResponse updatePregnantByIdV2(String id, SyncV2YunBookbuildingRequest param, Integer userId, boolean b) { | |
| 2270 | + // TODO 2019/6/5 14:59 dongqing 数据的效验,整理 | |
| 2271 | + | |
| 2272 | + return updatePregnantById(id, param, userId, b); | |
| 2273 | + } | |
| 2274 | + | |
| 2275 | + /** | |
| 2276 | + * 保存v2.0的数据 | |
| 2277 | + * | |
| 2278 | + * @param param 主键 | |
| 2279 | + * @param userId 请求参数 | |
| 2280 | + * @param b 是否同步数据 | |
| 2281 | + * @return BaseResponse | |
| 2282 | + */ | |
| 2283 | + public BaseResponse createOrUpdateYunBuildV2(SyncV2YunBookbuildingRequest param, Integer userId, boolean b) { | |
| 2284 | + // TODO 2019/6/5 15:01 dongqing 数据的效验,整理 | |
| 2285 | + | |
| 2286 | + return createOrUpdateYunBuild(param, userId, b); | |
| 2287 | + } | |
| 2288 | + | |
| 2289 | + /** | |
| 2290 | + * 保存历史数据,根据时间和医院id | |
| 2291 | + * | |
| 2292 | + * @param param 请求参数 | |
| 2293 | + * @return BaseResponse | |
| 2294 | + */ | |
| 2295 | + public BaseResponse saveByV2(SyncV2HistoryRequest param) { | |
| 2296 | + // TODO 2019/6/5 15:01 dongqing 数据的效验,整理 | |
| 2297 | + RestTemplate restTemplate = new RestTemplate(); | |
| 2298 | + HttpHeaders headers = new HttpHeaders(); | |
| 2299 | + headers.setContentType(MediaType.APPLICATION_JSON); | |
| 2300 | + String startTime = param.getStartTime(); | |
| 2301 | + String endTime = param.getEndTime(); | |
| 2302 | + // TODO 2019/6/5 15:39 dongqing 分批次请求保存 | |
| 2303 | + | |
| 2304 | + JSONObject jsonObject = new JSONObject(); | |
| 2305 | + String result = restTemplate.postForObject(syncToV2Url + "/wx/babyMeasureInfo/saveOrUpdate", jsonObject, String.class); | |
| 2306 | + | |
| 2307 | + return null; | |
| 2198 | 2308 | } |
| 2199 | 2309 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/request/SyncV2HistoryRequest.java
View file @
ac03d92
| 1 | +package com.lyms.platform.operate.web.request; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * | |
| 5 | + * @Author dongqin | |
| 6 | + * @Description | |
| 7 | + * @Date 15:23 2019/6/5 | |
| 8 | + */ | |
| 9 | + | |
| 10 | +public class SyncV2HistoryRequest { | |
| 11 | + | |
| 12 | + /** | |
| 13 | + * 开始时间 | |
| 14 | + */ | |
| 15 | + private String startTime; | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * 结束时间 | |
| 19 | + */ | |
| 20 | + private String endTime; | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * 医院id | |
| 24 | + */ | |
| 25 | + private String historyId; | |
| 26 | + | |
| 27 | + public String getStartTime() { | |
| 28 | + return startTime; | |
| 29 | + } | |
| 30 | + | |
| 31 | + public void setStartTime(String startTime) { | |
| 32 | + this.startTime = startTime; | |
| 33 | + } | |
| 34 | + | |
| 35 | + public String getEndTime() { | |
| 36 | + return endTime; | |
| 37 | + } | |
| 38 | + | |
| 39 | + public void setEndTime(String endTime) { | |
| 40 | + this.endTime = endTime; | |
| 41 | + } | |
| 42 | + | |
| 43 | + public String getHistoryId() { | |
| 44 | + return historyId; | |
| 45 | + } | |
| 46 | + | |
| 47 | + public void setHistoryId(String historyId) { | |
| 48 | + this.historyId = historyId; | |
| 49 | + } | |
| 50 | +} |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/request/SyncV2YunBookbuildingRequest.java
View file @
ac03d92
| 1 | +package com.lyms.platform.operate.web.request; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * | |
| 5 | + * @Author dongqin | |
| 6 | + * @Description 请求的参数 | |
| 7 | + * @Date 14:45 2019/6/5 | |
| 8 | + */ | |
| 9 | + | |
| 10 | +public class SyncV2YunBookbuildingRequest extends YunBookbuildingAddRequest { | |
| 11 | + | |
| 12 | + // TODO 2019/6/5 14:45 dongqing 这里添加额外需要的参数,其他参数父类即可拿到 | |
| 13 | + private Integer userId; | |
| 14 | + | |
| 15 | + public Integer getUserId() { | |
| 16 | + return userId; | |
| 17 | + } | |
| 18 | + | |
| 19 | + public void setUserId(Integer userId) { | |
| 20 | + this.userId = userId; | |
| 21 | + } | |
| 22 | +} |
platform-operate-api/src/main/resources/config.properties
View file @
ac03d92