瀏覽代碼

SolrHelper注入异常解决

LiTaohong 7 年之前
父節點
當前提交
8342799a2f

+ 5 - 4
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/controller/medicine/PhysicalExaminationController.java

@ -13,6 +13,7 @@ import com.yihu.mm.util.JSONUtil;
import com.yihu.wlyy.entity.patient.Patient;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -63,7 +64,7 @@ public class PhysicalExaminationController extends WeixinBaseController {
    @ApiOperation(value = "新增预约单/获取咨询编号等信息")
    @RequestMapping(value = "/insertslip",produces="application/json;charset=UTF-8")
    @ResponseBody
    public String insertslip(@ApiParam(name = "patientCode", value = "居民code", required = true)@RequestParam(required = true, name = "patientCode") String patientCode, HttpServletRequest req){
    public String insertslip(@ApiParam(name = "patientCode", value = "居民code", required = true)@RequestParam(required = true, name = "patientCode") String patientCode, HttpServletRequest req) throws JSONException {
        Patient patient = patientService.findByCode(patientCode);
        int isSignJM = patientService.isSignJM(patientCode);
@ -95,7 +96,7 @@ public class PhysicalExaminationController extends WeixinBaseController {
    @ResponseBody
    public String findQuestion(@ApiParam(name = "pb_id", value = "问卷编号,第一题为0", required = true)@RequestParam(required = true, name = "pb_id") String pb_id,
                               @ApiParam(name = "patientCode", value = "居民code", required = true)@RequestParam(required = true, name = "patientCode") String patientCode,
                               @ApiParam(name = "ct_id", value = "咨询编号", required = true)@RequestParam(required = true, name = "ct_id") String ct_id) throws IOException {
                               @ApiParam(name = "ct_id", value = "咨询编号", required = true)@RequestParam(required = true, name = "ct_id") String ct_id) throws IOException, JSONException {
        String question = physicalExaminationService.findQuestion(examCode, pb_id, ct_id);
@ -144,7 +145,7 @@ public class PhysicalExaminationController extends WeixinBaseController {
                               @ApiParam(name = "pb_id", value = "问卷编号,第一题为0", required = true)@RequestParam(required = true, name = "pb_id") String pb_id,
                                @ApiParam(name = "type", value = "试题类型(0单选 ,1多选)", required = true)@RequestParam(required = true, name = "type") String type,
                               @ApiParam(name = "dc_answer", value = "问题答案", required = true)@RequestParam(required = true, name = "dc_answer") String dc_answer,
                             @ApiParam(name = "patientCode", value = "居民code", required = true)@RequestParam(required = true, name = "patientCode") String patientCode){
                             @ApiParam(name = "patientCode", value = "居民code", required = true)@RequestParam(required = true, name = "patientCode") String patientCode) throws JSONException {
        //提交答案
        String result = physicalExaminationService.handleExam(examCode, pb_id, dc_answer, ct_id);
        JSONObject resultJson = new JSONObject(result);
@ -224,7 +225,7 @@ public class PhysicalExaminationController extends WeixinBaseController {
    public String dillphoneimgdata(@RequestParam MultipartFile file,
                              @ApiParam(name = "patientCode", value = "居民code", required = true)@RequestParam(required = true, name = "patientCode") String patientCode,
                              @ApiParam(name = "type", value = "1.脸型  2.舌像  3.声音", required = true)@RequestParam(required = true, name = "type") String type,
                             @ApiParam(name = "ct_id", value = "咨询编号", required = true)@RequestParam(required = true, name = "ct_id") String ct_id){
                             @ApiParam(name = "ct_id", value = "咨询编号", required = true)@RequestParam(required = true, name = "ct_id") String ct_id) throws JSONException {
        String uploadAttachment = physicalExaminationService.uploadAttachment(file);
        JSONObject uploadResult = new JSONObject(uploadAttachment);
        if(physicalExaminationService.getSuccess(uploadResult)){

+ 1 - 1
patient-co/patient-co-figure-label/pom.xml

@ -91,7 +91,7 @@
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>common-data-solr-starter</artifactId>
            <version>1.0.1</version>
            <version>1.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>

+ 14 - 0
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/config/db/FigureLabelJpa.java

@ -2,6 +2,8 @@ package com.yihu.wlyy.figure.label.config.db;
import com.alibaba.druid.pool.DruidDataSource;
import com.yihu.base.SolrHelper;
import com.yihu.base.SolrPool;
import com.yihu.wlyy.figure.label.config.db.properties.DataSourceProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@ -142,4 +144,16 @@ public class FigureLabelJpa {
    public JdbcTemplate thirdJdbcTemplate(@Qualifier("wlyy85DataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
    @Bean
    public SolrHelper solrHelper() {
        SolrHelper solrHelper = new SolrHelper();
        return solrHelper;
    }
    @Bean
    public SolrPool solrPool() {
        SolrPool solrPool = new SolrPool();
        return solrPool;
    }
}

+ 2 - 2
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/ConvertHelper.java

@ -71,7 +71,7 @@ public class ConvertHelper {
        try {
            Class clazz = Class.forName(flLabelDictJob.getConvertClazz());
            Object obj = ApplicationContextHolderUtil.getContext().getBean(clazz);
            Method method = obj.getClass().getMethod("convert", List.class, List.class,String.class,String.class);
            Method method = obj.getClass().getMethod("convert", List.class, List.class,List.class,String.class,String.class);
            saveModels = (List<SaveModel>) method.invoke(obj, dataModels, hbaseDatas,flLabelDictList,sourceType,source);
        } catch (Exception e) {
          logger.error("customized class or convert() method not found:" + flLabelDictJob.getConvertClazz());
@ -148,7 +148,7 @@ public class ConvertHelper {
     * @return
     */
    public void generateDataSource(DataModel dataModel,SaveModel saveModel,String sourceType,String sources) {
        if(!StringUtils.endsWithIgnoreCase(SourceTypeEnum.MYSQL.toString(),sourceType) && !StringUtils.endsWithIgnoreCase(SourceTypeEnum.ELASTICSEARCH.toString(),sourceType) ){
        if(!StringUtils.endsWithIgnoreCase(SourceTypeEnum.MYSQL.toString(),sourceType) && !StringUtils.endsWithIgnoreCase(SourceTypeEnum.ELASTICSEARCH.toString(),sourceType) && !StringUtils.endsWithIgnoreCase(SourceTypeEnum.HBASE.toString(),sourceType)){
            return;
        }
        StringBuilder ids = new StringBuilder();

+ 58 - 0
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/EhrHealthProblemConvert.java

@ -0,0 +1,58 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.figure_label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.util.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @author litaohong on 2018/5/7
 * @project patient-co-management
 * 医疗云数据,健康问题标签
 */
@Component
public class EhrHealthProblemConvert implements Convert{
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict one = flLabelDictList.get(0);
        hbaseDatas.forEach(
                hbaseMap -> {
                    SaveModel saveModel = new SaveModel();
                    saveModel.setIdcard(String.valueOf(hbaseMap.get("EHR_000017")));
                    saveModel.setDictCode(one.getDictCode());
                    Object labelCode = hbaseMap.get("health_problem");
                    if(null == labelCode){
                        return;
                    }
                    Object labelName = hbaseMap.get("health_problem_name");
                    if(null == labelName){
                        return;
                    }
                    saveModel.setLabelType(one.getParentCode());
                    saveModel.setLabelCode(String.valueOf(labelCode));
                    saveModel.setLabelName(String.valueOf(labelName));
                    DataModel dataModel = new DataModel();
                    dataModel.setIdstr(String.valueOf(hbaseMap.get("rowkey")));
                    convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
                    saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
                    saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
                    saveModels.add(saveModel);
                }
        );
        return saveModels;
    }
}

+ 58 - 0
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/EhrICD10CMConvert.java

@ -0,0 +1,58 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.figure_label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.util.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @author litaohong on 2018/5/7
 * @project patient-co-management
 * 医疗云数据,标准疾病诊断标签
 */
@Component
public class EhrICD10CMConvert implements Convert{
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict one = flLabelDictList.get(0);
        hbaseDatas.forEach(
                hbaseMap -> {
                    SaveModel saveModel = new SaveModel();
                    saveModel.setIdcard(String.valueOf(hbaseMap.get("EHR_000017")));
                    saveModel.setDictCode(one.getDictCode());
                    Object labelCode = hbaseMap.get("diagnosis");
                    if(null == labelCode){
                        return;
                    }
                    Object labelName = hbaseMap.get("diagnosis_name");
                    if(null == labelName){
                        return;
                    }
                    saveModel.setLabelType(one.getParentCode());
                    saveModel.setLabelCode(String.valueOf(labelCode));
                    saveModel.setLabelName(String.valueOf(labelName));
                    DataModel dataModel = new DataModel();
                    dataModel.setIdstr(String.valueOf(hbaseMap.get("rowkey")));
                    convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
                    saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
                    saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
                    saveModels.add(saveModel);
                }
        );
        return saveModels;
    }
}

+ 2 - 2
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/ESExtracter.java

@ -25,8 +25,8 @@ public class ESExtracter implements Extracter{
    private ElasticsearchUtil elasticsearchUtil;
    @Override
    public  List<Object> extractData(String sql, String datasource){
        List<Object> saveModels = new ArrayList<>();
    public  List<DataModel> extractData(String sql, String datasource){
        List<DataModel> saveModels = new ArrayList<>();
        List<Map<String,Object>> list = elasticsearchUtil.excuteDataModel(sql);
        for(Map<String,Object> tempMap:list){
            try {

+ 47 - 20
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/HbaseExtracter.java

@ -4,6 +4,7 @@ import com.yihu.base.SolrHelper;
import com.yihu.base.hbase.HBaseHelper;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.util.TimeUtil;
import org.apache.solr.common.SolrDocumentList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -42,49 +43,75 @@ public class HbaseExtracter implements Extracter{
    public  List<Map<String,Object>>  extractData(String core, String q, String fq) {
        List<Map<String,Object>> result = new ArrayList<>();
        String[] arr = core.split(";");
        String solrCore = arr[0];
        String table = arr[1];
        List<String> rowkeys = new ArrayList<>();
        rowkeys = getRowkeys(core,q,fq);
        rowkeys = getRowkeys(solrCore,q,fq);
        for(String rowkey : rowkeys){
           Map<String,Object> map = hBaseHelper.getResultMap(rowkey,"HealthProfile");
           Map<String,Object> map = hBaseHelper.getResultMap(table,rowkey);
            result.add(map);
        }
        return result;
    }
    public List<String> getRowkeys(String core, String q, String fq) {
        List<String> rowkeyList = new ArrayList<>();
        long count = 0;
        try {
            count = solrHelper.count(core, q);
            solrHelper.query(core, q, fq, null, 0, 0);
            String[] fqs = {fq};
            rowkeyList = getRowkeysFromSolr(core, q, fqs, 0, count);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("get solr query error");
        }
        int number = (int) count / numPerPage + 1;
       /* int number = (int) count / numPerPage + 1;
        List<String> rowkeys = new ArrayList<>();
        ExecutorService fixedThreadPool = Executors.newFixedThreadPool(number);
        List<Callable<List<String>>> threadList = new ArrayList<>();
        for (int i = 0; i < number; i++) {
            MutilThreadSearchSolrIndexExtracter searchSolrIndexExtracter = new MutilThreadSearchSolrIndexExtracter(solrHelper, core, q, fq, i * numPerPage, numPerPage);
            threadList.add(searchSolrIndexExtracter);
            long start = System.currentTimeMillis();
            String logTitle = "therad get data";
            TimeUtil.start(logger, logTitle, start);
            try {
                List<Future<List<String>>> futureList = fixedThreadPool.invokeAll(threadList);
                //取回线程执行的结果
                for (Future future : futureList) {
                    rowkeys.addAll((List<String>) future.get());
                }
            } catch (Exception e) {
                e.printStackTrace();
                logger.error("get futureList result error");
        }
        long start = System.currentTimeMillis();
        String logTitle = "therad get data";
        TimeUtil.start(logger, logTitle, start);
        try {
            List<Future<List<String>>> futureList = fixedThreadPool.invokeAll(threadList);
            //取回线程执行的结果
            for (Future future : futureList) {
                rowkeys.addAll((List<String>) future.get());
            }
            long finish = System.currentTimeMillis();
            TimeUtil.finish(logger, logTitle, start, finish);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("get futureList result error");
        }
        return null;
        long finish = System.currentTimeMillis();
        TimeUtil.finish(logger, logTitle, start, finish);
        return rowkeys;*/
        return rowkeyList;
    }
    public List<String> getRowkeysFromSolr(String core,String q,String[] fq,long start,long rows){
        List<String> rowkeyList = new ArrayList<>();
        SolrDocumentList solrDocumentList = null;
        String logTitle = "get data from solr";
        TimeUtil.start(logger, logTitle, start);
        try {
            solrDocumentList = solrHelper.queryfl(core,q,fq,null,"rowkey",start,rows);
        } catch (Exception e) {
            e.printStackTrace();
        }
        long finish = System.currentTimeMillis();
        TimeUtil.finish(logger, logTitle, start, finish);
        logger.info("job get data counts:" + solrDocumentList.size());
        solrDocumentList.forEach(
                document -> {
                    rowkeyList.add(document.get("rowkey").toString());
                }
        );
        return rowkeyList;
    }
}

+ 2 - 2
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/MutilThreadSearchSolrIndexExtracter.java

@ -25,7 +25,7 @@ public class MutilThreadSearchSolrIndexExtracter implements Callable {
    private String core;
    private String q;
    private String fq;
    private String[] fq;
    private long start;
    private long rows;
@ -40,7 +40,7 @@ public class MutilThreadSearchSolrIndexExtracter implements Callable {
    @Override
    public Object call() throws Exception {
        List<String> rowkeyList = new ArrayList<>();
        SolrDocumentList solrDocumentList = solrHelper.query(core,q,fq,null,start,rows);
        SolrDocumentList solrDocumentList = solrHelper.queryfl(core,q,fq,null,"rowkey",start,rows);
        logger.info("job get data counts:" + solrDocumentList.size());
        solrDocumentList.forEach(
                document -> {

+ 2 - 1
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/job/Es2EsJob.java

@ -69,6 +69,7 @@ public class Es2EsJob implements Job {
     */
    private long lastDataId;
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        JobDataMap paramsMap = context.getJobDetail().getJobDataMap();
        initParams(paramsMap);
@ -142,7 +143,7 @@ public class Es2EsJob implements Job {
        List<SaveModel> list = new ArrayList<>();
        FlLabelDictJob flLabelDictJob = flLabelDictJobDao.findByJobId(this.flJobConfigId);
        try {
            list = convertHelper.convert(this.dataModelList, flLabelDictJob,this.sourceType,this.source);
            list = convertHelper.convert(this.dataModelList, null,flLabelDictJob,this.sourceType,this.source);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }

+ 1 - 1
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/job/Hbase2ESJob.java

@ -122,7 +122,7 @@ public class Hbase2ESJob implements Job {
        }
        //1抽取数据
        this.q = this.flJobConfig.getSql();
        String sqlFiled = this.flJobConfig.getSqlField();
        fq = this.flJobConfig.getSqlField() + ":" + "[* TO " + this.sqlFiledValue + "]";
    }

+ 1 - 1
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/job/Mysql2ESJob.java

@ -139,7 +139,7 @@ public class Mysql2ESJob implements Job {
        List<SaveModel> list = new ArrayList<>();
        FlLabelDictJob flLabelDictJob = flLabelDictJobDao.findByJobId(this.flJobConfigId);
        try {
            list = convertHelper.convert(this.dataModelList, flLabelDictJob,this.sourceType,this.source);
            list = convertHelper.convert(this.dataModelList, null,flLabelDictJob,this.sourceType,this.source);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }

+ 2 - 1
patient-co/patient-co-figure-label/src/main/resources/logback.xml

@ -24,7 +24,8 @@
    </appender>
    <root level="INFO">
    <!--<root level="debug">-->
    <root level="info">
        <!--<appender-ref ref="console" />-->
        <appender-ref ref="rollingFile"/>
    </root>