浏览代码

bug修改

chenweida 7 年之前
父节点
当前提交
658e8df55a

+ 14 - 5
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/save/es/ElastricSearchSave.java

@ -36,9 +36,10 @@ public class ElastricSearchSave {
    private ElasticFactory elasticFactory;
    public Boolean save(List<SaveModel> sms) {
        JestClient jestClient = null;
        try {
            //得到链接
            JestClient jestClient = elasticFactory.getJestClient();
            jestClient = elasticFactory.getJestClient();
            int success = 0;
            int error = 0;
@ -59,19 +60,23 @@ public class ElastricSearchSave {
            logger.info("save flag:" + br.isSucceeded());
            logger.info("save success:" + success);
            logger.info("save error:" + error);
            jestClient.shutdownClient();
            return br.isSucceeded();
        } catch (Exception e) {
            logger.error(" save error :" + e.getMessage());
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
        return null;
    }
    public Boolean update(List<SaveModel> sms) {
        JestClient jestClient = null;
        try {
            //得到链接
            JestClient jestClient = elasticFactory.getJestClient();
            jestClient = elasticFactory.getJestClient();
            int success = 0;
            int error = 0;
@ -79,8 +84,8 @@ public class ElastricSearchSave {
            Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
            for (SaveModel obj : sms) {
                try {
                    JSONObject jo=new JSONObject();
                    jo.put("doc",obj);
                    JSONObject jo = new JSONObject();
                    jo.put("doc", obj);
                    Update index = new Update.Builder(jo.toString()).index(esIndex).type(esType).id(obj.getId()).build();
                    bulk.addAction(index);
                    success++;
@ -98,6 +103,10 @@ public class ElastricSearchSave {
            return isSuccessed;
        } catch (Exception e) {
            logger.error(" update error :" + e.getMessage());
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
        return null;
    }

+ 8 - 4
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/job/business/MysqlToEsQuotaJob.java

@ -132,7 +132,7 @@ public class MysqlToEsQuotaJob implements Job {
        this.quotaDate = DateUtil.strToDate(endTime, "yyyy-MM-dd");
        this.wlyyJobCongId = map.getString("jobConfig");
        this.quartzJobConfig=quartzJobConfigDao.findById(wlyyJobCongId);
        this.quartzJobConfig = quartzJobConfigDao.findById(wlyyJobCongId);
    }
    /**
@ -180,8 +180,9 @@ public class MysqlToEsQuotaJob implements Job {
     * @param timeLevel
     */
    private void deleteData(Date quotaDate, String quotaCode, String timeLevel) {
        JestClient jestClient = null;
        try {
            JestClient jestClient = elasticFactory.getJestClient();
            jestClient = elasticFactory.getJestClient();
            //先根据条件查找出来
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.query(
@ -206,9 +207,12 @@ public class MysqlToEsQuotaJob implements Job {
            logger.info("delete data count:" + saveModels.size());
            logger.info("delete flag:" + br.isSucceeded());
            jestClient.shutdownClient();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
    }
@ -285,7 +289,7 @@ public class MysqlToEsQuotaJob implements Job {
                dataModels = SpringUtil.getBean(ExtractHelper.class).extractData(quartzJobConfig, startTime, endTime, year, timeLevel);
            } else {
                //缓存的key 是 时间+timelevel+key
                StringBuffer bu = new StringBuffer(DateUtil.dateToStr(quotaDate, "yyyy-MM-dd") + "-" + timeLevel + "-" +quartzJobConfig.getCacheKey());
                StringBuffer bu = new StringBuffer(DateUtil.dateToStr(quotaDate, "yyyy-MM-dd") + "-" + timeLevel + "-" + quartzJobConfig.getCacheKey());
                //支持的话判断缓存有没有值
                dataModels = Cache.getCache(bu.toString());
                if (dataModels == null) {

+ 31 - 27
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/config/es/ElastricSearchSave.java

@ -20,31 +20,35 @@ import java.util.List;
@Component
@Scope("prototype")
public class ElastricSearchSave {
	
	private Logger logger = LoggerFactory.getLogger(ElastricSearchSave.class);
	@Autowired
	private ElasticFactory elasticFactory;
	
	public Boolean save(List  sms,String esIndex,String esType) {
		try {
			//得到链接
			JestClient jestClient = elasticFactory.getJestClient();
			
			Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
			for (Object obj : sms) {
				Index index = new Index.Builder(obj).build();
				bulk.addAction(index);
			}
			BulkResult br = jestClient.execute(bulk.build());
			logger.info("save data count:" + sms.size());
			logger.info("save flag:" + br.isSucceeded());
			jestClient.shutdownClient();
			return br.isSucceeded();
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(" save error :" + e.getMessage());
		}
		return null;
	}
	
    private Logger logger = LoggerFactory.getLogger(ElastricSearchSave.class);
    @Autowired
    private ElasticFactory elasticFactory;
    public Boolean save(List sms, String esIndex, String esType) {
        JestClient jestClient = null;
        try {
            //得到链接
            jestClient = elasticFactory.getJestClient();
            Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
            for (Object obj : sms) {
                Index index = new Index.Builder(obj).build();
                bulk.addAction(index);
            }
            BulkResult br = jestClient.execute(bulk.build());
            logger.info("save data count:" + sms.size());
            logger.info("save flag:" + br.isSucceeded());
            return br.isSucceeded();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(" save error :" + e.getMessage());
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
        return null;
    }
}

+ 8 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/config/es/ElastricSearchSave.java

@ -27,10 +27,12 @@ public class ElastricSearchSave {
    @Autowired
    private ElasticFactory elasticFactory;
    public Boolean save(List  sms,String esIndex,String esType) {
    public Boolean save(List sms, String esIndex, String esType) {
        JestClient jestClient = null;
        try {
            //得到链接
            JestClient jestClient = elasticFactory.getJestClient();
            jestClient = elasticFactory.getJestClient();
            Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
            for (Object obj : sms) {
@ -40,11 +42,14 @@ public class ElastricSearchSave {
            BulkResult br = jestClient.execute(bulk.build());
            logger.info("save data count:" + sms.size());
            logger.info("save flag:" + br.isSucceeded());
            jestClient.shutdownClient();
            return br.isSucceeded();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(" save error :" + e.getMessage());
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
        return null;
    }

+ 136 - 110
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/followup/FollowUpService.java

@ -903,77 +903,88 @@ public class FollowUpService extends BaseService {
     */
    @Transactional
    public void esSaveFollowupProjectData(String id, String followupProject, String followupProjectData) throws Exception {
        JestClient jestClient = null;
        try {
        JestClient jestClient = elasticFactory.getJestClient();
        //先根据条件查找出来
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.query(
                new BoolQueryBuilder()
                        .must(QueryBuilders.matchQuery("followup_id", id))
                        .must(QueryBuilders.matchQuery("followup_project", followupProject))
        );
        Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType)
                .build();
        SearchResult result = jestClient.execute(search);
        List<FollowupContentESDO> dataList = result.getSourceAsObjectList(FollowupContentESDO.class);
        //删除原有记录
        this.esDeleteFollowUpContent(dataList);
        //保存新的随访详情信息
        List<FollowupContentESDO> newdatalist = new ArrayList<>();
        FollowupContentESDO followupContentESDO = new FollowupContentESDO();
        followupContentESDO = JSON.parseObject(followupProjectData, FollowupContentESDO.class);
        followupContentESDO.setFollowup_id(id);
        followupContentESDO.setFollowup_project(followupProject);
        followupContentESDO.setCreate_time(new Date());
        newdatalist.add(followupContentESDO);
        elastricSearchSave.save(newdatalist, esIndex, esType);
            jestClient = elasticFactory.getJestClient();
            //先根据条件查找出来
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.query(
                    new BoolQueryBuilder()
                            .must(QueryBuilders.matchQuery("followup_id", id))
                            .must(QueryBuilders.matchQuery("followup_project", followupProject))
            );
            Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType)
                    .build();
            SearchResult result = jestClient.execute(search);
            List<FollowupContentESDO> dataList = result.getSourceAsObjectList(FollowupContentESDO.class);
            //删除原有记录
            this.esDeleteFollowUpContent(dataList);
            //保存新的随访详情信息
            List<FollowupContentESDO> newdatalist = new ArrayList<>();
            FollowupContentESDO followupContentESDO = new FollowupContentESDO();
            followupContentESDO = JSON.parseObject(followupProjectData, FollowupContentESDO.class);
            followupContentESDO.setFollowup_id(id);
            followupContentESDO.setFollowup_project(followupProject);
            followupContentESDO.setCreate_time(new Date());
            newdatalist.add(followupContentESDO);
            elastricSearchSave.save(newdatalist, esIndex, esType);
            //如果该随访是已完成的,则添加随访信息上传映射,上传到基卫
            Followup followup = followupDao.findOne(Long.valueOf(id));
            if ("1".equals(followup.getStatus())) {
                FollowupMapping followupMapping = followUpMappingDao.findByFollowupId(Integer.parseInt(id));
                if (followupMapping == null) {
                    followupMapping = new FollowupMapping();
                    followupMapping.setCode(UUID.randomUUID().toString());
                    followupMapping.setFollowupId(Integer.parseInt(id));
                    followupMapping.setUpdateTime(DateUtil.getNowTimestamp());
                    followupMapping.setCreateTime(DateUtil.getNowTimestamp());
                }
                followupMapping.setNeedUpload(1);
                followUpMappingDao.save(followupMapping);
            }
        //如果该随访是已完成的,则添加随访信息上传映射,上传到基卫
        Followup followup = followupDao.findOne(Long.valueOf(id));
        if ("1".equals(followup.getStatus())) {
            FollowupMapping followupMapping = followUpMappingDao.findByFollowupId(Integer.parseInt(id));
            if (followupMapping == null) {
                followupMapping = new FollowupMapping();
                followupMapping.setCode(UUID.randomUUID().toString());
                followupMapping.setFollowupId(Integer.parseInt(id));
                followupMapping.setUpdateTime(DateUtil.getNowTimestamp());
                followupMapping.setCreateTime(DateUtil.getNowTimestamp());
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
            followupMapping.setNeedUpload(1);
            followUpMappingDao.save(followupMapping);
        }
        jestClient.shutdownClient();
    }
    /**
     * ES获取面访项目数据
     */
    public FollowupContentESDO esGetFollowupProjectData(String id, String followupProject) throws Exception {
        //根据随访ID、分类ID获取随访记录详情
        JestClient jestClient = elasticFactory.getJestClient();
        //先根据条件查找出来
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.query(
                new BoolQueryBuilder()
                        .must(QueryBuilders.matchQuery("followup_id", id))
                        .must(QueryBuilders.matchQuery("followup_project", followupProject))
        );
        Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType)
                .build();
        SearchResult result = jestClient.execute(search);
        FollowupContentESDO followupContentESDO = result.getSourceAsObject(FollowupContentESDO.class);
        jestClient.shutdownClient();
        JestClient jestClient = null;
        FollowupContentESDO followupContentESDO = null;
        try {
            //根据随访ID、分类ID获取随访记录详情
            jestClient = elasticFactory.getJestClient();
            //先根据条件查找出来
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.query(
                    new BoolQueryBuilder()
                            .must(QueryBuilders.matchQuery("followup_id", id))
                            .must(QueryBuilders.matchQuery("followup_project", followupProject))
            );
            Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType)
                    .build();
            SearchResult result = jestClient.execute(search);
            followupContentESDO = result.getSourceAsObject(FollowupContentESDO.class);
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
        return followupContentESDO;
    }
@ -984,8 +995,9 @@ public class FollowUpService extends BaseService {
     * @date 2017/11/1 15:17
     */
    public void esDeleteFollowUpContent(List<FollowupContentESDO> datalist) throws Exception {
        JestClient jestClient = null;
        try {
            JestClient jestClient = elasticFactory.getJestClient();
            jestClient = elasticFactory.getJestClient();
            //根据id批量删除
            Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
            for (FollowupContentESDO obj : datalist) {
@ -997,8 +1009,10 @@ public class FollowUpService extends BaseService {
            logger.info("delete data count:" + datalist.size());
            logger.info("delete flag:" + br.isSucceeded());
            jestClient.shutdownClient();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
    }
@ -1010,32 +1024,37 @@ public class FollowUpService extends BaseService {
     * @date 2017/11/1 19:41
     */
    public List<String> esfindProjectByFollowupId(String id) throws Exception {
        //根据随访ID、分类ID获取随访记录详情
        JestClient jestClient = null;
        List<String> resultList = new ArrayList<>();
        try {
            //根据随访ID、分类ID获取随访记录详情
            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> followupContentESDOList = new ArrayList<>();
            followupContentESDOList = result.getSourceAsObjectList(FollowupContentESDO.class);
            if (!followupContentESDOList.isEmpty()) {
                for (FollowupContentESDO followupContentESDO : followupContentESDOList) {
                    resultList.add(followupContentESDO.getFollowup_project());
                }
            }
        JestClient 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> followupContentESDOList = new ArrayList<>();
        followupContentESDOList = result.getSourceAsObjectList(FollowupContentESDO.class);
        if (!followupContentESDOList.isEmpty()) {
            for (FollowupContentESDO followupContentESDO : followupContentESDOList) {
                resultList.add(followupContentESDO.getFollowup_project());
            jestClient.shutdownClient();
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
        jestClient.shutdownClient();
        return resultList;
    }
@ -1046,30 +1065,36 @@ public class FollowUpService extends BaseService {
     * @date 2017/11/1 19:41
     */
    public List<FollowupContentESDO> esfindFollowUpContestsByFollowupId(String id) throws Exception {
        //根据随访ID、分类ID获取随访记录详情
        List<String> resultList = new ArrayList<>();
        JestClient jestClient = null;
        List<FollowupContentESDO> followupContentESDOList = new ArrayList<>();
        try {
            //根据随访ID、分类ID获取随访记录详情
        JestClient jestClient = elasticFactory.getJestClient();
        //先根据条件查找出来
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.query(
                new BoolQueryBuilder()
                        .must(QueryBuilders.matchQuery("followup_id", id))
        );
            List<String> resultList = new ArrayList<>();
        Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType)
                .build();
        SearchResult result = jestClient.execute(search);
            jestClient = elasticFactory.getJestClient();
            //先根据条件查找出来
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.query(
                    new BoolQueryBuilder()
                            .must(QueryBuilders.matchQuery("followup_id", id))
            );
        List<FollowupContentESDO> followupContentESDOList = new ArrayList<>();
            Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType)
                    .build();
            SearchResult result = jestClient.execute(search);
        jestClient.shutdownClient();
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
        return followupContentESDOList;
    }
    /**
     * 根据续方CODE获取随访记录信息
     *
     * @param prescriptionCode
     * @return
     */
@ -1084,6 +1109,7 @@ public class FollowUpService extends BaseService {
    /**
     * 获取随访详情记录分类记录数
     *
     * @param followupid
     * @param type
     * @return
@ -1092,25 +1118,25 @@ public class FollowUpService extends BaseService {
        int count = 0;
        String[] typelist = null;
        if(type.contains(",")){
        if (type.contains(",")) {
            typelist = type.split(",");
        }else{
        } else {
            typelist = new String[]{type};
        }
        for (String typekey: typelist) {
            if(!"drug".equals(type)){
        for (String typekey : typelist) {
            if (!"drug".equals(type)) {
                FollowupContentESDO followupContentESDO = this.esGetFollowupProjectData(followupid,typekey);
                if(followupContentESDO != null){
                    count ++;
                FollowupContentESDO followupContentESDO = this.esGetFollowupProjectData(followupid, typekey);
                if (followupContentESDO != null) {
                    count++;
                }
            }else{
            } else {
                //获取用药记录
                List<FollowupDrugs> drugsList = followupDrugsDao.findByFollowupId(Long.valueOf(followupid));
                if(!drugsList.isEmpty()){
                    count = count +drugsList.size();
                if (!drugsList.isEmpty()) {
                    count = count + drugsList.size();
                }
            }
        }