瀏覽代碼

随访同步接口修改

huangwenjie 7 年之前
父節點
當前提交
bd31a424e6

+ 0 - 1
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/SignZYService.java

@ -1,6 +1,5 @@
package com.yihu.wlyy.service.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.service.common.SystemConfig;
import com.yihu.wlyy.service.common.util.*;
import com.yihu.wlyy.service.dao.*;

+ 2 - 2
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/job/FollowUpSynJob.java

@ -35,8 +35,8 @@ public class FollowUpSynJob implements Job {
			do{
				String startTime =  systemDictService.getFollowupSynTime();   //上次执行时间
				logger.info("采集时间:start="+startTime);
				end = DateUtil.getNextMin(DateUtil.strToDate(startTime), 60);
				String endTime = DateUtil.dateToStrLong(end);//采集60分钟后的数据
				end = DateUtil.getNextMin(DateUtil.strToDate(startTime), 20);
				String endTime = DateUtil.dateToStrLong(end);//采集20分钟后的数据
				logger.info("采集时间:end="+endTime);
				//根据起止时间查询家签居民随访记录,并同步到本地数据库
				jwPrescriptionService.getFollowUpByTime(startTime,endTime);

+ 44 - 18
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/third/jw/JwPrescriptionService.java

@ -455,8 +455,8 @@ public class JwPrescriptionService {
//            params.add(new BasicNameValuePair("IDENTITY_CARD_NO", "350221197506113526"));//身份证
            String response = httpClientUtil.post(url, params, "UTF-8");
    
            //居民随访记录
            List<Followup> followups = new ArrayList<>();
            //随访ID,ES集合对象 MAP
            HashMap<String,List<FollowupContentESDO>> followupidToESDOListMap = new HashMap<>();
    
            if (StringUtils.isNotBlank(response)) {
//                logger.info("从基卫获取随访信息报文为:"+response);
@ -803,7 +803,9 @@ public class JwPrescriptionService {
    
//                                logger.info("同步单条随访记录-ES数据对象组装完毕,时间:"+DateUtil.getStringDate());
                                //ES保存新数据
                                this.esSaveFollowupContentData(String.valueOf(followupId),newList);
//                                this.esSaveFollowupContentData(String.valueOf(followupId),newList);
    
                                followupidToESDOListMap.put(String.valueOf(followupId),newList);
                        
                                List<FollowupDrugs> DRUG_LIST = new ArrayList<>();//用药记录
                        
@ -864,6 +866,11 @@ public class JwPrescriptionService {
                logger.info("同步随访信息报错接口失败:无数据返回, hosipitalcode" + hospitalMapping.getCode());
                continue;
            }
            
            //处理随访详情数据
            if(!followupidToESDOListMap.isEmpty()){
                this.esSaveFollowupContentData(followupidToESDOListMap);
            }
        }
    }
    
@ -1204,32 +1211,51 @@ public class JwPrescriptionService {
     *@author huangwenjie
     *@date 2017/11/1 14:57
     */
    public void esSaveFollowupContentData(String followupid, List<FollowupContentESDO> newdatalist) throws Exception {
    public void esSaveFollowupContentData(HashMap<String,List<FollowupContentESDO>>  newdataMap) throws Exception {
        JestClient jestClient = null;
        
        try {
//            logger.info("同步单条随访记录-开始建立ES数据连接,时间:"+DateUtil.getStringDate());
            //            logger.info("同步单条随访记录-开始建立ES数据连接,时间:"+DateUtil.getStringDate());
            jestClient = elasticFactory.getJestClient();
            //先根据条件查找出来
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.query(
                    new BoolQueryBuilder()
                            .must(QueryBuilders.matchQuery("followup_id", id))
            );
            Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType).build();
            SearchResult result = jestClient.execute(search);
    
            List<FollowupContentESDO> resultdata = new ArrayList<>();
    
            for (String followid: newdataMap.keySet()) {
                //先根据条件查找出来
                SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
                searchSourceBuilder.query(
                        new BoolQueryBuilder()
                                .must(QueryBuilders.matchQuery("followup_id", followid))
                );
                Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType).build();
                SearchResult result = jestClient.execute(search);
//            logger.info("同步单条随访记录-开始查询ES数据,时间:"+DateUtil.getStringDate());
            List<FollowupContentESDO> dataList = result.getSourceAsObjectList(FollowupContentESDO.class);
                List<FollowupContentESDO> dataList = result.getSourceAsObjectList(FollowupContentESDO.class);
//            logger.info("同步单条随访记录-ES数据查询成功,时间:"+DateUtil.getStringDate());
            if(!dataList.isEmpty()){
                //删除原有记录
                if(!dataList.isEmpty()){
                    //删除原有记录
//                logger.info("同步单条随访记录-开始删除ES数据,时间:"+DateUtil.getStringDate());
                this.esDeleteFollowUpContent(dataList);
//                    this.esDeleteFollowUpContent(dataList);
                    //根据id批量删除
                    Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
                    for (FollowupContentESDO obj : dataList) {
                        Delete index = new Delete.Builder(obj.getId()).build();
                        bulk.addAction(index);
                    }
                    BulkResult br = jestClient.execute(bulk.build());
    
                    logger.info("delete data count:" + dataList.size());
                    logger.info("delete flag:" + br.isSucceeded());
//                logger.info("同步单条随访记录-ES数据删除成功,时间:"+DateUtil.getStringDate());
                }
                resultdata.addAll(newdataMap.get(followid));
            }
            //保存新的随访详情记录
//            logger.info("同步单条随访记录-开始保存ES数据,时间:"+DateUtil.getStringDate());
            elastricSearchSave.save(newdatalist,esIndex,esType);
            if(!resultdata.isEmpty()){
                elastricSearchSave.save(resultdata,esIndex,esType);
            }
//            logger.info("同步单条随访记录-ES数据保存成功,时间:"+DateUtil.getStringDate());
            jestClient.shutdownClient();
        }catch (Exception e){